android.graphics.drawable.ShapeDrawable

Here are the examples of the java api class android.graphics.drawable.ShapeDrawable taken from open source projects.

1. SUtils#createButtonShape()

Project: SublimePicker
File: SUtils.java
// Base button shape
private static Drawable createButtonShape(Context context, int color) {
    // Translation of Lollipop's xml button-bg definition to Java
    int paddingH = context.getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
    int paddingV = context.getResources().getDimensionPixelSize(R.dimen.button_padding_vertical_material);
    int insetH = context.getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
    int insetV = context.getResources().getDimensionPixelSize(R.dimen.button_inset_vertical_material);
    float[] outerRadii = new float[8];
    Arrays.fill(outerRadii, CORNER_RADIUS);
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);
    return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV);
}

2. DetailActivity#colorButton()

Project: google-io-2014-compat
File: DetailActivity.java
@Override
public void colorButton(int id, int bgColor, int tintColor) {
    ImageButton buttonView = (ImageButton) findViewById(id);
    StateListDrawable bg = new StateListDrawable();
    ShapeDrawable normal = new ShapeDrawable(new OvalShape());
    normal.getPaint().setColor(bgColor);
    ShapeDrawable pressed = new ShapeDrawable(new OvalShape());
    pressed.getPaint().setColor(tintColor);
    bg.addState(new int[] { android.R.attr.state_pressed }, pressed);
    bg.addState(new int[] {}, normal);
    Utils.setBackgroundCompat(buttonView, bg);
}

3. ShareMenuButtonFactory#get()

Project: actor-platform
File: ShareMenuButtonFactory.java
public static StateListDrawable get(int color, Context context) {
    ShapeDrawable bg = new ShapeDrawable(new OvalShape());
    int padding = Screen.dp(5);
    bg.getPaint().setColor(color);
    ShapeDrawable bgPressed = new ShapeDrawable(new OvalShape());
    bgPressed.getPaint().setColor(ActorStyle.getDarkenArgb(color, 0.95));
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_pressed }, new InsetDrawable(bgPressed, padding));
    states.addState(StateSet.WILD_CARD, new InsetDrawable(bg, padding));
    return states;
}

4. FloatingActionButton#createDrawable()

Project: UltimateAndroid
File: FloatingActionButton.java
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;
    }
}

5. FloatingActionButton#createDrawable()

Project: UltimateAndroid
File: FloatingActionButton.java
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;
    }
}

6. SwipeNumberPicker#createBackgroundDrawable()

Project: SwipeNumberPicker
File: SwipeNumberPicker.java
private Drawable createBackgroundDrawable(int color) {
    ShapeDrawable backgroundDrawable = new ShapeDrawable(new RoundRectShape(new float[] { mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius, mCornerRadius }, null, null));
    final Paint paint = backgroundDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setColor(color);
    paint.setStrokeWidth(mStrokeWidth);
    Drawable[] layers = { backgroundDrawable };
    LayerDrawable drawable = new LayerDrawable(layers);
    int halfStrokeWidth = (int) (mStrokeWidth / 2f);
    drawable.setLayerInset(0, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
    return drawable;
}

7. SUtils#createBgDrawable()

Project: SublimePicker
File: SUtils.java
// Creates a drawable with the supplied color and corner radii
public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight, int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;
    RoundRectShape r = new RoundRectShape(outerRadii, null, null);
    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

8. SpringFloatingActionMenu#generateRevealCircle()

Project: SpringFloatingActionMenu
File: SpringFloatingActionMenu.java
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;
}

9. BadgeView#getDefaultBackground()

Project: serenity-android
File: BadgeView.java
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;
}

10. BadgeView#getDefaultBackground()

Project: RefreshActionItem
File: BadgeView.java
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;
}

11. BadgeView#getDefaultBackground()

Project: RefreshActionItem
File: BadgeView.java
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;
}

12. MaterialDrawable#createCircleDrawable()

Project: MaterialQQLite
File: MaterialDrawable.java
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);
}

13. PagerIndicator#destroySelf()

Project: LoyalNativeSlider
File: PagerIndicator.java
/**
     * clear self means unregister the dataset observer and remove all the child views(indicators).
     */
public void destroySelf() {
    if (mPager == null || mPager.getAdapter() == null) {
        return;
    }
    InfinitePagerAdapter wrapper = (InfinitePagerAdapter) mPager.getAdapter();
    PagerAdapter adapter = wrapper.getRealAdapter();
    if (adapter != null) {
        adapter.unregisterDataSetObserver(dataChangeObserver);
    }
    removeAllViews();
    ShapeDrawable shapeDrawable;
}

14. FloatingActionButton#createDrawable()

Project: FloatingActionButton
File: FloatingActionButton.java
private Drawable createDrawable(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);
    if (mShadow && !hasLollipopApi()) {
        Drawable shadowDrawable = getResources().getDrawable(mType == TYPE_NORMAL ? R.drawable.fab_shadow : R.drawable.fab_shadow_mini);
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { shadowDrawable, shapeDrawable });
        layerDrawable.setLayerInset(1, mShadowSize, mShadowSize, mShadowSize, mShadowSize);
        return layerDrawable;
    } else {
        return shapeDrawable;
    }
}

