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.appeaser.sublimepickerlibrary.datepicker.DayPickerPagerAdapter.java

public DayPickerPagerAdapter(@NonNull Context context, @LayoutRes int layoutResId, @IdRes int calendarViewId) {
    mInflater = LayoutInflater.from(context);
    mLayoutResId = layoutResId;//www  .ja  va 2s.  com
    mCalendarViewId = calendarViewId;

    final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlHighlight });
    mDayHighlightColor = ta.getColorStateList(0);
    ta.recycle();
}

From source file:com.ichi2.anki.widgets.DeckAdapter.java

public DeckAdapter(LayoutInflater layoutInflater, Context context) {
    mLayoutInflater = layoutInflater;//from  w  w  w. ja va 2s.c  om
    mDeckList = new ArrayList<>();
    // Get the colors from the theme attributes
    int[] attrs = new int[] { R.attr.zeroCountColor, R.attr.newCountColor, R.attr.learnCountColor,
            R.attr.reviewCountColor, R.attr.currentDeckBackground, android.R.attr.textColor,
            R.attr.dynDeckColor, R.attr.expandRef, R.attr.collapseRef };
    TypedArray ta = context.obtainStyledAttributes(attrs);
    Resources res = context.getResources();
    mZeroCountColor = ta.getColor(0, res.getColor(R.color.zero_count));
    mNewCountColor = ta.getColor(1, res.getColor(R.color.new_count));
    mLearnCountColor = ta.getColor(2, res.getColor(R.color.learn_count));
    mReviewCountColor = ta.getColor(3, res.getColor(R.color.review_count));
    mRowCurrentDrawable = ta.getResourceId(4, 0);
    mDeckNameDefaultColor = ta.getColor(5, res.getColor(R.color.black));
    mDeckNameDynColor = ta.getColor(6, res.getColor(R.color.deckadapter_deck_name_dyn));
    mExpandImage = ta.getDrawable(7);
    mCollapseImage = ta.getDrawable(8);
    ta.recycle();
}

From source file:android.support.v7.app.ActionBarActivityDelegateBase.java

private MenuView getListMenuView(Context context, MenuPresenter.Callback cb) {
    if (mMenu == null) {
        return null;
    }/*from  www  .j a  va 2  s.com*/

    if (mListMenuPresenter == null) {
        TypedArray a = context.obtainStyledAttributes(R.styleable.Theme);
        final int listPresenterTheme = a.getResourceId(R.styleable.Theme_panelMenuListTheme,
                R.style.Theme_AppCompat_CompactMenu);
        a.recycle();

        mListMenuPresenter = new ListMenuPresenter(R.layout.abc_list_menu_item_layout, listPresenterTheme);
        mListMenuPresenter.setCallback(cb);
        mMenu.addMenuPresenter(mListMenuPresenter);
    } else {
        // Make sure we update the ListView
        mListMenuPresenter.updateMenuView(false);
    }

    return mListMenuPresenter.getMenuView(new FrameLayout(context));
}

From source file:org.lol.reddit.reddit.prepared.RedditPreparedComment.java

public RedditPreparedComment(final Context context, final RedditComment comment, final long timestamp,
        final boolean needsUpdating, final RedditPreparedPost parentPost, final RedditAccount user,
        final EnumSet<PrefsUtility.AppearanceCommentHeaderItems> headerItems) {

    this.src = comment;
    this.parentPost = parentPost;
    this.headerItems = headerItems;

    // TODO custom time

    // TODO don't fetch these every time
    final TypedArray appearance = context.obtainStyledAttributes(new int[] { R.attr.rrCommentHeaderBoldCol,
            R.attr.rrCommentHeaderAuthorCol, R.attr.rrPostSubtitleUpvoteCol, R.attr.rrPostSubtitleDownvoteCol,
            R.attr.rrFlairBackCol, R.attr.rrFlairTextCol, R.attr.rrGoldBackCol, R.attr.rrGoldTextCol });

    rrCommentHeaderBoldCol = appearance.getColor(0, 255);
    rrCommentHeaderAuthorCol = appearance.getColor(1, 255);
    rrPostSubtitleUpvoteCol = appearance.getColor(2, 255);
    rrPostSubtitleDownvoteCol = appearance.getColor(3, 255);
    rrFlairBackCol = appearance.getColor(4, 0);
    rrFlairTextCol = appearance.getColor(5, 255);
    rrGoldBackCol = appearance.getColor(6, 0);
    rrGoldTextCol = appearance.getColor(7, 255);

    body = MarkdownParser.parse(StringEscapeUtils.unescapeHtml4(comment.body).toCharArray());
    if (comment.author_flair_text != null) {
        flair = StringEscapeUtils.unescapeHtml4(comment.author_flair_text);
    } else {/*from   ww  w .  java 2 s. c om*/
        flair = null;
    }

    idAlone = comment.id;
    idAndType = comment.name;

    if (comment.likes == null) {
        voteDirection = 0;
    } else {
        voteDirection = Boolean.TRUE.equals(comment.likes) ? 1 : -1;
    }

    saved = Boolean.TRUE.equals(comment.saved);

    lastChange = timestamp;
    if (src.likes != null) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, true);
    } else if (needsUpdating) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, false);
    }

    rebuildHeader(context);
}

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

