Browse Source

Release 0.5.5. A few changes that can be seen in the changelog.

Aidan Follestad 10 years ago
parent
commit
cc7a216fc7

+ 7 - 0
CHANGELOG.md

@@ -1,5 +1,12 @@
 # Changelog
 
+###### Version 0.5.5
+
+> 1. Added `itemColor` and `itemColorRes` methods to the Builder for changing default list item color.
+> 2. Added `accentColor` and `accentColorRes` methods as a convenience method to the three methods `positiveColor`, `negativeColor`, and `neutralColor` (and their 'res' variants).
+> 3. Added `ThemeSingleton`, for internal use only right now unless you really think your app needs it. Used for dynamic global theming (changing at/after runtime).
+> 4. In the Builder, the `icon` method for a drawable resource ID was renamed to `iconRes` for consistency.
+
 ###### Version 0.5.4
 
 > 1. Fixes for positioning of negative button (bug that came up with the previous update that improved RTL support).

+ 7 - 0
README.md

@@ -8,6 +8,13 @@ The code you see below is also found in the sample project. You can download a A
 
 For the full history, see the [Changelog](https://github.com/afollestad/material-dialogs/blob/master/CHANGELOG.md).
 
+###### Version 0.5.5
+
+> 1. Added `itemColor` and `itemColorRes` methods to the Builder for changing default list item color.
+> 2. Added `accentColor` and `accentColorRes` methods as a convenience method to the three methods `positiveColor`, `negativeColor`, and `neutralColor` (and their 'res' variants).
+> 3. Added `ThemeSingleton`, for internal use only right now unless you really think your app needs it. Used for dynamic global theming (changing at/after runtime).
+> 4. In the Builder, the `icon` method for a drawable resource ID was renamed to `iconRes` for consistency.
+
 ###### Version 0.5.4
 
 > 1. Fixes for positioning of negative button (bug that came up with the previous update that improved RTL support).

+ 2 - 2
library/build.gradle

@@ -9,7 +9,7 @@ android {
         minSdkVersion 8
         targetSdkVersion 21
         versionCode 1
-        versionName "0.5.4"
+        versionName "0.5.5"
     }
     lintOptions {
         abortOnError false
@@ -27,7 +27,7 @@ publish {
     userOrg = 'drummer-aidan'
     groupId = 'com.afollestad'
     artifactId = 'material-dialogs'
-    version = '0.5.4'
+    version = '0.5.5'
     description = 'A library for implementing Material design styled dialogs across all versions of Android.'
     website = 'https://github.com/afollestad/material-dialogs'
     issueTracker = "${website}/issues"

+ 58 - 2
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -154,7 +154,9 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             content.setTextColor(contentColor);
         }
 
-        if (builder.theme == Theme.LIGHT) {
+        if (builder.itemColor != -1) {
+            defaultItemColor = builder.itemColor;
+        } else if (builder.theme == Theme.LIGHT) {
             defaultItemColor = Color.BLACK;
         } else {
             defaultItemColor = Color.WHITE;
@@ -852,6 +854,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         protected boolean wrapCustomViewInScroll;
         protected int dividerColor;
         protected int backgroundColor;
+        protected int itemColor;
 
         public Builder(@NonNull Context context) {
             this.context = context;
@@ -883,6 +886,27 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
                     a.recycle();
                 }
             }
+            checkSingleton();
+        }
+
+        private void checkSingleton() {
+            if (ThemeSingleton.get(false) == null) return;
+            ThemeSingleton s = ThemeSingleton.get();
+            theme(s.darkTheme ? Theme.DARK : Theme.LIGHT);
+            if (s.titleColor != -1)
+                titleColorRes(s.titleColor);
+            if (s.contentColor != -1)
+                contentColorRes(s.contentColor);
+            if (s.accentColor != -1)
+                accentColorRes(s.accentColor);
+            if (s.itemColor != -1)
+                itemColorRes(s.itemColor);
+            if (s.icon != -1)
+                iconRes(s.icon);
+            if (s.backgroundColor != -1)
+                backgroundColorRes(s.backgroundColor);
+            if (s.dividerColor != -1)
+                dividerColorRes(s.dividerColor);
         }
 
         public Builder title(@StringRes int titleRes) {
@@ -928,7 +952,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
-        public Builder icon(@DrawableRes int icon) {
+        public Builder iconRes(@DrawableRes int icon) {
             this.icon = context.getResources().getDrawable(icon);
             return this;
         }
@@ -1118,6 +1142,29 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
+        /**
+         * Convience method for setting the positive, neutral, and negative color all at once.
+         *
+         * @param colorRes The new color resource to use.
+         * @return An instance of the Builder so calls can be chained.
+         */
+        public Builder accentColorRes(@ColorRes int colorRes) {
+            return accentColor(this.context.getResources().getColor(colorRes));
+        }
+
+        /**
+         * Convience method for setting the positive, neutral, and negative color all at once.
+         *
+         * @param color The new color to use.
+         * @return An instance of the Builder so calls can be chained.
+         */
+        public Builder accentColor(int color) {
+            this.positiveColor = color;
+            this.negativeColor = color;
+            this.neutralColor = color;
+            return this;
+        }
+
         public Builder dividerColorRes(@ColorRes int colorRes) {
             return dividerColor(this.context.getResources().getColor(colorRes));
         }
@@ -1136,6 +1183,15 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
+        public Builder itemColorRes(@ColorRes int colorRes) {
+            return itemColor(this.context.getResources().getColor(colorRes));
+        }
+
+        public Builder itemColor(int color) {
+            this.itemColor = color;
+            return this;
+        }
+
         public Builder callback(ButtonCallback callback) {
             this.callback = callback;
             return this;

+ 1 - 1
library/src/main/java/com/afollestad/materialdialogs/MaterialDialogCompat.java

@@ -59,7 +59,7 @@ public class MaterialDialogCompat {
         }
 
         public Builder setIcon(@DrawableRes int iconId) {
-            builder.icon(iconId);
+            builder.iconRes(iconId);
             return this;
         }
 

+ 47 - 0
library/src/main/java/com/afollestad/materialdialogs/ThemeSingleton.java

@@ -0,0 +1,47 @@
+package com.afollestad.materialdialogs;
+
+import android.support.annotation.ColorRes;
+import android.support.annotation.DrawableRes;
+
+/**
+ * Use of this is discouraged for now; for internal use only. See the Global Theming section of the README.
+ */
+public class ThemeSingleton {
+
+    private static ThemeSingleton singleton;
+
+    public static ThemeSingleton get(boolean createIfNull) {
+        if (singleton == null && createIfNull)
+            singleton = new ThemeSingleton();
+        return singleton;
+    }
+
+    public static ThemeSingleton get() {
+        return get(true);
+    }
+
+//    <attr name="md_dark_theme" format="boolean" />
+//    <attr name="md_title_color" format="color" />
+//    <attr name="md_content_color" format="color" />
+//    <attr name="md_accent_color" format="color" />
+//    <attr name="md_item_color" format="color" />
+//    <attr name="md_icon" format="reference" />
+//    <attr name="md_background_color" format="color" />
+//    <attr name="md_divider_color" format="color" />
+
+    public boolean darkTheme = false;
+    @ColorRes
+    public int titleColor = -1;
+    @ColorRes
+    public int contentColor = -1;
+    @ColorRes
+    public int accentColor = -1;
+    @ColorRes
+    public int itemColor = -1;
+    @DrawableRes
+    public int icon = -1;
+    @ColorRes
+    public int backgroundColor = -1;
+    @ColorRes
+    public int dividerColor = -1;
+}

+ 1 - 1
sample/build.gradle

@@ -9,7 +9,7 @@ android {
         minSdkVersion 14
         targetSdkVersion 21
         versionCode 60
-        versionName "0.5.4"
+        versionName "0.5.5"
     }
     lintOptions {
         abortOnError false

+ 1 - 1
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -199,7 +199,7 @@ public class MainActivity extends ActionBarActivity implements FolderSelectorDia
 
     private void showBasicIcon() {
         new MaterialDialog.Builder(this)
-                .icon(R.drawable.ic_launcher)
+                .iconRes(R.drawable.ic_launcher)
                 .title(R.string.useGoogleLocationServices)
                 .content(R.string.useGoogleLocationServicesPrompt)
                 .positiveText(R.string.agree)