// onClick handler for finish edit button public void finishEditAssignment(View v) { Intent data = new Intent(); boolean dueBool = false; // get the class name EditText className = (EditText) findViewById(R.id.edit_class_editText); String classStr = className.getText().toString(); // get the assignment EditText assignment = (EditText) findViewById(R.id.edit_assignment_editText); String assignmentStr = assignment.getText().toString(); // get the date from the datepicker and create a string of that date int[] userDate = getDateTimeFromPickers(); String dueDateStr = userDate[0] + 1 + "/" + userDate[1] + "/" + userDate[2]; Calendar c = Calendar.getInstance(); // set the calendar to start of today c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); // and get that as a Date Date today = c.getTime(); // reuse the calendar to set user specified date c.set(Calendar.YEAR, userDate[2]); c.set(Calendar.MONTH, userDate[0]); c.set(Calendar.DAY_OF_MONTH, userDate[1]); // get as a Date Date dateSpecified = c.getTime(); // compare the user specified date to the current date to make sure it's not before the current // date if (dateSpecified.before(today)) { dueBool = true; } boolean classBool = "".equals(classStr); boolean assignBool = "".equals(assignmentStr); if (classBool || assignBool || dueBool) { if (classBool) { Context context = getApplicationContext(); CharSequence text = "No Class, try again"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } if (assignBool) { Context context = getApplicationContext(); CharSequence text = "No assignment, try again"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } if (dueBool) { Context context = getApplicationContext(); CharSequence text = "That date is before the current date, try again"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } // if all fields have valid inputs, pass the input back to the agenda page to be published to // the page } else { db.updateAssignment(assignId, classStr, assignmentStr, dueDateStr, 1); setResult(RESULT_OK, data); finish(); } }