android.content.res.Resources.Theme#resolveAttributes()源码实例Demo

下面列出了android.content.res.Resources.Theme#resolveAttributes() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: GradientColor.java
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();
}
 
源代码2 项目: android_9.0.0_r45   文件: ColorStateList.java
/**
 * Applies a theme to this color state list.
 * <p>
 * <strong>Note:</strong> Applying a theme may affect the changing
 * configuration parameters of this color state list. After calling this
 * method, any dependent configurations must be updated by obtaining the
 * new configuration mask from {@link #getChangingConfigurations()}.
 *
 * @param t the theme to apply
 */
private void applyTheme(Theme t) {
    if (mThemeAttrs == null) {
        return;
    }

    boolean hasUnresolvedAttrs = false;

    final int[][] themeAttrsList = mThemeAttrs;
    final int N = themeAttrsList.length;
    for (int i = 0; i < N; i++) {
        if (themeAttrsList[i] != null) {
            final TypedArray a = t.resolveAttributes(themeAttrsList[i],
                    R.styleable.ColorStateListItem);

            final float defaultAlphaMod;
            if (themeAttrsList[i][R.styleable.ColorStateListItem_color] != 0) {
                // If the base color hasn't been resolved yet, the current
                // color's alpha channel is either full-opacity (if we
                // haven't resolved the alpha modulation yet) or
                // pre-modulated. Either is okay as a default value.
                defaultAlphaMod = Color.alpha(mColors[i]) / 255.0f;
            } else {
                // Otherwise, the only correct default value is 1. Even if
                // nothing is resolved during this call, we can apply this
                // multiple times without losing of information.
                defaultAlphaMod = 1.0f;
            }

            // Extract the theme attributes, if any, before attempting to
            // read from the typed array. This prevents a crash if we have
            // unresolved attrs.
            themeAttrsList[i] = a.extractThemeAttrs(themeAttrsList[i]);
            if (themeAttrsList[i] != null) {
                hasUnresolvedAttrs = true;
            }

            final int baseColor = a.getColor(
                    R.styleable.ColorStateListItem_color, mColors[i]);
            final float alphaMod = a.getFloat(
                    R.styleable.ColorStateListItem_alpha, defaultAlphaMod);
            mColors[i] = modulateColorAlpha(baseColor, alphaMod);

            // Account for any configuration changes.
            mChangingConfigurations |= a.getChangingConfigurations();

            a.recycle();
        }
    }

    if (!hasUnresolvedAttrs) {
        mThemeAttrs = null;
    }

    onColorsChanged();
}
 
源代码3 项目: android_9.0.0_r45   文件: GradientColor.java
/**
 * Apply theme to all the items.
 */
private void applyItemsAttrsTheme(Theme t) {
    if (mItemsThemeAttrs == null) {
        return;
    }

    boolean hasUnresolvedAttrs = false;

    final int[][] themeAttrsList = mItemsThemeAttrs;
    final int N = themeAttrsList.length;
    for (int i = 0; i < N; i++) {
        if (themeAttrsList[i] != null) {
            final TypedArray a = t.resolveAttributes(themeAttrsList[i],
                    R.styleable.GradientColorItem);

            // Extract the theme attributes, if any, before attempting to
            // read from the typed array. This prevents a crash if we have
            // unresolved attrs.
            themeAttrsList[i] = a.extractThemeAttrs(themeAttrsList[i]);
            if (themeAttrsList[i] != null) {
                hasUnresolvedAttrs = true;
            }

            mItemColors[i] = a.getColor(R.styleable.GradientColorItem_color, mItemColors[i]);
            mItemOffsets[i] = a.getFloat(R.styleable.GradientColorItem_offset, mItemOffsets[i]);
            if (DBG_GRADIENT) {
                Log.v(TAG, "applyItemsAttrsTheme Colors[i] " + i + " " +
                        Integer.toHexString(mItemColors[i]));
                Log.v(TAG, "Offsets[i] " + i + " " + mItemOffsets[i]);
            }

            // Account for any configuration changes.
            mChangingConfigurations |= a.getChangingConfigurations();

            a.recycle();
        }
    }

    if (!hasUnresolvedAttrs) {
        mItemsThemeAttrs = null;
    }
}