private void setDailyNotes(Dialog dialog) { if (selectedCell == null) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } EditText dailyNotesEditText = (EditText) dialog.findViewById(R.id.dailynotes_edit_text); String dailyNotes = dailyNotesEditText.getText().toString(); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mCalendarView.getYear()); c.set(Calendar.MONTH, mCalendarView.getMonth()); c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth()); try { mDatabase = mDatabase.open(); if (dailyNotes.length() == 0) mDatabase.deleteDailyNotes(c); else mDatabase.setDailyNote(c, dailyNotes); Toast.makeText(this, R.string.daily_notes_saved_toast, Toast.LENGTH_LONG).show(); mDatabase.close(); mCalendarView.invalidate(); } catch (Exception e) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } }
/////////////////////// on Cell touch, quit this activity public void onTouch(Cell cell) { Intent intent = getIntent(); String action = intent.getAction(); // check which intent.action was requested if (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT)) { Intent ret = new Intent(); ret.putExtra("year", mView.getYear()); ret.putExtra("month", mView.getMonth()); ret.putExtra("day", cell.getDayOfMonth()); this.setResult(RESULT_OK, ret); finish(); // activity should be closed, then go to onActivity Result return; } else if (action.equals(Intent.ACTION_VIEW)) { Intent ret = new Intent(Intent.ACTION_VIEW); ret.putExtra("year", mView.getYear()); ret.putExtra("month", mView.getMonth()); ret.putExtra("day", cell.getDayOfMonth()); ret.setClass(this, TimeSlotListActivity.class); // finish(); //activity should be closed, then go to onActivity Result startActivity(ret); return; } // int day = cell.getDayOfMonth(); // //// change the calendar view accordingly // if(mView.firstDay(day)) // mView.previousMonth(); // else if(mView.lastDay(day)) // mView.nextMonth(); // else // return; //do nothing //// // mHandler.post(new Runnable() { // public void run() { // //show toast on the next or previous month // Toast.makeText(CalendarActivity.this, DateUtils.getMonthString(mView.getMonth(), // DateUtils.LENGTH_LONG) + " "+mView.getYear(), Toast.LENGTH_SHORT).show(); // } // }); }
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); }
private void setOvertime(Dialog dialog) { if (selectedCell == null) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } EditText hoursEditText = (EditText) dialog.findViewById(R.id.overtime_hours_edit_text); EditText minutesEditText = (EditText) dialog.findViewById(R.id.overtime_minutes_edit_text); String hours = hoursEditText.getText().toString(); String minutes = minutesEditText.getText().toString(); if (hours.equals("") && minutes.equals("")) { Toast.makeText(this, R.string.error_form_complete_something, Toast.LENGTH_SHORT).show(); return; } Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mCalendarView.getYear()); c.set(Calendar.MONTH, mCalendarView.getMonth()); c.set(Calendar.DAY_OF_MONTH, selectedCell.getDayOfMonth()); try { hours = hours.equals("") ? "0" : hours; minutes = minutes.equals("") ? "0" : minutes; long hoursFloat = Long.valueOf(hours); long minutesFloat = Long.valueOf(minutes); long overtimeMinutes = hoursFloat * 60 + minutesFloat; mDatabase = mDatabase.open(); mDatabase.setOvertime(c, overtimeMinutes); mDatabase.close(); mCalendarView.invalidate(); Toast.makeText(this, R.string.overtime_show_tip, Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(this, R.string.error_generic, Toast.LENGTH_SHORT).show(); return; } }