Example usage for android.graphics.drawable GradientDrawable setShape

List of usage examples for android.graphics.drawable GradientDrawable setShape

Introduction

In this page you can find the example usage for android.graphics.drawable GradientDrawable setShape.

Prototype

public void setShape(@Shape int shape) 

Source Link

Document

Sets the type of shape used to draw the gradient.

Note: changing this property will affect all instances of a drawable loaded from a resource.

Usage

From source file:android.support.design.widget.FloatingActionButtonImpl.java

GradientDrawable createShapeDrawable() {
    GradientDrawable d = newGradientDrawableForShape();
    d.setShape(GradientDrawable.OVAL);
    d.setColor(Color.WHITE);
    return d;
}

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonEclairMr1.java

@Override
void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint,
        PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
    // Now we need to tint the original background with the tint, using
    // an InsetDrawable if we have a border width
    mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*  ww w  .  ja  v a 2s.c  o  m*/

    // Now we created a mask Drawable which will be used for touch feedback.
    // As we don't know the actual outline of mShapeDrawable, we'll just guess that it's a
    // circle
    GradientDrawable touchFeedbackShape = new GradientDrawable();
    touchFeedbackShape.setShape(GradientDrawable.OVAL);
    touchFeedbackShape.setColor(Color.WHITE);
    touchFeedbackShape.setCornerRadius(mShadowViewDelegate.getRadius());

    // We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need
    // to inset for any border here as LayerDrawable will nest the padding for us
    mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape);
    DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor));
    DrawableCompat.setTintMode(mRippleDrawable, PorterDuff.Mode.MULTIPLY);

    final Drawable[] layers;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable };
    } else {
        mBorderDrawable = null;
        layers = new Drawable[] { mShapeDrawable, mRippleDrawable };
    }

    mShadowDrawable = new ShadowDrawableWrapper(mView.getResources(), new LayerDrawable(layers),
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);

    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);

    updatePadding();
}

From source file:im.vector.adapters.RoomViewHolder.java

/**
 * Refresh the holder layout/*from  w  w w . java 2 s . co m*/
 *
 * @param room                   the room
 * @param isDirectChat           true when the room is a direct chat one
 * @param isInvitation           true when the room is an invitation one
 * @param moreRoomActionListener
 */
