Example usage for android.graphics.drawable GradientDrawable setColor

List of usage examples for android.graphics.drawable GradientDrawable setColor

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable setColor.

Prototype

public void setColor(@Nullable ColorStateList colorStateList) 

Source Link

Document

Changes this drawable to use a single color state list instead of a gradient.

Usage

From source file:com.saulmm.cui.recycler.ProductViewHolder.java

void bind(Product product) {
    binding.setProduct(product);/*from  w ww  .java 2  s . com*/

    final GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat
            .getDrawable(itemView.getContext(), R.drawable.bg_product);

    gradientDrawable.setColor(ContextCompat.getColor(itemView.getContext(), product.color));

    gradientDrawable.setSize(itemView.getWidth(), getDrawableHeight());

    gradientDrawable.mutate();

    binding.imgProduct.setBackground(gradientDrawable);
    binding.imgProduct.setImageResource(product.image);
}

From source file:me.trashout.ui.SelectableImageButton.java

/**
 * Change background selected color/*from  w  w w  .j a va 2s.c  o  m*/
 * @param color
 */
public void setBackgroundSelectedColor(int color) {

    LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(getContext(),
            R.drawable.background_trash_circle_button_selected);
    GradientDrawable shape = (GradientDrawable) layerDrawable
            .findDrawableByLayerId(R.id.selected_background_shape).mutate();
    shape.setColor(color);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, shape);
    states.addState(new int[] { android.R.attr.state_selected }, shape);
    states.addState(new int[] {},
            ContextCompat.getDrawable(getContext(), R.drawable.background_trash_circle_button));

    setBackground(states);
    invalidate();
}

From source file:ro.expectations.expenses.widget.dialog.CategoryPickerAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    mCursor.moveToPosition(position);/*ww w .  jav  a 2 s .c  o  m*/

    // Set the icon background color
    GradientDrawable bgShape = (GradientDrawable) holder.mCategoryIconBackground.getBackground();
    bgShape.setColor(0xFF000000 | ContextCompat.getColor(mContext, R.color.colorPrimary));

    // Set the icon
    int iconId;
    if (getItemId(position) == 0) {
        iconId = R.drawable.ic_clear_black_24dp;
    } else {
        iconId = R.drawable.ic_question_mark_black_24dp;
    }
    holder.mCategoryIcon.setImageDrawable(DrawableHelper.tint(mContext, iconId, R.color.colorWhite));

    // Set the category name
    String name = mCursor.getString(COLUMN_CATEGORY_NAME);
    holder.mCategoryName.setText(name);

    // Set the proper padding for a dialog.
    TypedValue value = new TypedValue();
    mContext.getTheme().resolveAttribute(R.attr.dialogPreferredPadding, value, true);
    DisplayMetrics metrics = new DisplayMetrics();
    ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
    int padding = (int) value.getDimension(metrics);
    holder.mCategoryItem.setPadding(padding, holder.mCategoryItem.getPaddingTop(), padding,
            holder.mCategoryItem.getPaddingBottom());
}

From source file:ro.expectations.expenses.ui.categories.CategoriesAdapter.java

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    mCursor.moveToPosition(position);/*from w w w  .  j a v  a 2  s  .co  m*/

    // Set the row background
    ListHelper.setItemBackground(mContext, holder.itemView, isItemSelected(position),
            holder.mCategoryIconBackground, holder.mSelectedIconBackground);

    // Set the icon background color
    GradientDrawable bgShape = (GradientDrawable) holder.mCategoryIconBackground.getBackground();
    bgShape.setColor(0xFF000000 | ContextCompat.getColor(mContext, R.color.colorPrimary));

    // Set the category name
    String name = mCursor.getString(COLUMN_CATEGORY_NAME);
    holder.mNameView.setText(name);

    // Show or hide the subcategories icon
    long parentId = mCursor.getLong(COLUMN_CATEGORY_PARENT_ID);
    if (parentId > 0) {
        holder.mSubcategoriesIcon.setVisibility(View.GONE);
    } else {
        long children = mCursor.getLong(COLUMN_CATEGORY_CHILDREN);
        if (children > 0) {
            holder.mSubcategoriesIcon.setVisibility(View.VISIBLE);
        } else {
            holder.mSubcategoriesIcon.setVisibility(View.GONE);
        }
    }
}

From source file:im.vector.adapters.VectorRoomSummaryAdapter.java

/**
 * Apply a rounded (sides) rectangle as a background to the view provided in aTargetView.
 *
 * @param aTargetView      view to apply the background
 * @param aBackgroundColor background colour
 *//*from   w ww.ja  v a2  s .  co m*/
private static void setUnreadBackground(View aTargetView, int aBackgroundColor) {
    if (null != aTargetView) {
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(aBackgroundColor);
        aTargetView.setBackground(shape);
    }
}

From source file:com.uprayzner.mediator.adapters.PlanStandsListAdapter.java

