Search in sources :

Example 51 with GestureDetector

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

the class KeyboardView method initGestureDetector.

private void initGestureDetector() {
    if (mGestureDetector == null) {
        mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

            @Override
            public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
                if (mPossiblePoly)
                    return false;
                final float absX = Math.abs(velocityX);
                final float absY = Math.abs(velocityY);
                float deltaX = me2.getX() - me1.getX();
                float deltaY = me2.getY() - me1.getY();
                // Half the keyboard width
                int travelX = getWidth() / 2;
                // Half the keyboard height
                int travelY = getHeight() / 2;
                mSwipeTracker.computeCurrentVelocity(1000);
                final float endingVelocityX = mSwipeTracker.getXVelocity();
                final float endingVelocityY = mSwipeTracker.getYVelocity();
                boolean sendDownKey = false;
                if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
                    if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeRight();
                        return true;
                    }
                } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
                    if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeLeft();
                        return true;
                    }
                } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
                    if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeUp();
                        return true;
                    }
                } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
                    if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeDown();
                        return true;
                    }
                }
                if (sendDownKey) {
                    detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
                }
                return false;
            }
        });
        mGestureDetector.setIsLongpressEnabled(false);
    }
}
Also used : GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 52 with GestureDetector

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

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

the class KeyboardView method initGestureDetector.

private void initGestureDetector() {
    if (mGestureDetector == null) {
        mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

            @Override
            public boolean onFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
                if (mPossiblePoly)
                    return false;
                final float absX = Math.abs(velocityX);
                final float absY = Math.abs(velocityY);
                float deltaX = me2.getX() - me1.getX();
                float deltaY = me2.getY() - me1.getY();
                // Half the keyboard width
                int travelX = getWidth() / 2;
                // Half the keyboard height
                int travelY = getHeight() / 2;
                mSwipeTracker.computeCurrentVelocity(1000);
                final float endingVelocityX = mSwipeTracker.getXVelocity();
                final float endingVelocityY = mSwipeTracker.getYVelocity();
                boolean sendDownKey = false;
                if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
                    if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeRight();
                        return true;
                    }
                } else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
                    if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
                        sendDownKey = true;
                    } else {
                        swipeLeft();
                        return true;
                    }
                } else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
                    if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeUp();
                        return true;
                    }
                } else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
                    if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
                        sendDownKey = true;
                    } else {
                        swipeDown();
                        return true;
                    }
                }
                if (sendDownKey) {
                    detectAndSendKey(mDownKey, mStartX, mStartY, me1.getEventTime());
                }
                return false;
            }
        });
        mGestureDetector.setIsLongpressEnabled(false);
    }
}
Also used : GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 54 with GestureDetector

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

use of android.view.GestureDetector in project MaterialLibrary by DeveloperPaul123.

the class CircularTextView method initialize.

/**
 * Initialize the view.
 */
private void initialize(Context context, AttributeSet attrs) {
    if (isInEditMode()) {
        text = "A";
        colors = new int[3];
        colors[0] = ColorGenerator.getRandomMaterialColor();
        colors[1] = ColorGenerator.getRandomMaterialColor();
        colors[2] = ColorGenerator.getRandomMaterialColor();
    } else {
        colors = new int[ColorGenerator.MATERIAL_COLORS_600.length];
        for (int i = 0; i < ColorGenerator.MATERIAL_COLORS_600.length; i++) {
            colors[i] = Color.parseColor(ColorGenerator.MATERIAL_COLORS_600[i]);
        }
    }
    mTextSize = getDimension(R.dimen.circular_text_size);
    maxTextSize = getDimension(R.dimen.circular_text_size);
    mSize = getDimension(R.dimen.circular_text_view_size);
    cx = mSize / 2;
    cy = cx;
    mPadding = getDimension(R.dimen.circular_text_view_padding);
    oneDp = getDimension(R.dimen.circular_text_view_one_dp);
    textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(mTextSize);
    textPaint.setColor(getResources().getColor(android.R.color.white));
    textPaint.setAntiAlias(true);
    textPaint.setStrokeCap(Paint.Cap.ROUND);
    textPaint.setStrokeWidth(1);
    textPaint.setTextAlign(Paint.Align.CENTER);
    checkMarkPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    checkMarkPaint.setStrokeWidth(2 * oneDp);
    checkMarkPaint.setStyle(Paint.Style.STROKE);
    checkMarkPaint.setColor(getResources().getColor(android.R.color.white));
    checkMarkPaint.setStrokeCap(Paint.Cap.ROUND);
    checkMarkPaint.setAntiAlias(true);
    mColor = colors[new Random().nextInt(colors.length)];
    mSecondColor = getResources().getColor(R.color.circular_text_view_second_color);
    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    backgroundPaint.setColor(mColor);
    backgroundPaint.setAntiAlias(true);
    backgroundPaint.setStrokeCap(Paint.Cap.ROUND);
    textAnimator = ObjectAnimator.ofFloat(this, "mTextSize", 0.0f, maxTextSize);
    textAnimator.setDuration(400);
    evaluator = new ArgbEvaluator();
    isBackShowing = false;
    gestureDetector = new GestureDetector(getContext(), new GestureListener());
}
Also used : Random(java.util.Random) ArgbEvaluator(android.animation.ArgbEvaluator) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

GestureDetector (android.view.GestureDetector)133 MotionEvent (android.view.MotionEvent)46 ScaleGestureDetector (android.view.ScaleGestureDetector)23 Paint (android.graphics.Paint)22 View (android.view.View)22 Scroller (android.widget.Scroller)13 WindowManager (android.view.WindowManager)11 Handler (android.os.Handler)9 TextView (android.widget.TextView)9 SimpleOnGestureListener (android.view.GestureDetector.SimpleOnGestureListener)8 LayoutInflater (android.view.LayoutInflater)8 TypedArray (android.content.res.TypedArray)7 ImageView (android.widget.ImageView)7 ViewConfiguration (android.view.ViewConfiguration)6 OverScroller (android.widget.OverScroller)6 Matrix (android.graphics.Matrix)5 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 SuppressLint (android.annotation.SuppressLint)4 Resources (android.content.res.Resources)4