Example usage for android.view GestureDetector setIsLongpressEnabled

List of usage examples for android.view GestureDetector setIsLongpressEnabled

Introduction

In this page you can find the example usage for android.view GestureDetector setIsLongpressEnabled.

Prototype

public void setIsLongpressEnabled(boolean isLongpressEnabled) 

Source Link

Document

Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further.

Usage

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private GestureDetector getOneFingerGestureDetector(final XYPlot plot) {
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override/*from   ww w .  java  2  s  . c  om*/
        public boolean onDown(MotionEvent motionEvent) {
            // Return true since the framework is weird:
            // http://stackoverflow.com/questions/4107565/on-android-do-gesture-events-work-on-the-emulator
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            double targetMinX;
            double targetMaxX;
            if (minX == originalMinX && maxX == originalMaxX) {
                // Reset zoom to two most recent days
                targetMaxX = originalMaxX;
                targetMinX = targetMaxX - History.deltaMsToDouble(86400 * 1000 * 2);
            } else {
                // Reset zoom to max out
                targetMinX = originalMinX;
                targetMaxX = originalMaxX;
            }

            animateXrange(plot, targetMinX, targetMaxX);

            return true;
        }

        @Override
        public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float dx, float dy) {
            scrollSideways(plot, dx);

            plot.setDomainBoundaries(minX, maxX, BoundaryMode.FIXED);
            redrawPlot(plot);
            return true;
        }
    };

    final GestureDetector gestureDetector = new GestureDetector(getActivity(), gestureListener);
    gestureDetector.setIsLongpressEnabled(false);
    gestureDetector.setOnDoubleTapListener(gestureListener);

    return gestureDetector;
}