Java Code Examples for android.view.GestureDetector#SimpleOnGestureListener

The following examples show how to use android.view.GestureDetector#SimpleOnGestureListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public EntityView(Context context, Point pos) {
    super(context);

    uuid = UUID.randomUUID();
    position = pos;

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {
            if (hasPanned || hasTransformed || hasReleased) {
                return;
            }

            recognizedLongPress = true;
            if (delegate != null) {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                delegate.onEntityLongClicked(EntityView.this);
            }
        }
    });
}
 
Example 2
Source File: ChartInfoViewHandler.java    From android-kline with Apache License 2.0 6 votes vote down vote up
public ChartInfoViewHandler(BarLineChartBase chart) {
    mChart = chart;
    mDetector = new GestureDetector(mChart.getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
            mIsLongPress = true;
            Highlight h = mChart.getHighlightByTouchPoint(e.getX(), e.getY());
            if (h != null) {
                mChart.highlightValue(h, true);
                mChart.disableScroll();
            }
        }

    });
}
 
Example 3
Source File: BannerView.java    From YCBanner with Apache License 2.0 6 votes vote down vote up
private void initGestureDetector() {
    //手势处理
    mGestureDetector = new GestureDetector(getContext(),
            new GestureDetector.SimpleOnGestureListener(){
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (mOnItemClickListener!=null){
                if (mAdapter instanceof AbsLoopPagerAdapter){
                    int count = ((AbsLoopPagerAdapter) mAdapter).getRealCount();
                    if (count<=1){

                    }else {

                    }
                    int i = mViewPager.getCurrentItem() % count;
                    Log.d("轮播图",count+"---"+i+"-----"+mViewPager.getCurrentItem());
                    mOnItemClickListener.onItemClick(i);
                }else {
                    mOnItemClickListener.onItemClick(mViewPager.getCurrentItem());
                }
            }
            return super.onSingleTapUp(e);
        }
    });
}
 
Example 4
Source File: MiniPlayerFragment.java    From Phonograph with GNU General Public License v3.0 6 votes vote down vote up
public FlingPlayBackController(Context context) {
    flingPlayBackController = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (Math.abs(velocityX) > Math.abs(velocityY)) {
                if (velocityX < 0) {
                    MusicPlayerRemote.playNextSong();
                    return true;
                } else if (velocityX > 0) {
                    MusicPlayerRemote.playPreviousSong();
                    return true;
                }
            }
            return false;
        }
    });
}
 
Example 5
Source File: EntityView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public EntityView(Context context, Point pos) {
    super(context);

    uuid = UUID.randomUUID();
    position = pos;

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {
            if (hasPanned || hasTransformed || hasReleased) {
                return;
            }

            recognizedLongPress = true;
            if (delegate != null) {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                delegate.onEntityLongClicked(EntityView.this);
            }
        }
    });
}
 
Example 6
Source File: PhotoViewAttacher.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    mRotateGestureDetector = new RotateGestureDetector(imageView.getContext(), this);

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 7
Source File: NewTabPageScrollView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor needed to inflate from XML.
 */
public NewTabPageScrollView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mGestureDetector = new GestureDetector(
            getContext(), new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    boolean retVal = super.onSingleTapUp(e);
                    requestFocus();
                    return retVal;
                }
            });
}
 
Example 8
Source File: PhotoViewAttacher.java    From zen4android with MIT License 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(this);

    // Finally, update the UI so that we're zoomable
    setZoomable(true);
}
 
Example 9
Source File: OnItemSelectedListener.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
protected OnItemSelectedListener(Context context) {
    gestureDetector = new GestureDetector(context,
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }
            });
}
 
Example 10
Source File: SpinnerNoSwipe.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
private void setup() {
    mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return performClick();
        }
    });
}
 
Example 11
Source File: CatalogListActivity.java    From android-migrate-to-jobs with Apache License 2.0 5 votes vote down vote up
public OnCatalogItemTouchListener() {
    mGestureDetector = new GestureDetector(getBaseContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent me) {
            return true;
        }
    });
}
 
Example 12
Source File: PhotoViewAttacher.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView) {
    mImageView = new WeakReference<ImageView>(imageView);

    imageView.setOnTouchListener(this);

    mViewTreeObserver = imageView.getViewTreeObserver();
    mViewTreeObserver.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (!imageView.isInEditMode()) {
        // Create Gesture Detectors...
        mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this);

        mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() {

            // forward long click listener
            @Override
            public void onLongPress(MotionEvent e) {
                if (null != mLongClickListener) {
                    mLongClickListener.onLongClick(mImageView.get());
                }
            }
        });

        mGestureDetector.setOnDoubleTapListener(this);

        // Finally, update the UI so that we're zoomable
        setZoomable(true);
    }
}
 
Example 13
Source File: PhotoViewAttacher.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 14
Source File: RecyclerItemClickListener.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
}
 
Example 15
Source File: BasicGestureDetectFragment.java    From android-BasicGestureDetect with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    View gestureView = getActivity().findViewById(R.id.sample_output);
    gestureView.setClickable(true);
    gestureView.setFocusable(true);

    // BEGIN_INCLUDE(init_detector)

    // First create the GestureListener that will include all our callbacks.
    // Then create the GestureDetector, which takes that listener as an argument.
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener();
    final GestureDetector gd = new GestureDetector(getActivity(), gestureListener);

    /* For the view where gestures will occur, create an onTouchListener that sends
     * all motion events to the gesture detector.  When the gesture detector
     * actually detects an event, it will use the callbacks you created in the
     * SimpleOnGestureListener to alert your application.
    */

    gestureView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            return false;
        }
    });
    // END_INCLUDE(init_detector)
}
 
