List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:com.zirkler.czannotationviewsample.AnnotationView.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); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return;//from w w w . j a v a2s. co m } // 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(), e); } } @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; } }); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
From source file:com.sim2dial.dialer.VideoCallFragment.java
@Override public void onResume() { super.onResume(); if (mVideoView != null) { ((GLSurfaceView) mVideoView).onResume(); }// w w w .j a v a 2s . c o m if (androidVideoWindowImpl != null) { synchronized (androidVideoWindowImpl) { LinphoneManager.getLc().setVideoWindow(androidVideoWindowImpl); } } mGestureDetector = new GestureDetector(inCallActivity, this); mScaleDetector = Compatibility.getScaleGestureDetector(inCallActivity, this); }
From source file:com.nice295.fridgeplease.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//* ww w . j av a 2 s . c om*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_ocr_capture); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); 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, 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(); } mTempItemArray = new ArrayList<String>(); mTags = new ArrayList<Tag>(); mTagsView = (TagView) findViewById(R.id.tags); /* //set click listener tags.setOnTagClickListener(new TagView.OnTagClickListener() { @Override public void onTagClick(Tag tag, int position) { Log.d(TAG, "onTagClick"); } }); //set delete listener tags.setOnTagDeleteListener(new TagView.OnTagDeleteListener() { @Override public void onTagDeleted(final TagView view, final Tag tag, final int position) { Log.d(TAG, "onTagDeleted"); } }); //set long click listener tags.setOnTagLongClickListener(new TagView.OnTagLongClickListener() { @Override public void onTagLongClick(Tag tag, int position) { Log.d(TAG, "onTagLongClick"); } }); */ 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(); */ //Paper.init(this); mDatabase = FirebaseDatabase.getInstance().getReference(); handler = new Handler() { public void handleMessage(Message msg) { synchronized (mTags) { mTagsView.addTags(mTags); } mMenu.findItem(R.id.action_add).setEnabled(true); } }; }
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
/** * Method that initializes all fields and sets listeners * * @param context Context used to create this view * @param attrs Attribute used to initialize fields */// w w w . ja va2 s .c o m private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, Color.parseColor("#33626262")); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); lastLongPressX = (int) event.getX(); lastLongPressY = (int) event.getY(); rippleStatus = RIPPLE_LONG_PRESS; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); }
From source file:com.dl7.commonlib.views.RippleView.java
/** * Method that initializes all fields and sets listeners * * @param context Context used to create this view * @param attrs Attribute used to initialize fields *//*from w w w . ja va2s .com*/ private void init(final Context context, final AttributeSet attrs) { if (isInEditMode()) return; final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView); rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, ContextCompat.getColor(context, R.color.rippelColor)); rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0); hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false); isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false); rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration); frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate); rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha); ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0); canvasHandler = new Handler(); zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f); zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200); isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false); typedArray.recycle(); paint = new Paint(); paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); paint.setColor(rippleColor); paint.setAlpha(rippleAlpha); this.setWillNotDraw(false); gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent event) { super.onLongPress(event); animateRipple(event); sendClickEvent(true); lastLongPressX = (int) event.getX(); lastLongPressY = (int) event.getY(); rippleStatus = RIPPLE_LONG_PRESS; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return true; } @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); this.setDrawingCacheEnabled(true); this.setClickable(true); this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); }
From source file:com.yek.keyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *//*from w w w . j a v a 2 s . co m*/ public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed); mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary); // themed final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId()); int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal); int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended); int colorOther = ContextCompat.getColor(context, R.color.candidate_other); float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height); try { colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal); colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor, colorRecommended); colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther); mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage); final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage); if (stripImage == null) setBackgroundColor(Color.BLACK); else setBackgroundDrawable(stripImage); fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel); } catch (Exception e) { Logger.w(TAG, "Got an exception while reading theme data", e); } mXGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20); a.recycle(); mColorNormal = colorNormal; mColorRecommended = colorRecommended; mColorOther = colorOther; if (mDivider == null) mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider); // end of themed mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(fontSizePixel); mPaint.setStrokeWidth(0); mPaint.setTextAlign(Align.CENTER); mTextPaint = new TextPaint(mPaint); final int minTouchableWidth = context.getResources() .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width); mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth)); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); scrollTo(0, getScrollY()); }
From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DaggerShowComicsComponent.builder().appComponent(((XKCDReaderApp) getApplication()).getComponent()) .showComicsModule(new ShowComicsModule(this)).build().inject(this); setContentView(R.layout.activity_show_comics); ButterKnife.bind(this); // Set the icon for the overview screen. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_overview); final int color = ContextCompat.getColor(this, R.color.primary); setTaskDescription(new ActivityManager.TaskDescription(null, icon, color)); }/*from w w w . j a va2 s. co m*/ setSupportActionBar(toolbar); // Set the correct margin for the overlaying toolbar. final AppBarLayout.LayoutParams layoutParams = new AppBarLayout.LayoutParams( searchToolbar.getLayoutParams()); layoutParams.setMargins(0, -layoutParams.height, 0, 0); searchToolbar.setLayoutParams(layoutParams); comicsAdapter = new ComicsAdapter(getSupportFragmentManager(), this); viewPager.setAdapter(comicsAdapter); viewPager.addOnPageChangeListener(this); searchAdapter = new SearchAdapter(); searchResults.setHasFixedSize(true); searchResults.setLayoutManager(new LinearLayoutManager(this)); searchResults.addItemDecoration(new DividerItemDecoration(this)); searchResults.setAdapter(searchAdapter); searchResults.addOnItemTouchListener(this); gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); tintedBackArrow.setColorFilter(ContextCompat.getColor(this, R.color.primary), PorterDuff.Mode.SRC_ATOP); presenter.attachView(this); if (checkPlayServicesAvailability()) { scheduleTasks(); } }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *//*w w w . java 2 s . c om*/ public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed); mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary); // themed final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId()); int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal); int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended); int colorOther = ContextCompat.getColor(context, R.color.candidate_other); float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height); try { colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal); colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor, colorRecommended); colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther); mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage); final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage); if (stripImage == null) setBackgroundColor(Color.BLACK); else setBackgroundDrawable(stripImage); fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel); } catch (Exception e) { Logger.w(TAG, "Got an exception while reading theme data", e); } mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20); a.recycle(); mColorNormal = colorNormal; mColorRecommended = colorRecommended; mColorOther = colorOther; if (mDivider == null) mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider); // end of themed mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(fontSizePixel); mPaint.setStrokeWidth(0); mPaint.setTextAlign(Align.CENTER); mTextPaint = new TextPaint(mPaint); final int minTouchableWidth = context.getResources() .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width); mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth)); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); scrollTo(0, getScrollY()); }
From source file:uk.org.downiesoft.slideshow.SlideShowActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window win = getWindow();/*from w w w . jav a2 s. com*/ win.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); win.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); win.requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); mUiHider = new UiHider(this); getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(mUiHider); mCacheManager = ThumbnailCacheManager.getInstance(this); SlideShowActivity.debug(1, TAG, "onCreate: %s", savedInstanceState == null ? "null" : savedInstanceState.toString()); setContentView(R.layout.activity_slide_show); PreferenceManager.setDefaultValues(this, R.xml.view_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.slideshow_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.cache_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.wallpaper_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.other_preferences, false); mSlideshowSettings = PreferenceManager.getDefaultSharedPreferences(this); int thumbSize = Integer.parseInt(mSlideshowSettings.getString(getString(R.string.PREFS_THUMBSIZE), "1")); // Hack to convert old hard-coded thumbsize settings to platform dependent sizes if (thumbSize > 2) { thumbSize = thumbSize / 90; SharedPreferences.Editor editor = mSlideshowSettings.edit(); editor.putString(getString(R.string.PREFS_THUMBSIZE), Integer.toString(thumbSize)); editor.apply(); } FragmentManager fm = getFragmentManager(); int cacheLimit = Integer .parseInt(mSlideshowSettings.getString(getString(R.string.PREFS_CACHE_LIMIT), "10")); mPreviewButton = (ImageView) findViewById(R.id.slideShowImageButton); mPreviewView = (FrameLayout) findViewById(R.id.previewContainer); RelativeLayout divider = (RelativeLayout) findViewById(R.id.frameDivider); if (divider != null) { divider.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { return mGestureDetector.onTouchEvent(event) || view.onTouchEvent(event); } }); } mPreviewFragment = (PreviewFragment) fm.findFragmentByTag(PreviewFragment.TAG); if (mPreviewView != null && mPreviewFragment == null) { mPreviewFragment = new PreviewFragment(); fm.beginTransaction().replace(R.id.previewContainer, mPreviewFragment, PreviewFragment.TAG).commit(); } mGridViewFragment = (GridViewFragment) fm.findFragmentByTag(GridViewFragment.TAG); if (mGridViewFragment == null) { mGridViewFragment = new GridViewFragment(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.fragmentContainer, mGridViewFragment, GridViewFragment.TAG); ft.commit(); } mGestureDetector = new GestureDetector(this, new DividerGestureListener()); // restart/stop service as required Intent intent = getIntent(); if (intent != null && intent.getAction() != null && intent.getAction().equals(ACTION_STOP_WALLPAPER) && isServiceRunning()) { stopWallpaperService(); finish(); } else { if (!mSlideshowSettings.getBoolean(getString(R.string.PREFS_WALLPAPER_ENABLE), false)) { if (isServiceRunning()) { stopWallpaperService(); } } else { if (!isServiceRunning()) { Intent startIntent = new Intent(SlideShowActivity.this, WallpaperService.class); startService(startIntent); invalidateOptionsMenu(); } } } mCacheManager.tidyCache(cacheLimit); BitmapManager.setDisplayMetrics(getResources().getDisplayMetrics()); }
From source file:com.masseyhacks.sjam.cheqout.ScannerActivity.java
/** * Initializes the UI and creates the detector pipeline. *///www . j a v a 2s .co m @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scanner); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // GO TO CART Intent intent = new Intent(getApplicationContext(), CartActivity.class); intent.putExtra("items", items); startActivity(intent); } }); items = new LinkedHashMap(); // quantities = new LinkedHashMap(); 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, true); 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(); }