Search in sources :

Example 36 with GestureDetector

use of android.view.GestureDetector in project EngineDriver by JMRI.

the class gamepad_test method onCreate.

/**
 * Called when the activity is first created.
 */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mainapp = (threaded_application) getApplication();
    if (mainapp.isForcingFinish()) {
        // expedite
        return;
    }
    result = RESULT_CANCELED;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        whichGamepadNo = extras.getString("whichGamepadNo");
    }
    mainapp.applyTheme(this);
    setContentView(R.layout.gamepad_test);
    // put pointer to this activity's handler in main app's shared variable
    myGesture = new GestureDetector(this);
    mainapp = (threaded_application) this.getApplication();
    prefs = getSharedPreferences("jmri.enginedriver_preferences", 0);
    prefGamepadTestEnforceTestingSimple = prefs.getBoolean("prefGamepadTestEnforceTestingSimple", getResources().getBoolean(R.bool.prefGamepadTestEnforceTestingSimpleDefaultValue));
    // tone generator for feedback sounds
    tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, preferences.getIntPrefValue(prefs, "prefGamePadFeedbackVolume", getApplicationContext().getResources().getString(R.string.prefGamePadFeedbackVolumeDefaultValue)));
    // set listener for select loco buttons
    bDpadUp = (Button) findViewById(R.id.gamepad_test_dpad_up);
    bDpadUp.setClickable(false);
    bDpadDown = (Button) findViewById(R.id.gamepad_test_dpad_down);
    bDpadDown.setClickable(false);
    bDpadLeft = (Button) findViewById(R.id.gamepad_test_dpad_left);
    bDpadLeft.setClickable(false);
    bDpadRight = (Button) findViewById(R.id.gamepad_test_dpad_right);
    bDpadRight.setClickable(false);
    bButtonX = (Button) findViewById(R.id.gamepad_test_button_x);
    bButtonX.setClickable(false);
    bButtonY = (Button) findViewById(R.id.gamepad_test_button_y);
    bButtonY.setClickable(false);
    bButtonA = (Button) findViewById(R.id.gamepad_test_button_a);
    bButtonA.setClickable(false);
    bButtonB = (Button) findViewById(R.id.gamepad_test_button_b);
    bButtonB.setClickable(false);
    bButtonStart = (Button) findViewById(R.id.gamepad_test_button_start);
    bButtonStart.setClickable(false);
    bButtonEnter = (Button) findViewById(R.id.gamepad_test_button_enter);
    bButtonEnter.setClickable(false);
    // tvGamepadMode =(TextView) findViewById(R.id.gamepad_test_mode);
    tvGamepadAllKeyCodes = (TextView) findViewById(R.id.gamepad_test_all_keycodes);
    tvGamepadKeyCode = (TextView) findViewById(R.id.gamepad_test_keycode);
    tvGamepadKeyFunction = (TextView) findViewById(R.id.gamepad_test_keyfunction);
    tvGamepadComplete = (TextView) findViewById(R.id.gamepad_test_complete);
    tvGamepadKeyCode.setText("");
    tvGamepadKeyFunction.setText("");
    tvGamepadComplete.setText(R.string.gamepadTestIncomplete);
    // Set the options for the mode.
    Spinner mode_spinner = (Spinner) findViewById(R.id.gamepad_test_mode);
    // ArrayAdapter<?> spinner_adapter = ArrayAdapter.createFromResource(this, R.array.prefGamePadTypeOptions, android.R.layout.simple_spinner_item);
    ArrayAdapter<?> spinner_adapter = ArrayAdapter.createFromResource(this, R.array.prefGamePadTypeEntryValues, android.R.layout.simple_spinner_item);
    spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mode_spinner.setAdapter(spinner_adapter);
    mode_spinner.setOnItemSelectedListener(new spinner_listener());
    setGamepadKeys();
    // Set the button
    Button cancelButton = (Button) findViewById(R.id.gamepad_test_button_cancel);
    gamepad_test.cancel_button_listener cancel_click_listener = new gamepad_test.cancel_button_listener();
    cancelButton.setOnClickListener(cancel_click_listener);
    Button resetButton = (Button) findViewById(R.id.gamepad_test_button_reset);
    gamepad_test.reset_button_listener reset_click_listener = new gamepad_test.reset_button_listener();
    resetButton.setOnClickListener(reset_click_listener);
    Button skipButton = (Button) findViewById(R.id.gamepad_test_button_skip);
    if (whichGamepadNo.equals(" ")) {
        resetButton.setVisibility(View.GONE);
        skipButton.setVisibility(View.GONE);
        cancelButton.setText(R.string.gamepadTestCancelNonForced);
        TextView tvHelpText = (TextView) findViewById(R.id.gamepad_test_help);
        tvHelpText.setText(R.string.gamepadTestHelpNonForced);
    } else {
        gamepad_test.skip_button_listener skip_click_listener = new gamepad_test.skip_button_listener();
        skipButton.setOnClickListener(skip_click_listener);
    }
}
Also used : Bundle(android.os.Bundle) Spinner(android.widget.Spinner) GestureDetector(android.view.GestureDetector) ToneGenerator(android.media.ToneGenerator) Button(android.widget.Button) TextView(android.widget.TextView)

