fix theme func

This commit is contained in:
Alexey Kuznetsov 2016-04-02 20:24:59 +03:00
commit dd8dbf9232
2 changed files with 8 additions and 14 deletions

View file

@ -437,7 +437,7 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(((MainApplication) getApplication()).getMainTheme());
setTheme(MainApplication.getTheme(this, R.style.AppThemeLight_NoActionBar, R.style.AppThemeDark_NoActionBar));
setContentView(R.layout.activity_main);

View file

@ -30,24 +30,18 @@ public class MainApplication extends Application {
context.setTheme(getUserTheme());
}
public int getUserTheme() {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
String theme = shared.getString(MainApplication.PREFERENCE_THEME, "");
public static int getTheme(Context context, int light, int dark) {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
String theme = shared.getString(PREFERENCE_THEME, "");
if (theme.equals("Theme_Dark")) {
return R.style.AppThemeDark;
return dark;
} else {
return R.style.AppThemeLight;
return light;
}
}
public int getMainTheme() {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
String theme = shared.getString(MainApplication.PREFERENCE_THEME, "");
if (theme.equals("Theme_Dark")) {
return R.style.AppThemeDark_NoActionBar;
} else {
return R.style.AppThemeLight_NoActionBar;
}
public int getUserTheme() {
return getTheme(this, R.style.AppThemeLight, R.style.AppThemeDark);
}
static public String formatTime(int tt) {