Example usage for android.view ViewConfiguration get

List of usage examples for android.view ViewConfiguration get

Introduction

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

Prototype

public static ViewConfiguration get(Context context) 

Source Link

Document

Returns a configuration for the specified context.

Usage

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*from  www .  j  a v a  2 s .  com*/
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}

From source file:android.improving.utils.views.swipeback.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  www  . jav  a2  s  .  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:android.wuliqing.com.lendphonesystemapp.swipeBack.ViewDragHelper.java

/**
 * Sets the sensitivity of the dragger./*from  w ww . j  a v a  2 s  .co  m*/
 *
 * @param context     The application context.
 * @param sensitivity value between 0 and 1, the final value for touchSlop =
 *                    ViewConfiguration.getScaledTouchSlop * (1 / s);
 */
public void setSensitivity(Context context, float sensitivity) {
    float s = Math.max(0f, Math.min(1.0f, sensitivity));
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    mTouchSlop = (int) (viewConfiguration.getScaledTouchSlop() * (1 / s));
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

public TwoWayView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mNeedSync = false;/*ww w  .j a  v  a 2s . c om*/
    mVelocityTracker = null;

    mLayoutMode = LAYOUT_NORMAL;
    mTouchMode = TOUCH_MODE_REST;
    mLastTouchMode = TOUCH_MODE_UNKNOWN;

    mIsAttached = false;

    mContextMenuInfo = null;

    mOnScrollListener = null;
    mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mOverscrollDistance = getScaledOverscrollDistance(vc);

    mOverScroll = 0;

    mScroller = new Scroller(context);

    mIsVertical = true;

    mItemsCanFocus = false;

    mTempRect = new Rect();

    mArrowScrollFocusResult = new ArrowScrollFocusResult();

    mSelectorPosition = INVALID_POSITION;

    mSelectorRect = new Rect();
    mSelectedStart = 0;

    mResurrectToPosition = INVALID_POSITION;

    mSelectedStart = 0;
    mNextSelectedPosition = INVALID_POSITION;
    mNextSelectedRowId = INVALID_ROW_ID;
    mSelectedPosition = INVALID_POSITION;
    mSelectedRowId = INVALID_ROW_ID;
    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    mChoiceMode = ChoiceMode.NONE;
    mCheckedItemCount = 0;
    mCheckedIdStates = null;
    mCheckStates = null;

    mRecycler = new RecycleBin();
    mDataSetObserver = null;

    mAreAllItemsSelectable = true;

    mStartEdge = null;
    mEndEdge = null;

    setClickable(true);
    setFocusableInTouchMode(true);
    setWillNotDraw(false);
    setAlwaysDrawnWithCacheEnabled(false);
    setWillNotDraw(false);
    setClipToPadding(false);

    ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwoWayView, defStyle, 0);
    initializeScrollbars(a);

    mDrawSelectorOnTop = a.getBoolean(R.styleable.TwoWayView_android_drawSelectorOnTop, false);

    Drawable d = a.getDrawable(R.styleable.TwoWayView_android_listSelector);
    if (d != null) {
        setSelector(d);
    }

    int orientation = a.getInt(R.styleable.TwoWayView_android_orientation, -1);
    if (orientation >= 0) {
        setOrientation(Orientation.values()[orientation]);
    }

    int choiceMode = a.getInt(R.styleable.TwoWayView_android_choiceMode, -1);
    if (choiceMode >= 0) {
        setChoiceMode(ChoiceMode.values()[choiceMode]);
    }

    a.recycle();

    updateScrollbarsDirection();
}

From source file:ayushi.view.customview.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 va  2s. c  o  m*/
 * If the interpolator is null, the default interpolator will be used.
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 * @param interpolator interpolator for scroller
 */
private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interpolator, 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, interpolator != null ? interpolator : sInterpolator);
}

From source file:com.dishes.views.stageredggridview.StaggeredGridView.java

public StaggeredGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView);
        mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTop, false);
        a.recycle();/* ww  w. j  av  a 2s.c o  m*/
    } else {
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }
}

From source file:com.cmg.android.cmgpdf.view.TwoWayView.java

public TwoWayView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mNeedSync = false;//from   w ww. j  av  a  2 s .com
    mVelocityTracker = null;

    mLayoutMode = LAYOUT_NORMAL;
    mTouchMode = TOUCH_MODE_REST;
    mLastTouchMode = TOUCH_MODE_UNKNOWN;

    mIsAttached = false;

    mContextMenuInfo = null;

    mOnScrollListener = null;
    mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mOverscrollDistance = getScaledOverscrollDistance(vc);

    mOverScroll = 0;

    mScroller = new Scroller(context);

    mIsVertical = true;

    mItemsCanFocus = false;

    mTempRect = new Rect();

    mArrowScrollFocusResult = new ArrowScrollFocusResult();

    mSelectorPosition = INVALID_POSITION;

    mSelectorRect = new Rect();
    mSelectedStart = 0;

    mResurrectToPosition = INVALID_POSITION;

    mSelectedStart = 0;
    mNextSelectedPosition = INVALID_POSITION;
    mNextSelectedRowId = INVALID_ROW_ID;
    mSelectedPosition = INVALID_POSITION;
    mSelectedRowId = INVALID_ROW_ID;
    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    mChoiceMode = ChoiceMode.NONE;
    mCheckedItemCount = 0;
    mCheckedIdStates = null;
    mCheckStates = null;

    mRecycler = new RecycleBin();
    mDataSetObserver = null;

    mAreAllItemsSelectable = true;

    mStartEdge = null;
    mEndEdge = null;

    setClickable(true);
    setFocusableInTouchMode(true);
    setWillNotDraw(false);
    setAlwaysDrawnWithCacheEnabled(false);
    setWillNotDraw(false);
    setClipToPadding(false);

    ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwoWayView, defStyle, 0);
    //initializeScrollbars(a);

    mDrawSelectorOnTop = a.getBoolean(R.styleable.TwoWayView_android_drawSelectorOnTop, false);

    Drawable d = a.getDrawable(R.styleable.TwoWayView_android_listSelector);
    if (d != null) {
        setSelector(d);
    }

    int orientation = a.getInt(R.styleable.TwoWayView_android_orientation, -1);
    if (orientation >= 0) {
        setOrientation(Orientation.values()[orientation]);
    }

    int choiceMode = a.getInt(R.styleable.TwoWayView_android_choiceMode, -1);
    if (choiceMode >= 0) {
        setChoiceMode(ChoiceMode.values()[choiceMode]);
    }

    a.recycle();

    updateScrollbarsDirection();
}

