Search in sources :

Example 11 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project SwipeMenuListView by baoyongzhang.

the class SwipeMenuLayout method init.

private void init() {
    setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mGestureListener = new SimpleOnGestureListener() {

        @Override
        public boolean onDown(MotionEvent e) {
            isFling = false;
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // TODO
            if (Math.abs(e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) {
                isFling = true;
            }
            // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    };
    mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener);
    // BounceInterpolator());
    if (mCloseInterpolator != null) {
        mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator);
    } else {
        mCloseScroller = ScrollerCompat.create(getContext());
    }
    if (mOpenInterpolator != null) {
        mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator);
    } else {
        mOpenScroller = ScrollerCompat.create(getContext());
    }
    LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mContentView.setLayoutParams(contentParams);
    if (mContentView.getId() < 1) {
        mContentView.setId(CONTENT_VIEW_ID);
    }
    mMenuView.setId(MENU_VIEW_ID);
    mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    addView(mContentView);
    addView(mMenuView);
// if (mContentView.getBackground() == null) {
// mContentView.setBackgroundColor(Color.WHITE);
// }
// in android 2.x, MenuView height is MATCH_PARENT is not work.
// getViewTreeObserver().addOnGlobalLayoutListener(
// new OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// setMenuHeight(mContentView.getHeight());
// // getViewTreeObserver()
// // .removeGlobalOnLayoutListener(this);
// }
// });
}
Also used : SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) AbsListView(android.widget.AbsListView) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent)

Example 12 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project AppIntro by apl-devs.

the class AppIntroBase method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(getLayoutId());
    gestureDetector = new GestureDetectorCompat(this, new WindowGestureListener());
    nextButton = findViewById(R.id.next);
    doneButton = findViewById(R.id.done);
    skipButton = findViewById(R.id.skip);
    backButton = findViewById(R.id.back);
    checkButton(nextButton, "next");
    checkButton(doneButton, "done");
    checkButton(skipButton, "skip");
    checkButton(backButton, "back");
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.bottomContainer);
    if (frameLayout != null && isRtl()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            frameLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
        }
    }
    if (isRtl()) {
        (nextButton).setScaleX(-1);
    }
    mVibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
    mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), fragments);
    pager = (AppIntroViewPager) findViewById(R.id.view_pager);
    if (doneButton != null) {
        doneButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(@NonNull View v) {
                if (isVibrateOn) {
                    mVibrator.vibrate(vibrateIntensity);
                }
                Fragment currentFragment = mPagerAdapter.getItem(pager.getCurrentItem());
                boolean isSlideChangingAllowed = handleBeforeSlideChanged();
                if (isSlideChangingAllowed) {
                    handleSlideChanged(currentFragment, null);
                    onDonePressed(currentFragment);
                } else {
                    handleIllegalSlideChangeAttempt();
                }
            }
        });
    }
    if (skipButton != null) {
        skipButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(@NonNull View v) {
                if (isVibrateOn) {
                    mVibrator.vibrate(vibrateIntensity);
                }
                onSkipPressed(mPagerAdapter.getItem(pager.getCurrentItem()));
            }
        });
    }
    if (nextButton != null) {
        nextButton.setOnClickListener(new NextButtonOnClickListener());
    }
    if (backButton != null) {
        backButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (pager.getCurrentItem() > 0) {
                    pager.setCurrentItem(pager.getCurrentItem() - 1);
                }
            }
        });
    }
    pager.setAdapter(this.mPagerAdapter);
    pager.addOnPageChangeListener(new PagerOnPageChangeListener());
    pager.setOnNextPageRequestedListener(this);
    setScrollDurationFactor(DEFAULT_SCROLL_DURATION_FACTOR);
}
Also used : FrameLayout(android.widget.FrameLayout) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 13 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project UltimateAndroid by cymcsg.

the class GestureImageView method init.

/**
     * 初始化
     * @param context
     */
private void init(final Context context) {
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    setScaleType(ScaleType.MATRIX);
    mImageMatrix = new Matrix();
    mScaleGesture = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            float factor = detector.getScaleFactor();
            mImageMatrix.postScale(factor, factor, mCenterX, mCenterY);
            setImageMatrix(mImageMatrix);
            return true;
        }
    });
    mGestureDetector = new GestureDetectorCompat(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            mImageMatrix.postScale(1.f, 1.f, mCenterX, mCenterY);
            setImageMatrix(mImageMatrix);
            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            //setImageMatrix(mImageMatrix);
            return true;
        }

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }
    });
}
Also used : Matrix(android.graphics.Matrix) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetectorCompat(android.support.v4.view.ScaleGestureDetectorCompat) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent)

Example 14 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project BaseRecyclerViewAdapterHelper by CymChad.

