Android4.4 SystemUI加入Dialog弹窗
此弹窗为开机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弹窗的更多相关文章
- jQuery的dialog弹窗实现
jQuery实现dialog弹窗: html代码如下: <input type="button" onclick="performances();" va ...
- 封装React AntD的dialog弹窗组件
前一段时间分享了基于vue和element所封装的弹窗组件(封装Vue Element的dialog弹窗组件),今天就来分享一个基于react和antD所封装的弹窗组件,反正所使用的技术还是那个技术, ...
- Flutter - 自定义Dialog弹窗
------------恢复内容开始------------ Flutter - 自定义Dialog弹窗 应用场景:app系统版本升级弹窗,系统退出登录弹窗,首页广告弹窗,消息中心弹窗,删除文件弹窗等 ...
- JQuery UI dialog 弹窗实例及参数说明
按钮代码: <a id="suprise" style="margin-left: 0.5em;cursor:pointer;">点我会有惊喜< ...
- Ext里dialog弹窗关闭与父窗口刷新问题总结
1.弹出弹窗的js代码 var dlg = new J.dialog({ id: 'unDelTel', title:'缴费', page:encodeURI('<%=basePath%> ...
- 封装Vue Element的dialog弹窗组件
我本没有想着说要封装一个弹窗组件,但有同行的朋友在问我,而且弹窗组件也确实在项目开发中用的比较多.思前想后,又本着样式统一且修改起来方便的原则,还是再为大家分享一个我所封装的弹窗组件吧. 其实,并不是 ...
- easyUI dialog 弹窗 居中显示
默认情况下应该是在屏幕居中显示的.但是有的时候没有居中只要重新纠正下就可以了 $('#add_dialog').dialog('open'); //打开添加对话框 $('#add_dialog').w ...
- 【Vue 2.X】基于ElementUI 实现 dialog弹窗移动效果-自定义指令系列(二)
v-dialogDrag: 弹窗拖拽 使用: <el-dialog XXX v-dialogDrag></el-dialog> Vue.directive('dialogDra ...
- 新人成长之入门Vue.js弹窗Dialog介绍(二)
前言 在上一篇博文中介绍了Vue.js的常用指令,今天总结归纳一下弹窗Dialog的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...
随机推荐
- HDU6074 Phone Call (并查集 LCA)
Phone Call Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Tota ...
- 【BFS】bzoj2252 [2010Beijing wc]矩阵距离
要注意一开始将所有为'1'的点入队,然后通过一次BFS去更新所有点的距离,直到无法更新为止. #include<cstdio> #include<queue> #include ...
- 计算gcd Exercise07_14
import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:计算gcd * */ public class Exercise07_14 ...
- [转]spring中<tx:advice></tx:advice>意义
<tx:advice id="tv" transaction-manager="transactionManager"> <tx:attrib ...
- IE主页被篡改为360导航终极处理办法
不得不吐槽360真他妈是流氓至极,在不被用户许可的情况下直接修改用户浏览器默认主页,还不容易找到修改的地方. 以IE为例:我们将其首页设置为百度https://www.baidu.com/,终极处理办 ...
- Inno Setup入门(十六)——Inno Setup类参考(2)
Inno Setup入门(十六)——Inno Setup类参考(2) http://379910987.blog.163.com/blog/static/33523797201112755641236 ...
- 原生js操作HTML DOM
先上图 1.一些常用的方法 obj.getElementById() 返回带有指定 ID 的元素. obj.getElementsByTagName() 返回包含带有指定标签名称的所有元素的节点列表( ...
- NodeJS搭建HTTP服务器
NodeJS本来的用途是编写高性能Web服务器.我们首先在这里重复一下官方文档里的例子,使用NodeJS内置的http模块简单实现一个HTTP服务器. 新建server.js var http = r ...
- Thunderbird for Ubuntu
转自:http://www.cnblogs.com/slave_wc/archive/2011/05/02/2034529.html 装好ubuntu 的一般基本配置见本博客另一篇文章: Ubun ...
- easyui-combobox绑定回车事件相关
去掉combobox回车内容不匹配清空输入项 问题描述:easyui的combobox插件,输入的内容如果和选项不匹配时,按下回车会导致输入的内容被清空. 解决办法:要解决回车时,combob ...