Android Studio-47th phase frosted glass effects and dynamic generation of QR codes and increased click-to-hot zones

Source: Internet
Author: User

Recently back to see the code, some custom view writing is very good, the following package out, I hope to help you:

1. Frosted Glass Effect: bitmaputils

package com.example.p030_popbgqcode.utils;import android.content.context;import  android.graphics.bitmap;import android.renderscript.allocation;import android.renderscript.element; Import android.renderscript.renderscript;import android.renderscript.scriptintrinsicblur;import  android.view.View;public class BitmapUtils {    /**      *      *  @param  view     * @ return     */    public static bitmap  Takescreenshot (View view)  {         View.setdrawingcacheenabled (True);         view.builddrawingcache (True) ;         bitmap res = bitmap.createbitmap ( View.getdrawingcache ());         view.setdRawingcacheenabled (False);        return res;     }    /**     *  Blur      *  @param  context     *  @param  src     * @ Return     */    public static bitmap blur (Context  CONTEXT, BITMAP SRC)  {        bitmap out  = bitmap.createbitmap (SRC);        //  Creating Renderscript Kernel Objects         RenderScript script =  Renderscript.create (context);        //  Creates a blur effect of the Renderscript tool object         scriptintrinsicblur blur =  scriptintrinsicblur.create (Script, element.u8_4 (script);        //  because Renderscript does not use VMS to allocate memory, So you need to use the allocation class to create and allocate memory space.         //  create allocation objects when the memory is empty, you need to use CopyTo () to fill in the data.         allocation inallo = allocation.createfrombitmap (SCRIPT, SRC);        allocation outallo =  Allocation.createfrombitmap (script, out);        //  Sets the degree of blur for rendering,  25f is the maximum blur         blur.setradius (25f);         //  set input memory for Blurscript objects          blur.setinput (Inallo);        //  save output data to output memory          blur.foreach (Outallo);         //   Populating data into allocation    &NBsp;    outallo.copyto (out);        return  out;    }}

Popwindows How to use:

Bitmap shot = Bitmaputils.takescreenshot (Activity.getwindow (). Getdecorview ()); Bitmap blur = Bitmaputils.blur (activity, shot);

2. Dynamically generate two-dimensional code: Qrcodeutil

package com.example.p030_popbgqcode.utils;import android.graphics.bitmap;import  android.widget.imageview;import com.google.zxing.barcodeformat;import  com.google.zxing.encodehinttype;import com.google.zxing.writerexception;import  com.google.zxing.common.bitmatrix;import com.google.zxing.qrcode.qrcodewriter;import  java.util.hashtable;public class qrcodeutil {    private static  int image_halfwidth = 50;//width value, which affects the middle picture size     private static final  int DEFAULT_SIZE = 500;    /**     *  Generate QR code, default size is 500*500     *     *  @param  text  Need to generate two-dimensional code text, URLs, etc.      *  @return  bitmap     */     public static void createqrcode (imageview iv, string  text)  {        createqrcode (iv, text, default_size);     }    /**     *  generate QR Code       *     *  @param  text  need to generate two-dimensional code text, URLs, etc.       *  @param  size  need to generate two-dimensional code size ()      *  @return  bitmap      */    public static void createqrcode (final  imageview iv, final string text, final int size)  {         new thread ()  {              @Override              Public void run ()  {                 super.run ();                 try {                      Hashtable<EncodeHintType, String> hints = new Hashtable<> ();                      hints.put (encodehinttype.character_set,  "Utf-8");                     bitmatrix bitmatrix =  new qrcodewriter (). Encode (text,                              barcodeformat.qr_code, size, size, hints);                     int[] pixels = new int[size * size];                      for  (int y = 0; y < size; y++)  {                          for  (int x = 0; x < size; x++)  {                              if  (Bitmatrix.get (x, y))  {                       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PIXELS[Y&NBSP;*&NBSP;SIZE&NBSP;+&NBSP;X]  = 0xff000000;                             } else {                                  pixels[y * size + x] =  0xffffffff;                             }                         }                      }                     sleep (500);                     final bitmap bitmap = bitmap.createbitmap (size, size,                              bitmap.config.argb_8888);                     bitmap.setpixels (Pixels, 0,  size, 0, 0, size, size);                     iv.post (new runnable ()  {                           @Override                  &nBsp;       public void run ()  {                              if  (iv != null)  {                                  iv.setimagebitmap (bitmap);                              }                         }                     });                 } catch  (writerexception e)  {                      E.printstacktrace ();                     toastutil.showtoastshort ("Creat code err");                 } catch  ( Interruptedexception e)  {                     toastutil.showtoastshort ("Creat code err");                      e.printstacktrace ();                 }            }        }.start ();     }}

How to use:

Qrcodeutil.createqrcode (PC_IV1, str, 300);

3. Increase the hot-click zone: Expandviewrectutils

package com.example.p030_popbgqcode.utils;import android.graphics.rect;import  android.view.touchdelegate;import android.view.view;public class expandviewrectutils {     /**     *  increase reaction Heat zone      * @ param view view     *  @param  top  Increase upper hot zone       *  @param  bottom  Increase lower hot zone      *  @param  left  Increase left hot zone      *  @param  right  increase right hot zone      */     public static void expandviewtouchdelegate (final View view,  Final int top, final int bottom, final int left, final int  right)  {         ((View)  view.getparent ()). Post (new  runnable ()  {             @Override              public void run ()  {                 rect bounds = new rect ();                 view.setenabled (TRUE);                  View.gethitrect (bounds);                 bounds.top -= top;                 bounds.bottom += bottom;                 bounds.left -= left;                 bounds.right += right;                 touchdelegate touchdelegate = new touchdelegate ( Bounds, view);                 if  (View.class.isInstance (view.getparent))  {                      (View)  view.getparent ()). Settouchdelegate (touchdelegate);                 }            }         });    }    /**      *  Restore the touch and click Response range of the view to a minimum of not less than the view itself range      *     *   @param  view &Nbsp;   */    public static void restoreviewtouchdelegate ( Final view view)  {         (View)  view.getparent () ). Post (new runnable ()  {            @ Override            public void run ()  {                rect  bounds = new rect ();                 bounds.setempty ();                 touchdelegate touchdelegate = new touchdelegate (bounds ,  view);                 if  (View.class.isInstanCE (View.getparent ()))  {                      (View)  view.getparent (). Settouchdelegate (Touchdelegate);                 }             }        } );     }}

How to use:

Expandviewrectutils.expandviewtouchdelegate (TV1, 10, 10, 10, 10);

Effects such as:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9E/10/wKiom1mKwHLitb95ABMSEs3r4Uo345.gif "title=" Fffffff.gif "alt=" Wkiom1mkwhlitb95abmses3r4uo345.gif "/>

Address: Https://github.com/geeklx/MyApplication/tree/master/p030_popbgqcode

Additional drawings:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9E/10/wKioL1mKwXiQ6L8YAAhb04uYOUo142.png "title=" Qq20170809160132.png "width=" "height=" 588 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:600PX;HEIGHT:588PX; "alt = "Wkiol1mkwxiq6l8yaahb04uyouo142.png"/>

This article is from the "Liangxiao Technology Center" blog, please be sure to keep this source http://liangxiao.blog.51cto.com/3626612/1954841

Android Studio-47th phase frosted glass effects and dynamic generation of QR codes and increased click-to-hot zones

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.