Android ring menu (processed menu keys and return keys + added animations)
Not much nonsense. first look at it:
Package com. example. circlemenuofbottom. anim; import android. view. animation. rotateAnimation; import android. widget. relativeLayout;/*** @ author lzd *** QQ: 2622596982 *** email: www.bkjia.com ** QQ chat group: 277599214 */public class MyAnimationUtils {/*** exit animation --- clockwise output ** @ param view * animation object */public static void animaOut (RelativeLayout view) {/** RotateAnimation animation = new RotateAnimation (0,180, * view. getWidth ()/2, view. getHeight (); animation. setDuration (500); * animation. setFillAfter (true); view. startAnimation (animation); */animaOut (view, 0 );} /*** go-out animation --- enter ** @ param view * the animation object */public static void animaIn (RelativeLayout view) counterclockwise) {/** // clockwise // RotateAnimation animation = new RotateAnimation (180, // * 360, view. getWidth ()/2, view. getHeight (); // enter RotateAnimation * animation = new RotateAnimation (-180,-360, view. getWidth ()/* 2, view. getHeight (); animation. setDuration (500); * animation. setFillAfter (true); view. startAnimation (animation); */animaIn (view, 0 );} /*** exit animation --- clockwise output ** @ param view * the animation execution object * @ param offSetTime * The Time of delayed execution */public static void animaOut (RelativeLayout view, int offSetTime) {RotateAnimation animation = new RotateAnimation (0,180, view. getWidth ()/2, view. getHeight (); animation. setDuration (500); animation. setStartOffset (offSetTime); animation. setFillAfter (true); view. startAnimation (animation);} public static void animaIn (RelativeLayout view, int offSetTime) {// clockwise forward // RotateAnimation animation = new RotateAnimation (180, // 360, view. getWidth ()/2, view. getHeight (); // enter RotateAnimation animation = new RotateAnimation (-180,-360, view. getWidth ()/2, view. getHeight (); animation. setDuration (500); animation. setStartOffset (offSetTime); animation. setFillAfter (true); view. startAnimation (animation );}}
Handling of buttons:
/** Listen to the menu key. When you click the menu key, the first and second menus are displayed and hidden ** listen to the Return key, and then press exit program once */private long exitTime = 0; @ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {// process the menu key if (event. getAction () = KeyEvent. ACTION_DOWN & keyCode = KeyEvent. KEYCODE_MENU) {// if the first-level menu is displayed, hide all if (isShowLevel1) {MyAnimationUtils. animaOut (level); isShowLevel1 = false; if (isShowLevel2) {MyAnimationUtils. animaOut (level2, 120); isShowLevel2 = false; if (isShowLevel3) {MyAnimationUtils. animaOut (level3, 120); isShowLevel3 = false ;}} else {// if the level-1 menu is hidden, display level-1 and level-2 menu MyAnimationUtils. animaIn (level); MyAnimationUtils. animaIn (level2, 120); isShowLevel1 = true; isShowLevel2 = true ;}// return key if (event. getAction () = KeyEvent. ACTION_DOWN & keyCode = KeyEvent. KEYCODE_BACK) {if (System. currentTimeMillis ()-exitTime> 2000) {Toast. makeText (this, press the return key again to exit, Toast. LENGTH_SHORT ). show (); exitTime = System. currentTimeMillis ();} else {finish (); System. exit (0);} return true;} return super. onKeyDown (keyCode, event );}