2

需要统计一圈的完整转圈数,以使用户在屏幕的有限区域内通过手指在屏幕上进行操作。一时间。设置时间,移动箭头。例如秒针转两圈就是两分钟。我不知道如何超越 360 度的值。下面,我的代码确定了矢量的角度:

public boolean onTouchEvent(MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN) {
            clockfacesec.getLocationOnScreen(secminxy);
            this.centerX = secminxy[0] + clockfacesec.getWidth()/2;
            this.centerY = secminxy[1] + clockfacesec.getHeight()/2;
            this.X = event.getRawX()- this.centerX;
            this.Y = event.getRawY() - this.centerY;
            setTimerface(this.X, this.Y);       
        }
        return gestures.onTouchEvent(event);
    }

    public void onMove(float dx, float dy) {
        this.X = this.X + dx;
        this.Y = this.Y + dy;
        setTimerface(this.X, this.Y);
    }

    private void setTimerface(float x, float y){    
        double r = Math.sqrt(x*x + y*y); 
        this.radsecmax = clockfacesec.getWidth()/2;
        this.radsecmin = (float) ((clockfacesec.getWidth()/2)*0.756);
            if(r > radsecmin && r < radsecmax){                                     
                int secseconds = tTime % 60;
                tTime = tTime - secseconds;
                double fi = Math.atan2(y, x) * 180 / Math.PI;
                if(fi < 0){
                    if (fi < -90) secView = (int)fi/6 + 75;
                    else secView = (int)fi/6 + 15;
                }else{
                    secView = (int)fi/6 + 15;
                }
                if (secView == 60) secView = 0;
                tTime = tTime + secView;
                settTime(tTime);
            }
    } 
}
private class GestureListener implements GestureDetector.OnGestureListener{
    Faceclock view;
    public GestureListener(Faceclock view) {
        this.view = view;
    }
    public boolean onDown(MotionEvent arg0) {
        return true;
    }
    public boolean onFling(MotionEvent arg0, MotionEvent arg1, float velocityX, float velocityY) {
        return true;
    }
    public void onLongPress(MotionEvent arg0) {}
    public boolean onScroll(MotionEvent e, MotionEvent arg1, float distanceX, float distanceY) {
        view.onMove(-distanceX, -distanceY);
        return true;
    }
    public void onShowPress(MotionEvent arg0) {}
    public boolean onSingleTapUp(MotionEvent arg0) {
        return false;
    }
}   
4

0 回答 0