Search in sources :

Example 71 with GradientDrawable

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));
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) AnimatedPathView(com.example.android.io2014.ui.AnimatedPathView) TextView(android.widget.TextView) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 72 with GradientDrawable

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;
}
Also used : Device(io.spark.core.android.cloud.api.Device) LayoutInflater(android.view.LayoutInflater) GradientDrawable(android.graphics.drawable.GradientDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 73 with GradientDrawable

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);
}
Also used : Window(android.view.Window) DisplayMetrics(android.util.DisplayMetrics) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 74 with GradientDrawable

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);
    }
}
Also used : AccountPainter(com.xabber.android.ui.color.AccountPainter) ColorDrawable(android.graphics.drawable.ColorDrawable) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) View(android.view.View) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 75 with GradientDrawable

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);
                }
            }
        });
    }
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) RadioGroup(android.widget.RadioGroup) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorStateList(android.content.res.ColorStateList) RadioButton(android.widget.RadioButton) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RadioButton(android.widget.RadioButton) Button(android.widget.Button) LayerDrawable(android.graphics.drawable.LayerDrawable)

Aggregations

GradientDrawable (android.graphics.drawable.GradientDrawable)169 Paint (android.graphics.Paint)19 Drawable (android.graphics.drawable.Drawable)19 StateListDrawable (android.graphics.drawable.StateListDrawable)19 View (android.view.View)19 SuppressLint (android.annotation.SuppressLint)18 TextView (android.widget.TextView)18 LayerDrawable (android.graphics.drawable.LayerDrawable)16 ImageView (android.widget.ImageView)14 LinearLayout (android.widget.LinearLayout)12 TypedArray (android.content.res.TypedArray)8 FrameLayout (android.widget.FrameLayout)6 TimeAnimator (android.animation.TimeAnimator)5 Typeface (android.graphics.Typeface)5 LayoutInflater (android.view.LayoutInflater)5 ViewGroup (android.view.ViewGroup)5 Attributes (com.cengalabs.flatui.Attributes)5 Resources (android.content.res.Resources)4 TextPaint (android.text.TextPaint)4 Button (android.widget.Button)4