2013-06-21 18:56:59 +00:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
2014-03-04 09:47:27 +00:00
|
|
|
import org.thoughtcrime.securesms.ConversationActivity;
|
2013-06-23 04:44:12 +00:00
|
|
|
import org.thoughtcrime.securesms.ConversationListActivity;
|
2013-06-21 18:56:59 +00:00
|
|
|
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-04-08 14:33:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
activity.recreate();
|
|
|
|
} else {
|
|
|
|
Intent intent = activity.getIntent();
|
|
|
|
activity.finish();
|
2013-06-21 18:56:59 +00:00
|
|
|
OverridePendingTransition.invoke(activity);
|
2014-04-08 14:33:21 +00:00
|
|
|
activity.startActivity(intent);
|
2013-06-21 18:56:59 +00:00
|
|
|
OverridePendingTransition.invoke(activity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-23 04:44:12 +00:00
|
|
|
private static 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
|
|
|
|
|
|
|
if (theme.equals("light")) {
|
2013-06-23 04:44:12 +00:00
|
|
|
if (activity instanceof ConversationListActivity) return R.style.TextSecure_LightTheme_NavigationDrawer;
|
2014-03-04 09:47:27 +00:00
|
|
|
else if (activity instanceof ConversationActivity) return R.style.TextSecure_LightTheme_ConversationActivity;
|
2013-06-23 04:44:12 +00:00
|
|
|
else return R.style.TextSecure_LightTheme;
|
2013-06-21 18:56:59 +00:00
|
|
|
} else if (theme.equals("dark")) {
|
2013-06-23 04:44:12 +00:00
|
|
|
if (activity instanceof ConversationListActivity) return R.style.TextSecure_DarkTheme_NavigationDrawer;
|
2014-03-04 09:47:27 +00:00
|
|
|
else if (activity instanceof ConversationActivity) return R.style.TextSecure_DarkTheme_ConversationActivity;
|
2013-06-23 04:44:12 +00:00
|
|
|
else 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|