From 314183d6f2c80c94f4a4b53b9243c87eb489a3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Borr=C3=A1s=20Paronella?= Date: Tue, 2 Sep 2014 20:15:29 +0200 Subject: [PATCH] Add option to use hex colors, int colors (Color.RED) or color resources --- .gitignore | 33 ++++- .idea/.name | 2 +- .idea/libraries/appcompat_v7_19_1_0.xml | 10 -- .idea/libraries/support_v4_19_1_0.xml | 11 -- .idea/misc.xml | 137 ++++++++++++++++++ .idea/modules.xml | 2 +- app/app.iml | 88 ----------- app/build.gradle | 3 +- .../me/lewisdeane/ldialogs/CustomDialog.java | 59 ++++++-- .../ldialogs/CustomListAdapter.java | 2 +- .../lewisdeane/ldialogs/CustomListDialog.java | 39 +++-- .../screenshots => screenshots}/banner.jpg | Bin .../screenshots => screenshots}/screen1.png | Bin .../screenshots => screenshots}/screen2.png | Bin .../screenshots => screenshots}/screen3.png | Bin 15 files changed, 251 insertions(+), 135 deletions(-) delete mode 100644 .idea/libraries/appcompat_v7_19_1_0.xml delete mode 100644 .idea/libraries/support_v4_19_1_0.xml delete mode 100644 app/app.iml rename {app/src/main/res/screenshots => screenshots}/banner.jpg (100%) rename {app/src/main/res/screenshots => screenshots}/screen1.png (100%) rename {app/src/main/res/screenshots => screenshots}/screen2.png (100%) rename {app/src/main/res/screenshots => screenshots}/screen3.png (100%) diff --git a/.gitignore b/.gitignore index 0f885ac..85b367b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,30 @@ -.gradle -/local.properties -/.idea/workspace.xml +# Built application files +/*/build/ +# Built application files +build/ + +# Crashlytics configuations +com_crashlytics_export_strings.xml + +# Local configuration file (sdk path, etc) +local.properties + +# Gradle generated files +.gradle/ + +# Signing files +.signing/ +gradle.properties + +# User-specific configurations +.idea/* +*.iml + +# OS-specific files .DS_Store -/build +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db \ No newline at end of file diff --git a/.idea/.name b/.idea/.name index 33b64dd..7cb9bc6 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -L Dialogs \ No newline at end of file +L-Dialogs \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_19_1_0.xml b/.idea/libraries/appcompat_v7_19_1_0.xml deleted file mode 100644 index d253471..0000000 --- a/.idea/libraries/appcompat_v7_19_1_0.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_19_1_0.xml b/.idea/libraries/support_v4_19_1_0.xml deleted file mode 100644 index 3f6ff2d..0000000 --- a/.idea/libraries/support_v4_19_1_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index b153e48..51cb76a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,6 +3,143 @@ + + + + + + + + + Abstraction issues + + + Android + + + Android Lint + + + Annotations verifyingGroovy + + + Assignment issues + + + Assignment issuesGroovy + + + Bitwise operation issues + + + Class structure + + + Code maturity issues + + + Code style issues + + + Compiler issues + + + Concurrency annotation issues + + + Control FlowGroovy + + + Control flow issues + + + Data flow issues + + + Declaration redundancy + + + Dependency issues + + + Encapsulation issues + + + Error handling + + + Error handlingGroovy + + + GPath inspectionsGroovy + + + General + + + Google Cloud Endpoints + + + Groovy + + + HTML + + + Imports + + + Internationalization issues + + + J2ME issues + + + JUnit issues + + + Javadoc issues + + + Language Injection + + + Manifest + + + Naming conventions + + + Packaging issues + + + Performance issues + + + Potentially confusing code constructsGroovy + + + Probable bugs + + + Properties Files + + + Resource management issues + + + Threading issues + + + Threading issuesGroovy + + + Visibility issues + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 1f53314..ad797a2 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index 16dc91f..0000000 --- a/app/app.iml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/build.gradle b/app/build.gradle index 696ab87..78656c8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,5 +21,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:19.+' + compile 'com.android.support:appcompat-v7:20.0.0' + compile 'com.android.support:support-v4:20.0.0' } diff --git a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomDialog.java b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomDialog.java index a9c0692..3b0dfb1 100644 --- a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomDialog.java +++ b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomDialog.java @@ -44,7 +44,7 @@ public class CustomDialog extends BaseDialog { private Theme mTheme = Theme.LIGHT; // String containing the hex colours to be used on the views. - private String mPositiveColour = "", mNegativeColour = "", mTitleColour = "", mContentColour = ""; + private int mPositiveColour = 0, mNegativeColour = 0, mTitleColour = 0, mContentColour = 0; // Alignment for title to use private Alignment mTitleAlignment = Alignment.LEFT; @@ -199,10 +199,10 @@ private int getIndexFromView(View _view) { private void applyTheme() { // Apply the correct colours based on theme and user preference. - ((TextView)mViews[0]).setTextColor(Color.parseColor(this.mTitleColour.length() > 0 ? mTitleColour : (mTheme == Theme.LIGHT ? LightColours.TITLE.mColour : DarkColours.TITLE.mColour))); - ((TextView)mViews[1]).setTextColor(Color.parseColor(this.mContentColour.length() > 0 ? mContentColour : (mTheme == Theme.LIGHT ? LightColours.CONTENT.mColour : DarkColours.CONTENT.mColour))); - ((Button)mViews[2]).setTextColor(Color.parseColor(this.mPositiveColour.length() > 0 ? mPositiveColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour))); - ((Button)mViews[3]).setTextColor(Color.parseColor(this.mNegativeColour.length() > 0 ? mNegativeColour : (mTheme == Theme.LIGHT ? LightColours.BUTTON.mColour : DarkColours.BUTTON.mColour))); + ((TextView)mViews[0]).setTextColor(this.mTitleColour != 0 ? mTitleColour : (mTheme == Theme.LIGHT ? Color.parseColor(LightColours.TITLE.mColour) : Color.parseColor(DarkColours.TITLE.mColour))); + ((TextView)mViews[1]).setTextColor(this.mContentColour != 0 ? mContentColour : (mTheme == Theme.LIGHT ? Color.parseColor(LightColours.CONTENT.mColour) : Color.parseColor(DarkColours.CONTENT.mColour))); + ((Button)mViews[2]).setTextColor(this.mPositiveColour != 0 ? mPositiveColour : (mTheme == Theme.LIGHT ? Color.parseColor(LightColours.BUTTON.mColour) : Color.parseColor(DarkColours.BUTTON.mColour))); + ((Button)mViews[3]).setTextColor(this.mNegativeColour != 0 ? mNegativeColour : (mTheme == Theme.LIGHT ? Color.parseColor(LightColours.BUTTON.mColour) : Color.parseColor(DarkColours.BUTTON.mColour))); } public CustomDialog setClickListener(ClickListener mCallbacks) { @@ -244,7 +244,8 @@ public Builder(Context _context, String _title, String _positiveText) { } // Optional parameters initialised by default. - private String mNegativeText = "", mPositiveColour = "", mNegativeColour = "", mTitleColour = "", mContentColour = "", mContent = ""; + private String mNegativeText = "", mContent = ""; + int mPositiveColour = 0, mNegativeColour = 0, mTitleColour = 0, mContentColour = 0; private boolean mDarkTheme = false; private Alignment mTitleAlignment = Alignment.LEFT; @@ -259,25 +260,65 @@ public Builder negativeText(String _negativeText) { } public Builder positiveColor(String _positiveColour) { - this.mPositiveColour = _positiveColour; + this.mPositiveColour = Color.parseColor(_positiveColour); return this; } public Builder negativeColor(String _negativeColour){ - this.mNegativeColour = _negativeColour; + this.mNegativeColour = Color.parseColor(_negativeColour); return this; } public Builder titleColor(String _colour){ - this.mTitleColour = _colour; + this.mTitleColour = Color.parseColor(_colour); return this; } public Builder contentColor(String _colour){ + this.mContentColour = Color.parseColor(_colour); + return this; + } + + public Builder positiveColor(int _positiveColour) { + this.mPositiveColour = _positiveColour; + return this; + } + + public Builder negativeColor(int _negativeColour){ + this.mNegativeColour = _negativeColour; + return this; + } + + public Builder titleColor(int _colour){ + this.mTitleColour = _colour; + return this; + } + + public Builder contentColor(int _colour){ this.mContentColour = _colour; return this; } + public Builder positiveColorRes(int _positiveColour) { + this.mPositiveColour = mContext.getResources().getColor(_positiveColour); + return this; + } + + public Builder negativeColorRes(int _negativeColour){ + this.mNegativeColour = mContext.getResources().getColor(_negativeColour); + return this; + } + + public Builder titleColorRes(int _colour){ + this.mTitleColour = mContext.getResources().getColor(_colour); + return this; + } + + public Builder contentColorRes(int _colour){ + this.mContentColour = mContext.getResources().getColor(_colour); + return this; + } + public Builder darkTheme(boolean _isDark) { this.mDarkTheme = _isDark; return this; diff --git a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListAdapter.java b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListAdapter.java index aa73d4a..2c354f0 100644 --- a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListAdapter.java +++ b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListAdapter.java @@ -43,7 +43,7 @@ public View getView(final int position, View convertView, ViewGroup parent) { mItemView.setTypeface(CustomListDialog.mTypeface); try { - mItemView.setTextColor(Color.parseColor(CustomListDialog.mItemColour)); + mItemView.setTextColor(CustomListDialog.mItemColour); } catch(Exception e){} return v; diff --git a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListDialog.java b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListDialog.java index 274beef..ef5c2b5 100644 --- a/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListDialog.java +++ b/app/src/main/java/uk/me/lewisdeane/ldialogs/CustomListDialog.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; +import android.support.annotation.ColorRes; import android.view.ContextThemeWrapper; import android.view.Gravity; import android.view.LayoutInflater; @@ -26,11 +27,11 @@ public class CustomListDialog extends BaseDialog { // Array of string containing the items for the list. private String[] mItems; - // String containing hex colour of title. - private String mTitleColour = ""; + // Colour of title. + private int mTitleColour = 0; - // String containing hex colour of items. - public static String mItemColour = ""; + // Colour of items. + public static int mItemColour = 0; // Alignment containing where to align the title private Alignment mTitleAlignment = Alignment.LEFT; @@ -70,8 +71,8 @@ private CustomListDialog(Builder _builder) { this.mTheme = _builder.mIsDark ? Theme.DARK : Theme.LIGHT; this.mTitle = _builder.mTitle; this.mItems = _builder.mItems; - this.mTitleColour = _builder.mTitleColour.length() > 0 ? _builder.mTitleColour : (this.mTheme == Theme.DARK ? DarkColours.TITLE.mColour : LightColours.TITLE.mColour); - this.mItemColour = _builder.mItemColour.length() > 0 ? _builder.mItemColour : (this.mTheme == Theme.DARK ? DarkColours.ITEM.mColour : LightColours.ITEM.mColour); + this.mTitleColour = _builder.mTitleColour != 0 ? _builder.mTitleColour : (this.mTheme == Theme.DARK ? Color.parseColor(DarkColours.TITLE.mColour) : Color.parseColor(LightColours.TITLE.mColour)); + this.mItemColour = _builder.mItemColour != 0 ? _builder.mItemColour : (this.mTheme == Theme.DARK ? Color.parseColor(DarkColours.ITEM.mColour) : Color.parseColor(LightColours.ITEM.mColour)); this.mTitleAlignment = _builder.mTitleAlignment; this.mItemAlignment = _builder.mItemAlignment; @@ -124,7 +125,7 @@ private CustomListDialog setTitleProperties() { // Apply correct properties if title view is available if (mTitleView != null) { mTitleView.setText(this.mTitle); - mTitleView.setTextColor(Color.parseColor(this.mTitleColour)); + mTitleView.setTextColor(this.mTitleColour); mTitleView.setTypeface(this.mTypeface); mTitleView.setGravity(getGravityFromAlignment(this.mTitleAlignment) | Gravity.CENTER_VERTICAL); } @@ -157,7 +158,7 @@ public Builder(Context _context, String _title, String[] _items) { // Optional parameters initialised with default values. private Alignment mTitleAlignment = Alignment.LEFT, mItemAlignment = Alignment.LEFT; - private String mTitleColour = "", mItemColour = ""; + private int mTitleColour = 0, mItemColour = 0; private boolean mIsDark = false; public Builder titleAlignment(Alignment _alignment) { @@ -171,15 +172,35 @@ public Builder itemAlignment(Alignment _alignment) { } public Builder titleColour(String _colour) { - this.mTitleColour = _colour; + this.mTitleColour = Color.parseColor(_colour); return this; } public Builder itemColour(String _colour) { + this.mItemColour = Color.parseColor(_colour); + return this; + } + + public Builder titleColour(int _colour) { + this.mTitleColour = _colour; + return this; + } + + public Builder itemColour(int _colour) { this.mItemColour = _colour; return this; } + public Builder titleColourRes(@ColorRes int _colour) { + this.mTitleColour = mContext.getResources().getColor(_colour); + return this; + } + + public Builder itemColourRes(@ColorRes int _colour) { + this.mItemColour = mContext.getResources().getColor(_colour); + return this; + } + public Builder darkTheme(boolean _isDark) { this.mIsDark = _isDark; return this; diff --git a/app/src/main/res/screenshots/banner.jpg b/screenshots/banner.jpg similarity index 100% rename from app/src/main/res/screenshots/banner.jpg rename to screenshots/banner.jpg diff --git a/app/src/main/res/screenshots/screen1.png b/screenshots/screen1.png similarity index 100% rename from app/src/main/res/screenshots/screen1.png rename to screenshots/screen1.png diff --git a/app/src/main/res/screenshots/screen2.png b/screenshots/screen2.png similarity index 100% rename from app/src/main/res/screenshots/screen2.png rename to screenshots/screen2.png diff --git a/app/src/main/res/screenshots/screen3.png b/screenshots/screen3.png similarity index 100% rename from app/src/main/res/screenshots/screen3.png rename to screenshots/screen3.png