Android screenshot and WindowManager display

Source: Internet
Author: User

  • Android screen.

  • The screenshot is displayed on the screen in real time. The user clicks the image -- disappears; the user does not click it. After the specified time, the image disappears automatically.

Perceptual knowledge:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/06453V521-0.gif "title =" MOV_0141_clip.gif "/>

For more information, see notes:

@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. about_me: // obtain the screen View targetView = mActivity. getWindow (). getDecorView (); targetView. setSystemUiVisibility (View. SYSTEM_UI_FLAG_FULLSCREEN); // capture the full screen targetView. setDrawingCacheEnabled (true); Bitmap fullBitmap = Bitmap. createBitmap (targetView. getDrawingCache ();/** get the status bar height Rect frame = new Rect (); mActivity. getWindow (). getDecorView (). ge TWindowVisibleDisplayFrame (frame); int statusBarHeight = frame. top; */DisplayMetrics dm = mActivity. getResources (). getDisplayMetrics ();/** remove the title bar Bitmap bitmap = Bitmap. createBitmap (fullBitmap, 0, statusBarHeight, dm. widthPixels, dm. heightPixels-statusBarHeight); targetView. destroyDrawingCache (); */OutputStream output = null; try {if (Environment. getExternalStorageState (). equals (Environment. MED IA_MOUNTED) {String sdPath = Environment. getExternalStorageDirectory (). getPath (); // SD card path String pngPath = sdPath + "/Remind/"; // storage path File pngDir = new File (pngPath); if (! PngDir. exists () {pngDir. mkdir (); // make path} String pngName = pngPath + System. currentTimeMillis () + ". png "; output = new FileOutputStream (pngName); if (output! = Null) {fullBitmap. compress (Bitmap. compressFormat. PNG, 100, output); // 100% HD large image output. flush (); output. close ();}/** WindowManager */LayoutInflater inflater = LayoutInflater. from (mActivity); screenShot = inflater. inflate (R. layout. screen_shot, null); wmManager = (WindowManager) mActivity. getSystemService (mActivity. WINDOW_SERVICE); WindowManager. layoutParams wmParams = new WindowManager. layoutParam S (); ImageView shotImg = (ImageView) screenShot. findViewById (R. id. screen_shot_img); shotImg. setImageBitmap (targetView. getDrawingCache ();/*** The following are WindowManager. layoutParams attributes */wmParams. type = WindowManager. layoutParams. TYPE_PRIORITY_PHONE; // here is the key wmParams. format = PixelFormat. RGBA_8888; wmParams. flags = WindowManager. layoutParams. FLAG_NOT_FOCUSABLE | WindowManager. layoutParams. FLAG_NOT_TOUCH_MODA L; wmParams. alpha = 0.8f; // transparency // WindowManager position wmParams. width = dm. widthPixels * 1/2; wmParams. height = dm. heightPixels * 1/2; wmParams. x = dm. widthPixels * 1/2; wmParams. y =-(dm. heightPixels * 1/5); // Add View wmManager. addView (screenShot, wmParams); isRemoved = false; // timer Timer = new timer (); // click the image to disappear. ShotImg. setOnClickListener (new OnClickListener () {@ Override public void onClick (View arg0) {if (wmManager! = Null &&! IsRemoved) {wmManager. removeView (screenShot); isRemoved = true; if (timer! = Null) {timer. cancel () ;}}}); // scheduled task, automatically disappears 3 seconds later. Timer. schedule (new TimerTask () {@ Override public void run () {if (wmManager! = Null &&! IsRemoved) {wmManager. removeView (screenShot); isRemoved = true ;}}, 3000) ;}} catch (Exception e) {e. printStackTrace ();} break; default: break ;}}



This article from the "wIsper technology into art" blog, please be sure to keep this source http://lichen.blog.51cto.com/697816/1218567

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.