15. MonthView#createCircle()

Project: DatePicker
File: MonthView.java
private BGCircle createCircle(float x, float y) {
    OvalShape circle = new OvalShape();
    circle.resize(0, 0);
    ShapeDrawable drawable = new ShapeDrawable(circle);
    BGCircle circle1 = new BGCircle(drawable);
    circle1.setX(x);
    circle1.setY(y);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        circle1.setRadius(circleRadius);
    }
    drawable.getPaint().setColor(mTManager.colorBGCircle());
    return circle1;
}

16. MaterialProgressDrawable#setUp()

Project: CommonPullToRefresh
File: MaterialProgressDrawable.java
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);
}

17. MaterialProgressDrawable#setUp()

Project: CommonPullToRefresh
File: MaterialProgressDrawable.java
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);
}

18. BadgeView#getDefaultBackground()

Project: android-viewbadger
File: BadgeView.java
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;
}

19. MaterialProgressDrawable#setUp()

Project: android-Ultra-Pull-To-Refresh
File: MaterialProgressDrawable.java
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);
}

20. MaterialDrawable#createCircleDrawable()

Project: android-PullRefreshLayout
File: MaterialDrawable.java
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);
}

21. FloatingActionButton#createOuterStrokeDrawable()

Project: android-floating-action-button
File: FloatingActionButton.java
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;
}

22. FloatingActionButton#createCircleDrawable()

Project: android-floating-action-button
File: FloatingActionButton.java
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;
}

23. ShapeDrawActivity#onCreate()

Project: coursera-android
File: ShapeDrawActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    int width = (int) getResources().getDimension(R.dimen.image_width);
    int height = (int) getResources().getDimension(R.dimen.image_height);
    int padding = (int) getResources().getDimension(R.dimen.padding);
    // Get container View
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.main_window);
    // Create Cyan Shape
    ShapeDrawable cyanShape = new ShapeDrawable(new OvalShape());
    cyanShape.getPaint().setColor(Color.CYAN);
    cyanShape.setIntrinsicHeight(height);
    cyanShape.setIntrinsicWidth(width);
    cyanShape.setAlpha(alpha);
    // Put Cyan Shape into an ImageView
    ImageView cyanView = new ImageView(getApplicationContext());
    cyanView.setImageDrawable(cyanShape);
    cyanView.setPadding(padding, padding, padding, padding);
    // Specify placement of ImageView within RelativeLayout
    RelativeLayout.LayoutParams cyanViewLayoutParams = new RelativeLayout.LayoutParams(height, width);
    cyanViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
    cyanViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    cyanView.setLayoutParams(cyanViewLayoutParams);
    rl.addView(cyanView);
    // Create Magenta Shape
    ShapeDrawable magentaShape = new ShapeDrawable(new OvalShape());
    magentaShape.getPaint().setColor(Color.MAGENTA);
    magentaShape.setIntrinsicHeight(height);
    magentaShape.setIntrinsicWidth(width);
    magentaShape.setAlpha(alpha);
    // Put Magenta Shape into an ImageView
    ImageView magentaView = new ImageView(getApplicationContext());
    magentaView.setImageDrawable(magentaShape);
    magentaView.setPadding(padding, padding, padding, padding);
    // Specify placement of ImageView within RelativeLayout
    RelativeLayout.LayoutParams magentaViewLayoutParams = new RelativeLayout.LayoutParams(height, width);
    magentaViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
    magentaViewLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    magentaView.setLayoutParams(magentaViewLayoutParams);
    rl.addView(magentaView);
}

24. Indicator#newOne()

Project: SwipeSelector
File: Indicator.java
/**
     * Creates a new ShapeDrawable, in this case a circle.
     * @param size the width and height for the circle
     * @param color the color resource for the circle
     * @return a nice and adorable tiny little circle indicator.
     */
protected static ShapeDrawable newOne(int size, int color) {
    ShapeDrawable indicator = new ShapeDrawable(new OvalShape());
    indicator.setIntrinsicWidth(size);
    indicator.setIntrinsicHeight(size);
    indicator.getPaint().setColor(color);
    return indicator;
}

25. OtherTaskFragment#createRectShape()

Project: Conquer
File: OtherTaskFragment.java
private static ShapeDrawable createRectShape(int width, int height, int color) {
    ShapeDrawable shape = new ShapeDrawable(new RectShape());
    shape.setIntrinsicHeight(height);
    shape.setIntrinsicWidth(width);
    shape.getPaint().setColor(color);
    return shape;
}

26. BadgeCircle#make()

Project: BottomBar
File: BadgeCircle.java
/**
     * Creates a new circle for the Badge background.
     *
     * @param size  the width and height for the circle
     * @param color the color for the circle
     * @return a nice and adorable circle.
     */