the class SimpleClickListener method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    if (recyclerView == null) {
        this.recyclerView = rv;
        this.baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
        mGestureDetector = new GestureDetectorCompat(recyclerView.getContext(), new ItemTouchHelperGestureListener(recyclerView));
    } else if (recyclerView != rv) {
        this.recyclerView = rv;
        this.baseQuickAdapter = (BaseQuickAdapter) recyclerView.getAdapter();
        mGestureDetector = new GestureDetectorCompat(recyclerView.getContext(), new ItemTouchHelperGestureListener(recyclerView));
    }
    if (!mGestureDetector.onTouchEvent(e) && e.getActionMasked() == MotionEvent.ACTION_UP && mIsShowPress) {
        if (mPressedView != null) {
            BaseViewHolder vh = (BaseViewHolder) recyclerView.getChildViewHolder(mPressedView);
            if (vh == null || !isHeaderOrFooterView(vh.getItemViewType())) {
                mPressedView.setPressed(false);
            }
        }
        mIsShowPress = false;
        mIsPrepressed = false;
    }
    return false;
}
Also used : BaseViewHolder(com.chad.library.adapter.base.BaseViewHolder) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat)

Example 15 with GestureDetectorCompat

use of android.support.v4.view.GestureDetectorCompat in project wire-android by wireapp.

the class CircularSeekBar method initAttributes.

/**
     * Initialize the CircularSeekBar with the attributes from the XML style.
     * Uses the defaults defined at the top of this file when an attribute is not specified by the user.
     *
     * @param attrArray TypedArray containing the attributes.
     */
protected void initAttributes(TypedArray attrArray) {
    circleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius, DEFAULT_CIRCLE_X_RADIUS * dpToPxScale);
    circleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius, DEFAULT_CIRCLE_Y_RADIUS * dpToPxScale);
    pointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius, DEFAULT_POINTER_RADIUS * dpToPxScale);
    pointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width, DEFAULT_POINTER_HALO_WIDTH * dpToPxScale);
    pointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width, DEFAULT_POINTER_HALO_BORDER_WIDTH * dpToPxScale);
    circleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width, DEFAULT_CIRCLE_STROKE_WIDTH * dpToPxScale);
    String tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_color);
    if (tempColor != null) {
        try {
            pointerColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerColor = DEFAULT_POINTER_COLOR;
        }
    }
    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color);
    if (tempColor != null) {
        try {
            pointerHaloColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColor = DEFAULT_POINTER_HALO_COLOR;
        }
    }
    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color_ontouch);
    if (tempColor != null) {
        try {
            pointerHaloColorOnTouch = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColorOnTouch = DEFAULT_POINTER_HALO_COLOR_ONTOUCH;
        }
    }
    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_color);
    if (tempColor != null) {
        try {
            circleColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleColor = DEFAULT_CIRCLE_COLOR;
        }
    }
    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_progress_color);
    if (tempColor != null) {
        try {
            circleProgressColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleProgressColor = DEFAULT_CIRCLE_PROGRESS_COLOR;
        }
    }
    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_fill);
    if (tempColor != null) {
        try {
            circleFillColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleFillColor = DEFAULT_CIRCLE_FILL_COLOR;
        }
    }
    pointerAlpha = Color.alpha(pointerHaloColor);
    pointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch, DEFAULT_POINTER_ALPHA_ONTOUCH);
    if (pointerAlphaOnTouch > 255 || pointerAlphaOnTouch < 0) {
        pointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH;
    }
    max = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX);
    progress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS);
    customRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII);
    maintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle, DEFAULT_MAINTAIN_EQUAL_CIRCLE);
    moveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle, DEFAULT_MOVE_OUTSIDE_CIRCLE);
    // Modulo 360 right now to avoid constant conversion
    startAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f)) % 360f);
    endAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f)) % 360f);
    if (MathUtils.floatEqual(startAngle, endAngle)) {
        //startAngle = startAngle + 1f;
        endAngle = endAngle - .1f;
    }
    final GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onSingleClick();
                return true;
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onDoubleClick();
            }
            return super.onDoubleTap(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            if (onArtLongClickListener != null) {
                onArtLongClickListener.onLongClick(CircularSeekBar.this);
            }
        }
    };
    gestureDetector = new GestureDetectorCompat(getContext(), gestureListener);
    gestureDetector.setOnDoubleTapListener(gestureListener);
}
Also used : GestureDetector(android.view.GestureDetector) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) MotionEvent(android.view.MotionEvent)

Aggregations

GestureDetectorCompat (android.support.v4.view.GestureDetectorCompat)33 MotionEvent (android.view.MotionEvent)12 ScaleGestureDetector (android.view.ScaleGestureDetector)8 Paint (android.graphics.Paint)6 Intent (android.content.Intent)5 View (android.view.View)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 GestureDetector (android.view.GestureDetector)4 LayoutInflater (android.view.LayoutInflater)4 OverScroller (android.widget.OverScroller)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3 TextPaint (android.text.TextPaint)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 Link (com.winsonchiu.reader.data.reddit.Link)3 Sort (com.winsonchiu.reader.data.reddit.Sort)3 AdapterLink (com.winsonchiu.reader.links.AdapterLink)3 Activity (android.app.Activity)2