Java Code Examples for android.graphics.drawable.ShapeDrawable#getPaint()
The following examples show how to use
android.graphics.drawable.ShapeDrawable#getPaint() .
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: FloatingActionButton.java From NewFastFrame with Apache License 2.0 | 6 votes |
private Drawable createCircleDrawable(int color, float strokeWidth) { int alpha = Color.alpha(color); int opaqueColor = opaque(color); ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = fillDrawable.getPaint(); paint.setAntiAlias(true); paint.setColor(opaqueColor); Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) }; LayerDrawable drawable = alpha == 255 || !mStrokeVisible ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers); int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); return drawable; }
Example 2
Source File: FloatingActionButton.java From android-chat-ui with Apache License 2.0 | 6 votes |
private Drawable createCircleDrawable(int color, float strokeWidth) { int alpha = Color.alpha(color); int opaqueColor = opaque(color); ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = fillDrawable.getPaint(); paint.setAntiAlias(true); paint.setColor(opaqueColor); Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) }; LayerDrawable drawable = alpha == 255 || !mStrokeVisible ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers); int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); return drawable; }
Example 3
Source File: BasicAnimationActivity.java From AnimationApiDemos with Apache License 2.0 | 6 votes |
private ShapeHolder addBall(float x, float y) { OvalShape circle = new OvalShape(); circle.resize(50f * mDensity, 50f * mDensity); ShapeDrawable drawable = new ShapeDrawable(circle); ShapeHolder shapeHolder = new ShapeHolder(drawable); shapeHolder.setX(x - 25f); shapeHolder.setY(y - 25f); int red = (int) (100 + Math.random() * 155); int green = (int) (100 + Math.random() * 155); int blue = (int) (100 + Math.random() * 155); int color = 0xff000000 | red << 16 | green << 8 | blue; Paint paint = drawable.getPaint(); // new // Paint(Paint.ANTI_ALIAS_FLAG); int darkColor = 0xff000000 | red / 4 << 16 | green / 4 << 8 | blue / 4; RadialGradient gradient = new RadialGradient(37.5f, 12.5f, 50f, color, darkColor, Shader.TileMode.CLAMP); paint.setShader(gradient); shapeHolder.setPaint(paint); balls.add(shapeHolder); return shapeHolder; }
Example 4
Source File: CircleIndicator.java From uPods-android with Apache License 2.0 | 6 votes |
private void createMovingItem() { OvalShape circle = new OvalShape(); ShapeDrawable drawable = new ShapeDrawable(circle); movingItem = new ShapeHolder(drawable); Paint paint = drawable.getPaint(); paint.setColor(mIndicatorSelectedBackground); paint.setAntiAlias(true); switch (mIndicatorMode) { case INSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP)); break; case OUTSIDE: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); break; case SOLO: paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); break; } movingItem.setPaint(paint); }
Example 5
Source File: MultiPropertyAnimation.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
private ShapeHolder addBall(float x, float y) { OvalShape circle = new OvalShape(); circle.resize(BALL_SIZE, BALL_SIZE); ShapeDrawable drawable = new ShapeDrawable(circle); ShapeHolder shapeHolder = new ShapeHolder(drawable); shapeHolder.setX(x); shapeHolder.setY(y); int red = (int)(100 + Math.random() * 155); int green = (int)(100 + Math.random() * 155); int blue = (int)(100 + Math.random() * 155); int color = 0xff000000 | red << 16 | green << 8 | blue; Paint paint = drawable.getPaint(); int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4; RadialGradient gradient = new RadialGradient(37.5f, 12.5f, 50f, color, darkColor, Shader.TileMode.CLAMP); paint.setShader(gradient); shapeHolder.setPaint(paint); balls.add(shapeHolder); return shapeHolder; }
Example 6
Source File: FloatingActionButton.java From FloatingActionButton with Apache License 2.0 | 6 votes |
private Drawable createCircleDrawable(int color, float strokeWidth) { int alpha = Color.alpha(color); int opaqueColor = opaque(color); ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = fillDrawable.getPaint(); paint.setAntiAlias(true); paint.setColor(opaqueColor); Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) }; LayerDrawable drawable = alpha == 255 || !mStrokeVisible ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers); int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); return drawable; }
Example 7
Source File: FloatingActionButton.java From android-floating-action-button with Apache License 2.0 | 5 votes |
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) { if (!mStrokeVisible) { return new ColorDrawable(Color.TRANSPARENT); } ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final int bottomStrokeColor = darkenColor(color); final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor); final int topStrokeColor = lightenColor(color); final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); shapeDrawable.setShaderFactory(new ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP ); } }); return shapeDrawable; }
Example 8
Source File: PopupContainerWithArrow.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
/** * Adds an arrow view pointing at the original icon. * @param horizontalOffset the horizontal offset of the arrow, so that it * points at the center of the original icon */ private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) { LayoutParams layoutParams = new LayoutParams(width, height); if (mIsLeftAligned) { layoutParams.gravity = Gravity.START; layoutParams.leftMargin = horizontalOffset; } else { layoutParams.gravity = Gravity.END; layoutParams.rightMargin = horizontalOffset; } if (mIsAboveIcon) { layoutParams.topMargin = verticalOffset; } else { layoutParams.bottomMargin = verticalOffset; } View arrowView = new View(getContext()); if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) { // This is only true if there wasn't room for the container next to the icon, // so we centered it instead. In that case we don't want to show the arrow. arrowView.setVisibility(INVISIBLE); } else { ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create( width, height, !mIsAboveIcon)); Paint arrowPaint = arrowDrawable.getPaint(); // Note that we have to use getChildAt() instead of getItemViewAt(), // since the latter expects the arrow which hasn't been added yet. PopupItemView itemAttachedToArrow = (PopupItemView) (getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0)); arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon)); // The corner path effect won't be reflected in the shadow, but shouldn't be noticeable. int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius); arrowPaint.setPathEffect(new CornerPathEffect(radius)); arrowView.setBackground(arrowDrawable); arrowView.setElevation(getElevation()); } addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams); return arrowView; }
Example 9
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 10
Source File: FloatingActionButton.java From android-chat-ui with Apache License 2.0 | 5 votes |
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) { if (!mStrokeVisible) { return new ColorDrawable(Color.TRANSPARENT); } ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final int bottomStrokeColor = darkenColor(color); final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor); final int topStrokeColor = lightenColor(color); final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); shapeDrawable.setShaderFactory(new ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP ); } }); return shapeDrawable; }
Example 11
Source File: FloatingActionButton.java From NewFastFrame with Apache License 2.0 | 5 votes |
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) { if (!mStrokeVisible) { return new ColorDrawable(Color.TRANSPARENT); } ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final int bottomStrokeColor = darkenColor(color); final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor); final int topStrokeColor = lightenColor(color); final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); shapeDrawable.setShaderFactory(new ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(width / 2, 0, width / 2, height, new int[]{topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor}, new float[]{0f, 0.2f, 0.5f, 0.8f, 1f}, TileMode.CLAMP ); } }); return shapeDrawable; }
Example 12
Source File: FloatingActionButton.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
private Drawable createOuterStrokeDrawable(float strokeWidth) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); paint.setColor(Color.BLACK); paint.setAlpha(opacityToAlpha(0.02f)); return shapeDrawable; }
Example 13
Source File: FloatingActionButton.java From FloatingActionButton with Apache License 2.0 | 5 votes |
private Drawable createOuterStrokeDrawable(float strokeWidth) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); paint.setColor(Color.BLACK); paint.setAlpha(opacityToAlpha(0.02f)); return shapeDrawable; }
Example 14
Source File: FloatingActionButton.java From NewFastFrame with Apache License 2.0 | 5 votes |
private Drawable createOuterStrokeDrawable(float strokeWidth) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); paint.setColor(Color.BLACK); paint.setAlpha(opacityToAlpha(0.02f)); return shapeDrawable; }
Example 15
Source File: CircleButton.java From vinci with Apache License 2.0 | 5 votes |
private Drawable createCircleDrawable(int color) { ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = fillDrawable.getPaint(); paint.setAntiAlias(true); paint.setColor(color); return fillDrawable; }
Example 16
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 17
Source File: FloatingActionButton.java From TvRemoteControl with Apache License 2.0 | 5 votes |
private Drawable createOuterStrokeDrawable(float strokeWidth) { ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); paint.setColor(Color.BLACK); paint.setAlpha(opacityToAlpha(0.02f)); return shapeDrawable; }
Example 18
Source File: FloatingActionButton.java From TvRemoteControl with Apache License 2.0 | 5 votes |
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) { if (!mStrokeVisible) { return new ColorDrawable(Color.TRANSPARENT); } ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape()); final int bottomStrokeColor = darkenColor(color); final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor); final int topStrokeColor = lightenColor(color); final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor); final Paint paint = shapeDrawable.getPaint(); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStyle(Style.STROKE); shapeDrawable.setShaderFactory(new ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP ); } }); return shapeDrawable; }
Example 19
Source File: NotesLayer.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
private static MarkerSymbol getMarkerSymbol(GPMapView mapView) { SharedPreferences peferences = PreferenceManager.getDefaultSharedPreferences(mapView.getContext()); // notes type boolean doCustom = peferences.getBoolean(LibraryConstants.PREFS_KEY_NOTES_CHECK, true); String textSizeStr = peferences.getString(LibraryConstants.PREFS_KEY_NOTES_TEXT_SIZE, LibraryConstants.DEFAULT_NOTES_SIZE + ""); //$NON-NLS-1$ textSize = Integer.parseInt(textSizeStr); colorStr = peferences.getString(LibraryConstants.PREFS_KEY_NOTES_CUSTOMCOLOR, ColorUtilities.ALMOST_BLACK.getHex()); Drawable notesDrawable; if (doCustom) { String opacityStr = peferences.getString(LibraryConstants.PREFS_KEY_NOTES_OPACITY, "255"); //$NON-NLS-1$ String sizeStr = peferences.getString(LibraryConstants.PREFS_KEY_NOTES_SIZE, LibraryConstants.DEFAULT_NOTES_SIZE + ""); //$NON-NLS-1$ int noteSize = Integer.parseInt(sizeStr); float opacity = Integer.parseInt(opacityStr); OvalShape notesShape = new OvalShape(); android.graphics.Paint notesPaint = new android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG); notesPaint.setStyle(android.graphics.Paint.Style.FILL); notesPaint.setColor(ColorUtilities.toColor(colorStr)); notesPaint.setAlpha((int) opacity); ShapeDrawable notesShapeDrawable = new ShapeDrawable(notesShape); android.graphics.Paint paint = notesShapeDrawable.getPaint(); paint.set(notesPaint); notesShapeDrawable.setIntrinsicHeight(noteSize); notesShapeDrawable.setIntrinsicWidth(noteSize); notesDrawable = notesShapeDrawable; } else { notesDrawable = Compat.getDrawable(mapView.getContext(), eu.geopaparazzi.library.R.drawable.ic_place_accent_24dp); } notesBitmap = AndroidGraphics.drawableToBitmap(notesDrawable); return new MarkerSymbol(notesBitmap, MarkerSymbol.HotspotPlace.CENTER, false); }
Example 20
Source File: MaterialProgressBar.java From zhizhihu with Apache License 2.0 | 4 votes |
private void setColour(ShapeDrawable drawable, int colour) { Paint paint = drawable.getPaint(); paint.setColor(colour); }