Example usage for android.graphics.drawable.shapes RoundRectShape RoundRectShape

List of usage examples for android.graphics.drawable.shapes RoundRectShape RoundRectShape

Introduction

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

Prototype

public RoundRectShape(@Nullable float[] outerRadii, @Nullable RectF inset, @Nullable float[] innerRadii) 

Source Link

Document

RoundRectShape constructor.

Usage

From source file:com.waz.zclient.utils.ViewUtils.java

public static Drawable getRoundedRect(int cornerRadius, int backgroundColor) {
    RoundRectShape rect = new RoundRectShape(new float[] { cornerRadius, cornerRadius, cornerRadius,
            cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius }, null, null);

    ShapeDrawable background = new ShapeDrawable(rect);
    background.getPaint().setColor(backgroundColor);

    return background;
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

public static Drawable createBgDrawable(int color, int rTopLeft, int rTopRight, int rBottomRight,
        int rBottomLeft) {
    float[] outerRadii = new float[8];
    outerRadii[0] = rTopLeft;//from   w w w . jav a  2  s.  c o  m
    outerRadii[1] = rTopLeft;
    outerRadii[2] = rTopRight;
    outerRadii[3] = rTopRight;
    outerRadii[4] = rBottomRight;
    outerRadii[5] = rBottomRight;
    outerRadii[6] = rBottomLeft;
    outerRadii[7] = rBottomLeft;

    RoundRectShape r = new RoundRectShape(outerRadii, null, null);

    ShapeDrawable shapeDrawable = new ShapeDrawable(r);
    shapeDrawable.getPaint().setColor(color);

    return shapeDrawable;
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

Shape getDrawableShape() {
    final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
    return new RoundRectShape(roundedCorners, null, null);
}

From source file:info.tellmetime.TellmetimeActivity.java

/**
 * Generates rainbow gradient and sets it as #mSeekBarHighlight progress drawable.
 *///from  w ww.ja va  2 s . co  m
private void drawRainbow() {
    float gradientWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 256,
            getResources().getDisplayMetrics());
    int[] colors = { 0xFFFFFFFF, 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF,
            0xFF888888, 0xFF000000 };
    LinearGradient rainbowGradient = new LinearGradient(0f, 0f, gradientWidth, 0f, colors, null,
            Shader.TileMode.CLAMP);
    float r = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    ShapeDrawable shape = new ShapeDrawable(
            new RoundRectShape(new float[] { r, r, r, r, r, r, r, r }, null, null));
    shape.getPaint().setShader(rainbowGradient);
    mSeekBarHighlight.setProgressDrawable(shape);

    // Generate bitmap with the same rainbow gradient and cache it for later use to retrieve color at given position.
    Bitmap bitmap = Bitmap.createBitmap((int) gradientWidth, 1, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL);
    paint.setShader(rainbowGradient);
    canvas.drawRect(0, 0, gradientWidth, 1, paint);
    mRainbow = bitmap;

    // Set max value to gradient's width and restore relative position.
    mSeekBarHighlight.setMax((int) (gradientWidth - 1));
    mSeekBarHighlight.setProgress((int) ((gradientWidth - 1) * mHighlightPosition));
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeSearchBox() {
    int boxColor = Color.rgb(241, 238, 229);
    int innerBoxColor = Color.rgb(246, 244, 239);
    int inlineColor = Color.rgb(133, 105, 75);

    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); // width,height
    searchBox = new SkyBox(this);
    searchBox.setBoxColor(boxColor);//from   w w  w .  ja  v a 2 s. com
    searchBox.setArrowHeight(ps(25));
    searchBox.setArrowDirection(false);
    param.leftMargin = ps(50);
    param.topMargin = ps(400);
    param.width = ps(400);
    param.height = ps(300);
    searchBox.setLayoutParams(param);
    searchBox.setArrowDirection(false);

    searchEditor = new EditText(this);
    this.setFrame(searchEditor, ps(20), ps(20), ps(400 - 140), ps(50));
    searchEditor.setTextSize(15f);
    searchEditor.setEllipsize(TruncateAt.END);
    searchEditor.setBackgroundColor(innerBoxColor);
    Drawable icon = getResources().getDrawable(R.drawable.search2x);

    Bitmap bitmap = ((BitmapDrawable) icon).getBitmap();
    Drawable fd = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, ps(28), ps(28), true));
    searchEditor.setCompoundDrawablesWithIntrinsicBounds(fd, null, null, null);
    RoundRectShape rrs = new RoundRectShape(
            new float[] { ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15), ps(15) }, null, null);
    SkyDrawable sd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 2);
    searchEditor.setBackgroundDrawable(sd);
    searchEditor.setHint(getString(R.string.searchhint));
    searchEditor.setPadding(ps(20), ps(5), ps(10), ps(5));
    searchEditor.setLines(1);
    searchEditor.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchEditor.setSingleLine();
    searchEditor.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_GO
                    || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_NEXT) {
                String key = searchEditor.getText().toString();
                if (key != null && key.length() > 1) {
                    showIndicator();
                    clearSearchBox(1);
                    makeFullScreen();
                    rv.searchKey(key);
                }
            }
            return false;
        }
    });
    searchBox.contentView.addView(searchEditor);

    Button cancelButton = new Button(this);
    this.setFrame(cancelButton, ps(290), ps(20), ps(90), ps(50));
    cancelButton.setText(getString(R.string.cancel));
    cancelButton.setId(3001);
    RoundRectShape crs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable cd = new SkyDrawable(crs, innerBoxColor, inlineColor, 2);
    cancelButton.setBackgroundDrawable(cd);
    cancelButton.setTextSize(12);
    cancelButton.setOnClickListener(listener);
    cancelButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(cancelButton));

    searchBox.contentView.addView(cancelButton);

    searchScrollView = new ScrollView(this);
    RoundRectShape rvs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable rd = new SkyDrawable(rvs, innerBoxColor, inlineColor, 2);
    searchScrollView.setBackgroundDrawable(rd);
    this.setFrame(searchScrollView, ps(20), ps(100), ps(360), ps(200));
    this.searchBox.contentView.addView(searchScrollView);

    searchResultView = new LinearLayout(this);
    searchResultView.setOrientation(LinearLayout.VERTICAL);
    searchScrollView.addView(searchResultView,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    this.ePubView.addView(searchBox);
    this.hideSearchBox();
}

