Example usage for android.content.res Resources newTheme

List of usage examples for android.content.res Resources newTheme

Introduction

In this page you can find the example usage for android.content.res Resources newTheme.

Prototype

public final Theme newTheme() 

Source Link

Document

Generate a new Theme object for this set of Resources.

Usage

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();/*from   w w w. j a va 2 s  .  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;
}