Example usage for android.view GestureDetector GestureDetector

List of usage examples for android.view GestureDetector GestureDetector

Introduction

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

Prototype

public GestureDetector(Context context, OnGestureListener listener) 

Source Link

Document

Creates a GestureDetector with the supplied listener.

Usage

From source file:org.photosynq.android.photosynq.barcode.BarcodeCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//* w w w. j a va  2 s. c o m*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_barcode_capture);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay);

    // read parameters from intent and preferences
    boolean autoFocus = getIntent().getBooleanExtra(INTENT_AUTOFOCUS, false);
    boolean useFlash;
    if (getIntent().hasExtra(INTENT_FLASH)) {
        useFlash = getIntent().getBooleanExtra(INTENT_FLASH, false);
    } else {
        useFlash = getPreferences(MODE_PRIVATE).getBoolean(getString(R.string.settings_barcode_flash), false);
    }

    mAutoCapture = getIntent().getBooleanExtra(INTENT_AUTOCAPTURE, false);

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    mFlashlightButton = (ImageButton) findViewById(R.id.ib_flashlight);
    mFlashlightButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFlashlight = !mFlashlight;
            switchFlashlight(mFlashlight);
        }
    });

    mFlashlight = useFlash;
    switchFlashlight(mFlashlight);

}

From source file:com.ttxgps.zoom.GestureImageViewTouchListener.java

public GestureImageViewTouchListener(final GestureImageView image, int displayWidth, int displayHeight,
        ViewPager pager) {//ww w . j  a  v  a  2  s .  c om
    super();
    this.image = image;
    mPager = pager;
    this.displayWidth = displayWidth;
    this.displayHeight = displayHeight;

    this.centerX = (float) displayWidth / 2.0f;
    this.centerY = (float) displayHeight / 2.0f;

    this.imageWidth = image.getImageWidth();
    this.imageHeight = image.getImageHeight();

    startingScale = image.getScale();

    currentScale = startingScale;
    lastScale = startingScale;

    boundaryRight = displayWidth;
    boundaryBottom = displayHeight;
    boundaryLeft = 0;
    boundaryTop = 0;

    next.x = image.getImageX();
    next.y = image.getImageY();

    flingListener = new FlingListener();
    flingAnimation = new FlingAnimation();
    zoomAnimation = new ZoomAnimation();
    moveAnimation = new MoveAnimation();

    flingAnimation.setListener(new FlingAnimationListener() {
        @Override
        public void onMove(float x, float y) {
            handleDrag(current.x + x, current.y + y);
        }

        @Override
        public void onComplete() {
        }
    });

    zoomAnimation.setZoom(2.0f);
    zoomAnimation.setZoomAnimationListener(new ZoomAnimationListener() {
        @Override
        public void onZoom(float scale, float x, float y) {
            if (scale <= maxScale && scale >= minScale) {
                handleScale(scale, x, y);
            }
        }

        @Override
        public void onComplete() {
            inZoom = false;
            handleUp();
        }
    });

    moveAnimation.setMoveAnimationListener(new MoveAnimationListener() {

        @Override
        public void onMove(float x, float y) {
            image.setPosition(x, y);
            image.redraw();
        }
    });

    tapDetector = new GestureDetector(image.getContext(), new SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // if (mPager != null
            // && mPager.getOnViewListener() != null) {
            // mPager.getOnViewListener().onDoubleTap();
            // if (image.zoom) {
            // startZoom(e);
            // }
            // }
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // if (mPager != null
            // && mPager.getOnViewListener() != null) {
            // mPager.getOnViewListener().onSingleTapConfirmed();
            // }
            if (!inZoom) {
                if (onClickListener != null) {
                    onClickListener.onClick(image);
                    return true;
                }
            }

            return false;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            // if (mPager != null
            // && mPager.getOnViewListener() != null) {
            // mPager.getOnViewListener().onLongPress();
            // }
            super.onLongPress(e);
        }

    });

    flingDetector = new GestureDetector(image.getContext(), flingListener);
    imageListener = image.getGestureImageViewListener();

    calculateBoundaries();
}

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