public void populateViews(final Context context, final MXSession session, final Room room,
        final boolean isDirectChat, final boolean isInvitation,
        final AbsAdapter.MoreRoomActionListener moreRoomActionListener) {
    // sanity check
    if (null == room) {
        Log.e(LOG_TAG, "## populateViews() : null room");
        return;
    }

    if (null == session) {
        Log.e(LOG_TAG, "## populateViews() : null session");
        return;
    }

    if (null == session.getDataHandler()) {
        Log.e(LOG_TAG, "## populateViews() : null dataHandler");
        return;
    }

    IMXStore store = session.getDataHandler().getStore(room.getRoomId());

    if (null == store) {
        Log.e(LOG_TAG, "## populateViews() : null Store");
        return;
    }

    final RoomSummary roomSummary = store.getSummary(room.getRoomId());

    if (null == roomSummary) {
        Log.e(LOG_TAG, "## populateViews() : null roomSummary");
        return;
    }

    int unreadMsgCount = roomSummary.getUnreadEventsCount();
    int highlightCount;
    int notificationCount;

    // Setup colors
    int mFuchsiaColor = ContextCompat.getColor(context, R.color.vector_fuchsia_color);
    int mGreenColor = ContextCompat.getColor(context, R.color.vector_green_color);
    int mSilverColor = ContextCompat.getColor(context, R.color.vector_silver_color);

    highlightCount = roomSummary.getHighlightCount();
    notificationCount = roomSummary.getNotificationCount();

    // fix a crash reported by GA
    if ((null != room.getDataHandler())
            && room.getDataHandler().getBingRulesManager().isRoomMentionOnly(room.getRoomId())) {
        notificationCount = highlightCount;
    }

    int bingUnreadColor;
    if (isInvitation || (0 != highlightCount)) {
        bingUnreadColor = mFuchsiaColor;
    } else if (0 != notificationCount) {
        bingUnreadColor = mGreenColor;
    } else if (0 != unreadMsgCount) {
        bingUnreadColor = mSilverColor;
    } else {
        bingUnreadColor = Color.TRANSPARENT;
    }

    if (isInvitation || (notificationCount > 0)) {
        vRoomUnreadCount.setText(isInvitation ? "!" : RoomUtils.formatUnreadMessagesCounter(notificationCount));
        vRoomUnreadCount.setTypeface(null, Typeface.BOLD);
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(bingUnreadColor);
        vRoomUnreadCount.setBackground(shape);
        vRoomUnreadCount.setVisibility(View.VISIBLE);
    } else {
        vRoomUnreadCount.setVisibility(View.GONE);
    }

    String roomName = VectorUtils.getRoomDisplayName(context, session, room);
    if (vRoomNameServer != null) {
        // This view holder is for the home page, we have up to two lines to display the name
        if (MXSession.isRoomAlias(roomName)) {
            // Room alias, split to display the server name on second line
            final String[] roomAliasSplitted = roomName.split(":");
            final String firstLine = roomAliasSplitted[0] + ":";
            final String secondLine = roomAliasSplitted[1];
            vRoomName.setLines(1);
            vRoomName.setText(firstLine);
            vRoomNameServer.setText(secondLine);
            vRoomNameServer.setVisibility(View.VISIBLE);
            vRoomNameServer.setTypeface(null, (0 != unreadMsgCount) ? Typeface.BOLD : Typeface.NORMAL);
        } else {
            // Allow the name to take two lines
            vRoomName.setLines(2);
            vRoomNameServer.setVisibility(View.GONE);
            vRoomName.setText(roomName);
        }
    } else {
        vRoomName.setText(roomName);
    }
    vRoomName.setTypeface(null, (0 != unreadMsgCount) ? Typeface.BOLD : Typeface.NORMAL);

    VectorUtils.loadRoomAvatar(context, session, vRoomAvatar, room);

    // get last message to be displayed
    if (vRoomLastMessage != null) {
        CharSequence lastMsgToDisplay = RoomUtils.getRoomMessageToDisplay(context, session, roomSummary);
        vRoomLastMessage.setText(lastMsgToDisplay);
    }

    if (mDirectChatIndicator != null) {
        mDirectChatIndicator.setVisibility(isDirectChat ? View.VISIBLE : View.INVISIBLE);
    }
    vRoomEncryptedIcon.setVisibility(room.isEncrypted() ? View.VISIBLE : View.INVISIBLE);

    if (vRoomUnreadIndicator != null) {
        // set bing view background colour
        vRoomUnreadIndicator.setBackgroundColor(bingUnreadColor);
        vRoomUnreadIndicator.setVisibility(roomSummary.isInvited() ? View.INVISIBLE : View.VISIBLE);
    }

    if (vRoomTimestamp != null) {
        vRoomTimestamp.setText(RoomUtils.getRoomTimestamp(context, roomSummary.getLatestReceivedEvent()));
    }

    if (vRoomMoreActionClickArea != null && vRoomMoreActionAnchor != null) {
        vRoomMoreActionClickArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != moreRoomActionListener) {
                    moreRoomActionListener.onMoreActionClick(vRoomMoreActionAnchor, room);
                }
            }
        });
    }
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableUtils.java

void inflateGradientRootElement(Context context, AttributeSet attrs, GradientDrawable gradientDrawable) {
    int shape = getAttrInt(context, attrs, android.R.attr.shape, GradientDrawable.RECTANGLE);
    gradientDrawable.setShape(shape);
    boolean dither = getAttrBoolean(context, attrs, android.R.attr.dither, false);
    gradientDrawable.setDither(dither);/* w  ww.  j a  v  a2s  .  c  om*/
}

From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java

void inflateGradientRootElement(Context context, AttributeSet attrs, GradientDrawable gradientDrawable) {
    int shape = DrawableUtils.getAttrInt(context, attrs, android.R.attr.shape, GradientDrawable.RECTANGLE);
    gradientDrawable.setShape(shape);
    boolean dither = DrawableUtils.getAttrBoolean(context, attrs, android.R.attr.dither, false);
    gradientDrawable.setDither(dither);//from w  w  w.  j  a va2s.c o m
}

From source file:com.arsy.maps_library.MapRadar.java

private void setDrawableAndBitmap() {
    mOuterDrawable.setColor(mFillColor);
    mOuterDrawable.setStroke(UiUtil.dpToPx(mStrokeWidth), mStrokeColor);
    mBackgroundImageDescriptor = UiUtil.drawableToBitmapDescriptor(mOuterDrawable);
    GradientDrawable radarDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR, mColors);
    radarDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
    radarDrawable.setShape(GradientDrawable.OVAL);
    radarDrawable.setSize(1200, 1200);//from   ww w . jav a 2  s  .  c om
    mBackgroundImageSweepDescriptor = UiUtil.drawableToBitmapDescriptor(radarDrawable);
}

From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

