How to add a Hibernate feature to the Android Tablet power button Menu

Source: Internet
Author: User
Tags sleep

1. Modify/frameworks/base/core/res/res/values/strings.xml

Declare several variables here:

<!--New screen-sleeping item-->

<string name= "Global_action_sleep" >Sleep</string>

<!--add a sleep string-->

<string name= "Sleep" >Sleep</string>

<!--new Confirmation screen hibernate information-->

<string name= "sleep_confirm" >the machine screen would turn off.</string>

2. Modify/frameworks/base/core/java/com/android/internal/app/shutdownthread.java

To refer to a few packages

Import Android.os.SystemClock;  
Android.os.PowerManager; Add screen standby method public static void Gotosleep (context Context,long time) {context.enforcecallingorselfpermission Droid.  
      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.interna  
                                   l.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_ser  
                                           VICE);  
                               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 (); }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

3. Modify/frameworks/policies/base/mid/com/android/internal/policy/impl/globalactions.java

Find Mitems = lists.newarraylist, the original code defines two singlepressaction, that is, the Power button menu item, then in the inside

Add a Singlepressaction button that implements the screen hibernate function, imitating 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;  
                 }  
                       
                }

After the revision, the patient waits, in the Android-x86 platform's tablet computer test can realize the computer the hibernation function

NOTE: Reprint this blog please specify 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.