此弹窗为开机SystemUI的显示弹窗:

首先。在SystemUI的源代码文件夹加入源代码类文件,文件夹为frameworks/base/packages/SystemUI/src/com/android/systemui/settings,类名暂取为UpdateUI.java内容例如以下:

/*

 * Copyright (C) 2008 The Android Open Source Project

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *      http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "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 for...

        IntentFilter filter = new IntentFilter();

        filter.addAction(ACTION);

        mContext.registerReceiver(mIntentReceiver, filter, null, null);

    }



    private boolean shouldShow(final String str) {

//此处处理广播过来的数据字段,如若与已存在xml的数据同样,则不再提示弹窗,否则弹窗并更新xml数据。

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 ====");

//此Dialog为第三方加入的于framework的标准dialog,在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;

    }



}

而后。将该类加入至SystemUI开机启动的service类名列表中:

改动文件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,

        };

至此。加入完成。。


Android4.4 SystemUI加入Dialog弹窗的更多相关文章

  1. jQuery的dialog弹窗实现

    jQuery实现dialog弹窗: html代码如下: <input type="button" onclick="performances();" va ...

  2. 封装React AntD的dialog弹窗组件

    前一段时间分享了基于vue和element所封装的弹窗组件(封装Vue Element的dialog弹窗组件),今天就来分享一个基于react和antD所封装的弹窗组件,反正所使用的技术还是那个技术, ...

  3. Flutter - 自定义Dialog弹窗

    ------------恢复内容开始------------ Flutter - 自定义Dialog弹窗 应用场景:app系统版本升级弹窗,系统退出登录弹窗,首页广告弹窗,消息中心弹窗,删除文件弹窗等 ...

  4. JQuery UI dialog 弹窗实例及参数说明

    按钮代码: <a id="suprise" style="margin-left: 0.5em;cursor:pointer;">点我会有惊喜< ...

  5. Ext里dialog弹窗关闭与父窗口刷新问题总结

    1.弹出弹窗的js代码 var dlg = new J.dialog({ id: 'unDelTel', title:'缴费', page:encodeURI('<%=basePath%> ...

  6. 封装Vue Element的dialog弹窗组件

    我本没有想着说要封装一个弹窗组件,但有同行的朋友在问我,而且弹窗组件也确实在项目开发中用的比较多.思前想后,又本着样式统一且修改起来方便的原则,还是再为大家分享一个我所封装的弹窗组件吧. 其实,并不是 ...

  7. easyUI dialog 弹窗 居中显示

    默认情况下应该是在屏幕居中显示的.但是有的时候没有居中只要重新纠正下就可以了 $('#add_dialog').dialog('open'); //打开添加对话框 $('#add_dialog').w ...

  8. 【Vue 2.X】基于ElementUI 实现 dialog弹窗移动效果-自定义指令系列(二)

    v-dialogDrag: 弹窗拖拽 使用: <el-dialog XXX v-dialogDrag></el-dialog> Vue.directive('dialogDra ...

  9. 新人成长之入门Vue.js弹窗Dialog介绍(二)

    前言 在上一篇博文中介绍了Vue.js的常用指令,今天总结归纳一下弹窗Dialog的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...

随机推荐

  1. HDU 5828 Rikka with Sequence(线段树 开根号)

    Rikka with Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. ZOJ 3949 Edge to the Root(想法)(倍增)

    Edge to the Root Time Limit: 1 Second      Memory Limit: 131072 KB Given a tree with n vertices, we ...

  3. CSS 笔记——定位尺寸

    3. 定位尺寸 -> 尺寸 (1)height 基本语法 height : auto | length 语法取值 auto : 默认值.无特殊定位,根据HTML定位规则分配 length : 由 ...

  4. 最优贸易 NOIP 2009 提高组 第三题

    题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...

  5. 【动态规划】POJ2385-Apple Catching

    [题目大意] 有两棵树1和2,奶牛Bessie位于树1下,每个单位时间会有一个苹果从其中一棵树掉下来,同时Bessie也可以移动一次,但是Bessie不希望移动超过W次,问T时间内Bessie最多得到 ...

  6. [转]spring property标签中的 ref属性和ref 标签有什么不同

    spring property标签中的 ref属性和ref 标签有什么不同? 如下:<property name="a" ref="b" /> sp ...

  7. (Mark)JS中关于闭包

    闭包(Closures) 在ECMAScript中,函数是“第一类”对象.这个名词意味着函数可以作为参数被传递给其他函数使用 (在这种情况下,函数被称为“funargs”——“functional a ...

  8. iOS笔记,得到一个控件的坐标

    [showBtn.superView  convertRect:showBtn.frame toView:nil]: 参数从后往前理解: toView-->指的目标控件的坐标需要在哪个view上 ...

  9. 【maven】ecplise新建maven项目 报错Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin

    在ecplise上新建maven项目 报错: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resourc ...

  10. socket心跳包机制实践与理解

    实现Socket心跳包主要分为两大类,第一采用tcp自带的KeepAlive,第二是自定义心跳包,恰巧我在产品VICA中都使用过,下面就这两种心跳包机制谈谈个人的理解与感受. 首先第一种KeepAli ...