コード例 #1
0
  @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);
      }
    }
  }