android.graphics.drawable.shapes.OvalShape Java Examples

The following examples show how to use android.graphics.drawable.shapes.OvalShape. 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: ProfileImageView.java    From Klyph with MIT License 6 votes vote down vote up
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 #2
Source File: FloatingActionButton.java    From FlowGeek with GNU General Public License v2.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: FloatingActionButton.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private Drawable createDrawable(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);

    if (mShadow) {
        LayerDrawable layerDrawable = new LayerDrawable(
                new Drawable[]{getResources().getDrawable(R.drawable.floating_acition_button_shadow),
                        shapeDrawable});
        int shadowSize = getDimension(
                mType == TYPE_NORMAL ? R.dimen.fab_shadow_size : R.dimen.fab_mini_shadow_size);
        layerDrawable.setLayerInset(1, shadowSize, shadowSize, shadowSize, shadowSize);
        return layerDrawable;
    } else {
        return shapeDrawable;
    }
}
 
Example #4
Source File: SpringFloatingActionMenu.java    From SpringFloatingActionMenu with Apache License 2.0 6 votes vote down vote up
private View generateRevealCircle() {
    int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL ?
            Utils.getDimension(mContext, R.dimen.fab_size_normal) :
            Utils.getDimension(mContext, R.dimen.fab_size_mini);
    View view = new View(mContext);
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(ContextCompat.getColor(mContext, mRevealColor));
    view.setBackgroundDrawable(shapeDrawable);
    LayoutParams lp = new LayoutParams(diameter, diameter);
    view.setLayoutParams(lp);

    // Make view clickable to avoid clicks on any view located behind the menu
    view.setClickable(true);

    // note it is invisible, but will be visible while  animating
    view.setVisibility(View.INVISIBLE);
    return view;
}
 
Example #5
Source File: CustomEvaluator.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private ShapeHolder createBall(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);
    return shapeHolder;
}
 
Example #6
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 #7
Source File: ColorPickerAdapter.java    From PhotoEditor with MIT License 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 #8
Source File: ActionButton.java    From Android-ActionButton with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a simple circle background to be applied behind the button
 *
 * @param color the main color of the circle
 * @param selectedColor the color to be displayed when button has been clicked
 */
public void setColors(int color, int selectedColor) {
    // create an oval and set it to the main color
    ShapeDrawable normal = new ShapeDrawable(new OvalShape());
    normal.getPaint().setColor(color);

    // create a second oval and set it to selected color
    ShapeDrawable selected = new ShapeDrawable(new OvalShape());
    selected.getPaint().setColor(selectedColor);

    // create a state drawable which displays appropriate drawable according to the
    // current state of the ActionButton
    StateListDrawable back = new StateListDrawable();
    back.addState(new int[] {android.R.attr.state_pressed},
            selected);
    back.addState(new int[] {},
            normal);

    // set the background for this button
    setBackgroundDrawable(back);
}
 
Example #9
Source File: MaterialDrawable.java    From android-PullRefreshLayout with MIT License 6 votes vote down vote up
private void createCircleDrawable() {
        float radius = CIRCLE_DIAMETER / 2;
        final float density = getContext().getResources().getDisplayMetrics().density;
        final int diameter = (int) (radius * density * 2);
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);

        mShadowRadius = (int) (density * SHADOW_RADIUS);

        OvalShape oval = new OvalShadow(mShadowRadius, diameter);
        mCircle = new ShapeDrawable(oval);
//        ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
        mCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
                KEY_SHADOW_COLOR);
        mPadding = (int) mShadowRadius;

        mCircle.getPaint().setColor(Color.WHITE);
    }
 
Example #10
Source File: AnimatorEvents.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private ShapeHolder createBall(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);
    return shapeHolder;
}
 
