android.content.res.Resources.Theme Java Examples
The following examples show how to use
android.content.res.Resources.Theme.
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: VectorDrawable.java From Mover with Apache License 2.0 | 6 votes |
@Override public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { // TODO THEME Not supported yet Theme theme = null; final VectorDrawableState state = mVectorState; state.mVPathRenderer = new VPathRenderer(); final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawable); updateStateFromTypedArray(a); a.recycle(); state.mCacheDirty = true; inflateInternal(res, parser, attrs, theme); mTintFilter = updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode); }
Example #2
Source File: ColorStateList.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Creates a ColorStateList from an XML document using given a set of * {@link Resources} and a {@link Theme}. * * @param r Resources against which the ColorStateList should be inflated. * @param parser Parser for the XML document defining the ColorStateList. * @param theme Optional theme to apply to the color state list, may be * {@code null}. * @return A new color state list. */ @NonNull public static ColorStateList createFromXml(@NonNull Resources r, @NonNull XmlPullParser parser, @Nullable Theme theme) throws XmlPullParserException, IOException { final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Seek parser to start tag. } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } return createFromXmlInner(r, parser, attrs, theme); }
Example #3
Source File: JarMainBFragmentActivity.java From letv with Apache License 2.0 | 6 votes |
public void setOverrideResources(JarResources myres) { JLog.i("clf", "setOverrideResources...myres=" + myres); if (myres == null) { this.myResources = null; this.resources = null; this.assetManager = null; this.theme = null; return; } this.myResources = myres; JLog.i("clf", "setOverrideResources...this.myResources=" + this.myResources); this.resources = myres.getResources(); JLog.i("clf", "setOverrideResources...this.resources=" + this.resources); this.assetManager = myres.getAssets(); JLog.i("clf", "setOverrideResources...this.assetManager=" + this.assetManager); Theme t = myres.getResources().newTheme(); JLog.i("clf", "setOverrideResources...t=" + t); t.setTo(getTheme()); this.theme = t; JLog.i("clf", "setOverrideResources...this.theme=" + this.theme); }
Example #4
Source File: LayerDrawable.java From RippleDrawable with MIT License | 6 votes |
private void updateLayerFromTypedArray(Theme theme, TypedValue[] extracted, ChildDrawable layer, TypedArray a) { final LayerState state = mLayerState; // Account for any configuration changes. state.mChildrenChangingConfigurations |= TypedArrayCompat.getChangingConfigurations(a); // Extract the theme attributes, if any. layer.mThemeAttrs = TypedArrayCompat.extractThemeAttrs(a); layer.mInsetL = getDimensionPixelOffset(theme, a, extracted, R.styleable.LayerDrawableItem_android_left, layer.mInsetL); layer.mInsetT = getDimensionPixelOffset(theme, a, extracted, R.styleable.LayerDrawableItem_android_top, layer.mInsetT); layer.mInsetR = getDimensionPixelOffset(theme, a, extracted, R.styleable.LayerDrawableItem_android_right, layer.mInsetR); layer.mInsetB = getDimensionPixelOffset(theme, a, extracted, R.styleable.LayerDrawableItem_android_bottom, layer.mInsetB); layer.mId = getResourceId(theme, a, extracted, R.styleable.LayerDrawableItem_android_id, layer.mId); final Drawable dr = TypedArrayCompat.getDrawable(theme, a, extracted, R.styleable.LayerDrawableItem_android_drawable); if (dr != null) { layer.mDrawable = dr; } }
Example #5
Source File: GradientColor.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Fill in this object based on the contents of an XML "gradient" element. */ private void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException { final TypedArray a = Resources.obtainAttributes(r, theme, attrs, R.styleable.GradientColor); updateRootElementState(a); mChangingConfigurations |= a.getChangingConfigurations(); a.recycle(); // Check correctness and throw exception if errors found. validateXmlContent(); inflateChildElements(r, parser, attrs, theme); onColorsChange(); }
Example #6
Source File: AnimatorInflater.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static int inferValueTypeOfKeyframe(Resources res, Theme theme, AttributeSet attrs) { int valueType; TypedArray a; if (theme != null) { a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0); } else { a = res.obtainAttributes(attrs, R.styleable.Keyframe); } TypedValue keyframeValue = a.peekValue(R.styleable.Keyframe_value); boolean hasValue = (keyframeValue != null); // When no value type is provided, check whether it's a color type first. // If not, fall back to default value type (i.e. float type). if (hasValue && isColorType(keyframeValue.type)) { valueType = VALUE_TYPE_COLOR; } else { valueType = VALUE_TYPE_FLOAT; } a.recycle(); return valueType; }
Example #7
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 #8
Source File: ThemeUtils.java From Android-MaterialPreference with MIT License | 6 votes |
@TargetApi(LOLLIPOP) static int resolveAccentColor(Context context) { Theme theme = context.getTheme(); // on Lollipop, grab system colorAccent attribute // pre-Lollipop, grab AppCompat colorAccent attribute // finally, check for custom mp_colorAccent attribute int attr = isAtLeastL() ? android.R.attr.colorAccent : R.attr.colorAccent; TypedArray typedArray = theme.obtainStyledAttributes(new int[] { attr, R.attr.mp_colorAccent }); int accentColor = typedArray.getColor(0, FALLBACK_COLOR); accentColor = typedArray.getColor(1, accentColor); typedArray.recycle(); return accentColor; }
Example #9
Source File: MaterialTextView.java From material-components-android with Apache License 2.0 | 6 votes |
private static boolean viewAttrsHasLineHeight( @NonNull Context context, @NonNull Theme theme, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray attributes = theme.obtainStyledAttributes( attrs, R.styleable.MaterialTextView, defStyleAttr, defStyleRes); int lineHeight = readFirstAvailableDimension( context, attributes, R.styleable.MaterialTextView_android_lineHeight, R.styleable.MaterialTextView_lineHeight); attributes.recycle(); return lineHeight != -1; }
Example #10
Source File: LayerDrawable.java From RippleDrawable with MIT License | 5 votes |
@Override public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException { super.inflate(r, parser, attrs, theme); final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable); updateStateFromTypedArray(theme, a, null); a.recycle(); inflateLayers(r, parser, attrs, theme); ensurePadding(); onStateChange(getState()); }
Example #11
Source File: LayerDrawable.java From RippleDrawable with MIT License | 5 votes |
/** * Initializes the constant state from the values in the typed array. */ private void updateStateFromTypedArray(Theme theme, TypedArray a, TypedValue[] extracted) { final LayerState state = mLayerState; // Account for any configuration changes. state.mChangingConfigurations |= TypedArrayCompat.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mThemeAttrs = TypedArrayCompat.extractThemeAttrs(a); mOpacityOverride = a.getInt(R.styleable.LayerDrawable_android_opacity, mOpacityOverride); state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_android_autoMirrored, state.mAutoMirrored); state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_android_paddingMode, state.mPaddingMode); }
Example #12
Source File: ActionController.java From science-journal with Apache License 2.0 | 5 votes |
/** * Updates the title bar for {@link ActionFragment} when a recording starts/stops. */ public void attachTitleBar(View titleBarView, boolean isTwoPane, OnClickListener listener, boolean hideDuringRecording, int titleResource, int iconResource) { titleBarView .findViewById(R.id.title_bar_close) .setOnClickListener(listener); ((TextView) titleBarView.findViewById(R.id.title_bar_text)) .setText(titleResource); ImageView icon = titleBarView.findViewById(R.id.title_bar_icon); if (isTwoPane) { recordingStatus .takeUntil(RxView.detaches(titleBarView)) .subscribe( status -> { Theme theme = titleBarView.getContext().getTheme(); if (status.state.shouldShowStopButton()) { theme = new ContextThemeWrapper( titleBarView.getContext(), R.style.RecordingProgressBarColor).getTheme(); if (hideDuringRecording) { titleBarView.setVisibility(View.GONE); } } else { titleBarView.setVisibility(View.VISIBLE); } icon.setImageDrawable( ResourcesCompat.getDrawable( titleBarView.getResources(), iconResource, theme)); }); } else { titleBarView.setVisibility(View.GONE); } }
Example #13
Source File: ThemeUtil.java From materialup with Apache License 2.0 | 5 votes |
public static boolean getThemeDark(Context context, int id) { Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(new int[]{id}); boolean result = a.getBoolean(0, false); a.recycle(); return result; }
Example #14
Source File: AccelerateInterpolator.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public AccelerateInterpolator(Resources res, Theme theme, AttributeSet attrs) { TypedArray a; if (theme != null) { a = theme.obtainStyledAttributes(attrs, R.styleable.AccelerateInterpolator, 0, 0); } else { a = res.obtainAttributes(attrs, R.styleable.AccelerateInterpolator); } mFactor = a.getFloat(R.styleable.AccelerateInterpolator_factor, 1.0f); mDoubleFactor = 2 * mFactor; setChangingConfiguration(a.getChangingConfigurations()); a.recycle(); }
Example #15
Source File: VectorDrawable.java From MrVector with MIT License | 5 votes |
public void applyTheme(Theme t) { if (mThemeAttrs == null) { return; } /* TODO TINT THEME Not supported yet final TypedArray a = t.resolveAttributes(mThemeAttrs, R.styleable.VectorDrawableGroup); updateStateFromTypedArray(a); a.recycle(); */ }
Example #16
Source File: DecelerateInterpolator.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public DecelerateInterpolator(Resources res, Theme theme, AttributeSet attrs) { TypedArray a; if (theme != null) { a = theme.obtainStyledAttributes(attrs, R.styleable.DecelerateInterpolator, 0, 0); } else { a = res.obtainAttributes(attrs, R.styleable.DecelerateInterpolator); } mFactor = a.getFloat(R.styleable.DecelerateInterpolator_factor, 1.0f); setChangingConfiguration(a.getChangingConfigurations()); a.recycle(); }
Example #17
Source File: LayerDrawable.java From RippleDrawable with MIT License | 5 votes |
/** * Obtains styled attributes from the theme, if available, or unstyled * resources if the theme is null. */ static TypedArray obtainAttributes(Resources res, Theme theme, AttributeSet set, int[] attrs) { if (theme == null) { return res.obtainAttributes(set, attrs); } return theme.obtainStyledAttributes(set, attrs, 0, 0); }
Example #18
Source File: ColorStateList.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Create from inside an XML document. Called on a parser positioned at a * tag in an XML document, tries to create a ColorStateList from that tag. * * @throws XmlPullParserException if the current tag is not <selector> * @return A new color state list for the current tag. */ @NonNull static ColorStateList createFromXmlInner(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException { final String name = parser.getName(); if (!name.equals("selector")) { throw new XmlPullParserException( parser.getPositionDescription() + ": invalid color state list tag " + name); } final ColorStateList colorStateList = new ColorStateList(); colorStateList.inflate(r, parser, attrs, theme); return colorStateList; }
Example #19
Source File: VectorDrawable.java From MrVector with MIT License | 5 votes |
@Override @TargetApi(LOLLIPOP) public void applyTheme(Theme t) { if (LOLLIPOP_PLUS) { super.applyTheme(t); } final VectorDrawableState state = mVectorState; if (state != null && state.mThemeAttrs != null) { /* TODO THEME Not supported yet final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.VectorDrawable); try { state.mCacheDirty = true; updateStateFromTypedArray(a); } catch (XmlPullParserException e) { throw new RuntimeException(e); } finally { a.recycle(); } */ mTintFilter = updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode); } final VPathRenderer path = state.mVPathRenderer; if (path != null && path.canApplyTheme()) { path.applyTheme(t); } }
Example #20
Source File: Colorful.java From MeiZiNews with MIT License | 5 votes |
/** * 修改各个视图绑定的属性 */ private void makeChange(int themeId) { Theme curTheme = mActivity.getTheme(); for (ViewSetter setter : mElements) { setter.setValue(curTheme, themeId); } }
Example #21
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 5 votes |
@Override @TargetApi(LOLLIPOP) public void applyTheme(Theme t) { if (LOLLIPOP_PLUS) { super.applyTheme(t); } final VectorDrawableState state = mVectorState; if (state != null && state.mThemeAttrs != null) { /* TODO THEME Not supported yet final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.VectorDrawable); try { state.mCacheDirty = true; updateStateFromTypedArray(a); } catch (XmlPullParserException e) { throw new RuntimeException(e); } finally { a.recycle(); } */ mTintFilter = updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode); } final VPathRenderer path = state.mVPathRenderer; if (path != null && path.canApplyTheme()) { path.applyTheme(t); } }
Example #22
Source File: GradientColor.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void applyRootAttrsTheme(Theme t) { final TypedArray a = t.resolveAttributes(mThemeAttrs, R.styleable.GradientColor); // mThemeAttrs will be set to null if if there are no theme attributes in the // typed array. mThemeAttrs = a.extractThemeAttrs(mThemeAttrs); // merging the attributes update inside the updateRootElementState(). updateRootElementState(a); // Account for any configuration changes. mChangingConfigurations |= a.getChangingConfigurations(); a.recycle(); }
Example #23
Source File: ThemeUtil.java From materialup 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 #24
Source File: VectorDrawable.java From MrVector with MIT License | 5 votes |
private VectorDrawable(VectorDrawableState state, Resources res, Theme theme) { if (theme != null && state.canApplyThemeCompat()) { // If we need to apply a theme, implicitly mutate. mVectorState = new VectorDrawableState(state); applyTheme(theme); } else { mVectorState = state; } mTintFilter = updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode); }
Example #25
Source File: ResCompat.java From NoHttp with Apache License 2.0 | 5 votes |
public static int getColor(int colorId, Theme theme) { Resources resources = NoHttp.getContext().getResources(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return resources.getColor(colorId, theme); else return resources.getColor(colorId); }
Example #26
Source File: ViewGroupSetter.java From Colorful with MIT License | 5 votes |
@Override public void setValue(Theme newTheme, int themeId) { mView.setBackgroundColor(getColor(newTheme)); // 清空AbsListView的元素 clearListViewRecyclerBin(mView); // 清空RecyclerView clearRecyclerViewRecyclerBin(mView); // 修改所有子元素的相关属性 changeChildenAttrs((ViewGroup) mView, newTheme, themeId); }
Example #27
Source File: ThemeUtils.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
/** * Returns {@link ColorStateList} for attr from the {@link Theme} * * @param theme {@link Theme} to get int from * @param attr Attribute of the int * @return {@link Drawable} for attr from the {@link Theme} */ @Nullable public static Drawable getDrawable(@NonNull final Theme theme, @AttrRes final int attr) { final TypedArray array = theme.obtainStyledAttributes(new int[]{attr}); try { return array.getDrawable(0); } finally { array.recycle(); } }
Example #28
Source File: VectorDrawable.java From Mover with Apache License 2.0 | 5 votes |
public void inflate(Resources res, AttributeSet attrs, Theme theme) { // TODO TINT THEME Not supported yet final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawableGroup); updateStateFromTypedArray(a); a.recycle(); }
Example #29
Source File: GradientColor.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void applyTheme(Theme t) { if (mThemeAttrs != null) { applyRootAttrsTheme(t); } if (mItemsThemeAttrs != null) { applyItemsAttrsTheme(t); } onColorsChange(); }
Example #30
Source File: ResCompat.java From NoHttp with Apache License 2.0 | 5 votes |
public static ColorStateList getColorStateList(int colorStateId, Theme theme) { Resources resources = NoHttp.getContext().getResources(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return resources.getColorStateList(colorStateId, theme); else return resources.getColorStateList(colorStateId); }