android.graphics.drawable.ShapeDrawable Java Examples

The following examples show how to use android.graphics.drawable.ShapeDrawable. 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 vote down vote up
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 FloatingActionButton with Apache License 2.0 6 votes vote down vote up
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: DirectionView.java    From UPMiss with GNU General Public License v3.0 6 votes vote down vote up
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    ShapeDrawable drawable = new ShapeDrawable(new DirectionShape(3));
    Paint paint = drawable.getPaint();

    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.DirectionView);
    int color = a.getColor(R.styleable.DirectionView_iLineColor, Color.GRAY);
    int size = a.getDimensionPixelOffset(R.styleable.DirectionView_iLineSize, (int) (getResources().getDisplayMetrics().density * 2));
    a.recycle();

    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(size);
    paint.setColor(color);

    setBackground(drawable);
}
 
Example #4
Source File: FloatingActionButton.java    From android-chat-ui with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: BitmapUtil.java    From Leanplum-Android-SDK with Apache License 2.0 6 votes vote down vote up
private static Drawable getBackground(int normalStateColor,
    int pressedStateColor) {
  StateListDrawable background = new StateListDrawable();
  int c = SizeUtil.dp10;
  float[] r = new float[] {c, c, c, c, c, c, c, c};
  RoundRectShape rr = new RoundRectShape(r, null, null);
  ShapeDrawable cd = new ShapeDrawable();
  cd.setShape(rr);
  cd.getPaint().setColor(pressedStateColor);
  background.addState(new int[] {android.R.attr.state_pressed,
      android.R.attr.state_focused}, cd);
  background.addState(new int[] {-android.R.attr.state_pressed,
      android.R.attr.state_focused}, cd);
  background.addState(new int[] {android.R.attr.state_pressed,
      -android.R.attr.state_focused}, cd);
  ShapeDrawable cd1 = new ShapeDrawable();
  cd1.setShape(rr);
  cd1.getPaint().setColor(normalStateColor);
  background.addState(new int[] {-android.R.attr.state_pressed,
      -android.R.attr.state_focused}, cd1);
  return background;
}
 
Example #6
Source File: BouncingBalls.java    From AnimationApiDemos with Apache License 2.0 6 votes vote down vote up
private ShapeHolder addBall(float x, float y) {
	OvalShape circle = new OvalShape();
	circle.resize(50f, 50f);
	ShapeDrawable drawable = new ShapeDrawable(circle);
	ShapeHolder shapeHolder = new ShapeHolder(drawable);
	shapeHolder.setX(x - 25f);
	shapeHolder.setY(y - 25f);
	int red = (int) (Math.random() * 255);
	int green = (int) (Math.random() * 255);
	int blue = (int) (Math.random() * 255);
	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 #7
Source File: DynamicPickerUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Set a hue gradient progress drawable for a seek bar.
 *
 * @param seekBar The seek bar to set the hue gradient.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setHueDrawable(@NonNull SeekBar seekBar) {
    if (DynamicSdkUtils.is21()) {
        seekBar.setProgressTintList(null);
    }

    LinearGradient gradient =
            new LinearGradient(0.0f, 0.0f, (float) seekBar.getWidth(), 0.0f,
                    new int[] { 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00,
                            0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF0000 },
                    null, Shader.TileMode.CLAMP);
    ShapeDrawable shape = new ShapeDrawable(new RectShape());
    shape.getPaint().setShader(gradient);

    Rect bounds = seekBar.getProgressDrawable().getBounds();
    bounds.inset(0, (int) (bounds.height() * 0.45f));

    seekBar.setProgressDrawable(shape);
    seekBar.getProgressDrawable().setBounds(bounds);
}
 
Example #8
Source File: ColorPickerAdapter.java    From react-native-photo-editor with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: CircleIndicator.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: MultiPropertyAnimation.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
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 #11
Source File: Utils.java    From BlackList with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the background color of the drawable
 **/
public static void setDrawableColor(Context context, Drawable drawable, @AttrRes int colorAttrRes) {
    int colorRes = getResourceId(context, colorAttrRes);
    int color = ContextCompat.getColor(context, colorRes);
    if (drawable instanceof ShapeDrawable) {
        ((ShapeDrawable) drawable).getPaint().setColor(color);
    } else if (drawable instanceof GradientDrawable) {
        ((GradientDrawable) drawable).setColor(color);
    } else if (drawable instanceof ColorDrawable) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ((ColorDrawable) drawable).setColor(color);
        }
    } else if (drawable instanceof RotateDrawable) {
        setDrawableColor(context, ((RotateDrawable) drawable).getDrawable(), colorAttrRes);
    }
}
 
Example #12
Source File: BadgeView.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private ShapeDrawable a()
{
    int i1 = a(8);
    float af[] = new float[8];
    af[0] = i1;
    af[1] = i1;
    af[2] = i1;
    af[3] = i1;
    af[4] = i1;
    af[5] = i1;
    af[6] = i1;
    af[7] = i1;
    ShapeDrawable shapedrawable = new ShapeDrawable(new RoundRectShape(af, null, null));
    shapedrawable.getPaint().setColor(n);
    return shapedrawable;
}
 