public RedditPreparedComment(final Context context, final RedditComment comment,
        final RedditPreparedComment parentComment, final long timestamp, final boolean needsUpdating,
        final RedditPreparedPost parentPost, final RedditAccount user,
        final EnumSet<PrefsUtility.AppearanceCommentHeaderItems> headerItems) {

    this.src = comment;
    this.parentPost = parentPost;
    this.headerItems = headerItems;

    // TODO custom time

    // TODO don't fetch these every time
    final TypedArray appearance = context
            .obtainStyledAttributes(new int[] { R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol,
                    R.attr.rrPostSubtitleUpvoteCol, R.attr.rrPostSubtitleDownvoteCol });

    rrCommentHeaderBoldCol = appearance.getColor(0, 255);
    rrCommentHeaderAuthorCol = appearance.getColor(1, 255);
    rrPostSubtitleUpvoteCol = appearance.getColor(2, 255);
    rrPostSubtitleDownvoteCol = appearance.getColor(3, 255);

    body = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(comment.body));
    if (comment.author_flair_text != null) {
        flair = StringEscapeUtils.unescapeHtml4(comment.author_flair_text);
    } else {/*from   w  w  w. ja v  a  2 s.  c  o m*/
        flair = null;
    }

    if (parentComment == null) {
        indentation = 0;
    } else {
        indentation = parentComment.indentation + 1;
        parentComment.addChild(this);
    }

    idAlone = comment.id;
    idAndType = comment.name;

    if (comment.likes == null) {
        voteDirection = 0;
    } else {
        voteDirection = Boolean.TRUE.equals(comment.likes) ? 1 : -1;
    }

    lastChange = timestamp;
    if (src.likes != null) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, true);
    } else if (needsUpdating) {
        RedditChangeDataManager.getInstance(context).update(src.link_id, user, this, false);
    }

    rebuildHeader(context);
}

From source file:com.ryan.ryanreader.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.rrPostSubtitleBoldCol,
            R.attr.rrPostSubtitleUpvoteCol, R.attr.rrPostSubtitleDownvoteCol });

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

    final BetterSSB postListDescSb = new BetterSSB();

    final int pointsCol;
    int score = src.score;

    if (Boolean.TRUE.equals(src.likes))
        score--;//from   ww w .  ja  v  a2  s . c  o  m
    if (Boolean.FALSE.equals(src.likes))
        score++;

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

    if (src.over_18) {
        postListDescSb.append(" NSFW ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE,
                Color.RED, 1f); // TODO color?
        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(
            RRTime.formatDurationMsAgo(context, RRTime.utcCurrentTimeMillis() - src.created_utc * 1000),
            BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_by) + " ", 0);
    postListDescSb.append(src.author, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);

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

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

    postListDescription = postListDescSb.get();
}

From source file:chao.widget.tablayout.TabLayout.java

static void checkAppCompatTheme(Context context) {
    TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);
    final boolean failed = !a.hasValue(0);
    if (a != null) {
        a.recycle();//w  w  w .ja va 2 s .com
    }
    if (failed) {
        throw new IllegalArgumentException(
                "You need to use a Theme.AppCompat theme " + "(or descendant) with the design library.");
    }
}

From source file:org.lol.reddit.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.rrPostSubtitleBoldCol, R.attr.rrPostSubtitleUpvoteCol,
                    R.attr.rrPostSubtitleDownvoteCol, R.attr.rrFlairBackCol, R.attr.rrFlairTextCol });

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

    final BetterSSB postListDescSb = new BetterSSB();

    final int pointsCol;
    int score = src.score;

    if (Boolean.TRUE.equals(src.likes))
        score--;/* www .  j a  va 2  s  .  c o m*/
    if (Boolean.FALSE.equals(src.likes))
        score++;

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

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

    if (src.link_flair_text != null && src.link_flair_text.length() > 0) {
        postListDescSb.append(" " + StringEscapeUtils.unescapeHtml4(src.link_flair_text) + " ",
                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(RRTime.formatDurationFrom(context, src.created_utc * 1000),
            BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_by) + " ", 0);
    postListDescSb.append(src.author, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);

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

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

    postListDescription = postListDescSb.get();
}

From source file:com.android.launcher3.Utilities.java

public static int getColorAccent(Context context) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { android.R.attr.colorAccent });
    int colorAccent = ta.getColor(0, 0);
    ta.recycle();/*from ww  w .j  a  v  a2 s  .c  o m*/
    return colorAccent;
}