Example usage for android.graphics.drawable GradientDrawable GradientDrawable

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

Introduction

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

Prototype

public GradientDrawable() 

Source Link

Usage

From source file:rus.cpuinfo.Ui.Fragments.Base.CpuInfoBaseTabFragment.java

@Nullable
@Override/*from  ww  w.  j  a va 2s . com*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_tab, container, false);
    ButterKnife.bind(this, v);

    mViewPager.setAdapter(createAdapter());
    mTabLayout.setupWithViewPager(mViewPager);

    View root = mTabLayout.getChildAt(0);

    if (root instanceof LinearLayout) {

        LinearLayout linearLayout = ((LinearLayout) root);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

        GradientDrawable drawable = new GradientDrawable();
        drawable.setSize(2, 0);

        linearLayout.setDividerDrawable(drawable);
    }

    if (savedInstanceState != null) {
        mCurrentItem = savedInstanceState.getInt(SELECTED_TAB);
    }

    return v;
}

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);
    }/*from  ww  w . j  a va2 s . co 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:org.dalol.orthodoxmezmurmedia.utilities.widgets.RecyclerViewFastIndexer.java

protected void init(Context context) {
    if (isInitialized)
        return;/*from ww  w . j ava  2s .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:com.intirix.cloudpasswordmanager.pages.settings.SavePasswordOptionsViewHolder.java

private void removeBorder(View view) {
    //use a GradientDrawable with only one color set, to make it a solid color
    GradientDrawable border = new GradientDrawable();
    border.setColor(0xFFFFFFFF); //white background
    border.setStroke(0, 0xFF000000); //black border with full opacity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackgroundDrawable(border);
    } else {//  w w  w  . j a  va  2  s  .  c  om
        view.setBackground(border);
    }
}

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:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {/*from   w w w .j av  a2  s  . c o m*/
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:com.tooltip.Tooltip.java

private View getContentView(Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);

    int padding = (int) builder.mPadding;

    TextView textView = new TextView(builder.mContext);
    TextViewCompat.setTextAppearance(textView, builder.mTextAppearance);
    textView.setText(builder.mText);//from  w w w  .  ja v a  2s . com
    textView.setPadding(padding, padding, padding, padding);
    textView.setLineSpacing(builder.mLineSpacingExtra, builder.mLineSpacingMultiplier);
    textView.setTypeface(builder.mTypeface, builder.mTextStyle);

    if (builder.mTextSize >= 0) {
        textView.setTextSize(TypedValue.TYPE_NULL, builder.mTextSize);
    }
    if (builder.mTextColor != null) {
        textView.setTextColor(builder.mTextColor);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackground(drawable);
    } else {
        //noinspection deprecation
        textView.setBackgroundDrawable(drawable);
    }

    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textView.setLayoutParams(textViewParams);

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) Util.dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(textView);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(textView);
    }

    mContentView.setOnClickListener(mClickListener);
    mContentView.setOnLongClickListener(mLongClickListener);

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

private void setBorderAttrs() {
    borderView = findViewById(R.id.border);
    borderParams = (RelativeLayout.LayoutParams) borderView.getLayoutParams();
    borderParams.setMargins(margin - borderSize, margin - borderSize, margin - borderSize, margin - borderSize);

    if (borderSize > 0) {
        GradientDrawable gd = new GradientDrawable();
        gd.setColor(borderColor);//from w w  w.  jav a2  s  .  co  m
        gd.setCornerRadius(radius + 3); // TODO

        Util.setBackground(borderView, gd);
    }
}

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

/**
 * Refresh the holder layout/*from   w ww  .j  a  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:com.esri.android.ecologicalmarineunitexplorer.watercolumn.WaterColumnFragment.java

private StateListDrawable buildStateList(int emuName) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    GradientDrawable defaultShape = new GradientDrawable();
    int color = Color.parseColor(EmuHelper.getColorForEMUCluster(getContext(), emuName));
    defaultShape.setColor(color);/*ww  w.j  a  v  a  2 s  .c o m*/

    GradientDrawable selectedPressShape = new GradientDrawable();
    selectedPressShape.setColor(color);
    selectedPressShape.setStroke(5, Color.parseColor("#f4f442"));

    stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape);
    stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape);

    return stateListDrawable;
}