List of usage examples for android.graphics.drawable GradientDrawable setStroke
public void setStroke(int width, ColorStateList colorStateList)
Set the stroke width and color state list for the drawable.
From source file:zemin.notification.NotificationView.java
private void updateContentBackground() { Drawable background = mBackground;// w w w.j ava2 s. c om if (hasState(CONTENT_BACKGROUND_CHANGED)) { if (mContentBackground != null) { if (mShadowEnabled) { final Drawable[] layers = new Drawable[] { getResources().getDrawable(android.R.drawable.dialog_holo_light_frame), mContentBackground, }; background = new LayerDrawable(layers); int l, t, r, b; l = t = r = b = 0; for (int i = 0, size = layers.length; i < size; i++) { Rect rect = new Rect(); layers[i].getPadding(rect); l += rect.left; t += rect.top; r += rect.right; b += rect.bottom; } setContentPadding(l, t, r, b); } else { background = mContentBackground; Rect rect = new Rect(); background.getPadding(rect); setContentPadding(rect.left, rect.top, rect.right, rect.bottom); } if (mContentBackground instanceof GradientDrawable) { GradientDrawable b = (GradientDrawable) mContentBackground; b.setCornerRadius(mCornerRadius); b.setStroke(mStrokeWidth, mStrokeColor); if (mBackgroundColorAnimator != null) { mBackgroundColorAnimator.cancel(); mBackgroundColorAnimator = null; } ColorProperty colorProperty = new ColorProperty(); mBackgroundColorAnimator = ObjectAnimator.ofObject(b, colorProperty, new ArgbEvaluator(), 0, 0); mBackgroundColorAnimator.setDuration(mBackgroundTransitionTime); if (mBackgroundAlphaAnimator != null) { mBackgroundAlphaAnimator.cancel(); mBackgroundAlphaAnimator = null; } AlphaProperty alphaProperty = new AlphaProperty(); mBackgroundAlphaAnimator = ObjectAnimator.ofObject(b, alphaProperty, new IntEvaluator(), 0, 0); mBackgroundAlphaAnimator.setDuration(mBackgroundTransitionTime); } } clearState(CONTENT_BACKGROUND_CHANGED); clearState(CONTENT_BACKGROUND_CHANGED_MINOR); } else if (hasState(CONTENT_BACKGROUND_CHANGED_MINOR)) { if (mContentBackground instanceof GradientDrawable) { GradientDrawable b = (GradientDrawable) mContentBackground; b.setStroke(mStrokeWidth, mStrokeColor); mBackgroundColorAnimator.setDuration(mBackgroundTransitionTime); mBackgroundAlphaAnimator.setDuration(mBackgroundTransitionTime); } clearState(CONTENT_BACKGROUND_CHANGED_MINOR); } mBackground = background; mContentView.setBackground(background); }
From source file:com.skytree.epubtest.BookViewActivity.java
public void checkListButton(int index) { GradientDrawable gradChecked = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xff407ee6, 0xff6ca2f9 }); gradChecked.setStroke(ps(1), Color.BLUE); GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xfff4f4f4, 0xffcdcdcd }); grad.setStroke(ps(1), Color.LTGRAY); listSelectedIndex = index;// ww w.j a v a 2 s . c o m Button buttons[] = { contentListButton, bookmarkListButton, highlightListButton }; for (int i = 0; i < buttons.length; i++) { Button button = buttons[i]; button.setBackgroundDrawable(grad); } Button target = buttons[index]; target.setBackgroundDrawable(gradChecked); // show contents.. if (listSelectedIndex == 0) fillContentsList(); else if (listSelectedIndex == 1) fillBookmarkList(); else if (listSelectedIndex == 2) fillHighlightList(); }
From source file:com.skytree.epubtest.BookViewActivity.java
public void fillBookmarkList() { this.listView.removeAllViews(); ArrayList<PageInformation> pis = sd.fetchBookmarks(this.bookCode); for (int i = 0; i < pis.size(); i++) { int textColor = Color.BLACK; Theme theme = getCurrentTheme(); textColor = theme.foregroundColor; PageInformation pi = pis.get(i); SkyLayout item = new SkyLayout(this); setFrame(item, 0, 0, listBox.getWidth(), ps(80)); ImageButton mark = this.makeImageButton(9898, R.drawable.bookmarked2x, ps(50), ps(90)); item.addView(mark);/* w w w. j a v a2 s . c o m*/ setFrame(mark, ps(10), ps(5), ps(60), ps(120)); int ci = pi.chapterIndex; if (rv.isRTL()) { ci = rv.getNumberOfChapters() - ci - 1; } String chapterTitle = rv.getChapterTitle(ci); if (chapterTitle == null || chapterTitle.isEmpty()) chapterTitle = "Chapter " + ci; TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor); setFrame(chapterLabel, ps(80), ps(5), this.listBox.getWidth() - ps(80), ps(40)); item.addView(chapterLabel); TextView dateLabel = this.makeLabel(9899, pi.datetime, Gravity.LEFT, 12, textColor); setFrame(dateLabel, this.listBox.getWidth() - ps(50 + 250), ps(48), this.listBox.getWidth() - ps(40), ps(40)); View lineView = new View(this); lineView.setBackgroundColor(Color.LTGRAY); setFrame(lineView, 0, ps(79), this.listBox.getWidth(), ps(1)); item.addView(dateLabel); item.addView(lineView); item.setSkyLayoutListener(bookmarkListDelegate); item.setId(pi.code); item.data = pi; Button deleteButton = new Button(this); GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xffcf666e, 0xff671521 }); grad.setStroke(ps(2), 0xff282828); deleteButton.setBackgroundDrawable(grad); deleteButton.setText(getString(R.string.delete)); deleteButton.setTextSize(12); deleteButton.setTypeface(null, Typeface.BOLD); deleteButton.setTextColor(Color.WHITE); deleteButton.setId(pi.code); deleteButton.setVisibility(View.INVISIBLE); deleteButton.setVisibility(View.GONE); deleteButton.setOnClickListener(deleteBookmarkDelegate); int dw = ps(120); int dh = ps(50); setFrame(deleteButton, this.listView.getWidth() - dw, (ps(80) - dh) / 2, dw, dh); item.deleteControl = deleteButton; item.addView(deleteButton); this.listView.addView(item); } }
From source file:com.skytree.epubtest.BookViewActivity.java
public void fillHighlightList() { Theme theme = getCurrentTheme();/* w w w. j a v a 2 s . co m*/ int textColor = theme.foregroundColor; this.listView.removeAllViews(); Highlights highlights = sd.fetchAllHighlights(this.bookCode); for (int i = 0; i < highlights.getSize(); i++) { Highlight highlight = highlights.getHighlight(i); SkyLayout item = new SkyLayout(this); int ci = highlight.chapterIndex; if (rv.isRTL()) { ci = rv.getNumberOfChapters() - ci - 1; } String chapterTitle = rv.getChapterTitle(ci); if (chapterTitle == null || chapterTitle.isEmpty()) chapterTitle = "Chapter " + ci; TextView chapterLabel = this.makeLabel(9899, chapterTitle, Gravity.LEFT, 16, textColor); setFrame(chapterLabel, ps(20), ps(5), this.listView.getWidth() - ps(20), ps(40)); item.addView(chapterLabel); GradientDrawable textGrad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { getBrighterColor(highlight.color), getDarkerColor(highlight.color) }); TextView textLabel = this.makeLabel(9899, highlight.text, Gravity.LEFT, 16, Color.BLACK); setFrame(textLabel, ps(20), ps(5 + 40 + 5), this.listView.getWidth() - ps(20), ps(70)); textLabel.setBackgroundDrawable(textGrad); textLabel.getBackground().setAlpha(180); item.addView(textLabel); int noteHeight = 0; if (highlight.isNote && highlight.note != null && highlight.note.length() != 0 && !highlight.note.equalsIgnoreCase("null")) { TextView noteLabel = this.makeLabel(9899, highlight.note, Gravity.LEFT, 16, Color.BLACK); noteLabel.setTextColor(getDarkerColor(highlight.color)); noteHeight = 70; setFrame(noteLabel, ps(20), ps(5 + 40 + 5 + 70 + 5), this.listView.getWidth() - ps(20), ps(noteHeight)); item.addView(noteLabel); } TextView dateLabel = this.makeLabel(9899, highlight.datetime, Gravity.RIGHT, 12, textColor); int lw = this.listView.getWidth(); setFrame(dateLabel, 0, ps(5 + 40 + 5 + 70 + 5 + noteHeight + 5), lw, ps(40)); item.addView(dateLabel); int itemHeight = ps(5 + 40 + 5 + 90 + 5 + noteHeight + 5 + 15 + 5); View lineView = new View(this); lineView.setBackgroundColor(Color.LTGRAY); setFrame(lineView, 0, itemHeight - ps(1), this.listView.getWidth(), ps(1)); item.addView(lineView); setFrame(item, 0, 0, listView.getWidth(), itemHeight); item.setSkyLayoutListener(highlightListDelegate); item.setId(highlight.code); item.data = highlight; Button deleteButton = new Button(this); GradientDrawable grad = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { 0xffcf666e, 0xff671521 }); grad.setStroke(ps(2), 0xff282828); deleteButton.setBackgroundDrawable(grad); deleteButton.setText(getString(R.string.delete)); deleteButton.setTypeface(null, Typeface.BOLD); deleteButton.setTextColor(Color.WHITE); deleteButton.setTextSize(12); deleteButton.setId(highlight.code); deleteButton.setVisibility(View.INVISIBLE); deleteButton.setVisibility(View.GONE); deleteButton.setOnClickListener(deleteHighlightDelegate); int dw = ps(120); int dh = ps(50); setFrame(deleteButton, this.listView.getWidth() - dw, (itemHeight - dh) / 2, dw, dh); item.deleteControl = deleteButton; item.addView(deleteButton); this.listView.addView(item); } }