protected static ShapeDrawable make(int size, int color) {
    ShapeDrawable indicator = new ShapeDrawable(new OvalShape());
    indicator.setIntrinsicWidth(size);
    indicator.setIntrinsicHeight(size);
    indicator.getPaint().setColor(color);
    return indicator;
}

27. DefaultClusterRenderer#makeClusterBackground()

Project: wigle-wifi-wardriving
File: DefaultClusterRenderer.java
private LayerDrawable makeClusterBackground() {
    mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    // Transparent white.
    outline.getPaint().setColor(0x80ffffff);
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
    int strokeWidth = (int) (mDensity * 3);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

28. TwitterStaticNativeAd#setCardStyling()

Project: twitter-kit-android
File: TwitterStaticNativeAd.java
private void setCardStyling() {
    final boolean isLightBg = ColorUtils.isLightColor(containerBackgroundColor);
    if (isLightBg) {
        cardBorderColor = getResources().getColor(R.color.tw__ad_light_card_border_color);
    } else {
        cardBorderColor = getResources().getColor(R.color.tw__ad_dark_card_border_color);
    }
    final ShapeDrawable bgDrawable = new ShapeDrawable(new RectShape());
    bgDrawable.getPaint().setColor(cardBackgroundColor);
    final ShapeDrawable borderDrawable = new ShapeDrawable(new RectShape());
    borderDrawable.getPaint().setColor(cardBorderColor);
    final Drawable[] layers = new Drawable[2];
    layers[0] = borderDrawable;
    layers[1] = bgDrawable;
    final LayerDrawable layerDrawable = new LayerDrawable(layers);
    layerDrawable.setLayerInset(0, 0, 0, 0, 0);
    layerDrawable.setLayerInset(1, 1, 0, 1, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        cardLayout.setBackground(layerDrawable);
    } else {
        cardLayout.setBackgroundDrawable(layerDrawable);
    }
}

29. ColorChooserDialog#createSelector()

Project: MaterialQQLite
File: ColorChooserDialog.java
private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}

30. CustomBorderDrawable#customButton()

Project: astrid
File: CustomBorderDrawable.java
public static StateListDrawable customButton(int tl, int tr, int br, int bl, int onColor, int offColor, int borderColor, int strokeWidth) {
    Shape shape = new RoundRectShape(new float[] { tl, tl, tr, tr, br, br, bl, bl }, null, null);
    ShapeDrawable sdOn = new CustomBorderDrawable(shape, onColor, borderColor, strokeWidth);
    ShapeDrawable sdOff = new CustomBorderDrawable(shape, offColor, borderColor, strokeWidth);
    StateListDrawable stld = new StateListDrawable();
    stld.addState(new int[] { android.R.attr.state_pressed }, sdOn);
    stld.addState(new int[] { android.R.attr.state_checked }, sdOn);
    stld.addState(new int[] { android.R.attr.state_enabled }, sdOff);
    return stld;
}

31. ColorChooseDialog#createSelector()

Project: AppPlus
File: ColorChooseDialog.java
private Drawable createSelector(int color) {
    ShapeDrawable coloredCircle = new ShapeDrawable(new OvalShape());
    coloredCircle.getPaint().setColor(color);
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(shiftColor(color));
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { -android.R.attr.state_pressed }, coloredCircle);
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}

32. DefaultClusterRenderer#makeClusterBackground()

Project: android-maps-utils
File: DefaultClusterRenderer.java
private LayerDrawable makeClusterBackground() {
    mColoredCircleBackground = new ShapeDrawable(new OvalShape());
    ShapeDrawable outline = new ShapeDrawable(new OvalShape());
    // Transparent white.
    outline.getPaint().setColor(0x80ffffff);
    LayerDrawable background = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
    int strokeWidth = (int) (mDensity * 3);
    background.setLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
    return background;
}

33. FloatingActionButton#createInnerStrokesDrawable()

Project: android-floating-action-button
File: FloatingActionButton.java
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;
}

34. FButton#createDrawable()

Project: android-flat-button
File: FButton.java
private LayerDrawable createDrawable(int radius, int topColor, int bottomColor) {
    float[] outerRadius = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };
    //Top
    RoundRectShape topRoundRect = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable topShapeDrawable = new ShapeDrawable(topRoundRect);
    topShapeDrawable.getPaint().setColor(topColor);
    //Bottom
    RoundRectShape roundRectShape = new RoundRectShape(outerRadius, null, null);
    ShapeDrawable bottomShapeDrawable = new ShapeDrawable(roundRectShape);
    bottomShapeDrawable.getPaint().setColor(bottomColor);
    //Create array
    Drawable[] drawArray = { bottomShapeDrawable, topShapeDrawable };
    LayerDrawable layerDrawable = new LayerDrawable(drawArray);
    //Set shadow height
    if (isShadowEnabled && topColor != Color.TRANSPARENT) {
        //unpressed drawable
        layerDrawable.setLayerInset(0, 0, 0, 0, 0);
    /*index, left, top, right, bottom*/
    } else {
        //pressed drawable
        layerDrawable.setLayerInset(0, 0, mShadowHeight, 0, 0);
    /*index, left, top, right, bottom*/
    }
    layerDrawable.setLayerInset(1, 0, 0, 0, mShadowHeight);
    return layerDrawable;
}

