@Override protected void onPrepareDialog(final int id, final Dialog dialog, Bundle bundle) { super.onPrepareDialog(id, dialog); switch (id) { case DIALOG_SET_WORK_SHIFT_ID: currentItems = (ArrayList<String>) dialogItems.clone(); ListView dropdown = ((AlertDialog) dialog).getListView(); if (selectedCell == null) break; boolean shiftSet = selectedCell.getShift().length() == 0 ? false : true; boolean overtimeSet = selectedCell.getOvertime().length() == 0 ? false : true; boolean dailyNotesSet = selectedCell.existsDailyNote(); if (shiftSet) { currentItems.add(0, getString(R.string.change_shift)); currentItems.add(getString(R.string.delete)); } if (overtimeSet) { currentItems.add(getString(R.string.overtime_delete)); } if (dailyNotesSet) { currentItems.add(getString(R.string.daily_notes_delete)); } String[] itemArray = new String[currentItems.size()]; itemArray = currentItems.toArray(itemArray); dropdown.setAdapter( new ArrayAdapter<CharSequence>(this, android.R.layout.select_dialog_item, itemArray)); break; case DIALOG_CHANGE_WORK_SHIFT_ID: ListView dropdown2 = ((AlertDialog) dialog).getListView(); dropdown2.setAdapter( new ArrayAdapter<CharSequence>(this, android.R.layout.select_dialog_item, changeItems)); break; case DIALOG_DAILYNOTES_ID: EditText dailyNotesET = (EditText) dialog.findViewById(R.id.dailynotes_edit_text); if (bundle != null) { dailyNotesET.setText(bundle.getString("dailyNotes")); } else { dailyNotesET.setText(""); } break; case DIALOG_DAY_DETAIL: dialog.setTitle(getString(R.string.detail) + ": " + bundle.getString("date")); TextView shiftTV = (TextView) dialog.findViewById(R.id.dialog_day_detail_workshift); TextView overtimeTV = (TextView) dialog.findViewById(R.id.dialog_day_detail_overtime); TextView totalHoursTV = (TextView) dialog.findViewById(R.id.dialog_day_detail_total_hours); TextView dailyNotesTV = (TextView) dialog.findViewById(R.id.dialog_day_detail_dailyNotes); shiftTV.setText(bundle.getString("shift")); overtimeTV.setText(bundle.getString("overtime")); totalHoursTV.setText(bundle.getString("hours")); dailyNotesTV.setText(bundle.getString("dailyNotes")); break; } }
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; } }
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); }
/////////////////////// 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(); // } // }); }
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; } }