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 (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.HeimiDialog;

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.HeimiDialog.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.heimi.ota.MainActivity”;

private static boolean fromService = false;
private static boolean forceUpdate = false;
private String vers;

private SharedPreferences sp;
HeimiDialog 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) {
//此处实现了数据的存储,如果是同样的提示数据,则弹窗不再弹出,每次从广播中获取的数据字段都会和已存的文件中数据做比较。
    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为一标准的dialog,包含于开篇的android.app.HeimiDialog中
    HeimiDialog.Builder b = new HeimiDialog.Builder(mContext);
    HeimiDialog 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.heimi.ota",
            "com.heimi.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

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

Android4.4 SystemUI添加提示弹窗的相关文章

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

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

PHP+JS的信息提示弹窗

基于PHP函数的Msg信息提示框 1.可以设置弹出信息,跳转地址,跳转的时间,跳转的信息标题提示: 2.代码实例: <?php function ShowMsg($msg, $gourl,$title='',$onlymsg=0, $limittime=0 ) { if(empty($GLOBALS['cfg_plus_dir'])) $GLOBALS['cfg_plus_dir'] = '..'; $htmlhead = "<html>\r\n<head>\r\n

【锋利的JQuery-学习笔记】添加提示图片

效果图: hot图片: (注意:这个图标本身就有抖动效果的,并不是由于标签<del>而具有抖动效果) 周期性抖动,起到提示的作用 html: <div class="jnCatainfo"> <h3>推荐品牌</h3> <ul> <li><a href="#nogo" >耐克</a></li> <li><a href="#nogo&

在ubuntu12.04下编译android4.1.2添加JNI层出现问题

tiny4412学习者,在ubuntu12.04下编译android4.1.2添加JNI层出现问题: (虚心请教解决方法) trouble writing output: Too many methods: 65540; max is 65536. By package: 26 android 145 android.accessibilityservice 702 android.accounts 436 android.animation 8 android.annotation 3793

Struts2框架中书写XML配置文件时能添加提示技巧(方案二)

1.  先在/工程名/WebRoot/WEB-INF/lib/struts2-core-2.1.8.jar中找到struts-2.1.dtd文件. 2.  在Myeclipse8.6-->Window-->Preferences 3.  在搜索框输入xml文件,找到XMLCatalog,单击XML Catalog出现如上页面,之后单击Add按钮,出现如下图: 4.  在Location中选择FileSystem,选择struts-2.1.dtd文件的位置,如果这个文件在工程里面,可以使用Wor

iOS消息通知 小红点&amp;自定义小红点&amp;应用图标添加提示

//添加消息通知 小红点iOS自带 NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items; UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:2]; personCenterTabBarItem.badgeValue = @"1"; //自定义方法(还需完善) UIImageView *dotImage

项目--给项目添加提示声音

1.使用系统内自带的声音 System.Media.SystemSounds.Beep.Play(); System.Media.SystemSounds.Asterisk.Play(); System.Media.SystemSounds.Exclamation.Play(); System.Media.SystemSounds.Hand.Play(); System.Media.SystemSounds.Question.Play(); 2.使用自定义的声音(非循环播放=== 播放一次;相对

Android - ScrollView添加提示Arrow(箭头)

ScrollView添加提示Arrow(箭头) 本文地址:http://blog.csdn.net/caroline_wendy 在ScrollView的滑动功能中,需要给用户提示,可以滑动,可以添加两个箭头. 定制ScrollView,创建监听器IScrollStateListener接口: private IScrollStateListener scrollStateListener; public void setScrollStateListener(IScrollStateListe