OSDN Git Service

Merge "Merge commit 'bc52ca2'"
authorMike Lockwood <lockwood@google.com>
Tue, 3 Apr 2012 19:12:58 +0000 (12:12 -0700)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Tue, 3 Apr 2012 19:12:58 +0000 (12:12 -0700)
core/java/android/app/DatePickerDialog.java
core/java/android/app/TimePickerDialog.java
core/java/android/widget/NumberPicker.java
core/res/res/layout/date_picker_holo.xml
core/res/res/layout/time_picker_holo.xml
core/res/res/values/public.xml
core/res/res/values/strings.xml
core/res/res/values/styles.xml

index bf8fde0..c62e5cf 100644 (file)
@@ -92,8 +92,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
         mCallBack = callBack;
 
         Context themeContext = getContext();
-        setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this);
-        setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel), (OnClickListener) null);
+        setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this);
         setIcon(0);
         setTitle(R.string.date_picker_dialog_title);
 
@@ -106,11 +105,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
     }
 
     public void onClick(DialogInterface dialog, int which) {
-        if (mCallBack != null) {
-            mDatePicker.clearFocus();
-            mCallBack.onDateSet(mDatePicker, mDatePicker.getYear(),
-                    mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
-        }
+        tryNotifyDateSet();
     }
 
     public void onDateChanged(DatePicker view, int year,
@@ -138,6 +133,20 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
         mDatePicker.updateDate(year, monthOfYear, dayOfMonth);
     }
 
+    private void tryNotifyDateSet() {
+        if (mCallBack != null) {
+            mDatePicker.clearFocus();
+            mCallBack.onDateSet(mDatePicker, mDatePicker.getYear(),
+                    mDatePicker.getMonth(), mDatePicker.getDayOfMonth());
+        }
+    }
+
+    @Override
+    protected void onStop() {
+        tryNotifyDateSet();
+        super.onStop();
+    }
+
     @Override
     public Bundle onSaveInstanceState() {
         Bundle state = super.onSaveInstanceState();
index 353b415..d773bc8 100644 (file)
@@ -96,9 +96,7 @@ public class TimePickerDialog extends AlertDialog
         setTitle(R.string.time_picker_dialog_title);
 
         Context themeContext = getContext();
-        setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this);
-        setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel),
-                (OnClickListener) null);
+        setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this);
 
         LayoutInflater inflater =
                 (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -114,11 +112,7 @@ public class TimePickerDialog extends AlertDialog
     }
 
     public void onClick(DialogInterface dialog, int which) {
-        if (mCallback != null) {
-            mTimePicker.clearFocus();
-            mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
-                    mTimePicker.getCurrentMinute());
-        }
+        tryNotifyTimeSet();
     }
 
     public void updateTime(int hourOfDay, int minutOfHour) {
@@ -130,6 +124,20 @@ public class TimePickerDialog extends AlertDialog
         /* do nothing */
     }
 