From source file:com.skytree.epubtest.BookViewActivity.java

public void makeFontBox() {
    int boxColor = Color.rgb(241, 238, 229);
    int innerBoxColor = Color.rgb(246, 244, 239);
    int inlineColor = Color.rgb(133, 105, 75);

    int width = 450;
    int height = 500;
    fontBox = new SkyBox(this);
    fontBox.setBoxColor(boxColor);/*w ww  .  j a v  a2 s .c o m*/
    fontBox.setArrowHeight(ps(25));
    fontBox.setArrowDirection(false);
    setFrame(fontBox, ps(50), ps(200), ps(width), ps(height));

    ScrollView fontBoxScrollView = new ScrollView(this);
    this.setFrame(fontBoxScrollView, ps(5), ps(10), ps(440), ps(height - 50));
    fontBox.contentView.addView(fontBoxScrollView); // NEW

    SkyLayout contentLayout = new SkyLayout(this);
    fontBoxScrollView.addView(contentLayout,
            new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    // #1 first make brightness controller
    // brView is the box containing the bright slider. 
    int FY = 10;
    View brView = new View(this);
    RoundRectShape rrs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable srd = new SkyDrawable(rrs, innerBoxColor, inlineColor, 1);
    brView.setBackgroundDrawable(srd);
    setFrame(brView, ps(20), ps(FY), ps(width - 40), ps(53));
    contentLayout.addView(brView);
    // darker and brighter icons
    int SBS = 60;
    ImageButton sbb = this.makeImageButton(9005, R.drawable.brightness2x, ps(SBS), ps(SBS));
    setFrame(sbb, ps(50), ps(FY), ps(SBS), ps(SBS));
    sbb.setAlpha(200);
    int BBS = 70;
    ImageButton bbb = this.makeImageButton(9006, R.drawable.brightness2x, ps(BBS), ps(BBS));
    setFrame(bbb, ps(width - 110), ps(FY - 5), ps(BBS), ps(BBS));
    bbb.setAlpha(200);
    contentLayout.addView(sbb);
    contentLayout.addView(bbb);
    // making bright slider      
    brightBar = new SeekBar(this);
    brightBar.setMax(999);
    brightBar.setId(997);
    brightBar.setBackgroundColor(Color.TRANSPARENT);
    brightBar.setOnSeekBarChangeListener(new SeekBarDelegate());
    brightBar.setProgressDrawable(new LineDrawable(Color.rgb(160, 160, 160), ps(10)));
    brightBar.setThumbOffset(-1);
    setFrame(brightBar, ps(100), ps(FY + 4), ps(width - 210), ps(50));
    contentLayout.addView(brightBar);

    // #2 second make decrese/increse font size buttons
    // decrease font size Button
    int FBY = 80;
    decreaseButton = new Button(this);
    setFrame(decreaseButton, ps(20), ps(FBY), ps(width - 40 - 20) / 2, ps(60));
    decreaseButton.setText(getString(R.string.chara));
    decreaseButton.setGravity(Gravity.CENTER);
    decreaseButton.setTextSize(14);
    decreaseButton.setId(5000);
    RoundRectShape drs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1);
    decreaseButton.setBackgroundDrawable(drd);
    decreaseButton.setOnClickListener(listener);
    decreaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(decreaseButton));
    contentLayout.addView(decreaseButton);
    // inccrease font size Button
    increaseButton = new Button(this);
    setFrame(increaseButton, ps(10 + width / 2), ps(FBY), ps(width - 40 - 20) / 2, ps(60));
    increaseButton.setText(getString(R.string.chara));
    increaseButton.setTextSize(18);
    increaseButton.setGravity(Gravity.CENTER);
    increaseButton.setId(5001);
    RoundRectShape irs = new RoundRectShape(
            new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
    SkyDrawable ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1);
    increaseButton.setBackgroundDrawable(ird);
    increaseButton.setOnClickListener(listener);
    increaseButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(increaseButton));
    contentLayout.addView(increaseButton);

    // # 3 make the button to increase/decrese line spacing. 
    int LBY = 145;
    // deccrease line space Button
    decreaseLineSpaceButton = this.makeImageButton(9005, R.drawable.decline2x, ps(30), ps(30));
    setFrame(decreaseLineSpaceButton, ps(20), ps(LBY), ps(width - 40 - 20) / 2, ps(60));
    decreaseLineSpaceButton.setId(4000);
    drs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null,
            null);
    drd = new SkyDrawable(drs, innerBoxColor, inlineColor, 1);
    decreaseLineSpaceButton.setBackgroundDrawable(drd);
    decreaseLineSpaceButton.setOnClickListener(listener);
    decreaseLineSpaceButton
            .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(decreaseLineSpaceButton));
    contentLayout.addView(decreaseLineSpaceButton);
    // inccrease line space Button        
    increaseLineSpaceButton = this.makeImageButton(9005, R.drawable.incline2x, ps(30), ps(30));
    setFrame(increaseLineSpaceButton, ps(10 + width / 2), ps(LBY), ps(width - 40 - 20) / 2, ps(60));
    increaseLineSpaceButton.setId(4001);
    irs = new RoundRectShape(new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null,
            null);
    ird = new SkyDrawable(irs, innerBoxColor, inlineColor, 1);
    increaseLineSpaceButton.setBackgroundDrawable(ird);
    increaseLineSpaceButton.setOnClickListener(listener);
    increaseLineSpaceButton
            .setOnTouchListener(new ImageButtonHighlighterOnTouchListener(increaseLineSpaceButton));
    contentLayout.addView(increaseLineSpaceButton);

    // #4 make themes selector.  
    int TY = 220;
    int TH = 70;
    int TW = (width - 40 - 20) / 3;

    HorizontalScrollView themeScrollView = new HorizontalScrollView(this);
    themesView = new LinearLayout(this);
    themesView.setOrientation(LinearLayout.HORIZONTAL);

    themeScrollView.addView(themesView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    for (int i = 0; i < this.themes.size(); i++) {
        Theme theme = themes.get(i);
        Button themeButton = new Button(this);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ps(TW), ps(TH));
        layoutParams.setMargins(0, 0, 24, 0);
        themesView.addView(themeButton, layoutParams);
        RoundRectShape rs = new RoundRectShape(
                new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
        SkyDrawable brd = new SkyDrawable(rs, theme.backgroundColor, Color.BLACK, 1);
        themeButton.setBackgroundDrawable(brd);
        themeButton.setText(theme.name);
        themeButton.setTextColor(theme.foregroundColor);
        themeButton.setId(7000 + i);
        themeButton.setOnClickListener(listener);
    }

    this.setFrame(themeScrollView, ps(20), ps(TY), ps(width - 40), ps(90));
    contentLayout.addView(themeScrollView);

    // #5 font list box
    int SY = 310;
    int fontButtonHeight = 80;
    int fontListHeight;
    fontListHeight = fontButtonHeight * fonts.size();
    fontListView = new LinearLayout(this);
    fontListView.setOrientation(LinearLayout.VERTICAL);
    contentLayout.addView(fontListView);
    this.setFrame(fontListView, ps(20), ps(SY), ps(width - 40), ps(fontListHeight));
    int inlineColor2 = Color.argb(140, 133, 105, 75);

    for (int i = 0; i < fonts.size(); i++) {
        CustomFont customFont = fonts.get(i);
        Button fontButton = new Button(this);
        fontButton.setText(customFont.fontFaceName);
        fontButton.setTextSize(20);
        Typeface tf = null;
        if (customFont.fontFileName == null || customFont.fontFileName.isEmpty()) {
            tf = this.getTypeface(customFont.fontFaceName, Typeface.BOLD);
        } else {
            tf = Typeface.createFromAsset(getAssets(), "fonts/" + customFont.fontFileName);
        }
        if (tf != null)
            fontButton.setTypeface(tf);
        fontButton.setId(5100 + i);
        RoundRectShape rs = new RoundRectShape(
                new float[] { ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5), ps(5) }, null, null);
        SkyDrawable brd = new SkyDrawable(rs, innerBoxColor, inlineColor2, 1);
        fontButton.setBackgroundDrawable(brd);
        this.setFrame(fontButton, ps(0), ps(0), ps(width - 40), ps(fontButtonHeight));
        fontListView.addView(fontButton);
        fontButton.setOnClickListener(listener);
        fontButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(fontButton));
    }

    this.ePubView.addView(fontBox);
    this.hideFontBox();
}