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