android.util.TypedValue#TYPE_FIRST_COLOR_INT源码实例Demo

下面列出了android.util.TypedValue#TYPE_FIRST_COLOR_INT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: scene   文件: Utility.java
public static Drawable getWindowBackground(Context context) {
    if (context instanceof Activity) {
        throw new IllegalArgumentException("Use Scene Context instead");
    }
    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        // windowBackground is a color
        int color = a.data;
        return new ColorDrawable(color);
    } else {
        // windowBackground is not a color, probably a drawable
        Drawable d = context.getResources().getDrawable(a.resourceId);
        return d;
    }
}
 
源代码2 项目: Overchan-Android   文件: CustomThemeHelper.java
public static void setCustomTheme(Context context, SparseIntArray customAttrs) {
    if (customAttrs == null || customAttrs.size() == 0) {
        currentAttrs = null;
        return;
    }
    
    TypedValue tmp = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, tmp, true);
    int textColorPrimaryOriginal = (tmp.type >= TypedValue.TYPE_FIRST_COLOR_INT && tmp.type <= TypedValue.TYPE_LAST_COLOR_INT) ?
            tmp.data : Color.TRANSPARENT;
    int textColorPrimaryOverridden = customAttrs.get(android.R.attr.textColorPrimary, textColorPrimaryOriginal);
    
    try {
        processWindow(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden);
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    
    CustomThemeHelper instance = new CustomThemeHelper(context, customAttrs, textColorPrimaryOriginal, textColorPrimaryOverridden);
    LayoutInflaterCompat.setFactory(instance.inflater, instance);
    currentAttrs = customAttrs;
}
 
源代码3 项目: AndroidTint   文件: ThemeHelper.java
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr});
    try {
        final TypedValue value = a.peekValue(0);
        if (value == null) {
            return fallback;
        }
        if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            return getActionTextStateList(context, value.data);
        } else {
            final ColorStateList stateList = a.getColorStateList(0);
            if (stateList != null) {
                return stateList;
            } else {
                return fallback;
            }
        }
    } finally {
        a.recycle();
    }
}
 
源代码4 项目: GracefulMovies   文件: StatusView.java
public StatusView(Context context) {
    super(context);

    LayoutInflater.from(context).inflate(R.layout.layout_status_view, this, true);
    mLoadingIv = findViewById(R.id.status_loading_iv);
    mHintTv = findViewById(R.id.status_hint_tv);
    mReloadBtn = findViewById(R.id.status_reload_btn);
    mReloadBtn.setOnClickListener(v -> {
        if (mOnReloadListener != null)
            mOnReloadListener.onReconnect();
    });

    setClickable(true); // block other views' touch event who under this view

    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        // windowBackground is a color
        mBgColor = a.data;
        setBackgroundColor(mBgColor);
    } else {
        // windowBackground is not a color, probably a drawable
        mBgDrawable = context.getResources().getDrawable(a.resourceId);
        setBackground(mBgDrawable);
    }
}
 
