List of usage examples for android.content Context getTheme
@ViewDebug.ExportedProperty(deepExport = true) public abstract Resources.Theme getTheme();
From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java
/** * Helper to get the default Selectable Background. Returns the resourceId of the * {@code R.attr.selectableItemBackground} attribute of the overridden style. * * @param context the context//from ww w .ja v a 2s . c o m * @return Default selectable background resId * @since 5.0.0-b7 * @deprecated Use {@link #getSelectableItemBackground(Context)} instead. */ @Deprecated public static int getSelectableBackground(Context context) { TypedValue outValue = new TypedValue(); // It's important to not use the android.R because this wouldn't add the overridden drawable context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true); return outValue.resourceId; }
From source file:com.example.mediastock.util.Utilities.java
/** * Method used for the floating action button behaviour. */// www.j a v a 2 s .co m public static int getToolbarHeight(Context context) { final TypedArray styledAttributes = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.actionBarSize }); int toolbarHeight = (int) styledAttributes.getDimension(0, 0); styledAttributes.recycle(); return toolbarHeight; }
From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java
/** * Helper method to get the drawable by its resource. Specific to the correct android version.. * * @param context the context// ww w .j a v a 2s .c o m * @param drawableRes drawable resource id * @return the drawable object * @since 5.0.0-b7 */ public static Drawable getDrawableCompat(Context context, @DrawableRes int drawableRes) { try { if (Utils.hasLollipop()) { return context.getResources().getDrawable(drawableRes, context.getTheme()); } else { return context.getResources().getDrawable(drawableRes); } } catch (Exception ex) { return null; } }
From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java
/** * Helper to get the system default Color Control Highlight. Returns the color of the * {@code R.attr.colorControlHighlight} attribute in the overridden style. * * @param context the context/*from ww w . j a v a 2s .c o m*/ * @return Default Color Control Highlight * @since 5.0.0-b7 Created, returns the resourceId * <br/> 5.0.0-rc1 Now returns the real color (not the resourceId) */ @ColorInt public static int getColorControlHighlight(Context context) { TypedValue outValue = new TypedValue(); // It's important to not use the android.R because this wouldn't add the overridden drawable context.getTheme().resolveAttribute(R.attr.colorControlHighlight, outValue, true); if (Utils.hasMarshmallow()) return context.getColor(outValue.resourceId); else return context.getResources().getColor(outValue.resourceId); }
From source file:org.isoron.uhabits.activities.BaseScreen.java
@Deprecated public static int getDefaultActionBarColor(Context context) { if (SDK_INT < LOLLIPOP) { return ResourcesCompat.getColor(context.getResources(), R.color.grey_900, context.getTheme()); } else {/*from w w w. ja v a 2 s . c o m*/ StyledResources res = new StyledResources(context); return res.getColor(R.attr.colorPrimary); } }
From source file:org.opensilk.common.ui.util.ThemeUtils.java
public static int getDisabledThemeAttrColor(Context context, int attr) { // Now retrieve the disabledAlpha value from the theme final float disabledAlpha; synchronized (sTypedValue) { context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, sTypedValue, true); disabledAlpha = sTypedValue.getFloat(); }//from w w w .ja v a2 s .c om return getThemeAttrColor(context, attr, disabledAlpha); }
From source file:android.support.design.widget.BottomSheetDialog.java
private static int getThemeResId(Context context, int themeId) { if (themeId == 0) { // If the provided theme is 0, then retrieve the dialogTheme from our theme TypedValue outValue = new TypedValue(); if (context.getTheme().resolveAttribute(R.attr.bottomSheetDialogTheme, outValue, true)) { themeId = outValue.resourceId; } else {//w ww . jav a2 s. c o m // bottomSheetDialogTheme is not provided; we default to our light theme themeId = R.style.Theme_Design_Light_BottomSheetDialog; } } return themeId; }
From source file:com.sbgapps.simplenumberpicker.utils.ThemeUtil.java
@ColorInt public static int getThemeAccentColor(Context context) { int colorAttr; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { colorAttr = android.R.attr.colorAccent; } else {// w ww . j a v a 2s .co m colorAttr = context.getResources().getIdentifier("colorAccent", "attr", context.getPackageName()); } TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(colorAttr, outValue, true); return outValue.data; }
From source file:com.sbgapps.simplenumberpicker.utils.ThemeUtil.java
@ColorInt public static int getThemePrimaryColor(Context context) { int colorAttr; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { colorAttr = android.R.attr.colorPrimary; } else {/*from w w w . ja v a2s . com*/ colorAttr = context.getResources().getIdentifier("colorPrimary", "attr", context.getPackageName()); } TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(colorAttr, outValue, true); return outValue.data; }
From source file:com.finchuk.clock2.timepickers.Utils.java
/** * @param resId The resource identifier of the desired theme attribute. *//*from www.ja v a 2 s. c o m*/ public static int getColorFromThemeAttr(Context context, int resId) { // http://stackoverflow.com/a/28777489/5055032 final TypedValue value = new TypedValue(); context.getTheme().resolveAttribute(resId, value, true); return value.data; }