Android Crack Screen and androidcrack

Source: Internet
Author: User

Android Crack Screen and androidcrack

This article introduces a fun App



Implementation idea: Use a custom View on a transparent Activity, then draw a. 9 broken glass image on the View, and add the sound effect. Then it disappears after a while.

The postInvalidate () method is used to redraw the view by using a set to hold the places touched by fingers and calling postInvalidate () in the touch event.

It should be noted that the playback sound effects here are the same as those in the Electric Screen (Electric Screen) of the previous blog, when you pause a sound effect, you need to pass the int return value when you start playing the video. This is different from the stop sound effect.

You can limit the number of screens to be drawn by limiting the set length.

Start a single thread and clear the effect after a period of time, that is, directly operate the set. After the operation is complete, call postInvalidate () and redraw.

Sample Code:

Public class CustomView extends View {private Paint mPaint; private SoundPool mSoundPool; private Map <Integer, Integer> mSoundMap = new HashMap <Integer, Integer> (); private int mIndex; private Bitmap mBitmap; private ArrayList <Float> mXPointList; private ArrayList <Float> mYPointList; private int mCount = 0; // Number of clicks private int mLength = 30; // total number of draws public CustomView (Context context, AttributeSet attrs) {super (Context); mPaint = new Paint (); mPaint. setAntiAlias (true); mPaint. setColor (Color. BLUE); // mPaint. setAlpha (127); mPaint. setStrokeWidth (2.0f); this. setKeepScreenOn (true); this. setFocusable (true); this. setLongClickable (true); this. mSoundPool = new SoundPool (5, AudioManager. STREAM_SYSTEM, 5); this. mSoundMap. put (1, mSoundPool. load (context, R. raw. cfokwowbfv, 1); this. mBitmap = BitmapFactory. decodeResource (getRe Sources (), R. drawable. screen); mXPointList = new ArrayList <Float> (); mYPointList = new ArrayList <Float> (); new Thread (new Runnable () {@ Overridepublic void run () {// TODO Auto-generated method stubwhile (true) {try {Thread. sleep (4000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke. printStackTrace ();} // mG ++; handler. sendEmptyMessage (0 );}}}). start () ;}@ Overridepublic boolean onTouch Event (MotionEvent arg1) {// TODO Auto-generated method stubswitch (arg1.getAction () {case MotionEvent. ACTION_DOWN: // drawBitmap (arg1.getX (), arg1.getY (); playSound (); mXPointList. add (arg1.getX (); mYPointList. add (arg1.getY (); postInvalidate (); mCount ++; if (mCount> mLength) {mXPointList. remove (0); mYPointList. remove (0); mLength ++;} break; case MotionEvent. ACTION_UP: break; case MotionEvent. ACTION_MOVE: bre Ak; default: break;} return super. onTouchEvent (arg1) ;}@ Overrideprotected void onDraw (Canvas canvas) {super. onDraw (canvas); for (int I = 0; I <mXPointList. size (); ++ I) {canvas. drawBitmap (mBitmap, mXPointList. get (I)-mBitmap. getWidth ()/2, mYPointList. get (I)-mBitmap. getHeight ()/2, null) ;}// play public void playSound () {mIndex = mSoundPool. play (mSoundMap. get (1), 1, 1, 0, 0, 1);} // stop playing public void st OpSound () {// Toast. makeText (getContext (), "zzzzz", 0 ). show (); mSoundPool. stop (mIndex) ;}@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {// TODO Auto-generated method stubToast. makeText (getContext (), "keydown", Toast. LENGTH_SHORT ). show (); return super. onKeyDown (keyCode, event);} // update the page Handler handler = new Handler () {public void handleMessage (Message msg) {if (msg. what = 0) {if (mCou Nt! = 0 & mXPointList. size ()! = 0) {for (int I = 0; I <new Random (). nextInt (mXPointList. size () + 1); I ++) {mXPointList. remove (0); mYPointList. remove (0); mLength ++ ;}} postInvalidate ();}}};}



Github: https://github.com/OneHead/crack_screen2D

WEAVER: http://weibo.com/2382477985

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.