源代码5 项目: revolution-irc   文件: LiveThemeComponent.java
public boolean addColorAttr(StyledAttributesHelper attrs,
                            int attr, LiveThemeManager.ColorPropertyApplier applier,
                            ColorStateListApplier colorStateListApplier) {
    TypedValue typedValue = new TypedValue();
    if (!attrs.getValue(attr, typedValue))
        return false;
    if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
            typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        addColorProperty(typedValue.resourceId, applier);
        return true;
    } else if (typedValue.type != TypedValue.TYPE_NULL && colorStateListApplier != null) {
        try {
            ThemedColorStateList th = ThemedColorStateList.createFromXml(
                    mContext.getResources(),
                    mContext.getResources().getXml(typedValue.resourceId), getTheme());
            th.attachToComponent(this, () ->
                    colorStateListApplier.onColorStateListChanged(th.createColorStateList()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    return false;
}
 
private View setOnClick(@IdRes int viewID, Class aActivity) {
	View view = getActivity().findViewById(viewID);

	if(getActivity().getClass() == aActivity) {
		// Get the attribute highlight color
		TypedValue a = new TypedValue();
		getActivity().getTheme().resolveAttribute(R.attr.navigationDrawerHighlighted, a, true);
		if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
			int color = a.data;
			view.setBackgroundColor(color);
		}

		setCloseDrawerOnClick(view, mDrawerLayout, containerView);
	} else {
		setStandardOnClick(view, getActivity(), aActivity, mDrawerLayout, containerView);
	}

	return view;
}
 
源代码7 项目: talk-android   文件: DialogUtils.java
public static ColorStateList resolveActionTextColorStateList(Context context, @AttrRes int colorAttr, ColorStateList fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{colorAttr});
    try {
        final TypedValue value = a.peekValue(0);
        if (value == null) {
            return fallback;
        }
        if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            return getActionTextStateList(context, value.data);
        } else {
            final ColorStateList stateList = a.getColorStateList(0);
            if (stateList != null) {
                return stateList;
            } else {
                return fallback;
            }
        }
    } finally {
        a.recycle();
    }
}
 
源代码8 项目: android_9.0.0_r45   文件: ResourcesImpl.java
@Nullable
ComplexColor loadComplexColor(Resources wrapper, @NonNull TypedValue value, int id,
        Resources.Theme theme) {
    if (TRACE_FOR_PRELOAD) {
        // Log only framework resources
        if ((id >>> 24) == 0x1) {
            final String name = getResourceName(id);
            if (name != null) android.util.Log.d("loadComplexColor", name);
        }
    }

    final long key = (((long) value.assetCookie) << 32) | value.data;

    // Handle inline color definitions.
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT
            && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return getColorStateListFromInt(value, key);
    }

    final String file = value.string.toString();

    ComplexColor complexColor;
    if (file.endsWith(".xml")) {
        try {
            complexColor = loadComplexColorFromName(wrapper, theme, value, id);
        } catch (Exception e) {
            final NotFoundException rnf = new NotFoundException(
                    "File " + file + " from complex color resource ID #0x"
                            + Integer.toHexString(id));
            rnf.initCause(e);
            throw rnf;
        }
    } else {
        throw new NotFoundException(
                "File " + file + " from drawable resource ID #0x"
                        + Integer.toHexString(id) + ": .xml extension required");
    }

    return complexColor;
}
 
源代码9 项目: android_9.0.0_r45   文件: ResourcesImpl.java
@NonNull
ColorStateList loadColorStateList(Resources wrapper, TypedValue value, int id,
        Resources.Theme theme)
        throws NotFoundException {
    if (TRACE_FOR_PRELOAD) {
        // Log only framework resources
        if ((id >>> 24) == 0x1) {
            final String name = getResourceName(id);
            if (name != null) android.util.Log.d("PreloadColorStateList", name);
        }
    }

    final long key = (((long) value.assetCookie) << 32) | value.data;

    // Handle inline color definitions.
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT
            && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return getColorStateListFromInt(value, key);
    }

    ComplexColor complexColor = loadComplexColorFromName(wrapper, theme, value, id);
    if (complexColor != null && complexColor instanceof ColorStateList) {
        return (ColorStateList) complexColor;
    }

    throw new NotFoundException(
            "Can't find ColorStateList from drawable resource ID #0x"
                    + Integer.toHexString(id));
}
 
源代码10 项目: PluginLoader   文件: ManifestReader.java
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
源代码11 项目: Twire   文件: Service.java
/**
 * Finds and returns an attribute color. If it was not found the method returns the default color
 */
public static int getColorAttribute(@AttrRes int attribute, @ColorRes int defaultColor, Context context) {
    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(attribute, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return a.data;
    } else {
        return ContextCompat.getColor(context, defaultColor);
    }
}
 
源代码12 项目: AndroidPlugin   文件: XmlManifestReader.java
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data))
                + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data))
                + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT
            && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT
            && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
