Search in sources :

Example 21 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project wire-android by wireapp.

the class TouchImageView method sharedConstructing.

private void sharedConstructing(Context context) {
    super.setClickable(true);
    this.context = context;
    scaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    gestureDetector = new GestureDetector(context, new GestureListener());
    matrix = new Matrix();
    prevMatrix = new Matrix();
    m = new float[9];
    normalizedScale = 1;
    if (scaleType == null) {
        scaleType = 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 22 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android_frameworks_base by crdroidandroid.

the class ExpandHelper method cancel.

/**
     * Use this to abort any pending expansions in progress.
     */
public void cancel() {
    finishExpanding(true, /* forceAbort */
    0f);
    clearView();
    // reset the gesture detector
    mSGD = new ScaleGestureDetector(mContext, mScaleGestureListener);
}
Also used : ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 23 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android_frameworks_base by crdroidandroid.

the class OverlayDisplayWindow method createWindow.

private void createWindow() {
    LayoutInflater inflater = LayoutInflater.from(mContext);
    mWindowContent = inflater.inflate(com.android.internal.R.layout.overlay_display_window, null);
    mWindowContent.setOnTouchListener(mOnTouchListener);
    mTextureView = (TextureView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_texture);
    mTextureView.setPivotX(0);
    mTextureView.setPivotY(0);
    mTextureView.getLayoutParams().width = mWidth;
    mTextureView.getLayoutParams().height = mHeight;
    mTextureView.setOpaque(false);
    mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    mTitleTextView = (TextView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_title);
    mTitleTextView.setText(mTitle);
    mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY);
    mWindowParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
    if (mSecure) {
        mWindowParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
    }
    if (DISABLE_MOVE_AND_RESIZE) {
        mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    }
    mWindowParams.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
    mWindowParams.alpha = WINDOW_ALPHA;
    mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowParams.setTitle(mTitle);
    mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
    mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
    // Set the initial position and scale.
    // The position and scale will be clamped when the display is first shown.
    mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayInfo.logicalWidth;
    mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayInfo.logicalHeight;
    mWindowScale = INITIAL_SCALE;
}
Also used : LayoutInflater(android.view.LayoutInflater) GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) WindowManager(android.view.WindowManager)

Example 24 with ScaleGestureDetector

use of android.view.ScaleGestureDetector in project android_frameworks_base by ResurrectionRemix.

the class ExpandHelper method cancel.

/**
     * Use this to abort any pending expansions in progress.
     */
public void cancel() {
    finishExpanding(true, /* forceAbort */
    0f);
    clearView();
    // reset the gesture detector
    mSGD = new ScaleGestureDetector(mContext, mScaleGestureListener);
}
Also used : ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 25 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)

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