Example usage for android.graphics.drawable ShapeDrawable getPaint

List of usage examples for android.graphics.drawable ShapeDrawable getPaint

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable getPaint.

Prototype

public Paint getPaint() 

Source Link

Document

Returns the Paint used to draw the shape.

Usage

From source file:com.justplay1.shoppist.features.search.SearchAdapter.java

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    SearchViewHolder holder = (SearchViewHolder) viewHolder;
    ProductViewModel item = getItem(position);
    holder.text1.setText(item.getName());

    OvalShape ovalShape = new OvalShape();
    ShapeDrawable drawable = new ShapeDrawable(ovalShape);
    drawable.getPaint().setColor(item.getCategory().getColor());
    ViewUtils.setBackground(holder.typeIcon, drawable);
    if (!item.getId().equals(SearchView.JUST_NAME)) {
        holder.text2.setText(item.getCategory().getName());
    } else {//from  w  w w . j  a  v a  2 s .c om
        holder.text2.setVisibility(View.GONE);
    }

    switch (contextType) {
    case Const.CONTEXT_QUICK_ADD_GOODS_TO_LIST:
        ViewUtils.setBackground(holder.iconEnd, iconEndDrawable);
        break;
    case Const.CONTEXT_QUICK_SEARCH_IN_GOODS_LIST:
        holder.iconEnd.setVisibility(View.GONE);
        break;
    }
}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

/**
 * >= api 21//w  w w . jav  a  2 s. c o m
 */
@SuppressWarnings("NewApi")
protected RippleDrawable createRippleDrawable() {
    ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
    drawable.getPaint().setColor(mColorNormal);
    return new RippleDrawable(createRippleStateList(), drawable, null);
}

From source file:org.opensilk.common.ui.widget.FloatingActionButton.java

/**
 * <= api 19/*from w w  w .j a va 2 s  . c om*/
 */
protected Drawable createSelectableDrawable() {

    ShapeDrawable drawableNormal = new ShapeDrawable(new OvalShape());
    drawableNormal.getPaint().setColor(mColorNormal);

    StateListDrawable stateDrawable = new StateListDrawable();

    ShapeDrawable drawableHighlight = new ShapeDrawable(new OvalShape());
    drawableHighlight.getPaint().setColor(mColorPressed);

    stateDrawable.addState(new int[] { android.R.attr.state_pressed }, drawableHighlight);
    stateDrawable.addState(new int[0], null);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { drawableNormal, stateDrawable });

    return layerDrawable;
}

From source file:com.ashlikun.badgeview.BadgeView.java

public void setBackground(int radius, int badgeColor) {

    if (radius <= 0 || (this.radius == radius && bvColor == badgeColor)) {
        return;// w w  w . j  av a  2 s . co  m
    }
    bvColor = badgeColor;
    this.radius = radius;
    float[] radiusArray = new float[] { radius, radius, radius, radius, radius, radius, radius, radius };
    RoundRectShape roundRect = new RoundRectShape(radiusArray, null, null);
    ShapeDrawable bgDrawable = new ShapeDrawable(roundRect);
    bgDrawable.getPaint().setColor(badgeColor);
    setBackgroundDrawable(bgDrawable);
}

From source file:com.tiancaicc.springfloatingactionmenu.MenuItemView.java

private void init(Context context, boolean hasMargin) {

    Resources resources = getResources();
    int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
    this.mDiameter = diameterPX;
    mBtn = new ImageButton(context);
    mBtn.setScaleType(ImageView.ScaleType.FIT_CENTER);
    if (hasMargin) {
        int p = Util.dpToPx(12, getResources());
        mBtn.setPadding(p, p, p, p);/* ww w . ja va  2s .  c  o  m*/
    }
    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);
    if (TextUtils.isEmpty(mMenuItem.getIconFilePath())) {
        mBtn.setImageResource(mMenuItem.getIcon());
    } else {
        mBtn.setImageURI(Uri.fromFile(new File(mMenuItem.getIconFilePath())));
    }
    mBtn.setClickable(false);
    addView(mBtn);

    mLabel = (com.github.omadahealth.typefaceview.TypefaceTextView) View.inflate(getContext(),
            R.layout.c_text_view, null);
    mLabel.setPaintFlags(mLabel.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    mLabel.setTextIsSelectable(false);
    LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelLp.gravity = Gravity.CENTER_HORIZONTAL;
    mLabel.setLayoutParams(labelLp);
    if (!TextUtils.isEmpty(mMenuItem.getLabel())) {
        mLabel.setPadding(0, Util.dpToPx(70, getResources()), 0, 0);
        Drawable bottomArrow = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow);
        mLabel.setCompoundDrawablesWithIntrinsicBounds(null, null, null, bottomArrow);
    }
    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);
        }
    });

}

