List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:me.jreilly.JamesTweet.Dashboard.DashActivity.java
/** * Initializes the navigation drawer and its contents *//*from ww w.j ava2 s . co m*/ public void initDrawer() { //Find the view id mDrawerView = (RecyclerView) findViewById(R.id.left_drawer); //Drawer size is fixed mDrawerView.setHasFixedSize(true); //Add List Dividers mDrawerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST)); //Initialize the Nav Adapter to populate the drawer mAdapter = new NavAdapter(navItems, this, mUsername, mprofileUrl); mActivity = this; mDrawerView.setAdapter(mAdapter); //Detect swipe to open navigation drawer final GestureDetector mGestureDetector = new GestureDetector(DashActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); //Detect Item CLicks and respond accordingly mDrawerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { View child = rv.findChildViewUnder(e.getX(), e.getY()); if (child != null && mGestureDetector.onTouchEvent(e)) { if (rv.getChildPosition(child) == 0) { swapToProfile(); } else if (navItems[rv.getChildPosition(child) - 1].equals("Timeline")) { swapToTimeline(); } else if (navItems[rv.getChildPosition(child) - 1].equals("Mentions")) { mDrawer.closeDrawers(); getSupportFragmentManager().beginTransaction() .replace(R.id.content_frame, new MentionsFragment()).commit(); } else if (navItems[rv.getChildPosition(child) - 1].equals("Favorites")) { mDrawer.closeDrawers(); getSupportFragmentManager().beginTransaction() .replace(R.id.content_frame, new FavoritesFragment()).commit(); } else if (navItems[rv.getChildPosition(child) - 1].equals("Settings")) { Intent intent = new Intent(mActivity, SettingsActivity.class); startActivity(intent); } return true; } return false; } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { } }); mLayoutManager = new LinearLayoutManager(this); mDrawerView.setLayoutManager(mLayoutManager); mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, this.toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); } }; mDrawer.setDrawerListener(mDrawerToggle); mDrawerToggle.syncState(); }
From source file:org.totschnig.myexpenses.activity.ManageCategories.java
@Override public void onCreate(Bundle savedInstanceState) { Intent intent = getIntent();/*from w w w .j a va 2s .c o m*/ String action = intent.getAction(); int title = 0; switch (action == null ? "" : action) { case Intent.ACTION_MAIN: case "myexpenses.intent.manage.categories": helpVariant = HelpVariant.manage; title = R.string.pref_manage_categories_title; break; case "myexpenses.intent.distribution": helpVariant = HelpVariant.distribution; //title is set in categories list break; case "myexpenses.intent.select_filter": helpVariant = HelpVariant.select_filter; title = R.string.search_category; break; default: helpVariant = HelpVariant.select_mapping; title = R.string.select_category; } setTheme(helpVariant.equals(HelpVariant.distribution) ? MyApplication.getThemeId() : MyApplication.getThemeIdEditDialog()); super.onCreate(savedInstanceState); if (helpVariant.equals(HelpVariant.distribution)) { DisplayMetrics dm = getResources().getDisplayMetrics(); final int REL_SWIPE_MIN_DISTANCE = (int) (SWIPE_MIN_DISTANCE * dm.densityDpi / 160.0f); final int REL_SWIPE_MAX_OFF_PATH = (int) (SWIPE_MAX_OFF_PATH * dm.densityDpi / 160.0f); final int REL_SWIPE_THRESHOLD_VELOCITY = (int) (SWIPE_THRESHOLD_VELOCITY * dm.densityDpi / 160.0f); mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { //http://stackoverflow.com/questions/937313/android-basic-gesture-detection try { if (Math.abs(e1.getY() - e2.getY()) > REL_SWIPE_MAX_OFF_PATH) return false; if (e1.getX() - e2.getX() > REL_SWIPE_MIN_DISTANCE && Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) { mListFragment.forward(); return true; } else if (e2.getX() - e1.getX() > REL_SWIPE_MIN_DISTANCE && Math.abs(velocityX) > REL_SWIPE_THRESHOLD_VELOCITY) { mListFragment.back(); return true; } } catch (Exception e) { } return false; } }); } setContentView(R.layout.select_category); setupToolbar(true); if (title != 0) getSupportActionBar().setTitle(title); FragmentManager fm = getSupportFragmentManager(); mListFragment = ((CategoryList) fm.findFragmentById(R.id.category_list)); if (helpVariant.equals(HelpVariant.select_mapping) || helpVariant.equals(HelpVariant.manage)) { configureFloatingActionButton(R.string.menu_create_main_cat); } else { findViewById(R.id.CREATE_COMMAND).setVisibility(View.GONE); } }
From source file:com.tjw.selectimage.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;//from w ww. ja v a 2s . c o m imageView.setOnTouchListener(this); imageView.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 (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.om.snipit.activities.BarcodeCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from w w w. j a va 2s. com*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_barcode_capture); ButterKnife.bind(this); //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); setupToolbar(toolbar, getString(R.string.barcode_capture_activity), true, Constants.DEFAULT_ACTIVITY_TOOLBAR_COLORS); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(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, R.string.capture_barcode_instructions, Snackbar.LENGTH_INDEFINITE).show(); }
From source file:com.github.chrisbanes.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;//w w w .j ava2s. c o m imageView.setOnTouchListener(this); imageView.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 (mOnClickListener != null) { mOnClickListener.onClick(mImageView); } final RectF displayRect = getDisplayRect(); final float x = e.getX(), y = e.getY(); if (mViewTapListener != null) { mViewTapListener.onViewTap(mImageView, x, y); } if (displayRect != null) { // 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.cpen321.fridgemanager.OcrReader.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//* www . ja va 2 s . c o m*/ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); // Get Text if (getIntent().getStringArrayListExtra("texts") == null) { texts = new ArrayList<>(); } else { texts = getIntent().getStringArrayListExtra("texts"); } mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. 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 Scan After Seeing Text Overlays. Pinch to Zoom.", Snackbar.LENGTH_LONG).show(); SharedPreferences settings = getSharedPreferences("prefs", 0); boolean firstCamera = settings.getBoolean("firstCamera", false); if (firstCamera == false) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("firstCamera", true); editor.commit(); showFirstTimeDialog(); } }
From source file:com.gmartinsribeiro.qrcodereader.BarcodeCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *///from ww w. j av a 2s .com @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.barcode_capture); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); if (Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(getResources().getColor(R.color.blue700)); } mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(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, "Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); }
From source file:it.jaschke.alexandria.BarcodeScanner.BarcodeCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from ww w. j ava2s. com*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.barcode_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(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, getApplicationContext().getString(R.string.tap_directions), Snackbar.LENGTH_INDEFINITE).show(); }
From source file:com.library.core.view.HorizontalListView.java
private synchronized void initView() { mLeftViewIndex = -1;// w w w .j a va 2 s . c om mRightViewIndex = 0; mDisplayOffset = 0; mCurrentX = 0; mNextX = 0; mFirstPosition = 0; mSpecificPosition = 0; mSpecificLeft = 0; mMaxX = Integer.MAX_VALUE; mMinX = 0;// Integer.MIN_VALUE; mScroller = new Scroller(getContext()); mGesture = new GestureDetector(getContext(), mOnGesture); System.out.println("initView mMaxX = Integer.MAX_VALUE"); }
From source file:com.konker.konkersensors.BarcodeCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from w w w.ja v a 2 s. com*/ @Override public void onCreate(Bundle icicle) { // Obtain the FirebaseAnalytics instance. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); //Bundle bundle = new Bundle(); //bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "BarcodeCaptureActivity"); //bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "activity"); //mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); super.onCreate(icicle); setContentView(R.layout.barcode_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(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(); }