Example usage for android.graphics.drawable GradientDrawable setCornerRadius

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

Introduction

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

Prototype

public void setCornerRadius(float radius) 

Source Link

Document

Specifies the radius for the corners of the gradient.

Usage

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

/**
 * Apply a rounded (sides) rectangle as a background to the view provided in aTargetView.
 *
 * @param aTargetView      view to apply the background
 * @param aBackgroundColor background colour
 *///from  w  w w.j a va2  s.  c om
private static void setUnreadBackground(View aTargetView, int aBackgroundColor) {
    if (null != aTargetView) {
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(aBackgroundColor);
        aTargetView.setBackground(shape);
    }
}

From source file:im.vector.view.UnreadCounterBadgeView.java

/**
 * Update the badge value and its status
 *
 * @param text   the new text value//from w ww. ja v  a2s.com
 * @param status the new status
 */
public void updateText(String text, @Status int status) {
    if (!TextUtils.isEmpty(text)) {
        mCounterTextView.setText(text);

        setVisibility(View.VISIBLE);
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        if (status == HIGHLIGHTED) {
            shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_fuchsia_color));
        } else if (status == NOTIFIED) {
            shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_green_color));
        } else { //if (status == DEFAULT)
            shape.setColor(ContextCompat.getColor(getContext(), R.color.vector_silver_color));
        }
        mParentView.setBackground(shape);
    } else {
        setVisibility(View.GONE);
    }
}

From source file:com.auth0.android.lock.views.CountryCodeSelectorView.java

private void setupBackground() {
    Drawable leftBackground = ViewUtils.getRoundedBackground(getResources(),
            ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal),
            ViewUtils.Corners.ONLY_LEFT);
    Drawable rightBackground = ViewUtils.getRoundedBackground(getResources(),
            ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_country_code_background),
            ViewUtils.Corners.ONLY_RIGHT);
    ViewUtils.setBackground(icon, leftBackground);
    ViewUtils.setBackground(chevron, rightBackground);
    ViewGroup parent = ((ViewGroup) countryNameTextView.getParent());
    Drawable bg = parent.getBackground();
    GradientDrawable gd = bg == null ? new GradientDrawable() : (GradientDrawable) bg;
    gd.setCornerRadius(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_widget_corner_radius));
    gd.setStroke(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_input_field_stroke_width),
            ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
    gd.setColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
    ViewUtils.setBackground(parent, gd);
}

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

/**
 * Refresh the holder layout//from w  w w.jav a2s . com
 *
 * @param context                 the context
 * @param group                   the group
 * @param isInvitation            true if it is an invitation
 * @param moreGroupActionListener the more actions listener
 */
