|
@@ -17,7 +17,6 @@ import android.widget.DatePicker.OnDateChangedListener;
|
|
|
import android.widget.TimePicker;
|
|
|
import android.widget.TimePicker.OnTimeChangedListener;
|
|
|
|
|
|
-import java.text.DateFormat;
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
import de.tudarmstadt.informatik.hostage.R;
|
|
@@ -55,6 +54,11 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
this(activity, DATE_TIME_PICKER);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructor
|
|
|
+ * @param activity the activity
|
|
|
+ * @param DialogType, what kind of dialog it is (TIME_PICKER, DATE_PICKER, DATE_TIME_PICKER)
|
|
|
+ */
|
|
|
public DateTimeDialogFragment(Activity activity, int DialogType) {
|
|
|
|
|
|
this.activity = activity;
|
|
@@ -82,6 +86,10 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
this.setupRootView(mView);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Configure the root view in here.
|
|
|
+ * @param mView, root view
|
|
|
+ */
|
|
|
private void setupRootView(View mView){
|
|
|
|
|
|
mCalendar = Calendar.getInstance();
|
|
@@ -105,6 +113,10 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set the current date.
|
|
|
+ * @param timeInMillis, date in milliseconds
|
|
|
+ */
|
|
|
public void setDate(long timeInMillis){
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTimeInMillis (timeInMillis);
|
|
@@ -120,6 +132,10 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
timePicker.setCurrentMinute(min);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the current selected date.
|
|
|
+ * @return long, date in milliseconds
|
|
|
+ */
|
|
|
public long getDate(){
|
|
|
|
|
|
int day = datePicker.getDayOfMonth();
|
|
@@ -135,13 +151,29 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
|
|
|
return calendar.getTime().getTime();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The listener which will be called if the user tapped "cancel" or "ok"
|
|
|
+ */
|
|
|
public interface DateTimeDialogFragmentListener {
|
|
|
+ /**
|
|
|
+ * Called if the user tapped "ok"
|
|
|
+ * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment}
|
|
|
+ */
|
|
|
public void onDateTimePickerPositiveClick(DateTimeDialogFragment dialog);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Called if the user tapped "cancel"
|
|
|
+ * @param dialog {@link DateTimeDialogFragment DateTimeDialogFragment}
|
|
|
+ */
|
|
|
public void onDateTimePickerNegativeClick(DateTimeDialogFragment dialog);
|
|
|
}
|
|
|
private DateTimeDialogFragmentListener mListener;
|
|
|
|
|
|
+ /**
|
|
|
+ * Set the user interaction listener.
|
|
|
+ * @param listener DateTimeDialogFragmentListener
|
|
|
+ */
|
|
|
public void setDateChangeListener(DateTimeDialogFragmentListener listener){
|
|
|
this.mListener = listener;
|
|
|
}
|
|
@@ -196,50 +228,76 @@ public class DateTimeDialogFragment extends DialogFragment implements OnDateChan
|
|
|
timePicker.setOnTimeChangedListener(this);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the value of the given field after computing the field values by calling complete() first.
|
|
|
+ * @param field int
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
public int get(final int field) {
|
|
|
return mCalendar.get(field);
|
|
|
}
|
|
|
|
|
|
- public long getDateTimeMillis() {
|
|
|
- return mCalendar.getTimeInMillis();
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Set the time picker style.
|
|
|
+ * @param is24HourView
|
|
|
+ */
|
|
|
public void setIs24HourView(boolean is24HourView) {
|
|
|
timePicker.setIs24HourView(is24HourView);
|
|
|
}
|
|
|
|
|
|
- public boolean is24HourView() {
|
|
|
- return timePicker.is24HourView();
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Show / hide the calendar view of the DatePicker.
|
|
|
+ * @param calendarView boolean
|
|
|
+ */
|
|
|
public void setCalendarViewShown(boolean calendarView) {
|
|
|
datePicker.setCalendarViewShown(calendarView);
|
|
|
}
|
|
|
|
|
|
- public boolean CalendarViewShown() {
|
|
|
- return datePicker.getCalendarViewShown();
|
|
|
- }
|
|
|
|
|
|
- public void updateDate(int year, int monthOfYear, int dayOfMonth) {
|
|
|
- datePicker.updateDate(year, monthOfYear, dayOfMonth);
|
|
|
- }
|
|
|
-
|
|
|
- public void updateTime(int currentHour, int currentMinute) {
|
|
|
- timePicker.setCurrentHour(currentHour);
|
|
|
- timePicker.setCurrentMinute(currentMinute);
|
|
|
- }
|
|
|
-
|
|
|
- public String getDateTime() {
|
|
|
- //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
|
|
|
- DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
|
|
|
- return dateFormat.format(mCalendar.getTime());
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
+ * Handles date change event.
|
|
|
+ * @param view DatePicker
|
|
|
+ * @param year changed year
|
|
|
+ * @param monthOfYear changed month of Year
|
|
|
+ * @param dayOfMonth changed day of Month
|
|
|
+ */
|
|
|
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
|
|
mCalendar.set(year, monthOfYear, dayOfMonth, mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Handles on time changed events.
|
|
|
+ * @param view TimePicker
|
|
|
+ * @param hourOfDay changed hour
|
|
|
+ * @param minute changed minute
|
|
|
+ */
|
|
|
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
|
|
|
mCalendar.set(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), hourOfDay, minute);
|
|
|
}
|
|
|
+
|
|
|
+ // MAYBE NEED IN FUTURE DEVELOPMENT
|
|
|
+ // UNUSED
|
|
|
+// public long getDateTimeMillis() {
|
|
|
+// return mCalendar.getTimeInMillis();
|
|
|
+// }
|
|
|
+// public boolean CalendarViewShown() {
|
|
|
+// return datePicker.getCalendarViewShown();
|
|
|
+// }
|
|
|
+// public boolean is24HourView() {
|
|
|
+// return timePicker.is24HourView();
|
|
|
+// }
|
|
|
+// public void updateDate(int year, int monthOfYear, int dayOfMonth) {
|
|
|
+// datePicker.updateDate(year, monthOfYear, dayOfMonth);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public void updateTime(int currentHour, int currentMinute) {
|
|
|
+// timePicker.setCurrentHour(currentHour);
|
|
|
+// timePicker.setCurrentMinute(currentMinute);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public String getDateTime() {
|
|
|
+// DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity);
|
|
|
+// return dateFormat.format(mCalendar.getTime());
|
|
|
+// }
|
|
|
}
|