ViewConfiguration.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
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 17package android.view; 18 19/** 20 * Contains methods to standard constants used in the UI for timeouts, sizes, and distances. 21 * 22 */ 23public class ViewConfiguration { 24 25 /** 26 * Defines the width of the horizontal scrollbar and the height of the vertical scrollbar in 27 * pixels 28 */ 29 private static final int SCROLL_BAR_SIZE = 6; 30 31 /** 32 * Defines the length of the fading edges in pixels 33 */ 34 private static final int FADING_EDGE_LENGTH = 12; 35 36 /** 37 * Defines the duration in milliseconds of the pressed state in child 38 * components. 39 */ 40 private static final int PRESSED_STATE_DURATION = 85; 41 42 /** 43 * Defines the duration in milliseconds before a press turns into 44 * a long press 45 */ 46 private static final int LONG_PRESS_TIMEOUT = 500; 47 48 /** 49 * Defines the duration in milliseconds we will wait to see if a touch event 50 * is a top or a scroll. If the user does not move within this interval, it is 51 * considered to be a tap. 52 */ 53 private static final int TAP_TIMEOUT = 100; 54 55 /** 56 * Defines the duration in milliseconds we will wait to see if a touch event 57 * is a jump tap. If the user does not complete the jump tap within this interval, it is 58 * considered to be a tap. 59 */ 60 private static final int JUMP_TAP_TIMEOUT = 500; 61 62 /** 63 * Defines the duration in milliseconds we want to display zoom controls in response 64 * to a user panning within an application. 65 */ 66 private static final int ZOOM_CONTROLS_TIMEOUT = 3000; 67 68 /** 69 * Defines the duration in milliseconds a user needs to hold down the 70 * appropriate button to bring up the global actions dialog (power off, 71 * lock screen, etc). 72 */ 73 private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 1000; 74 75 76 /** 77 * Inset in pixels to look for touchable content when the user touches the edge of the screen 78 */ 79 private static final int EDGE_SLOP = 12; 80 81 /** 82 * Distance a touch can wander before we think the user is scrolling in pixels 83 */ 84 private static final int TOUCH_SLOP = 12; 85 86 /** 87 * Distance a touch needs to be outside of a window's bounds for it to 88 * count as outside for purposes of dismissing the window. 89 */ 90 private static final int WINDOW_TOUCH_SLOP = 16; 91 92 /** 93 * Minimum velocity to initiate a fling, as measured in pixels per second 94 */ 95 private static final int MINIMUM_FLING_VELOCITY = 50; 96 97 /** 98 * The maximum size of View's drawing cache, expressed in bytes. This size 99 * should be at least equal to the size of the screen in ARGB888 format. 100 */ 101 private static final int MAXIMUM_DRAWING_CACHE_SIZE = 320 * 480 * 4; // One HVGA screen, ARGB8888 102 103 /** 104 * The coefficient of friction applied to flings/scrolls. 105 */ 106 private static float SCROLL_FRICTION = 0.015f; 107 108 /** 109 * @return The width of the horizontal scrollbar and the height of the vertical 110 * scrollbar in pixels 111 */ 112 public static int getScrollBarSize() { 113 return SCROLL_BAR_SIZE; 114 } 115 116 /** 117 * @return Defines the length of the fading edges in pixels 118 */ 119 public static int getFadingEdgeLength() { 120 return FADING_EDGE_LENGTH; 121 } 122 123 /** 124 * @return Defines the duration in milliseconds of the pressed state in child 125 * components. 126 */ 127 public static int getPressedStateDuration() { 128 return PRESSED_STATE_DURATION; 129 } 130 131 /** 132 * @return Defines the duration in milliseconds before a press turns into 133 * a long press 134 */ 135 public static int getLongPressTimeout() { 136 return LONG_PRESS_TIMEOUT; 137 } 138 139 /** 140 * @return Defines the duration in milliseconds we will wait to see if a touch event 141 * is a top or a scroll. If the user does not move within this interval, it is 142 * considered to be a tap. 143 */ 144 public static int getTapTimeout() { 145 return TAP_TIMEOUT; 146 } 147 148 /** 149 * @return Defines the duration in milliseconds we will wait to see if a touch event 150 * is a jump tap. If the user does not move within this interval, it is 151 * considered to be a tap. 152 */ 153 public static int getJumpTapTimeout() { 154 return JUMP_TAP_TIMEOUT; 155 } 156 157 /** 158 * @return Inset in pixels to look for touchable content when the user touches the edge of the 159 * screen 160 */ 161 public static int getEdgeSlop() { 162 return EDGE_SLOP; 163 } 164 165 /** 166 * @return Distance a touch can wander before we think the user is scrolling in pixels 167 */ 168 public static int getTouchSlop() { 169 return TOUCH_SLOP; 170 } 171 172 /** 173 * @return Distance a touch must be outside the bounds of a window for it 174 * to be counted as outside the window for purposes of dismissing that 175 * window. 176 */ 177 public static int getWindowTouchSlop() { 178 return WINDOW_TOUCH_SLOP; 179 } 180 181 /** 182 * Minimum velocity to initiate a fling, as measured in pixels per second 183 */ 184 public static int getMinimumFlingVelocity() { 185 return MINIMUM_FLING_VELOCITY; 186 } 187 188 /** 189 * The maximum drawing cache size expressed in bytes. 190 * 191 * @return the maximum size of View's drawing cache expressed in bytes 192 */ 193 public static int getMaximumDrawingCacheSize() { 194 return MAXIMUM_DRAWING_CACHE_SIZE; 195 } 196 197 /** 198 * The amount of time that the zoom controls should be 199 * displayed on the screen expressed in milliseconds. 200 * 201 * @return the time the zoom controls should be visible expressed 202 * in milliseconds. 203 */ 204 public static long getZoomControlsTimeout() { 205 return ZOOM_CONTROLS_TIMEOUT; 206 } 207 208 /** 209 * The amount of time a user needs to press the relevant key to bring up 210 * the global actions dialog. 211 * 212 * @return how long a user needs to press the relevant key to bring up 213 * the global actions dialog. 214 */ 215 public static long getGlobalActionKeyTimeout() { 216 return GLOBAL_ACTIONS_KEY_TIMEOUT; 217 } 218 219 /** 220 * The amount of friction applied to scrolls and flings. 221 * 222 * @return A scalar dimensionless value representing the coefficient of 223 * friction. 224 */ 225 public static float getScrollFriction() { 226 return SCROLL_FRICTION; 227 } 228} 229