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(@StyleableRes int[] attrs) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:ca.co.rufus.androidboilerplate.ui.misc.DividerItemDecoration.java

public DividerItemDecoration(Context context, int orientation, float paddingStart, boolean rtl) {
    this.rtl = rtl;

    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    divider = a.getDrawable(0);/*from  w  ww.  j a  v a 2 s  . co m*/
    a.recycle();
    setOrientation(orientation);
    setPaddingStart(paddingStart);
}

From source file:catchla.yep.adapter.decorator.DividerItemDecoration.java

public DividerItemDecoration(Context context, int orientation) {
    mPadding = new Rect();
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);//w  w w  . ja v  a2 s  .  c  o m
    a.recycle();
    setOrientation(orientation);
}

From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedMessage.java

public RedditPreparedMessage(final Context context, final RedditMessage message, final long timestamp) {

    this.src = message;

    // TODO custom time

    final TypedArray appearance = context.obtainStyledAttributes(
            new int[] { R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol, });

    rrCommentHeaderBoldCol = appearance.getColor(0, 255);
    rrCommentHeaderAuthorCol = appearance.getColor(1, 255);

    body = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(message.body));

    idAndType = message.name;//from   www  . j  ava2s. co  m

    final BetterSSB sb = new BetterSSB();

    if (src.author == null) {
        sb.append("[" + context.getString(R.string.general_unknown) + "]",
                BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f);
    } else {
        sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f);
    }

    sb.append("   ", 0);
    sb.append(RRTime.formatDurationMsAgo(context, RRTime.utcCurrentTimeMillis() - src.created_utc * 1000L),
            BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f);

    header = sb.get();
}

From source file:com.android.mail.browse.ConversationPagerController.java

private void setupPageMargin(Context c) {
    final TypedArray a = c.obtainStyledAttributes(new int[] { android.R.attr.listDivider });
    final Drawable divider = a.getDrawable(0);
    a.recycle();//from   w  w  w .  ja  v  a 2  s .c  o  m
    final int padding = c.getResources().getDimensionPixelOffset(R.dimen.conversation_page_gutter);
    final Drawable gutterDrawable = new PageMarginDrawable(divider, padding, 0, padding, 0,
            c.getResources().getColor(R.color.conversation_view_background_color));
    mPager.setPageMargin(gutterDrawable.getIntrinsicWidth() + 2 * padding);
    mPager.setPageMarginDrawable(gutterDrawable);
}

From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedMessage.java

public RedditPreparedMessage(final Context context, final RedditMessage message, final long timestamp) {

    this.src = message;

    final int srCommentHeaderBoldCol;
    final int srCommentHeaderAuthorCol;

    {/* w ww . ja  v a 2 s. co  m*/
        final TypedArray appearance = context.obtainStyledAttributes(
                new int[] { R.attr.srCommentHeaderBoldCol, R.attr.srCommentHeaderAuthorCol, });

        srCommentHeaderBoldCol = appearance.getColor(0, 255);
        srCommentHeaderAuthorCol = appearance.getColor(1, 255);

        appearance.recycle();
    }

    body = MarkdownParser.parse(message.getUnescapedBodyMarkdown().toCharArray());

    idAndType = message.name;

    final BetterSSB sb = new BetterSSB();

    if (src.author == null) {
        sb.append("[" + context.getString(R.string.general_unknown) + "]",
                BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, srCommentHeaderAuthorCol, 0, 1f);
    } else {
        sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, srCommentHeaderAuthorCol, 0, 1f);
    }

    sb.append("   ", 0);
    sb.append(SRTime.formatDurationFrom(context, src.created_utc * 1000L),
            BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, srCommentHeaderBoldCol, 0, 1f);

    header = sb.get();
}

From source file:com.android.cards.view.helper.CardViewHelperImplBase.java

@Override
public Drawable getResourceFromAttrs(Context themedContext, int attr) {
    // Create an array of the attributes we want to resolve
    // using values from a theme
    int[] attrs = new int[] { attr /* index 0 */ };

    // Obtain the styled attributes. 'themedContext' is a context with a
    // theme, typically the current Activity (i.e. 'this')
    TypedArray ta = themedContext.obtainStyledAttributes(attrs);

    // To get the value of the 'listItemBackground' attribute that was
    // set in the theme used in 'themedContext'. The parameter is the index
    // of the attribute in the 'attrs' array. The returned Drawable
    // is what you are after
    Drawable drawableFromTheme = ta.getDrawable(0 /* index */);

    // Finally, free the resources used by TypedArray
    ta.recycle();//from www. j ava  2 s  .  c om

    return drawableFromTheme;
}

From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java

public static Drawable getDrawableFromAttribute(Context context, int attr) {
    int[] attrs = new int[] { attr };
    android.content.res.TypedArray ta = context.obtainStyledAttributes(attrs);
    Drawable drawableFromTheme = ta.getDrawable(0);
    ta.recycle();//from ww w  .  j a  va2 s . c  o m

    return drawableFromTheme;
}

From source file:github.daneren2005.dsub.util.Util.java

public static int getAttribute(Context context, int attr) {
    int res;//from w w  w  . j av a2 s  . c  o m
    int[] attrs = new int[] { attr };
    TypedArray typedArray = context.obtainStyledAttributes(attrs);
    res = typedArray.getResourceId(0, 0);
    typedArray.recycle();
    return res;
}

From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java

public SunriseDrawable(Context context) {

    mContext = context;//  w  ww .  j a v  a 2 s.  c om

    Resources res = context.getResources();
    final TypedArray a = context.obtainStyledAttributes(new int[] { R.attr.colorPrimary, R.attr.colorAccent,
            R.attr.colorPrimaryDark, R.attr.appsiHomeWidgetPrimaryColor, });

    int primaryColor = a.getColor(0, Color.BLACK);
    int accentColor = a.getColor(1, Color.BLACK);
    int primaryColorDark = a.getColor(2, Color.BLACK);
    int textColor = a.getColor(3, Color.BLACK);
    a.recycle();

    mIsRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;

    float density = res.getDisplayMetrics().density;
    int sunBounds = (int) (density * 16);
    mTopOffset = (int) (density * 12);
    mLeftOffset = (int) (density * 24);
    mRightOffset = (int) (density * 24);
    mBottomOffset = (int) (density * 24);
    mDotRadius = (int) (density * 2);

    mSunImage = mContext.getResources().getDrawable(R.drawable.ic_weather_clear);
    mSunImage.setBounds(0, 0, sunBounds, sunBounds);

    mArcPaint = new Paint();
    mArcPaint.setColor(primaryColorDark);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setAntiAlias(true);

    mArcFillPaint = new Paint();
    mArcFillPaint.setColor(primaryColor);
    mArcFillPaint.setAlpha(64);
    mArcFillPaint.setStyle(Paint.Style.FILL);
    mArcFillPaint.setAntiAlias(true);

    mLinePaint = new Paint();
    mLinePaint.setColor(textColor);
    mLinePaint.setAlpha(128);
    mLinePaint.setStyle(Paint.Style.STROKE);

    mDotPaint = new Paint();
    mDotPaint.setStyle(Paint.Style.FILL);
    mDotPaint.setColor(primaryColorDark);
    mDotPaint.setAntiAlias(true);
}

From source file:com.android.contacts.activities.ActionBarAdapter.java

private void setupTabs(Context context) {
    final TypedArray attributeArray = context
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    mMaxPortraitTabHeight = attributeArray.getDimensionPixelSize(0, 0);
    // Hide tabs initially
    setPortraitTabHeight(0);//from ww  w .  jav  a  2s  .  co  m
}