Java Code Examples for android.graphics.drawable.GradientDrawable#setSize()

The following examples show how to use android.graphics.drawable.GradientDrawable#setSize() . 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: SegmentedButtonGroup.java    From SegmentedButton with Apache License 2.0 6 votes vote down vote up
/**
 * Set divider between buttons with a specified solid color, width, radius and padding
 *
 * @param color   color of the divider
 * @param width   width of the divider drawable, in pixels
 * @param radius  corner radius of the divider drawable to round the corners, in pixels
 * @param padding space above and below the divider drawable within the button group, in pixels
 */
public void setDivider(@ColorInt int color, int width, int radius, int padding)
{
    // Create GradientDrawable of the specified color
    // This is used to specify the corner radius, unlike ColorDrawable that does not have that feature
    GradientDrawable drawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP,
        new int[] {color, color});

    drawable.setCornerRadius(radius);
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setSize(width, 0);

    dividerLayout.setDividerDrawable(drawable);
    dividerLayout.setDividerPadding(padding);
    dividerLayout.setShowDividers(SHOW_DIVIDER_MIDDLE);

    // Loop through and update the divider width for each of the dummy divider views
    for (int i = 0; i < dividerLayout.getChildCount(); ++i)
    {
        final ButtonActor view = (ButtonActor)dividerLayout.getChildAt(i);
        view.setDividerWidth(width);
    }
    dividerLayout.requestLayout();
}
 
Example 2
Source File: TodayWidgetConfigureActivity.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
private void setUpOpacitySeekBar() {
    int mOpacitySeekBarColor = ContextCompat.getColor(this, R.color.ets_red_fonce);
    mOpacitySeekBar = (SeekBar) findViewById(R.id.opacity_seekbar);

    mOpacitySeekBar.setProgress(loadOpacityDefaultPref());

    mOpacitySeekBar.setOnSeekBarChangeListener(mOpacityListener);

    mOpacitySeekBar.getProgressDrawable().setColorFilter(mOpacitySeekBarColor,
            PorterDuff.Mode.SRC_IN);

    if (android.os.Build.VERSION.SDK_INT < 16) {
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setShape(GradientDrawable.OVAL);
        gradientDrawable.setSize(50, 50);
        gradientDrawable.setColor(mOpacitySeekBarColor);
        mOpacitySeekBar.setThumb(gradientDrawable);
    } else {
        mOpacitySeekBar.getThumb().setColorFilter(mOpacitySeekBarColor, PorterDuff.Mode.SRC_IN);
    }
}
 
Example 3
Source File: BaseListFragment.java    From pandora with Apache License 2.0 6 votes vote down vote up
@Override
protected View getLayoutView() {
    adapter = new UniversalAdapter();
    recyclerView = new MenuRecyclerView(getContext());
    recyclerView.setBackgroundColor(ViewKnife.getColor(R.color.pd_main_bg));
    recyclerView.setLayoutManager(onCreateLayoutManager());
    if (needDefaultDivider()) {
        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        GradientDrawable horizontalDrawable = new GradientDrawable();
        horizontalDrawable.setColor(0xffE5E5E5);
        horizontalDrawable.setSize(0, 1);
        divider.setDrawable(horizontalDrawable);
        recyclerView.addItemDecoration(divider);
    }
    recyclerView.setAdapter(adapter);
    return recyclerView;
}
 
Example 4
Source File: DynamicDrawableUtils.java    From dynamic-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Get a gradient drawable according to the supplied drawable.
 *
 * @param width The width in dip for the drawable.
 * @param height The height in dip for the drawable.
 * @param drawable The drawable drawable to create the gradient drawable.
 * @param color The color for the drawable.
 *
 * @return The gradient drawable according to the supplied parameters.
 */
public static @NonNull Drawable getCornerDrawable(int width, int height,
        @NonNull GradientDrawable drawable, @ColorInt int color) {
    drawable.setColor(color);

    if (width > 0 && height > 0) {
        drawable.setSize(DynamicUnitUtils.convertDpToPixels(width),
                DynamicUnitUtils.convertDpToPixels(height));
    }

    return drawable;
}
 
Example 5
Source File: Utils.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
static Drawable getDefaultHorizontalSlider(Context context) {
    final float density = context.getResources().getDisplayMetrics().density;
    GradientDrawable background = new GradientDrawable();
    background.setSize((int) (24 * density), (int) (8 * density));
    background.setColor(0x80000000);
    return background;
}
 
