Example usage for android.graphics.drawable GradientDrawable RECTANGLE

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

Introduction

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

Prototype

int RECTANGLE

To view the source code for android.graphics.drawable GradientDrawable RECTANGLE.

Click Source Link

Document

Shape is a rectangle, possibly with rounded corners

Usage

From source file:Main.java

public static Drawable createRandomColorShapeDrawable() {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    drawable.setCornerRadius(5);//w w w  . j a  va 2 s  . co  m
    drawable.setColor(createRandomColor());
    return drawable;
}

From source file:Main.java

public static Drawable createDrawableBackground(int color, int cornerRadius, boolean hasBorder,
        int borderThickness, int borderColor) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setShape(GradientDrawable.RECTANGLE);
    if (hasBorder)
        drawable.setStroke(borderThickness, borderColor);
    drawable.setCornerRadius(cornerRadius);
    drawable.setColor(color);/* w  w  w  .java2  s  .c om*/
    return drawable;
}

From source file:Main.java

public static void setGradientForPreferenceView(View v) {

    int[] colorsForGradient = new int[2];
    colorsForGradient[0] = Color.argb(0, 0, 0, 0);
    colorsForGradient[1] = Color.argb(64, 255, 255, 255);
    GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colorsForGradient);
    d.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    d.setShape(GradientDrawable.RECTANGLE);
    // doesn't help d.setUseLevel(true);
    d.setDither(true);//w w  w  . j  a  v a2  s. c o m
    v.setBackgroundDrawable(d);
}

From source file:com.fuzz.emptyhusk.prefab.ProportionalImageCellGenerator.java

@Override
public void onBindChild(@NonNull View child, @NonNull CutoutViewLayoutParams lp, @Nullable View originator) {
    child.setBackgroundResource(lp.cellBackgroundId);
    if (originator != null) {
        rvChildLength = originator.getHeight();
        if (originator.getParent() instanceof ViewGroup) {
            rvLength = ((ViewGroup) originator.getParent()).getHeight();
        }//  w  ww  .  j a  va2s .co  m
    }
    if (child instanceof ImageView) {
        GradientDrawable elongated = new GradientDrawable();
        elongated.setShape(GradientDrawable.RECTANGLE);

        int accent = ContextCompat.getColor(child.getContext(), R.color.transparentColorAccent);

        float fractionOfParent = rvLength * 1.0f / rvChildLength;

        elongated.setColor(accent);
        float proposedLength = fractionOfParent * lp.perpendicularLength;
        elongated.setSize(lp.perpendicularLength, (int) proposedLength);

        ((ImageView) child).setImageDrawable(elongated);
    }
}

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

/**
 * Update the badge value and its status
 *
 * @param text   the new text value/*from   w  w w .  j ava 2s. c  om*/
 * @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:im.vector.adapters.GroupViewHolder.java

/**
 * Refresh the holder layout// w  w  w  .j  a  v a 2  s.c  o  m
 *
 * @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:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

protected void init(Context context) {
    if (isInitialized)
        return;/* w w  w . ja v a2  s  . c o  m*/
    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:im.vector.adapters.RoomViewHolder.java

/**
 * Refresh the holder layout//from  ww w  .  j a va2s. 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:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

GradientDrawable createGradientDrawable(int color) {
    GradientDrawable gradientDrawable = new GradientDrawable();
    gradientDrawable.setShape(GradientDrawable.RECTANGLE);
    gradientDrawable.setColor(color);//from  www  . j  a v a 2 s  .c om
    return gradientDrawable;
}

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);// ww w  . j a v  a2s  .co m
    boolean dither = getAttrBoolean(context, attrs, android.R.attr.dither, false);
    gradientDrawable.setDither(dither);
}