Improve the Android 12 splash screen.

This commit is contained in:
Greyson Parrelli
2022-04-27 14:43:41 -04:00
parent 39a11ce26c
commit 11db59d8a1
14 changed files with 159 additions and 18 deletions

View File

@@ -11,16 +11,14 @@ import androidx.appcompat.app.AppCompatDelegate;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.keyvalue.SettingsValues;
import org.thoughtcrime.securesms.keyvalue.SettingsValues.Theme;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
public class DynamicTheme {
private static final String TAG = Log.tag(DynamicTheme.class);
public static final String DARK = "dark";
public static final String LIGHT = "light";
public static final String SYSTEM = "system";
private static int globalNightModeConfiguration;
private int onCreateNightModeConfiguration;
@@ -55,9 +53,9 @@ public class DynamicTheme {
}
public static void setDefaultDayNightMode(@NonNull Context context) {
String theme = SignalStore.settings().getTheme();
Theme theme = SignalStore.settings().getTheme();
if (theme.equals(SYSTEM)) {
if (theme == Theme.SYSTEM) {
Log.d(TAG, "Setting to follow system expecting: " + ConfigurationUtil.getNightModeConfiguration(context.getApplicationContext()));
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else if (DynamicTheme.isDarkTheme(context)) {
@@ -75,12 +73,12 @@ public class DynamicTheme {
* Takes the system theme into account.
*/
public static boolean isDarkTheme(@NonNull Context context) {
String theme = SignalStore.settings().getTheme();
Theme theme = SignalStore.settings().getTheme();
if (theme.equals(SYSTEM) && systemThemeAvailable()) {
if (theme == Theme.SYSTEM && systemThemeAvailable()) {
return isSystemInDarkTheme(context);
} else {
return theme.equals(DARK);
return theme == Theme.DARK;
}
}

View File

@@ -0,0 +1,36 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.keyvalue.SettingsValues;
public final class SplashScreenUtil {
private SplashScreenUtil() {}
/**
* Sets the splash screen for Android 12+ devices based on the passed-in theme.
*/
public static void setSplashScreenThemeIfNecessary(@Nullable Activity activity, @NonNull SettingsValues.Theme theme) {
if (Build.VERSION.SDK_INT < 31 || activity == null) {
return;
}
switch (theme) {
case LIGHT:
activity.getSplashScreen().setSplashScreenTheme(R.style.Theme_Signal_DayNight_NoActionBar_LightSplash);
break;
case DARK:
activity.getSplashScreen().setSplashScreenTheme(R.style.Theme_Signal_DayNight_NoActionBar_DarkSplash);
break;
case SYSTEM:
activity.getSplashScreen().setSplashScreenTheme(Resources.ID_NULL);
break;
}
}
}

View File

@@ -774,7 +774,7 @@ public class TextSecurePreferences {
* @deprecated Use {@link SettingsValues#getTheme()} via {@link org.thoughtcrime.securesms.keyvalue.SignalStore} instead.
*/
public static String getTheme(Context context) {
return getStringPreference(context, THEME_PREF, DynamicTheme.systemThemeAvailable() ? DynamicTheme.SYSTEM : DynamicTheme.LIGHT);
return getStringPreference(context, THEME_PREF, DynamicTheme.systemThemeAvailable() ? "system" : "light");
}
public static boolean isShowInviteReminders(Context context) {