Example 6
Source File: RoundHelper.java    From RadioRealButton with Apache License 2.0 5 votes vote down vote up
private static GradientDrawable getGradientDrawable(int dividerColor, int dividerRadius, Integer dividerSize) {
    GradientDrawable gradient =
            new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{dividerColor, dividerColor});
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setCornerRadius(dividerRadius);
    if (null != dividerSize)
        gradient.setSize(dividerSize, 0);
    return gradient;
}
 
Example 7
Source File: MyDrawable.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
public static GradientDrawable getIcFolderSelectedDrawable( int color){
    GradientDrawable gradientDrawable=new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.OVAL);
    gradientDrawable.setSize(SizeUtils.dp2px(24), SizeUtils.dp2px(24));
    gradientDrawable.setBounds(0,0,SizeUtils.dp2px(24), SizeUtils.dp2px(24));
    gradientDrawable.setColor(color);
    return gradientDrawable;
}
 
Example 8
Source File: ProductAdapter.java    From From-design-to-Android-part1 with Apache License 2.0 5 votes vote down vote up
@NonNull
private GradientDrawable createProductBackground(Product product) {
    final GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(
        itemView.getContext(), R.drawable.bg_product);

    gradientDrawable.setColor(ContextCompat.getColor(
        itemView.getContext(), product.color));

    gradientDrawable.setSize(itemView.getWidth(), getDrawableHeight());
    gradientDrawable.mutate();
    return gradientDrawable;
}
 
Example 9
Source File: ColorPointHintView.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable makeNormalDrawable() {
    GradientDrawable dotNormal = new GradientDrawable();
    dotNormal.setColor(normalColor);
    dotNormal.setCornerRadius(LibUtils.dip2px(getContext(), 4));
    dotNormal.setSize(LibUtils.dip2px(getContext(), 8),
            LibUtils.dip2px(getContext(), 8));
    return dotNormal;
}
 
Example 10
Source File: ColorPointHintView.java    From stynico with MIT License 5 votes vote down vote up
@Override
   public Drawable makeNormalDrawable()
{
       GradientDrawable dot_normal = new GradientDrawable();
       dot_normal.setColor(normalColor);
       dot_normal.setCornerRadius(dump.v.Util.dip2px(getContext(), 4));
       dot_normal.setSize(dump.v.Util.dip2px(getContext(), 8), dump.v.Util.dip2px(getContext(), 8));
       return dot_normal;
   }
 
Example 11
Source File: Utils.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
static Drawable getDefaultHorizontalIndicator(Context context) {
    final float density = context.getResources().getDisplayMetrics().density;
    GradientDrawable background = new GradientDrawable();
    background.setSize((int) (54 * density), (int) (54 * density));
    final float radius = 27 * density;
    background.setCornerRadii(new float[]{radius, radius, radius, radius, 0, 0,
            radius, radius});
    background.setColor(0xFF4859D2);
    return background;
}
 
Example 12
Source File: Utils.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
static Drawable getDefaultBackground(Context context) {
    final float density = context.getResources().getDisplayMetrics().density;
    GradientDrawable background = new GradientDrawable();
    background.setSize((int) (8 * density), (int) (8 * density));
    background.setColor(0x40000000);
    return background;
}
 
Example 13
Source File: OptionScanHighlighter.java    From talkback with Apache License 2.0 5 votes vote down vote up
private GradientDrawable getHighlightDrawable(int halfStrokeWidth, Rect rectForNodeHighlight) {
  GradientDrawable highlightDrawable = new GradientDrawable();
  highlightDrawable.setShape(GradientDrawable.RECTANGLE);
  highlightDrawable.setCornerRadius(halfStrokeWidth);
  highlightDrawable.setSize(rectForNodeHighlight.width(), rectForNodeHighlight.height());
  return highlightDrawable;
}
 
Example 14
Source File: RoundHelper.java    From SegmentedButton with Apache License 2.0 5 votes vote down vote up
private static GradientDrawable getGradientDrawable(int dividerColor, int dividerRadius, int dividerSize) {
    GradientDrawable gradient =
            new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{dividerColor, dividerColor});
    gradient.setShape(GradientDrawable.RECTANGLE);
    gradient.setCornerRadius(dividerRadius);
    gradient.setSize(dividerSize, 0);
    return gradient;
}
 
