From 03878de43643ddd63449d9a97f1b8bf56f90132c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 18 May 2019 13:19:29 +0300 Subject: [PATCH] multi-color progress indicators --- .../ui/MobileLedgerListFragment.java | 2 +- .../ui/activity/MainActivity.java | 5 +++-- .../net/ktnx/mobileledger/utils/Colors.java | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java index 654bd4db..d53cc6f0 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java @@ -35,7 +35,7 @@ public class MobileLedgerListFragment extends Fragment { protected MainActivity mActivity; protected RecyclerView root; protected void themeChanged(Integer counter) { - swiper.setColorSchemeColors(Colors.primary); + swiper.setColorSchemeColors(Colors.getColors()); } public void onBackgroundTaskRunningChanged(Boolean isRunning) { if (mActivity == null) return; diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index be2702fb..afa9c71e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -577,8 +577,9 @@ public class MainActivity extends ProfileThemedActivity { public void onRetrieveStart() { ProgressBar progressBar = findViewById(R.id.transaction_list_progress_bar); bTransactionListCancelDownload.setEnabled(true); - progressBar.setIndeterminateTintList(ColorStateList.valueOf(Colors.primary)); - progressBar.setProgressTintList(ColorStateList.valueOf(Colors.primary)); + ColorStateList csl = Colors.getColorStateList(); + progressBar.setIndeterminateTintList(csl); + progressBar.setProgressTintList(csl); progressBar.setIndeterminate(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false); else progressBar.setProgress(0); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java index fb4298b2..f0db19eb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java @@ -18,6 +18,7 @@ package net.ktnx.mobileledger.utils; import android.app.Activity; +import android.content.res.ColorStateList; import android.content.res.Resources; import android.util.TypedValue; @@ -30,6 +31,7 @@ import java.util.Locale; import androidx.annotation.ColorInt; import androidx.annotation.ColorLong; +import androidx.annotation.NonNull; import androidx.lifecycle.MutableLiveData; import static java.lang.Math.abs; @@ -39,6 +41,7 @@ public class Colors { public static final int DEFAULT_HUE_DEG = 261; private static final float blueLightness = 0.665f; private static final float yellowLightness = 0.350f; + private static final int[][] EMPTY_STATES = new int[][]{new int[0]}; public static @ColorInt int accent; @ColorInt @@ -189,4 +192,22 @@ public class Colors { refreshColors(activity.getTheme()); } + public static @NonNull + ColorStateList getColorStateList() { + return getColorStateList(profileThemeId); + } + public static @NonNull + ColorStateList getColorStateList(int hue) { + return new ColorStateList(EMPTY_STATES, getColors(hue)); + } + public static int[] getColors() { + return getColors(profileThemeId); + } + public static int[] getColors(int hue) { + int[] colors = new int[]{0, 0, 0, 0, 0, 0}; + for (int i = 0; i < 6; i++, hue = (hue + 60) % 360) { + colors[i] = getPrimaryColorForHue(hue); + } + return colors; + } } -- 2.39.5