use of android.content.res.ColorStateList in project Genius-Android by qiujuer.
the class Loading method init.
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
final Context context = getContext();
final Resources resource = getResources();
if (attrs == null) {
// default we init a circle style loading drawable
setProgressStyle(STYLE_CIRCLE);
return;
}
final float density = resource.getDisplayMetrics().density;
// default size 2dp
final int baseSize = (int) (density * 2);
// Load attributes
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Loading, defStyleAttr, defStyleRes);
int bgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gBackgroundLineSize, baseSize);
int fgLineSize = a.getDimensionPixelOffset(R.styleable.Loading_gForegroundLineSize, baseSize);
// transparent color
int bgColor = 0;
ColorStateList colorStateList = a.getColorStateList(R.styleable.Loading_gBackgroundColor);
if (colorStateList != null)
bgColor = colorStateList.getDefaultColor();
int fgColorId = a.getResourceId(R.styleable.Loading_gForegroundColor, R.array.g_default_loading_fg);
int style = a.getInt(R.styleable.Loading_gProgressStyle, 1);
boolean autoRun = a.getBoolean(R.styleable.Loading_gAutoRun, true);
float progress = a.getFloat(R.styleable.Loading_gProgressFloat, 0);
a.recycle();
setProgressStyle(style);
setAutoRun(autoRun);
setProgress(progress);
setBackgroundLineSize(bgLineSize);
setForegroundLineSize(fgLineSize);
setBackgroundColor(bgColor);
// Check for IDE preview render
if (!isInEditMode()) {
String type = resource.getResourceTypeName(fgColorId);
try {
switch(type) {
case "color":
setForegroundColor(resource.getColor(fgColorId));
break;
case "array":
setForegroundColor(resource.getIntArray(fgColorId));
break;
default:
setForegroundColor(resource.getIntArray(R.array.g_default_loading_fg));
break;
}
} catch (Exception e) {
setForegroundColor(resource.getIntArray(R.array.g_default_loading_fg));
}
}
}
use of android.content.res.ColorStateList in project MaterialEditText by rengwuxian.
the class MaterialAutoCompleteTextView method resetTextColor.
private void resetTextColor() {
if (textColorStateList == null) {
textColorStateList = new ColorStateList(new int[][] { new int[] { android.R.attr.state_enabled }, EMPTY_STATE_SET }, new int[] { baseColor & 0x00ffffff | 0xdf000000, baseColor & 0x00ffffff | 0x44000000 });
setTextColor(textColorStateList);
} else {
setTextColor(textColorStateList);
}
}
use of android.content.res.ColorStateList in project material by rey5137.
the class ContactView method init.
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
setWillNotDraw(false);
mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ContactView, defStyleAttr, defStyleRes);
mAvatarSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_avatarSize, ThemeUtil.dpToPx(context, 40));
mSpacing = a.getDimensionPixelOffset(R.styleable.ContactView_cv_spacing, ThemeUtil.dpToPx(context, 8));
mMinHeight = a.getDimensionPixelOffset(R.styleable.ContactView_android_minHeight, 0);
int avatarSrc = a.getResourceId(R.styleable.ContactView_cv_avatarSrc, 0);
mNameView = new TextView(context);
mNameView.setGravity(GravityCompat.START);
mNameView.setSingleLine(true);
mNameView.setEllipsize(TextUtils.TruncateAt.END);
int nameTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_nameTextSize, 0);
ColorStateList nameTextColor = a.getColorStateList(R.styleable.ContactView_cv_nameTextColor);
int nameTextAppearance = a.getResourceId(R.styleable.ContactView_cv_nameTextAppearance, 0);
if (nameTextAppearance > 0)
mNameView.setTextAppearance(context, nameTextAppearance);
if (nameTextSize > 0)
mNameView.setTextSize(TypedValue.COMPLEX_UNIT_PX, nameTextSize);
if (nameTextColor != null)
mNameView.setTextColor(nameTextColor);
setNameText(a.getString(R.styleable.ContactView_cv_name));
mAddressView = new TextView(context);
mAddressView.setGravity(GravityCompat.START);
mAddressView.setSingleLine(true);
mAddressView.setEllipsize(TextUtils.TruncateAt.END);
int addressTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_addressTextSize, 0);
ColorStateList addressTextColor = a.getColorStateList(R.styleable.ContactView_cv_addressTextColor);
int addressTextAppearance = a.getResourceId(R.styleable.ContactView_cv_addressTextAppearance, 0);
if (addressTextAppearance > 0)
mAddressView.setTextAppearance(context, addressTextAppearance);
if (addressTextSize > 0)
mAddressView.setTextSize(TypedValue.COMPLEX_UNIT_PX, addressTextSize);
if (addressTextColor != null)
mAddressView.setTextColor(addressTextColor);
setAddressText(a.getString(R.styleable.ContactView_cv_address));
mButtonSize = a.getDimensionPixelOffset(R.styleable.ContactView_cv_buttonSize, 0);
if (mButtonSize > 0) {
mButton = new ImageButton(context);
int resId = a.getResourceId(R.styleable.ContactView_cv_buttonSrc, 0);
if (resId != 0)
mButton.setImageResource(resId);
ViewUtil.setBackground(mButton, BlankDrawable.getInstance());
mButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
mButton.setFocusableInTouchMode(false);
mButton.setFocusable(false);
mButton.setClickable(false);
}
a.recycle();
addView(mNameView);
addView(mAddressView);
if (mButton != null)
addView(mButton);
mAvatarDrawable = new AvatarDrawable();
if (avatarSrc != 0)
setAvatarResource(avatarSrc);
}
use of android.content.res.ColorStateList in project philm by chrisbanes.
the class DrawableTintUtils method createFromColorRes.
public static Drawable createFromColorRes(@NonNull Context context, @DrawableRes int drawableId, @ColorRes int colorId) {
Drawable d = ContextCompat.getDrawable(context, drawableId);
d = DrawableCompat.wrap(d.mutate());
ColorStateList tint = AppCompatResources.getColorStateList(context, colorId);
DrawableCompat.setTintList(d, tint);
return d;
}
use of android.content.res.ColorStateList in project material-dialogs by afollestad.
the class CircleView method update.
private void update(@ColorInt int color) {
innerPaint.setColor(color);
outerPaint.setColor(shiftColorDown(color));
Drawable selector = createSelector(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int[][] states = new int[][] { new int[] { android.R.attr.state_pressed } };
int[] colors = new int[] { shiftColorUp(color) };
ColorStateList rippleColors = new ColorStateList(states, colors);
setForeground(new RippleDrawable(rippleColors, selector, null));
} else {
setForeground(selector);
}
}
Aggregations