Example 15
Source File: ColorPointHintView.java    From styT with Apache License 2.0 5 votes vote down vote up
@Override
   public Drawable makeFocusDrawable()
{
       GradientDrawable dot_focus = new GradientDrawable();
       dot_focus.setColor(focusColor);
       dot_focus.setCornerRadius(dump.v.Util.dip2px(getContext(), 4));
       dot_focus.setSize(dump.v.Util.dip2px(getContext(), 8), dump.v.Util.dip2px(getContext(), 8));
       return dot_focus;
   }
 
Example 16
Source File: BackgroundHelper.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public static Drawable getRedDotDrawable(Context context) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.OVAL);
    gradientDrawable.setColor(ContextCompat.getColor(context, R.color.color_FF3A5C));
    gradientDrawable.setSize(DisplayHelper.dpToPx(9), DisplayHelper.dpToPx(9));
    return gradientDrawable;
}
 
Example 17
Source File: BackgroundHelper.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
public static Drawable getDotDrawable(Context context, @ColorRes int colorRes, int diameter) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.OVAL);
    gradientDrawable.setColor(ContextCompat.getColor(context, colorRes));
    gradientDrawable.setSize(diameter, diameter);
    return gradientDrawable;
}
 
Example 18
Source File: DrawableValue.java    From proteus with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(ProteusView view, GradientDrawable gradientDrawable) {
  gradientDrawable.setSize((int) DimensionAttributeProcessor.evaluate(width, view), (int) DimensionAttributeProcessor.evaluate(height, view));
}
 
