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:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java

private void colorKarma(Context context) {
    final int boldCol;
    final int rrPostSubtitleUpvoteCol;
    final int rrPostSubtitleDownvoteCol;

    final TypedArray appearance = context.obtainStyledAttributes(new int[] { R.attr.srPostSubtitleBoldCol,
            R.attr.srPostSubtitleUpvoteCol, R.attr.srPostSubtitleDownvoteCol });

    boldCol = appearance.getColor(0, 255);
    rrPostSubtitleUpvoteCol = appearance.getColor(1, 255);
    rrPostSubtitleDownvoteCol = appearance.getColor(2, 255);

    appearance.recycle();/*from  w  w  w  .ja va2 s .c  o m*/

    final BetterSSB karmaSB = new BetterSSB();

    final int pointsCol;

    final int score = computeScore();

    if (isUpvoted()) {
        pointsCol = rrPostSubtitleUpvoteCol;
    } else if (isDownvoted()) {
        pointsCol = rrPostSubtitleDownvoteCol;
    } else {
        pointsCol = boldCol;
    }

    karmaSB.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f);

    postKarma = karmaSB.get();
}

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

private void rebuildSubtitle(Context context) {

    // TODO customise display
    // TODO preference for the X days, X hours thing

    final TypedArray appearance = context
            .obtainStyledAttributes(new int[] { R.attr.srPostSubtitleBoldCol, R.attr.srPostSubtitleUpvoteCol,
                    R.attr.srPostSubtitleDownvoteCol, R.attr.srFlairBackCol, R.attr.srFlairTextCol });

    final int boldCol = appearance.getColor(0, 255), rrPostSubtitleUpvoteCol = appearance.getColor(1, 255),
            rrPostSubtitleDownvoteCol = appearance.getColor(2, 255),
            rrFlairBackCol = appearance.getColor(3, 255), rrFlairTextCol = appearance.getColor(4, 255);

    appearance.recycle();//from   w  w  w .  ja  v a 2s .  c om

    final BetterSSB postListDescSb = new BetterSSB();

    //      SpannableStringBuilder for the Karma that goes between our up/downvote arrows
    final BetterSSB karmaSb = new BetterSSB();

    final int pointsCol;

    final int score = computeScore();

    if (isUpvoted()) {
        pointsCol = rrPostSubtitleUpvoteCol;
    } else if (isDownvoted()) {
        pointsCol = rrPostSubtitleDownvoteCol;
    } else {
        pointsCol = boldCol;
    }

    if (src.isSpoiler()) {
        postListDescSb.append(" SPOILER ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE,
                Color.rgb(50, 50, 50), 1f);
        postListDescSb.append("  ", 0);
    }

    if (src.isStickied()) {
        postListDescSb.append(" STICKY ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE,
                Color.rgb(0, 170, 0), 1f); // TODO color?
        postListDescSb.append("  ", 0);
    }

    if (src.isNsfw()) {
        postListDescSb.append(" NSFW ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE,
                Color.RED, 1f); // TODO color?
        postListDescSb.append("  ", 0);
    }

    if (src.getFlairText() != null) {
        postListDescSb.append(" " + src.getFlairText() + " ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, rrFlairTextCol,
                rrFlairBackCol, 1f);
        postListDescSb.append("  ", 0);
    }

    postListDescSb.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_points) + " ", 0);
    postListDescSb.append(SRTime.formatDurationFrom(context, src.getCreatedTimeSecsUTC() * 1000),
            BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_by) + " ", 0);
    postListDescSb.append(src.getAuthor(), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);

    if (showSubreddit) {
        postListDescSb.append(" " + context.getString(R.string.subtitle_to) + " ", 0);
        postListDescSb.append(src.getSubreddit(), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    }

    postListDescSb.append(" (" + src.getDomain() + ")", 0);

    karmaSb.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f);

    postListDescription = postListDescSb.get();
    postKarma = karmaSb.get();
}

From source file:com.appunite.list.AbsHorizontalListView.java

public AbsHorizontalListView(Context context) {
    super(context);
    initAbsListView();//www . j  ava2  s. com

    setHorizontalScrollBarEnabled(true);
    TypedArray a = context.obtainStyledAttributes(R.styleable.View);
    initializeScrollbars(a);
    a.recycle();
}

From source file:com.appunite.list.AbsListView.java

public AbsListView(Context context) {
    super(context);
    initAbsListView();//  w  ww  .j  a  v  a 2  s  .c  o m

    setVerticalScrollBarEnabled(true);
    TypedArray a = context.obtainStyledAttributes(R.styleable.View);
    initializeScrollbars(a);
    a.recycle();
}