35. WheelView#createOvalDrawable()

Project: WheelView
File: WheelView.java
private Drawable createOvalDrawable(int color) {
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

36. AddFloatingActionButton#getIconDrawable()

Project: UltimateRecyclerView
File: AddFloatingActionButton.java
/**
     * generate the PLUS sign
     *
     * @return the drawable product
     */
@Override
protected Drawable getIconDrawable() {
    final float iconSize = getDimension(R.dimen.fab_icon_size);
    final float iconHalfSize = iconSize / 2f;
    final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
    final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
    final float plusOffset = (iconSize - plusSize) / 2f;
    final Shape shape = new Shape() {

        @Override
        public void draw(Canvas canvas, Paint paint) {
            canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
            canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
        }
    };
    ShapeDrawable drawable = new ShapeDrawable(shape);
    final Paint paint = drawable.getPaint();
    paint.setColor(mPlusColor);
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    return drawable;
}

37. AddFloatingActionButton#getIconDrawable()

Project: UltimateAndroid
File: AddFloatingActionButton.java
@Override
Drawable getIconDrawable() {
    final float iconSize = getDimension(R.dimen.fab_icon_size);
    final float iconHalfSize = iconSize / 2f;
    final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
    final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
    final float plusOffset = (iconSize - plusSize) / 2f;
    final Shape shape = new Shape() {

        @Override
        public void draw(Canvas canvas, Paint paint) {
            canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
            canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
        }
    };
    ShapeDrawable drawable = new ShapeDrawable(shape);
    final Paint paint = drawable.getPaint();
    paint.setColor(mPlusColor);
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    return drawable;
}

38. ProgressbarWheelActivity#onCreate()

Project: UltimateAndroid
File: ProgressbarWheelActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress_wheel_activity);
    pw_two = (ProgressWheel) findViewById(R.id.progressBarTwo);
    pw_three = (ProgressWheel) findViewById(R.id.progressBarThree);
    pw_four = (ProgressWheel) findViewById(R.id.progressBarFour);
    //pw_five = (ProgressWheel) findViewById(R.id.progressBarFive);
    ShapeDrawable bg = new ShapeDrawable(new RectShape());
    int[] pixels = new int[] { 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFFFF, 0xFFFFFFFF };
    Bitmap bm = Bitmap.createBitmap(pixels, 8, 1, Bitmap.Config.ARGB_8888);
    Shader shader = new BitmapShader(bm, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    pw_three.setRimShader(shader);
    pw_three.spin();
    pw_four.spin();
    final Runnable r = new Runnable() {

        public void run() {
            running = true;
            while (progress < 361) {
                pw_two.incrementProgress();
                progress++;
                try {
                    Thread.sleep(15);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            running = false;
        }
    };
    Button spin = (Button) findViewById(R.id.btn_spin);
    spin.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                if (pw_two.isSpinning) {
                    pw_two.stopSpinning();
                }
                pw_two.resetCount();
                pw_two.setText("Loading...");
                pw_two.spin();
            }
        }
    });
    Button increment = (Button) findViewById(R.id.btn_increment);
    increment.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                progress = 0;
                pw_two.resetCount();
                Thread s = new Thread(r);
                s.start();
            }
        }
    });
}

39. AddFloatingActionButton#getIconDrawable()

Project: UltimateAndroid
File: AddFloatingActionButton.java
@Override
Drawable getIconDrawable() {
    final float iconSize = getDimension(R.dimen.fab_icon_size);
    final float iconHalfSize = iconSize / 2f;
    final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
    final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
    final float plusOffset = (iconSize - plusSize) / 2f;
    final Shape shape = new Shape() {

        @Override
        public void draw(Canvas canvas, Paint paint) {
            canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
            canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
        }
    };
    ShapeDrawable drawable = new ShapeDrawable(shape);
    final Paint paint = drawable.getPaint();
    paint.setColor(mPlusColor);
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    return drawable;
}

40. ProgressbarWheelActivity#onCreate()

Project: UltimateAndroid
File: ProgressbarWheelActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress_wheel_activity);
    pw_two = (ProgressWheel) findViewById(R.id.progressBarTwo);
    pw_three = (ProgressWheel) findViewById(R.id.progressBarThree);
    pw_four = (ProgressWheel) findViewById(R.id.progressBarFour);
    //pw_five = (ProgressWheel) findViewById(R.id.progressBarFive);
    ShapeDrawable bg = new ShapeDrawable(new RectShape());
    int[] pixels = new int[] { 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFFFF, 0xFFFFFFFF };
    Bitmap bm = Bitmap.createBitmap(pixels, 8, 1, Bitmap.Config.ARGB_8888);
    Shader shader = new BitmapShader(bm, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    pw_three.setRimShader(shader);
    pw_three.spin();
    pw_four.spin();
    final Runnable r = new Runnable() {

        public void run() {
            running = true;
            while (progress < 361) {
                pw_two.incrementProgress();
                progress++;
                try {
                    Thread.sleep(15);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            running = false;
        }
    };
    Button spin = (Button) findViewById(R.id.btn_spin);
    spin.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                if (pw_two.isSpinning) {
                    pw_two.stopSpinning();
                }
                pw_two.resetCount();
                pw_two.setText("Loading...");
                pw_two.spin();
            }
        }
    });
    Button increment = (Button) findViewById(R.id.btn_increment);
    increment.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                progress = 0;
                pw_two.resetCount();
                Thread s = new Thread(r);
                s.start();
            }
        }
    });
}

