Search in sources :

Example 21 with GestureDetector

use of android.view.GestureDetector in project frostwire by frostwire.

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 22 with GestureDetector

use of android.view.GestureDetector in project apps-android-wikipedia by wikimedia.

the class ZoomableDraweeView method init.

private void init() {
    mZoomableController = createZoomableController();
    mZoomableController.setListener(mZoomableListener);
    mTapGestureDetector = new GestureDetector(getContext(), mTapListenerWrapper);
}
Also used : GestureDetector(android.view.GestureDetector)

Example 23 with GestureDetector

use of android.view.GestureDetector in project yoo_home_Android by culturer.

the class SkyWheel method init.

private void init() {
    mDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onDown(MotionEvent e) {
            if (mAnimator != null && mAnimator.isRunning()) {
                mAnimator.cancel();
            }
            return false;
        }

        /**
         * 手指点击一次的时候调用一次
         * @param e
         * @return
         */
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            // 点击时,判断当前点是否被某个子控件包含,如果包含直接调用子控件的点击事件即可
            int index = getClickPosition(e);
            if (index > -1) {
                // 强制让当前的控件的点击事件执行
                getChildAt(index).performClick();
            }
            return false;
        }

        /**
         * @param e1 按下事件 action—_down
         * @param e2 move事件,最近一次的action_move
         * @param distanceX = 上一次move事件的x值 - 当前move事件的x值
         * @param distanceY = 上一次move事件的y值 - 当前move事件的y值
         * @return
         */
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            // 计算出手指滑动过程中的角度变化夹角
            // 计算出起始点的角度
            double startDegree = getDegree(e2.getX() + distanceX, e2.getY() + distanceX);
            // 计算出结束点的角度
            double endDegree = getDegree(e2.getX(), e2.getY());
            // 计算出夹角
            double diff = endDegree - startDegree;
            setDegree(diffDegree + diff);
            return false;
        }

        /**
         * @param e1 手指按下的事件
         * @param e2 手指移动的事件
         * @param velocityX 手指离开屏幕时,在x轴的速率(像素/s)
         * @param velocityY 手指离开屏幕时,在y轴的速率(像素/s)
         * @return
         */
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // 计算当前点的角度
            double startDegree = getDegree(e2.getX(), e2.getY());
            // 计算1ms后的角度
            double endDegreeAfter1ms = getDegree(e2.getX() + velocityX / 1000, e2.getY() + velocityY / 1000);
            // 计算出1ms的角速度
            double velocityAfter1ms = endDegreeAfter1ms - startDegree;
            // 计算出1s的角速度
            double velocityAfter1s = velocityAfter1ms * 1000;
            // 通过角速度设置,要移动到的角度
            startFlingAnimation(velocityAfter1s);
            return false;
        }
    });
}
Also used : GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 24 with GestureDetector

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

the class DividerView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mHandle = (DividerHandleView) findViewById(R.id.docked_divider_handle);
    mBackground = findViewById(R.id.docked_divider_background);
    mMinimizedShadow = (MinimizedDockShadow) findViewById(R.id.minimized_dock_shadow);
    mHandle.setOnTouchListener(this);
    mDividerWindowWidth = getResources().getDimensionPixelSize(com.android.internal.R.dimen.docked_stack_divider_thickness);
    mDividerInsets = getResources().getDimensionPixelSize(com.android.internal.R.dimen.docked_stack_divider_insets);
    mDividerSize = mDividerWindowWidth - 2 * mDividerInsets;
    mTouchElevation = getResources().getDimensionPixelSize(R.dimen.docked_stack_divider_lift_elevation);
    mLongPressEntraceAnimDuration = getResources().getInteger(R.integer.long_press_dock_anim_duration);
    mGrowRecents = getResources().getBoolean(R.bool.recents_grow_in_multiwindow);
    mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
    mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.3f);
    updateDisplayInfo();
    boolean landscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    mHandle.setPointerIcon(PointerIcon.getSystemIcon(getContext(), landscape ? TYPE_HORIZONTAL_DOUBLE_ARROW : TYPE_VERTICAL_DOUBLE_ARROW));
    getViewTreeObserver().addOnComputeInternalInsetsListener(this);
    mHandle.setAccessibilityDelegate(mHandleDelegate);
    mGestureDetector = new GestureDetector(mContext, new SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (SWAPPING_ENABLED) {
                updateDockSide();
                SystemServicesProxy ssp = Recents.getSystemServices();
                if (mDockSide != WindowManager.DOCKED_INVALID && !ssp.isRecentsActivityVisible()) {
                    mWindowManagerProxy.swapTasks();
                    return true;
                }
            }
            return false;
        }
    });
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) FlingAnimationUtils(com.android.systemui.statusbar.FlingAnimationUtils) SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 25 with GestureDetector

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

the class SystemGesturesPointerEventListener method systemReady.

public void systemReady() {
    Handler h = new Handler(Looper.myLooper());
    mGestureDetector = new GestureDetector(mContext, new FlingGestureDetector(), h);
    mOverscroller = new OverScroller(mContext);
}
Also used : Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) OverScroller(android.widget.OverScroller)

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