public void populateViews(final Context context, final MXSession session, final Group group,
        final AbsAdapter.GroupInvitationListener invitationListener, final boolean isInvitation,
        final AbsAdapter.MoreGroupActionListener moreGroupActionListener) {
    // sanity check
    if (null == group) {
        Log.e(LOG_TAG, "## populateViews() : null group");
        return;
    }

    if (isInvitation) {
        vGroupMembersCount.setText("!");
        vGroupMembersCount.setTypeface(null, Typeface.BOLD);
        GradientDrawable shape = new GradientDrawable();
        shape.setShape(GradientDrawable.RECTANGLE);
        shape.setCornerRadius(100);
        shape.setColor(ContextCompat.getColor(context, R.color.vector_fuchsia_color));
        vGroupMembersCount.setBackground(shape);
        vGroupMembersCount.setVisibility(View.VISIBLE);
    } else {
        vGroupMembersCount.setVisibility(View.GONE);
    }

    vGroupName.setText(group.getDisplayName());
    vGroupName.setTypeface(null, Typeface.NORMAL);

    VectorUtils.loadGroupAvatar(context, session, vGroupAvatar, group);

    vGroupTopic.setText(group.getShortDescription());

    if (vGroupMoreActionClickArea != null && vGroupMoreActionAnchor != null) {
        vGroupMoreActionClickArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != moreGroupActionListener) {
                    moreGroupActionListener.onMoreActionClick(vGroupMoreActionAnchor, group);
                }
            }
        });
    }
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticLayout.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticLayout_layout_round, round);
    bgShape.setCornerRadius(round);

    color = typedArray.getInt(R.styleable.ElasticLayout_layout_backgroundColor, color);
    bgShape.setColor(color);//from w w  w .  j  a  va  2s.c om

    scale = typedArray.getFloat(R.styleable.ElasticLayout_layout_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticLayout_layout_duration, duration);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticButton.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticButton_button_round, round);
    bgShape.setCornerRadius(round);

    color = typedArray.getInt(R.styleable.ElasticButton_button_backgroundColor, color);
    bgShape.setColor(color);// w w  w.j  a  va2 s . c  o  m

    scale = typedArray.getFloat(R.styleable.ElasticButton_button_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticButton_button_duration, duration);

    labelText = typedArray.getString(R.styleable.ElasticButton_button_labelText);
    view.setText(labelText);

    labelColor = typedArray.getInt(R.styleable.ElasticButton_button_labelColor, labelColor);
    view.setTextColor(labelColor);

    labelSize = typedArray.getInt(R.styleable.ElasticButton_button_labelSize, labelSize);
    view.setTextSize(labelSize);

    labelStyle = typedArray.getInt(R.styleable.ElasticButton_button_labelStyle, labelStyle);

    if (labelStyle == 0)
        view.setTypeface(null, Typeface.NORMAL);
    else if (labelStyle == 1)
        view.setTypeface(null, Typeface.BOLD);
    else if (labelStyle == 2)
        view.setTypeface(null, Typeface.ITALIC);
}

From source file:com.skydoves.elasticviewsexample.ElasticVIews.ElasticCheckButton.java

private void setTypeArray(TypedArray typedArray) {
    GradientDrawable bgShape = (GradientDrawable) view.getBackground();

    round = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_round, round);
    bgShape.setCornerRadius(round);

    color = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_backgroundColor, color);
    bgShape.setColor(color);//from  www.  jav  a2s . c  o  m

    scale = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_scale, scale);

    duration = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_duration, duration);

    labelText = typedArray.getString(R.styleable.ElasticCheckButton_checkbutton_labelText);
    view.setText(labelText);

    labelColor = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelColor, labelColor);
    view.setTextColor(labelColor);

    labelSize = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelSize, labelSize);
    view.setTextSize(labelSize);

    labelStyle = typedArray.getInt(R.styleable.ElasticCheckButton_checkbutton_labelStyle, labelStyle);

    if (labelStyle == 0)
        view.setTypeface(null, Typeface.NORMAL);
    else if (labelStyle == 1)
        view.setTypeface(null, Typeface.BOLD);
    else if (labelStyle == 2)
        view.setTypeface(null, Typeface.ITALIC);

    alpha = typedArray.getFloat(R.styleable.ElasticCheckButton_checkbutton_alpha, alpha);

    checked = typedArray.getBoolean(R.styleable.ElasticCheckButton_checkbutton_ischecked, checked);
    if (checked)
        view.setAlpha(alpha);
}

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

/**
 * Refresh the holder layout/*from   w w  w .  ja va  2 s  . c  om*/
 *
 * @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:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java

private View getColorImageView(int color) {
    final ImageView imageView = new ImageView(this);
    int width = EUExUtil.dipToPixels(32);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, width);
    int margin = EUExUtil.dipToPixels(4);
    lp.leftMargin = margin;//from   ww w.  j a  v a2s .  c o  m
    lp.rightMargin = margin;
    imageView.setLayoutParams(lp);
    imageView.setTag(color);
    GradientDrawable colorDrawable = new GradientDrawable();
    colorDrawable.setColor(color);
    colorDrawable.setCornerRadius(8);
    if (Build.VERSION.SDK_INT < 16) {
        imageView.setBackgroundDrawable(colorDrawable);
    } else {
        imageView.setBackground(colorDrawable);
    }
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCurrnetColor = (int) imageView.getTag();
            mScrawlImageView.setPaintColor(mCurrnetColor);
            mPreviewView.setColor(mCurrnetColor);
        }
    });
    return imageView;
}

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);
    }//  w w w .ja v a 2 s .  com

    // 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();
}