Example #13
Source File: PaletteGridAdapter.java    From color-picker with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: MaterialProgressDrawable.java    From Elephant with Apache License 2.0 5 votes vote down vote up
private void setUp(final double diameter) {
    PtrLocalDisplay.init(mParent.getContext());
    final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
    final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
    int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}
 
Example #15
Source File: CircleImageView.java    From 365browser with Apache License 2.0 5 votes vote down vote up
ShapeDrawable initializeNonElevated(float radius, float density) {
    final int diameter = (int) (radius * density * 2);
    final int shadowYOffset = (int) (density * Y_OFFSET);
    final int shadowXOffset = (int) (density * X_OFFSET);
    OvalShape oval = new OvalShadow(mShadowRadius, diameter);
    ShapeDrawable circle = new ShapeDrawable(oval);
    setLayerType(View.LAYER_TYPE_SOFTWARE, circle.getPaint());
    circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
            KEY_SHADOW_COLOR);
    final int padding = mShadowRadius;
    // set padding so the inner image sits correctly within the shadow.
    setPadding(padding, padding, padding, padding);
    return circle;
}
 
Example #16
Source File: MyConfig.java    From CalendarPicker with MIT License 5 votes vote down vote up
public static void setDrawableColor(Drawable v, Integer customColor){

        if(customColor != null) {
            if (v instanceof ShapeDrawable) {
                ((ShapeDrawable)v).getPaint().setColor(customColor);
            } else if (v instanceof GradientDrawable) {
                ((GradientDrawable)v).setColor(customColor);
            } else if (v instanceof ColorDrawable) {
                ((ColorDrawable)v).setColor(customColor);
            }
        }
    }
 
Example #17
Source File: LineChartView.java    From line-chart-view with MIT License 5 votes vote down vote up
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 #18
Source File: BadgeView.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private ShapeDrawable getDefaultBackground() {

    int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP);
    float[] outerR = new float[] { r, r, r, r, r, r, r, r };

    RoundRectShape rr = new RoundRectShape(outerR, null, null);
    ShapeDrawable drawable = new ShapeDrawable(rr);
    drawable.getPaint()
        .setColor(badgeColor);

    return drawable;
  }
 
Example #19
Source File: DayView.java    From material-hijri-calendarview with Apache License 2.0 5 votes vote down vote up
private static Drawable generateCircleDrawable(final int color) {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(0, 0, 0, 0, color, color, Shader.TileMode.REPEAT);
        }
    });
    return drawable;
}
 
Example #20
Source File: FloatingActionButton.java    From TvRemoteControl with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: CircleProgressBar.java    From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Update the background color of the mBgCircle image view.
 */
public void setBackgroundColorResource(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }
}
 
Example #22
Source File: FloatingActionButton.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
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 #23
Source File: FloatingActionButton.java    From TestChat with Apache License 2.0 5 votes vote down vote up
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 #24
Source File: FloatingActionButton.java    From TestChat with Apache License 2.0 5 votes vote down vote up
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 #25
Source File: ViewHelper.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@NonNull private static Drawable getRippleMask(int color) {
    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, 3);
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example #26
Source File: ExpandableElementUtil.java    From litho with Apache License 2.0 5 votes vote down vote up
static ShapeDrawable getMessageBackground(ComponentContext c, int color) {
  final RoundRectShape roundedRectShape =
      new RoundRectShape(
          new float[] {40, 40, 40, 40, 40, 40, 40, 40},
          null,
          new float[] {40, 40, 40, 40, 40, 40, 40, 40});
  final ShapeDrawable oval = new ShapeDrawable(roundedRectShape);
  oval.getPaint().setColor(color);
  return oval;
}
 
Example #27
Source File: ShowMessageExampleComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Drawable buildRoundedRect(int radius) {
  final float[] radii = new float[8];
  Arrays.fill(radii, radius);
  final RoundRectShape roundedRectShape = new RoundRectShape(radii, null, radii);
  final ShapeDrawable drawable = new ShapeDrawable(roundedRectShape);
  drawable.getPaint().setColor(Color.RED);
  return drawable;
}
 
Example #28
Source File: DrawableUtils.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
private static Drawable getRippleMask(@ColorInt int color) {
    float[] outerRadii = new float[8];
    // 3 is the radius of final ripple, instead of 3 we can give required final radius
    Arrays.fill(outerRadii, 3);
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}
 
Example #29
Source File: FloatingActionButton.java    From FloatingActionButton with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: MaterialProgressDrawable.java    From JD-Test with Apache License 2.0 5 votes vote down vote up
private void setUp(final double diameter) {
    PtrLocalDisplay.init(mParent.getContext());
    final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET);
    final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET);
    int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS);
    OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter);
    mShadow = new ShapeDrawable(oval);
    if (Build.VERSION.SDK_INT >= 11) {
        mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint());
    }
    mShadow.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
}