Use ContextCompat.getColor().

This commit is contained in:
Isira Seneviratne 2020-07-16 06:43:45 +05:30
parent 6a0cd0a14a
commit 5254a6f1aa
8 changed files with 62 additions and 45 deletions

View File

@ -221,7 +221,7 @@ public class SelectAppsView extends SwapView implements LoaderManager.LoaderCall
int colour; int colour;
if (checked) { if (checked) {
resource = R.drawable.ic_check_circle; resource = R.drawable.ic_check_circle;
colour = getResources().getColor(R.color.swap_bright_blue); colour = ContextCompat.getColor(getContext(), R.color.swap_bright_blue);
} else { } else {
resource = R.drawable.ic_add_circle_outline; resource = R.drawable.ic_add_circle_outline;
colour = 0xFFD0D0D4; colour = 0xFFD0D0D4;

View File

@ -3,10 +3,13 @@ package org.fdroid.fdroid.nearby;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import androidx.annotation.ColorInt;
import androidx.annotation.LayoutRes;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.LayoutRes;
import androidx.core.content.ContextCompat;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
/** /**
@ -42,7 +45,7 @@ public class SwapView extends RelativeLayout {
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SwapView, 0, 0); attrs, R.styleable.SwapView, 0, 0);
toolbarColor = a.getColor(R.styleable.SwapView_toolbarColor, 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); toolbarTitle = a.getString(R.styleable.SwapView_toolbarTitle);
a.recycle(); a.recycle();
} }
@ -53,7 +56,7 @@ public class SwapView extends RelativeLayout {
final TypedArray a = context.obtainStyledAttributes( final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SwapView, 0, 0); attrs, R.styleable.SwapView, 0, 0);
toolbarColor = a.getColor(R.styleable.SwapView_toolbarColor, 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); toolbarTitle = a.getString(R.styleable.SwapView_toolbarTitle);
a.recycle(); a.recycle();
} }

View File

@ -934,7 +934,8 @@ public class SwapWorkflowActivity extends AppCompatActivity {
new QrGenAsyncTask(SwapWorkflowActivity.this, R.id.wifi_qr_code).execute(qrUriString); new QrGenAsyncTask(SwapWorkflowActivity.this, R.id.wifi_qr_code).execute(qrUriString);
// Replace all blacks with the background blue. // 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); final View qrWarningMessage = container.findViewById(R.id.warning_qr_scanner);
if (CameraCharacteristicsChecker.getInstance(this).hasAutofocus()) { if (CameraCharacteristicsChecker.getInstance(this).hasAutofocus()) {

View File

@ -1,10 +1,12 @@
package org.fdroid.fdroid.panic; package org.fdroid.fdroid.panic;
import android.content.Context; 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.CheckBoxPreference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
@ -31,11 +33,10 @@ public class DestructiveCheckBoxPreference extends CheckBoxPreference {
if (!holder.itemView.isEnabled()) { if (!holder.itemView.isEnabled()) {
return; return;
} }
Resources resources = getContext().getResources();
if (FDroidApp.isAppThemeLight()) { 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 { } else {
holder.itemView.setBackgroundColor(resources.getColor(R.color.panic_destructive_dark)); holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_dark));
} }
} }
} }

View File

@ -1,9 +1,12 @@
package org.fdroid.fdroid.panic; package org.fdroid.fdroid.panic;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet;
import androidx.core.content.ContextCompat;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder; import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
@ -28,9 +31,9 @@ public class DestructivePreference extends Preference {
public void onBindViewHolder(PreferenceViewHolder holder) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder); super.onBindViewHolder(holder);
if (FDroidApp.isAppThemeLight()) { 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 { } else {
holder.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.panic_destructive_dark)); holder.itemView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.panic_destructive_dark));
} }
} }
} }

View File

@ -20,23 +20,25 @@
package org.fdroid.fdroid.panic; package org.fdroid.fdroid.panic;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.LightingColorFilter; import android.graphics.LightingColorFilter;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; 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.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.TextView; 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.FDroidApp;
import org.fdroid.fdroid.Preferences; import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
@ -116,9 +118,9 @@ public class SelectInstalledAppsActivity extends AppCompatActivity implements Lo
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
checkId = menuItem.getItemId(); checkId = menuItem.getItemId();
if (FDroidApp.isAppThemeLight()) { if (FDroidApp.isAppThemeLight()) {
Resources resources = getResources(); Drawable icon = ContextCompat.getDrawable(this, R.drawable.check);
Drawable icon = resources.getDrawable(R.drawable.check); icon.setColorFilter(new LightingColorFilter(0xffffffff, ContextCompat.getColor(this,
icon.setColorFilter(new LightingColorFilter(0xffffffff, resources.getColor(android.R.color.white))); android.R.color.white)));
menuItem.setIcon(icon); menuItem.setIcon(icon);
} else { } else {
menuItem.setIcon(R.drawable.check); menuItem.setIcon(R.drawable.check);

View File

@ -35,15 +35,6 @@ import android.net.wifi.WifiManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; 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.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -57,6 +48,18 @@ import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.AddRepoIntentService;
import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.IndexUpdater; import org.fdroid.fdroid.IndexUpdater;
@ -538,7 +541,8 @@ public class ManageReposActivity extends AppCompatActivity
overwriteMessage.setText(getString(messageRes, name)); overwriteMessage.setText(getString(messageRes, name));
overwriteMessage.setVisibility(View.VISIBLE); overwriteMessage.setVisibility(View.VISIBLE);
if (redMessage) { if (redMessage) {
overwriteMessage.setTextColor(getResources().getColor(R.color.red)); overwriteMessage.setTextColor(ContextCompat.getColor(ManageReposActivity.this,
R.color.red));
} else { } else {
overwriteMessage.setTextColor(defaultTextColour); overwriteMessage.setTextColor(defaultTextColour);
} }

View File

@ -13,14 +13,6 @@ import android.nfc.NfcAdapter;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; 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.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -33,6 +25,17 @@ import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; 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.FDroidApp;
import org.fdroid.fdroid.NfcHelper; import org.fdroid.fdroid.NfcHelper;
import org.fdroid.fdroid.NfcNotEnabledActivity; 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 // 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)) { if (TextUtils.isEmpty(repo.fingerprint) && TextUtils.isEmpty(repo.signingCertificate)) {
repoFingerprint = getResources().getString(R.string.unsigned); 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.setVisibility(View.VISIBLE);
repoFingerprintDescView.setText(getResources().getString(R.string.unsigned_description)); repoFingerprintDescView.setText(getResources().getString(R.string.unsigned_description));
} else { } else {