Search in sources :

Example 1 with SimpleOnGestureListener

use of android.view.GestureDetector.SimpleOnGestureListener 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 2 with SimpleOnGestureListener

use of android.view.GestureDetector.SimpleOnGestureListener in project android_frameworks_base by AOSPA.

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 3 with SimpleOnGestureListener

use of android.view.GestureDetector.SimpleOnGestureListener in project android_frameworks_base by DirtyUnicorns.

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 4 with SimpleOnGestureListener

use of android.view.GestureDetector.SimpleOnGestureListener in project FloatBall by leavesC.

the class ProgressBall method init.

private void init() {
    // 初始化小球画笔
    ballPaint = new Paint();
    ballPaint.setAntiAlias(true);
    ballPaint.setColor(Color.argb(0xff, 0x3a, 0x8c, 0x6c));
    // 初始化(波浪)进度条画笔
    progressPaint = new Paint();
    progressPaint.setAntiAlias(true);
    progressPaint.setColor(Color.argb(0xff, 0x4e, 0xc9, 0x63));
    progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    // 初始化文字画笔
    textPaint = new Paint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(25);
    handler = new Handler();
    path = new Path();
    bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmapCanvas = new Canvas(bitmap);
    // 手势监听
    // 重点在于将单击和双击操作分隔开
    SimpleOnGestureListener listener = new SimpleOnGestureListener() {

        // 双击
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // 当前波浪起伏次数为零,说明“单击效果”没有影响到现在
            if (currentCount == 0) {
                // 当前进度为零或者已达到目标进度值,说明“双击效果”没有影响到现在,此时可以允许进行双击操作
                if (currentProgress == 0 || currentProgress == targetProgress) {
                    currentProgress = 0;
                    isSingleTop = false;
                    startDoubleTapAnimation();
                }
            }
            return super.onDoubleTap(e);
        }

        // 单击
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // 当前进度值等于目标进度值,且当前波动次数为零,则允许进行单击操作
            if (currentProgress == targetProgress && currentCount == 0) {
                isSingleTop = true;
                startSingleTapAnimation();
            }
            return super.onSingleTapConfirmed(e);
        }
    };
    gestureDetector = new GestureDetector(context, listener);
    setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    });
    // 接受点击操作
    setClickable(true);
}
Also used : Path(android.graphics.Path) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 5 with SimpleOnGestureListener

use of android.view.GestureDetector.SimpleOnGestureListener in project KeepScore by nolanlawson.

the class DragSortListView method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mRemoveListener != null && mGestureDetector == null) {
        if (mRemoveMode == FLING) {
            mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mFloatView != null) {
                        if (velocityX > 1000) {
                            Rect r = mTempRect;
                            mFloatView.getDrawingRect(r);
                            if (e2.getX() > r.right * 2 / 3) {
                                // fast fling right with release near the right edge of the screen
                                dropFloatView(true);
                            }
                        }
                        // onTouch handlers. Gobble...
                        return true;
                    }
                    return false;
                }
            });
        }
    }
    if (mDragListener != null || mDropListener != null) {
        switch(ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // Log.d("mobeta", "action down!");
                int x = (int) ev.getX();
                int y = (int) ev.getY();
                mLastX = x;
                mLastY = y;
                mDownY = y;
                // includes headers/footers
                int itemnum = pointToPosition(x, y);
                final int numHeaders = getHeaderViewsCount();
                final int numFooters = getFooterViewsCount();
                // Log.d("mobeta", "touch down on position " + itemnum);
                if (itemnum == AdapterView.INVALID_POSITION || itemnum < numHeaders || itemnum >= getCount() - numFooters) {
                    break;
                }
                ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
                mDragPointX = x - item.getLeft();
                mDragPointY = y - item.getTop();
                final int rawX = (int) ev.getRawX();
                final int rawY = (int) ev.getRawY();
                mXOffset = rawX - x;
                mYOffset = rawY - y;
                View dragBox = (View) item.getTag();
                boolean dragHit = false;
                if (dragBox != null) {
                    dragBox.getLocationOnScreen(mTempLoc);
                    dragHit = rawX > mTempLoc[0] && rawY > mTempLoc[1] && rawX < mTempLoc[0] + dragBox.getWidth() && rawY < mTempLoc[1] + dragBox.getHeight();
                }
                if (dragHit) {
                    // item.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
                    item.setDrawingCacheEnabled(true);
                    // Create a copy of the drawing cache so that it does not get recycled
                    // by the framework when the list tries to clean up memory
                    Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
                    item.setDrawingCacheEnabled(false);
                    mFloatViewHeight = item.getHeight();
                    mFloatViewHeightHalf = mFloatViewHeight / 2;
                    mExpDragPos = itemnum;
                    mSrcDragPos = itemnum;
                    // Log.d("mobeta", "getCount() = " + getCount());
                    // Log.d("mobeta", "headers = " + getHeaderViewsCount());
                    startDragging(bitmap, x, y);
                    // cancel ListView fling
                    MotionEvent ev2 = MotionEvent.obtain(ev);
                    ev2.setAction(MotionEvent.ACTION_CANCEL);
                    super.onInterceptTouchEvent(ev2);
                    // return false;
                    return true;
                }
                removeFloatView();
                break;
        }
    }
    return super.onInterceptTouchEvent(ev);
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) ViewGroup(android.view.ViewGroup) SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) GestureDetector(android.view.GestureDetector) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) MotionEvent(android.view.MotionEvent)

Aggregations

SimpleOnGestureListener (android.view.GestureDetector.SimpleOnGestureListener)12 MotionEvent (android.view.MotionEvent)12 GestureDetector (android.view.GestureDetector)10 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 View (android.view.View)4 GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)2 ViewGroup (android.view.ViewGroup)2 AbsListView (android.widget.AbsListView)2 ValueAnimator (android.animation.ValueAnimator)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Path (android.graphics.Path)1 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 Handler (android.os.Handler)1 RecyclerView (android.support.v7.widget.RecyclerView)1