Added in new time picker library.

Change-Id: Id252345cbb938870df02f1bb7f3dc6a65191298d
diff --git a/Android.mk b/Android.mk
index b9c730c..c0aa8cc 100644
--- a/Android.mk
+++ b/Android.mk
@@ -4,8 +4,8 @@
 # Include res dir from chips
 chips_dir := ../../../frameworks/ex/chips/res
 color_picker_dir := ../../../frameworks/opt/colorpicker/res
-
-res_dirs := $(chips_dir) $(color_picker_dir) res
+datetimepicker_dir := ../../../frameworks/opt/datetimepicker/res
+res_dirs := $(chips_dir) $(color_picker_dir) $(datetimepicker_dir) res
 src_dirs := src
 
 LOCAL_EMMA_COVERAGE_FILTER := +com.android.calendar.*
@@ -16,17 +16,18 @@
 
 # bundled
 #LOCAL_STATIC_JAVA_LIBRARIES += \
-#		android-common \
-#		android-common-chips \
-#		calendar-common
+#        android-common \
+#        android-common-chips \
+#        calendar-common
 
 # unbundled
 LOCAL_STATIC_JAVA_LIBRARIES := \
-		android-common \
-		android-common-chips \
-		colorpicker \
-		android-support-v4 \
-		calendar-common
+        android-common \
+        android-common-chips \
+        colorpicker \
+        android-opt-datetimepicker \
+        android-support-v4 \
+        calendar-common
 
 LOCAL_SDK_VERSION := 17
 
@@ -34,11 +35,13 @@
 
 LOCAL_PACKAGE_NAME := Calendar
 
-LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags \
+                             ../../../frameworks/opt/datetimepicker/proguard.flags
 
 LOCAL_AAPT_FLAGS := --auto-add-overlay
 LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips
 LOCAL_AAPT_FLAGS += --extra-packages com.android.colorpicker
+LOCAL_AAPT_FLAGS += --extra-packages com.android.datetimepicker
 
 include $(BUILD_PACKAGE)
 
diff --git a/project.properties b/project.properties
index 4f053a4..d80cd19 100644
--- a/project.properties
+++ b/project.properties
@@ -16,3 +16,4 @@
 android.library.reference.1=../../../frameworks/ex/chips
 android.library.reference.2=../../../frameworks/opt/calendar
 android.library.reference.3=../../../frameworks/opt/colorpicker
+android.library.reference.4=../../../frameworks/opt/datetimepicker
diff --git a/src/com/android/calendar/event/EditEventFragment.java b/src/com/android/calendar/event/EditEventFragment.java
index 220e17c..944ce23 100644
--- a/src/com/android/calendar/event/EditEventFragment.java
+++ b/src/com/android/calendar/event/EditEventFragment.java
@@ -127,6 +127,8 @@
     private boolean mIsReadOnly = false;
     public boolean mShowModifyDialogOnLaunch = false;
 
+    private boolean mTimeSelectedWasStartTime;
+
     private InputMethodManager mInputMethodManager;
 
     private final Intent mIntent;
@@ -522,7 +524,7 @@
         } else {
             view = inflater.inflate(R.layout.edit_event, null);
         }
-        mView = new EditEventView(mContext, view, mOnDone);
+        mView = new EditEventView(mContext, view, mOnDone, mTimeSelectedWasStartTime);
         startQuery();
 
         if (mUseCustomActionBar) {
@@ -569,6 +571,11 @@
             if (savedInstanceState.containsKey(BUNDLE_KEY_READ_ONLY)) {
                 mIsReadOnly = savedInstanceState.getBoolean(BUNDLE_KEY_READ_ONLY);
             }
+            if (savedInstanceState.containsKey("EditEventView_timebuttonclicked")) {
+                mTimeSelectedWasStartTime = savedInstanceState.getBoolean(
+                        "EditEventView_timebuttonclicked");
+            }
+
         }
     }
 
@@ -891,6 +898,8 @@
         outState.putBoolean(BUNDLE_KEY_EDIT_ON_LAUNCH, mShowModifyDialogOnLaunch);
         outState.putSerializable(BUNDLE_KEY_EVENT, mEventBundle);
         outState.putBoolean(BUNDLE_KEY_READ_ONLY, mIsReadOnly);
