• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.view;
18 
19 import android.annotation.FloatRange;
20 import android.annotation.TestApi;
21 import android.annotation.UiContext;
22 import android.app.Activity;
23 import android.app.AppGlobals;
24 import android.compat.annotation.UnsupportedAppUsage;
25 import android.content.Context;
26 import android.content.res.Configuration;
27 import android.content.res.Resources;
28 import android.graphics.Rect;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.RemoteException;
32 import android.os.StrictMode;
33 import android.provider.Settings;
34 import android.util.DisplayMetrics;
35 import android.util.SparseArray;
36 import android.util.TypedValue;
37 
38 /**
39  * Contains methods to standard constants used in the UI for timeouts, sizes, and distances.
40  */
41 public class ViewConfiguration {
42     private static final String TAG = "ViewConfiguration";
43 
44     /**
45      * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in
46      * dips
47      */
48     private static final int SCROLL_BAR_SIZE = 4;
49 
50     /**
51      * Duration of the fade when scrollbars fade away in milliseconds
52      */
53     private static final int SCROLL_BAR_FADE_DURATION = 250;
54 
55     /**
56      * Default delay before the scrollbars fade in milliseconds
57      */
58     private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
59 
60     /**
61      * Defines the length of the fading edges in dips
62      */
63     private static final int FADING_EDGE_LENGTH = 12;
64 
65     /**
66      * Defines the duration in milliseconds of the pressed state in child
67      * components.
68      */
69     private static final int PRESSED_STATE_DURATION = 64;
70 
71     /**
72      * Defines the default duration in milliseconds before a press turns into
73      * a long press
74      * @hide
75      */
76     public static final int DEFAULT_LONG_PRESS_TIMEOUT = 400;
77 
78     /**
79      * Defines the default duration in milliseconds between the first tap's up event and the second
80      * tap's down event for an interaction to be considered part of the same multi-press.
81      */
82     private static final int DEFAULT_MULTI_PRESS_TIMEOUT = 300;
83 
84     /**
85      * Defines the time between successive key repeats in milliseconds.
86      */
87     private static final int KEY_REPEAT_DELAY = 50;
88 
89     /**
90      * Defines the duration in milliseconds a user needs to hold down the
91      * appropriate button to bring up the global actions dialog (power off,
92      * lock screen, etc).
93      */
94     private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
95 
96     /**
97      * Defines the duration in milliseconds a user needs to hold down the
98      * appropriate buttons (power + volume down) to trigger the screenshot chord.
99      */
100     private static final int SCREENSHOT_CHORD_KEY_TIMEOUT = 0;
101 
102     /**
103      * Defines the duration in milliseconds a user needs to hold down the
104      * appropriate button to bring up the accessibility shortcut for the first time
105      */
106     private static final int A11Y_SHORTCUT_KEY_TIMEOUT = 3000;
107 
108     /**
109      * Defines the duration in milliseconds a user needs to hold down the
110      * appropriate button to enable the accessibility shortcut once it's configured.
111      */
112     private static final int A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION = 1000;
113 
114     /**
115      * Defines the duration in milliseconds we will wait to see if a touch event
116      * is a tap or a scroll. If the user does not move within this interval, it is
117      * considered to be a tap.
118      */
119     private static final int TAP_TIMEOUT = 100;
120 
121     /**
122      * Defines the duration in milliseconds we will wait to see if a touch event
123      * is a jump tap. If the user does not complete the jump tap within this interval, it is
124      * considered to be a tap.
125      */
126     private static final int JUMP_TAP_TIMEOUT = 500;
127 
128     /**
129      * Defines the duration in milliseconds between the first tap's up event and
130      * the second tap's down event for an interaction to be considered a
131      * double-tap.
132      */
133     private static final int DOUBLE_TAP_TIMEOUT = 300;
134 
135     /**
136      * Defines the minimum duration in milliseconds between the first tap's up event and
137      * the second tap's down event for an interaction to be considered a
138      * double-tap.
139      */
140     private static final int DOUBLE_TAP_MIN_TIME = 40;
141 
142     /**
143      * Defines the maximum duration in milliseconds between a touch pad
144      * touch and release for a given touch to be considered a tap (click) as
145      * opposed to a hover movement gesture.
146      */
147     private static final int HOVER_TAP_TIMEOUT = 150;
148 
149     /**
150      * Defines the maximum distance in pixels that a touch pad touch can move
151      * before being released for it to be considered a tap (click) as opposed
152      * to a hover movement gesture.
153      */
154     private static final int HOVER_TAP_SLOP = 20;
155 
156     /**
157      * Defines the duration in milliseconds we want to display zoom controls in response
158      * to a user panning within an application.
159      */
160     private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
161 
162     /**
163      * Inset in dips to look for touchable content when the user touches the edge of the screen
164      */
165     private static final int EDGE_SLOP = 12;
166 
167     /**
168      * Distance a touch can wander before we think the user is scrolling in dips.
169      * Note that this value defined here is only used as a fallback by legacy/misbehaving
170      * applications that do not provide a Context for determining density/configuration-dependent
171      * values.
172      *
173      * To alter this value, see the configuration resource config_viewConfigurationTouchSlop
174      * in frameworks/base/core/res/res/values/config.xml or the appropriate device resource overlay.
175      * It may be appropriate to tweak this on a device-specific basis in an overlay based on
176      * the characteristics of the touch panel and firmware.
177      */
178     private static final int TOUCH_SLOP = 8;
179 
180     /**
181      * Defines the minimum size of the touch target for a scrollbar in dips
182      */
183     private static final int MIN_SCROLLBAR_TOUCH_TARGET = 48;
184 
185     /**
186      * Distance the first touch can wander before we stop considering this event a double tap
187      * (in dips)
188      */
189     private static final int DOUBLE_TAP_TOUCH_SLOP = TOUCH_SLOP;
190 
191     /**
192      * Distance a touch can wander before we think the user is attempting a paged scroll
193      * (in dips)
194      *
195      * Note that this value defined here is only used as a fallback by legacy/misbehaving
196      * applications that do not provide a Context for determining density/configuration-dependent
197      * values.
198      *
199      * See the note above on {@link #TOUCH_SLOP} regarding the dimen resource
200      * config_viewConfigurationTouchSlop. ViewConfiguration will report a paging touch slop of
201      * config_viewConfigurationTouchSlop * 2 when provided with a Context.
202      */
203     private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
204 
205     /**
206      * Distance in dips between the first touch and second touch to still be considered a double tap
207      */
208     private static final int DOUBLE_TAP_SLOP = 100;
209 
210     /**
211      * Distance in dips a touch needs to be outside of a window's bounds for it to
212      * count as outside for purposes of dismissing the window.
213      */
214     private static final int WINDOW_TOUCH_SLOP = 16;
215 
216     /**
217      * Minimum velocity to initiate a fling, as measured in dips per second
218      */
219     private static final int MINIMUM_FLING_VELOCITY = 50;
220 
221     /**
222      * Maximum velocity to initiate a fling, as measured in dips per second
223      */
224     private static final int MAXIMUM_FLING_VELOCITY = 8000;
225 
226     /**
227      * Delay before dispatching a recurring accessibility event in milliseconds.
228      * This delay guarantees that a recurring event will be send at most once
229      * during the {@link #SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS} time
230      * frame.
231      */
232     private static final long SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS = 100;
233 
234     /**
235      * The maximum size of View's drawing cache, expressed in bytes. This size
236      * should be at least equal to the size of the screen in ARGB888 format.
237      */
238     @Deprecated
239     private static final int MAXIMUM_DRAWING_CACHE_SIZE = 480 * 800 * 4; // ARGB8888
240 
241     /**
242      * The coefficient of friction applied to flings/scrolls.
243      */
244     @UnsupportedAppUsage
245     private static final float SCROLL_FRICTION = 0.015f;
246 
247     /**
248      * Max distance in dips to overscroll for edge effects
249      */
250     private static final int OVERSCROLL_DISTANCE = 0;
251 
252     /**
253      * Max distance in dips to overfling for edge effects
254      */
255     private static final int OVERFLING_DISTANCE = 6;
256 
257     /**
258      * Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event,
259      * in dips per axis value.
260      */
261     private static final float HORIZONTAL_SCROLL_FACTOR = 64;
262 
263     /**
264      * Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event,
265      * in dips per axis value.
266      */
267     private static final float VERTICAL_SCROLL_FACTOR = 64;
268 
269     /**
270      * Default duration to hide an action mode for.
271      */
272     private static final long ACTION_MODE_HIDE_DURATION_DEFAULT = 2000;
273 
274     /**
275      * Defines the duration in milliseconds before an end of a long press causes a tooltip to be
276      * hidden.
277      */
278     private static final int LONG_PRESS_TOOLTIP_HIDE_TIMEOUT = 1500;
279 
280     /**
281      * Defines the duration in milliseconds before a hover event causes a tooltip to be shown.
282      */
283     private static final int HOVER_TOOLTIP_SHOW_TIMEOUT = 500;
284 
285     /**
286      * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden.
287      * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
288      */
289     private static final int HOVER_TOOLTIP_HIDE_TIMEOUT = 15000;
290 
291     /**
292      * Defines the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
293      * (short version to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
294      */
295     private static final int HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT = 3000;
296 
297     /**
298      * Configuration values for overriding {@link #hasPermanentMenuKey()} behavior.
299      * These constants must match the definition in res/values/config.xml.
300      */
301     private static final int HAS_PERMANENT_MENU_KEY_AUTODETECT = 0;
302     private static final int HAS_PERMANENT_MENU_KEY_TRUE = 1;
303     private static final int HAS_PERMANENT_MENU_KEY_FALSE = 2;
304 
305     /**
306      * The multiplication factor for inhibiting default gestures.
307      */
308     private static final float AMBIGUOUS_GESTURE_MULTIPLIER = 2f;
309 
310     /**
311      * The timeout value in milliseconds to adjust the selection span and actions for the selected
312      * text when TextClassifier has been initialized.
313      */
314     private static final int SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND = 200;
315 
316     /**
317      * The timeout value in milliseconds to adjust the selection span and actions for the selected
318      * text when TextClassifier has not been initialized.
319      */
320     private static final int SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND = 500;
321 
322     private final boolean mConstructedWithContext;
323     private final int mEdgeSlop;
324     private final int mFadingEdgeLength;
325     private final int mMinimumFlingVelocity;
326     private final int mMaximumFlingVelocity;
327     private final int mScrollbarSize;
328     private final int mTouchSlop;
329     private final int mMinScalingSpan;
330     private final int mHoverSlop;
331     private final int mMinScrollbarTouchTarget;
332     private final int mDoubleTapTouchSlop;
333     private final int mPagingTouchSlop;
334     private final int mDoubleTapSlop;
335     private final int mWindowTouchSlop;
336     private final float mAmbiguousGestureMultiplier;
337     private final int mMaximumDrawingCacheSize;
338     private final int mOverscrollDistance;
339     private final int mOverflingDistance;
340     @UnsupportedAppUsage
341     private final boolean mFadingMarqueeEnabled;
342     private final long mGlobalActionsKeyTimeout;
343     private final float mVerticalScrollFactor;
344     private final float mHorizontalScrollFactor;
345     private final boolean mShowMenuShortcutsWhenKeyboardPresent;
346     private final long mScreenshotChordKeyTimeout;
347     private final int mSmartSelectionInitializedTimeout;
348     private final int mSmartSelectionInitializingTimeout;
349 
350     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
351     private boolean sHasPermanentMenuKey;
352     @UnsupportedAppUsage
353     private boolean sHasPermanentMenuKeySet;
354 
355     @UnsupportedAppUsage
356     static final SparseArray<ViewConfiguration> sConfigurations =
357             new SparseArray<ViewConfiguration>(2);
358 
359     /**
360      * @deprecated Use {@link android.view.ViewConfiguration#get(android.content.Context)} instead.
361      */
362     @Deprecated
ViewConfiguration()363     public ViewConfiguration() {
364         mConstructedWithContext = false;
365         mEdgeSlop = EDGE_SLOP;
366         mFadingEdgeLength = FADING_EDGE_LENGTH;
367         mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
368         mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
369         mScrollbarSize = SCROLL_BAR_SIZE;
370         mTouchSlop = TOUCH_SLOP;
371         mHoverSlop = TOUCH_SLOP / 2;
372         mMinScrollbarTouchTarget = MIN_SCROLLBAR_TOUCH_TARGET;
373         mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
374         mPagingTouchSlop = PAGING_TOUCH_SLOP;
375         mDoubleTapSlop = DOUBLE_TAP_SLOP;
376         mWindowTouchSlop = WINDOW_TOUCH_SLOP;
377         mAmbiguousGestureMultiplier = AMBIGUOUS_GESTURE_MULTIPLIER;
378         //noinspection deprecation
379         mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;
380         mOverscrollDistance = OVERSCROLL_DISTANCE;
381         mOverflingDistance = OVERFLING_DISTANCE;
382         mFadingMarqueeEnabled = true;
383         mGlobalActionsKeyTimeout = GLOBAL_ACTIONS_KEY_TIMEOUT;
384         mHorizontalScrollFactor = HORIZONTAL_SCROLL_FACTOR;
385         mVerticalScrollFactor = VERTICAL_SCROLL_FACTOR;
386         mShowMenuShortcutsWhenKeyboardPresent = false;
387         mScreenshotChordKeyTimeout = SCREENSHOT_CHORD_KEY_TIMEOUT;
388 
389         // Getter throws if mConstructedWithContext is false so doesn't matter what
390         // this value is.
391         mMinScalingSpan = 0;
392         mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND;
393         mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND;
394     }
395 
396     /**
397      * Creates a new configuration for the specified visual {@link Context}. The configuration
398      * depends on various parameters of the {@link Context}, like the dimension of the display or
399      * the density of the display.
400      *
401      * @param context A visual {@link Context} used to initialize the view configuration. It must
402      *                be {@link Activity} or other {@link Context} created with
403      *                {@link Context#createWindowContext(int, Bundle)}.
404      *
405      * @see #get(android.content.Context)
406      * @see android.util.DisplayMetrics
407      */
ViewConfiguration(@iContext Context context)408     private ViewConfiguration(@UiContext Context context) {
409         mConstructedWithContext = true;
410         final Resources res = context.getResources();
411         final DisplayMetrics metrics = res.getDisplayMetrics();
412         final Configuration config = res.getConfiguration();
413         final float density = metrics.density;
414         final float sizeAndDensity;
415         if (config.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE)) {
416             sizeAndDensity = density * 1.5f;
417         } else {
418             sizeAndDensity = density;
419         }
420 
421         mEdgeSlop = (int) (sizeAndDensity * EDGE_SLOP + 0.5f);
422         mFadingEdgeLength = (int) (sizeAndDensity * FADING_EDGE_LENGTH + 0.5f);
423         mScrollbarSize = res.getDimensionPixelSize(
424                 com.android.internal.R.dimen.config_scrollbarSize);
425         mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f);
426         mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f);
427 
428         final TypedValue multiplierValue = new TypedValue();
429         res.getValue(
430                 com.android.internal.R.dimen.config_ambiguousGestureMultiplier,
431                 multiplierValue,
432                 true /*resolveRefs*/);
433         mAmbiguousGestureMultiplier = Math.max(1.0f, multiplierValue.getFloat());
434 
435         // Size of the screen in bytes, in ARGB_8888 format
436         final WindowManager windowManager = context.getSystemService(WindowManager.class);
437         final Rect maxWindowBounds = windowManager.getMaximumWindowMetrics().getBounds();
438         mMaximumDrawingCacheSize = 4 * maxWindowBounds.width() * maxWindowBounds.height();
439 
440         mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f);
441         mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f);
442 
443         if (!sHasPermanentMenuKeySet) {
444             final int configVal = res.getInteger(
445                     com.android.internal.R.integer.config_overrideHasPermanentMenuKey);
446 
447             switch (configVal) {
448                 default:
449                 case HAS_PERMANENT_MENU_KEY_AUTODETECT: {
450                     IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
451                     try {
452                         sHasPermanentMenuKey = !wm.hasNavigationBar(context.getDisplayId());
453                         sHasPermanentMenuKeySet = true;
454                     } catch (RemoteException ex) {
455                         sHasPermanentMenuKey = false;
456                     }
457                 }
458                 break;
459 
460                 case HAS_PERMANENT_MENU_KEY_TRUE:
461                     sHasPermanentMenuKey = true;
462                     sHasPermanentMenuKeySet = true;
463                     break;
464 
465                 case HAS_PERMANENT_MENU_KEY_FALSE:
466                     sHasPermanentMenuKey = false;
467                     sHasPermanentMenuKeySet = true;
468                     break;
469             }
470         }
471 
472         mFadingMarqueeEnabled = res.getBoolean(
473                 com.android.internal.R.bool.config_ui_enableFadingMarquee);
474         mTouchSlop = res.getDimensionPixelSize(
475                 com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
476         mHoverSlop = res.getDimensionPixelSize(
477                 com.android.internal.R.dimen.config_viewConfigurationHoverSlop);
478         mMinScrollbarTouchTarget = res.getDimensionPixelSize(
479                 com.android.internal.R.dimen.config_minScrollbarTouchTarget);
480         mPagingTouchSlop = mTouchSlop * 2;
481 
482         mDoubleTapTouchSlop = mTouchSlop;
483 
484         mMinimumFlingVelocity = res.getDimensionPixelSize(
485                 com.android.internal.R.dimen.config_viewMinFlingVelocity);
486         mMaximumFlingVelocity = res.getDimensionPixelSize(
487                 com.android.internal.R.dimen.config_viewMaxFlingVelocity);
488         mGlobalActionsKeyTimeout = res.getInteger(
489                 com.android.internal.R.integer.config_globalActionsKeyTimeout);
490 
491         mHorizontalScrollFactor = res.getDimensionPixelSize(
492                 com.android.internal.R.dimen.config_horizontalScrollFactor);
493         mVerticalScrollFactor = res.getDimensionPixelSize(
494                 com.android.internal.R.dimen.config_verticalScrollFactor);
495 
496         mShowMenuShortcutsWhenKeyboardPresent = res.getBoolean(
497             com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
498 
499         mMinScalingSpan = res.getDimensionPixelSize(
500                 com.android.internal.R.dimen.config_minScalingSpan);
501 
502         mScreenshotChordKeyTimeout = res.getInteger(
503                 com.android.internal.R.integer.config_screenshotChordKeyTimeout);
504 
505         mSmartSelectionInitializedTimeout = res.getInteger(
506                 com.android.internal.R.integer.config_smartSelectionInitializedTimeoutMillis);
507         mSmartSelectionInitializingTimeout = res.getInteger(
508                 com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis);
509     }
510 
511     /**
512      * Returns a configuration for the specified visual {@link Context}. The configuration depends
513      * on various parameters of the {@link Context}, like the dimension of the display or the
514      * density of the display.
515      *
516      * @param context A visual {@link Context} used to initialize the view configuration. It must
517      *                be {@link Activity} or other {@link Context} created with
518      *                {@link Context#createWindowContext(int, Bundle)}.
519      */
520     // TODO(b/182007470): Use @ConfigurationContext instead
get(@iContext Context context)521     public static ViewConfiguration get(@UiContext Context context) {
522         StrictMode.assertConfigurationContext(context, "ViewConfiguration");
523 
524         final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
525         final int density = (int) (100.0f * metrics.density);
526 
527         ViewConfiguration configuration = sConfigurations.get(density);
528         if (configuration == null) {
529             configuration = new ViewConfiguration(context);
530             sConfigurations.put(density, configuration);
531         }
532 
533         return configuration;
534     }
535 
536     /**
537      * @return The width of the horizontal scrollbar and the height of the vertical
538      *         scrollbar in dips
539      *
540      * @deprecated Use {@link #getScaledScrollBarSize()} instead.
541      */
542     @Deprecated
getScrollBarSize()543     public static int getScrollBarSize() {
544         return SCROLL_BAR_SIZE;
545     }
546 
547     /**
548      * @return The width of the horizontal scrollbar and the height of the vertical
549      *         scrollbar in pixels
550      */
getScaledScrollBarSize()551     public int getScaledScrollBarSize() {
552         return mScrollbarSize;
553     }
554 
555     /**
556      * @return the minimum size of the scrollbar thumb's touch target in pixels
557      * @hide
558      */
getScaledMinScrollbarTouchTarget()559     public int getScaledMinScrollbarTouchTarget() {
560         return mMinScrollbarTouchTarget;
561     }
562 
563     /**
564      * @return Duration of the fade when scrollbars fade away in milliseconds
565      */
getScrollBarFadeDuration()566     public static int getScrollBarFadeDuration() {
567         return SCROLL_BAR_FADE_DURATION;
568     }
569 
570     /**
571      * @return Default delay before the scrollbars fade in milliseconds
572      */
getScrollDefaultDelay()573     public static int getScrollDefaultDelay() {
574         return SCROLL_BAR_DEFAULT_DELAY;
575     }
576 
577     /**
578      * @return the length of the fading edges in dips
579      *
580      * @deprecated Use {@link #getScaledFadingEdgeLength()} instead.
581      */
582     @Deprecated
getFadingEdgeLength()583     public static int getFadingEdgeLength() {
584         return FADING_EDGE_LENGTH;
585     }
586 
587     /**
588      * @return the length of the fading edges in pixels
589      */
getScaledFadingEdgeLength()590     public int getScaledFadingEdgeLength() {
591         return mFadingEdgeLength;
592     }
593 
594     /**
595      * @return the duration in milliseconds of the pressed state in child
596      * components.
597      */
getPressedStateDuration()598     public static int getPressedStateDuration() {
599         return PRESSED_STATE_DURATION;
600     }
601 
602     /**
603      * @return the duration in milliseconds before a press turns into
604      * a long press
605      */
getLongPressTimeout()606     public static int getLongPressTimeout() {
607         return AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,
608                 DEFAULT_LONG_PRESS_TIMEOUT);
609     }
610 
611     /**
612      * @return the duration in milliseconds between the first tap's up event and the second tap's
613      * down event for an interaction to be considered part of the same multi-press.
614      */
getMultiPressTimeout()615     public static int getMultiPressTimeout() {
616         return AppGlobals.getIntCoreSetting(Settings.Secure.MULTI_PRESS_TIMEOUT,
617                 DEFAULT_MULTI_PRESS_TIMEOUT);
618     }
619 
620     /**
621      * @return the time before the first key repeat in milliseconds.
622      */
getKeyRepeatTimeout()623     public static int getKeyRepeatTimeout() {
624         return getLongPressTimeout();
625     }
626 
627     /**
628      * @return the time between successive key repeats in milliseconds.
629      */
getKeyRepeatDelay()630     public static int getKeyRepeatDelay() {
631         return KEY_REPEAT_DELAY;
632     }
633 
634     /**
635      * @return the duration in milliseconds we will wait to see if a touch event
636      * is a tap or a scroll. If the user does not move within this interval, it is
637      * considered to be a tap.
638      */
getTapTimeout()639     public static int getTapTimeout() {
640         return TAP_TIMEOUT;
641     }
642 
643     /**
644      * @return the duration in milliseconds we will wait to see if a touch event
645      * is a jump tap. If the user does not move within this interval, it is
646      * considered to be a tap.
647      */
getJumpTapTimeout()648     public static int getJumpTapTimeout() {
649         return JUMP_TAP_TIMEOUT;
650     }
651 
652     /**
653      * @return the duration in milliseconds between the first tap's up event and
654      * the second tap's down event for an interaction to be considered a
655      * double-tap.
656      */
getDoubleTapTimeout()657     public static int getDoubleTapTimeout() {
658         return DOUBLE_TAP_TIMEOUT;
659     }
660 
661     /**
662      * @return the minimum duration in milliseconds between the first tap's
663      * up event and the second tap's down event for an interaction to be considered a
664      * double-tap.
665      *
666      * @hide
667      */
668     @UnsupportedAppUsage
getDoubleTapMinTime()669     public static int getDoubleTapMinTime() {
670         return DOUBLE_TAP_MIN_TIME;
671     }
672 
673     /**
674      * @return the maximum duration in milliseconds between a touch pad
675      * touch and release for a given touch to be considered a tap (click) as
676      * opposed to a hover movement gesture.
677      * @hide
678      */
getHoverTapTimeout()679     public static int getHoverTapTimeout() {
680         return HOVER_TAP_TIMEOUT;
681     }
682 
683     /**
684      * @return the maximum distance in pixels that a touch pad touch can move
685      * before being released for it to be considered a tap (click) as opposed
686      * to a hover movement gesture.
687      * @hide
688      */
689     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getHoverTapSlop()690     public static int getHoverTapSlop() {
691         return HOVER_TAP_SLOP;
692     }
693 
694     /**
695      * @return Inset in dips to look for touchable content when the user touches the edge of the
696      *         screen
697      *
698      * @deprecated Use {@link #getScaledEdgeSlop()} instead.
699      */
700     @Deprecated
getEdgeSlop()701     public static int getEdgeSlop() {
702         return EDGE_SLOP;
703     }
704 
705     /**
706      * @return Inset in pixels to look for touchable content when the user touches the edge of the
707      *         screen
708      */
getScaledEdgeSlop()709     public int getScaledEdgeSlop() {
710         return mEdgeSlop;
711     }
712 
713     /**
714      * @return Distance in dips a touch can wander before we think the user is scrolling
715      *
716      * @deprecated Use {@link #getScaledTouchSlop()} instead.
717      */
718     @Deprecated
getTouchSlop()719     public static int getTouchSlop() {
720         return TOUCH_SLOP;
721     }
722 
723     /**
724      * @return Distance in pixels a touch can wander before we think the user is scrolling
725      */
getScaledTouchSlop()726     public int getScaledTouchSlop() {
727         return mTouchSlop;
728     }
729 
730     /**
731      * @return Distance in pixels a hover can wander while it is still considered "stationary".
732      *
733      */
getScaledHoverSlop()734     public int getScaledHoverSlop() {
735         return mHoverSlop;
736     }
737 
738     /**
739      * @return Distance in pixels the first touch can wander before we do not consider this a
740      * potential double tap event
741      * @hide
742      */
743     @UnsupportedAppUsage
getScaledDoubleTapTouchSlop()744     public int getScaledDoubleTapTouchSlop() {
745         return mDoubleTapTouchSlop;
746     }
747 
748     /**
749      * @return Distance in pixels a touch can wander before we think the user is scrolling a full
750      * page
751      */
getScaledPagingTouchSlop()752     public int getScaledPagingTouchSlop() {
753         return mPagingTouchSlop;
754     }
755 
756     /**
757      * @return Distance in dips between the first touch and second touch to still be
758      *         considered a double tap
759      * @deprecated Use {@link #getScaledDoubleTapSlop()} instead.
760      * @hide The only client of this should be GestureDetector, which needs this
761      *       for clients that still use its deprecated constructor.
762      */
763     @Deprecated
764     @UnsupportedAppUsage
getDoubleTapSlop()765     public static int getDoubleTapSlop() {
766         return DOUBLE_TAP_SLOP;
767     }
768 
769     /**
770      * @return Distance in pixels between the first touch and second touch to still be
771      *         considered a double tap
772      */
getScaledDoubleTapSlop()773     public int getScaledDoubleTapSlop() {
774         return mDoubleTapSlop;
775     }
776 
777     /**
778      * Interval for dispatching a recurring accessibility event in milliseconds.
779      * This interval guarantees that a recurring event will be send at most once
780      * during the {@link #getSendRecurringAccessibilityEventsInterval()} time frame.
781      *
782      * @return The delay in milliseconds.
783      *
784      * @hide
785      */
getSendRecurringAccessibilityEventsInterval()786     public static long getSendRecurringAccessibilityEventsInterval() {
787         return SEND_RECURRING_ACCESSIBILITY_EVENTS_INTERVAL_MILLIS;
788     }
789 
790     /**
791      * @return Distance in dips a touch must be outside the bounds of a window for it
792      * to be counted as outside the window for purposes of dismissing that
793      * window.
794      *
795      * @deprecated Use {@link #getScaledWindowTouchSlop()} instead.
796      */
797     @Deprecated
getWindowTouchSlop()798     public static int getWindowTouchSlop() {
799         return WINDOW_TOUCH_SLOP;
800     }
801 
802     /**
803      * @return Distance in pixels a touch must be outside the bounds of a window for it
804      * to be counted as outside the window for purposes of dismissing that window.
805      */
getScaledWindowTouchSlop()806     public int getScaledWindowTouchSlop() {
807         return mWindowTouchSlop;
808     }
809 
810     /**
811      * @return Minimum velocity to initiate a fling, as measured in dips per second.
812      *
813      * @deprecated Use {@link #getScaledMinimumFlingVelocity()} instead.
814      */
815     @Deprecated
getMinimumFlingVelocity()816     public static int getMinimumFlingVelocity() {
817         return MINIMUM_FLING_VELOCITY;
818     }
819 
820     /**
821      * @return Minimum velocity to initiate a fling, as measured in pixels per second.
822      */
getScaledMinimumFlingVelocity()823     public int getScaledMinimumFlingVelocity() {
824         return mMinimumFlingVelocity;
825     }
826 
827     /**
828      * @return Maximum velocity to initiate a fling, as measured in dips per second.
829      *
830      * @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
831      */
832     @Deprecated
getMaximumFlingVelocity()833     public static int getMaximumFlingVelocity() {
834         return MAXIMUM_FLING_VELOCITY;
835     }
836 
837     /**
838      * @return Maximum velocity to initiate a fling, as measured in pixels per second.
839      */
getScaledMaximumFlingVelocity()840     public int getScaledMaximumFlingVelocity() {
841         return mMaximumFlingVelocity;
842     }
843 
844     /**
845      * @return Amount to scroll in response to a {@link MotionEvent#ACTION_SCROLL} event. Multiply
846      * this by the event's axis value to obtain the number of pixels to be scrolled.
847      *
848      * @removed
849      */
getScaledScrollFactor()850     public int getScaledScrollFactor() {
851         return (int) mVerticalScrollFactor;
852     }
853 
854     /**
855      * @return Amount to scroll in response to a horizontal {@link MotionEvent#ACTION_SCROLL} event.
856      * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
857      */
getScaledHorizontalScrollFactor()858     public float getScaledHorizontalScrollFactor() {
859         return mHorizontalScrollFactor;
860     }
861 
862     /**
863      * @return Amount to scroll in response to a vertical {@link MotionEvent#ACTION_SCROLL} event.
864      * Multiply this by the event's axis value to obtain the number of pixels to be scrolled.
865      */
getScaledVerticalScrollFactor()866     public float getScaledVerticalScrollFactor() {
867         return mVerticalScrollFactor;
868     }
869 
870     /**
871      * The maximum drawing cache size expressed in bytes.
872      *
873      * @return the maximum size of View's drawing cache expressed in bytes
874      *
875      * @deprecated Use {@link #getScaledMaximumDrawingCacheSize()} instead.
876      */
877     @Deprecated
getMaximumDrawingCacheSize()878     public static int getMaximumDrawingCacheSize() {
879         //noinspection deprecation
880         return MAXIMUM_DRAWING_CACHE_SIZE;
881     }
882 
883     /**
884      * The maximum drawing cache size expressed in bytes.
885      *
886      * @return the maximum size of View's drawing cache expressed in bytes
887      */
getScaledMaximumDrawingCacheSize()888     public int getScaledMaximumDrawingCacheSize() {
889         return mMaximumDrawingCacheSize;
890     }
891 
892     /**
893      * @return The maximum distance a View should overscroll by when showing edge effects (in
894      * pixels).
895      */
getScaledOverscrollDistance()896     public int getScaledOverscrollDistance() {
897         return mOverscrollDistance;
898     }
899 
900     /**
901      * @return The maximum distance a View should overfling by when showing edge effects (in
902      * pixels).
903      */
getScaledOverflingDistance()904     public int getScaledOverflingDistance() {
905         return mOverflingDistance;
906     }
907 
908     /**
909      * The amount of time that the zoom controls should be
910      * displayed on the screen expressed in milliseconds.
911      *
912      * @return the time the zoom controls should be visible expressed
913      * in milliseconds.
914      */
getZoomControlsTimeout()915     public static long getZoomControlsTimeout() {
916         return ZOOM_CONTROLS_TIMEOUT;
917     }
918 
919     /**
920      * The amount of time a user needs to press the relevant key to bring up
921      * the global actions dialog.
922      *
923      * @return how long a user needs to press the relevant key to bring up
924      *   the global actions dialog.
925      * @deprecated This timeout should not be used by applications
926      */
927     @Deprecated
getGlobalActionKeyTimeout()928     public static long getGlobalActionKeyTimeout() {
929         return GLOBAL_ACTIONS_KEY_TIMEOUT;
930     }
931 
932     /**
933      * The amount of time a user needs to press the relevant key to bring up
934      * the global actions dialog.
935      *
936      * @return how long a user needs to press the relevant key to bring up
937      *   the global actions dialog.
938      * @hide
939      */
940     @TestApi
getDeviceGlobalActionKeyTimeout()941     public long getDeviceGlobalActionKeyTimeout() {
942         return mGlobalActionsKeyTimeout;
943     }
944 
945     /**
946      * The amount of time a user needs to press the relevant keys to trigger
947      * the screenshot chord.
948      *
949      * @return how long a user needs to press the relevant keys to trigger
950      *   the screenshot chord.
951      * @hide
952      */
getScreenshotChordKeyTimeout()953     public long getScreenshotChordKeyTimeout() {
954         return mScreenshotChordKeyTimeout;
955     }
956 
957     /**
958      * The amount of time a user needs to press the relevant keys to activate the accessibility
959      * shortcut.
960      *
961      * @return how long a user needs to press the relevant keys to activate the accessibility
962      *   shortcut.
963      * @hide
964      */
getAccessibilityShortcutKeyTimeout()965     public long getAccessibilityShortcutKeyTimeout() {
966         return A11Y_SHORTCUT_KEY_TIMEOUT;
967     }
968 
969     /**
970      * @return The amount of time a user needs to press the relevant keys to activate the
971      *   accessibility shortcut after it's confirmed that accessibility shortcut is used.
972      * @hide
973      */
getAccessibilityShortcutKeyTimeoutAfterConfirmation()974     public long getAccessibilityShortcutKeyTimeoutAfterConfirmation() {
975         return A11Y_SHORTCUT_KEY_TIMEOUT_AFTER_CONFIRMATION;
976     }
977 
978     /**
979      * The amount of friction applied to scrolls and flings.
980      *
981      * @return A scalar dimensionless value representing the coefficient of
982      *         friction.
983      */
getScrollFriction()984     public static float getScrollFriction() {
985         return SCROLL_FRICTION;
986     }
987 
988     /**
989      * @return the default duration in milliseconds for {@link ActionMode#hide(long)}.
990      */
getDefaultActionModeHideDuration()991     public static long getDefaultActionModeHideDuration() {
992         return ACTION_MODE_HIDE_DURATION_DEFAULT;
993     }
994 
995     /**
996      * The multiplication factor for inhibiting default gestures.
997      *
998      * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set,
999      * then certain actions, such as scrolling, will be inhibited. However, to account for the
1000      * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling
1001      * touch slop and the long-press timeout) should be scaled by this factor and remain in effect.
1002      *
1003      * @deprecated Use {@link #getScaledAmbiguousGestureMultiplier()}.
1004      */
1005     @Deprecated
1006     @FloatRange(from = 1.0)
getAmbiguousGestureMultiplier()1007     public static float getAmbiguousGestureMultiplier() {
1008         return AMBIGUOUS_GESTURE_MULTIPLIER;
1009     }
1010 
1011     /**
1012      * The multiplication factor for inhibiting default gestures.
1013      *
1014      * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set,
1015      * then certain actions, such as scrolling, will be inhibited. However, to account for the
1016      * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling
1017      * touch slop and the long-press timeout) should be scaled by this factor and remain in effect.
1018      */
1019     @FloatRange(from = 1.0)
getScaledAmbiguousGestureMultiplier()1020     public float getScaledAmbiguousGestureMultiplier() {
1021         return mAmbiguousGestureMultiplier;
1022     }
1023 
1024     /**
1025      * Report if the device has a permanent menu key available to the user.
1026      *
1027      * <p>As of Android 3.0, devices may not have a permanent menu key available.
1028      * Apps should use the action bar to present menu options to users.
1029      * However, there are some apps where the action bar is inappropriate
1030      * or undesirable. This method may be used to detect if a menu key is present.
1031      * If not, applications should provide another on-screen affordance to access
1032      * functionality.
1033      *
1034      * @return true if a permanent menu key is present, false otherwise.
1035      */
hasPermanentMenuKey()1036     public boolean hasPermanentMenuKey() {
1037         return sHasPermanentMenuKey;
1038     }
1039 
1040     /**
1041      * Check if shortcuts should be displayed in menus.
1042      *
1043      * @return {@code True} if shortcuts should be displayed in menus.
1044      */
shouldShowMenuShortcutsWhenKeyboardPresent()1045     public boolean shouldShowMenuShortcutsWhenKeyboardPresent() {
1046         return mShowMenuShortcutsWhenKeyboardPresent;
1047     }
1048 
1049     /**
1050      * Retrieves the distance in pixels between touches that must be reached for a gesture to be
1051      * interpreted as scaling.
1052      *
1053      * In general, scaling shouldn't start until this distance has been met or surpassed, and
1054      * scaling should end when the distance in pixels between touches drops below this distance.
1055      *
1056      * @return The distance in pixels
1057      * @throws IllegalStateException if this method is called on a ViewConfiguration that was
1058      *         instantiated using a constructor with no Context parameter.
1059      */
getScaledMinimumScalingSpan()1060     public int getScaledMinimumScalingSpan() {
1061         if (!mConstructedWithContext) {
1062             throw new IllegalStateException("Min scaling span cannot be determined when this "
1063                     + "method is called on a ViewConfiguration that was instantiated using a "
1064                     + "constructor with no Context parameter");
1065         }
1066         return mMinScalingSpan;
1067     }
1068 
1069     /**
1070      * @hide
1071      * @return Whether or not marquee should use fading edges.
1072      */
1073     @UnsupportedAppUsage
isFadingMarqueeEnabled()1074     public boolean isFadingMarqueeEnabled() {
1075         return mFadingMarqueeEnabled;
1076     }
1077 
1078     /**
1079      * @return the timeout value in milliseconds to adjust the selection span and actions for the
1080      *         selected text when TextClassifier has been initialized.
1081      * @hide
1082      */
getSmartSelectionInitializedTimeout()1083     public int getSmartSelectionInitializedTimeout() {
1084         return mSmartSelectionInitializedTimeout;
1085     }
1086 
1087     /**
1088      * @return the timeout value in milliseconds to adjust the selection span and actions for the
1089      *         selected text when TextClassifier has not been initialized.
1090      * @hide
1091      */
getSmartSelectionInitializingTimeout()1092     public int getSmartSelectionInitializingTimeout() {
1093         return mSmartSelectionInitializingTimeout;
1094     }
1095 
1096     /**
1097      * @return the duration in milliseconds before an end of a long press causes a tooltip to be
1098      * hidden
1099      * @hide
1100      */
1101     @TestApi
getLongPressTooltipHideTimeout()1102     public static int getLongPressTooltipHideTimeout() {
1103         return LONG_PRESS_TOOLTIP_HIDE_TIMEOUT;
1104     }
1105 
1106     /**
1107      * @return the duration in milliseconds before a hover event causes a tooltip to be shown
1108      * @hide
1109      */
1110     @TestApi
getHoverTooltipShowTimeout()1111     public static int getHoverTooltipShowTimeout() {
1112         return HOVER_TOOLTIP_SHOW_TIMEOUT;
1113     }
1114 
1115     /**
1116      * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1117      * (default variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is not set).
1118      * @hide
1119      */
1120     @TestApi
getHoverTooltipHideTimeout()1121     public static int getHoverTooltipHideTimeout() {
1122         return HOVER_TOOLTIP_HIDE_TIMEOUT;
1123     }
1124 
1125     /**
1126      * @return the duration in milliseconds before mouse inactivity causes a tooltip to be hidden
1127      * (shorter variant to be used when {@link View#SYSTEM_UI_FLAG_LOW_PROFILE} is set).
1128      * @hide
1129      */
1130     @TestApi
getHoverTooltipHideShortTimeout()1131     public static int getHoverTooltipHideShortTimeout() {
1132         return HOVER_TOOLTIP_HIDE_SHORT_TIMEOUT;
1133     }
1134 }
1135