blob: 774a2dea63115b84612faf1188c401abaae1c397 [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;
31import android.util.SparseArray;
32
33/**
34 * Contains methods to standard constants used in the UI for timeouts, sizes, and distances.
35 */
36public class ViewConfiguration {
37 /**
38 * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in
Gilles Debunne006fa482011-10-27 17:23:36 -070039 * dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 */
Tarun Lohani8c89baa2017-06-16 17:21:04 +000041 private static final int SCROLL_BAR_SIZE = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43 /**
Mike Cleronf116bf82009-09-27 19:14:12 -070044 * Duration of the fade when scrollbars fade away in milliseconds
45 */
46 private static final int SCROLL_BAR_FADE_DURATION = 250;
47
48 /**
49 * Default delay before the scrollbars fade in milliseconds
50 */
51 private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
52
53 /**
Gilles Debunne006fa482011-10-27 17:23:36 -070054 * Defines the length of the fading edges in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 */
56 private static final int FADING_EDGE_LENGTH = 12;
57
58 /**
59 * Defines the duration in milliseconds of the pressed state in child
60 * components.
61 */
Daisuke Miyakawac19895f2012-04-03 12:25:26 -070062 private static final int PRESSED_STATE_DURATION = 64;
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 /**
Jeff Browna4547672011-03-02 21:38:11 -080065 * Defines the default duration in milliseconds before a press turns into
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 * a long press
67 */
Jeff Browna4547672011-03-02 21:38:11 -080068 private static final int DEFAULT_LONG_PRESS_TIMEOUT = 500;
69
70 /**
Anthony Hugh96e9cc52016-07-12 15:17:24 -070071 * Defines the default duration in milliseconds between the first tap's up event and the second
72 * tap's down event for an interaction to be considered part of the same multi-press.
73 */
74 private static final int DEFAULT_MULTI_PRESS_TIMEOUT = 300;
75
76 /**
Jeff Browna4547672011-03-02 21:38:11 -080077 * Defines the time between successive key repeats in milliseconds.
78 */
79 private static final int KEY_REPEAT_DELAY = 50;
80
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 /**
82 * Defines the duration in milliseconds a user needs to hold down the
83 * appropriate button to bring up the global actions dialog (power off,
84 * lock screen, etc).
85 */
86 private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -070087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 /**
Phil Weaver106fe732016-11-22 18:18:39 -080089 * Defines the duration in milliseconds a user needs to hold down the
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +010090 * appropriate buttons (power + volume down) to trigger the screenshot chord.
91 */
92 private static final int SCREENSHOT_CHORD_KEY_TIMEOUT = 500;
93
94 /**
95 * Defines the duration in milliseconds a user needs to hold down the
Eugene Susla5f19cd32017-10-19 14:00:59 -070096 * appropriate button to bring up the accessibility shortcut for the first time
Phil Weaver106fe732016-11-22 18:18:39 -080097 */
98 private static final int A11Y_SHORTCUT_KEY_TIMEOUT = 3000;
99
100 /**
Eugene Susla5f19cd32017-10-19 14:00:59 -0700101 * Defines the duration in milliseconds a user needs to hold down the
102 * appropriate button to enable the accessibility shortcut once it's configured.
103 */
Eugene Suslac8841582017-10-31 17:10:41 -0700104 private static final int A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION = 1000;
Eugene Susla5f19cd32017-10-19 14:00:59 -0700105
106 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700107 * Defines the duration in milliseconds we will wait to see if a touch event
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 * is a tap or a scroll. If the user does not move within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700109 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 */
Alan Viverette97d9b652014-03-17 15:33:05 -0700111 private static final int TAP_TIMEOUT = 100;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700114 * Defines the duration in milliseconds we will wait to see if a touch event
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 * 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 -0700116 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 */
118 private static final int JUMP_TAP_TIMEOUT = 500;
119
120 /**
121 * Defines the duration in milliseconds between the first tap's up event and
122 * the second tap's down event for an interaction to be considered a
123 * double-tap.
124 */
125 private static final int DOUBLE_TAP_TIMEOUT = 300;
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700126
127 /**
Adam Powellaf1785f2013-09-05 13:44:45 -0700128 * Defines the minimum duration in milliseconds between the first tap's up event and
129 * the second tap's down event for an interaction to be considered a
130 * double-tap.
131 */
132 private static final int DOUBLE_TAP_MIN_TIME = 40;
133
134 /**
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700135 * Defines the maximum duration in milliseconds between a touch pad
136 * touch and release for a given touch to be considered a tap (click) as
137 * opposed to a hover movement gesture.
138 */
139 private static final int HOVER_TAP_TIMEOUT = 150;
140
141 /**
142 * Defines the maximum distance in pixels that a touch pad touch can move
143 * before being released for it to be considered a tap (click) as opposed
144 * to a hover movement gesture.
145 */
146 private static final int HOVER_TAP_SLOP = 20;
147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 /**
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700149 * Defines the duration in milliseconds we want to display zoom controls in response
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 * to a user panning within an application.
151 */
152 private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
153
154 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700155 * 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 -0800156 */
157 private static final int EDGE_SLOP = 12;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 /**
Adam Powell7d39f852011-12-05 19:26:54 -0800160 * Distance a touch can wander before we think the user is scrolling in dips.
161 * Note that this value defined here is only used as a fallback by legacy/misbehaving
162 * applications that do not provide a Context for determining density/configuration-dependent
163 * values.
164 *
165 * To alter this value, see the configuration resource config_viewConfigurationTouchSlop
166 * in frameworks/base/core/res/res/values/config.xml or the appropriate device resource overlay.
167 * It may be appropriate to tweak this on a device-specific basis in an overlay based on
168 * the characteristics of the touch panel and firmware.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 */
Adam Powell6720a872011-12-07 17:35:32 -0800170 private static final int TOUCH_SLOP = 8;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 /**
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800173 * Defines the minimum size of the touch target for a scrollbar in dips
174 */
175 private static final int MIN_SCROLLBAR_TOUCH_TARGET = 48;
176
177 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700178 * Distance the first touch can wander before we stop considering this event a double tap
179 * (in dips)
180 */
181 private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;
182
183 /**
Adam Powellde8d0832010-03-09 17:11:30 -0800184 * Distance a touch can wander before we think the user is attempting a paged scroll
185 * (in dips)
Adam Powell7d39f852011-12-05 19:26:54 -0800186 *
187 * Note that this value defined here is only used as a fallback by legacy/misbehaving
188 * applications that do not provide a Context for determining density/configuration-dependent
189 * values.
190 *
191 * See the note above on {@link #TOUCH_SLOP} regarding the dimen resource
192 * config_viewConfigurationTouchSlop. ViewConfiguration will report a paging touch slop of
193 * config_viewConfigurationTouchSlop * 2 when provided with a Context.
Adam Powellde8d0832010-03-09 17:11:30 -0800194 */
Adam Powellb7ef1d92010-03-11 10:25:24 -0800195 private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700196
Adam Powellde8d0832010-03-09 17:11:30 -0800197 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700198 * 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 -0800199 */
200 private static final int DOUBLE_TAP_SLOP = 100;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700203 * 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 -0800204 * count as outside for purposes of dismissing the window.
205 */
206 private static final int WINDOW_TOUCH_SLOP = 16;
207
208 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700209 * Minimum velocity to initiate a fling, as measured in dips per second
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 */
211 private static final int MINIMUM_FLING_VELOCITY = 50;
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700212
Romain Guy4296fc42009-07-06 11:48:52 -0700213 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700214 * Maximum velocity to initiate a fling, as measured in dips per second
Romain Guy4296fc42009-07-06 11:48:52 -0700215 */
Adam Powell637d3372010-08-25 14:37:03 -0700216 private static final int MAXIMUM_FLING_VELOCITY = 8000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217
218 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700219 * Delay before dispatching a recurring accessibility event in milliseconds.
220 * This delay guarantees that a recurring event will be send at most once
221 * during the {@link #SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS} time
222 * frame.
223 */
Svetoslav Ganove15ccb92012-05-16 15:48:55 -0700224 private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;
Svetoslav Ganova0156172011-06-26 17:55:44 -0700225
226 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 * The maximum size of View's drawing cache, expressed in bytes. This size
228 * should be at least equal to the size of the screen in ARGB888 format.
229 */
230 @Deprecated
Romain Guy0211a0a2011-02-14 16:34:59 -0800231 private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232
233 /**
234 * The coefficient of friction applied to flings/scrolls.
235 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100236 @UnsupportedAppUsage
Romain Guy0211a0a2011-02-14 16:34:59 -0800237 private static final float SCROLL_FRICTION = 0.015f;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
Adam Powell637d3372010-08-25 14:37:03 -0700239 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700240 * Max distance in dips to overscroll for edge effects
Adam Powell637d3372010-08-25 14:37:03 -0700241 */
242 private static final int OVERSCROLL_DISTANCE = 0;
243
244 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700245 * Max distance in dips to overfling for edge effects
Adam Powell637d3372010-08-25 14:37:03 -0700246 */
Gilles Debunne8ce7aab2011-01-25 11:23:30 -0800247 private static final int OVERFLING_DISTANCE = 6;
Adam Powell637d3372010-08-25 14:37:03 -0700248
Adam Powellcc84ff42013-12-04 11:15:29 -0800249 /**
Aaron Whytef8306522017-03-22 16:30:58 -0700250 * Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event,
251 * in dips per axis value.
Ned Burns69af4322016-08-17 17:30:25 -0400252 */
Aaron Whytef8306522017-03-22 16:30:58 -0700253 private static final float HORIZONTAL_SCROLL_FACTOR = 64;
254
255 /**
256 * Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event,
257 * in dips per axis value.
258 */
259 private static final float VERTICAL_SCROLL_FACTOR = 64;
Ned Burns69af4322016-08-17 17:30:25 -0400260
261 /**
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100262 * Default duration to hide an action mode for.
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100263 */
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100264 private static final long ACTION_MODE_HIDE_DURATION_DEFAULT = 2000;
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100265
266 /**
Vladislav Kaznacheevf847ee32016-11-21 14:11:00 -0800267 * Defines the duration in milliseconds before an end of a long press causes a tooltip to be
268 * hidden.
269 */
270 private static final int LONG_PRESS_TOOLTIP_HIDE_TIMEOUT = 1500;
271
272 /**
273 * Defines the duration in milliseconds before a hover event causes a tooltip to be shown.
274 */
275 private static final int HOVER_TOOLTIP_SHOW_TIMEOUT = 500;
276
277 /**
278 * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden.
279 * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
280 */
281 private static final int HOVER_TOOLTIP_HIDE_TIMEOUT = 15000;
282
283 /**
284 * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
285 * (short version to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
286 */
287 private static final int HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT = 3000;
288
289 /**
Adam Powellcc84ff42013-12-04 11:15:29 -0800290 * Configuration values for overriding {@link #hasPermanentMenuKey()} behavior.
291 * These constants must match the definition in res/values/config.xml.
292 */
293 private static final int HAS_PERMANENT_MENU_KEY_AUTODETECT = 0;
294 private static final int HAS_PERMANENT_MENU_KEY_TRUE = 1;
295 private static final int HAS_PERMANENT_MENU_KEY_FALSE = 2;
296
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800297 /**
298 * The multiplication factor for inhibiting default gestures.
299 */
300 private static final float AMBIGUOUS_GESTURE_MULTIPLIER = 2f;
301
shepshapardba6dbff2019-02-06 16:14:22 -0800302 private final boolean mConstructedWithContext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 private final int mEdgeSlop;
304 private final int mFadingEdgeLength;
305 private final int mMinimumFlingVelocity;
Romain Guy4296fc42009-07-06 11:48:52 -0700306 private final int mMaximumFlingVelocity;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 private final int mScrollbarSize;
308 private final int mTouchSlop;
shepshapardba6dbff2019-02-06 16:14:22 -0800309 private final int mMinScalingSpan;
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800310 private final int mHoverSlop;
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800311 private final int mMinScrollbarTouchTarget;
Gilles Debunne006fa482011-10-27 17:23:36 -0700312 private final int mDoubleTapTouchSlop;
Adam Powellde8d0832010-03-09 17:11:30 -0800313 private final int mPagingTouchSlop;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 private final int mDoubleTapSlop;
315 private final int mWindowTouchSlop;
316 private final int mMaximumDrawingCacheSize;
Adam Powell637d3372010-08-25 14:37:03 -0700317 private final int mOverscrollDistance;
318 private final int mOverflingDistance;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100319 @UnsupportedAppUsage
Romain Guy68055452011-08-02 16:33:02 -0700320 private final boolean mFadingMarqueeEnabled;
Justin Kohfeabd2c2014-05-02 10:02:44 -0700321 private final long mGlobalActionsKeyTimeout;
Aaron Whytef8306522017-03-22 16:30:58 -0700322 private final float mVerticalScrollFactor;
323 private final float mHorizontalScrollFactor;
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800324 private final boolean mShowMenuShortcutsWhenKeyboardPresent;
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100325 private final long mScreenshotChordKeyTimeout;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326
Sumir Kataria471709a2019-02-04 16:20:19 -0800327 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
Adam Powell8c470622011-06-30 18:19:51 -0700328 private boolean sHasPermanentMenuKey;
Mathew Inwooda570dee2018-08-17 14:56:00 +0100329 @UnsupportedAppUsage
Adam Powell8c470622011-06-30 18:19:51 -0700330 private boolean sHasPermanentMenuKeySet;
331
Mathew Inwooda570dee2018-08-17 14:56:00 +0100332 @UnsupportedAppUsage
Xavier Ducrohet7f9f99ea2011-08-11 10:16:17 -0700333 static final SparseArray<ViewConfiguration> sConfigurations =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 new SparseArray<ViewConfiguration>(2);
335
336 /**
337 * @deprecated Use {@link android.view.ViewConfiguration#get(android.content.Context)} instead.
338 */
339 @Deprecated
340 public ViewConfiguration() {
shepshapardba6dbff2019-02-06 16:14:22 -0800341 mConstructedWithContext = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 mEdgeSlop = EDGE_SLOP;
343 mFadingEdgeLength = FADING_EDGE_LENGTH;
344 mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
Romain Guy4296fc42009-07-06 11:48:52 -0700345 mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 mScrollbarSize = SCROLL_BAR_SIZE;
347 mTouchSlop = TOUCH_SLOP;
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800348 mHoverSlop = TOUCH_SLOP / 2;
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800349 mMinScrollbarTouchTarget = MIN_SCROLLBAR_TOUCH_TARGET;
Gilles Debunne006fa482011-10-27 17:23:36 -0700350 mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
Adam Powellde8d0832010-03-09 17:11:30 -0800351 mPagingTouchSlop = PAGING_TOUCH_SLOP;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 mDoubleTapSlop = DOUBLE_TAP_SLOP;
353 mWindowTouchSlop = WINDOW_TOUCH_SLOP;
354 //noinspection deprecation
355 mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;
Adam Powell637d3372010-08-25 14:37:03 -0700356 mOverscrollDistance = OVERSCROLL_DISTANCE;
357 mOverflingDistance = OVERFLING_DISTANCE;
Romain Guy68055452011-08-02 16:33:02 -0700358 mFadingMarqueeEnabled = true;
Justin Kohfeabd2c2014-05-02 10:02:44 -0700359 mGlobalActionsKeyTimeout = GLOBAL_ACTIONS_KEY_TIMEOUT;
Aaron Whytef8306522017-03-22 16:30:58 -0700360 mHorizontalScrollFactor = HORIZONTAL_SCROLL_FACTOR;
361 mVerticalScrollFactor = VERTICAL_SCROLL_FACTOR;
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800362 mShowMenuShortcutsWhenKeyboardPresent = false;
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100363 mScreenshotChordKeyTimeout = SCREENSHOT_CHORD_KEY_TIMEOUT;
shepshapardba6dbff2019-02-06 16:14:22 -0800364
365 // Getter throws if mConstructedWithContext is false so doesn't matter what
366 // this value is.
367 mMinScalingSpan = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 }
369
370 /**
371 * Creates a new configuration for the specified context. The configuration depends on
372 * various parameters of the context, like the dimension of the display or the density
373 * of the display.
374 *
375 * @param context The application context used to initialize this view configuration.
376 *
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700377 * @see #get(android.content.Context)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 * @see android.util.DisplayMetrics
379 */
380 private ViewConfiguration(Context context) {
shepshapardba6dbff2019-02-06 16:14:22 -0800381 mConstructedWithContext = true;
Adam Powell8c470622011-06-30 18:19:51 -0700382 final Resources res = context.getResources();
383 final DisplayMetrics metrics = res.getDisplayMetrics();
384 final Configuration config = res.getConfiguration();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 final float density = metrics.density;
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800386 final float sizeAndDensity;
Adam Powell8c470622011-06-30 18:19:51 -0700387 if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800388 sizeAndDensity = density * 1.5f;
389 } else {
390 sizeAndDensity = density;
391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800393 mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);
394 mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f);
Tarun Lohani8c89baa2017-06-16 17:21:04 +0000395 mScrollbarSize = res.getDimensionPixelSize(
396 com.android.internal.R.dimen.config_scrollbarSize);
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800397 mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
398 mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
400 // Size of the screen in bytes, in ARGB_8888 format
John Reckab149232019-11-14 00:19:48 +0000401 final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
402 final Display display = win.getDefaultDisplay();
403 final Point size = new Point();
404 display.getRealSize(size);
405 mMaximumDrawingCacheSize = 4 * size.x * size.y;
Adam Powell637d3372010-08-25 14:37:03 -0700406
Dianne Hackbornff801ec2011-01-22 18:05:38 -0800407 mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
408 mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);
Adam Powell8c470622011-06-30 18:19:51 -0700409
410 if (!sHasPermanentMenuKeySet) {
Adam Powellcc84ff42013-12-04 11:15:29 -0800411 final int configVal = res.getInteger(
412 com.android.internal.R.integer.config_overrideHasPermanentMenuKey);
413
414 switch (configVal) {
415 default:
416 case HAS_PERMANENT_MENU_KEY_AUTODETECT: {
417 IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
418 try {
Charles Chenea6e7f02018-11-19 21:37:45 +0800419 sHasPermanentMenuKey = !wm.hasNavigationBar(context.getDisplayId());
Adam Powellcc84ff42013-12-04 11:15:29 -0800420 sHasPermanentMenuKeySet = true;
421 } catch (RemoteException ex) {
422 sHasPermanentMenuKey = false;
423 }
424 }
425 break;
426
427 case HAS_PERMANENT_MENU_KEY_TRUE:
428 sHasPermanentMenuKey = true;
429 sHasPermanentMenuKeySet = true;
430 break;
431
432 case HAS_PERMANENT_MENU_KEY_FALSE:
433 sHasPermanentMenuKey = false;
434 sHasPermanentMenuKeySet = true;
435 break;
Adam Powell8c470622011-06-30 18:19:51 -0700436 }
437 }
Romain Guy68055452011-08-02 16:33:02 -0700438
439 mFadingMarqueeEnabled = res.getBoolean(
440 com.android.internal.R.bool.config_ui_enableFadingMarquee);
Adam Powell7d39f852011-12-05 19:26:54 -0800441 mTouchSlop = res.getDimensionPixelSize(
442 com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800443 mHoverSlop = res.getDimensionPixelSize(
444 com.android.internal.R.dimen.config_viewConfigurationHoverSlop);
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800445 mMinScrollbarTouchTarget = res.getDimensionPixelSize(
446 com.android.internal.R.dimen.config_minScrollbarTouchTarget);
Adam Powell7d39f852011-12-05 19:26:54 -0800447 mPagingTouchSlop = mTouchSlop * 2;
Adam Powelle4b8ff82011-12-06 16:40:49 -0800448
449 mDoubleTapTouchSlop = mTouchSlop;
Mindy Pereira23ffc732014-04-30 17:09:35 -0700450
451 mMinimumFlingVelocity = res.getDimensionPixelSize(
452 com.android.internal.R.dimen.config_viewMinFlingVelocity);
453 mMaximumFlingVelocity = res.getDimensionPixelSize(
454 com.android.internal.R.dimen.config_viewMaxFlingVelocity);
Justin Kohfeabd2c2014-05-02 10:02:44 -0700455 mGlobalActionsKeyTimeout = res.getInteger(
456 com.android.internal.R.integer.config_globalActionsKeyTimeout);
Aaron Whytef8306522017-03-22 16:30:58 -0700457
458 mHorizontalScrollFactor = res.getDimensionPixelSize(
459 com.android.internal.R.dimen.config_horizontalScrollFactor);
460 mVerticalScrollFactor = res.getDimensionPixelSize(
461 com.android.internal.R.dimen.config_verticalScrollFactor);
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800462
463 mShowMenuShortcutsWhenKeyboardPresent = res.getBoolean(
464 com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
465
shepshapardba6dbff2019-02-06 16:14:22 -0800466 mMinScalingSpan = res.getDimensionPixelSize(
467 com.android.internal.R.dimen.config_minScalingSpan);
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100468
469 mScreenshotChordKeyTimeout = res.getInteger(
470 com.android.internal.R.integer.config_screenshotChordKeyTimeout);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 }
472
473 /**
474 * Returns a configuration for the specified context. The configuration depends on
475 * various parameters of the context, like the dimension of the display or the
476 * density of the display.
477 *
478 * @param context The application context used to initialize the view configuration.
479 */
480 public static ViewConfiguration get(Context context) {
481 final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
482 final int density = (int) (100.0f * metrics.density);
483
484 ViewConfiguration configuration = sConfigurations.get(density);
485 if (configuration == null) {
486 configuration = new ViewConfiguration(context);
487 sConfigurations.put(density, configuration);
488 }
489
490 return configuration;
491 }
492
493 /**
494 * @return The width of the horizontal scrollbar and the height of the vertical
Gilles Debunne006fa482011-10-27 17:23:36 -0700495 * scrollbar in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 *
497 * @deprecated Use {@link #getScaledScrollBarSize()} instead.
498 */
499 @Deprecated
500 public static int getScrollBarSize() {
501 return SCROLL_BAR_SIZE;
502 }
503
504 /**
505 * @return The width of the horizontal scrollbar and the height of the vertical
506 * scrollbar in pixels
507 */
508 public int getScaledScrollBarSize() {
509 return mScrollbarSize;
510 }
511
512 /**
Vladislav Kaznacheev4d2c60142017-02-07 17:11:54 -0800513 * @return the minimum size of the scrollbar thumb's touch target in pixels
514 * @hide
515 */
516 public int getScaledMinScrollbarTouchTarget() {
517 return mMinScrollbarTouchTarget;
518 }
519
520 /**
Mike Cleronf116bf82009-09-27 19:14:12 -0700521 * @return Duration of the fade when scrollbars fade away in milliseconds
522 */
523 public static int getScrollBarFadeDuration() {
524 return SCROLL_BAR_FADE_DURATION;
525 }
526
527 /**
Alan Viverette25f0e612015-02-27 12:34:30 -0800528 * @return Default delay before the scrollbars fade in milliseconds
Mike Cleronf116bf82009-09-27 19:14:12 -0700529 */
530 public static int getScrollDefaultDelay() {
531 return SCROLL_BAR_DEFAULT_DELAY;
532 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700533
Mike Cleronf116bf82009-09-27 19:14:12 -0700534 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700535 * @return the length of the fading edges in dips
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 *
537 * @deprecated Use {@link #getScaledFadingEdgeLength()} instead.
538 */
539 @Deprecated
540 public static int getFadingEdgeLength() {
541 return FADING_EDGE_LENGTH;
542 }
543
544 /**
545 * @return the length of the fading edges in pixels
546 */
547 public int getScaledFadingEdgeLength() {
548 return mFadingEdgeLength;
549 }
550
551 /**
552 * @return the duration in milliseconds of the pressed state in child
553 * components.
554 */
555 public static int getPressedStateDuration() {
556 return PRESSED_STATE_DURATION;
557 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 /**
560 * @return the duration in milliseconds before a press turns into
561 * a long press
562 */
563 public static int getLongPressTimeout() {
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800564 return AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,
Jeff Browna4547672011-03-02 21:38:11 -0800565 DEFAULT_LONG_PRESS_TIMEOUT);
566 }
567
568 /**
Anthony Hugh96e9cc52016-07-12 15:17:24 -0700569 * @return the duration in milliseconds between the first tap's up event and the second tap's
570 * down event for an interaction to be considered part of the same multi-press.
571 * @hide
572 */
573 public static int getMultiPressTimeout() {
574 return AppGlobals.getIntCoreSetting(Settings.Secure.MULTI_PRESS_TIMEOUT,
575 DEFAULT_MULTI_PRESS_TIMEOUT);
576 }
577
578 /**
Jeff Browna4547672011-03-02 21:38:11 -0800579 * @return the time before the first key repeat in milliseconds.
580 */
581 public static int getKeyRepeatTimeout() {
582 return getLongPressTimeout();
583 }
584
585 /**
586 * @return the time between successive key repeats in milliseconds.
587 */
588 public static int getKeyRepeatDelay() {
589 return KEY_REPEAT_DELAY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 }
Svetoslav Ganov54d068e2011-03-02 12:58:40 -0800591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 /**
593 * @return the duration in milliseconds we will wait to see if a touch event
594 * is a tap or a scroll. If the user does not move within this interval, it is
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700595 * considered to be a tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 */
597 public static int getTapTimeout() {
598 return TAP_TIMEOUT;
599 }
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700600
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 jump tap. 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 getJumpTapTimeout() {
607 return JUMP_TAP_TIMEOUT;
608 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700609
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 /**
611 * @return the duration in milliseconds between the first tap's up event and
612 * the second tap's down event for an interaction to be considered a
613 * double-tap.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800614 */
615 public static int getDoubleTapTimeout() {
616 return DOUBLE_TAP_TIMEOUT;
617 }
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700618
619 /**
Adam Powellaf1785f2013-09-05 13:44:45 -0700620 * @return the minimum duration in milliseconds between the first tap's
621 * up event and the second tap's down event for an interaction to be considered a
622 * double-tap.
623 *
624 * @hide
625 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100626 @UnsupportedAppUsage
Adam Powellaf1785f2013-09-05 13:44:45 -0700627 public static int getDoubleTapMinTime() {
628 return DOUBLE_TAP_MIN_TIME;
629 }
630
631 /**
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700632 * @return the maximum duration in milliseconds between a touch pad
633 * touch and release for a given touch to be considered a tap (click) as
634 * opposed to a hover movement gesture.
635 * @hide
636 */
637 public static int getHoverTapTimeout() {
638 return HOVER_TAP_TIMEOUT;
639 }
640
641 /**
642 * @return the maximum distance in pixels that a touch pad touch can move
643 * before being released for it to be considered a tap (click) as opposed
644 * to a hover movement gesture.
645 * @hide
646 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100647 @UnsupportedAppUsage
Jeff Brownbb3fcba0c2011-06-06 19:23:05 -0700648 public static int getHoverTapSlop() {
649 return HOVER_TAP_SLOP;
650 }
651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700653 * @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 -0800654 * screen
655 *
656 * @deprecated Use {@link #getScaledEdgeSlop()} instead.
657 */
658 @Deprecated
659 public static int getEdgeSlop() {
660 return EDGE_SLOP;
661 }
662
663 /**
664 * @return Inset in pixels to look for touchable content when the user touches the edge of the
665 * screen
666 */
667 public int getScaledEdgeSlop() {
668 return mEdgeSlop;
669 }
670
671 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700672 * @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 -0800673 *
674 * @deprecated Use {@link #getScaledTouchSlop()} instead.
675 */
676 @Deprecated
677 public static int getTouchSlop() {
678 return TOUCH_SLOP;
679 }
680
681 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700682 * @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 -0800683 */
684 public int getScaledTouchSlop() {
685 return mTouchSlop;
686 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700687
Adam Powellde8d0832010-03-09 17:11:30 -0800688 /**
Vladislav Kaznacheev556ac612017-12-07 11:02:08 -0800689 * @return Distance in pixels a hover can wander while it is still considered "stationary".
690 *
691 */
692 public int getScaledHoverSlop() {
693 return mHoverSlop;
694 }
695
696 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700697 * @return Distance in pixels the first touch can wander before we do not consider this a
698 * potential double tap event
699 * @hide
700 */
Mathew Inwooda570dee2018-08-17 14:56:00 +0100701 @UnsupportedAppUsage
Gilles Debunne006fa482011-10-27 17:23:36 -0700702 public int getScaledDoubleTapTouchSlop() {
703 return mDoubleTapTouchSlop;
704 }
705
706 /**
707 * @return Distance in pixels a touch can wander before we think the user is scrolling a full
708 * page
Adam Powellde8d0832010-03-09 17:11:30 -0800709 */
710 public int getScaledPagingTouchSlop() {
711 return mPagingTouchSlop;
712 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713
714 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700715 * @return Distance in dips between the first touch and second touch to still be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 * considered a double tap
717 * @deprecated Use {@link #getScaledDoubleTapSlop()} instead.
718 * @hide The only client of this should be GestureDetector, which needs this
719 * for clients that still use its deprecated constructor.
720 */
721 @Deprecated
Mathew Inwooda570dee2018-08-17 14:56:00 +0100722 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 public static int getDoubleTapSlop() {
724 return DOUBLE_TAP_SLOP;
725 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700728 * @return Distance in pixels between the first touch and second touch to still be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 * considered a double tap
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
731 public int getScaledDoubleTapSlop() {
732 return mDoubleTapSlop;
733 }
734
735 /**
Svetoslav Ganova0156172011-06-26 17:55:44 -0700736 * Interval for dispatching a recurring accessibility event in milliseconds.
737 * This interval guarantees that a recurring event will be send at most once
738 * during the {@link #getSendRecurringAccessibilityEventsInterval()} time frame.
739 *
740 * @return The delay in milliseconds.
741 *
742 * @hide
743 */
744 public static long getSendRecurringAccessibilityEventsInterval() {
745 return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;
746 }
747
748 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700749 * @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 -0800750 * to be counted as outside the window for purposes of dismissing that
751 * window.
752 *
753 * @deprecated Use {@link #getScaledWindowTouchSlop()} instead.
754 */
755 @Deprecated
756 public static int getWindowTouchSlop() {
757 return WINDOW_TOUCH_SLOP;
758 }
759
760 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700761 * @return Distance in pixels a touch must be outside the bounds of a window for it
762 * to be counted as outside the window for purposes of dismissing that window.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 */
764 public int getScaledWindowTouchSlop() {
765 return mWindowTouchSlop;
766 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700767
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700769 * @return Minimum velocity to initiate a fling, as measured in dips per second.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 *
771 * @deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.
772 */
773 @Deprecated
774 public static int getMinimumFlingVelocity() {
775 return MINIMUM_FLING_VELOCITY;
776 }
777
778 /**
779 * @return Minimum velocity to initiate a fling, as measured in pixels per second.
780 */
781 public int getScaledMinimumFlingVelocity() {
782 return mMinimumFlingVelocity;
783 }
784
785 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700786 * @return Maximum velocity to initiate a fling, as measured in dips per second.
Romain Guy4296fc42009-07-06 11:48:52 -0700787 *
788 * @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
789 */
790 @Deprecated
791 public static int getMaximumFlingVelocity() {
792 return MAXIMUM_FLING_VELOCITY;
793 }
794
795 /**
796 * @return Maximum velocity to initiate a fling, as measured in pixels per second.
797 */
798 public int getScaledMaximumFlingVelocity() {
799 return mMaximumFlingVelocity;
800 }
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700801
Romain Guy4296fc42009-07-06 11:48:52 -0700802 /**
Ned Burns69af4322016-08-17 17:30:25 -0400803 * @return Amount to scroll in response to a {@link MotionEvent#ACTION_SCROLL} event. Multiply
804 * this by the event's axis value to obtain the number of pixels to be scrolled.
Aaron Whytef8306522017-03-22 16:30:58 -0700805 *
806 * @removed
Ned Burns69af4322016-08-17 17:30:25 -0400807 */
808 public int getScaledScrollFactor() {
Aaron Whytef8306522017-03-22 16:30:58 -0700809 return (int) mVerticalScrollFactor;
810 }
811
812 /**
813 * @return Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event.
814 * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
815 */
816 public float getScaledHorizontalScrollFactor() {
817 return mHorizontalScrollFactor;
818 }
819
820 /**
821 * @return Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event.
822 * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
823 */
824 public float getScaledVerticalScrollFactor() {
825 return mVerticalScrollFactor;
Ned Burns69af4322016-08-17 17:30:25 -0400826 }
827
828 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 * The maximum drawing cache size expressed in bytes.
830 *
831 * @return the maximum size of View's drawing cache expressed in bytes
832 *
833 * @deprecated Use {@link #getScaledMaximumDrawingCacheSize()} instead.
834 */
835 @Deprecated
836 public static int getMaximumDrawingCacheSize() {
837 //noinspection deprecation
838 return MAXIMUM_DRAWING_CACHE_SIZE;
839 }
840
841 /**
842 * The maximum drawing cache size expressed in bytes.
843 *
844 * @return the maximum size of View's drawing cache expressed in bytes
845 */
846 public int getScaledMaximumDrawingCacheSize() {
847 return mMaximumDrawingCacheSize;
848 }
849
850 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700851 * @return The maximum distance a View should overscroll by when showing edge effects (in
852 * pixels).
Adam Powell637d3372010-08-25 14:37:03 -0700853 */
854 public int getScaledOverscrollDistance() {
855 return mOverscrollDistance;
856 }
857
858 /**
Gilles Debunne006fa482011-10-27 17:23:36 -0700859 * @return The maximum distance a View should overfling by when showing edge effects (in
860 * pixels).
Adam Powell637d3372010-08-25 14:37:03 -0700861 */
862 public int getScaledOverflingDistance() {
863 return mOverflingDistance;
864 }
865
866 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 * The amount of time that the zoom controls should be
868 * displayed on the screen expressed in milliseconds.
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700869 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 * @return the time the zoom controls should be visible expressed
871 * in milliseconds.
872 */
873 public static long getZoomControlsTimeout() {
874 return ZOOM_CONTROLS_TIMEOUT;
875 }
876
877 /**
878 * The amount of time a user needs to press the relevant key to bring up
879 * the global actions dialog.
880 *
881 * @return how long a user needs to press the relevant key to bring up
882 * the global actions dialog.
Justin Koh8031fa02014-05-05 16:28:49 -0700883 * @deprecated This timeout should not be used by applications
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 */
Justin Koh1aa59f82014-05-04 12:13:25 -0700885 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 public static long getGlobalActionKeyTimeout() {
887 return GLOBAL_ACTIONS_KEY_TIMEOUT;
888 }
889
890 /**
Justin Kohfeabd2c2014-05-02 10:02:44 -0700891 * The amount of time a user needs to press the relevant key to bring up
892 * the global actions dialog.
893 *
894 * @return how long a user needs to press the relevant key to bring up
895 * the global actions dialog.
Justin Koh1aa59f82014-05-04 12:13:25 -0700896 * @hide
Justin Kohfeabd2c2014-05-02 10:02:44 -0700897 */
Aurimas Liutikas80e4e182018-08-13 16:13:37 -0700898 @TestApi
Justin Kohfeabd2c2014-05-02 10:02:44 -0700899 public long getDeviceGlobalActionKeyTimeout() {
900 return mGlobalActionsKeyTimeout;
901 }
902
903 /**
Edward Savage-Jones8f5c95b2018-11-14 22:19:28 +0100904 * The amount of time a user needs to press the relevant keys to trigger
905 * the screenshot chord.
906 *
907 * @return how long a user needs to press the relevant keys to trigger
908 * the screenshot chord.
909 * @hide
910 */
911 public long getScreenshotChordKeyTimeout() {
912 return mScreenshotChordKeyTimeout;
913 }
914
915 /**
Phil Weaver106fe732016-11-22 18:18:39 -0800916 * The amount of time a user needs to press the relevant keys to activate the accessibility
917 * shortcut.
918 *
919 * @return how long a user needs to press the relevant keys to activate the accessibility
920 * shortcut.
921 * @hide
922 */
923 public long getAccessibilityShortcutKeyTimeout() {
924 return A11Y_SHORTCUT_KEY_TIMEOUT;
925 }
926
927 /**
Eugene Susla5f19cd32017-10-19 14:00:59 -0700928 * @return The amount of time a user needs to press the relevant keys to activate the
929 * accessibility shortcut after it's confirmed that accessibility shortcut is used.
930 * @hide
931 */
932 public long getAccessibilityShortcutKeyTimeoutAfterConfirmation() {
933 return A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION;
934 }
935
936 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 * The amount of friction applied to scrolls and flings.
Daisuke Miyakawac19895f2012-04-03 12:25:26 -0700938 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 * @return A scalar dimensionless value representing the coefficient of
940 * friction.
941 */
942 public static float getScrollFriction() {
943 return SCROLL_FRICTION;
944 }
Adam Powell8c470622011-06-30 18:19:51 -0700945
946 /**
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100947 * @return the default duration in milliseconds for {@link ActionMode#hide(long)}.
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100948 */
Abodunrinwa Toki9e211282015-06-05 02:46:57 +0100949 public static long getDefaultActionModeHideDuration() {
950 return ACTION_MODE_HIDE_DURATION_DEFAULT;
Abodunrinwa Tokifd3a3a12015-05-05 20:04:34 +0100951 }
952
953 /**
Siarhei Vishniakou6e1cdb62019-02-22 15:07:56 -0600954 * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set,
955 * then certain actions, such as scrolling, will be inhibited.
Siarhei Vishniakou8b047dd2019-01-24 16:04:13 -0800956 * However, to account for the possibility of incorrect classification,
957 * the default scrolling will only be inhibited if the pointer travels less than
958 * (getScaledTouchSlop() * this factor).
959 * Likewise, the default long press timeout will be increased by this factor for some situations
960 * where the default behaviour is to cancel it.
961 *
962 * @return The multiplication factor for inhibiting default gestures.
963 */
964 @FloatRange(from = 1.0)
965 public static float getAmbiguousGestureMultiplier() {
966 return AMBIGUOUS_GESTURE_MULTIPLIER;
967 }
968
969 /**
Adam Powell8c470622011-06-30 18:19:51 -0700970 * Report if the device has a permanent menu key available to the user.
971 *
972 * <p>As of Android 3.0, devices may not have a permanent menu key available.
973 * Apps should use the action bar to present menu options to users.
974 * However, there are some apps where the action bar is inappropriate
975 * or undesirable. This method may be used to detect if a menu key is present.
976 * If not, applications should provide another on-screen affordance to access
977 * functionality.
978 *
979 * @return true if a permanent menu key is present, false otherwise.
980 */
981 public boolean hasPermanentMenuKey() {
982 return sHasPermanentMenuKey;
983 }
Romain Guy68055452011-08-02 16:33:02 -0700984
985 /**
Vladislav Kaznacheeva725df92018-02-26 16:22:34 -0800986 * Check if shortcuts should be displayed in menus.
987 *
988 * @return {@code True} if shortcuts should be displayed in menus.
989 */
990 public boolean shouldShowMenuShortcutsWhenKeyboardPresent() {
991 return mShowMenuShortcutsWhenKeyboardPresent;
992 }
993
994 /**
shepshapardba6dbff2019-02-06 16:14:22 -0800995 * Retrieves the distance in pixels between touches that must be reached for a gesture to be
996 * interpreted as scaling.
997 *
998 * In general, scaling shouldn't start until this distance has been met or surpassed, and
999 * scaling should end when the distance in pixels between touches drops below this distance.
1000 *
1001 * @return The distance in pixels
1002 * @throws IllegalStateException if this method is called on a ViewConfiguration that was
1003 * instantiated using a constructor with no Context parameter.
1004 */
shepshapard192c6352019-02-26 11:05:46 -08001005 public int getScaledMinimumScalingSpan() {
shepshapardba6dbff2019-02-06 16:14:22 -08001006 if (!mConstructedWithContext) {
1007 throw new IllegalStateException("Min scaling span cannot be determined when this "
1008 + "method is called on a ViewConfiguration that was instantiated using a "
1009 + "constructor with no Context parameter");
1010 }
1011 return mMinScalingSpan;
1012 }
1013
1014 /**
Romain Guy68055452011-08-02 16:33:02 -07001015 * @hide
1016 * @return Whether or not marquee should use fading edges.
1017 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01001018 @UnsupportedAppUsage
Romain Guy68055452011-08-02 16:33:02 -07001019 public boolean isFadingMarqueeEnabled() {
1020 return mFadingMarqueeEnabled;
1021 }
Vladislav Kaznacheevf847ee32016-11-21 14:11:00 -08001022
1023 /**
1024 * @return the duration in milliseconds before an end of a long press causes a tooltip to be
1025 * hidden
1026 * @hide
1027 */
1028 @TestApi
1029 public static int getLongPressTooltipHideTimeout() {
1030 return LONG_PRESS_TOOLTIP_HIDE_TIMEOUT;
1031 }
1032
1033 /**
1034 * @return the duration in milliseconds before a hover event causes a tooltip to be shown
1035 * @hide
1036 */
1037 @TestApi
1038 public static int getHoverTooltipShowTimeout() {
1039 return HOVER_TOOLTIP_SHOW_TIMEOUT;
1040 }
1041
1042 /**
1043 * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1044 * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
1045 * @hide
1046 */
1047 @TestApi
1048 public static int getHoverTooltipHideTimeout() {
1049 return HOVER_TOOLTIP_HIDE_TIMEOUT;
1050 }
1051
1052 /**
1053 * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1054 * (shorter variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
1055 * @hide
1056 */
1057 @TestApi
1058 public static int getHoverTooltipHideShortTimeout() {
1059 return HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT;
1060 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061}