Example 37 with GestureDetector

use of android.view.GestureDetector in project Applozic-Android-SDK by AppLozic.

the class TouchImageView method sharedConstructing.

private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (mScaleType == null) {
        mScaleType = ScaleType.FIT_CENTER;
    }
    minScale = 1;
    maxScale = 3;
    superMinScale = SUPER_MIN_MULTIPLIER * minScale;
    superMaxScale = SUPER_MAX_MULTIPLIER * maxScale;
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setState(State.NONE);
    onDrawReady = false;
    super.setOnTouchListener(new PrivateOnTouchListener());
}
Also used : Matrix(android.graphics.Matrix) GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 38 with GestureDetector

use of android.view.GestureDetector in project weiui by kuaifan.

the class SubsamplingScaleImageView method setGestureDetector.

private void setGestureDetector(final Context context) {
    this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) {
                PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f));
                float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale;
                float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale;
                new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start();
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            performClick();
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (zoomEnabled && readySent && vTranslate != null) {
                // Hacky solution for #15 - after a double tap the GestureDetector gets in a state
                // where the next fling is ignored, so here we replace it with a new one.
                setGestureDetector(context);
                if (quickScaleEnabled) {
                    // Store quick scale params. This will become either a double tap zoom or a
                    // quick scale depending on whether the user swipes.
                    vCenterStart = new PointF(e.getX(), e.getY());
                    vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                    scaleStart = scale;
                    isQuickScaling = true;
                    isZooming = true;
                    quickScaleLastDistance = -1F;
                    quickScaleSCenter = viewToSourceCoord(vCenterStart);
                    quickScaleVStart = new PointF(e.getX(), e.getY());
                    quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y);
                    quickScaleMoved = false;
                    // We need to get events in onTouchEvent after this.
                    return false;
                } else {
                    // Start double tap zoom animation.
                    doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY()));
                    return true;
                }
            }
            return super.onDoubleTapEvent(e);
        }
    });
}
Also used : PointF(android.graphics.PointF) GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 39 with GestureDetector

use of android.view.GestureDetector in project weiui by kuaifan.

the class GestureCropImageView method setupGestureListeners.

private void setupGestureListeners() {
    mGestureDetector = new GestureDetector(getContext(), new GestureListener(), null, true);
    mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleListener());
    mRotateDetector = new RotationGestureDetector(new RotateListener());
}
Also used : RotationGestureDetector(com.yalantis.ucrop.weiui.library.util.RotationGestureDetector) GestureDetector(android.view.GestureDetector) RotationGestureDetector(com.yalantis.ucrop.weiui.library.util.RotationGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 40 with GestureDetector

use of android.view.GestureDetector in project Rocket by mozilla-tw.

the class SubsamplingScaleImageView method setGestureDetector.

private void setGestureDetector(final Context context) {
    this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) {
                PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f));
                float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale;
                float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale;
                new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD).withPanLimited(false).withOrigin(ORIGIN_FLING).start();
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            performClick();
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (zoomEnabled && readySent && vTranslate != null) {
                // Hacky solution for #15 - after a double tap the GestureDetector gets in a state
                // where the next fling is ignored, so here we replace it with a new one.
                setGestureDetector(context);
                if (quickScaleEnabled) {
                    // Store quick scale params. This will become either a double tap zoom or a
                    // quick scale depending on whether the user swipes.
                    vCenterStart = new PointF(e.getX(), e.getY());
                    vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                    scaleStart = scale;
                    isQuickScaling = true;
                    isZooming = true;
                    quickScaleLastDistance = -1F;
                    quickScaleSCenter = viewToSourceCoord(vCenterStart);
                    quickScaleVStart = new PointF(e.getX(), e.getY());
                    quickScaleVLastPoint = new PointF(quickScaleSCenter.x, quickScaleSCenter.y);
                    quickScaleMoved = false;
                    // We need to get events in onTouchEvent after this.
                    return false;
                } else {
                    // Start double tap zoom animation.
                    doubleTapZoom(viewToSourceCoord(new PointF(e.getX(), e.getY())), new PointF(e.getX(), e.getY()));
                    return true;
                }
            }
            return super.onDoubleTapEvent(e);
        }
    });
}
Also used : PointF(android.graphics.PointF) GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Aggregations

GestureDetector (android.view.GestureDetector)220 MotionEvent (android.view.MotionEvent)90 View (android.view.View)53 ScaleGestureDetector (android.view.ScaleGestureDetector)42 Paint (android.graphics.Paint)30 TextView (android.widget.TextView)29 Handler (android.os.Handler)20 ImageView (android.widget.ImageView)20 Matrix (android.graphics.Matrix)18 SuppressLint (android.annotation.SuppressLint)17 Scroller (android.widget.Scroller)16 WindowManager (android.view.WindowManager)15 TypedArray (android.content.res.TypedArray)12 SimpleOnGestureListener (android.view.GestureDetector.SimpleOnGestureListener)11 ViewGroup (android.view.ViewGroup)10 AdapterView (android.widget.AdapterView)10 Intent (android.content.Intent)9 SharedPreferences (android.content.SharedPreferences)9 PointF (android.graphics.PointF)9 OverScroller (android.widget.OverScroller)9