Java Code Examples for android.graphics.drawable.ShapeDrawable#setBounds()
The following examples show how to use
android.graphics.drawable.ShapeDrawable#setBounds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorPickerAdapter.java From indigenous-android with GNU General Public License v3.0 | 6 votes |
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
Example 2
Source File: ColorPickerAdapter.java From PhotoEditor with MIT License | 6 votes |
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
Example 3
Source File: ColorPickerAdapter.java From react-native-photo-editor with Apache License 2.0 | 6 votes |
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
Example 4
Source File: MagnifierView.java From AndroidDigIn with Apache License 2.0 | 6 votes |
public MagnifierView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); bitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.pic)).getBitmap(); scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * FACTOR, bitmap.getHeight() * FACTOR, true); // bitmap.recycle(); mBitmapShader = new BitmapShader(scaledBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mShapeDrawable = new ShapeDrawable(new OvalShape()); mShapeDrawable.setBounds(0, 0, WIDTH, WIDTH); mShapeDrawable.getPaint().setShader(mBitmapShader); mMatrix = new Matrix(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(3); }
Example 5
Source File: ColorPickerAdapter.java From photo-editor-android with MIT License | 6 votes |
private void buildColorPickerView(View view, int colorCode) { view.setVisibility(View.VISIBLE); ShapeDrawable biggerCircle = new ShapeDrawable(new OvalShape()); biggerCircle.setIntrinsicHeight(20); biggerCircle.setIntrinsicWidth(20); biggerCircle.setBounds(new Rect(0, 0, 20, 20)); biggerCircle.getPaint().setColor(colorCode); ShapeDrawable smallerCircle = new ShapeDrawable(new OvalShape()); smallerCircle.setIntrinsicHeight(5); smallerCircle.setIntrinsicWidth(5); smallerCircle.setBounds(new Rect(0, 0, 5, 5)); smallerCircle.getPaint().setColor(Color.WHITE); smallerCircle.setPadding(10, 10, 10, 10); Drawable[] drawables = {smallerCircle, biggerCircle}; LayerDrawable layerDrawable = new LayerDrawable(drawables); view.setBackgroundDrawable(layerDrawable); }
Example 6
Source File: ColorChooserDialog.java From Material-Color-Picker with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void Colorize() { for (int i = 0; i < buttons.size(); i++) { ShapeDrawable d = new ShapeDrawable(new OvalShape()); d.setBounds(58, 58, 58, 58); Log.e("Shape drown no", i + ""); buttons.get(i).setVisibility(View.INVISIBLE); d.getPaint().setStyle(Paint.Style.FILL); d.getPaint().setColor(colors.get(i)); buttons.get(i).setBackground(d); } animate(); }
Example 7
Source File: GameView.java From CanEffect with Apache License 2.0 | 5 votes |
public void onDraw(Canvas canvas) { super.onDraw(canvas); //将图片裁剪为椭圆形 /* 构建ShapeDrawable对象并定义形状为椭圆 */ mShapeDrawableQQ = new ShapeDrawable(new OvalShape()); /* 设置要绘制的椭圆形的东西为ShapeDrawable图片 */ mShapeDrawableQQ.getPaint().setShader(mBitmapShader); /* 设置显示区域 */ mShapeDrawableQQ.setBounds(0,0, BitQQwidth, BitQQheight); /* 绘制ShapeDrawableQQ */ mShapeDrawableQQ.draw(canvas); //绘制渐变的矩形 mPaint.setShader(mLinearGradient); canvas.drawRect(BitQQwidth, 0, 320, 156, mPaint); //显示混合渲染效果 mPaint.setShader(mComposeShader); canvas.drawRect(0, 300, BitQQwidth, 300+BitQQheight, mPaint); //绘制环形渐变 mPaint.setShader(mRadialGradient); canvas.drawCircle(50, 200, 50, mPaint); //绘制梯度渐变 mPaint.setShader(mSweepGradient); canvas.drawRect(150, 160, 300, 300, mPaint); }
Example 8
Source File: ColorChooserDialog.java From Material-Color-Picker with Apache License 2.0 | 5 votes |
private void ColorizeOld() { for (int i = 0; i < buttons.size(); i++) { ShapeDrawable d = new ShapeDrawable(new OvalShape()); d.getPaint().setColor(colors.get(i)); d.getPaint().setStrokeWidth(1f); d.setBounds(58, 58, 58, 58); buttons.get(i).setVisibility(View.INVISIBLE); d.getPaint().setStyle(Paint.Style.FILL); d.getPaint().setColor(colors.get(i)); buttons.get(i).setBackgroundDrawable(d); } animate(); }
Example 9
Source File: LineChartView.java From line-chart-view with MIT License | 5 votes |
protected void drawYLabels(ShapeDrawable labelDrawable) { Shape labelsShape = new Shape() { @Override public void draw(Canvas canvas, Paint paint) { labelPaint.setTextAlign(Paint.Align.RIGHT); labelPaint.setTextSize(lineChartStyle.getLabelTextSize()); labelPaint.setColor(lineChartStyle.getLabelTextColor()); long minY = getMinY(); long maxY = getMaxY(); long yrange = maxY - minY; float height = getHeight(); float left = getYLabelWidth(); List<Long> yLabels = getYLabels(); for (long y : yLabels) { String label = formatYLabel(y); float yCoordinate = getYCoordinate(height, y, minY, yrange); canvas.drawText(label, left, yCoordinate, labelPaint); } } }; measureYLabel(); labelDrawable.setBounds(0, 0, getWidth(), getHeight()); labelDrawable.setShape(labelsShape); }
Example 10
Source File: LineChartView.java From line-chart-view with MIT License | 5 votes |
protected void drawXLabels(ShapeDrawable labelDrawable) { Shape labelsShape = new Shape() { @Override public void draw(Canvas canvas, Paint paint) { labelPaint.setTextAlign(Paint.Align.CENTER); labelPaint.setTextSize(lineChartStyle.getLabelTextSize()); labelPaint.setColor(lineChartStyle.getLabelTextColor()); long minX = getMinX(); long maxX = getMaxX(); long xrange = maxX - minX; float width = getWidth(); float height = getHeight(); float labelHeight = height - lineChartStyle.getXLabelMargin(); Rect textBounds = new Rect(); List<Long> xLabels = getXLabels(); for (long x : xLabels) { String label = formatXLabel(x); labelPaint.getTextBounds(label, 0, label.length(), textBounds); float xCoordinate = getXCoordinate(width, x, minX, xrange); canvas.drawText(label, xCoordinate, labelHeight, labelPaint); } } }; measureXLabel(); labelDrawable.setBounds(0, 0, getWidth(), getHeight()); labelDrawable.setShape(labelsShape); }
Example 11
Source File: LineChartView.java From line-chart-view with MIT License | 5 votes |
protected void drawLineChart(ShapeDrawable chartDrawable) { Shape chartShape = new Shape() { @Override public void draw(Canvas canvas, Paint paint) { long minX = getMinX(); long maxX = getMaxX(); long xrange = maxX - minX; long minY = getMinY(); long maxY = getMaxY(); long yrange = maxY - minY; float width = getWidth(); float height = getHeight(); float left = getChartLeftMargin(); float top = getChartTopMargin(); float right = width - getChartRightMargin(); float bottom = height - getChartBottomMargin(); drawChartFrame(canvas, left, top, right, bottom); drawXGrid(canvas, minX, xrange); drawYGrid(canvas, minY, yrange); List<LineChartStyle.Border> borders = lineChartStyle.getBorders(); for (LineChartStyle.Border border : borders) { drawChartBorder(canvas, border, left, top, right, bottom); } drawLines(canvas, minX, xrange, minY, yrange); if (lineChartStyle.isDrawPoint()) { drawPoints(canvas, minX, xrange, minY, yrange); } } }; chartDrawable.setBounds(0, 0, getWidth(), getHeight()); chartDrawable.setShape(chartShape); }
Example 12
Source File: PinputView.java From android-pin with MIT License | 5 votes |
protected Drawable makeCharShape(float size, int color, Rect bounds) { Shape shape = new OvalShape(); shape.resize(size, size); ShapeDrawable drawable = new ShapeDrawable(shape); drawable.getPaint().setColor(color); drawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG); drawable.setBounds(bounds); return drawable; }
Example 13
Source File: CropImageView.java From CropImageView with MIT License | 5 votes |
private Drawable getCircleDrawable(int color, int width, int height) { ShapeDrawable biggerCircle= new ShapeDrawable( new OvalShape()); biggerCircle.setIntrinsicWidth( width); biggerCircle.setIntrinsicHeight( height ); biggerCircle.setBounds(new Rect(0, 0, width, height)); biggerCircle.getPaint().setColor(color); return biggerCircle; }
Example 14
Source File: ShadowLayout.java From ShadowLayout with MIT License | 4 votes |
private void setSpaceCorner(Canvas canvas, int trueHeight) { int leftTop; int rightTop; int rightBottom; int leftBottom; if (mCornerRadius_leftTop == -1) { leftTop = (int) mCornerRadius; } else { leftTop = (int) mCornerRadius_leftTop; } if (leftTop > trueHeight / 2) { leftTop = trueHeight / 2; } if (mCornerRadius_rightTop == -1) { rightTop = (int) mCornerRadius; } else { rightTop = (int) mCornerRadius_rightTop; } if (rightTop > trueHeight / 2) { rightTop = trueHeight / 2; } if (mCornerRadius_rightBottom == -1) { rightBottom = (int) mCornerRadius; } else { rightBottom = (int) mCornerRadius_rightBottom; } if (rightBottom > trueHeight / 2) { rightBottom = trueHeight / 2; } if (mCornerRadius_leftBottom == -1) { leftBottom = (int) mCornerRadius; } else { leftBottom = (int) mCornerRadius_leftBottom; } if (leftBottom > trueHeight / 2) { leftBottom = trueHeight / 2; } float[] outerR = new float[]{leftTop, leftTop, rightTop, rightTop, rightBottom, rightBottom, leftBottom, leftBottom};//左上,右上,右下,左下 ShapeDrawable mDrawables = new ShapeDrawable(new RoundRectShape(outerR, null, null)); mDrawables.getPaint().setColor(paint.getColor()); mDrawables.setBounds(leftPading, topPading, getWidth() - rightPading, getHeight() - bottomPading); mDrawables.draw(canvas); }
Example 15
Source File: VerticalSeekBar.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 4 votes |
private void grxSetUPAdditionalOptions(TypedArray a){ mGrxZeroOffset = a.getInt(R.styleable.VerticalSeekBar_zeroOffset,0); mGrxDividerStep = a.getInt(R.styleable.VerticalSeekBar_dividerStep,0); mGrxHalfDividerLength = a.getDimension(R.styleable.VerticalSeekBar_dividerLength,0f)/2; mGrxHalfDividerThickness = a.getDimensionPixelSize(R.styleable.VerticalSeekBar_dividerThickness,0)/2; mGrxHalfProgressThickness = a.getDimensionPixelSize(R.styleable.VerticalSeekBar_progressThickness,0)/2; mGrxShowBackgroundTrack = a.getBoolean(R.styleable.VerticalSeekBar_showBackgroundTrack,true); mGrxZeroOffsetCircleRadius = a.getDimensionPixelSize(R.styleable.VerticalSeekBar_zeroOffsetCircleRadius,0); mGrxMin = a.getInt(R.styleable.VerticalSeekBar_min,0); mGrxNumSteps = getMax() - mGrxMin; mGrxProgressPaint = new Paint(); mGrxProgressPaint.setStyle(Paint.Style.FILL); TypedValue typedValue = new TypedValue(); TypedArray b = getContext().obtainStyledAttributes(typedValue.data, new int[] { android.R.attr.colorAccent }); int color = b.getColor(0, 0); b.recycle(); mGrxProgressPaint.setColor(color); Drawable currentprogressdrawable = getProgressDrawable(); Drawable track = null; mGrxShowBackgroundTrack=false;//bbb if(currentprogressdrawable!= null && currentprogressdrawable instanceof LayerDrawable) { if (!mGrxShowBackgroundTrack){ int indexbg = ((LayerDrawable) currentprogressdrawable).findIndexByLayerId(android.R.id.background); ((LayerDrawable) currentprogressdrawable).setDrawable(indexbg, new ColorDrawable(0)); } int indexprogress = ((LayerDrawable) currentprogressdrawable).findIndexByLayerId(android.R.id.progress); ((LayerDrawable) currentprogressdrawable).setDrawable(indexprogress, new ColorDrawable(0)); } mGrxDividerPaint = new Paint(); mGrxDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE); mGrxDividerPaint.setColor(color); mGrxDividerPaint.setStrokeWidth(2.0f); mTickMark = new ShapeDrawable(new OvalShape()); mTickMark.setIntrinsicHeight(10); mTickMark.setIntrinsicWidth(10); mTickMark.getPaint().setColor(color); mTickMark.setBounds(new Rect(-2, -2, 2, 2)); mTickMarkSoft = new ShapeDrawable(new OvalShape()); mTickMarkSoft.setIntrinsicHeight(10); mTickMarkSoft.setIntrinsicWidth(10); mTickMarkSoft.getPaint().setColor(color&0x10ffffff); mTickMarkSoft.setBounds(new Rect(-4, -4, 4, 4)); }
Example 16
Source File: AddTagAdapter.java From talk-android with MIT License | votes |
public TagViewHolder(View itemView) { super(itemView); ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); final int size = DensityUtil.dip2px(itemView.getContext(), 8.0f); drawable.setIntrinsicHeight(size); drawable.setIntrinsicWidth(size); drawable.setBounds(0, 0, size, size); drawable.getPaint().setColor(itemView.getResources().getColor(R.color.colorPrimary)); tagText = (TextView) itemView.findViewById(R.id.tag_text); tagText.setCompoundDrawables(drawable, null, null, null); tagSelectImage = (ImageView) itemView.findViewById(R.id.tag_check); final Drawable selectImage = ThemeUtil.getDrawableWithColor(itemView.getResources(), R.drawable.ic_save_blue, R.color.colorPrimary); tagSelectImage.setImageDrawable(selectImage); }