From source file:android.support.v7.widget.AppCompatProgressBarHelper.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *//*  w  w w.j a v a  2  s.c o m*/
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:android.support.v7.internal.widget.TintRatingBar.java

/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 *///from w w w  . j  av  a2 s .  c o  m
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT,
                Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}

From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java

@Override
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.

    // We construct a remote views item based on our widget item xml
    // file, and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
    sd1.getPaint().setColor(0xFFFFFFFF);
    sd1.getPaint().setStyle(Style.STROKE);
    sd1.getPaint().setStrokeWidth(1);// w  w  w  .  j a  v  a2  s. c o  m
    Canvas c = new Canvas();
    sd1.draw(c);
    Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888);
    c.drawBitmap(b, 0, 0, sd1.getPaint());
    // Next, we set a fill-intent which will be used to fill-in the
    // pending intent template
    // which is set on the collection view in StackWidgetProvider.

    if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES  dimensionato come le preferenze selezionate

        BookmarkDescriptor myDescriptor = ALLPREFERENCES[position];

        // set the widgetbutton
        if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity?
            String type = myDescriptor.params.get(0).value;
            if (WidgetHelper.TYPE_DT.equals(type)) {
                // dt -> put icons and hide text
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));

                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt);

            } else if (WidgetHelper.TYPE_JP.equals(type)) {
                // jp -> put text and hide icon

                rv.setViewVisibility(R.id.image_widget_item, View.GONE);
                // rv.setImageViewBitmap(R.id.text_widget_item,
                // getBackground(Color.parseColor("#6EB046")));
                if (!("0".equals(myDescriptor.params.get(2).value))) {
                    //bus
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80);

                    rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID(
                            myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3
                    rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor",
                    //Integer.parseInt(myDescriptor.params.get(2).value));
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                } else {
                    //train
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12);
                    //controllo contesto getRouteDescriptor i vari parametri
                    rv.setTextViewText(R.id.text_widget_item,
                            mContext.getString(
                                    RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value,
                                            myDescriptor.params.get(4).value).getNameResource()));
                    rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK);
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                }

            } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) {
                // jp parcheggio -> put text and hide icon
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));
                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

            }
            BookmarkDescriptor bookmark = myDescriptor;
            Bundle extras = new Bundle();
            extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent());
            if (bookmark.getParams() != null) {
                for (Param param : bookmark.getParams()) {
                    extras.putString(param.name, param.value);

                }

            }
            Intent fillInIntent = new Intent(bookmark.getIntent());
            fillInIntent.putExtras(extras);
            rv.setOnClickFillInIntent(R.id.layout, fillInIntent);
        }

    }
    // Return the remote views object.
    // AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
    // manager.updateAppWidget(thisWidget, rv);
    return rv;
}

From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java

public static Drawable createDrawable(Context context, int color) {

    ShapeDrawable shape = new ShapeDrawable();
    shape.getPaint().setStyle(Style.FILL);
    shape.setIntrinsicHeight(1);/*from w w  w .  ja  v  a  2  s  . co  m*/
    shape.getPaint().setColor(context.getResources().getColor(R.color.transparent));

    shape.getPaint().setStyle(Style.STROKE);
    shape.getPaint().setStrokeWidth(4);
    shape.getPaint().setColor(color);

    ShapeDrawable shapeD = new ShapeDrawable();
    shapeD.getPaint().setStyle(Style.FILL);
    shapeD.getPaint().setColor(color);
    ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL);

    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { clipDrawable, shape });
    return layerDrawable;
}

From source file:com.saulmm.cui.OrderDialogFragment.java

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;
}