41. SUtils#createImageViewShape()

Project: SublimePicker
File: SUtils.java
// Base icon bg shape
private static Drawable createImageViewShape(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

42. MenuItemView#init()

Project: SpringFloatingActionMenu
File: MenuItemView.java
private void init(Context context) {
    Resources resources = getResources();
    int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
    this.mDiameter = diameterPX;
    mBtn = new ImageButton(context);
    LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX);
    btnLp.gravity = Gravity.CENTER_HORIZONTAL;
    btnLp.bottomMargin = Util.dpToPx(mGapSize, resources);
    mBtn.setLayoutParams(btnLp);
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor()));
    mBtn.setBackgroundDrawable(shapeDrawable);
    mBtn.setImageResource(mMenuItem.getIcon());
    mBtn.setClickable(false);
    addView(mBtn);
    mLabel = new TextView(context);
    LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelLp.gravity = Gravity.CENTER_HORIZONTAL;
    mLabel.setLayoutParams(labelLp);
    mLabel.setText(mMenuItem.getLabel());
    mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor()));
    mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
    addView(mLabel);
    setOrientation(LinearLayout.VERTICAL);
    if (mAlphaAnimation) {
        setAlpha(0);
    }
    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            getViewTreeObserver().removeGlobalOnLayoutListener(this);
            applyPressAnimation();
            ViewGroup parent = (ViewGroup) getParent();
            parent.setClipChildren(false);
            parent.setClipToPadding(false);
            setClipChildren(false);
            setClipToPadding(false);
        }
    });
}

43. ShapeDrawableTest#getPaint_ShouldReturnTheSamePaint()

Project: robolectric
File: ShapeDrawableTest.java
@Test
public void getPaint_ShouldReturnTheSamePaint() throws Exception {
    ShapeDrawable shapeDrawable = new ShapeDrawable();
    Paint paint = shapeDrawable.getPaint();
    assertNotNull(paint);
    assertThat(shapeDrawable.getPaint(), is(paint));
}

44. WheelView#createOvalDrawable()

Project: nx-remote-controller-mod
File: WheelView.java
private Drawable createOvalDrawable(int color) {
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    shapeDrawable.getPaint().setColor(color);
    return shapeDrawable;
}

45. PlayTransition#createAnimator()

