Permalink
Browse files

centralize theme setting in activities

  • Loading branch information...
1 parent a7fe8e0 commit b79d13e8d2eefc72cc81c759d1d051e745537b52 @tuxmobil tuxmobil committed Mar 29, 2012
@@ -91,11 +91,7 @@
public void onCreate(Bundle savedInstanceState) {
mConfig = YaximApplication.getConfig(this);
mTheme = mConfig.theme;
- if (mConfig.theme.equals("light")) {
- setTheme(R.style.YaximLightTheme);
- } else {
- setTheme(R.style.YaximDarkTheme);
- }
+ setTheme(mConfig.getTheme());
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
@@ -5,6 +5,7 @@
import org.yaxim.androidclient.MainWindow;
import org.yaxim.androidclient.R;
+import org.yaxim.androidclient.YaximApplication;
import org.yaxim.androidclient.data.ChatProvider;
import org.yaxim.androidclient.data.ChatProvider.ChatConstants;
import org.yaxim.androidclient.data.RosterProvider;
@@ -80,20 +81,13 @@
private ServiceConnection mServiceConnection;
private XMPPChatServiceAdapter mServiceAdapter;
private int mChatFontSize;
- private SharedPreferences prefs;
@Override
public void onCreate(Bundle savedInstanceState) {
- prefs = PreferenceManager.getDefaultSharedPreferences(this);
- String theme = prefs.getString(PreferenceConstants.THEME, "dark");
- if (theme.equals("light")) {
- setTheme(R.style.YaximLightTheme);
- } else {
- setTheme(R.style.YaximDarkTheme);
- }
+ setTheme(YaximApplication.getConfig(this).getTheme());
super.onCreate(savedInstanceState);
- mChatFontSize = Integer.valueOf(prefs.getString("setSizeChat", "18"));
+ mChatFontSize = Integer.valueOf(YaximApplication.getConfig(this).chatFontSize);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.mainchat);
@@ -1,5 +1,6 @@
package org.yaxim.androidclient.data;
+import org.yaxim.androidclient.R;
import org.yaxim.androidclient.exceptions.YaximXMPPAdressMalformedException;
import org.yaxim.androidclient.util.PreferenceConstants;
import org.yaxim.androidclient.util.XMPPHelper;
@@ -38,6 +39,8 @@
public Uri notifySound;
public boolean smackdebug;
+ public String theme;
+ public String chatFontSize;
private final SharedPreferences prefs;
@@ -117,6 +120,8 @@ private void loadPrefs(SharedPreferences prefs) {
false);
this.statusMode = prefs.getString(PreferenceConstants.STATUS_MODE, "available");
this.statusMessage = prefs.getString(PreferenceConstants.STATUS_MESSAGE, "");
+ this.theme = prefs.getString(PreferenceConstants.THEME, "dark");
+ this.chatFontSize = prefs.getString("setSizeChat", "18");
try {
XMPPHelper.verifyJabberID(jabberID);
@@ -125,4 +130,13 @@ private void loadPrefs(SharedPreferences prefs) {
Log.e(TAG, "Exception in getPreferences(): " + e);
}
}
+
+
+ public int getTheme() {
+ if (theme.equals("light")) {
+ return R.style.YaximLightTheme;
+ } else {
+ return R.style.YaximDarkTheme;
+ }
+ }
}
@@ -1,5 +1,6 @@
package org.yaxim.androidclient.preferences;
+import org.yaxim.androidclient.YaximApplication;
import org.yaxim.androidclient.exceptions.YaximXMPPAdressMalformedException;
import org.yaxim.androidclient.util.PreferenceConstants;
import org.yaxim.androidclient.util.XMPPHelper;
@@ -30,12 +31,7 @@
private int themedTextColor;
public void onCreate(Bundle savedInstanceState) {
- String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(PreferenceConstants.THEME, "dark");
- if (theme.equals("light")) {
- setTheme(R.style.YaximLightTheme);
- } else {
- setTheme(R.style.YaximDarkTheme);
- }
+ setTheme(YaximApplication.getConfig(this).getTheme());
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.accountprefs);
@@ -5,17 +5,14 @@
import android.preference.PreferenceManager;
import org.yaxim.androidclient.R;
+import org.yaxim.androidclient.YaximApplication;
import org.yaxim.androidclient.util.PreferenceConstants;
public class MainPrefs extends PreferenceActivity{
- public void onCreate(Bundle savedInstanceState) {
- String theme = PreferenceManager.getDefaultSharedPreferences(this).getString(PreferenceConstants.THEME, "dark");
- if (theme.equals("light")) {
- setTheme(R.style.YaximLightTheme);
- } else {
- setTheme(R.style.YaximDarkTheme);
- }
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.layout.mainprefs);
- }
+ public void onCreate(Bundle savedInstanceState) {
+ setTheme(YaximApplication.getConfig(this).getTheme());
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.layout.mainprefs);
+ }
+
}

0 comments on commit b79d13e

Please sign in to comment.