protected void init(Context context) {
    if (isInitialized)
        return;//from  ww w .  j a  v  a 2s.  c om
    isInitialized = true;
    setOrientation(HORIZONTAL);
    setClipChildren(false);
    setWillNotDraw(false);

    bubble = new TextView(context);
    bubble.setTextColor(Color.WHITE);
    bubble.setTextSize(48);

    GradientDrawable bubbleDrawable = new GradientDrawable();
    bubbleDrawable.setColor(0xFFce891e);
    bubbleDrawable.setSize(getCustomSize(88), getCustomSize(88));
    bubbleDrawable.setCornerRadii(new float[] { getCustomSize(44), getCustomSize(44), getCustomSize(44),
            getCustomSize(44), 0, 0, getCustomSize(44), getCustomSize(44) });

    bubble.setBackgroundDrawable(bubbleDrawable);

    //bubble.setBackgroundResource(R.drawable.recycler_view_fast_scroller__bubble);
    bubble.setGravity(Gravity.CENTER);

    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT | Gravity.END;

    addView(bubble, params);

    if (bubble != null)
        bubble.setVisibility(INVISIBLE);

    handle = new ImageView(context);
    //handle.setBackgroundResource(R.drawable.recycler_view_fast_scroller__handle);

    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setSize(getCustomSize(4), getCustomSize(35));
    drawable.setColor(0xFFce891e);
    drawable.setCornerRadius(getCustomSize(5));

    GradientDrawable drawable2 = new GradientDrawable();
    drawable2.setShape(GradientDrawable.RECTANGLE);
    drawable2.setSize(getCustomSize(4), getCustomSize(35));
    drawable2.setColor(0xFFf3a124);
    drawable2.setCornerRadius(getCustomSize(5));

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_selected }, drawable);
    states.addState(new int[] {}, drawable2);

    handle.setBackgroundDrawable(states);

    LayoutParams params2 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    int dimension = getCustomSize(3);

    int doubleDimension = dimension * 2;
    params2.leftMargin = doubleDimension;
    params2.rightMargin = doubleDimension;

    handle.setPadding(dimension, 0, dimension, 0);
    handle.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                v.setBackgroundColor(Color.parseColor("#00891e"));
            } else {
                v.setBackgroundColor(Color.parseColor("#44891e"));
            }
        }
    });

    addView(handle, params2);

}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

private void setLegends() {
    if (mChart.getData().getDataSets().size() > 1) {
        final Resources resources = ApplicationData.getAppContext().getResources();
        final float density = getResources().getDisplayMetrics().density;
        final float legendWidth = resources.getDimension(R.dimen.chart_legend_width) / density;
        final float legendHeight = resources.getDimension(R.dimen.chart_legend_height) / density;
        final float legendMargin = resources.getDimension(R.dimen.chart_legend_margin) / density;
        final float legendCorner = resources.getDimension(R.dimen.chart_legend_corner) / density;

        for (ILineDataSet lineDataSet : mChart.getData().getDataSets()) {
            final CheckBox checkBox = new CheckBox(mLegendLayout.getContext());
            checkBox.setChecked(true);//from w w w .ja v a  2  s . co m
            checkBox.setText(lineDataSet.getLabel());
            checkBox.setTag(lineDataSet);
            checkBox.setOnCheckedChangeListener(mLegendCheckedChangeListener);

            GradientDrawable drawable = new GradientDrawable();
            drawable.setShape(GradientDrawable.RECTANGLE);
            drawable.setColor(lineDataSet.getColor());
            drawable.setSize((int) legendWidth, (int) legendHeight);
            drawable.setCornerRadius(legendCorner);

            checkBox.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null);
            checkBox.setCompoundDrawablePadding((int) legendMargin);

            final GridLayout.Spec titleTxtSpecColumn = GridLayout.spec(GridLayout.UNDEFINED);
            final GridLayout.Spec titleRowSpec = GridLayout.spec(GridLayout.UNDEFINED);
            final GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams(titleRowSpec,
                    titleTxtSpecColumn);
            layoutParams.setMargins((int) legendWidth, 0, (int) legendWidth, 0);
            mLegendLayout.addView(checkBox, layoutParams);
        }
    }
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

GradientDrawable createGradientDrawable(int color) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    gradientDrawable.setColor(color);//from www.ja  v a2  s. c  o  m
    return gradientDrawable;
}

From source file:io.imoji.sdk.grid.ui.ResultView.java

private Drawable getPlaceholder(int placeholderRandomizer, int position) {
    int[] colorArray = context.getResources().getIntArray(R.array.search_widget_placeholder_colors);
    int color = colorArray[(placeholderRandomizer + position) % colorArray.length];

    GradientDrawable placeholder = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { ColorUtils.setAlphaComponent(Color.WHITE, GRADIENT_START_ALPHA),
                    ColorUtils.setAlphaComponent(Color.WHITE, GRADIENT_END_ALPHA) });
    placeholder.setColor(color);/*from w w  w.  j ava 2 s.c om*/
    placeholder.setShape(GradientDrawable.OVAL);
    return placeholder;
}