Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60b674e0 authored by Alan Viverette's avatar Alan Viverette
Browse files

Clean up date picker attributes, add carets

Bug: 19819283
Bug: 19431364
Change-Id: Idd66f4ceb99d598c0f256d85c43bff6e25ccdd8f
parent 469d9449
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -657,7 +657,7 @@ package android {
    field public static final int headerDividersEnabled = 16843310; // 0x101022e
    field public static final deprecated int headerMonthTextAppearance = 16843926; // 0x1010496
    field public static final deprecated int headerTimeTextAppearance = 16843935; // 0x101049f
    field public static final int headerYearTextAppearance = 16843928; // 0x1010498
    field public static final deprecated int headerYearTextAppearance = 16843928; // 0x1010498
    field public static final int height = 16843093; // 0x1010155
    field public static final int hideOnContentScroll = 16843843; // 0x1010443
    field public static final int hint = 16843088; // 0x1010150
@@ -1456,7 +1456,7 @@ package android {
    field public static final int x = 16842924; // 0x10100ac
    field public static final int xlargeScreens = 16843455; // 0x10102bf
    field public static final int y = 16842925; // 0x10100ad
    field public static final int yearListItemTextAppearance = 16843929; // 0x1010499
    field public static final deprecated int yearListItemTextAppearance = 16843929; // 0x1010499
    field public static final deprecated int yearListSelectorColor = 16843930; // 0x101049a
    field public static final int yesNoPreferenceStyle = 16842896; // 0x1010090
    field public static final int zAdjustment = 16843201; // 0x10101c1
+2 −2
Original line number Diff line number Diff line
@@ -728,7 +728,7 @@ package android {
    field public static final int headerDividersEnabled = 16843310; // 0x101022e
    field public static final deprecated int headerMonthTextAppearance = 16843926; // 0x1010496
    field public static final deprecated int headerTimeTextAppearance = 16843935; // 0x101049f
    field public static final int headerYearTextAppearance = 16843928; // 0x1010498
    field public static final deprecated int headerYearTextAppearance = 16843928; // 0x1010498
    field public static final int height = 16843093; // 0x1010155
    field public static final int hideOnContentScroll = 16843843; // 0x1010443
    field public static final int hint = 16843088; // 0x1010150
@@ -1531,7 +1531,7 @@ package android {
    field public static final int x = 16842924; // 0x10100ac
    field public static final int xlargeScreens = 16843455; // 0x10102bf
    field public static final int y = 16842925; // 0x10100ad
    field public static final int yearListItemTextAppearance = 16843929; // 0x1010499
    field public static final deprecated int yearListItemTextAppearance = 16843929; // 0x1010499
    field public static final deprecated int yearListSelectorColor = 16843930; // 0x101049a
    field public static final int yesNoPreferenceStyle = 16842896; // 0x1010090
    field public static final int zAdjustment = 16843201; // 0x10101c1
+1 −0
Original line number Diff line number Diff line
@@ -11162,6 +11162,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            invalidateViewProperty(false, true);
            invalidateParentIfNeededAndWasQuickRejected();
            notifySubtreeAccessibilityStateChangedIfNeeded();
        }
    }
+5 −26
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import java.util.Locale;
 * A delegate for picking up a date (day / month / year).
 */
class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {

    private static final int USE_LOCALE = 0;

    private static final int UNINITIALIZED = -1;
@@ -61,9 +60,9 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {

    private static final int ANIMATION_DURATION = 300;

    public static final int[] ATTRS_TEXT_COLOR = new int[]{com.android.internal.R.attr.textColor};

    public static final int[] ATTRS_DISABLED_ALPHA = new int[]{
    private static final int[] ATTRS_TEXT_COLOR = new int[] {
            com.android.internal.R.attr.textColor};
    private static final int[] ATTRS_DISABLED_ALPHA = new int[] {
            com.android.internal.R.attr.disabledAlpha};

    private SimpleDateFormat mYearFormat;
@@ -157,6 +156,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {
            header.setBackground(a.getDrawable(R.styleable.DatePicker_headerBackground));
        }

        a.recycle();

        // Set up picker container.
        mAnimator = (ViewAnimator) mContainer.findViewById(R.id.animator);

@@ -174,32 +175,10 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {
        mYearPickerView.setDate(mCurrentDate.getTimeInMillis());
        mYearPickerView.setOnYearSelectedListener(mOnYearSelectedListener);

        final int yearTextAppearanceResId = a.getResourceId(
                R.styleable.DatePicker_yearListItemTextAppearance, 0);
        if (yearTextAppearanceResId != 0) {
            mYearPickerView.setYearTextAppearance(yearTextAppearanceResId);
        }

        final int yearActivatedTextAppearanceResId = a.getResourceId(
                R.styleable.DatePicker_yearListItemActivatedTextAppearance, 0);
        if (yearActivatedTextAppearanceResId != 0) {
            mYearPickerView.setYearActivatedTextAppearance(yearActivatedTextAppearanceResId);
        }

        a.recycle();

        // Set up content descriptions.
        mSelectDay = res.getString(R.string.select_day);
        mSelectYear = res.getString(R.string.select_year);

        final Animation inAnim = new AlphaAnimation(0, 1);
        inAnim.setDuration(ANIMATION_DURATION);
        mAnimator.setInAnimation(inAnim);

        final Animation outAnim = new AlphaAnimation(1, 0);
        outAnim.setDuration(ANIMATION_DURATION);
        mAnimator.setOutAnimation(outAnim);

        // Initialize for current locale. This also initializes the date, so no
        // need to call onDateChanged.
        onLocaleChanged(mCurrentLocale);
+77 −30
Original line number Diff line number Diff line
@@ -18,10 +18,15 @@ package android.widget;

import com.android.internal.widget.PagerAdapter;

import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleMonthView.OnDayClickListener;
@@ -37,9 +42,13 @@ class DayPickerAdapter extends PagerAdapter {
    private final Calendar mMinDate = Calendar.getInstance();
    private final Calendar mMaxDate = Calendar.getInstance();

    private final SparseArray<SimpleMonthView> mItems = new SparseArray<>();
    private final SparseArray<ViewHolder> mItems = new SparseArray<>();

    private Calendar mSelectedDay = Calendar.getInstance();
    private final LayoutInflater mInflater;
    private final int mLayoutResId;
    private final int mCalendarViewId;

    private Calendar mSelectedDay = null;

    private int mMonthTextAppearance;
    private int mDayOfWeekTextAppearance;
@@ -51,19 +60,29 @@ class DayPickerAdapter extends PagerAdapter {

    private OnDaySelectedListener mOnDaySelectedListener;

    private int mCount;
    private int mFirstDayOfWeek;

    public DayPickerAdapter(Context context) {
    public DayPickerAdapter(@NonNull Context context, @LayoutRes int layoutResId,
            @IdRes int calendarViewId) {
        mInflater = LayoutInflater.from(context);
        mLayoutResId = layoutResId;
        mCalendarViewId = calendarViewId;

        final TypedArray ta = context.obtainStyledAttributes(new int[] {
                com.android.internal.R.attr.colorControlHighlight});
        mDayHighlightColor = ta.getColorStateList(0);
        ta.recycle();
    }

    public void setRange(Calendar min, Calendar max) {
    public void setRange(@NonNull Calendar min, @NonNull Calendar max) {
        mMinDate.setTimeInMillis(min.getTimeInMillis());
        mMaxDate.setTimeInMillis(max.getTimeInMillis());

        final int diffYear = mMaxDate.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR);
        final int diffMonth = mMaxDate.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH);
        mCount = diffMonth + MONTHS_IN_YEAR * diffYear + 1;

        // Positions are now invalid, clear everything and start over.
        notifyDataSetChanged();
    }
@@ -80,7 +99,7 @@ class DayPickerAdapter extends PagerAdapter {
        // Update displayed views.
        final int count = mItems.size();
        for (int i = 0; i < count; i++) {
            final SimpleMonthView monthView = mItems.valueAt(i);
            final SimpleMonthView monthView = mItems.valueAt(i).calendar;
            monthView.setFirstDayOfWeek(weekStart);
        }
    }
@@ -94,23 +113,25 @@ class DayPickerAdapter extends PagerAdapter {
     *
     * @param day the selected day
     */
    public void setSelectedDay(Calendar day) {
    public void setSelectedDay(@Nullable Calendar day) {
        final int oldPosition = getPositionForDay(mSelectedDay);
        final int newPosition = getPositionForDay(day);

        // Clear the old position if necessary.
        if (oldPosition != newPosition) {
            final SimpleMonthView oldMonthView = mItems.get(oldPosition, null);
        if (oldPosition != newPosition && oldPosition >= 0) {
            final ViewHolder oldMonthView = mItems.get(oldPosition, null);
            if (oldMonthView != null) {
                oldMonthView.setSelectedDay(-1);
                oldMonthView.calendar.setSelectedDay(-1);
            }
        }

        // Set the new position.
        final SimpleMonthView newMonthView = mItems.get(newPosition, null);
        if (newPosition >= 0) {
            final ViewHolder newMonthView = mItems.get(newPosition, null);
            if (newMonthView != null) {
                final int dayOfMonth = day.get(Calendar.DAY_OF_MONTH);
            newMonthView.setSelectedDay(dayOfMonth);
                newMonthView.calendar.setSelectedDay(dayOfMonth);
            }
        }

        mSelectedDay = day;
@@ -155,14 +176,13 @@ class DayPickerAdapter extends PagerAdapter {

    @Override
    public int getCount() {
        final int diffYear = mMaxDate.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR);
        final int diffMonth = mMaxDate.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH);
        return diffMonth + MONTHS_IN_YEAR * diffYear + 1;
        return mCount;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
        final ViewHolder holder = (ViewHolder) object;
        return view == holder.container;
    }

    private int getMonthForPosition(int position) {
@@ -173,7 +193,11 @@ class DayPickerAdapter extends PagerAdapter {
        return position / MONTHS_IN_YEAR + mMinDate.get(Calendar.YEAR);
    }

    private int getPositionForDay(Calendar day) {
    private int getPositionForDay(@Nullable Calendar day) {
        if (day == null) {
            return -1;
        }

        final int yearOffset = (day.get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
        final int monthOffset = (day.get(Calendar.MONTH) - mMinDate.get(Calendar.MONTH));
        return yearOffset * MONTHS_IN_YEAR + monthOffset;
@@ -181,7 +205,9 @@ class DayPickerAdapter extends PagerAdapter {

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final SimpleMonthView v = new SimpleMonthView(container.getContext());
        final View itemView = mInflater.inflate(mLayoutResId, container, false);

        final SimpleMonthView v = (SimpleMonthView) itemView.findViewById(mCalendarViewId);
        v.setOnDayClickListener(mOnDayClickListener);
        v.setMonthTextAppearance(mMonthTextAppearance);
        v.setDayOfWeekTextAppearance(mDayOfWeekTextAppearance);
@@ -205,7 +231,7 @@ class DayPickerAdapter extends PagerAdapter {
        final int year = getYearForPosition(position);

        final int selectedDay;
        if (mSelectedDay.get(Calendar.MONTH) == month) {
        if (mSelectedDay != null && mSelectedDay.get(Calendar.MONTH) == month) {
            selectedDay = mSelectedDay.get(Calendar.DAY_OF_MONTH);
        } else {
            selectedDay = -1;
@@ -227,33 +253,34 @@ class DayPickerAdapter extends PagerAdapter {

        v.setMonthParams(selectedDay, month, year, mFirstDayOfWeek,
                enabledDayRangeStart, enabledDayRangeEnd);
        v.setPrevEnabled(position > 0);
        v.setNextEnabled(position < mCount - 1);

        mItems.put(position, v);
        final ViewHolder holder = new ViewHolder(position, itemView, v);
        mItems.put(position, holder);

        container.addView(v);
        container.addView(itemView);

        return v;
        return holder;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mItems.get(position));
        final ViewHolder holder = (ViewHolder) object;
        container.removeView(holder.container);

        mItems.remove(position);
    }

    @Override
    public int getItemPosition(Object object) {
        final int index = mItems.indexOfValue((SimpleMonthView) object);
        if (index < 0) {
            return mItems.keyAt(index);
        }
        return -1;
        final ViewHolder holder = (ViewHolder) object;
        return holder.position;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        final SimpleMonthView v = mItems.get(position);
        final SimpleMonthView v = mItems.get(position).calendar;
        if (v != null) {
            return v.getTitle();
        }
@@ -275,9 +302,29 @@ class DayPickerAdapter extends PagerAdapter {
                }
            }
        }

        @Override
        public void onNavigationClick(SimpleMonthView view, int direction, boolean animate) {
            if (mOnDaySelectedListener != null) {
                mOnDaySelectedListener.onNavigationClick(DayPickerAdapter.this, direction, animate);
            }
        }
    };

    private static class ViewHolder {
        public final int position;
        public final View container;
        public final SimpleMonthView calendar;

        public ViewHolder(int position, View container, SimpleMonthView calendar) {
            this.position = position;
            this.container = container;
            this.calendar = calendar;
        }
    }

    public interface OnDaySelectedListener {
        public void onDaySelected(DayPickerAdapter view, Calendar day);
        public void onNavigationClick(DayPickerAdapter view, int direction, boolean animate);
    }
}
Loading