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:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java

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

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StgStaggeredGridView);
        mColCount = a.getInteger(R.styleable.StgStaggeredGridView_stgNumColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StgStaggeredGridView_stgDrawSelectorOnTop, false);
    } else {/* w w  w . j  a  v  a2s .co m*/
        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();
    }

    mMinimumVelocity = vc.getScaledMinimumFlingVelocity();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mOverscrollDistance = vc.getScaledOverscrollDistance(); //TODO
    mOverflingDistance = vc.getScaledOverflingDistance();
}

From source file:com.hippo.widget.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//w  w  w. j  a va 2  s  .c  o m
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mHeaderTotalDragDistance = mSpinnerFinalOffset;

    mProgressBar = new SwipeProgressBar(this);
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
}

From source file:com.hainva.feedlynavigation.FeedlyViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*from w  w  w .j a  v  a2 s . co m*/
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    if (Build.VERSION.SDK_INT >= 11) {
        mPageTransformer = new FeedlyPageTransformer();
        setChildrenDrawingOrderEnabledCompat(true);
        mDrawingOrder = DRAW_ORDER_REVERSE;
        // if (needsPopulate) populate();
    }

    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:cnedu.ustcjd.widget.MultiSlider.java

public MultiSlider(Context context, AttributeSet attrs, int defStyle, int styleRes) {
    super(context, attrs, defStyle);
    if ((Build.VERSION.SDK_INT >= 21) && getBackground() == null) {
        setBackgroundResource(R.drawable.control_background_multi_material);
    }/* w  w w . j av  a2 s. c o m*/

    mUiThreadId = Thread.currentThread().getId();

    a = context.obtainStyledAttributes(attrs, R.styleable.MultiSlider, defStyle, styleRes);
    mNoInvalidate = true;
    int numThumbs = a.getInt(R.styleable.MultiSlider_thumbNumber, 2);
    initMultiSlider(numThumbs);

    Drawable trackDrawable = a.getDrawable(R.styleable.MultiSlider_android_track);
    if (trackDrawable == null) {
        trackDrawable = ContextCompat.getDrawable(getContext(), R.drawable.multislider_track_material);
    }

    setTrackDrawable(getTintedDrawable(trackDrawable, a.getColor(R.styleable.MultiSlider_trackColor, 0)));

    //TODO
    //        mMinWidth = a.getDimensionPixelSize(R.styleable.MultiSlider_minWidth, mMinWidth);
    //        mMaxWidth = a.getDimensionPixelSize(R.styleable.MultiSlider_maxWidth, mMaxWidth);
    //        mMinHeight = a.getDimensionPixelSize(R.styleable.MultiSlider_minHeight, mMinHeight);
    //        mMaxHeight = a.getDimensionPixelSize(R.styleable.MultiSlider_maxHeight, mMaxHeight);

    setStep(a.getInt(R.styleable.MultiSlider_scaleStep, mStep));
    setStepsThumbsApart(a.getInt(R.styleable.MultiSlider_stepsThumbsApart, mStepsThumbsApart));
    setDrawThumbsApart(a.getBoolean(R.styleable.MultiSlider_drawThumbsApart, mDrawThumbsApart));
    setMax(a.getInt(R.styleable.MultiSlider_scaleMax, mScaleMax), true);
    setMin(a.getInt(R.styleable.MultiSlider_scaleMin, mScaleMin), true);

    mMirrorForRtl = a.getBoolean(R.styleable.MultiSlider_mirrorForRTL, mMirrorForRtl);

    // --> now place thumbs

    defThumbDrawable = a.getDrawable(R.styleable.MultiSlider_android_thumb);

    if (defThumbDrawable == null) {
        if (Build.VERSION.SDK_INT >= 21) {
            defThumbDrawable = ContextCompat.getDrawable(getContext(),
                    R.drawable.multislider_thumb_material_anim);
        } else {
            defThumbDrawable = ContextCompat.getDrawable(getContext(), R.drawable.multislider_thumb_material);
        }
    }

    defRangeDrawable = a.getDrawable(R.styleable.MultiSlider_range);
    if (defRangeDrawable == null) {
        defRangeDrawable = ContextCompat.getDrawable(getContext(), R.drawable.multislider_range_material);
    }

    Drawable range1Drawable = a.getDrawable(R.styleable.MultiSlider_range1);
    Drawable range2Drawable = a.getDrawable(R.styleable.MultiSlider_range2);

    defRangeColor = a.getColor(R.styleable.MultiSlider_rangeColor, 0);
    defThumbColor = a.getColor(R.styleable.MultiSlider_thumbColor, 0);
    setThumbDrawables(defThumbDrawable, defRangeDrawable, range1Drawable, range2Drawable); //
    // will
    // guess thumbOffset if
    // thumb != null...
    // ...but allow layout to override this

    int thumbOffset = a.getDimensionPixelOffset(R.styleable.MultiSlider_android_thumbOffset,
            defThumbDrawable.getIntrinsicWidth() / 2);
    setThumbOffset(thumbOffset);

    repositionThumbs();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mNoInvalidate = false;
    a.recycle();
}

From source file:android.support.custom.view.VerticalViewPager.java

void initViewPager() {
    setWillNotDraw(false);// ww  w.  j  a va 2 s. c o m
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);

    final float density = context.getResources().getDisplayMetrics().density;
    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:com.cyanogenmod.filemanager.ui.widgets.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  ava  2s. c om
 *
 * @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 = new Scroller(context, sInterpolator);
}

From source file:com.albedinsky.android.support.ui.widget.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 a  2  s. com*/
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
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);
    mScroller = new Scroller(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./* w  w w  .  j av a  2s.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.cyan.widget.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from w ww.j  av  a  2  s .  co m
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mHeaderTotalDragDistance = mSpinnerFinalOffset;

    mProgressBar = new SwipeProgressBar(this);
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);

}

From source file:com.haibison.android.lockpattern.LockPatternFragment.java

public boolean onTouchEvent(MotionEvent event) {
    /*//w w w. j  a  va 2s . c o  m
     * Support canceling dialog on touching outside in APIs < 11.
     * 
     * getActivity() piece of code is copied from android.view.Window. You can find
     * it by searching for methods shouldCloseOnTouch() and isOutOfBounds().
     */
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && event.getAction() == MotionEvent.ACTION_DOWN
            && fa.getWindow().peekDecorView() != null) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        final int slop = ViewConfiguration.get(getActivity()).getScaledWindowTouchSlop();
        final View decorView = fa.getWindow().getDecorView();
        boolean isOutOfBounds = (x < -slop) || (y < -slop) || (x > (decorView.getWidth() + slop))
                || (y > (decorView.getHeight() + slop));
        if (isOutOfBounds) {
            finishWithNegativeResult(fa.RESULT_CANCELED);
            return true;
        }
    } // if

    return fa.onTouchEvent(event);
}