編輯:關於Android編程
Android5.0 長按電源鍵關機沒有彈確定對話框直接關機,但用戶點擊了關機選項之後,應該彈一個確定對話框給用戶提示是否真的進入關機模式。
首先在frameworks層將對話框的標志位打開。
frameworks\base\policy\src\com\android\internal\policy\impl\GlobalActions.java
@Override public void onPress() { final boolean quickbootEnabled = Settings.System.getInt( mContext.getContentResolver(), "enable_quickboot", 0) == 1; // go to quickboot mode if enabled if (quickbootEnabled) { startQuickBoot(); return; } // shutdown by making sure radio and power are handled accordingly. mWindowManagerFuncs.shutdown(true /* confirm */);//20150423 show the power-off dialog }
frameworks\base\services\core\java\com\android\server\power\ShutdownThread.java
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; } } boolean showRebootOption = false; String[] defaultActions = context.getResources().getStringArray( com.android.internal.R.array.config_globalActionsList); for (int i = 0; i < defaultActions.length; i++) { if (defaultActions[i].equals("reboot") && mReboot) {// if (defaultActions[i].equals("reboot")) {20150421 for power_off dialog showRebootOption = true; break; } } final int longPressBehavior = context.getResources().getInteger( com.android.internal.R.integer.config_longPressOnPowerBehavior); int resourceId = mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_confirm : (longPressBehavior == 2 ? com.android.internal.R.string.shutdown_confirm_question : com.android.internal.R.string.shutdown_confirm); if (showRebootOption && !mRebootSafeMode) { resourceId = com.android.internal.R.string.reboot_confirm; } Log.d(TAG, "Notifying thread to start shutdown longPressBehavior=" + longPressBehavior); if (confirm) { final CloseDialogReceiver closer = new CloseDialogReceiver(context); if (sConfirmDialog != null) { sConfirmDialog.dismiss(); } sConfirmDialog = new AlertDialog.Builder(context) .setTitle(mRebootSafeMode ? com.android.internal.R.string.reboot_safemode_title : showRebootOption ? com.android.internal.R.string.reboot_title : 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 = sConfirmDialog; sConfirmDialog.setOnDismissListener(closer); sConfirmDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); sConfirmDialog.show(); } else { beginShutdownSequence(context); } }
效果圖知識點分析效果圖來看不復雜內容並沒多少,值得介紹一下的知識點也就下面幾個吧- 列表標題懸停- 左右列表滑動時聯動- 添加商品時的拋物線動畫- 底部彈出購物車清單-
首先,我們要知道什麼是數據持久化。數據持久化就是指那些內存中的瞬時數據保存到存儲設備中,保證即使手機在關機的情況下,這些數據不會丟失。保存在內存中的數據是處於瞬時狀態,保
概述關於Retrofit,Rxjava,MVP等的使用現在已經成為了Android項目開發的標配,而Clean架構都能很好的兼顧這些方面,使得代碼結構清晰,而且在一般在項
先看演示: 一個Handler允許你發送和處理消息(Message)以及與一個線程的消息隊列相關的Runnable對象。每個Handler實例都和單個線程以及該線程的消息