1. Modify/frameworks/base/CORE/RES/values/strings. xml
Declare several variables here:
<! -- New sleep item -->
<String name = "global_action_sleep"> sleep </string>
<! -- Added the sleep string -->
<String name = "Sleep"> sleep </string>
<! -- Added confirmation screen sleep information -->
<String name = "sleep_confirm"> the machine screen will turn off. </string>
2. Modify/frameworks/base/CORE/Java/COM/Android/Internal/APP/shutdownthread. Java
Several packages to reference
Import Android. OS. systemclock;
Android. OS. powermanager;
// Add the screen standby Method
Public static void Gotosleep (context, long time ){
Context. enforcecallingorselfpermission (Android. manifest. Permission. device_power, null );
Final alertdialog dialog = new alertdialog. Builder (context)
. Seticon (Android. R. drawable. ic_dialog_alert)
. Settitle (COM. Android. Internal. R. String. Sleep)
. Setmessage (COM. Android. Internal. R. String. sleep_confirm)
. Setpositivebutton (COM. Android. Internal. R. String. Yes,
New dialoginterface. onclicklistener (){
Public void onclick
(Dialoginterface dialog, int which ){
Powermanager PM = (powermanager) mcontext. getsystemservice (context. power_service );
PM. Gotosleep (systemclock. uptimemillis ());
}
})
. Setnegativebutton (COM. Android. Internal. R. String. No, null)
. Create ();
Dialog. getwindow (). settype
(Windowmanager. layoutparams. type_keyguard_dialog );
Dialog. getwindow (). addflags
(Windowmanager. layoutparams. flag_blur_behind );
Dialog. Show ();
}
3. Modify/frameworks/policies/base/Mid/COM/Android/Internal/policy/impl/globalactions. Java
Find mitems = lists. newarraylist. The original code defines two singlepressactions, that is, the menu items of the power button.
Add a button for singlepressaction to implement screen sleep, following the original code
New singlepressaction (COM. Android. Internal. R. drawable. ic_lock_power_off,
R. String. global_action_sleep ){
Public void onpress (){
Shutdownthread. Gotosleep (mcontext, systemclock. uptimemillis ());
}
Public Boolean showduringkeyguard (){
Return true;
}
Public Boolean showbeforeprovisioning (){
Return true;
}
}
Modified and re-compiled, wait patiently, on the tablet of the android-x86 platform test can realize the computer sleep function
Note: Reprinted this blog please indicate http://blog.sina.com.cn/hylinblog