List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
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/* ww w . j a v a 2 s . c o m*/ * @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 == null) 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, 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.doctoror.fuckoffmusicplayer.presentation.util.DrawableUtils.java
@Nullable public static Drawable getTintedDrawable(@NonNull final Context context, @DrawableRes final int res, @Nullable final ColorStateList tint) { final Drawable d = ResourcesCompat.getDrawable(context.getResources(), res, context.getTheme()); return getTintedDrawable(d, tint); }
From source file:com.example.ray.firstapp.bottombar.MiscUtils.java
protected static int getColor(Context context, int color) { TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); return tv.data; }
From source file:Main.java
public static int getActionBarHeightInDp(Context context) { int actionBarHeight = 0; TypedValue tv = new TypedValue(); final DisplayMetrics dm = context.getResources().getDisplayMetrics(); if (Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) actionBarHeight = (int) TypedValue.complexToFloat(tv.data); } else {//from w w w . j a va 2 s. com tv.data = 48; actionBarHeight = (int) TypedValue.complexToFloat(tv.data); } return actionBarHeight; }
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 ava2 s.com * @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, getAttributeArray(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.android.datetimepicker.Utils.java
/** * Gets the required boolean value from the current context, if possible/available * @param context The context to use as reference for the boolean * @param attr Attribute id to resolve//w ww .j av a 2s . com * @param fallback Default value to return if no value is specified in theme * @return the boolean value from current theme */ private static boolean resolveBoolean(Context context, @AttrRes int attr, boolean fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr }); try { return a.getBoolean(0, fallback); } finally { a.recycle(); } }
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 * @param styleAttrId Theme style id//from w w w . j av a2 s . c om * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, 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); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { subStyleAttrId }); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, new int[] { attributeId }); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
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 * @param styleAttrId Theme style id//from w w w .java2 s . co m * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, int[] attributeId) { if (styleAttrId == -1 || attributeId == null) return null; final Resources.Theme theme = context.getTheme(); final TypedValue value = new TypedValue(); theme.resolveAttribute(styleAttrId, value, true); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, new int[] { subStyleAttrId }); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, attributeId); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
/** * MediaRouterThemeHelper (support-v7)// www. ja va2 s . c om */ public static boolean isLightTheme(Context context) { synchronized (sTypedValue) { return context.getTheme().resolveAttribute(R.attr.isLightTheme, sTypedValue, true) && sTypedValue.data != 0; } }
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 * @param styleAttrId Theme style id//from ww w.j av a 2s . c o m * @param subStyleAttrId the sub style from the theme to look up after the first style * @param attributeId if -1 returns null. * @return null if no theme or attribute defined. */ static String pullFontPathFromTheme(Context context, int styleAttrId, int subStyleAttrId, 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); int subStyleResId = -1; final TypedArray parentTypedArray = theme.obtainStyledAttributes(value.resourceId, getAttributeArray(subStyleAttrId)); try { subStyleResId = parentTypedArray.getResourceId(0, -1); } catch (Exception ignore) { // Failed for some reason. return null; } finally { parentTypedArray.recycle(); } if (subStyleResId == -1) return null; final TypedArray subTypedArray = context.obtainStyledAttributes(subStyleResId, getAttributeArray(attributeId)); if (subTypedArray != null) { try { return subTypedArray.getString(0); } catch (Exception ignore) { // Failed for some reason. return null; } finally { subTypedArray.recycle(); } } return null; }