Skip to content

Commit 71d88f5

Browse files
Material Design Teamkendrickumstattd
authored andcommitted
[TimePicker] Fix ClockFaceView cropping in split-screen
Cropping occurred because `ClockFaceView` size calculation ignored parent constraints and radius calculation didn't update on resize. PiperOrigin-RevId: 846258916
1 parent cd3f114 commit 71d88f5

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

lib/java/com/google/android/material/timepicker/ClockFaceView.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import android.view.MotionEvent;
4646
import android.view.View;
4747
import android.view.ViewOutlineProvider;
48-
import android.view.ViewTreeObserver.OnPreDrawListener;
4948
import android.view.accessibility.AccessibilityNodeInfo;
5049
import android.widget.TextView;
5150
import androidx.annotation.FloatRange;
@@ -139,22 +138,6 @@ public ClockFaceView(@NonNull Context context, @Nullable AttributeSet attrs, int
139138
setBackgroundColor(
140139
backgroundColor == null ? defaultBackgroundColor : backgroundColor.getDefaultColor());
141140

142-
getViewTreeObserver()
143-
.addOnPreDrawListener(
144-
new OnPreDrawListener() {
145-
@Override
146-
public boolean onPreDraw() {
147-
if (!isShown()) {
148-
return true;
149-
}
150-
getViewTreeObserver().removeOnPreDrawListener(this);
151-
int circleRadius =
152-
getHeight() / 2 - clockHandView.getSelectorRadius() - clockHandPadding;
153-
setRadius(circleRadius);
154-
return true;
155-
}
156-
});
157-
158141
a.recycle();
159142

160143
setOutlineProvider(
@@ -385,8 +368,21 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
385368
// proportionally to the smaller size
386369
int size = (int) (clockSize / max3(minimumHeight / height, minimumWidth / width, 1f));
387370

371+
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
372+
if (widthSpecMode != MeasureSpec.UNSPECIFIED) {
373+
size = Math.min(size, MeasureSpec.getSize(widthMeasureSpec));
374+
}
375+
376+
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
377+
if (heightSpecMode != MeasureSpec.UNSPECIFIED) {
378+
size = Math.min(size, MeasureSpec.getSize(heightMeasureSpec));
379+
}
380+
388381
int spec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
389-
setMeasuredDimension(size, size);
382+
int circleRadius = size / 2 - clockHandView.getSelectorRadius() - clockHandPadding;
383+
if (circleRadius != getRadius()) {
384+
setRadius(circleRadius);
385+
}
390386
super.onMeasure(spec, spec);
391387
}
392388

lib/java/com/google/android/material/timepicker/res/layout-land/material_timepicker.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
android:layout_width="wrap_content"
5252
android:layout_height="wrap_content"
5353
android:layout_marginStart="@dimen/clock_face_margin_start"
54+
app:layout_constrainedWidth="true"
55+
app:layout_constraintEnd_toEndOf="parent"
5456
app:layout_constraintStart_toEndOf="@+id/material_clock_display_and_toggle"
5557
app:layout_constraintTop_toTopOf="parent" />
5658

0 commit comments

Comments
 (0)