public static Drawable drawable(final int[] colorBoxes, final float[] position, final GradientAngle gradientAngle) { ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { AngleCoordinate ac = AngleCoordinate.getAngleCoordinate(gradientAngle, width, height); LinearGradient linearGradient = new LinearGradient(ac.x1, ac.y1, ac.x2, ac.y2, colorBoxes, position, Shader.TileMode.REPEAT); return linearGradient; } }; PaintDrawable paint = new PaintDrawable(); paint.setShape(new RectShape()); paint.setShaderFactory(shaderFactory); return paint; }
private void setShape() { ShapeDrawable drawable = new ShapeDrawable(); // Set color of drawable. drawable.getPaint().setColor((backgroundColor == Component.COLOR_DEFAULT) ? SHAPED_DEFAULT_BACKGROUND_COLOR : backgroundColor); // Set shape of drawable. switch (shape) { case Component.BUTTON_SHAPE_ROUNDED: drawable.setShape(new RoundRectShape(ROUNDED_CORNERS_ARRAY, null, null)); break; case Component.BUTTON_SHAPE_RECT: drawable.setShape(new RectShape()); break; case Component.BUTTON_SHAPE_OVAL: drawable.setShape(new OvalShape()); break; default: throw new IllegalArgumentException(); } // Set drawable to the background of the button. view.setBackgroundDrawable(drawable); view.invalidate(); }
void setupColorImageView(int[] padding, String type, int[] manualDimensions, boolean[] isManualDimensions, int[] autoDimensions) { colorImageView = new ImageView(gismoContext); fullContainerRelativeLayout.addView(colorImageView); colorImageView.setTag(Enums.ItemTag.Image); GradientDrawable outlineDrawable = new GradientDrawable(); ShapeDrawable shapeDrawable = new ShapeDrawable(); if (type.equals("oval")) { shapeDrawable.setShape(new OvalShape()); outlineDrawable.setShape(GradientDrawable.OVAL); } else { shapeDrawable.setShape(new RectShape()); outlineDrawable.setShape(GradientDrawable.RECTANGLE); } shapeDrawable.setIntrinsicWidth(isManualDimensions[0] ? manualDimensions[0] : autoDimensions[0]); shapeDrawable.setIntrinsicHeight(isManualDimensions[1] ? manualDimensions[1] : autoDimensions[1]); colorImageView.setImageDrawable(new LayerDrawable(new Drawable[]{shapeDrawable, outlineDrawable})); colorImageView.getLayoutParams().height = RelativeLayout.LayoutParams.WRAP_CONTENT; colorImageView.getLayoutParams().width = RelativeLayout.LayoutParams.WRAP_CONTENT; colorImageView.setPadding(padding[0], padding[1], padding[2], padding[3]); colorImageView.setAdjustViewBounds(true); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public Drawable initBackgroundDrawable(View view, Drawable mBackgroundColorDrawable) { RippleDrawable mBackgroundRippleDrawable = new RippleDrawable( ColorStateList.valueOf(Color.TRANSPARENT), null, new ShapeDrawable(new RectShape()) ); view.setBackground(new LayerDrawable(new Drawable[] { mBackgroundColorDrawable, mBackgroundRippleDrawable })); return mBackgroundRippleDrawable; }
@TargetApi(Build.VERSION_CODES.M) @Override public Drawable initBackgroundDrawable(View view, Drawable mBackgroundColorDrawable) { RippleDrawable mBackgroundRippleDrawable = new RippleDrawable( ColorStateList.valueOf(Color.TRANSPARENT), null, new ShapeDrawable(new RectShape()) ); view.setBackground(mBackgroundColorDrawable); view.setForeground(mBackgroundRippleDrawable); return mBackgroundRippleDrawable; }
/** * Initializes the color seekbar with the gradient */ public void init() { LinearGradient colorGradient; if (Build.VERSION.SDK_INT >= 16) { colorGradient = new LinearGradient(0.f, 0.f, this.getMeasuredWidth() - this.getThumb().getIntrinsicWidth(), 0.f, new int[]{0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF, 0xFFFF0000, 0xFFFF00FF, 0xFFFFFF00, 0xFFFFFF}, null, Shader.TileMode.CLAMP ); } else { colorGradient = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, new int[]{0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF, 0xFFFF0000, 0xFFFF00FF, 0xFFFFFF00, 0xFFFFFF}, null, Shader.TileMode.CLAMP ); } ShapeDrawable shape = new ShapeDrawable(new RectShape()); shape.getPaint().setShader(colorGradient); this.setProgressDrawable(shape); this.setMax(256 * 7 - 1); }
/** * Update gradient parameters. */ private void updateGradientParameters() { // - Initialize gradient. mSideHypot = (int) Math.hypot(getWidth(), getHeight()); ShapeDrawable mDrawable = new ShapeDrawable(new RectShape()); final double radiansAngle = Math.toRadians(mDegreesAngle); mDrawable.getPaint().setShader(new LinearGradient(0, 0, (int) (mSideHypot * Math.cos(radiansAngle)), (int) (mSideHypot * Math.sin(radiansAngle)), mColorA, mColorB, Shader.TileMode.REPEAT)); // - Initialize foreground gradient layout. if (mForegroundLayout == null) { mForegroundLayout = new FrameLayout(getContext()); mForegroundLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); addView(mForegroundLayout); } mForegroundLayout.setVisibility(isChecked() ? View.VISIBLE : View.INVISIBLE); mForegroundLayout.setForeground(mDrawable); }
public final void onLoaded(FifeImageView paramFifeImageView, Bitmap paramBitmap) { if (this.mSwatchView != null) { int i = Bitmap.createScaledBitmap(Bitmap.createBitmap(paramBitmap, 0, 0, paramBitmap.getWidth(), Math.min(20, paramBitmap.getHeight())), 1, 1, false).getPixel(0, 0); int j = Color.argb(0, Color.red(i), Color.green(i), Color.blue(i)); float f = this.mTotalHeight; int[] arrayOfInt = { i, i, j }; float[] arrayOfFloat = new float[3]; arrayOfFloat[0] = 0.0F; arrayOfFloat[1] = this.mBreakPoint; arrayOfFloat[2] = 1.0F; LinearGradient localLinearGradient = new LinearGradient(0.0F, 0.0F, 0.0F, f, arrayOfInt, arrayOfFloat, Shader.TileMode.CLAMP); ShapeDrawable localShapeDrawable = new ShapeDrawable(new RectShape()); localShapeDrawable.getPaint().setShader(localLinearGradient); UiUtils.setBackground(this.mSwatchView, localShapeDrawable); UiUtils.setBackground(this.mBackground, new ColorDrawable(i)); } if (this.mOnLoadedListener != null) { this.mOnLoadedListener.onLoaded(paramFifeImageView, paramBitmap); } }
public kxi(Context paramContext) { mbb localmbb = mbb.b(paramContext); Resources localResources = paramContext.getResources(); if (efj.D(paramContext)) {} for (Object localObject = new ColorDrawable(1342177280);; localObject = localResources.getDrawable(aau.BY)) { this.e = new ShapeDrawable(new RectShape()); this.e.getPaint().setColor(localResources.getColor(aau.BX)); this.f = new ColorDrawable(this.e.getPaint().getColor()); Drawable[] arrayOfDrawable = new Drawable[2]; arrayOfDrawable[0] = localObject; arrayOfDrawable[1] = this.f; this.g = new LayerDrawable(arrayOfDrawable); this.c = efj.y(paramContext); this.h = ((kwz)localmbb.b(kwz.class)); ((gpl)localmbb.a(gpl.class)).a(this); return; } }
public static Bitmap getTransparentBitmap(View parent) { //create a bitmap if (parent.getWidth() == 0 || parent.getHeight() == 0) { return null; } int width = parent.getWidth(); int height = parent.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape()); shapeDrawable.setAlpha(180); shapeDrawable.getPaint().setColor(0x66000000); shapeDrawable.setBounds(0, 0, width, height); shapeDrawable.draw(canvas); return bitmap; }
private void init() { ShapeDrawable bottomLayer = new ShapeDrawable(new RectShape()); bottomLayer.getPaint().setColor(Color.BLUE); ShapeDrawable midLayer = new ShapeDrawable(new RectShape()); midLayer.getPaint().setColor(Color.GREEN); midLayer.getPaint().setStyle(Paint.Style.STROKE);//空心,only display the border line and transparent content Drawable[] layer = new Drawable[] { bottomLayer, midLayer, getContext().getResources().getDrawable(R.drawable.ic_fab_star) }; LayerDrawable layerDrawable = new LayerDrawable(layer); // left, top, right, bottom. the distance with outer border of whole layout. layerDrawable.setLayerInset(0, 10, 10, 10, 10); layerDrawable.setLayerInset(1, 20, 20, 20, 20); setBackgroundByVersion(layerDrawable); }
private static LayerDrawable ˊ(Context paramContext) { int i = (int)(10.0F * paramContext.getResources().getDisplayMetrics().density); ShapeDrawable localShapeDrawable1 = new ShapeDrawable(new RectShape()); Paint localPaint1 = localShapeDrawable1.getPaint(); localPaint1.setColor(-1); localPaint1.setStyle(Paint.Style.FILL_AND_STROKE); localPaint1.setStrokeWidth(1.0F); localShapeDrawable1.setPadding(i, i, i, i); int j = (int)(1.5D * paramContext.getResources().getDisplayMetrics().density); ShapeDrawable localShapeDrawable2 = new ShapeDrawable(new RectShape()); Paint localPaint2 = localShapeDrawable2.getPaint(); localPaint2.setColor(-12303292); localPaint2.setStyle(Paint.Style.FILL_AND_STROKE); localPaint2.setStrokeWidth(1.0F); localShapeDrawable2.setPadding(0, 0, 0, j); return new LayerDrawable(new Drawable[] { localShapeDrawable2, localShapeDrawable1 }); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); LinearGradient gradient = new LinearGradient(0.0f, 0.0f, ((float) getWidth()), 0.0f, new int[]{0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF, 0xFFFF0000, 0xFFFF00FF, 0xFFFFFF00, 0xFFFFFFFF}, null, Shader.TileMode.CLAMP); ShapeDrawable shape = new ShapeDrawable(new RectShape()); shape.getPaint().setShader(gradient); Rect bounds = getProgressDrawable().getBounds(); setProgressDrawable(shape); getProgressDrawable().setBounds(bounds); }
public void init() { mPaint = new Paint(); mPaint.setAlpha(100); setRippleColor(Color.BLACK, 0.2f); ShapeDrawable normal = new ShapeDrawable(new RectShape()); normal.getPaint().setColor(Color.parseColor("#00FFFFFF")); StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, normal); states.addState(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, normal); states.addState(new int[] { android.R.attr.state_enabled }, normal); states.addState(new int[] { -android.R.attr.state_enabled }, normal); setBackgroundDrawable(states); }
private void applyProgressBarSettings() { if (mHeaderProgressBar != null) { final int strokeWidth = mHeaderProgressBar.getResources() .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width); mHeaderProgressBar.setIndeterminateDrawable( new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext()) .color(mProgressDrawableColor) .strokeWidth(strokeWidth) .build()); ShapeDrawable shape = new ShapeDrawable(); shape.setShape(new RectShape()); shape.getPaint().setColor(mProgressDrawableColor); ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL); mHeaderProgressBar.setProgressDrawable(clipDrawable); } }
private void applyProgressBarSettings() { if (mHeaderProgressBar != null) { final int strokeWidth = mHeaderProgressBar.getResources() .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width); mHeaderProgressBar.setIndeterminateDrawable( new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext()) .color(mProgressDrawableColor) .width(strokeWidth) .build()); ShapeDrawable shape = new ShapeDrawable(); shape.setShape(new RectShape()); shape.getPaint().setColor(mProgressDrawableColor); ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL); mHeaderProgressBar.setProgressDrawable(clipDrawable); } }
public BorderDrawable(String shapeType, final int borderColor, final int borderWidth) { super(); final Shape shape = shapeType.equals(RECT) ? new RectShape() : new OvalShape(); final ShapeDrawable transparentShape = new ShapeDrawable(shape); transparentShape.getPaint().setColor(0x00000000);// Transparent final GradientDrawable shapeDrawable = new GradientDrawable(); shapeDrawable.setShape(shapeType.equals(RECT) ? GradientDrawable.RECTANGLE : GradientDrawable.OVAL); shapeDrawable.setStroke(borderWidth, borderColor); addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, -android.R.attr.state_pressed }, shapeDrawable); addState(new int[] { android.R.attr.state_enabled, -android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable); addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused, android.R.attr.state_pressed }, shapeDrawable); addState(new int[] {}, transparentShape); }
private void applyProgressBarSettings() { if (mHeaderProgressBar != null) { final int strokeWidth = mHeaderProgressBar.getResources() .getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width); mHeaderProgressBar.setIndeterminateDrawable( new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext()) .color(mProgressDrawableColor) .build()); ShapeDrawable shape = new ShapeDrawable(); shape.setShape(new RectShape()); shape.getPaint().setColor(mProgressDrawableColor); ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL); mHeaderProgressBar.setProgressDrawable(clipDrawable); } }
@Override @SuppressWarnings(value = { "deprecation" }) public View getItemView(int section, int position, View convertView, ViewGroup parent) { TextView tv = null; if (convertView != null) { tv = (TextView) convertView; } else { tv = new TextView(context); RectShape rs = new RectShape(); ShapeDrawable sd = new BottomBorderBackground(rs, Color.WHITE, Color.GRAY); tv.setBackgroundDrawable(sd); tv.setPadding(20, 0, 0, 0); tv.setGravity(Gravity.CENTER_VERTICAL); } tv.setLayoutParams(new LayoutParams(300, itemHeight)); tv.setText("s" + section + " p" + position); return tv; }
private void drawBar(Canvas canvas) { int padding = 5; // Padding on both sides. int x = 0; int y = 10; int width = (int) (Math.floor(getWidth() / segmentColors.length)) - (2 * padding); int height = 50; mDrawable = new ShapeDrawable(new RectShape()); for (int i = 0; i < segmentColors.length; i++) { x = x + padding; if ((mLevel * segmentColors.length) > (i + 0.5)) { mDrawable.getPaint().setColor(segmentColors[i]); } else { mDrawable.getPaint().setColor(segmentOffColor); } mDrawable.setBounds(x, y, x + width, y + height); mDrawable.draw(canvas); x = x + width + padding; } }
/** * Generates bitmaps used for drawing joystick. */ void generateBitmap() { // Size and shape of joystick gate ShapeDrawable squareShape = new ShapeDrawable(); squareShape.setShape(new RectShape()); squareShape.setBounds(0, 0, (int) radius * 2, (int) radius * 2); // Create joystick gate bitmap and render shape handlesBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444); Canvas handlesCanvas = new Canvas(handlesBitmap); squareShape.getPaint().set(parent.blackPaint); squareShape.draw(handlesCanvas); parent.strokePaint.setStrokeWidth(standardRadius * .1f); squareShape.getPaint().set(parent.strokePaint); squareShape.draw(handlesCanvas); handlesCanvas.rotate(45, radius, radius); squareShape.getPaint().set(parent.clearPaint); squareShape.draw(handlesCanvas); parent.strokePaint.setStrokeWidth(standardRadius * .05f); squareShape.getPaint().set(parent.strokePaint); squareShape.draw(handlesCanvas); }
private Builder() { text = ""; color = Color.GRAY; textColor = Color.WHITE; borderThickness = 0; width = -1; height = -1; shape = new RectShape(); font = Typeface.create("sans-serif-light", Typeface.NORMAL); fontSize = -1; isBold = false; toUpperCase = false; }
/** * 创建 TextView 背景 {@link android.graphics.drawable.Drawable} * * @return {@link ShapeDrawable} */ private ShapeDrawable createFrameDrawableBg() { ShapeDrawable shape = new ShapeDrawable(new RectShape()); Paint paint = shape.getPaint(); paint.setColor(frameColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(frameWidth); return shape; }
/** * 初始化默认的Drawable,{@link #defaultDrawable} */ private void initDefaultDrawable() { defaultDrawable = new ShapeDrawable(new RectShape()); Paint paint = defaultDrawable.getPaint(); paint.setColor(frameColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(strokeWidth); setTextViewDrawable(defaultDrawable); }
public ATableViewPlainFooterDrawable(ATableView tableView, int rowHeight) { super(new RectShape()); Resources res = tableView.getResources(); mStrokeWidth = DrawableUtils.getStrokeWidth(res); mStrokeOffset = (float) Math.ceil(rowHeight * res.getDisplayMetrics().density) + mStrokeWidth; // stroke. mStrokePaint = new Paint(); mStrokePaint.setStyle(Paint.Style.STROKE); mStrokePaint.setStrokeWidth(mStrokeWidth); mStrokePaint.setColor(DrawableUtils.getSeparatorColor(tableView)); }
public static void setCommonTabDivider(CommonTabLayout tabLayout, @ColorInt int color, int showDividers, int padding) { LinearLayout linearLayout = (LinearLayout) tabLayout.getChildAt(0); linearLayout.setDividerPadding(padding); RectShape rectShape = new RectShape(); float density = tabLayout.getResources().getDisplayMetrics().density; ShapeDrawable shapeDrawable = new ShapeDrawable(rectShape); shapeDrawable.setIntrinsicWidth((int) density); shapeDrawable.setIntrinsicHeight((int) density); shapeDrawable.getPaint().setColor(color); shapeDrawable.getPaint().setStyle(Paint.Style.STROKE); linearLayout.setDividerDrawable(shapeDrawable); linearLayout.setShowDividers(showDividers); }
private void initSquare(Context context) { if (mTriangle == null) { TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); // triangle Path chipPath = new Path(); chipPath.moveTo(500f, 0f); chipPath.lineTo(500f, 500f); chipPath.lineTo(0f, 500f); chipPath.close(); mTriangle = new ShapeDrawable(new PathShape(chipPath, 500f, 500f)); mTriangle.setDither(true); int triangleColor = Color.parseColor("#cc1f1f1f"); if (theme.resolveAttribute(R.attr.cp_badgeTriangleColor, typedValue, true)) { triangleColor = typedValue.data; } mTriangle.getPaint().setColor(triangleColor); // line mLinePaint = new Paint(); int lineColor = Color.parseColor("#ffffffff"); if (theme.resolveAttribute(R.attr.cp_badgeLineColor, typedValue, true)) { lineColor = typedValue.data; } mLinePaint.setColor(lineColor); mOffset = 1.5f * mDensity; mLinePaint.setStrokeWidth(mOffset); } initOverlay(context, new RectShape()); }
private Drawable createDrawableFrom(ShapeDrawable.ShaderFactory sf) { PaintDrawable p = new PaintDrawable(); p.setShape(new RectShape()); p.setShaderFactory(sf); return p; }