Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1dc4d37c authored by Stevie Kideckel's avatar Stevie Kideckel Committed by Automerger Merge Worker
Browse files

Merge "Add a flag for the fps of the AnalogClock" into sc-dev am: ef1e1dfb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14663326

Change-Id: I7ca33171100ea1686cf4a2d0e33638df7c362c3d
parents 933492a0 ef1e1dfb
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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,
@@ -743,7 +749,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;
@@ -781,7 +787,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.
+11 −0
Original line number Diff line number Diff line
@@ -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() {
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -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...
    }