private void initialiseColourPicker() {
   FragmentManager fm = getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   if (persistenceManager.getLightMode() == Profile.LightMode.RGBW) {
     // RGBW
     RGBWColourWheelFragment colourFragment =
         RGBWColourWheelFragment.newInstance(PersistenceManager.DEFAULT_COLOUR);
     ft.add(R.id.flThemeColourPicker, colourFragment).commit();
   } else if (persistenceManager.getLightMode() == Profile.LightMode.RGBA) {
     // RGBA
     RGBAColourWheelFragment colourFragment =
         RGBAColourWheelFragment.newInstance(PersistenceManager.DEFAULT_COLOUR);
     ft.add(R.id.flThemeColourPicker, colourFragment).commit();
   } else if (persistenceManager.getLightMode() == Profile.LightMode.RGBWW) {
     // RGBWW
     RGBWWColourWheelFragment colourFragment =
         RGBWWColourWheelFragment.newInstance(PersistenceManager.DEFAULT_COLOUR);
     ft.add(R.id.flThemeColourPicker, colourFragment).commit();
   } else if (persistenceManager.getLightMode() == Profile.LightMode.RGBAWW) {
     // RGBAWW
     RGBAWWColourWheelFragment colourFragment =
         RGBAWWColourWheelFragment.newInstance(PersistenceManager.DEFAULT_COLOUR);
     ft.add(R.id.flThemeColourPicker, colourFragment).commit();
   } else {
     // RGB
     RGBColourWheelFragment colourFragment =
         RGBColourWheelFragment.newInstance(PersistenceManager.DEFAULT_COLOUR);
     ft.add(R.id.flThemeColourPicker, colourFragment).commit();
   }
 }
 /** Creates the theme, static colours fragment. */
 private void initialiseStaticColoursFragment() {
   FragmentManager fm = getFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   int coloursPerSequence = Theme.MAX_COLOURS_PER_THEME;
   if (persistenceManager.getDidio() != null && persistenceManager.getDidio().isLegacy()) {
     coloursPerSequence = Theme.MAX_COLOURS_PER_THEME_LEGACY;
   }
   staticColours = StaticColoursFragment.newInstance(true, coloursPerSequence, theme);
   ft.add(R.id.flThemeStaticColours, staticColours).commit();
 }
  @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);
      }
    }
  }
 @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();
 }