Add a flag for the fps of the AnalogClock

Bug: 188414386
Test: tested locally
Change-Id: I3e28f63bea6aafa0760c6938b706e44643fc12f3
This commit is contained in:
Stevie Kideckel
2021-05-20 15:06:53 +00:00
parent 65782cf2c1
commit 697a23f0cb
3 changed files with 24 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ package android.widget;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppGlobals;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -61,8 +62,9 @@ import java.util.Locale;
@Deprecated
public class AnalogClock extends View {
private static final String LOG_TAG = "AnalogClock";
/** How many times per second that the seconds hand advances. */
private static final long SECONDS_HAND_FPS = 30;
private final int mSecondsHandFps;
private Clock mClock;
@Nullable
@@ -106,6 +108,10 @@ public class AnalogClock extends View {
public AnalogClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mSecondsHandFps = AppGlobals.getIntCoreSetting(
WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS,
WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT);
final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.AnalogClock, defStyleAttr, defStyleRes);
saveAttributeDataForStyleable(context, com.android.internal.R.styleable.AnalogClock,
@@ -728,7 +734,7 @@ public class AnalogClock extends View {
// n positions between two given numbers, where n is the number of ticks per second. This
// ensures the second hand advances by a consistent distance despite our handler callbacks
// occurring at inconsistent frequencies.
mSeconds = Math.round(rawSeconds * SECONDS_HAND_FPS) / (float) SECONDS_HAND_FPS;
mSeconds = Math.round(rawSeconds * mSecondsHandFps) / (float) mSecondsHandFps;
mMinutes = localTime.getMinute() + mSeconds / 60.0f;
mHour = localTime.getHour() + mMinutes / 60.0f;
mChanged = true;
@@ -765,7 +771,7 @@ public class AnalogClock extends View {
// How many milliseconds through the second we currently are.
long millisOfSecond = Duration.ofNanos(localTime.getNano()).toMillis();
// How many milliseconds there are between tick positions for the seconds hand.
double millisPerTick = 1000 / (double) SECONDS_HAND_FPS;
double millisPerTick = 1000 / (double) mSecondsHandFps;
// How many milliseconds we are past the last tick position.
long millisPastLastTick = Math.round(millisOfSecond % millisPerTick);
// How many milliseconds there are until the next tick position.

View File

@@ -199,6 +199,17 @@ public final class WidgetFlags {
*/
public static final float MAGNIFIER_ASPECT_RATIO_DEFAULT = 5.5f;
/** The flag of the fps of the analog clock seconds hand. */
public static final String ANALOG_CLOCK_SECONDS_HAND_FPS =
"AnalogClockFeature__analog_clock_seconds_hand_fps";
/** The key name used in app core settings for {@link #ANALOG_CLOCK_SECONDS_HAND_FPS}. */
public static final String KEY_ANALOG_CLOCK_SECONDS_HAND_FPS =
"widget__analog_clock_seconds_hand_fps";
/** Default value for the flag {@link #ANALOG_CLOCK_SECONDS_HAND_FPS}. */
public static final int ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT = 1;
private WidgetFlags() {
}
}

View File

@@ -159,6 +159,10 @@ final class CoreSettingsObserver extends ContentObserver {
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
sDeviceConfigEntries.add(new DeviceConfigEntry<>(
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS,
WidgetFlags.KEY_ANALOG_CLOCK_SECONDS_HAND_FPS, int.class,
WidgetFlags.ANALOG_CLOCK_SECONDS_HAND_FPS_DEFAULT));
// add other device configs here...
}