2013-06-21 11:56:59 -07:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
|
|
|
|
public class DynamicTheme {
|
|
|
|
|
2015-11-06 17:48:37 -08:00
|
|
|
public static final String DARK = "dark";
|
|
|
|
public static final String LIGHT = "light";
|
|
|
|
|
2013-06-21 11:56:59 -07:00
|
|
|
private int currentTheme;
|
|
|
|
|
|
|
|
public void onCreate(Activity activity) {
|
|
|
|
currentTheme = getSelectedTheme(activity);
|
|
|
|
activity.setTheme(currentTheme);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume(Activity activity) {
|
|
|
|
if (currentTheme != getSelectedTheme(activity)) {
|
2014-05-23 22:22:23 +02:00
|
|
|
Intent intent = activity.getIntent();
|
|
|
|
activity.finish();
|
|
|
|
OverridePendingTransition.invoke(activity);
|
|
|
|
activity.startActivity(intent);
|
|
|
|
OverridePendingTransition.invoke(activity);
|
2013-06-21 11:56:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 00:32:57 +01:00
|
|
|
protected int getSelectedTheme(Activity activity) {
|
2013-07-11 14:58:40 -07:00
|
|
|
String theme = TextSecurePreferences.getTheme(activity);
|
2013-06-21 11:56:59 -07:00
|
|
|
|
2015-11-06 17:48:37 -08:00
|
|
|
if (theme.equals(DARK)) return R.style.TextSecure_DarkTheme;
|
2013-06-21 11:56:59 -07:00
|
|
|
|
|
|
|
return R.style.TextSecure_LightTheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final class OverridePendingTransition {
|
|
|
|
static void invoke(Activity activity) {
|
|
|
|
activity.overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|