List of usage examples for android.graphics.drawable GradientDrawable GradientDrawable
public GradientDrawable()
From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
private void setLegends() { if (mChart.getData().getDataSets().size() > 1) { final Resources resources = ApplicationData.getAppContext().getResources(); final float density = getResources().getDisplayMetrics().density; final float legendWidth = resources.getDimension(R.dimen.chart_legend_width) / density; final float legendHeight = resources.getDimension(R.dimen.chart_legend_height) / density; final float legendMargin = resources.getDimension(R.dimen.chart_legend_margin) / density; final float legendCorner = resources.getDimension(R.dimen.chart_legend_corner) / density; for (ILineDataSet lineDataSet : mChart.getData().getDataSets()) { final CheckBox checkBox = new CheckBox(mLegendLayout.getContext()); checkBox.setChecked(true);//w w w .j a va 2 s . c om checkBox.setText(lineDataSet.getLabel()); checkBox.setTag(lineDataSet); checkBox.setOnCheckedChangeListener(mLegendCheckedChangeListener); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.RECTANGLE); drawable.setColor(lineDataSet.getColor()); drawable.setSize((int) legendWidth, (int) legendHeight); drawable.setCornerRadius(legendCorner); checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); checkBox.setCompoundDrawablePadding((int) legendMargin); final GridLayout.Spec titleTxtSpecColumn = GridLayout.spec(GridLayout.UNDEFINED); final GridLayout.Spec titleRowSpec = GridLayout.spec(GridLayout.UNDEFINED); final GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(titleRowSpec, titleTxtSpecColumn); layoutParams.setMargins((int) legendWidth, 0, (int) legendWidth, 0); mLegendLayout.addView(checkBox, layoutParams); } } }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
private GradientDrawable makeTrackDrawable(int color, int thumbWidth, int thumbHeight, float radius, int padding) { GradientDrawable trackDrawable = new GradientDrawable(); if (padding > 0) { trackDrawable.setStroke(padding, Color.TRANSPARENT); }/*from w w w . ja v a2 s.c o m*/ trackDrawable.setCornerRadius(radius); trackDrawable.setSize((int) (thumbWidth * Default.DEFAULT_MEASURE_FACTOR), thumbHeight); trackDrawable.setColor(getTrackColor(color)); return trackDrawable; }
From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java
/** get background drawable */ private GradientDrawable createDrawable() { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(mCornerRadius); drawable.setColor(mNumBackground);//from www. ja v a 2s . co m return drawable; }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
private GradientDrawable makeThumbDrawable(int color, int thumbWidth, int thumbHeight, float radius, int padding) { GradientDrawable thumbDrawable = new GradientDrawable(); if (padding > 0) { thumbDrawable.setStroke(padding, Color.TRANSPARENT);//make a transparent stroke ,just like padding }/* w ww.j ava2 s .com*/ thumbDrawable.setCornerRadius(radius); thumbDrawable.setSize(thumbWidth, thumbHeight); thumbDrawable.setColor(color); return thumbDrawable; }
From source file:com.hctrom.romcontrol.MainViewActivity.java
public void showHideRebootMenu() { for (int i = 0; i < rebootFabs.length; i++) { if (rebootFabs[i].isShown()) { overlay.setVisibility(View.GONE); rebootFabs[i].hide();//from ww w . j a v a 2s.c o m rebootFabs_text[i].setVisibility(View.GONE); } else { overlay.setVisibility(View.VISIBLE); rebootFabs[i].show(); rebootFabs_text[i].setVisibility(View.VISIBLE); GradientDrawable gd = new GradientDrawable(); gd.setColor(getResources().getColor(R.color.button_material_dark)); // Changes this drawbale to use a single color instead of a gradient gd.setCornerRadius(20); gd.setStroke(1, 0xFF000000); rebootFabs_text[i].setBackgroundDrawable(gd); } } if (!overlay.isShown()) { Blurry.delete((ViewGroup) findViewById(R.id.content)); } else { Blurry.with(MainViewActivity.this).radius(25).sampling(2).async().animate(200) .onto((ViewGroup) findViewById(R.id.content)); } }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
@SuppressLint("NewApi") private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) { if (viewRunnables == null) createViewRunnables();/* w w w .j a v a2 s . com*/ ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); int layoutRule; int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0, paddingTop = 0, paddingBottom = 0; boolean hasCornerRadius = false, hasCornerRadii = false; for (Map.Entry<String, String> entry : attrs.entrySet()) { String attr = entry.getKey(); if (viewRunnables.containsKey(attr)) { viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs); continue; } if (attr.startsWith("cornerRadius")) { hasCornerRadius = true; hasCornerRadii = !attr.equals("cornerRadius"); continue; } layoutRule = NO_LAYOUT_RULE; boolean layoutTarget = false; switch (attr) { case "id": String idValue = parseId(entry.getValue()); if (parent != null) { DynamicLayoutInfo info = getDynamicLayoutInfo(parent); int newId = highestIdNumberUsed++; view.setId(newId); info.nameToIdNumber.put(idValue, newId); } break; case "width": case "layout_width": switch (entry.getValue()) { case "wrap_content": layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; break; case "fill_parent": case "match_parent": layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; break; default: layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; } break; case "height": case "layout_height": switch (entry.getValue()) { case "wrap_content": layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; break; case "fill_parent": case "match_parent": layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; break; default: layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; } break; case "layout_gravity": if (parent != null && parent instanceof LinearLayout) { ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue()); } else if (parent != null && parent instanceof FrameLayout) { ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue()); } break; case "layout_weight": if (parent != null && parent instanceof LinearLayout) { ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue()); } break; case "layout_below": layoutRule = RelativeLayout.BELOW; layoutTarget = true; break; case "layout_above": layoutRule = RelativeLayout.ABOVE; layoutTarget = true; break; case "layout_toLeftOf": layoutRule = RelativeLayout.LEFT_OF; layoutTarget = true; break; case "layout_toRightOf": layoutRule = RelativeLayout.RIGHT_OF; layoutTarget = true; break; case "layout_alignBottom": layoutRule = RelativeLayout.ALIGN_BOTTOM; layoutTarget = true; break; case "layout_alignTop": layoutRule = RelativeLayout.ALIGN_TOP; layoutTarget = true; break; case "layout_alignLeft": case "layout_alignStart": layoutRule = RelativeLayout.ALIGN_LEFT; layoutTarget = true; break; case "layout_alignRight": case "layout_alignEnd": layoutRule = RelativeLayout.ALIGN_RIGHT; layoutTarget = true; break; case "layout_alignParentBottom": layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM; break; case "layout_alignParentTop": layoutRule = RelativeLayout.ALIGN_PARENT_TOP; break; case "layout_alignParentLeft": case "layout_alignParentStart": layoutRule = RelativeLayout.ALIGN_PARENT_LEFT; break; case "layout_alignParentRight": case "layout_alignParentEnd": layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT; break; case "layout_centerHorizontal": layoutRule = RelativeLayout.CENTER_HORIZONTAL; break; case "layout_centerVertical": layoutRule = RelativeLayout.CENTER_VERTICAL; break; case "layout_centerInParent": layoutRule = RelativeLayout.CENTER_IN_PARENT; break; case "layout_margin": marginLeft = marginRight = marginTop = marginBottom = DimensionConverter .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "layout_marginLeft": marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; case "layout_marginTop": marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; case "layout_marginRight": marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, true); break; case "layout_marginBottom": marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics(), parent, false); break; case "padding": paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingLeft": paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingTop": paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingRight": paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; case "paddingBottom": paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics()); break; } if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) { if (layoutTarget) { int anchor = idNumFromIdString(parent, parseId(entry.getValue())); ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor); } else if (entry.getValue().equals("true")) { ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule); } } } // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background if (attrs.containsKey("background") || attrs.containsKey("borderColor")) { String bgValue = attrs.containsKey("background") ? attrs.get("background") : null; if (bgValue != null && bgValue.startsWith("@drawable/")) { view.setBackground(getDrawableByName(view, bgValue)); } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) { if (view instanceof Button || attrs.containsKey("pressedColor")) { int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue); int pressedColor; if (attrs.containsKey("pressedColor")) { pressedColor = parseColor(view, attrs.get("pressedColor")); } else { pressedColor = adjustBrightness(bgColor, 0.9f); } GradientDrawable gd = new GradientDrawable(); gd.setColor(bgColor); GradientDrawable pressedGd = new GradientDrawable(); pressedGd.setColor(pressedColor); if (hasCornerRadii) { float radii[] = new float[8]; for (int i = 0; i < CORNERS.length; i++) { String corner = CORNERS[i]; if (attrs.containsKey("cornerRadius" + corner)) { radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension( attrs.get("cornerRadius" + corner), view.getResources().getDisplayMetrics()); } gd.setCornerRadii(radii); pressedGd.setCornerRadii(radii); } } else if (hasCornerRadius) { float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); gd.setCornerRadius(cornerRadius); pressedGd.setCornerRadius(cornerRadius); } if (attrs.containsKey("borderColor")) { String borderWidth = "1dp"; if (attrs.containsKey("borderWidth")) { borderWidth = attrs.get("borderWidth"); } int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth, view.getResources().getDisplayMetrics()); gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor"))); pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor"))); } StateListDrawable selector = new StateListDrawable(); selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd); selector.addState(new int[] {}, gd); view.setBackground(selector); getDynamicLayoutInfo(view).bgDrawable = gd; } else if (hasCornerRadius || attrs.containsKey("borderColor")) { GradientDrawable gd = new GradientDrawable(); int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue); gd.setColor(bgColor); if (hasCornerRadii) { float radii[] = new float[8]; for (int i = 0; i < CORNERS.length; i++) { String corner = CORNERS[i]; if (attrs.containsKey("cornerRadius" + corner)) { radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension( attrs.get("cornerRadius" + corner), view.getResources().getDisplayMetrics()); } gd.setCornerRadii(radii); } } else if (hasCornerRadius) { float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"), view.getResources().getDisplayMetrics()); gd.setCornerRadius(cornerRadius); } if (attrs.containsKey("borderColor")) { String borderWidth = "1dp"; if (attrs.containsKey("borderWidth")) { borderWidth = attrs.get("borderWidth"); } gd.setStroke( DimensionConverter.stringToDimensionPixelSize(borderWidth, view.getResources().getDisplayMetrics()), parseColor(view, attrs.get("borderColor"))); } view.setBackground(gd); getDynamicLayoutInfo(view).bgDrawable = gd; } else { view.setBackgroundColor(parseColor(view, bgValue)); } } } if (layoutParams instanceof ViewGroup.MarginLayoutParams) { ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight, marginBottom); } view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); view.setLayoutParams(layoutParams); }
From source file:zemin.notification.NotificationView.java
void setContentView(View view) { if (mContentView == view || view == null) return;// w w w . ja v a2 s. co m if (mContentView != null) { mContentViewSwitcher.start(view); } else { mContentBackground = new GradientDrawable(); addState(CONTENT_BACKGROUND_CHANGED); mDimension[0] = LayoutParams.MATCH_PARENT; mDimension[1] = LayoutParams.WRAP_CONTENT; mHideAnimationListener = mDismissAnimationListener; mDefaultShowAnimation = AnimationFactory.pushDownIn(); mDefaultHideAnimation = AnimationFactory.pushUpOut(); mContentViewSwitcher = new ContentViewSwitcher(); mGestureDetector = new GestureDetectorCompat(mContext, this); setContentViewInner(view); } }
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 w w . j ava2 s. c o 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:am.widget.basetabstrip.BaseTabStrip.java
/** * ?Tag//from w w w . ja v a 2 s . co m * * @return Tag */ @SuppressWarnings("unused") protected Drawable getDefaultTagBackground() { final float density = getResources().getDisplayMetrics().density; final GradientDrawable mBackground = new GradientDrawable(); mBackground.setShape(GradientDrawable.RECTANGLE); mBackground.setColor(0xffff4444); mBackground.setCornerRadius(100000 * density); mBackground.setSize((int) (10 * density), (int) (10 * density)); return mBackground; }
From source file:com.todoroo.astrid.activity.TaskEditFragment.java
private void setupWaitingOnMe() { if (!isNewTask) { WaitingOnMe wom = waitingOnMeDao.findByTask(model.getUuid()); if (wom != null) { final View waitingOnMe = getView().findViewById(R.id.waiting_on_me); waitingOnMe.setVisibility(View.VISIBLE); int themeColor = getResources().getColor(ThemeService.getTaskEditThemeColor()); TextView dismiss = (TextView) waitingOnMe.findViewById(R.id.wom_dismiss); dismiss.setOnClickListener(new OnClickListener() { @Override// w w w .j ava 2 s .c o m public void onClick(View v) { WaitingOnMe template = new WaitingOnMe(); template.setValue(WaitingOnMe.DELETED_AT, DateUtilities.now()); waitingOnMeDao.update(WaitingOnMe.TASK_UUID.eq(model.getUuid()), template); waitingOnMe.setVisibility(View.GONE); } }); dismiss.setTextColor(getResources().getColor(R.color.task_edit_deadline_gray)); GradientDrawable gd = new GradientDrawable(); gd.setColor(ThemeService.getDarkVsLight(Color.rgb(0xee, 0xee, 0xee), Color.rgb(0x22, 0x22, 0x22), false)); gd.setCornerRadius(4.0f); dismiss.setBackgroundDrawable(gd); TextView ack = (TextView) waitingOnMe.findViewById(R.id.wom_acknowledge); ack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { WaitingOnMe template = new WaitingOnMe(); template.setValue(WaitingOnMe.ACKNOWLEDGED, 1); waitingOnMeDao.update(WaitingOnMe.TASK_UUID.eq(model.getUuid()), template); waitingOnMe.setVisibility(View.GONE); } }); ack.setTextColor(themeColor); gd = new GradientDrawable(); gd.setColor(ThemeService.getDarkVsLight(Color.WHITE, Color.rgb(0x22, 0x22, 0x22), false)); gd.setCornerRadius(4.0f); ack.setBackgroundDrawable(gd); TextView womText = (TextView) waitingOnMe.findViewById(R.id.wom_message); womText.setText(getWomText(wom)); womText.setTextColor(themeColor); ImageView womIcon = (ImageView) waitingOnMe.findViewById(R.id.wom_icon); womIcon.setImageResource(ThemeService.getTaskEditDrawable(R.drawable.tea_icn_waiting, R.drawable.tea_icn_waiting_lightblue)); } } }