From 65982302d30f6f86ad9531317e35110908d1140c Mon Sep 17 00:00:00 2001 From: Javier Santos Date: Mon, 20 Jun 2016 18:44:35 +0200 Subject: [PATCH] Add #22 darker overlay --- .../demo/MainActivity.java | 1 + .../MaterialStyledDialog.java | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/github/javiersantos/materialstyleddialogs/demo/MainActivity.java b/app/src/main/java/com/github/javiersantos/materialstyleddialogs/demo/MainActivity.java index 6a857d5..710bf52 100644 --- a/app/src/main/java/com/github/javiersantos/materialstyleddialogs/demo/MainActivity.java +++ b/app/src/main/java/com/github/javiersantos/materialstyleddialogs/demo/MainActivity.java @@ -161,6 +161,7 @@ public void onClick(MaterialDialog dialog, DialogAction which) { .setStyle(Style.HEADER_WITH_TITLE) .setHeaderDrawable(R.drawable.header) .withDialogAnimation(true) + .withDarkerOverlay(true) .setTitle("An awesome library?") .setDescription("Do you like this library? Check out my other Open Source libraries and apps!") .setPositive("GitHub", new MaterialDialog.SingleButtonCallback() { diff --git a/library/src/main/java/com/github/javiersantos/materialstyleddialogs/MaterialStyledDialog.java b/library/src/main/java/com/github/javiersantos/materialstyleddialogs/MaterialStyledDialog.java index 68a0108..60c6d64 100644 --- a/library/src/main/java/com/github/javiersantos/materialstyleddialogs/MaterialStyledDialog.java +++ b/library/src/main/java/com/github/javiersantos/materialstyleddialogs/MaterialStyledDialog.java @@ -34,7 +34,7 @@ public class MaterialStyledDialog { private Style style; // setStyle() private Duration duration; // withDialogAnimation() - private Boolean isIconAnimation, isDialogAnimation, isDialogDivider, isCancelable, scrollable; // withIconAnimation(), withDialogAnimation(), withDivider(), setCancelable(), setScrollable() + private boolean isIconAnimation, isDialogAnimation, isDialogDivider, isCancelable, isScrollable, isDarkerOverlay; // withIconAnimation(), withDialogAnimation(), withDivider(), setCancelable(), setScrollable(), withDarkerOverlay() private Drawable headerDrawable, iconDrawable; // setHeaderDrawable(), setIconDrawable() private Integer primaryColor, maxLines; // setHeaderColor(), setScrollable() private CharSequence title, description; // setTitle(), setDescription() @@ -52,10 +52,11 @@ public MaterialStyledDialog(Context context) { this.isIconAnimation = true; this.isDialogAnimation = false; this.isDialogDivider = false; + this.isDarkerOverlay = false; this.duration = Duration.NORMAL; this.isCancelable = true; this.primaryColor = UtilsLibrary.getPrimaryColor(context); - this.scrollable = false; + this.isScrollable = false; this.maxLines = 5; } @@ -165,6 +166,17 @@ public MaterialStyledDialog withDivider(Boolean withDivider) { return this; } + /** + * Set if the header will display a gray/darker overlay. Default: false. + * + * @param withDarkerOverlay true to apply a darker overlay, false otherwise + * @return this + */ + public MaterialStyledDialog withDarkerOverlay(Boolean withDarkerOverlay) { + this.isDarkerOverlay = withDarkerOverlay; + return this; + } + /** * Set an icon for the dialog header * @param icon to show @@ -313,24 +325,24 @@ public MaterialStyledDialog setCancelable(Boolean cancelable) { } /** - * Set if the description will be scrollable. Default: false. + * Set if the description will be isScrollable. Default: false. * - * @param scrollable true to enable scrollable description, false otherwise + * @param scrollable true to enable isScrollable description, false otherwise * @return this */ public MaterialStyledDialog setScrollable(Boolean scrollable) { - this.scrollable = scrollable; + this.isScrollable = scrollable; return this; } /** - * Set if the description will be scrollable, with custom maximum lines. Default: false, 5. + * Set if the description will be isScrollable, with custom maximum lines. Default: false, 5. * - * @param scrollable true to enable scrollable description, false otherwise + * @param scrollable true to enable isScrollable description, false otherwise * @return this */ public MaterialStyledDialog setScrollable(Boolean scrollable, Integer maxLines) { - this.scrollable = scrollable; + this.isScrollable = scrollable; this.maxLines = maxLines; return this; } @@ -419,8 +431,8 @@ private View initStyle() { // Set header color or drawable if (headerDrawable != null) { dialogHeader.setImageDrawable(headerDrawable); - if (style == Style.HEADER_WITH_TITLE) { - // Apply some darker to the header when STYLE_HEADER_TITLE is enabled + // Apply gray/darker overlay to the header if enabled + if (isDarkerOverlay) { dialogHeader.setColorFilter(Color.rgb(123, 123, 123), PorterDuff.Mode.MULTIPLY); } } @@ -453,8 +465,8 @@ private View initStyle() { dialogDescription.setText(description); // Set scrollable - dialogDescription.setVerticalScrollBarEnabled(scrollable); - if (scrollable) { + dialogDescription.setVerticalScrollBarEnabled(isScrollable); + if (isScrollable) { dialogDescription.setMaxLines(maxLines); dialogDescription.setMovementMethod(new ScrollingMovementMethod()); } else {