restart if theme changed

This commit is contained in:
Andrew Dolgov 2013-04-29 21:30:57 +04:00
parent afdc28c041
commit d9ef4625b8

View File

@ -29,6 +29,7 @@ public class CommonActivity extends SherlockFragmentActivity {
private boolean m_smallScreenMode = true;
private boolean m_compatMode = false;
private String m_theme;
protected SharedPreferences m_prefs;
@ -84,6 +85,18 @@ public class CommonActivity extends SherlockFragmentActivity {
return m_writableDb;
}
@Override
public void onResume() {
super.onResume();
if (!m_theme.equals(m_prefs.getString("theme", "THEME_DARK"))) {
Log.d(TAG, "theme changed, restarting");
finish();
startActivity(getIntent());
}
}
@Override
public void onDestroy() {
super.onDestroy();
@ -97,6 +110,12 @@ public class CommonActivity extends SherlockFragmentActivity {
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
if (savedInstanceState != null) {
m_theme = savedInstanceState.getString("theme");
} else {
m_theme = m_prefs.getString("theme", "THEME_DARK");
}
initDatabase();
m_compatMode = android.os.Build.VERSION.SDK_INT <= 10;
@ -106,6 +125,13 @@ public class CommonActivity extends SherlockFragmentActivity {
super.onCreate(savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putString("theme", m_theme);
}
public boolean isSmallScreen() {
return m_smallScreenMode;
}