privateenumSelectedIcon{DEFAULT,BEDTIME,ALARM}privateSelectedIconmSelectionState=SelectedIcon.DEFAULT;@OverridepublicbooleanonTouchEvent(MotionEventevent){posX=(int)event.getX();posY=(int)event.getY();doubleangleTouch=Math.toDegrees(Math.atan2(posY-center,posX-center))+90;if(angleTouch<-0.1){angleTouch=360+angleTouch;}//Reset status to nothing selected on pointer upif(event.getActionMasked()==MotionEvent.ACTION_UP)//ACTION_POINTER_UP if considering multi-touch{mSelectionState=SelectedIcon.DEFAULT;returntrue;}elseif(mSelectionState==SelectedIcon.DEFAULT)//Nothing selected yet{//Check if we are within selection distance of anythingif((Math.abs(angleTouch-angleBedtime)<15||Math.abs(angleTouch-angleBedtime)>340)){mSelectionState=SelectedIcon.BEDTIME;}elseif((Math.abs(angleTouch-angleAlarmtime)<15||Math.abs(angleTouch-angleAlarmtime)>340)){mSelectionState=SelectedIcon.ALARM;}}//If the pointer has been within selection distance of an icon this session,//move it accordingly. switch(mSelectionState){caseBEDTIME:{angleBedtimeIcon=(float)Math.atan2(posX-center,posY-center);break;}caseALARM:{angleAlarmIcon=(float)Math.atan2(posX-center,posY-center);break;}default:{//Nothing}}returntrue;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.