Java Code Examples for android.content.Context#getTheme()
The following examples show how to use
android.content.Context#getTheme() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorTextView.java From timecat with Apache License 2.0 | 6 votes |
private void init(Context context, AttributeSet attrs, int defStyleAttr) { final Resources.Theme theme = context.getTheme(); int[] styles = new int[]{-2000244}; TypedArray a = theme.obtainStyledAttributes(attrs, styles, defStyleAttr, 0); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case -2002018: mText = a.getText(attr); break; } } a.recycle(); if (!TextUtils.isEmpty(mText)) { setColorText((String) mText); } }
Example 2
Source File: RecyclerAdapterSlotsItem.java From intra42 with Apache License 2.0 | 6 votes |
RecyclerAdapterSlotsItem(Context context, List<SlotsTools.SlotsGroup> slots) { this.context = context; this.slots = slots; Resources.Theme theme = context.getTheme(); // Get the primary text color of the theme TypedValue typedValueDefault = new TypedValue(); theme.resolveAttribute(android.R.attr.textColorPrimary, typedValueDefault, true); TypedArray arrDefault = context.obtainStyledAttributes(typedValueDefault.data, new int[]{android.R.attr.textColorPrimary}); textColorDefault = arrDefault.getColor(0, -1); arrDefault.recycle(); TypedValue typedValueError = new TypedValue(); theme.resolveAttribute(R.attr.colorError, typedValueError, true); TypedArray arrError = context.obtainStyledAttributes(typedValueError.data, new int[]{R.attr.colorError}); textColorError = arrError.getColor(0, -1); arrError.recycle(); }
Example 3
Source File: TVShowListFragment.java From Kore with Apache License 2.0 | 6 votes |
public TVShowsAdapter(Context context) { // Get the default accent color Resources.Theme theme = context.getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorAccent, R.attr.colorInProgress, R.attr.colorFinished }); themeAccentColor = styledAttributes.getColor(styledAttributes.getIndex(0), getResources().getColor(R.color.default_accent)); inProgressColor = styledAttributes.getColor(styledAttributes.getIndex(1), getResources().getColor(R.color.orange_500)); finishedColor = styledAttributes.getColor(styledAttributes.getIndex(2), getResources().getColor(R.color.light_green_600)); styledAttributes.recycle(); this.hostManager = HostManager.getInstance(context); // Get the art dimensions // Use the same dimensions as in the details fragment, so that it hits Picasso's cache when // the user transitions to that fragment, avoiding another call and imediatelly showing the image Resources resources = context.getResources(); artWidth = (int)(resources.getDimension(R.dimen.now_playing_poster_width) / UIUtils.IMAGE_RESIZE_FACTOR); artHeight = (int)(resources.getDimension(R.dimen.now_playing_poster_height) / UIUtils.IMAGE_RESIZE_FACTOR); }
Example 4
Source File: AbstractCalendarView.java From holo-calendar with Apache License 2.0 | 6 votes |
private void parseAttributes(final Context context, final AttributeSet attrs) { final Resources.Theme theme = context.getTheme(); if(theme != null) { TypedArray a = theme.obtainStyledAttributes( attrs, R.styleable.AbstractCalendarView, 0, 0); try { // Retrieve the first day of week //noinspection ConstantConditions final int firstDay = a.getInt(R.styleable.AbstractCalendarView_firstDayOfWeek, Calendar.MONDAY); setFirstDayOfWeek(firstDay); // Retrieve the last day of week final int lastDay = a.getInt(R.styleable.AbstractCalendarView_firstDayOfWeek, Calendar.SUNDAY); setLastDayOfWeek(lastDay); // Retrieve the style for the day views mDayStyle = a.getInt(R.styleable.AbstractCalendarView_dayStyle, DayStyleFactory.DEFAULT_STYLE); } finally { //noinspection ConstantConditions a.recycle(); } } }
Example 5
Source File: TabView.java From narrate-android with Apache License 2.0 | 6 votes |
private void setAttributes(Context context, AttributeSet attrs){ Resources.Theme theme = context.getTheme(); if (theme != null) { TypedArray typedArray = theme.obtainStyledAttributes(attrs, R.styleable.TabView, 0, 0); if (typedArray != null) { int n = typedArray.getIndexCount(); for (int i = 0; i < n; i++){ int attr = typedArray.getIndex(i); switch (attr){ case R.styleable.TabView_src: int src = typedArray.getResourceId(i, 0); setIcon(src); break; case R.styleable.TabView_text: CharSequence text = typedArray.getText(attr); setText(text); break; } } typedArray.recycle(); } } }
Example 6
Source File: FooterLayout.java From Expert-Android-Programming with MIT License | 6 votes |
private void loadAttributes(Context context, AttributeSet attrs) { TypedValue outValue = new TypedValue(); Resources.Theme theme = context.getTheme(); // use ?attr/colorPrimary as background color theme.resolveAttribute(R.attr.colorPrimary, outValue, true); TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.FooterLayout, 0, 0); int containerGravity; try { setColor(a.getColor(R.styleable.FooterLayout_ft_color, outValue.data)); animationDuration = a.getInteger(R.styleable.FooterLayout_ft_anim_duration, DEFAULT_ANIMATION_DURATION); containerGravity = a.getInteger(R.styleable.FooterLayout_ft_container_gravity, 1); mFabSize = a.getInteger(R.styleable.FooterLayout_ft_fab_type, DEFAULT_FAB_SIZE); } finally { a.recycle(); } mFabExpandLayout.setGravity(getGravity(containerGravity)); }
Example 7
Source File: UIUtils.java From RetailStore with Apache License 2.0 | 6 votes |
/** * Calculates the Action Bar height in pixels. */ public static int calculateActionBarSize(Context context) { if (context == null) { return 0; } Resources.Theme curTheme = context.getTheme(); if (curTheme == null) { return 0; } TypedArray att = curTheme.obtainStyledAttributes(RES_IDS_ACTION_BAR_SIZE); if (att == null) { return 0; } float size = att.getDimension(0, 0); att.recycle(); return (int) size; }
Example 8
Source File: PandroidCompatViewFactory.java From pandroid with Apache License 2.0 | 6 votes |
@Override @SuppressLint("RestrictedApi") public View onCreateView(String name, Context context, AttributeSet attrs) { final Resources.Theme theme = context.getTheme(); switch (name) { case "Button": return new PandroidCompatButton(new ContextThemeWrapper(context, theme), attrs); case "EditText": return new PandroidCompatEditText(new ContextThemeWrapper(context, theme), attrs); case "RadioButton": return new PandroidCompatEditText(new ContextThemeWrapper(context, theme), attrs); case "Switch": return new PandroidCompatSwitch(new ContextThemeWrapper(context, theme), attrs); case "TextView": return new PandroidCompatTextView(new ContextThemeWrapper(context, theme), attrs); case "ToggleButton": return new ToggleButton(new ContextThemeWrapper(context, theme), attrs); default: return null; } }
Example 9
Source File: MaterialTextView.java From material-components-android with Apache License 2.0 | 6 votes |
public MaterialTextView( @NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(wrap(context, attrs, defStyleAttr, defStyleRes), attrs, defStyleAttr); // Ensure we are using the correctly themed context rather than the context that was passed in. context = getContext(); if (canApplyTextAppearanceLineHeight(context)) { final Resources.Theme theme = context.getTheme(); if (!viewAttrsHasLineHeight(context, theme, attrs, defStyleAttr, defStyleRes)) { int resId = findViewAppearanceResourceId(theme, attrs, defStyleAttr, defStyleRes); if (resId != -1) { applyLineHeightFromViewAppearance(theme, resId); } } } }
Example 10
Source File: ThemeUtil.java From droidddle with Apache License 2.0 | 5 votes |
public static Drawable getThemeDrawable(Context context, int res) { Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(new int[]{res}); Drawable result = a.getDrawable(0); a.recycle(); return result; }
Example 11
Source File: AttrsHelper.java From GithubTrends with Apache License 2.0 | 5 votes |
public static int getColor(Context context, int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(attr, typedValue, true); int color = typedValue.data; return color; }
Example 12
Source File: ViewHelper.java From WanAndroid with GNU General Public License v3.0 | 5 votes |
@ColorInt private static int getColorAttr(@NonNull Context context, int attr) { Resources.Theme theme = context.getTheme(); TypedArray typedArray = theme.obtainStyledAttributes(new int[]{attr}); final int color = typedArray.getColor(0, Color.LTGRAY); typedArray.recycle(); return color; }
Example 13
Source File: ThemeUtil.java From droidddle with Apache License 2.0 | 5 votes |
public static int getThemeColor(Context context, int id) { Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(new int[]{id}); int result = a.getColor(0, DEFAULT_COLOR); a.recycle(); return result; }
Example 14
Source File: TitleTextView.java From RateDialog with Apache License 2.0 | 5 votes |
private int getPrimaryTextColor(Context context) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true); TypedArray arr = context.obtainStyledAttributes(typedValue.data, new int[]{ android.R.attr.textColorPrimary}); int color = arr.getColor(0, -1); arr.recycle(); return color; }
Example 15
Source File: WaypointList.java From msdkui-android with Apache License 2.0 | 5 votes |
@ColorInt private int getListDividerColor(final Context context) { final TypedValue typedValue = new TypedValue(); final Resources.Theme theme = context.getTheme(); theme.resolveAttribute(R.attr.colorDividerLight, typedValue, true); return typedValue.data; }
Example 16
Source File: Util.java From XPrivacyLua with GNU General Public License v3.0 | 4 votes |
public static int resolveColor(Context context, int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(attr, typedValue, true); return typedValue.data; }
Example 17
Source File: TapTargetView.java From styT with Apache License 2.0 | 4 votes |
protected void applyTargetOptions(Context context) { shouldTintTarget = target.tintTarget; shouldDrawShadow = target.drawShadow; cancelable = target.cancelable; // We can't clip out portions of a view outline, so if the user specified a transparent // target, we need to fallback to drawing a jittered shadow approximation if (shouldDrawShadow && Build.VERSION.SDK_INT >= 21 && !target.transparentTarget) { outlineProvider = new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { if (outerCircleCenter == null) return; outline.setOval( (int) (outerCircleCenter[0] - outerCircleRadius), (int) (outerCircleCenter[1] - outerCircleRadius), (int) (outerCircleCenter[0] + outerCircleRadius), (int) (outerCircleCenter[1] + outerCircleRadius)); outline.setAlpha(outerCircleAlpha / 255.0f); if (Build.VERSION.SDK_INT >= 22) { outline.offset(0, SHADOW_DIM); } } }; setOutlineProvider(outlineProvider); setElevation(SHADOW_DIM); } setLayerType(LAYER_TYPE_HARDWARE, null); final Resources.Theme theme = context.getTheme(); isDark = UiUtil.themeIntAttr(context, "isLightTheme") == 0; final Integer outerCircleColor = target.outerCircleColorInt(context); if (outerCircleColor != null) { outerCirclePaint.setColor(outerCircleColor); } else if (theme != null) { outerCirclePaint.setColor(UiUtil.themeIntAttr(context, "colorPrimary")); } else { outerCirclePaint.setColor(Color.WHITE); } final Integer targetCircleColor = target.targetCircleColorInt(context); if (targetCircleColor != null) { targetCirclePaint.setColor(targetCircleColor); } else { targetCirclePaint.setColor(isDark ? Color.BLACK : Color.WHITE); } if (target.transparentTarget) { targetCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } targetCirclePulsePaint.setColor(targetCirclePaint.getColor()); final Integer targetDimColor = target.dimColorInt(context); if (targetDimColor != null) { dimColor = UiUtil.setAlpha(targetDimColor, 0.3f); } else { dimColor = -1; } final Integer titleTextColor = target.titleTextColorInt(context); if (titleTextColor != null) { titlePaint.setColor(titleTextColor); } else { titlePaint.setColor(isDark ? Color.BLACK : Color.WHITE); } final Integer descriptionTextColor = target.descriptionTextColorInt(context); if (descriptionTextColor != null) { descriptionPaint.setColor(descriptionTextColor); } else { descriptionPaint.setColor(titlePaint.getColor()); } if (target.titleTypeface != null) { titlePaint.setTypeface(target.titleTypeface); } if (target.descriptionTypeface != null) { descriptionPaint.setTypeface(target.descriptionTypeface); } }
Example 18
Source File: AbsSkinHandler.java From NightOwl with Apache License 2.0 | 4 votes |
@Override public void collect(int mode, View view, Context context, AttributeSet attrs) { Log.d(TAG, String.format("collected %s %s %s", view, context, attrs)); ColorBox box = ColorBox.newInstance(); onBeforeCollect(view,context,attrs,box); final Resources.Theme theme = context.getTheme(); int systemStyleResId = 0; Class clz = this.getClass(); // SystemStyleable OwlSysStyleable systemStyleable = (OwlSysStyleable) clz.getAnnotation(OwlSysStyleable.class); if ( systemStyleable != null ){ String value = systemStyleable.value(); systemStyleResId = attrs.getAttributeResourceValue(ANDROID_XML, value, 0); } // OwlStyleable Field[] fields = clz.getFields(); for ( Field field : fields ){ OwlStyleable owlStyleable = field.getAnnotation(OwlStyleable.class); if ( owlStyleable == null ) continue; Class scopeClz = field.getDeclaringClass(); OwlAttrScope owlAttrScope = (OwlAttrScope) scopeClz.getAnnotation(OwlAttrScope.class); if ( owlAttrScope == null ) continue; int scope = owlAttrScope.value(); int[] styleableResId = getStaticFieldIntArraySafely(field); if ( styleableResId == null ) continue; TypedArray a = theme.obtainStyledAttributes(attrs, styleableResId, 0, systemStyleResId); if ( a != null ){ obtainStyle(view, box, scope, a); a.recycle(); } } onAfterCollect(view,context,attrs,box); insertSkinBox(view, box); // first refresh box.refreshSkin(mode, view, true); }
Example 19
Source File: Utils.java From Man-Man with GNU General Public License v3.0 | 4 votes |
public static int getThemedResource(Context context, int resource) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); theme.resolveAttribute(resource, typedValue, true); return typedValue.resourceId; }
Example 20
Source File: Carbon.java From Carbon with Apache License 2.0 | 4 votes |
public static Drawable getThemeDrawable(Context context, int attr) { Resources.Theme theme = context.getTheme(); TypedValue typedValue = new TypedValue(); theme.resolveAttribute(attr, typedValue, true); return typedValue.resourceId != 0 ? ContextCompat.getDrawable(context, typedValue.resourceId) : null; }