mirror of
https://github.com/oxen-io/session-android.git
synced 2025-11-13 05:33:29 +00:00
Theme Support
1) Broke out the UI elements of the major Activites into stylable attributes. 2) Created a 'light' and 'dark' theme for the newly stylable attrs. 3) Touched up some of the UI spacing. 4) Implemented dynamic theme switching support.
This commit is contained in:
61
src/org/thoughtcrime/securesms/util/DynamicTheme.java
Normal file
61
src/org/thoughtcrime/securesms/util/DynamicTheme.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class DynamicTheme {
|
||||
|
||||
private int currentTheme;
|
||||
|
||||
public void onCreate(Activity activity) {
|
||||
currentTheme = getSelectedTheme(activity);
|
||||
activity.setTheme(currentTheme);
|
||||
}
|
||||
|
||||
public void onResume(Activity activity) {
|
||||
if (currentTheme != getSelectedTheme(activity)) {
|
||||
Intent intent = activity.getIntent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
|
||||
activity.startActivity(intent);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
|
||||
OverridePendingTransition.invoke(activity);
|
||||
}
|
||||
|
||||
activity.finish();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
|
||||
OverridePendingTransition.invoke(activity);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static int getSelectedTheme(Context context) {
|
||||
String theme = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getString(ApplicationPreferencesActivity.THEME_PREF, "light");
|
||||
|
||||
return getSelectedTheme(theme);
|
||||
}
|
||||
|
||||
public static int getSelectedTheme(String theme) {
|
||||
if (theme.equals("light")) {
|
||||
return R.style.TextSecure_LightTheme;
|
||||
} else if (theme.equals("dark")) {
|
||||
return R.style.TextSecure_DarkTheme;
|
||||
}
|
||||
|
||||
return R.style.TextSecure_LightTheme;
|
||||
}
|
||||
|
||||
private static final class OverridePendingTransition {
|
||||
static void invoke(Activity activity) {
|
||||
activity.overridePendingTransition(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user