The windmill of version 1.0 and version 2.0 has an unsatisfactory effect: when the finger is lifted, the windmill will stop turning, and now version 3 to do is let the finger lift the time to let the windmill continue to rotate for a while, the idea is as follows:
1) Keep the windmill spinning for 5 seconds while your finger is lifted.
2) You need to listen for MOTIONEVENT.ACTION_UP events and record the time the finger is lifted uptime
3) Capture MOTIONEVENT.ACTION_UP events and redraw for five seconds
Based on the above instructions, the following changes are made to the Rotationview code (based on version 2, which mainly modifies the Ontouchevent event:
/** finger lift Time **/ private long upTime = 0; /** finger lifted when the windmill continued to turn the time **/private final long stoptimeduration =; @Overridepublic boolean ontouchevent (Motionevent event) {int action = event.getaction (); switch (action) {case MOTIONEVENT.ACTION_MOVE://continues to redraw with the MOVE of the finger//This method uses Postinvalidate () in the UI thread itself; Break;case motionevent.action_up:// Continuously redraw with the move of the finger uptime = System.currenttimemillis ();p Ost (new Runnable () {@Overridepublic void run () {Long Duration = System.currenttimemillis ()-uptime;if (duration ==stoptimeduration) {return;} else if (duration<stoptimeduration) {post (this);} Used in non-UI threads. Invalidate ();}}); break;} return true;}
Of course, this version of the windmill is still problematic: the speed of the windmill rotation is consistent, does not change with the pace of the movement of the finger, this will be resolved in the next version, see the Custom view of the Big Windmill Series (iii)
Custom view of the Big Windmill series Demo (ii)