In Android system, pressing the Power key long will pop up a dialog box to select functions such as "Flight Mode", "Mute", "Shutdown" and other functions. These features are very suitable for mobile phones, but there is no need for set-top box products.
This article briefly introduces how to customize the shutdown interface.
My goal is to hold down the Power key and the power will shut down, and the "Device Will Turn Off" selection dialog box will pop up. If you can select "Yes" to shut down, and "No" return to the system.
The code that pops up the dialog box is located at:
frameworks\policies\base\phone\com\android\internal\policy\impl\
The code that displays the dialog box is as follows:
Java code:
Runnable mPowerLongPress = new Runnable() {
public void run() {
mShouldTurnOffOnKeyUp = false;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); showGlobalActionsDialog();
}
};
Calling the showGlobalActionsDialog method will display the above-mentioned dialog box showing "Flight Mode", "Mute", "Shutdown", and options.
Because my goal is not to do with this program, just comment out this line of code and replace it with shutdown code. So where is the shutdown code? This code is located at:
frameworks\policies\base\phone\com\android\internal\policy\impl\in the createDialog method of this file, there is the following code:
Java code:
mItems = (
// SilentModeToggle,
// mAirplaneModeOn in aircraft mode,
// last: power off new SinglePressAction( .ic_lock_power_off, .global_action_power_off) {
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
(mContext, true);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true
}
});
From the code, we can see that if the "Shutdown" option of the above dialog box is selected, the shutdown method of ShutdownThread will be called to shut down. The second parameter of the shutdown method identifies whether a query dialog box pops up.
The code we can modify, the final code is as follows:
Java code:
Runnable mPowerLongPress = new Runnable() {
public void run() {
mShouldTurnOffOnKeyUp = false;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
//showGlobalActionsDialog();
(mContext, false);
}
};
This article briefly introduces how to customize the shutdown interface.
My goal is to hold down the Power key and the power will shut down, and the "Device Will Turn Off" selection dialog box will pop up. If you can select "Yes" to shut down, and "No" return to the system.
The code that pops up the dialog box is located at:
frameworks\policies\base\phone\com\android\internal\policy\impl\
The code that displays the dialog box is as follows:
Copy the codeThe code is as follows:
Java code:
Runnable mPowerLongPress = new Runnable() {
public void run() {
mShouldTurnOffOnKeyUp = false;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); showGlobalActionsDialog();
}
};
Calling the showGlobalActionsDialog method will display the above-mentioned dialog box showing "Flight Mode", "Mute", "Shutdown", and options.
Because my goal is not to do with this program, just comment out this line of code and replace it with shutdown code. So where is the shutdown code? This code is located at:
frameworks\policies\base\phone\com\android\internal\policy\impl\in the createDialog method of this file, there is the following code:
Copy the codeThe code is as follows:
Java code:
mItems = (
// SilentModeToggle,
// mAirplaneModeOn in aircraft mode,
// last: power off new SinglePressAction( .ic_lock_power_off, .global_action_power_off) {
public void onPress() {
// shutdown by making sure radio and power are handled accordingly.
(mContext, true);
}
public boolean showDuringKeyguard() {
return true;
}
public boolean showBeforeProvisioning() {
return true
}
});
From the code, we can see that if the "Shutdown" option of the above dialog box is selected, the shutdown method of ShutdownThread will be called to shut down. The second parameter of the shutdown method identifies whether a query dialog box pops up.
The code we can modify, the final code is as follows:
Copy the codeThe code is as follows:
Java code:
Runnable mPowerLongPress = new Runnable() {
public void run() {
mShouldTurnOffOnKeyUp = false;
performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
//showGlobalActionsDialog();
(mContext, false);
}
};