Project: Muzesto
File: PlayTransition.java
@Override
public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) {
    if (startValues == null || endValues == null) {
        return null;
    }
    Rect startBounds = (Rect) startValues.values.get(PROPERTY_BOUNDS);
    Rect endBounds = (Rect) endValues.values.get(PROPERTY_BOUNDS);
    if (startBounds == null || endBounds == null || startBounds.equals(endBounds)) {
        return null;
    }
    Bitmap startImage = (Bitmap) startValues.values.get(PROPERTY_IMAGE);
    Drawable startBackground = new BitmapDrawable(sceneRoot.getContext().getResources(), startImage);
    final View startView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), startBackground);
    Drawable shrinkingBackground = new ColorDrawable(mColor);
    final View shrinkingView = addViewToOverlay(sceneRoot, startImage.getWidth(), startImage.getHeight(), shrinkingBackground);
    int[] sceneRootLoc = new int[2];
    sceneRoot.getLocationInWindow(sceneRootLoc);
    int[] startLoc = (int[]) startValues.values.get(PROPERTY_POSITION);
    int startTranslationX = startLoc[0] - sceneRootLoc[0];
    int startTranslationY = startLoc[1] - sceneRootLoc[1];
    startView.setTranslationX(startTranslationX);
    startView.setTranslationY(startTranslationY);
    shrinkingView.setTranslationX(startTranslationX);
    shrinkingView.setTranslationY(startTranslationY);
    final View endView = endValues.view;
    float startRadius = calculateMaxRadius(shrinkingView);
    int minRadius = Math.min(calculateMinRadius(shrinkingView), calculateMinRadius(endView));
    ShapeDrawable circleBackground = new ShapeDrawable(new OvalShape());
    circleBackground.getPaint().setColor(mColor);
    final View circleView = addViewToOverlay(sceneRoot, minRadius * 2, minRadius * 2, circleBackground);
    float circleStartX = startLoc[0] - sceneRootLoc[0] + ((startView.getWidth() - circleView.getWidth()) / 2);
    float circleStartY = startLoc[1] - sceneRootLoc[1] + ((startView.getHeight() - circleView.getHeight()) / 2);
    circleView.setTranslationX(circleStartX);
    circleView.setTranslationY(circleStartY);
    circleView.setVisibility(View.INVISIBLE);
    shrinkingView.setAlpha(0f);
    endView.setAlpha(0f);
    Animator shrinkingAnimator = createCircularReveal(shrinkingView, startRadius, minRadius);
    shrinkingAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            shrinkingView.setVisibility(View.INVISIBLE);
            startView.setVisibility(View.INVISIBLE);
            circleView.setVisibility(View.VISIBLE);
        }
    });
    Animator startAnimator = createCircularReveal(startView, startRadius, minRadius);
    Animator fadeInAnimator = ObjectAnimator.ofFloat(shrinkingView, View.ALPHA, 0, 1);
    AnimatorSet shrinkFadeSet = new AnimatorSet();
    shrinkFadeSet.playTogether(shrinkingAnimator, startAnimator, fadeInAnimator);
    int[] endLoc = (int[]) endValues.values.get(PROPERTY_POSITION);
    float circleEndX = endLoc[0] - sceneRootLoc[0] + ((endView.getWidth() - circleView.getWidth()) / 2);
    float circleEndY = endLoc[1] - sceneRootLoc[1] + ((endView.getHeight() - circleView.getHeight()) / 2);
    Path circlePath = getPathMotion().getPath(circleStartX, circleStartY, circleEndX, circleEndY);
    Animator circleAnimator = ObjectAnimator.ofFloat(circleView, View.TRANSLATION_X, View.TRANSLATION_Y, circlePath);
    final View growingView = addViewToOverlay(sceneRoot, endView.getWidth(), endView.getHeight(), shrinkingBackground);
    growingView.setVisibility(View.INVISIBLE);
    float endTranslationX = endLoc[0] - sceneRootLoc[0];
    float endTranslationY = endLoc[1] - sceneRootLoc[1];
    growingView.setTranslationX(endTranslationX);
    growingView.setTranslationY(endTranslationY);
    float endRadius = calculateMaxRadius(endView);
    circleAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            circleView.setVisibility(View.INVISIBLE);
            growingView.setVisibility(View.VISIBLE);
            endView.setAlpha(1f);
        }
    });
    Animator fadeOutAnimator = ObjectAnimator.ofFloat(growingView, View.ALPHA, 1, 0);
    Animator endAnimator = createCircularReveal(endView, minRadius, endRadius);
    Animator growingAnimator = createCircularReveal(growingView, minRadius, endRadius);
    growingAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            sceneRoot.getOverlay().remove(startView);
            sceneRoot.getOverlay().remove(shrinkingView);
            sceneRoot.getOverlay().remove(circleView);
            sceneRoot.getOverlay().remove(growingView);
        }
    });
    AnimatorSet growingFadeSet = new AnimatorSet();
    growingFadeSet.playTogether(fadeOutAnimator, endAnimator, growingAnimator);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playSequentially(shrinkFadeSet, circleAnimator, growingFadeSet);
    return animatorSet;
}

46. MetaballMenu#createBackgroundShape()

Project: MetaballMenu
File: MetaballMenu.java
/**
     * Create the background shape / Layer -List programmatically. TO have the shadow effect, we need
     * shapes placed on top of the other with varying Alphas and with an inset, to give an illusion of elevation
     * An xml can also be provided to do this statically (included: menu_shape_shadow)
     * The shape stack (starting from bottom) is: Shape1, Shape2, Shape3, foreground
     *
     * @author Melvin Lobo
     */
private Drawable createBackgroundShape() {
    //The radius array to draw the round rect shape. Each pair is for one corner
    float[] radiiFloat = new float[] { mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius, mfBackgroundShapeRadius };
    Drawable backgroundDrawable = null;
    //Foreground Shape
    RoundRectShape foregroundRect = new RoundRectShape(radiiFloat, null, null);
    ShapeDrawable foregroundShape = new ShapeDrawable(foregroundRect);
    foregroundShape.getPaint().setColor(mnBackgroundColor);
    if (mbElevationRequired) {
        //First Shape
        RoundRectShape rect1 = new RoundRectShape(radiiFloat, null, null);
        ShapeDrawable shape1 = new ShapeDrawable(rect1);
        shape1.getPaint().setColor(Color.parseColor(SHAPE_1_COLOR));
        //Second Shape
        RoundRectShape rect2 = new RoundRectShape(radiiFloat, null, null);
        ShapeDrawable shape2 = new ShapeDrawable(rect2);
        shape2.getPaint().setColor(Color.parseColor(SHAPE_2_COLOR));
        //Third Shape
        RoundRectShape rect3 = new RoundRectShape(radiiFloat, null, null);
        ShapeDrawable shape3 = new ShapeDrawable(rect3);
        shape3.getPaint().setColor(Color.parseColor(SHAPE_3_COLOR));
        //Fourth Shape
        RoundRectShape rect4 = new RoundRectShape(radiiFloat, null, null);
        ShapeDrawable shape4 = new ShapeDrawable(rect4);
        shape4.getPaint().setColor(Color.parseColor(SHAPE_2_COLOR));
        //Create an array of shapes for the layer list
        Drawable[] layerArray = { shape1, shape2, shape3, shape4, foregroundShape };
        LayerDrawable drawable = new LayerDrawable(layerArray);
        //Set the insets to get the elevates shadow effect (refer to the menu_shape_xml for better understanding)
        drawable.setLayerInset(0, 0, 0, 0, 0);
        drawable.setLayerInset(1, (int) d2x(1), (int) d2x(1), (int) d2x(1), (int) d2x(1));
        drawable.setLayerInset(2, (int) d2x(2), (int) d2x(2), (int) d2x(2), (int) d2x(2));
        drawable.setLayerInset(3, (int) d2x(3), (int) d2x(3), (int) d2x(3), (int) d2x(3));
        drawable.setLayerInset(4, (int) d2x(2), (int) d2x(2), (int) d2x(2), (int) d2x(4));
        backgroundDrawable = drawable;
    } else {
        backgroundDrawable = foregroundShape;
    }
    return backgroundDrawable;
}

