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的使用,弹窗经常被使用在一些表单的增删改查啊,或者弹出一些提示信息等等,在保留当前页面状态的情况下,告知用户并承载相关 ...
随机推荐
- Linux基础系列-Day1
Linux发展简史 Unix:1969年由美国电话电报公司(AT&T)贝尔实验室的两个工程师所创造的操作系统,它允许计算机同时处理多用户和程序. BSD:重要的Unix分支,1977年由加州大 ...
- poj 1127(直线相交+并查集)
Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...
- 2016ACM-ICPC网络赛北京赛区 1001 (trie树牌大模拟)
[题目传送门] 1383 : The Book List 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The history of Peking University ...
- [2018湖南省队集训] 6.24 T1 marshland
题面在这里! 一开始感觉像一个类似二分图的最小割,于是成功跑偏2333333 很容易发现一个关键性质,'L'的两个角落在的偶数格 的行(或者列)的奇偶性一定不同.... 于是我们再把偶数格按照行(或者 ...
- 【枚举】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem G. Equation
f(n)定义为n的十进制表示下所有位的平方和. 问你方程K*f(n)=n在a<=n<=b中的解的个数. 发现f(n)最大不超过2000,可以直接枚举f(n),然后判断K*f(n)的位的平方 ...
- GCDAsyncSocket类库,IOS下TCP通讯使用心得
关于在IOS下使用Socket进行通讯的技术文章也许诺很久了,今日又是一个还债的日子,网上虽然很多介绍过AsyncSocket或GCDAsyncSocket的文章,但其实就那么一两篇大部分都是转载,于 ...
- php的json_encode()之后float类型丢失精度
在后台php中,金额保留两位小数.但是前端显示精度丢失,出现了14位小数的奇怪现象.本来以为是前端js解析之后出现的问题.检查之后发现json_encode()之后就出现了. 原始的值: array( ...
- Problem F: 程序填充(函数、指针):去数组负数
#include <stdio.h> void f(int *a,int *m) { int i,j; ;i < *m;i++) ) { ;j++) a[j]=a[j+]; (*m) ...
- ES6 标签模板
标签模板其实不是模板,而是函数调用的一种特殊形式."标签"指的是函数,紧跟在后面的模板字符串就是它的参数. var a = 5; var b = 10; tag `Hello ${ ...
- mysql知识点汇总四
1.表的垂直分割 “垂直分割”是一种把数据库中的表按列变成几张表的方法,这样可以降低表的复杂度和字段的数目,从而达到优化的目的.(以前,在银行做过项目,见过一张表有100多个字段,很恐怖) 示例一:在 ...