session-android/src/org/thoughtcrime/securesms/util/DynamicTheme.java

41 lines
1.0 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.util;
import android.app.Activity;
import android.content.Intent;
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();
activity.finish();
OverridePendingTransition.invoke(activity);
activity.startActivity(intent);
OverridePendingTransition.invoke(activity);
}
}
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
2014-06-29 03:40:57 +00:00
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);
}
}
}