Search in sources :

Example 26 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project PhotoPicker by donglua.

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 27 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android-vision by googlesamples.

the class BarcodeCaptureActivity method onCreate.

/**
     * Initializes the UI and creates the detector pipeline.
     */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.barcode_capture);
    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);
    // read parameters from the intent used to launch the activity.
    boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false);
    boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);
    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }
    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());
    Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) SuppressLint(android.annotation.SuppressLint)

Example 28 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project jmonkeyengine by jMonkeyEngine.

the class AndroidInputHandler method addListeners.

protected void addListeners(GLSurfaceView view) {
    view.setOnTouchListener(this);
    view.setOnKeyListener(this);
    AndroidGestureProcessor gestureHandler = new AndroidGestureProcessor(touchInput);
    touchInput.setGestureDetector(new GestureDetector(view.getContext(), gestureHandler));
    touchInput.setScaleDetector(new ScaleGestureDetector(view.getContext(), gestureHandler));
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 29 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project Klyph by jonathangerbaud.

the class TouchImageView method sharedConstructing.

private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    matrix.setTranslate(1f, 1f);
    m = new float[9];
    setImageMatrix(matrix);
    setScaleType(ScaleType.MATRIX);
    setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mScaleDetector.onTouchEvent(event);
            matrix.getValues(m);
            float x = m[Matrix.MTRANS_X];
            float y = m[Matrix.MTRANS_Y];
            PointF curr = new PointF(event.getX(), event.getY());
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    last.set(event.getX(), event.getY());
                    start.set(last);
                    mode = DRAG;
                    break;
                case MotionEvent.ACTION_MOVE:
                    if (mode == DRAG) {
                        float deltaX = curr.x - last.x;
                        float deltaY = curr.y - last.y;
                        float scaleWidth = Math.round(origWidth * saveScale);
                        float scaleHeight = Math.round(origHeight * saveScale);
                        if (scaleWidth < width) {
                            deltaX = 0;
                            if (y + deltaY > 0)
                                deltaY = -y;
                            else if (y + deltaY < -bottom)
                                deltaY = -(y + bottom);
                        } else if (scaleHeight < height) {
                            deltaY = 0;
                            if (x + deltaX > 0)
                                deltaX = -x;
                            else if (x + deltaX < -right)
                                deltaX = -(x + right);
                        } else {
                            if (x + deltaX > 0)
                                deltaX = -x;
                            else if (x + deltaX < -right)
                                deltaX = -(x + right);
                            if (y + deltaY > 0)
                                deltaY = -y;
                            else if (y + deltaY < -bottom)
                                deltaY = -(y + bottom);
                        }
                        matrix.postTranslate(deltaX, deltaY);
                        last.set(curr.x, curr.y);
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    mode = NONE;
                    int xDiff = (int) Math.abs(curr.x - start.x);
                    int yDiff = (int) Math.abs(curr.y - start.y);
                    if (xDiff < CLICK && yDiff < CLICK)
                        performClick();
                    break;
                case MotionEvent.ACTION_POINTER_UP:
                    mode = NONE;
                    break;
            }
            setImageMatrix(matrix);
            invalidate();
            // indicate event was handled
            return true;
        }
    });
}
Also used : PointF(android.graphics.PointF) ScaleGestureDetector(android.view.ScaleGestureDetector) ImageView(android.widget.ImageView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 30 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project ZoomableImageView by laurencedawson.

the class ZoomableImageView method init.

// Setup the view
private void init(Context context) {
    mPaint = new Paint();
    mPaint.setDither(true);
    mPaint.setFilterBitmap(true);
    mPaint.setAntiAlias(true);
    // Setup the refresh runnable
    mRefresh = new Runnable() {

        @Override
        public void run() {
            postInvalidate();
        }
    };
    // Setup the gesture and scale listeners
    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new MyGestureListener());
    // Force hardware acceleration
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) Paint(android.graphics.Paint) ScaleGestureDetector(android.view.ScaleGestureDetector)

Aggregations

ScaleGestureDetector (android.view.ScaleGestureDetector)46 GestureDetector (android.view.GestureDetector)23 Paint (android.graphics.Paint)8 Matrix (android.graphics.Matrix)7 LayoutInflater (android.view.LayoutInflater)6 WindowManager (android.view.WindowManager)6 MotionEvent (android.view.MotionEvent)5 Point (android.graphics.Point)4 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)4 ImageView (android.widget.ImageView)3 SuppressLint (android.annotation.SuppressLint)2 PackageManager (android.content.pm.PackageManager)2 PointF (android.graphics.PointF)2 Rect (android.graphics.Rect)2 View (android.view.View)2 ViewParent (android.view.ViewParent)2 Scroller (android.widget.Scroller)2 Drawable (android.graphics.drawable.Drawable)1 ScaleGestureDetectorCompat (android.support.v4.view.ScaleGestureDetectorCompat)1 FastOutLinearInInterpolator (android.support.v4.view.animation.FastOutLinearInInterpolator)1