Example #11
Source File: DotWidget.java    From star-zone-android with Apache License 2.0 6 votes vote down vote up
private ShapeDrawable getDotBackground() {
    ShapeDrawable drawable = null;
    switch (mode) {
        case ROUND_RECT:
            int radius = dip2Pixels(dotRadius);
            float[] outerRect = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };

            RoundRectShape rr = new RoundRectShape(outerRect, null, null);
            drawable = new InnerShapeDrawableWithText(rr, dotText);
            drawable.getPaint().setColor(dotColor);
            break;
        case CIRCLE:
            OvalShape os = new OvalShape();
            drawable = new InnerShapeDrawableWithText(os, dotText);
            drawable.getPaint().setColor(dotColor);
            //                int paddingPixels = dip2Pixels(8);
            //                drawable.setPadding(paddingPixels, paddingPixels, paddingPixels,
            //                        paddingPixels);
            break;
    }

    return drawable;
}
 
Example #12
Source File: BasicAnimationActivity.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 * 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 #13
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 #14
Source File: ColorChooserDialog.java    From Material-Color-Picker with Apache License 2.0 6 votes vote down vote up
@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 #15
Source File: AnimationSeeking.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 #16
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 #17
Source File: DownloadNotificationService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private Bitmap getLargeNotificationIcon(Bitmap bitmap) {
    Resources resources = mContext.getResources();
    int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
    int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);
    final OvalShape circle = new OvalShape();
    circle.resize(width, height);
    final Paint paint = new Paint();
    paint.setColor(ApiCompatibilityUtils.getColor(resources, R.color.google_blue_grey_500));

    final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    circle.draw(canvas, paint);
    float leftOffset = (width - bitmap.getWidth()) / 2f;
    float topOffset = (height - bitmap.getHeight()) / 2f;
    if (leftOffset >= 0 && topOffset >= 0) {
        canvas.drawBitmap(bitmap, leftOffset, topOffset, null);
    } else {
        // Scale down the icon into the notification icon dimensions
        canvas.drawBitmap(bitmap,
                new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
                new Rect(0, 0, width, height),
                null);
    }
    return result;
}
 
Example #18
Source File: FloatingActionButton.java    From android_gisapp with GNU General Public License v3.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 #19
Source File: ImageWindow.java    From ImageWindow with Apache License 2.0 6 votes vote down vote up
private void init() {

        ImageView closeButton = new ImageView(getContext());
        closeButton.setLayoutParams(new RelativeLayout.LayoutParams((int) (mCloseButtonSize), (int) (mCloseButtonSize)));
        StateListDrawable drawable = new StateListDrawable();
        ShapeDrawable shape = new ShapeDrawable(new OvalShape());
        ShapeDrawable shapePressed = new ShapeDrawable(new OvalShape());
        shape.setColorFilter(mCloseColor, PorterDuff.Mode.SRC_ATOP);
        shapePressed.setColorFilter(mCloseColor - 0x444444, PorterDuff.Mode.SRC_ATOP);//a little bit darker
        drawable.addState(new int[]{android.R.attr.state_pressed}, shapePressed);
        drawable.addState(new int[]{}, shape);
        closeButton.setImageResource(mCloseIcon);
        closeButton.setBackground(drawable); //todo change this to support lower api
        closeButton.setClickable(true);
        closeButton.setId(R.id.closeId);
        mImageView = new CustomImageView(getContext(), mCloseButtonSize, mCloseButtonMargin, mCornerRadius);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(Math.round(mTopLeftMargin), Math.round(mTopLeftMargin), 0, 0);
        mImageView.setLayoutParams(params);
        mImageView.setAdjustViewBounds(true);
        addView(mImageView);
        addView(closeButton);
    }
 
Example #20
Source File: VMIndicatorView.java    From VMLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * 创建移动小圆点
 */
private void createMoveItems() {
    OvalShape circle = new OvalShape();
    ShapeDrawable drawable = new ShapeDrawable(circle);
    moveHolder = new VMIndicatorHolder(drawable);

    Paint paint = drawable.getPaint();
    paint.setColor(mIndicatorSelected);
    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;
    default:
        break;
    }

    moveHolder.setPaint(paint);
}
 
Example #21
Source File: OrderDialogFragment.java    From From-design-to-Android-part1 with Apache License 2.0 6 votes vote down vote up
private Drawable createProductImageDrawable(Product product) {
    final ShapeDrawable background = new ShapeDrawable();
    background.setShape(new OvalShape());
    background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

    final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
        BitmapFactory.decodeResource(getResources(), product.image));

    final LayerDrawable layerDrawable = new LayerDrawable
        (new Drawable[]{background, bitmapDrawable});

    final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
    layerDrawable.setLayerInset(1, padding, padding, padding, padding);

    return layerDrawable;
}
 
