Skip to content

Commit e3a3093

Browse files
pubiqqpekingme
authored andcommitted
[Internal] Use monotonic clock to measure time intervals
Resolves #4289 GIT_ORIGIN_REV_ID=6686c2a3101c235c1fec087a0f77acbfecd23540 PiperOrigin-RevId: 718390534
1 parent cfe8220 commit e3a3093

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

lib/java/com/google/android/material/bottomsheet/BottomSheetBehavior.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.os.Build.VERSION_CODES;
3434
import android.os.Parcel;
3535
import android.os.Parcelable;
36+
import android.os.SystemClock;
3637
import android.util.AttributeSet;
3738
import android.util.Log;
3839
import android.util.SparseIntArray;
@@ -1216,7 +1217,7 @@ public boolean isDraggableOnNestedScroll() {
12161217
return draggableOnNestedScroll;
12171218
}
12181219

1219-
/*
1220+
/**
12201221
* Sets the velocity threshold considered significant enough to trigger a slide
12211222
* to the next stable state.
12221223
*
@@ -1228,7 +1229,7 @@ public void setSignificantVelocityThreshold(int significantVelocityThreshold) {
12281229
this.significantVelocityThreshold = significantVelocityThreshold;
12291230
}
12301231

1231-
/*
1232+
/**
12321233
* Returns the significant velocity threshold.
12331234
*
12341235
* @see #setSignificantVelocityThreshold(int)
@@ -1899,7 +1900,7 @@ public boolean tryCaptureView(@NonNull View child, int pointerId) {
18991900
return false;
19001901
}
19011902
}
1902-
viewCapturedMillis = System.currentTimeMillis();
1903+
viewCapturedMillis = SystemClock.uptimeMillis();
19031904
return viewRef != null && viewRef.get() == child;
19041905
}
19051906

@@ -1929,7 +1930,7 @@ public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel)
19291930
targetState = STATE_EXPANDED;
19301931
} else {
19311932
int currentTop = releasedChild.getTop();
1932-
long dragDurationMillis = System.currentTimeMillis() - viewCapturedMillis;
1933+
long dragDurationMillis = SystemClock.uptimeMillis() - viewCapturedMillis;
19331934

19341935
if (shouldSkipHalfExpandedStateWhenDragging()) {
19351936
float yPositionPercentage = currentTop * 100f / parentHeight;

lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.graphics.PixelFormat;
2626
import android.graphics.Rect;
2727
import android.graphics.drawable.Drawable;
28+
import android.os.SystemClock;
2829
import android.util.Property;
2930
import androidx.annotation.FloatRange;
3031
import androidx.annotation.IntRange;
@@ -467,7 +468,7 @@ float getPhaseFraction() {
467468
? baseSpec.wavelengthDeterminate
468469
: baseSpec.wavelengthIndeterminate;
469470
int cycleInMs = (int) (1000f * wavelength / baseSpec.waveSpeed * durationScale);
470-
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
471+
phaseFraction = (float) (SystemClock.uptimeMillis() % cycleInMs) / cycleInMs;
471472
if (phaseFraction < 0f) {
472473
phaseFraction = (phaseFraction % 1) + 1f;
473474
}

lib/java/com/google/android/material/textfield/DropdownMenuEndIconDelegate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.animation.ValueAnimator;
2828
import android.annotation.SuppressLint;
2929
import android.content.Context;
30+
import android.os.SystemClock;
3031
import android.text.Editable;
3132
import android.view.MotionEvent;
3233
import android.view.View;
@@ -280,7 +281,7 @@ private void setUpDropdownShowHideBehavior() {
280281
}
281282

282283
private boolean isDropdownPopupActive() {
283-
long activeFor = System.currentTimeMillis() - dropdownPopupActivatedAt;
284+
long activeFor = SystemClock.uptimeMillis() - dropdownPopupActivatedAt;
284285
return activeFor < 0 || activeFor > 300;
285286
}
286287

@@ -297,7 +298,7 @@ private static AutoCompleteTextView castAutoCompleteTextViewOrThrow(EditText edi
297298

298299
private void updateDropdownPopupDirty() {
299300
dropdownPopupDirty = true;
300-
dropdownPopupActivatedAt = System.currentTimeMillis();
301+
dropdownPopupActivatedAt = SystemClock.uptimeMillis();
301302
}
302303

303304
private void setEndIconChecked(boolean checked) {

0 commit comments

Comments
 (0)