List of usage examples for android.view ViewConfiguration getScaledTouchSlop
public int getScaledTouchSlop()
From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java
private void setupCallbacks() { ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext()); slop = vc.getScaledTouchSlop(); recyclerView.addItemDecoration(this); recyclerView.addOnItemTouchListener(mOnItemTouchListener); recyclerView.addOnChildAttachStateChangeListener(this); recyclerView.addOnScrollListener(scrollListener); Resources resources = recyclerView.getContext().getResources(); isRtl = resources.getBoolean(R.bool.rtl_enabled); if (recyclerView.getAdapter() == null) { throw new IllegalStateException("SwipeOpenItemTouchHelper.attachToRecyclerView must be called after " + "the RecyclerView's adapter has been set."); } else {// w ww.j a va 2 s.co m recyclerView.getAdapter().registerAdapterDataObserver(adapterDataObserver); } }
From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *//*from w w w.j a va 2 s.co m*/ @SuppressLint("PrivateResource") public IconSwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; TintTypedArray a; a = TintTypedArray.obtainStyledAttributes(context, attrs, android.support.v7.appcompat.R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_thumbTextPadding, 0); /*mSwitchMinWidth = a.getDimensionPixelSize( android.support.v7.appcompat.R.styleable.SwitchCompat_switchMinWidth, 0);*/ mSwitchPadding = a .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_splitTrack, false); final int appearance = a .getResourceId(android.support.v7.appcompat.R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mDrawableManager = AppCompatDrawableManager.get(); a.recycle(); a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.IconSwitchCompat, defStyleAttr, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.IconSwitchCompat_minWidth, 0); Drawable icon = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawable); Drawable iconChecked = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawableChecked); DrawableCompat.setTintList(icon, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor)); DrawableCompat.setTintList(iconChecked, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor)); mIconDrawable = new StateListDrawable(); ((StateListDrawable) mIconDrawable).addState(CHECKED_STATE_SET, iconChecked); ((StateListDrawable) mIconDrawable).addState(new int[] {}, icon); if (mIconDrawable != null) { mIconDrawable.setCallback(this); } /*if (mThumbDrawable != null) { DrawableCompat.setTintList(mThumbDrawable, a.getColorStateList(R.styleable.IconSwitchCompat_thumbColor)); } if (mTrackDrawable != null) { DrawableCompat.setTintList(mTrackDrawable, a.getColorStateList(R.styleable.IconSwitchCompat_trackColor)); }*/ a.recycle(); ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:com.bitflake.counter.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);/*from w ww. j a va 2 s . co m*/ textPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = this.sideItems; try { textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (textColor == null) { textColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, marqueeRepeatLimit); dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt(); boringMetrics = new BoringLayout.Metrics(); boringMetrics.ascent = fontMetricsInt.ascent; boringMetrics.bottom = fontMetricsInt.bottom; boringMetrics.descent = fontMetricsInt.descent; boringMetrics.leading = fontMetricsInt.leading; boringMetrics.top = fontMetricsInt.top; boringMetrics.width = itemWidth; setWillNotDraw(false); flingScrollerX = new OverScroller(context); adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; overscrollDistance = configuration.getScaledOverscrollDistance(); previousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); touchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, touchHelper); }
From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java
public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // create the selector wheel paint TextPaint paint = new TextPaint(); paint.setAntiAlias(true);/* w w w. java 2 s . c om*/ mTextPaint = paint; TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0); CharSequence[] values; int ellipsize = 3; // END default value int sideItems = mSideItems; try { mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor); if (mTextColor == null) { mTextColor = ColorStateList.valueOf(0xFF000000); } values = a.getTextArray(R.styleable.HorizontalPicker_values); ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize); mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit, mMarqueeRepeatLimit); mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize); sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems); float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1); if (textSize > -1) { setTextSize(textSize); } } finally { a.recycle(); } switch (ellipsize) { case 1: setEllipsize(TextUtils.TruncateAt.START); break; case 2: setEllipsize(TextUtils.TruncateAt.MIDDLE); break; case 3: setEllipsize(TextUtils.TruncateAt.END); break; case 4: setEllipsize(TextUtils.TruncateAt.MARQUEE); break; } Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt(); mBoringMetrics = new BoringLayout.Metrics(); mBoringMetrics.ascent = fontMetricsInt.ascent; mBoringMetrics.bottom = fontMetricsInt.bottom; mBoringMetrics.descent = fontMetricsInt.descent; mBoringMetrics.leading = fontMetricsInt.leading; mBoringMetrics.top = fontMetricsInt.top; mBoringMetrics.width = mItemWidth; setWillNotDraw(false); mFlingScrollerX = new OverScroller(context); mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f)); // initialize constants ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mOverscrollDistance = configuration.getScaledOverscrollDistance(); mPreviousScrollerX = Integer.MIN_VALUE; setValues(values); setSideItems(sideItems); mTouchHelper = new PickerTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); }
From source file:com.quran.labs.androidquran.widgets.SlidingUpPanelLayout.java
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { mShadowDrawable = null;/*from w ww. j a v a 2 s. com*/ mScrollTouchSlop = 0; mDragHelper = null; return; } if (attrs != null) { TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS); if (defAttrs != null) { int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY); if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) { throw new IllegalArgumentException("gravity must be set to either top or bottom"); } mIsSlidingUp = gravity == Gravity.BOTTOM; } defAttrs.recycle(); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout); if (ta != null) { mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1); mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1); mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_parallaxOffset, -1); mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY); mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR); mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1); mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay, DEFAULT_OVERLAY_FLAG); mArbitraryPositionEnabled = ta.getBoolean(R.styleable.SlidingUpPanelLayout_arbitraryPosition, DEFAULT_ARBITRARY_POS_FLAG); } ta.recycle(); } final float density = context.getResources().getDisplayMetrics().density; if (mPanelHeight == -1) { mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f); } if (mShadowHeight == -1) { mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f); } if (mParallaxOffset == -1) { mParallaxOffset = (int) (DEFAULT_PARALLAX_OFFSET * density); } // If the shadow height is zero, don't show the shadow if (mShadowHeight > 0) { if (mIsSlidingUp) { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_above_shadow); } else { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_below_shadow); } } else { mShadowDrawable = null; } setWillNotDraw(false); mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback()); mDragHelper.setMinVelocity(mMinFlingVelocity * density); mCanSlide = true; mIsSlidingEnabled = true; ViewConfiguration vc = ViewConfiguration.get(context); mScrollTouchSlop = vc.getScaledTouchSlop(); }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
/** * Construct a new Switch with a default style determined by the given theme * attribute, overriding specific style attributes as requested. * //from ww w. j ava 2 s .c om * @param context * The Context that will determine this widget's theming. * @param attrs * Specification of attributes that should deviate from the * default styling. * @param defStyleAttr * An attribute in the current theme that contains a reference to * a style resource that supplies default values for the view. * Can be 0 to not look for defaults. */ public SmoothSwitch(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); final float density = res.getDisplayMetrics().density; mTextPaint.density = density;//res.getDisplayMetrics().density; final int thumbSize = (int) (Default.DEFAULT_SIZE_DP * density + 0.5f);// truckSize = 15dp final int thumbWidth = thumbSize;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbWidth, thumbSize); mThumbColorOn = Default.DEFAULT_THUMB_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOn, Default.DEFAULT_THUMB_ON_COLOR); mThumbColorOff = Default.DEFAULT_THUMB_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOff, Default.DEFAULT_THUMB_OFF_COLOR); mTrackColorOn = Default.DEFAULT_TRACK_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOn, Default.DEFAULT_TRACK_ON_COLOR); mTrackColorOff = Default.DEFAULT_TRACK_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOff, Default.DEFAULT_TRACK_OFF_COLOR); final float radius = thumbSize * Default.DEFAULT_RADIUS_PERCENT_OF_SIZE;//a.getFloat(R.styleable.SwitchCompat_radiusPercentOfThumbSize, // Default.DEFAULT_RADIUS_PERCENT_OF_SIZE); final int thumbPadding = (int) (thumbSize * Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_thumbPaddingPercentOfThumbSize, // Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE) + 0.5f); final int trackPadding = (int) (thumbSize * Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_trackPaddingPercentOfThumbSize, // Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE) + 0.5f); final int curThumbColor = isChecked() ? mThumbColorOn : mThumbColorOff; final int curTrackColor = isChecked() ? mTrackColorOn : mTrackColorOff; mThumbDrawable = makeThumbDrawable(curThumbColor, thumbWidth, thumbSize, radius, thumbPadding); mTrackDrawable = makeTrackDrawable(curTrackColor, thumbWidth, thumbSize, radius, trackPadding); // final int onDisableColor = getDisableColor(onColor); // final int offDisableColor = getDisableColor(offColor); // final StateListDrawable thumbDrawable = new StateListDrawable(); // thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked}, // makeThumbDrawable(onDisableColor, thumbSize));// Disabled ON // thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked}, // makeThumbDrawable(offDisableColor, thumbSize));// Disabled OFF // thumbDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked }, // makeThumbDrawable(onColor, thumbSize)); // thumbDrawable.addState(new int[] {}, makeThumbDrawable(offColor, thumbSize)); // mThumbDrawable = thumbDrawable; // // final StateListDrawable trackDrawable = new StateListDrawable(); // trackDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked}, // makeTrackDrawable(onDisableColor, thumbSize));// Disabled ON // trackDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked}, // makeTrackDrawable(offDisableColor, thumbSize));// Disabled OFF // trackDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked }, // makeTrackDrawable(onColor, thumbSize)); // trackDrawable.addState(new int[] {}, makeTrackDrawable(offColor, thumbSize)); // mTrackDrawable = trackDrawable; // mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); // mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = false;//a.getBoolean(R.styleable.SwitchCompat_showText, false); mThumbTextPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); // mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchMinWidth = Math.max(mSwitchMinWidth, thumbWidth * 2); mSwitchPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); // mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); // final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); // if (appearance != 0) { // setSwitchTextAppearance(context, appearance); // }else{ // ColorStateList colors = a.getColorStateList(R.styleable.SwitchCompat_switchTextColor); // if (colors != null) { // mTextColors = colors; // } else { // // If no color set in TextAppearance, default to the view's textColor // mTextColors = getTextColors(); // } // float ts = a.getDimension(R.styleable.SwitchCompat_switchTextSize, 0); // if (ts != 0) { // if (ts != mTextPaint.getTextSize()) { // mTextPaint.setTextSize(ts); // requestLayout(); // } // } // } // mTintManager = a.getTintManager(); // a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:jackson.com.slidingmenulib.MyViewDragHelper.java
/** * Apps should use ViewDragHelper.create() to get a new instance. * This will allow VDH to use internal compatibility implementations for different * platform versions./*from www. j av a 2 s . c om*/ * * @param context Context to initialize config-dependent params from * @param forParent Parent view to monitor */ private MyViewDragHelper(Context context, ViewGroup forParent, ViewDragHelper.Callback cb) { if (forParent == null) { throw new IllegalArgumentException("Parent view may not be null"); } if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } mParentView = forParent; mCallback = cb; final ViewConfiguration vc = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mEdgeSize = (int) (EDGE_SIZE * density + 0.5f); mTouchSlop = vc.getScaledTouchSlop(); mMaxVelocity = vc.getScaledMaximumFlingVelocity(); mMinVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = new OverScroller(context, sInterpolator); }
From source file:com.chauthai.swipereveallayout.ViewDragHelper.java
/** * Apps should use ViewDragHelper.create() to get a new instance. * This will allow VDH to use internal compatibility implementations for different * platform versions.//from w w w . j a v a2s. c o m * * @param context Context to initialize config-dependent params from * @param forParent Parent view to monitor */ private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) { if (forParent == null) { throw new IllegalArgumentException("Parent view may not be null"); } if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } mParentView = forParent; mCallback = cb; final ViewConfiguration vc = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mEdgeSize = (int) (EDGE_SIZE * density + 0.5f); mTouchSlop = vc.getScaledTouchSlop(); mMaxVelocity = vc.getScaledMaximumFlingVelocity(); mMinVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = ScrollerCompat.create(context, sInterpolator); }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
private void initWorkspace(Context context, AttributeSet attrs, int defStyle) { Theme theme = context.getTheme();/*from www . java 2 s . co m*/ TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.AviaryWorkspace, defStyle, 0); mDefaultScreen = a.getInt(R.styleable.AviaryWorkspace_aviary_defaultScreen, 0); int overscrollMode = a.getInt(R.styleable.AviaryWorkspace_aviary_overscroll, 0); a.recycle(); setHapticFeedbackEnabled(false); mScrollInterpolator = new DecelerateInterpolator(1.0f); mScroller = new Scroller(context, mScrollInterpolator); mPreviousScreen = INVALID_SCREEN; final ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mPaddingTop = getPaddingTop(); mPaddingBottom = getPaddingBottom(); mPaddingLeft = getPaddingLeft(); mPaddingRight = getPaddingRight(); setOverScroll(overscrollMode); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
/** * Initializes the header and any static values *///from w w w . ja v a 2s. c om private void initialize() { Context context = getContext(); if (!sInitialized) { sInitialized = true; Resources resources = context.getResources(); sCropSize = resources.getDimensionPixelSize(R.dimen.photo_view_crop_width); sCropDimPaint = new Paint(); sCropDimPaint.setAntiAlias(true); sCropDimPaint.setColor(ContextCompat.getColor(context, R.color.photo_view_crop_dim_color)); sCropDimPaint.setStyle(Style.FILL); sCropPaint = new Paint(); sCropPaint.setAntiAlias(true); sCropPaint.setColor(ContextCompat.getColor(context, R.color.photo_view_crop_dim_color)); sCropPaint.setStyle(Style.STROKE); sCropPaint.setStrokeWidth(resources.getDimension(R.dimen.photo_view_crop_stroke_width)); final ViewConfiguration configuration = ViewConfiguration.get(context); final int touchSlop = configuration.getScaledTouchSlop(); sTouchSlopSquare = touchSlop * touchSlop; } mGestureDetector = new GestureDetectorCompat(context, this, null); scaleGestureDetector = new ScaleGestureDetector(context, this); mQuickScaleEnabled = ScaleGestureDetectorCompat.isQuickScaleEnabled(scaleGestureDetector); mScaleRunnable = new ScaleRunnable(this); mTranslateRunnable = new TranslateRunnable(this); mSnapRunnable = new SnapRunnable(this); mRotateRunnable = new RotateRunnable(this); }