Merge "Add a flag for the fps of the AnalogClock" into sc-dev am: ef1e1dfb44 am: 5a2a0bfc18
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14663326 Change-Id: I16d0bb40868fea7588968aaac26b36f640ffe91b
This commit is contained in:
@@ -18,6 +18,7 @@ package android.widget;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.app.AppGlobals;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -61,8 +62,9 @@ import java.util.Locale;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public class AnalogClock extends View {
|
public class AnalogClock extends View {
|
||||||
private static final String LOG_TAG = "AnalogClock";
|
private static final String LOG_TAG = "AnalogClock";
|
||||||
|
|
||||||
/** How many times per second that the seconds hand advances. */
|
/** 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;
|
private Clock mClock;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -106,6 +108,10 @@ public class AnalogClock extends View {
|
|||||||
public AnalogClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public AnalogClock(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, 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(
|
final TypedArray a = context.obtainStyledAttributes(
|
||||||
attrs, com.android.internal.R.styleable.AnalogClock, defStyleAttr, defStyleRes);
|
attrs, com.android.internal.R.styleable.AnalogClock, defStyleAttr, defStyleRes);
|
||||||
saveAttributeDataForStyleable(context, com.android.internal.R.styleable.AnalogClock,
|
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
|
// 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
|
// ensures the second hand advances by a consistent distance despite our handler callbacks
|
||||||
// occurring at inconsistent frequencies.
|
// 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;
|
mMinutes = localTime.getMinute() + mSeconds / 60.0f;
|
||||||
mHour = localTime.getHour() + mMinutes / 60.0f;
|
mHour = localTime.getHour() + mMinutes / 60.0f;
|
||||||
mChanged = true;
|
mChanged = true;
|
||||||
@@ -781,7 +787,7 @@ public class AnalogClock extends View {
|
|||||||
// How many milliseconds through the second we currently are.
|
// How many milliseconds through the second we currently are.
|
||||||
long millisOfSecond = Duration.ofNanos(localTime.getNano()).toMillis();
|
long millisOfSecond = Duration.ofNanos(localTime.getNano()).toMillis();
|
||||||
// How many milliseconds there are between tick positions for the seconds hand.
|
// 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.
|
// How many milliseconds we are past the last tick position.
|
||||||
long millisPastLastTick = Math.round(millisOfSecond % millisPerTick);
|
long millisPastLastTick = Math.round(millisOfSecond % millisPerTick);
|
||||||
// How many milliseconds there are until the next tick position.
|
// How many milliseconds there are until the next tick position.
|
||||||
|
|||||||
@@ -199,6 +199,17 @@ public final class WidgetFlags {
|
|||||||
*/
|
*/
|
||||||
public static final float MAGNIFIER_ASPECT_RATIO_DEFAULT = 5.5f;
|
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() {
|
private WidgetFlags() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,6 +159,10 @@ final class CoreSettingsObserver extends ContentObserver {
|
|||||||
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
|
DeviceConfig.NAMESPACE_WIDGET, WidgetFlags.MAGNIFIER_ASPECT_RATIO,
|
||||||
WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
|
WidgetFlags.KEY_MAGNIFIER_ASPECT_RATIO, float.class,
|
||||||
WidgetFlags.MAGNIFIER_ASPECT_RATIO_DEFAULT));
|
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...
|
// add other device configs here...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user