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的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...
随机推荐
- 【Leetcode】264. Ugly Number II ,丑数
原题 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime facto ...
- uva 10910(子集和问题)
Marks Distribution Time limit: 3.000 seconds In an examination one student appeared in N subjects an ...
- 手机发送验证码—.net代码
注册过程中,短信发送验证码流程如下: (1).用户提交手机号码,申请湖区验证码 (2).网站按照预制规则生成验证码 (3).网站将用户手机号码和验证码发送到短信平台 (4).将制定内容发送到制定手机号 ...
- java环境搭建的一些小知识
1.Path配置的是可执行程序的路径,例如(java.exe.javac.exe),这些可执行程序一般在bin目录下,所以path一般配置的是在程序包的bin目录下,实现帮助操作系统操作java的目的 ...
- 【Splay】Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals) B. Cards Sorting
Splay要支持找最左侧的最小值所在的位置.类似线段树一样处理一下,如果左子树最小值等于全局最小值,就查左子树:否则如果当前节点等于全局最小值,就查当前节点:否则查右子树. 为了统计答案,当然还得维护 ...
- 2.1(java编程思想笔记)位移操作
java位移操作主要有两种: 有符号位移:有符号位移会保留原有数字正负性,即正数依然是正数,负数依然是负数. 有符号位左移时,低位补0. 有符号右移时:当数字为正数,高位补0.当数字为负时高位补1. ...
- Xcode9出现错误safe area layout guide before ios 9 真正解决办法
网上很多解决办法瞎扯淡,以讹传讹之势愈演愈烈. 正解是选中控制器,右边面板的Builds for 选择iOS9.0 and Later,如下图红框广为流传的错解是不勾选Use Safe Area La ...
- python获取函数名
Date: 20140223Auth: Jin 参考: http://hi.baidu.com/greysign/item/d11919d325c4c2e6b2f777bf 获取函数名python中获 ...
- 椭圆曲线加密算法(ECC)原理和C++实现源码(摘录)
/* 1.用户A选定一条适合加密的椭圆曲线Ep(a,b)(如:y2=x3+ax+b),并取椭圆曲线上一点,作为基点G. 2.用户A选择一个私有密钥k,并生成公开密钥K=kG. 3.用户A将Ep(a,b ...
- RACLE 错误 12899 处理, oracle 11g 更改字符集
工作需要,安装装了oracle 11g,在导入其他机器上的备份数据的时间,发生一个错误: IMP-00019: 由于 ORACLE 错误 12899 而拒绝行IMP-00003: 遇到 ORACLE ...