From: Damyan Ivanov Date: Sun, 17 Feb 2019 20:12:02 +0000 (+0200) Subject: use Colors.* for run-time color control X-Git-Tag: v0.7~71 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=254ccdbeec488fb1309513a3ff9be28f9b06855c;p=mobile-ledger.git use Colors.* for run-time color control --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index da678a6a..52b27229 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -20,7 +20,6 @@ package net.ktnx.mobileledger.ui.account_summary; import android.content.Context; import android.content.res.Resources; import android.graphics.Typeface; -import android.os.Build; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -33,6 +32,7 @@ import android.widget.TextView; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.LedgerAccount; +import net.ktnx.mobileledger.utils.Colors; import java.util.List; @@ -68,14 +68,10 @@ class AccountSummaryAdapter extends RecyclerView.Adapter= Build.VERSION_CODES.M) holder.row - .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme())); - else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg)); + holder.row.setBackgroundColor(Colors.tableRowDarkBG); } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row - .setBackgroundColor(rm.getColor(R.color.drawer_background, ctx.getTheme())); - else holder.row.setBackgroundColor(rm.getColor(R.color.drawer_background)); + holder.row.setBackgroundColor(Colors.tableRowLightBG); } holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 2fcfe67f..04cde356 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -40,6 +40,7 @@ import net.ktnx.mobileledger.model.LedgerAccount; import net.ktnx.mobileledger.ui.MobileLedgerListFragment; import net.ktnx.mobileledger.ui.RecyclerItemListener; import net.ktnx.mobileledger.ui.activity.MainActivity; +import net.ktnx.mobileledger.utils.Colors; import java.util.List; import java.util.Observer; @@ -152,7 +153,9 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { } }); swiper = mActivity.findViewById(R.id.account_swiper); - swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent); + Colors.themeWatch.addObserver( + (o, arg) -> swiper.setColorSchemeColors(Colors.primary)); + swiper.setColorSchemeColors(Colors.primary); swiper.setOnRefreshListener(() -> { Log.d("ui", "refreshing accounts via swipe"); mActivity.scheduleTransactionListRetrieval(); @@ -160,8 +163,8 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { Data.accounts.addObserver( (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged())); - Data.profile.addObserver( - (o, arg) -> mActivity.runOnUiThread(() -> AccountSummaryViewModel.scheduleAccountListReload())); + Data.profile.addObserver((o, arg) -> mActivity.runOnUiThread( + AccountSummaryViewModel::scheduleAccountListReload)); update_account_table(); } private void update_account_table() { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java index 932607ef..65274dfb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java @@ -30,6 +30,8 @@ import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; +import net.ktnx.mobileledger.utils.Colors; + /** * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls * to be used with AppCompat. @@ -43,6 +45,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); + Colors.setupTheme(this); } @Override diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java index 0d72499d..72dec223 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java @@ -6,14 +6,24 @@ import android.support.v7.app.AppCompatActivity; import android.util.Log; import net.ktnx.mobileledger.ui.CrashReportDialogFragment; +import net.ktnx.mobileledger.utils.Colors; import java.io.PrintWriter; import java.io.StringWriter; -public class CrashReportingActivity extends AppCompatActivity { +public abstract class CrashReportingActivity extends AppCompatActivity { + protected void setupProfileColors() { + Colors.setupTheme(this); + } + @Override + protected void onStart() { + super.onStart(); + Colors.refreshColors(getTheme()); + } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Colors.setupTheme(this); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override 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 641d296c..a96a0b97 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 @@ -19,9 +19,10 @@ package net.ktnx.mobileledger.ui.activity; import android.content.Intent; import android.content.pm.PackageInfo; +import android.content.res.ColorStateList; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; -import android.support.annotation.ColorInt; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -46,6 +47,7 @@ import net.ktnx.mobileledger.model.LedgerAccount; import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment; import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment; +import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.MLDB; import java.lang.ref.WeakReference; @@ -225,20 +227,13 @@ public class MainActivity extends CrashReportingActivity { } public void markDrawerItemCurrent(int id) { TextView item = drawer.findViewById(id); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - item.setBackgroundColor(getResources().getColor(R.color.table_row_dark_bg, getTheme())); - } - else { - item.setBackgroundColor(getResources().getColor(R.color.table_row_dark_bg)); - } - - @ColorInt int transparent = getResources().getColor(android.R.color.transparent); + item.setBackgroundColor(Colors.tableRowDarkBG); LinearLayout actions = drawer.findViewById(R.id.nav_actions); for (int i = 0; i < actions.getChildCount(); i++) { View view = actions.getChildAt(i); if (view.getId() != id) { - view.setBackgroundColor(transparent); + view.setBackgroundColor(Color.TRANSPARENT); } } } @@ -340,6 +335,8 @@ public class MainActivity extends CrashReportingActivity { else Toast.makeText(this, error, Toast.LENGTH_LONG).show(); } public void onRetrieveStart() { + progressBar.setIndeterminateTintList(ColorStateList.valueOf(Colors.primary)); + progressBar.setProgressTintList(ColorStateList.valueOf(Colors.primary)); 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/ui/transaction_list/TransactionListAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java index 0980eacd..6cf729dc 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java @@ -38,6 +38,7 @@ import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; import net.ktnx.mobileledger.model.TransactionListItem; +import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.MLDB; @@ -162,8 +163,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter swiper.setColorSchemeColors(Colors.primary)); + swiper.setColorSchemeColors(Colors.primary); vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter); accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java b/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java index 8a2c8366..7a9913d8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Globals.java @@ -19,7 +19,6 @@ package net.ktnx.mobileledger.utils; import android.app.Activity; import android.content.Context; -import android.support.annotation.ColorInt; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -32,12 +31,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public final class Globals { - @ColorInt - public static int tableRowLightBG; - @ColorInt - public static int tableRowDarkBG; - @ColorInt - public static int primaryDark, defaultTextColor; public static String[] monthNames; public static String developerEmail = "dam+mole-crash@ktnx.net"; private static SimpleDateFormat ledgerDateFormatter =