android.graphics.drawable.shapes.Shape Java Examples
The following examples show how to use
android.graphics.drawable.shapes.Shape.
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: TooltipErrorView.java From buddycloud-android with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public boolean onPreDraw() { mContentHolder.measure(getMeasuredWidth(), getTextHeight() + mPointHeightPx); Shape shape = getTooltipShape(); ShapeDrawable d = new ShapeDrawable(shape); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mContentHolder.setBackground(d); } else { mContentHolder.setBackgroundDrawable(d); } return true; }
Example #2
Source File: Slice.java From Slice with Apache License 2.0 | 6 votes |
@SuppressWarnings("WeakerAccess") @TargetApi(Build.VERSION_CODES.LOLLIPOP) public Slice setRipple(@ColorInt final int mask) { if (SDK_LOLLIPOP) { if (mask != 0) { ShapeDrawable shape = new ShapeDrawable(new Shape() { @Override public void draw(Canvas canvas, Paint paint) { paint.setColor(mask); canvas.drawPath(((CustomRoundRectDrawable) drawable).buildConvexPath(), paint); } }); RippleDrawable ripple = new RippleDrawable(buildColorStateList(mask), drawable, shape); view.setBackground(ripple); } else { view.setBackground(drawable); } } else { Log.i(TAG, "setRipple() only work for API 21+"); } return this; }
Example #3
Source File: ProfileImageView.java From Contacts with MIT License | 6 votes |
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); }
Example #4
Source File: Slice.java From Slice with Apache License 2.0 | 6 votes |
@SuppressWarnings("WeakerAccess") @TargetApi(Build.VERSION_CODES.LOLLIPOP) public Slice setRipple(@ColorInt final int mask) { if (SDK_LOLLIPOP) { if (mask != 0) { ShapeDrawable shape = new ShapeDrawable(new Shape() { @Override public void draw(Canvas canvas, Paint paint) { paint.setColor(mask); canvas.drawPath(((CustomRoundRectDrawable) drawable).buildConvexPath(), paint); } }); RippleDrawable ripple = new RippleDrawable(buildColorStateList(mask), drawable, shape); view.setBackground(ripple); } else { view.setBackground(drawable); } } else { Log.i(TAG, "setRipple() only work for API 21+"); } return this; }
Example #5
Source File: BrushDrawable.java From libcommon with Apache License 2.0 | 6 votes |
/** * #drawをOverrideしても良いけど、色々処理をしているので#onDrawの方をOverrideする * (#onDrawは#drawから呼び出される) */ @Override protected void onDraw(final Shape shape, final Canvas canvas, final Paint paint) { canvas.rotate(mRotation, mPivot.x, mPivot.y); // これを入れると背景が透過する(backgroundの指定してても見えなくなる) // canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); final int count = canvas.save(); // final DrawFilter org = canvas.getDrawFilter(); try { // canvas.setDrawFilter(mDrawFilter); mPaint.setShader(mShader); /* paint.setColor(Color.TRANSPARENT); // 消しゴムの時 paint.setXfermode(mClearXfermode); */ // canvas.drawPaint(mPaint); super.onDraw(shape, canvas, paint); // 描画自体は上位に任せる(実際はShape#drawに任せる) } finally { // canvas.setDrawFilter(org); canvas.restoreToCount(count); } }
Example #6
Source File: ProfileImageView.java From Klyph with MIT License | 6 votes |
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); }
Example #7
Source File: ProfileImageView.java From KlyphMessenger with MIT License | 6 votes |
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); }
Example #8
Source File: DotWidget.java From star-zone-android with Apache License 2.0 | 6 votes |
@Override protected void onDraw(Shape shape, Canvas canvas, Paint paint) { super.onDraw(shape, canvas, paint); if (!TextUtils.isEmpty(text)) { Rect r = getBounds(); if (dotTextSize == 0) { dotTextSize = (int) (r.width() * 0.5); textPaint.setTextSize(dotTextSize); } //保证文字居中 Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt(); int baseline = r.top + (r.bottom - r.top - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top; textPaint.setTextAlign(Paint.Align.CENTER); canvas.drawText(text, r.centerX(), baseline, textPaint); } }
Example #9
Source File: MaskDrawable.java From UILibrary with MIT License | 5 votes |
public MaskDrawable(Drawable content, Shape mask){ mDrawingContent = content; mMask = mask; mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(0xFFFFFFFF); }
Example #10
Source File: TooltipErrorView.java From buddycloud-android with Apache License 2.0 | 5 votes |
/** * Get the tooltip shape * * @return */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private Shape getTooltipShape() { Resources r = this.getContext().getResources(); final int pointHeightPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, POINTER_HEIGHT, r.getDisplayMetrics()); final int pointedHeightPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, POINTER_WIDE_HEIGHT, r.getDisplayMetrics()); final int pointStartPx = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, POINTER_START, r.getDisplayMetrics()); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mContentHolder .getLayoutParams(); mToolTipTV.setY(pointHeightPx); params.height = mToolTipTV.getHeight() + pointHeightPx; final Path rectPath = new Path(); final Path rectBorderPath = new Path(); // Create the rectangular shape Shape shape = new RectShape() { @Override protected void onResize(float w, float h) { createShapePath(rectPath, rectBorderPath, w, h, pointHeightPx, pointedHeightPx, pointStartPx); } @Override public void draw(Canvas canvas, Paint paint) { drawOnCanvas(canvas, paint, rectPath, rectBorderPath); } }; return shape; }
Example #11
Source File: PaletteGridAdapter.java From color-picker with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") @SuppressWarnings("deprecation") @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { view = mLayoutInflater.inflate(R.layout.dmfs_colorpickerdialog_palette_field, null); } // set the background to a colored circle // TODO: allow to customize the shape Shape shape = new ArcShape(0, 360); ShapeDrawable bg = new ShapeDrawable(shape); bg.getPaint().setColor(mPalette.colorAt(position)); if (android.os.Build.VERSION.SDK_INT < 16) { view.setBackgroundDrawable(bg); } else { view.setBackground(bg); } return view; }
Example #12
Source File: ScheduleClassAdapter.java From utexas-utilities with Apache License 2.0 | 5 votes |
private void drawCurrentMinutesLine(Shape shape, Canvas canvas, Paint paint, int bgColor) { paint.setStrokeWidth(3f); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawColor(bgColor); Paint blur = new Paint(paint); blur.setStrokeWidth(3f); blur.setMaskFilter(new BlurMaskFilter(3, BlurMaskFilter.Blur.SOLID)); canvas.drawLine(0, (int) ((currMinutes / 30.0) * shape.getHeight() + .5), shape.getWidth(), (int) ((currMinutes / 30.0) * shape.getHeight() + .5), paint); }
Example #13
Source File: RFABShape.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static ShapeDrawable generateCornerShapeDrawable(int color, int topLeftCorner, int topRightCorner, int bottomRightCorner, int bottomLeftCorner) { Shape shape = new RoundRectShape(new float[]{topLeftCorner, topLeftCorner, topRightCorner, topRightCorner, bottomRightCorner, bottomRightCorner, bottomLeftCorner, bottomLeftCorner}, null, null); ShapeDrawable sd = new ShapeDrawable(shape); sd.getPaint().setColor(color); sd.getPaint().setStyle(Paint.Style.FILL); return sd; }
Example #14
Source File: BrushDrawable.java From libcommon with Apache License 2.0 | 5 votes |
public void setRotation(final float rotation) { // if (DEBUG) Log.v(TAG, "setRotation:" + rotation); final Shape shape = getShape(); if (shape instanceof BaseShape) { ((BaseShape)shape).setRotation(rotation); mRotation = 0; } else { if (mRotation != rotation) { mRotation = rotation; } } invalidateSelf(); }
Example #15
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 #16
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 #17
Source File: DefaultSectionAdapter.java From UltimateAndroid with Apache License 2.0 | 5 votes |
public BottomBorderBackground(Shape s, int fill, int stroke) { super(s); fillpaint = new Paint(this.getPaint()); fillpaint.setColor(fill); strokepaint = new Paint(fillpaint); strokepaint.setStyle(Paint.Style.STROKE); strokepaint.setStrokeWidth(2); strokepaint.setColor(stroke); }
Example #18
Source File: FloatingActionButton.java From ShareBox with Apache License 2.0 | 5 votes |
private CircleDrawable(Shape s) { super(s); circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0; circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0; if (mProgressBarEnabled) { circleInsetHorizontal += mProgressWidth; circleInsetVertical += mProgressWidth; } }
Example #19
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 #20
Source File: MaskDrawable.java From UILibrary with MIT License | 5 votes |
public void setMask(Shape mask){ mMask = mask; mMask.resize(getBounds().width(), getBounds().height()); recreateBitmap(); invalidateSelf(); }
Example #21
Source File: ContactBadge.java From Android-ContactPicker with Apache License 2.0 | 5 votes |
private void initOverlay(Context context, Shape shape) { // pressed state TypedValue typedValue = new TypedValue(); Theme theme = context.getTheme(); mPressedOverlay = new ShapeDrawable(shape); int overlayColor = Color.parseColor("#aa888888"); if (theme.resolveAttribute(R.attr.cp_badgeOverlayColor, typedValue, true)) { overlayColor = typedValue.data; } Paint paint = mPressedOverlay.getPaint(); paint.setColor(overlayColor); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); }
Example #22
Source File: FloatingActionButton.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
private CircleDrawable(Shape s) { super(s); circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0; circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0; if (mProgressBarEnabled) { circleInsetHorizontal += mProgressWidth; circleInsetVertical += mProgressWidth; } }
Example #23
Source File: Spans.java From Pioneer with Apache License 2.0 | 5 votes |
public ShapeSpan(Shape shape, Paint.Style style, int strokeWidth, @ColorInt int color, boolean includePad, CharacterStyle... styles) { super(styles); this.shape = shape; this.style = style; this.strokeWidth = strokeWidth; this.color = color; this.includePad = includePad; }
Example #24
Source File: Spans.java From Pioneer with Apache License 2.0 | 5 votes |
public ShapeSpan(Shape shape, Paint.Style style, int strokeWidth, @ColorInt int color, boolean includePad, CharacterStyle... styles) { super(styles); this.shape = shape; this.style = style; this.strokeWidth = strokeWidth; this.color = color; this.includePad = includePad; }
Example #25
Source File: FloatingActionButton.java From FloatingActionButton with Apache License 2.0 | 5 votes |
private CircleDrawable(Shape s) { super(s); circleInsetHorizontal = hasShadow() ? mShadowRadius + Math.abs(mShadowXOffset) : 0; circleInsetVertical = hasShadow() ? mShadowRadius + Math.abs(mShadowYOffset) : 0; if (mProgressBarEnabled) { circleInsetHorizontal += mProgressWidth; circleInsetVertical += mProgressWidth; } }
Example #26
Source File: PositionMarker.java From mappwidget with Apache License 2.0 | 5 votes |
public PositionMarker(MapWidget context, Object id, Drawable roundPointerDrawable, Drawable arrowPointerDrawable) { super(id, null, new Point(0, 0), false, false); this.context = context; accuracy = 500; pixelsInMeter = 0; hasBearing = false; arrowPointerPivotPoint = null; roundPointerPivotPoint= null; this.context = context; Shape accuracyShape = new OvalShape(); accuracyShape.resize(getAccuracyDiameter(), getAccuracyDiameter()); accuracyDrawable = new ShapeDrawable(accuracyShape); this.roundPointerDrawable = roundPointerDrawable; this.arrowPointerDrawable = arrowPointerDrawable; Paint accuracyAreaPaint = accuracyDrawable.getPaint(); accuracyAreaPaint.setStyle(Style.FILL); accuracyBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG); accuracyBorderPaint.setStyle(Style.STROKE); setDrawable(roundPointerDrawable); }
Example #27
Source File: RFABShape.java From RapidFloatingActionButton with Apache License 2.0 | 5 votes |
public static ShapeDrawable generateCornerShapeDrawable(int color, int topLeftCorner, int topRightCorner, int bottomRightCorner, int bottomLeftCorner) { Shape shape = new RoundRectShape(new float[]{topLeftCorner, topLeftCorner, topRightCorner, topRightCorner, bottomRightCorner, bottomRightCorner, bottomLeftCorner, bottomLeftCorner}, null, null); ShapeDrawable sd = new ShapeDrawable(shape); sd.getPaint().setColor(color); sd.getPaint().setStyle(Paint.Style.FILL); return sd; }
Example #28
Source File: RFABShape.java From RapidFloatingActionButton with Apache License 2.0 | 5 votes |
public static ShapeDrawable generateCornerStrokeDrawable(int color, float width, int topLeftCorner, int topRightCorner, int bottomRightCorner, int bottomLeftCorner) { Shape shape = new RoundRectShape(new float[]{topLeftCorner, topLeftCorner, topRightCorner, topRightCorner, bottomRightCorner, bottomRightCorner, bottomLeftCorner, bottomLeftCorner}, null, null); ShapeDrawable sd = new ShapeDrawable(shape); sd.getPaint().setColor(color); sd.getPaint().setStyle(Paint.Style.STROKE); sd.getPaint().setAntiAlias(true); sd.getPaint().setStrokeWidth(width); return sd; }
Example #29
Source File: RFABShape.java From RapidFloatingActionButton with Apache License 2.0 | 5 votes |
public static ShapeDrawable generateBackgroundDrawable(int color) { Shape shape = new OvalShape(); ShapeDrawable sd = new ShapeDrawable(shape); Paint paint = sd.getPaint(); paint.setColor(color); paint.setStyle(Paint.Style.FILL); return sd; }
Example #30
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); }