位置: 编程技术 - 正文
推荐整理分享Android 4.1.2系统添加重启功能(android4.4.2升级包),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:android os 4.1,android 4.4.2,android 4.4,安卓4.1.2,android os 4.2,android 4.4,android 4.2.2,android os 4.1,内容如对您有帮助,希望把文章链接给更多的朋友!
转自: * Create the global actions dialog. * @return A new dialog. */private GlobalActionsDialog createDialog() { // Simple toggle style if there's no vibrator, otherwise use a tri-state if (!mHasVibrator) { mSilentModeAction = new SilentModeToggleAction(); } else { mSilentModeAction = new SilentModeTriStateAction(mContext, mAudioManager, mHandler); } mAirplaneModeOn = new ToggleAction( R.drawable.ic_lock_airplane_mode, R.drawable.ic_lock_airplane_mode_off, R.string.global_actions_toggle_airplane_mode, R.string.global_actions_airplane_mode_on_status, R.string.global_actions_airplane_mode_off_status) { void onToggle(boolean on) { if (mHasTelephony && Boolean.parseBoolean( SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) { mIsWaitingForEcmExit = true; // Launch ECM exit dialog Intent ecmDialogIntent = new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null); ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(ecmDialogIntent); } else { changeAirplaneModeSystemSetting(on); } } @Override protected void changeStateFromPress(boolean buttonOn) { if (!mHasTelephony) return; // In ECM mode airplane state cannot be changed if (!(Boolean.parseBoolean( SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) { mState = buttonOn ? State.TurningOn : State.TurningOff; mAirplaneState = mState; } } public boolean showDuringKeyguard() { return true; } public boolean showBeforeProvisioning() { return false; } }; onAirplaneModeChanged(); mItems = new ArrayList<Action>(); // first: power off mItems.add( new SinglePressAction( com.android.internal.R.drawable.ic_lock_power_off, R.string.global_action_power_off) { public void onPress() { // shutdown by making sure radio and power are handled accordingly. mWindowManagerFuncs.shutdown(true); } public boolean onLongPress() { mWindowManagerFuncs.rebootSafeMode(true); return true; } public boolean showDuringKeyguard() { return true; } public boolean showBeforeProvisioning() { return true; } });我们可以看到mItems.add函数是添加一个选项,该菜单的第一个选项就是关机选项,我们可以在此之后添加重启选项,代码如下:mItems.add( new SinglePressAction( com.android.internal.R.drawable.ic_lock_power_off, R.string.global_action_reboot) { public void onPress() { // reboot mWindowManagerFuncs.reboot(); } public boolean showDuringKeyguard() { return true; } public boolean showBeforeProvisioning() { return true; } });上面的代码中使用了mWindowManagerFuncs.reboot函数和R.string.global_action_reboot资源,因此我们需要该资源并实现reboot函数。首先在frameworks/base/core/java/android/view/WindowManagerPolicy.java中添加reboot接口:/** * Interface for calling back in to the window manager that is private * between it and the policy. */public interface WindowManagerFuncs { ... /** * Switch the keyboard layout for the given device. * Direction should be 1 or -1 to go to the next or previous keyboard layout. */ public void switchKeyboardLayout(int deviceId, int direction); public void shutdown(); public void reboot(); public void rebootSafeMode();}然后在frameworks/base/services/java/com/android/server/wm/WindowManagerService.java中实现该接口:// Called by window manager policy. Not exposed externally.@Overridepublic void shutdown() { ShutdownThread.shutdown(mContext, true);}// Called by window manager policy. Not exposed externally.@Overridepublic void reboot() { ShutdownThread.reboot(mContext, null, true);}// Called by window manager policy. Not exposed externally. @Overridepublic void rebootSafeMode() { ShutdownThread.rebootSafeMode(mContext, true);}接下来,为了在按下重启选项之后,能出现”重启“之类的提示,还需要修改frameworks/base/services/java/com/android/server/pm/ShutdownThread.java中的shutdownInner函数和beginShutdownSequence函数:static void shutdownInner(final Context context, boolean confirm) { // ensure that only one thread is trying to power down. // any additional calls are just returned synchronized (sIsStartedGuard) { if (sIsStarted) { Log.d(TAG, "Request to shutdown already running, returning."); return; } } final int longPressBehavior = context.getResources().getInteger( com.android.internal.R.integer.config_longPressOnPowerBehavior); final int resourceId = mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_confirm : (longPressBehavior == 2 ? com.android.internal.R.string.shutdown_confirm_question : (mReboot ? com.android.internal.R.string.reboot_confirm : com.android.internal.R.string.shutdown_confirm)); Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" longPressBehavior); if (confirm) { final CloseDialogReceiver closer = new CloseDialogReceiver(context); final AlertDialog dialog = new AlertDialog.Builder(context) .setTitle(mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_title : (mReboot ? com.android.internal.R.string.reboot : com.android.internal.R.string.power_off)) .setMessage(resourceId) .setPositiveButton(com.android.internal.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { beginShutdownSequence(context); } }) .setNegativeButton(com.android.internal.R.string.no, null) .create(); closer.dialog = dialog; dialog.setOnDismissListener(closer); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); dialog.show(); } else { beginShutdownSequence(context); }}private static void beginShutdownSequence(Context context) { synchronized (sIsStartedGuard) { if (sIsStarted) { Log.d(TAG, "Shutdown sequence already running, returning."); return; } sIsStarted = true; } // throw up an indeterminate system dialog to indicate radio is // shutting down. ProgressDialog pd = new ProgressDialog(context); pd.setTitle(context.getText(com.android.internal.R.string.power_off)); pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress)); pd.setIndeterminate(true); pd.setCancelable(false); pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); pd.show(); sInstance.mContext = context; sInstance.mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); // make sure we never fall asleep again sInstance.mCpuWakeLock = null; try { sInstance.mCpuWakeLock = sInstance.mPowerManager.newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, TAG "-cpu"); sInstance.mCpuWakeLock.setReferenceCounted(false); sInstance.mCpuWakeLock.acquire(); } catch (SecurityException e) { Log.w(TAG, "No permission to acquire wake lock", e); sInstance.mCpuWakeLock = null; } // also make sure the screen stays on for better user experience sInstance.mScreenWakeLock = null; if (sInstance.mPowerManager.isScreenOn()) { try { sInstance.mScreenWakeLock = sInstance.mPowerManager.newWakeLock( PowerManager.FULL_WAKE_LOCK, TAG "-screen"); sInstance.mScreenWakeLock.setReferenceCounted(false); sInstance.mScreenWakeLock.acquire(); } catch (SecurityException e) { Log.w(TAG, "No permission to acquire wake lock", e); sInstance.mScreenWakeLock = null; } } // start the thread that initiates shutdown sInstance.mHandler = new Handler() { }; sInstance.start();}至此关于代码部分的改动全部完成,接下来就需要添加使用到的资源了,就是前面用到的字符串。首先需要在frameworks/base/core/res/res/values/strings.xml中添加一下字符串:<string name="reboot">Reboot</string><string name="reboot_progress">Rebootu</string><string name="reboot_confirm" product="tablet">Your tablet will reboot.</string><string name="reboot_confirm" product="default">Your phone will reboot.</string><!-- label for item that reboot in phone options dialog --><string name="global_action_reboot">Reboot</string>而后需要在frameworks/base/core/res/res/values/public.xml中声明这些资源,否则编译的时候会出现找不到该资源的错误。<java-symbol type="string" name="reboot" /><java-symbol type="string" name="reboot_confirm" /><java-symbol type="string" name="reboot_progress" /><java-symbol type="string" name="global_action_reboot" />至此,全部修改完成,编译烧写即可。
Android设计模式之单例模式 Singleton 一.概述单例模式是设计模式中最简单的一种,但是它没有设计模式中的那种各种对象之间的抽象关系,所以有人不认为它是一种模式,而是一种实现技巧.单
Android ListViewitem滑动出现删除按钮 我自己一个人弄的公司的产品客户端,所以还是想记录下来以免忘记或者丢失...在我的上一篇博文(点击打开链接)是一个文件管理的东西,基础组件也是
Android 4.1.2为通知栏添加wifi开关 摘自:
标签: android4.4.2升级包
本文链接地址:https://www.jiuchutong.com/biancheng/379574.html 转载请保留说明!友情链接: 武汉网站建设