2013-06-21 18:56:59 +00:00
|
|
|
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)) {
|
2014-05-23 20:22:23 +00:00
|
|
|
Intent intent = activity.getIntent();
|
|
|
|
activity.finish();
|
|
|
|
OverridePendingTransition.invoke(activity);
|
|
|
|
activity.startActivity(intent);
|
|
|
|
OverridePendingTransition.invoke(activity);
|
2013-06-21 18:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-08 23:32:57 +00:00
|
|
|
protected int getSelectedTheme(Activity activity) {
|
2013-07-11 21:58:40 +00:00
|
|
|
String theme = TextSecurePreferences.getTheme(activity);
|
2013-06-21 18:56:59 +00:00
|
|
|
|
2014-06-29 03:40:57 +00:00
|
|
|
if (theme.equals("dark")) return R.style.TextSecure_DarkTheme;
|
2013-06-21 18:56:59 +00:00
|
|
|
|
|
|
|
return R.style.TextSecure_LightTheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final class OverridePendingTransition {
|
|
|
|
static void invoke(Activity activity) {
|
|
|
|
activity.overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|