From 5254a6f1aab01362e8ff47aec7b6c6a182576662 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 16 Jul 2020 06:43:45 +0530 Subject: [PATCH] Use ContextCompat.getColor(). --- .../fdroid/fdroid/nearby/SelectAppsView.java | 2 +- .../org/fdroid/fdroid/nearby/SwapView.java | 11 +++++--- .../fdroid/nearby/SwapWorkflowActivity.java | 3 ++- .../panic/DestructiveCheckBoxPreference.java | 11 ++++---- .../fdroid/panic/DestructivePreference.java | 9 ++++--- .../panic/SelectInstalledAppsActivity.java | 26 ++++++++++--------- .../fdroid/views/ManageReposActivity.java | 24 ++++++++++------- .../fdroid/views/RepoDetailsActivity.java | 21 ++++++++------- 8 files changed, 62 insertions(+), 45 deletions(-) diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/SelectAppsView.java b/app/src/full/java/org/fdroid/fdroid/nearby/SelectAppsView.java index 2ba8dcc69..6ba6cb4c4 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/SelectAppsView.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/SelectAppsView.java @@ -221,7 +221,7 @@ public class SelectAppsView extends SwapView implements LoaderManager.LoaderCall int colour; if (checked) { resource = R.drawable.ic_check_circle; - colour = getResources().getColor(R.color.swap_bright_blue); + colour = ContextCompat.getColor(getContext(), R.color.swap_bright_blue); } else { resource = R.drawable.ic_add_circle_outline; colour = 0xFFD0D0D4; diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/SwapView.java b/app/src/full/java/org/fdroid/fdroid/nearby/SwapView.java index a7901ef07..c2dcaa251 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/SwapView.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/SwapView.java @@ -3,10 +3,13 @@ package org.fdroid.fdroid.nearby; import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; -import androidx.annotation.ColorInt; -import androidx.annotation.LayoutRes; import android.util.AttributeSet; import android.widget.RelativeLayout; + +import androidx.annotation.ColorInt; +import androidx.annotation.LayoutRes; +import androidx.core.content.ContextCompat; + import org.fdroid.fdroid.R; /** @@ -42,7 +45,7 @@ public class SwapView extends RelativeLayout { final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SwapView, 0, 0); toolbarColor = a.getColor(R.styleable.SwapView_toolbarColor, - getResources().getColor(R.color.swap_blue)); + ContextCompat.getColor(context, R.color.swap_blue)); toolbarTitle = a.getString(R.styleable.SwapView_toolbarTitle); a.recycle(); } @@ -53,7 +56,7 @@ public class SwapView extends RelativeLayout { final TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SwapView, 0, 0); toolbarColor = a.getColor(R.styleable.SwapView_toolbarColor, - getResources().getColor(R.color.swap_blue)); + ContextCompat.getColor(context, R.color.swap_blue)); toolbarTitle = a.getString(R.styleable.SwapView_toolbarTitle); a.recycle(); } diff --git a/app/src/full/java/org/fdroid/fdroid/nearby/SwapWorkflowActivity.java b/app/src/full/java/org/fdroid/fdroid/nearby/SwapWorkflowActivity.java index 0be72390f..56ce77818 100644 --- a/app/src/full/java/org/fdroid/fdroid/nearby/SwapWorkflowActivity.java +++ b/app/src/full/java/org/fdroid/fdroid/nearby/SwapWorkflowActivity.java @@ -934,7 +934,8 @@ public class SwapWorkflowActivity extends AppCompatActivity { new QrGenAsyncTask(SwapWorkflowActivity.this, R.id.wifi_qr_code).execute(qrUriString); // Replace all blacks with the background blue. - qrImage.setColorFilter(new LightingColorFilter(0xffffffff, getResources().getColor(R.color.swap_blue))); + qrImage.setColorFilter(new LightingColorFilter(0xffffffff, ContextCompat.getColor(this, + R.color.swap_blue))); final View qrWarningMessage = container.findViewById(R.id.warning_qr_scanner); if (CameraCharacteristicsChecker.getInstance(this).hasAutofocus()) { diff --git a/app/src/full/java/org/fdroid/fdroid/panic/DestructiveCheckBoxPreference.java b/app/src/full/java/org/fdroid/fdroid/panic/DestructiveCheckBoxPreference.java index e09e0afe3..67fe2fb3e 100644 --- a/app/src/full/java/org/fdroid/fdroid/panic/DestructiveCheckBoxPreference.java +++ b/app/src/full/java/org/fdroid/fdroid/panic/DestructiveCheckBoxPreference.java @@ -1,10 +1,12 @@ package org.fdroid.fdroid.panic; import android.content.Context; -import android.content.res.Resources; +import android.util.AttributeSet; + +import androidx.core.content.ContextCompat; import androidx.preference.CheckBoxPreference; import androidx.preference.PreferenceViewHolder; -import android.util.AttributeSet; + import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.R; @@ -31,11 +33,10 @@ public class DestructiveCheckBoxPreference extends CheckBoxPreference { if (!holder.itemView.isEnabled()) { return; } - Resources resources = getContext().getResources(); if (FDroidApp.isAppThemeLight()) { - holder.itemView.setBackgroundColor(resources.getColor(R.color.panic_destructive_light)); + holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_light)); } else { - holder.itemView.setBackgroundColor(resources.getColor(R.color.panic_destructive_dark)); + holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_dark)); } } } diff --git a/app/src/full/java/org/fdroid/fdroid/panic/DestructivePreference.java b/app/src/full/java/org/fdroid/fdroid/panic/DestructivePreference.java index 53a613e74..5927ec02c 100644 --- a/app/src/full/java/org/fdroid/fdroid/panic/DestructivePreference.java +++ b/app/src/full/java/org/fdroid/fdroid/panic/DestructivePreference.java @@ -1,9 +1,12 @@ package org.fdroid.fdroid.panic; import android.content.Context; +import android.util.AttributeSet; + +import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; -import android.util.AttributeSet; + import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.R; @@ -28,9 +31,9 @@ public class DestructivePreference extends Preference { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); if (FDroidApp.isAppThemeLight()) { - holder.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.panic_destructive_light)); + holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_light)); } else { - holder.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.panic_destructive_dark)); + holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_dark)); } } } diff --git a/app/src/full/java/org/fdroid/fdroid/panic/SelectInstalledAppsActivity.java b/app/src/full/java/org/fdroid/fdroid/panic/SelectInstalledAppsActivity.java index f5d68348b..1264c4aee 100644 --- a/app/src/full/java/org/fdroid/fdroid/panic/SelectInstalledAppsActivity.java +++ b/app/src/full/java/org/fdroid/fdroid/panic/SelectInstalledAppsActivity.java @@ -20,23 +20,25 @@ package org.fdroid.fdroid.panic; import android.annotation.SuppressLint; -import android.content.res.Resources; import android.database.Cursor; import android.graphics.LightingColorFilter; import android.graphics.drawable.Drawable; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.loader.app.LoaderManager; -import androidx.loader.content.CursorLoader; -import androidx.loader.content.Loader; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; +import androidx.loader.app.LoaderManager; +import androidx.loader.content.CursorLoader; +import androidx.loader.content.Loader; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.R; @@ -116,9 +118,9 @@ public class SelectInstalledAppsActivity extends AppCompatActivity implements Lo menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); checkId = menuItem.getItemId(); if (FDroidApp.isAppThemeLight()) { - Resources resources = getResources(); - Drawable icon = resources.getDrawable(R.drawable.check); - icon.setColorFilter(new LightingColorFilter(0xffffffff, resources.getColor(android.R.color.white))); + Drawable icon = ContextCompat.getDrawable(this, R.drawable.check); + icon.setColorFilter(new LightingColorFilter(0xffffffff, ContextCompat.getColor(this, + android.R.color.white))); menuItem.setIcon(icon); } else { menuItem.setIcon(R.drawable.check); diff --git a/app/src/main/java/org/fdroid/fdroid/views/ManageReposActivity.java b/app/src/main/java/org/fdroid/fdroid/views/ManageReposActivity.java index 15dc3f34e..bddb0a15a 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/ManageReposActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/ManageReposActivity.java @@ -35,15 +35,6 @@ import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.loader.app.LoaderManager; -import androidx.core.app.NavUtils; -import androidx.core.app.TaskStackBuilder; -import androidx.loader.content.CursorLoader; -import androidx.loader.content.Loader; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -57,6 +48,18 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.app.NavUtils; +import androidx.core.app.TaskStackBuilder; +import androidx.core.content.ContextCompat; +import androidx.loader.app.LoaderManager; +import androidx.loader.content.CursorLoader; +import androidx.loader.content.Loader; + import org.fdroid.fdroid.AddRepoIntentService; import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.IndexUpdater; @@ -538,7 +541,8 @@ public class ManageReposActivity extends AppCompatActivity overwriteMessage.setText(getString(messageRes, name)); overwriteMessage.setVisibility(View.VISIBLE); if (redMessage) { - overwriteMessage.setTextColor(getResources().getColor(R.color.red)); + overwriteMessage.setTextColor(ContextCompat.getColor(ManageReposActivity.this, + R.color.red)); } else { overwriteMessage.setTextColor(defaultTextColour); } diff --git a/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java b/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java index 28291685c..cbdbc981e 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java @@ -13,14 +13,6 @@ import android.nfc.NfcAdapter; import android.os.Build; import android.os.Bundle; import android.os.Parcelable; -import androidx.annotation.NonNull; -import androidx.core.app.NavUtils; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.text.format.DateUtils; import android.view.LayoutInflater; @@ -33,6 +25,17 @@ import android.widget.CompoundButton; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.app.NavUtils; +import androidx.core.content.ContextCompat; +import androidx.localbroadcastmanager.content.LocalBroadcastManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.NfcHelper; import org.fdroid.fdroid.NfcNotEnabledActivity; @@ -305,7 +308,7 @@ public class RepoDetailsActivity extends AppCompatActivity { // TODO show the current state of the signature check, not just whether there is a key or not if (TextUtils.isEmpty(repo.fingerprint) && TextUtils.isEmpty(repo.signingCertificate)) { repoFingerprint = getResources().getString(R.string.unsigned); - repoFingerprintView.setTextColor(getResources().getColor(R.color.unsigned)); + repoFingerprintView.setTextColor(ContextCompat.getColor(this, R.color.unsigned)); repoFingerprintDescView.setVisibility(View.VISIBLE); repoFingerprintDescView.setText(getResources().getString(R.string.unsigned_description)); } else {