MTK6577+Android4.0之增加重启功能
MTK6577+Android4.0之增加重啟功能
?
長按power按鍵,彈出下圖:
圖1
這里要實現增加Reboot的功能,下面記下要實現所做的修改。
1.?????在長按power按鍵彈出的界面增加Reboot界面
?
首先關機的那個彈出菜單是在
frameworks/base/policy/src/com/android/internal/policy/impl/GlobalActions.java這個文件中的private AlertDialog createDialog(),如下:
? ?
/*** Create the global actions dialog.* @return A new dialog.*/private AlertDialog createDialog() {mSilentModeAction = newSilentModeAction(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 (Boolean.parseBoolean(SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))){mIsWaitingForEcmExit =true;// Launch ECM exit dialogIntent ecmDialogIntent =new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,null);ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);mContext.startActivity(ecmDialogIntent);} else {changeAirplaneModeSystemSetting(on);}}@Overrideprotected voidchangeStateFromPress(boolean buttonOn) {// In ECM mode airplane statecannot be changedif (!(Boolean.parseBoolean(SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {mState = buttonOn ?State.TurningOn : State.TurningOff;mAirplaneState = mState;}}public boolean showDuringKeyguard(){return true;}public booleanshowBeforeProvisioning() {return false;}//M{public boolean isEnabled() {if(KeyguardUpdateMonitor.dual_sim_setting == 0){Log.e(TAG, "if userunselect the dual sim mode setting on phone starting, the airplane mode can notbe set.");return false; //if user hasnot yet selected any item in the dual_sim_mode_setting dialog on phonestarting, the airplane mode should be disabled.}else {returnsuper.isEnabled();}}//}M};mItems = new ArrayList<Action>();// first: power offmItems.add(new SinglePressAction(com.android.internal.R.drawable.ic_lock_power_off,R.string.global_action_power_off) {public void onPress() {// shutdown by making sureradio and power are handled accordingly.ShutdownThread.shutdown(mContext, true);}public booleanshowDuringKeyguard() {return true;}public booleanshowBeforeProvisioning() {return true;}});// next: airplane modemItems.add(mAirplaneModeOn);// last: silent modeif (SHOW_SILENT_TOGGLE) {mItems.add(mSilentModeAction);}mAdapter = new MyAdapter();final AlertDialog.Builder ab = newAlertDialog.Builder(mContext);ab.setAdapter(mAdapter, this).setInverseBackgroundForced(true);final AlertDialog dialog = ab.create();dialog.getListView().setItemsCanFocus(true);dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);dialog.setOnDismissListener(this);return dialog; }上面的代碼在// first: power off和// next: airplane mode之間增加了reboot部分,代碼如下:
// second:reboot,kandi add at 2015.01.21mItems.add(new SinglePressAction(com.android.internal.R.drawable.ic_lock_reboot,R.string.global_action_reboot) {public void onPress() {// shutdown by making sureradio and power are handled accordingly.ShutdownThread.reboot(mContext,null, true);}public booleanshowDuringKeyguard() {return true;}public booleanshowBeforeProvisioning() {return true;}});此代碼主要闡述下面幾點:
(1)??增加字符串global_action_reboot和圖片資源ic_lock_reboot,這些的定義在后面描述。
(2)??ShutdownThread.reboot(mContext,null, true)此函數是調用
/*** Request a clean shutdown, waiting forsubsystems to clean up their* state etc. Must be called from a Looper thread in whichits UI* is shown.** @param context Context used to displaythe shutdown progress dialog.* @param reason code to pass to the kernel(e.g. "recovery"), or null.* @param confirm true if user confirmationis needed before shutting down.*/public static void reboot(final Contextcontext, String reason, boolean confirm) {mReboot = true;mRebootReason = reason;shutdown(context, confirm); }reason 如果值為是null,正常重啟;如果是recovery,系統重啟進入recovery mode
confirm true顯示關機提示框,需要用戶;false不顯示提示框,直接關機。
2.?????增加點擊Reboot后的重啟
為了在按下重啟選項之后,能出現”重啟“之類的提示,還需要修改\frameworks\base\core\java\com\android\internal\app\ ShutdownThread.java中的shutdown函數和beginShutdownSequence函數:
?
(1)??shutdown函數
修改之前 final intresourceId = longPressBehavior == 2? com.android.internal.R.string.shutdown_confirm_question : com.android.internal.R.string.shutdown_confirm; 修改之后 final intresourceId = 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);(2)??beginShutdownSequence函數
修改之前: pd.setTitle(context.getText(com.android.internal.R.string.power_off)); pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));修改之后: if(mReboot){pd.setTitle(context.getText(com.android.internal.R.string.global_action_reboot));pd.setMessage(context.getText(com.android.internal.R.string.reboot_progress));}else{pd.setTitle(context.getText(com.android.internal.R.string.power_off));pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));}3.?????增加字符串和圖片資源
?
(1)??增加字符串
在frameworks/base/core/res/res/values/strings.xml中添加一下字符串:
<stringname="reboot_progress">Reboot...\u2026</string> <stringname="reboot_confirm" product="default">Your phone willReboot.</string> <stringname="reboot_confirm" product="default">Your phone willReboot.</string> <stringname="global_action_reboot">Reboot</string> <stringname="reboot">Reboot2</string>在\frameworks\base\core\res\res\values\public.xml增加以下字符串
<publictype="drawable" name="ic_menu_sort_by_size"id="0x0108009d" />//已有 <publictype="drawable" name="ic_lock_reboot"id="0x0108009e" />//增加(2)??增加重啟的圖片資源
把ic_lock_reboot.png拷貝到\frameworks\base\core\res\res\drawable-hdpi目錄下
?
4.?????編譯及升級
./mk r dr,然后單獨升級system.img
轉載于:https://www.cnblogs.com/LoongEmbedded/p/5298300.html
總結
以上是生活随笔為你收集整理的MTK6577+Android4.0之增加重启功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css强制一行显示超出的部分显示点点点
- 下一篇: MTK6577+Android烧录