Example 16
Source File: PhotoViewAttacher.java    From Android with MIT License 4 votes vote down vote up
public PhotoViewAttacher(ImageView imageView, boolean zoomable) {
    mImageView = new WeakReference<>(imageView);

    imageView.setDrawingCacheEnabled(true);
    imageView.setOnTouchListener(this);

    ViewTreeObserver observer = imageView.getViewTreeObserver();
    if (null != observer)
        observer.addOnGlobalLayoutListener(this);

    // Make sure we using MATRIX Scale Type
    setImageViewScaleTypeMatrix(imageView);

    if (imageView.isInEditMode()) {
        return;
    }
    // Create Gesture Detectors...
    mScaleDragDetector = VersionedGestureDetector.newInstance(
            imageView.getContext(), this);

    mGestureDetector = new GestureDetector(imageView.getContext(),
            new GestureDetector.SimpleOnGestureListener() {

                // forward long click listener
                @Override
                public void onLongPress(MotionEvent e) {
                    if (null != mLongClickListener) {
                        mLongClickListener.onLongClick(getImageView());
                    }
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2,
                                       float velocityX, float velocityY) {
                    if (mSingleFlingListener != null) {
                        if (getScale() > DEFAULT_MIN_SCALE) {
                            return false;
                        }

                        if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH
                                || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) {
                            return false;
                        }

                        return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
                    }
                    return false;
                }
            });

    mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this));
    mBaseRotation = 0.0f;

    // Finally, update the UI so that we're zoomable
    setZoomable(zoomable);
}
 
Example 17
Source File: CustomSwipeRefreshLayout.java    From NewFastFrame with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context
 * @param attrs
 */
public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            //                                如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
            return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);

        }
    });
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(
            android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    if (((IAdaptScreen) getContext()).cancelAdapt()) {
        mCircleDiameter = (int) (MaterialProgressDrawable.CIRCLE_DIAMETER_LARGE * metrics.density);
    } else {
        mCircleDiameter = (int) (MaterialProgressDrawable.CIRCLE_DIAMETER * metrics.density);
    }

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
    mTotalDragDistance = mSpinnerOffsetEnd;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    mOriginalOffsetTop = mCurrentTargetOffsetTop = -mCircleDiameter;
    moveToStart(1.0f);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}
 
Example 18
Source File: MoveableImageView.java    From VideoMeeting with Apache License 2.0 4 votes vote down vote up
public MoveableImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mScaleMatrix = new Matrix();
    setScaleType(ScaleType.MATRIX);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    direct = 0;
    present_x = 0;
    last_x = 0;

    // 双击事件,单击事件
    mGestureDetector = new GestureDetector(context,
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDoubleTap(MotionEvent event) {
                    if (scale_ing)
                        return true;

                    Log.v("Double Tap", "Double Tap");

                    float x = event.getX();
                    float y = event.getY();

                    if (getScale() < mMidScale) {
                        // 触发动画
                        scale_ing = true;
                        postDelayed(new ScaleAnimation(mMidScale, x, y), 10);

                    } else {
                        // 触发动画
                        scale_ing = true;
                        postDelayed(new ScaleAnimation(mInitScale, x, y),
                                10);
                    }

                    return true;
                }

                @Override
                public boolean onSingleTapUp(MotionEvent e) {

                    if (scale_ing)
                        return true;
                    if (mOnSingleTouchListener != null){
                        mOnSingleTouchListener.onSingleTouch(
                                MoveableImageView.this, e,singleTap);
                        singleTap = !singleTap;
                    }
                    Log.v("Single Tap", "Single Tap");
                    return false;
                }

            });

    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    setOnTouchListener(this);

}
 
Example 19
Source File: WebViewActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }



        String url = getIntent().getStringExtra(EXTRA_URL);
        this.url = url;
        toolbar.setTitle(url);
        webLayout = new WebLayout(this);
        String[] imageUrls = {};


        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(container, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .setWebChromeClient(mWebChromeClient)
                .setWebViewClient(mWebViewClient)
                .setWebLayout(webLayout)
                .addJavascriptInterface("imagelistener",new MJavascriptInterface(WebViewActivity.this,imageUrls,webView))
                .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
                .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时,弹窗咨询用户是否前往其他应用
                .interceptUnkownUrl() //拦截找不到相关页面的Scheme
                .createAgentWeb()
                .ready()
//                .get();
                .go(url);


        WebSettings webSettings = mAgentWeb.getAgentWebSettings().getWebSettings();
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕        ☆☆
        webSettings.setDisplayZoomControls(true);
        webSettings.setUseWideViewPort(true);


        webSettings.setUserAgentString("Mozilla/5.0 (Windows Phone 10.0; Android 9.1; Microsoft; Lumia 950 XL Dual SIM; KaiOS; Java) Gecko/68 Firefox/68 SearchCraft/2.8.2 baiduboxapp/4.3.0.10");

//        mAgentWeb.getUrlLoader().loadUrl(url);

//        mAgentWeb.getUrlLoader().loadDataWithBaseURL(url,"<script src=\"https://focus.com/nolimit.js\"></script>",null,"utf-8",null);


        /*webView.requestDisallowInterceptTouchEvent(false);
        webView.setWebViewClient(new WebViewClient());
        */
/*        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);*/
//        webView.loadUrl(url);
//        webView.loadData();




        //双击顶栏回顶部事件
        final GestureDetector gestureDetector1 = new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                mAgentWeb.getWebCreator().getWebView().scrollTo(0,0);
                return super.onDoubleTap(e);
            }
        });


        toolbar.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return gestureDetector1.onTouchEvent(motionEvent);
            }
        });
    }
 
Example 20
Source File: GestureListenerWrapper.java    From fresco with MIT License 4 votes vote down vote up
public void setListener(GestureDetector.SimpleOnGestureListener listener) {
  mDelegate = listener;
}