Android4.4 Systemui joins the dialog pop-up window

Source: Internet
Author: User

This pop-up window is the display popup for the boot Systemui:

first. The source code folder is added to the Systemui file, the folder is Frameworks/base/packages/systemui/src/com/android/systemui/settings, The class name is tentatively taken as Updateui.java contents such as the following:

/*
* Copyright (C) The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You are not a use this file except in compliance with the License.
* Obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable or agreed to writing, software
* Distributed under the License is distributed on a "as is" BASIS,
* Without warranties or CONDITIONS of any KIND, either express or implied.
* See the License for the specific language governing permissions and
* Limitations under the License.
*/

Package com.android.systemui.settings;

Import Android.app.ActivityManager;
Import Android.app.ActivityManager.RunningTaskInfo;
Import Android.app.AlertDialog;
Import Android.app.Dialog;
Import Android.app.XXDialog;
Import Android.content.BroadcastReceiver;
Import Android.content.ComponentName;
Import Android.content.ContentResolver;
Import android.content.SharedPreferences;
Import Android.content.SharedPreferences.Editor;
Import Android.content.Context;
Import Android.content.DialogInterface;
Import Android.content.DialogInterface.OnDismissListener;
Import android.content.Intent;
Import Android.content.IntentFilter;
Import Android.net.Uri;
Import Android.os.UserHandle;
Import android.provider.Settings;
Import Android.util.Slog;
Import Android.view.View;
Import android.view.MotionEvent;
Import Android.view.WindowManager;
Import Android.widget.Button;
Import Android.widget.TextView;

Import COM.ANDROID.SYSTEMUI.R;
Import Com.android.systemui.SystemUI;
Import Android.app.XXDialog.ButtonClickListener;

Import Java.io.FileDescriptor;
Import Java.io.PrintWriter;
Import Java.util.Arrays;
Import java.util.List;

public class UpdateUI extends Systemui {
Static final String TAG = "UpdateUI";
Static final String ACTION = "Android.hm.WITH_UPGRADE_ICON";
Static final String Sourceflag = "From_check_service";
Static final String Forceflag = "Force";
Static final String Update = "com." XX.ota.MainActivity ";

private static Boolean fromservice = false;
private static Boolean forceupdate = false;
Private String vers;

Private Sharedpreferences sp;
Xxdialog Mupdatedialog;
TextView Mupdatetextview;

Private Long mscreenofftime =-1;

public void Start () {
Register for Intent broadcasts ...
Intentfilter filter = new Intentfilter ();
Filter.addaction (ACTION);
Mcontext.registerreceiver (mintentreceiver, filter, NULL, NULL);
}

Private Boolean shouldshow (Final String str) {

The Broadcast data field is processed here, and if it is the same as the data that already exists in the XML, the popup is no longer prompted, otherwise the popup window and the XML data are updated.


SP = mcontext.getsharedpreferences ("version", context.mode_private);
String Version = sp.getstring ("Version", "");
if (!str.equals (version)) {
Editor ed = Sp.edit ();
Ed.putstring ("version", Vers);
Ed.commit ();

return true;
}

return false;
}

Private Boolean Gettopwindow () {
Activitymanager am = (activitymanager) (Mcontext). Getsystemservice (Context.activity_service);
ComponentName cn = Am.getrunningtasks (1). Get (0). topactivity;
SLOG.E (TAG, "activity:" + cn.getclassname (). toString ());
if (Cn.getclassname (). Contains (Update))
return true;

return false;
}

Private Broadcastreceiver Mintentreceiver = new Broadcastreceiver () {
@Override
public void OnReceive (context context, Intent Intent) {
String action = Intent.getaction ();
if (Action.equals (action)) {
Fromservice = Intent.getbooleanextra (Sourceflag, false);
ForceUpdate = Intent.getbooleanextra (Forceflag, false);
Vers = Intent.getstringextra ("version");
if (Fromservice &&!gettopwindow ()) {
if (forceupdate) {
Showupdatedialog (forceupdate);
Return
} else if (Shouldshow (vers)) {
Showupdatedialog (forceupdate);
Return
}
}
}
}
};

void Dismissupdatedialog () {
if (mupdatedialog! = null) {
Mupdatedialog.dismiss ();
Mupdatedialog = null;
}
}

void Showupdatedialog (Final boolean bool) {
SLOG.E (TAG, "= = = Show update Dialog = = = =");

This dialog is a third party added to the framework's standard dialog, in Android.app.XXDialog.


Xxdialog.builder B = new Xxdialog.builder (mcontext);
Xxdialog dialog = B.create ();
Dialog.setrightbuttonname (mcontext.getstring (r.string.sure));
Dialog.setleftbuttonname (mcontext.getstring (r.string.cancel));
Dialog.setcontent (mcontext.getstring (R.string.update_notice));
Dialog.settitle (mcontext.getstring (r.string.system_update));
Dialog.notcloseontouch ();
if (bool) {
Dialog.setleftbuttonvisible (FALSE);
Dialog.setmiddlelinevisible (FALSE);
}

Final Intent Intent = new Intent ();
ComponentName comp = new ComponentName ("com. Xx.ota ",
"com. XX.ota.MainActivity ");
Intent.setcomponent (comp);
Intent.setaction ("Android.intent.action.VIEW");
Intent.setflags (Intent.flag_activity_new_task);
if (Intent.resolveactivity (Mcontext.getpackagemanager ()) = null) {
Dialog.setclicklistener (New Buttonclicklistener () {

@Override
public void RightClick () {
Mcontext.startactivityasuser (Intent, userhandle.current);
Dismissupdatedialog ();
}

@Override
public void Leftclick () {
if (!bool)
Dismissupdatedialog ();
}
});
}

Dialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Dialog.getwindow (). GetAttributes (). Privateflags |=
WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dialog.show ();
Mupdatedialog = Dialog;
}

}

Then. Add this class to the list of service class names that systemui boot up:

Change File Frameworks/base/packages/systemui/src/com/android/systemui/systemuiservice.java

Private final class<?>[] SERVICES = new class[] {
Com.android.systemui.recent.Recents.class,
Com.android.systemui.statusbar.SystemBars.class,
Com.android.systemui.usb.StorageNotification.class,
Com.android.systemui.power.PowerUI.class,
Com.android.systemui.media.RingtonePlayer.class,
Com.android.systemui.settings.SettingsUI.class,
Com.android.systemui.settings.UpdateUI.class,
Com.android.systemui.net.NetWorkWarningUI.class,
};

So far. Join Complete:


Android4.4 Systemui joins the dialog pop-up window

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.