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