源代码13 项目: Android-Plugin-Framework   文件: ManifestReader.java
private static String getAttributeValue(XmlResourceParser parser, int index) {
    int type = parser.getAttributeValueType(index);
    int data = parser.getAttributeValueData(index);
    if (type == TypedValue.TYPE_STRING) {
        return parser.getAttributeValue(index);
    }
    if (type == TypedValue.TYPE_ATTRIBUTE) {
        return String.format("?%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_REFERENCE) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    if (type == TypedValue.TYPE_FLOAT) {
        return String.valueOf(Float.intBitsToFloat(data));
    }
    if (type == TypedValue.TYPE_INT_HEX) {
        return String.format("0x%08X", data);
    }
    if (type == TypedValue.TYPE_INT_BOOLEAN) {
        return data != 0 ? "true" : "false";
    }
    if (type == TypedValue.TYPE_DIMENSION) {
        return Float.toString(complexToFloat(data)) + DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type == TypedValue.TYPE_FRACTION) {
        return Float.toString(complexToFloat(data)) + FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
    }
    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return String.format("#%08X", data);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return String.valueOf(data);
    }
    if (type == 0x07) {
        return String.format("@%s%08X", getPackage(data), data);
    }
    return String.format("<0x%X, type 0x%02X>", data, type);
}
 
源代码14 项目: ratel   文件: ResValueFactory.java
public ResScalarValue factory(int type, int value, String rawValue) throws AndrolibException {
    switch (type) {
        case TypedValue.TYPE_NULL:
            if (value == TypedValue.DATA_NULL_UNDEFINED) { // Special case $empty as explicitly defined empty value
                return new ResStringValue(null, value);
            } else if (value == TypedValue.DATA_NULL_EMPTY) {
                return new ResEmptyValue(value, rawValue, type);
            }
            return new ResReferenceValue(mPackage, 0, null);
        case TypedValue.TYPE_REFERENCE:
            return newReference(value, rawValue);
        case TypedValue.TYPE_ATTRIBUTE:
            return newReference(value, rawValue, true);
        case TypedValue.TYPE_STRING:
            return new ResStringValue(rawValue, value);
        case TypedValue.TYPE_FLOAT:
            return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
        case TypedValue.TYPE_DIMENSION:
            return new ResDimenValue(value, rawValue);
        case TypedValue.TYPE_FRACTION:
            return new ResFractionValue(value, rawValue);
        case TypedValue.TYPE_INT_BOOLEAN:
            return new ResBoolValue(value != 0, value, rawValue);
        case TypedValue.TYPE_DYNAMIC_REFERENCE:
            return newReference(value, rawValue);
        case TypedValue.TYPE_DYNAMIC_ATTRIBUTE:
            return newReference(value, rawValue, true);
    }

    if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return new ResColorValue(value, rawValue);
    }
    if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
        return new ResIntValue(value, rawValue, type);
    }

    throw new AndrolibException("Invalid value type: " + type);
}
 
