@Override
    public void onClick(DialogInterface dialog, int item) {
      CharSequence option = changeItems[item];

      Calendar c = Calendar.getInstance();
      c.set(Calendar.YEAR, mCalendarView.getYear());
      c.set(Calendar.MONTH, mCalendarView.getMonth());
      c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth());

      String newShiftAbbreviation = option.toString().split(" \\(")[0];
      mDatabase = mDatabase.open();
      Shift newShift = mShiftTable.get(newShiftAbbreviation);
      String previousShift =
          mDatabase.changeWorkShift(
              c,
              newShiftAbbreviation,
              newShift.getName(),
              newShift.getColor(),
              newShift.getHours());
      mDatabase.close();
      if (previousShift != null) {

        mCalendarView.invalidate();
      }
    }
 private void refreshShiftsPreferences() {
   // Create default shifts if preferences are empty
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
   mCustomShifts = prefs.getString("shifts", "");
   if (mCustomShifts.equals("")) {
     SharedPreferences.Editor editor1 = prefs.edit();
     editor1.putString("shifts", DEFAULT_SHIFTS);
     editor1.commit();
     mCustomShifts = DEFAULT_SHIFTS;
   }
   mShiftList = Shift.parse(mCustomShifts);
   mShiftTable = new Hashtable<String, Shift>();
   changeItems = new CharSequence[mShiftList.size()];
   int i = 0;
   dialogItems = new ArrayList<String>();
   String itemRow;
   for (Shift s : mShiftList) {
     itemRow = s.getAbbreviation() + " (" + s.getName() + ")";
     changeItems[i++] = itemRow;
     dialogItems.add(itemRow);
     mShiftTable.put(s.getAbbreviation(), s);
   }
   dialogItems.add(getString(R.string.overtime_set));
   dialogItems.add(getString(R.string.daily_notes));
 }
    @Override
    public void onClick(DialogInterface dialog, int item) {
      CharSequence option = currentItems.get(item);

      Toast.makeText(getApplicationContext(), option, Toast.LENGTH_SHORT).show();

      Calendar c = Calendar.getInstance();
      c.set(Calendar.YEAR, mCalendarView.getYear());
      c.set(Calendar.MONTH, mCalendarView.getMonth());
      c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth());

      if (option.equals(getString(R.string.change_shift))) {
        showDialog(DIALOG_CHANGE_WORK_SHIFT_ID);
      } else if (option.equals(getString(R.string.delete))) {
        mDatabase = mDatabase.open();
        mDatabase.deleteShift(c);
        mDatabase.close();
      } else if (option.equals(getString(R.string.overtime_set))) {
        showDialog(DIALOG_OVERTIME_ID);
      } else if (option.equals(getString(R.string.overtime_delete))) {
        mDatabase = mDatabase.open();
        mDatabase.deleteOvertime(c);
        mDatabase.close();
      } else if (option.equals(getString(R.string.daily_notes))) {
        if (selectedCell.existsDailyNote()) {
          Bundle data = new Bundle();
          data.putSerializable("date", df.format(c.getTime()));
          mDatabase = mDatabase.open();
          String dailyNotes = mDatabase.getDailyNote(c);
          mDatabase.close();
          data.putString("dailyNotes", dailyNotes);
          showDialog(DIALOG_DAILYNOTES_ID, data);
        } else {
          showDialog(DIALOG_DAILYNOTES_ID);
        }
      } else if (option.equals(getString(R.string.daily_notes_delete))) {
        mDatabase = mDatabase.open();
        mDatabase.deleteDailyNotes(c);
        mDatabase.close();
      } else {
        String abbreviation = currentItems.get(item).split(" \\(")[0];
        mDatabase = mDatabase.open();
        Shift shift = mShiftTable.get(abbreviation);
        mDatabase.setWorkShift(
            c, abbreviation, shift.getName(), shift.getColor(), shift.getHours());
        mDatabase.close();
      }
      mCalendarView.invalidate();
    }
  public void onTouch(Cell cell) {
    selectedCell = cell;
    mStateHolder.mSavedSelectedCell = cell;

    if (cell.getOvertime().equals("") && cell.getShift().equals("") && !cell.existsDailyNote()) {
      Toast.makeText(getApplicationContext(), R.string.long_press_help, Toast.LENGTH_SHORT).show();
      return;
    }
    Bundle data = new Bundle();
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, mCalendarView.getYear());
    c.set(Calendar.MONTH, mCalendarView.getMonth());
    c.set(Calendar.DAY_OF_MONTH, cell.getDayOfMonth());
    data.putSerializable("date", df.format(c.getTime()));
    float totalHours = 0;
    if (!cell.getOvertime().equals("")) {
      mDatabase = mDatabase.open();
      long overtimeMinutes = mDatabase.getOvertime(c);
      mDatabase.close();
      data.putString("overtime", Helper.formatInterval(overtimeMinutes));
      totalHours += overtimeMinutes / 60f;
    } else {
      data.putString("overtime", getString(R.string.unknown));
    }
    if (cell.existsDailyNote()) {
      mDatabase = mDatabase.open();
      String dailyNotes = mDatabase.getDailyNote(c);
      mDatabase.close();
      data.putString("dailyNotes", dailyNotes);
    } else {
      data.putString("dailyNotes", getString(R.string.unknown));
    }
    if (!cell.getShift().equals("")) {
      Shift s = mShiftTable.get(selectedCell.getShift());
      if (s == null) {
        mDatabase = mDatabase.open();
        s = mDatabase.getShiftObject(c);
        mDatabase.close();
        data.putString("shift", selectedCell.getShift());
      }
      data.putString("shift", s.getName());
      totalHours += s.getHours();
    } else {
      data.putString("shift", getString(R.string.unknown));
    }
    String totalHoursString = Helper.formatInterval(totalHours);
    data.putString("hours", totalHoursString);
    showDialog(DIALOG_DAY_DETAIL, data);
  }