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 @ColorInt int getColor(Context context, @AttrRes int attribute) {
    TypedValue value = new TypedValue();
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        return value.data;
    } else {/*from  ww w  .  ja  va2s.c  o m*/
        return Color.BLACK;
    }
}

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

static @ColorInt int getColor(Context context, @AttrRes int attribute) {
    TypedValue value = new TypedValue();
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        return value.data;
    } else {/*from   ww  w.ja va 2 s .  com*/
        return Color.BLACK;
    }
}

From source file:Main.java

public static Drawable getDrawable(Context context, int resId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return context.getResources().getDrawable(resId, context.getTheme());
    } else {//from w  w  w.  j ava  2s  .  c  o  m
        return context.getResources().getDrawable(resId);
    }
}

From source file:org.bubenheimer.android.preference.EditNonNegIntPreference.java

private static Pair<Integer, Integer> extractMinMax(final Context context, final AttributeSet attrs) {
    final int min;
    final int max;
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditNonNegIntPreference,
            0, 0);/*from w  ww. ja  v  a 2s. c  om*/
    try {
        min = a.getInteger(R.styleable.EditNonNegIntPreference_min, 0);
        max = a.getInteger(R.styleable.EditNonNegIntPreference_max, Integer.MAX_VALUE);
    } finally {
        a.recycle();
    }
    return new Pair<>(min, max);
}

From source file:org.tasks.ui.MenuColorizer.java

public static void colorToolbar(Context context, Toolbar toolbar) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.actionBarPrimaryText, typedValue, true);
    colorToolbar(toolbar, typedValue.data);
}

From source file:eu.power_switch.gui.ThemeHelper.java

/**
 * Get Color from Theme attribute/* w  w  w. j  a va2s  .c o  m*/
 *
 * @param context Activity context
 * @param attr    Attribute ressource ID
 * @return Color as Int
 */
@ColorInt
public static int getThemeAttrColor(Context context, @AttrRes int attr) {
    TypedValue typedValue = new TypedValue();
    if (context.getTheme().resolveAttribute(attr, typedValue, true)) {
        if (typedValue.type >= TypedValue.TYPE_FIRST_INT && typedValue.type <= TypedValue.TYPE_LAST_INT) {
            return typedValue.data;
        } else if (typedValue.type == TypedValue.TYPE_STRING) {
            return ContextCompat.getColor(context, typedValue.resourceId);
        }
    }

    return 0;
}

From source file:Main.java

@SuppressLint("NewApi")
public static void setTextColor(Context ctx, TextView view, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        view.setTextColor(ctx.getResources().getColor(id, ctx.getTheme()));
    } else {/*w  w  w. j a  v a2s  .  c om*/
        view.setTextColor(ctx.getResources().getColor(id));
    }
}

From source file:Main.java

/**
 * Get color//w  w w  .j  av a 2 s .  c o m
 *
 * @param context Context
 * @param colorId color defined in colors.xml
 * @return color
 * @see android.content.res.Resources#getColor(int)
 */
public static int getColor(Context context, int colorId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getResources().getColor(colorId, context.getTheme());
    } else {
        return context.getResources().getColor(colorId);
    }
}

From source file:org.mozilla.focus.utils.DrawableUtils.java

public static Drawable loadAndTintDrawable(@NonNull Context context, @DrawableRes int resourceId,
        @ColorInt int color) {
    final Drawable drawable = context.getResources().getDrawable(resourceId, context.getTheme());
    final Drawable wrapped = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTint(wrapped, color);
    return wrapped;
}

From source file:com.zzc.androidtrain.view.refresh.Utils.java

public static int getActionBarSize(Context context) {
    TypedArray styledAttributes = context.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int size = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();//ww w  .j a v a  2s . co  m
    return size;
}