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) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:cc.solart.turbo.TurboRecyclerView.java

public TurboRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TurboRecyclerView);
    int max = ta.getInteger(R.styleable.TurboRecyclerView_maxDragDistance, DRAG_MAX_DISTANCE);
    mTotalDragDistance = convertDpToPixel(context, max);
    mLoadEnabled = ta.getBoolean(R.styleable.TurboRecyclerView_enableLoad, false);
    ta.recycle();//from   w  ww .  j  a va 2s.  c  o m
}

From source file:cn.com.hgh.view.SlideSwitch.java

public SlideSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    listener = null;//from w w  w . ja  v  a2 s . com
    paint = new Paint();
    paint.setAntiAlias(true);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.slideswitch);
    color_theme = a.getColor(R.styleable.slideswitch_themeColor, DEFAULT_COLOR_THEME);
    isOpen = a.getBoolean(R.styleable.slideswitch_isOpen, false);
    shape = a.getInt(R.styleable.slideswitch_shape1, SHAPE_RECT);
    a.recycle();

}

From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);
    setHorizontalScrollBarEnabled(false); //??????

    if (attrs != null) {
        TypedArray attrsTypedArray = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
        if (attrsTypedArray != null) {
            allowWidthFull = attrsTypedArray.getBoolean(R.styleable.PagerSlidingTabStrip_allowWidthFull, false);
            slidingBlockDrawable = attrsTypedArray.getDrawable(R.styleable.PagerSlidingTabStrip_slidingBlock);
            attrsTypedArray.recycle();//from  w w  w. j  a  v a2s.c o  m
        }
    }
}

From source file:android.support.transition.Visibility.java

public Visibility(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.VISIBILITY_TRANSITION);
    @Mode//w  w w  . j av  a  2s. c  o  m
    int mode = TypedArrayUtils.getNamedInt(a, (XmlResourceParser) attrs, "transitionVisibilityMode",
            Styleable.VisibilityTransition.TRANSITION_VISIBILITY_MODE, 0);
    a.recycle();
    if (mode != 0) {
        setMode(mode);
    }
}

From source file:android.support.transition.ChangeTransform.java

public ChangeTransform(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.CHANGE_TRANSFORM);
    mUseOverlay = TypedArrayUtils.getNamedBoolean(a, (XmlPullParser) attrs, "reparentWithOverlay",
            Styleable.ChangeTransform.REPARENT_WITH_OVERLAY, true);
    mReparent = TypedArrayUtils.getNamedBoolean(a, (XmlPullParser) attrs, "reparent",
            Styleable.ChangeTransform.REPARENT, true);
    a.recycle();//from  w ww  .  j av a2  s. c om
}

From source file:com.ameron32.apps.tapnotes._trial.ui.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);// w  w  w.  j  a v a 2  s  . co  m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMarginLeft = mExpandedMarginRight = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);
        if (isRtl) {
            mExpandedMarginRight = marginStart;
        } else {
            mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            mExpandedMarginLeft = marginEnd;
        } else {
            mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom,
                0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        mCollapsedTitleTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize,
                0);
    }

    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:com.todddavies.components.progressbar.ProgressWheel.java

/**
 * The constructor for the ProgressWheel
 *
 * @param context//from   w w w  .  j  a  v a  2 s .  c  o  m
 * @param attrs
 */
public ProgressWheel(Context context, AttributeSet attrs) {
    super(context, attrs);

    parseAttributes(context.obtainStyledAttributes(attrs, R.styleable.ProgressWheel));
}

From source file:android.support.transition.TransitionSet.java

public TransitionSet(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.TRANSITION_SET);
    int ordering = TypedArrayUtils.getNamedInt(a, (XmlResourceParser) attrs, "transitionOrdering",
            Styleable.TransitionSet.TRANSITION_ORDERING, TransitionSet.ORDERING_TOGETHER);
    setOrdering(ordering);/*from w  ww.  jav a  2 s. c  om*/
    a.recycle();
}

From source file:au.com.zacher.popularmovies.activity.layout.CollapsingTitleLayout.java

public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    this.mTextPaint = new TextPaint();
    this.mTextPaint.setAntiAlias(true);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    this.mExpandedMarginLeft = this.mExpandedMarginRight = this.mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);

    final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginStart)) {
        final int marginStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginStart,
                0);//from ww w. ja  va2s.co  m
        if (isRtl) {
            this.mExpandedMarginRight = marginStart;
        } else {
            this.mExpandedMarginLeft = marginStart;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginEnd)) {
        final int marginEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginEnd, 0);
        if (isRtl) {
            this.mExpandedMarginLeft = marginEnd;
        } else {
            this.mExpandedMarginRight = marginEnd;
        }
    }
    if (a.hasValue(R.styleable.CollapsingTitleLayout_expandedMarginBottom)) {
        this.mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMarginBottom, 0);
    }

    final int tp = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance,
            android.R.style.TextAppearance);
    this.setTextAppearance(tp);

    if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        this.mCollapsedTitleTextSize = a
                .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
    }

    this.mRequestedExpandedTitleTextSize = a.getDimensionPixelSize(
            R.styleable.CollapsingTitleLayout_expandedTextSize, this.mCollapsedTitleTextSize);

    final int interpolatorId = a.getResourceId(R.styleable.CollapsingTitleLayout_textSizeInterpolator,
            android.R.anim.accelerate_interpolator);
    this.mTextSizeInterpolator = AnimationUtils.loadInterpolator(context, interpolatorId);

    a.recycle();

    this.mToolbarContentBounds = new Rect();

    this.setWillNotDraw(false);
}

From source file:android.support.v7.widget.ActionBarContainer.java

public ActionBarContainer(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Set a transparent background so that we project appropriately.
    final Drawable bg = Build.VERSION.SDK_INT >= 21 ? new ActionBarBackgroundDrawableV21(this)
            : new ActionBarBackgroundDrawable(this);
    ViewCompat.setBackground(this, bg);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
    mBackground = a.getDrawable(R.styleable.ActionBar_background);
    mStackedBackground = a.getDrawable(R.styleable.ActionBar_backgroundStacked);
    mHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, -1);

    if (getId() == R.id.split_action_bar) {
        mIsSplit = true;//from  w w w .  ja va  2 s  .co m
        mSplitBackground = a.getDrawable(R.styleable.ActionBar_backgroundSplit);
    }
    a.recycle();

    setWillNotDraw(mIsSplit ? mSplitBackground == null : mBackground == null && mStackedBackground == null);
}