summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/android/widget/CalendarView.java12
-rw-r--r--core/java/android/widget/DatePicker.java11
-rw-r--r--core/java/android/widget/NumberPicker.java14
3 files changed, 26 insertions, 11 deletions
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index 899e872..13a407f 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -897,10 +897,13 @@ public class CalendarView extends FrameLayout {
throw new IllegalArgumentException("fromDate: " + mMinDate.getTime()
+ " does not precede toDate: " + date.getTime());
}
- int fromDateDayOfWeek = mMinDate.get(Calendar.DAY_OF_WEEK);
- long diff = (fromDateDayOfWeek - mFirstDayOfWeek) * MILLIS_IN_DAY;
- long refDay = mMinDate.getTimeInMillis() - diff;
- return (int) ((date.getTimeInMillis() - refDay) / MILLIS_IN_WEEK);
+ long endTimeMillis = date.getTimeInMillis()
+ + date.getTimeZone().getOffset(date.getTimeInMillis());
+ long startTimeMillis = mMinDate.getTimeInMillis()
+ + mMinDate.getTimeZone().getOffset(mMinDate.getTimeInMillis());
+ long dayOffsetMillis = (mMinDate.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek)
+ * MILLIS_IN_DAY;
+ return (int) ((endTimeMillis - startTimeMillis + dayOffsetMillis) / MILLIS_IN_WEEK);
}
/**
@@ -1180,6 +1183,7 @@ public class CalendarView extends FrameLayout {
mNumCells = mShowWeekNumber ? mDaysPerWeek + 1 : mDaysPerWeek;
mWeek = weekNumber;
mTempDate.setTimeInMillis(mMinDate.getTimeInMillis());
+
mTempDate.add(Calendar.WEEK_OF_YEAR, mWeek);
mTempDate.setFirstDayOfWeek(mFirstDayOfWeek);
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index ea868a6..7293572 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -184,6 +184,8 @@ public class DatePicker extends FrameLayout {
// now set the date to the adjusted one
setDate(mTempDate.get(Calendar.YEAR), mTempDate.get(Calendar.MONTH),
mTempDate.get(Calendar.DAY_OF_MONTH));
+ updateSpinners();
+ updateCalendarView();
notifyDateChanged();
}
};
@@ -195,6 +197,7 @@ public class DatePicker extends FrameLayout {
mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
public void onSelectedDayChange(CalendarView view, int year, int month, int monthDay) {
setDate(year, month, monthDay);
+ updateSpinners();
notifyDateChanged();
}
});
@@ -469,6 +472,8 @@ public class DatePicker extends FrameLayout {
return;
}
setDate(year, month, dayOfMonth);
+ updateSpinners();
+ updateCalendarView();
notifyDateChanged();
}
@@ -489,6 +494,8 @@ public class DatePicker extends FrameLayout {
SavedState ss = (SavedState) state;
super.onRestoreInstanceState(ss.getSuperState());
setDate(ss.mYear, ss.mMonth, ss.mDay);
+ updateSpinners();
+ updateCalendarView();
}
/**
@@ -504,6 +511,8 @@ public class DatePicker extends FrameLayout {
public void init(int year, int monthOfYear, int dayOfMonth,
OnDateChangedListener onDateChangedListener) {
setDate(year, monthOfYear, dayOfMonth);
+ updateSpinners();
+ updateCalendarView();
mOnDateChangedListener = onDateChangedListener;
}
@@ -553,8 +562,6 @@ public class DatePicker extends FrameLayout {
} else if (mCurrentDate.after(mMaxDate)) {
mCurrentDate.setTimeInMillis(mMaxDate.getTimeInMillis());
}
- updateSpinners();
- updateCalendarView();
}
private void updateSpinners() {
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index c5161bc..c5b1caa 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -623,7 +623,11 @@ public class NumberPicker extends LinearLayout {
hideInputControls();
return true;
}
- if (isEventInInputText(event)) {
+ if (isEventInViewHitRect(event, mInputText)
+ || (!mIncrementButton.isShown()
+ && isEventInViewHitRect(event, mIncrementButton))
+ || (!mDecrementButton.isShown()
+ && isEventInViewHitRect(event, mDecrementButton))) {
mAdjustScrollerOnUpEvent = false;
setDrawSelectorWheel(true);
hideInputControls();
@@ -708,7 +712,7 @@ public class NumberPicker extends LinearLayout {
public boolean dispatchTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
if ((action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP)
- && !isEventInInputText(event)) {
+ && !isEventInViewHitRect(event, mInputText)) {
removeAllCallbacks();
}
return super.dispatchTouchEvent(event);
@@ -1177,10 +1181,10 @@ public class NumberPicker extends LinearLayout {
}
/**
- * @return If the <code>event</code> is in the input text.
+ * @return If the <code>event</code> is in the <code>view</code>.
*/
- private boolean isEventInInputText(MotionEvent event) {
- mInputText.getHitRect(mTempRect);
+ private boolean isEventInViewHitRect(MotionEvent event, View view) {
+ view.getHitRect(mTempRect);
return mTempRect.contains((int) event.getX(), (int) event.getY());
}