Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:com.fa.mastodon.util.ThemeUtils.java

public static @DrawableRes int getDrawableId(Context context, @AttrRes int attribute,
        @DrawableRes int fallbackDrawableId) {
    TypedValue value = new TypedValue();
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        return value.resourceId;
    } else {/*  w ww.  j a  v a  2s . c  om*/
        return fallbackDrawableId;
    }
}

From source file:com.keylesspalace.tusky.ThemeUtils.java

static @DrawableRes int getDrawableId(Context context, @AttrRes int attribute,
        @DrawableRes int fallbackDrawableId) {
    TypedValue value = new TypedValue();
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        return value.resourceId;
    } else {//from   www. j a  v a  2 s . c  om
        return fallbackDrawableId;
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
private static int getColor(Context context, int id, int defaultValue) {
    if (value == null) {
        value = new TypedValue();
    }/* w  w w  . j  av a2 s. c  o m*/

    try {
        Resources.Theme theme = context.getTheme();
        if (theme != null && theme.resolveAttribute(id, value, true)) {
            if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) {
                return value.data;
            } else if (value.type == TypedValue.TYPE_STRING) {
                return context.getResources().getColor(value.resourceId);
            }
        }
    } catch (Exception ignored) {
    }
    return defaultValue;
}

From source file:com.tr4android.support.extension.picker.PickerThemeUtils.java

public static float getDisabledAlpha(Context context) {
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    return outValue.getFloat();
}

From source file:com.dm.material.dashboard.candybar.helpers.ColorHelper.java

public static int getAttributeColor(@NonNull Context context, int attr) {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    theme.resolveAttribute(attr, typedValue, true);
    return typedValue.data;
}

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

public static float getDisabledAlpha(Context context) {
    TypedValue value = new TypedValue();
    return context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, value, true) ? value.getFloat()
            : 0.5f;//from   w  ww.  ja  v  a  2  s  .com
}

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

private static boolean isLightTheme(Context context) {
    TypedValue value = new TypedValue();
    return context.getTheme().resolveAttribute(android.support.v7.appcompat.R.attr.isLightTheme, value, true)
            && value.data != 0;//from  ww  w . j a va  2s.c o  m
}

From source file:com.kyo.fitssystemwindows.FitsSystemWindowsFrameLayout2.java

public static int getActionBarHeight(Context context) {
    int result = 0;
    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    if (tv.resourceId > 0) {

        result = context.getResources().getDimensionPixelSize(tv.resourceId);
    }//from w ww  .j a  va2s. c o m
    return result;
}

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

public static int getThemeResource(Context context, int attr) {
    TypedValue value = new TypedValue();
    return context.getTheme().resolveAttribute(attr, value, true) ? value.resourceId : 0;
}

From source file:im.ene.ribbon.MiscUtils.java

/**
 * Returns the current theme defined color
 *//* w  ww .  j  a  va2s .  c  o m*/
static int getColor(Context context, @AttrRes int color) {
    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(color, tv, true);
    return tv.data;
}