Loading core/java/android/widget/DatePickerCalendarDelegate.java +6 −6 Original line number Diff line number Diff line Loading @@ -534,22 +534,23 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { @Override public void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; final SavedState ss = (SavedState) state; // TODO: Move instance state into DayPickerView, YearPickerView. mCurrentDate.set(ss.getSelectedYear(), ss.getSelectedMonth(), ss.getSelectedDay()); mCurrentView = ss.getCurrentView(); mMinDate.setTimeInMillis(ss.getMinDate()); mMaxDate.setTimeInMillis(ss.getMaxDate()); onCurrentDateChanged(false); setCurrentView(mCurrentView); final int currentView = ss.getCurrentView(); setCurrentView(currentView); final int listPosition = ss.getListPosition(); if (listPosition != -1) { if (mCurrentView == VIEW_MONTH_DAY) { if (currentView == VIEW_MONTH_DAY) { mDayPickerView.setCurrentItem(listPosition); } else if (mCurrentView == VIEW_YEAR) { } else if (currentView == VIEW_YEAR) { final int listPositionOffset = ss.getListPositionOffset(); mYearPickerView.setSelectionFromTop(listPosition, listPositionOffset); } Loading Loading @@ -601,7 +602,6 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { * Class for managing state storing/restoring. */ private static class SavedState extends View.BaseSavedState { private final int mSelectedYear; private final int mSelectedMonth; private final int mSelectedDay; Loading core/java/android/widget/DayPickerView.java +92 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,12 @@ import com.android.internal.R; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.MathUtils; import android.view.View; import java.util.ArrayList; import java.util.Calendar; import java.util.Locale; Loading @@ -41,6 +44,8 @@ class DayPickerView extends ViewPager { private final Calendar mMinDate = Calendar.getInstance(); private final Calendar mMaxDate = Calendar.getInstance(); private final ArrayList<View> mMatchParentChildren = new ArrayList<>(1); private final DayPickerAdapter mAdapter; /** Temporary calendar used for date calculations. */ Loading Loading @@ -140,6 +145,93 @@ class DayPickerView extends ViewPager { }); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { populate(); // Everything below is mostly copied from FrameLayout. int count = getChildCount(); final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { measureChild(child, widthMeasureSpec, heightMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } // Account for padding too maxWidth += getPaddingLeft() + getPaddingRight(); maxHeight += getPaddingTop() + getPaddingBottom(); // Check against our minimum height and width maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); count = mMatchParentChildren.size(); if (count > 1) { for (int i = 0; i < count; i++) { final View child = mMatchParentChildren.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidthMeasureSpec; final int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } mMatchParentChildren.clear(); } public void setDayOfWeekTextAppearance(int resId) { mAdapter.setDayOfWeekTextAppearance(resId); } Loading core/java/android/widget/SimpleMonthView.java +3 −15 Original line number Diff line number Diff line Loading @@ -585,7 +585,6 @@ class SimpleMonthView extends View { mToday = day; } } mNumWeeks = calculateNumRows(); // Invalidate the old title. mTitle = null; Loading Loading @@ -616,18 +615,6 @@ class SimpleMonthView extends View { } } public void reuse() { mNumWeeks = MAX_WEEKS_IN_MONTH; requestLayout(); } private int calculateNumRows() { final int offset = findDayOffset(); final int dividend = (offset + mDaysInMonth) / DAYS_IN_WEEK; final int remainder = (offset + mDaysInMonth) % DAYS_IN_WEEK; return dividend + (remainder > 0 ? 1 : 0); } private boolean sameDay(int day, Calendar today) { return mYear == today.get(Calendar.YEAR) && mMonth == today.get(Calendar.MONTH) && day == today.get(Calendar.DAY_OF_MONTH); Loading @@ -635,8 +622,9 @@ class SimpleMonthView extends View { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int preferredHeight = mDesiredDayHeight * mNumWeeks + mDesiredDayOfWeekHeight + mDesiredMonthHeight + getPaddingTop() + getPaddingBottom(); final int preferredHeight = mDesiredDayHeight * MAX_WEEKS_IN_MONTH + mDesiredDayOfWeekHeight + mDesiredMonthHeight + getPaddingTop() + getPaddingBottom(); final int preferredWidth = mDesiredCellWidth * DAYS_IN_WEEK + getPaddingStart() + getPaddingEnd(); final int resolvedWidth = resolveSize(preferredWidth, widthMeasureSpec); Loading core/java/android/widget/TextView.java +1 −0 Original line number Diff line number Diff line Loading @@ -540,6 +540,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Layout mLayout; private boolean mLocaleChanged = false; @ViewDebug.ExportedProperty(category = "text") private int mGravity = Gravity.TOP | Gravity.START; private boolean mHorizontallyScrolling; Loading core/java/android/widget/YearPickerView.java +16 −11 Original line number Diff line number Diff line Loading @@ -178,24 +178,29 @@ class YearPickerView extends ListView { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(ITEM_LAYOUT, parent, false); final TextView v; final boolean hasNewView = convertView == null; if (hasNewView) { v = (TextView) mInflater.inflate(ITEM_LAYOUT, parent, false); } else { v = (TextView) convertView; } final int year = getYearForPosition(position); final boolean activated = mActivatedYear == year; if (hasNewView || v.isActivated() != activated) { final int textAppearanceResId; if (activated && ITEM_TEXT_ACTIVATED_APPEARANCE != 0) { textAppearanceResId = ITEM_TEXT_ACTIVATED_APPEARANCE; } else { textAppearanceResId = ITEM_TEXT_APPEARANCE; } final TextView v = (TextView) convertView; v.setText("" + year); v.setTextAppearance(v.getContext(), textAppearanceResId); v.setTextAppearance(textAppearanceResId); v.setActivated(activated); } v.setText(Integer.toString(year)); return v; } Loading Loading
core/java/android/widget/DatePickerCalendarDelegate.java +6 −6 Original line number Diff line number Diff line Loading @@ -534,22 +534,23 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { @Override public void onRestoreInstanceState(Parcelable state) { SavedState ss = (SavedState) state; final SavedState ss = (SavedState) state; // TODO: Move instance state into DayPickerView, YearPickerView. mCurrentDate.set(ss.getSelectedYear(), ss.getSelectedMonth(), ss.getSelectedDay()); mCurrentView = ss.getCurrentView(); mMinDate.setTimeInMillis(ss.getMinDate()); mMaxDate.setTimeInMillis(ss.getMaxDate()); onCurrentDateChanged(false); setCurrentView(mCurrentView); final int currentView = ss.getCurrentView(); setCurrentView(currentView); final int listPosition = ss.getListPosition(); if (listPosition != -1) { if (mCurrentView == VIEW_MONTH_DAY) { if (currentView == VIEW_MONTH_DAY) { mDayPickerView.setCurrentItem(listPosition); } else if (mCurrentView == VIEW_YEAR) { } else if (currentView == VIEW_YEAR) { final int listPositionOffset = ss.getListPositionOffset(); mYearPickerView.setSelectionFromTop(listPosition, listPositionOffset); } Loading Loading @@ -601,7 +602,6 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate { * Class for managing state storing/restoring. */ private static class SavedState extends View.BaseSavedState { private final int mSelectedYear; private final int mSelectedMonth; private final int mSelectedDay; Loading
core/java/android/widget/DayPickerView.java +92 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,12 @@ import com.android.internal.R; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.MathUtils; import android.view.View; import java.util.ArrayList; import java.util.Calendar; import java.util.Locale; Loading @@ -41,6 +44,8 @@ class DayPickerView extends ViewPager { private final Calendar mMinDate = Calendar.getInstance(); private final Calendar mMaxDate = Calendar.getInstance(); private final ArrayList<View> mMatchParentChildren = new ArrayList<>(1); private final DayPickerAdapter mAdapter; /** Temporary calendar used for date calculations. */ Loading Loading @@ -140,6 +145,93 @@ class DayPickerView extends ViewPager { }); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { populate(); // Everything below is mostly copied from FrameLayout. int count = getChildCount(); final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { measureChild(child, widthMeasureSpec, heightMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } // Account for padding too maxWidth += getPaddingLeft() + getPaddingRight(); maxHeight += getPaddingTop() + getPaddingBottom(); // Check against our minimum height and width maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); count = mMatchParentChildren.size(); if (count > 1) { for (int i = 0; i < count; i++) { final View child = mMatchParentChildren.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidthMeasureSpec; final int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } mMatchParentChildren.clear(); } public void setDayOfWeekTextAppearance(int resId) { mAdapter.setDayOfWeekTextAppearance(resId); } Loading
core/java/android/widget/SimpleMonthView.java +3 −15 Original line number Diff line number Diff line Loading @@ -585,7 +585,6 @@ class SimpleMonthView extends View { mToday = day; } } mNumWeeks = calculateNumRows(); // Invalidate the old title. mTitle = null; Loading Loading @@ -616,18 +615,6 @@ class SimpleMonthView extends View { } } public void reuse() { mNumWeeks = MAX_WEEKS_IN_MONTH; requestLayout(); } private int calculateNumRows() { final int offset = findDayOffset(); final int dividend = (offset + mDaysInMonth) / DAYS_IN_WEEK; final int remainder = (offset + mDaysInMonth) % DAYS_IN_WEEK; return dividend + (remainder > 0 ? 1 : 0); } private boolean sameDay(int day, Calendar today) { return mYear == today.get(Calendar.YEAR) && mMonth == today.get(Calendar.MONTH) && day == today.get(Calendar.DAY_OF_MONTH); Loading @@ -635,8 +622,9 @@ class SimpleMonthView extends View { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final int preferredHeight = mDesiredDayHeight * mNumWeeks + mDesiredDayOfWeekHeight + mDesiredMonthHeight + getPaddingTop() + getPaddingBottom(); final int preferredHeight = mDesiredDayHeight * MAX_WEEKS_IN_MONTH + mDesiredDayOfWeekHeight + mDesiredMonthHeight + getPaddingTop() + getPaddingBottom(); final int preferredWidth = mDesiredCellWidth * DAYS_IN_WEEK + getPaddingStart() + getPaddingEnd(); final int resolvedWidth = resolveSize(preferredWidth, widthMeasureSpec); Loading
core/java/android/widget/TextView.java +1 −0 Original line number Diff line number Diff line Loading @@ -540,6 +540,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private Layout mLayout; private boolean mLocaleChanged = false; @ViewDebug.ExportedProperty(category = "text") private int mGravity = Gravity.TOP | Gravity.START; private boolean mHorizontallyScrolling; Loading
core/java/android/widget/YearPickerView.java +16 −11 Original line number Diff line number Diff line Loading @@ -178,24 +178,29 @@ class YearPickerView extends ListView { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(ITEM_LAYOUT, parent, false); final TextView v; final boolean hasNewView = convertView == null; if (hasNewView) { v = (TextView) mInflater.inflate(ITEM_LAYOUT, parent, false); } else { v = (TextView) convertView; } final int year = getYearForPosition(position); final boolean activated = mActivatedYear == year; if (hasNewView || v.isActivated() != activated) { final int textAppearanceResId; if (activated && ITEM_TEXT_ACTIVATED_APPEARANCE != 0) { textAppearanceResId = ITEM_TEXT_ACTIVATED_APPEARANCE; } else { textAppearanceResId = ITEM_TEXT_APPEARANCE; } final TextView v = (TextView) convertView; v.setText("" + year); v.setTextAppearance(v.getContext(), textAppearanceResId); v.setTextAppearance(textAppearanceResId); v.setActivated(activated); } v.setText(Integer.toString(year)); return v; } Loading