List of usage examples for android.graphics.drawable GradientDrawable GradientDrawable
public GradientDrawable()
From source file:android.support.design.widget.FloatingActionButtonImpl.java
GradientDrawable newGradientDrawableForShape() {
return new GradientDrawable();
}
From source file:com.esri.android.ecologicalmarineunitexplorer.bottomsheet.BottomSheetFragment.java
/** * Build a stateful drawable for a given EMU * @param emuName String representing name * @return StateListDrawable responsive to selected, pressed, and enabled states *//* ww w. j a va 2 s . c o m*/ private static StateListDrawable buildStateList(final int emuName) { final StateListDrawable stateListDrawable = new StateListDrawable(); final GradientDrawable defaultShape = new GradientDrawable(); final int color = Color.parseColor(EmuHelper.getColorForEMUCluster(emuName)); defaultShape.setColor(color); final GradientDrawable selectedPressShape = new GradientDrawable(); selectedPressShape.setColor(color); selectedPressShape.setStroke(5, Color.parseColor("#f4f442")); stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape); return stateListDrawable; }
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 www .j a v a 2 s.c o m*/ 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.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 {// w ww .j av a 2 s .c o m 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.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 {/*from ww w .j a v a2s. 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.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java
GradientDrawable createGradientDrawable(int color) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.RECTANGLE); gradientDrawable.setColor(color);/*from w ww .ja va 2s. c o m*/ return gradientDrawable; }
From source file:com.sonvp.tooltip.Tooltip.java
private View getViewTooltip(Builder builder, int backgroundColor) { View toolTip = null;/*from w w w . j a v a 2 s.c o m*/ if (builder.viewTooltip == null) { TextView text = new TextView(builder.context); text.setPadding((int) builder.leftPadding, (int) builder.topPadding, (int) builder.rightPadding, (int) builder.bottomPadding); text.setGravity(builder.textGravity); text.setTextColor(builder.textColor); text.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.textSize); text.setTypeface(builder.typeface, builder.typefaceStyle); int lines = builder.lines; if (lines > 0) { text.setLines(lines); text.setEllipsize(TextUtils.TruncateAt.END); } CharSequence txt = builder.text; if (TextUtils.isEmpty(txt)) { txt = builder.context.getString(builder.textResourceId); } text.setText(txt); toolTip = text; } else { toolTip = builder.viewTooltip; } float radius = builder.radius; if (radius > 0.0F) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(backgroundColor); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); drawable.setCornerRadius(radius); //noinspection deprecation toolTip.setBackgroundDrawable(drawable); } else { toolTip.setBackgroundColor(backgroundColor); } return toolTip; }
From source file:com.auth0.android.lock.views.ValidatedInputView.java
/** * Updates the view knowing if the input is valid or not. * * @param isValid if the input is valid or not for this kind of DataType. */// w w w. jav a 2 s.co m @CallSuper protected void updateBorder(boolean isValid) { ViewGroup parent = ((ViewGroup) input.getParent()); Drawable bg = parent.getBackground(); GradientDrawable gd = bg == null ? new GradientDrawable() : (GradientDrawable) bg; gd.setCornerRadius(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_corner_radius)); int strokeColor = isValid ? R.color.com_auth0_lock_input_field_border_normal : R.color.com_auth0_lock_input_field_border_error; gd.setStroke(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_input_field_stroke_width), ContextCompat.getColor(getContext(), strokeColor)); gd.setColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal)); ViewUtils.setBackground(parent, gd); errorDescription.setVisibility(isValid ? INVISIBLE : VISIBLE); requestLayout(); }
From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java
private View getColorImageView(int color) { final ImageView imageView = new ImageView(this); int width = EUExUtil.dipToPixels(32); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width); int margin = EUExUtil.dipToPixels(4); lp.leftMargin = margin;//from w w w. jav a2s.c om lp.rightMargin = margin; imageView.setLayoutParams(lp); imageView.setTag(color); GradientDrawable colorDrawable = new GradientDrawable(); colorDrawable.setColor(color); colorDrawable.setCornerRadius(8); if (Build.VERSION.SDK_INT < 16) { imageView.setBackgroundDrawable(colorDrawable); } else { imageView.setBackground(colorDrawable); } imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCurrnetColor = (int) imageView.getTag(); mScrawlImageView.setPaintColor(mCurrnetColor); mPreviewView.setColor(mCurrnetColor); } }); return imageView; }
From source file:io.imoji.sdk.editor.fragment.TagImojiFragment.java
public Drawable createTagDrawable() { GradientDrawable d = new GradientDrawable(); TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.colorAccent }); final int accentColor = a.getColor(0, Color.WHITE); a.recycle();/*from w w w . j av a 2 s. c om*/ d.setColor(0xB3FFFFFF & accentColor); d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp)); d.setShape(GradientDrawable.RECTANGLE); GradientDrawable d1 = new GradientDrawable(); d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp)); d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK); GradientDrawable d2 = new GradientDrawable(); d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor); d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp)); LayerDrawable layer = new LayerDrawable(new Drawable[] { d, d2, d1 }); int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp); int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp); int oneAndHalf = halfDp + oneDp; layer.setLayerInset(2, 0, 0, 0, 0); layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp); layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf); return layer; }