From a01735ef1c8b6cb957545bdf59753c7a1fddccd9 Mon Sep 17 00:00:00 2001 From: David Prodinger Date: Sun, 7 Jun 2020 16:44:20 +0200 Subject: [PATCH] Text Selected/Unselected Color (#6) * Add option for unselected text color * update README.md --- README.md | 48 +++---- build.gradle | 2 +- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- sample/build.gradle | 8 +- .../dpro/weekdaysselector/MainActivity.java | 11 +- sample/src/main/res/layout/activity_main.xml | 8 +- weekdaysselector/build.gradle | 9 +- .../widgets/OnWeekdaysChangeListener.java | 1 - .../java/com/dpro/widgets/WeekdaysPicker.java | 128 ++++++++++-------- .../src/main/res/values/attrs.xml | 1 + 11 files changed, 129 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 9748676..cb0cd7a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Add the dependency ```groovy dependencies { - implementation 'com.github.DavidProdinger:weekdays-selector:1.1.0' + implementation 'com.github.DavidProdinger:weekdays-selector:1.1.1' } ``` @@ -49,7 +49,7 @@ Add the dependency com.github.DavidProdinger weekdays-selector - 1.1.0 + 1.1.1 ``` @@ -98,6 +98,7 @@ public class MainActivity extends AppCompatActivity { * `highlight_color`: Color of selected days and unselected Text (default=Color.RED) * `background_color`: Background-Color of unselected days (default=Color.LTGRAY) * `text_color`: Color of selected days text (default=Color.WHITE) +* `text_unselected_color`: Color of unselected days text (default=`highlight_color`) * `sunday_first_day`: Starting with Sunday or Monday (default=true) * `show_weekend`: Display weekend (Satuarday and Sunday) (default=true) * `weekenddarker`: Allows that weekend has another color (default=false) @@ -120,32 +121,32 @@ WeekdaysPicker widget = (WeekdaysPicker) findViewById(R.id.weekdays); ```java widget.setOnWeekdaysChangeListener(new OnWeekdaysChangeListener() { - @Override - public void onChange(View view, int clickedDayOfWeek, List selectedDays) { - // Do Something - } - }); + @Override + public void onChange(View view, int clickedDayOfWeek, List selectedDays) { + // Do Something + } +}); ``` #### OnWeekRecurrenceChange Listener ```java widget.setOnWeekRecurrenceChangeListener(new OnWeekRecurrenceChangeListener() { - @Override - public void onWeekChange(View view, List selectedDays, int even_week) { - // Do something else - switch (even_week) { - case WeekdaysPicker.ALL: - // if all weeks selected - break; - case WeekdaysPicker.ODD: - // if odd weeks selected - break; - case WeekdaysPicker.EVEN: - // if even weeks selected - break; - } - } - }); + @Override + public void onWeekChange(View view, List selectedDays, int even_week) { + // Do something else + switch (even_week) { + case WeekdaysPicker.ALL: + // if all weeks selected + break; + case WeekdaysPicker.ODD: + // if odd weeks selected + break; + case WeekdaysPicker.EVEN: + // if even weeks selected + break; + } + } +}); ``` ### Get selected Days @@ -272,6 +273,7 @@ widget.setHighlightColor(Color.RED); widget.setBackgroundColor(Color.LTGRAY); widget.setWeekendColor(Color.GRAY); widget.setTextColor(Color.WHITE); +widget.setTextUnselectedColor(Color.WHITE); widget.setSundayFirstDay(true); widget.setShowWeekend(true); widget.setRecurrence(true); diff --git a/build.gradle b/build.gradle index ae9fbaf..7d34715 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:4.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle.properties b/gradle.properties index 743d692..8de5058 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,8 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f6a2dad..f0cf563 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Apr 04 16:14:46 CEST 2018 +#Sun Jun 07 15:37:41 CEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index a94471f..fafacd1 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' + compileSdkVersion 29 + buildToolsVersion '29.0.3' defaultConfig { applicationId "com.dpro.weekdaysselector" minSdkVersion 14 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" } @@ -20,6 +20,6 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation project(":weekdaysselector") } diff --git a/sample/src/main/java/com/dpro/weekdaysselector/MainActivity.java b/sample/src/main/java/com/dpro/weekdaysselector/MainActivity.java index 27fc898..aa6ef00 100644 --- a/sample/src/main/java/com/dpro/weekdaysselector/MainActivity.java +++ b/sample/src/main/java/com/dpro/weekdaysselector/MainActivity.java @@ -2,19 +2,19 @@ import android.graphics.Color; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.CompoundButton; import android.widget.LinearLayout; import android.widget.Switch; import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; + import com.dpro.widgets.OnWeekRecurrenceChangeListener; import com.dpro.widgets.OnWeekdaysChangeListener; import com.dpro.widgets.WeekdaysPicker; import java.util.Arrays; -import java.util.Calendar; import java.util.LinkedHashMap; import java.util.List; @@ -23,6 +23,7 @@ import static java.util.Calendar.SUNDAY; import static java.util.Calendar.THURSDAY; import static java.util.Calendar.TUESDAY; +import static java.util.Calendar.WEDNESDAY; public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener { @@ -37,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - selected_days = Arrays.asList(Calendar.SATURDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.SUNDAY); + selected_days = Arrays.asList(SATURDAY, WEDNESDAY, THURSDAY, SUNDAY); mp.put(SUNDAY, true); mp.put(SATURDAY, true); @@ -80,6 +81,7 @@ public void onWeekChange(View view, List selectedDays, int even_week) { ((Switch) findViewById(R.id.sw_background_color)).setOnCheckedChangeListener(this); ((Switch) findViewById(R.id.sw_weekend_color)).setOnCheckedChangeListener(this); ((Switch) findViewById(R.id.sw_text_color)).setOnCheckedChangeListener(this); + ((Switch) findViewById(R.id.sw_text_unselected_color)).setOnCheckedChangeListener(this); ((Switch) findViewById(R.id.sw_sunday_first)).setOnCheckedChangeListener(this); ((Switch) findViewById(R.id.sw_show_weekend)).setOnCheckedChangeListener(this); ((Switch) findViewById(R.id.sw_recurrence)).setOnCheckedChangeListener(this); @@ -120,6 +122,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { case R.id.sw_text_color: widget.setTextColor(isChecked ? Color.BLUE : Color.WHITE); break; + case R.id.sw_text_unselected_color: + widget.setTextUnselectedColor(isChecked ? Color.GRAY : Color.RED); + break; case R.id.sw_sunday_first: widget.setSundayFirstDay(isChecked); break; diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 8851d2d..7b924c3 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -76,7 +76,13 @@ android:id="@+id/sw_text_color" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="Text highlight Color" /> + android:text="Text selected Color" /> + + * Created by David Prodinger on 24.10.2017. */ - public interface OnWeekdaysChangeListener { /** * @param view View of Weekdayspicker diff --git a/weekdaysselector/src/main/java/com/dpro/widgets/WeekdaysPicker.java b/weekdaysselector/src/main/java/com/dpro/widgets/WeekdaysPicker.java index c810bf8..d6bcc23 100644 --- a/weekdaysselector/src/main/java/com/dpro/widgets/WeekdaysPicker.java +++ b/weekdaysselector/src/main/java/com/dpro/widgets/WeekdaysPicker.java @@ -12,7 +12,6 @@ import android.graphics.drawable.shapes.OvalShape; import android.graphics.drawable.shapes.RectShape; import android.os.Build; -import android.support.annotation.ColorInt; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; @@ -23,13 +22,14 @@ import android.widget.LinearLayout; import android.widget.Spinner; +import androidx.annotation.ColorInt; + import com.amulyakhare.textdrawable.TextDrawable; import java.text.DateFormatSymbols; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -67,6 +67,7 @@ public class WeekdaysPicker extends LinearLayout { private int mHighlightColor = Color.RED; private TextDrawable.IBuilder selectedBuilder; private int mTextColor = Color.WHITE; + private int mTextUnselectedColor = mHighlightColor; private int mBackgroundColor = Color.LTGRAY; private TextDrawable.IBuilder unselectedBuilder; private TextDrawable.IBuilder unselectedWeekendBuilder; @@ -184,6 +185,7 @@ private void initView(AttributeSet attrs) { mBackgroundColor = a.getColor(R.styleable.WeekdaysPicker_background_color, Color.LTGRAY); mWeekendColor = a.getColor(R.styleable.WeekdaysPicker_weekend_color, Color.GRAY); mTextColor = a.getColor(R.styleable.WeekdaysPicker_text_color, Color.WHITE); + mTextUnselectedColor = a.getColor(R.styleable.WeekdaysPicker_text_unselected_color, mHighlightColor); sunday_first_day = a.getBoolean(R.styleable.WeekdaysPicker_sunday_first_day, true); weekend = a.getBoolean(R.styleable.WeekdaysPicker_show_weekend, true); fullSize = a.getBoolean(R.styleable.WeekdaysPicker_full_size, false); @@ -289,34 +291,29 @@ private void createDayViews(LinkedHashMap daySet) { if (sunday_first_day && daySet.containsKey(SUNDAY)) { LinkedHashMap map = new LinkedHashMap<>(); - Iterator it = daySet.entrySet().iterator(); int x = 0; map.put(SUNDAY, daySet.get(SUNDAY)); - while (it.hasNext()) { + for (Map.Entry entry : daySet.entrySet()) { if (x == 0) { x++; continue; } - Map.Entry entry = (Map.Entry) it.next(); - map.put((int) entry.getKey(), (boolean) entry.getValue()); + map.put(entry.getKey(), entry.getValue()); x++; } daySet = map; } - Iterator it = daySet.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); + for (Map.Entry entry : daySet.entrySet()) { System.out.println("ID " + entry.getKey()); - if (!weekend && ((int) entry.getKey() == SATURDAY || (int) entry.getKey() == SUNDAY)) { - //Weekend - } else { + if (weekend || (entry.getKey() != SATURDAY && entry.getKey() != SUNDAY)) { if (findViewWithTag(entry.getKey()) != null) { - setDaySelected((ImageView) findViewWithTag(entry.getKey()), (boolean) entry.getValue()); + setDaySelected((ImageView) findViewWithTag(entry.getKey()), entry.getValue()); } else { - createDayView((int) entry.getKey(), (boolean) entry.getValue()); + createDayView(entry.getKey(), entry.getValue()); } } + } } @@ -496,7 +493,7 @@ private void initColors() { unSelectedDayBackgroundColor = mBackgroundColor;//Color.LTGRAY; unSelectedWeekendColor = weekendDarker ? mWeekendColor : mBackgroundColor; //Color.GRAY || Color.LTGRAY selectedTextColor = mTextColor;//Color.WHITE; - unSelectedTextColor = mHighlightColor; + unSelectedTextColor = mTextUnselectedColor; if (mWeekendTextColorChanged) { unSelectedWeekendTextColor = mWeekendTextColor; @@ -798,15 +795,6 @@ public void setFullSize(boolean b) { fullSize = b; } - /** - * Set the highlightcolor - * - * @param color - */ - public void setHighlightColor(String color) { - mHighlightColor = Color.parseColor(color); - } - /** * get highlightcolor */ @@ -819,17 +807,17 @@ public int getHighlightColor() { * * @param color */ - public void setHighlightColor(@ColorInt int color) { - mHighlightColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); + public void setHighlightColor(String color) { + mHighlightColor = Color.parseColor(color); } /** - * Set the backgroundcolor + * Set the highlightcolor * * @param color */ - public void setBackgroundColor(String color) { - mBackgroundColor = Color.parseColor(color); + public void setHighlightColor(@ColorInt int color) { + mHighlightColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -844,17 +832,17 @@ public int getBackgroundColor() { * * @param color */ - public void setBackgroundColor(@ColorInt int color) { - mBackgroundColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); + public void setBackgroundColor(String color) { + mBackgroundColor = Color.parseColor(color); } /** - * Set the weekendcolor + * Set the backgroundcolor * * @param color */ - public void setWeekendColor(String color) { - mWeekendColor = Color.parseColor(color); + public void setBackgroundColor(@ColorInt int color) { + mBackgroundColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -869,17 +857,17 @@ public int getWeekendColor() { * * @param color */ - public void setWeekendColor(@ColorInt int color) { - mWeekendColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); + public void setWeekendColor(String color) { + mWeekendColor = Color.parseColor(color); } /** - * Set the textcolor + * Set the weekendcolor * * @param color */ - public void setTextColor(String color) { - mTextColor = Color.parseColor(color); + public void setWeekendColor(@ColorInt int color) { + mWeekendColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -889,6 +877,15 @@ public int getTextColor() { return mTextColor; } + /** + * Set the textcolor + * + * @param color + */ + public void setTextColor(String color) { + mTextColor = Color.parseColor(color); + } + /** * Set the textcolor * @@ -899,13 +896,28 @@ public void setTextColor(@ColorInt int color) { } /** - * Set the weekendtextcolor + * get text unselected color + */ + public int getTextUnselectedColor() { + return mTextUnselectedColor; + } + + /** + * Set the text unselected color * * @param color */ - public void setWeekendTextColor(String color) { - mWeekendTextColorChanged = true; - mWeekendTextColor = Color.parseColor(color); + public void setTextUnselectedColor(String color) { + mTextUnselectedColor = Color.parseColor(color); + } + + /** + * Set the text unselected color + * + * @param color + */ + public void setTextUnselectedColor(@ColorInt int color) { + mTextUnselectedColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -920,18 +932,19 @@ public int getWeekendTextColor() { * * @param color */ - public void setWeekendTextColor(@ColorInt int color) { + public void setWeekendTextColor(String color) { mWeekendTextColorChanged = true; - mWeekendTextColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); + mWeekendTextColor = Color.parseColor(color); } /** - * Set the bordercolor + * Set the weekendtextcolor * * @param color */ - public void setBorderColor(String color) { - mBorderColor = Color.parseColor(color); + public void setWeekendTextColor(@ColorInt int color) { + mWeekendTextColorChanged = true; + mWeekendTextColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -946,17 +959,17 @@ public int getBorderColor() { * * @param color */ - public void setBorderColor(@ColorInt int color) { - mBorderColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); + public void setBorderColor(String color) { + mBorderColor = Color.parseColor(color); } /** - * Set the borderhighlightcolor + * Set the bordercolor * * @param color */ - public void setBorderHighlightColor(String color) { - mBorderHighlightColor = Color.parseColor(color); + public void setBorderColor(@ColorInt int color) { + mBorderColor = Color.argb(255, Color.red(color), Color.green(color), Color.blue(color)); } /** @@ -966,6 +979,15 @@ public int getBorderHighlightColor() { return mBorderHighlightColor; } + /** + * Set the borderhighlightcolor + * + * @param color + */ + public void setBorderHighlightColor(String color) { + mBorderHighlightColor = Color.parseColor(color); + } + /** * Set the borderhighlightcolor * diff --git a/weekdaysselector/src/main/res/values/attrs.xml b/weekdaysselector/src/main/res/values/attrs.xml index 000773f..9c0d6c3 100644 --- a/weekdaysselector/src/main/res/values/attrs.xml +++ b/weekdaysselector/src/main/res/values/attrs.xml @@ -5,6 +5,7 @@ +