use of android.content.res.ColorStateList in project Android-Switch-Demo-pre-4.0 by pellucide.
the class MySwitch method setSwitchTextAppearance.
/**
* Sets the switch text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*/
public void setSwitchTextAppearance(Context context, int resid) {
TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.mySwitchTextAppearanceAttrib);
ColorStateList colors;
int ts;
colors = appearance.getColorStateList(R.styleable.mySwitchTextAppearanceAttrib_textColor);
if (colors != null) {
mTextColors = colors;
} else {
// If no color set in TextAppearance, default to the view's textColor
mTextColors = getTextColors();
}
ts = appearance.getDimensionPixelSize(R.styleable.mySwitchTextAppearanceAttrib_textSize, 0);
if (ts != 0) {
if (ts != mTextPaint.getTextSize()) {
mTextPaint.setTextSize(ts);
requestLayout();
}
}
int typefaceIndex, styleIndex;
typefaceIndex = appearance.getInt(R.styleable.mySwitchTextAppearanceAttrib_typeface, -1);
styleIndex = appearance.getInt(R.styleable.mySwitchTextAppearanceAttrib_textStyle, -1);
setSwitchTypefaceByIndex(typefaceIndex, styleIndex);
appearance.recycle();
}
use of android.content.res.ColorStateList in project XobotOS by xamarin.
the class TextView method getTextColors.
/**
* Returns the TextView_textColor attribute from the
* Resources.StyledAttributes, if set, or the TextAppearance_textColor
* from the TextView_textAppearance attribute, if TextView_textColor
* was not set directly.
*/
public static ColorStateList getTextColors(Context context, TypedArray attrs) {
ColorStateList colors;
colors = attrs.getColorStateList(com.android.internal.R.styleable.TextView_textColor);
if (colors == null) {
int ap = attrs.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
if (ap != -1) {
TypedArray appearance;
appearance = context.obtainStyledAttributes(ap, com.android.internal.R.styleable.TextAppearance);
colors = appearance.getColorStateList(com.android.internal.R.styleable.TextAppearance_textColor);
appearance.recycle();
}
}
return colors;
}
use of android.content.res.ColorStateList in project XobotOS by xamarin.
the class Switch method setSwitchTextAppearance.
/**
* Sets the switch text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*/
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);
appearance.recycle();
}
use of android.content.res.ColorStateList in project android_frameworks_base by ResurrectionRemix.
the class Toast method makeText.
/**
* Make a standard toast that just contains a text view.
*
* @param context The context to use. Usually your {@link android.app.Application}
* or {@link android.app.Activity} object.
* @param text The text to show. Can be formatted text.
* @param duration How long to display the message. Either {@link #LENGTH_SHORT} or
* {@link #LENGTH_LONG}
*
*/
public static Toast makeText(Context context, CharSequence text, @Duration int duration) {
Toast result = new Toast(context);
final ColorStateList textColor = RandomColorHelper.getToastTextColorList(tContext);
LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflate.inflate(com.android.internal.R.layout.transient_notification, null);
TextView tv = (TextView) v.findViewById(com.android.internal.R.id.message);
tv.setText(text);
tv.setTextColor(textColor);
result.mNextView = v;
result.mDuration = duration;
return result;
}
use of android.content.res.ColorStateList in project android_frameworks_base by ResurrectionRemix.
the class TextView method applyCompoundDrawableTint.
private void applyCompoundDrawableTint() {
if (mDrawables == null) {
return;
}
if (mDrawables.mHasTint || mDrawables.mHasTintMode) {
final ColorStateList tintList = mDrawables.mTintList;
final PorterDuff.Mode tintMode = mDrawables.mTintMode;
final boolean hasTint = mDrawables.mHasTint;
final boolean hasTintMode = mDrawables.mHasTintMode;
final int[] state = getDrawableState();
for (Drawable dr : mDrawables.mShowing) {
if (dr == null) {
continue;
}
if (dr == mDrawables.mDrawableError) {
// drawable tint to it.
continue;
}
dr.mutate();
if (hasTint) {
dr.setTintList(tintList);
}
if (hasTintMode) {
dr.setTintMode(tintMode);
}
// stateful before applying the tint, so let's try again.
if (dr.isStateful()) {
dr.setState(state);
}
}
}
}
Aggregations