List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:com.maxleap.mall.fragments.MainFragment.java
private void initBanner(final View view) { RelativeLayout bannerLayout = (RelativeLayout) view.findViewById(R.id.banner_layout); bannerLayout.setVisibility(View.GONE); if (mBanners == null) { mBanners = new ArrayList<Banner>(); }/*from ww w.jav a 2s . c o m*/ if (mBanners.isEmpty()) { fetchBannerData(bannerLayout); } else { bannerLayout.setVisibility(View.VISIBLE); } viewPager = (ViewPager) view.findViewById(R.id.head_view_pager); mBannerAdapter = new BannerAdapter(mContext, mBanners); viewPager.setAdapter(mBannerAdapter); final Indicator indicatorLayout = (Indicator) view.findViewById(R.id.head_indicator_layout); indicatorLayout.setCount(mBanners.size()); indicatorLayout.select(0); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { indicatorLayout.select(position); } @Override public void onPageScrollStateChanged(int state) { mSwipeRefreshLayout.setEnabled(state == ViewPager.SCROLL_STATE_IDLE); } }); final GestureDetector tapGestureDetector = new GestureDetector(getActivity(), new TapGestureListener()); viewPager.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { tapGestureDetector.onTouchEvent(event); return false; } }); }
From source file:io.asv.mtgocr.ocrreader.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *///from w w w . j a v a 2s . co m @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.ocr_capture); //region asv imgBgCard = (ImageView) findViewById(R.id.imgBgCard); btnOk = (Button) findViewById(R.id.btnOk); btnCancel = (Button) findViewById(R.id.btnCancel); fabOcr = (FloatingActionButton) findViewById(R.id.fabOcr); txtSearch = (EditText) findViewById(R.id.txtSearch); lytSearch = (RelativeLayout) findViewById(R.id.lytSearch); lytRecycler = (RelativeLayout) findViewById(R.id.lytRecycler); topLayout = (LinearLayout) findViewById(R.id.topLayout); btnOk.setOnClickListener(this); btnCancel.setOnClickListener(this); fabOcr.setOnClickListener(this); //mnu1 //endregion 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(App.INTENT_AUTO_FOCUS, false); boolean useFlash = getIntent().getBooleanExtra(App.INTENT_USE_FLASH, false); mPersistorMode = getIntent().getStringExtra(App.INTENT_PERSISTOR_MODE); loadPersistModeDataCardInfo(); //region RecyclerView setUpRecyclerView(); lytRecycler.setVisibility(View.VISIBLE); fabOcr.setVisibility(View.VISIBLE); topLayout.setVisibility(View.GONE); //endregion showPersistorUI(); //region 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(); } //endregion gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); }
From source file:com.svpino.longhorn.fragments.StockListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_stock_list, container, false); setHasOptionsMenu(true);/*from w ww .ja v a 2 s. co m*/ if (isHoneycombOrLater()) { this.actionModeCallback = new ActionModeCallback(); } this.tableLayout = (TableLayout) view.findViewById(R.id.tableLayout); this.viewFlipper = (ViewFlipper) view.findViewById(R.id.viewFlipper); StockOverviewLayout stockOverviewLayout1 = new StockOverviewLayout(getActivity()); StockOverviewLayout stockOverviewLayout2 = new StockOverviewLayout(getActivity()); this.viewFlipper.addView(stockOverviewLayout1); this.viewFlipper.addView(stockOverviewLayout2); this.animateStockOverviewContentCallback = new AnimateStockOverviewContentCallback(); this.flipInNextAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.flip_in_next); this.flipInNextAnimation .setAnimationListener(new StockOverviewAnimationListener(this.animateStockOverviewContentCallback)); this.flipInPreviousAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.flip_in_previous); this.flipInPreviousAnimation .setAnimationListener(new StockOverviewAnimationListener(this.animateStockOverviewContentCallback)); this.flipOutNextAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.flip_out_next); this.flipOutPreviousAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.flip_out_previous); this.viewFlipperGestureDetector = new GestureDetector(getActivity(), new ViewFlipperGestureDetector()); this.viewFlipper.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (StockListFragment.this.viewFlipperGestureDetector.onTouchEvent(event)) { return false; } return true; } }); createDashboardTiles(true); return view; }
From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java
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); }/* ww w. j a v a 2 s . co m*/ // 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); }
From source file:de.dmxcontrol.activity.ControlActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); SWIPE_MIN_VELOCITY = this.getResources().getInteger(R.integer.swipe_min_velocity); SWIPE_MIN_DISTANCE = this.getResources().getInteger(R.integer.swipe_min_distance); //Change the EdgeEffectColor to our HighlightColor int glowDrawableId = this.getResources().getIdentifier("overscroll_glow", "drawable", "android"); Drawable androidGlow = this.getResources().getDrawable(glowDrawableId); androidGlow.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight), PorterDuff.Mode.SRC_IN);/* www .jav a 2 s .c o m*/ int edgeDrawableId = this.getResources().getIdentifier("overscroll_edge", "drawable", "android"); Drawable androidEdge = this.getResources().getDrawable(edgeDrawableId); androidEdge.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight), PorterDuff.Mode.SRC_IN); int scrollBarHDrawableId = this.getResources().getIdentifier("scrollbar_handle_horizontal", "drawable", "android"); Drawable androidscrollBarH = this.getResources().getDrawable(scrollBarHDrawableId); androidscrollBarH.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight), PorterDuff.Mode.SRC_IN); int scrollBarVDrawableId = this.getResources().getIdentifier("scrollbar_handle_vertical", "drawable", "android"); Drawable androidscrollBarV = this.getResources().getDrawable(scrollBarVDrawableId); androidscrollBarV.setColorFilter(this.getResources().getColor(R.color.btn_background_highlight), PorterDuff.Mode.SRC_IN); setContentView(R.layout.root_screen_with_selector_drawer); gestureDetector = new GestureDetector(this, this); edgeEffect = new EdgeEffect(this); if (((DMXControlApplication) getApplication()).getJustStarted() && !DISABLE_SPLASH) { showDialog(DIALOG_SPLASH); } ad = new AboutDialogs(this); }
From source file:com.frank.protean.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView) { mImageView = imageView;// w ww . j a v a 2s . co m imageView.setOnTouchListener(this); imageView.addOnLayoutChangeListener(this); if (imageView.isInEditMode()) { return; } mBaseRotation = 0.0f; // Create Gesture Detectors... mScaleDragDetector = new CustomGestureDetector(imageView.getContext(), onGestureListener); 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.ycl.framework.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(final ImageView imageView) { mImageView = new WeakReference<ImageView>(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;/*w w w. ja v a 2 s.c o m*/ } // Create Gesture Detectors... mScaleDragDetector = com.ycl.framework.photoview.gestures.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(true); }
From source file:com.sflib.CustomView.photoview.PhotoViewAttacher.java
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<ImageView>(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;// ww w .j av a 2s . com } // 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); }
From source file:org.solovyev.android.messenger.MainActivity.java
private void initTabs(@Nullable Bundle savedInstanceState) { final ActionBar actionBar = getSupportActionBar(); tabsEnabled = false;/*from ww w . ja v a 2 s.co m*/ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (PrimaryFragment tabFragment : tabFragments) { addTab(tabFragment); } int selectedTab = -1; if (savedInstanceState != null) { selectedTab = savedInstanceState.getInt(SELECTED_TAB, -1); } if (selectedTab >= 0) { actionBar.setSelectedNavigationItem(selectedTab); } gestureDetector = new GestureDetector(this, new SwipeTabsGestureListener()); tabsEnabled = true; // activity created first time => we must select first tab if (selectedTab == -1) { actionBar.setSelectedNavigationItem(0); } }
From source file:android.widget.Gallery.java
public Gallery(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mGestureDetector = new GestureDetector(context, this); mGestureDetector.setIsLongpressEnabled(true); TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Gallery, defStyle, 0); int index = a.getInt(com.android.internal.R.styleable.Gallery_gravity, -1); if (index >= 0) { setGravity(index);/*from w ww . jav a2 s . c o m*/ } int animationDuration = a.getInt(com.android.internal.R.styleable.Gallery_animationDuration, -1); if (animationDuration > 0) { setAnimationDuration(animationDuration); } int spacing = a.getDimensionPixelOffset(com.android.internal.R.styleable.Gallery_spacing, 0); setSpacing(spacing); float unselectedAlpha = a.getFloat(com.android.internal.R.styleable.Gallery_unselectedAlpha, 0.5f); setUnselectedAlpha(unselectedAlpha); a.recycle(); // We draw the selected item last (because otherwise the item to the // right overlaps it) mGroupFlags |= FLAG_USE_CHILD_DRAWING_ORDER; mGroupFlags |= FLAG_SUPPORT_STATIC_TRANSFORMATIONS; }