Example #22
Source File: FloatingActionButton.java    From TvRemoteControl 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 #23
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 #24
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 #25
Source File: MultiPropertyAnimation.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(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 #26
Source File: ColorPreference.java    From ColorPicker with Apache License 2.0 5 votes vote down vote up
private void updateShownColor() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mColorView.setBackground(new ShapeDrawable(new OvalShape()));
        ((ShapeDrawable) mColorView.getBackground()).getPaint().setColor(mCurrentValue);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mColorView.setBackground(new ColorCircleDrawable(mCurrentValue));
    } else {
        mColorView.setBackgroundDrawable(new ColorCircleDrawable(mCurrentValue));
    }
    mColorView.invalidate();
}
 
Example #27
Source File: OrreryDrawable.java    From AnimationApiDemos with Apache License 2.0 5 votes vote down vote up
public static OrreryDrawable Create() {
	ShapeDrawable space = new ShapeDrawable(new RectShape());
	space.getPaint().setColor(Color.BLACK);
	space.setIntrinsicHeight(SPACE_HEIGHT);
	space.setIntrinsicWidth(SPACE_HEIGHT);
	ShapeDrawable sun = new ShapeDrawable(new OvalShape());
	sun.getPaint().setColor(Color.YELLOW);
	sun.setIntrinsicHeight(RADIUS_SUN * 2);
	sun.setIntrinsicWidth(RADIUS_SUN * 2);
	ShapeDrawable earth = new ShapeDrawable(new OvalShape());
	earth.getPaint().setColor(Color.BLUE);
	earth.setIntrinsicHeight(RADIUS_EARTH * 2);
	earth.setIntrinsicWidth(RADIUS_EARTH * 2);
	ShapeDrawable moon = new ShapeDrawable(new OvalShape());
	moon.getPaint().setColor(Color.LTGRAY);
	moon.setIntrinsicHeight(RADIUS_MOON * 2);
	moon.setIntrinsicWidth(RADIUS_MOON * 2);
	Drawable[] bodies = { space, sun, earth, moon };
	OrreryDrawable myOrrery = new OrreryDrawable(bodies);
	myOrrery.setEarthPosition(0);
	myOrrery.setMoonPosition(0);
	myOrrery.setLayerInset(SPACE_ID, 0, 0, 0, 0);
	myOrrery.setLayerInset(SUN_ID, SPACE_HEIGHT / 2 - RADIUS_SUN,
			SPACE_HEIGHT / 2 - RADIUS_SUN, SPACE_HEIGHT / 2 - RADIUS_SUN,
			SPACE_HEIGHT / 2 - RADIUS_SUN);
	return myOrrery;
}
 
Example #28
Source File: CircleButton.java    From vinci with Apache License 2.0 5 votes vote down vote up
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 #29
Source File: TextDrawable.java    From CanPhotos with Apache License 2.0 5 votes vote down vote up
private void drawBorder(Canvas canvas) {
    RectF rect = new RectF(getBounds());
    rect.inset(borderThickness/2, borderThickness/2);

    if (shape instanceof OvalShape) {
        canvas.drawOval(rect, borderPaint);
    }
    else if (shape instanceof RoundRectShape) {
        canvas.drawRoundRect(rect, radius, radius, borderPaint);
    }
    else {
        canvas.drawRect(rect, borderPaint);
    }
}
 
Example #30
Source File: DefaultMarkView.java    From mCalendarView with Apache License 2.0 5 votes vote down vote up
public Dot(Context context, int color) {
    super(context);
    this.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, (float) 1.0));
    View dotView = new View(getContext());
    LayoutParams lp = new RelativeLayout.LayoutParams(10, 10);
    lp.addRule(CENTER_IN_PARENT,TRUE);
    dotView.setLayoutParams(lp);
    ShapeDrawable dot = new ShapeDrawable(new OvalShape());

    dot.getPaint().setColor(color);
    dotView.setBackground(dot);
    this.addView(dotView);
}