47. CircleView#createSelector()

Project: material-dialogs
File: CircleView.java
private Drawable createSelector(int color) {
    ShapeDrawable darkerCircle = new ShapeDrawable(new OvalShape());
    darkerCircle.getPaint().setColor(translucentColor(shiftColorUp(color)));
    StateListDrawable stateListDrawable = new StateListDrawable();
    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, darkerCircle);
    return stateListDrawable;
}

48. DayView#generateCircleDrawable()

Project: material-calendarview
File: DayView.java
private static Drawable generateCircleDrawable(final int color) {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(color);
    return drawable;
}

49. CircularContactView#drawContent()

Project: ListViewVariants
File: CircularContactView.java
@SuppressWarnings("deprecation")
private void drawContent(final int viewWidth, final int viewHeight) {
    ShapeDrawable roundedBackgroundDrawable = null;
    if (mBackgroundColor != 0) {
        roundedBackgroundDrawable = new ShapeDrawable(new OvalShape());
        roundedBackgroundDrawable.getPaint().setColor(mBackgroundColor);
        roundedBackgroundDrawable.setIntrinsicHeight(viewHeight);
        roundedBackgroundDrawable.setIntrinsicWidth(viewWidth);
        roundedBackgroundDrawable.setBounds(new Rect(0, 0, viewWidth, viewHeight));
    }
    if (mImageResId != 0) {
        mImageView.setBackgroundDrawable(roundedBackgroundDrawable);
        mImageView.setImageResource(mImageResId);
        mImageView.setScaleType(ScaleType.CENTER_INSIDE);
    } else if (mText != null) {
        mTextView.setText(mText);
        mTextView.setBackgroundDrawable(roundedBackgroundDrawable);
        mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewHeight / 2);
    } else if (mBitmap != null) {
        mImageView.setScaleType(ScaleType.FIT_CENTER);
        mImageView.setBackgroundDrawable(roundedBackgroundDrawable);
        if (mBitmap.getWidth() != mBitmap.getHeight())
            mBitmap = ThumbnailUtils.extractThumbnail(mBitmap, viewWidth, viewHeight);
        final RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), mBitmap);
        roundedBitmapDrawable.setCornerRadius((mBitmap.getWidth() + mBitmap.getHeight()) / 4);
        mImageView.setImageDrawable(roundedBitmapDrawable);
    }
    resetValuesState(false);
}

50. FloatActionButton#init()

Project: Genius-Android
File: FloatActionButton.java
private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    if (attrs == null)
        return;
    final Context context = getContext();
    final Resources resource = getResources();
    // Load attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatActionButton, defStyleAttr, defStyleRes);
    ColorStateList bgColor = a.getColorStateList(R.styleable.FloatActionButton_gBackgroundColor);
    int touchColor = a.getColor(R.styleable.FloatActionButton_gTouchColor, Ui.TOUCH_PRESS_COLOR);
    a.recycle();
    // Enable
    boolean enable = Ui.isTrueFromAttribute(attrs, "enabled", true);
    setEnabled(enable);
    // BackgroundColor
    if (bgColor == null) {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                bgColor = resource.getColorStateList(R.color.g_default_float_action_bg, null);
            } else {
                //noinspection deprecation
                bgColor = resource.getColorStateList(R.color.g_default_float_action_bg);
            }
        } catch (Resources.NotFoundException ignored) {
        }
    }
    // Background drawable
    final float density = resource.getDisplayMetrics().density;
    final int shadowYOffset = (int) (density * Ui.Y_OFFSET);
    final int shadowXOffset = (int) (density * Ui.X_OFFSET);
    final int maxShadowOffset = Math.max(shadowXOffset, shadowYOffset);
    mShadowRadius = (int) (density * Ui.SHADOW_RADIUS);
    mShadowRadius += maxShadowOffset;
    ShapeDrawable background;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        background = new ShapeDrawable(new OvalShape());
        //ViewCompat.setElevation(this, Ui.SHADOW_ELEVATION * density);
        setElevation(Ui.SHADOW_ELEVATION * density);
    } else {
        Shape oval = new OvalShadowShape(mShadowRadius);
        background = new ShapeDrawable(oval);
        // We want set this LayerType type on Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
        setLayerType(LAYER_TYPE_SOFTWARE, background.getPaint());
        if (!isInEditMode()) {
            background.getPaint().setShadowLayer(mShadowRadius - maxShadowOffset, shadowXOffset, shadowYOffset, Ui.KEY_SHADOW_COLOR);
        }
        final int padding = mShadowRadius;
        // set padding so the inner image sits correctly within the shadow.
        setPadding(Math.max(padding, getPaddingLeft()), Math.max(padding, getPaddingTop()), Math.max(padding, getPaddingRight()), Math.max(padding, getPaddingBottom()));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackground(background);
    } else {
        //noinspection deprecation
        setBackgroundDrawable(background);
    }
    setBackgroundColor(bgColor);
    // TouchDrawable
    mTouchDrawable = new TouchEffectDrawable(new FloatEffect(), ColorStateList.valueOf(touchColor));
    mTouchDrawable.setCallback(this);
}