Example 19
Source File: GeneralDialog.java    From pandora with Apache License 2.0 4 votes vote down vote up
private void transform(Window window) {
    try {
        View sysContent = window.findViewById(Window.ID_ANDROID_CONTENT);
        GradientDrawable backgroundDrawable = new GradientDrawable();
        backgroundDrawable.setCornerRadius(ViewKnife.dip2px(10));
        backgroundDrawable.setColor(Color.WHITE);
        ViewCompat.setBackground(sysContent, backgroundDrawable);

        DialogTitle title = window.findViewById(androidx.appcompat.R.id.alertTitle);
        TextView message = window.findViewById(android.R.id.message);
        Button button1 = window.findViewById(android.R.id.button1);
        Button button2 = window.findViewById(android.R.id.button2);
        Button button3 = window.findViewById(android.R.id.button3);
        LinearLayout buttonParent = (LinearLayout) button1.getParent();

        buttonParent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        GradientDrawable verticalDrawable = new GradientDrawable();
        verticalDrawable.setColor(0xffE5E5E5);
        verticalDrawable.setSize(ViewKnife.dip2px(.5f), 0);
        buttonParent.setDividerDrawable(verticalDrawable);
        buttonParent.setPadding(0, 0, 0, 0);

        GradientDrawable innerDrawable = new GradientDrawable();
        innerDrawable.setStroke(ViewKnife.dip2px(.5f), 0xffE5E5E5);
        InsetDrawable insetDrawable = new InsetDrawable(innerDrawable,
                ViewKnife.dip2px(-1), 0, ViewKnife.dip2px(-1), ViewKnife.dip2px(-1));
        ViewCompat.setBackground(buttonParent, insetDrawable);

        window.findViewById(androidx.appcompat.R.id.spacer).setVisibility(View.GONE);

        View textSpacerNoButtons = window.findViewById(androidx.appcompat.R.id.textSpacerNoButtons);
        if (textSpacerNoButtons != null) {
            textSpacerNoButtons.setVisibility(View.VISIBLE);
        }
        button1.setTextColor(0xff5B6B91);
        button2.setTextColor(0xff353535);
        button3.setTextColor(0xff353535);
        button1.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        button2.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        button3.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        ((LinearLayout.LayoutParams) button3.getLayoutParams()).weight = 1;
        ((LinearLayout.LayoutParams) button2.getLayoutParams()).weight = 1;
        ((LinearLayout.LayoutParams) button1.getLayoutParams()).weight = 1;

        if (message != null) {
            message.setTextColor(0xff202020);
            if (getArguments().getBoolean(ATTR7, false)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    message.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
                } else {
                    message.setGravity(Gravity.CENTER_HORIZONTAL);
                }
            }
        }

        title.setTextColor(0xff353535);
        title.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        } else {
            title.setGravity(Gravity.CENTER_HORIZONTAL);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
Example 20
Source File: Drawables.java    From noDrawable with Apache License 2.0 4 votes vote down vote up
public static Drawable create(
        @ShapeMode int shapeMode, @ColorInt Integer solidColor,
        @ColorInt int strokeColor, @DP float strokeWidth, @DP float strokeDash, @DP float strokeDashGap,
        @DP float radius, @DP float radiusLT, @DP float radiusLB, @DP float radiusRT, @DP float radiusRB,
        @ColorInt Integer startColor, @ColorInt Integer centerColor, @ColorInt Integer endColor,
        @Orientation int orientation, @GradientType int gradientType,
        Float radialCenterX, Float radialCenterY, float radialRadius,
        @DP float width, @DP float height,
        @DP float marginLeft, @DP float marginTop, @DP float marginRight, @DP float marginBottom,
        @DP float ringThickness,
        @DP float   ringThicknessRatio,
        @DP float ringInnerRadius,
        @DP float   ringInnerRadiusRatio
) {
    if (shapeMode == INVALID && solidColor == null && strokeColor == INVALID
            && strokeWidth == INVALID && strokeDash == INVALID && strokeDashGap == INVALID
            && radius == INVALID && radiusLT == INVALID && radiusLB == INVALID
            && radiusRT == INVALID && radiusRB == INVALID && startColor == null
            && centerColor == null && endColor == null && orientation == INVALID
            && gradientType == INVALID && radialCenterX == null && radialCenterY == null
            && radialRadius == INVALID && width == INVALID && height == INVALID
            && marginLeft == INVALID && marginTop == INVALID && marginRight == INVALID && marginBottom == INVALID
            ) {
        // 这里需要判断empty,因为有可能只设置了一个state的drawable,那么其他state的就是empty了
        return null;
    }
    GradientDrawable drawable = new GradientDrawable();
    if (startColor != null && endColor != null) {
        int[] colors;
        if (centerColor != null) {
            colors = new int[3];
            colors[0] = startColor;
            colors[1] = centerColor;
            colors[2] = endColor;
        } else {
            colors = new int[2];
            colors[0] = startColor;
            colors[1] = endColor;
        }
        drawable.setColors(colors);
        drawable.setOrientation(mapOrientation(orientation));
        drawable.setGradientType(gradientType);
        if (gradientType == GradientType.RADIAL) {
            drawable.setGradientCenter(radialCenterX == null ? .5f : radialCenterX,
                    radialCenterY == null ? .5f : radialCenterY);
            drawable.setGradientRadius(dip2px(radialRadius));
        }
    } else {
        if (solidColor != null) {
            drawable.setColor(solidColor);
        }
    }
    drawable.setShape(validShapeMode(shapeMode));
    if (shapeMode == ShapeMode.RING) {
        // 由于GradientDrawable中没有ring相关的公开API,所以使用反射,若对性能有要求,请注意。
        setRingValue(drawable, ringThickness, ringThicknessRatio, ringInnerRadius, ringInnerRadiusRatio);
    }
    if (strokeWidth > 0) {
        drawable.setStroke(dip2px(strokeWidth), strokeColor, dip2px(strokeDash), dip2px(strokeDashGap));
    }
    if (radius <= 0) {
        float[] radiusEach = new float[]{dip2px(radiusLT), dip2px(radiusLT), dip2px(radiusRT), dip2px(radiusRT),
                dip2px(radiusRB), dip2px(radiusRB), dip2px(radiusLB), dip2px(radiusLB)};
        drawable.setCornerRadii(radiusEach);
    } else {
        drawable.setCornerRadius(dip2px(radius));
    }
    if (width > 0 && height > 0) {
        // https://stackoverflow.com/a/29180660/4698946
        drawable.setSize(dip2px(width), dip2px(height));
    }
    if (marginLeft != 0 || marginTop != 0 || marginRight != 0 || marginBottom != 0) {
        return new InsetDrawable(drawable,
                dip2px(marginLeft),
                dip2px(marginTop),
                dip2px(marginRight),
                dip2px(marginBottom));
    } else {
        return drawable;
    }
}