@Override public void onStop() { if (optionsFragment != null && !optionsFragment.isThemeRemoved()) { // update the sequence theme.setColours(staticColours.getColours()); theme.setName(optionsFragment.getName()); for (int i = 0; i < themes.size(); i++) { if (themes.get(i).getObjId().equals(theme.getObjId())) { themes.set(i, theme); } } persistenceManager.setThemes(themes); } super.onStop(); }
@Override public void onCreate(Bundle savedInstanceState) { // get the persistence manager super.onCreate(savedInstanceState); Activity activity = getActivity(); if (activity instanceof ControlFreakActivity) { persistenceManager = ((ControlFreakActivity) activity).getPersistenceManager(); } if (persistenceManager == null) { // this should never happen! SharedPreferences prefs = getActivity().getPreferences(Activity.MODE_PRIVATE); persistenceManager = new PersistenceManager(prefs); } // Get the theme passed in or create a new theme boolean isNewTheme; if (getArguments() != null) { if (getArguments().getSerializable(ARG_THEME) != null) { theme = (Theme) getArguments().getSerializable(ARG_THEME); isNewTheme = false; } else { isNewTheme = true; theme = Theme.createDefaultTheme(); } } else { isNewTheme = true; theme = Theme.createDefaultTheme(); } themes = persistenceManager.getThemes(); // initial save if a new sequence if (isNewTheme) { if (themes.size() < Sequence.MAX_SEQUENCES) { theme.setName(getString(R.string.themeText) + String.valueOf(themes.size() + 1)); themes.add(theme); persistenceManager.setThemes(themes); } } }