private void init(Context context) {
    mSmoothMatrix = new Matrix();
    mPaint = new Paint();
    mPaint.setColor(mBgColor);/*from w w w  .  ja  va  2  s. co  m*/
    mPaint.setStyle(Style.FILL);
    //      setBackgroundColor(mBgColor);

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

    mScaleGestureDetector = new ScaleGestureDetector(context, this);

    setOnTouchListener(this);

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

    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public boolean onDoubleTap(MotionEvent e) {

            if (isAutoScale == true) {
                return true;
            }

            float X = e.getX();
            float Y = e.getY();

            if (getScale() < mMidScale) {

                postDelayed(new AutoScaleRunnable(mMidScale, X, Y), 16);
                isAutoScale = true;

            } else if ((getScale() >= mMidScale) && (getScale() < mMaxScale)) {

                postDelayed(new AutoScaleRunnable(mMaxScale, X, Y), 16);
                isAutoScale = true;

            } else {

                postDelayed(new AutoScaleRunnable(mMinScale, X, Y), 5);
                isAutoScale = true;

            }
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mClickListener != null)
                mClickListener.onClick(ZoomImageView.this);
            return super.onSingleTapUp(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            if (mLongClickListener != null)
                mLongClickListener.onLongClick(ZoomImageView.this);
        }
    });
}

From source file:com.appolica.interactiveinfowindow.InfoWindowManager.java

/**
 * Call this method if you are not using
 * {@link com.appolica.interactiveinfowindow.fragment.MapInfoWindowFragment}. If you are calling
 * it from a Fragment we suggest you to call it in {@link Fragment#onViewCreated(View, Bundle)}
 * and if you are calling it from an Activity you should call it in
 * {@link android.app.Activity#onCreate(Bundle)}.
 *
 * @param parent             The parent of your {@link com.google.android.gms.maps.MapView} or
 *                           {@link com.google.android.gms.maps.SupportMapFragment}.
 * @param savedInstanceState The saved state Bundle from your Fragment/Activity.
 *//* w  w w.  j ava 2s  .c o m*/
public void onParentViewCreated(@NonNull final TouchInterceptFrameLayout parent,
        @Nullable final Bundle savedInstanceState) {

    this.parent = parent;
    this.idProvider = new FragmentContainerIdProvider(savedInstanceState);
    this.containerSpec = generateDefaultContainerSpecs(parent.getContext());

    parent.setDetector(new GestureDetector(parent.getContext(), new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            if (isOpen()) {
                centerInfoWindow(currentWindow, currentContainer);
            }

            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            if (isOpen()) {
                if (hideOnFling) {
                    hide(currentWindow);
                } else {
                    centerInfoWindow(currentWindow, currentContainer);
                }
            }

            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {

            if (isOpen()) {
                centerInfoWindow(currentWindow, currentContainer);
            }

            return true;
        }
    }));

    currentContainer = parent.findViewById(idProvider.currentId);

    if (currentContainer == null) {
        currentContainer = createContainer(parent);

        parent.addView(currentContainer);
    }

    final Fragment oldFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_INFO);
    if (oldFragment != null) {
        fragmentManager.beginTransaction().remove(oldFragment).commitNow();
    }

}

From source file:com.bayarchain.OCR.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*  w  ww . j a  v a  2 s  . c om*/
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.ocr_capture2);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);
    demoName = (EditText) findViewById(R.id.editText);
    clear_btn = (Button) findViewById(R.id.clear_button);
    continue_btn = (Button) findViewById(R.id.continue_button);

    continue_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if (!demoName.getText().toString().equals("")) {
                Intent returnIntent = new Intent();
                returnIntent.putExtra("result", demoName.getText().toString().replace("$", ""));
                setResult(Activity.RESULT_OK, returnIntent);
                OcrCaptureActivity.this.finish();
            } else
                Toast.makeText(OcrCaptureActivity.this, "Please enter only numbers!", Toast.LENGTH_SHORT)
                        .show();
        }
    });
    clear_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            demoName.setText("");
        }
    });

    // read parameters from the intent used to launch the activity.
    boolean autoFocus = true;
    boolean useFlash = false;

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
}

From source file:com.example.android.foldinglayout.FoldingLayoutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fold);

    mImageView = (ImageView) findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image));

    if (hasApiLevel(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
        initTextureView();// www.j  a  v a2s.  co m
    }

    mAnchorSeekBar = (SeekBar) findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout) findViewById(R.id.fold_view);
    mFoldLayout.setBackgroundColor(Color.BLACK);
    mFoldLayout.setFoldListener(mOnFoldListener);

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

    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

    mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector());
    mItemSelectedListener = new ItemSelectedListener();

    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();

    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
}

From source file:com.cqyw.goheadlines.widget.horizonListView.HorizontalListView.java

private synchronized void initView() {
    mLeftViewIndex = -1;//from w  ww.j  av  a  2 s. c  om
    mRightViewIndex = 0;
    mDisplayOffset = 0;
    mCurrentX = 0;
    mNextX = 0;
    mMaxX = Integer.MAX_VALUE;
    mScroller = new Scroller(getContext());
    mGesture = new GestureDetector(getContext(), mOnGesture);
}

