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

Commit c97cd147 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show hint instead of auto-populating timepicker."

parents 4345352b 07b2bb7f
Loading
Loading
Loading
Loading
+29 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.os.LocaleList;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.MathUtils;
@@ -55,6 +56,7 @@ public class TextInputTimePickerView extends RelativeLayout {
    private OnValueTypedListener mListener;

    private boolean mErrorShowing;
    private boolean mTimeSet;

    interface OnValueTypedListener {
        void onValueChanged(int inputType, int newValue);
@@ -155,8 +157,15 @@ public class TextInputTimePickerView extends RelativeLayout {
    }

    boolean validateInput() {
        final boolean inputValid = parseAndSetHourInternal(mHourEditText.getText().toString())
                && parseAndSetMinuteInternal(mMinuteEditText.getText().toString());
        final String hourText = TextUtils.isEmpty(mHourEditText.getText())
                ? mHourEditText.getHint().toString()
                : mHourEditText.getText().toString();
        final String minuteText = TextUtils.isEmpty(mMinuteEditText.getText())
                ? mMinuteEditText.getHint().toString()
                : mMinuteEditText.getText().toString();

        final boolean inputValid = parseAndSetHourInternal(hourText)
                && parseAndSetMinuteInternal(minuteText);
        setError(!inputValid);
        return inputValid;
    }
@@ -173,6 +182,14 @@ public class TextInputTimePickerView extends RelativeLayout {
        mMinuteLabel.setVisibility(enabled ? View.INVISIBLE : View.VISIBLE);
    }

    private void setTimeSet(boolean timeSet) {
        mTimeSet = mTimeSet || timeSet;
    }

    private boolean isTimeSet() {
        return mTimeSet;
    }

    /**
     * Computes the display value and updates the text of the view.
     * <p>
@@ -195,8 +212,14 @@ public class TextInputTimePickerView extends RelativeLayout {
            mAmPmSpinner.setSelection(1);
        }

        if (isTimeSet()) {
            mHourEditText.setText(String.format(hourFormat, localizedHour));
            mMinuteEditText.setText(String.format(minuteFormat, minute));
        } else {
            mHourEditText.setHint(String.format(hourFormat, localizedHour));
            mMinuteEditText.setHint(String.format(minuteFormat, minute));
        }


        if (mErrorShowing) {
            validateInput();
@@ -214,6 +237,7 @@ public class TextInputTimePickerView extends RelativeLayout {
                return false;
            }
            mListener.onValueChanged(HOURS, getHourOfDayFromLocalizedHour(hour));
            setTimeSet(true);
            return true;
        } catch (NumberFormatException e) {
            // Do nothing since we cannot parse the input.
@@ -229,6 +253,7 @@ public class TextInputTimePickerView extends RelativeLayout {
                return false;
            }
            mListener.onValueChanged(MINUTES, minutes);
            setTimeSet(true);
            return true;
        } catch (NumberFormatException e) {
            // Do nothing since we cannot parse the input.
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@
        android:textAppearance="@style/TextAppearance.Material.TimePicker.TimeLabel"
        android:importantForAccessibility="no" />

    <!-- The minutes should always be to the left of the separator,
    <!-- The minutes should always be to the right of the separator,
         regardless of the current locale's layout direction. -->
    <com.android.internal.widget.NumericTextView
        android:id="@+id/minutes"