mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 13:59:14 +00:00
Merge pull request #1301 from alexbakker/fix-1300
Use MaterialColors.getColor instead of our own helper
This commit is contained in:
commit
8512986a6b
7 changed files with 23 additions and 36 deletions
|
@ -1,23 +0,0 @@
|
||||||
package com.beemdevelopment.aegis.helpers;
|
|
||||||
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.util.TypedValue;
|
|
||||||
|
|
||||||
import androidx.annotation.ColorInt;
|
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.R;
|
|
||||||
|
|
||||||
public class ThemeHelper {
|
|
||||||
private ThemeHelper() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getThemeColor(int attributeId, Resources.Theme currentTheme) {
|
|
||||||
TypedValue typedValue = new TypedValue();
|
|
||||||
currentTheme.resolveAttribute(attributeId, typedValue, true);
|
|
||||||
@ColorInt int color = typedValue.data;
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,11 +16,11 @@ import androidx.annotation.StringRes;
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.BuildConfig;
|
import com.beemdevelopment.aegis.BuildConfig;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
import com.beemdevelopment.aegis.licenses.GlideLicense;
|
import com.beemdevelopment.aegis.licenses.GlideLicense;
|
||||||
import com.beemdevelopment.aegis.licenses.ProtobufLicense;
|
import com.beemdevelopment.aegis.licenses.ProtobufLicense;
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.ChangelogDialog;
|
import com.beemdevelopment.aegis.ui.dialogs.ChangelogDialog;
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.LicenseDialog;
|
import com.beemdevelopment.aegis.ui.dialogs.LicenseDialog;
|
||||||
|
import com.google.android.material.color.MaterialColors;
|
||||||
|
|
||||||
import de.psdev.licensesdialog.LicenseResolver;
|
import de.psdev.licensesdialog.LicenseResolver;
|
||||||
import de.psdev.licensesdialog.LicensesDialog;
|
import de.psdev.licensesdialog.LicensesDialog;
|
||||||
|
@ -148,7 +148,8 @@ public class AboutActivity extends AegisActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getThemeColorAsHex(@AttrRes int attributeId) {
|
private String getThemeColorAsHex(@AttrRes int attributeId) {
|
||||||
return String.format("%06X", (0xFFFFFF & ThemeHelper.getThemeColor(attributeId, getTheme())));
|
int color = MaterialColors.getColor(this, attributeId, getClass().getCanonicalName());
|
||||||
|
return String.format("%06X", 0xFFFFFF & color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,11 +22,11 @@ import com.beemdevelopment.aegis.Preferences;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.Theme;
|
import com.beemdevelopment.aegis.Theme;
|
||||||
import com.beemdevelopment.aegis.ThemeMap;
|
import com.beemdevelopment.aegis.ThemeMap;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
import com.beemdevelopment.aegis.icons.IconPackManager;
|
import com.beemdevelopment.aegis.icons.IconPackManager;
|
||||||
import com.beemdevelopment.aegis.vault.VaultManager;
|
import com.beemdevelopment.aegis.vault.VaultManager;
|
||||||
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
|
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
|
||||||
import com.google.android.material.color.DynamicColors;
|
import com.google.android.material.color.DynamicColors;
|
||||||
|
import com.google.android.material.color.MaterialColors;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
@ -251,7 +251,7 @@ public abstract class AegisActivity extends AppCompatActivity implements VaultMa
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
int statusBarColor = visibility == View.VISIBLE
|
int statusBarColor = visibility == View.VISIBLE
|
||||||
? ThemeHelper.getThemeColor(com.google.android.material.R.attr.colorSurfaceContainer, getTheme())
|
? MaterialColors.getColor(actionModeView, com.google.android.material.R.attr.colorSurfaceContainer)
|
||||||
: _statusBarColor;
|
: _statusBarColor;
|
||||||
getWindow().setStatusBarColor(statusBarColor);
|
getWindow().setStatusBarColor(statusBarColor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.Theme;
|
import com.beemdevelopment.aegis.Theme;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
import com.google.android.material.color.MaterialColors;
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
|
|
||||||
|
@ -70,11 +70,21 @@ public abstract class SimpleWebViewDialog extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBackgroundColor() {
|
protected String getBackgroundColor() {
|
||||||
return colorToCSS(ThemeHelper.getThemeColor(com.google.android.material.R.attr.colorSurfaceContainerHigh, requireContext().getTheme()));
|
int color = MaterialColors.getColor(
|
||||||
|
requireContext(),
|
||||||
|
com.google.android.material.R.attr.colorSurfaceContainerHigh,
|
||||||
|
getClass().getCanonicalName()
|
||||||
|
);
|
||||||
|
return colorToCSS(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getTextColor() {
|
protected String getTextColor() {
|
||||||
return colorToCSS(0xFFFFFF & ThemeHelper.getThemeColor(com.google.android.material.R.attr.colorOnSurface, requireContext().getTheme()));
|
int color = MaterialColors.getColor(
|
||||||
|
requireContext(),
|
||||||
|
com.google.android.material.R.attr.colorOnSurface,
|
||||||
|
getClass().getCanonicalName()
|
||||||
|
);
|
||||||
|
return colorToCSS(0xFFFFFF & color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
|
|
|
@ -19,9 +19,9 @@ import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.Preferences;
|
import com.beemdevelopment.aegis.Preferences;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||||
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
|
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
|
||||||
|
import com.google.android.material.color.MaterialColors;
|
||||||
|
|
||||||
public class BackupsPreferencesFragment extends PreferencesFragment {
|
public class BackupsPreferencesFragment extends PreferencesFragment {
|
||||||
private SwitchPreferenceCompat _androidBackupsPreference;
|
private SwitchPreferenceCompat _androidBackupsPreference;
|
||||||
|
@ -216,7 +216,7 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
|
||||||
message = getString(R.string.backup_status_failed, res.getElapsedSince(requireContext()));
|
message = getString(R.string.backup_status_failed, res.getElapsedSince(requireContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int color = ThemeHelper.getThemeColor(colorAttr, requireContext().getTheme());
|
int color = MaterialColors.getColor(requireContext(), colorAttr, getClass().getCanonicalName());
|
||||||
Spannable spannable = new SpannableString(message);
|
Spannable spannable = new SpannableString(message);
|
||||||
spannable.setSpan(new ForegroundColorSpan(color), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new ForegroundColorSpan(color), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
|
@ -32,7 +32,6 @@ import com.beemdevelopment.aegis.ViewMode;
|
||||||
import com.beemdevelopment.aegis.helpers.AnimationsHelper;
|
import com.beemdevelopment.aegis.helpers.AnimationsHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.MetricsHelper;
|
import com.beemdevelopment.aegis.helpers.MetricsHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.SimpleItemTouchHelperCallback;
|
import com.beemdevelopment.aegis.helpers.SimpleItemTouchHelperCallback;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
import com.beemdevelopment.aegis.helpers.UiRefresher;
|
import com.beemdevelopment.aegis.helpers.UiRefresher;
|
||||||
import com.beemdevelopment.aegis.otp.TotpInfo;
|
import com.beemdevelopment.aegis.otp.TotpInfo;
|
||||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||||
|
@ -635,7 +634,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
private class CompactDividerDecoration extends MaterialDividerItemDecoration {
|
private class CompactDividerDecoration extends MaterialDividerItemDecoration {
|
||||||
public CompactDividerDecoration() {
|
public CompactDividerDecoration() {
|
||||||
super(requireContext(), DividerItemDecoration.VERTICAL);
|
super(requireContext(), DividerItemDecoration.VERTICAL);
|
||||||
setDividerColor(ThemeHelper.getThemeColor(androidx.appcompat.R.attr.divider, requireContext().getTheme()));
|
setDividerColorResource(requireContext(), android.R.color.transparent);
|
||||||
setLastItemDecorated(false);
|
setLastItemDecorated(false);
|
||||||
setDividerThickness(MetricsHelper.convertDpToPixels(requireContext(), 0.5f));
|
setDividerThickness(MetricsHelper.convertDpToPixels(requireContext(), 0.5f));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ import android.widget.TextView;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
import com.beemdevelopment.aegis.icons.IconPack;
|
import com.beemdevelopment.aegis.icons.IconPack;
|
||||||
import com.beemdevelopment.aegis.icons.IconType;
|
import com.beemdevelopment.aegis.icons.IconType;
|
||||||
import com.beemdevelopment.aegis.ui.glide.GlideHelper;
|
import com.beemdevelopment.aegis.ui.glide.GlideHelper;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.google.android.material.color.MaterialColors;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class IconHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
public void loadIcon(Context context) {
|
public void loadIcon(Context context) {
|
||||||
if (_isCustom) {
|
if (_isCustom) {
|
||||||
int tint = ThemeHelper.getThemeColor(com.google.android.material.R.attr.colorOnSurfaceVariant, context.getTheme());
|
int tint = MaterialColors.getColor(itemView, com.google.android.material.R.attr.colorOnSurfaceVariant);
|
||||||
GlideHelper.loadResource(Glide.with(context), R.drawable.ic_outline_add_24, tint, _imageView);
|
GlideHelper.loadResource(Glide.with(context), R.drawable.ic_outline_add_24, tint, _imageView);
|
||||||
} else {
|
} else {
|
||||||
GlideHelper.loadIconFile(Glide.with(context), _iconFile, _iconType, _imageView);
|
GlideHelper.loadIconFile(Glide.with(context), _iconFile, _iconType, _imageView);
|
||||||
|
|
Loading…
Add table
Reference in a new issue