+
+        outState.putBoolean("EditEventView_timebuttonclicked", mView.mTimeSelectedWasStartTime);
     }
 
     @Override
diff --git a/src/com/android/calendar/event/EditEventView.java b/src/com/android/calendar/event/EditEventView.java
index ebed1e0..aa30f21 100644
--- a/src/com/android/calendar/event/EditEventView.java
+++ b/src/com/android/calendar/event/EditEventView.java
@@ -21,10 +21,13 @@
 import android.app.DatePickerDialog;
 import android.app.DatePickerDialog.OnDateSetListener;
 import android.app.FragmentManager;
+import android.app.Fragment;
+import android.app.FragmentTransaction;
 import android.app.ProgressDialog;
 import android.app.Service;
-import android.app.TimePickerDialog;
-import android.app.TimePickerDialog.OnTimeSetListener;
+import com.android.datetimepicker.TimePickerDialog;
+import com.android.datetimepicker.TimePickerDialog.OnTimeSetListener;
+import com.android.datetimepicker.TimePicker;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -72,7 +75,6 @@
 import android.widget.Spinner;
 import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;
-import android.widget.TimePicker;
 
 import com.android.calendar.CalendarEventModel;
 import com.android.calendar.CalendarEventModel.Attendee;
@@ -111,6 +113,7 @@
     private static final String GOOGLE_SECONDARY_CALENDAR = "calendar.google.com";
     private static final String PERIOD_SPACE = ". ";
     static final String FRAG_TAG_RECUR_PICKER = "recurrencePickerDialogFragment";
+    private static final String FRAG_TAG_TIME_PICKER = "timePickerDialogFragment";
 
     ArrayList<View> mEditOnlyList = new ArrayList<View>();
     ArrayList<View> mEditViewList = new ArrayList<View>();
@@ -172,6 +175,10 @@
     private Rfc822Validator mEmailValidator;
     private TimezoneAdapter mTimezoneAdapter;
 
+    public boolean mTimeSelectedWasStartTime;
+
+    private ArrayList<Integer> mRecurrenceIndexes = new ArrayList<Integer>(0);
+
     /**
      * Contents of the "minutes" spinner.  This has default values from the XML file, augmented
      * with any additional values that were already associated with the event.
@@ -285,10 +292,18 @@
 
         @Override
         public void onClick(View v) {
-            TimePickerDialog tp = new TimePickerDialog(mActivity, new TimeListener(v), mTime.hour,
-                    mTime.minute, DateFormat.is24HourFormat(mActivity));
-            tp.setCanceledOnTouchOutside(true);
-            tp.show();
+            FragmentManager fm = mActivity.getFragmentManager();
+            FragmentTransaction ft = fm.beginTransaction();
+
+            if (v == mStartTimeButton) {
+                mTimeSelectedWasStartTime = true;
+            } else {
+                mTimeSelectedWasStartTime = false;
+            }
+
+            TimePickerDialog tp = TimePickerDialog.newInstance(new TimeListener(v),
+                    mTime.hour, mTime.minute, DateFormat.is24HourFormat(mActivity));
+            tp.show(ft, FRAG_TAG_TIME_PICKER);
         }
     }
 
@@ -743,7 +758,8 @@
         return true;
     }
 
-    public EditEventView(Activity activity, View view, EditDoneRunnable done) {
+    public EditEventView(Activity activity, View view, EditDoneRunnable done,
+            boolean timeSelectedWasStartTime) {
 
         mActivity = activity;
         mView = view;
@@ -880,6 +896,17 @@
         if (rpd != null) {
             rpd.setOnRecurrenceSetListener(this);
         }
+        TimePickerDialog tpd = (TimePickerDialog) fm.findFragmentByTag(FRAG_TAG_TIME_PICKER);
+        if (tpd != null) {
+            View v;
+            mTimeSelectedWasStartTime = timeSelectedWasStartTime;
+            if (timeSelectedWasStartTime) {
+                v = mStartTimeButton;
+            } else {
+                v = mEndTimeButton;
+            }
+            tpd.setOnTimeSetListener(new TimeListener(v));
+        }
     }