mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 09:38:33 +00:00
Follow system theme on Android 10+.
This commit is contained in:
parent
2e19d0459b
commit
4e7a92637c
@ -7,6 +7,7 @@ import androidx.preference.ListPreference;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicDarkActionBarTheme extends DynamicTheme {
|
public class DynamicDarkActionBarTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) {
|
|
||||||
return R.style.TextSecure_DarkTheme_Conversation;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightTheme_Conversation;
|
return R.style.TextSecure_LightTheme_Conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkTheme_Conversation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicDarkToolbarTheme extends DynamicTheme {
|
public class DynamicDarkToolbarTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) {
|
|
||||||
return R.style.TextSecure_DarkNoActionBar_DarkToolbar;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightNoActionBar_DarkToolbar;
|
return R.style.TextSecure_LightNoActionBar_DarkToolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkNoActionBar_DarkToolbar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicIntroTheme extends DynamicTheme {
|
public class DynamicIntroTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) return R.style.TextSecure_DarkIntroTheme;
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightIntroTheme;
|
return R.style.TextSecure_LightIntroTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkIntroTheme;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicNoActionBarInviteTheme extends DynamicTheme {
|
public class DynamicNoActionBarInviteTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) return R.style.Signal_NoActionBar_Invite;
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.Signal_Light_NoActionBar_Invite;
|
return R.style.Signal_Light_NoActionBar_Invite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.Signal_NoActionBar_Invite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicNoActionBarTheme extends DynamicTheme {
|
public class DynamicNoActionBarTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) return R.style.TextSecure_DarkNoActionBar;
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightNoActionBar;
|
return R.style.TextSecure_LightNoActionBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkNoActionBar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicRegistrationTheme extends DynamicTheme {
|
public class DynamicRegistrationTheme extends DynamicTheme {
|
||||||
@Override
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
|
||||||
|
|
||||||
if (theme.equals("dark")) return R.style.TextSecure_DarkRegistrationTheme;
|
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightRegistrationTheme;
|
return R.style.TextSecure_LightRegistrationTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkRegistrationTheme;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,19 @@ package org.thoughtcrime.securesms.util;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.StyleRes;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
import androidx.appcompat.app.AppCompatDelegate;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
|
|
||||||
public class DynamicTheme {
|
public class DynamicTheme {
|
||||||
|
|
||||||
public static final String DARK = "dark";
|
public static final String DARK = "dark";
|
||||||
public static final String LIGHT = "light";
|
public static final String LIGHT = "light";
|
||||||
|
public static final String SYSTEM = "system";
|
||||||
|
|
||||||
private int currentTheme;
|
private int currentTheme;
|
||||||
|
|
||||||
@ -30,16 +34,38 @@ public class DynamicTheme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getSelectedTheme(Activity activity) {
|
private @StyleRes int getSelectedTheme(Activity activity) {
|
||||||
String theme = TextSecurePreferences.getTheme(activity);
|
String theme = TextSecurePreferences.getTheme(activity);
|
||||||
|
|
||||||
if (theme.equals(DARK)) {
|
if (theme.equals(SYSTEM) && systemThemeAvailable()) {
|
||||||
return R.style.TextSecure_DarkTheme;
|
if (isSystemInDarkTheme(activity)) {
|
||||||
|
return getDarkThemeStyle();
|
||||||
|
} else {
|
||||||
|
return getLightThemeStyle();
|
||||||
|
}
|
||||||
|
} else if (theme.equals(DARK)) {
|
||||||
|
return getDarkThemeStyle();
|
||||||
|
} else {
|
||||||
|
return getLightThemeStyle();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getLightThemeStyle() {
|
||||||
return R.style.TextSecure_LightTheme;
|
return R.style.TextSecure_LightTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @StyleRes int getDarkThemeStyle() {
|
||||||
|
return R.style.TextSecure_DarkTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean systemThemeAvailable() {
|
||||||
|
return Build.VERSION.SDK_INT >= 29;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSystemInDarkTheme(@NonNull Activity activity) {
|
||||||
|
return (activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
}
|
||||||
|
|
||||||
private static final class OverridePendingTransition {
|
private static final class OverridePendingTransition {
|
||||||
static void invoke(Activity activity) {
|
static void invoke(Activity activity) {
|
||||||
activity.overridePendingTransition(0, 0);
|
activity.overridePendingTransition(0, 0);
|
||||||
|
@ -886,7 +886,7 @@ public class TextSecurePreferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getTheme(Context context) {
|
public static String getTheme(Context context) {
|
||||||
return getStringPreference(context, THEME_PREF, "light");
|
return getStringPreference(context, THEME_PREF, DynamicTheme.systemThemeAvailable() ? DynamicTheme.SYSTEM : DynamicTheme.LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isVerifying(Context context) {
|
public static boolean isVerifying(Context context) {
|
||||||
|
16
app/src/main/res/values-v29/arrays.xml
Normal file
16
app/src/main/res/values-v29/arrays.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<string-array name="pref_theme_entries" tools:ignore="InconsistentArrays">
|
||||||
|
<item>@string/preferences__system_theme</item>
|
||||||
|
<item>@string/preferences__light_theme</item>
|
||||||
|
<item>@string/preferences__dark_theme</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_theme_values" translatable="false" tools:ignore="InconsistentArrays">
|
||||||
|
<item>system</item>
|
||||||
|
<item>light</item>
|
||||||
|
<item>dark</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
</resources>
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<string-array name="language_entries">
|
<string-array name="language_entries">
|
||||||
<!-- zz --><item>@string/preferences__default</item>
|
<!-- zz --><item>@string/preferences__default</item>
|
||||||
@ -143,12 +143,12 @@
|
|||||||
<item>vi</item>
|
<item>vi</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_theme_entries">
|
<string-array name="pref_theme_entries" tools:ignore="InconsistentArrays">
|
||||||
<item>@string/preferences__light_theme</item>
|
<item>@string/preferences__light_theme</item>
|
||||||
<item>@string/preferences__dark_theme</item>
|
<item>@string/preferences__dark_theme</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_theme_values" translatable="false">
|
<string-array name="pref_theme_values" translatable="false" tools:ignore="InconsistentArrays">
|
||||||
<item>light</item>
|
<item>light</item>
|
||||||
<item>dark</item>
|
<item>dark</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
@ -1471,7 +1471,7 @@
|
|||||||
<string name="preferences__linked_devices">Linked devices</string>
|
<string name="preferences__linked_devices">Linked devices</string>
|
||||||
<string name="preferences__light_theme">Light</string>
|
<string name="preferences__light_theme">Light</string>
|
||||||
<string name="preferences__dark_theme">Dark</string>
|
<string name="preferences__dark_theme">Dark</string>
|
||||||
<string name="preferences__system_theme">System</string>
|
<string name="preferences__system_theme">System default</string>
|
||||||
<string name="preferences__appearance">Appearance</string>
|
<string name="preferences__appearance">Appearance</string>
|
||||||
<string name="preferences__theme">Theme</string>
|
<string name="preferences__theme">Theme</string>
|
||||||
<string name="preferences__default">Default</string>
|
<string name="preferences__default">Default</string>
|
||||||
|
18
app/src/main/res/xml-v29/preferences_appearance.xml
Normal file
18
app/src/main/res/xml-v29/preferences_appearance.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<org.thoughtcrime.securesms.preferences.widgets.SignalListPreference
|
||||||
|
android:key="pref_theme"
|
||||||
|
android:title="@string/preferences__theme"
|
||||||
|
android:entries="@array/pref_theme_entries"
|
||||||
|
android:entryValues="@array/pref_theme_values"
|
||||||
|
android:defaultValue="system">
|
||||||
|
</org.thoughtcrime.securesms.preferences.widgets.SignalListPreference>
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.preferences.widgets.SignalListPreference
|
||||||
|
android:key="pref_language"
|
||||||
|
android:title="@string/preferences__language"
|
||||||
|
android:entries="@array/language_entries"
|
||||||
|
android:entryValues="@array/language_values"
|
||||||
|
android:defaultValue="zz"/>
|
||||||
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user