51. DrawableUtils#getRippleMask()

Project: FlexibleAdapter
File: DrawableUtils.java
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;
}

52. BaseToggleSwitch#setColors()

Project: Android-Toggle-Switch
File: BaseToggleSwitch.java
protected void setColors(ToggleSwitchButton toggleSwitchButton, int bgColor, int textColor) {
    ShapeDrawable sd = new ShapeDrawable(buildRect(toggleSwitchButton));
    sd.getPaint().setColor(bgColor);
    toggleSwitchButton.getView().setBackground(sd);
    toggleSwitchButton.getTextView().setTextColor(textColor);
}

53. MainActivity#onCreate()

Project: android-floating-action-button
File: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.pink_icon).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "Clicked pink Floating Action Button", Toast.LENGTH_SHORT).show();
        }
    });
    FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
    button.setSize(FloatingActionButton.SIZE_MINI);
    button.setColorNormalResId(R.color.pink);
    button.setColorPressedResId(R.color.pink_pressed);
    button.setIcon(R.drawable.ic_fab_star);
    button.setStrokeVisible(false);
    final View actionB = findViewById(R.id.action_b);
    FloatingActionButton actionC = new FloatingActionButton(getBaseContext());
    actionC.setTitle("Hide/Show Action above");
    actionC.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            actionB.setVisibility(actionB.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
        }
    });
    final FloatingActionsMenu menuMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    menuMultipleActions.addButton(actionC);
    final FloatingActionButton removeAction = (FloatingActionButton) findViewById(R.id.button_remove);
    removeAction.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ((FloatingActionsMenu) findViewById(R.id.multiple_actions_down)).removeButton(removeAction);
        }
    });
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(getResources().getColor(R.color.white));
    ((FloatingActionButton) findViewById(R.id.setter_drawable)).setIconDrawable(drawable);
    final FloatingActionButton actionA = (FloatingActionButton) findViewById(R.id.action_a);
    actionA.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            actionA.setTitle("Action A clicked");
        }
    });
    // Test that FAMs containing FABs with visibility GONE do not cause crashes
    findViewById(R.id.button_gone).setVisibility(View.GONE);
    final FloatingActionButton actionEnable = (FloatingActionButton) findViewById(R.id.action_enable);
    actionEnable.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            menuMultipleActions.setEnabled(!menuMultipleActions.isEnabled());
        }
    });
    FloatingActionsMenu rightLabels = (FloatingActionsMenu) findViewById(R.id.right_labels);
    FloatingActionButton addedOnce = new FloatingActionButton(this);
    addedOnce.setTitle("Added once");
    rightLabels.addButton(addedOnce);
    FloatingActionButton addedTwice = new FloatingActionButton(this);
    addedTwice.setTitle("Added twice");
    rightLabels.addButton(addedTwice);
    rightLabels.removeButton(addedTwice);
    rightLabels.addButton(addedTwice);
}

54. AddFloatingActionButton#getIconDrawable()

Project: android-floating-action-button
File: AddFloatingActionButton.java
@Override
Drawable getIconDrawable() {
    final float iconSize = getDimension(R.dimen.fab_icon_size);
    final float iconHalfSize = iconSize / 2f;
    final float plusSize = getDimension(R.dimen.fab_plus_icon_size);
    final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f;
    final float plusOffset = (iconSize - plusSize) / 2f;
    final Shape shape = new Shape() {

        @Override
        public void draw(Canvas canvas, Paint paint) {
            canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint);
            canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint);
        }
    };
    ShapeDrawable drawable = new ShapeDrawable(shape);
    final Paint paint = drawable.getPaint();
    paint.setColor(mPlusColor);
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    return drawable;
}