+    private void tryNotifyTimeSet() {
+        if (mCallback != null) {
+            mTimePicker.clearFocus();
+            mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
+                    mTimePicker.getCurrentMinute());
+        }
+    }
+
+    @Override
+    protected void onStop() {
+        tryNotifyTimeSet();
+        super.onStop();
+    }
+
     @Override
     public Bundle onSaveInstanceState() {
         Bundle state = super.onSaveInstanceState();
index 4e56cd6..d897a39 100644 (file)
@@ -112,10 +112,10 @@ public class NumberPicker extends LinearLayout {
     private static final int SELECTOR_ADJUSTMENT_DURATION_MILLIS = 800;
 
     /**
-     * The duration of scrolling to the next/previous value while changing the
-     * current value by one, i.e. increment or decrement.
+     * The duration of scrolling to the next/previous value while snapping to
+     * a given position.
      */
-    private static final int CHANGE_CURRENT_BY_ONE_SCROLL_DURATION = 300;
+    private static final int SNAP_SCROLL_DURATION = 300;
 
     /**
      * The strength of fading in the top and bottom while drawing the selector.
@@ -140,7 +140,7 @@ public class NumberPicker extends LinearLayout {
     /**
      * Coefficient for adjusting touch scroll distance.
      */
-    private static final float TOUCH_SCROLL_DECELERATION_COEFFICIENT = 2.5f;
+    private static final float TOUCH_SCROLL_DECELERATION_COEFFICIENT = 2.0f;
 
     /**
      * The resource id for the default layout.
@@ -152,7 +152,7 @@ public class NumberPicker extends LinearLayout {
      */
     private static final char[] DIGIT_CHARACTERS = new char[] {
             '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
-     };
+    };
 
     /**
      * Constant for unspecified size.
@@ -838,7 +838,13 @@ public class NumberPicker extends LinearLayout {
                     if (absDeltaMoveY > mMinFlingDistance) {
                         fling(initialVelocity);
                     } else {
-                        changeValueByOne(deltaMove < 0);
+                        final int normalizedDeltaMove =
+                            (int) (absDeltaMoveY / TOUCH_SCROLL_DECELERATION_COEFFICIENT);
+                        if (normalizedDeltaMove < mSelectorElementHeight) {
+                            snapToNextValue(deltaMove < 0);
+                        } else {
+                            snapToClosestValue();
+                        }
                     }
                     onScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                 } else {
@@ -1509,11 +1515,9 @@ public class NumberPicker extends LinearLayout {
             }
             mPreviousScrollerY = 0;
             if (increment) {
-                mFlingScroller.startScroll(0, 0, 0, -mSelectorElementHeight,
-                        CHANGE_CURRENT_BY_ONE_SCROLL_DURATION);
+                mFlingScroller.startScroll(0, 0, 0, -mSelectorElementHeight, SNAP_SCROLL_DURATION);
             } else {
-                mFlingScroller.startScroll(0, 0, 0, mSelectorElementHeight,
-                        CHANGE_CURRENT_BY_ONE_SCROLL_DURATION);
+                mFlingScroller.startScroll(0, 0, 0, mSelectorElementHeight, SNAP_SCROLL_DURATION);
             }
             invalidate();
         } else {
@@ -1902,6 +1906,42 @@ public class NumberPicker extends LinearLayout {
         return false;
     }
 
+    private void snapToNextValue(boolean increment) {
+        int deltaY = mCurrentScrollOffset - mInitialScrollOffset;
+        int amountToScroll = 0;
+        if (deltaY != 0) {
+            mPreviousScrollerY = 0;
+            if (deltaY > 0) {
+                if (increment) {
+                    amountToScroll = - deltaY;
+                } else {
+                    amountToScroll = mSelectorElementHeight - deltaY;
+                }
+            } else {
+                if (increment) {
+                    amountToScroll = - mSelectorElementHeight - deltaY;
+                } else {
+                    amountToScroll = - deltaY;
+                }
+            }
+            mFlingScroller.startScroll(0, 0, 0, amountToScroll, SNAP_SCROLL_DURATION);
+            invalidate();
+        }
+    }
+
+    private void snapToClosestValue() {
+        // adjust to the closest value
+        int deltaY = mInitialScrollOffset - mCurrentScrollOffset;
+        if (deltaY != 0) {
+            mPreviousScrollerY = 0;
+            if (Math.abs(deltaY) > mSelectorElementHeight / 2) {
+                deltaY += (deltaY > 0) ? -mSelectorElementHeight : mSelectorElementHeight;
+            }
+            mFlingScroller.startScroll(0, 0, 0, deltaY, SNAP_SCROLL_DURATION);
+            invalidate();
+        }
+    }
+
     /**
      * Command for setting the input text selection.
      */
index 57b5614..122a61a 100644 (file)
@@ -41,6 +41,8 @@
             android:id="@+id/month"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginTop="10dip"
+            android:layout_marginBottom="10dip"
             android:layout_marginLeft="16dip"
             android:layout_marginRight="16dip"
             android:focusable="true"
@@ -52,6 +54,8 @@
             android:id="@+id/day"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginTop="10dip"
+            android:layout_marginBottom="10dip"
             android:layout_marginLeft="16dip"
             android:layout_marginRight="16dip"
             android:focusable="true"
@@ -63,6 +67,8 @@
             android:id="@+id/year"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_marginTop="10dip"
+            android:layout_marginBottom="10dip"
             android:layout_marginLeft="16dip"
             android:layout_marginRight="16dip"
             android:focusable="true"
index 29c97b7..24b6194 100644 (file)
@@ -30,6 +30,8 @@
         android:id="@+id/hour"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginTop="10dip"
+        android:layout_marginBottom="10dip"
         android:layout_marginLeft="16dip"
         android:layout_marginRight="14dip"
         android:focusable="true"
@@ -49,6 +51,8 @@
         android:id="@+id/minute"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginTop="10dip"
+        android:layout_marginBottom="10dip"
         android:layout_marginLeft="14dip"
         android:layout_marginRight="16dip"
         android:focusable="true"
@@ -60,6 +64,8 @@
         android:id="@+id/amPm"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginTop="10dip"
+        android:layout_marginBottom="10dip"
         android:layout_marginLeft="16dip"
         android:layout_marginRight="16dip"
         android:focusable="true"
index b60cda7..9f29630 100644 (file)
   <java-symbol type="string" name="date_picker_increment_year_button" />
   <java-symbol type="string" name="date_time" />
   <java-symbol type="string" name="date_time_set" />
+  <java-symbol type="string" name="date_time_done" />
   <java-symbol type="string" name="day_of_week_long_friday" />
   <java-symbol type="string" name="day_of_week_long_monday" />
   <java-symbol type="string" name="day_of_week_long_saturday" />
index 8919664..718de0a 100755 (executable)
     <string name="date_picker_dialog_title">Set date</string>
     <!-- Name of the button in the date/time picker to accept the date/time change -->
     <string name="date_time_set">Set</string>
+    <!-- Name of the button in the date/time picker to accept the date/time change -->
+    <string name="date_time_done">Done</string>
 
     <!-- Security Permissions strings-->
     <!-- The default permission group for any permissions that have not explicitly set a group. -->
index 288b8b2..baeb9cc 100644 (file)
@@ -1643,7 +1643,7 @@ please see styles_device_defaults.xml.
         <item name="android:selectionDividerHeight">2dip</item>
         <item name="android:selectionDividersDistance">48dip</item>
         <item name="android:internalMinWidth">48dip</item>
-        <item name="android:internalMaxHeight">200dip</item>
+        <item name="android:internalMaxHeight">180dip</item>
         <item name="android:minFlingDistance">150dip</item>
     </style>