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,

};

至此。加入完成。。

时间: 2024-08-05 01:59:45

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

Android4.4 SystemUI添加提示弹窗

此弹窗为开机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 (

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 (t

jQuery的dialog弹窗实现

jQuery实现dialog弹窗: html代码如下: <input type="button" onclick="performances();" value="分配" style="background:#18a689 none repeat scroll 0 0;border:1px solid #18a689;color:#FFF;text-shadow:0px -1px 1px #1c6a9e;height:30px;w

Android4.4 SystemUI分析之PowerUI

以下分析是基于MTK Android4.4原生的SystemUI与Google 的SystemUI有微小的区别,但两者的整体框架是差不多的. 这一篇是分析SystemUI的第一篇,先从最简单的PowerUI着手,源码路径:/frameworks/base/packages/SystemUI  程序目录结构如下: 我导入Eclipse编辑,报错的原因是因为找不到Framework上的一些包和资源,这个没有关系:修改完后在使用mmm模块编译,再push到手机(eng版本)上进行调试,push后需要重

Android4.4 SystemUI分析之Clock时钟显示

SystemUI上的时间显示只要就在/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java类上 效果图 这个类也很简单,监听处理广播 @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); if (!mAttached) { mAttached = true; IntentFilte

easyUI dialog 弹窗 居中显示

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

Android编程入门--底部Dialog弹窗

参考博客:Android实现底部对话框BottomDialog dialog_bottom <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layo

Android4.4 SystemUI分析之DessertCase

在SystemUI中有一个Activity可以显示所有的Logo 这个Activity涉及到的图标存放在SystemUI/res/drawable-nodpi目录下 在这里我自己写了个小的测试程序,把相关的文件拿出来 DessertCase.java.DessertCaseDream.java.DessertCaseView.java,只要是在DessertCaseView这个View中动态改变图标的位置 只要在测试程序中启动DessertCase.java就可以了 Intent intent

非自定义和自定义Dialog的介绍!!!

一.非自定义Dialog的几种形式介绍 转自:http://www.kwstu.com/ArticleView/kwstu_20139682354515 前言 对话框对于应用也是必不可少的一个组件,在Android中也不例外,对话框对于一些提示重要信息,或者一些需要用户额外交互的一些内容很有帮 助.本篇博客就讲解一下Android下对话框的使用,在本篇博客中,将了解到对话框的一些常规属性的设置,以及各式的对话框的使用,并都会提供小 Demo来展示所有的效果. Dialog Dialog,对话框,