mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-04 07:41:40 -04:00
settings for pure black oled
This commit is contained in:
@@ -16,10 +16,21 @@ public class CatimaAppCompatActivity extends AppCompatActivity {
|
||||
super.attachBaseContext(Utils.updateBaseContextLocale(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// XXX on the splash screen activity, aka the main activity, this has to be executed after applying dynamic colors, not before
|
||||
// so running this only on non main for now
|
||||
if (!this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())) {
|
||||
Utils.patchOledDarkTheme(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
// material you themes uses background color for top bar, let the layout underneath show through
|
||||
// material 3 designer does not consider status bar colors
|
||||
// XXX changing this in onCreate causes issues with the splash screen activity, so doing this here
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
getWindow().getDecorView().setSystemUiVisibility(Utils.isDarkModeEnabled(this) ? 0 : View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
@@ -27,5 +38,10 @@ public class CatimaAppCompatActivity extends AppCompatActivity {
|
||||
// icons are always white back then
|
||||
getWindow().setStatusBarColor(Utils.isDarkModeEnabled(this) ? Color.TRANSPARENT : Color.argb(127, 0, 0, 0));
|
||||
}
|
||||
// XXX android 9 and below has a nasty rendering bug if the theme was patched earlier
|
||||
// the splash screen activity needs the fix regardless to solve a dynamic color api issue
|
||||
if (!this.getClass().getSimpleName().equals(MainActivity.class.getSimpleName())) {
|
||||
Utils.postPatchOledDarkTheme(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,13 +183,15 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
|
||||
|
||||
// onPreCreate can't tell this activity uses a material theme due to splash screen, force color application here
|
||||
DynamicColors.applyIfAvailable(this);
|
||||
Utils.patchOledDarkTheme(this);
|
||||
setTitle(R.string.app_name);
|
||||
|
||||
setContentView(R.layout.main_activity);
|
||||
|
||||
// XXX more dynamic color fixing due to splash screen
|
||||
// without this the background color will get stuck with the old color before dynamic color
|
||||
TypedValue typedValue = new TypedValue();
|
||||
getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true);
|
||||
getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true);
|
||||
findViewById(android.R.id.content).setBackgroundColor(typedValue.data);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.os.Build;
|
||||
import android.os.LocaleList;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
@@ -39,9 +40,11 @@ import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
|
||||
import protect.card_locker.preferences.Settings;
|
||||
|
||||
public class Utils {
|
||||
@@ -457,6 +460,25 @@ public class Utils {
|
||||
R = 255 - R;
|
||||
G = 255 - G;
|
||||
B = 255 - B;
|
||||
return R + (G << 8) + ( B << 16) + ( A << 24);
|
||||
return R + (G << 8) + (B << 16) + (A << 24);
|
||||
}
|
||||
|
||||
// replace colors in the current theme
|
||||
// use before views are inflated, after dynamic color
|
||||
public static void patchOledDarkTheme(AppCompatActivity activity) {
|
||||
if (isDarkModeEnabled(activity) && new Settings(activity).getOledDark()) {
|
||||
activity.getTheme().applyStyle(R.style.DarkBackground, true);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX android 9 and below has issues with patched theme where the background becomes a
|
||||
// rendering mess
|
||||
// use after views are inflated
|
||||
public static void postPatchOledDarkTheme(AppCompatActivity activity) {
|
||||
if (isDarkModeEnabled(activity) && new Settings(activity).getOledDark()) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
activity.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true);
|
||||
activity.findViewById(android.R.id.content).setBackgroundColor(typedValue.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.annotation.IntegerRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import protect.card_locker.R;
|
||||
import protect.card_locker.Utils;
|
||||
|
||||
@@ -102,4 +103,8 @@ public class Settings {
|
||||
public boolean getDisableLockscreenWhileViewingCard() {
|
||||
return getBoolean(R.string.settings_key_disable_lockscreen_while_viewing_card, true);
|
||||
}
|
||||
|
||||
public boolean getOledDark() {
|
||||
return getBoolean(R.string.settings_key_oled_dark, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.fragment.app.DialogFragment;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import nl.invissvenska.numberpickerpreference.NumberDialogPreference;
|
||||
import nl.invissvenska.numberpickerpreference.NumberPickerPreferenceDialogFragment;
|
||||
import protect.card_locker.CatimaAppCompatActivity;
|
||||
@@ -132,6 +133,13 @@ public class SettingsActivity extends CatimaAppCompatActivity {
|
||||
refreshActivity(true);
|
||||
return true;
|
||||
});
|
||||
|
||||
Preference oledDarkPreference = findPreference(getResources().getString(R.string.settings_key_oled_dark));
|
||||
assert oledDarkPreference != null;
|
||||
oledDarkPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
refreshActivity(true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void refreshActivity(boolean reloadMain) {
|
||||
|
||||
Reference in New Issue
Block a user