Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

In this page you can find the example usage for android.content Context obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs,
        @AttrRes int defStyleAttr, @StyleRes int defStyleRes) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

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

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

    mNeedSync = false;/*from w ww.  j  a v  a  2 s  .  c o  m*/
    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.artifex.mupdf.view.ThumbnailViews.java

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

    mNeedSync = false;/*from  w ww. ja  v a2s .  c o  m*/
    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.artifex.mupdflib.TwoWayView.java

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

    mContext = context;//from   ww w .  j  a v  a2s  . c  o  m

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

    mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE;

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

    mScroller = new Scroller(context);

    mIsVertical = true;

    mTempRect = new Rect();

    mArrowScrollFocusResult = new ArrowScrollFocusResult();

    mSelectorPosition = INVALID_POSITION;

    mSelectorRect = new Rect();

    mResurrectToPosition = INVALID_POSITION;

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

    mChoiceMode = ChoiceMode.NONE;

    mRecycler = new RecycleBin();

    mAreAllItemsSelectable = true;

    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);

    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();
}

From source file:cn.ismartv.recyclerview.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setScrollContainer(true);//from w  w w .  j a v  a  2s. co  m
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.
    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);
    }

    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}

From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, CLIP_TO_PADDING_ATTR, defStyle, 0);
        mClipToPadding = a.getBoolean(0, true);
        a.recycle();//from ww w  . j a v  a 2  s .com
    } else {
        mClipToPadding = true;
    }
    setScrollContainer(true);
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    mPostUpdatesOnAnimation = version >= 16;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    setWillNotDraw(getOverScrollMode() == View.OVER_SCROLL_NEVER);

    mItemAnimator.setListener(mItemAnimatorListener);
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.

    boolean nestedScrollingEnabled = true;

    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        int descendantFocusability = a.getInt(R.styleable.RecyclerView_android_descendantFocusability, -1);
        if (descendantFocusability == -1) {
            setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        }
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);

        if (Build.VERSION.SDK_INT >= 21) {
            a = context.obtainStyledAttributes(attrs, NESTED_SCROLLING_ATTRS, defStyle, defStyleRes);
            nestedScrollingEnabled = a.getBoolean(0, true);
            a.recycle();
        }
    } else {
        setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    }

    // Re-set whether nested scrolling is enabled so that it is set on all API levels
    setNestedScrollingEnabled(nestedScrollingEnabled);
}

From source file:android.support.v71.widget.RecyclerView.java

public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    LogUtil.e("---------------RecyclerView  --------------------- ");
    //   /* w  ww .ja v a  2  s.c  o  m*/
    setScrollContainer(true);
    //  touch ?
    setFocusableInTouchMode(true);
    final int version = Build.VERSION.SDK_INT;
    //TODO  > 16  ? 
    mPostUpdatesOnAnimation = version >= 16;

    // ?  ? ??
    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();

    // ?   ?
    setWillNotDraw(ViewCompat.getOverScrollMode(this) == ViewCompat.OVER_SCROLL_NEVER);

    // ?
    mItemAnimator.setListener(mItemAnimatorListener);
    // ? adapter Manager
    initAdapterManager();
    initChildrenHelper();
    // If not explicitly specified this view is important for accessibility.
    // ,  RecycleView ??  accessibility
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    // ?  AccessibilityManager ? ?,  ? ??,  ?  app ?
    mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    setAccessibilityDelegateCompat(new android.support.v71.widget.RecyclerViewAccessibilityDelegate(this));
    // Create the layoutManager if specified.
    if (attrs != null) {
        int defStyleRes = 0;
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyle, defStyleRes);
        //xml ?  LayoutManager
        String layoutManagerName = a.getString(R.styleable.RecyclerView_layoutManager);
        a.recycle();
        createLayoutManager(context, layoutManagerName, attrs, defStyle, defStyleRes);
    }

    // 
    mScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
}