Improve the Android 12 splash screen.

fork-5.53.8
Greyson Parrelli 2022-04-27 14:43:41 -04:00
rodzic 39a11ce26c
commit 11db59d8a1
14 zmienionych plików z 159 dodań i 18 usunięć

Wyświetl plik

@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.util.CachedInflater;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.SplashScreenUtil;
import org.thoughtcrime.securesms.util.WindowUtil;
public class MainActivity extends PassphraseRequiredActivity implements VoiceNoteMediaControllerOwner {
@ -100,6 +101,12 @@ public class MainActivity extends PassphraseRequiredActivity implements VoiceNot
updateTabVisibility();
}
@Override
protected void onStop() {
super.onStop();
SplashScreenUtil.setSplashScreenThemeIfNecessary(this, SignalStore.settings().getTheme());
}
@Override
public void onBackPressed() {
if (!navigator.onBackPressed()) {

Wyświetl plik

@ -8,6 +8,7 @@ import org.thoughtcrime.securesms.components.settings.DSLSettingsAdapter
import org.thoughtcrime.securesms.components.settings.DSLSettingsFragment
import org.thoughtcrime.securesms.components.settings.DSLSettingsText
import org.thoughtcrime.securesms.components.settings.configure
import org.thoughtcrime.securesms.keyvalue.SettingsValues
import org.thoughtcrime.securesms.util.navigation.safeNavigate
class AppearanceSettingsFragment : DSLSettingsFragment(R.string.preferences__appearance) {
@ -36,9 +37,9 @@ class AppearanceSettingsFragment : DSLSettingsFragment(R.string.preferences__app
radioListPref(
title = DSLSettingsText.from(R.string.preferences__theme),
listItems = themeLabels,
selected = themeValues.indexOf(state.theme),
selected = themeValues.indexOf(state.theme.serialize()),
onSelected = {
viewModel.setTheme(themeValues[it])
viewModel.setTheme(activity, SettingsValues.Theme.deserialize(themeValues[it]))
}
)

Wyświetl plik

@ -1,7 +1,9 @@
package org.thoughtcrime.securesms.components.settings.app.appearance
import org.thoughtcrime.securesms.keyvalue.SettingsValues
data class AppearanceSettingsState(
val theme: String,
val theme: SettingsValues.Theme,
val messageFontSize: Int,
val language: String
)

Wyświetl plik

@ -1,9 +1,12 @@
package org.thoughtcrime.securesms.components.settings.app.appearance
import android.app.Activity
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import org.thoughtcrime.securesms.jobs.EmojiSearchIndexDownloadJob
import org.thoughtcrime.securesms.keyvalue.SettingsValues.Theme
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.util.SplashScreenUtil
import org.thoughtcrime.securesms.util.livedata.Store
class AppearanceSettingsViewModel : ViewModel() {
@ -21,9 +24,10 @@ class AppearanceSettingsViewModel : ViewModel() {
val state: LiveData<AppearanceSettingsState> = store.stateLiveData
fun setTheme(theme: String) {
fun setTheme(activity: Activity?, theme: Theme) {
store.update { it.copy(theme = theme) }
SignalStore.settings().theme = theme
SplashScreenUtil.setSplashScreenThemeIfNecessary(activity, theme)
}
fun setLanguage(language: String) {

Wyświetl plik

@ -181,12 +181,12 @@ public final class SettingsValues extends SignalStoreValues {
return CallBandwidthMode.fromCode(getInteger(CALL_BANDWIDTH_MODE, CallBandwidthMode.HIGH_ALWAYS.getCode()));
}
public @NonNull String getTheme() {
return getString(THEME, TextSecurePreferences.getTheme(ApplicationDependencies.getApplication()));
public @NonNull Theme getTheme() {
return Theme.deserialize(getString(THEME, TextSecurePreferences.getTheme(ApplicationDependencies.getApplication())));
}
public void setTheme(@NonNull String theme) {
putString(THEME, theme);
public void setTheme(@NonNull Theme theme) {
putString(THEME, theme.serialize());
onConfigurationSettingChanged.postValue(THEME);
}
@ -432,4 +432,27 @@ public final class SettingsValues extends SignalStoreValues {
return value;
}
}
public enum Theme {
SYSTEM("system"), LIGHT("light"), DARK("dark");
private final String value;
Theme(String value) {
this.value = value;
}
public @NonNull String serialize() {
return value;
}
public static @NonNull Theme deserialize(@NonNull String value) {
switch (value) {
case "system": return SYSTEM;
case "light": return LIGHT;
case "dark": return DARK;
default: throw new IllegalArgumentException("Unrecognized value " + value);
}
}
}
}

Wyświetl plik

@ -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;
}
}

Wyświetl plik

@ -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;
}
}
}

Wyświetl plik

@ -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) {

Wyświetl plik

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="192dp"
android:height="192dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M48.24,30.7l0.54,2.18a21.46,21.46 0,0 0,-6 2.5L41.6,33.45A24,24 0,0 1,48.24 30.7ZM59.76,30.7 L59.22,32.88a21.46,21.46 0,0 1,6 2.5l1.16,-1.93A24,24 0,0 0,59.76 30.7ZM33.45,41.6a24,24 0,0 0,-2.75 6.64l2.18,0.54a21.46,21.46 0,0 1,2.5 -6ZM32.25,54a21.85,21.85 0,0 1,0.24 -3.26l-2.22,-0.34a24.13,24.13 0,0 0,0 7.2l2.22,-0.34A21.85,21.85 0,0 1,32.25 54ZM66.4,74.55l-1.16,-1.93a21.46,21.46 0,0 1,-6 2.5l0.54,2.18A24,24 0,0 0,66.4 74.55ZM75.75,54a21.85,21.85 0,0 1,-0.24 3.26l2.22,0.34a24.13,24.13 0,0 0,0 -7.2l-2.22,0.34A21.85,21.85 0,0 1,75.75 54ZM77.3,59.76 L75.12,59.22a21.46,21.46 0,0 1,-2.5 6l1.93,1.16A24,24 0,0 0,77.3 59.76ZM57.3,75.51a22.26,22.26 0,0 1,-6.52 0l-0.34,2.22a24.14,24.14 0,0 0,7.2 0ZM71.51,66.9a21.9,21.9 0,0 1,-4.61 4.61l1.34,1.81a24.46,24.46 0,0 0,5.08 -5.08ZM66.9,36.49a21.9,21.9 0,0 1,4.61 4.61l1.81,-1.34a24.46,24.46 0,0 0,-5.08 -5.08ZM36.49,41.1a21.9,21.9 0,0 1,4.61 -4.61l-1.34,-1.81a24.46,24.46 0,0 0,-5.08 5.08ZM74.55,41.6 L72.62,42.76a21.46,21.46 0,0 1,2.5 6l2.18,-0.54A24,24 0,0 0,74.55 41.6ZM50.74,32.49a22.26,22.26 0,0 1,6.52 0l0.34,-2.22a24.13,24.13 0,0 0,-7.2 0ZM37.65,73.91 L33,75l1.09,-4.65 -2.2,-0.51 -1.08,4.65a2.25,2.25 0,0 0,2.7 2.7l4.65,-1.08ZM32.36,67.83 L34.55,68.34 35.31,65.12a21.41,21.41 0,0 1,-2.43 -5.9l-2.18,0.54a23.85,23.85 0,0 0,2.22 5.7ZM42.88,72.69 L39.66,73.45 40.17,75.64 42.53,75.08a24.09,24.09 0,0 0,5.71 2.22l0.54,-2.18A21.41,21.41 0,0 1,42.88 72.69ZM54,34.5A19.5,19.5 0,0 0,37.49 64.37l-1.87,8 8,-1.87A19.5,19.5 0,1 0,54 34.5Z"
android:strokeAlpha="0.95"
android:fillColor="#fff"
android:fillAlpha="0.95"/>
</vector>

Wyświetl plik

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="192dp"
android:height="192dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M48.24,30.7l0.54,2.18a21.46,21.46 0,0 0,-6 2.5L41.6,33.45A24,24 0,0 1,48.24 30.7ZM59.76,30.7 L59.22,32.88a21.46,21.46 0,0 1,6 2.5l1.16,-1.93A24,24 0,0 0,59.76 30.7ZM33.45,41.6a24,24 0,0 0,-2.75 6.64l2.18,0.54a21.46,21.46 0,0 1,2.5 -6ZM32.25,54a21.85,21.85 0,0 1,0.24 -3.26l-2.22,-0.34a24.13,24.13 0,0 0,0 7.2l2.22,-0.34A21.85,21.85 0,0 1,32.25 54ZM66.4,74.55l-1.16,-1.93a21.46,21.46 0,0 1,-6 2.5l0.54,2.18A24,24 0,0 0,66.4 74.55ZM75.75,54a21.85,21.85 0,0 1,-0.24 3.26l2.22,0.34a24.13,24.13 0,0 0,0 -7.2l-2.22,0.34A21.85,21.85 0,0 1,75.75 54ZM77.3,59.76 L75.12,59.22a21.46,21.46 0,0 1,-2.5 6l1.93,1.16A24,24 0,0 0,77.3 59.76ZM57.3,75.51a22.26,22.26 0,0 1,-6.52 0l-0.34,2.22a24.14,24.14 0,0 0,7.2 0ZM71.51,66.9a21.9,21.9 0,0 1,-4.61 4.61l1.34,1.81a24.46,24.46 0,0 0,5.08 -5.08ZM66.9,36.49a21.9,21.9 0,0 1,4.61 4.61l1.81,-1.34a24.46,24.46 0,0 0,-5.08 -5.08ZM36.49,41.1a21.9,21.9 0,0 1,4.61 -4.61l-1.34,-1.81a24.46,24.46 0,0 0,-5.08 5.08ZM74.55,41.6 L72.62,42.76a21.46,21.46 0,0 1,2.5 6l2.18,-0.54A24,24 0,0 0,74.55 41.6ZM50.74,32.49a22.26,22.26 0,0 1,6.52 0l0.34,-2.22a24.13,24.13 0,0 0,-7.2 0ZM37.65,73.91 L33,75l1.09,-4.65 -2.2,-0.51 -1.08,4.65a2.25,2.25 0,0 0,2.7 2.7l4.65,-1.08ZM32.36,67.83 L34.55,68.34 35.31,65.12a21.41,21.41 0,0 1,-2.43 -5.9l-2.18,0.54a23.85,23.85 0,0 0,2.22 5.7ZM42.88,72.69 L39.66,73.45 40.17,75.64 42.53,75.08a24.09,24.09 0,0 0,5.71 2.22l0.54,-2.18A21.41,21.41 0,0 1,42.88 72.69ZM54,34.5A19.5,19.5 0,0 0,37.49 64.37l-1.87,8 8,-1.87A19.5,19.5 0,1 0,54 34.5Z"
android:strokeAlpha="0.95"
android:fillColor="@color/core_ultramarine_icon"
android:fillAlpha="0.95"/>
</vector>

Wyświetl plik

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="192dp"
android:height="192dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M48.24,30.7l0.54,2.18a21.46,21.46 0,0 0,-6 2.5L41.6,33.45A24,24 0,0 1,48.24 30.7ZM59.76,30.7 L59.22,32.88a21.46,21.46 0,0 1,6 2.5l1.16,-1.93A24,24 0,0 0,59.76 30.7ZM33.45,41.6a24,24 0,0 0,-2.75 6.64l2.18,0.54a21.46,21.46 0,0 1,2.5 -6ZM32.25,54a21.85,21.85 0,0 1,0.24 -3.26l-2.22,-0.34a24.13,24.13 0,0 0,0 7.2l2.22,-0.34A21.85,21.85 0,0 1,32.25 54ZM66.4,74.55l-1.16,-1.93a21.46,21.46 0,0 1,-6 2.5l0.54,2.18A24,24 0,0 0,66.4 74.55ZM75.75,54a21.85,21.85 0,0 1,-0.24 3.26l2.22,0.34a24.13,24.13 0,0 0,0 -7.2l-2.22,0.34A21.85,21.85 0,0 1,75.75 54ZM77.3,59.76 L75.12,59.22a21.46,21.46 0,0 1,-2.5 6l1.93,1.16A24,24 0,0 0,77.3 59.76ZM57.3,75.51a22.26,22.26 0,0 1,-6.52 0l-0.34,2.22a24.14,24.14 0,0 0,7.2 0ZM71.51,66.9a21.9,21.9 0,0 1,-4.61 4.61l1.34,1.81a24.46,24.46 0,0 0,5.08 -5.08ZM66.9,36.49a21.9,21.9 0,0 1,4.61 4.61l1.81,-1.34a24.46,24.46 0,0 0,-5.08 -5.08ZM36.49,41.1a21.9,21.9 0,0 1,4.61 -4.61l-1.34,-1.81a24.46,24.46 0,0 0,-5.08 5.08ZM74.55,41.6 L72.62,42.76a21.46,21.46 0,0 1,2.5 6l2.18,-0.54A24,24 0,0 0,74.55 41.6ZM50.74,32.49a22.26,22.26 0,0 1,6.52 0l0.34,-2.22a24.13,24.13 0,0 0,-7.2 0ZM37.65,73.91 L33,75l1.09,-4.65 -2.2,-0.51 -1.08,4.65a2.25,2.25 0,0 0,2.7 2.7l4.65,-1.08ZM32.36,67.83 L34.55,68.34 35.31,65.12a21.41,21.41 0,0 1,-2.43 -5.9l-2.18,0.54a23.85,23.85 0,0 0,2.22 5.7ZM42.88,72.69 L39.66,73.45 40.17,75.64 42.53,75.08a24.09,24.09 0,0 0,5.71 2.22l0.54,-2.18A21.41,21.41 0,0 1,42.88 72.69ZM54,34.5A19.5,19.5 0,0 0,37.49 64.37l-1.87,8 8,-1.87A19.5,19.5 0,1 0,54 34.5Z"
android:strokeAlpha="0.95"
android:fillColor="#fff"
android:fillAlpha="0.95"/>
</vector>

Wyświetl plik

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="192dp"
android:height="192dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M48.24,30.7l0.54,2.18a21.46,21.46 0,0 0,-6 2.5L41.6,33.45A24,24 0,0 1,48.24 30.7ZM59.76,30.7 L59.22,32.88a21.46,21.46 0,0 1,6 2.5l1.16,-1.93A24,24 0,0 0,59.76 30.7ZM33.45,41.6a24,24 0,0 0,-2.75 6.64l2.18,0.54a21.46,21.46 0,0 1,2.5 -6ZM32.25,54a21.85,21.85 0,0 1,0.24 -3.26l-2.22,-0.34a24.13,24.13 0,0 0,0 7.2l2.22,-0.34A21.85,21.85 0,0 1,32.25 54ZM66.4,74.55l-1.16,-1.93a21.46,21.46 0,0 1,-6 2.5l0.54,2.18A24,24 0,0 0,66.4 74.55ZM75.75,54a21.85,21.85 0,0 1,-0.24 3.26l2.22,0.34a24.13,24.13 0,0 0,0 -7.2l-2.22,0.34A21.85,21.85 0,0 1,75.75 54ZM77.3,59.76 L75.12,59.22a21.46,21.46 0,0 1,-2.5 6l1.93,1.16A24,24 0,0 0,77.3 59.76ZM57.3,75.51a22.26,22.26 0,0 1,-6.52 0l-0.34,2.22a24.14,24.14 0,0 0,7.2 0ZM71.51,66.9a21.9,21.9 0,0 1,-4.61 4.61l1.34,1.81a24.46,24.46 0,0 0,5.08 -5.08ZM66.9,36.49a21.9,21.9 0,0 1,4.61 4.61l1.81,-1.34a24.46,24.46 0,0 0,-5.08 -5.08ZM36.49,41.1a21.9,21.9 0,0 1,4.61 -4.61l-1.34,-1.81a24.46,24.46 0,0 0,-5.08 5.08ZM74.55,41.6 L72.62,42.76a21.46,21.46 0,0 1,2.5 6l2.18,-0.54A24,24 0,0 0,74.55 41.6ZM50.74,32.49a22.26,22.26 0,0 1,6.52 0l0.34,-2.22a24.13,24.13 0,0 0,-7.2 0ZM37.65,73.91 L33,75l1.09,-4.65 -2.2,-0.51 -1.08,4.65a2.25,2.25 0,0 0,2.7 2.7l4.65,-1.08ZM32.36,67.83 L34.55,68.34 35.31,65.12a21.41,21.41 0,0 1,-2.43 -5.9l-2.18,0.54a23.85,23.85 0,0 0,2.22 5.7ZM42.88,72.69 L39.66,73.45 40.17,75.64 42.53,75.08a24.09,24.09 0,0 0,5.71 2.22l0.54,-2.18A21.41,21.41 0,0 1,42.88 72.69ZM54,34.5A19.5,19.5 0,0 0,37.49 64.37l-1.87,8 8,-1.87A19.5,19.5 0,1 0,54 34.5Z"
android:strokeAlpha="0.95"
android:fillColor="@color/core_ultramarine_icon"
android:fillAlpha="0.95"/>
</vector>

Wyświetl plik

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Signal.DayNight.NoActionBar" parent="TextSecure.LightNoActionBar">
<item name="android:windowSplashScreenBackground">@color/signal_background_primary</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
</style>
</resources>

Wyświetl plik

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Signal.DayNight.NoActionBar" parent="TextSecure.LightNoActionBar">
<item name="android:windowSplashScreenBackground">@color/signal_background_primary</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
</style>
<!-- Exists for manual override of Splash theme when setting app theme-->
<style name="Theme.Signal.DayNight.NoActionBar.LightSplash" parent="Theme.Signal.DayNight.NoActionBar">
<item name="android:windowSplashScreenBackground">@color/white</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash_light</item>
</style>
<!-- Exists for manual override of Splash theme when setting app theme-->
<style name="Theme.Signal.DayNight.NoActionBar.DarkSplash" parent="Theme.Signal.DayNight.NoActionBar">
<item name="android:windowSplashScreenBackground">@color/core_grey_95</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_splash_dark</item>
</style>
</resources>