From source file:com.av.remusic.widget.RoundViewPager.java

void initViewPager() {
    setWillNotDraw(false);//from   ww  w .j  a  v  a2  s.c  om
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        private final Rect mTempRect = new Rect();

        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) {
            // First let the ViewPager itself try and consume them...
            final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets);
            if (applied.isConsumed()) {
                // If the ViewPager consumed all insets, return now
                return applied;
            }

            // Now we'll manually dispatch the insets to our children. Since ViewPager
            // children are always full-height, we do not want to use the standard
            // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
            // the rest of the children will not receive any insets. To workaround this
            // we manually dispatch the applied insets, not allowing children to
            // consume them from each other. We do however keep track of any insets
            // which are consumed, returning the union of our children's consumption
            final Rect res = mTempRect;
            res.left = applied.getSystemWindowInsetLeft();
            res.top = applied.getSystemWindowInsetTop();
            res.right = applied.getSystemWindowInsetRight();
            res.bottom = applied.getSystemWindowInsetBottom();

            for (int i = 0, count = getChildCount(); i < count; i++) {
                final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i),
                        applied);
                // Now keep track of any consumed by tracking each dimension's min
                // value
                res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left);
                res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top);
                res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right);
                res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom);
            }

            // Now return a new WindowInsets, using the consumed window insets
            return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom);
        }
    });
    isRotating = false;
}

From source file:com.artifex.mupdf.view.ThumbnailViews.java

public ThumbnailViews(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mNeedSync = false;// w w  w .j  av a 2 s. c om
    mVelocityTracker = null;

    mLayoutMode = LAYOUT_NORMAL;
    mTouchMode = TOUCH_MODE_REST;
    mLastTouchMode = TOUCH_MODE_UNKNOWN;

    mIsAttached = false;

    mContextMenuInfo = null;

    mOnScrollListener = null;
    mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mOverscrollDistance = getScaledOverscrollDistance(vc);

    mOverScroll = 0;

    mScroller = new Scroller(context);

    mIsVertical = true;

    mItemsCanFocus = false;

    mTempRect = new Rect();

    mArrowScrollFocusResult = new ArrowScrollFocusResult();

    mSelectorPosition = INVALID_POSITION;

    mSelectorRect = new Rect();
    mSelectedStart = 0;

    mResurrectToPosition = INVALID_POSITION;

    mSelectedStart = 0;
    mNextSelectedPosition = INVALID_POSITION;
    mNextSelectedRowId = INVALID_ROW_ID;
    mSelectedPosition = INVALID_POSITION;
    mSelectedRowId = INVALID_ROW_ID;
    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    mChoiceMode = ChoiceMode.NONE;
    mCheckedItemCount = 0;
    mCheckedIdStates = null;
    mCheckStates = null;

    mRecycler = new RecycleBin();
    mDataSetObserver = null;

    mAreAllItemsSelectable = true;

    mStartEdge = null;
    mEndEdge = null;

    setClickable(true);
    setFocusableInTouchMode(true);
    setWillNotDraw(false);
    setAlwaysDrawnWithCacheEnabled(false);
    setWillNotDraw(false);
    setClipToPadding(false);

    ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TwoWayView, defStyle, 0);
    initializeScrollbars(a);

    mDrawSelectorOnTop = a.getBoolean(R.styleable.TwoWayView_android_drawSelectorOnTop, false);

    Drawable d = a.getDrawable(R.styleable.TwoWayView_android_listSelector);
    if (d != null) {
        setSelector(d);
    }

    int orientation = a.getInt(R.styleable.TwoWayView_android_orientation, -1);
    if (orientation >= 0) {
        setOrientation(Orientation.values()[orientation]);
    }

    int choiceMode = a.getInt(R.styleable.TwoWayView_android_choiceMode, -1);
    if (choiceMode >= 0) {
        setChoiceMode(ChoiceMode.values()[choiceMode]);
    }

    a.recycle();

    updateScrollbarsDirection();
}

From source file:com.example.myronlg.cardviewpagerdemo.MultiCardViewPager.java

void initViewPager() {

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override//from   www  .j a v a2 s. c o m
        public void onGlobalLayout() {
            itemScrollOffset = (int) (getClientWidth() * mAdapter.getPageWidth(0));
            //                int maxScrollX = (int) (2*getClientWidth()*mAdapter.getPageWidth(0) + (mAdapter.getCount() - 2) * getClientWidth() * mAdapter.getPageWidth(1) - getWidth() + getClientWidth()*0.5F);
            maxScrollX = (int) (getClientWidth() * (2 * mAdapter.getPageWidth(0)
                    + (mAdapter.getCount() - 2) * mAdapter.getPageWidth(1) - 1 + 0.0F));
            minScrollX = (int) (-getClientWidth() * 0.0F);
            //                itemScrollOffset = 0;
            getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });

    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);

    myScroller = new Scroller(context, new AccelerateInterpolator());
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;

    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}