Example usage for android.content.res TypedArray getColor

List of usage examples for android.content.res TypedArray getColor

Introduction

In this page you can find the example usage for android.content.res TypedArray getColor.

Prototype

@ColorInt
public int getColor(@StyleableRes int index, @ColorInt int defValue) 

Source Link

Document

Retrieve the color value for the attribute at index.

Usage

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static int getThemeColor(Context context, int themeResourceId) {
    final Context appContext = context.getApplicationContext();
    final Resources res = appContext.getResources();
    final TypedArray a = appContext.obtainStyledAttributes(null,
            new int[] { android.R.attr.colorActivatedHighlight }, 0, themeResourceId);
    try {//  ww w. j  a va  2  s.c  o  m
        return a.getColor(0, res.getColor(R.color.material_light_blue));
    } finally {
        a.recycle();
    }
}

From source file:com.codetroopers.betterpickers.radialtimepicker.AmPmCirclesView.java

void setTheme(TypedArray themeColors) {
    mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpAmPmCircleColor,
            ContextCompat.getColor(getContext(), R.color.bpBlue));
    mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpAmPmCircleColor,
            ContextCompat.getColor(getContext(), R.color.bpBlue));
    mAmPmTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpAmPmTextColor,
            ContextCompat.getColor(getContext(), R.color.bpWhite));
    mSelectedAlpha = 200;/*from  www  . j  a  v  a2  s .c o m*/
    mUnselectedAlpha = 50;
}

From source file:com.facebook.react.views.toolbar.ReactToolbarManager.java

private static int[] getDefaultColors(Context context) {
    Resources.Theme theme = context.getTheme();
    TypedArray toolbarStyle = null;// w  w w.j  a v  a  2s  .c  o m
    TypedArray textAppearances = null;
    TypedArray titleTextAppearance = null;
    TypedArray subtitleTextAppearance = null;

    try {
        toolbarStyle = theme.obtainStyledAttributes(new int[] { getIdentifier(context, "toolbarStyle") });

        int toolbarStyleResId = toolbarStyle.getResourceId(0, 0);
        textAppearances = theme.obtainStyledAttributes(toolbarStyleResId,
                new int[] { getIdentifier(context, "titleTextAppearance"),
                        getIdentifier(context, "subtitleTextAppearance"), });

        int titleTextAppearanceResId = textAppearances.getResourceId(0, 0);
        int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0);

        titleTextAppearance = theme.obtainStyledAttributes(titleTextAppearanceResId,
                new int[] { android.R.attr.textColor });
        subtitleTextAppearance = theme.obtainStyledAttributes(subtitleTextAppearanceResId,
                new int[] { android.R.attr.textColor });

        int titleTextColor = titleTextAppearance.getColor(0, Color.BLACK);
        int subtitleTextColor = subtitleTextAppearance.getColor(0, Color.BLACK);

        return new int[] { titleTextColor, subtitleTextColor };
    } finally {
        recycleQuietly(toolbarStyle);
        recycleQuietly(textAppearances);
        recycleQuietly(titleTextAppearance);
        recycleQuietly(subtitleTextAppearance);
    }
}

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;/*ww w. j  a v  a2 s. c om*/

    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:arun.com.chromer.browsing.customtabs.dynamictoolbar.AppColorExtractorJob.java

private int getThemedColor(@Nullable Resources resources, int attributeId, @NonNull String packageName)
        throws PackageManager.NameNotFoundException {
    if (resources == null || attributeId == 0)
        return -1;
    // Create dummy theme
    final Resources.Theme tempTheme = resources.newTheme();
    // Need the theme id to apply the theme, so let's get it.
    int themeId = getPackageManager().getPackageInfo(packageName, GET_META_DATA).applicationInfo.theme;
    // Apply the theme
    tempTheme.applyStyle(themeId, false);
    // Attempt to get styled values now
    final TypedArray array = tempTheme.obtainStyledAttributes(new int[] { attributeId });
    // Styled color
    int color = array.getColor(0, NO_COLOR);
    array.recycle();/*  w  ww  .j a v  a  2s .  c  om*/
    if (color == ContextCompat.getColor(this, R.color.md_grey_100)
            || color == ContextCompat.getColor(this, R.color.md_grey_900)) {
        color = NO_COLOR;
    }
    return color;
}

From source file:ca.hoogit.garagepi.Controls.DoorView.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.door_view, this);
    ButterKnife.bind(this);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DoorView, defStyle, 0);
    mOpenedColor = a.getColor(R.styleable.DoorView_openedColor,
            ContextCompat.getColor(context, R.color.colorAccent));
    mClosedColor = a.getColor(R.styleable.DoorView_closedColor,
            ContextCompat.getColor(context, R.color.colorPrimary));
    mDoorName = a.getString(R.styleable.DoorView_doorName);
    a.recycle();/*from  w  w w.  j  a va  2s.  c  om*/

    mContext = context;

    mToggleContainer.setOnClickListener(OnSingleClickListener.wrap(v -> {
        if (mOnToggle != null) {
            mOnToggle.onToggle(mDoorName);
        }
    }));

    mToggleContainer.setOnTouchListener((v, event) -> {
        int origColor = mDoorValue ? mOpenedColor : mClosedColor;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mToggleContainer.setBackgroundColor(ColorUtil.darken(origColor));
        } else if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            mToggleContainer.setBackgroundColor(origColor);
        }
        return false;
    });

    setupViews();
}

From source file:com.filemanager.free.ui.views.FastScroller.java

int resolveColor(@NonNull Context context, @AttrRes int i) {
    TypedArray obtainStyledAttributes = context.obtainStyledAttributes(new int[] { i });
    int color = obtainStyledAttributes.getColor(0, 0);
    obtainStyledAttributes.recycle();/*from   ww w.ja va2  s.  c  o m*/
    return color;
}

From source file:com.astuetz.viewpager.extensions.FixedTabsView.java

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

    this.mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);//from w  ww.j  a v  a 2  s  . c  o  m
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setOrientation(LinearLayout.HORIZONTAL);
}

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;

    {/*from w  ww.  j av  a  2  s.c  om*/
        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:android_network.hetnet.vpn_service.AdapterAccess.java

public AdapterAccess(Context context, Cursor cursor) {
    super(context, cursor, 0);
    colID = cursor.getColumnIndex("ID");
    colVersion = cursor.getColumnIndex("version");
    colProtocol = cursor.getColumnIndex("protocol");
    colDaddr = cursor.getColumnIndex("daddr");
    colDPort = cursor.getColumnIndex("dport");
    colTime = cursor.getColumnIndex("time");
    colAllowed = cursor.getColumnIndex("allowed");
    colBlock = cursor.getColumnIndex("block");
    colSent = cursor.getColumnIndex("sent");
    colReceived = cursor.getColumnIndex("received");
    colConnections = cursor.getColumnIndex("connections");

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {/* w  w  w . j  a v  a  2  s  . c o m*/
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;
}