Ok, the question is. In my Android app I have two separate activities for options and for the main activity. There is the place in the main activity, when it checks for changes in options and applies the styles. It looks like this:
if (prefs.getBoolean("opt_changed", true)) {
Theme = prefs.getInt("theme", Theme);
Font = prefs.getInt("font", Font);
Size = prefs.getInt("size", Size);
SetApplicableStyle(this, Theme, Font, Size);
/** Setting opt_changed to false. */
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("opt_changed", false);
editor.commit(); // apply changes
}
SetApplicableStyle
method, called here, looks this way:
public void SetApplicableStyle (DTypeActivity dTypeActivity, int Theme, int Font, int Size) {
// Retrieving the EditText and the View as objects
final EditText edit_text = (EditText) findViewById(R.id.editText1);
final View main_view = (View) findViewById(R.id.mainview);
// Setting the theme
switch(Theme){
case 1:
SetThemeLight (this);
break;
case 2:
SetThemeBlue (this);
break;
case 3:
SetThemeDark (this);
break;
}
// Setting the font
switch(Font){
case 1:
SetFontSans (this);
break;
case 2:
SetFontSerif (this);
break;
case 3:
SetFontMono (this);
break;
}
// Setting the size
switch(Size){
case 1:
SetSizeSm (this);
break;
case 2:
SetSizeMd (this);
break;
case 3:
SetSizeBg (this);
break;
}
}
And as the example of the Set[Something][Somewhat]
methods, there is the SetThemeLight
one:
public void SetThemeLight (DTypeActivity dTypeActivity) {
final EditText edit_text = (EditText) findViewById(R.id.editText1);
final View main_view = (View) findViewById(R.id.mainview);
main_view.setBackgroundDrawable(getResources().getDrawable(R.drawable.grey_background));
edit_text.getBackground().setAlpha(0);
edit_text.setTextColor(getResources().getColor(R.color.DrText));
}
My question concerns the amount of methods, that are used in this simple app. I've been thinking on reducing the amount of code and implemented the SetApplicableStyle
method. Now I'm thinking whether it would be alright to get rid of Set[Something][Somewhat]
and put the lines from them straight to the cases of SetApplicableStyle
switches. My main concern is the amount of methods, but I know, that huge methods are also a bad practice. What would be the better solution here?
Full source code is available here.