Android4.4 SystemUI添加Dialog弹窗

此弹窗为开机SystemUI的显示弹窗:

/** 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** ** 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 ====");

你在雨中行走,你从不打伞,你有自己的天空,它从不下雨。

Android4.4 SystemUI添加Dialog弹窗

相关文章:

你感兴趣的文章:

标签云: