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.doctoror.fuckoffmusicplayer.presentation.util.DrawableUtils.java

@Nullable
public static Drawable getTintedDrawableFromAttrTint(@NonNull final Context context,
        @Nullable final Drawable src, @AttrRes final int tintAttr) {
    return getTintedDrawable(src, ThemeUtils.getColorStateList(context.getTheme(), tintAttr));
}

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

public static Drawable getDrawable(Context context, @AttrRes int attribute, @DrawableRes int fallbackDrawable) {
    TypedValue value = new TypedValue();
    @DrawableRes/*from  ww w  .j a v a2 s. c  o  m*/
    int resourceId;
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        resourceId = value.resourceId;
    } else {
        resourceId = fallbackDrawable;
    }
    return ContextCompat.getDrawable(context, resourceId);
}

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

static Drawable getDrawable(Context context, @AttrRes int attribute, @DrawableRes int fallbackDrawable) {
    TypedValue value = new TypedValue();
    @DrawableRes//  w w w . ja  v  a2 s. c o m
    int resourceId;
    if (context.getTheme().resolveAttribute(attribute, value, true)) {
        resourceId = value.resourceId;
    } else {
        resourceId = fallbackDrawable;
    }
    return ContextCompat.getDrawable(context, resourceId);
}

From source file:com.andryr.guitartuner.Utils.java

public static int getAttrColor(Context context, int attrId) {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    theme.resolveAttribute(attrId, typedValue, true);
    if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
            && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return typedValue.data;
    } else {//w  ww  . j a  v  a 2s .  co  m
        return context.getResources().getColor(typedValue.resourceId);
    }
}

From source file:com.bobomee.android.recyclerviewhelperdemo.fragment.FastScrollFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static int getColorAccent(Context context) {
    int accentAttr = android.R.attr.colorAccent;
    TypedArray androidAttr = context.getTheme().obtainStyledAttributes(new int[] { accentAttr });
    int colorAccent = androidAttr.getColor(0, 0xFF009688); //Default: material_deep_teal_500
    androidAttr.recycle();/*from ww  w. j a v  a 2s .  co m*/
    return colorAccent;
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.DrawableUtils.java

@Nullable
public static Drawable getTintedDrawableFromAttrTint(@NonNull final Context context, @DrawableRes final int res,
        @AttrRes final int tintAttr) {
    return getTintedDrawable(context, res, ThemeUtils.getColorStateList(context.getTheme(), tintAttr));
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
        view.setBackground(ctx.getResources().getDrawable(night ? darkResId : lightResId, ctx.getTheme()));
    } else {// www .  j  a  v  a 2  s.com
        view.setBackgroundDrawable(ctx.getResources().getDrawable(night ? darkResId : lightResId));
    }
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.DrawableUtils.java

@Nullable
public static Drawable getTintedDrawable(@NonNull final Context context, @DrawableRes final int res,
        @ColorInt final int tint) {
    final Drawable d = ResourcesCompat.getDrawable(context.getResources(), res, context.getTheme());
    return getTintedDrawable(d, tint);
}

From source file:Main.java

/**
 * Last but not least, try to pull the Font Path from the Theme, which is defined.
 *
 * @param context     Activity Context//from  w  ww. j a va 2  s  .  c om
 * @param styleAttrId Theme style id
 * @param attributeId if -1 returns null.
 * @return null if no theme or attribute defined.
 */
static String pullFontPathFromTheme(Context context, int styleAttrId, int attributeId) {
    if (styleAttrId == -1 || attributeId == -1)
        return null;

    final Resources.Theme theme = context.getTheme();
    final TypedValue value = new TypedValue();

    theme.resolveAttribute(styleAttrId, value, true);
    final TypedArray typedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { attributeId });
    try {
        String font = typedArray.getString(0);
        return font;
    } catch (Exception ignore) {
        // Failed for some reason.
        return null;
    } finally {
        typedArray.recycle();
    }
}

From source file:com.monmonja.library.utils.ViewUtils.java

public static void makeToast(Context context, int resId) {
    TypedValue tv = new TypedValue();
    int offsetY = 0;
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        offsetY = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }//from  w ww. j ava2 s.  com

    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    View view = toast.getView();
    view.setBackgroundColor(context.getResources().getColor(R.color.toast_background));
    TextView text = (TextView) view.findViewById(android.R.id.message);
    text.setTextColor(context.getResources().getColor(android.R.color.white));
    toast.show();
}