源代码15 项目: LibScout   文件: AXMLPrinter.java
public static String getAttributeValue(AXmlResourceParser parser,int index) {
	int type=parser.getAttributeValueType(index);
	int data=parser.getAttributeValueData(index);
	if (type==TypedValue.TYPE_STRING) {
		return parser.getAttributeValue(index);
	}
	if (type==TypedValue.TYPE_ATTRIBUTE) {
		return String.format("?%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_REFERENCE) {
		return String.format("@%s%08X",getPackage(data),data);
	}
	if (type==TypedValue.TYPE_FLOAT) {
		return String.valueOf(Float.intBitsToFloat(data));
	}
	if (type==TypedValue.TYPE_INT_HEX) {
		return String.format("0x%08X",data);
	}
	if (type==TypedValue.TYPE_INT_BOOLEAN) {
		return data!=0?"true":"false";
	}
	if (type==TypedValue.TYPE_DIMENSION) {
		return Float.toString(complexToFloat(data))+
			DIMENSION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type==TypedValue.TYPE_FRACTION) {
		return Float.toString(complexToFloat(data))+
			FRACTION_UNITS[data & TypedValue.COMPLEX_UNIT_MASK];
	}
	if (type>=TypedValue.TYPE_FIRST_COLOR_INT && type<=TypedValue.TYPE_LAST_COLOR_INT) {
		return String.format("#%08X",data);
	}
	if (type>=TypedValue.TYPE_FIRST_INT && type<=TypedValue.TYPE_LAST_INT) {
		return String.valueOf(data);
	}
	return String.format("<0x%X, type 0x%02X>",data,type);
}
 
源代码16 项目: AndroidTint   文件: ThemeHelper.java
public static ColorStateList getActionTextColorStateList(Context context, @ColorRes int colorId) {
    final TypedValue value = new TypedValue();
    context.getResources().getValue(colorId, value, true);
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        return getActionTextStateList(context, value.data);
    } else {

        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
            //noinspection deprecation
            return context.getResources().getColorStateList(colorId);
        } else {
            return context.getColorStateList(colorId);
        }
    }
}
 
源代码17 项目: ArscEditor   文件: ResValueFactory.java
public ResScalarValue factory(int type, int value, String rawValue) throws IOException {
	switch (type) {
	case TypedValue.TYPE_NULL:
		return new ResReferenceValue(mPackage, 0, null);
	case TypedValue.TYPE_REFERENCE:
		return newReference(value, rawValue);
	case TypedValue.TYPE_ATTRIBUTE:
		return newReference(value, rawValue, true);
	case TypedValue.TYPE_STRING:
		return new ResStringValue(rawValue, value);
	case TypedValue.TYPE_FLOAT:
		return new ResFloatValue(Float.intBitsToFloat(value), value, rawValue);
	case TypedValue.TYPE_DIMENSION:
		return new ResDimenValue(value, rawValue);
	case TypedValue.TYPE_FRACTION:
		return new ResFractionValue(value, rawValue);
	case TypedValue.TYPE_INT_BOOLEAN:
		return new ResBoolValue(value != 0, value, rawValue);
	case 0x07:
		return newReference(value, rawValue);
	}

	if (type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT) {
		return new ResColorValue(value, rawValue);
	}
	if (type >= TypedValue.TYPE_FIRST_INT && type <= TypedValue.TYPE_LAST_INT) {
		return new ResIntValue(value, rawValue, type);
	}

	throw new IOException("Invalid value type: " + type);
}
 
private void setThemeBackground(View view) {
    TypedValue a = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.windowBackground, a, true);
    if (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        view.setBackgroundColor(a.data);
    } else {
        try {
            Drawable d = ResourcesCompat.getDrawable(getActivity().getResources(), a.resourceId, getActivity().getTheme());
            ViewCompat.setBackground(view, d);
        } catch (Resources.NotFoundException ignore) {
        }
    }
}
 
