List of usage examples for android.graphics.drawable GradientDrawable setShape
public void setShape(@Shape int shape)
Sets the type of shape used to draw the gradient.
Note: changing this property will affect all instances of a drawable loaded from a resource.
From source file:Main.java
public static Drawable createRandomColorShapeDrawable() { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setCornerRadius(5);/*from w w w .j a va 2 s.c o m*/ drawable.setColor(createRandomColor()); return drawable; }
From source file:Main.java
public static Drawable createDrawableBackground(int color, int cornerRadius, boolean hasBorder, int borderThickness, int borderColor) { GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); if (hasBorder) drawable.setStroke(borderThickness, borderColor); drawable.setCornerRadius(cornerRadius); drawable.setColor(color);/* ww w. j av a 2 s . com*/ return drawable; }
From source file:Main.java
public static void setGradientForPreferenceView(View v) { int[] colorsForGradient = new int[2]; colorsForGradient[0] = Color.argb(0, 0, 0, 0); colorsForGradient[1] = Color.argb(64, 255, 255, 255); GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colorsForGradient); d.setGradientType(GradientDrawable.LINEAR_GRADIENT); d.setShape(GradientDrawable.RECTANGLE); // doesn't help d.setUseLevel(true); d.setDither(true);/*from w w w .j av a2s . c om*/ v.setBackgroundDrawable(d); }
From source file:org.smssecure.smssecure.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {/*from ww w . j a v a2s . com*/ colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.tingtingapps.securesms.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {// w w w. j a v a2 s. c om colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res .getDrawable(com.tingtingapps.securesms.R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.fast.access.kam.widget.colorpicker.dashclockpicker.ColorPickerDialogDash.java
private static void setColorViewValue(View view, int color) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable != null && currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {//from w w w . ja v a 2s .c om colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color int darkenedColor = Color.rgb(Color.red(color) * 192 / 256, Color.green(color) * 192 / 256, Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); colorChoiceDrawable.setStroke( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()), darkenedColor); imageView.setImageDrawable(colorChoiceDrawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.fuzz.emptyhusk.prefab.ProportionalImageCellGenerator.java
@Override public void onBindChild(@NonNull View child, @NonNull CutoutViewLayoutParams lp, @Nullable View originator) { child.setBackgroundResource(lp.cellBackgroundId); if (originator != null) { rvChildLength = originator.getHeight(); if (originator.getParent() instanceof ViewGroup) { rvLength = ((ViewGroup) originator.getParent()).getHeight(); }//from www . j av a2s. c o m } if (child instanceof ImageView) { GradientDrawable elongated = new GradientDrawable(); elongated.setShape(GradientDrawable.RECTANGLE); int accent = ContextCompat.getColor(child.getContext(), R.color.transparentColorAccent); float fractionOfParent = rvLength * 1.0f / rvChildLength; elongated.setColor(accent); float proposedLength = fractionOfParent * lp.perpendicularLength; elongated.setSize(lp.perpendicularLength, (int) proposedLength); ((ImageView) child).setImageDrawable(elongated); } }
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 */// www. j a va2s . c om 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:im.vector.view.UnreadCounterBadgeView.java
/** * Update the badge value and its status * * @param text the new text value//w w w. jav a 2 s . c o m * @param status the new status */ public void updateText(String text, @Status int status) { if (!TextUtils.isEmpty(text)) { mCounterTextView.setText(text); setVisibility(View.VISIBLE); GradientDrawable shape = new GradientDrawable(); shape.setShape(GradientDrawable.RECTANGLE); shape.setCornerRadius(100); if (status == HIGHLIGHTED) { shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_fuchsia_color)); } else if (status == NOTIFIED) { shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_green_color)); } else { //if (status == DEFAULT) shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_silver_color)); } mParentView.setBackground(shape); } else { setVisibility(View.GONE); } }
From source file:im.vector.adapters.GroupViewHolder.java
/** * Refresh the holder layout/*from w w w . j ava 2 s .c o 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); } } }); } }