Loading core/java/android/widget/TimePicker.java +20 −18 Original line number Diff line number Diff line Loading @@ -16,20 +16,20 @@ package android.widget; import com.android.internal.R; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.annotation.Widget; import android.content.Context; import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable.Creator; import android.util.AttributeSet; import android.util.MathUtils; import android.view.View; import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; import java.util.Locale; Loading Loading @@ -103,8 +103,8 @@ public class TimePicker extends FrameLayout { * @param hour the hour to set, in the range (0-23) * @see #getHour() */ public void setHour(int hour) { mDelegate.setHour(hour); public void setHour(@IntRange(from = 0, to = 23) int hour) { mDelegate.setHour(MathUtils.constrain(hour, 0, 23)); } /** Loading @@ -118,13 +118,13 @@ public class TimePicker extends FrameLayout { } /** * Sets the currently selected minute.. * Sets the currently selected minute. * * @param minute the minute to set, in the range (0-59) * @see #getMinute() */ public void setMinute(int minute) { mDelegate.setMinute(minute); public void setMinute(@IntRange(from = 0, to = 59) int minute) { mDelegate.setMinute(MathUtils.constrain(minute, 0, 59)); } /** Loading @@ -138,8 +138,9 @@ public class TimePicker extends FrameLayout { } /** * Sets the current hour. * Sets the currently selected hour using 24-hour time. * * @param currentHour the hour to set, in the range (0-23) * @deprecated Use {@link #setHour(int)} */ @Deprecated Loading @@ -148,33 +149,34 @@ public class TimePicker extends FrameLayout { } /** * @return the current hour in the range (0-23) * @return the currently selected hour, in the range (0-23) * @deprecated Use {@link #getHour()} */ @NonNull @Deprecated public Integer getCurrentHour() { return mDelegate.getHour(); return getHour(); } /** * Set the current minute (0-59). * Sets the currently selected minute. * * @param currentMinute the minute to set, in the range (0-59) * @deprecated Use {@link #setMinute(int)} */ @Deprecated public void setCurrentMinute(@NonNull Integer currentMinute) { mDelegate.setMinute(currentMinute); setMinute(currentMinute); } /** * @return the current minute * @return the currently selected minute, in the range (0-59) * @deprecated Use {@link #getMinute()} */ @NonNull @Deprecated public Integer getCurrentMinute() { return mDelegate.getMinute(); return getMinute(); } /** Loading Loading @@ -281,10 +283,10 @@ public class TimePicker extends FrameLayout { * for the real behavior. */ interface TimePickerDelegate { void setHour(int hour); void setHour(@IntRange(from = 0, to = 23) int hour); int getHour(); void setMinute(int minute); void setMinute(@IntRange(from = 0, to = 59) int minute); int getMinute(); void setIs24Hour(boolean is24Hour); Loading core/java/com/android/internal/widget/AlertDialogLayout.java +90 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.annotation.AttrRes; import android.annotation.Nullable; import android.annotation.StyleRes; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; Loading Loading @@ -265,4 +267,92 @@ public class AlertDialogLayout extends LinearLayout { return 0; } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int paddingLeft = mPaddingLeft; // Where right end of child should go final int width = right - left; final int childRight = width - mPaddingRight; // Space available for child final int childSpace = width - paddingLeft - mPaddingRight; final int totalLength = getMeasuredHeight(); final int count = getChildCount(); final int gravity = getGravity(); final int majorGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; final int minorGravity = gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; int childTop; switch (majorGravity) { case Gravity.BOTTOM: // totalLength contains the padding already childTop = mPaddingTop + bottom - top - totalLength; break; // totalLength contains the padding already case Gravity.CENTER_VERTICAL: childTop = mPaddingTop + (bottom - top - totalLength) / 2; break; case Gravity.TOP: default: childTop = mPaddingTop; break; } final Drawable dividerDrawable = getDividerDrawable(); final int dividerHeight = dividerDrawable == null ? 0 : dividerDrawable.getIntrinsicHeight(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child != null && child.getVisibility() != GONE) { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); int layoutGravity = lp.gravity; if (layoutGravity < 0) { layoutGravity = minorGravity; } final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity( layoutGravity, layoutDirection); final int childLeft; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = paddingLeft + ((childSpace - childWidth) / 2) + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = childRight - childWidth - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = paddingLeft + lp.leftMargin; break; } if (hasDividerBeforeChildAt(i)) { childTop += dividerHeight; } childTop += lp.topMargin; setChildFrame(child, childLeft, childTop, childWidth, childHeight); childTop += childHeight + lp.bottomMargin; } } } private void setChildFrame(View child, int left, int top, int width, int height) { child.layout(left, top, left + width, top + height); } } Loading
core/java/android/widget/TimePicker.java +20 −18 Original line number Diff line number Diff line Loading @@ -16,20 +16,20 @@ package android.widget; import com.android.internal.R; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.annotation.Widget; import android.content.Context; import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable.Creator; import android.util.AttributeSet; import android.util.MathUtils; import android.view.View; import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; import java.util.Locale; Loading Loading @@ -103,8 +103,8 @@ public class TimePicker extends FrameLayout { * @param hour the hour to set, in the range (0-23) * @see #getHour() */ public void setHour(int hour) { mDelegate.setHour(hour); public void setHour(@IntRange(from = 0, to = 23) int hour) { mDelegate.setHour(MathUtils.constrain(hour, 0, 23)); } /** Loading @@ -118,13 +118,13 @@ public class TimePicker extends FrameLayout { } /** * Sets the currently selected minute.. * Sets the currently selected minute. * * @param minute the minute to set, in the range (0-59) * @see #getMinute() */ public void setMinute(int minute) { mDelegate.setMinute(minute); public void setMinute(@IntRange(from = 0, to = 59) int minute) { mDelegate.setMinute(MathUtils.constrain(minute, 0, 59)); } /** Loading @@ -138,8 +138,9 @@ public class TimePicker extends FrameLayout { } /** * Sets the current hour. * Sets the currently selected hour using 24-hour time. * * @param currentHour the hour to set, in the range (0-23) * @deprecated Use {@link #setHour(int)} */ @Deprecated Loading @@ -148,33 +149,34 @@ public class TimePicker extends FrameLayout { } /** * @return the current hour in the range (0-23) * @return the currently selected hour, in the range (0-23) * @deprecated Use {@link #getHour()} */ @NonNull @Deprecated public Integer getCurrentHour() { return mDelegate.getHour(); return getHour(); } /** * Set the current minute (0-59). * Sets the currently selected minute. * * @param currentMinute the minute to set, in the range (0-59) * @deprecated Use {@link #setMinute(int)} */ @Deprecated public void setCurrentMinute(@NonNull Integer currentMinute) { mDelegate.setMinute(currentMinute); setMinute(currentMinute); } /** * @return the current minute * @return the currently selected minute, in the range (0-59) * @deprecated Use {@link #getMinute()} */ @NonNull @Deprecated public Integer getCurrentMinute() { return mDelegate.getMinute(); return getMinute(); } /** Loading Loading @@ -281,10 +283,10 @@ public class TimePicker extends FrameLayout { * for the real behavior. */ interface TimePickerDelegate { void setHour(int hour); void setHour(@IntRange(from = 0, to = 23) int hour); int getHour(); void setMinute(int minute); void setMinute(@IntRange(from = 0, to = 59) int minute); int getMinute(); void setIs24Hour(boolean is24Hour); Loading
core/java/com/android/internal/widget/AlertDialogLayout.java +90 −0 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import android.annotation.AttrRes; import android.annotation.Nullable; import android.annotation.StyleRes; import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; Loading Loading @@ -265,4 +267,92 @@ public class AlertDialogLayout extends LinearLayout { return 0; } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { final int paddingLeft = mPaddingLeft; // Where right end of child should go final int width = right - left; final int childRight = width - mPaddingRight; // Space available for child final int childSpace = width - paddingLeft - mPaddingRight; final int totalLength = getMeasuredHeight(); final int count = getChildCount(); final int gravity = getGravity(); final int majorGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; final int minorGravity = gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; int childTop; switch (majorGravity) { case Gravity.BOTTOM: // totalLength contains the padding already childTop = mPaddingTop + bottom - top - totalLength; break; // totalLength contains the padding already case Gravity.CENTER_VERTICAL: childTop = mPaddingTop + (bottom - top - totalLength) / 2; break; case Gravity.TOP: default: childTop = mPaddingTop; break; } final Drawable dividerDrawable = getDividerDrawable(); final int dividerHeight = dividerDrawable == null ? 0 : dividerDrawable.getIntrinsicHeight(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child != null && child.getVisibility() != GONE) { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); int layoutGravity = lp.gravity; if (layoutGravity < 0) { layoutGravity = minorGravity; } final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity( layoutGravity, layoutDirection); final int childLeft; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = paddingLeft + ((childSpace - childWidth) / 2) + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = childRight - childWidth - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = paddingLeft + lp.leftMargin; break; } if (hasDividerBeforeChildAt(i)) { childTop += dividerHeight; } childTop += lp.topMargin; setChildFrame(child, childLeft, childTop, childWidth, childHeight); childTop += childHeight + lp.bottomMargin; } } } private void setChildFrame(View child, int left, int top, int width, int height) { child.layout(left, top, left + width, top + height); } }