Add screenshot shortcuts to android4.0

Source: Internet
Author: User

The Samsung 7-inch tablet is 3. X system, a screenshot button is added to the status bar to get galaxy notes 10.1. This function cannot be deleted and added to the status bar. In this case, we added this button on our tablet today to implement simple and quick screenshot functions, instead of pressing power and vol.

  In the frameworks/base/packages/systemui/RES/drawable-mdpi/directory of android4.0 source code, the ic_sysbar_screenshot.png file is shown as follows:    The background of the image is a transparent PNG file.

 Next, modify the frameworks/base/packages/systemui/RES/layout-sw600dp/status_bar.xml file

    Android: layout_width = "80dip"  Android: layout_height = "match_parent"  Android: src = "@ drawable/ic_sysbar_screenshot"  Android: contentdescription = "@ string/accessibility_screenshot"  Systemui: glowbackground = "@ drawable/ic_sysbar_highlight"  />  Next, modify the frameworks/base/packages/systemui/RES/values/strings. xml file and add the following content:  Screenshot  So far, re-compile the source code, and there will be more screenshots on the status bar. Next, we need to continue to implement the screenshot function and check the source code in frameworks, found frameworks/base/policy/src/COM/Android/Internal/policy/impl/phonewindowmanager. the Java file contains reference parts, so you can continue to modify frameworks/base/packages/systemui/src/COM/Android/systemui/statusbar/tablet/tabletstatusbar. add the following content to the Java file:    Import Android. OS. Messenger; Import Android. content. componentname;  Import Android. content. serviceconnection;  Add the view mscreenshotbutton; statement after view mrecentbutton.  Add the following content to mrecentbutton. setonclicklistener (monclicklistener:    Mscreenshotbutton = mnavigationarea. findviewbyid (R. Id. my_screenshot );  Mscreenshotbutton. setonclicklistener (New View. onclicklistener (){  @ Override  Public void onclick (view v ){  Mhandler. postdelayed (mscreenshotchordlongpres S,  Viewconfiguration. getglobalactionkeytimeou T ());  }  });  Add the following content before public int getstatusbarheight:  Private Final runnable mscreenshotchordlongpres S = new runnable (){  Public void run (){  Takescreenshot ();  }  };
  Final object mscreenshotlock = new object ();  Serviceconnection mscreenshotconnection = NULL;
  Final runnable mscreenshottimeout = new runnable (){  @ Override public void run (){  Synchronized (mscreenshotlock ){  If (mscreenshotconnection! = NULL ){  Mcontext. unbindservice (mscreenshotconnection );  Mscreenshotconnection = NULL;  }  }  }  };
  // Assume this is called from the handler thread.  Private void takescreenshot (){  Synchronized (mscreenshotlock ){  If (mscreenshotconnection! = NULL ){  Return;    }  Componentname Cn = new componentname ("com. Android. systemui ",  "Com. Android. systemui. screenshot. takescreenshotservice ");  Intent intent = new intent ();  Intent. setcomponent (CN );  Serviceconnection conn = new serviceconnection (){  @ Override  Public void onserviceconnected (componentname name, ibinder Service ){  Synchronized (mscreenshotlock ){  If (mscreenshotconnection! = This ){  Return;  }  Messenger messenger = new messenger (service );  Message MSG = message. Obtain (null, 1 );  Final serviceconnection myconn = this;  Handler H = new handler (mhandler. getlooper ()){  @ Override  Public void handlemessage (Message MSG ){  Synchronized (mscreenshotlock ){  If (mscreenshotconnection = myconn ){  Mcontext. unbindservice (mscreenshotconnection );  Mscreenshotconnection = NULL;  Mhandler. removecallbacks (mscreenshottimeout );  }  }    }  };  MSG. replyto = new messenger (h );  MSG. arg1 = msg. arg2 = 0;  Try {  Messenger. Send (MSG );  } Catch (RemoteException e ){  }  }  }  @ Override  Public void onservicedisconnected (componentname name ){}  };  If (mcontext. bindservice (intent, Conn, context. bind_auto_create )){  Mscreenshotconnection = conn;  Mhandler. postdelayed (mscreenshottimeout, 10000 );  }  }  }  At this point, the source code is compiled and burned again, and the screenshot function is implemented. Currently, some icons are saved for processing, which is not described in this section.  When the screenshot function is implemented, since this function has been implemented on 4.0, you can directly find the source code to confirm where it is implemented and use it directly. Try to use it as much as possible, but you will not be out of school.

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.