Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ef1e1df

Browse files
Stevie KideckelAndroid (Google) Code Review
authored andcommitted
Merge "Add a flag for the fps of the AnalogClock" into sc-dev
2 parents 015ab56 + 697a23f commit ef1e1df

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

core/java/android/widget/AnalogClock.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.annotation.NonNull;
2020
import android.annotation.Nullable;
21+
import android.app.AppGlobals;
2122
import android.compat.annotation.UnsupportedAppUsage;
2223
import android.content.BroadcastReceiver;
2324
import android.content.Context;
@@ -61,8 +62,9 @@
6162
@Deprecated
6263
public class AnalogClock extends View {
6364
private static final String LOG_TAG = "AnalogClock";
65+
6466
/** How many times per second that the seconds hand advances. */
65-
private static final long SECONDS_HAND_FPS = 30;
67+
private final int mSecondsHandFps;
6668

6769
private Clock mClock;
6870
@Nullable
@@ -106,6 +108,10 @@ public AnalogClock(Context context, AttributeSet attrs, int defStyleAttr) {
106108
public AnalogClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
107109
super(context, attrs, defStyleAttr, defStyleRes);
108110

111+
mSecondsHandFps = AppGlobals.getIntCoreSetting(
112+
WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS,
113+
WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT);
114+
109115
final TypedArray a = context.obtainStyledAttributes(
110116
attrs, com.android.internal.R.styleable.AnalogClock, defStyleAttr, defStyleRes);
111117
saveAttributeDataForStyleable(context, com.android.internal.R.styleable.AnalogClock,
@@ -743,7 +749,7 @@ private void onTimeChanged(LocalTime localTime, long nowMillis) {
743749
// n positions between two given numbers, where n is the number of ticks per second. This
744750
// ensures the second hand advances by a consistent distance despite our handler callbacks
745751
// occurring at inconsistent frequencies.
746-
mSeconds = Math.round(rawSeconds * SECONDS_HAND_FPS) / (float) SECONDS_HAND_FPS;
752+
mSeconds = Math.round(rawSeconds * mSecondsHandFps) / (float) mSecondsHandFps;
747753
mMinutes = localTime.getMinute() + mSeconds / 60.0f;
748754
mHour = localTime.getHour() + mMinutes / 60.0f;
749755
mChanged = true;
@@ -781,7 +787,7 @@ public void run() {
781787
// How many milliseconds through the second we currently are.
782788
long millisOfSecond = Duration.ofNanos(localTime.getNano()).toMillis();
783789
// How many milliseconds there are between tick positions for the seconds hand.
784-
double millisPerTick = 1000 / (double) SECONDS_HAND_FPS;
790+
double millisPerTick = 1000 / (double) mSecondsHandFps;
785791
// How many milliseconds we are past the last tick position.
786792
long millisPastLastTick = Math.round(millisOfSecond % millisPerTick);
787793
// How many milliseconds there are until the next tick position.

core/java/android/widget/WidgetFlags.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ public final class WidgetFlags {
199199
*/
200200
public static final float MAGNIFIER_ASPECT_RATIO_DEFAULT = 5.5f;
201201

202+
/** The flag of the fps of the analog clock seconds hand. */
203+
public static final String ANALOG_CLOCK_SECONDS_HAND_FPS =
204+
"AnalogClockFeature__analog_clock_seconds_hand_fps";
205+
206+
/** The key name used in app core settings for {@link #ANALOG_CLOCK_SECONDS_HAND_FPS}. */
207+
public static final String KEY_ANALOG_CLOCK_SECONDS_HAND_FPS =
208+
"widget__analog_clock_seconds_hand_fps";
209+
210+
/** Default value for the flag {@link #ANALOG_CLOCK_SECONDS_HAND_FPS}. */
211+
public static final int ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT = 1;
212+
202213
private WidgetFlags() {
203214
}
204215
}

services/core/java/com/android/server/am/CoreSettingsObserver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ private static class DeviceConfigEntry<T> {
159159
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
160160
WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
161161
WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
162+
sDeviceConfigEntries.add(new DeviceConfigEntry<>(
163+
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS,
164+
WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, int.class,
165+
WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT));
162166
// add other device configs here...
163167
}
164168

0 commit comments

Comments
 (0)