@Override
public void onBindViewHolder(final StandViewHolder holder, final int position) {
    final IPlanStandCard card = getItem(position);

    GradientDrawable drawable = (GradientDrawable) holder.header.getBackground();
    drawable.setColor(card.getColor());

    holder.title.setText(card.getTitle());
    setProgressColor(card.getColor(), holder.progressBar);
    holder.logo.setBackgroundColor(Color.argb(25, Color.red(card.getColor()), Color.green(card.getColor()),
            Color.blue(card.getColor())));

    Glide.with(holder.logo.getContext()).load(card.getImageUrl()).crossFade().fitCenter().override(200, 300)
            .listener(new RequestListener<String, GlideDrawable>() {
                @Override//  www . ja va  2  s . c  o  m
                public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                        boolean isFirstResource) {
                    holder.progressBar.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            holder.progressBar.setVisibility(View.VISIBLE);
                        }
                    }, 50);
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model,
                        Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    holder.progressBar.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            holder.progressBar.setVisibility(View.GONE);
                        }
                    }, 50);
                    return false;
                }
            }).into(holder.logo);

    holder.container.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            listener.onListItemClick(position, card);
        }
    });
}

From source file:app.com.timbuktu.fragment.ColorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_collectionview, container, false);
    Bundle bdl = getArguments();/* ww w  .j a v  a 2 s .co  m*/

    mFragmentLayout = (FrameLayout) v.findViewById(R.id.fragment_layout);

    LayerDrawable bgDrawable = (LayerDrawable) mFragmentLayout.getBackground();
    GradientDrawable shape = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.background_shape);
    shape.setColor(bdl.getInt(EXTRA_COLOR));

    TextView tv = (TextView) v.findViewById(R.id.header);
    Collection collection = bdl.getParcelable(EXTRA_COLLECTION);
    tv.setText("Position - " + bdl.getInt(EXTRA_POS));

    if (collection != null) {
        tv.setText("Position - " + bdl.getInt(EXTRA_POS) + " # of Pics :" + collection.size());

        ImageView imgView = (ImageView) v.findViewById(R.id.collage);
        mTask = new CollageWorkerTask(imgView, collection);
        mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    return v;
}

From source file:com.varejodigital.activities.DetailActivity.java

private void updateBackground(View view, Palette palette) {
    int lightMutedColor = palette.getLightMutedColor(getResources().getColor(R.color.accent));
    int mutedColor = palette.getMutedColor(getResources().getColor(R.color.accent));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        RippleDrawable ripple = (RippleDrawable) view.getBackground();
        GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
        rippleBackground.setColor(lightMutedColor);
        ripple.setColor(ColorStateList.valueOf(mutedColor));
    } else {//w  w  w.  j a v  a  2  s.c  om
        StateListDrawable drawable = (StateListDrawable) view.getBackground();
        drawable.setColorFilter(mutedColor, PorterDuff.Mode.SRC_ATOP);
    }
}

From source file:ro.expectations.expenses.ui.categories.EditCategoryActivity.java

@Override
public void onColorSelected(@ColorInt int color, @ColorInt int darkColor, @ColorInt int accentColor) {

    // change the collapsing toolbar layout
    mCollapsingToolbarLayout.setBackgroundColor(color);

    // change the support action bar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setBackgroundDrawable(new ColorDrawable(color));
    }//from   w w  w  . j a v  a  2 s . c om

    // change the status bar
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(darkColor);
    }

    // change the floating action button
    mFloatingActionButton.setBackgroundTintList(ColorStateList.valueOf(accentColor));

    // change the change icon color
    GradientDrawable bgShape = (GradientDrawable) mChangeColorBackground.getBackground();
    bgShape.setColor(0xFF000000 | accentColor);
}

From source file:im.vector.adapters.GroupViewHolder.java

/**
 * Refresh the holder layout//from w ww .  j  a  v  a  2s.  co  m
 *
 * @param context                 the context
 * @param group                   the group
 * @param isInvitation            true if it is an invitation
 * @param moreGroupActionListener the more actions listener
 */
public void populateViews(final Context context, final MXSession session, final Group group,
        final AbsAdapter.GroupInvitationListener invitationListener, final boolean isInvitation,
        final AbsAdapter.MoreGroupActionListener moreGroupActionListener) {
    // sanity check
    if (null == group) {
        Log.e(LOG_TAG, "## populateViews() : null group");
        return;
    }

    if (isInvitation) {
        vGroupMembersCount.setText("!");
        vGroupMembersCount.setTypeface(null, Typeface.BOLD);
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(ContextCompat.getColor(context, R.color.vector_fuchsia_color));
        vGroupMembersCount.setBackground(shape);
        vGroupMembersCount.setVisibility(View.VISIBLE);
    } else {
        vGroupMembersCount.setVisibility(View.GONE);
    }

    vGroupName.setText(group.getDisplayName());
    vGroupName.setTypeface(null, Typeface.NORMAL);

    VectorUtils.loadGroupAvatar(context, session, vGroupAvatar, group);

    vGroupTopic.setText(group.getShortDescription());

    if (vGroupMoreActionClickArea != null && vGroupMoreActionAnchor != null) {
        vGroupMoreActionClickArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != moreGroupActionListener) {
                    moreGroupActionListener.onMoreActionClick(vGroupMoreActionAnchor, group);
                }
            }
        });
    }
}