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的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...
随机推荐
- 中国石油大学(华东)暑期集训--二进制(BZOJ5294)【线段树】
问题 C: 二进制 时间限制: 1 Sec 内存限制: 128 MB提交: 8 解决: 2[提交] [状态] [讨论版] [命题人:] 题目描述 pupil发现对于一个十进制数,无论怎么将其的数字 ...
- shell 倒引号
`command` 倒引号 (backticks) 在前面的单双引号,括住的是字串,但如果该字串是一列命令列,会怎样?答案是不会执行.要处理这种情况,我们得用倒单引号来做. fdv=`date +%F ...
- Line Reflection -- LeetCode
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...
- [Codeforces #211] Tutorial
Link: Codeforces #211 传送门 一套非常简单的题目,但很多细节都是错了一次才能发现啊…… 还是不能养成OJ依赖症,交之前先多想想corner case!!! A: 模拟,要特判0啊 ...
- hdu 1864 最大报销额(背包)
最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 【Matrix-tree定理】【BEST Theorem】hdu6064 RXD and numbers
题意:给你一张有向图,求从1出发,回到1的欧拉回路数量. 先特判掉欧拉回路不存在时的情况. 看这个吧:http://blog.csdn.net/yuanjunlai141/article/detail ...
- 搭建vsftpd
安装完软件以后 1.建立用户 adduser ftp passwd 密码 2.修改vsftp.conf文件 anonymous_enable改为NO,阻止匿名上传 Anon_mkdir_write_e ...
- Spring+Spring MVC+MyBatis整合
一.准备工作 1.1导入所需jar包 1.2数据库 CREATE TABLE `t_customer` ( `id` ) NOT NULL AUTO_INCREMENT, `username` ...
- ES6 Set结构和Map结构(上)
Set ES6提供了新的数据结构--Set,它类似于数组,但是成员的值都是唯一的,没有重复的值. Set本身也是一个构造函数,用来生成Set数据结构 var s = new Set(); [2,3,5 ...
- python多线程以及同步队列(转)
转自:http://www.w3cschool.cc/python/python-multithreading.html 多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长 ...