Search in sources :

Example 41 with GestureDetector

use of android.view.GestureDetector in project BaseProject by feer921.

the class RippleView method init.

/**
 * Method that initializes all fields and sets listeners
 *
 * @param context Context used to create this view
 * @param attrs Attribute used to initialize fields
 */
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
    rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, getResources().getColor(R.color.white));
    rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
    hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
    isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
    rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration);
    frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate);
    rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha);
    ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
    canvasHandler = new Handler();
    zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
    zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
    typedArray.recycle();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);
    this.setWillNotDraw(false);
    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {

        @Override
        public void onLongPress(MotionEvent event) {
            super.onLongPress(event);
            animateRipple(event);
            sendClickEvent(true);
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
    this.setDrawingCacheEnabled(true);
    this.setClickable(true);
}
Also used : TypedArray(android.content.res.TypedArray) Handler(android.os.Handler) GestureDetector(android.view.GestureDetector) Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 42 with GestureDetector

use of android.view.GestureDetector in project AndroidStudy by tinggengyan.

the class LongPressedTextView method init.

private void init() {
    gestureListener = new GestureDetector.SimpleOnGestureListener() {

        @Override
        public void onLongPress(MotionEvent e) {
            if (pressedChangedListener != null) {
                pressedChangedListener.onLongPress();
            }
        }
    };
    gestureDetector = new GestureDetector(getContext(), gestureListener);
}
Also used : GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 43 with GestureDetector

use of android.view.GestureDetector in project MyApp by MatthewDevelop.

the class BaseSetupActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    preference = getSharedPreferences("config", MODE_PRIVATE);
    mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

        /**
         * 监听手势滑动事件
         * @param e1 手势滑动的起点
         * @param e2 手势滑动的终点
         * @param velocityX 水平速度
         * @param velocityY 垂直速度
         * @return
         */
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // 判断纵向滑动幅度是否过大,过大则不切换界面
            if (Math.abs(e2.getRawY() - e1.getRawY()) > 100) {
                return true;
            }
            // 判断用户的滑动速度是否过慢
            if (Math.abs(velocityX) < 100) {
                return true;
            }
            // 向右划,到上一页
            if ((e2.getRawX() - e1.getRawX()) > 200) {
                showPreviousPage();
                return true;
            }
            // 向左划,下一页
            if ((e1.getRawX() - e2.getRawX()) > 200) {
                showNextPage();
                return true;
            }
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    });
}
Also used : GestureDetector(android.view.GestureDetector) MotionEvent(android.view.MotionEvent)

Example 44 with GestureDetector

use of android.view.GestureDetector in project GomoTest by suReZj.

the class ImageViewTouch method init.

@Override
protected void init() {
    super.init();
    mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    mGestureListener = getGestureListener();
    mScaleListener = getScaleListener();
    mScaleDetector = new ScaleGestureDetector(getContext(), mScaleListener);
    mGestureDetector = new GestureDetector(getContext(), mGestureListener, null, true);
    mDoubleTapDirection = 1;
}
Also used : GestureDetector(android.view.GestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector) ScaleGestureDetector(android.view.ScaleGestureDetector)

Example 45 with GestureDetector

use of android.view.GestureDetector in project quran_android by quran.

the class QuranImagePageLayout method setPageController.

@Override
public void setPageController(PageController controller, int pageNumber) {
    super.setPageController(controller, pageNumber);
    final GestureDetector gestureDetector = new GestureDetector(context, new PageGestureDetector());
    OnTouchListener gestureListener = (v, event) -> gestureDetector.onTouchEvent(event);
    imageView.setOnTouchListener(gestureListener);
    imageView.setClickable(true);
    imageView.setLongClickable(true);
}
Also used : Context(android.content.Context) GestureDetector(android.view.GestureDetector) AyahSelectedListener(com.quran.labs.androidquran.ui.helpers.AyahSelectedListener) MotionEvent(android.view.MotionEvent) PageController(com.quran.labs.androidquran.ui.util.PageController) View(android.view.View) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) NonNull(android.support.annotation.NonNull) GestureDetector(android.view.GestureDetector)

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