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:com.auth0.android.lock.views.ValidatedInputView.java

/**
 * Updates the view knowing if the input is valid or not.
 *
 * @param isValid if the input is valid or not for this kind of DataType.
 *//* ww  w  . ja v  a2  s  .  c o  m*/
@CallSuper
protected void updateBorder(boolean isValid) {
    ViewGroup parent = ((ViewGroup) input.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));
    int strokeColor = isValid ? R.color.com_auth0_lock_input_field_border_normal
            : R.color.com_auth0_lock_input_field_border_error;
    gd.setStroke(getResources().getDimensionPixelSize(R.dimen.com_auth0_lock_input_field_stroke_width),
            ContextCompat.getColor(getContext(), strokeColor));
    gd.setColor(ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal));
    ViewUtils.setBackground(parent, gd);

    errorDescription.setVisibility(isValid ? INVISIBLE : VISIBLE);
    requestLayout();
}

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

protected void init(Context context) {
    if (isInitialized)
        return;/*from w w  w  .  jav a2  s. co  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:io.imoji.sdk.editor.fragment.TagImojiFragment.java

public Drawable createTagDrawable() {

    GradientDrawable d = new GradientDrawable();
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.colorAccent });
    final int accentColor = a.getColor(0, Color.WHITE);
    a.recycle();//from www .jav  a  2s. co m
    d.setColor(0xB3FFFFFF & accentColor);
    d.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d.setShape(GradientDrawable.RECTANGLE);

    GradientDrawable d1 = new GradientDrawable();
    d1.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));
    d1.setStroke((int) getResources().getDimension(R.dimen.dim_0_5dp), 0x66FFFFFF & Color.BLACK);

    GradientDrawable d2 = new GradientDrawable();
    d2.setStroke((int) getResources().getDimension(R.dimen.dim_1dp), accentColor);
    d2.setCornerRadius(getResources().getDimension(R.dimen.dim_8dp));

    LayerDrawable layer = new LayerDrawable(new Drawable[] { d, d2, d1 });

    int halfDp = (int) getResources().getDimension(R.dimen.dim_0_5dp);
    int oneDp = (int) getResources().getDimension(R.dimen.dim_1dp);
    int oneAndHalf = halfDp + oneDp;

    layer.setLayerInset(2, 0, 0, 0, 0);
    layer.setLayerInset(1, halfDp, halfDp, halfDp, halfDp);
    layer.setLayerInset(0, oneAndHalf, oneAndHalf, oneAndHalf, oneAndHalf);

    return layer;
}

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 ww.  j a v  a 2s . c o 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.coolerfall.uiart.PagerSlidingTabStrip.java

/** get background drawable */
private GradientDrawable createDrawable() {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setCornerRadius(mCornerRadius);
    drawable.setColor(mNumBackground);//  w ww.j  a  v a  2 s  .  c  o  m

    return drawable;
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

public void showHideRebootMenu() {

    for (int i = 0; i < rebootFabs.length; i++) {
        if (rebootFabs[i].isShown()) {
            overlay.setVisibility(View.GONE);
            rebootFabs[i].hide();/*from  w  w  w  .  ja  va  2  s  .com*/
            rebootFabs_text[i].setVisibility(View.GONE);
        } else {
            overlay.setVisibility(View.VISIBLE);
            rebootFabs[i].show();
            rebootFabs_text[i].setVisibility(View.VISIBLE);
            GradientDrawable gd = new GradientDrawable();
            gd.setColor(getResources().getColor(R.color.button_material_dark)); // Changes this drawbale to use a single color instead of a gradient
            gd.setCornerRadius(20);
            gd.setStroke(1, 0xFF000000);
            rebootFabs_text[i].setBackgroundDrawable(gd);
        }
    }

    if (!overlay.isShown()) {
        Blurry.delete((ViewGroup) findViewById(R.id.content));
    } else {
        Blurry.with(MainViewActivity.this).radius(25).sampling(2).async().animate(200)
                .onto((ViewGroup) findViewById(R.id.content));
    }
}

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 {//w  ww.  j a  v  a 2 s .  co  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:org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment.java

private void refresh() {
    if (currentAccount == null) {
        currentAccount = AccountsPreferences.getDefaultAccount(getActivity());
        if (currentAccount == null) {
            return;
        }/*from w  w w .j  a  v a 2s  .com*/
    }

    List<AlfrescoAccount> list = AlfrescoAccountManager.retrieveAccounts(getActivity());
    // We add all extra parameters at the end of the list.
    if (currentAccount.getTypeId() == AlfrescoAccount.TYPE_ALFRESCO_CLOUD) {
        list.add(new AlfrescoAccount(AccountsAdapter.NETWORK_ITEM, getString(R.string.cloud_networks_switch),
                null, null, null, null, "0", null, "false"));
    }

    // We add profiles management option if at least there's 2 profiles
    // available
    if (configManager != null && configManager.getConfig(currentAccount.getId()) != null
            && configManager.getConfig(currentAccount.getId()).getProfiles().size() > 1) {
        list.add(new AlfrescoAccount(AccountsAdapter.PROFILES_ITEM, getString(R.string.profiles_switch), null,
                null, null, null, "0", null, "false"));
    }

    list.add(new AlfrescoAccount(AccountsAdapter.MANAGE_ITEM, getString(R.string.manage_accounts), null, null,
            null, null, "0", null, "false"));

    // Init the adapter and create the menu
    if (accountsAdapter == null) {
        accountsAdapter = new AccountsAdapter(getActivity(), list, R.layout.row_single_line, null);
    } else {
        accountsAdapter.clear();
        accountsAdapter.addAll(list);
    }

    accountsAdapter.setNotifyOnChange(false);

    ((TextView) accountsSpinnerButton.findViewById(R.id.accounts_spinner_title))
            .setText(currentAccount.getTitle());
    AccountsAdapter.displayAvatar(getActivity(), currentAccount, R.drawable.ic_account_light,
            ((ImageView) accountsSpinnerButton.findViewById(R.id.accounts_spinner_icon)));
    accountsSpinnerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listPopupWindow != null) {
                listPopupWindow.dismiss();
                listPopupWindow = null;
            } else {
                listPopupWindow = new ListPopupWindow(getActivity());
                GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
                        new int[] { 0xFF282828, 0xFF282828 });
                gd.setCornerRadius(0f);
                listPopupWindow.setBackgroundDrawable(gd);
                listPopupWindow.setAnchorView(accountsSpinnerButton);
                listPopupWindow.setAdapter(accountsAdapter);
                listPopupWindow.setOnItemClickListener(MainMenuFragment.this);
                listPopupWindow.setWidth(ListPopupWindow.WRAP_CONTENT);
                listPopupWindow.show();
            }
        }
    });

    if (OperationsFragment.canDisplay(getActivity(), currentAccount)) {
        show(R.id.menu_notifications);
        showOperationsMenu = true;
    } else {
        hide(R.id.menu_notifications);
        showOperationsMenu = false;
    }
    getActivity().invalidateOptionsMenu();
}

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  va2  s . 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);/*  w ww.  ja  v a2s . c o m*/
        gd.setCornerRadius(radius + 3); // TODO

        Util.setBackground(borderView, gd);
    }
}