源代码19 项目: SegmentedButton   文件: SegmentedButtonGroup.java
private void getAttributes(Context context, @Nullable AttributeSet attrs)
{
    // According to docs for obtainStyledAttributes, attrs can be null and I assume that each value will be set
    // to the default
    final TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup, 0, 0);

    // Load background if available, this can be a drawable or a color
    // Note: Not well documented but getDrawable will return a ColorDrawable if a color is specified
    if (ta.hasValue(R.styleable.SegmentedButtonGroup_android_background))
        backgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_android_background);

    // Load background on selection if available, can be drawable or color
    if (ta.hasValue(R.styleable.SegmentedButtonGroup_selectedBackground))
        selectedBackgroundDrawable = ta.getDrawable(R.styleable.SegmentedButtonGroup_selectedBackground);

    // Note: Must read radius before setBorder call in order to round the border corners!
    radius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_radius, 0);
    selectedButtonRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedButtonRadius, 0);

    // Setup border for button group
    // Width is the thickness of the border, color is the color of the border
    // Dash width and gap, if the dash width is not zero will make the border dashed with a ratio between dash
    // width and gap
    borderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderWidth, 0);
    borderColor = ta.getColor(R.styleable.SegmentedButtonGroup_borderColor, Color.BLACK);
    borderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashWidth, 0);
    borderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_borderDashGap, 0);

    // Set the border to the read values, this will set the border values to itself but will create a
    // GradientDrawable containing the border
    setBorder(borderWidth, borderColor, borderDashWidth, borderDashGap);

    // Get border information for the selected button
    // Same defaults as the border above, however this border information will be passed to each button so that
    // the correct border can be rendered around the selected button
    selectedBorderWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderWidth, 0);
    selectedBorderColor = ta.getColor(R.styleable.SegmentedButtonGroup_selectedBorderColor, Color.BLACK);
    selectedBorderDashWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashWidth, 0);
    selectedBorderDashGap = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_selectedBorderDashGap, 0);

    position = ta.getInt(R.styleable.SegmentedButtonGroup_position, 0);
    draggable = ta.getBoolean(R.styleable.SegmentedButtonGroup_draggable, false);

    // Update clickable property
    // Not updating this property sets the clickable value to false by default but this sets the default to true
    // while keeping the clickable value if specified in the layouot XML
    setClickable(ta.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true));

    ripple = ta.getBoolean(R.styleable.SegmentedButtonGroup_ripple, true);
    hasRippleColor = ta.hasValue(R.styleable.SegmentedButtonGroup_rippleColor);
    rippleColor = ta.getColor(R.styleable.SegmentedButtonGroup_rippleColor, Color.GRAY);

    final int dividerWidth = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerWidth, 1);
    final int dividerRadius = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerRadius, 0);
    final int dividerPadding = ta.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_dividerPadding, 0);

    // Load divider value if available, the divider can be either a drawable resource or a color
    // Load the TypedValue first and check the type to determine if color or drawable
    final TypedValue value = new TypedValue();
    if (ta.getValue(R.styleable.SegmentedButtonGroup_divider, value))
    {
        if (value.type == TypedValue.TYPE_REFERENCE || value.type == TypedValue.TYPE_STRING)
        {
            // Note: Odd case where Android Studio layout preview editor will fail to display a
            // SegmentedButtonGroup with a divider drawable because value.resourceId returns 0 and thus
            // ContextCompat.getDrawable will return NullPointerException
            // Loading drawable TypedArray.getDrawable or doing TypedArray.getResourceId fixes the problem
            if (isInEditMode())
            {
                setDivider(ta.getDrawable(R.styleable.SegmentedButtonGroup_divider), dividerWidth, dividerRadius,
                    dividerPadding);
            }
            else
            {
                setDivider(ContextCompat.getDrawable(context, value.resourceId), dividerWidth, dividerRadius,
                    dividerPadding);
            }
        }
        else if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT)
        {
            // Divider is a color, value.data is the color value
            setDivider(value.data, dividerWidth, dividerRadius, dividerPadding);
        }
        else
        {
            // Invalid type for the divider, throw an exception
            throw new IllegalArgumentException("Invalid type for SegmentedButtonGroup divider in layout XML "
                + "resource. Must be a color or drawable");
        }
    }

    int selectionAnimationInterpolator = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationInterpolator,
        ANIM_INTERPOLATOR_FAST_OUT_SLOW_IN);
    setSelectionAnimationInterpolator(selectionAnimationInterpolator);
    selectionAnimationDuration = ta.getInt(R.styleable.SegmentedButtonGroup_selectionAnimationDuration, 500);

    // Recycle the typed array, required once done using it
    ta.recycle();
}
 
源代码20 项目: prevent   文件: ColorUtils.java
private static boolean isColor(int type) {
    return type >= TypedValue.TYPE_FIRST_COLOR_INT && type <= TypedValue.TYPE_LAST_COLOR_INT;
}