This article describes a fun app
Implementation ideas: Use a custom view on a transparent activity and then draw on the view. 9 of broken glass pictures, plus sound effects. And then disappear for a while.
The main use of a postinvalidate () method, with a set to put the finger touched place, call Postinvalidate () in the Touch event, method to redraw the view.
It is important to note that the playback sound is the same as the play sound in the previous blog's Android Lightning Effect (Electric screen, motorized), when you pause the sound, you get the int return value when you start playing, and the stop sound is different.
You can limit the number of screens that are drawn by limiting the length of the collection.
Open a single thread, after a period of time to begin to clear the effect, that is, the direct operation of the collection, the operation is finished calling Postinvalidate (); A re-drawing is possible.
Example code:
public class CustomView extends View {private Paint mpaint;private soundpool msoundpool;private Map<integer, INTEGER&G T Msoundmap = new Hashmap<integer, integer> ();p rivate int mindex;private Bitmap mbitmap;private arraylist<float& Gt mxpointlist;private arraylist<float> mypointlist;private int mCount = 0;//clicks private int mlength = 30;//Plot Total publi C 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 (Getresources (), 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-generate D catch Blocke.printstacktrace ();} Mg++;handler.sendemptymessage (0);}}). Start ();} @Overridepublic boolean ontouchevent (motionevent arg1) {//TODO auto-generated method Stubswitch (Arg1.getaction ()) { Case motionevent.action_down://Drawbitmap (Arg1.getx (), Arg1.gety ());p laysound (); Mxpointlist.add (Arg1.getX ()); Mypointlist.add (Arg1.gety ());p ostinvalidate () mcount++;if (MCount > Mlength) {mxpointlist.remove (0); Mypointlist.remove (0); mlength++;} Break;case motionevent.action_up:break;case Motionevent.action_move:break;default:break;} Return super.ontouchevent (ARG1);} @Overrideprotected void OnDraw (canvas canvas) {super.ondraw (canvas); for (int i = 0; i < mxpointlist.size (); ++i) {Canva S.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 Stopsound () {//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 interface Handler handler = new Handler () {public void Handlemessage (Message msg) {if (Msg.what = = 0) {if (MCount! = 0 && Amp 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
Weibo: http://weibo.com/2382477985
Android splash Screen effect (Crack screen, Smash screens)