blob: 47a79bd5484afe52a4036ad3886f9b4993015c29 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -080019import android.annotation.FloatRange;
Vladislav Kaznacheevf847ee32016-11-21 14:11:00 -080020import android.annotation.TestApi;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080021import android.app.AppGlobals;
Artur Satayevad9254c2019-12-10 17:47:54 +000022import android.compat.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.Context;
Dianne Hackbornff801ec2011-01-22 18:05:38 -080024import android.content.res.Configuration;
Adam Powell8c470622011-06-30 18:19:51 -070025import android.content.res.Resources;
John Reckab149232019-11-14 00:19:48 +000026import android.graphics.Point;
Sumir Kataria471709a2019-02-04 16:20:19 -080027import android.os.Build;
Adam Powell8c470622011-06-30 18:19:51 -070028import android.os.RemoteException;
Svetoslav Ganov54d068e2011-03-02 12:58:40 -080029import android.provider.Settings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.util.DisplayMetrics;
Andrii Kuliane57f2dc2020-01-26 20:59:07 -080031import android.util.Size;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.util.SparseArray;
Philip Quinn1687d422020-01-24 12:49:46 -080033import android.util.TypedValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35/**
36 * Contains methods to standard constants used in the UI for timeouts, sizes, and distances.
37 */
38public class ViewConfiguration {
39 /**
40 * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in
Gilles Debunne006fa482011-10-27 17:23:36 -070041 * dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
Tarun Lohani8c89baa2017-06-16 17:21:04 +000043 private static final int SCROLL_BAR_SIZE = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
45 /**
Mike Cleronf116bf82009-09-27 19:14:12 -070046 * Duration of the fade when scrollbars fade away in milliseconds
47 */
48 private static final int SCROLL_BAR_FADE_DURATION = 250;
49
50 /**
51 * Default delay before the scrollbars fade in milliseconds
52 */
53 private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
54
55 /**
Gilles Debunne006fa482011-10-27 17:23:36 -070056 * Defines the length of the fading edges in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057 */
58 private static final int FADING_EDGE_LENGTH = 12;
59
60 /**
61 * Defines the duration in milliseconds of the pressed state in child
62 * components.
63 */
Daisuke Miyakawac19895f2012-04-03 12:25:26 -070064 private static final int PRESSED_STATE_DURATION = 64;
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 /**
Jeff Browna4547672011-03-02 21:38:11 -080067 * Defines the default duration in milliseconds before a press turns into
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 * a long press
69 */
Jeff Browna4547672011-03-02 21:38:11 -080070 private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;
71
72 /**
Anthony Hugh96e9cc52016-07-12 15:17:24 -070073 * Defines the default duration in milliseconds between the first tap's up event and the second
74 * tap's down event for an interaction to be considered part of the same multi-press.
75 */
76 private static final int DEFAULT_MULTI_PRESS_TIMEOUT = 300;
77
78 /**
Jeff Browna4547672011-03-02 21:38:11 -080079 * Defines the time between successive key repeats in milliseconds.
80 */
81 private static final int KEY_REPEAT_DELAY = 50;
82
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 /**
84 * Defines the duration in milliseconds a user needs to hold down the
85 * appropriate button to bring up the global actions dialog (power off,
86 * lock screen, etc).
87 */
88 private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -070089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 /**
Phil Weaver106fe732016-11-22 18:18:39 -080091 * Defines the duration in milliseconds a user needs to hold down the
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +010092 * appropriate buttons (power + volume down) to trigger the screenshot chord.
93 */
94 private static final int SCREENSHOT_CHORD_KEY_TIMEOUT = 500;
95
96 /**
97 * Defines the duration in milliseconds a user needs to hold down the
Eugene Susla5f19cd32017-10-19 14:00:59 -070098 * appropriate button to bring up the accessibility shortcut for the first time
Phil Weaver106fe732016-11-22 18:18:39 -080099 */
100 private static final int A11Y_SHORTCUT_KEY_TIMEOUT = 3000;
101
102 /**
Eugene Susla5f19cd32017-10-19 14:00:59 -0700103 * Defines the duration in milliseconds a user needs to hold down the
104 * appropriate button to enable the accessibility shortcut once it's configured.
105 */
Eugene Suslac8841582017-10-31 17:10:41 -0700106 private static final int A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION = 1000;
Eugene Susla5f19cd32017-10-19 14:00:59 -0700107
108 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700109 * Defines the duration in milliseconds we will wait to see if a touch event
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 * is a tap or a scroll. If the user does not move within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700111 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
Alan Viverette97d9b652014-03-17 15:33:05 -0700113 private static final int TAP_TIMEOUT = 100;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700116 * Defines the duration in milliseconds we will wait to see if a touch event
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 * is a jump tap. If the user does not complete the jump tap within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700118 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 */
120 private static final int JUMP_TAP_TIMEOUT = 500;
121
122 /**
123 * Defines the duration in milliseconds between the first tap's up event and
124 * the second tap's down event for an interaction to be considered a
125 * double-tap.
126 */
127 private static final int DOUBLE_TAP_TIMEOUT = 300;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700128
129 /**
Adam Powellaf1785f2013-09-05 13:44:45 -0700130 * Defines the minimum duration in milliseconds between the first tap's up event and
131 * the second tap's down event for an interaction to be considered a
132 * double-tap.
133 */
134 private static final int DOUBLE_TAP_MIN_TIME = 40;
135
136 /**
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700137 * Defines the maximum duration in milliseconds between a touch pad
138 * touch and release for a given touch to be considered a tap (click) as
139 * opposed to a hover movement gesture.
140 */
141 private static final int HOVER_TAP_TIMEOUT = 150;
142
143 /**
144 * Defines the maximum distance in pixels that a touch pad touch can move
145 * before being released for it to be considered a tap (click) as opposed
146 * to a hover movement gesture.
147 */
148 private static final int HOVER_TAP_SLOP = 20;
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700151 * Defines the duration in milliseconds we want to display zoom controls in response
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 * to a user panning within an application.
153 */
154 private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
155
156 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700157 * Inset in dips to look for touchable content when the user touches the edge of the screen
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 */
159 private static final int EDGE_SLOP = 12;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 /**
Adam Powell7d39f852011-12-05 19:26:54 -0800162 * Distance a touch can wander before we think the user is scrolling in dips.
163 * Note that this value defined here is only used as a fallback by legacy/misbehaving
164 * applications that do not provide a Context for determining density/configuration-dependent
165 * values.
166 *
167 * To alter this value, see the configuration resource config_viewConfigurationTouchSlop
168 * in frameworks/base/core/res/res/values/config.xml or the appropriate device resource overlay.
169 * It may be appropriate to tweak this on a device-specific basis in an overlay based on
170 * the characteristics of the touch panel and firmware.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 */
Adam Powell6720a872011-12-07 17:35:32 -0800172 private static final int TOUCH_SLOP = 8;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 /**
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800175 * Defines the minimum size of the touch target for a scrollbar in dips
176 */
177 private static final int MIN_SCROLLBAR_TOUCH_TARGET = 48;
178
179 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700180 * Distance the first touch can wander before we stop considering this event a double tap
181 * (in dips)
182 */
183 private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;
184
185 /**
Adam Powellde8d0832010-03-09 17:11:30 -0800186 * Distance a touch can wander before we think the user is attempting a paged scroll
187 * (in dips)
Adam Powell7d39f852011-12-05 19:26:54 -0800188 *
189 * Note that this value defined here is only used as a fallback by legacy/misbehaving
190 * applications that do not provide a Context for determining density/configuration-dependent
191 * values.
192 *
193 * See the note above on {@link #TOUCH_SLOP} regarding the dimen resource
194 * config_viewConfigurationTouchSlop. ViewConfiguration will report a paging touch slop of
195 * config_viewConfigurationTouchSlop * 2 when provided with a Context.
Adam Powellde8d0832010-03-09 17:11:30 -0800196 */
Adam Powellb7ef1d92010-03-11 10:25:24 -0800197 private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700198
Adam Powellde8d0832010-03-09 17:11:30 -0800199 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700200 * Distance in dips between the first touch and second touch to still be considered a double tap
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 */
202 private static final int DOUBLE_TAP_SLOP = 100;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700205 * Distance in dips a touch needs to be outside of a window's bounds for it to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 * count as outside for purposes of dismissing the window.
207 */
208 private static final int WINDOW_TOUCH_SLOP = 16;
209
210 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700211 * Minimum velocity to initiate a fling, as measured in dips per second
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 */
213 private static final int MINIMUM_FLING_VELOCITY = 50;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700214
Romain Guy4296fc42009-07-06 11:48:52 -0700215 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700216 * Maximum velocity to initiate a fling, as measured in dips per second
Romain Guy4296fc42009-07-06 11:48:52 -0700217 */
Adam Powell637d3372010-08-25 14:37:03 -0700218 private static final int MAXIMUM_FLING_VELOCITY = 8000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219
220 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700221 * Delay before dispatching a recurring accessibility event in milliseconds.
222 * This delay guarantees that a recurring event will be send at most once
223 * during the {@link #SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS} time
224 * frame.
225 */
Svetoslav Ganove15ccb92012-05-16 15:48:55 -0700226 private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;
Svetoslav Ganova0156172011-06-26 17:55:44 -0700227
228 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 * The maximum size of View's drawing cache, expressed in bytes. This size
230 * should be at least equal to the size of the screen in ARGB888 format.
231 */
232 @Deprecated
Romain Guy0211a0a2011-02-14 16:34:59 -0800233 private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234
235 /**
236 * The coefficient of friction applied to flings/scrolls.
237 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100238 @UnsupportedAppUsage
Romain Guy0211a0a2011-02-14 16:34:59 -0800239 private static final float SCROLL_FRICTION = 0.015f;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240
Adam Powell637d3372010-08-25 14:37:03 -0700241 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700242 * Max distance in dips to overscroll for edge effects
Adam Powell637d3372010-08-25 14:37:03 -0700243 */
244 private static final int OVERSCROLL_DISTANCE = 0;
245
246 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700247 * Max distance in dips to overfling for edge effects
Adam Powell637d3372010-08-25 14:37:03 -0700248 */
Gilles Debunne8ce7aab2011-01-25 11:23:30 -0800249 private static final int OVERFLING_DISTANCE = 6;
Adam Powell637d3372010-08-25 14:37:03 -0700250
Adam Powellcc84ff42013-12-04 11:15:29 -0800251 /**
Aaron Whytef8306522017-03-22 16:30:58 -0700252 * Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event,
253 * in dips per axis value.
Ned Burns69af4322016-08-17 17:30:25 -0400254 */
Aaron Whytef8306522017-03-22 16:30:58 -0700255 private static final float HORIZONTAL_SCROLL_FACTOR = 64;
256
257 /**
258 * Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event,
259 * in dips per axis value.
260 */
261 private static final float VERTICAL_SCROLL_FACTOR = 64;
Ned Burns69af4322016-08-17 17:30:25 -0400262
263 /**
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100264 * Default duration to hide an action mode for.
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100265 */
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100266 private static final long ACTION_MODE_HIDE_DURATION_DEFAULT = 2000;
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100267
268 /**
Vladislav Kaznacheevf847ee32016-11-21 14:11:00 -0800269 * Defines the duration in milliseconds before an end of a long press causes a tooltip to be
270 * hidden.
271 */
272 private static final int LONG_PRESS_TOOLTIP_HIDE_TIMEOUT = 1500;
273
274 /**
275 * Defines the duration in milliseconds before a hover event causes a tooltip to be shown.
276 */
277 private static final int HOVER_TOOLTIP_SHOW_TIMEOUT = 500;
278
279 /**
280 * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden.
281 * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
282 */
283 private static final int HOVER_TOOLTIP_HIDE_TIMEOUT = 15000;
284
285 /**
286 * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
287 * (short version to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
288 */
289 private static final int HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT = 3000;
290
291 /**
Adam Powellcc84ff42013-12-04 11:15:29 -0800292 * Configuration values for overriding {@link #hasPermanentMenuKey()} behavior.
293 * These constants must match the definition in res/values/config.xml.
294 */
295 private static final int HAS_PERMANENT_MENU_KEY_AUTODETECT = 0;
296 private static final int HAS_PERMANENT_MENU_KEY_TRUE = 1;
297 private static final int HAS_PERMANENT_MENU_KEY_FALSE = 2;
298
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800299 /**
300 * The multiplication factor for inhibiting default gestures.
301 */
302 private static final float AMBIGUOUS_GESTURE_MULTIPLIER = 2f;
303
shepshapardba6dbff2019-02-06 16:14:22 -0800304 private final boolean mConstructedWithContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 private final int mEdgeSlop;
306 private final int mFadingEdgeLength;
307 private final int mMinimumFlingVelocity;
Romain Guy4296fc42009-07-06 11:48:52 -0700308 private final int mMaximumFlingVelocity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 private final int mScrollbarSize;
310 private final int mTouchSlop;
shepshapardba6dbff2019-02-06 16:14:22 -0800311 private final int mMinScalingSpan;
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800312 private final int mHoverSlop;
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800313 private final int mMinScrollbarTouchTarget;
Gilles Debunne006fa482011-10-27 17:23:36 -0700314 private final int mDoubleTapTouchSlop;
Adam Powellde8d0832010-03-09 17:11:30 -0800315 private final int mPagingTouchSlop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 private final int mDoubleTapSlop;
317 private final int mWindowTouchSlop;
Philip Quinn1687d422020-01-24 12:49:46 -0800318 private final float mAmbiguousGestureMultiplier;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 private final int mMaximumDrawingCacheSize;
Adam Powell637d3372010-08-25 14:37:03 -0700320 private final int mOverscrollDistance;
321 private final int mOverflingDistance;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100322 @UnsupportedAppUsage
Romain Guy68055452011-08-02 16:33:02 -0700323 private final boolean mFadingMarqueeEnabled;
Justin Kohfeabd2c2014-05-02 10:02:44 -0700324 private final long mGlobalActionsKeyTimeout;
Aaron Whytef8306522017-03-22 16:30:58 -0700325 private final float mVerticalScrollFactor;
326 private final float mHorizontalScrollFactor;
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800327 private final boolean mShowMenuShortcutsWhenKeyboardPresent;
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100328 private final long mScreenshotChordKeyTimeout;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329
Sumir Kataria471709a2019-02-04 16:20:19 -0800330 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
Adam Powell8c470622011-06-30 18:19:51 -0700331 private boolean sHasPermanentMenuKey;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100332 @UnsupportedAppUsage
Adam Powell8c470622011-06-30 18:19:51 -0700333 private boolean sHasPermanentMenuKeySet;
334
Mathew Inwooda570dee2018-08-17 14:56:00 +0100335 @UnsupportedAppUsage
Xavier Ducrohet7f9f99ea2011-08-11 10:16:17 -0700336 static final SparseArray<ViewConfiguration> sConfigurations =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 new SparseArray<ViewConfiguration>(2);
338
339 /**
340 * @deprecated Use {@link android.view.ViewConfiguration#get(android.content.Context)} instead.
341 */
342 @Deprecated
343 public ViewConfiguration() {
shepshapardba6dbff2019-02-06 16:14:22 -0800344 mConstructedWithContext = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 mEdgeSlop = EDGE_SLOP;
346 mFadingEdgeLength = FADING_EDGE_LENGTH;
347 mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
Romain Guy4296fc42009-07-06 11:48:52 -0700348 mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 mScrollbarSize = SCROLL_BAR_SIZE;
350 mTouchSlop = TOUCH_SLOP;
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800351 mHoverSlop = TOUCH_SLOP / 2;
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800352 mMinScrollbarTouchTarget = MIN_SCROLLBAR_TOUCH_TARGET;
Gilles Debunne006fa482011-10-27 17:23:36 -0700353 mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
Adam Powellde8d0832010-03-09 17:11:30 -0800354 mPagingTouchSlop = PAGING_TOUCH_SLOP;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 mDoubleTapSlop = DOUBLE_TAP_SLOP;
356 mWindowTouchSlop = WINDOW_TOUCH_SLOP;
Philip Quinn1687d422020-01-24 12:49:46 -0800357 mAmbiguousGestureMultiplier = AMBIGUOUS_GESTURE_MULTIPLIER;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 //noinspection deprecation
359 mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;
Adam Powell637d3372010-08-25 14:37:03 -0700360 mOverscrollDistance = OVERSCROLL_DISTANCE;
361 mOverflingDistance = OVERFLING_DISTANCE;
Romain Guy68055452011-08-02 16:33:02 -0700362 mFadingMarqueeEnabled = true;
Justin Kohfeabd2c2014-05-02 10:02:44 -0700363 mGlobalActionsKeyTimeout = GLOBAL_ACTIONS_KEY_TIMEOUT;
Aaron Whytef8306522017-03-22 16:30:58 -0700364 mHorizontalScrollFactor = HORIZONTAL_SCROLL_FACTOR;
365 mVerticalScrollFactor = VERTICAL_SCROLL_FACTOR;
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800366 mShowMenuShortcutsWhenKeyboardPresent = false;
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100367 mScreenshotChordKeyTimeout = SCREENSHOT_CHORD_KEY_TIMEOUT;
shepshapardba6dbff2019-02-06 16:14:22 -0800368
369 // Getter throws if mConstructedWithContext is false so doesn't matter what
370 // this value is.
371 mMinScalingSpan = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 }
373
374 /**
375 * Creates a new configuration for the specified context. The configuration depends on
376 * various parameters of the context, like the dimension of the display or the density
377 * of the display.
378 *
379 * @param context The application context used to initialize this view configuration.
380 *
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700381 * @see #get(android.content.Context)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 * @see android.util.DisplayMetrics
383 */
384 private ViewConfiguration(Context context) {
shepshapardba6dbff2019-02-06 16:14:22 -0800385 mConstructedWithContext = true;
Adam Powell8c470622011-06-30 18:19:51 -0700386 final Resources res = context.getResources();
387 final DisplayMetrics metrics = res.getDisplayMetrics();
388 final Configuration config = res.getConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 final float density = metrics.density;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800390 final float sizeAndDensity;
Adam Powell8c470622011-06-30 18:19:51 -0700391 if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800392 sizeAndDensity = density * 1.5f;
393 } else {
394 sizeAndDensity = density;
395 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800397 mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);
398 mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f);
Tarun Lohani8c89baa2017-06-16 17:21:04 +0000399 mScrollbarSize = res.getDimensionPixelSize(
400 com.android.internal.R.dimen.config_scrollbarSize);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800401 mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
402 mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403
Philip Quinn1687d422020-01-24 12:49:46 -0800404 final TypedValue multiplierValue = new TypedValue();
405 res.getValue(
406 com.android.internal.R.dimen.config_ambiguousGestureMultiplier,
407 multiplierValue,
408 true /*resolveRefs*/);
409 mAmbiguousGestureMultiplier = multiplierValue.getFloat();
410
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // Size of the screen in bytes, in ARGB_8888 format
Andrii Kuliane57f2dc2020-01-26 20:59:07 -0800412 final WindowManager windowManager = context.getSystemService(WindowManager.class);
413 final Size maxWindowSize = windowManager.getMaximumWindowMetrics().getSize();
414 mMaximumDrawingCacheSize = 4 * maxWindowSize.getWidth() * maxWindowSize.getHeight();
Adam Powell637d3372010-08-25 14:37:03 -0700415
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800416 mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
417 mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);
Adam Powell8c470622011-06-30 18:19:51 -0700418
419 if (!sHasPermanentMenuKeySet) {
Adam Powellcc84ff42013-12-04 11:15:29 -0800420 final int configVal = res.getInteger(
421 com.android.internal.R.integer.config_overrideHasPermanentMenuKey);
422
423 switch (configVal) {
424 default:
425 case HAS_PERMANENT_MENU_KEY_AUTODETECT: {
426 IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
427 try {
Charles Chenea6e7f02018-11-19 21:37:45 +0800428 sHasPermanentMenuKey = !wm.hasNavigationBar(context.getDisplayId());
Adam Powellcc84ff42013-12-04 11:15:29 -0800429 sHasPermanentMenuKeySet = true;
430 } catch (RemoteException ex) {
431 sHasPermanentMenuKey = false;
432 }
433 }
434 break;
435
436 case HAS_PERMANENT_MENU_KEY_TRUE:
437 sHasPermanentMenuKey = true;
438 sHasPermanentMenuKeySet = true;
439 break;
440
441 case HAS_PERMANENT_MENU_KEY_FALSE:
442 sHasPermanentMenuKey = false;
443 sHasPermanentMenuKeySet = true;
444 break;
Adam Powell8c470622011-06-30 18:19:51 -0700445 }
446 }
Romain Guy68055452011-08-02 16:33:02 -0700447
448 mFadingMarqueeEnabled = res.getBoolean(
449 com.android.internal.R.bool.config_ui_enableFadingMarquee);
Adam Powell7d39f852011-12-05 19:26:54 -0800450 mTouchSlop = res.getDimensionPixelSize(
451 com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800452 mHoverSlop = res.getDimensionPixelSize(
453 com.android.internal.R.dimen.config_viewConfigurationHoverSlop);
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800454 mMinScrollbarTouchTarget = res.getDimensionPixelSize(
455 com.android.internal.R.dimen.config_minScrollbarTouchTarget);
Adam Powell7d39f852011-12-05 19:26:54 -0800456 mPagingTouchSlop = mTouchSlop * 2;
Adam Powelle4b8ff82011-12-06 16:40:49 -0800457
458 mDoubleTapTouchSlop = mTouchSlop;
Mindy Pereira23ffc732014-04-30 17:09:35 -0700459
460 mMinimumFlingVelocity = res.getDimensionPixelSize(
461 com.android.internal.R.dimen.config_viewMinFlingVelocity);
462 mMaximumFlingVelocity = res.getDimensionPixelSize(
463 com.android.internal.R.dimen.config_viewMaxFlingVelocity);
Justin Kohfeabd2c2014-05-02 10:02:44 -0700464 mGlobalActionsKeyTimeout = res.getInteger(
465 com.android.internal.R.integer.config_globalActionsKeyTimeout);
Aaron Whytef8306522017-03-22 16:30:58 -0700466
467 mHorizontalScrollFactor = res.getDimensionPixelSize(
468 com.android.internal.R.dimen.config_horizontalScrollFactor);
469 mVerticalScrollFactor = res.getDimensionPixelSize(
470 com.android.internal.R.dimen.config_verticalScrollFactor);
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800471
472 mShowMenuShortcutsWhenKeyboardPresent = res.getBoolean(
473 com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
474
shepshapardba6dbff2019-02-06 16:14:22 -0800475 mMinScalingSpan = res.getDimensionPixelSize(
476 com.android.internal.R.dimen.config_minScalingSpan);
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100477
478 mScreenshotChordKeyTimeout = res.getInteger(
479 com.android.internal.R.integer.config_screenshotChordKeyTimeout);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 }
481
482 /**
483 * Returns a configuration for the specified context. The configuration depends on
484 * various parameters of the context, like the dimension of the display or the
485 * density of the display.
486 *
487 * @param context The application context used to initialize the view configuration.
488 */
489 public static ViewConfiguration get(Context context) {
490 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
491 final int density = (int) (100.0f * metrics.density);
492
493 ViewConfiguration configuration = sConfigurations.get(density);
494 if (configuration == null) {
495 configuration = new ViewConfiguration(context);
496 sConfigurations.put(density, configuration);
497 }
498
499 return configuration;
500 }
501
502 /**
503 * @return The width of the horizontal scrollbar and the height of the vertical
Gilles Debunne006fa482011-10-27 17:23:36 -0700504 * scrollbar in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 *
506 * @deprecated Use {@link #getScaledScrollBarSize()} instead.
507 */
508 @Deprecated
509 public static int getScrollBarSize() {
510 return SCROLL_BAR_SIZE;
511 }
512
513 /**
514 * @return The width of the horizontal scrollbar and the height of the vertical
515 * scrollbar in pixels
516 */
517 public int getScaledScrollBarSize() {
518 return mScrollbarSize;
519 }
520
521 /**
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800522 * @return the minimum size of the scrollbar thumb's touch target in pixels
523 * @hide
524 */
525 public int getScaledMinScrollbarTouchTarget() {
526 return mMinScrollbarTouchTarget;
527 }
528
529 /**
Mike Cleronf116bf82009-09-27 19:14:12 -0700530 * @return Duration of the fade when scrollbars fade away in milliseconds
531 */
532 public static int getScrollBarFadeDuration() {
533 return SCROLL_BAR_FADE_DURATION;
534 }
535
536 /**
Alan Viverette25f0e612015-02-27 12:34:30 -0800537 * @return Default delay before the scrollbars fade in milliseconds
Mike Cleronf116bf82009-09-27 19:14:12 -0700538 */
539 public static int getScrollDefaultDelay() {
540 return SCROLL_BAR_DEFAULT_DELAY;
541 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700542
Mike Cleronf116bf82009-09-27 19:14:12 -0700543 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700544 * @return the length of the fading edges in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 *
546 * @deprecated Use {@link #getScaledFadingEdgeLength()} instead.
547 */
548 @Deprecated
549 public static int getFadingEdgeLength() {
550 return FADING_EDGE_LENGTH;
551 }
552
553 /**
554 * @return the length of the fading edges in pixels
555 */
556 public int getScaledFadingEdgeLength() {
557 return mFadingEdgeLength;
558 }
559
560 /**
561 * @return the duration in milliseconds of the pressed state in child
562 * components.
563 */
564 public static int getPressedStateDuration() {
565 return PRESSED_STATE_DURATION;
566 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800567
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 /**
569 * @return the duration in milliseconds before a press turns into
570 * a long press
571 */
572 public static int getLongPressTimeout() {
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800573 return AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,
Jeff Browna4547672011-03-02 21:38:11 -0800574 DEFAULT_LONG_PRESS_TIMEOUT);
575 }
576
577 /**
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700578 * @return the duration in milliseconds between the first tap's up event and the second tap's
579 * down event for an interaction to be considered part of the same multi-press.
580 * @hide
581 */
582 public static int getMultiPressTimeout() {
583 return AppGlobals.getIntCoreSetting(Settings.Secure.MULTI_PRESS_TIMEOUT,
584 DEFAULT_MULTI_PRESS_TIMEOUT);
585 }
586
587 /**
Jeff Browna4547672011-03-02 21:38:11 -0800588 * @return the time before the first key repeat in milliseconds.
589 */
590 public static int getKeyRepeatTimeout() {
591 return getLongPressTimeout();
592 }
593
594 /**
595 * @return the time between successive key repeats in milliseconds.
596 */
597 public static int getKeyRepeatDelay() {
598 return KEY_REPEAT_DELAY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 /**
602 * @return the duration in milliseconds we will wait to see if a touch event
603 * is a tap or a scroll. If the user does not move within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700604 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 */
606 public static int getTapTimeout() {
607 return TAP_TIMEOUT;
608 }
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 /**
611 * @return the duration in milliseconds we will wait to see if a touch event
612 * is a jump tap. If the user does not move within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700613 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 */
615 public static int getJumpTapTimeout() {
616 return JUMP_TAP_TIMEOUT;
617 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700618
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 /**
620 * @return the duration in milliseconds between the first tap's up event and
621 * the second tap's down event for an interaction to be considered a
622 * double-tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 */
624 public static int getDoubleTapTimeout() {
625 return DOUBLE_TAP_TIMEOUT;
626 }
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700627
628 /**
Adam Powellaf1785f2013-09-05 13:44:45 -0700629 * @return the minimum duration in milliseconds between the first tap's
630 * up event and the second tap's down event for an interaction to be considered a
631 * double-tap.
632 *
633 * @hide
634 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100635 @UnsupportedAppUsage
Adam Powellaf1785f2013-09-05 13:44:45 -0700636 public static int getDoubleTapMinTime() {
637 return DOUBLE_TAP_MIN_TIME;
638 }
639
640 /**
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700641 * @return the maximum duration in milliseconds between a touch pad
642 * touch and release for a given touch to be considered a tap (click) as
643 * opposed to a hover movement gesture.
644 * @hide
645 */
646 public static int getHoverTapTimeout() {
647 return HOVER_TAP_TIMEOUT;
648 }
649
650 /**
651 * @return the maximum distance in pixels that a touch pad touch can move
652 * before being released for it to be considered a tap (click) as opposed
653 * to a hover movement gesture.
654 * @hide
655 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100656 @UnsupportedAppUsage
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700657 public static int getHoverTapSlop() {
658 return HOVER_TAP_SLOP;
659 }
660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700662 * @return Inset in dips to look for touchable content when the user touches the edge of the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 * screen
664 *
665 * @deprecated Use {@link #getScaledEdgeSlop()} instead.
666 */
667 @Deprecated
668 public static int getEdgeSlop() {
669 return EDGE_SLOP;
670 }
671
672 /**
673 * @return Inset in pixels to look for touchable content when the user touches the edge of the
674 * screen
675 */
676 public int getScaledEdgeSlop() {
677 return mEdgeSlop;
678 }
679
680 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700681 * @return Distance in dips a touch can wander before we think the user is scrolling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 *
683 * @deprecated Use {@link #getScaledTouchSlop()} instead.
684 */
685 @Deprecated
686 public static int getTouchSlop() {
687 return TOUCH_SLOP;
688 }
689
690 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700691 * @return Distance in pixels a touch can wander before we think the user is scrolling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 */
693 public int getScaledTouchSlop() {
694 return mTouchSlop;
695 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700696
Adam Powellde8d0832010-03-09 17:11:30 -0800697 /**
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800698 * @return Distance in pixels a hover can wander while it is still considered "stationary".
699 *
700 */
701 public int getScaledHoverSlop() {
702 return mHoverSlop;
703 }
704
705 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700706 * @return Distance in pixels the first touch can wander before we do not consider this a
707 * potential double tap event
708 * @hide
709 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100710 @UnsupportedAppUsage
Gilles Debunne006fa482011-10-27 17:23:36 -0700711 public int getScaledDoubleTapTouchSlop() {
712 return mDoubleTapTouchSlop;
713 }
714
715 /**
716 * @return Distance in pixels a touch can wander before we think the user is scrolling a full
717 * page
Adam Powellde8d0832010-03-09 17:11:30 -0800718 */
719 public int getScaledPagingTouchSlop() {
720 return mPagingTouchSlop;
721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722
723 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700724 * @return Distance in dips between the first touch and second touch to still be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 * considered a double tap
726 * @deprecated Use {@link #getScaledDoubleTapSlop()} instead.
727 * @hide The only client of this should be GestureDetector, which needs this
728 * for clients that still use its deprecated constructor.
729 */
730 @Deprecated
Mathew Inwooda570dee2018-08-17 14:56:00 +0100731 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 public static int getDoubleTapSlop() {
733 return DOUBLE_TAP_SLOP;
734 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700735
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700737 * @return Distance in pixels between the first touch and second touch to still be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 * considered a double tap
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 */
740 public int getScaledDoubleTapSlop() {
741 return mDoubleTapSlop;
742 }
743
744 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700745 * Interval for dispatching a recurring accessibility event in milliseconds.
746 * This interval guarantees that a recurring event will be send at most once
747 * during the {@link #getSendRecurringAccessibilityEventsInterval()} time frame.
748 *
749 * @return The delay in milliseconds.
750 *
751 * @hide
752 */
753 public static long getSendRecurringAccessibilityEventsInterval() {
754 return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;
755 }
756
757 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700758 * @return Distance in dips a touch must be outside the bounds of a window for it
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * to be counted as outside the window for purposes of dismissing that
760 * window.
761 *
762 * @deprecated Use {@link #getScaledWindowTouchSlop()} instead.
763 */
764 @Deprecated
765 public static int getWindowTouchSlop() {
766 return WINDOW_TOUCH_SLOP;
767 }
768
769 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700770 * @return Distance in pixels a touch must be outside the bounds of a window for it
771 * to be counted as outside the window for purposes of dismissing that window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 */
773 public int getScaledWindowTouchSlop() {
774 return mWindowTouchSlop;
775 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700778 * @return Minimum velocity to initiate a fling, as measured in dips per second.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 *
780 * @deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.
781 */
782 @Deprecated
783 public static int getMinimumFlingVelocity() {
784 return MINIMUM_FLING_VELOCITY;
785 }
786
787 /**
788 * @return Minimum velocity to initiate a fling, as measured in pixels per second.
789 */
790 public int getScaledMinimumFlingVelocity() {
791 return mMinimumFlingVelocity;
792 }
793
794 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700795 * @return Maximum velocity to initiate a fling, as measured in dips per second.
Romain Guy4296fc42009-07-06 11:48:52 -0700796 *
797 * @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
798 */
799 @Deprecated
800 public static int getMaximumFlingVelocity() {
801 return MAXIMUM_FLING_VELOCITY;
802 }
803
804 /**
805 * @return Maximum velocity to initiate a fling, as measured in pixels per second.
806 */
807 public int getScaledMaximumFlingVelocity() {
808 return mMaximumFlingVelocity;
809 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700810
Romain Guy4296fc42009-07-06 11:48:52 -0700811 /**
Ned Burns69af4322016-08-17 17:30:25 -0400812 * @return Amount to scroll in response to a {@link MotionEvent#ACTION_SCROLL} event. Multiply
813 * this by the event's axis value to obtain the number of pixels to be scrolled.
Aaron Whytef8306522017-03-22 16:30:58 -0700814 *
815 * @removed
Ned Burns69af4322016-08-17 17:30:25 -0400816 */
817 public int getScaledScrollFactor() {
Aaron Whytef8306522017-03-22 16:30:58 -0700818 return (int) mVerticalScrollFactor;
819 }
820
821 /**
822 * @return Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event.
823 * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
824 */
825 public float getScaledHorizontalScrollFactor() {
826 return mHorizontalScrollFactor;
827 }
828
829 /**
830 * @return Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event.
831 * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
832 */
833 public float getScaledVerticalScrollFactor() {
834 return mVerticalScrollFactor;
Ned Burns69af4322016-08-17 17:30:25 -0400835 }
836
837 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * The maximum drawing cache size expressed in bytes.
839 *
840 * @return the maximum size of View's drawing cache expressed in bytes
841 *
842 * @deprecated Use {@link #getScaledMaximumDrawingCacheSize()} instead.
843 */
844 @Deprecated
845 public static int getMaximumDrawingCacheSize() {
846 //noinspection deprecation
847 return MAXIMUM_DRAWING_CACHE_SIZE;
848 }
849
850 /**
851 * The maximum drawing cache size expressed in bytes.
852 *
853 * @return the maximum size of View's drawing cache expressed in bytes
854 */
855 public int getScaledMaximumDrawingCacheSize() {
856 return mMaximumDrawingCacheSize;
857 }
858
859 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700860 * @return The maximum distance a View should overscroll by when showing edge effects (in
861 * pixels).
Adam Powell637d3372010-08-25 14:37:03 -0700862 */
863 public int getScaledOverscrollDistance() {
864 return mOverscrollDistance;
865 }
866
867 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700868 * @return The maximum distance a View should overfling by when showing edge effects (in
869 * pixels).
Adam Powell637d3372010-08-25 14:37:03 -0700870 */
871 public int getScaledOverflingDistance() {
872 return mOverflingDistance;
873 }
874
875 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800876 * The amount of time that the zoom controls should be
877 * displayed on the screen expressed in milliseconds.
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700878 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 * @return the time the zoom controls should be visible expressed
880 * in milliseconds.
881 */
882 public static long getZoomControlsTimeout() {
883 return ZOOM_CONTROLS_TIMEOUT;
884 }
885
886 /**
887 * The amount of time a user needs to press the relevant key to bring up
888 * the global actions dialog.
889 *
890 * @return how long a user needs to press the relevant key to bring up
891 * the global actions dialog.
Justin Koh8031fa02014-05-05 16:28:49 -0700892 * @deprecated This timeout should not be used by applications
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 */
Justin Koh1aa59f82014-05-04 12:13:25 -0700894 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 public static long getGlobalActionKeyTimeout() {
896 return GLOBAL_ACTIONS_KEY_TIMEOUT;
897 }
898
899 /**
Justin Kohfeabd2c2014-05-02 10:02:44 -0700900 * The amount of time a user needs to press the relevant key to bring up
901 * the global actions dialog.
902 *
903 * @return how long a user needs to press the relevant key to bring up
904 * the global actions dialog.
Justin Koh1aa59f82014-05-04 12:13:25 -0700905 * @hide
Justin Kohfeabd2c2014-05-02 10:02:44 -0700906 */
Aurimas Liutikas80e4e182018-08-13 16:13:37 -0700907 @TestApi
Justin Kohfeabd2c2014-05-02 10:02:44 -0700908 public long getDeviceGlobalActionKeyTimeout() {
909 return mGlobalActionsKeyTimeout;
910 }
911
912 /**
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100913 * The amount of time a user needs to press the relevant keys to trigger
914 * the screenshot chord.
915 *
916 * @return how long a user needs to press the relevant keys to trigger
917 * the screenshot chord.
918 * @hide
919 */
920 public long getScreenshotChordKeyTimeout() {
921 return mScreenshotChordKeyTimeout;
922 }
923
924 /**
Phil Weaver106fe732016-11-22 18:18:39 -0800925 * The amount of time a user needs to press the relevant keys to activate the accessibility
926 * shortcut.
927 *
928 * @return how long a user needs to press the relevant keys to activate the accessibility
929 * shortcut.
930 * @hide
931 */
932 public long getAccessibilityShortcutKeyTimeout() {
933 return A11Y_SHORTCUT_KEY_TIMEOUT;
934 }
935
936 /**
Eugene Susla5f19cd32017-10-19 14:00:59 -0700937 * @return The amount of time a user needs to press the relevant keys to activate the
938 * accessibility shortcut after it's confirmed that accessibility shortcut is used.
939 * @hide
940 */
941 public long getAccessibilityShortcutKeyTimeoutAfterConfirmation() {
942 return A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION;
943 }
944
945 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 * The amount of friction applied to scrolls and flings.
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700947 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 * @return A scalar dimensionless value representing the coefficient of
949 * friction.
950 */
951 public static float getScrollFriction() {
952 return SCROLL_FRICTION;
953 }
Adam Powell8c470622011-06-30 18:19:51 -0700954
955 /**
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100956 * @return the default duration in milliseconds for {@link ActionMode#hide(long)}.
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100957 */
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100958 public static long getDefaultActionModeHideDuration() {
959 return ACTION_MODE_HIDE_DURATION_DEFAULT;
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100960 }
961
962 /**
Philip Quinn1687d422020-01-24 12:49:46 -0800963 * The multiplication factor for inhibiting default gestures.
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800964 *
Philip Quinn1687d422020-01-24 12:49:46 -0800965 * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set,
966 * then certain actions, such as scrolling, will be inhibited. However, to account for the
967 * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling
968 * touch slop and the long-press timeout) should be scaled by this factor and remain in effect.
969 *
970 * @deprecated Use {@link #getScaledAmbiguousGestureMultiplier()}.
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800971 */
Philip Quinn1687d422020-01-24 12:49:46 -0800972 @Deprecated
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800973 @FloatRange(from = 1.0)
974 public static float getAmbiguousGestureMultiplier() {
975 return AMBIGUOUS_GESTURE_MULTIPLIER;
976 }
977
978 /**
Philip Quinn1687d422020-01-24 12:49:46 -0800979 * The multiplication factor for inhibiting default gestures.
980 *
981 * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set,
982 * then certain actions, such as scrolling, will be inhibited. However, to account for the
983 * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling
984 * touch slop and the long-press timeout) should be scaled by this factor and remain in effect.
985 */
986 @FloatRange(from = 1.0)
987 public float getScaledAmbiguousGestureMultiplier() {
988 return mAmbiguousGestureMultiplier;
989 }
990
991 /**
Adam Powell8c470622011-06-30 18:19:51 -0700992 * Report if the device has a permanent menu key available to the user.
993 *
994 * <p>As of Android 3.0, devices may not have a permanent menu key available.
995 * Apps should use the action bar to present menu options to users.
996 * However, there are some apps where the action bar is inappropriate
997 * or undesirable. This method may be used to detect if a menu key is present.
998 * If not, applications should provide another on-screen affordance to access
999 * functionality.
1000 *
1001 * @return true if a permanent menu key is present, false otherwise.
1002 */
1003 public boolean hasPermanentMenuKey() {
1004 return sHasPermanentMenuKey;
1005 }
Romain Guy68055452011-08-02 16:33:02 -07001006
1007 /**
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -08001008 * Check if shortcuts should be displayed in menus.
1009 *
1010 * @return {@code True} if shortcuts should be displayed in menus.
1011 */
1012 public boolean shouldShowMenuShortcutsWhenKeyboardPresent() {
1013 return mShowMenuShortcutsWhenKeyboardPresent;
1014 }
1015
1016 /**
shepshapardba6dbff2019-02-06 16:14:22 -08001017 * Retrieves the distance in pixels between touches that must be reached for a gesture to be
1018 * interpreted as scaling.
1019 *
1020 * In general, scaling shouldn't start until this distance has been met or surpassed, and
1021 * scaling should end when the distance in pixels between touches drops below this distance.
1022 *
1023 * @return The distance in pixels
1024 * @throws IllegalStateException if this method is called on a ViewConfiguration that was
1025 * instantiated using a constructor with no Context parameter.
1026 */
shepshapard192c6352019-02-26 11:05:46 -08001027 public int getScaledMinimumScalingSpan() {
shepshapardba6dbff2019-02-06 16:14:22 -08001028 if (!mConstructedWithContext) {
1029 throw new IllegalStateException("Min scaling span cannot be determined when this "
1030 + "method is called on a ViewConfiguration that was instantiated using a "
1031 + "constructor with no Context parameter");
1032 }
1033 return mMinScalingSpan;
1034 }
1035
1036 /**
Romain Guy68055452011-08-02 16:33:02 -07001037 * @hide
1038 * @return Whether or not marquee should use fading edges.
1039 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001040 @UnsupportedAppUsage
Romain Guy68055452011-08-02 16:33:02 -07001041 public boolean isFadingMarqueeEnabled() {
1042 return mFadingMarqueeEnabled;
1043 }
Vladislav Kaznacheevf847ee32016-11-21 14:11:00 -08001044
1045 /**
1046 * @return the duration in milliseconds before an end of a long press causes a tooltip to be
1047 * hidden
1048 * @hide
1049 */
1050 @TestApi
1051 public static int getLongPressTooltipHideTimeout() {
1052 return LONG_PRESS_TOOLTIP_HIDE_TIMEOUT;
1053 }
1054
1055 /**
1056 * @return the duration in milliseconds before a hover event causes a tooltip to be shown
1057 * @hide
1058 */
1059 @TestApi
1060 public static int getHoverTooltipShowTimeout() {
1061 return HOVER_TOOLTIP_SHOW_TIMEOUT;
1062 }
1063
1064 /**
1065 * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1066 * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
1067 * @hide
1068 */
1069 @TestApi
1070 public static int getHoverTooltipHideTimeout() {
1071 return HOVER_TOOLTIP_HIDE_TIMEOUT;
1072 }
1073
1074 /**
1075 * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1076 * (shorter variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
1077 * @hide
1078 */
1079 @TestApi
1080 public static int getHoverTooltipHideShortTimeout() {
1081 return HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT;
1082 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001083}