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