From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java

public PhotoViewAttacher(ImageView imageView) {
    mImageView = imageView;/* w  ww.ja  v a  2  s  . c  o m*/
    View parent = (View) mImageView.getParent();
    parent.setOnTouchListener(this);
    parent.addOnLayoutChangeListener(this);

    if (imageView.isInEditMode()) {
        return;
    }

    mBaseRotation = 0.0f;

    // Create Gesture Detectors...
    mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), this);

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

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

                @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 GestureDetector.OnDoubleTapListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mIsDragging) {
                return false;
            }
            if (mOnClickListener != null) {
                mOnClickListener.onClick(mImageView);
            }
            final RectF displayRect = getDisplayRect();

            if (displayRect != null) {
                final float x = e.getX(), y = e.getY();

                // Check to see if the user tapped on the photo
                if (displayRect.contains(x, y)) {

                    float xResult = (x - displayRect.left) / displayRect.width();
                    float yResult = (y - displayRect.top) / displayRect.height();

                    if (mPhotoTapListener != null) {
                        mPhotoTapListener.onPhotoTap(mImageView, xResult, yResult);
                    }
                    return true;
                } else {
                    if (mOutsidePhotoTapListener != null) {
                        mOutsidePhotoTapListener.onOutsidePhotoTap(mImageView);
                    }
                }
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent ev) {
            try {
                float scale = getScale();
                float x = ev.getX();
                float y = ev.getY();

                if (scale < getMediumScale()) {
                    setScale(getMediumScale(), x, y, true);
                } else if (scale >= getMediumScale() && scale < getMaximumScale()) {
                    setScale(getMaximumScale(), x, y, true);
                } else {
                    setScale(getMinimumScale(), x, y, true);
                }
            } catch (ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // Wait for the confirmed onDoubleTap() instead
            return false;
        }
    });
}

From source file:com.example.android.enghack_receipt_scanner.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from www .j a  va  2  s .  c o m
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.ocr_capture);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    ActionBar topBar = getSupportActionBar();
    if (topBar != null) {
        topBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6A8347")));
    }

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);

    // read parameters from the intent used to launch the activity.
    boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, true);
    boolean useFlash = getIntent().getBooleanExtra(UseFlash, false);

    // Check for the ocr_capture permission before accessing the ocr_capture.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();
}

From source file:com.example.sherrychuang.splitsmart.Activity.OcrCaptureActivity.java

/**
 * Initializes the UI and creates the detector pipeline.
 *///from w w  w .j  a  v a  2s .com
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.ocr_capture);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);
    itemInputs = new ArrayList<>();
    e = (Event) getIntent().getSerializableExtra("event");
    itemInputsTest = new ArrayList<>();
    String s = "Apple";
    List<Tag> tmp = new ArrayList<Tag>();
    itemInputsTest.add(new ItemInput(false, s, "", tmp));
    // Set good defaults for capturing text.
    itemInputsTest.get(0).setPrice("2");

    ItemAr = new String[itemInputs.size()];
    PriceAr = new String[itemInputs.size()];
    for (int j = 0; j < itemInputs.size(); j++) {
        ItemAr[j] = itemInputs.get(j).getItemName();
        PriceAr[j] = itemInputs.get(j).getPrice();
    }

    boolean autoFocus = true;
    boolean useFlash = false;

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    // TODO: Set up the Text To Speech engine.
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                Log.d("TTS", "Text to speech engine started successfully.");
                tts.setLanguage(Locale.US);
            } else {
                Log.d("TTS", "Error starting the text to speech engine.");
            }
        }
    };
    tts = new TextToSpeech(this.getApplicationContext(), listener);
    //button for saving item and price
    Button btn = (Button) findViewById(R.id.done);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Log.d("OcrCaptureActivity", "done");
            Intent myIntent = new Intent(OcrCaptureActivity.this, BillPage.class);
            myIntent.putExtra("Event", e);
            myIntent.putExtra("ItemInput", ItemAr);
            myIntent.putExtra("PriceInput", PriceAr);
            onPause();
            OcrCaptureActivity.this.startActivity(myIntent);

            /*if(itemInputs!=null) {
            Intent myIntent = new Intent(view.getContext(), BillContentPage.class);
            myIntent.putExtra("ItemInput", itemInputsTest);
            OcrCaptureActivity.this.startActivity(myIntent);
            }*/

        }

    });
}