How to add the sleep function to the power menu of the Android tablet

Source: Internet
Author: User
Tags sleep function

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.