diff options
author | 2025-02-19 05:37:01 -0800 | |
---|---|---|
committer | 2025-02-25 11:58:15 -0800 | |
commit | 36c4f0306d7e9b9eff645a667148a5f2c5e9d17d (patch) | |
tree | dc859a050fe95c3ae5b32d30abb83f605d158faa | |
parent | 1f96aeb3601db0b74efab74e33ad162fc45773d5 (diff) |
Revert^2 "Migrate constants to resources in ViewConfiguration"
This reverts commit 54ef3f879a41f7098190f670a40d64fa4ed96f3a.
Reason for revert: b/395092092 was caused due to b/396088244, which is
a resources problem in general and has nothing to do with this change
specifically. Moreover, SysUI lock screen is already broken
(b/397348346) due to another resources change in the framework.
Change-Id: I6a8fb99ca420da0cbb35c5134f3ab93afe6c4485
-rw-r--r-- | apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java | 278 | ||||
-rw-r--r-- | core/java/android/view/ViewConfiguration.java | 231 | ||||
-rw-r--r-- | core/res/res/values/config.xml | 37 | ||||
-rw-r--r-- | core/res/res/values/symbols.xml | 11 |
4 files changed, 491 insertions, 66 deletions
diff --git a/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java index 7a7250b9e910..8e3ed6d9931c 100644 --- a/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java +++ b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java @@ -19,24 +19,27 @@ package android.view; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import android.content.Context; +import android.perftests.utils.BenchmarkState; +import android.perftests.utils.PerfStatusReporter; -import androidx.benchmark.BenchmarkState; -import androidx.benchmark.junit4.BenchmarkRule; -import androidx.test.filters.SmallTest; +import androidx.test.filters.LargeTest; +import androidx.test.runner.AndroidJUnit4; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; -@SmallTest +@LargeTest +@RunWith(AndroidJUnit4.class) public class ViewConfigurationPerfTest { @Rule - public final BenchmarkRule mBenchmarkRule = new BenchmarkRule(); + public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); private final Context mContext = getInstrumentation().getTargetContext(); @Test public void testGet_newViewConfiguration() { - final BenchmarkState state = mBenchmarkRule.getState(); + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { state.pauseTiming(); @@ -50,7 +53,7 @@ public class ViewConfigurationPerfTest { @Test public void testGet_cachedViewConfiguration() { - final BenchmarkState state = mBenchmarkRule.getState(); + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); // Do `get` once to make sure there's something cached. ViewConfiguration.get(mContext); @@ -58,4 +61,265 @@ public class ViewConfigurationPerfTest { ViewConfiguration.get(mContext); } } + + @Test + public void testGetPressedStateDuration_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getPressedStateDuration(); + } + } + + @Test + public void testGetPressedStateDuration_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getPressedStateDuration(); + + while (state.keepRunning()) { + ViewConfiguration.getPressedStateDuration(); + } + } + + @Test + public void testGetTapTimeout_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getTapTimeout(); + } + } + + @Test + public void testGetTapTimeout_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getTapTimeout(); + + while (state.keepRunning()) { + ViewConfiguration.getTapTimeout(); + } + } + + @Test + public void testGetJumpTapTimeout_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getJumpTapTimeout(); + } + } + + @Test + public void testGetJumpTapTimeout_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getJumpTapTimeout(); + + while (state.keepRunning()) { + ViewConfiguration.getJumpTapTimeout(); + } + } + + @Test + public void testGetDoubleTapTimeout_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getDoubleTapTimeout(); + } + } + + @Test + public void testGetDoubleTapTimeout_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getDoubleTapTimeout(); + + while (state.keepRunning()) { + ViewConfiguration.getDoubleTapTimeout(); + } + } + + @Test + public void testGetDoubleTapMinTime_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getDoubleTapMinTime(); + } + } + + @Test + public void testGetDoubleTapMinTime_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getDoubleTapMinTime(); + + while (state.keepRunning()) { + ViewConfiguration.getDoubleTapMinTime(); + } + } + + @Test + public void testGetZoomControlsTimeout_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getZoomControlsTimeout(); + } + } + + @Test + public void testGetZoomControlsTimeout_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getZoomControlsTimeout(); + + while (state.keepRunning()) { + ViewConfiguration.getZoomControlsTimeout(); + } + } + + @Test + public void testGetLongPressTimeout() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + ViewConfiguration.getLongPressTimeout(); + } + } + + @Test + public void testGetMultiPressTimeout() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + ViewConfiguration.getMultiPressTimeout(); + } + } + + @Test + public void testGetKeyRepeatTimeout() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + ViewConfiguration.getKeyRepeatTimeout(); + } + } + + @Test + public void testGetKeyRepeatDelay() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + ViewConfiguration.getKeyRepeatDelay(); + } + } + + @Test + public void testGetHoverTapSlop_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getHoverTapSlop(); + } + } + + @Test + public void testGetHoverTapSlop_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getHoverTapSlop(); + + while (state.keepRunning()) { + ViewConfiguration.getHoverTapSlop(); + } + } + + @Test + public void testGetScrollFriction_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getScrollFriction(); + } + } + + @Test + public void testGetScrollFriction_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getScrollFriction(); + + while (state.keepRunning()) { + ViewConfiguration.getScrollFriction(); + } + } + + @Test + public void testGetDefaultActionModeHideDuration_unCached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset any caches. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.getDefaultActionModeHideDuration(); + } + } + + @Test + public void testGetDefaultActionModeHideDuration_cached() { + final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); + // Do `get` once to make sure the value gets cached. + ViewConfiguration.getDefaultActionModeHideDuration(); + + while (state.keepRunning()) { + ViewConfiguration.getDefaultActionModeHideDuration(); + } + } } diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 9e97a8eb58aa..2895bf3f846a 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -21,7 +21,9 @@ import android.annotation.NonNull; import android.annotation.TestApi; import android.annotation.UiContext; import android.app.Activity; +import android.app.ActivityThread; import android.app.AppGlobals; +import android.app.Application; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.res.Configuration; @@ -39,14 +41,13 @@ import android.util.SparseArray; import android.util.TypedValue; import android.view.flags.Flags; +import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; /** * Contains methods to standard constants used in the UI for timeouts, sizes, and distances. */ public class ViewConfiguration { - private static final String TAG = "ViewConfiguration"; - /** * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in * dips @@ -349,6 +350,8 @@ public class ViewConfiguration { */ private static final int SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND = 500; + private static ResourceCache sResourceCache = new ResourceCache(); + private final boolean mConstructedWithContext; private final int mEdgeSlop; private final int mFadingEdgeLength; @@ -374,7 +377,6 @@ public class ViewConfiguration { private final int mOverscrollDistance; private final int mOverflingDistance; private final boolean mViewTouchScreenHapticScrollFeedbackEnabled; - @UnsupportedAppUsage private final boolean mFadingMarqueeEnabled; private final long mGlobalActionsKeyTimeout; private final float mVerticalScrollFactor; @@ -468,14 +470,12 @@ public class ViewConfiguration { mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f); mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f); - mScrollbarSize = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_scrollbarSize); + mScrollbarSize = res.getDimensionPixelSize(R.dimen.config_scrollbarSize); mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f); mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f); final TypedValue multiplierValue = new TypedValue(); - res.getValue( - com.android.internal.R.dimen.config_ambiguousGestureMultiplier, + res.getValue(R.dimen.config_ambiguousGestureMultiplier, multiplierValue, true /*resolveRefs*/); mAmbiguousGestureMultiplier = Math.max(1.0f, multiplierValue.getFloat()); @@ -488,8 +488,7 @@ public class ViewConfiguration { mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f); if (!sHasPermanentMenuKeySet) { - final int configVal = res.getInteger( - com.android.internal.R.integer.config_overrideHasPermanentMenuKey); + final int configVal = res.getInteger(R.integer.config_overrideHasPermanentMenuKey); switch (configVal) { default: @@ -516,32 +515,27 @@ public class ViewConfiguration { } } - mFadingMarqueeEnabled = res.getBoolean( - com.android.internal.R.bool.config_ui_enableFadingMarquee); - mTouchSlop = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewConfigurationTouchSlop); + mFadingMarqueeEnabled = res.getBoolean(R.bool.config_ui_enableFadingMarquee); + mTouchSlop = res.getDimensionPixelSize(R.dimen.config_viewConfigurationTouchSlop); mHandwritingSlop = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewConfigurationHandwritingSlop); - mHoverSlop = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewConfigurationHoverSlop); + R.dimen.config_viewConfigurationHandwritingSlop); + mHoverSlop = res.getDimensionPixelSize(R.dimen.config_viewConfigurationHoverSlop); mMinScrollbarTouchTarget = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_minScrollbarTouchTarget); + R.dimen.config_minScrollbarTouchTarget); mPagingTouchSlop = mTouchSlop * 2; mDoubleTapTouchSlop = mTouchSlop; mHandwritingGestureLineMargin = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewConfigurationHandwritingGestureLineMargin); + R.dimen.config_viewConfigurationHandwritingGestureLineMargin); - mMinimumFlingVelocity = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewMinFlingVelocity); - mMaximumFlingVelocity = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewMaxFlingVelocity); + mMinimumFlingVelocity = res.getDimensionPixelSize(R.dimen.config_viewMinFlingVelocity); + mMaximumFlingVelocity = res.getDimensionPixelSize(R.dimen.config_viewMaxFlingVelocity); int configMinRotaryEncoderFlingVelocity = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewMinRotaryEncoderFlingVelocity); + R.dimen.config_viewMinRotaryEncoderFlingVelocity); int configMaxRotaryEncoderFlingVelocity = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_viewMaxRotaryEncoderFlingVelocity); + R.dimen.config_viewMaxRotaryEncoderFlingVelocity); if (configMinRotaryEncoderFlingVelocity < 0 || configMaxRotaryEncoderFlingVelocity < 0) { mMinimumRotaryEncoderFlingVelocity = NO_FLING_MIN_VELOCITY; mMaximumRotaryEncoderFlingVelocity = NO_FLING_MAX_VELOCITY; @@ -551,8 +545,7 @@ public class ViewConfiguration { } int configRotaryEncoderHapticScrollFeedbackTickIntervalPixels = - res.getDimensionPixelSize( - com.android.internal.R.dimen + res.getDimensionPixelSize(R.dimen .config_rotaryEncoderAxisScrollTickInterval); mRotaryEncoderHapticScrollFeedbackTickIntervalPixels = configRotaryEncoderHapticScrollFeedbackTickIntervalPixels > 0 @@ -560,41 +553,31 @@ public class ViewConfiguration { : NO_HAPTIC_SCROLL_TICK_INTERVAL; mRotaryEncoderHapticScrollFeedbackEnabled = - res.getBoolean( - com.android.internal.R.bool + res.getBoolean(R.bool .config_viewRotaryEncoderHapticScrollFedbackEnabled); - mGlobalActionsKeyTimeout = res.getInteger( - com.android.internal.R.integer.config_globalActionsKeyTimeout); + mGlobalActionsKeyTimeout = res.getInteger(R.integer.config_globalActionsKeyTimeout); - mHorizontalScrollFactor = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_horizontalScrollFactor); - mVerticalScrollFactor = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_verticalScrollFactor); + mHorizontalScrollFactor = res.getDimensionPixelSize(R.dimen.config_horizontalScrollFactor); + mVerticalScrollFactor = res.getDimensionPixelSize(R.dimen.config_verticalScrollFactor); mShowMenuShortcutsWhenKeyboardPresent = res.getBoolean( - com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent); + R.bool.config_showMenuShortcutsWhenKeyboardPresent); - mMinScalingSpan = res.getDimensionPixelSize( - com.android.internal.R.dimen.config_minScalingSpan); + mMinScalingSpan = res.getDimensionPixelSize(R.dimen.config_minScalingSpan); - mScreenshotChordKeyTimeout = res.getInteger( - com.android.internal.R.integer.config_screenshotChordKeyTimeout); + mScreenshotChordKeyTimeout = res.getInteger(R.integer.config_screenshotChordKeyTimeout); mSmartSelectionInitializedTimeout = res.getInteger( - com.android.internal.R.integer.config_smartSelectionInitializedTimeoutMillis); + R.integer.config_smartSelectionInitializedTimeoutMillis); mSmartSelectionInitializingTimeout = res.getInteger( - com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis); - mPreferKeepClearForFocusEnabled = res.getBoolean( - com.android.internal.R.bool.config_preferKeepClearForFocus); + R.integer.config_smartSelectionInitializingTimeoutMillis); + mPreferKeepClearForFocusEnabled = res.getBoolean(R.bool.config_preferKeepClearForFocus); mViewBasedRotaryEncoderScrollHapticsEnabledConfig = - res.getBoolean( - com.android.internal.R.bool.config_viewBasedRotaryEncoderHapticsEnabled); + res.getBoolean(R.bool.config_viewBasedRotaryEncoderHapticsEnabled); mViewTouchScreenHapticScrollFeedbackEnabled = Flags.enableScrollFeedbackForTouch() - ? res.getBoolean( - com.android.internal.R.bool - .config_viewTouchScreenHapticScrollFeedbackEnabled) + ? res.getBoolean(R.bool.config_viewTouchScreenHapticScrollFeedbackEnabled) : false; } @@ -632,6 +615,7 @@ public class ViewConfiguration { @VisibleForTesting public static void resetCacheForTesting() { sConfigurations.clear(); + sResourceCache = new ResourceCache(); } /** @@ -707,7 +691,7 @@ public class ViewConfiguration { * components. */ public static int getPressedStateDuration() { - return PRESSED_STATE_DURATION; + return sResourceCache.getPressedStateDuration(); } /** @@ -752,7 +736,7 @@ public class ViewConfiguration { * considered to be a tap. */ public static int getTapTimeout() { - return TAP_TIMEOUT; + return sResourceCache.getTapTimeout(); } /** @@ -761,7 +745,7 @@ public class ViewConfiguration { * considered to be a tap. */ public static int getJumpTapTimeout() { - return JUMP_TAP_TIMEOUT; + return sResourceCache.getJumpTapTimeout(); } /** @@ -770,7 +754,7 @@ public class ViewConfiguration { * double-tap. */ public static int getDoubleTapTimeout() { - return DOUBLE_TAP_TIMEOUT; + return sResourceCache.getDoubleTapTimeout(); } /** @@ -782,7 +766,7 @@ public class ViewConfiguration { */ @UnsupportedAppUsage public static int getDoubleTapMinTime() { - return DOUBLE_TAP_MIN_TIME; + return sResourceCache.getDoubleTapMinTime(); } /** @@ -792,7 +776,7 @@ public class ViewConfiguration { * @hide */ public static int getHoverTapTimeout() { - return HOVER_TAP_TIMEOUT; + return sResourceCache.getHoverTapTimeout(); } /** @@ -803,7 +787,7 @@ public class ViewConfiguration { */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static int getHoverTapSlop() { - return HOVER_TAP_SLOP; + return sResourceCache.getHoverTapSlop(); } /** @@ -1044,7 +1028,7 @@ public class ViewConfiguration { * in milliseconds. */ public static long getZoomControlsTimeout() { - return ZOOM_CONTROLS_TIMEOUT; + return sResourceCache.getZoomControlsTimeout(); } /** @@ -1113,14 +1097,14 @@ public class ViewConfiguration { * friction. */ public static float getScrollFriction() { - return SCROLL_FRICTION; + return sResourceCache.getScrollFriction(); } /** * @return the default duration in milliseconds for {@link ActionMode#hide(long)}. */ public static long getDefaultActionModeHideDuration() { - return ACTION_MODE_HIDE_DURATION_DEFAULT; + return sResourceCache.getDefaultActionModeHideDuration(); } /** @@ -1471,8 +1455,137 @@ public class ViewConfiguration { return HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT; } - private static final int getDisplayDensity(Context context) { + private static int getDisplayDensity(Context context) { final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); return (int) (100.0f * metrics.density); } + + /** + * Fetches resource values statically and caches them locally for fast lookup. Note that these + * values will not be updated during the lifetime of a process, even if resource overlays are + * applied. + */ + private static final class ResourceCache { + + private int mPressedStateDuration = -1; + private int mTapTimeout = -1; + private int mJumpTapTimeout = -1; + private int mDoubleTapTimeout = -1; + private int mDoubleTapMinTime = -1; + private int mHoverTapTimeout = -1; + private int mHoverTapSlop = -1; + private long mZoomControlsTimeout = -1L; + private float mScrollFriction = -1f; + private long mDefaultActionModeHideDuration = -1L; + + public int getPressedStateDuration() { + if (mPressedStateDuration < 0) { + Resources resources = getCurrentResources(); + mPressedStateDuration = resources != null + ? resources.getInteger(R.integer.config_pressedStateDurationMillis) + : PRESSED_STATE_DURATION; + } + return mPressedStateDuration; + } + + public int getTapTimeout() { + if (mTapTimeout < 0) { + Resources resources = getCurrentResources(); + mTapTimeout = resources != null + ? resources.getInteger(R.integer.config_tapTimeoutMillis) + : TAP_TIMEOUT; + } + return mTapTimeout; + } + + public int getJumpTapTimeout() { + if (mJumpTapTimeout < 0) { + Resources resources = getCurrentResources(); + mJumpTapTimeout = resources != null + ? resources.getInteger(R.integer.config_jumpTapTimeoutMillis) + : JUMP_TAP_TIMEOUT; + } + return mJumpTapTimeout; + } + + public int getDoubleTapTimeout() { + if (mDoubleTapTimeout < 0) { + Resources resources = getCurrentResources(); + mDoubleTapTimeout = resources != null + ? resources.getInteger(R.integer.config_doubleTapTimeoutMillis) + : DOUBLE_TAP_TIMEOUT; + } + return mDoubleTapTimeout; + } + + public int getDoubleTapMinTime() { + if (mDoubleTapMinTime < 0) { + Resources resources = getCurrentResources(); + mDoubleTapMinTime = resources != null + ? resources.getInteger(R.integer.config_doubleTapMinTimeMillis) + : DOUBLE_TAP_MIN_TIME; + } + return mDoubleTapMinTime; + } + + public int getHoverTapTimeout() { + if (mHoverTapTimeout < 0) { + Resources resources = getCurrentResources(); + mHoverTapTimeout = resources != null + ? resources.getInteger(R.integer.config_hoverTapTimeoutMillis) + : HOVER_TAP_TIMEOUT; + } + return mHoverTapTimeout; + } + + public int getHoverTapSlop() { + if (mHoverTapSlop < 0) { + Resources resources = getCurrentResources(); + mHoverTapSlop = resources != null + ? resources.getDimensionPixelSize(R.dimen.config_hoverTapSlop) + : HOVER_TAP_SLOP; + } + return mHoverTapSlop; + } + + public long getZoomControlsTimeout() { + if (mZoomControlsTimeout < 0) { + Resources resources = getCurrentResources(); + mZoomControlsTimeout = resources != null + ? resources.getInteger(R.integer.config_zoomControlsTimeoutMillis) + : ZOOM_CONTROLS_TIMEOUT; + } + return mZoomControlsTimeout; + } + + public float getScrollFriction() { + if (mScrollFriction < 0) { + Resources resources = getCurrentResources(); + mScrollFriction = resources != null + ? resources.getFloat(R.dimen.config_scrollFriction) + : SCROLL_FRICTION; + } + return mScrollFriction; + } + + public long getDefaultActionModeHideDuration() { + if (mDefaultActionModeHideDuration < 0) { + Resources resources = getCurrentResources(); + mDefaultActionModeHideDuration = resources != null + ? resources.getInteger(R.integer.config_defaultActionModeHideDurationMillis) + : ACTION_MODE_HIDE_DURATION_DEFAULT; + } + return mDefaultActionModeHideDuration; + } + + private static Resources getCurrentResources() { + if (!android.companion.virtualdevice.flags.Flags + .migrateViewconfigurationConstantsToResources()) { + return null; + } + Application application = ActivityThread.currentApplication(); + Context context = application != null ? application.getApplicationContext() : null; + return context != null ? context.getResources() : null; + } + } } diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 1cb38bed1388..fbb8e25eeced 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -3072,6 +3072,43 @@ {@link MotionEvent#ACTION_SCROLL} event. --> <dimen name="config_scrollFactor">64dp</dimen> + <!-- Duration in milliseconds of the pressed state in child components. --> + <integer name="config_pressedStateDurationMillis">64</integer> + + <!-- Duration in milliseconds we will wait to see if a touch event is a tap or a scroll. + If the user does not move within this interval, it is considered to be a tap. --> + <integer name="config_tapTimeoutMillis">100</integer> + + <!-- Duration in milliseconds we will wait to see if a touch event is a jump tap. + If the user does not move within this interval, it is considered to be a tap. --> + <integer name="config_jumpTapTimeoutMillis">500</integer> + + <!-- Duration in milliseconds between the first tap's up event and the second tap's down + event for an interaction to be considered a double-tap. --> + <integer name="config_doubleTapTimeoutMillis">300</integer> + + <!-- Minimum duration in milliseconds between the first tap's up event and the second tap's + down event for an interaction to be considered a double-tap. --> + <integer name="config_doubleTapMinTimeMillis">40</integer> + + <!-- Maximum duration in milliseconds between a touch pad touch and release for a given touch + to be considered a tap (click) as opposed to a hover movement gesture. --> + <integer name="config_hoverTapTimeoutMillis">150</integer> + + <!-- The amount of time in milliseconds that the zoom controls should be displayed on the + screen. --> + <integer name="config_zoomControlsTimeoutMillis">3000</integer> + + <!-- Default duration in milliseconds for {@link ActionMode#hide(long)}. --> + <integer name="config_defaultActionModeHideDurationMillis">2000</integer> + + <!-- Maximum distance in pixels that a touch pad touch can move before being released + for it to be considered a tap (click) as opposed to a hover movement gesture. --> + <dimen name="config_hoverTapSlop">20px</dimen> + + <!-- The amount of friction applied to scrolls and flings. --> + <item name="config_scrollFriction" format="float" type="dimen">0.015</item> + <!-- Maximum number of grid columns permitted in the ResolverActivity used for picking activities to handle an intent. --> <integer name="config_maxResolverActivityColumns">3</integer> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index c8c1e73bfba2..4e473236f5a5 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -4159,6 +4159,17 @@ <java-symbol type="string" name="config_headlineFontFamily" /> <java-symbol type="string" name="config_headlineFontFamilyMedium" /> + <java-symbol type="integer" name="config_pressedStateDurationMillis" /> + <java-symbol type="integer" name="config_tapTimeoutMillis" /> + <java-symbol type="integer" name="config_jumpTapTimeoutMillis" /> + <java-symbol type="integer" name="config_doubleTapTimeoutMillis" /> + <java-symbol type="integer" name="config_doubleTapMinTimeMillis" /> + <java-symbol type="integer" name="config_hoverTapTimeoutMillis" /> + <java-symbol type="integer" name="config_zoomControlsTimeoutMillis" /> + <java-symbol type="integer" name="config_defaultActionModeHideDurationMillis" /> + <java-symbol type="dimen" name="config_hoverTapSlop" /> + <java-symbol type="dimen" name="config_scrollFriction" /> + <java-symbol type="drawable" name="stat_sys_vitals" /> <java-symbol type="color" name="text_color_primary" /> |