use of android.content.res.ColorStateList in project android_frameworks_base by ParanoidAndroid.
the class Switch method setSwitchTextAppearance.
/**
* Sets the switch text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*
* @attr ref android.R.styleable#Switch_switchTextAppearance
*/
public void setSwitchTextAppearance(Context context, int resid) {
TypedArray appearance = context.obtainStyledAttributes(resid, com.android.internal.R.styleable.TextAppearance);
ColorStateList colors;
int ts;
colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
if (colors != null) {
mTextColors = colors;
} else {
// If no color set in TextAppearance, default to the view's textColor
mTextColors = getTextColors();
}
ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.TextAppearance_textSize, 0);
if (ts != 0) {
if (ts != mTextPaint.getTextSize()) {
mTextPaint.setTextSize(ts);
requestLayout();
}
}
int typefaceIndex, styleIndex;
typefaceIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_typeface, -1);
styleIndex = appearance.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, -1);
setSwitchTypefaceByIndex(typefaceIndex, styleIndex);
boolean allCaps = appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps, false);
if (allCaps) {
mSwitchTransformationMethod = new AllCapsTransformationMethod(getContext());
mSwitchTransformationMethod.setLengthChangesAllowed(true);
} else {
mSwitchTransformationMethod = null;
}
appearance.recycle();
}
use of android.content.res.ColorStateList in project android_frameworks_base by ParanoidAndroid.
the class ColorStateListTest method testStateIsInList.
@SmallTest
public void testStateIsInList() throws Exception {
ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
int[] focusedState = { android.R.attr.state_focused };
int focusColor = colorStateList.getColorForState(focusedState, R.color.failColor);
assertEquals(mResources.getColor(R.color.testcolor1), focusColor);
}
use of android.content.res.ColorStateList in project android_frameworks_base by ParanoidAndroid.
the class ColorStateListTest method testEmptyState.
@SmallTest
public void testEmptyState() throws Exception {
ColorStateList colorStateList = mResources.getColorStateList(R.color.color1);
int[] emptyState = {};
int defaultColor = colorStateList.getColorForState(emptyState, mFailureColor);
assertEquals(mResources.getColor(R.color.testcolor2), defaultColor);
}
use of android.content.res.ColorStateList in project HoloEverywhere by Prototik.
the class TextView method setTextAppearance.
public static <T extends android.widget.TextView & FontStyleProvider> void setTextAppearance(T textView, TypedArray appearance) {
int color = appearance.getColor(R.styleable.TextAppearance_android_textColorHighlight, 0);
if (color != 0) {
textView.setHighlightColor(color);
}
ColorStateList colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColor);
if (colors != null) {
textView.setTextColor(colors);
}
int ts = appearance.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0);
if (ts != 0) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, ts);
}
colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColorHint);
if (colors != null) {
textView.setHintTextColor(colors);
}
colors = appearance.getColorStateList(R.styleable.TextAppearance_android_textColorLink);
if (colors != null) {
textView.setLinkTextColor(colors);
}
if (appearance.getBoolean(R.styleable.TextAppearance_android_textAllCaps, false)) {
textView.setTransformationMethod(new AllCapsTransformationMethod(textView.getContext()));
}
Object[] font = parseFontStyle(appearance);
textView.setFontStyle((String) font[2], (Integer) font[1] | ((Boolean) font[0] ? 0 : textView.getFontStyle()));
}
use of android.content.res.ColorStateList in project ElasticDownload by Tibolte.
the class VectorDrawable method updateStateFromTypedArray.
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
final VectorDrawableState state = mVectorState;
final VPathRenderer pathRenderer = state.mVPathRenderer;
// Account for any configuration changes.
state.mChangingConfigurations |= getChangingConfigurations(a);
// Extract the theme attributes, if any.
//TODO: will not support drawable theming yet (applies to tinting mainly)
//state.mThemeAttrs = a.extractThemeAttrs();
final int tintMode = a.getInt(R.styleable.VectorDrawable_vc_tintMode, -1);
if (tintMode != -1) {
state.mTintMode = parseTintMode(tintMode, PorterDuff.Mode.SRC_IN);
}
final ColorStateList tint = a.getColorStateList(R.styleable.VectorDrawable_vc_tint);
if (tint != null) {
state.mTint = tint;
}
state.mAutoMirrored = a.getBoolean(R.styleable.VectorDrawable_vc_autoMirrored, state.mAutoMirrored);
pathRenderer.mViewportWidth = a.getFloat(R.styleable.VectorDrawable_vc_viewportWidth, pathRenderer.mViewportWidth);
pathRenderer.mViewportHeight = a.getFloat(R.styleable.VectorDrawable_vc_viewportHeight, pathRenderer.mViewportHeight);
if (pathRenderer.mViewportWidth <= 0) {
throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires viewportWidth > 0");
} else if (pathRenderer.mViewportHeight <= 0) {
throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires viewportHeight > 0");
}
pathRenderer.mBaseWidth = a.getDimension(R.styleable.VectorDrawable_android_width, pathRenderer.mBaseWidth);
pathRenderer.mBaseHeight = a.getDimension(R.styleable.VectorDrawable_android_height, pathRenderer.mBaseHeight);
if (pathRenderer.mBaseWidth <= 0) {
throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires width > 0");
} else if (pathRenderer.mBaseHeight <= 0) {
throw new XmlPullParserException(a.getPositionDescription() + "<menu_vector> tag requires height > 0");
}
final float alphaInFloat = a.getFloat(R.styleable.VectorDrawable_android_alpha, pathRenderer.getAlpha());
pathRenderer.setAlpha(alphaInFloat);
final String name = a.getString(R.styleable.VectorDrawable_android_name);
if (name != null) {
pathRenderer.mRootName = name;
pathRenderer.mVGTargetsMap.put(name, pathRenderer);
}
}
Aggregations