2

画面の限られた領域で画面上でユーザーを指で操作するには、円で完全に回転する回数を数える必要があります。一度に。時間を設定し、矢印を動かします。例えば秒針2回転で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