use of android.graphics.drawable.GradientDrawable in project google-io-2014 by romainguy.
the class DetailActivity method colorRipple.
private void colorRipple(int id, int bgColor, int tintColor) {
View buttonView = findViewById(id);
RippleDrawable ripple = (RippleDrawable) buttonView.getBackground();
GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
rippleBackground.setColor(bgColor);
ripple.setColor(ColorStateList.valueOf(tintColor));
}
use of android.graphics.drawable.GradientDrawable in project android-app by spark.
the class DeviceListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.core_row, parent, false);
ViewHolder holder = new ViewHolder();
holder.activeStripe = Ui.findView(convertView, R.id.active_core_stripe);
holder.coreName = Ui.findView(convertView, R.id.core_name);
convertView.setTag(holder);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
final Device device = getItem(position);
holder.coreName.setText(device.name);
Drawable[] compoundDrawables = holder.coreName.getCompoundDrawables();
GradientDrawable dotDrawable = (GradientDrawable) compoundDrawables[0];
dotDrawable.setColor(device.color);
holder.activeStripe.setBackgroundColor(device.color);
if (convertView.isActivated()) {
holder.activeStripe.setVisibility(View.VISIBLE);
} else {
holder.activeStripe.setVisibility(View.INVISIBLE);
}
return convertView;
}
use of android.graphics.drawable.GradientDrawable in project StylishMusicPlayer by ryanhoo.
the class BaseActivity method onAttachedToWindow.
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
// https://crazygui.wordpress.com/2010/09/05/high-quality-radial-gradient-in-android/
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
// int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;
Window window = getWindow();
GradientDrawable gradientBackgroundDrawable = GradientUtils.create(ContextCompat.getColor(this, R.color.mp_theme_dark_blue_gradientColor), ContextCompat.getColor(this, R.color.mp_theme_dark_blue_background), // (int) Math.hypot(screenWidth / 2, screenHeight / 2),
screenHeight / 2, 0.5f, 0.5f);
window.setBackgroundDrawable(gradientBackgroundDrawable);
window.setFormat(PixelFormat.RGBA_8888);
}
use of android.graphics.drawable.GradientDrawable in project xabber-android by redsolution.
the class ChatScrollIndicatorAdapter method update.
public void update(ArrayList<AbstractChat> activeChats) {
final LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final int size = activeChats.size() + 1;
linearLayout.removeAllViews();
for (int i = 0; i < size; i++) {
View view;
if (i == 0) {
view = inflater.inflate(R.layout.chat_scroll_indicator_item_square, linearLayout, false);
} else {
view = inflater.inflate(R.layout.chat_scroll_indicator_item_circle, linearLayout, false);
}
linearLayout.addView(view);
final AccountViewHolder accountViewHolder = new AccountViewHolder(view);
final AccountPainter accountPainter = ColorManager.getInstance().getAccountPainter();
if (i > 0) {
final String account = activeChats.get(i - 1).getAccount();
((GradientDrawable) accountViewHolder.body.getDrawable()).setColor(accountPainter.getAccountMainColor(account));
((GradientDrawable) accountViewHolder.selection.getDrawable()).setColor(accountPainter.getAccountMainColor(account));
} else {
accountViewHolder.body.setImageDrawable(new ColorDrawable(accountPainter.getDefaultMainColor()));
accountViewHolder.selection.setImageDrawable(new ColorDrawable(accountPainter.getDefaultMainColor()));
}
view.setTag(accountViewHolder);
}
}
use of android.graphics.drawable.GradientDrawable in project JustAndroid by chinaltz.
the class SegmentedGroup method updateBackground.
private void updateBackground(View view) {
if (!isInEditMode()) {
int checked = mLayoutSelector.getSelected();
int unchecked = mLayoutSelector.getUnselected();
//Set text color
ColorStateList colorStateList = new ColorStateList(new int[][] { { -android.R.attr.state_checked }, { android.R.attr.state_checked } }, new int[] { mTintColor, mCheckedTextColor });
((Button) view).setTextColor(colorStateList);
//Redraw with tint color
Drawable checkedDrawable = resources.getDrawable(checked).mutate();
Drawable uncheckedDrawable = resources.getDrawable(unchecked).mutate();
((GradientDrawable) checkedDrawable).setColor(mTintColor);
((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor);
((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor);
((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor);
//Set proper radius
((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view));
GradientDrawable maskDrawable = (GradientDrawable) resources.getDrawable(unchecked).mutate();
maskDrawable.setStroke(mMarginDp, mTintColor);
maskDrawable.setColor(mUnCheckedTintColor);
maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view));
int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor));
maskDrawable.setColor(maskColor);
LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] { uncheckedDrawable, maskDrawable });
Drawable[] drawables = { uncheckedDrawable, checkedDrawable };
TransitionDrawable transitionDrawable = new TransitionDrawable(drawables);
if (((RadioButton) view).isChecked()) {
transitionDrawable.reverseTransition(0);
}
StateListDrawable stateListDrawable = new StateListDrawable();
stateListDrawable.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_pressed }, pressedDrawable);
stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable);
mDrawableMap.put(view.getId(), transitionDrawable);
//Set button background
if (Build.VERSION.SDK_INT >= 16) {
view.setBackground(stateListDrawable);
} else {
view.setBackgroundDrawable(stateListDrawable);
}
super.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
TransitionDrawable current = mDrawableMap.get(checkedId);
current.reverseTransition(200);
if (mLastCheckId != 0) {
TransitionDrawable last = mDrawableMap.get(mLastCheckId);
if (last != null)
last.reverseTransition(200);
}
mLastCheckId = checkedId;
if (mCheckedChangeListener != null) {
mCheckedChangeListener.onCheckedChanged(group, checkedId);
}
}
});
}
}
Aggregations