The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 19 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.res.Resources; |
| 23 | import android.content.res.TypedArray; |
| 24 | import android.graphics.Bitmap; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 25 | import android.graphics.Camera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 27 | import android.graphics.Insets; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 28 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.graphics.LinearGradient; |
| 30 | import android.graphics.Matrix; |
| 31 | import android.graphics.Paint; |
| 32 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 33 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.graphics.PorterDuff; |
| 35 | import android.graphics.PorterDuffXfermode; |
| 36 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 37 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.graphics.Region; |
| 39 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.graphics.drawable.ColorDrawable; |
| 41 | import android.graphics.drawable.Drawable; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.os.Handler; |
| 44 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Parcel; |
| 46 | import android.os.Parcelable; |
| 47 | import android.os.RemoteException; |
| 48 | import android.os.SystemClock; |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 49 | import android.os.SystemProperties; |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 50 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 52 | import android.util.FloatProperty; |
| 53 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 55 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 56 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 57 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 58 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 59 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 60 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 61 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.view.ContextMenu.ContextMenuInfo; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 63 | import android.view.accessibility.AccessibilityEvent; |
| 64 | import android.view.accessibility.AccessibilityEventSource; |
| 65 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 66 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 67 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 69 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 70 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 71 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.view.inputmethod.InputConnection; |
| 73 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.widget.ScrollBarDrawable; |
| 75 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 76 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 77 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 78 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 79 | import com.android.internal.R; |
| 80 | import com.android.internal.util.Predicate; |
| 81 | import com.android.internal.view.menu.MenuBuilder; |
| 82 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 83 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 84 | import java.lang.reflect.InvocationTargetException; |
| 85 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import java.util.ArrayList; |
| 87 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 88 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 89 | import java.util.concurrent.CopyOnWriteArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * <p> |
| 93 | * This class represents the basic building block for user interface components. A View |
| 94 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 95 | * event handling. View is the base class for <em>widgets</em>, which are |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 96 | * used to create interactive UI components (buttons, text fields, etc.). The |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 98 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 99 | * their layout properties. |
| 100 | * </p> |
| 101 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 102 | * <div class="special reference"> |
| 103 | * <h3>Developer Guides</h3> |
| 104 | * <p>For information about using this class to develop your application's user interface, |
| 105 | * read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> developer guide. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 107 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | * <a name="Using"></a> |
| 109 | * <h3>Using Views</h3> |
| 110 | * <p> |
| 111 | * All of the views in a window are arranged in a single tree. You can add views |
| 112 | * either from code or by specifying a tree of views in one or more XML layout |
| 113 | * files. There are many specialized subclasses of views that act as controls or |
| 114 | * are capable of displaying text, images, or other content. |
| 115 | * </p> |
| 116 | * <p> |
| 117 | * Once you have created a tree of views, there are typically a few types of |
| 118 | * common operations you may wish to perform: |
| 119 | * <ul> |
| 120 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 121 | * {@link android.widget.TextView}. The available properties and the methods |
| 122 | * that set them will vary among the different subclasses of views. Note that |
| 123 | * properties that are known at build time can be set in the XML layout |
| 124 | * files.</li> |
| 125 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 126 | * response to user input. To force focus to a specific view, call |
| 127 | * {@link #requestFocus}.</li> |
| 128 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 129 | * that will be notified when something interesting happens to the view. For |
| 130 | * example, all views will let you set a listener to be notified when the view |
| 131 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 132 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 133 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 134 | * exposes a listener to notify clients when the button is clicked.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 136 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | * </ul> |
| 138 | * </p> |
| 139 | * <p><em> |
| 140 | * Note: The Android framework is responsible for measuring, laying out and |
| 141 | * drawing views. You should not call methods that perform these actions on |
| 142 | * views yourself unless you are actually implementing a |
| 143 | * {@link android.view.ViewGroup}. |
| 144 | * </em></p> |
| 145 | * |
| 146 | * <a name="Lifecycle"></a> |
| 147 | * <h3>Implementing a Custom View</h3> |
| 148 | * |
| 149 | * <p> |
| 150 | * To implement a custom view, you will usually begin by providing overrides for |
| 151 | * some of the standard methods that the framework calls on all views. You do |
| 152 | * not need to override all of these methods. In fact, you can start by just |
| 153 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 154 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 155 | * <thead> |
| 156 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 157 | * </thead> |
| 158 | * |
| 159 | * <tbody> |
| 160 | * <tr> |
| 161 | * <td rowspan="2">Creation</td> |
| 162 | * <td>Constructors</td> |
| 163 | * <td>There is a form of the constructor that are called when the view |
| 164 | * is created from code and a form that is called when the view is |
| 165 | * inflated from a layout file. The second form should parse and apply |
| 166 | * any attributes defined in the layout file. |
| 167 | * </td> |
| 168 | * </tr> |
| 169 | * <tr> |
| 170 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 171 | * <td>Called after a view and all of its children has been inflated |
| 172 | * from XML.</td> |
| 173 | * </tr> |
| 174 | * |
| 175 | * <tr> |
| 176 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 177 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | * <td>Called to determine the size requirements for this view and all |
| 179 | * of its children. |
| 180 | * </td> |
| 181 | * </tr> |
| 182 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 183 | * <td><code>{@link #onLayout(boolean, int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | * <td>Called when this view should assign a size and position to all |
| 185 | * of its children. |
| 186 | * </td> |
| 187 | * </tr> |
| 188 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 189 | * <td><code>{@link #onSizeChanged(int, int, int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | * <td>Called when the size of this view has changed. |
| 191 | * </td> |
| 192 | * </tr> |
| 193 | * |
| 194 | * <tr> |
| 195 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 196 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | * <td>Called when the view should render its content. |
| 198 | * </td> |
| 199 | * </tr> |
| 200 | * |
| 201 | * <tr> |
| 202 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 203 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | * <td>Called when a new key event occurs. |
| 205 | * </td> |
| 206 | * </tr> |
| 207 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 208 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | * <td>Called when a key up event occurs. |
| 210 | * </td> |
| 211 | * </tr> |
| 212 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 213 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | * <td>Called when a trackball motion event occurs. |
| 215 | * </td> |
| 216 | * </tr> |
| 217 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 218 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | * <td>Called when a touch screen motion event occurs. |
| 220 | * </td> |
| 221 | * </tr> |
| 222 | * |
| 223 | * <tr> |
| 224 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 225 | * <td><code>{@link #onFocusChanged(boolean, int, android.graphics.Rect)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | * <td>Called when the view gains or loses focus. |
| 227 | * </td> |
| 228 | * </tr> |
| 229 | * |
| 230 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 231 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | * <td>Called when the window containing the view gains or loses focus. |
| 233 | * </td> |
| 234 | * </tr> |
| 235 | * |
| 236 | * <tr> |
| 237 | * <td rowspan="3">Attaching</td> |
| 238 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 239 | * <td>Called when the view is attached to a window. |
| 240 | * </td> |
| 241 | * </tr> |
| 242 | * |
| 243 | * <tr> |
| 244 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 245 | * <td>Called when the view is detached from its window. |
| 246 | * </td> |
| 247 | * </tr> |
| 248 | * |
| 249 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 250 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | * <td>Called when the visibility of the window containing the view |
| 252 | * has changed. |
| 253 | * </td> |
| 254 | * </tr> |
| 255 | * </tbody> |
| 256 | * |
| 257 | * </table> |
| 258 | * </p> |
| 259 | * |
| 260 | * <a name="IDs"></a> |
| 261 | * <h3>IDs</h3> |
| 262 | * Views may have an integer id associated with them. These ids are typically |
| 263 | * assigned in the layout XML files, and are used to find specific views within |
| 264 | * the view tree. A common pattern is to: |
| 265 | * <ul> |
| 266 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 267 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 268 | * <Button |
| 269 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | * android:layout_width="wrap_content" |
| 271 | * android:layout_height="wrap_content" |
| 272 | * android:text="@string/my_button_text"/> |
| 273 | * </pre></li> |
| 274 | * <li>From the onCreate method of an Activity, find the Button |
| 275 | * <pre class="prettyprint"> |
| 276 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 277 | * </pre></li> |
| 278 | * </ul> |
| 279 | * <p> |
| 280 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 281 | * ensure that they are at least unique within the part of the tree you are |
| 282 | * searching. |
| 283 | * </p> |
| 284 | * |
| 285 | * <a name="Position"></a> |
| 286 | * <h3>Position</h3> |
| 287 | * <p> |
| 288 | * The geometry of a view is that of a rectangle. A view has a location, |
| 289 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 290 | * two dimensions, expressed as a width and a height. The unit for location |
| 291 | * and dimensions is the pixel. |
| 292 | * </p> |
| 293 | * |
| 294 | * <p> |
| 295 | * It is possible to retrieve the location of a view by invoking the methods |
| 296 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 297 | * coordinate of the rectangle representing the view. The latter returns the |
| 298 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 299 | * both return the location of the view relative to its parent. For instance, |
| 300 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 301 | * right of the left edge of its direct parent. |
| 302 | * </p> |
| 303 | * |
| 304 | * <p> |
| 305 | * In addition, several convenience methods are offered to avoid unnecessary |
| 306 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 307 | * These methods return the coordinates of the right and bottom edges of the |
| 308 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 309 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 310 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 311 | * </p> |
| 312 | * |
| 313 | * <a name="SizePaddingMargins"></a> |
| 314 | * <h3>Size, padding and margins</h3> |
| 315 | * <p> |
| 316 | * The size of a view is expressed with a width and a height. A view actually |
| 317 | * possess two pairs of width and height values. |
| 318 | * </p> |
| 319 | * |
| 320 | * <p> |
| 321 | * The first pair is known as <em>measured width</em> and |
| 322 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 323 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 324 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 325 | * and {@link #getMeasuredHeight()}. |
| 326 | * </p> |
| 327 | * |
| 328 | * <p> |
| 329 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 330 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 331 | * dimensions define the actual size of the view on screen, at drawing time and |
| 332 | * after layout. These values may, but do not have to, be different from the |
| 333 | * measured width and height. The width and height can be obtained by calling |
| 334 | * {@link #getWidth()} and {@link #getHeight()}. |
| 335 | * </p> |
| 336 | * |
| 337 | * <p> |
| 338 | * To measure its dimensions, a view takes into account its padding. The padding |
| 339 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 340 | * Padding can be used to offset the content of the view by a specific amount of |
| 341 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 342 | * 2 pixels to the right of the left edge. Padding can be set using the |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 343 | * {@link #setPadding(int, int, int, int)} method and queried by calling |
| 344 | * {@link #getPaddingLeft()}, {@link #getPaddingTop()}, {@link #getPaddingRight()}, |
| 345 | * {@link #getPaddingBottom()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | * </p> |
| 347 | * |
| 348 | * <p> |
| 349 | * Even though a view can define a padding, it does not provide any support for |
| 350 | * margins. However, view groups provide such a support. Refer to |
| 351 | * {@link android.view.ViewGroup} and |
| 352 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 353 | * </p> |
| 354 | * |
| 355 | * <a name="Layout"></a> |
| 356 | * <h3>Layout</h3> |
| 357 | * <p> |
| 358 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 359 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 360 | * of the view tree. Each view pushes dimension specifications down the tree |
| 361 | * during the recursion. At the end of the measure pass, every view has stored |
| 362 | * its measurements. The second pass happens in |
| 363 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 364 | * this pass each parent is responsible for positioning all of its children |
| 365 | * using the sizes computed in the measure pass. |
| 366 | * </p> |
| 367 | * |
| 368 | * <p> |
| 369 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 370 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 371 | * that view's descendants. A view's measured width and measured height values |
| 372 | * must respect the constraints imposed by the view's parents. This guarantees |
| 373 | * that at the end of the measure pass, all parents accept all of their |
| 374 | * children's measurements. A parent view may call measure() more than once on |
| 375 | * its children. For example, the parent may measure each child once with |
| 376 | * unspecified dimensions to find out how big they want to be, then call |
| 377 | * measure() on them again with actual numbers if the sum of all the children's |
| 378 | * unconstrained sizes is too big or too small. |
| 379 | * </p> |
| 380 | * |
| 381 | * <p> |
| 382 | * The measure pass uses two classes to communicate dimensions. The |
| 383 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 384 | * want to be measured and positioned. The base LayoutParams class just |
| 385 | * describes how big the view wants to be for both width and height. For each |
| 386 | * dimension, it can specify one of: |
| 387 | * <ul> |
| 388 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 389 | * <li>MATCH_PARENT, which means the view wants to be as big as its parent |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | * (minus padding) |
| 391 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 392 | * enclose its content (plus padding). |
| 393 | * </ul> |
| 394 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 395 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 396 | * an X and Y value. |
| 397 | * </p> |
| 398 | * |
| 399 | * <p> |
| 400 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 401 | * child. A MeasureSpec can be in one of three modes: |
| 402 | * <ul> |
| 403 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 404 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 405 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 406 | * tall the child view wants to be given a width of 240 pixels. |
| 407 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 408 | * child. The child must use this size, and guarantee that all of its |
| 409 | * descendants will fit within this size. |
| 410 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 411 | * child. The child must gurantee that it and all of its descendants will fit |
| 412 | * within this size. |
| 413 | * </ul> |
| 414 | * </p> |
| 415 | * |
| 416 | * <p> |
| 417 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 418 | * called by a view on itself when it believes that is can no longer fit within |
| 419 | * its current bounds. |
| 420 | * </p> |
| 421 | * |
| 422 | * <a name="Drawing"></a> |
| 423 | * <h3>Drawing</h3> |
| 424 | * <p> |
| 425 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 426 | * intersects the invalid region. Because the tree is traversed in-order, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | * this means that parents will draw before (i.e., behind) their children, with |
| 428 | * siblings drawn in the order they appear in the tree. |
| 429 | * If you set a background drawable for a View, then the View will draw it for you |
| 430 | * before calling back to its <code>onDraw()</code> method. |
| 431 | * </p> |
| 432 | * |
| 433 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 434 | * Note that the framework will not draw views that are not in the invalid region. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | * </p> |
| 436 | * |
| 437 | * <p> |
| 438 | * To force a view to draw, call {@link #invalidate()}. |
| 439 | * </p> |
| 440 | * |
| 441 | * <a name="EventHandlingThreading"></a> |
| 442 | * <h3>Event Handling and Threading</h3> |
| 443 | * <p> |
| 444 | * The basic cycle of a view is as follows: |
| 445 | * <ol> |
| 446 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 447 | * handles the event and notifies any listeners.</li> |
| 448 | * <li>If in the course of processing the event, the view's bounds may need |
| 449 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 450 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 451 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 452 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 453 | * the framework will take care of measuring, laying out, and drawing the tree |
| 454 | * as appropriate.</li> |
| 455 | * </ol> |
| 456 | * </p> |
| 457 | * |
| 458 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 459 | * the UI thread when calling any method on any view.</em> |
| 460 | * If you are doing work on other threads and want to update the state of a view |
| 461 | * from that thread, you should use a {@link Handler}. |
| 462 | * </p> |
| 463 | * |
| 464 | * <a name="FocusHandling"></a> |
| 465 | * <h3>Focus Handling</h3> |
| 466 | * <p> |
| 467 | * The framework will handle routine focus movement in response to user input. |
| 468 | * This includes changing the focus as views are removed or hidden, or as new |
| 469 | * views become available. Views indicate their willingness to take focus |
| 470 | * through the {@link #isFocusable} method. To change whether a view can take |
| 471 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 472 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 473 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 474 | * </p> |
| 475 | * <p> |
| 476 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 477 | * given direction. In rare cases, the default algorithm may not match the |
| 478 | * intended behavior of the developer. In these situations, you can provide |
| 479 | * explicit overrides by using these XML attributes in the layout file: |
| 480 | * <pre> |
| 481 | * nextFocusDown |
| 482 | * nextFocusLeft |
| 483 | * nextFocusRight |
| 484 | * nextFocusUp |
| 485 | * </pre> |
| 486 | * </p> |
| 487 | * |
| 488 | * |
| 489 | * <p> |
| 490 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 491 | * </p> |
| 492 | * |
| 493 | * <a name="TouchMode"></a> |
| 494 | * <h3>Touch Mode</h3> |
| 495 | * <p> |
| 496 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 497 | * necessary to give focus to actionable items such as buttons so the user can see |
| 498 | * what will take input. If the device has touch capabilities, however, and the user |
| 499 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 500 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 501 | * for interaction named 'touch mode'. |
| 502 | * </p> |
| 503 | * <p> |
| 504 | * For a touch capable device, once the user touches the screen, the device |
| 505 | * will enter touch mode. From this point onward, only views for which |
| 506 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 507 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 508 | * only fire the on click listeners. |
| 509 | * </p> |
| 510 | * <p> |
| 511 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 512 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 513 | * with the user interface without touching the screen again. |
| 514 | * </p> |
| 515 | * <p> |
| 516 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 517 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 518 | * </p> |
| 519 | * |
| 520 | * <a name="Scrolling"></a> |
| 521 | * <h3>Scrolling</h3> |
| 522 | * <p> |
| 523 | * The framework provides basic support for views that wish to internally |
| 524 | * scroll their content. This includes keeping track of the X and Y scroll |
| 525 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 526 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 527 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | * </p> |
| 529 | * |
| 530 | * <a name="Tags"></a> |
| 531 | * <h3>Tags</h3> |
| 532 | * <p> |
| 533 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 534 | * extra piece of information that can be associated with a view. They are most |
| 535 | * often used as a convenience to store data related to views in the views |
| 536 | * themselves rather than by putting them in a separate structure. |
| 537 | * </p> |
| 538 | * |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 539 | * <a name="Properties"></a> |
| 540 | * <h3>Properties</h3> |
| 541 | * <p> |
| 542 | * The View class exposes an {@link #ALPHA} property, as well as several transform-related |
| 543 | * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are |
| 544 | * available both in the {@link Property} form as well as in similarly-named setter/getter |
| 545 | * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can |
| 546 | * be used to set persistent state associated with these rendering-related properties on the view. |
| 547 | * The properties and methods can also be used in conjunction with |
| 548 | * {@link android.animation.Animator Animator}-based animations, described more in the |
| 549 | * <a href="#Animation">Animation</a> section. |
| 550 | * </p> |
| 551 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | * <a name="Animation"></a> |
| 553 | * <h3>Animation</h3> |
| 554 | * <p> |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 555 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 556 | * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based |
| 557 | * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and |
| 558 | * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 |
| 559 | * {@link android.view.animation.Animation Animation}-based classes, which instead animate only |
| 560 | * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class |
| 561 | * makes animating these View properties particularly easy and efficient. |
| 562 | * </p> |
| 563 | * <p> |
| 564 | * Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | * You can attach an {@link Animation} object to a view using |
| 566 | * {@link #setAnimation(Animation)} or |
| 567 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 568 | * rotation, translation and alpha of a view over time. If the animation is |
| 569 | * attached to a view that has children, the animation will affect the entire |
| 570 | * subtree rooted by that node. When an animation is started, the framework will |
| 571 | * take care of redrawing the appropriate views until the animation completes. |
| 572 | * </p> |
| 573 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 574 | * <a name="Security"></a> |
| 575 | * <h3>Security</h3> |
| 576 | * <p> |
| 577 | * Sometimes it is essential that an application be able to verify that an action |
| 578 | * is being performed with the full knowledge and consent of the user, such as |
| 579 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 580 | * Unfortunately, a malicious application could try to spoof the user into |
| 581 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 582 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 583 | * improve the security of views that provide access to sensitive functionality. |
| 584 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 585 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 586 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 587 | * will discard touches that are received whenever the view's window is obscured by |
| 588 | * another visible window. As a result, the view will not receive touches whenever a |
| 589 | * toast, dialog or other window appears above the view's window. |
| 590 | * </p><p> |
| 591 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 592 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 593 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 594 | * </p> |
| 595 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 596 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 597 | * @attr ref android.R.styleable#View_background |
| 598 | * @attr ref android.R.styleable#View_clickable |
| 599 | * @attr ref android.R.styleable#View_contentDescription |
| 600 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 601 | * @attr ref android.R.styleable#View_duplicateParentState |
| 602 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 603 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 604 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 605 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 606 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 608 | * @attr ref android.R.styleable#View_isScrollContainer |
| 609 | * @attr ref android.R.styleable#View_focusable |
| 610 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 611 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 612 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 613 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_longClickable |
| 615 | * @attr ref android.R.styleable#View_minHeight |
| 616 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_nextFocusDown |
| 618 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 619 | * @attr ref android.R.styleable#View_nextFocusRight |
| 620 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 621 | * @attr ref android.R.styleable#View_onClick |
| 622 | * @attr ref android.R.styleable#View_padding |
| 623 | * @attr ref android.R.styleable#View_paddingBottom |
| 624 | * @attr ref android.R.styleable#View_paddingLeft |
| 625 | * @attr ref android.R.styleable#View_paddingRight |
| 626 | * @attr ref android.R.styleable#View_paddingTop |
| 627 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 628 | * @attr ref android.R.styleable#View_rotation |
| 629 | * @attr ref android.R.styleable#View_rotationX |
| 630 | * @attr ref android.R.styleable#View_rotationY |
| 631 | * @attr ref android.R.styleable#View_scaleX |
| 632 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | * @attr ref android.R.styleable#View_scrollX |
| 634 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 635 | * @attr ref android.R.styleable#View_scrollbarSize |
| 636 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 637 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 638 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 639 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 641 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 643 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 644 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 645 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 646 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 647 | * @attr ref android.R.styleable#View_tag |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 648 | * @attr ref android.R.styleable#View_transformPivotX |
| 649 | * @attr ref android.R.styleable#View_transformPivotY |
| 650 | * @attr ref android.R.styleable#View_translationX |
| 651 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 652 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | * |
| 654 | * @see android.view.ViewGroup |
| 655 | */ |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 656 | public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback, |
| 657 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | private static final boolean DBG = false; |
| 659 | |
| 660 | /** |
| 661 | * The logging tag used by this class with android.util.Log. |
| 662 | */ |
| 663 | protected static final String VIEW_LOG_TAG = "View"; |
| 664 | |
| 665 | /** |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 666 | * When set to true, apps will draw debugging information about their layouts. |
| 667 | * |
| 668 | * @hide |
| 669 | */ |
| 670 | public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout"; |
| 671 | |
| 672 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | * Used to mark a View that has no ID. |
| 674 | */ |
| 675 | public static final int NO_ID = -1; |
| 676 | |
| 677 | /** |
| 678 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 679 | * calling setFlags. |
| 680 | */ |
| 681 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 682 | |
| 683 | /** |
| 684 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 685 | * setFlags. |
| 686 | */ |
| 687 | private static final int FOCUSABLE = 0x00000001; |
| 688 | |
| 689 | /** |
| 690 | * Mask for use with setFlags indicating bits used for focus. |
| 691 | */ |
| 692 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 693 | |
| 694 | /** |
| 695 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 696 | */ |
| 697 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 698 | |
| 699 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 700 | * This view is visible. |
| 701 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 702 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | */ |
| 704 | public static final int VISIBLE = 0x00000000; |
| 705 | |
| 706 | /** |
| 707 | * This view is invisible, but it still takes up space for layout purposes. |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 708 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 709 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | */ |
| 711 | public static final int INVISIBLE = 0x00000004; |
| 712 | |
| 713 | /** |
| 714 | * This view is invisible, and it doesn't take any space for layout |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 715 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 716 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | */ |
| 718 | public static final int GONE = 0x00000008; |
| 719 | |
| 720 | /** |
| 721 | * Mask for use with setFlags indicating bits used for visibility. |
| 722 | * {@hide} |
| 723 | */ |
| 724 | static final int VISIBILITY_MASK = 0x0000000C; |
| 725 | |
| 726 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 727 | |
| 728 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 729 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | * Use with ENABLED_MASK when calling setFlags. |
| 731 | * {@hide} |
| 732 | */ |
| 733 | static final int ENABLED = 0x00000000; |
| 734 | |
| 735 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 736 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | * Use with ENABLED_MASK when calling setFlags. |
| 738 | * {@hide} |
| 739 | */ |
| 740 | static final int DISABLED = 0x00000020; |
| 741 | |
| 742 | /** |
| 743 | * Mask for use with setFlags indicating bits used for indicating whether |
| 744 | * this view is enabled |
| 745 | * {@hide} |
| 746 | */ |
| 747 | static final int ENABLED_MASK = 0x00000020; |
| 748 | |
| 749 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 750 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 751 | * called and further optimizations will be performed. It is okay to have |
| 752 | * this flag set and a background. Use with DRAW_MASK when calling setFlags. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | * {@hide} |
| 754 | */ |
| 755 | static final int WILL_NOT_DRAW = 0x00000080; |
| 756 | |
| 757 | /** |
| 758 | * Mask for use with setFlags indicating bits used for indicating whether |
| 759 | * this view is will draw |
| 760 | * {@hide} |
| 761 | */ |
| 762 | static final int DRAW_MASK = 0x00000080; |
| 763 | |
| 764 | /** |
| 765 | * <p>This view doesn't show scrollbars.</p> |
| 766 | * {@hide} |
| 767 | */ |
| 768 | static final int SCROLLBARS_NONE = 0x00000000; |
| 769 | |
| 770 | /** |
| 771 | * <p>This view shows horizontal scrollbars.</p> |
| 772 | * {@hide} |
| 773 | */ |
| 774 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 775 | |
| 776 | /** |
| 777 | * <p>This view shows vertical scrollbars.</p> |
| 778 | * {@hide} |
| 779 | */ |
| 780 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 781 | |
| 782 | /** |
| 783 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 784 | * scrollbars are enabled.</p> |
| 785 | * {@hide} |
| 786 | */ |
| 787 | static final int SCROLLBARS_MASK = 0x00000300; |
| 788 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 789 | /** |
| 790 | * Indicates that the view should filter touches when its window is obscured. |
| 791 | * Refer to the class comments for more information about this security feature. |
| 792 | * {@hide} |
| 793 | */ |
| 794 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 795 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 796 | /** |
| 797 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 798 | * that they are optional and should be skipped if the window has |
| 799 | * requested system UI flags that ignore those insets for layout. |
| 800 | */ |
| 801 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | |
| 803 | /** |
| 804 | * <p>This view doesn't show fading edges.</p> |
| 805 | * {@hide} |
| 806 | */ |
| 807 | static final int FADING_EDGE_NONE = 0x00000000; |
| 808 | |
| 809 | /** |
| 810 | * <p>This view shows horizontal fading edges.</p> |
| 811 | * {@hide} |
| 812 | */ |
| 813 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 814 | |
| 815 | /** |
| 816 | * <p>This view shows vertical fading edges.</p> |
| 817 | * {@hide} |
| 818 | */ |
| 819 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 820 | |
| 821 | /** |
| 822 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 823 | * fading edges are enabled.</p> |
| 824 | * {@hide} |
| 825 | */ |
| 826 | static final int FADING_EDGE_MASK = 0x00003000; |
| 827 | |
| 828 | /** |
| 829 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 830 | * to clicks by notifying the OnClickListener.<p> |
| 831 | * {@hide} |
| 832 | */ |
| 833 | static final int CLICKABLE = 0x00004000; |
| 834 | |
| 835 | /** |
| 836 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 837 | * {@hide} |
| 838 | */ |
| 839 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 840 | |
| 841 | /** |
| 842 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 843 | * {@hide} |
| 844 | */ |
| 845 | static final int SAVE_DISABLED = 0x000010000; |
| 846 | |
| 847 | /** |
| 848 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 849 | * property.</p> |
| 850 | * {@hide} |
| 851 | */ |
| 852 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 853 | |
| 854 | /** |
| 855 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 856 | * {@hide} |
| 857 | */ |
| 858 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 859 | |
| 860 | /** |
| 861 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 862 | * {@hide} |
| 863 | */ |
| 864 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 865 | |
| 866 | /** |
| 867 | * <p>Enables low quality mode for the drawing cache.</p> |
| 868 | */ |
| 869 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 870 | |
| 871 | /** |
| 872 | * <p>Enables high quality mode for the drawing cache.</p> |
| 873 | */ |
| 874 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 875 | |
| 876 | /** |
| 877 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 878 | */ |
| 879 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 880 | |
| 881 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 882 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 883 | }; |
| 884 | |
| 885 | /** |
| 886 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 887 | * quality property.</p> |
| 888 | * {@hide} |
| 889 | */ |
| 890 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 891 | |
| 892 | /** |
| 893 | * <p> |
| 894 | * Indicates this view can be long clicked. When long clickable, a View |
| 895 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 896 | * context menu. |
| 897 | * </p> |
| 898 | * {@hide} |
| 899 | */ |
| 900 | static final int LONG_CLICKABLE = 0x00200000; |
| 901 | |
| 902 | /** |
| 903 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 904 | * and ignores its original internal states.</p> |
| 905 | * |
| 906 | * @hide |
| 907 | */ |
| 908 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 909 | |
| 910 | /** |
| 911 | * The scrollbar style to display the scrollbars inside the content area, |
| 912 | * without increasing the padding. The scrollbars will be overlaid with |
| 913 | * translucency on the view's content. |
| 914 | */ |
| 915 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 916 | |
| 917 | /** |
| 918 | * The scrollbar style to display the scrollbars inside the padded area, |
| 919 | * increasing the padding of the view. The scrollbars will not overlap the |
| 920 | * content area of the view. |
| 921 | */ |
| 922 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 923 | |
| 924 | /** |
| 925 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 926 | * without increasing the padding. The scrollbars will be overlaid with |
| 927 | * translucency. |
| 928 | */ |
| 929 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 930 | |
| 931 | /** |
| 932 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 933 | * increasing the padding of the view. The scrollbars will only overlap the |
| 934 | * background, if any. |
| 935 | */ |
| 936 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 937 | |
| 938 | /** |
| 939 | * Mask to check if the scrollbar style is overlay or inset. |
| 940 | * {@hide} |
| 941 | */ |
| 942 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 943 | |
| 944 | /** |
| 945 | * Mask to check if the scrollbar style is inside or outside. |
| 946 | * {@hide} |
| 947 | */ |
| 948 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 949 | |
| 950 | /** |
| 951 | * Mask for scrollbar style. |
| 952 | * {@hide} |
| 953 | */ |
| 954 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 955 | |
| 956 | /** |
| 957 | * View flag indicating that the screen should remain on while the |
| 958 | * window containing this view is visible to the user. This effectively |
| 959 | * takes care of automatically setting the WindowManager's |
| 960 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 961 | */ |
| 962 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 963 | |
| 964 | /** |
| 965 | * View flag indicating whether this view should have sound effects enabled |
| 966 | * for events such as clicking and touching. |
| 967 | */ |
| 968 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 969 | |
| 970 | /** |
| 971 | * View flag indicating whether this view should have haptic feedback |
| 972 | * enabled for events such as long presses. |
| 973 | */ |
| 974 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 975 | |
| 976 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 977 | * <p>Indicates that the view hierarchy should stop saving state when |
| 978 | * it reaches this view. If state saving is initiated immediately at |
| 979 | * the view, it will be allowed. |
| 980 | * {@hide} |
| 981 | */ |
| 982 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 983 | |
| 984 | /** |
| 985 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 986 | * {@hide} |
| 987 | */ |
| 988 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 989 | |
| 990 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 991 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 992 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 993 | */ |
| 994 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 995 | |
| 996 | /** |
| 997 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 998 | * should add only Views focusable in touch mode. |
| 999 | */ |
| 1000 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1001 | |
| 1002 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1003 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1004 | * should add only accessibility focusable Views. |
| 1005 | * |
| 1006 | * @hide |
| 1007 | */ |
| 1008 | public static final int FOCUSABLES_ACCESSIBILITY = 0x00000002; |
| 1009 | |
| 1010 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1011 | * Use with {@link #focusSearch(int)}. Move focus to the previous selectable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | * item. |
| 1013 | */ |
| 1014 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1015 | |
| 1016 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1017 | * Use with {@link #focusSearch(int)}. Move focus to the next selectable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | * item. |
| 1019 | */ |
| 1020 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1021 | |
| 1022 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1023 | * Use with {@link #focusSearch(int)}. Move focus to the left. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | */ |
| 1025 | public static final int FOCUS_LEFT = 0x00000011; |
| 1026 | |
| 1027 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1028 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | */ |
| 1030 | public static final int FOCUS_UP = 0x00000021; |
| 1031 | |
| 1032 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1033 | * Use with {@link #focusSearch(int)}. Move focus to the right. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | */ |
| 1035 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1036 | |
| 1037 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1038 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | */ |
| 1040 | public static final int FOCUS_DOWN = 0x00000082; |
| 1041 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1042 | // Accessibility focus directions. |
| 1043 | |
| 1044 | /** |
| 1045 | * The accessibility focus which is the current user position when |
| 1046 | * interacting with the accessibility framework. |
| 1047 | */ |
| 1048 | public static final int FOCUS_ACCESSIBILITY = 0x00001000; |
| 1049 | |
| 1050 | /** |
| 1051 | * Use with {@link #focusSearch(int)}. Move acessibility focus left. |
| 1052 | */ |
| 1053 | public static final int ACCESSIBILITY_FOCUS_LEFT = FOCUS_LEFT | FOCUS_ACCESSIBILITY; |
| 1054 | |
| 1055 | /** |
| 1056 | * Use with {@link #focusSearch(int)}. Move acessibility focus up. |
| 1057 | */ |
| 1058 | public static final int ACCESSIBILITY_FOCUS_UP = FOCUS_UP | FOCUS_ACCESSIBILITY; |
| 1059 | |
| 1060 | /** |
| 1061 | * Use with {@link #focusSearch(int)}. Move acessibility focus right. |
| 1062 | */ |
| 1063 | public static final int ACCESSIBILITY_FOCUS_RIGHT = FOCUS_RIGHT | FOCUS_ACCESSIBILITY; |
| 1064 | |
| 1065 | /** |
| 1066 | * Use with {@link #focusSearch(int)}. Move acessibility focus down. |
| 1067 | */ |
| 1068 | public static final int ACCESSIBILITY_FOCUS_DOWN = FOCUS_DOWN | FOCUS_ACCESSIBILITY; |
| 1069 | |
| 1070 | /** |
Svetoslav Ganov | d6e716d | 2012-04-20 18:36:11 -0700 | [diff] [blame] | 1071 | * Use with {@link #focusSearch(int)}. Move acessibility focus forward. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1072 | */ |
| 1073 | public static final int ACCESSIBILITY_FOCUS_FORWARD = FOCUS_FORWARD | FOCUS_ACCESSIBILITY; |
| 1074 | |
| 1075 | /** |
Svetoslav Ganov | d6e716d | 2012-04-20 18:36:11 -0700 | [diff] [blame] | 1076 | * Use with {@link #focusSearch(int)}. Move acessibility focus backward. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1077 | */ |
| 1078 | public static final int ACCESSIBILITY_FOCUS_BACKWARD = FOCUS_BACKWARD | FOCUS_ACCESSIBILITY; |
| 1079 | |
| 1080 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1081 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1082 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1083 | */ |
| 1084 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1085 | |
| 1086 | /** |
| 1087 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1088 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1089 | */ |
| 1090 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1091 | |
| 1092 | /** |
| 1093 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1094 | * for functions that combine both width and height into a single int, |
| 1095 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1096 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1097 | */ |
| 1098 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1099 | |
| 1100 | /** |
| 1101 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1102 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1103 | * is smaller that the space the view would like to have. |
| 1104 | */ |
| 1105 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1106 | |
| 1107 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | * Base View state sets |
| 1109 | */ |
| 1110 | // Singles |
| 1111 | /** |
| 1112 | * Indicates the view has no states set. States are used with |
| 1113 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1114 | * view depending on its state. |
| 1115 | * |
| 1116 | * @see android.graphics.drawable.Drawable |
| 1117 | * @see #getDrawableState() |
| 1118 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1119 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | /** |
| 1121 | * Indicates the view is enabled. States are used with |
| 1122 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1123 | * view depending on its state. |
| 1124 | * |
| 1125 | * @see android.graphics.drawable.Drawable |
| 1126 | * @see #getDrawableState() |
| 1127 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1128 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | /** |
| 1130 | * Indicates the view is focused. States are used with |
| 1131 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1132 | * view depending on its state. |
| 1133 | * |
| 1134 | * @see android.graphics.drawable.Drawable |
| 1135 | * @see #getDrawableState() |
| 1136 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1137 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | /** |
| 1139 | * Indicates the view is selected. States are used with |
| 1140 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1141 | * view depending on its state. |
| 1142 | * |
| 1143 | * @see android.graphics.drawable.Drawable |
| 1144 | * @see #getDrawableState() |
| 1145 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1146 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | /** |
| 1148 | * Indicates the view is pressed. States are used with |
| 1149 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1150 | * view depending on its state. |
| 1151 | * |
| 1152 | * @see android.graphics.drawable.Drawable |
| 1153 | * @see #getDrawableState() |
| 1154 | * @hide |
| 1155 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1156 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | /** |
| 1158 | * Indicates the view's window has focus. States are used with |
| 1159 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1160 | * view depending on its state. |
| 1161 | * |
| 1162 | * @see android.graphics.drawable.Drawable |
| 1163 | * @see #getDrawableState() |
| 1164 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1165 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | // Doubles |
| 1167 | /** |
| 1168 | * Indicates the view is enabled and has the focus. |
| 1169 | * |
| 1170 | * @see #ENABLED_STATE_SET |
| 1171 | * @see #FOCUSED_STATE_SET |
| 1172 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1173 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | /** |
| 1175 | * Indicates the view is enabled and selected. |
| 1176 | * |
| 1177 | * @see #ENABLED_STATE_SET |
| 1178 | * @see #SELECTED_STATE_SET |
| 1179 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1180 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | /** |
| 1182 | * Indicates the view is enabled and that its window has focus. |
| 1183 | * |
| 1184 | * @see #ENABLED_STATE_SET |
| 1185 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1186 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1187 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1188 | /** |
| 1189 | * Indicates the view is focused and selected. |
| 1190 | * |
| 1191 | * @see #FOCUSED_STATE_SET |
| 1192 | * @see #SELECTED_STATE_SET |
| 1193 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1194 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | /** |
| 1196 | * Indicates the view has the focus and that its window has the focus. |
| 1197 | * |
| 1198 | * @see #FOCUSED_STATE_SET |
| 1199 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1200 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1201 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | /** |
| 1203 | * Indicates the view is selected and that its window has the focus. |
| 1204 | * |
| 1205 | * @see #SELECTED_STATE_SET |
| 1206 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1207 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1208 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | // Triples |
| 1210 | /** |
| 1211 | * Indicates the view is enabled, focused and selected. |
| 1212 | * |
| 1213 | * @see #ENABLED_STATE_SET |
| 1214 | * @see #FOCUSED_STATE_SET |
| 1215 | * @see #SELECTED_STATE_SET |
| 1216 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1217 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | /** |
| 1219 | * Indicates the view is enabled, focused and its window has the focus. |
| 1220 | * |
| 1221 | * @see #ENABLED_STATE_SET |
| 1222 | * @see #FOCUSED_STATE_SET |
| 1223 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1224 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1225 | protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | /** |
| 1227 | * Indicates the view is enabled, selected and its window has the focus. |
| 1228 | * |
| 1229 | * @see #ENABLED_STATE_SET |
| 1230 | * @see #SELECTED_STATE_SET |
| 1231 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1232 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1233 | protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | /** |
| 1235 | * Indicates the view is focused, selected and its window has the focus. |
| 1236 | * |
| 1237 | * @see #FOCUSED_STATE_SET |
| 1238 | * @see #SELECTED_STATE_SET |
| 1239 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1240 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1241 | protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | /** |
| 1243 | * Indicates the view is enabled, focused, selected and its window |
| 1244 | * has the focus. |
| 1245 | * |
| 1246 | * @see #ENABLED_STATE_SET |
| 1247 | * @see #FOCUSED_STATE_SET |
| 1248 | * @see #SELECTED_STATE_SET |
| 1249 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1250 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1251 | protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | /** |
| 1253 | * Indicates the view is pressed and its window has the focus. |
| 1254 | * |
| 1255 | * @see #PRESSED_STATE_SET |
| 1256 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1257 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1258 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | /** |
| 1260 | * Indicates the view is pressed and selected. |
| 1261 | * |
| 1262 | * @see #PRESSED_STATE_SET |
| 1263 | * @see #SELECTED_STATE_SET |
| 1264 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1265 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | /** |
| 1267 | * Indicates the view is pressed, selected and its window has the focus. |
| 1268 | * |
| 1269 | * @see #PRESSED_STATE_SET |
| 1270 | * @see #SELECTED_STATE_SET |
| 1271 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1272 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1273 | protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | /** |
| 1275 | * Indicates the view is pressed and focused. |
| 1276 | * |
| 1277 | * @see #PRESSED_STATE_SET |
| 1278 | * @see #FOCUSED_STATE_SET |
| 1279 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1280 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | /** |
| 1282 | * Indicates the view is pressed, focused and its window has the focus. |
| 1283 | * |
| 1284 | * @see #PRESSED_STATE_SET |
| 1285 | * @see #FOCUSED_STATE_SET |
| 1286 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1287 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1288 | protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | /** |
| 1290 | * Indicates the view is pressed, focused and selected. |
| 1291 | * |
| 1292 | * @see #PRESSED_STATE_SET |
| 1293 | * @see #SELECTED_STATE_SET |
| 1294 | * @see #FOCUSED_STATE_SET |
| 1295 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1296 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | /** |
| 1298 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1299 | * |
| 1300 | * @see #PRESSED_STATE_SET |
| 1301 | * @see #FOCUSED_STATE_SET |
| 1302 | * @see #SELECTED_STATE_SET |
| 1303 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1304 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1305 | protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | /** |
| 1307 | * Indicates the view is pressed and enabled. |
| 1308 | * |
| 1309 | * @see #PRESSED_STATE_SET |
| 1310 | * @see #ENABLED_STATE_SET |
| 1311 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1312 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | /** |
| 1314 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1315 | * |
| 1316 | * @see #PRESSED_STATE_SET |
| 1317 | * @see #ENABLED_STATE_SET |
| 1318 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1319 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1320 | protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | /** |
| 1322 | * Indicates the view is pressed, enabled and selected. |
| 1323 | * |
| 1324 | * @see #PRESSED_STATE_SET |
| 1325 | * @see #ENABLED_STATE_SET |
| 1326 | * @see #SELECTED_STATE_SET |
| 1327 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1328 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | /** |
| 1330 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1331 | * focus. |
| 1332 | * |
| 1333 | * @see #PRESSED_STATE_SET |
| 1334 | * @see #ENABLED_STATE_SET |
| 1335 | * @see #SELECTED_STATE_SET |
| 1336 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1337 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1338 | protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | /** |
| 1340 | * Indicates the view is pressed, enabled and focused. |
| 1341 | * |
| 1342 | * @see #PRESSED_STATE_SET |
| 1343 | * @see #ENABLED_STATE_SET |
| 1344 | * @see #FOCUSED_STATE_SET |
| 1345 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1346 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | /** |
| 1348 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1349 | * focus. |
| 1350 | * |
| 1351 | * @see #PRESSED_STATE_SET |
| 1352 | * @see #ENABLED_STATE_SET |
| 1353 | * @see #FOCUSED_STATE_SET |
| 1354 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1355 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1356 | protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1357 | /** |
| 1358 | * Indicates the view is pressed, enabled, focused and selected. |
| 1359 | * |
| 1360 | * @see #PRESSED_STATE_SET |
| 1361 | * @see #ENABLED_STATE_SET |
| 1362 | * @see #SELECTED_STATE_SET |
| 1363 | * @see #FOCUSED_STATE_SET |
| 1364 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1365 | protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | /** |
| 1367 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1368 | * has the focus. |
| 1369 | * |
| 1370 | * @see #PRESSED_STATE_SET |
| 1371 | * @see #ENABLED_STATE_SET |
| 1372 | * @see #SELECTED_STATE_SET |
| 1373 | * @see #FOCUSED_STATE_SET |
| 1374 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1375 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1376 | protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | |
| 1378 | /** |
| 1379 | * The order here is very important to {@link #getDrawableState()} |
| 1380 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1381 | private static final int[][] VIEW_STATE_SETS; |
| 1382 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1383 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1384 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1385 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1386 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1387 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1388 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1389 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1390 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1391 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1392 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1393 | |
| 1394 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1395 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1396 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1397 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1398 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1399 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1400 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1401 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1402 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1403 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1404 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | }; |
| 1406 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1407 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1408 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1409 | throw new IllegalStateException( |
| 1410 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1411 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1412 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1413 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1414 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1415 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1416 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1417 | orderedIds[i * 2] = viewState; |
| 1418 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1422 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1423 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1424 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1425 | int numBits = Integer.bitCount(i); |
| 1426 | int[] set = new int[numBits]; |
| 1427 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1428 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1429 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1430 | set[pos++] = orderedIds[j]; |
| 1431 | } |
| 1432 | } |
| 1433 | VIEW_STATE_SETS[i] = set; |
| 1434 | } |
| 1435 | |
| 1436 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1437 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1438 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1439 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1440 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1441 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1442 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1443 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1444 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1445 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1446 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1447 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1448 | | VIEW_STATE_FOCUSED]; |
| 1449 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1450 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1451 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1452 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1453 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1454 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1456 | | VIEW_STATE_ENABLED]; |
| 1457 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1458 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1459 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1460 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1461 | | VIEW_STATE_ENABLED]; |
| 1462 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1463 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1464 | | VIEW_STATE_ENABLED]; |
| 1465 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1467 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1468 | |
| 1469 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1470 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1471 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1472 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1473 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1476 | | VIEW_STATE_PRESSED]; |
| 1477 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1478 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1479 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1480 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1481 | | VIEW_STATE_PRESSED]; |
| 1482 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1483 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1484 | | VIEW_STATE_PRESSED]; |
| 1485 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1486 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1487 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1488 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1489 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1490 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1491 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1492 | | VIEW_STATE_PRESSED]; |
| 1493 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1494 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1495 | | VIEW_STATE_PRESSED]; |
| 1496 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1497 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1498 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1499 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1500 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1501 | | VIEW_STATE_PRESSED]; |
| 1502 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1503 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1504 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1505 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1506 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1507 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1508 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1509 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1510 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1511 | | VIEW_STATE_PRESSED]; |
| 1512 | } |
| 1513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1515 | * Accessibility event types that are dispatched for text population. |
| 1516 | */ |
| 1517 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1518 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1519 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1520 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1521 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1522 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1523 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1524 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1525 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1526 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
| 1527 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1528 | |
| 1529 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1531 | * be extended in the future to hold our own class with more than just |
| 1532 | * a Rect. :) |
| 1533 | */ |
| 1534 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1535 | |
| 1536 | /** |
| 1537 | * Map used to store views' tags. |
| 1538 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1539 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1542 | * The next available accessiiblity id. |
| 1543 | */ |
| 1544 | private static int sNextAccessibilityViewId; |
| 1545 | |
| 1546 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | * The animation currently associated with this view. |
| 1548 | * @hide |
| 1549 | */ |
| 1550 | protected Animation mCurrentAnimation = null; |
| 1551 | |
| 1552 | /** |
| 1553 | * Width as measured during measure pass. |
| 1554 | * {@hide} |
| 1555 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1556 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1557 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | |
| 1559 | /** |
| 1560 | * Height as measured during measure pass. |
| 1561 | * {@hide} |
| 1562 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1563 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1564 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | |
| 1566 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1567 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1568 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1569 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1570 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1571 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1572 | * |
| 1573 | * {@hide} |
| 1574 | */ |
| 1575 | boolean mRecreateDisplayList = false; |
| 1576 | |
| 1577 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | * The view's identifier. |
| 1579 | * {@hide} |
| 1580 | * |
| 1581 | * @see #setId(int) |
| 1582 | * @see #getId() |
| 1583 | */ |
| 1584 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1585 | int mID = NO_ID; |
| 1586 | |
| 1587 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1588 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1589 | */ |
| 1590 | int mAccessibilityViewId = NO_ID; |
| 1591 | |
| 1592 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | * The view's tag. |
| 1594 | * {@hide} |
| 1595 | * |
| 1596 | * @see #setTag(Object) |
| 1597 | * @see #getTag() |
| 1598 | */ |
| 1599 | protected Object mTag; |
| 1600 | |
| 1601 | // for mPrivateFlags: |
| 1602 | /** {@hide} */ |
| 1603 | static final int WANTS_FOCUS = 0x00000001; |
| 1604 | /** {@hide} */ |
| 1605 | static final int FOCUSED = 0x00000002; |
| 1606 | /** {@hide} */ |
| 1607 | static final int SELECTED = 0x00000004; |
| 1608 | /** {@hide} */ |
| 1609 | static final int IS_ROOT_NAMESPACE = 0x00000008; |
| 1610 | /** {@hide} */ |
| 1611 | static final int HAS_BOUNDS = 0x00000010; |
| 1612 | /** {@hide} */ |
| 1613 | static final int DRAWN = 0x00000020; |
| 1614 | /** |
| 1615 | * When this flag is set, this view is running an animation on behalf of its |
| 1616 | * children and should therefore not cancel invalidate requests, even if they |
| 1617 | * lie outside of this view's bounds. |
| 1618 | * |
| 1619 | * {@hide} |
| 1620 | */ |
| 1621 | static final int DRAW_ANIMATION = 0x00000040; |
| 1622 | /** {@hide} */ |
| 1623 | static final int SKIP_DRAW = 0x00000080; |
| 1624 | /** {@hide} */ |
| 1625 | static final int ONLY_DRAWS_BACKGROUND = 0x00000100; |
| 1626 | /** {@hide} */ |
| 1627 | static final int REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
| 1628 | /** {@hide} */ |
| 1629 | static final int DRAWABLE_STATE_DIRTY = 0x00000400; |
| 1630 | /** {@hide} */ |
| 1631 | static final int MEASURED_DIMENSION_SET = 0x00000800; |
| 1632 | /** {@hide} */ |
| 1633 | static final int FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1634 | /** {@hide} */ |
| 1635 | static final int LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | |
| 1637 | private static final int PRESSED = 0x00004000; |
| 1638 | |
| 1639 | /** {@hide} */ |
| 1640 | static final int DRAWING_CACHE_VALID = 0x00008000; |
| 1641 | /** |
| 1642 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1643 | * more) after its animation has completed. |
| 1644 | * {@hide} |
| 1645 | */ |
| 1646 | static final int ANIMATION_STARTED = 0x00010000; |
| 1647 | |
| 1648 | private static final int SAVE_STATE_CALLED = 0x00020000; |
| 1649 | |
| 1650 | /** |
| 1651 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1652 | * the alpha must be restored. |
| 1653 | * {@hide} |
| 1654 | */ |
| 1655 | static final int ALPHA_SET = 0x00040000; |
| 1656 | |
| 1657 | /** |
| 1658 | * Set by {@link #setScrollContainer(boolean)}. |
| 1659 | */ |
| 1660 | static final int SCROLL_CONTAINER = 0x00080000; |
| 1661 | |
| 1662 | /** |
| 1663 | * Set by {@link #setScrollContainer(boolean)}. |
| 1664 | */ |
| 1665 | static final int SCROLL_CONTAINER_ADDED = 0x00100000; |
| 1666 | |
| 1667 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1668 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1669 | * |
| 1670 | * @hide |
| 1671 | */ |
| 1672 | static final int DIRTY = 0x00200000; |
| 1673 | |
| 1674 | /** |
| 1675 | * View flag indicating whether this view was invalidated by an opaque |
| 1676 | * invalidate request. |
| 1677 | * |
| 1678 | * @hide |
| 1679 | */ |
| 1680 | static final int DIRTY_OPAQUE = 0x00400000; |
| 1681 | |
| 1682 | /** |
| 1683 | * Mask for {@link #DIRTY} and {@link #DIRTY_OPAQUE}. |
| 1684 | * |
| 1685 | * @hide |
| 1686 | */ |
| 1687 | static final int DIRTY_MASK = 0x00600000; |
| 1688 | |
| 1689 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1690 | * Indicates whether the background is opaque. |
| 1691 | * |
| 1692 | * @hide |
| 1693 | */ |
| 1694 | static final int OPAQUE_BACKGROUND = 0x00800000; |
| 1695 | |
| 1696 | /** |
| 1697 | * Indicates whether the scrollbars are opaque. |
| 1698 | * |
| 1699 | * @hide |
| 1700 | */ |
| 1701 | static final int OPAQUE_SCROLLBARS = 0x01000000; |
| 1702 | |
| 1703 | /** |
| 1704 | * Indicates whether the view is opaque. |
| 1705 | * |
| 1706 | * @hide |
| 1707 | */ |
| 1708 | static final int OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1709 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1710 | /** |
| 1711 | * Indicates a prepressed state; |
| 1712 | * the short time between ACTION_DOWN and recognizing |
| 1713 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1714 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1715 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1716 | * @hide |
| 1717 | */ |
| 1718 | private static final int PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1719 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1720 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1721 | * Indicates whether the view is temporarily detached. |
| 1722 | * |
| 1723 | * @hide |
| 1724 | */ |
| 1725 | static final int CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1726 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1727 | /** |
| 1728 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1729 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1730 | * @hide |
| 1731 | */ |
| 1732 | private static final int AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1733 | |
| 1734 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1735 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1736 | * @hide |
| 1737 | */ |
| 1738 | private static final int HOVERED = 0x10000000; |
| 1739 | |
| 1740 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1741 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1742 | * for transform operations |
| 1743 | * |
| 1744 | * @hide |
| 1745 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1746 | private static final int PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1747 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1748 | /** {@hide} */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 1749 | static final int ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1750 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1751 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1752 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1753 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1754 | * a view's display list (as opposed to just returning a reference to its existing |
| 1755 | * display list). |
| 1756 | * |
| 1757 | * @hide |
| 1758 | */ |
| 1759 | static final int INVALIDATED = 0x80000000; |
| 1760 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1761 | /* Masks for mPrivateFlags2 */ |
| 1762 | |
| 1763 | /** |
| 1764 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1765 | * Cleared when the drag operation concludes. |
| 1766 | * @hide |
| 1767 | */ |
| 1768 | static final int DRAG_CAN_ACCEPT = 0x00000001; |
| 1769 | |
| 1770 | /** |
| 1771 | * Indicates that this view is currently directly under the drag location in a |
| 1772 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1773 | * the drag exits the view, or when the drag operation concludes. |
| 1774 | * @hide |
| 1775 | */ |
| 1776 | static final int DRAG_HOVERED = 0x00000002; |
| 1777 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1778 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1779 | * Horizontal layout direction of this view is from Left to Right. |
| 1780 | * Use with {@link #setLayoutDirection}. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1781 | * @hide |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1782 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1783 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1784 | |
| 1785 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1786 | * Horizontal layout direction of this view is from Right to Left. |
| 1787 | * Use with {@link #setLayoutDirection}. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1788 | * @hide |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1789 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1790 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1791 | |
| 1792 | /** |
| 1793 | * Horizontal layout direction of this view is inherited from its parent. |
| 1794 | * Use with {@link #setLayoutDirection}. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1795 | * @hide |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1796 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1797 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1798 | |
| 1799 | /** |
| 1800 | * Horizontal layout direction of this view is from deduced from the default language |
| 1801 | * script for the locale. Use with {@link #setLayoutDirection}. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1802 | * @hide |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1803 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1804 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1805 | |
| 1806 | /** |
| 1807 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1808 | * @hide |
| 1809 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1810 | static final int LAYOUT_DIRECTION_MASK_SHIFT = 2; |
| 1811 | |
| 1812 | /** |
| 1813 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1814 | * @hide |
| 1815 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1816 | static final int LAYOUT_DIRECTION_MASK = 0x00000003 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1817 | |
| 1818 | /** |
| 1819 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1820 | * right-to-left direction. |
| 1821 | * @hide |
| 1822 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1823 | static final int LAYOUT_DIRECTION_RESOLVED_RTL = 4 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1824 | |
| 1825 | /** |
| 1826 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1827 | * @hide |
| 1828 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1829 | static final int LAYOUT_DIRECTION_RESOLVED = 8 << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1830 | |
| 1831 | /** |
| 1832 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1833 | * @hide |
| 1834 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1835 | static final int LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C << LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1836 | |
| 1837 | /* |
| 1838 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1839 | * flag value. |
| 1840 | * @hide |
| 1841 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1842 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1843 | LAYOUT_DIRECTION_LTR, |
| 1844 | LAYOUT_DIRECTION_RTL, |
| 1845 | LAYOUT_DIRECTION_INHERIT, |
| 1846 | LAYOUT_DIRECTION_LOCALE |
| 1847 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1848 | |
| 1849 | /** |
| 1850 | * Default horizontal layout direction. |
| 1851 | * @hide |
| 1852 | */ |
| 1853 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1854 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1855 | /** |
| 1856 | * Indicates that the view is tracking some sort of transient state |
| 1857 | * that the app should not need to be aware of, but that the framework |
| 1858 | * should take special care to preserve. |
| 1859 | * |
| 1860 | * @hide |
| 1861 | */ |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1862 | static final int HAS_TRANSIENT_STATE = 0x00000100; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1863 | |
| 1864 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1865 | /** |
| 1866 | * Text direction is inherited thru {@link ViewGroup} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1867 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1868 | */ |
| 1869 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1870 | |
| 1871 | /** |
| 1872 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1873 | * determines the paragraph direction. If there is no strong directional character, the |
| 1874 | * paragraph direction is the view's resolved layout direction. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1875 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1876 | */ |
| 1877 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1878 | |
| 1879 | /** |
| 1880 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1881 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1882 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1883 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1884 | */ |
| 1885 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1886 | |
| 1887 | /** |
| 1888 | * Text direction is forced to LTR. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1889 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1890 | */ |
| 1891 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1892 | |
| 1893 | /** |
| 1894 | * Text direction is forced to RTL. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1895 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1896 | */ |
| 1897 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1898 | |
| 1899 | /** |
| 1900 | * Text direction is coming from the system Locale. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1901 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1902 | */ |
| 1903 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1904 | |
| 1905 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1906 | * Default text direction is inherited |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1907 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1908 | */ |
| 1909 | protected static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
| 1910 | |
| 1911 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1912 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1913 | * @hide |
| 1914 | */ |
| 1915 | static final int TEXT_DIRECTION_MASK_SHIFT = 6; |
| 1916 | |
| 1917 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1918 | * Mask for use with private flags indicating bits used for text direction. |
| 1919 | * @hide |
| 1920 | */ |
| 1921 | static final int TEXT_DIRECTION_MASK = 0x00000007 << TEXT_DIRECTION_MASK_SHIFT; |
| 1922 | |
| 1923 | /** |
| 1924 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1925 | * flag value. |
| 1926 | * @hide |
| 1927 | */ |
| 1928 | private static final int[] TEXT_DIRECTION_FLAGS = { |
| 1929 | TEXT_DIRECTION_INHERIT << TEXT_DIRECTION_MASK_SHIFT, |
| 1930 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_MASK_SHIFT, |
| 1931 | TEXT_DIRECTION_ANY_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1932 | TEXT_DIRECTION_LTR << TEXT_DIRECTION_MASK_SHIFT, |
| 1933 | TEXT_DIRECTION_RTL << TEXT_DIRECTION_MASK_SHIFT, |
| 1934 | TEXT_DIRECTION_LOCALE << TEXT_DIRECTION_MASK_SHIFT |
| 1935 | }; |
| 1936 | |
| 1937 | /** |
| 1938 | * Indicates whether the view text direction has been resolved. |
| 1939 | * @hide |
| 1940 | */ |
| 1941 | static final int TEXT_DIRECTION_RESOLVED = 0x00000008 << TEXT_DIRECTION_MASK_SHIFT; |
| 1942 | |
| 1943 | /** |
| 1944 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1945 | * @hide |
| 1946 | */ |
| 1947 | static final int TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
| 1948 | |
| 1949 | /** |
| 1950 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1951 | * @hide |
| 1952 | */ |
| 1953 | static final int TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1954 | |
| 1955 | /** |
| 1956 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1957 | * @hide |
| 1958 | */ |
| 1959 | static final int TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1960 | TEXT_DIRECTION_FIRST_STRONG << TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
| 1961 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1962 | /* |
| 1963 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1964 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1965 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1966 | */ |
| 1967 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1968 | |
| 1969 | /** |
| 1970 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1971 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1972 | * |
| 1973 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1974 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1975 | */ |
| 1976 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1977 | |
| 1978 | /** |
| 1979 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1980 | * |
| 1981 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1982 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1983 | */ |
| 1984 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1985 | |
| 1986 | /** |
| 1987 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1988 | * |
| 1989 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1990 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1991 | */ |
| 1992 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1993 | |
| 1994 | /** |
| 1995 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 1996 | * |
| 1997 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 1998 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1999 | */ |
| 2000 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 2001 | |
| 2002 | /** |
| 2003 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 2004 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 2005 | * |
| 2006 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 2007 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2008 | */ |
| 2009 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 2010 | |
| 2011 | /** |
| 2012 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 2013 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 2014 | * |
| 2015 | * Use with {@link #setTextAlignment(int)} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 2016 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2017 | */ |
| 2018 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 2019 | |
| 2020 | /** |
| 2021 | * Default text alignment is inherited |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 2022 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2023 | */ |
| 2024 | protected static int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
| 2025 | |
| 2026 | /** |
| 2027 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 2028 | * @hide |
| 2029 | */ |
| 2030 | static final int TEXT_ALIGNMENT_MASK_SHIFT = 13; |
| 2031 | |
| 2032 | /** |
| 2033 | * Mask for use with private flags indicating bits used for text alignment. |
| 2034 | * @hide |
| 2035 | */ |
| 2036 | static final int TEXT_ALIGNMENT_MASK = 0x00000007 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 2037 | |
| 2038 | /** |
| 2039 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 2040 | * flag value. |
| 2041 | * @hide |
| 2042 | */ |
| 2043 | private static final int[] TEXT_ALIGNMENT_FLAGS = { |
| 2044 | TEXT_ALIGNMENT_INHERIT << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2045 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2046 | TEXT_ALIGNMENT_TEXT_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2047 | TEXT_ALIGNMENT_TEXT_END << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2048 | TEXT_ALIGNMENT_CENTER << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2049 | TEXT_ALIGNMENT_VIEW_START << TEXT_ALIGNMENT_MASK_SHIFT, |
| 2050 | TEXT_ALIGNMENT_VIEW_END << TEXT_ALIGNMENT_MASK_SHIFT |
| 2051 | }; |
| 2052 | |
| 2053 | /** |
| 2054 | * Indicates whether the view text alignment has been resolved. |
| 2055 | * @hide |
| 2056 | */ |
| 2057 | static final int TEXT_ALIGNMENT_RESOLVED = 0x00000008 << TEXT_ALIGNMENT_MASK_SHIFT; |
| 2058 | |
| 2059 | /** |
| 2060 | * Bit shift to get the resolved text alignment. |
| 2061 | * @hide |
| 2062 | */ |
| 2063 | static final int TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
| 2064 | |
| 2065 | /** |
| 2066 | * Mask for use with private flags indicating bits used for text alignment. |
| 2067 | * @hide |
| 2068 | */ |
| 2069 | static final int TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 2070 | |
| 2071 | /** |
| 2072 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2073 | */ |
| 2074 | public static final int TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2075 | TEXT_ALIGNMENT_GRAVITY << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 2076 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2077 | // Accessiblity constants for mPrivateFlags2 |
| 2078 | |
| 2079 | /** |
| 2080 | * Shift for accessibility related bits in {@link #mPrivateFlags2}. |
| 2081 | */ |
| 2082 | static final int IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
| 2083 | |
| 2084 | /** |
| 2085 | * Automatically determine whether a view is important for accessibility. |
| 2086 | */ |
| 2087 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2088 | |
| 2089 | /** |
| 2090 | * The view is important for accessibility. |
| 2091 | */ |
| 2092 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2093 | |
| 2094 | /** |
| 2095 | * The view is not important for accessibility. |
| 2096 | */ |
| 2097 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2098 | |
| 2099 | /** |
| 2100 | * The default whether the view is important for accessiblity. |
| 2101 | */ |
| 2102 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2103 | |
| 2104 | /** |
| 2105 | * Mask for obtainig the bits which specify how to determine |
| 2106 | * whether a view is important for accessibility. |
| 2107 | */ |
| 2108 | static final int IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 2109 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
| 2110 | << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 2111 | |
| 2112 | /** |
| 2113 | * Flag indicating whether a view has accessibility focus. |
| 2114 | */ |
| 2115 | static final int ACCESSIBILITY_FOCUSED = 0x00000040 << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 2116 | |
| 2117 | /** |
| 2118 | * Flag indicating whether a view state for accessibility has changed. |
| 2119 | */ |
| 2120 | static final int ACCESSIBILITY_STATE_CHANGED = 0x00000080 << IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2121 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2122 | /* End of masks for mPrivateFlags2 */ |
| 2123 | |
| 2124 | static final int DRAG_MASK = DRAG_CAN_ACCEPT | DRAG_HOVERED; |
| 2125 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2126 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2127 | * Always allow a user to over-scroll this view, provided it is a |
| 2128 | * view that can scroll. |
| 2129 | * |
| 2130 | * @see #getOverScrollMode() |
| 2131 | * @see #setOverScrollMode(int) |
| 2132 | */ |
| 2133 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2134 | |
| 2135 | /** |
| 2136 | * Allow a user to over-scroll this view only if the content is large |
| 2137 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2138 | * |
| 2139 | * @see #getOverScrollMode() |
| 2140 | * @see #setOverScrollMode(int) |
| 2141 | */ |
| 2142 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2143 | |
| 2144 | /** |
| 2145 | * Never allow a user to over-scroll this view. |
| 2146 | * |
| 2147 | * @see #getOverScrollMode() |
| 2148 | * @see #setOverScrollMode(int) |
| 2149 | */ |
| 2150 | public static final int OVER_SCROLL_NEVER = 2; |
| 2151 | |
| 2152 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2153 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2154 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2155 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2156 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2157 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2158 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2159 | |
| 2160 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2161 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2162 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2163 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2164 | * <p>This is for use in games, book readers, video players, or any other |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2165 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2166 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2167 | * <p>In low profile mode, the status bar and/or navigation icons may dim. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2168 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2169 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2170 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2171 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2172 | |
| 2173 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2174 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2175 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2176 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2177 | * <p>This is an even less obtrusive state than that called for by |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2178 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2179 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2180 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2181 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2182 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2183 | * window flags) for displaying content using every last pixel on the display. |
| 2184 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2185 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2186 | * interaction will cause them to reappear immediately. When this happens, both |
| 2187 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2188 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2189 | * |
| 2190 | * @see #setSystemUiVisibility(int) |
| 2191 | */ |
| 2192 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2193 | |
| 2194 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2195 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2196 | * into the normal fullscreen mode so that its content can take over the screen |
| 2197 | * while still allowing the user to interact with the application. |
| 2198 | * |
| 2199 | * <p>This has the same visual effect as |
| 2200 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2201 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2202 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2203 | * hidden while the user is in the View's window, focusing the experience on |
| 2204 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2205 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2206 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2207 | * hide the action bar. |
| 2208 | * |
| 2209 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2210 | * it is a transient state -- that is, the application does this at certain |
| 2211 | * points in its user interaction where it wants to allow the user to focus |
| 2212 | * on content, but not as a continuous state. For situations where the application |
| 2213 | * would like to simply stay full screen the entire time (such as a game that |
| 2214 | * wants to take over the screen), the |
| 2215 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2216 | * is usually a better approach. The state set here will be removed by the system |
| 2217 | * in various situations (such as the user moving to another application) like |
| 2218 | * the other system UI states. |
| 2219 | * |
| 2220 | * <p>When using this flag, the application should provide some easy facility |
| 2221 | * for the user to go out of it. A common example would be in an e-book |
| 2222 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2223 | * decorations that had been hidden while the user was immersed in reading |
| 2224 | * the book. |
| 2225 | * |
| 2226 | * @see #setSystemUiVisibility(int) |
| 2227 | */ |
| 2228 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2229 | |
| 2230 | /** |
| 2231 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2232 | * flags, we would like a stable view of the content insets given to |
| 2233 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2234 | * will always represent the worst case that the application can expect |
| 2235 | * as a continue state. In practice this means with any of system bar, |
| 2236 | * nav bar, and status bar shown, but not the space that would be needed |
| 2237 | * for an input method. |
| 2238 | * |
| 2239 | * <p>If you are using ActionBar in |
| 2240 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2241 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2242 | * insets it adds to those given to the application. |
| 2243 | */ |
| 2244 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2245 | |
| 2246 | /** |
| 2247 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2248 | * to be layed out as if it has requested |
| 2249 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2250 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2251 | * the expense that some of its user interface may be covered by screen |
| 2252 | * decorations when they are shown. You can perform layout of your inner |
| 2253 | * UI elements to account for the navagation system UI through the |
| 2254 | * {@link #fitSystemWindows(Rect)} method. |
| 2255 | */ |
| 2256 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2257 | |
| 2258 | /** |
| 2259 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2260 | * to be layed out as if it has requested |
| 2261 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2262 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2263 | * the expense that some of its user interface may be covered by screen |
| 2264 | * decorations when they are shown. You can perform layout of your inner |
| 2265 | * UI elements to account for non-fullscreen system UI through the |
| 2266 | * {@link #fitSystemWindows(Rect)} method. |
| 2267 | */ |
| 2268 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2269 | |
| 2270 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2271 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2272 | */ |
| 2273 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2274 | |
| 2275 | /** |
| 2276 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2277 | */ |
| 2278 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2279 | |
| 2280 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2281 | * @hide |
| 2282 | * |
| 2283 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2284 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2285 | * |
| 2286 | * Flag to make the status bar not expandable. Unless you also |
| 2287 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2288 | */ |
| 2289 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2290 | |
| 2291 | /** |
| 2292 | * @hide |
| 2293 | * |
| 2294 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2295 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2296 | * |
| 2297 | * Flag to hide notification icons and scrolling ticker text. |
| 2298 | */ |
| 2299 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2300 | |
| 2301 | /** |
| 2302 | * @hide |
| 2303 | * |
| 2304 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2305 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2306 | * |
| 2307 | * Flag to disable incoming notification alerts. This will not block |
| 2308 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2309 | */ |
| 2310 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2311 | |
| 2312 | /** |
| 2313 | * @hide |
| 2314 | * |
| 2315 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2316 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2317 | * |
| 2318 | * Flag to hide only the scrolling ticker. Note that |
| 2319 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2320 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2321 | */ |
| 2322 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2323 | |
| 2324 | /** |
| 2325 | * @hide |
| 2326 | * |
| 2327 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2328 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2329 | * |
| 2330 | * Flag to hide the center system info area. |
| 2331 | */ |
| 2332 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2333 | |
| 2334 | /** |
| 2335 | * @hide |
| 2336 | * |
| 2337 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2338 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2339 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2340 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2341 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2342 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2343 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2344 | |
| 2345 | /** |
| 2346 | * @hide |
| 2347 | * |
| 2348 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2349 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2350 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2351 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2352 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2353 | */ |
| 2354 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2355 | |
| 2356 | /** |
| 2357 | * @hide |
| 2358 | * |
| 2359 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2360 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2361 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2362 | * Flag to hide only the clock. You might use this if your activity has |
| 2363 | * its own clock making the status bar's clock redundant. |
| 2364 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2365 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2366 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2367 | /** |
| 2368 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2369 | * |
| 2370 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2371 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2372 | * |
| 2373 | * Flag to hide only the recent apps button. Don't use this |
| 2374 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2375 | */ |
| 2376 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2377 | |
| 2378 | /** |
| 2379 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2380 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2381 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2382 | |
| 2383 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2384 | * These are the system UI flags that can be cleared by events outside |
| 2385 | * of an application. Currently this is just the ability to tap on the |
| 2386 | * screen while hiding the navigation bar to have it return. |
| 2387 | * @hide |
| 2388 | */ |
| 2389 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2390 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2391 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2392 | |
| 2393 | /** |
| 2394 | * Flags that can impact the layout in relation to system UI. |
| 2395 | */ |
| 2396 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2397 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2398 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2399 | |
| 2400 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2401 | * Find views that render the specified text. |
| 2402 | * |
| 2403 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2404 | */ |
| 2405 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2406 | |
| 2407 | /** |
| 2408 | * Find find views that contain the specified content description. |
| 2409 | * |
| 2410 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2411 | */ |
| 2412 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2413 | |
| 2414 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2415 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2416 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2417 | * text. If this flag is set Views with providers are automatically |
| 2418 | * added and it is a responsibility of the client to call the APIs of |
| 2419 | * the provider to determine whether the virtual tree rooted at this View |
| 2420 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2421 | * represeting the virtual views with this text. |
| 2422 | * |
| 2423 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2424 | * |
| 2425 | * @hide |
| 2426 | */ |
| 2427 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2428 | |
| 2429 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2430 | * Indicates that the screen has changed state and is now off. |
| 2431 | * |
| 2432 | * @see #onScreenStateChanged(int) |
| 2433 | */ |
| 2434 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2435 | |
| 2436 | /** |
| 2437 | * Indicates that the screen has changed state and is now on. |
| 2438 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2439 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2440 | */ |
| 2441 | public static final int SCREEN_STATE_ON = 0x1; |
| 2442 | |
| 2443 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2444 | * Controls the over-scroll mode for this view. |
| 2445 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2446 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2447 | * and {@link #OVER_SCROLL_NEVER}. |
| 2448 | */ |
| 2449 | private int mOverScrollMode; |
| 2450 | |
| 2451 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2452 | * The parent this view is attached to. |
| 2453 | * {@hide} |
| 2454 | * |
| 2455 | * @see #getParent() |
| 2456 | */ |
| 2457 | protected ViewParent mParent; |
| 2458 | |
| 2459 | /** |
| 2460 | * {@hide} |
| 2461 | */ |
| 2462 | AttachInfo mAttachInfo; |
| 2463 | |
| 2464 | /** |
| 2465 | * {@hide} |
| 2466 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2467 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2468 | @ViewDebug.FlagToString(mask = FORCE_LAYOUT, equals = FORCE_LAYOUT, |
| 2469 | name = "FORCE_LAYOUT"), |
| 2470 | @ViewDebug.FlagToString(mask = LAYOUT_REQUIRED, equals = LAYOUT_REQUIRED, |
| 2471 | name = "LAYOUT_REQUIRED"), |
| 2472 | @ViewDebug.FlagToString(mask = DRAWING_CACHE_VALID, equals = DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2473 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2474 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "DRAWN", outputIf = true), |
| 2475 | @ViewDebug.FlagToString(mask = DRAWN, equals = DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2476 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2477 | @ViewDebug.FlagToString(mask = DIRTY_MASK, equals = DIRTY, name = "DIRTY") |
| 2478 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2479 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2480 | int mPrivateFlags2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | |
| 2482 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2483 | * This view's request for the visibility of the status bar. |
| 2484 | * @hide |
| 2485 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2486 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2487 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2488 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2489 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2490 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2491 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2492 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2493 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2494 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2495 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2496 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2497 | int mSystemUiVisibility; |
| 2498 | |
| 2499 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 2500 | * Reference count for transient state. |
| 2501 | * @see #setHasTransientState(boolean) |
| 2502 | */ |
| 2503 | int mTransientStateCount = 0; |
| 2504 | |
| 2505 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | * Count of how many windows this view has been attached to. |
| 2507 | */ |
| 2508 | int mWindowAttachCount; |
| 2509 | |
| 2510 | /** |
| 2511 | * The layout parameters associated with this view and used by the parent |
| 2512 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2513 | * laid out. |
| 2514 | * {@hide} |
| 2515 | */ |
| 2516 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2517 | |
| 2518 | /** |
| 2519 | * The view flags hold various views states. |
| 2520 | * {@hide} |
| 2521 | */ |
| 2522 | @ViewDebug.ExportedProperty |
| 2523 | int mViewFlags; |
| 2524 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2525 | static class TransformationInfo { |
| 2526 | /** |
| 2527 | * The transform matrix for the View. This transform is calculated internally |
| 2528 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2529 | * is used by default. Do *not* use this variable directly; instead call |
| 2530 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2531 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2532 | */ |
| 2533 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2534 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2535 | /** |
| 2536 | * The transform matrix for the View. This transform is calculated internally |
| 2537 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2538 | * is used by default. Do *not* use this variable directly; instead call |
| 2539 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2540 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2541 | */ |
| 2542 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2543 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2544 | /** |
| 2545 | * An internal variable that tracks whether we need to recalculate the |
| 2546 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2547 | * have changed since the matrix was last calculated. |
| 2548 | */ |
| 2549 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2550 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2551 | /** |
| 2552 | * An internal variable that tracks whether we need to recalculate the |
| 2553 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2554 | * have changed since the matrix was last calculated. |
| 2555 | */ |
| 2556 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2557 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2558 | /** |
| 2559 | * A variable that tracks whether we need to recalculate the |
| 2560 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2561 | * have changed since the matrix was last calculated. This variable |
| 2562 | * is only valid after a call to updateMatrix() or to a function that |
| 2563 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2564 | */ |
| 2565 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2566 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2567 | /** |
| 2568 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2569 | */ |
| 2570 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2571 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2572 | /** |
| 2573 | * This matrix is used when computing the matrix for 3D rotations. |
| 2574 | */ |
| 2575 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2576 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2577 | /** |
| 2578 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2579 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2580 | * set), so thes values are only used then as well. |
| 2581 | */ |
| 2582 | private int mPrevWidth = -1; |
| 2583 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2584 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * The degrees rotation around the vertical axis through the pivot point. |
| 2587 | */ |
| 2588 | @ViewDebug.ExportedProperty |
| 2589 | float mRotationY = 0f; |
| 2590 | |
| 2591 | /** |
| 2592 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2593 | */ |
| 2594 | @ViewDebug.ExportedProperty |
| 2595 | float mRotationX = 0f; |
| 2596 | |
| 2597 | /** |
| 2598 | * The degrees rotation around the pivot point. |
| 2599 | */ |
| 2600 | @ViewDebug.ExportedProperty |
| 2601 | float mRotation = 0f; |
| 2602 | |
| 2603 | /** |
| 2604 | * The amount of translation of the object away from its left property (post-layout). |
| 2605 | */ |
| 2606 | @ViewDebug.ExportedProperty |
| 2607 | float mTranslationX = 0f; |
| 2608 | |
| 2609 | /** |
| 2610 | * The amount of translation of the object away from its top property (post-layout). |
| 2611 | */ |
| 2612 | @ViewDebug.ExportedProperty |
| 2613 | float mTranslationY = 0f; |
| 2614 | |
| 2615 | /** |
| 2616 | * The amount of scale in the x direction around the pivot point. A |
| 2617 | * value of 1 means no scaling is applied. |
| 2618 | */ |
| 2619 | @ViewDebug.ExportedProperty |
| 2620 | float mScaleX = 1f; |
| 2621 | |
| 2622 | /** |
| 2623 | * The amount of scale in the y direction around the pivot point. A |
| 2624 | * value of 1 means no scaling is applied. |
| 2625 | */ |
| 2626 | @ViewDebug.ExportedProperty |
| 2627 | float mScaleY = 1f; |
| 2628 | |
| 2629 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2630 | * The x location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2631 | */ |
| 2632 | @ViewDebug.ExportedProperty |
| 2633 | float mPivotX = 0f; |
| 2634 | |
| 2635 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2636 | * The y location of the point around which the view is rotated and scaled. |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2637 | */ |
| 2638 | @ViewDebug.ExportedProperty |
| 2639 | float mPivotY = 0f; |
| 2640 | |
| 2641 | /** |
| 2642 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2643 | * completely transparent and 1 means completely opaque. |
| 2644 | */ |
| 2645 | @ViewDebug.ExportedProperty |
| 2646 | float mAlpha = 1f; |
| 2647 | } |
| 2648 | |
| 2649 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2650 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2651 | private boolean mLastIsOpaque; |
| 2652 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2653 | /** |
| 2654 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2655 | * zero. |
| 2656 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2657 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2658 | |
| 2659 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | * The distance in pixels from the left edge of this view's parent |
| 2661 | * to the left edge of this view. |
| 2662 | * {@hide} |
| 2663 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2664 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | protected int mLeft; |
| 2666 | /** |
| 2667 | * The distance in pixels from the left edge of this view's parent |
| 2668 | * to the right edge of this view. |
| 2669 | * {@hide} |
| 2670 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2671 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | protected int mRight; |
| 2673 | /** |
| 2674 | * The distance in pixels from the top edge of this view's parent |
| 2675 | * to the top edge of this view. |
| 2676 | * {@hide} |
| 2677 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2678 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | protected int mTop; |
| 2680 | /** |
| 2681 | * The distance in pixels from the top edge of this view's parent |
| 2682 | * to the bottom edge of this view. |
| 2683 | * {@hide} |
| 2684 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2685 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2686 | protected int mBottom; |
| 2687 | |
| 2688 | /** |
| 2689 | * The offset, in pixels, by which the content of this view is scrolled |
| 2690 | * horizontally. |
| 2691 | * {@hide} |
| 2692 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2693 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | protected int mScrollX; |
| 2695 | /** |
| 2696 | * The offset, in pixels, by which the content of this view is scrolled |
| 2697 | * vertically. |
| 2698 | * {@hide} |
| 2699 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2700 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2701 | protected int mScrollY; |
| 2702 | |
| 2703 | /** |
| 2704 | * The left padding in pixels, that is the distance in pixels between the |
| 2705 | * left edge of this view and the left edge of its content. |
| 2706 | * {@hide} |
| 2707 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2708 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | protected int mPaddingLeft; |
| 2710 | /** |
| 2711 | * The right padding in pixels, that is the distance in pixels between the |
| 2712 | * right edge of this view and the right edge of its content. |
| 2713 | * {@hide} |
| 2714 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2715 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | protected int mPaddingRight; |
| 2717 | /** |
| 2718 | * The top padding in pixels, that is the distance in pixels between the |
| 2719 | * top edge of this view and the top edge of its content. |
| 2720 | * {@hide} |
| 2721 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2722 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | protected int mPaddingTop; |
| 2724 | /** |
| 2725 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2726 | * bottom edge of this view and the bottom edge of its content. |
| 2727 | * {@hide} |
| 2728 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2729 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | protected int mPaddingBottom; |
| 2731 | |
| 2732 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2733 | * The layout insets in pixels, that is the distance in pixels between the |
| 2734 | * visible edges of this view its bounds. |
| 2735 | */ |
| 2736 | private Insets mLayoutInsets; |
| 2737 | |
| 2738 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2739 | * Briefly describes the view and is primarily used for accessibility support. |
| 2740 | */ |
| 2741 | private CharSequence mContentDescription; |
| 2742 | |
| 2743 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | * Cache the paddingRight set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2745 | * |
| 2746 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2747 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2748 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2749 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | |
| 2751 | /** |
| 2752 | * Cache the paddingBottom set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2753 | * |
| 2754 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2756 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2757 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2759 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2760 | * Cache the paddingLeft set by the user to append to the scrollbar's size. |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2761 | * |
| 2762 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2763 | */ |
| 2764 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2765 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2766 | |
| 2767 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2768 | * Cache if the user padding is relative. |
| 2769 | * |
| 2770 | */ |
| 2771 | @ViewDebug.ExportedProperty(category = "padding") |
| 2772 | boolean mUserPaddingRelative; |
| 2773 | |
| 2774 | /** |
| 2775 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2776 | * |
| 2777 | */ |
| 2778 | @ViewDebug.ExportedProperty(category = "padding") |
| 2779 | int mUserPaddingStart; |
| 2780 | |
| 2781 | /** |
| 2782 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2783 | * |
| 2784 | */ |
| 2785 | @ViewDebug.ExportedProperty(category = "padding") |
| 2786 | int mUserPaddingEnd; |
| 2787 | |
| 2788 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2789 | * @hide |
| 2790 | */ |
| 2791 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2792 | /** |
| 2793 | * @hide |
| 2794 | */ |
| 2795 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2796 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2797 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | |
| 2799 | private int mBackgroundResource; |
| 2800 | private boolean mBackgroundSizeChanged; |
| 2801 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2802 | static class ListenerInfo { |
| 2803 | /** |
| 2804 | * Listener used to dispatch focus change events. |
| 2805 | * This field should be made private, so it is hidden from the SDK. |
| 2806 | * {@hide} |
| 2807 | */ |
| 2808 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2810 | /** |
| 2811 | * Listeners for layout change events. |
| 2812 | */ |
| 2813 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2814 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2815 | /** |
| 2816 | * Listeners for attach events. |
| 2817 | */ |
| 2818 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2819 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2820 | /** |
| 2821 | * Listener used to dispatch click events. |
| 2822 | * This field should be made private, so it is hidden from the SDK. |
| 2823 | * {@hide} |
| 2824 | */ |
| 2825 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2827 | /** |
| 2828 | * Listener used to dispatch long click events. |
| 2829 | * This field should be made private, so it is hidden from the SDK. |
| 2830 | * {@hide} |
| 2831 | */ |
| 2832 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2834 | /** |
| 2835 | * Listener used to build the context menu. |
| 2836 | * This field should be made private, so it is hidden from the SDK. |
| 2837 | * {@hide} |
| 2838 | */ |
| 2839 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2841 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2843 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2845 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2846 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2847 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2848 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2849 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2850 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2851 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2852 | } |
| 2853 | |
| 2854 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2855 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | /** |
| 2857 | * The application environment this view lives in. |
| 2858 | * This field should be made private, so it is hidden from the SDK. |
| 2859 | * {@hide} |
| 2860 | */ |
| 2861 | protected Context mContext; |
| 2862 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2863 | private final Resources mResources; |
| 2864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | private ScrollabilityCache mScrollCache; |
| 2866 | |
| 2867 | private int[] mDrawableState = null; |
| 2868 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2869 | /** |
| 2870 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2871 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2872 | * @hide |
| 2873 | */ |
| 2874 | public boolean mCachingFailed; |
| 2875 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2876 | private Bitmap mDrawingCache; |
| 2877 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2878 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2879 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | |
| 2881 | /** |
| 2882 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2883 | * the user may specify which view to go to next. |
| 2884 | */ |
| 2885 | private int mNextFocusLeftId = View.NO_ID; |
| 2886 | |
| 2887 | /** |
| 2888 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2889 | * the user may specify which view to go to next. |
| 2890 | */ |
| 2891 | private int mNextFocusRightId = View.NO_ID; |
| 2892 | |
| 2893 | /** |
| 2894 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2895 | * the user may specify which view to go to next. |
| 2896 | */ |
| 2897 | private int mNextFocusUpId = View.NO_ID; |
| 2898 | |
| 2899 | /** |
| 2900 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2901 | * the user may specify which view to go to next. |
| 2902 | */ |
| 2903 | private int mNextFocusDownId = View.NO_ID; |
| 2904 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2905 | /** |
| 2906 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2907 | * the user may specify which view to go to next. |
| 2908 | */ |
| 2909 | int mNextFocusForwardId = View.NO_ID; |
| 2910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2912 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2913 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2914 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | private UnsetPressedState mUnsetPressedState; |
| 2917 | |
| 2918 | /** |
| 2919 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2920 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2921 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2922 | * should not be invoked. |
| 2923 | */ |
| 2924 | private boolean mHasPerformedLongPress; |
| 2925 | |
| 2926 | /** |
| 2927 | * The minimum height of the view. We'll try our best to have the height |
| 2928 | * of this view to at least this amount. |
| 2929 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2930 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | private int mMinHeight; |
| 2932 | |
| 2933 | /** |
| 2934 | * The minimum width of the view. We'll try our best to have the width |
| 2935 | * of this view to at least this amount. |
| 2936 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2937 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | private int mMinWidth; |
| 2939 | |
| 2940 | /** |
| 2941 | * The delegate to handle touch events that are physically in this view |
| 2942 | * but should be handled by another view. |
| 2943 | */ |
| 2944 | private TouchDelegate mTouchDelegate = null; |
| 2945 | |
| 2946 | /** |
| 2947 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2948 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2949 | */ |
| 2950 | private int mDrawingCacheBackgroundColor = 0; |
| 2951 | |
| 2952 | /** |
| 2953 | * Special tree observer used when mAttachInfo is null. |
| 2954 | */ |
| 2955 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2956 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2957 | /** |
| 2958 | * Cache the touch slop from the context that created the view. |
| 2959 | */ |
| 2960 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2963 | * Object that handles automatic animation of view properties. |
| 2964 | */ |
| 2965 | private ViewPropertyAnimator mAnimator = null; |
| 2966 | |
| 2967 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2968 | * Flag indicating that a drag can cross window boundaries. When |
| 2969 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 2970 | * with this flag set, all visible applications will be able to participate |
| 2971 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 2972 | * |
| 2973 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 2974 | */ |
| 2975 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 2976 | |
| 2977 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2978 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 2979 | */ |
| 2980 | private float mVerticalScrollFactor; |
| 2981 | |
| 2982 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2983 | * Position of the vertical scroll bar. |
| 2984 | */ |
| 2985 | private int mVerticalScrollbarPosition; |
| 2986 | |
| 2987 | /** |
| 2988 | * Position the scroll bar at the default position as determined by the system. |
| 2989 | */ |
| 2990 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 2991 | |
| 2992 | /** |
| 2993 | * Position the scroll bar along the left edge. |
| 2994 | */ |
| 2995 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 2996 | |
| 2997 | /** |
| 2998 | * Position the scroll bar along the right edge. |
| 2999 | */ |
| 3000 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 3001 | |
| 3002 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3003 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3004 | * |
| 3005 | * @see #getLayerType() |
| 3006 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3007 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3008 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3009 | */ |
| 3010 | public static final int LAYER_TYPE_NONE = 0; |
| 3011 | |
| 3012 | /** |
| 3013 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 3014 | * by a bitmap and causes the view to be rendered using Android's software |
| 3015 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3016 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3017 | * <p>Software layers have various usages:</p> |
| 3018 | * <p>When the application is not using hardware acceleration, a software layer |
| 3019 | * is useful to apply a specific color filter and/or blending mode and/or |
| 3020 | * translucency to a view and all its children.</p> |
| 3021 | * <p>When the application is using hardware acceleration, a software layer |
| 3022 | * is useful to render drawing primitives not supported by the hardware |
| 3023 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 3024 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3025 | * when animating a complex view tree with a translation, a software layer can |
| 3026 | * be used to render the view tree only once.</p> |
| 3027 | * <p>Software layers should be avoided when the affected view tree updates |
| 3028 | * often. Every update will require to re-render the software layer, which can |
| 3029 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3030 | * since the layer will have to be uploaded into a hardware texture after every |
| 3031 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3032 | * |
| 3033 | * @see #getLayerType() |
| 3034 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3035 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3036 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3037 | */ |
| 3038 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3039 | |
| 3040 | /** |
| 3041 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3042 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3043 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3044 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3045 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3046 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3047 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3048 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3049 | * blending mode and/or translucency to a view and all its children.</p> |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 3050 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3051 | * texture and reduce the complexity of drawing operations. For instance, |
| 3052 | * when animating a complex view tree with a translation, a hardware layer can |
| 3053 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3054 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3055 | * rotation transformations are applied on a view. It can also be used to |
| 3056 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3057 | * |
| 3058 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3059 | * @see #setLayerType(int, android.graphics.Paint) |
| 3060 | * @see #LAYER_TYPE_NONE |
| 3061 | * @see #LAYER_TYPE_SOFTWARE |
| 3062 | */ |
| 3063 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3064 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3065 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3066 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3067 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3068 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3069 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3070 | int mLayerType = LAYER_TYPE_NONE; |
| 3071 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3072 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3073 | |
| 3074 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3075 | * Set to true when the view is sending hover accessibility events because it |
| 3076 | * is the innermost hovered view. |
| 3077 | */ |
| 3078 | private boolean mSendingHoverAccessibilityEvents; |
| 3079 | |
| 3080 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | * Simple constructor to use when creating a view from code. |
| 3082 | * |
| 3083 | * @param context The Context the view is running in, through which it can |
| 3084 | * access the current theme, resources, etc. |
| 3085 | */ |
| 3086 | public View(Context context) { |
| 3087 | mContext = context; |
| 3088 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3089 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3090 | // Set layout and text direction defaults |
| 3091 | mPrivateFlags2 = (LAYOUT_DIRECTION_DEFAULT << LAYOUT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3092 | (TEXT_DIRECTION_DEFAULT << TEXT_DIRECTION_MASK_SHIFT) | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3093 | (TEXT_ALIGNMENT_DEFAULT << TEXT_ALIGNMENT_MASK_SHIFT) | |
| 3094 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3095 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3096 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3097 | mUserPaddingStart = -1; |
| 3098 | mUserPaddingEnd = -1; |
| 3099 | mUserPaddingRelative = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 3103 | * Delegate for injecting accessiblity functionality. |
| 3104 | */ |
| 3105 | AccessibilityDelegate mAccessibilityDelegate; |
| 3106 | |
| 3107 | /** |
| 3108 | * Consistency verifier for debugging purposes. |
| 3109 | * @hide |
| 3110 | */ |
| 3111 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3112 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3113 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3114 | |
| 3115 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | * Constructor that is called when inflating a view from XML. This is called |
| 3117 | * when a view is being constructed from an XML file, supplying attributes |
| 3118 | * that were specified in the XML file. This version uses a default style of |
| 3119 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3120 | * and the given AttributeSet. |
| 3121 | * |
| 3122 | * <p> |
| 3123 | * The method onFinishInflate() will be called after all children have been |
| 3124 | * added. |
| 3125 | * |
| 3126 | * @param context The Context the view is running in, through which it can |
| 3127 | * access the current theme, resources, etc. |
| 3128 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3129 | * @see #View(Context, AttributeSet, int) |
| 3130 | */ |
| 3131 | public View(Context context, AttributeSet attrs) { |
| 3132 | this(context, attrs, 0); |
| 3133 | } |
| 3134 | |
| 3135 | /** |
| 3136 | * Perform inflation from XML and apply a class-specific base style. This |
| 3137 | * constructor of View allows subclasses to use their own base style when |
| 3138 | * they are inflating. For example, a Button class's constructor would call |
| 3139 | * this version of the super class constructor and supply |
| 3140 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3141 | * the theme's button style to modify all of the base view attributes (in |
| 3142 | * particular its background) as well as the Button class's attributes. |
| 3143 | * |
| 3144 | * @param context The Context the view is running in, through which it can |
| 3145 | * access the current theme, resources, etc. |
| 3146 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3147 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3148 | * will be applied (beyond what is included in the theme). This may |
| 3149 | * either be an attribute resource, whose value will be retrieved |
| 3150 | * from the current theme, or an explicit style resource. |
| 3151 | * @see #View(Context, AttributeSet) |
| 3152 | */ |
| 3153 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3154 | this(context); |
| 3155 | |
| 3156 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3157 | defStyle, 0); |
| 3158 | |
| 3159 | Drawable background = null; |
| 3160 | |
| 3161 | int leftPadding = -1; |
| 3162 | int topPadding = -1; |
| 3163 | int rightPadding = -1; |
| 3164 | int bottomPadding = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3165 | int startPadding = -1; |
| 3166 | int endPadding = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | |
| 3168 | int padding = -1; |
| 3169 | |
| 3170 | int viewFlagValues = 0; |
| 3171 | int viewFlagMasks = 0; |
| 3172 | |
| 3173 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3175 | int x = 0; |
| 3176 | int y = 0; |
| 3177 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3178 | float tx = 0; |
| 3179 | float ty = 0; |
| 3180 | float rotation = 0; |
| 3181 | float rotationX = 0; |
| 3182 | float rotationY = 0; |
| 3183 | float sx = 1f; |
| 3184 | float sy = 1f; |
| 3185 | boolean transformSet = false; |
| 3186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
| 3188 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3189 | int overScrollMode = mOverScrollMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | final int N = a.getIndexCount(); |
| 3191 | for (int i = 0; i < N; i++) { |
| 3192 | int attr = a.getIndex(i); |
| 3193 | switch (attr) { |
| 3194 | case com.android.internal.R.styleable.View_background: |
| 3195 | background = a.getDrawable(attr); |
| 3196 | break; |
| 3197 | case com.android.internal.R.styleable.View_padding: |
| 3198 | padding = a.getDimensionPixelSize(attr, -1); |
| 3199 | break; |
| 3200 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3201 | leftPadding = a.getDimensionPixelSize(attr, -1); |
| 3202 | break; |
| 3203 | case com.android.internal.R.styleable.View_paddingTop: |
| 3204 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3205 | break; |
| 3206 | case com.android.internal.R.styleable.View_paddingRight: |
| 3207 | rightPadding = a.getDimensionPixelSize(attr, -1); |
| 3208 | break; |
| 3209 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3210 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3211 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3212 | case com.android.internal.R.styleable.View_paddingStart: |
| 3213 | startPadding = a.getDimensionPixelSize(attr, -1); |
| 3214 | break; |
| 3215 | case com.android.internal.R.styleable.View_paddingEnd: |
| 3216 | endPadding = a.getDimensionPixelSize(attr, -1); |
| 3217 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | case com.android.internal.R.styleable.View_scrollX: |
| 3219 | x = a.getDimensionPixelOffset(attr, 0); |
| 3220 | break; |
| 3221 | case com.android.internal.R.styleable.View_scrollY: |
| 3222 | y = a.getDimensionPixelOffset(attr, 0); |
| 3223 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3224 | case com.android.internal.R.styleable.View_alpha: |
| 3225 | setAlpha(a.getFloat(attr, 1f)); |
| 3226 | break; |
| 3227 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3228 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3229 | break; |
| 3230 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3231 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3232 | break; |
| 3233 | case com.android.internal.R.styleable.View_translationX: |
| 3234 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3235 | transformSet = true; |
| 3236 | break; |
| 3237 | case com.android.internal.R.styleable.View_translationY: |
| 3238 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3239 | transformSet = true; |
| 3240 | break; |
| 3241 | case com.android.internal.R.styleable.View_rotation: |
| 3242 | rotation = a.getFloat(attr, 0); |
| 3243 | transformSet = true; |
| 3244 | break; |
| 3245 | case com.android.internal.R.styleable.View_rotationX: |
| 3246 | rotationX = a.getFloat(attr, 0); |
| 3247 | transformSet = true; |
| 3248 | break; |
| 3249 | case com.android.internal.R.styleable.View_rotationY: |
| 3250 | rotationY = a.getFloat(attr, 0); |
| 3251 | transformSet = true; |
| 3252 | break; |
| 3253 | case com.android.internal.R.styleable.View_scaleX: |
| 3254 | sx = a.getFloat(attr, 1f); |
| 3255 | transformSet = true; |
| 3256 | break; |
| 3257 | case com.android.internal.R.styleable.View_scaleY: |
| 3258 | sy = a.getFloat(attr, 1f); |
| 3259 | transformSet = true; |
| 3260 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | case com.android.internal.R.styleable.View_id: |
| 3262 | mID = a.getResourceId(attr, NO_ID); |
| 3263 | break; |
| 3264 | case com.android.internal.R.styleable.View_tag: |
| 3265 | mTag = a.getText(attr); |
| 3266 | break; |
| 3267 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3268 | if (a.getBoolean(attr, false)) { |
| 3269 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3270 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3271 | } |
| 3272 | break; |
| 3273 | case com.android.internal.R.styleable.View_focusable: |
| 3274 | if (a.getBoolean(attr, false)) { |
| 3275 | viewFlagValues |= FOCUSABLE; |
| 3276 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3277 | } |
| 3278 | break; |
| 3279 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3280 | if (a.getBoolean(attr, false)) { |
| 3281 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3282 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3283 | } |
| 3284 | break; |
| 3285 | case com.android.internal.R.styleable.View_clickable: |
| 3286 | if (a.getBoolean(attr, false)) { |
| 3287 | viewFlagValues |= CLICKABLE; |
| 3288 | viewFlagMasks |= CLICKABLE; |
| 3289 | } |
| 3290 | break; |
| 3291 | case com.android.internal.R.styleable.View_longClickable: |
| 3292 | if (a.getBoolean(attr, false)) { |
| 3293 | viewFlagValues |= LONG_CLICKABLE; |
| 3294 | viewFlagMasks |= LONG_CLICKABLE; |
| 3295 | } |
| 3296 | break; |
| 3297 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3298 | if (!a.getBoolean(attr, true)) { |
| 3299 | viewFlagValues |= SAVE_DISABLED; |
| 3300 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3301 | } |
| 3302 | break; |
| 3303 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3304 | if (a.getBoolean(attr, false)) { |
| 3305 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3306 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3307 | } |
| 3308 | break; |
| 3309 | case com.android.internal.R.styleable.View_visibility: |
| 3310 | final int visibility = a.getInt(attr, 0); |
| 3311 | if (visibility != 0) { |
| 3312 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3313 | viewFlagMasks |= VISIBILITY_MASK; |
| 3314 | } |
| 3315 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3316 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3317 | // Clear any layout direction flags (included resolved bits) already set |
| 3318 | mPrivateFlags2 &= ~(LAYOUT_DIRECTION_MASK | LAYOUT_DIRECTION_RESOLVED_MASK); |
| 3319 | // Set the layout direction flags depending on the value of the attribute |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3320 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3321 | final int value = (layoutDirection != -1) ? |
| 3322 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
| 3323 | mPrivateFlags2 |= (value << LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3324 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3326 | final int cacheQuality = a.getInt(attr, 0); |
| 3327 | if (cacheQuality != 0) { |
| 3328 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3329 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3330 | } |
| 3331 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3332 | case com.android.internal.R.styleable.View_contentDescription: |
| 3333 | mContentDescription = a.getString(attr); |
| 3334 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3336 | if (!a.getBoolean(attr, true)) { |
| 3337 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3338 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3339 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3340 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3342 | if (!a.getBoolean(attr, true)) { |
| 3343 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3344 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3345 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3346 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3347 | case R.styleable.View_scrollbars: |
| 3348 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3349 | if (scrollbars != SCROLLBARS_NONE) { |
| 3350 | viewFlagValues |= scrollbars; |
| 3351 | viewFlagMasks |= SCROLLBARS_MASK; |
| 3352 | initializeScrollbars(a); |
| 3353 | } |
| 3354 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3355 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | case R.styleable.View_fadingEdge: |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3357 | if (context.getApplicationInfo().targetSdkVersion >= ICE_CREAM_SANDWICH) { |
| 3358 | // Ignore the attribute starting with ICS |
| 3359 | break; |
| 3360 | } |
| 3361 | // With builds < ICS, fall through and apply fading edges |
| 3362 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3364 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3365 | viewFlagValues |= fadingEdge; |
| 3366 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3367 | initializeFadingEdge(a); |
| 3368 | } |
| 3369 | break; |
| 3370 | case R.styleable.View_scrollbarStyle: |
| 3371 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3372 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3373 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3374 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3375 | } |
| 3376 | break; |
| 3377 | case R.styleable.View_isScrollContainer: |
| 3378 | setScrollContainer = true; |
| 3379 | if (a.getBoolean(attr, false)) { |
| 3380 | setScrollContainer(true); |
| 3381 | } |
| 3382 | break; |
| 3383 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3384 | if (a.getBoolean(attr, false)) { |
| 3385 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3386 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3387 | } |
| 3388 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3389 | case R.styleable.View_filterTouchesWhenObscured: |
| 3390 | if (a.getBoolean(attr, false)) { |
| 3391 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3392 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3393 | } |
| 3394 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | case R.styleable.View_nextFocusLeft: |
| 3396 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3397 | break; |
| 3398 | case R.styleable.View_nextFocusRight: |
| 3399 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3400 | break; |
| 3401 | case R.styleable.View_nextFocusUp: |
| 3402 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3403 | break; |
| 3404 | case R.styleable.View_nextFocusDown: |
| 3405 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3406 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3407 | case R.styleable.View_nextFocusForward: |
| 3408 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3409 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | case R.styleable.View_minWidth: |
| 3411 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3412 | break; |
| 3413 | case R.styleable.View_minHeight: |
| 3414 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3415 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3416 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3417 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3418 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3419 | + "be used within a restricted context"); |
| 3420 | } |
| 3421 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3422 | final String handlerName = a.getString(attr); |
| 3423 | if (handlerName != null) { |
| 3424 | setOnClickListener(new OnClickListener() { |
| 3425 | private Method mHandler; |
| 3426 | |
| 3427 | public void onClick(View v) { |
| 3428 | if (mHandler == null) { |
| 3429 | try { |
| 3430 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3431 | View.class); |
| 3432 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3433 | int id = getId(); |
| 3434 | String idText = id == NO_ID ? "" : " with id '" |
| 3435 | + getContext().getResources().getResourceEntryName( |
| 3436 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3437 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3438 | handlerName + "(View) in the activity " |
| 3439 | + getContext().getClass() + " for onClick handler" |
| 3440 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | try { |
| 3445 | mHandler.invoke(getContext(), View.this); |
| 3446 | } catch (IllegalAccessException e) { |
| 3447 | throw new IllegalStateException("Could not execute non " |
| 3448 | + "public method of the activity", e); |
| 3449 | } catch (InvocationTargetException e) { |
| 3450 | throw new IllegalStateException("Could not execute " |
| 3451 | + "method of the activity", e); |
| 3452 | } |
| 3453 | } |
| 3454 | }); |
| 3455 | } |
| 3456 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3457 | case R.styleable.View_overScrollMode: |
| 3458 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3459 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3460 | case R.styleable.View_verticalScrollbarPosition: |
| 3461 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3462 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3463 | case R.styleable.View_layerType: |
| 3464 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3465 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3466 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3467 | // Clear any text direction flag already set |
| 3468 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
| 3469 | // Set the text direction flags depending on the value of the attribute |
| 3470 | final int textDirection = a.getInt(attr, -1); |
| 3471 | if (textDirection != -1) { |
| 3472 | mPrivateFlags2 |= TEXT_DIRECTION_FLAGS[textDirection]; |
| 3473 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3474 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3475 | case R.styleable.View_textAlignment: |
| 3476 | // Clear any text alignment flag already set |
| 3477 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 3478 | // Set the text alignment flag depending on the value of the attribute |
| 3479 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
| 3480 | mPrivateFlags2 |= TEXT_ALIGNMENT_FLAGS[textAlignment]; |
| 3481 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3482 | case R.styleable.View_importantForAccessibility: |
| 3483 | setImportantForAccessibility(a.getInt(attr, |
| 3484 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | } |
| 3486 | } |
| 3487 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3488 | a.recycle(); |
| 3489 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3490 | setOverScrollMode(overScrollMode); |
| 3491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | if (background != null) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3493 | setBackground(background); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | } |
| 3495 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3496 | // Cache user padding as we cannot fully resolve padding here (we dont have yet the resolved |
| 3497 | // layout direction). Those cached values will be used later during padding resolution. |
| 3498 | mUserPaddingStart = startPadding; |
| 3499 | mUserPaddingEnd = endPadding; |
| 3500 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3501 | updateUserPaddingRelative(); |
| 3502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | if (padding >= 0) { |
| 3504 | leftPadding = padding; |
| 3505 | topPadding = padding; |
| 3506 | rightPadding = padding; |
| 3507 | bottomPadding = padding; |
| 3508 | } |
| 3509 | |
| 3510 | // If the user specified the padding (either with android:padding or |
| 3511 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3512 | // use the default padding or the padding from the background drawable |
| 3513 | // (stored at this point in mPadding*) |
| 3514 | setPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
| 3515 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3516 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3517 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3518 | |
| 3519 | if (viewFlagMasks != 0) { |
| 3520 | setFlags(viewFlagValues, viewFlagMasks); |
| 3521 | } |
| 3522 | |
| 3523 | // Needs to be called after mViewFlags is set |
| 3524 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3525 | recomputePadding(); |
| 3526 | } |
| 3527 | |
| 3528 | if (x != 0 || y != 0) { |
| 3529 | scrollTo(x, y); |
| 3530 | } |
| 3531 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3532 | if (transformSet) { |
| 3533 | setTranslationX(tx); |
| 3534 | setTranslationY(ty); |
| 3535 | setRotation(rotation); |
| 3536 | setRotationX(rotationX); |
| 3537 | setRotationY(rotationY); |
| 3538 | setScaleX(sx); |
| 3539 | setScaleY(sy); |
| 3540 | } |
| 3541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3543 | setScrollContainer(true); |
| 3544 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3545 | |
| 3546 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3549 | private void updateUserPaddingRelative() { |
| 3550 | mUserPaddingRelative = (mUserPaddingStart >= 0 || mUserPaddingEnd >= 0); |
| 3551 | } |
| 3552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | /** |
| 3554 | * Non-public constructor for use in testing |
| 3555 | */ |
| 3556 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3557 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | } |
| 3559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | /** |
| 3561 | * <p> |
| 3562 | * Initializes the fading edges from a given set of styled attributes. This |
| 3563 | * method should be called by subclasses that need fading edges and when an |
| 3564 | * instance of these subclasses is created programmatically rather than |
| 3565 | * being inflated from XML. This method is automatically called when the XML |
| 3566 | * is inflated. |
| 3567 | * </p> |
| 3568 | * |
| 3569 | * @param a the styled attributes set to initialize the fading edges from |
| 3570 | */ |
| 3571 | protected void initializeFadingEdge(TypedArray a) { |
| 3572 | initScrollCache(); |
| 3573 | |
| 3574 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3575 | R.styleable.View_fadingEdgeLength, |
| 3576 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3577 | } |
| 3578 | |
| 3579 | /** |
| 3580 | * Returns the size of the vertical faded edges used to indicate that more |
| 3581 | * content in this view is visible. |
| 3582 | * |
| 3583 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3584 | * faded edges are not enabled for this view. |
| 3585 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3586 | */ |
| 3587 | public int getVerticalFadingEdgeLength() { |
| 3588 | if (isVerticalFadingEdgeEnabled()) { |
| 3589 | ScrollabilityCache cache = mScrollCache; |
| 3590 | if (cache != null) { |
| 3591 | return cache.fadingEdgeLength; |
| 3592 | } |
| 3593 | } |
| 3594 | return 0; |
| 3595 | } |
| 3596 | |
| 3597 | /** |
| 3598 | * Set the size of the faded edge used to indicate that more content in this |
| 3599 | * view is available. Will not change whether the fading edge is enabled; use |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 3600 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3601 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3602 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | * |
| 3604 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3605 | * content in this view is visible. |
| 3606 | */ |
| 3607 | public void setFadingEdgeLength(int length) { |
| 3608 | initScrollCache(); |
| 3609 | mScrollCache.fadingEdgeLength = length; |
| 3610 | } |
| 3611 | |
| 3612 | /** |
| 3613 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3614 | * content in this view is visible. |
| 3615 | * |
| 3616 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3617 | * faded edges are not enabled for this view. |
| 3618 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3619 | */ |
| 3620 | public int getHorizontalFadingEdgeLength() { |
| 3621 | if (isHorizontalFadingEdgeEnabled()) { |
| 3622 | ScrollabilityCache cache = mScrollCache; |
| 3623 | if (cache != null) { |
| 3624 | return cache.fadingEdgeLength; |
| 3625 | } |
| 3626 | } |
| 3627 | return 0; |
| 3628 | } |
| 3629 | |
| 3630 | /** |
| 3631 | * Returns the width of the vertical scrollbar. |
| 3632 | * |
| 3633 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3634 | * is no vertical scrollbar. |
| 3635 | */ |
| 3636 | public int getVerticalScrollbarWidth() { |
| 3637 | ScrollabilityCache cache = mScrollCache; |
| 3638 | if (cache != null) { |
| 3639 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3640 | if (scrollBar != null) { |
| 3641 | int size = scrollBar.getSize(true); |
| 3642 | if (size <= 0) { |
| 3643 | size = cache.scrollBarSize; |
| 3644 | } |
| 3645 | return size; |
| 3646 | } |
| 3647 | return 0; |
| 3648 | } |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
| 3652 | /** |
| 3653 | * Returns the height of the horizontal scrollbar. |
| 3654 | * |
| 3655 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3656 | * there is no horizontal scrollbar. |
| 3657 | */ |
| 3658 | protected int getHorizontalScrollbarHeight() { |
| 3659 | ScrollabilityCache cache = mScrollCache; |
| 3660 | if (cache != null) { |
| 3661 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3662 | if (scrollBar != null) { |
| 3663 | int size = scrollBar.getSize(false); |
| 3664 | if (size <= 0) { |
| 3665 | size = cache.scrollBarSize; |
| 3666 | } |
| 3667 | return size; |
| 3668 | } |
| 3669 | return 0; |
| 3670 | } |
| 3671 | return 0; |
| 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * <p> |
| 3676 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3677 | * method should be called by subclasses that need scrollbars and when an |
| 3678 | * instance of these subclasses is created programmatically rather than |
| 3679 | * being inflated from XML. This method is automatically called when the XML |
| 3680 | * is inflated. |
| 3681 | * </p> |
| 3682 | * |
| 3683 | * @param a the styled attributes set to initialize the scrollbars from |
| 3684 | */ |
| 3685 | protected void initializeScrollbars(TypedArray a) { |
| 3686 | initScrollCache(); |
| 3687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3689 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3690 | if (scrollabilityCache.scrollBar == null) { |
| 3691 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3692 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3693 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3694 | final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3696 | if (!fadeScrollbars) { |
| 3697 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3698 | } |
| 3699 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3700 | |
| 3701 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3702 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3703 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3704 | .getScrollBarFadeDuration()); |
| 3705 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3706 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3707 | ViewConfiguration.getScrollDefaultDelay()); |
| 3708 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3710 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3711 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3712 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3713 | |
| 3714 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3715 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3716 | |
| 3717 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3718 | if (thumb != null) { |
| 3719 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3720 | } |
| 3721 | |
| 3722 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3723 | false); |
| 3724 | if (alwaysDraw) { |
| 3725 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3726 | } |
| 3727 | |
| 3728 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3729 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3730 | |
| 3731 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3732 | if (thumb != null) { |
| 3733 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3734 | } |
| 3735 | |
| 3736 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3737 | false); |
| 3738 | if (alwaysDraw) { |
| 3739 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3740 | } |
| 3741 | |
| 3742 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3743 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * <p> |
| 3748 | * Initalizes the scrollability cache if necessary. |
| 3749 | * </p> |
| 3750 | */ |
| 3751 | private void initScrollCache() { |
| 3752 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3753 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3757 | private ScrollabilityCache getScrollCache() { |
| 3758 | initScrollCache(); |
| 3759 | return mScrollCache; |
| 3760 | } |
| 3761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3763 | * Set the position of the vertical scroll bar. Should be one of |
| 3764 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3765 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3766 | * |
| 3767 | * @param position Where the vertical scroll bar should be positioned. |
| 3768 | */ |
| 3769 | public void setVerticalScrollbarPosition(int position) { |
| 3770 | if (mVerticalScrollbarPosition != position) { |
| 3771 | mVerticalScrollbarPosition = position; |
| 3772 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3773 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | /** |
| 3778 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3779 | * @see #setVerticalScrollbarPosition(int) |
| 3780 | */ |
| 3781 | public int getVerticalScrollbarPosition() { |
| 3782 | return mVerticalScrollbarPosition; |
| 3783 | } |
| 3784 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3785 | ListenerInfo getListenerInfo() { |
| 3786 | if (mListenerInfo != null) { |
| 3787 | return mListenerInfo; |
| 3788 | } |
| 3789 | mListenerInfo = new ListenerInfo(); |
| 3790 | return mListenerInfo; |
| 3791 | } |
| 3792 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3793 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | * Register a callback to be invoked when focus of this view changed. |
| 3795 | * |
| 3796 | * @param l The callback that will run. |
| 3797 | */ |
| 3798 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3799 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3803 | * Add a listener that will be called when the bounds of the view change due to |
| 3804 | * layout processing. |
| 3805 | * |
| 3806 | * @param listener The listener that will be called when layout bounds change. |
| 3807 | */ |
| 3808 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3809 | ListenerInfo li = getListenerInfo(); |
| 3810 | if (li.mOnLayoutChangeListeners == null) { |
| 3811 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3812 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3813 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3814 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3815 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | /** |
| 3819 | * Remove a listener for layout changes. |
| 3820 | * |
| 3821 | * @param listener The listener for layout bounds change. |
| 3822 | */ |
| 3823 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3824 | ListenerInfo li = mListenerInfo; |
| 3825 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3826 | return; |
| 3827 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3828 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3832 | * Add a listener for attach state changes. |
| 3833 | * |
| 3834 | * This listener will be called whenever this view is attached or detached |
| 3835 | * from a window. Remove the listener using |
| 3836 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3837 | * |
| 3838 | * @param listener Listener to attach |
| 3839 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3840 | */ |
| 3841 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3842 | ListenerInfo li = getListenerInfo(); |
| 3843 | if (li.mOnAttachStateChangeListeners == null) { |
| 3844 | li.mOnAttachStateChangeListeners |
| 3845 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3846 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3847 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | /** |
| 3851 | * Remove a listener for attach state changes. The listener will receive no further |
| 3852 | * notification of window attach/detach events. |
| 3853 | * |
| 3854 | * @param listener Listener to remove |
| 3855 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3856 | */ |
| 3857 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3858 | ListenerInfo li = mListenerInfo; |
| 3859 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3860 | return; |
| 3861 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3862 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | * Returns the focus-change callback registered for this view. |
| 3867 | * |
| 3868 | * @return The callback, or null if one is not registered. |
| 3869 | */ |
| 3870 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3871 | ListenerInfo li = mListenerInfo; |
| 3872 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 3877 | * clickable, it becomes clickable. |
| 3878 | * |
| 3879 | * @param l The callback that will run |
| 3880 | * |
| 3881 | * @see #setClickable(boolean) |
| 3882 | */ |
| 3883 | public void setOnClickListener(OnClickListener l) { |
| 3884 | if (!isClickable()) { |
| 3885 | setClickable(true); |
| 3886 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3887 | getListenerInfo().mOnClickListener = l; |
| 3888 | } |
| 3889 | |
| 3890 | /** |
| 3891 | * Return whether this view has an attached OnClickListener. Returns |
| 3892 | * true if there is a listener, false if there is none. |
| 3893 | */ |
| 3894 | public boolean hasOnClickListeners() { |
| 3895 | ListenerInfo li = mListenerInfo; |
| 3896 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 3901 | * long clickable, it becomes long clickable. |
| 3902 | * |
| 3903 | * @param l The callback that will run |
| 3904 | * |
| 3905 | * @see #setLongClickable(boolean) |
| 3906 | */ |
| 3907 | public void setOnLongClickListener(OnLongClickListener l) { |
| 3908 | if (!isLongClickable()) { |
| 3909 | setLongClickable(true); |
| 3910 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3911 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | /** |
| 3915 | * Register a callback to be invoked when the context menu for this view is |
| 3916 | * being built. If this view is not long clickable, it becomes long clickable. |
| 3917 | * |
| 3918 | * @param l The callback that will run |
| 3919 | * |
| 3920 | */ |
| 3921 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 3922 | if (!isLongClickable()) { |
| 3923 | setLongClickable(true); |
| 3924 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3925 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3929 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 3930 | * actions associated with clicking: reporting accessibility event, playing |
| 3931 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | * |
| 3933 | * @return True there was an assigned OnClickListener that was called, false |
| 3934 | * otherwise is returned. |
| 3935 | */ |
| 3936 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3937 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 3938 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3939 | ListenerInfo li = mListenerInfo; |
| 3940 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3942 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | return true; |
| 3944 | } |
| 3945 | |
| 3946 | return false; |
| 3947 | } |
| 3948 | |
| 3949 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3950 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 3951 | * this only calls the listener, and does not do any associated clicking |
| 3952 | * actions like reporting an accessibility event. |
| 3953 | * |
| 3954 | * @return True there was an assigned OnClickListener that was called, false |
| 3955 | * otherwise is returned. |
| 3956 | */ |
| 3957 | public boolean callOnClick() { |
| 3958 | ListenerInfo li = mListenerInfo; |
| 3959 | if (li != null && li.mOnClickListener != null) { |
| 3960 | li.mOnClickListener.onClick(this); |
| 3961 | return true; |
| 3962 | } |
| 3963 | return false; |
| 3964 | } |
| 3965 | |
| 3966 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3967 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 3968 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 3970 | * @return True if one of the above receivers consumed the event, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | */ |
| 3972 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3973 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 3974 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3975 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3976 | ListenerInfo li = mListenerInfo; |
| 3977 | if (li != null && li.mOnLongClickListener != null) { |
| 3978 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | } |
| 3980 | if (!handled) { |
| 3981 | handled = showContextMenu(); |
| 3982 | } |
| 3983 | if (handled) { |
| 3984 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 3985 | } |
| 3986 | return handled; |
| 3987 | } |
| 3988 | |
| 3989 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3990 | * Performs button-related actions during a touch down event. |
| 3991 | * |
| 3992 | * @param event The event. |
| 3993 | * @return True if the down was consumed. |
| 3994 | * |
| 3995 | * @hide |
| 3996 | */ |
| 3997 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 3998 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 3999 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 4000 | return true; |
| 4001 | } |
| 4002 | } |
| 4003 | return false; |
| 4004 | } |
| 4005 | |
| 4006 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4007 | * Bring up the context menu for this view. |
| 4008 | * |
| 4009 | * @return Whether a context menu was displayed. |
| 4010 | */ |
| 4011 | public boolean showContextMenu() { |
| 4012 | return getParent().showContextMenuForChild(this); |
| 4013 | } |
| 4014 | |
| 4015 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4016 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 4017 | * |
| 4018 | * @param x The referenced x coordinate. |
| 4019 | * @param y The referenced y coordinate. |
| 4020 | * @param metaState The keyboard modifiers that were pressed. |
| 4021 | * @return Whether a context menu was displayed. |
| 4022 | * |
| 4023 | * @hide |
| 4024 | */ |
| 4025 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4026 | return showContextMenu(); |
| 4027 | } |
| 4028 | |
| 4029 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4030 | * Start an action mode. |
| 4031 | * |
| 4032 | * @param callback Callback that will control the lifecycle of the action mode |
| 4033 | * @return The new action mode if it is started, null otherwise |
| 4034 | * |
| 4035 | * @see ActionMode |
| 4036 | */ |
| 4037 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4038 | ViewParent parent = getParent(); |
| 4039 | if (parent == null) return null; |
| 4040 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4041 | } |
| 4042 | |
| 4043 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4044 | * Register a callback to be invoked when a key is pressed in this view. |
| 4045 | * @param l the key listener to attach to this view |
| 4046 | */ |
| 4047 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4048 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /** |
| 4052 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4053 | * @param l the touch listener to attach to this view |
| 4054 | */ |
| 4055 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4056 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4060 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4061 | * @param l the generic motion listener to attach to this view |
| 4062 | */ |
| 4063 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4064 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4068 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4069 | * @param l the hover listener to attach to this view |
| 4070 | */ |
| 4071 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4072 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4076 | * Register a drag event listener callback object for this View. The parameter is |
| 4077 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4078 | * View, the system calls the |
| 4079 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4080 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4081 | */ |
| 4082 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4083 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4087 | * Give this view focus. This will cause |
| 4088 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} to be called. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4089 | * |
| 4090 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4091 | * gives it focus no matter what. It should only be called internally by framework |
| 4092 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4093 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4094 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4095 | * {@link View#FOCUS_LEFT} or {@link View#FOCUS_RIGHT}. This is the direction which |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | * focus moved when requestFocus() is called. It may not always |
| 4097 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4098 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4099 | * prior in this View's coordinate system. |
| 4100 | */ |
| 4101 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4102 | if (DBG) { |
| 4103 | System.out.println(this + " requestFocus()"); |
| 4104 | } |
| 4105 | |
| 4106 | if ((mPrivateFlags & FOCUSED) == 0) { |
| 4107 | mPrivateFlags |= FOCUSED; |
| 4108 | |
| 4109 | if (mParent != null) { |
| 4110 | mParent.requestChildFocus(this, this); |
| 4111 | } |
| 4112 | |
| 4113 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4114 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4115 | |
| 4116 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4117 | notifyAccessibilityStateChanged(); |
| 4118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | /** |
| 4123 | * Request that a rectangle of this view be visible on the screen, |
| 4124 | * scrolling if necessary just enough. |
| 4125 | * |
| 4126 | * <p>A View should call this if it maintains some notion of which part |
| 4127 | * of its content is interesting. For example, a text editing view |
| 4128 | * should call this when its cursor moves. |
| 4129 | * |
| 4130 | * @param rectangle The rectangle. |
| 4131 | * @return Whether any parent scrolled. |
| 4132 | */ |
| 4133 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4134 | return requestRectangleOnScreen(rectangle, false); |
| 4135 | } |
| 4136 | |
| 4137 | /** |
| 4138 | * Request that a rectangle of this view be visible on the screen, |
| 4139 | * scrolling if necessary just enough. |
| 4140 | * |
| 4141 | * <p>A View should call this if it maintains some notion of which part |
| 4142 | * of its content is interesting. For example, a text editing view |
| 4143 | * should call this when its cursor moves. |
| 4144 | * |
| 4145 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4146 | * animated. |
| 4147 | * |
| 4148 | * @param rectangle The rectangle. |
| 4149 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4150 | * @return Whether any parent scrolled. |
| 4151 | */ |
| 4152 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 4153 | View child = this; |
| 4154 | ViewParent parent = mParent; |
| 4155 | boolean scrolled = false; |
| 4156 | while (parent != null) { |
| 4157 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4158 | rectangle, immediate); |
| 4159 | |
| 4160 | // offset rect so next call has the rectangle in the |
| 4161 | // coordinate system of its direct child. |
| 4162 | rectangle.offset(child.getLeft(), child.getTop()); |
| 4163 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 4164 | |
| 4165 | if (!(parent instanceof View)) { |
| 4166 | break; |
| 4167 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | child = (View) parent; |
| 4170 | parent = child.getParent(); |
| 4171 | } |
| 4172 | return scrolled; |
| 4173 | } |
| 4174 | |
| 4175 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4176 | * Called when this view wants to give up focus. If focus is cleared |
| 4177 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4178 | * <p> |
| 4179 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4180 | * to give focus to the first focusable View from the top. Hence, if this |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4181 | * View is the first from the top that can take focus, then all callbacks |
| 4182 | * related to clearing focus will be invoked after wich the framework will |
| 4183 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4184 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | */ |
| 4186 | public void clearFocus() { |
| 4187 | if (DBG) { |
| 4188 | System.out.println(this + " clearFocus()"); |
| 4189 | } |
| 4190 | |
| 4191 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4192 | mPrivateFlags &= ~FOCUSED; |
| 4193 | |
| 4194 | if (mParent != null) { |
| 4195 | mParent.clearChildFocus(this); |
| 4196 | } |
| 4197 | |
| 4198 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4201 | |
| 4202 | ensureInputFocusOnFirstFocusable(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4203 | |
| 4204 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4205 | notifyAccessibilityStateChanged(); |
| 4206 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4210 | void ensureInputFocusOnFirstFocusable() { |
| 4211 | View root = getRootView(); |
| 4212 | if (root != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4213 | root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | /** |
| 4218 | * Called internally by the view system when a new view is getting focus. |
| 4219 | * This is what clears the old focus. |
| 4220 | */ |
| 4221 | void unFocus() { |
| 4222 | if (DBG) { |
| 4223 | System.out.println(this + " unFocus()"); |
| 4224 | } |
| 4225 | |
| 4226 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 4227 | mPrivateFlags &= ~FOCUSED; |
| 4228 | |
| 4229 | onFocusChanged(false, 0, null); |
| 4230 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4231 | |
| 4232 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4233 | notifyAccessibilityStateChanged(); |
| 4234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | /** |
| 4239 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4240 | * view that has focus. |
| 4241 | * |
| 4242 | * @return True if this view has or contains focus, false otherwise. |
| 4243 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4244 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | public boolean hasFocus() { |
| 4246 | return (mPrivateFlags & FOCUSED) != 0; |
| 4247 | } |
| 4248 | |
| 4249 | /** |
| 4250 | * Returns true if this view is focusable or if it contains a reachable View |
| 4251 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4252 | * is a View whose parents do not block descendants focus. |
| 4253 | * |
| 4254 | * Only {@link #VISIBLE} views are considered focusable. |
| 4255 | * |
| 4256 | * @return True if the view is focusable or if the view contains a focusable |
| 4257 | * View, false otherwise. |
| 4258 | * |
| 4259 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4260 | */ |
| 4261 | public boolean hasFocusable() { |
| 4262 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4263 | } |
| 4264 | |
| 4265 | /** |
| 4266 | * Called by the view system when the focus state of this view changes. |
| 4267 | * When the focus change event is caused by directional navigation, direction |
| 4268 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4269 | * When overriding, be sure to call up through to the super class so that |
| 4270 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4271 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | * @param gainFocus True if the View has focus; false otherwise. |
| 4273 | * @param direction The direction focus has moved when requestFocus() |
| 4274 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4275 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4276 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4277 | * It may not always apply, in which case use the default. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4279 | * system, of the previously focused view. If applicable, this will be |
| 4280 | * passed in as finer grained information about where the focus is coming |
| 4281 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4282 | */ |
| 4283 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4284 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4285 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4286 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 4287 | requestAccessibilityFocus(); |
| 4288 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4289 | } |
| 4290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4292 | if (!gainFocus) { |
| 4293 | if (isPressed()) { |
| 4294 | setPressed(false); |
| 4295 | } |
| 4296 | if (imm != null && mAttachInfo != null |
| 4297 | && mAttachInfo.mHasWindowFocus) { |
| 4298 | imm.focusOut(this); |
| 4299 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4300 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | } else if (imm != null && mAttachInfo != null |
| 4302 | && mAttachInfo.mHasWindowFocus) { |
| 4303 | imm.focusIn(this); |
| 4304 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4305 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4306 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4307 | ListenerInfo li = mListenerInfo; |
| 4308 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4309 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4311 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4312 | if (mAttachInfo != null) { |
| 4313 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4318 | * Sends an accessibility event of the given type. If accessiiblity is |
| 4319 | * not enabled this method has no effect. The default implementation calls |
| 4320 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4321 | * to populate information about the event source (this View), then calls |
| 4322 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4323 | * populate the text content of the event source including its descendants, |
| 4324 | * and last calls |
| 4325 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4326 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4327 | * <p> |
| 4328 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4329 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4330 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4331 | * responsible for handling this call. |
| 4332 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4333 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4334 | * @param eventType The type of the event to send, as defined by several types from |
| 4335 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4336 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4337 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4338 | * |
| 4339 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4340 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4341 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4342 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4343 | */ |
| 4344 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4345 | if (mAccessibilityDelegate != null) { |
| 4346 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4347 | } else { |
| 4348 | sendAccessibilityEventInternal(eventType); |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4353 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4354 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4355 | * sort of a context change for which none of the events representing UI transitions |
| 4356 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4357 | * is not enabled this method does nothing. |
| 4358 | * |
| 4359 | * @param text The announcement text. |
| 4360 | */ |
| 4361 | public void announceForAccessibility(CharSequence text) { |
| 4362 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4363 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4364 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
| 4365 | event.getText().add(text); |
| 4366 | sendAccessibilityEventUnchecked(event); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4371 | * @see #sendAccessibilityEvent(int) |
| 4372 | * |
| 4373 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4374 | */ |
| 4375 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4376 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4377 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4382 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4383 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4384 | * perform a check whether accessibility is enabled. |
| 4385 | * <p> |
| 4386 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4387 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4388 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4389 | * is responsible for handling this call. |
| 4390 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4391 | * |
| 4392 | * @param event The event to send. |
| 4393 | * |
| 4394 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4395 | */ |
| 4396 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4397 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4398 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4399 | } else { |
| 4400 | sendAccessibilityEventUncheckedInternal(event); |
| 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | /** |
| 4405 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4406 | * |
| 4407 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4408 | */ |
| 4409 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4410 | if (!isShown()) { |
| 4411 | return; |
| 4412 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4413 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4414 | // Only a subset of accessibility events populates text content. |
| 4415 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4416 | dispatchPopulateAccessibilityEvent(event); |
| 4417 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4418 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 4419 | // track of accessibility focus position in such nodes. |
| 4420 | final int eventType = event.getEventType(); |
| 4421 | switch (eventType) { |
| 4422 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
| 4423 | final long virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 4424 | event.getSourceNodeId()); |
| 4425 | if (virtualNodeId != AccessibilityNodeInfo.UNDEFINED) { |
| 4426 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 4427 | if (viewRootImpl != null) { |
| 4428 | viewRootImpl.setAccessibilityFocusedHost(this); |
| 4429 | } |
| 4430 | } |
| 4431 | } break; |
| 4432 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
| 4433 | final long virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 4434 | event.getSourceNodeId()); |
| 4435 | if (virtualNodeId != AccessibilityNodeInfo.UNDEFINED) { |
| 4436 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 4437 | if (viewRootImpl != null) { |
| 4438 | viewRootImpl.setAccessibilityFocusedHost(null); |
| 4439 | } |
| 4440 | } |
| 4441 | } break; |
| 4442 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4443 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4444 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4448 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4449 | * to its children for adding their text content to the event. Note that the |
| 4450 | * event text is populated in a separate dispatch path since we add to the |
| 4451 | * event not only the text of the source but also the text of all its descendants. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4452 | * A typical implementation will call |
| 4453 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4454 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4455 | * on each child. Override this method if custom population of the event text |
| 4456 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4457 | * <p> |
| 4458 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4459 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4460 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4461 | * is responsible for handling this call. |
| 4462 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4463 | * <p> |
| 4464 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4465 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4466 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4467 | * |
| 4468 | * @param event The event. |
| 4469 | * |
| 4470 | * @return True if the event population was completed. |
| 4471 | */ |
| 4472 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4473 | if (mAccessibilityDelegate != null) { |
| 4474 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4475 | } else { |
| 4476 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | /** |
| 4481 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4482 | * |
| 4483 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4484 | */ |
| 4485 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4486 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4487 | return false; |
| 4488 | } |
| 4489 | |
| 4490 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4491 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4492 | * giving a chance to this View to populate the accessibility event with its |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4493 | * text content. While this method is free to modify event |
| 4494 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4495 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4496 | * <p> |
| 4497 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4498 | * to the text added by the super implementation: |
| 4499 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4500 | * super.onPopulateAccessibilityEvent(event); |
| 4501 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4502 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4503 | * mCurrentDate.getTimeInMillis(), flags); |
| 4504 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4505 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4506 | * <p> |
| 4507 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4508 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4509 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4510 | * is responsible for handling this call. |
| 4511 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4512 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4513 | * information to the event, in case the default implementation has basic information to add. |
| 4514 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4515 | * |
| 4516 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4517 | * |
| 4518 | * @see #sendAccessibilityEvent(int) |
| 4519 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4520 | */ |
| 4521 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4522 | if (mAccessibilityDelegate != null) { |
| 4523 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4524 | } else { |
| 4525 | onPopulateAccessibilityEventInternal(event); |
| 4526 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4530 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4531 | * |
| 4532 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4533 | */ |
| 4534 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4535 | |
| 4536 | } |
| 4537 | |
| 4538 | /** |
| 4539 | * Initializes an {@link AccessibilityEvent} with information about |
| 4540 | * this View which is the event source. In other words, the source of |
| 4541 | * an accessibility event is the view whose state change triggered firing |
| 4542 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4543 | * <p> |
| 4544 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4545 | * to properties set by the super implementation: |
| 4546 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4547 | * super.onInitializeAccessibilityEvent(event); |
| 4548 | * event.setPassword(true); |
| 4549 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4550 | * <p> |
| 4551 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4552 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4553 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4554 | * is responsible for handling this call. |
| 4555 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4556 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4557 | * information to the event, in case the default implementation has basic information to add. |
| 4558 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4559 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4560 | * |
| 4561 | * @see #sendAccessibilityEvent(int) |
| 4562 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4563 | */ |
| 4564 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4565 | if (mAccessibilityDelegate != null) { |
| 4566 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4567 | } else { |
| 4568 | onInitializeAccessibilityEventInternal(event); |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | /** |
| 4573 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4574 | * |
| 4575 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4576 | */ |
| 4577 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4578 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4579 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4580 | event.setPackageName(getContext().getPackageName()); |
| 4581 | event.setEnabled(isEnabled()); |
| 4582 | event.setContentDescription(mContentDescription); |
| 4583 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4584 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4585 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4586 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4587 | FOCUSABLES_ALL); |
| 4588 | event.setItemCount(focusablesTempList.size()); |
| 4589 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4590 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4595 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4596 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4597 | * This method is responsible for obtaining an accessibility node info from a |
| 4598 | * pool of reusable instances and calling |
| 4599 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4600 | * initialize the former. |
| 4601 | * <p> |
| 4602 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4603 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4604 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4605 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4606 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4607 | * |
| 4608 | * @see AccessibilityNodeInfo |
| 4609 | */ |
| 4610 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4611 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4612 | if (provider != null) { |
| 4613 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4614 | } else { |
| 4615 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4616 | onInitializeAccessibilityNodeInfo(info); |
| 4617 | return info; |
| 4618 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | /** |
| 4622 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4623 | * The base implementation sets: |
| 4624 | * <ul> |
| 4625 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4626 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4627 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4628 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4629 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4630 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4631 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4632 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4633 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4634 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4635 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4636 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4637 | * </ul> |
| 4638 | * <p> |
| 4639 | * Subclasses should override this method, call the super implementation, |
| 4640 | * and set additional attributes. |
| 4641 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4642 | * <p> |
| 4643 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4644 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4645 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4646 | * is responsible for handling this call. |
| 4647 | * </p> |
| 4648 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4649 | * @param info The instance to initialize. |
| 4650 | */ |
| 4651 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4652 | if (mAccessibilityDelegate != null) { |
| 4653 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4654 | } else { |
| 4655 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4656 | } |
| 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4661 | * |
| 4662 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4663 | */ |
| 4664 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4665 | Rect bounds = mAttachInfo.mTmpInvalRect; |
| 4666 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4667 | info.setBoundsInParent(bounds); |
| 4668 | |
Svetoslav Ganov | aa6f3de | 2012-04-09 17:39:00 -0700 | [diff] [blame] | 4669 | getGlobalVisibleRect(bounds); |
| 4670 | bounds.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4671 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4672 | |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4673 | if ((mPrivateFlags & IS_ROOT_NAMESPACE) == 0) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4674 | ViewParent parent = getParentForAccessibility(); |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4675 | if (parent instanceof View) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4676 | info.setParent((View) parent); |
Svetoslav Ganov | 57f3b566db | 2011-10-31 17:59:14 -0700 | [diff] [blame] | 4677 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4681 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4682 | info.setContentDescription(getContentDescription()); |
| 4683 | |
| 4684 | info.setEnabled(isEnabled()); |
| 4685 | info.setClickable(isClickable()); |
| 4686 | info.setFocusable(isFocusable()); |
| 4687 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4688 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4689 | info.setSelected(isSelected()); |
| 4690 | info.setLongClickable(isLongClickable()); |
| 4691 | |
| 4692 | // TODO: These make sense only if we are in an AdapterView but all |
| 4693 | // views can be selected. Maybe from accessiiblity perspective |
| 4694 | // we should report as selectable view in an AdapterView. |
| 4695 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4696 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4697 | |
| 4698 | if (isFocusable()) { |
| 4699 | if (isFocused()) { |
| 4700 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4701 | } else { |
| 4702 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4703 | } |
| 4704 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4705 | |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame^] | 4706 | if (!isAccessibilityFocused()) { |
| 4707 | info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
| 4708 | } else { |
| 4709 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); |
| 4710 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4711 | |
| 4712 | if (isClickable()) { |
| 4713 | info.addAction(AccessibilityNodeInfo.ACTION_CLICK); |
| 4714 | } |
| 4715 | |
| 4716 | if (isLongClickable()) { |
| 4717 | info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK); |
| 4718 | } |
| 4719 | |
| 4720 | if (getContentDescription() != null) { |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 4721 | info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); |
| 4722 | info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); |
| 4723 | info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
| 4724 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD); |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4725 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4726 | } |
| 4727 | |
| 4728 | /** |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 4729 | * Computes whether this view is visible on the screen. |
| 4730 | * |
| 4731 | * @return Whether the view is visible on the screen. |
| 4732 | */ |
| 4733 | boolean isDisplayedOnScreen() { |
| 4734 | // The first two checks are made also made by isShown() which |
| 4735 | // however traverses the tree up to the parent to catch that. |
| 4736 | // Therefore, we do some fail fast check to minimize the up |
| 4737 | // tree traversal. |
| 4738 | return (mAttachInfo != null |
| 4739 | && mAttachInfo.mWindowVisibility == View.VISIBLE |
| 4740 | && getAlpha() > 0 |
| 4741 | && isShown() |
| 4742 | && getGlobalVisibleRect(mAttachInfo.mTmpInvalRect)); |
| 4743 | } |
| 4744 | |
| 4745 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4746 | * Sets a delegate for implementing accessibility support via compositon as |
| 4747 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4748 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4749 | * |
| 4750 | * @param delegate The delegate instance. |
| 4751 | * |
| 4752 | * @see AccessibilityDelegate |
| 4753 | */ |
| 4754 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4755 | mAccessibilityDelegate = delegate; |
| 4756 | } |
| 4757 | |
| 4758 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4759 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4760 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4761 | * that explore the window content. |
| 4762 | * <p> |
| 4763 | * If this method returns an instance, this instance is responsible for managing |
| 4764 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4765 | * View including the one representing the View itself. Similarly the returned |
| 4766 | * instance is responsible for performing accessibility actions on any virtual |
| 4767 | * view or the root view itself. |
| 4768 | * </p> |
| 4769 | * <p> |
| 4770 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4771 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4772 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4773 | * is responsible for handling this call. |
| 4774 | * </p> |
| 4775 | * |
| 4776 | * @return The provider. |
| 4777 | * |
| 4778 | * @see AccessibilityNodeProvider |
| 4779 | */ |
| 4780 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4781 | if (mAccessibilityDelegate != null) { |
| 4782 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4783 | } else { |
| 4784 | return null; |
| 4785 | } |
| 4786 | } |
| 4787 | |
| 4788 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4789 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4790 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4791 | * |
| 4792 | * @return The view accessibility id. |
| 4793 | * |
| 4794 | * @hide |
| 4795 | */ |
| 4796 | public int getAccessibilityViewId() { |
| 4797 | if (mAccessibilityViewId == NO_ID) { |
| 4798 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4799 | } |
| 4800 | return mAccessibilityViewId; |
| 4801 | } |
| 4802 | |
| 4803 | /** |
| 4804 | * Gets the unique identifier of the window in which this View reseides. |
| 4805 | * |
| 4806 | * @return The window accessibility id. |
| 4807 | * |
| 4808 | * @hide |
| 4809 | */ |
| 4810 | public int getAccessibilityWindowId() { |
| 4811 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 4812 | } |
| 4813 | |
| 4814 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4815 | * Gets the {@link View} description. It briefly describes the view and is |
| 4816 | * primarily used for accessibility support. Set this property to enable |
| 4817 | * better accessibility support for your application. This is especially |
| 4818 | * true for views that do not have textual representation (For example, |
| 4819 | * ImageButton). |
| 4820 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4821 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4822 | * |
| 4823 | * @attr ref android.R.styleable#View_contentDescription |
| 4824 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4825 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4826 | public CharSequence getContentDescription() { |
| 4827 | return mContentDescription; |
| 4828 | } |
| 4829 | |
| 4830 | /** |
| 4831 | * Sets the {@link View} description. It briefly describes the view and is |
| 4832 | * primarily used for accessibility support. Set this property to enable |
| 4833 | * better accessibility support for your application. This is especially |
| 4834 | * true for views that do not have textual representation (For example, |
| 4835 | * ImageButton). |
| 4836 | * |
| 4837 | * @param contentDescription The content description. |
| 4838 | * |
| 4839 | * @attr ref android.R.styleable#View_contentDescription |
| 4840 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 4841 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4842 | public void setContentDescription(CharSequence contentDescription) { |
| 4843 | mContentDescription = contentDescription; |
| 4844 | } |
| 4845 | |
| 4846 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4847 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 4848 | * focus within its window. This method can be used to clear any state tied to the |
| 4849 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 4850 | * loses focus, this method can be used to cancel the press. |
| 4851 | * |
| 4852 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 4853 | * |
| 4854 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4855 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4856 | * |
| 4857 | * @hide pending API council approval |
| 4858 | */ |
| 4859 | protected void onFocusLost() { |
| 4860 | resetPressedState(); |
| 4861 | } |
| 4862 | |
| 4863 | private void resetPressedState() { |
| 4864 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 4865 | return; |
| 4866 | } |
| 4867 | |
| 4868 | if (isPressed()) { |
| 4869 | setPressed(false); |
| 4870 | |
| 4871 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 4872 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4873 | } |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | * Returns true if this view has focus |
| 4879 | * |
| 4880 | * @return True if this view has focus, false otherwise. |
| 4881 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4882 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | public boolean isFocused() { |
| 4884 | return (mPrivateFlags & FOCUSED) != 0; |
| 4885 | } |
| 4886 | |
| 4887 | /** |
| 4888 | * Find the view in the hierarchy rooted at this view that currently has |
| 4889 | * focus. |
| 4890 | * |
| 4891 | * @return The view that currently has focus, or null if no focused view can |
| 4892 | * be found. |
| 4893 | */ |
| 4894 | public View findFocus() { |
| 4895 | return (mPrivateFlags & FOCUSED) != 0 ? this : null; |
| 4896 | } |
| 4897 | |
| 4898 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4899 | * Indicates whether this view is one of the set of scrollable containers in |
| 4900 | * its window. |
| 4901 | * |
| 4902 | * @return whether this view is one of the set of scrollable containers in |
| 4903 | * its window |
| 4904 | * |
| 4905 | * @attr ref android.R.styleable#View_isScrollContainer |
| 4906 | */ |
| 4907 | public boolean isScrollContainer() { |
| 4908 | return (mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0; |
| 4909 | } |
| 4910 | |
| 4911 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | * Change whether this view is one of the set of scrollable containers in |
| 4913 | * its window. This will be used to determine whether the window can |
| 4914 | * resize or must pan when a soft input area is open -- scrollable |
| 4915 | * containers allow the window to use resize mode since the container |
| 4916 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4917 | * |
| 4918 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | */ |
| 4920 | public void setScrollContainer(boolean isScrollContainer) { |
| 4921 | if (isScrollContainer) { |
| 4922 | if (mAttachInfo != null && (mPrivateFlags&SCROLL_CONTAINER_ADDED) == 0) { |
| 4923 | mAttachInfo.mScrollContainers.add(this); |
| 4924 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 4925 | } |
| 4926 | mPrivateFlags |= SCROLL_CONTAINER; |
| 4927 | } else { |
| 4928 | if ((mPrivateFlags&SCROLL_CONTAINER_ADDED) != 0) { |
| 4929 | mAttachInfo.mScrollContainers.remove(this); |
| 4930 | } |
| 4931 | mPrivateFlags &= ~(SCROLL_CONTAINER|SCROLL_CONTAINER_ADDED); |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | /** |
| 4936 | * Returns the quality of the drawing cache. |
| 4937 | * |
| 4938 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4939 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4940 | * |
| 4941 | * @see #setDrawingCacheQuality(int) |
| 4942 | * @see #setDrawingCacheEnabled(boolean) |
| 4943 | * @see #isDrawingCacheEnabled() |
| 4944 | * |
| 4945 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4946 | */ |
| 4947 | public int getDrawingCacheQuality() { |
| 4948 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 4949 | } |
| 4950 | |
| 4951 | /** |
| 4952 | * Set the drawing cache quality of this view. This value is used only when the |
| 4953 | * drawing cache is enabled |
| 4954 | * |
| 4955 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 4956 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 4957 | * |
| 4958 | * @see #getDrawingCacheQuality() |
| 4959 | * @see #setDrawingCacheEnabled(boolean) |
| 4960 | * @see #isDrawingCacheEnabled() |
| 4961 | * |
| 4962 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 4963 | */ |
| 4964 | public void setDrawingCacheQuality(int quality) { |
| 4965 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 4966 | } |
| 4967 | |
| 4968 | /** |
| 4969 | * Returns whether the screen should remain on, corresponding to the current |
| 4970 | * value of {@link #KEEP_SCREEN_ON}. |
| 4971 | * |
| 4972 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 4973 | * |
| 4974 | * @see #setKeepScreenOn(boolean) |
| 4975 | * |
| 4976 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4977 | */ |
| 4978 | public boolean getKeepScreenOn() { |
| 4979 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 4980 | } |
| 4981 | |
| 4982 | /** |
| 4983 | * Controls whether the screen should remain on, modifying the |
| 4984 | * value of {@link #KEEP_SCREEN_ON}. |
| 4985 | * |
| 4986 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 4987 | * |
| 4988 | * @see #getKeepScreenOn() |
| 4989 | * |
| 4990 | * @attr ref android.R.styleable#View_keepScreenOn |
| 4991 | */ |
| 4992 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 4993 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 4994 | } |
| 4995 | |
| 4996 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4997 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 4998 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4999 | * |
| 5000 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5001 | */ |
| 5002 | public int getNextFocusLeftId() { |
| 5003 | return mNextFocusLeftId; |
| 5004 | } |
| 5005 | |
| 5006 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5007 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5008 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 5009 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5010 | * |
| 5011 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5012 | */ |
| 5013 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 5014 | mNextFocusLeftId = nextFocusLeftId; |
| 5015 | } |
| 5016 | |
| 5017 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5018 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5019 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5020 | * |
| 5021 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5022 | */ |
| 5023 | public int getNextFocusRightId() { |
| 5024 | return mNextFocusRightId; |
| 5025 | } |
| 5026 | |
| 5027 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5028 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5029 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 5030 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | * |
| 5032 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5033 | */ |
| 5034 | public void setNextFocusRightId(int nextFocusRightId) { |
| 5035 | mNextFocusRightId = nextFocusRightId; |
| 5036 | } |
| 5037 | |
| 5038 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5039 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5040 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5041 | * |
| 5042 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5043 | */ |
| 5044 | public int getNextFocusUpId() { |
| 5045 | return mNextFocusUpId; |
| 5046 | } |
| 5047 | |
| 5048 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5049 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5050 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 5051 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5052 | * |
| 5053 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5054 | */ |
| 5055 | public void setNextFocusUpId(int nextFocusUpId) { |
| 5056 | mNextFocusUpId = nextFocusUpId; |
| 5057 | } |
| 5058 | |
| 5059 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5060 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5061 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5062 | * |
| 5063 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5064 | */ |
| 5065 | public int getNextFocusDownId() { |
| 5066 | return mNextFocusDownId; |
| 5067 | } |
| 5068 | |
| 5069 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5070 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5071 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5072 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5073 | * |
| 5074 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5075 | */ |
| 5076 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5077 | mNextFocusDownId = nextFocusDownId; |
| 5078 | } |
| 5079 | |
| 5080 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5081 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5082 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5083 | * |
| 5084 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5085 | */ |
| 5086 | public int getNextFocusForwardId() { |
| 5087 | return mNextFocusForwardId; |
| 5088 | } |
| 5089 | |
| 5090 | /** |
| 5091 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5092 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5093 | * decide automatically. |
| 5094 | * |
| 5095 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5096 | */ |
| 5097 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5098 | mNextFocusForwardId = nextFocusForwardId; |
| 5099 | } |
| 5100 | |
| 5101 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5102 | * Returns the visibility of this view and all of its ancestors |
| 5103 | * |
| 5104 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5105 | */ |
| 5106 | public boolean isShown() { |
| 5107 | View current = this; |
| 5108 | //noinspection ConstantConditions |
| 5109 | do { |
| 5110 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5111 | return false; |
| 5112 | } |
| 5113 | ViewParent parent = current.mParent; |
| 5114 | if (parent == null) { |
| 5115 | return false; // We are not attached to the view root |
| 5116 | } |
| 5117 | if (!(parent instanceof View)) { |
| 5118 | return true; |
| 5119 | } |
| 5120 | current = (View) parent; |
| 5121 | } while (current != null); |
| 5122 | |
| 5123 | return false; |
| 5124 | } |
| 5125 | |
| 5126 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5127 | * Called by the view hierarchy when the content insets for a window have |
| 5128 | * changed, to allow it to adjust its content to fit within those windows. |
| 5129 | * The content insets tell you the space that the status bar, input method, |
| 5130 | * and other system windows infringe on the application's window. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5131 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5132 | * <p>You do not normally need to deal with this function, since the default |
| 5133 | * window decoration given to applications takes care of applying it to the |
| 5134 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5135 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5136 | * and your content can be placed under those system elements. You can then |
| 5137 | * use this method within your view hierarchy if you have parts of your UI |
| 5138 | * which you would like to ensure are not being covered. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5139 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5140 | * <p>The default implementation of this method simply applies the content |
| 5141 | * inset's to the view's padding. This can be enabled through |
| 5142 | * {@link #setFitsSystemWindows(boolean)}. Alternatively, you can override |
| 5143 | * the method and handle the insets however you would like. Note that the |
| 5144 | * insets provided by the framework are always relative to the far edges |
| 5145 | * of the window, not accounting for the location of the called view within |
| 5146 | * that window. (In fact when this method is called you do not yet know |
| 5147 | * where the layout will place the view, as it is done before layout happens.) |
| 5148 | * |
| 5149 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5150 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5151 | * call to continue to your children, you must be sure to call the super |
| 5152 | * implementation. |
| 5153 | * |
| 5154 | * @param insets Current content insets of the window. Prior to |
| 5155 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5156 | * the insets or else you and Android will be unhappy. |
| 5157 | * |
| 5158 | * @return Return true if this view applied the insets and it should not |
| 5159 | * continue propagating further down the hierarchy, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | */ |
| 5161 | protected boolean fitSystemWindows(Rect insets) { |
| 5162 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5163 | mUserPaddingStart = -1; |
| 5164 | mUserPaddingEnd = -1; |
| 5165 | mUserPaddingRelative = false; |
| 5166 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5167 | || mAttachInfo == null |
| 5168 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5169 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5170 | return true; |
| 5171 | } else { |
| 5172 | internalSetPadding(0, 0, 0, 0); |
| 5173 | return false; |
| 5174 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | } |
| 5176 | return false; |
| 5177 | } |
| 5178 | |
| 5179 | /** |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5180 | * Set whether or not this view should account for system screen decorations |
| 5181 | * such as the status bar and inset its content. This allows this view to be |
| 5182 | * positioned in absolute screen coordinates and remain visible to the user. |
| 5183 | * |
| 5184 | * <p>This should only be used by top-level window decor views. |
| 5185 | * |
| 5186 | * @param fitSystemWindows true to inset content for system screen decorations, false for |
| 5187 | * default behavior. |
| 5188 | * |
| 5189 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 5190 | */ |
| 5191 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5192 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5193 | } |
| 5194 | |
| 5195 | /** |
| 5196 | * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view |
| 5197 | * will account for system screen decorations such as the status bar and inset its |
| 5198 | * content. This allows the view to be positioned in absolute screen coordinates |
| 5199 | * and remain visible to the user. |
| 5200 | * |
| 5201 | * @return true if this view will adjust its content bounds for system screen decorations. |
| 5202 | * |
| 5203 | * @attr ref android.R.styleable#View_fitsSystemWindows |
| 5204 | */ |
| 5205 | public boolean fitsSystemWindows() { |
| 5206 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5207 | } |
| 5208 | |
| 5209 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5210 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5211 | */ |
| 5212 | public void requestFitSystemWindows() { |
| 5213 | if (mParent != null) { |
| 5214 | mParent.requestFitSystemWindows(); |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5220 | * @hide |
| 5221 | */ |
| 5222 | public void makeOptionalFitsSystemWindows() { |
| 5223 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5224 | } |
| 5225 | |
| 5226 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5227 | * Returns the visibility status for this view. |
| 5228 | * |
| 5229 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5230 | * @attr ref android.R.styleable#View_visibility |
| 5231 | */ |
| 5232 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5233 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5234 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5235 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | }) |
| 5237 | public int getVisibility() { |
| 5238 | return mViewFlags & VISIBILITY_MASK; |
| 5239 | } |
| 5240 | |
| 5241 | /** |
| 5242 | * Set the enabled state of this view. |
| 5243 | * |
| 5244 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5245 | * @attr ref android.R.styleable#View_visibility |
| 5246 | */ |
| 5247 | @RemotableViewMethod |
| 5248 | public void setVisibility(int visibility) { |
| 5249 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5250 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | /** |
| 5254 | * Returns the enabled status for this view. The interpretation of the |
| 5255 | * enabled state varies by subclass. |
| 5256 | * |
| 5257 | * @return True if this view is enabled, false otherwise. |
| 5258 | */ |
| 5259 | @ViewDebug.ExportedProperty |
| 5260 | public boolean isEnabled() { |
| 5261 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5262 | } |
| 5263 | |
| 5264 | /** |
| 5265 | * Set the enabled state of this view. The interpretation of the enabled |
| 5266 | * state varies by subclass. |
| 5267 | * |
| 5268 | * @param enabled True if this view is enabled, false otherwise. |
| 5269 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5270 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5272 | if (enabled == isEnabled()) return; |
| 5273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5274 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5275 | |
| 5276 | /* |
| 5277 | * The View most likely has to change its appearance, so refresh |
| 5278 | * the drawable state. |
| 5279 | */ |
| 5280 | refreshDrawableState(); |
| 5281 | |
| 5282 | // Invalidate too, since the default behavior for views is to be |
| 5283 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5284 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | /** |
| 5288 | * Set whether this view can receive the focus. |
| 5289 | * |
| 5290 | * Setting this to false will also ensure that this view is not focusable |
| 5291 | * in touch mode. |
| 5292 | * |
| 5293 | * @param focusable If true, this view can receive the focus. |
| 5294 | * |
| 5295 | * @see #setFocusableInTouchMode(boolean) |
| 5296 | * @attr ref android.R.styleable#View_focusable |
| 5297 | */ |
| 5298 | public void setFocusable(boolean focusable) { |
| 5299 | if (!focusable) { |
| 5300 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5301 | } |
| 5302 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5303 | } |
| 5304 | |
| 5305 | /** |
| 5306 | * Set whether this view can receive focus while in touch mode. |
| 5307 | * |
| 5308 | * Setting this to true will also ensure that this view is focusable. |
| 5309 | * |
| 5310 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5311 | * in touch mode. |
| 5312 | * |
| 5313 | * @see #setFocusable(boolean) |
| 5314 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5315 | */ |
| 5316 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5317 | // Focusable in touch mode should always be set before the focusable flag |
| 5318 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5319 | // which, in touch mode, will not successfully request focus on this view |
| 5320 | // because the focusable in touch mode flag is not set |
| 5321 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5322 | if (focusableInTouchMode) { |
| 5323 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | /** |
| 5328 | * Set whether this view should have sound effects enabled for events such as |
| 5329 | * clicking and touching. |
| 5330 | * |
| 5331 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5332 | * for instance, a dial key that plays dtmf tones. |
| 5333 | * |
| 5334 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5335 | * @see #isSoundEffectsEnabled() |
| 5336 | * @see #playSoundEffect(int) |
| 5337 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5338 | */ |
| 5339 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5340 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5341 | } |
| 5342 | |
| 5343 | /** |
| 5344 | * @return whether this view should have sound effects enabled for events such as |
| 5345 | * clicking and touching. |
| 5346 | * |
| 5347 | * @see #setSoundEffectsEnabled(boolean) |
| 5348 | * @see #playSoundEffect(int) |
| 5349 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5350 | */ |
| 5351 | @ViewDebug.ExportedProperty |
| 5352 | public boolean isSoundEffectsEnabled() { |
| 5353 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5354 | } |
| 5355 | |
| 5356 | /** |
| 5357 | * Set whether this view should have haptic feedback for events such as |
| 5358 | * long presses. |
| 5359 | * |
| 5360 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5361 | * its own haptic feedback. |
| 5362 | * |
| 5363 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5364 | * @see #isHapticFeedbackEnabled() |
| 5365 | * @see #performHapticFeedback(int) |
| 5366 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5367 | */ |
| 5368 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5369 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5370 | } |
| 5371 | |
| 5372 | /** |
| 5373 | * @return whether this view should have haptic feedback enabled for events |
| 5374 | * long presses. |
| 5375 | * |
| 5376 | * @see #setHapticFeedbackEnabled(boolean) |
| 5377 | * @see #performHapticFeedback(int) |
| 5378 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5379 | */ |
| 5380 | @ViewDebug.ExportedProperty |
| 5381 | public boolean isHapticFeedbackEnabled() { |
| 5382 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5383 | } |
| 5384 | |
| 5385 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5386 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5387 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5388 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5389 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5390 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5391 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 5392 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5393 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 5394 | * @hide |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5395 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5396 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5397 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5398 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5399 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5400 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5401 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5402 | public int getLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5403 | return (mPrivateFlags2 & LAYOUT_DIRECTION_MASK) >> LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5407 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5408 | * resolution to the view's children and resolve layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5409 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5410 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5411 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5412 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5413 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5414 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5415 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 5416 | * @hide |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5417 | */ |
| 5418 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5419 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5420 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5421 | // Reset the current layout direction and the resolved one |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5422 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 5423 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5424 | // Set the new layout direction (filtered) and ask for a layout pass |
| 5425 | mPrivateFlags2 |= |
| 5426 | ((layoutDirection << LAYOUT_DIRECTION_MASK_SHIFT) & LAYOUT_DIRECTION_MASK); |
| 5427 | requestLayout(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5428 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5432 | * Returns the resolved layout direction for this view. |
| 5433 | * |
| 5434 | * @return {@link #LAYOUT_DIRECTION_RTL} if the layout direction is RTL or returns |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5435 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 5436 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5437 | */ |
| 5438 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5439 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5440 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5441 | }) |
| 5442 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 5443 | // The layout diretion will be resolved only if needed |
| 5444 | if ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED) != LAYOUT_DIRECTION_RESOLVED) { |
| 5445 | resolveLayoutDirection(); |
| 5446 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 5447 | return ((mPrivateFlags2 & LAYOUT_DIRECTION_RESOLVED_RTL) == LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5448 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 5449 | } |
| 5450 | |
| 5451 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5452 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5453 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5454 | * |
| 5455 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 5456 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5457 | */ |
| 5458 | @ViewDebug.ExportedProperty(category = "layout") |
| 5459 | public boolean isLayoutRtl() { |
| 5460 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 5461 | } |
| 5462 | |
| 5463 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5464 | * Indicates whether the view is currently tracking transient state that the |
| 5465 | * app should not need to concern itself with saving and restoring, but that |
| 5466 | * the framework should take special note to preserve when possible. |
| 5467 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5468 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5469 | * data source, such as an adapter binding item views in a list. This may be |
| 5470 | * because the view is performing an animation, tracking user selection |
| 5471 | * of content, or similar.</p> |
| 5472 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5473 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5474 | */ |
| 5475 | @ViewDebug.ExportedProperty(category = "layout") |
| 5476 | public boolean hasTransientState() { |
| 5477 | return (mPrivateFlags2 & HAS_TRANSIENT_STATE) == HAS_TRANSIENT_STATE; |
| 5478 | } |
| 5479 | |
| 5480 | /** |
| 5481 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5482 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 5483 | * so every call to setHasTransientState(true) should be paired with a later call |
| 5484 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5485 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5486 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5487 | * data source, such as an adapter binding item views in a list. This may be |
| 5488 | * because the view is performing an animation, tracking user selection |
| 5489 | * of content, or similar.</p> |
| 5490 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5491 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5492 | */ |
| 5493 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5494 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 5495 | mTransientStateCount - 1; |
| 5496 | if (mTransientStateCount < 0) { |
| 5497 | mTransientStateCount = 0; |
| 5498 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 5499 | "unmatched pair of setHasTransientState calls"); |
| 5500 | } |
| 5501 | if ((hasTransientState && mTransientStateCount == 1) || |
| 5502 | (hasTransientState && mTransientStateCount == 0)) { |
| 5503 | // update flag if we've just incremented up from 0 or decremented down to 0 |
| 5504 | mPrivateFlags2 = (mPrivateFlags2 & ~HAS_TRANSIENT_STATE) | |
| 5505 | (hasTransientState ? HAS_TRANSIENT_STATE : 0); |
| 5506 | if (mParent != null) { |
| 5507 | try { |
| 5508 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5509 | } catch (AbstractMethodError e) { |
| 5510 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5511 | " does not fully implement ViewParent", e); |
| 5512 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5513 | } |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5518 | * If this view doesn't do any drawing on its own, set this flag to |
| 5519 | * allow further optimizations. By default, this flag is not set on |
| 5520 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5521 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5522 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5523 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5524 | * |
| 5525 | * @param willNotDraw whether or not this View draw on its own |
| 5526 | */ |
| 5527 | public void setWillNotDraw(boolean willNotDraw) { |
| 5528 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5529 | } |
| 5530 | |
| 5531 | /** |
| 5532 | * Returns whether or not this View draws on its own. |
| 5533 | * |
| 5534 | * @return true if this view has nothing to draw, false otherwise |
| 5535 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5536 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5537 | public boolean willNotDraw() { |
| 5538 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5539 | } |
| 5540 | |
| 5541 | /** |
| 5542 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5543 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5544 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5545 | * unnecessary usage of the memory. |
| 5546 | * |
| 5547 | * @param willNotCacheDrawing true if this view does not cache its |
| 5548 | * drawing, false otherwise |
| 5549 | */ |
| 5550 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 5551 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 5552 | } |
| 5553 | |
| 5554 | /** |
| 5555 | * Returns whether or not this View can cache its drawing or not. |
| 5556 | * |
| 5557 | * @return true if this view does not cache its drawing, false otherwise |
| 5558 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5559 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | public boolean willNotCacheDrawing() { |
| 5561 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 5562 | } |
| 5563 | |
| 5564 | /** |
| 5565 | * Indicates whether this view reacts to click events or not. |
| 5566 | * |
| 5567 | * @return true if the view is clickable, false otherwise |
| 5568 | * |
| 5569 | * @see #setClickable(boolean) |
| 5570 | * @attr ref android.R.styleable#View_clickable |
| 5571 | */ |
| 5572 | @ViewDebug.ExportedProperty |
| 5573 | public boolean isClickable() { |
| 5574 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 5575 | } |
| 5576 | |
| 5577 | /** |
| 5578 | * Enables or disables click events for this view. When a view |
| 5579 | * is clickable it will change its state to "pressed" on every click. |
| 5580 | * Subclasses should set the view clickable to visually react to |
| 5581 | * user's clicks. |
| 5582 | * |
| 5583 | * @param clickable true to make the view clickable, false otherwise |
| 5584 | * |
| 5585 | * @see #isClickable() |
| 5586 | * @attr ref android.R.styleable#View_clickable |
| 5587 | */ |
| 5588 | public void setClickable(boolean clickable) { |
| 5589 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 5590 | } |
| 5591 | |
| 5592 | /** |
| 5593 | * Indicates whether this view reacts to long click events or not. |
| 5594 | * |
| 5595 | * @return true if the view is long clickable, false otherwise |
| 5596 | * |
| 5597 | * @see #setLongClickable(boolean) |
| 5598 | * @attr ref android.R.styleable#View_longClickable |
| 5599 | */ |
| 5600 | public boolean isLongClickable() { |
| 5601 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5602 | } |
| 5603 | |
| 5604 | /** |
| 5605 | * Enables or disables long click events for this view. When a view is long |
| 5606 | * clickable it reacts to the user holding down the button for a longer |
| 5607 | * duration than a tap. This event can either launch the listener or a |
| 5608 | * context menu. |
| 5609 | * |
| 5610 | * @param longClickable true to make the view long clickable, false otherwise |
| 5611 | * @see #isLongClickable() |
| 5612 | * @attr ref android.R.styleable#View_longClickable |
| 5613 | */ |
| 5614 | public void setLongClickable(boolean longClickable) { |
| 5615 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5616 | } |
| 5617 | |
| 5618 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5619 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5620 | * |
| 5621 | * @see #isClickable() |
| 5622 | * @see #setClickable(boolean) |
| 5623 | * |
| 5624 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5625 | * the View's internal state from a previously set "pressed" state. |
| 5626 | */ |
| 5627 | public void setPressed(boolean pressed) { |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5628 | final boolean needsRefresh = pressed != ((mPrivateFlags & PRESSED) == PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 5629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5630 | if (pressed) { |
| 5631 | mPrivateFlags |= PRESSED; |
| 5632 | } else { |
| 5633 | mPrivateFlags &= ~PRESSED; |
| 5634 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5635 | |
| 5636 | if (needsRefresh) { |
| 5637 | refreshDrawableState(); |
| 5638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5639 | dispatchSetPressed(pressed); |
| 5640 | } |
| 5641 | |
| 5642 | /** |
| 5643 | * Dispatch setPressed to all of this View's children. |
| 5644 | * |
| 5645 | * @see #setPressed(boolean) |
| 5646 | * |
| 5647 | * @param pressed The new pressed state |
| 5648 | */ |
| 5649 | protected void dispatchSetPressed(boolean pressed) { |
| 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * Indicates whether the view is currently in pressed state. Unless |
| 5654 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5655 | * the pressed state. |
| 5656 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5657 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | * @see #isClickable() |
| 5659 | * @see #setClickable(boolean) |
| 5660 | * |
| 5661 | * @return true if the view is currently pressed, false otherwise |
| 5662 | */ |
| 5663 | public boolean isPressed() { |
| 5664 | return (mPrivateFlags & PRESSED) == PRESSED; |
| 5665 | } |
| 5666 | |
| 5667 | /** |
| 5668 | * Indicates whether this view will save its state (that is, |
| 5669 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5670 | * |
| 5671 | * @return Returns true if the view state saving is enabled, else false. |
| 5672 | * |
| 5673 | * @see #setSaveEnabled(boolean) |
| 5674 | * @attr ref android.R.styleable#View_saveEnabled |
| 5675 | */ |
| 5676 | public boolean isSaveEnabled() { |
| 5677 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5678 | } |
| 5679 | |
| 5680 | /** |
| 5681 | * Controls whether the saving of this view's state is |
| 5682 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5683 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5684 | * view still must have an id assigned to it (via {@link #setId(int)}) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5685 | * for its state to be saved. This flag can only disable the |
| 5686 | * saving of this view; any child views may still have their state saved. |
| 5687 | * |
| 5688 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5689 | * (the default) to allow it. |
| 5690 | * |
| 5691 | * @see #isSaveEnabled() |
| 5692 | * @see #setId(int) |
| 5693 | * @see #onSaveInstanceState() |
| 5694 | * @attr ref android.R.styleable#View_saveEnabled |
| 5695 | */ |
| 5696 | public void setSaveEnabled(boolean enabled) { |
| 5697 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5698 | } |
| 5699 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5700 | /** |
| 5701 | * Gets whether the framework should discard touches when the view's |
| 5702 | * window is obscured by another visible window. |
| 5703 | * Refer to the {@link View} security documentation for more details. |
| 5704 | * |
| 5705 | * @return True if touch filtering is enabled. |
| 5706 | * |
| 5707 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5708 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5709 | */ |
| 5710 | @ViewDebug.ExportedProperty |
| 5711 | public boolean getFilterTouchesWhenObscured() { |
| 5712 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5713 | } |
| 5714 | |
| 5715 | /** |
| 5716 | * Sets whether the framework should discard touches when the view's |
| 5717 | * window is obscured by another visible window. |
| 5718 | * Refer to the {@link View} security documentation for more details. |
| 5719 | * |
| 5720 | * @param enabled True if touch filtering should be enabled. |
| 5721 | * |
| 5722 | * @see #getFilterTouchesWhenObscured |
| 5723 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5724 | */ |
| 5725 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5726 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5727 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5729 | |
| 5730 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5731 | * Indicates whether the entire hierarchy under this view will save its |
| 5732 | * state when a state saving traversal occurs from its parent. The default |
| 5733 | * is true; if false, these views will not be saved unless |
| 5734 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5735 | * |
| 5736 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5737 | * |
| 5738 | * @see #setSaveFromParentEnabled(boolean) |
| 5739 | */ |
| 5740 | public boolean isSaveFromParentEnabled() { |
| 5741 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5742 | } |
| 5743 | |
| 5744 | /** |
| 5745 | * Controls whether the entire hierarchy under this view will save its |
| 5746 | * state when a state saving traversal occurs from its parent. The default |
| 5747 | * is true; if false, these views will not be saved unless |
| 5748 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5749 | * |
| 5750 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5751 | * (the default) to allow it. |
| 5752 | * |
| 5753 | * @see #isSaveFromParentEnabled() |
| 5754 | * @see #setId(int) |
| 5755 | * @see #onSaveInstanceState() |
| 5756 | */ |
| 5757 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5758 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5759 | } |
| 5760 | |
| 5761 | |
| 5762 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5763 | * Returns whether this View is able to take focus. |
| 5764 | * |
| 5765 | * @return True if this view can take focus, or false otherwise. |
| 5766 | * @attr ref android.R.styleable#View_focusable |
| 5767 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5768 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5769 | public final boolean isFocusable() { |
| 5770 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 5771 | } |
| 5772 | |
| 5773 | /** |
| 5774 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 5775 | * For example, a button would like focus when the user is navigating via a D-pad |
| 5776 | * so that the user can click on it, but once the user starts touching the screen, |
| 5777 | * the button shouldn't take focus |
| 5778 | * @return Whether the view is focusable in touch mode. |
| 5779 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5780 | */ |
| 5781 | @ViewDebug.ExportedProperty |
| 5782 | public final boolean isFocusableInTouchMode() { |
| 5783 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 5784 | } |
| 5785 | |
| 5786 | /** |
| 5787 | * Find the nearest view in the specified direction that can take focus. |
| 5788 | * This does not actually give focus to that view. |
| 5789 | * |
| 5790 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 5791 | * |
| 5792 | * @return The nearest focusable in the specified direction, or null if none |
| 5793 | * can be found. |
| 5794 | */ |
| 5795 | public View focusSearch(int direction) { |
| 5796 | if (mParent != null) { |
| 5797 | return mParent.focusSearch(this, direction); |
| 5798 | } else { |
| 5799 | return null; |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | /** |
| 5804 | * This method is the last chance for the focused view and its ancestors to |
| 5805 | * respond to an arrow key. This is called when the focused view did not |
| 5806 | * consume the key internally, nor could the view system find a new view in |
| 5807 | * the requested direction to give focus to. |
| 5808 | * |
| 5809 | * @param focused The currently focused view. |
| 5810 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 5811 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 5812 | * @return True if the this view consumed this unhandled move. |
| 5813 | */ |
| 5814 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 5815 | return false; |
| 5816 | } |
| 5817 | |
| 5818 | /** |
| 5819 | * If a user manually specified the next view id for a particular direction, |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5820 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5821 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5822 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 5823 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | * @return The user specified next view, or null if there is none. |
| 5825 | */ |
| 5826 | View findUserSetNextFocus(View root, int direction) { |
| 5827 | switch (direction) { |
| 5828 | case FOCUS_LEFT: |
| 5829 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5830 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5831 | case FOCUS_RIGHT: |
| 5832 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5833 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | case FOCUS_UP: |
| 5835 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5836 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | case FOCUS_DOWN: |
| 5838 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5839 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5840 | case FOCUS_FORWARD: |
| 5841 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5842 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5843 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 5844 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5845 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5846 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5847 | @Override |
| 5848 | public boolean apply(View t) { |
| 5849 | return t.mNextFocusForwardId == id; |
| 5850 | } |
| 5851 | }); |
| 5852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5853 | } |
| 5854 | return null; |
| 5855 | } |
| 5856 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 5857 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 5858 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 5859 | @Override |
| 5860 | public boolean apply(View t) { |
| 5861 | return t.mID == childViewId; |
| 5862 | } |
| 5863 | }); |
| 5864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5865 | if (result == null) { |
| 5866 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 5867 | + "by user for id " + childViewId); |
| 5868 | } |
| 5869 | return result; |
| 5870 | } |
| 5871 | |
| 5872 | /** |
| 5873 | * Find and return all focusable views that are descendants of this view, |
| 5874 | * possibly including this view if it is focusable itself. |
| 5875 | * |
| 5876 | * @param direction The direction of the focus |
| 5877 | * @return A list of focusable views |
| 5878 | */ |
| 5879 | public ArrayList<View> getFocusables(int direction) { |
| 5880 | ArrayList<View> result = new ArrayList<View>(24); |
| 5881 | addFocusables(result, direction); |
| 5882 | return result; |
| 5883 | } |
| 5884 | |
| 5885 | /** |
| 5886 | * Add any focusable views that are descendants of this view (possibly |
| 5887 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 5888 | * only add views that are also focusable in touch mode. |
| 5889 | * |
| 5890 | * @param views Focusable views found so far |
| 5891 | * @param direction The direction of the focus |
| 5892 | */ |
| 5893 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5894 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 5895 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5896 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5897 | /** |
| 5898 | * Adds any focusable views that are descendants of this view (possibly |
| 5899 | * including this view if it is focusable itself) to views. This method |
| 5900 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5901 | * only views focusable in touch mode if we are in touch mode or |
| 5902 | * only views that can take accessibility focus if accessibility is enabeld |
| 5903 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5904 | * |
| 5905 | * @param views Focusable views found so far or null if all we are interested is |
| 5906 | * the number of focusables. |
| 5907 | * @param direction The direction of the focus. |
| 5908 | * @param focusableMode The type of focusables to be added. |
| 5909 | * |
| 5910 | * @see #FOCUSABLES_ALL |
| 5911 | * @see #FOCUSABLES_TOUCH_MODE |
| 5912 | */ |
| 5913 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5914 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5915 | return; |
| 5916 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5917 | if ((focusableMode & FOCUSABLES_ACCESSIBILITY) == FOCUSABLES_ACCESSIBILITY) { |
| 5918 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 5919 | && includeForAccessibility()) { |
| 5920 | views.add(this); |
| 5921 | return; |
| 5922 | } |
| 5923 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 5924 | if (!isFocusable()) { |
| 5925 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5926 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 5927 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 5928 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 5929 | return; |
| 5930 | } |
| 5931 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5935 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5936 | * The search is performed by either the text that the View renders or the content |
| 5937 | * description that describes the view for accessibility purposes and the view does |
| 5938 | * not render or both. Clients can specify how the search is to be performed via |
| 5939 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 5940 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5941 | * |
| 5942 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5943 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5944 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5945 | * @see #FIND_VIEWS_WITH_TEXT |
| 5946 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 5947 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5948 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5949 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5950 | if (getAccessibilityNodeProvider() != null) { |
| 5951 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 5952 | outViews.add(this); |
| 5953 | } |
| 5954 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
| 5955 | && !TextUtils.isEmpty(searched) && !TextUtils.isEmpty(mContentDescription)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 5956 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 5957 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 5958 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 5959 | outViews.add(this); |
| 5960 | } |
| 5961 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5962 | } |
| 5963 | |
| 5964 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5965 | * Find and return all touchable views that are descendants of this view, |
| 5966 | * possibly including this view if it is touchable itself. |
| 5967 | * |
| 5968 | * @return A list of touchable views |
| 5969 | */ |
| 5970 | public ArrayList<View> getTouchables() { |
| 5971 | ArrayList<View> result = new ArrayList<View>(); |
| 5972 | addTouchables(result); |
| 5973 | return result; |
| 5974 | } |
| 5975 | |
| 5976 | /** |
| 5977 | * Add any touchable views that are descendants of this view (possibly |
| 5978 | * including this view if it is touchable itself) to views. |
| 5979 | * |
| 5980 | * @param views Touchable views found so far |
| 5981 | */ |
| 5982 | public void addTouchables(ArrayList<View> views) { |
| 5983 | final int viewFlags = mViewFlags; |
| 5984 | |
| 5985 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 5986 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 5987 | views.add(this); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5992 | * Returns whether this View is accessibility focused. |
| 5993 | * |
| 5994 | * @return True if this View is accessibility focused. |
| 5995 | */ |
| 5996 | boolean isAccessibilityFocused() { |
| 5997 | return (mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0; |
| 5998 | } |
| 5999 | |
| 6000 | /** |
| 6001 | * Call this to try to give accessibility focus to this view. |
| 6002 | * |
| 6003 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 6004 | * returns false or the view is no visible or the view already has accessibility |
| 6005 | * focus. |
| 6006 | * |
| 6007 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6008 | * have focus, and you want your parent to look for the next one. |
| 6009 | * |
| 6010 | * @return Whether this view actually took accessibility focus. |
| 6011 | * |
| 6012 | * @hide |
| 6013 | */ |
| 6014 | public boolean requestAccessibilityFocus() { |
Svetoslav Ganov | 07b726c | 2012-04-30 12:24:57 -0700 | [diff] [blame] | 6015 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 6016 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6017 | return false; |
| 6018 | } |
| 6019 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6020 | return false; |
| 6021 | } |
| 6022 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) == 0) { |
| 6023 | mPrivateFlags2 |= ACCESSIBILITY_FOCUSED; |
| 6024 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6025 | if (viewRootImpl != null) { |
| 6026 | viewRootImpl.setAccessibilityFocusedHost(this); |
| 6027 | } |
| 6028 | invalidate(); |
| 6029 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 6030 | notifyAccessibilityStateChanged(); |
| 6031 | // Try to give input focus to this view - not a descendant. |
| 6032 | requestFocusNoSearch(View.FOCUS_DOWN, null); |
| 6033 | return true; |
| 6034 | } |
| 6035 | return false; |
| 6036 | } |
| 6037 | |
| 6038 | /** |
| 6039 | * Call this to try to clear accessibility focus of this view. |
| 6040 | * |
| 6041 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6042 | * have focus, and you want your parent to look for the next one. |
| 6043 | * |
| 6044 | * @hide |
| 6045 | */ |
| 6046 | public void clearAccessibilityFocus() { |
| 6047 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0) { |
| 6048 | mPrivateFlags2 &= ~ACCESSIBILITY_FOCUSED; |
| 6049 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6050 | if (viewRootImpl != null) { |
| 6051 | viewRootImpl.setAccessibilityFocusedHost(null); |
| 6052 | } |
| 6053 | invalidate(); |
| 6054 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 6055 | notifyAccessibilityStateChanged(); |
| 6056 | // Try to move accessibility focus to the input focus. |
| 6057 | View rootView = getRootView(); |
| 6058 | if (rootView != null) { |
| 6059 | View inputFocus = rootView.findFocus(); |
| 6060 | if (inputFocus != null) { |
| 6061 | inputFocus.requestAccessibilityFocus(); |
| 6062 | } |
| 6063 | } |
| 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | /** |
| 6068 | * Find the best view to take accessibility focus from a hover. |
| 6069 | * This function finds the deepest actionable view and if that |
| 6070 | * fails ask the parent to take accessibility focus from hover. |
| 6071 | * |
| 6072 | * @param x The X hovered location in this view coorditantes. |
| 6073 | * @param y The Y hovered location in this view coorditantes. |
| 6074 | * @return Whether the request was handled. |
| 6075 | * |
| 6076 | * @hide |
| 6077 | */ |
| 6078 | public boolean requestAccessibilityFocusFromHover(float x, float y) { |
| 6079 | if (onRequestAccessibilityFocusFromHover(x, y)) { |
| 6080 | return true; |
| 6081 | } |
| 6082 | ViewParent parent = mParent; |
| 6083 | if (parent instanceof View) { |
| 6084 | View parentView = (View) parent; |
| 6085 | |
| 6086 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 6087 | position[0] = x; |
| 6088 | position[1] = y; |
| 6089 | |
| 6090 | // Compensate for the transformation of the current matrix. |
| 6091 | if (!hasIdentityMatrix()) { |
| 6092 | getMatrix().mapPoints(position); |
| 6093 | } |
| 6094 | |
| 6095 | // Compensate for the parent scroll and the offset |
| 6096 | // of this view stop from the parent top. |
| 6097 | position[0] += mLeft - parentView.mScrollX; |
| 6098 | position[1] += mTop - parentView.mScrollY; |
| 6099 | |
| 6100 | return parentView.requestAccessibilityFocusFromHover(position[0], position[1]); |
| 6101 | } |
| 6102 | return false; |
| 6103 | } |
| 6104 | |
| 6105 | /** |
| 6106 | * Requests to give this View focus from hover. |
| 6107 | * |
| 6108 | * @param x The X hovered location in this view coorditantes. |
| 6109 | * @param y The Y hovered location in this view coorditantes. |
| 6110 | * @return Whether the request was handled. |
| 6111 | * |
| 6112 | * @hide |
| 6113 | */ |
| 6114 | public boolean onRequestAccessibilityFocusFromHover(float x, float y) { |
| 6115 | if (includeForAccessibility() |
| 6116 | && (isActionableForAccessibility() || hasListenersForAccessibility())) { |
| 6117 | return requestAccessibilityFocus(); |
| 6118 | } |
| 6119 | return false; |
| 6120 | } |
| 6121 | |
| 6122 | /** |
| 6123 | * Clears accessibility focus without calling any callback methods |
| 6124 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6125 | * is used for clearing accessibility focus when giving this focus to |
| 6126 | * another view. |
| 6127 | */ |
| 6128 | void clearAccessibilityFocusNoCallbacks() { |
| 6129 | if ((mPrivateFlags2 & ACCESSIBILITY_FOCUSED) != 0) { |
| 6130 | mPrivateFlags2 &= ~ACCESSIBILITY_FOCUSED; |
| 6131 | invalidate(); |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6136 | * Call this to try to give focus to a specific view or to one of its |
| 6137 | * descendants. |
| 6138 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6139 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6140 | * false), or if it is focusable and it is not focusable in touch mode |
| 6141 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6143 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | * have focus, and you want your parent to look for the next one. |
| 6145 | * |
| 6146 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6147 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6148 | * |
| 6149 | * @return Whether this view or one of its descendants actually took focus. |
| 6150 | */ |
| 6151 | public final boolean requestFocus() { |
| 6152 | return requestFocus(View.FOCUS_DOWN); |
| 6153 | } |
| 6154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | /** |
| 6156 | * Call this to try to give focus to a specific view or to one of its |
| 6157 | * descendants and give it a hint about what direction focus is heading. |
| 6158 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6159 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6160 | * false), or if it is focusable and it is not focusable in touch mode |
| 6161 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6163 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | * have focus, and you want your parent to look for the next one. |
| 6165 | * |
| 6166 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6167 | * <code>null</code> set for the previously focused rectangle. |
| 6168 | * |
| 6169 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6170 | * @return Whether this view or one of its descendants actually took focus. |
| 6171 | */ |
| 6172 | public final boolean requestFocus(int direction) { |
| 6173 | return requestFocus(direction, null); |
| 6174 | } |
| 6175 | |
| 6176 | /** |
| 6177 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6178 | * and give it hints about the direction and a specific rectangle that the focus |
| 6179 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6180 | * about where focus is coming from, and therefore, where to show selection, or |
| 6181 | * forward focus change internally. |
| 6182 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6183 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6184 | * false), or if it is focusable and it is not focusable in touch mode |
| 6185 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | * |
| 6187 | * A View will not take focus if it is not visible. |
| 6188 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6189 | * A View will not take focus if one of its parents has |
| 6190 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6191 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6192 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6193 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | * have focus, and you want your parent to look for the next one. |
| 6195 | * |
| 6196 | * You may wish to override this method if your custom {@link View} has an internal |
| 6197 | * {@link View} that it wishes to forward the request to. |
| 6198 | * |
| 6199 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6200 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6201 | * to give a finer grained hint about where focus is coming from. May be null |
| 6202 | * if there is no hint. |
| 6203 | * @return Whether this view or one of its descendants actually took focus. |
| 6204 | */ |
| 6205 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6206 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6207 | } |
| 6208 | |
| 6209 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6210 | // need to be focusable |
| 6211 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6212 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6213 | return false; |
| 6214 | } |
| 6215 | |
| 6216 | // need to be focusable in touch mode if in touch mode |
| 6217 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6218 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6219 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6220 | } |
| 6221 | |
| 6222 | // need to not have any parents blocking us |
| 6223 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6224 | return false; |
| 6225 | } |
| 6226 | |
| 6227 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6228 | return true; |
| 6229 | } |
| 6230 | |
| 6231 | /** |
| 6232 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6233 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6234 | * touch mode to request focus when they are touched. |
| 6235 | * |
| 6236 | * @return Whether this view or one of its descendants actually took focus. |
| 6237 | * |
| 6238 | * @see #isInTouchMode() |
| 6239 | * |
| 6240 | */ |
| 6241 | public final boolean requestFocusFromTouch() { |
| 6242 | // Leave touch mode if we need to |
| 6243 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6244 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6245 | if (viewRoot != null) { |
| 6246 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6247 | } |
| 6248 | } |
| 6249 | return requestFocus(View.FOCUS_DOWN); |
| 6250 | } |
| 6251 | |
| 6252 | /** |
| 6253 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6254 | */ |
| 6255 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6256 | ViewParent ancestor = mParent; |
| 6257 | while (ancestor instanceof ViewGroup) { |
| 6258 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6259 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6260 | return true; |
| 6261 | } else { |
| 6262 | ancestor = vgAncestor.getParent(); |
| 6263 | } |
| 6264 | } |
| 6265 | return false; |
| 6266 | } |
| 6267 | |
| 6268 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6269 | * Gets the mode for determining whether this View is important for accessibility |
| 6270 | * which is if it fires accessibility events and if it is reported to |
| 6271 | * accessibility services that query the screen. |
| 6272 | * |
| 6273 | * @return The mode for determining whether a View is important for accessibility. |
| 6274 | * |
| 6275 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6276 | * |
| 6277 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6278 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6279 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6280 | */ |
| 6281 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
| 6282 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, |
| 6283 | to = "IMPORTANT_FOR_ACCESSIBILITY_AUTO"), |
| 6284 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, |
| 6285 | to = "IMPORTANT_FOR_ACCESSIBILITY_YES"), |
| 6286 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, |
| 6287 | to = "IMPORTANT_FOR_ACCESSIBILITY_NO") |
| 6288 | }) |
| 6289 | public int getImportantForAccessibility() { |
| 6290 | return (mPrivateFlags2 & IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6291 | >> IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 6292 | } |
| 6293 | |
| 6294 | /** |
| 6295 | * Sets how to determine whether this view is important for accessibility |
| 6296 | * which is if it fires accessibility events and if it is reported to |
| 6297 | * accessibility services that query the screen. |
| 6298 | * |
| 6299 | * @param mode How to determine whether this view is important for accessibility. |
| 6300 | * |
| 6301 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6302 | * |
| 6303 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6304 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6305 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6306 | */ |
| 6307 | public void setImportantForAccessibility(int mode) { |
| 6308 | if (mode != getImportantForAccessibility()) { |
| 6309 | mPrivateFlags2 &= ~IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6310 | mPrivateFlags2 |= (mode << IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6311 | & IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6312 | notifyAccessibilityStateChanged(); |
| 6313 | } |
| 6314 | } |
| 6315 | |
| 6316 | /** |
| 6317 | * Gets whether this view should be exposed for accessibility. |
| 6318 | * |
| 6319 | * @return Whether the view is exposed for accessibility. |
| 6320 | * |
| 6321 | * @hide |
| 6322 | */ |
| 6323 | public boolean isImportantForAccessibility() { |
| 6324 | final int mode = (mPrivateFlags2 & IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6325 | >> IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
| 6326 | switch (mode) { |
| 6327 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6328 | return true; |
| 6329 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6330 | return false; |
| 6331 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
| 6332 | return isActionableForAccessibility() || hasListenersForAccessibility(); |
| 6333 | default: |
| 6334 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6335 | + mode); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | /** |
| 6340 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6341 | * accessibility is not necessary the immediate parent. It is the first |
| 6342 | * predecessor that is important for accessibility. |
| 6343 | * |
| 6344 | * @return The parent for accessibility purposes. |
| 6345 | */ |
| 6346 | public ViewParent getParentForAccessibility() { |
| 6347 | if (mParent instanceof View) { |
| 6348 | View parentView = (View) mParent; |
| 6349 | if (parentView.includeForAccessibility()) { |
| 6350 | return mParent; |
| 6351 | } else { |
| 6352 | return mParent.getParentForAccessibility(); |
| 6353 | } |
| 6354 | } |
| 6355 | return null; |
| 6356 | } |
| 6357 | |
| 6358 | /** |
| 6359 | * Adds the children of a given View for accessibility. Since some Views are |
| 6360 | * not important for accessibility the children for accessibility are not |
| 6361 | * necessarily direct children of the riew, rather they are the first level of |
| 6362 | * descendants important for accessibility. |
| 6363 | * |
| 6364 | * @param children The list of children for accessibility. |
| 6365 | */ |
| 6366 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6367 | if (includeForAccessibility()) { |
| 6368 | children.add(this); |
| 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | /** |
| 6373 | * Whether to regard this view for accessibility. A view is regarded for |
| 6374 | * accessibility if it is important for accessibility or the querying |
| 6375 | * accessibility service has explicitly requested that view not |
| 6376 | * important for accessibility are regarded. |
| 6377 | * |
| 6378 | * @return Whether to regard the view for accessibility. |
| 6379 | */ |
| 6380 | boolean includeForAccessibility() { |
| 6381 | if (mAttachInfo != null) { |
| 6382 | if (!mAttachInfo.mIncludeNotImportantViews) { |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 6383 | return isImportantForAccessibility() && isDisplayedOnScreen(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6384 | } else { |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 6385 | return isDisplayedOnScreen(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6386 | } |
| 6387 | } |
| 6388 | return false; |
| 6389 | } |
| 6390 | |
| 6391 | /** |
| 6392 | * Returns whether the View is considered actionable from |
| 6393 | * accessibility perspective. Such view are important for |
| 6394 | * accessiiblity. |
| 6395 | * |
| 6396 | * @return True if the view is actionable for accessibility. |
| 6397 | */ |
| 6398 | private boolean isActionableForAccessibility() { |
| 6399 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6400 | } |
| 6401 | |
| 6402 | /** |
| 6403 | * Returns whether the View has registered callbacks wich makes it |
| 6404 | * important for accessiiblity. |
| 6405 | * |
| 6406 | * @return True if the view is actionable for accessibility. |
| 6407 | */ |
| 6408 | private boolean hasListenersForAccessibility() { |
| 6409 | ListenerInfo info = getListenerInfo(); |
| 6410 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6411 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6412 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6413 | } |
| 6414 | |
| 6415 | /** |
| 6416 | * Notifies accessibility services that some view's important for |
| 6417 | * accessibility state has changed. Note that such notifications |
| 6418 | * are made at most once every |
| 6419 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6420 | * to avoid unnecessary load to the system. Also once a view has |
| 6421 | * made a notifucation this method is a NOP until the notification has |
| 6422 | * been sent to clients. |
| 6423 | * |
| 6424 | * @hide |
| 6425 | * |
| 6426 | * TODO: Makse sure this method is called for any view state change |
| 6427 | * that is interesting for accessilility purposes. |
| 6428 | */ |
| 6429 | public void notifyAccessibilityStateChanged() { |
| 6430 | if ((mPrivateFlags2 & ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6431 | mPrivateFlags2 |= ACCESSIBILITY_STATE_CHANGED; |
| 6432 | if (mParent != null) { |
| 6433 | mParent.childAccessibilityStateChanged(this); |
| 6434 | } |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | /** |
| 6439 | * Reset the state indicating the this view has requested clients |
| 6440 | * interested in its accessiblity state to be notified. |
| 6441 | * |
| 6442 | * @hide |
| 6443 | */ |
| 6444 | public void resetAccessibilityStateChanged() { |
| 6445 | mPrivateFlags2 &= ~ACCESSIBILITY_STATE_CHANGED; |
| 6446 | } |
| 6447 | |
| 6448 | /** |
| 6449 | * Performs the specified accessibility action on the view. For |
| 6450 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 6451 | * |
| 6452 | * @param action The action to perform. |
| 6453 | * @return Whether the action was performed. |
| 6454 | */ |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 6455 | public boolean performAccessibilityAction(int action, Bundle args) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6456 | switch (action) { |
| 6457 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6458 | if (isClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6459 | return performClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6460 | } |
| 6461 | } break; |
| 6462 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6463 | if (isLongClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6464 | return performLongClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6465 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6466 | } break; |
| 6467 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6468 | if (!hasFocus()) { |
| 6469 | // Get out of touch mode since accessibility |
| 6470 | // wants to move focus around. |
| 6471 | getViewRootImpl().ensureTouchMode(false); |
| 6472 | return requestFocus(); |
| 6473 | } |
| 6474 | } break; |
| 6475 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6476 | if (hasFocus()) { |
| 6477 | clearFocus(); |
| 6478 | return !isFocused(); |
| 6479 | } |
| 6480 | } break; |
| 6481 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6482 | if (!isSelected()) { |
| 6483 | setSelected(true); |
| 6484 | return isSelected(); |
| 6485 | } |
| 6486 | } break; |
| 6487 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6488 | if (isSelected()) { |
| 6489 | setSelected(false); |
| 6490 | return !isSelected(); |
| 6491 | } |
| 6492 | } break; |
| 6493 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
| 6494 | if (!isAccessibilityFocused()) { |
| 6495 | return requestAccessibilityFocus(); |
| 6496 | } |
| 6497 | } break; |
| 6498 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 6499 | if (isAccessibilityFocused()) { |
| 6500 | clearAccessibilityFocus(); |
| 6501 | return true; |
| 6502 | } |
| 6503 | } break; |
| 6504 | } |
| 6505 | return false; |
| 6506 | } |
| 6507 | |
| 6508 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6509 | * @hide |
| 6510 | */ |
| 6511 | public void dispatchStartTemporaryDetach() { |
| 6512 | onStartTemporaryDetach(); |
| 6513 | } |
| 6514 | |
| 6515 | /** |
| 6516 | * This is called when a container is going to temporarily detach a child, with |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 6518 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6519 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | */ |
| 6521 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6522 | removeUnsetPressCallback(); |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 6523 | mPrivateFlags |= CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | /** |
| 6527 | * @hide |
| 6528 | */ |
| 6529 | public void dispatchFinishTemporaryDetach() { |
| 6530 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | /** |
| 6534 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 6535 | * changing the view. |
| 6536 | */ |
| 6537 | public void onFinishTemporaryDetach() { |
| 6538 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6541 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 6542 | * for this view's window. Returns null if the view is not currently attached |
| 6543 | * to the window. Normally you will not need to use this directly, but |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6544 | * just use the standard high-level event callbacks like |
| 6545 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6546 | */ |
| 6547 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 6548 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 6549 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6550 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6551 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6552 | * Dispatch a key event before it is processed by any input method |
| 6553 | * associated with the view hierarchy. This can be used to intercept |
| 6554 | * key events in special situations before the IME consumes them; a |
| 6555 | * typical example would be handling the BACK key to update the application's |
| 6556 | * UI instead of allowing the IME to see it and close itself. |
| 6557 | * |
| 6558 | * @param event The key event to be dispatched. |
| 6559 | * @return True if the event was handled, false otherwise. |
| 6560 | */ |
| 6561 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 6562 | return onKeyPreIme(event.getKeyCode(), event); |
| 6563 | } |
| 6564 | |
| 6565 | /** |
| 6566 | * Dispatch a key event to the next view on the focus path. This path runs |
| 6567 | * from the top of the view tree down to the currently focused view. If this |
| 6568 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 6569 | * the next node down the focus path. This method also fires any key |
| 6570 | * listeners. |
| 6571 | * |
| 6572 | * @param event The key event to be dispatched. |
| 6573 | * @return True if the event was handled, false otherwise. |
| 6574 | */ |
| 6575 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6576 | if (mInputEventConsistencyVerifier != null) { |
| 6577 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 6578 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6580 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6581 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6582 | ListenerInfo li = mListenerInfo; |
| 6583 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6584 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6585 | return true; |
| 6586 | } |
| 6587 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6588 | if (event.dispatch(this, mAttachInfo != null |
| 6589 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 6590 | return true; |
| 6591 | } |
| 6592 | |
| 6593 | if (mInputEventConsistencyVerifier != null) { |
| 6594 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6595 | } |
| 6596 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6597 | } |
| 6598 | |
| 6599 | /** |
| 6600 | * Dispatches a key shortcut event. |
| 6601 | * |
| 6602 | * @param event The key event to be dispatched. |
| 6603 | * @return True if the event was handled by the view, false otherwise. |
| 6604 | */ |
| 6605 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6606 | return onKeyShortcut(event.getKeyCode(), event); |
| 6607 | } |
| 6608 | |
| 6609 | /** |
| 6610 | * Pass the touch screen motion event down to the target view, or this |
| 6611 | * view if it is the target. |
| 6612 | * |
| 6613 | * @param event The motion event to be dispatched. |
| 6614 | * @return True if the event was handled by the view, false otherwise. |
| 6615 | */ |
| 6616 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6617 | if (mInputEventConsistencyVerifier != null) { |
| 6618 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 6619 | } |
| 6620 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6621 | if (onFilterTouchEventForSecurity(event)) { |
| 6622 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6623 | ListenerInfo li = mListenerInfo; |
| 6624 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6625 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6626 | return true; |
| 6627 | } |
| 6628 | |
| 6629 | if (onTouchEvent(event)) { |
| 6630 | return true; |
| 6631 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6632 | } |
| 6633 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6634 | if (mInputEventConsistencyVerifier != null) { |
| 6635 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6636 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6637 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6641 | * Filter the touch event to apply security policies. |
| 6642 | * |
| 6643 | * @param event The motion event to be filtered. |
| 6644 | * @return True if the event should be dispatched, false if the event should be dropped. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6645 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6646 | * @see #getFilterTouchesWhenObscured |
| 6647 | */ |
| 6648 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6649 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6650 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 6651 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 6652 | // Window is obscured, drop this touch. |
| 6653 | return false; |
| 6654 | } |
| 6655 | return true; |
| 6656 | } |
| 6657 | |
| 6658 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6659 | * Pass a trackball motion event down to the focused view. |
| 6660 | * |
| 6661 | * @param event The motion event to be dispatched. |
| 6662 | * @return True if the event was handled by the view, false otherwise. |
| 6663 | */ |
| 6664 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6665 | if (mInputEventConsistencyVerifier != null) { |
| 6666 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 6667 | } |
| 6668 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6669 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6673 | * Dispatch a generic motion event. |
| 6674 | * <p> |
| 6675 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 6676 | * are delivered to the view under the pointer. All other generic motion events are |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6677 | * delivered to the focused view. Hover events are handled specially and are delivered |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6678 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6679 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6680 | * |
| 6681 | * @param event The motion event to be dispatched. |
| 6682 | * @return True if the event was handled by the view, false otherwise. |
| 6683 | */ |
| 6684 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6685 | if (mInputEventConsistencyVerifier != null) { |
| 6686 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 6687 | } |
| 6688 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6689 | final int source = event.getSource(); |
| 6690 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 6691 | final int action = event.getAction(); |
| 6692 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 6693 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 6694 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 6695 | if (dispatchHoverEvent(event)) { |
| 6696 | return true; |
| 6697 | } |
| 6698 | } else if (dispatchGenericPointerEvent(event)) { |
| 6699 | return true; |
| 6700 | } |
| 6701 | } else if (dispatchGenericFocusedEvent(event)) { |
| 6702 | return true; |
| 6703 | } |
| 6704 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6705 | if (dispatchGenericMotionEventInternal(event)) { |
| 6706 | return true; |
| 6707 | } |
| 6708 | |
| 6709 | if (mInputEventConsistencyVerifier != null) { |
| 6710 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6711 | } |
| 6712 | return false; |
| 6713 | } |
| 6714 | |
| 6715 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 6716 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6717 | ListenerInfo li = mListenerInfo; |
| 6718 | if (li != null && li.mOnGenericMotionListener != null |
| 6719 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6720 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6721 | return true; |
| 6722 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6723 | |
| 6724 | if (onGenericMotionEvent(event)) { |
| 6725 | return true; |
| 6726 | } |
| 6727 | |
| 6728 | if (mInputEventConsistencyVerifier != null) { |
| 6729 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6730 | } |
| 6731 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6735 | * Dispatch a hover event. |
| 6736 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6737 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6738 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6739 | * </p> |
| 6740 | * |
| 6741 | * @param event The motion event to be dispatched. |
| 6742 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6743 | */ |
| 6744 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 6745 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6746 | ListenerInfo li = mListenerInfo; |
| 6747 | if (li != null && li.mOnHoverListener != null |
| 6748 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6749 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 6750 | return true; |
| 6751 | } |
| 6752 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6753 | return onHoverEvent(event); |
| 6754 | } |
| 6755 | |
| 6756 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 6757 | * Returns true if the view has a child to which it has recently sent |
| 6758 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 6759 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 6760 | * @hide |
| 6761 | */ |
| 6762 | protected boolean hasHoveredChild() { |
| 6763 | return false; |
| 6764 | } |
| 6765 | |
| 6766 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6767 | * Dispatch a generic motion event to the view under the first pointer. |
| 6768 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6769 | * Do not call this method directly. |
| 6770 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6771 | * </p> |
| 6772 | * |
| 6773 | * @param event The motion event to be dispatched. |
| 6774 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6775 | */ |
| 6776 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 6777 | return false; |
| 6778 | } |
| 6779 | |
| 6780 | /** |
| 6781 | * Dispatch a generic motion event to the currently focused view. |
| 6782 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6783 | * Do not call this method directly. |
| 6784 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6785 | * </p> |
| 6786 | * |
| 6787 | * @param event The motion event to be dispatched. |
| 6788 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 6789 | */ |
| 6790 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 6791 | return false; |
| 6792 | } |
| 6793 | |
| 6794 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6795 | * Dispatch a pointer event. |
| 6796 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6797 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 6798 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 6799 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 6800 | * and should not be expected to handle other pointing device features. |
| 6801 | * </p> |
| 6802 | * |
| 6803 | * @param event The motion event to be dispatched. |
| 6804 | * @return True if the event was handled by the view, false otherwise. |
| 6805 | * @hide |
| 6806 | */ |
| 6807 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 6808 | if (event.isTouchEvent()) { |
| 6809 | return dispatchTouchEvent(event); |
| 6810 | } else { |
| 6811 | return dispatchGenericMotionEvent(event); |
| 6812 | } |
| 6813 | } |
| 6814 | |
| 6815 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6816 | * Called when the window containing this view gains or loses window focus. |
| 6817 | * ViewGroups should override to route to their children. |
| 6818 | * |
| 6819 | * @param hasFocus True if the window containing this view now has focus, |
| 6820 | * false otherwise. |
| 6821 | */ |
| 6822 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 6823 | onWindowFocusChanged(hasFocus); |
| 6824 | } |
| 6825 | |
| 6826 | /** |
| 6827 | * Called when the window containing this view gains or loses focus. Note |
| 6828 | * that this is separate from view focus: to receive key events, both |
| 6829 | * your view and its window must have focus. If a window is displayed |
| 6830 | * on top of yours that takes input focus, then your own window will lose |
| 6831 | * focus but the view focus will remain unchanged. |
| 6832 | * |
| 6833 | * @param hasWindowFocus True if the window containing this view now has |
| 6834 | * focus, false otherwise. |
| 6835 | */ |
| 6836 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 6837 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 6838 | if (!hasWindowFocus) { |
| 6839 | if (isPressed()) { |
| 6840 | setPressed(false); |
| 6841 | } |
| 6842 | if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6843 | imm.focusOut(this); |
| 6844 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 6845 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 6846 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 6847 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | } else if (imm != null && (mPrivateFlags & FOCUSED) != 0) { |
| 6849 | imm.focusIn(this); |
| 6850 | } |
| 6851 | refreshDrawableState(); |
| 6852 | } |
| 6853 | |
| 6854 | /** |
| 6855 | * Returns true if this view is in a window that currently has window focus. |
| 6856 | * Note that this is not the same as the view itself having focus. |
| 6857 | * |
| 6858 | * @return True if this view is in a window that currently has window focus. |
| 6859 | */ |
| 6860 | public boolean hasWindowFocus() { |
| 6861 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 6862 | } |
| 6863 | |
| 6864 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6865 | * Dispatch a view visibility change down the view hierarchy. |
| 6866 | * ViewGroups should override to route to their children. |
| 6867 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6868 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6869 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6870 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6871 | */ |
| 6872 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 6873 | onVisibilityChanged(changedView, visibility); |
| 6874 | } |
| 6875 | |
| 6876 | /** |
| 6877 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 6878 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 6879 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6880 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 6881 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6882 | */ |
| 6883 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6884 | if (visibility == VISIBLE) { |
| 6885 | if (mAttachInfo != null) { |
| 6886 | initialAwakenScrollBars(); |
| 6887 | } else { |
| 6888 | mPrivateFlags |= AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 6889 | } |
| 6890 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6894 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 6895 | * a View moves out of the screen, it might receives a display hint indicating |
| 6896 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6897 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6898 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6899 | * @param hint A hint about whether or not this view is displayed: |
| 6900 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6901 | */ |
| 6902 | public void dispatchDisplayHint(int hint) { |
| 6903 | onDisplayHint(hint); |
| 6904 | } |
| 6905 | |
| 6906 | /** |
| 6907 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 6908 | * a View moves out of the screen, it might receives a display hint indicating |
| 6909 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 6910 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6911 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 6912 | * @param hint A hint about whether or not this view is displayed: |
| 6913 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 6914 | */ |
| 6915 | protected void onDisplayHint(int hint) { |
| 6916 | } |
| 6917 | |
| 6918 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6919 | * Dispatch a window visibility change down the view hierarchy. |
| 6920 | * ViewGroups should override to route to their children. |
| 6921 | * |
| 6922 | * @param visibility The new visibility of the window. |
| 6923 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6924 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | */ |
| 6926 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 6927 | onWindowVisibilityChanged(visibility); |
| 6928 | } |
| 6929 | |
| 6930 | /** |
| 6931 | * Called when the window containing has change its visibility |
| 6932 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 6933 | * that this tells you whether or not your window is being made visible |
| 6934 | * to the window manager; this does <em>not</em> tell you whether or not |
| 6935 | * your window is obscured by other windows on the screen, even if it |
| 6936 | * is itself visible. |
| 6937 | * |
| 6938 | * @param visibility The new visibility of the window. |
| 6939 | */ |
| 6940 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 6941 | if (visibility == VISIBLE) { |
| 6942 | initialAwakenScrollBars(); |
| 6943 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | /** |
| 6947 | * Returns the current visibility of the window this view is attached to |
| 6948 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 6949 | * |
| 6950 | * @return Returns the current visibility of the view's window. |
| 6951 | */ |
| 6952 | public int getWindowVisibility() { |
| 6953 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 6954 | } |
| 6955 | |
| 6956 | /** |
| 6957 | * Retrieve the overall visible display size in which the window this view is |
| 6958 | * attached to has been positioned in. This takes into account screen |
| 6959 | * decorations above the window, for both cases where the window itself |
| 6960 | * is being position inside of them or the window is being placed under |
| 6961 | * then and covered insets are used for the window to position its content |
| 6962 | * inside. In effect, this tells you the available area where content can |
| 6963 | * be placed and remain visible to users. |
| 6964 | * |
| 6965 | * <p>This function requires an IPC back to the window manager to retrieve |
| 6966 | * the requested information, so should not be used in performance critical |
| 6967 | * code like drawing. |
| 6968 | * |
| 6969 | * @param outRect Filled in with the visible display frame. If the view |
| 6970 | * is not attached to a window, this is simply the raw display size. |
| 6971 | */ |
| 6972 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 6973 | if (mAttachInfo != null) { |
| 6974 | try { |
| 6975 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 6976 | } catch (RemoteException e) { |
| 6977 | return; |
| 6978 | } |
| 6979 | // XXX This is really broken, and probably all needs to be done |
| 6980 | // in the window manager, and we need to know more about whether |
| 6981 | // we want the area behind or in front of the IME. |
| 6982 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 6983 | outRect.left += insets.left; |
| 6984 | outRect.top += insets.top; |
| 6985 | outRect.right -= insets.right; |
| 6986 | outRect.bottom -= insets.bottom; |
| 6987 | return; |
| 6988 | } |
| 6989 | Display d = WindowManagerImpl.getDefault().getDefaultDisplay(); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 6990 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6991 | } |
| 6992 | |
| 6993 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6994 | * Dispatch a notification about a resource configuration change down |
| 6995 | * the view hierarchy. |
| 6996 | * ViewGroups should override to route to their children. |
| 6997 | * |
| 6998 | * @param newConfig The new resource configuration. |
| 6999 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7000 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7001 | */ |
| 7002 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 7003 | onConfigurationChanged(newConfig); |
| 7004 | } |
| 7005 | |
| 7006 | /** |
| 7007 | * Called when the current configuration of the resources being used |
| 7008 | * by the application have changed. You can use this to decide when |
| 7009 | * to reload resources that can changed based on orientation and other |
| 7010 | * configuration characterstics. You only need to use this if you are |
| 7011 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 7012 | * recreating the activity instance upon a configuration change. |
| 7013 | * |
| 7014 | * @param newConfig The new resource configuration. |
| 7015 | */ |
| 7016 | protected void onConfigurationChanged(Configuration newConfig) { |
| 7017 | } |
| 7018 | |
| 7019 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | * Private function to aggregate all per-view attributes in to the view |
| 7021 | * root. |
| 7022 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7023 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7024 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7025 | } |
| 7026 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7027 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7028 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7029 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7030 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7031 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7032 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7033 | ListenerInfo li = mListenerInfo; |
| 7034 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7035 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7041 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7043 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 7044 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | ai.mRecomputeGlobalAttributes = true; |
| 7046 | } |
| 7047 | } |
| 7048 | } |
| 7049 | |
| 7050 | /** |
| 7051 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 7052 | * once the user begins interacting with the device by touch, and affects various |
| 7053 | * things like whether focus is always visible to the user. |
| 7054 | * |
| 7055 | * @return Whether the device is in touch mode. |
| 7056 | */ |
| 7057 | @ViewDebug.ExportedProperty |
| 7058 | public boolean isInTouchMode() { |
| 7059 | if (mAttachInfo != null) { |
| 7060 | return mAttachInfo.mInTouchMode; |
| 7061 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7062 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | } |
| 7064 | } |
| 7065 | |
| 7066 | /** |
| 7067 | * Returns the context the view is running in, through which it can |
| 7068 | * access the current theme, resources, etc. |
| 7069 | * |
| 7070 | * @return The view's Context. |
| 7071 | */ |
| 7072 | @ViewDebug.CapturedViewProperty |
| 7073 | public final Context getContext() { |
| 7074 | return mContext; |
| 7075 | } |
| 7076 | |
| 7077 | /** |
| 7078 | * Handle a key event before it is processed by any input method |
| 7079 | * associated with the view hierarchy. This can be used to intercept |
| 7080 | * key events in special situations before the IME consumes them; a |
| 7081 | * typical example would be handling the BACK key to update the application's |
| 7082 | * UI instead of allowing the IME to see it and close itself. |
| 7083 | * |
| 7084 | * @param keyCode The value in event.getKeyCode(). |
| 7085 | * @param event Description of the key event. |
| 7086 | * @return If you handled the event, return true. If you want to allow the |
| 7087 | * event to be handled by the next receiver, return false. |
| 7088 | */ |
| 7089 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7090 | return false; |
| 7091 | } |
| 7092 | |
| 7093 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7094 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7095 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7096 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7097 | * is released, if the view is enabled and clickable. |
| 7098 | * |
| 7099 | * @param keyCode A key code that represents the button pressed, from |
| 7100 | * {@link android.view.KeyEvent}. |
| 7101 | * @param event The KeyEvent object that defines the button action. |
| 7102 | */ |
| 7103 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7104 | boolean result = false; |
| 7105 | |
| 7106 | switch (keyCode) { |
| 7107 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7108 | case KeyEvent.KEYCODE_ENTER: { |
| 7109 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7110 | return true; |
| 7111 | } |
| 7112 | // Long clickable items don't necessarily have to be clickable |
| 7113 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7114 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7115 | (event.getRepeatCount() == 0)) { |
| 7116 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7117 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7118 | return true; |
| 7119 | } |
| 7120 | break; |
| 7121 | } |
| 7122 | } |
| 7123 | return result; |
| 7124 | } |
| 7125 | |
| 7126 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7127 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7128 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7129 | * the event). |
| 7130 | */ |
| 7131 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7132 | return false; |
| 7133 | } |
| 7134 | |
| 7135 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7136 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7137 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7139 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
| 7140 | * |
| 7141 | * @param keyCode A key code that represents the button pressed, from |
| 7142 | * {@link android.view.KeyEvent}. |
| 7143 | * @param event The KeyEvent object that defines the button action. |
| 7144 | */ |
| 7145 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7146 | boolean result = false; |
| 7147 | |
| 7148 | switch (keyCode) { |
| 7149 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7150 | case KeyEvent.KEYCODE_ENTER: { |
| 7151 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7152 | return true; |
| 7153 | } |
| 7154 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7155 | setPressed(false); |
| 7156 | |
| 7157 | if (!mHasPerformedLongPress) { |
| 7158 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7159 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7160 | |
| 7161 | result = performClick(); |
| 7162 | } |
| 7163 | } |
| 7164 | break; |
| 7165 | } |
| 7166 | } |
| 7167 | return result; |
| 7168 | } |
| 7169 | |
| 7170 | /** |
| 7171 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7172 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7173 | * the event). |
| 7174 | * |
| 7175 | * @param keyCode A key code that represents the button pressed, from |
| 7176 | * {@link android.view.KeyEvent}. |
| 7177 | * @param repeatCount The number of times the action was made. |
| 7178 | * @param event The KeyEvent object that defines the button action. |
| 7179 | */ |
| 7180 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7181 | return false; |
| 7182 | } |
| 7183 | |
| 7184 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7185 | * Called on the focused view when a key shortcut event is not handled. |
| 7186 | * Override this method to implement local key shortcuts for the View. |
| 7187 | * Key shortcuts can also be implemented by setting the |
| 7188 | * {@link MenuItem#setShortcut(char, char) shortcut} property of menu items. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | * |
| 7190 | * @param keyCode The value in event.getKeyCode(). |
| 7191 | * @param event Description of the key event. |
| 7192 | * @return If you handled the event, return true. If you want to allow the |
| 7193 | * event to be handled by the next receiver, return false. |
| 7194 | */ |
| 7195 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7196 | return false; |
| 7197 | } |
| 7198 | |
| 7199 | /** |
| 7200 | * Check whether the called view is a text editor, in which case it |
| 7201 | * would make sense to automatically display a soft input window for |
| 7202 | * it. Subclasses should override this if they implement |
| 7203 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7204 | * a call on that method would return a non-null InputConnection, and |
| 7205 | * they are really a first-class editor that the user would normally |
| 7206 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7207 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7208 | * <p>The default implementation always returns false. This does |
| 7209 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7210 | * will not be called or the user can not otherwise perform edits on your |
| 7211 | * view; it is just a hint to the system that this is not the primary |
| 7212 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7213 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | * @return Returns true if this view is a text editor, else false. |
| 7215 | */ |
| 7216 | public boolean onCheckIsTextEditor() { |
| 7217 | return false; |
| 7218 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7220 | /** |
| 7221 | * Create a new InputConnection for an InputMethod to interact |
| 7222 | * with the view. The default implementation returns null, since it doesn't |
| 7223 | * support input methods. You can override this to implement such support. |
| 7224 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7225 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | * <p>When implementing this, you probably also want to implement |
| 7227 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7228 | * non-null InputConnection. |
| 7229 | * |
| 7230 | * @param outAttrs Fill in with attribute information about the connection. |
| 7231 | */ |
| 7232 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7233 | return null; |
| 7234 | } |
| 7235 | |
| 7236 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7237 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7238 | * when a view who is not the current |
| 7239 | * input connection target is trying to make a call on the manager. The |
| 7240 | * default implementation returns false; you can override this to return |
| 7241 | * true for certain views if you are performing InputConnection proxying |
| 7242 | * to them. |
| 7243 | * @param view The View that is making the InputMethodManager call. |
| 7244 | * @return Return true to allow the call, false to reject. |
| 7245 | */ |
| 7246 | public boolean checkInputConnectionProxy(View view) { |
| 7247 | return false; |
| 7248 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7249 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7250 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7251 | * Show the context menu for this view. It is not safe to hold on to the |
| 7252 | * menu after returning from this method. |
| 7253 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7254 | * You should normally not overload this method. Overload |
| 7255 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7256 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7257 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7258 | * @param menu The context menu to populate |
| 7259 | */ |
| 7260 | public void createContextMenu(ContextMenu menu) { |
| 7261 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7262 | |
| 7263 | // Sets the current menu info so all items added to menu will have |
| 7264 | // my extra info set. |
| 7265 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7266 | |
| 7267 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7268 | ListenerInfo li = mListenerInfo; |
| 7269 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7270 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | } |
| 7272 | |
| 7273 | // Clear the extra information so subsequent items that aren't mine don't |
| 7274 | // have my extra info. |
| 7275 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7276 | |
| 7277 | if (mParent != null) { |
| 7278 | mParent.createContextMenu(menu); |
| 7279 | } |
| 7280 | } |
| 7281 | |
| 7282 | /** |
| 7283 | * Views should implement this if they have extra information to associate |
| 7284 | * with the context menu. The return result is supplied as a parameter to |
| 7285 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7286 | * callback. |
| 7287 | * |
| 7288 | * @return Extra information about the item for which the context menu |
| 7289 | * should be shown. This information will vary across different |
| 7290 | * subclasses of View. |
| 7291 | */ |
| 7292 | protected ContextMenuInfo getContextMenuInfo() { |
| 7293 | return null; |
| 7294 | } |
| 7295 | |
| 7296 | /** |
| 7297 | * Views should implement this if the view itself is going to add items to |
| 7298 | * the context menu. |
| 7299 | * |
| 7300 | * @param menu the context menu to populate |
| 7301 | */ |
| 7302 | protected void onCreateContextMenu(ContextMenu menu) { |
| 7303 | } |
| 7304 | |
| 7305 | /** |
| 7306 | * Implement this method to handle trackball motion events. The |
| 7307 | * <em>relative</em> movement of the trackball since the last event |
| 7308 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 7309 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 7310 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 7311 | * they will often be fractional values, representing the more fine-grained |
| 7312 | * movement information available from a trackball). |
| 7313 | * |
| 7314 | * @param event The motion event. |
| 7315 | * @return True if the event was handled, false otherwise. |
| 7316 | */ |
| 7317 | public boolean onTrackballEvent(MotionEvent event) { |
| 7318 | return false; |
| 7319 | } |
| 7320 | |
| 7321 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7322 | * Implement this method to handle generic motion events. |
| 7323 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7324 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 7325 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7326 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 7327 | * the class of input that was received. Implementations of this method |
| 7328 | * must examine the bits in the source before processing the event. |
| 7329 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7330 | * </p><p> |
| 7331 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7332 | * are delivered to the view under the pointer. All other generic motion events are |
| 7333 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7334 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7335 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7336 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7337 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 7338 | * // process the joystick movement... |
| 7339 | * return true; |
| 7340 | * } |
| 7341 | * } |
| 7342 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7343 | * switch (event.getAction()) { |
| 7344 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 7345 | * // process the mouse hover movement... |
| 7346 | * return true; |
| 7347 | * case MotionEvent.ACTION_SCROLL: |
| 7348 | * // process the scroll wheel movement... |
| 7349 | * return true; |
| 7350 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7351 | * } |
| 7352 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7353 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7354 | * |
| 7355 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7356 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7357 | */ |
| 7358 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 7359 | return false; |
| 7360 | } |
| 7361 | |
| 7362 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7363 | * Implement this method to handle hover events. |
| 7364 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7365 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 7366 | * bounds of a view and the view is not currently being touched. |
| 7367 | * Hover events are represented as pointer events with action |
| 7368 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 7369 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 7370 | * </p> |
| 7371 | * <ul> |
| 7372 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 7373 | * when the pointer enters the bounds of the view.</li> |
| 7374 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 7375 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 7376 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 7377 | * when the pointer has exited the bounds of the view or when the pointer is |
| 7378 | * about to go down due to a button click, tap, or similar user action that |
| 7379 | * causes the view to be touched.</li> |
| 7380 | * </ul> |
| 7381 | * <p> |
| 7382 | * The view should implement this method to return true to indicate that it is |
| 7383 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7384 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7385 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 7386 | * of the view when a hover enter or hover exit event is received, if the view |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7387 | * is enabled and is clickable. The default implementation also sends hover |
| 7388 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7389 | * </p> |
| 7390 | * |
| 7391 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7392 | * @return True if the view handled the hover event. |
| 7393 | * |
| 7394 | * @see #isHovered |
| 7395 | * @see #setHovered |
| 7396 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7397 | */ |
| 7398 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7399 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 7400 | // the window. This code ensures that we only send accessibility events for |
| 7401 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7402 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7403 | if (!mSendingHoverAccessibilityEvents) { |
| 7404 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 7405 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 7406 | && !hasHoveredChild() |
| 7407 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7408 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7409 | mSendingHoverAccessibilityEvents = true; |
| 7410 | requestAccessibilityFocusFromHover((int) event.getX(), (int) event.getY()); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7411 | } |
| 7412 | } else { |
| 7413 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7414 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7415 | && !pointInView(event.getX(), event.getY()))) { |
| 7416 | mSendingHoverAccessibilityEvents = false; |
| 7417 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7418 | // If the window does not have input focus we take away accessibility |
| 7419 | // focus as soon as the user stop hovering over the view. |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 7420 | if (mAttachInfo != null && !mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7421 | getViewRootImpl().setAccessibilityFocusedHost(null); |
| 7422 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7423 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7424 | } |
| 7425 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7426 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7427 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7428 | case MotionEvent.ACTION_HOVER_ENTER: |
| 7429 | setHovered(true); |
| 7430 | break; |
| 7431 | case MotionEvent.ACTION_HOVER_EXIT: |
| 7432 | setHovered(false); |
| 7433 | break; |
| 7434 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7435 | |
| 7436 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 7437 | // This is to provide compatibility with existing applications that |
| 7438 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 7439 | // break because of the new default handling for hoverable views |
| 7440 | // in onHoverEvent. |
| 7441 | // Note that onGenericMotionEvent will be called by default when |
| 7442 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 7443 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7444 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7445 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7446 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7447 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7448 | } |
| 7449 | |
| 7450 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7451 | * Returns true if the view should handle {@link #onHoverEvent} |
| 7452 | * by calling {@link #setHovered} to change its hovered state. |
| 7453 | * |
| 7454 | * @return True if the view is hoverable. |
| 7455 | */ |
| 7456 | private boolean isHoverable() { |
| 7457 | final int viewFlags = mViewFlags; |
| 7458 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 7459 | return false; |
| 7460 | } |
| 7461 | |
| 7462 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 7463 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 7464 | } |
| 7465 | |
| 7466 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7467 | * Returns true if the view is currently hovered. |
| 7468 | * |
| 7469 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7470 | * |
| 7471 | * @see #setHovered |
| 7472 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7473 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7474 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7475 | public boolean isHovered() { |
| 7476 | return (mPrivateFlags & HOVERED) != 0; |
| 7477 | } |
| 7478 | |
| 7479 | /** |
| 7480 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7481 | * <p> |
| 7482 | * Calling this method also changes the drawable state of the view. This |
| 7483 | * enables the view to react to hover by using different drawable resources |
| 7484 | * to change its appearance. |
| 7485 | * </p><p> |
| 7486 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 7487 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7488 | * |
| 7489 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7490 | * |
| 7491 | * @see #isHovered |
| 7492 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7493 | */ |
| 7494 | public void setHovered(boolean hovered) { |
| 7495 | if (hovered) { |
| 7496 | if ((mPrivateFlags & HOVERED) == 0) { |
| 7497 | mPrivateFlags |= HOVERED; |
| 7498 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7499 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7500 | } |
| 7501 | } else { |
| 7502 | if ((mPrivateFlags & HOVERED) != 0) { |
| 7503 | mPrivateFlags &= ~HOVERED; |
| 7504 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7505 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7506 | } |
| 7507 | } |
| 7508 | } |
| 7509 | |
| 7510 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7511 | * Implement this method to handle hover state changes. |
| 7512 | * <p> |
| 7513 | * This method is called whenever the hover state changes as a result of a |
| 7514 | * call to {@link #setHovered}. |
| 7515 | * </p> |
| 7516 | * |
| 7517 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 7518 | * |
| 7519 | * @see #isHovered |
| 7520 | * @see #setHovered |
| 7521 | */ |
| 7522 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7523 | } |
| 7524 | |
| 7525 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | * Implement this method to handle touch screen motion events. |
| 7527 | * |
| 7528 | * @param event The motion event. |
| 7529 | * @return True if the event was handled, false otherwise. |
| 7530 | */ |
| 7531 | public boolean onTouchEvent(MotionEvent event) { |
| 7532 | final int viewFlags = mViewFlags; |
| 7533 | |
| 7534 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 7535 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7536 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 7537 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7538 | // A disabled view that is clickable still consumes the touch |
| 7539 | // events, it just doesn't respond to them. |
| 7540 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7541 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 7542 | } |
| 7543 | |
| 7544 | if (mTouchDelegate != null) { |
| 7545 | if (mTouchDelegate.onTouchEvent(event)) { |
| 7546 | return true; |
| 7547 | } |
| 7548 | } |
| 7549 | |
| 7550 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7551 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 7552 | switch (event.getAction()) { |
| 7553 | case MotionEvent.ACTION_UP: |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7554 | boolean prepressed = (mPrivateFlags & PREPRESSED) != 0; |
| 7555 | if ((mPrivateFlags & PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | // take focus if we don't have it already and we should in |
| 7557 | // touch mode. |
| 7558 | boolean focusTaken = false; |
| 7559 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 7560 | focusTaken = requestFocus(); |
| 7561 | } |
| 7562 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7563 | if (prepressed) { |
| 7564 | // The button is being released before we actually |
| 7565 | // showed it as pressed. Make it show the pressed |
| 7566 | // state now (before scheduling the click) to ensure |
| 7567 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7568 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7569 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7571 | if (!mHasPerformedLongPress) { |
| 7572 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7573 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | |
| 7575 | // Only perform take click actions if we were in the pressed state |
| 7576 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 7577 | // Use a Runnable and post this rather than calling |
| 7578 | // performClick directly. This lets other visual state |
| 7579 | // of the view update before click actions start. |
| 7580 | if (mPerformClick == null) { |
| 7581 | mPerformClick = new PerformClick(); |
| 7582 | } |
| 7583 | if (!post(mPerformClick)) { |
| 7584 | performClick(); |
| 7585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | if (mUnsetPressedState == null) { |
| 7590 | mUnsetPressedState = new UnsetPressedState(); |
| 7591 | } |
| 7592 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7593 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7594 | postDelayed(mUnsetPressedState, |
| 7595 | ViewConfiguration.getPressedStateDuration()); |
| 7596 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7597 | // If the post failed, unpress right now |
| 7598 | mUnsetPressedState.run(); |
| 7599 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7600 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | } |
| 7602 | break; |
| 7603 | |
| 7604 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 7605 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7606 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 7607 | if (performButtonActionOnTouchDown(event)) { |
| 7608 | break; |
| 7609 | } |
| 7610 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7611 | // Walk up the hierarchy to determine if we're inside a scrolling container. |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 7612 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7613 | |
| 7614 | // For views inside a scrolling container, delay the pressed feedback for |
| 7615 | // a short period in case this is a scroll. |
| 7616 | if (isInScrollingContainer) { |
| 7617 | mPrivateFlags |= PREPRESSED; |
| 7618 | if (mPendingCheckForTap == null) { |
| 7619 | mPendingCheckForTap = new CheckForTap(); |
| 7620 | } |
| 7621 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 7622 | } else { |
| 7623 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7624 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7625 | checkForLongClick(0); |
| 7626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7627 | break; |
| 7628 | |
| 7629 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7630 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7631 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7632 | break; |
| 7633 | |
| 7634 | case MotionEvent.ACTION_MOVE: |
| 7635 | final int x = (int) event.getX(); |
| 7636 | final int y = (int) event.getY(); |
| 7637 | |
| 7638 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 7639 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7640 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7641 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | if ((mPrivateFlags & PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7643 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7644 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7645 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7646 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | } |
| 7649 | break; |
| 7650 | } |
| 7651 | return true; |
| 7652 | } |
| 7653 | |
| 7654 | return false; |
| 7655 | } |
| 7656 | |
| 7657 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 7658 | * @hide |
| 7659 | */ |
| 7660 | public boolean isInScrollingContainer() { |
| 7661 | ViewParent p = getParent(); |
| 7662 | while (p != null && p instanceof ViewGroup) { |
| 7663 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 7664 | return true; |
| 7665 | } |
| 7666 | p = p.getParent(); |
| 7667 | } |
| 7668 | return false; |
| 7669 | } |
| 7670 | |
| 7671 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7672 | * Remove the longpress detection timer. |
| 7673 | */ |
| 7674 | private void removeLongPressCallback() { |
| 7675 | if (mPendingCheckForLongPress != null) { |
| 7676 | removeCallbacks(mPendingCheckForLongPress); |
| 7677 | } |
| 7678 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 7679 | |
| 7680 | /** |
| 7681 | * Remove the pending click action |
| 7682 | */ |
| 7683 | private void removePerformClickCallback() { |
| 7684 | if (mPerformClick != null) { |
| 7685 | removeCallbacks(mPerformClick); |
| 7686 | } |
| 7687 | } |
| 7688 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7689 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7690 | * Remove the prepress detection timer. |
| 7691 | */ |
| 7692 | private void removeUnsetPressCallback() { |
| 7693 | if ((mPrivateFlags & PRESSED) != 0 && mUnsetPressedState != null) { |
| 7694 | setPressed(false); |
| 7695 | removeCallbacks(mUnsetPressedState); |
| 7696 | } |
| 7697 | } |
| 7698 | |
| 7699 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7700 | * Remove the tap detection timer. |
| 7701 | */ |
| 7702 | private void removeTapCallback() { |
| 7703 | if (mPendingCheckForTap != null) { |
| 7704 | mPrivateFlags &= ~PREPRESSED; |
| 7705 | removeCallbacks(mPendingCheckForTap); |
| 7706 | } |
| 7707 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7708 | |
| 7709 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7710 | * Cancels a pending long press. Your subclass can use this if you |
| 7711 | * want the context menu to come up if the user presses and holds |
| 7712 | * at the same place, but you don't want it to come up if they press |
| 7713 | * and then move around enough to cause scrolling. |
| 7714 | */ |
| 7715 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7716 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 7717 | |
| 7718 | /* |
| 7719 | * The prepressed state handled by the tap callback is a display |
| 7720 | * construct, but the tap callback will post a long press callback |
| 7721 | * less its own timeout. Remove it here. |
| 7722 | */ |
| 7723 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | } |
| 7725 | |
| 7726 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7727 | * Remove the pending callback for sending a |
| 7728 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 7729 | */ |
| 7730 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 7731 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 7732 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
| 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7737 | * Sets the TouchDelegate for this View. |
| 7738 | */ |
| 7739 | public void setTouchDelegate(TouchDelegate delegate) { |
| 7740 | mTouchDelegate = delegate; |
| 7741 | } |
| 7742 | |
| 7743 | /** |
| 7744 | * Gets the TouchDelegate for this View. |
| 7745 | */ |
| 7746 | public TouchDelegate getTouchDelegate() { |
| 7747 | return mTouchDelegate; |
| 7748 | } |
| 7749 | |
| 7750 | /** |
| 7751 | * Set flags controlling behavior of this view. |
| 7752 | * |
| 7753 | * @param flags Constant indicating the value which should be set |
| 7754 | * @param mask Constant indicating the bit range that should be changed |
| 7755 | */ |
| 7756 | void setFlags(int flags, int mask) { |
| 7757 | int old = mViewFlags; |
| 7758 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 7759 | |
| 7760 | int changed = mViewFlags ^ old; |
| 7761 | if (changed == 0) { |
| 7762 | return; |
| 7763 | } |
| 7764 | int privateFlags = mPrivateFlags; |
| 7765 | |
| 7766 | /* Check if the FOCUSABLE bit has changed */ |
| 7767 | if (((changed & FOCUSABLE_MASK) != 0) && |
| 7768 | ((privateFlags & HAS_BOUNDS) !=0)) { |
| 7769 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
| 7770 | && ((privateFlags & FOCUSED) != 0)) { |
| 7771 | /* Give up focus if we are no longer focusable */ |
| 7772 | clearFocus(); |
| 7773 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
| 7774 | && ((privateFlags & FOCUSED) == 0)) { |
| 7775 | /* |
| 7776 | * Tell the view system that we are now available to take focus |
| 7777 | * if no one else already has it. |
| 7778 | */ |
| 7779 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 7780 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7781 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7782 | notifyAccessibilityStateChanged(); |
| 7783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7784 | } |
| 7785 | |
| 7786 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 7787 | if ((changed & VISIBILITY_MASK) != 0) { |
| 7788 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7789 | * If this view is becoming visible, invalidate it in case it changed while |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7790 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 7791 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | */ |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7793 | mPrivateFlags |= DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 7794 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | |
| 7796 | needGlobalAttributesUpdate(true); |
| 7797 | |
| 7798 | // a view becoming visible is worth notifying the parent |
| 7799 | // about in case nothing has focus. even if this specific view |
| 7800 | // isn't focusable, it may contain something that is, so let |
| 7801 | // the root view try to give this focus if nothing else does. |
| 7802 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 7803 | mParent.focusableViewAvailable(this); |
| 7804 | } |
| 7805 | } |
| 7806 | } |
| 7807 | |
| 7808 | /* Check if the GONE bit has changed */ |
| 7809 | if ((changed & GONE) != 0) { |
| 7810 | needGlobalAttributesUpdate(false); |
| 7811 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7813 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 7814 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7815 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 7816 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 7817 | if (mParent instanceof View) { |
| 7818 | // GONE views noop invalidation, so invalidate the parent |
| 7819 | ((View) mParent).invalidate(true); |
| 7820 | } |
| 7821 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 7822 | // time it is visible and gets invalidated |
| 7823 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | } |
| 7825 | if (mAttachInfo != null) { |
| 7826 | mAttachInfo.mViewVisibilityChanged = true; |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | /* Check if the VISIBLE bit has changed */ |
| 7831 | if ((changed & INVISIBLE) != 0) { |
| 7832 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 7833 | /* |
| 7834 | * If this view is becoming invisible, set the DRAWN flag so that |
| 7835 | * the next invalidate() will not be skipped. |
| 7836 | */ |
| 7837 | mPrivateFlags |= DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | |
| 7839 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7840 | // root view becoming invisible shouldn't clear focus and accessibility focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7841 | if (getRootView() != this) { |
| 7842 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7843 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7844 | } |
| 7845 | } |
| 7846 | if (mAttachInfo != null) { |
| 7847 | mAttachInfo.mViewVisibilityChanged = true; |
| 7848 | } |
| 7849 | } |
| 7850 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7851 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7852 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 7853 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 7854 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7855 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 7856 | } else if (mParent != null) { |
| 7857 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7858 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7859 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 7860 | } |
| 7861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 7863 | destroyDrawingCache(); |
| 7864 | } |
| 7865 | |
| 7866 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 7867 | destroyDrawingCache(); |
| 7868 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7869 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 7873 | destroyDrawingCache(); |
| 7874 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 7875 | } |
| 7876 | |
| 7877 | if ((changed & DRAW_MASK) != 0) { |
| 7878 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7879 | if (mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | mPrivateFlags &= ~SKIP_DRAW; |
| 7881 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 7882 | } else { |
| 7883 | mPrivateFlags |= SKIP_DRAW; |
| 7884 | } |
| 7885 | } else { |
| 7886 | mPrivateFlags &= ~SKIP_DRAW; |
| 7887 | } |
| 7888 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 7889 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | } |
| 7891 | |
| 7892 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7893 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | mParent.recomputeViewAttributes(this); |
| 7895 | } |
| 7896 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7897 | |
| 7898 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 7899 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 7900 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 7901 | notifyAccessibilityStateChanged(); |
| 7902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | } |
| 7904 | |
| 7905 | /** |
| 7906 | * Change the view's z order in the tree, so it's on top of other sibling |
| 7907 | * views |
| 7908 | */ |
| 7909 | public void bringToFront() { |
| 7910 | if (mParent != null) { |
| 7911 | mParent.bringChildToFront(this); |
| 7912 | } |
| 7913 | } |
| 7914 | |
| 7915 | /** |
| 7916 | * This is called in response to an internal scroll in this view (i.e., the |
| 7917 | * view scrolled its own contents). This is typically as a result of |
| 7918 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 7919 | * called. |
| 7920 | * |
| 7921 | * @param l Current horizontal scroll origin. |
| 7922 | * @param t Current vertical scroll origin. |
| 7923 | * @param oldl Previous horizontal scroll origin. |
| 7924 | * @param oldt Previous vertical scroll origin. |
| 7925 | */ |
| 7926 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7927 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7928 | postSendViewScrolledAccessibilityEventCallback(); |
| 7929 | } |
| 7930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7931 | mBackgroundSizeChanged = true; |
| 7932 | |
| 7933 | final AttachInfo ai = mAttachInfo; |
| 7934 | if (ai != null) { |
| 7935 | ai.mViewScrollChanged = true; |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7940 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 7941 | * changes due to layout processing. |
| 7942 | */ |
| 7943 | public interface OnLayoutChangeListener { |
| 7944 | /** |
| 7945 | * Called when the focus state of a view has changed. |
| 7946 | * |
| 7947 | * @param v The view whose state has changed. |
| 7948 | * @param left The new value of the view's left property. |
| 7949 | * @param top The new value of the view's top property. |
| 7950 | * @param right The new value of the view's right property. |
| 7951 | * @param bottom The new value of the view's bottom property. |
| 7952 | * @param oldLeft The previous value of the view's left property. |
| 7953 | * @param oldTop The previous value of the view's top property. |
| 7954 | * @param oldRight The previous value of the view's right property. |
| 7955 | * @param oldBottom The previous value of the view's bottom property. |
| 7956 | */ |
| 7957 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 7958 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 7959 | } |
| 7960 | |
| 7961 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7962 | * This is called during layout when the size of this view has changed. If |
| 7963 | * you were just added to the view hierarchy, you're called with the old |
| 7964 | * values of 0. |
| 7965 | * |
| 7966 | * @param w Current width of this view. |
| 7967 | * @param h Current height of this view. |
| 7968 | * @param oldw Old width of this view. |
| 7969 | * @param oldh Old height of this view. |
| 7970 | */ |
| 7971 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 7972 | } |
| 7973 | |
| 7974 | /** |
| 7975 | * Called by draw to draw the child views. This may be overridden |
| 7976 | * by derived classes to gain control just before its children are drawn |
| 7977 | * (but after its own view has been drawn). |
| 7978 | * @param canvas the canvas on which to draw the view |
| 7979 | */ |
| 7980 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | } |
| 7983 | |
| 7984 | /** |
| 7985 | * Gets the parent of this view. Note that the parent is a |
| 7986 | * ViewParent and not necessarily a View. |
| 7987 | * |
| 7988 | * @return Parent of this view. |
| 7989 | */ |
| 7990 | public final ViewParent getParent() { |
| 7991 | return mParent; |
| 7992 | } |
| 7993 | |
| 7994 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7995 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 7996 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 7997 | * invalidated. |
| 7998 | * @param value the x position to scroll to |
| 7999 | */ |
| 8000 | public void setScrollX(int value) { |
| 8001 | scrollTo(value, mScrollY); |
| 8002 | } |
| 8003 | |
| 8004 | /** |
| 8005 | * Set the vertical scrolled position of your view. This will cause a call to |
| 8006 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8007 | * invalidated. |
| 8008 | * @param value the y position to scroll to |
| 8009 | */ |
| 8010 | public void setScrollY(int value) { |
| 8011 | scrollTo(mScrollX, value); |
| 8012 | } |
| 8013 | |
| 8014 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | * Return the scrolled left position of this view. This is the left edge of |
| 8016 | * the displayed part of your view. You do not need to draw any pixels |
| 8017 | * farther left, since those are outside of the frame of your view on |
| 8018 | * screen. |
| 8019 | * |
| 8020 | * @return The left edge of the displayed part of your view, in pixels. |
| 8021 | */ |
| 8022 | public final int getScrollX() { |
| 8023 | return mScrollX; |
| 8024 | } |
| 8025 | |
| 8026 | /** |
| 8027 | * Return the scrolled top position of this view. This is the top edge of |
| 8028 | * the displayed part of your view. You do not need to draw any pixels above |
| 8029 | * it, since those are outside of the frame of your view on screen. |
| 8030 | * |
| 8031 | * @return The top edge of the displayed part of your view, in pixels. |
| 8032 | */ |
| 8033 | public final int getScrollY() { |
| 8034 | return mScrollY; |
| 8035 | } |
| 8036 | |
| 8037 | /** |
| 8038 | * Return the width of the your view. |
| 8039 | * |
| 8040 | * @return The width of your view, in pixels. |
| 8041 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8042 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | public final int getWidth() { |
| 8044 | return mRight - mLeft; |
| 8045 | } |
| 8046 | |
| 8047 | /** |
| 8048 | * Return the height of your view. |
| 8049 | * |
| 8050 | * @return The height of your view, in pixels. |
| 8051 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8052 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8053 | public final int getHeight() { |
| 8054 | return mBottom - mTop; |
| 8055 | } |
| 8056 | |
| 8057 | /** |
| 8058 | * Return the visible drawing bounds of your view. Fills in the output |
| 8059 | * rectangle with the values from getScrollX(), getScrollY(), |
| 8060 | * getWidth(), and getHeight(). |
| 8061 | * |
| 8062 | * @param outRect The (scrolled) drawing bounds of the view. |
| 8063 | */ |
| 8064 | public void getDrawingRect(Rect outRect) { |
| 8065 | outRect.left = mScrollX; |
| 8066 | outRect.top = mScrollY; |
| 8067 | outRect.right = mScrollX + (mRight - mLeft); |
| 8068 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 8069 | } |
| 8070 | |
| 8071 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8072 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 8073 | * raw width component (that is the result is masked by |
| 8074 | * {@link #MEASURED_SIZE_MASK}). |
| 8075 | * |
| 8076 | * @return The raw measured width of this view. |
| 8077 | */ |
| 8078 | public final int getMeasuredWidth() { |
| 8079 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8080 | } |
| 8081 | |
| 8082 | /** |
| 8083 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8084 | * by the most recent call to {@link #measure(int, int)}. This result is a bit mask |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8085 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8086 | * This should be used during measurement and layout calculations only. Use |
| 8087 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8088 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8089 | * @return The measured width of this view as a bit mask. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8090 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8091 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8092 | return mMeasuredWidth; |
| 8093 | } |
| 8094 | |
| 8095 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8096 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8097 | * raw width component (that is the result is masked by |
| 8098 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8100 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | */ |
| 8102 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8103 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8104 | } |
| 8105 | |
| 8106 | /** |
| 8107 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8108 | * by the most recent call to {@link #measure(int, int)}. This result is a bit mask |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8109 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8110 | * This should be used during measurement and layout calculations only. Use |
| 8111 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8112 | * |
| 8113 | * @return The measured width of this view as a bit mask. |
| 8114 | */ |
| 8115 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8116 | return mMeasuredHeight; |
| 8117 | } |
| 8118 | |
| 8119 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8120 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8121 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8122 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8123 | * and the height component is at the shifted bits |
| 8124 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8125 | */ |
| 8126 | public final int getMeasuredState() { |
| 8127 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8128 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8129 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8130 | } |
| 8131 | |
| 8132 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8133 | * The transform matrix of this view, which is calculated based on the current |
| 8134 | * roation, scale, and pivot properties. |
| 8135 | * |
| 8136 | * @see #getRotation() |
| 8137 | * @see #getScaleX() |
| 8138 | * @see #getScaleY() |
| 8139 | * @see #getPivotX() |
| 8140 | * @see #getPivotY() |
| 8141 | * @return The current transform matrix for the view |
| 8142 | */ |
| 8143 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8144 | if (mTransformationInfo != null) { |
| 8145 | updateMatrix(); |
| 8146 | return mTransformationInfo.mMatrix; |
| 8147 | } |
| 8148 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8149 | } |
| 8150 | |
| 8151 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8152 | * Utility function to determine if the value is far enough away from zero to be |
| 8153 | * considered non-zero. |
| 8154 | * @param value A floating point value to check for zero-ness |
| 8155 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8156 | */ |
| 8157 | private static boolean nonzero(float value) { |
| 8158 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8159 | } |
| 8160 | |
| 8161 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8162 | * Returns true if the transform matrix is the identity matrix. |
| 8163 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8164 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8165 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8166 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8167 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8168 | if (mTransformationInfo != null) { |
| 8169 | updateMatrix(); |
| 8170 | return mTransformationInfo.mMatrixIsIdentity; |
| 8171 | } |
| 8172 | return true; |
| 8173 | } |
| 8174 | |
| 8175 | void ensureTransformationInfo() { |
| 8176 | if (mTransformationInfo == null) { |
| 8177 | mTransformationInfo = new TransformationInfo(); |
| 8178 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8179 | } |
| 8180 | |
| 8181 | /** |
| 8182 | * Recomputes the transform matrix if necessary. |
| 8183 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8184 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8185 | final TransformationInfo info = mTransformationInfo; |
| 8186 | if (info == null) { |
| 8187 | return; |
| 8188 | } |
| 8189 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8190 | // transform-related properties have changed since the last time someone |
| 8191 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8192 | |
| 8193 | // Figure out if we need to update the pivot point |
| 8194 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8195 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8196 | info.mPrevWidth = mRight - mLeft; |
| 8197 | info.mPrevHeight = mBottom - mTop; |
| 8198 | info.mPivotX = info.mPrevWidth / 2f; |
| 8199 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8200 | } |
| 8201 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8202 | info.mMatrix.reset(); |
| 8203 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8204 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8205 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8206 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8207 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8208 | if (info.mCamera == null) { |
| 8209 | info.mCamera = new Camera(); |
| 8210 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8211 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8212 | info.mCamera.save(); |
| 8213 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8214 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8215 | info.mCamera.getMatrix(info.matrix3D); |
| 8216 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8217 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8218 | info.mPivotY + info.mTranslationY); |
| 8219 | info.mMatrix.postConcat(info.matrix3D); |
| 8220 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8221 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8222 | info.mMatrixDirty = false; |
| 8223 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8224 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8225 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8226 | } |
| 8227 | |
| 8228 | /** |
| 8229 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8230 | * We cache the matrix to avoid recalculating it when transform properties |
| 8231 | * have not changed. |
| 8232 | * |
| 8233 | * @return The inverse of the current matrix of this view. |
| 8234 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8235 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8236 | final TransformationInfo info = mTransformationInfo; |
| 8237 | if (info != null) { |
| 8238 | updateMatrix(); |
| 8239 | if (info.mInverseMatrixDirty) { |
| 8240 | if (info.mInverseMatrix == null) { |
| 8241 | info.mInverseMatrix = new Matrix(); |
| 8242 | } |
| 8243 | info.mMatrix.invert(info.mInverseMatrix); |
| 8244 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8245 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8246 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8247 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8248 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8249 | } |
| 8250 | |
| 8251 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8252 | * Gets the distance along the Z axis from the camera to this view. |
| 8253 | * |
| 8254 | * @see #setCameraDistance(float) |
| 8255 | * |
| 8256 | * @return The distance along the Z axis. |
| 8257 | */ |
| 8258 | public float getCameraDistance() { |
| 8259 | ensureTransformationInfo(); |
| 8260 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8261 | final TransformationInfo info = mTransformationInfo; |
| 8262 | if (info.mCamera == null) { |
| 8263 | info.mCamera = new Camera(); |
| 8264 | info.matrix3D = new Matrix(); |
| 8265 | } |
| 8266 | return -(info.mCamera.getLocationZ() * dpi); |
| 8267 | } |
| 8268 | |
| 8269 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8270 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8271 | * views are drawn) from the camera to this view. The camera's distance |
| 8272 | * affects 3D transformations, for instance rotations around the X and Y |
| 8273 | * axis. If the rotationX or rotationY properties are changed and this view is |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8274 | * large (more than half the size of the screen), it is recommended to always |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8275 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8276 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8277 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8278 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8279 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8280 | * For example, a large distance will result in a large viewing angle, and there |
| 8281 | * will not be much perspective distortion of the view as it rotates. A short |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8282 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8283 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8284 | * behind the camera (which is why the recommendation is to use a distance at |
| 8285 | * least as far as the size of the view, if the view is to be rotated.)</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8286 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8287 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8288 | * on the screen density. For instance, on a medium density display, the |
| 8289 | * default distance is 1280. On a high density display, the default distance |
| 8290 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8291 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8292 | * <p>If you want to specify a distance that leads to visually consistent |
| 8293 | * results across various densities, use the following formula:</p> |
| 8294 | * <pre> |
| 8295 | * float scale = context.getResources().getDisplayMetrics().density; |
| 8296 | * view.setCameraDistance(distance * scale); |
| 8297 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8298 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8299 | * <p>The density scale factor of a high density display is 1.5, |
| 8300 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8301 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8302 | * @param distance The distance in "depth pixels", if negative the opposite |
| 8303 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8304 | * |
| 8305 | * @see #setRotationX(float) |
| 8306 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8307 | */ |
| 8308 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8309 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8310 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8311 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8312 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8313 | final TransformationInfo info = mTransformationInfo; |
| 8314 | if (info.mCamera == null) { |
| 8315 | info.mCamera = new Camera(); |
| 8316 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8317 | } |
| 8318 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8319 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 8320 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8321 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8322 | invalidateViewProperty(false, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8323 | if (mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 8324 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8325 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8326 | } |
| 8327 | |
| 8328 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8329 | * The degrees that the view is rotated around the pivot point. |
| 8330 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8331 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8332 | * @see #getPivotX() |
| 8333 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8334 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8335 | * @return The degrees of rotation. |
| 8336 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8337 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8338 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8339 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8340 | } |
| 8341 | |
| 8342 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8343 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 8344 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8345 | * |
| 8346 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8347 | * |
| 8348 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8349 | * @see #getPivotX() |
| 8350 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8351 | * @see #setRotationX(float) |
| 8352 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8353 | * |
| 8354 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8355 | */ |
| 8356 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8357 | ensureTransformationInfo(); |
| 8358 | final TransformationInfo info = mTransformationInfo; |
| 8359 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8360 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8361 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8362 | info.mRotation = rotation; |
| 8363 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8364 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8365 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8366 | mDisplayList.setRotation(rotation); |
| 8367 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8368 | } |
| 8369 | } |
| 8370 | |
| 8371 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8372 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 8373 | * |
| 8374 | * @see #getPivotX() |
| 8375 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8376 | * @see #setRotationY(float) |
| 8377 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8378 | * @return The degrees of Y rotation. |
| 8379 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8380 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8381 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8382 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8383 | } |
| 8384 | |
| 8385 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8386 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 8387 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 8388 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8389 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8390 | * When rotating large views, it is recommended to adjust the camera distance |
| 8391 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8392 | * |
| 8393 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8394 | * |
| 8395 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8396 | * @see #getPivotX() |
| 8397 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8398 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8399 | * @see #setRotationX(float) |
| 8400 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8401 | * |
| 8402 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8403 | */ |
| 8404 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8405 | ensureTransformationInfo(); |
| 8406 | final TransformationInfo info = mTransformationInfo; |
| 8407 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8408 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8409 | info.mRotationY = rotationY; |
| 8410 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8411 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8412 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8413 | mDisplayList.setRotationY(rotationY); |
| 8414 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | /** |
| 8419 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8420 | * |
| 8421 | * @see #getPivotX() |
| 8422 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8423 | * @see #setRotationX(float) |
| 8424 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8425 | * @return The degrees of X rotation. |
| 8426 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8427 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8428 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8429 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8430 | } |
| 8431 | |
| 8432 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8433 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8434 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 8435 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8436 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8437 | * When rotating large views, it is recommended to adjust the camera distance |
| 8438 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8439 | * |
| 8440 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8441 | * |
| 8442 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8443 | * @see #getPivotX() |
| 8444 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8445 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8446 | * @see #setRotationY(float) |
| 8447 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8448 | * |
| 8449 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8450 | */ |
| 8451 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8452 | ensureTransformationInfo(); |
| 8453 | final TransformationInfo info = mTransformationInfo; |
| 8454 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8455 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8456 | info.mRotationX = rotationX; |
| 8457 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8458 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8459 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8460 | mDisplayList.setRotationX(rotationX); |
| 8461 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8466 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 8467 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 8468 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8469 | * <p>By default, this is 1.0f. |
| 8470 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8471 | * @see #getPivotX() |
| 8472 | * @see #getPivotY() |
| 8473 | * @return The scaling factor. |
| 8474 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8475 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8476 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8477 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | /** |
| 8481 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 8482 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8483 | * |
| 8484 | * @param scaleX The scaling factor. |
| 8485 | * @see #getPivotX() |
| 8486 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8487 | * |
| 8488 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8489 | */ |
| 8490 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8491 | ensureTransformationInfo(); |
| 8492 | final TransformationInfo info = mTransformationInfo; |
| 8493 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8494 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8495 | info.mScaleX = scaleX; |
| 8496 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8497 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8498 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8499 | mDisplayList.setScaleX(scaleX); |
| 8500 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8501 | } |
| 8502 | } |
| 8503 | |
| 8504 | /** |
| 8505 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 8506 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 8507 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8508 | * <p>By default, this is 1.0f. |
| 8509 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8510 | * @see #getPivotX() |
| 8511 | * @see #getPivotY() |
| 8512 | * @return The scaling factor. |
| 8513 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8514 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8515 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8516 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8517 | } |
| 8518 | |
| 8519 | /** |
| 8520 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 8521 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8522 | * |
| 8523 | * @param scaleY The scaling factor. |
| 8524 | * @see #getPivotX() |
| 8525 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8526 | * |
| 8527 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8528 | */ |
| 8529 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8530 | ensureTransformationInfo(); |
| 8531 | final TransformationInfo info = mTransformationInfo; |
| 8532 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8533 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8534 | info.mScaleY = scaleY; |
| 8535 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8536 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8537 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8538 | mDisplayList.setScaleY(scaleY); |
| 8539 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8540 | } |
| 8541 | } |
| 8542 | |
| 8543 | /** |
| 8544 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 8545 | * and {@link #setScaleX(float) scaled}. |
| 8546 | * |
| 8547 | * @see #getRotation() |
| 8548 | * @see #getScaleX() |
| 8549 | * @see #getScaleY() |
| 8550 | * @see #getPivotY() |
| 8551 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8552 | * |
| 8553 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8554 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8555 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8556 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8557 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8558 | } |
| 8559 | |
| 8560 | /** |
| 8561 | * Sets the x location of the point around which the view is |
| 8562 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8563 | * By default, the pivot point is centered on the object. |
| 8564 | * Setting this property disables this behavior and causes the view to use only the |
| 8565 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8566 | * |
| 8567 | * @param pivotX The x location of the pivot point. |
| 8568 | * @see #getRotation() |
| 8569 | * @see #getScaleX() |
| 8570 | * @see #getScaleY() |
| 8571 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8572 | * |
| 8573 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8574 | */ |
| 8575 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8576 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8577 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8578 | final TransformationInfo info = mTransformationInfo; |
| 8579 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8580 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8581 | info.mPivotX = pivotX; |
| 8582 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8583 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8584 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8585 | mDisplayList.setPivotX(pivotX); |
| 8586 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8587 | } |
| 8588 | } |
| 8589 | |
| 8590 | /** |
| 8591 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 8592 | * and {@link #setScaleY(float) scaled}. |
| 8593 | * |
| 8594 | * @see #getRotation() |
| 8595 | * @see #getScaleX() |
| 8596 | * @see #getScaleY() |
| 8597 | * @see #getPivotY() |
| 8598 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8599 | * |
| 8600 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8601 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8602 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8603 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8604 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8605 | } |
| 8606 | |
| 8607 | /** |
| 8608 | * Sets the y location of the point around which the view is {@link #setRotation(float) rotated} |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8609 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 8610 | * Setting this property disables this behavior and causes the view to use only the |
| 8611 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8612 | * |
| 8613 | * @param pivotY The y location of the pivot point. |
| 8614 | * @see #getRotation() |
| 8615 | * @see #getScaleX() |
| 8616 | * @see #getScaleY() |
| 8617 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8618 | * |
| 8619 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8620 | */ |
| 8621 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8622 | ensureTransformationInfo(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8623 | mPrivateFlags |= PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8624 | final TransformationInfo info = mTransformationInfo; |
| 8625 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8626 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8627 | info.mPivotY = pivotY; |
| 8628 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8629 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8630 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8631 | mDisplayList.setPivotY(pivotY); |
| 8632 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8633 | } |
| 8634 | } |
| 8635 | |
| 8636 | /** |
| 8637 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 8638 | * completely transparent and 1 means the view is completely opaque. |
| 8639 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8640 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8641 | * @return The opacity of the view. |
| 8642 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8643 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8644 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8645 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8646 | } |
| 8647 | |
| 8648 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 8649 | * Returns whether this View has content which overlaps. This function, intended to be |
| 8650 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 8651 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 8652 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 8653 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 8654 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 8655 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 8656 | * an ImageView with only the foreground image. The default implementation returns true; |
| 8657 | * subclasses should override if they have cases which can be optimized. |
| 8658 | * |
| 8659 | * @return true if the content in this view might overlap, false otherwise. |
| 8660 | */ |
| 8661 | public boolean hasOverlappingRendering() { |
| 8662 | return true; |
| 8663 | } |
| 8664 | |
| 8665 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8666 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 8667 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8668 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 8669 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 8670 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 8671 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8672 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8673 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8674 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 8675 | * performance implications. It is generally best to use the alpha property sparingly and |
| 8676 | * transiently, as in the case of fading animations.</p> |
| 8677 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8678 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8679 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8680 | * @see #setLayerType(int, android.graphics.Paint) |
| 8681 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8682 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8683 | */ |
| 8684 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8685 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8686 | if (mTransformationInfo.mAlpha != alpha) { |
| 8687 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8688 | if (onSetAlpha((int) (alpha * 255))) { |
| 8689 | mPrivateFlags |= ALPHA_SET; |
| 8690 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8691 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8692 | invalidate(true); |
| 8693 | } else { |
| 8694 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8695 | invalidateViewProperty(true, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8696 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8697 | mDisplayList.setAlpha(alpha); |
| 8698 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8699 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8700 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8701 | } |
| 8702 | |
| 8703 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8704 | * Faster version of setAlpha() which performs the same steps except there are |
| 8705 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 8706 | * on the parent and this object. The return value indicates whether the subclass handles |
| 8707 | * alpha (the return value for onSetAlpha()). |
| 8708 | * |
| 8709 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8710 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 8711 | * the new value for the alpha property is different from the old value |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8712 | */ |
| 8713 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8714 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8715 | if (mTransformationInfo.mAlpha != alpha) { |
| 8716 | mTransformationInfo.mAlpha = alpha; |
| 8717 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 8718 | if (subclassHandlesAlpha) { |
| 8719 | mPrivateFlags |= ALPHA_SET; |
| 8720 | return true; |
| 8721 | } else { |
| 8722 | mPrivateFlags &= ~ALPHA_SET; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8723 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8724 | mDisplayList.setAlpha(alpha); |
| 8725 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8726 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8727 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 8728 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 8729 | } |
| 8730 | |
| 8731 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8732 | * Top position of this view relative to its parent. |
| 8733 | * |
| 8734 | * @return The top of this view, in pixels. |
| 8735 | */ |
| 8736 | @ViewDebug.CapturedViewProperty |
| 8737 | public final int getTop() { |
| 8738 | return mTop; |
| 8739 | } |
| 8740 | |
| 8741 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8742 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 8743 | * by the layout system and should not generally be called otherwise, because the property |
| 8744 | * may be changed at any time by the layout. |
| 8745 | * |
| 8746 | * @param top The top of this view, in pixels. |
| 8747 | */ |
| 8748 | public final void setTop(int top) { |
| 8749 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8750 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8751 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8752 | || mTransformationInfo.mMatrixIsIdentity; |
| 8753 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8754 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8755 | int minTop; |
| 8756 | int yLoc; |
| 8757 | if (top < mTop) { |
| 8758 | minTop = top; |
| 8759 | yLoc = top - mTop; |
| 8760 | } else { |
| 8761 | minTop = mTop; |
| 8762 | yLoc = 0; |
| 8763 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8764 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8765 | } |
| 8766 | } else { |
| 8767 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8768 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8769 | } |
| 8770 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8771 | int width = mRight - mLeft; |
| 8772 | int oldHeight = mBottom - mTop; |
| 8773 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8774 | mTop = top; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8775 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8776 | mDisplayList.setTop(mTop); |
| 8777 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8778 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8779 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8780 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8781 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8782 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8783 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8784 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8785 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8786 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8787 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8788 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8789 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8790 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8791 | } |
| 8792 | } |
| 8793 | |
| 8794 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8795 | * Bottom position of this view relative to its parent. |
| 8796 | * |
| 8797 | * @return The bottom of this view, in pixels. |
| 8798 | */ |
| 8799 | @ViewDebug.CapturedViewProperty |
| 8800 | public final int getBottom() { |
| 8801 | return mBottom; |
| 8802 | } |
| 8803 | |
| 8804 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 8805 | * True if this view has changed since the last time being drawn. |
| 8806 | * |
| 8807 | * @return The dirty state of this view. |
| 8808 | */ |
| 8809 | public boolean isDirty() { |
| 8810 | return (mPrivateFlags & DIRTY_MASK) != 0; |
| 8811 | } |
| 8812 | |
| 8813 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8814 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 8815 | * called by the layout system and should not generally be called otherwise, because the |
| 8816 | * property may be changed at any time by the layout. |
| 8817 | * |
| 8818 | * @param bottom The bottom of this view, in pixels. |
| 8819 | */ |
| 8820 | public final void setBottom(int bottom) { |
| 8821 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8822 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8823 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8824 | || mTransformationInfo.mMatrixIsIdentity; |
| 8825 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8826 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8827 | int maxBottom; |
| 8828 | if (bottom < mBottom) { |
| 8829 | maxBottom = mBottom; |
| 8830 | } else { |
| 8831 | maxBottom = bottom; |
| 8832 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8833 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8834 | } |
| 8835 | } else { |
| 8836 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8837 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8838 | } |
| 8839 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8840 | int width = mRight - mLeft; |
| 8841 | int oldHeight = mBottom - mTop; |
| 8842 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8843 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8844 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8845 | mDisplayList.setBottom(mBottom); |
| 8846 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8847 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8848 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 8849 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8850 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8851 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8852 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8853 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8854 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8855 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8856 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8857 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8858 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8859 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8860 | } |
| 8861 | } |
| 8862 | |
| 8863 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8864 | * Left position of this view relative to its parent. |
| 8865 | * |
| 8866 | * @return The left edge of this view, in pixels. |
| 8867 | */ |
| 8868 | @ViewDebug.CapturedViewProperty |
| 8869 | public final int getLeft() { |
| 8870 | return mLeft; |
| 8871 | } |
| 8872 | |
| 8873 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8874 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 8875 | * by the layout system and should not generally be called otherwise, because the property |
| 8876 | * may be changed at any time by the layout. |
| 8877 | * |
| 8878 | * @param left The bottom of this view, in pixels. |
| 8879 | */ |
| 8880 | public final void setLeft(int left) { |
| 8881 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8882 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8883 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8884 | || mTransformationInfo.mMatrixIsIdentity; |
| 8885 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8886 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8887 | int minLeft; |
| 8888 | int xLoc; |
| 8889 | if (left < mLeft) { |
| 8890 | minLeft = left; |
| 8891 | xLoc = left - mLeft; |
| 8892 | } else { |
| 8893 | minLeft = mLeft; |
| 8894 | xLoc = 0; |
| 8895 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8896 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8897 | } |
| 8898 | } else { |
| 8899 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8900 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8901 | } |
| 8902 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8903 | int oldWidth = mRight - mLeft; |
| 8904 | int height = mBottom - mTop; |
| 8905 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8906 | mLeft = left; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8907 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8908 | mDisplayList.setLeft(left); |
| 8909 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8910 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8911 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8912 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8913 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8914 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8915 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8916 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8917 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8918 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8919 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8920 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8921 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8922 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8923 | } |
| 8924 | } |
| 8925 | |
| 8926 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8927 | * Right position of this view relative to its parent. |
| 8928 | * |
| 8929 | * @return The right edge of this view, in pixels. |
| 8930 | */ |
| 8931 | @ViewDebug.CapturedViewProperty |
| 8932 | public final int getRight() { |
| 8933 | return mRight; |
| 8934 | } |
| 8935 | |
| 8936 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8937 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 8938 | * by the layout system and should not generally be called otherwise, because the property |
| 8939 | * may be changed at any time by the layout. |
| 8940 | * |
| 8941 | * @param right The bottom of this view, in pixels. |
| 8942 | */ |
| 8943 | public final void setRight(int right) { |
| 8944 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8945 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8946 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 8947 | || mTransformationInfo.mMatrixIsIdentity; |
| 8948 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8949 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8950 | int maxRight; |
| 8951 | if (right < mRight) { |
| 8952 | maxRight = mRight; |
| 8953 | } else { |
| 8954 | maxRight = right; |
| 8955 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 8956 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8957 | } |
| 8958 | } else { |
| 8959 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8960 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8961 | } |
| 8962 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8963 | int oldWidth = mRight - mLeft; |
| 8964 | int height = mBottom - mTop; |
| 8965 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8966 | mRight = right; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8967 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8968 | mDisplayList.setRight(mRight); |
| 8969 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8970 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 8971 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 8972 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8973 | if (!matrixIsIdentity) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8974 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 8975 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8976 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 8977 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8978 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8979 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8980 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 8981 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 8982 | invalidateParentIfNeeded(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8987 | * The visual x position of this view, in pixels. This is equivalent to the |
| 8988 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8989 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8990 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8991 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8992 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8993 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8994 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8995 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8996 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8997 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 8998 | /** |
| 8999 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 9000 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 9001 | * the x value passed in and the current {@link #getLeft() left} property. |
| 9002 | * |
| 9003 | * @param x The visual x position of this view, in pixels. |
| 9004 | */ |
| 9005 | public void setX(float x) { |
| 9006 | setTranslationX(x - mLeft); |
| 9007 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9008 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9009 | /** |
| 9010 | * The visual y position of this view, in pixels. This is equivalent to the |
| 9011 | * {@link #setTranslationY(float) translationY} property plus the current |
| 9012 | * {@link #getTop() top} property. |
| 9013 | * |
| 9014 | * @return The visual y position of this view, in pixels. |
| 9015 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9016 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9017 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9018 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9019 | } |
| 9020 | |
| 9021 | /** |
| 9022 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 9023 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 9024 | * the y value passed in and the current {@link #getTop() top} property. |
| 9025 | * |
| 9026 | * @param y The visual y position of this view, in pixels. |
| 9027 | */ |
| 9028 | public void setY(float y) { |
| 9029 | setTranslationY(y - mTop); |
| 9030 | } |
| 9031 | |
| 9032 | |
| 9033 | /** |
| 9034 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9035 | * This position is post-layout, in addition to wherever the object's |
| 9036 | * layout placed it. |
| 9037 | * |
| 9038 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 9039 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9040 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9041 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9042 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9043 | } |
| 9044 | |
| 9045 | /** |
| 9046 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9047 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9048 | * layout placed it. |
| 9049 | * |
| 9050 | * @param translationX The horizontal position of this view relative to its left position, |
| 9051 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9052 | * |
| 9053 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9054 | */ |
| 9055 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9056 | ensureTransformationInfo(); |
| 9057 | final TransformationInfo info = mTransformationInfo; |
| 9058 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9059 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9060 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9061 | info.mTranslationX = translationX; |
| 9062 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9063 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9064 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9065 | mDisplayList.setTranslationX(translationX); |
| 9066 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9067 | } |
| 9068 | } |
| 9069 | |
| 9070 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9071 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 9072 | * This position is post-layout, in addition to wherever the object's |
| 9073 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9074 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9075 | * @return The vertical position of this view relative to its top position, |
| 9076 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9077 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9078 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9079 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9080 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9081 | } |
| 9082 | |
| 9083 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9084 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9085 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9086 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9087 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9088 | * @param translationY The vertical position of this view relative to its top position, |
| 9089 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9090 | * |
| 9091 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9092 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9093 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9094 | ensureTransformationInfo(); |
| 9095 | final TransformationInfo info = mTransformationInfo; |
| 9096 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9097 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9098 | info.mTranslationY = translationY; |
| 9099 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9100 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9101 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9102 | mDisplayList.setTranslationY(translationY); |
| 9103 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9104 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9105 | } |
| 9106 | |
| 9107 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9108 | * Hit rectangle in parent's coordinates |
| 9109 | * |
| 9110 | * @param outRect The hit rectangle of the view. |
| 9111 | */ |
| 9112 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9113 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9114 | final TransformationInfo info = mTransformationInfo; |
| 9115 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9116 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9117 | } else { |
| 9118 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9119 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9120 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9121 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9122 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9123 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9128 | * Determines whether the given point, in local coordinates is inside the view. |
| 9129 | */ |
| 9130 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9131 | return localX >= 0 && localX < (mRight - mLeft) |
| 9132 | && localY >= 0 && localY < (mBottom - mTop); |
| 9133 | } |
| 9134 | |
| 9135 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9136 | * Utility method to determine whether the given point, in local coordinates, |
| 9137 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9138 | * This method is called while processing touch-move events to determine if the event |
| 9139 | * is still within the view. |
| 9140 | */ |
| 9141 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9142 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9143 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | /** |
| 9147 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9148 | * starting from the rectangle filled in by this method. |
| 9149 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9150 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 9151 | * of the view. However, if your view maintains some idea of internal selection, |
| 9152 | * such as a cursor, or a selected row or column, you should override this method and |
| 9153 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | * |
| 9155 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9156 | */ |
| 9157 | public void getFocusedRect(Rect r) { |
| 9158 | getDrawingRect(r); |
| 9159 | } |
| 9160 | |
| 9161 | /** |
| 9162 | * If some part of this view is not clipped by any of its parents, then |
| 9163 | * return that area in r in global (root) coordinates. To convert r to local |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 9164 | * coordinates (without taking possible View rotations into account), offset |
| 9165 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9166 | * If the view is completely clipped or translated out, return false. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9167 | * |
| 9168 | * @param r If true is returned, r holds the global coordinates of the |
| 9169 | * visible portion of this view. |
| 9170 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9171 | * between this view and its root. globalOffet may be null. |
| 9172 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9173 | * root level. |
| 9174 | */ |
| 9175 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9176 | int width = mRight - mLeft; |
| 9177 | int height = mBottom - mTop; |
| 9178 | if (width > 0 && height > 0) { |
| 9179 | r.set(0, 0, width, height); |
| 9180 | if (globalOffset != null) { |
| 9181 | globalOffset.set(-mScrollX, -mScrollY); |
| 9182 | } |
| 9183 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9184 | } |
| 9185 | return false; |
| 9186 | } |
| 9187 | |
| 9188 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9189 | return getGlobalVisibleRect(r, null); |
| 9190 | } |
| 9191 | |
| 9192 | public final boolean getLocalVisibleRect(Rect r) { |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 9193 | final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9194 | if (getGlobalVisibleRect(r, offset)) { |
| 9195 | r.offset(-offset.x, -offset.y); // make r local |
| 9196 | return true; |
| 9197 | } |
| 9198 | return false; |
| 9199 | } |
| 9200 | |
| 9201 | /** |
| 9202 | * Offset this view's vertical location by the specified number of pixels. |
| 9203 | * |
| 9204 | * @param offset the number of pixels to offset the view by |
| 9205 | */ |
| 9206 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9207 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9208 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9209 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9210 | || mTransformationInfo.mMatrixIsIdentity; |
| 9211 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9212 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9213 | invalidateViewProperty(false, false); |
| 9214 | } else { |
| 9215 | final ViewParent p = mParent; |
| 9216 | if (p != null && mAttachInfo != null) { |
| 9217 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9218 | int minTop; |
| 9219 | int maxBottom; |
| 9220 | int yLoc; |
| 9221 | if (offset < 0) { |
| 9222 | minTop = mTop + offset; |
| 9223 | maxBottom = mBottom; |
| 9224 | yLoc = offset; |
| 9225 | } else { |
| 9226 | minTop = mTop; |
| 9227 | maxBottom = mBottom + offset; |
| 9228 | yLoc = 0; |
| 9229 | } |
| 9230 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9231 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9232 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9233 | } |
| 9234 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9235 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9236 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9237 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9238 | mTop += offset; |
| 9239 | mBottom += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9240 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9241 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9242 | invalidateViewProperty(false, false); |
| 9243 | } else { |
| 9244 | if (!matrixIsIdentity) { |
| 9245 | invalidateViewProperty(false, true); |
| 9246 | } |
| 9247 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9248 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9249 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9250 | } |
| 9251 | |
| 9252 | /** |
| 9253 | * Offset this view's horizontal location by the specified amount of pixels. |
| 9254 | * |
| 9255 | * @param offset the numer of pixels to offset the view by |
| 9256 | */ |
| 9257 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9258 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9259 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9260 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9261 | || mTransformationInfo.mMatrixIsIdentity; |
| 9262 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9263 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9264 | invalidateViewProperty(false, false); |
| 9265 | } else { |
| 9266 | final ViewParent p = mParent; |
| 9267 | if (p != null && mAttachInfo != null) { |
| 9268 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9269 | int minLeft; |
| 9270 | int maxRight; |
| 9271 | if (offset < 0) { |
| 9272 | minLeft = mLeft + offset; |
| 9273 | maxRight = mRight; |
| 9274 | } else { |
| 9275 | minLeft = mLeft; |
| 9276 | maxRight = mRight + offset; |
| 9277 | } |
| 9278 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 9279 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9280 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9281 | } |
| 9282 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9283 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9284 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9285 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9286 | mLeft += offset; |
| 9287 | mRight += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9288 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9289 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9290 | invalidateViewProperty(false, false); |
| 9291 | } else { |
| 9292 | if (!matrixIsIdentity) { |
| 9293 | invalidateViewProperty(false, true); |
| 9294 | } |
| 9295 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9296 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9297 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9298 | } |
| 9299 | |
| 9300 | /** |
| 9301 | * Get the LayoutParams associated with this view. All views should have |
| 9302 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 9303 | * view specifying how it should be arranged. There are many subclasses of |
| 9304 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 9305 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9306 | * |
| 9307 | * This method may return null if this View is not attached to a parent |
| 9308 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 9309 | * was not invoked successfully. When a View is attached to a parent |
| 9310 | * ViewGroup, this method must not return null. |
| 9311 | * |
| 9312 | * @return The LayoutParams associated with this view, or null if no |
| 9313 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9314 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 9315 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9316 | public ViewGroup.LayoutParams getLayoutParams() { |
| 9317 | return mLayoutParams; |
| 9318 | } |
| 9319 | |
| 9320 | /** |
| 9321 | * Set the layout parameters associated with this view. These supply |
| 9322 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 9323 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 9324 | * correspond to the different subclasses of ViewGroup that are responsible |
| 9325 | * for arranging their children. |
| 9326 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9327 | * @param params The layout parameters for this view, cannot be null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9328 | */ |
| 9329 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 9330 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9331 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9332 | } |
| 9333 | mLayoutParams = params; |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 9334 | if (mParent instanceof ViewGroup) { |
| 9335 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 9336 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9337 | requestLayout(); |
| 9338 | } |
| 9339 | |
| 9340 | /** |
| 9341 | * Set the scrolled position of your view. This will cause a call to |
| 9342 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9343 | * invalidated. |
| 9344 | * @param x the x position to scroll to |
| 9345 | * @param y the y position to scroll to |
| 9346 | */ |
| 9347 | public void scrollTo(int x, int y) { |
| 9348 | if (mScrollX != x || mScrollY != y) { |
| 9349 | int oldX = mScrollX; |
| 9350 | int oldY = mScrollY; |
| 9351 | mScrollX = x; |
| 9352 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9353 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9354 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9355 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9356 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | } |
| 9359 | } |
| 9360 | |
| 9361 | /** |
| 9362 | * Move the scrolled position of your view. This will cause a call to |
| 9363 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9364 | * invalidated. |
| 9365 | * @param x the amount of pixels to scroll by horizontally |
| 9366 | * @param y the amount of pixels to scroll by vertically |
| 9367 | */ |
| 9368 | public void scrollBy(int x, int y) { |
| 9369 | scrollTo(mScrollX + x, mScrollY + y); |
| 9370 | } |
| 9371 | |
| 9372 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9373 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 9374 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 9375 | * provides animated scrolling, the start delay should equal the duration |
| 9376 | * of the scrolling animation.</p> |
| 9377 | * |
| 9378 | * <p>The animation starts only if at least one of the scrollbars is |
| 9379 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9380 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9381 | * this method returns true, and false otherwise. If the animation is |
| 9382 | * started, this method calls {@link #invalidate()}; in that case the |
| 9383 | * caller should not call {@link #invalidate()}.</p> |
| 9384 | * |
| 9385 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9386 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9387 | * |
| 9388 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 9389 | * and {@link #scrollTo(int, int)}.</p> |
| 9390 | * |
| 9391 | * @return true if the animation is played, false otherwise |
| 9392 | * |
| 9393 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9394 | * @see #scrollBy(int, int) |
| 9395 | * @see #scrollTo(int, int) |
| 9396 | * @see #isHorizontalScrollBarEnabled() |
| 9397 | * @see #isVerticalScrollBarEnabled() |
| 9398 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9399 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9400 | */ |
| 9401 | protected boolean awakenScrollBars() { |
| 9402 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9403 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9404 | } |
| 9405 | |
| 9406 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9407 | * Trigger the scrollbars to draw. |
| 9408 | * This method differs from awakenScrollBars() only in its default duration. |
| 9409 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 9410 | * usual to give the user more of a chance to notice them. |
| 9411 | * |
| 9412 | * @return true if the animation is played, false otherwise. |
| 9413 | */ |
| 9414 | private boolean initialAwakenScrollBars() { |
| 9415 | return mScrollCache != null && |
| 9416 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 9417 | } |
| 9418 | |
| 9419 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9420 | * <p> |
| 9421 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9422 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9423 | * provides animated scrolling, the start delay should equal the duration of |
| 9424 | * the scrolling animation. |
| 9425 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9426 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9427 | * <p> |
| 9428 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9429 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9430 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9431 | * this method returns true, and false otherwise. If the animation is |
| 9432 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 9433 | * should not call {@link #invalidate()}. |
| 9434 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9435 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9436 | * <p> |
| 9437 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9438 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9439 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9440 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9441 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9442 | * should start; when the delay is 0, the animation starts |
| 9443 | * immediately |
| 9444 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9445 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9446 | * @see #scrollBy(int, int) |
| 9447 | * @see #scrollTo(int, int) |
| 9448 | * @see #isHorizontalScrollBarEnabled() |
| 9449 | * @see #isVerticalScrollBarEnabled() |
| 9450 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9451 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9452 | */ |
| 9453 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9454 | return awakenScrollBars(startDelay, true); |
| 9455 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9456 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9457 | /** |
| 9458 | * <p> |
| 9459 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9460 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9461 | * provides animated scrolling, the start delay should equal the duration of |
| 9462 | * the scrolling animation. |
| 9463 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9464 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9465 | * <p> |
| 9466 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9467 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9468 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9469 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9470 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9471 | * is set to true; in that case the caller |
| 9472 | * should not call {@link #invalidate()}. |
| 9473 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9474 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9475 | * <p> |
| 9476 | * This method should be invoked everytime a subclass directly updates the |
| 9477 | * scroll parameters. |
| 9478 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9479 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9480 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9481 | * should start; when the delay is 0, the animation starts |
| 9482 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9483 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9484 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9485 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9486 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9487 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9488 | * @see #scrollBy(int, int) |
| 9489 | * @see #scrollTo(int, int) |
| 9490 | * @see #isHorizontalScrollBarEnabled() |
| 9491 | * @see #isVerticalScrollBarEnabled() |
| 9492 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9493 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9494 | */ |
| 9495 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9496 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9497 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9498 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 9499 | return false; |
| 9500 | } |
| 9501 | |
| 9502 | if (scrollCache.scrollBar == null) { |
| 9503 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 9504 | } |
| 9505 | |
| 9506 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 9507 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9508 | if (invalidate) { |
| 9509 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9510 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9511 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9512 | |
| 9513 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 9514 | // FIXME: this is copied from WindowManagerService. |
| 9515 | // We should get this value from the system when it |
| 9516 | // is possible to do so. |
| 9517 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 9518 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 9519 | } |
| 9520 | |
| 9521 | // Tell mScrollCache when we should start fading. This may |
| 9522 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 9523 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9524 | scrollCache.fadeStartTime = fadeStartTime; |
| 9525 | scrollCache.state = ScrollabilityCache.ON; |
| 9526 | |
| 9527 | // Schedule our fader to run, unscheduling any old ones first |
| 9528 | if (mAttachInfo != null) { |
| 9529 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 9530 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 9531 | } |
| 9532 | |
| 9533 | return true; |
| 9534 | } |
| 9535 | |
| 9536 | return false; |
| 9537 | } |
| 9538 | |
| 9539 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9540 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 9541 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 9542 | */ |
| 9543 | private boolean skipInvalidate() { |
| 9544 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 9545 | (!(mParent instanceof ViewGroup) || |
| 9546 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 9547 | } |
| 9548 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 9549 | * Mark the area defined by dirty as needing to be drawn. If the view is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9550 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 9551 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 9552 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | * |
| 9554 | * WARNING: This method is destructive to dirty. |
| 9555 | * @param dirty the rectangle representing the bounds of the dirty region |
| 9556 | */ |
| 9557 | public void invalidate(Rect dirty) { |
| 9558 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9559 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9560 | } |
| 9561 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9562 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9563 | return; |
| 9564 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9565 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9566 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 9567 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9569 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9570 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9571 | final ViewParent p = mParent; |
| 9572 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9573 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9574 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9575 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9576 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9577 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9578 | p.invalidateChild(this, null); |
| 9579 | return; |
| 9580 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 9581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9582 | if (p != null && ai != null) { |
| 9583 | final int scrollX = mScrollX; |
| 9584 | final int scrollY = mScrollY; |
| 9585 | final Rect r = ai.mTmpInvalRect; |
| 9586 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 9587 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 9588 | mParent.invalidateChild(this, r); |
| 9589 | } |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 9594 | * Mark the area defined by the rect (l,t,r,b) as needing to be drawn. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9595 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9596 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 9597 | * will be called at some point in the future. This must be called from |
| 9598 | * a UI thread. To call from a non-UI thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | * @param l the left position of the dirty region |
| 9600 | * @param t the top position of the dirty region |
| 9601 | * @param r the right position of the dirty region |
| 9602 | * @param b the bottom position of the dirty region |
| 9603 | */ |
| 9604 | public void invalidate(int l, int t, int r, int b) { |
| 9605 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9606 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9607 | } |
| 9608 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9609 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9610 | return; |
| 9611 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9612 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9613 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID || |
| 9614 | (mPrivateFlags & INVALIDATED) != INVALIDATED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9616 | mPrivateFlags |= INVALIDATED; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9617 | mPrivateFlags |= DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9618 | final ViewParent p = mParent; |
| 9619 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9620 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9621 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9622 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9623 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9624 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9625 | p.invalidateChild(this, null); |
| 9626 | return; |
| 9627 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 9628 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9629 | if (p != null && ai != null && l < r && t < b) { |
| 9630 | final int scrollX = mScrollX; |
| 9631 | final int scrollY = mScrollY; |
| 9632 | final Rect tmpr = ai.mTmpInvalRect; |
| 9633 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 9634 | p.invalidateChild(this, tmpr); |
| 9635 | } |
| 9636 | } |
| 9637 | } |
| 9638 | |
| 9639 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9640 | * Invalidate the whole view. If the view is visible, |
| 9641 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 9642 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 9643 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9644 | */ |
| 9645 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9646 | invalidate(true); |
| 9647 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9648 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9649 | /** |
| 9650 | * This is where the invalidate() work actually happens. A full invalidate() |
| 9651 | * causes the drawing cache to be invalidated, but this function can be called with |
| 9652 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 9653 | * need it (for example, a component that remains at the same dimensions with the same |
| 9654 | * content). |
| 9655 | * |
| 9656 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 9657 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 9658 | * View's contents or dimensions have not changed. |
| 9659 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 9660 | void invalidate(boolean invalidateCache) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9661 | if (ViewDebug.TRACE_HIERARCHY) { |
| 9662 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.INVALIDATE); |
| 9663 | } |
| 9664 | |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 9665 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 9666 | return; |
| 9667 | } |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 9668 | if ((mPrivateFlags & (DRAWN | HAS_BOUNDS)) == (DRAWN | HAS_BOUNDS) || |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 9669 | (invalidateCache && (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) || |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9670 | (mPrivateFlags & INVALIDATED) != INVALIDATED || isOpaque() != mLastIsOpaque) { |
| 9671 | mLastIsOpaque = isOpaque(); |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9672 | mPrivateFlags &= ~DRAWN; |
Chet Haase | f186f30 | 2011-09-11 11:06:06 -0700 | [diff] [blame] | 9673 | mPrivateFlags |= DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9674 | if (invalidateCache) { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9675 | mPrivateFlags |= INVALIDATED; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9676 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 9677 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9678 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9679 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9680 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 9681 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 9682 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 9683 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 9684 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 9685 | p.invalidateChild(this, null); |
| 9686 | return; |
| 9687 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 9688 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 9689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9690 | if (p != null && ai != null) { |
| 9691 | final Rect r = ai.mTmpInvalRect; |
| 9692 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9693 | // Don't call invalidate -- we don't want to internally scroll |
| 9694 | // our own bounds |
| 9695 | p.invalidateChild(this, r); |
| 9696 | } |
| 9697 | } |
| 9698 | } |
| 9699 | |
| 9700 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9701 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 9702 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 9703 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 9704 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 9705 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 9706 | * |
| 9707 | * The method also handles normal invalidation logic if display list properties are not |
| 9708 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 9709 | * backup approach, to handle these cases used in the various property-setting methods. |
| 9710 | * |
| 9711 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 9712 | * are not being used in this view |
| 9713 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 9714 | * list properties are not being used in this view |
| 9715 | */ |
| 9716 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9717 | if (mDisplayList == null || (mPrivateFlags & DRAW_ANIMATION) == DRAW_ANIMATION) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9718 | if (invalidateParent) { |
| 9719 | invalidateParentCaches(); |
| 9720 | } |
| 9721 | if (forceRedraw) { |
| 9722 | mPrivateFlags |= DRAWN; // force another invalidation with the new orientation |
| 9723 | } |
| 9724 | invalidate(false); |
| 9725 | } else { |
| 9726 | final AttachInfo ai = mAttachInfo; |
| 9727 | final ViewParent p = mParent; |
| 9728 | if (p != null && ai != null) { |
| 9729 | final Rect r = ai.mTmpInvalRect; |
| 9730 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 9731 | if (mParent instanceof ViewGroup) { |
| 9732 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 9733 | } else { |
| 9734 | mParent.invalidateChild(this, r); |
| 9735 | } |
| 9736 | } |
| 9737 | } |
| 9738 | } |
| 9739 | |
| 9740 | /** |
| 9741 | * Utility method to transform a given Rect by the current matrix of this view. |
| 9742 | */ |
| 9743 | void transformRect(final Rect rect) { |
| 9744 | if (!getMatrix().isIdentity()) { |
| 9745 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 9746 | boundingRect.set(rect); |
| 9747 | getMatrix().mapRect(boundingRect); |
| 9748 | rect.set((int) (boundingRect.left - 0.5f), |
| 9749 | (int) (boundingRect.top - 0.5f), |
| 9750 | (int) (boundingRect.right + 0.5f), |
| 9751 | (int) (boundingRect.bottom + 0.5f)); |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9756 | * Used to indicate that the parent of this view should clear its caches. This functionality |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9757 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9758 | * which is necessary when various parent-managed properties of the view change, such as |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9759 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 9760 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9761 | * |
| 9762 | * @hide |
| 9763 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9764 | protected void invalidateParentCaches() { |
| 9765 | if (mParent instanceof View) { |
| 9766 | ((View) mParent).mPrivateFlags |= INVALIDATED; |
| 9767 | } |
| 9768 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9769 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9770 | /** |
| 9771 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 9772 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 9773 | * which is necessary when various parent-managed properties of the view change, such as |
| 9774 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 9775 | * an invalidation event to the parent. |
| 9776 | * |
| 9777 | * @hide |
| 9778 | */ |
| 9779 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9780 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9781 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 9782 | } |
| 9783 | } |
| 9784 | |
| 9785 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9786 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 9787 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 9788 | * |
| 9789 | * Subclasses of View should override this method whenever possible to indicate |
| 9790 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 9791 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 9792 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 9793 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9794 | * @return True if this View is guaranteed to be fully opaque, false otherwise. |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9795 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 9796 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9797 | public boolean isOpaque() { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 9798 | return (mPrivateFlags & OPAQUE_MASK) == OPAQUE_MASK && |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9799 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1) |
| 9800 | >= 1.0f - ViewConfiguration.ALPHA_THRESHOLD); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9801 | } |
| 9802 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 9803 | /** |
| 9804 | * @hide |
| 9805 | */ |
| 9806 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9807 | // Opaque if: |
| 9808 | // - Has a background |
| 9809 | // - Background is opaque |
| 9810 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 9811 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9812 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 9813 | mPrivateFlags |= OPAQUE_BACKGROUND; |
| 9814 | } else { |
| 9815 | mPrivateFlags &= ~OPAQUE_BACKGROUND; |
| 9816 | } |
| 9817 | |
| 9818 | final int flags = mViewFlags; |
| 9819 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 9820 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
| 9821 | mPrivateFlags |= OPAQUE_SCROLLBARS; |
| 9822 | } else { |
| 9823 | mPrivateFlags &= ~OPAQUE_SCROLLBARS; |
| 9824 | } |
| 9825 | } |
| 9826 | |
| 9827 | /** |
| 9828 | * @hide |
| 9829 | */ |
| 9830 | protected boolean hasOpaqueScrollbars() { |
| 9831 | return (mPrivateFlags & OPAQUE_SCROLLBARS) == OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 9832 | } |
| 9833 | |
| 9834 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9835 | * @return A handler associated with the thread running the View. This |
| 9836 | * handler can be used to pump events in the UI events queue. |
| 9837 | */ |
| 9838 | public Handler getHandler() { |
| 9839 | if (mAttachInfo != null) { |
| 9840 | return mAttachInfo.mHandler; |
| 9841 | } |
| 9842 | return null; |
| 9843 | } |
| 9844 | |
| 9845 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9846 | * Gets the view root associated with the View. |
| 9847 | * @return The view root, or null if none. |
| 9848 | * @hide |
| 9849 | */ |
| 9850 | public ViewRootImpl getViewRootImpl() { |
| 9851 | if (mAttachInfo != null) { |
| 9852 | return mAttachInfo.mViewRootImpl; |
| 9853 | } |
| 9854 | return null; |
| 9855 | } |
| 9856 | |
| 9857 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9858 | * <p>Causes the Runnable to be added to the message queue. |
| 9859 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9860 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9861 | * <p>This method can be invoked from outside of the UI thread |
| 9862 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9863 | * |
| 9864 | * @param action The Runnable that will be executed. |
| 9865 | * |
| 9866 | * @return Returns true if the Runnable was successfully placed in to the |
| 9867 | * message queue. Returns false on failure, usually because the |
| 9868 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9869 | * |
| 9870 | * @see #postDelayed |
| 9871 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | */ |
| 9873 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9874 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9875 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9876 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9877 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9878 | // Assume that post will succeed later |
| 9879 | ViewRootImpl.getRunQueue().post(action); |
| 9880 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9881 | } |
| 9882 | |
| 9883 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9884 | * <p>Causes the Runnable to be added to the message queue, to be run |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9885 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9886 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9887 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9888 | * <p>This method can be invoked from outside of the UI thread |
| 9889 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | * |
| 9891 | * @param action The Runnable that will be executed. |
| 9892 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9893 | * will be executed. |
| 9894 | * |
| 9895 | * @return true if the Runnable was successfully placed in to the |
| 9896 | * message queue. Returns false on failure, usually because the |
| 9897 | * looper processing the message queue is exiting. Note that a |
| 9898 | * result of true does not mean the Runnable will be processed -- |
| 9899 | * if the looper is quit before the delivery time of the message |
| 9900 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9901 | * |
| 9902 | * @see #post |
| 9903 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9904 | */ |
| 9905 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9906 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 9907 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9908 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9909 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 9910 | // Assume that post will succeed later |
| 9911 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9912 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | } |
| 9914 | |
| 9915 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9916 | * <p>Causes the Runnable to execute on the next animation time step. |
| 9917 | * The runnable will be run on the user interface thread.</p> |
| 9918 | * |
| 9919 | * <p>This method can be invoked from outside of the UI thread |
| 9920 | * only when this View is attached to a window.</p> |
| 9921 | * |
| 9922 | * @param action The Runnable that will be executed. |
| 9923 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9924 | * @see #postOnAnimationDelayed |
| 9925 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9926 | */ |
| 9927 | public void postOnAnimation(Runnable action) { |
| 9928 | final AttachInfo attachInfo = mAttachInfo; |
| 9929 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9930 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 9931 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9932 | } else { |
| 9933 | // Assume that post will succeed later |
| 9934 | ViewRootImpl.getRunQueue().post(action); |
| 9935 | } |
| 9936 | } |
| 9937 | |
| 9938 | /** |
| 9939 | * <p>Causes the Runnable to execute on the next animation time step, |
| 9940 | * after the specified amount of time elapses. |
| 9941 | * The runnable will be run on the user interface thread.</p> |
| 9942 | * |
| 9943 | * <p>This method can be invoked from outside of the UI thread |
| 9944 | * only when this View is attached to a window.</p> |
| 9945 | * |
| 9946 | * @param action The Runnable that will be executed. |
| 9947 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 9948 | * will be executed. |
| 9949 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9950 | * @see #postOnAnimation |
| 9951 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9952 | */ |
| 9953 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 9954 | final AttachInfo attachInfo = mAttachInfo; |
| 9955 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9956 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 9957 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 9958 | } else { |
| 9959 | // Assume that post will succeed later |
| 9960 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 9961 | } |
| 9962 | } |
| 9963 | |
| 9964 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9965 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9966 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9967 | * <p>This method can be invoked from outside of the UI thread |
| 9968 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9969 | * |
| 9970 | * @param action The Runnable to remove from the message handling queue |
| 9971 | * |
| 9972 | * @return true if this view could ask the Handler to remove the Runnable, |
| 9973 | * false otherwise. When the returned value is true, the Runnable |
| 9974 | * may or may not have been actually removed from the message queue |
| 9975 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 9976 | * |
| 9977 | * @see #post |
| 9978 | * @see #postDelayed |
| 9979 | * @see #postOnAnimation |
| 9980 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9981 | */ |
| 9982 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9983 | if (action != null) { |
| 9984 | final AttachInfo attachInfo = mAttachInfo; |
| 9985 | if (attachInfo != null) { |
| 9986 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 9987 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 9988 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 9989 | } else { |
| 9990 | // Assume that post will succeed later |
| 9991 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 9992 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9994 | return true; |
| 9995 | } |
| 9996 | |
| 9997 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 9998 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 9999 | * Use this to invalidate the View from a non-UI thread.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10001 | * <p>This method can be invoked from outside of the UI thread |
| 10002 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10003 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10004 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10005 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | */ |
| 10007 | public void postInvalidate() { |
| 10008 | postInvalidateDelayed(0); |
| 10009 | } |
| 10010 | |
| 10011 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10012 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10013 | * through the event loop. Use this to invalidate the View from a non-UI thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10014 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10015 | * <p>This method can be invoked from outside of the UI thread |
| 10016 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10017 | * |
| 10018 | * @param left The left coordinate of the rectangle to invalidate. |
| 10019 | * @param top The top coordinate of the rectangle to invalidate. |
| 10020 | * @param right The right coordinate of the rectangle to invalidate. |
| 10021 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10022 | * |
| 10023 | * @see #invalidate(int, int, int, int) |
| 10024 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10025 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10026 | */ |
| 10027 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 10028 | postInvalidateDelayed(0, left, top, right, bottom); |
| 10029 | } |
| 10030 | |
| 10031 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10032 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 10033 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10034 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10035 | * <p>This method can be invoked from outside of the UI thread |
| 10036 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10037 | * |
| 10038 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10039 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10040 | * |
| 10041 | * @see #invalidate() |
| 10042 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10043 | */ |
| 10044 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 10045 | // We try only with the AttachInfo because there's no point in invalidating |
| 10046 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10047 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10048 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10049 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | } |
| 10051 | } |
| 10052 | |
| 10053 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10054 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10055 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10056 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10057 | * <p>This method can be invoked from outside of the UI thread |
| 10058 | * only when this View is attached to a window.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10059 | * |
| 10060 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10061 | * invalidation by |
| 10062 | * @param left The left coordinate of the rectangle to invalidate. |
| 10063 | * @param top The top coordinate of the rectangle to invalidate. |
| 10064 | * @param right The right coordinate of the rectangle to invalidate. |
| 10065 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10066 | * |
| 10067 | * @see #invalidate(int, int, int, int) |
| 10068 | * @see #invalidate(Rect) |
| 10069 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10070 | */ |
| 10071 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 10072 | int right, int bottom) { |
| 10073 | |
| 10074 | // We try only with the AttachInfo because there's no point in invalidating |
| 10075 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10076 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10077 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10078 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10079 | info.target = this; |
| 10080 | info.left = left; |
| 10081 | info.top = top; |
| 10082 | info.right = right; |
| 10083 | info.bottom = bottom; |
| 10084 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10085 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10086 | } |
| 10087 | } |
| 10088 | |
| 10089 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10090 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10091 | * next display frame.</p> |
| 10092 | * |
| 10093 | * <p>This method can be invoked from outside of the UI thread |
| 10094 | * only when this View is attached to a window.</p> |
| 10095 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10096 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10097 | */ |
| 10098 | public void postInvalidateOnAnimation() { |
| 10099 | // We try only with the AttachInfo because there's no point in invalidating |
| 10100 | // if we are not attached to our window |
| 10101 | final AttachInfo attachInfo = mAttachInfo; |
| 10102 | if (attachInfo != null) { |
| 10103 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10104 | } |
| 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10109 | * time step, typically the next display frame.</p> |
| 10110 | * |
| 10111 | * <p>This method can be invoked from outside of the UI thread |
| 10112 | * only when this View is attached to a window.</p> |
| 10113 | * |
| 10114 | * @param left The left coordinate of the rectangle to invalidate. |
| 10115 | * @param top The top coordinate of the rectangle to invalidate. |
| 10116 | * @param right The right coordinate of the rectangle to invalidate. |
| 10117 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10118 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10119 | * @see #invalidate(int, int, int, int) |
| 10120 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10121 | */ |
| 10122 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10123 | // We try only with the AttachInfo because there's no point in invalidating |
| 10124 | // if we are not attached to our window |
| 10125 | final AttachInfo attachInfo = mAttachInfo; |
| 10126 | if (attachInfo != null) { |
| 10127 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10128 | info.target = this; |
| 10129 | info.left = left; |
| 10130 | info.top = top; |
| 10131 | info.right = right; |
| 10132 | info.bottom = bottom; |
| 10133 | |
| 10134 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10135 | } |
| 10136 | } |
| 10137 | |
| 10138 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10139 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10140 | * This event is sent at most once every |
| 10141 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10142 | */ |
| 10143 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10144 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10145 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10146 | } |
| 10147 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10148 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10149 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10150 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10151 | } |
| 10152 | } |
| 10153 | |
| 10154 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10155 | * Called by a parent to request that a child update its values for mScrollX |
| 10156 | * and mScrollY if necessary. This will typically be done if the child is |
| 10157 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10158 | * object. |
| 10159 | */ |
| 10160 | public void computeScroll() { |
| 10161 | } |
| 10162 | |
| 10163 | /** |
| 10164 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10165 | * scrolled horizontally.</p> |
| 10166 | * |
| 10167 | * @return true if the horizontal edges should are faded on scroll, false |
| 10168 | * otherwise |
| 10169 | * |
| 10170 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10171 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10172 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10173 | */ |
| 10174 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10175 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10176 | } |
| 10177 | |
| 10178 | /** |
| 10179 | * <p>Define whether the horizontal edges should be faded when this view |
| 10180 | * is scrolled horizontally.</p> |
| 10181 | * |
| 10182 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10183 | * be faded when the view is scrolled |
| 10184 | * horizontally |
| 10185 | * |
| 10186 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10187 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10188 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10189 | */ |
| 10190 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10191 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10192 | if (horizontalFadingEdgeEnabled) { |
| 10193 | initScrollCache(); |
| 10194 | } |
| 10195 | |
| 10196 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10197 | } |
| 10198 | } |
| 10199 | |
| 10200 | /** |
| 10201 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10202 | * scrolled horizontally.</p> |
| 10203 | * |
| 10204 | * @return true if the vertical edges should are faded on scroll, false |
| 10205 | * otherwise |
| 10206 | * |
| 10207 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10208 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10209 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10210 | */ |
| 10211 | public boolean isVerticalFadingEdgeEnabled() { |
| 10212 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10213 | } |
| 10214 | |
| 10215 | /** |
| 10216 | * <p>Define whether the vertical edges should be faded when this view |
| 10217 | * is scrolled vertically.</p> |
| 10218 | * |
| 10219 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10220 | * be faded when the view is scrolled |
| 10221 | * vertically |
| 10222 | * |
| 10223 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10224 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10225 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10226 | */ |
| 10227 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10228 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10229 | if (verticalFadingEdgeEnabled) { |
| 10230 | initScrollCache(); |
| 10231 | } |
| 10232 | |
| 10233 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10234 | } |
| 10235 | } |
| 10236 | |
| 10237 | /** |
| 10238 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10239 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10240 | * returns 0.0 or 1.0 but no value in between. |
| 10241 | * |
| 10242 | * Subclasses should override this method to provide a smoother fade transition |
| 10243 | * when scrolling occurs. |
| 10244 | * |
| 10245 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10246 | */ |
| 10247 | protected float getTopFadingEdgeStrength() { |
| 10248 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10249 | } |
| 10250 | |
| 10251 | /** |
| 10252 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 10253 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10254 | * returns 0.0 or 1.0 but no value in between. |
| 10255 | * |
| 10256 | * Subclasses should override this method to provide a smoother fade transition |
| 10257 | * when scrolling occurs. |
| 10258 | * |
| 10259 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 10260 | */ |
| 10261 | protected float getBottomFadingEdgeStrength() { |
| 10262 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 10263 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 10264 | } |
| 10265 | |
| 10266 | /** |
| 10267 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 10268 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10269 | * returns 0.0 or 1.0 but no value in between. |
| 10270 | * |
| 10271 | * Subclasses should override this method to provide a smoother fade transition |
| 10272 | * when scrolling occurs. |
| 10273 | * |
| 10274 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 10275 | */ |
| 10276 | protected float getLeftFadingEdgeStrength() { |
| 10277 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10278 | } |
| 10279 | |
| 10280 | /** |
| 10281 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 10282 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10283 | * returns 0.0 or 1.0 but no value in between. |
| 10284 | * |
| 10285 | * Subclasses should override this method to provide a smoother fade transition |
| 10286 | * when scrolling occurs. |
| 10287 | * |
| 10288 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 10289 | */ |
| 10290 | protected float getRightFadingEdgeStrength() { |
| 10291 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 10292 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 10293 | } |
| 10294 | |
| 10295 | /** |
| 10296 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 10297 | * scrollbar is not drawn by default.</p> |
| 10298 | * |
| 10299 | * @return true if the horizontal scrollbar should be painted, false |
| 10300 | * otherwise |
| 10301 | * |
| 10302 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10303 | */ |
| 10304 | public boolean isHorizontalScrollBarEnabled() { |
| 10305 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10306 | } |
| 10307 | |
| 10308 | /** |
| 10309 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 10310 | * scrollbar is not drawn by default.</p> |
| 10311 | * |
| 10312 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 10313 | * be painted |
| 10314 | * |
| 10315 | * @see #isHorizontalScrollBarEnabled() |
| 10316 | */ |
| 10317 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 10318 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 10319 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10320 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10321 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10322 | } |
| 10323 | } |
| 10324 | |
| 10325 | /** |
| 10326 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 10327 | * scrollbar is not drawn by default.</p> |
| 10328 | * |
| 10329 | * @return true if the vertical scrollbar should be painted, false |
| 10330 | * otherwise |
| 10331 | * |
| 10332 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10333 | */ |
| 10334 | public boolean isVerticalScrollBarEnabled() { |
| 10335 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 10336 | } |
| 10337 | |
| 10338 | /** |
| 10339 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 10340 | * scrollbar is not drawn by default.</p> |
| 10341 | * |
| 10342 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 10343 | * be painted |
| 10344 | * |
| 10345 | * @see #isVerticalScrollBarEnabled() |
| 10346 | */ |
| 10347 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 10348 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 10349 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10350 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10351 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10352 | } |
| 10353 | } |
| 10354 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10355 | /** |
| 10356 | * @hide |
| 10357 | */ |
| 10358 | protected void recomputePadding() { |
| 10359 | setPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10360 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10361 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10362 | /** |
| 10363 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10364 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10365 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10366 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10367 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10368 | */ |
| 10369 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 10370 | initScrollCache(); |
| 10371 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 10372 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10373 | if (fadeScrollbars) { |
| 10374 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 10375 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10376 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 10377 | } |
| 10378 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10380 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10381 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10382 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10383 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10384 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10385 | * |
| 10386 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10387 | */ |
| 10388 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10389 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10390 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10391 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10392 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10393 | * |
| 10394 | * Returns the delay before scrollbars fade. |
| 10395 | * |
| 10396 | * @return the delay before scrollbars fade |
| 10397 | * |
| 10398 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10399 | */ |
| 10400 | public int getScrollBarDefaultDelayBeforeFade() { |
| 10401 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 10402 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 10403 | } |
| 10404 | |
| 10405 | /** |
| 10406 | * Define the delay before scrollbars fade. |
| 10407 | * |
| 10408 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 10409 | * |
| 10410 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10411 | */ |
| 10412 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 10413 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 10414 | } |
| 10415 | |
| 10416 | /** |
| 10417 | * |
| 10418 | * Returns the scrollbar fade duration. |
| 10419 | * |
| 10420 | * @return the scrollbar fade duration |
| 10421 | * |
| 10422 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10423 | */ |
| 10424 | public int getScrollBarFadeDuration() { |
| 10425 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 10426 | mScrollCache.scrollBarFadeDuration; |
| 10427 | } |
| 10428 | |
| 10429 | /** |
| 10430 | * Define the scrollbar fade duration. |
| 10431 | * |
| 10432 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 10433 | * |
| 10434 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10435 | */ |
| 10436 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 10437 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 10438 | } |
| 10439 | |
| 10440 | /** |
| 10441 | * |
| 10442 | * Returns the scrollbar size. |
| 10443 | * |
| 10444 | * @return the scrollbar size |
| 10445 | * |
| 10446 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10447 | */ |
| 10448 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 10449 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10450 | mScrollCache.scrollBarSize; |
| 10451 | } |
| 10452 | |
| 10453 | /** |
| 10454 | * Define the scrollbar size. |
| 10455 | * |
| 10456 | * @param scrollBarSize - the scrollbar size |
| 10457 | * |
| 10458 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10459 | */ |
| 10460 | public void setScrollBarSize(int scrollBarSize) { |
| 10461 | getScrollCache().scrollBarSize = scrollBarSize; |
| 10462 | } |
| 10463 | |
| 10464 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10465 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 10466 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 10467 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 10468 | * if a view has a background drawable and you want to draw the scrollbars |
| 10469 | * inside the padding specified by the drawable, you can use |
| 10470 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 10471 | * appear at the edge of the view, ignoring the padding, then you can use |
| 10472 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 10473 | * @param style the style of the scrollbars. Should be one of |
| 10474 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 10475 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 10476 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10477 | * @see #SCROLLBARS_INSIDE_INSET |
| 10478 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10479 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10480 | * |
| 10481 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10482 | */ |
| 10483 | public void setScrollBarStyle(int style) { |
| 10484 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 10485 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10486 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10487 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10488 | } |
| 10489 | } |
| 10490 | |
| 10491 | /** |
| 10492 | * <p>Returns the current scrollbar style.</p> |
| 10493 | * @return the current scrollbar style |
| 10494 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10495 | * @see #SCROLLBARS_INSIDE_INSET |
| 10496 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10497 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10498 | * |
| 10499 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10500 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 10501 | @ViewDebug.ExportedProperty(mapping = { |
| 10502 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 10503 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 10504 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 10505 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 10506 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10507 | public int getScrollBarStyle() { |
| 10508 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 10509 | } |
| 10510 | |
| 10511 | /** |
| 10512 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 10513 | * represents.</p> |
| 10514 | * |
| 10515 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10516 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 10517 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 10518 | * |
| 10519 | * <p>The default range is the drawing width of this view.</p> |
| 10520 | * |
| 10521 | * @return the total horizontal range represented by the horizontal |
| 10522 | * scrollbar |
| 10523 | * |
| 10524 | * @see #computeHorizontalScrollExtent() |
| 10525 | * @see #computeHorizontalScrollOffset() |
| 10526 | * @see android.widget.ScrollBarDrawable |
| 10527 | */ |
| 10528 | protected int computeHorizontalScrollRange() { |
| 10529 | return getWidth(); |
| 10530 | } |
| 10531 | |
| 10532 | /** |
| 10533 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 10534 | * within the horizontal range. This value is used to compute the position |
| 10535 | * of the thumb within the scrollbar's track.</p> |
| 10536 | * |
| 10537 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10538 | * units used by {@link #computeHorizontalScrollRange()} and |
| 10539 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 10540 | * |
| 10541 | * <p>The default offset is the scroll offset of this view.</p> |
| 10542 | * |
| 10543 | * @return the horizontal offset of the scrollbar's thumb |
| 10544 | * |
| 10545 | * @see #computeHorizontalScrollRange() |
| 10546 | * @see #computeHorizontalScrollExtent() |
| 10547 | * @see android.widget.ScrollBarDrawable |
| 10548 | */ |
| 10549 | protected int computeHorizontalScrollOffset() { |
| 10550 | return mScrollX; |
| 10551 | } |
| 10552 | |
| 10553 | /** |
| 10554 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 10555 | * within the horizontal range. This value is used to compute the length |
| 10556 | * of the thumb within the scrollbar's track.</p> |
| 10557 | * |
| 10558 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10559 | * units used by {@link #computeHorizontalScrollRange()} and |
| 10560 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 10561 | * |
| 10562 | * <p>The default extent is the drawing width of this view.</p> |
| 10563 | * |
| 10564 | * @return the horizontal extent of the scrollbar's thumb |
| 10565 | * |
| 10566 | * @see #computeHorizontalScrollRange() |
| 10567 | * @see #computeHorizontalScrollOffset() |
| 10568 | * @see android.widget.ScrollBarDrawable |
| 10569 | */ |
| 10570 | protected int computeHorizontalScrollExtent() { |
| 10571 | return getWidth(); |
| 10572 | } |
| 10573 | |
| 10574 | /** |
| 10575 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 10576 | * |
| 10577 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10578 | * units used by {@link #computeVerticalScrollExtent()} and |
| 10579 | * {@link #computeVerticalScrollOffset()}.</p> |
| 10580 | * |
| 10581 | * @return the total vertical range represented by the vertical scrollbar |
| 10582 | * |
| 10583 | * <p>The default range is the drawing height of this view.</p> |
| 10584 | * |
| 10585 | * @see #computeVerticalScrollExtent() |
| 10586 | * @see #computeVerticalScrollOffset() |
| 10587 | * @see android.widget.ScrollBarDrawable |
| 10588 | */ |
| 10589 | protected int computeVerticalScrollRange() { |
| 10590 | return getHeight(); |
| 10591 | } |
| 10592 | |
| 10593 | /** |
| 10594 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 10595 | * within the horizontal range. This value is used to compute the position |
| 10596 | * of the thumb within the scrollbar's track.</p> |
| 10597 | * |
| 10598 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10599 | * units used by {@link #computeVerticalScrollRange()} and |
| 10600 | * {@link #computeVerticalScrollExtent()}.</p> |
| 10601 | * |
| 10602 | * <p>The default offset is the scroll offset of this view.</p> |
| 10603 | * |
| 10604 | * @return the vertical offset of the scrollbar's thumb |
| 10605 | * |
| 10606 | * @see #computeVerticalScrollRange() |
| 10607 | * @see #computeVerticalScrollExtent() |
| 10608 | * @see android.widget.ScrollBarDrawable |
| 10609 | */ |
| 10610 | protected int computeVerticalScrollOffset() { |
| 10611 | return mScrollY; |
| 10612 | } |
| 10613 | |
| 10614 | /** |
| 10615 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 10616 | * within the vertical range. This value is used to compute the length |
| 10617 | * of the thumb within the scrollbar's track.</p> |
| 10618 | * |
| 10619 | * <p>The range is expressed in arbitrary units that must be the same as the |
Gilles Debunne | 5296424 | 2010-02-24 11:05:19 -0800 | [diff] [blame] | 10620 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10621 | * {@link #computeVerticalScrollOffset()}.</p> |
| 10622 | * |
| 10623 | * <p>The default extent is the drawing height of this view.</p> |
| 10624 | * |
| 10625 | * @return the vertical extent of the scrollbar's thumb |
| 10626 | * |
| 10627 | * @see #computeVerticalScrollRange() |
| 10628 | * @see #computeVerticalScrollOffset() |
| 10629 | * @see android.widget.ScrollBarDrawable |
| 10630 | */ |
| 10631 | protected int computeVerticalScrollExtent() { |
| 10632 | return getHeight(); |
| 10633 | } |
| 10634 | |
| 10635 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 10636 | * Check if this view can be scrolled horizontally in a certain direction. |
| 10637 | * |
| 10638 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 10639 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 10640 | */ |
| 10641 | public boolean canScrollHorizontally(int direction) { |
| 10642 | final int offset = computeHorizontalScrollOffset(); |
| 10643 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 10644 | if (range == 0) return false; |
| 10645 | if (direction < 0) { |
| 10646 | return offset > 0; |
| 10647 | } else { |
| 10648 | return offset < range - 1; |
| 10649 | } |
| 10650 | } |
| 10651 | |
| 10652 | /** |
| 10653 | * Check if this view can be scrolled vertically in a certain direction. |
| 10654 | * |
| 10655 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 10656 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 10657 | */ |
| 10658 | public boolean canScrollVertically(int direction) { |
| 10659 | final int offset = computeVerticalScrollOffset(); |
| 10660 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 10661 | if (range == 0) return false; |
| 10662 | if (direction < 0) { |
| 10663 | return offset > 0; |
| 10664 | } else { |
| 10665 | return offset < range - 1; |
| 10666 | } |
| 10667 | } |
| 10668 | |
| 10669 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10670 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 10671 | * scrollbars are painted only if they have been awakened first.</p> |
| 10672 | * |
| 10673 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10674 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10675 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10676 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 10677 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10678 | // scrollbars are drawn only when the animation is running |
| 10679 | final ScrollabilityCache cache = mScrollCache; |
| 10680 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10681 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10682 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10683 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10684 | if (state == ScrollabilityCache.OFF) { |
| 10685 | return; |
| 10686 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10687 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10688 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10689 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10690 | if (state == ScrollabilityCache.FADING) { |
| 10691 | // We're fading -- get our fade interpolation |
| 10692 | if (cache.interpolatorValues == null) { |
| 10693 | cache.interpolatorValues = new float[1]; |
| 10694 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10695 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10696 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10697 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10698 | // Stops the animation if we're done |
| 10699 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 10700 | Interpolator.Result.FREEZE_END) { |
| 10701 | cache.state = ScrollabilityCache.OFF; |
| 10702 | } else { |
| 10703 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 10704 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10705 | |
| 10706 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10707 | // drawing. We only want this when we're fading so that |
| 10708 | // we prevent excessive redraws |
| 10709 | invalidate = true; |
| 10710 | } else { |
| 10711 | // We're just on -- but we may have been fading before so |
| 10712 | // reset alpha |
| 10713 | cache.scrollBar.setAlpha(255); |
| 10714 | } |
| 10715 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10717 | final int viewFlags = mViewFlags; |
| 10718 | |
| 10719 | final boolean drawHorizontalScrollBar = |
| 10720 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10721 | final boolean drawVerticalScrollBar = |
| 10722 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 10723 | && !isVerticalScrollBarHidden(); |
| 10724 | |
| 10725 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 10726 | final int width = mRight - mLeft; |
| 10727 | final int height = mBottom - mTop; |
| 10728 | |
| 10729 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10730 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10731 | final int scrollX = mScrollX; |
| 10732 | final int scrollY = mScrollY; |
| 10733 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 10734 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10735 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10737 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10738 | int size = scrollBar.getSize(false); |
| 10739 | if (size <= 0) { |
| 10740 | size = cache.scrollBarSize; |
| 10741 | } |
| 10742 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10743 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10744 | computeHorizontalScrollOffset(), |
| 10745 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10746 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10747 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10748 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10749 | left = scrollX + (mPaddingLeft & inside); |
| 10750 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 10751 | bottom = top + size; |
| 10752 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10753 | if (invalidate) { |
| 10754 | invalidate(left, top, right, bottom); |
| 10755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10756 | } |
| 10757 | |
| 10758 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 10759 | int size = scrollBar.getSize(true); |
| 10760 | if (size <= 0) { |
| 10761 | size = cache.scrollBarSize; |
| 10762 | } |
| 10763 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10764 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 10765 | computeVerticalScrollOffset(), |
| 10766 | computeVerticalScrollExtent(), true); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10767 | switch (mVerticalScrollbarPosition) { |
| 10768 | default: |
| 10769 | case SCROLLBAR_POSITION_DEFAULT: |
| 10770 | case SCROLLBAR_POSITION_RIGHT: |
| 10771 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 10772 | break; |
| 10773 | case SCROLLBAR_POSITION_LEFT: |
| 10774 | left = scrollX + (mUserPaddingLeft & inside); |
| 10775 | break; |
| 10776 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10777 | top = scrollY + (mPaddingTop & inside); |
| 10778 | right = left + size; |
| 10779 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 10780 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 10781 | if (invalidate) { |
| 10782 | invalidate(left, top, right, bottom); |
| 10783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10784 | } |
| 10785 | } |
| 10786 | } |
| 10787 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10789 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10790 | * Override this if the vertical scrollbar needs to be hidden in a subclass, like when |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10791 | * FastScroller is visible. |
| 10792 | * @return whether to temporarily hide the vertical scrollbar |
| 10793 | * @hide |
| 10794 | */ |
| 10795 | protected boolean isVerticalScrollBarHidden() { |
| 10796 | return false; |
| 10797 | } |
| 10798 | |
| 10799 | /** |
| 10800 | * <p>Draw the horizontal scrollbar if |
| 10801 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 10802 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10803 | * @param canvas the canvas on which to draw the scrollbar |
| 10804 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10805 | * |
| 10806 | * @see #isHorizontalScrollBarEnabled() |
| 10807 | * @see #computeHorizontalScrollRange() |
| 10808 | * @see #computeHorizontalScrollExtent() |
| 10809 | * @see #computeHorizontalScrollOffset() |
| 10810 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10811 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10812 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10813 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10814 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10815 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10816 | scrollBar.draw(canvas); |
| 10817 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10818 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 10819 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10820 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 10821 | * returns true.</p> |
| 10822 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10823 | * @param canvas the canvas on which to draw the scrollbar |
| 10824 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10825 | * |
| 10826 | * @see #isVerticalScrollBarEnabled() |
| 10827 | * @see #computeVerticalScrollRange() |
| 10828 | * @see #computeVerticalScrollExtent() |
| 10829 | * @see #computeVerticalScrollOffset() |
| 10830 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10831 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10832 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 10833 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 10834 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 10835 | scrollBar.setBounds(l, t, r, b); |
| 10836 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10837 | } |
| 10838 | |
| 10839 | /** |
| 10840 | * Implement this to do your drawing. |
| 10841 | * |
| 10842 | * @param canvas the canvas on which the background will be drawn |
| 10843 | */ |
| 10844 | protected void onDraw(Canvas canvas) { |
| 10845 | } |
| 10846 | |
| 10847 | /* |
| 10848 | * Caller is responsible for calling requestLayout if necessary. |
| 10849 | * (This allows addViewInLayout to not request a new layout.) |
| 10850 | */ |
| 10851 | void assignParent(ViewParent parent) { |
| 10852 | if (mParent == null) { |
| 10853 | mParent = parent; |
| 10854 | } else if (parent == null) { |
| 10855 | mParent = null; |
| 10856 | } else { |
| 10857 | throw new RuntimeException("view " + this + " being added, but" |
| 10858 | + " it already has a parent"); |
| 10859 | } |
| 10860 | } |
| 10861 | |
| 10862 | /** |
| 10863 | * This is called when the view is attached to a window. At this point it |
| 10864 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10865 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 10866 | * however it may be called any time before the first onDraw -- including |
| 10867 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10868 | * |
| 10869 | * @see #onDetachedFromWindow() |
| 10870 | */ |
| 10871 | protected void onAttachedToWindow() { |
| 10872 | if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 10873 | mParent.requestTransparentRegion(this); |
| 10874 | } |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10875 | if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
| 10876 | initialAwakenScrollBars(); |
| 10877 | mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH; |
| 10878 | } |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 10879 | jumpDrawablesToCurrentState(); |
Fabrice Di Meglio | a646145 | 2011-08-19 15:42:04 -0700 | [diff] [blame] | 10880 | // Order is important here: LayoutDirection MUST be resolved before Padding |
| 10881 | // and TextDirection |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10882 | resolveLayoutDirection(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10883 | resolvePadding(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 10884 | resolveTextDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 10885 | resolveTextAlignment(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 10886 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 10887 | if (isFocused()) { |
| 10888 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 10889 | imm.focusIn(this); |
| 10890 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10891 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 10892 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10893 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 10894 | * @see #onScreenStateChanged(int) |
| 10895 | */ |
| 10896 | void dispatchScreenStateChanged(int screenState) { |
| 10897 | onScreenStateChanged(screenState); |
| 10898 | } |
| 10899 | |
| 10900 | /** |
| 10901 | * This method is called whenever the state of the screen this view is |
| 10902 | * attached to changes. A state change will usually occurs when the screen |
| 10903 | * turns on or off (whether it happens automatically or the user does it |
| 10904 | * manually.) |
| 10905 | * |
| 10906 | * @param screenState The new state of the screen. Can be either |
| 10907 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 10908 | */ |
| 10909 | public void onScreenStateChanged(int screenState) { |
| 10910 | } |
| 10911 | |
| 10912 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10913 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 10914 | */ |
| 10915 | private boolean hasRtlSupport() { |
| 10916 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 10917 | } |
| 10918 | |
| 10919 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10920 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 10921 | * that the parent directionality can and will be resolved before its children. |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10922 | * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 10923 | * @hide |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 10924 | */ |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10925 | public void resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10926 | // Clear any previous layout direction resolution |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 10927 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10928 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10929 | if (hasRtlSupport()) { |
| 10930 | // Set resolved depending on layout direction |
| 10931 | switch (getLayoutDirection()) { |
| 10932 | case LAYOUT_DIRECTION_INHERIT: |
| 10933 | // If this is root view, no need to look at parent's layout dir. |
| 10934 | if (canResolveLayoutDirection()) { |
| 10935 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10936 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10937 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 10938 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10939 | } |
| 10940 | } else { |
| 10941 | // Nothing to do, LTR by default |
| 10942 | } |
| 10943 | break; |
| 10944 | case LAYOUT_DIRECTION_RTL: |
| 10945 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10946 | break; |
| 10947 | case LAYOUT_DIRECTION_LOCALE: |
| 10948 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 10949 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED_RTL; |
| 10950 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10951 | break; |
| 10952 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 10953 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 10954 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 10955 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10956 | |
| 10957 | // Set to resolved |
| 10958 | mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10959 | onResolvedLayoutDirectionChanged(); |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 10960 | // Resolve padding |
| 10961 | resolvePadding(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10962 | } |
| 10963 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10964 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10965 | * Called when layout direction has been resolved. |
| 10966 | * |
| 10967 | * The default implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 10968 | * @hide |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 10969 | */ |
| 10970 | public void onResolvedLayoutDirectionChanged() { |
| 10971 | } |
| 10972 | |
| 10973 | /** |
| 10974 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 10975 | * @hide |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 10976 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10977 | public void resolvePadding() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10978 | // If the user specified the absolute padding (either with android:padding or |
| 10979 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 10980 | // use the default padding or the padding from the background drawable |
| 10981 | // (stored at this point in mPadding*) |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 10982 | int resolvedLayoutDirection = getResolvedLayoutDirection(); |
| 10983 | switch (resolvedLayoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10984 | case LAYOUT_DIRECTION_RTL: |
| 10985 | // Start user padding override Right user padding. Otherwise, if Right user |
| 10986 | // padding is not defined, use the default Right padding. If Right user padding |
| 10987 | // is defined, just use it. |
| 10988 | if (mUserPaddingStart >= 0) { |
| 10989 | mUserPaddingRight = mUserPaddingStart; |
| 10990 | } else if (mUserPaddingRight < 0) { |
| 10991 | mUserPaddingRight = mPaddingRight; |
| 10992 | } |
| 10993 | if (mUserPaddingEnd >= 0) { |
| 10994 | mUserPaddingLeft = mUserPaddingEnd; |
| 10995 | } else if (mUserPaddingLeft < 0) { |
| 10996 | mUserPaddingLeft = mPaddingLeft; |
| 10997 | } |
| 10998 | break; |
| 10999 | case LAYOUT_DIRECTION_LTR: |
| 11000 | default: |
| 11001 | // Start user padding override Left user padding. Otherwise, if Left user |
| 11002 | // padding is not defined, use the default left padding. If Left user padding |
| 11003 | // is defined, just use it. |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 11004 | if (mUserPaddingStart >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11005 | mUserPaddingLeft = mUserPaddingStart; |
| 11006 | } else if (mUserPaddingLeft < 0) { |
| 11007 | mUserPaddingLeft = mPaddingLeft; |
| 11008 | } |
Fabrice Di Meglio | f3e1a93 | 2011-07-15 17:15:39 -0700 | [diff] [blame] | 11009 | if (mUserPaddingEnd >= 0) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11010 | mUserPaddingRight = mUserPaddingEnd; |
| 11011 | } else if (mUserPaddingRight < 0) { |
| 11012 | mUserPaddingRight = mPaddingRight; |
| 11013 | } |
| 11014 | } |
| 11015 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11016 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11017 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 11018 | if(isPaddingRelative()) { |
| 11019 | setPaddingRelative(mUserPaddingStart, mPaddingTop, mUserPaddingEnd, mUserPaddingBottom); |
| 11020 | } else { |
| 11021 | recomputePadding(); |
| 11022 | } |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11023 | onPaddingChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11024 | } |
| 11025 | |
| 11026 | /** |
| 11027 | * Resolve padding depending on the layout direction. Subclasses that care about |
| 11028 | * padding resolution should override this method. The default implementation does |
| 11029 | * nothing. |
| 11030 | * |
| 11031 | * @param layoutDirection the direction of the layout |
| 11032 | * |
Fabrice Di Meglio | e8dc07d | 2012-03-09 17:10:19 -0800 | [diff] [blame] | 11033 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 11034 | * @see {@link #LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 11035 | * @hide |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11036 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11037 | public void onPaddingChanged(int layoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11038 | } |
| 11039 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11040 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11041 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11042 | * |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11043 | * @return true if layout direction resolution can be done otherwise return false. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 11044 | * @hide |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11045 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11046 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11047 | switch (getLayoutDirection()) { |
| 11048 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11049 | return (mParent != null) && (mParent instanceof ViewGroup); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11050 | default: |
| 11051 | return true; |
| 11052 | } |
| 11053 | } |
| 11054 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11055 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11056 | * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} |
| 11057 | * when reset is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 11058 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11059 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11060 | public void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 11061 | // Reset the current resolved bits |
| 11062 | mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11063 | onResolvedLayoutDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 11064 | // Reset also the text direction |
| 11065 | resetResolvedTextDirection(); |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11066 | } |
| 11067 | |
| 11068 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11069 | * Called during reset of resolved layout direction. |
| 11070 | * |
| 11071 | * Subclasses need to override this method to clear cached information that depends on the |
| 11072 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 11073 | * |
| 11074 | * The default implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 11075 | * @hide |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11076 | */ |
| 11077 | public void onResolvedLayoutDirectionReset() { |
| 11078 | } |
| 11079 | |
| 11080 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11081 | * Check if a Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11082 | * |
| 11083 | * @param locale Locale to check |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11084 | * @return true if the Locale uses an RTL script. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 11085 | * @hide |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11086 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 11087 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 11088 | return (LAYOUT_DIRECTION_RTL == LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11089 | } |
| 11090 | |
| 11091 | /** |
| 11092 | * This is called when the view is detached from a window. At this point it |
| 11093 | * no longer has a surface for drawing. |
| 11094 | * |
| 11095 | * @see #onAttachedToWindow() |
| 11096 | */ |
| 11097 | protected void onDetachedFromWindow() { |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 11098 | mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11099 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11100 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11101 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11102 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11103 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11105 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11106 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11107 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11108 | |
| 11109 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11110 | if (mDisplayList != null) { |
| 11111 | mAttachInfo.mViewRootImpl.invalidateDisplayList(mDisplayList); |
| 11112 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11113 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11114 | } else { |
| 11115 | if (mDisplayList != null) { |
| 11116 | // Should never happen |
| 11117 | mDisplayList.invalidate(); |
| 11118 | } |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11119 | } |
| 11120 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11121 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11122 | |
| 11123 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 11124 | resetResolvedTextAlignment(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11125 | resetAccessibilityStateChanged(); |
| 11126 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11127 | } |
| 11128 | |
| 11129 | /** |
| 11130 | * @return The number of times this view has been attached to a window |
| 11131 | */ |
| 11132 | protected int getWindowAttachCount() { |
| 11133 | return mWindowAttachCount; |
| 11134 | } |
| 11135 | |
| 11136 | /** |
| 11137 | * Retrieve a unique token identifying the window this view is attached to. |
| 11138 | * @return Return the window's token for use in |
| 11139 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11140 | */ |
| 11141 | public IBinder getWindowToken() { |
| 11142 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11143 | } |
| 11144 | |
| 11145 | /** |
| 11146 | * Retrieve a unique token identifying the top-level "real" window of |
| 11147 | * the window that this view is attached to. That is, this is like |
| 11148 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11149 | * window (attached to another containing window), then the token of |
| 11150 | * the containing window is returned instead. |
| 11151 | * |
| 11152 | * @return Returns the associated window token, either |
| 11153 | * {@link #getWindowToken()} or the containing window's token. |
| 11154 | */ |
| 11155 | public IBinder getApplicationWindowToken() { |
| 11156 | AttachInfo ai = mAttachInfo; |
| 11157 | if (ai != null) { |
| 11158 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11159 | if (appWindowToken == null) { |
| 11160 | appWindowToken = ai.mWindowToken; |
| 11161 | } |
| 11162 | return appWindowToken; |
| 11163 | } |
| 11164 | return null; |
| 11165 | } |
| 11166 | |
| 11167 | /** |
| 11168 | * Retrieve private session object this view hierarchy is using to |
| 11169 | * communicate with the window manager. |
| 11170 | * @return the session object to communicate with the window manager |
| 11171 | */ |
| 11172 | /*package*/ IWindowSession getWindowSession() { |
| 11173 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11174 | } |
| 11175 | |
| 11176 | /** |
| 11177 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11178 | * this view |
| 11179 | */ |
| 11180 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 11181 | //System.out.println("Attached! " + this); |
| 11182 | mAttachInfo = info; |
| 11183 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11184 | // We will need to evaluate the drawable state at least once. |
| 11185 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11186 | if (mFloatingTreeObserver != null) { |
| 11187 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 11188 | mFloatingTreeObserver = null; |
| 11189 | } |
| 11190 | if ((mPrivateFlags&SCROLL_CONTAINER) != 0) { |
| 11191 | mAttachInfo.mScrollContainers.add(this); |
| 11192 | mPrivateFlags |= SCROLL_CONTAINER_ADDED; |
| 11193 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 11194 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11195 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11196 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11197 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11198 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11199 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11200 | if (listeners != null && listeners.size() > 0) { |
| 11201 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11202 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11203 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11204 | // the array from being modified while we iterate it. |
| 11205 | for (OnAttachStateChangeListener listener : listeners) { |
| 11206 | listener.onViewAttachedToWindow(this); |
| 11207 | } |
| 11208 | } |
| 11209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11210 | int vis = info.mWindowVisibility; |
| 11211 | if (vis != GONE) { |
| 11212 | onWindowVisibilityChanged(vis); |
| 11213 | } |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11214 | if ((mPrivateFlags&DRAWABLE_STATE_DIRTY) != 0) { |
| 11215 | // If nobody has evaluated the drawable state yet, then do it now. |
| 11216 | refreshDrawableState(); |
| 11217 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11218 | } |
| 11219 | |
| 11220 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11221 | AttachInfo info = mAttachInfo; |
| 11222 | if (info != null) { |
| 11223 | int vis = info.mWindowVisibility; |
| 11224 | if (vis != GONE) { |
| 11225 | onWindowVisibilityChanged(GONE); |
| 11226 | } |
| 11227 | } |
| 11228 | |
| 11229 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11230 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11231 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11232 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11233 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11234 | if (listeners != null && listeners.size() > 0) { |
| 11235 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11236 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11237 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11238 | // the array from being modified while we iterate it. |
| 11239 | for (OnAttachStateChangeListener listener : listeners) { |
| 11240 | listener.onViewDetachedFromWindow(this); |
| 11241 | } |
| 11242 | } |
| 11243 | |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11244 | if ((mPrivateFlags & SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11245 | mAttachInfo.mScrollContainers.remove(this); |
| 11246 | mPrivateFlags &= ~SCROLL_CONTAINER_ADDED; |
| 11247 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11249 | mAttachInfo = null; |
| 11250 | } |
| 11251 | |
| 11252 | /** |
| 11253 | * Store this view hierarchy's frozen state into the given container. |
| 11254 | * |
| 11255 | * @param container The SparseArray in which to save the view's state. |
| 11256 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11257 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11258 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11259 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11260 | */ |
| 11261 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 11262 | dispatchSaveInstanceState(container); |
| 11263 | } |
| 11264 | |
| 11265 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11266 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 11267 | * this view and its children. May be overridden to modify how freezing happens to a |
| 11268 | * view's children; for example, some views may want to not store state for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11269 | * |
| 11270 | * @param container The SparseArray in which to save the view's state. |
| 11271 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11272 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11273 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11274 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11275 | */ |
| 11276 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 11277 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
| 11278 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 11279 | Parcelable state = onSaveInstanceState(); |
| 11280 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 11281 | throw new IllegalStateException( |
| 11282 | "Derived class did not call super.onSaveInstanceState()"); |
| 11283 | } |
| 11284 | if (state != null) { |
| 11285 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 11286 | // + ": " + state); |
| 11287 | container.put(mID, state); |
| 11288 | } |
| 11289 | } |
| 11290 | } |
| 11291 | |
| 11292 | /** |
| 11293 | * Hook allowing a view to generate a representation of its internal state |
| 11294 | * that can later be used to create a new instance with that same state. |
| 11295 | * This state should only contain information that is not persistent or can |
| 11296 | * not be reconstructed later. For example, you will never store your |
| 11297 | * current position on screen because that will be computed again when a |
| 11298 | * new instance of the view is placed in its view hierarchy. |
| 11299 | * <p> |
| 11300 | * Some examples of things you may store here: the current cursor position |
| 11301 | * in a text view (but usually not the text itself since that is stored in a |
| 11302 | * content provider or other persistent storage), the currently selected |
| 11303 | * item in a list view. |
| 11304 | * |
| 11305 | * @return Returns a Parcelable object containing the view's current dynamic |
| 11306 | * state, or null if there is nothing interesting to save. The |
| 11307 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11308 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 11309 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11310 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11311 | * @see #setSaveEnabled(boolean) |
| 11312 | */ |
| 11313 | protected Parcelable onSaveInstanceState() { |
| 11314 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 11315 | return BaseSavedState.EMPTY_STATE; |
| 11316 | } |
| 11317 | |
| 11318 | /** |
| 11319 | * Restore this view hierarchy's frozen state from the given container. |
| 11320 | * |
| 11321 | * @param container The SparseArray which holds previously frozen states. |
| 11322 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11323 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11324 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11325 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11326 | */ |
| 11327 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 11328 | dispatchRestoreInstanceState(container); |
| 11329 | } |
| 11330 | |
| 11331 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11332 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 11333 | * state for this view and its children. May be overridden to modify how restoring |
| 11334 | * happens to a view's children; for example, some views may want to not store state |
| 11335 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11336 | * |
| 11337 | * @param container The SparseArray which holds previously saved state. |
| 11338 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11339 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11340 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11341 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11342 | */ |
| 11343 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 11344 | if (mID != NO_ID) { |
| 11345 | Parcelable state = container.get(mID); |
| 11346 | if (state != null) { |
| 11347 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 11348 | // + ": " + state); |
| 11349 | mPrivateFlags &= ~SAVE_STATE_CALLED; |
| 11350 | onRestoreInstanceState(state); |
| 11351 | if ((mPrivateFlags & SAVE_STATE_CALLED) == 0) { |
| 11352 | throw new IllegalStateException( |
| 11353 | "Derived class did not call super.onRestoreInstanceState()"); |
| 11354 | } |
| 11355 | } |
| 11356 | } |
| 11357 | } |
| 11358 | |
| 11359 | /** |
| 11360 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 11361 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 11362 | * null state. |
| 11363 | * |
| 11364 | * @param state The frozen state that had previously been returned by |
| 11365 | * {@link #onSaveInstanceState}. |
| 11366 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11367 | * @see #onSaveInstanceState() |
| 11368 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11369 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11370 | */ |
| 11371 | protected void onRestoreInstanceState(Parcelable state) { |
| 11372 | mPrivateFlags |= SAVE_STATE_CALLED; |
| 11373 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11374 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 11375 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11376 | + "when two views of different type have the same id in the same hierarchy. " |
| 11377 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11378 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11379 | } |
| 11380 | } |
| 11381 | |
| 11382 | /** |
| 11383 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 11384 | * |
| 11385 | * @return the drawing start time in milliseconds |
| 11386 | */ |
| 11387 | public long getDrawingTime() { |
| 11388 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 11389 | } |
| 11390 | |
| 11391 | /** |
| 11392 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 11393 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 11394 | * than from its own internal properties.</p> |
| 11395 | * |
| 11396 | * <p>Note: in the current implementation, setting this property to true after the |
| 11397 | * view was added to a ViewGroup might have no effect at all. This property should |
| 11398 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 11399 | * |
| 11400 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 11401 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11402 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 11403 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 11404 | * parent, these states should not be affected by this method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11405 | * |
| 11406 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 11407 | * to disable it. |
| 11408 | * |
| 11409 | * @see #getDrawableState() |
| 11410 | * @see #isDuplicateParentStateEnabled() |
| 11411 | */ |
| 11412 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 11413 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 11414 | } |
| 11415 | |
| 11416 | /** |
| 11417 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 11418 | * |
| 11419 | * @return True if this view's drawable state is duplicated from the parent, |
| 11420 | * false otherwise |
| 11421 | * |
| 11422 | * @see #getDrawableState() |
| 11423 | * @see #setDuplicateParentStateEnabled(boolean) |
| 11424 | */ |
| 11425 | public boolean isDuplicateParentStateEnabled() { |
| 11426 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 11427 | } |
| 11428 | |
| 11429 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11430 | * <p>Specifies the type of layer backing this view. The layer can be |
| 11431 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 11432 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11433 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11434 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 11435 | * instance that controls how the layer is composed on screen. The following |
| 11436 | * properties of the paint are taken into account when composing the layer:</p> |
| 11437 | * <ul> |
| 11438 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 11439 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 11440 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 11441 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11442 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11443 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 11444 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 11445 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 11446 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 11447 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11448 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11449 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 11450 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 11451 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11452 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11453 | * @param layerType The ype of layer to use with this view, must be one of |
| 11454 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 11455 | * {@link #LAYER_TYPE_HARDWARE} |
| 11456 | * @param paint The paint used to compose the layer. This argument is optional |
| 11457 | * and can be null. It is ignored when the layer type is |
| 11458 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11459 | * |
| 11460 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11461 | * @see #LAYER_TYPE_NONE |
| 11462 | * @see #LAYER_TYPE_SOFTWARE |
| 11463 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11464 | * @see #setAlpha(float) |
| 11465 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11466 | * @attr ref android.R.styleable#View_layerType |
| 11467 | */ |
| 11468 | public void setLayerType(int layerType, Paint paint) { |
| 11469 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11470 | throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, " |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11471 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 11472 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11473 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11474 | if (layerType == mLayerType) { |
| 11475 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 11476 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11477 | invalidateParentCaches(); |
| 11478 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11479 | } |
| 11480 | return; |
| 11481 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11482 | |
| 11483 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11484 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 11485 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11486 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11487 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11488 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11489 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11490 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11491 | default: |
| 11492 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11493 | } |
| 11494 | |
| 11495 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 11496 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 11497 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 11498 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11499 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11500 | invalidateParentCaches(); |
| 11501 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11502 | } |
| 11503 | |
| 11504 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11505 | * Indicates whether this view has a static layer. A view with layer type |
| 11506 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 11507 | * dynamic. |
| 11508 | */ |
| 11509 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 11510 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11511 | } |
| 11512 | |
| 11513 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11514 | * Indicates what type of layer is currently associated with this view. By default |
| 11515 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 11516 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 11517 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11518 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11519 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 11520 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11521 | * |
| 11522 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11523 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11524 | * @see #LAYER_TYPE_NONE |
| 11525 | * @see #LAYER_TYPE_SOFTWARE |
| 11526 | * @see #LAYER_TYPE_HARDWARE |
| 11527 | */ |
| 11528 | public int getLayerType() { |
| 11529 | return mLayerType; |
| 11530 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11531 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11532 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11533 | * Forces this view's layer to be created and this view to be rendered |
| 11534 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 11535 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11536 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11537 | * This method can for instance be used to render a view into its layer before |
| 11538 | * starting an animation. If this view is complex, rendering into the layer |
| 11539 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11540 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11541 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11542 | * |
| 11543 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11544 | */ |
| 11545 | public void buildLayer() { |
| 11546 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 11547 | |
| 11548 | if (mAttachInfo == null) { |
| 11549 | throw new IllegalStateException("This view must be attached to a window first"); |
| 11550 | } |
| 11551 | |
| 11552 | switch (mLayerType) { |
| 11553 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 11554 | if (mAttachInfo.mHardwareRenderer != null && |
| 11555 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 11556 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11557 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 11558 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11559 | break; |
| 11560 | case LAYER_TYPE_SOFTWARE: |
| 11561 | buildDrawingCache(true); |
| 11562 | break; |
| 11563 | } |
| 11564 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11565 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11566 | // Make sure the HardwareRenderer.validate() was invoked before calling this method |
| 11567 | void flushLayer() { |
| 11568 | if (mLayerType == LAYER_TYPE_HARDWARE && mHardwareLayer != null) { |
| 11569 | mHardwareLayer.flush(); |
| 11570 | } |
| 11571 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 11572 | |
| 11573 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11574 | * <p>Returns a hardware layer that can be used to draw this view again |
| 11575 | * without executing its draw method.</p> |
| 11576 | * |
| 11577 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 11578 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11579 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 11580 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 11581 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11582 | return null; |
| 11583 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11584 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11585 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11586 | |
| 11587 | final int width = mRight - mLeft; |
| 11588 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11589 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11590 | if (width == 0 || height == 0) { |
| 11591 | return null; |
| 11592 | } |
| 11593 | |
| 11594 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
| 11595 | if (mHardwareLayer == null) { |
| 11596 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 11597 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 11598 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11599 | } else if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 11600 | mHardwareLayer.resize(width, height); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 11601 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11602 | } |
| 11603 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 11604 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 11605 | if (!mHardwareLayer.isValid()) { |
| 11606 | return null; |
| 11607 | } |
| 11608 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11609 | mHardwareLayer.redraw(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 11610 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11611 | } |
| 11612 | |
| 11613 | return mHardwareLayer; |
| 11614 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11615 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11616 | /** |
| 11617 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11618 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11619 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11620 | * |
| 11621 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 11622 | * @see #LAYER_TYPE_HARDWARE |
| 11623 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11624 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11625 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11626 | AttachInfo info = mAttachInfo; |
| 11627 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11628 | info.mHardwareRenderer.isEnabled() && |
| 11629 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11630 | mHardwareLayer.destroy(); |
| 11631 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11632 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 11633 | invalidate(true); |
| 11634 | invalidateParentCaches(); |
| 11635 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 11636 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11637 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 11638 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11639 | } |
| 11640 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11641 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11642 | * Destroys all hardware rendering resources. This method is invoked |
| 11643 | * when the system needs to reclaim resources. Upon execution of this |
| 11644 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11645 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11646 | * Note: you <strong>must</strong> call |
| 11647 | * <code>super.destroyHardwareResources()</code> when overriding |
| 11648 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11649 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11650 | * @hide |
| 11651 | */ |
| 11652 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11653 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11654 | } |
| 11655 | |
| 11656 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11657 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 11658 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 11659 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 11660 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 11661 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 11662 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11663 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11664 | * <p>Enabling the drawing cache is similar to |
| 11665 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11666 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 11667 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 11668 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 11669 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 11670 | * for information on how to enable software and hardware layers.</p> |
| 11671 | * |
| 11672 | * <p>This API can be used to manually generate |
| 11673 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 11674 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11675 | * |
| 11676 | * @param enabled true to enable the drawing cache, false otherwise |
| 11677 | * |
| 11678 | * @see #isDrawingCacheEnabled() |
| 11679 | * @see #getDrawingCache() |
| 11680 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11681 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11682 | */ |
| 11683 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 11684 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11685 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 11686 | } |
| 11687 | |
| 11688 | /** |
| 11689 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 11690 | * |
| 11691 | * @return true if the drawing cache is enabled |
| 11692 | * |
| 11693 | * @see #setDrawingCacheEnabled(boolean) |
| 11694 | * @see #getDrawingCache() |
| 11695 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 11696 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11697 | public boolean isDrawingCacheEnabled() { |
| 11698 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 11699 | } |
| 11700 | |
| 11701 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11702 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 11703 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11704 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11705 | * @hide |
| 11706 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11707 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11708 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
| 11709 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.DIRTY_MASK) + |
| 11710 | ") DRAWN(" + (mPrivateFlags & DRAWN) + ")" + " CACHE_VALID(" + |
| 11711 | (mPrivateFlags & View.DRAWING_CACHE_VALID) + |
| 11712 | ") INVALIDATED(" + (mPrivateFlags & INVALIDATED) + ")"); |
| 11713 | if (clear) { |
| 11714 | mPrivateFlags &= clearMask; |
| 11715 | } |
| 11716 | if (this instanceof ViewGroup) { |
| 11717 | ViewGroup parent = (ViewGroup) this; |
| 11718 | final int count = parent.getChildCount(); |
| 11719 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 11720 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11721 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 11722 | } |
| 11723 | } |
| 11724 | } |
| 11725 | |
| 11726 | /** |
| 11727 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 11728 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 11729 | * to recreate its own display list, which would happen if it went through the normal |
| 11730 | * draw/dispatchDraw mechanisms. |
| 11731 | * |
| 11732 | * @hide |
| 11733 | */ |
| 11734 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11735 | |
| 11736 | /** |
| 11737 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 11738 | * This method checks these conditions and returns the appropriate result. |
| 11739 | * |
| 11740 | * @return true if view has the ability to create a display list, false otherwise. |
| 11741 | * |
| 11742 | * @hide |
| 11743 | */ |
| 11744 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 11745 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 11746 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11747 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11748 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 11749 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 11750 | * is not supported or this this has not been attached to a window. |
| 11751 | * |
| 11752 | * @hide |
| 11753 | */ |
| 11754 | public HardwareRenderer getHardwareRenderer() { |
| 11755 | if (mAttachInfo != null) { |
| 11756 | return mAttachInfo.mHardwareRenderer; |
| 11757 | } |
| 11758 | return null; |
| 11759 | } |
| 11760 | |
| 11761 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11762 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 11763 | * Otherwise, the same display list will be returned (after having been rendered into |
| 11764 | * along the way, depending on the invalidation state of the view). |
| 11765 | * |
| 11766 | * @param displayList The previous version of this displayList, could be null. |
| 11767 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 11768 | * the view will avoid creating a layer inside the resulting display list. |
| 11769 | * @return A new or reused DisplayList object. |
| 11770 | */ |
| 11771 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 11772 | if (!canHaveDisplayList()) { |
| 11773 | return null; |
| 11774 | } |
| 11775 | |
| 11776 | if (((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || |
| 11777 | displayList == null || !displayList.isValid() || |
| 11778 | (!isLayer && mRecreateDisplayList))) { |
| 11779 | // Don't need to recreate the display list, just need to tell our |
| 11780 | // children to restore/recreate theirs |
| 11781 | if (displayList != null && displayList.isValid() && |
| 11782 | !isLayer && !mRecreateDisplayList) { |
| 11783 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11784 | mPrivateFlags &= ~DIRTY_MASK; |
| 11785 | dispatchGetDisplayList(); |
| 11786 | |
| 11787 | return displayList; |
| 11788 | } |
| 11789 | |
| 11790 | if (!isLayer) { |
| 11791 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 11792 | // we copy in child display lists into ours in drawChild() |
| 11793 | mRecreateDisplayList = true; |
| 11794 | } |
| 11795 | if (displayList == null) { |
| 11796 | final String name = getClass().getSimpleName(); |
| 11797 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 11798 | // If we're creating a new display list, make sure our parent gets invalidated |
| 11799 | // since they will need to recreate their display list to account for this |
| 11800 | // new child display list. |
| 11801 | invalidateParentCaches(); |
| 11802 | } |
| 11803 | |
| 11804 | boolean caching = false; |
| 11805 | final HardwareCanvas canvas = displayList.start(); |
| 11806 | int restoreCount = 0; |
| 11807 | int width = mRight - mLeft; |
| 11808 | int height = mBottom - mTop; |
| 11809 | |
| 11810 | try { |
| 11811 | canvas.setViewport(width, height); |
| 11812 | // The dirty rect should always be null for a display list |
| 11813 | canvas.onPreDraw(null); |
| 11814 | int layerType = ( |
| 11815 | !(mParent instanceof ViewGroup) || ((ViewGroup)mParent).mDrawLayers) ? |
| 11816 | getLayerType() : LAYER_TYPE_NONE; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 11817 | if (!isLayer && layerType != LAYER_TYPE_NONE) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11818 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 11819 | final HardwareLayer layer = getHardwareLayer(); |
| 11820 | if (layer != null && layer.isValid()) { |
| 11821 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 11822 | } else { |
| 11823 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 11824 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 11825 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 11826 | } |
| 11827 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11828 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 11829 | buildDrawingCache(true); |
| 11830 | Bitmap cache = getDrawingCache(true); |
| 11831 | if (cache != null) { |
| 11832 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 11833 | caching = true; |
| 11834 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11835 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11836 | } else { |
| 11837 | |
| 11838 | computeScroll(); |
| 11839 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11840 | canvas.translate(-mScrollX, -mScrollY); |
| 11841 | if (!isLayer) { |
| 11842 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11843 | mPrivateFlags &= ~DIRTY_MASK; |
| 11844 | } |
| 11845 | |
| 11846 | // Fast path for layouts with no backgrounds |
| 11847 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 11848 | dispatchDraw(canvas); |
| 11849 | } else { |
| 11850 | draw(canvas); |
| 11851 | } |
| 11852 | } |
| 11853 | } finally { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11854 | canvas.onPostDraw(); |
| 11855 | |
| 11856 | displayList.end(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 11857 | displayList.setCaching(caching); |
| 11858 | if (isLayer) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11859 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 11860 | } else { |
| 11861 | setDisplayListProperties(displayList); |
| 11862 | } |
| 11863 | } |
| 11864 | } else if (!isLayer) { |
| 11865 | mPrivateFlags |= DRAWN | DRAWING_CACHE_VALID; |
| 11866 | mPrivateFlags &= ~DIRTY_MASK; |
| 11867 | } |
| 11868 | |
| 11869 | return displayList; |
| 11870 | } |
| 11871 | |
| 11872 | /** |
| 11873 | * Get the DisplayList for the HardwareLayer |
| 11874 | * |
| 11875 | * @param layer The HardwareLayer whose DisplayList we want |
| 11876 | * @return A DisplayList fopr the specified HardwareLayer |
| 11877 | */ |
| 11878 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 11879 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 11880 | layer.setDisplayList(displayList); |
| 11881 | return displayList; |
| 11882 | } |
| 11883 | |
| 11884 | |
| 11885 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11886 | * <p>Returns a display list that can be used to draw this view again |
| 11887 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11888 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11889 | * @return A DisplayList ready to replay, or null if caching is not enabled. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11890 | * |
| 11891 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11892 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11893 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 11894 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 11895 | return mDisplayList; |
| 11896 | } |
| 11897 | |
| 11898 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11899 | * <p>Calling this method is equivalent to calling <code>getDrawingCache(false)</code>.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11900 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11901 | * @return A non-scaled bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11902 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11903 | * @see #getDrawingCache(boolean) |
| 11904 | */ |
| 11905 | public Bitmap getDrawingCache() { |
| 11906 | return getDrawingCache(false); |
| 11907 | } |
| 11908 | |
| 11909 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11910 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 11911 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 11912 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 11913 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 11914 | * request the drawing cache by calling this method and draw it on screen if the |
| 11915 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11916 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11917 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 11918 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 11919 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 11920 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 11921 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 11922 | * size than the view. This implies that your application must be able to handle this |
| 11923 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11924 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11925 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 11926 | * the current density of the screen when the application is in compatibility |
| 11927 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11928 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11929 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11930 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11931 | * @see #setDrawingCacheEnabled(boolean) |
| 11932 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11933 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11934 | * @see #destroyDrawingCache() |
| 11935 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11936 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11937 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 11938 | return null; |
| 11939 | } |
| 11940 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11941 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11942 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11943 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11944 | } |
| 11945 | |
| 11946 | /** |
| 11947 | * <p>Frees the resources used by the drawing cache. If you call |
| 11948 | * {@link #buildDrawingCache()} manually without calling |
| 11949 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 11950 | * should cleanup the cache with this method afterwards.</p> |
| 11951 | * |
| 11952 | * @see #setDrawingCacheEnabled(boolean) |
| 11953 | * @see #buildDrawingCache() |
| 11954 | * @see #getDrawingCache() |
| 11955 | */ |
| 11956 | public void destroyDrawingCache() { |
| 11957 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11958 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11959 | mDrawingCache = null; |
| 11960 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11961 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 11962 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11963 | mUnscaledDrawingCache = null; |
| 11964 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11965 | } |
| 11966 | |
| 11967 | /** |
| 11968 | * Setting a solid background color for the drawing cache's bitmaps will improve |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 11969 | * performance and memory usage. Note, though that this should only be used if this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11970 | * view will always be drawn on top of a solid color. |
| 11971 | * |
| 11972 | * @param color The background color to use for the drawing cache's bitmap |
| 11973 | * |
| 11974 | * @see #setDrawingCacheEnabled(boolean) |
| 11975 | * @see #buildDrawingCache() |
| 11976 | * @see #getDrawingCache() |
| 11977 | */ |
| 11978 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 11979 | if (color != mDrawingCacheBackgroundColor) { |
| 11980 | mDrawingCacheBackgroundColor = color; |
| 11981 | mPrivateFlags &= ~DRAWING_CACHE_VALID; |
| 11982 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11983 | } |
| 11984 | |
| 11985 | /** |
| 11986 | * @see #setDrawingCacheBackgroundColor(int) |
| 11987 | * |
| 11988 | * @return The background color to used for the drawing cache's bitmap |
| 11989 | */ |
| 11990 | public int getDrawingCacheBackgroundColor() { |
| 11991 | return mDrawingCacheBackgroundColor; |
| 11992 | } |
| 11993 | |
| 11994 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11995 | * <p>Calling this method is equivalent to calling <code>buildDrawingCache(false)</code>.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11996 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 11997 | * @see #buildDrawingCache(boolean) |
| 11998 | */ |
| 11999 | public void buildDrawingCache() { |
| 12000 | buildDrawingCache(false); |
| 12001 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 12002 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12003 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12004 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 12005 | * |
| 12006 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 12007 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12008 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12009 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12010 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12011 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12012 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12013 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12014 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12015 | * size than the view. This implies that your application must be able to handle this |
| 12016 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12017 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12018 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 12019 | * you do not need the drawing cache bitmap, calling this method will increase memory |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12020 | * usage and cause the view to be rendered in software once, thus negatively impacting |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12021 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12022 | * |
| 12023 | * @see #getDrawingCache() |
| 12024 | * @see #destroyDrawingCache() |
| 12025 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12026 | public void buildDrawingCache(boolean autoScale) { |
| 12027 | if ((mPrivateFlags & DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12028 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12029 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12030 | |
| 12031 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12032 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.BUILD_CACHE); |
| 12033 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12034 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12035 | int width = mRight - mLeft; |
| 12036 | int height = mBottom - mTop; |
| 12037 | |
| 12038 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12039 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12040 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12041 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12042 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 12043 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12045 | |
| 12046 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12047 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12048 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12049 | |
| 12050 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12051 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12052 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12053 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 12054 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12055 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12056 | return; |
| 12057 | } |
| 12058 | |
| 12059 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12060 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12061 | |
| 12062 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12063 | Bitmap.Config quality; |
| 12064 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12065 | // Never pick ARGB_4444 because it looks awful |
| 12066 | // Keep the DRAWING_CACHE_QUALITY_LOW flag just in case |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12067 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 12068 | case DRAWING_CACHE_QUALITY_AUTO: |
| 12069 | quality = Bitmap.Config.ARGB_8888; |
| 12070 | break; |
| 12071 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12072 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12073 | break; |
| 12074 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12075 | quality = Bitmap.Config.ARGB_8888; |
| 12076 | break; |
| 12077 | default: |
| 12078 | quality = Bitmap.Config.ARGB_8888; |
| 12079 | break; |
| 12080 | } |
| 12081 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12082 | // Optimization for translucent windows |
| 12083 | // If the window is translucent, use a 32 bits bitmap to benefit from memcpy() |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12084 | quality = use32BitCache ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12085 | } |
| 12086 | |
| 12087 | // Try to cleanup memory |
| 12088 | if (bitmap != null) bitmap.recycle(); |
| 12089 | |
| 12090 | try { |
| 12091 | bitmap = Bitmap.createBitmap(width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12092 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12093 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12094 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12095 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12096 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12097 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12098 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12099 | } catch (OutOfMemoryError e) { |
| 12100 | // If there is not enough memory to create the bitmap cache, just |
| 12101 | // ignore the issue as bitmap caches are not required to draw the |
| 12102 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12103 | if (autoScale) { |
| 12104 | mDrawingCache = null; |
| 12105 | } else { |
| 12106 | mUnscaledDrawingCache = null; |
| 12107 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12108 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12109 | return; |
| 12110 | } |
| 12111 | |
| 12112 | clear = drawingCacheBackgroundColor != 0; |
| 12113 | } |
| 12114 | |
| 12115 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12116 | if (attachInfo != null) { |
| 12117 | canvas = attachInfo.mCanvas; |
| 12118 | if (canvas == null) { |
| 12119 | canvas = new Canvas(); |
| 12120 | } |
| 12121 | canvas.setBitmap(bitmap); |
| 12122 | // Temporarily clobber the cached Canvas in case one of our children |
| 12123 | // is also using a drawing cache. Without this, the children would |
| 12124 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12125 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 12126 | attachInfo.mCanvas = null; |
| 12127 | } else { |
| 12128 | // This case should hopefully never or seldom happen |
| 12129 | canvas = new Canvas(bitmap); |
| 12130 | } |
| 12131 | |
| 12132 | if (clear) { |
| 12133 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 12134 | } |
| 12135 | |
| 12136 | computeScroll(); |
| 12137 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12138 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12139 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12140 | final float scale = attachInfo.mApplicationScale; |
| 12141 | canvas.scale(scale, scale); |
| 12142 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12144 | canvas.translate(-mScrollX, -mScrollY); |
| 12145 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12146 | mPrivateFlags |= DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12147 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 12148 | mLayerType != LAYER_TYPE_NONE) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12149 | mPrivateFlags |= DRAWING_CACHE_VALID; |
| 12150 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12151 | |
| 12152 | // Fast path for layouts with no backgrounds |
| 12153 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12154 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12155 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 12156 | } |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12157 | mPrivateFlags &= ~DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12158 | dispatchDraw(canvas); |
| 12159 | } else { |
| 12160 | draw(canvas); |
| 12161 | } |
| 12162 | |
| 12163 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12164 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12165 | |
| 12166 | if (attachInfo != null) { |
| 12167 | // Restore the cached Canvas for our siblings |
| 12168 | attachInfo.mCanvas = canvas; |
| 12169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12170 | } |
| 12171 | } |
| 12172 | |
| 12173 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12174 | * Create a snapshot of the view into a bitmap. We should probably make |
| 12175 | * some form of this public, but should think about the API. |
| 12176 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 12177 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12178 | int width = mRight - mLeft; |
| 12179 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12180 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12181 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12182 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12183 | width = (int) ((width * scale) + 0.5f); |
| 12184 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12185 | |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12186 | Bitmap bitmap = Bitmap.createBitmap(width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12187 | if (bitmap == null) { |
| 12188 | throw new OutOfMemoryError(); |
| 12189 | } |
| 12190 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 12191 | Resources resources = getResources(); |
| 12192 | if (resources != null) { |
| 12193 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 12194 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12195 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12196 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12197 | if (attachInfo != null) { |
| 12198 | canvas = attachInfo.mCanvas; |
| 12199 | if (canvas == null) { |
| 12200 | canvas = new Canvas(); |
| 12201 | } |
| 12202 | canvas.setBitmap(bitmap); |
| 12203 | // Temporarily clobber the cached Canvas in case one of our children |
| 12204 | // is also using a drawing cache. Without this, the children would |
| 12205 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12206 | // things would happen (invisible views, corrupted drawings, etc.) |
| 12207 | attachInfo.mCanvas = null; |
| 12208 | } else { |
| 12209 | // This case should hopefully never or seldom happen |
| 12210 | canvas = new Canvas(bitmap); |
| 12211 | } |
| 12212 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12213 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12214 | bitmap.eraseColor(backgroundColor); |
| 12215 | } |
| 12216 | |
| 12217 | computeScroll(); |
| 12218 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12219 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12220 | canvas.translate(-mScrollX, -mScrollY); |
| 12221 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12222 | // Temporarily remove the dirty mask |
| 12223 | int flags = mPrivateFlags; |
| 12224 | mPrivateFlags &= ~DIRTY_MASK; |
| 12225 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12226 | // Fast path for layouts with no backgrounds |
| 12227 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12228 | dispatchDraw(canvas); |
| 12229 | } else { |
| 12230 | draw(canvas); |
| 12231 | } |
| 12232 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12233 | mPrivateFlags = flags; |
| 12234 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12235 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12236 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12237 | |
| 12238 | if (attachInfo != null) { |
| 12239 | // Restore the cached Canvas for our siblings |
| 12240 | attachInfo.mCanvas = canvas; |
| 12241 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12242 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12243 | return bitmap; |
| 12244 | } |
| 12245 | |
| 12246 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12247 | * Indicates whether this View is currently in edit mode. A View is usually |
| 12248 | * in edit mode when displayed within a developer tool. For instance, if |
| 12249 | * this View is being drawn by a visual user interface builder, this method |
| 12250 | * should return true. |
| 12251 | * |
| 12252 | * Subclasses should check the return value of this method to provide |
| 12253 | * different behaviors if their normal behavior might interfere with the |
| 12254 | * host environment. For instance: the class spawns a thread in its |
| 12255 | * constructor, the drawing code relies on device-specific features, etc. |
| 12256 | * |
| 12257 | * This method is usually checked in the drawing code of custom widgets. |
| 12258 | * |
| 12259 | * @return True if this View is in edit mode, false otherwise. |
| 12260 | */ |
| 12261 | public boolean isInEditMode() { |
| 12262 | return false; |
| 12263 | } |
| 12264 | |
| 12265 | /** |
| 12266 | * If the View draws content inside its padding and enables fading edges, |
| 12267 | * it needs to support padding offsets. Padding offsets are added to the |
| 12268 | * fading edges to extend the length of the fade so that it covers pixels |
| 12269 | * drawn inside the padding. |
| 12270 | * |
| 12271 | * Subclasses of this class should override this method if they need |
| 12272 | * to draw content inside the padding. |
| 12273 | * |
| 12274 | * @return True if padding offset must be applied, false otherwise. |
| 12275 | * |
| 12276 | * @see #getLeftPaddingOffset() |
| 12277 | * @see #getRightPaddingOffset() |
| 12278 | * @see #getTopPaddingOffset() |
| 12279 | * @see #getBottomPaddingOffset() |
| 12280 | * |
| 12281 | * @since CURRENT |
| 12282 | */ |
| 12283 | protected boolean isPaddingOffsetRequired() { |
| 12284 | return false; |
| 12285 | } |
| 12286 | |
| 12287 | /** |
| 12288 | * Amount by which to extend the left fading region. Called only when |
| 12289 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12290 | * |
| 12291 | * @return The left padding offset in pixels. |
| 12292 | * |
| 12293 | * @see #isPaddingOffsetRequired() |
| 12294 | * |
| 12295 | * @since CURRENT |
| 12296 | */ |
| 12297 | protected int getLeftPaddingOffset() { |
| 12298 | return 0; |
| 12299 | } |
| 12300 | |
| 12301 | /** |
| 12302 | * Amount by which to extend the right fading region. Called only when |
| 12303 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12304 | * |
| 12305 | * @return The right padding offset in pixels. |
| 12306 | * |
| 12307 | * @see #isPaddingOffsetRequired() |
| 12308 | * |
| 12309 | * @since CURRENT |
| 12310 | */ |
| 12311 | protected int getRightPaddingOffset() { |
| 12312 | return 0; |
| 12313 | } |
| 12314 | |
| 12315 | /** |
| 12316 | * Amount by which to extend the top fading region. Called only when |
| 12317 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12318 | * |
| 12319 | * @return The top padding offset in pixels. |
| 12320 | * |
| 12321 | * @see #isPaddingOffsetRequired() |
| 12322 | * |
| 12323 | * @since CURRENT |
| 12324 | */ |
| 12325 | protected int getTopPaddingOffset() { |
| 12326 | return 0; |
| 12327 | } |
| 12328 | |
| 12329 | /** |
| 12330 | * Amount by which to extend the bottom fading region. Called only when |
| 12331 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12332 | * |
| 12333 | * @return The bottom padding offset in pixels. |
| 12334 | * |
| 12335 | * @see #isPaddingOffsetRequired() |
| 12336 | * |
| 12337 | * @since CURRENT |
| 12338 | */ |
| 12339 | protected int getBottomPaddingOffset() { |
| 12340 | return 0; |
| 12341 | } |
| 12342 | |
| 12343 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12344 | * @hide |
| 12345 | * @param offsetRequired |
| 12346 | */ |
| 12347 | protected int getFadeTop(boolean offsetRequired) { |
| 12348 | int top = mPaddingTop; |
| 12349 | if (offsetRequired) top += getTopPaddingOffset(); |
| 12350 | return top; |
| 12351 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12352 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12353 | /** |
| 12354 | * @hide |
| 12355 | * @param offsetRequired |
| 12356 | */ |
| 12357 | protected int getFadeHeight(boolean offsetRequired) { |
| 12358 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12359 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12360 | return mBottom - mTop - mPaddingBottom - padding; |
| 12361 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12362 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12363 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12364 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12365 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12366 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12367 | * <p>Even if this method returns true, it does not mean that every call |
| 12368 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 12369 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12370 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12371 | * window is hardware accelerated, |
| 12372 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 12373 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12374 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12375 | * @return True if the view is attached to a window and the window is |
| 12376 | * hardware accelerated; false in any other case. |
| 12377 | */ |
| 12378 | public boolean isHardwareAccelerated() { |
| 12379 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 12380 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12381 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12382 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12383 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 12384 | * case of an active Animation being run on the view. |
| 12385 | */ |
| 12386 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 12387 | Animation a, boolean scalingRequired) { |
| 12388 | Transformation invalidationTransform; |
| 12389 | final int flags = parent.mGroupFlags; |
| 12390 | final boolean initialized = a.isInitialized(); |
| 12391 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 12392 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12393 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
| 12394 | onAnimationStart(); |
| 12395 | } |
| 12396 | |
| 12397 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 12398 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 12399 | if (parent.mInvalidationTransformation == null) { |
| 12400 | parent.mInvalidationTransformation = new Transformation(); |
| 12401 | } |
| 12402 | invalidationTransform = parent.mInvalidationTransformation; |
| 12403 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 12404 | } else { |
| 12405 | invalidationTransform = parent.mChildTransformation; |
| 12406 | } |
| 12407 | if (more) { |
| 12408 | if (!a.willChangeBounds()) { |
| 12409 | if ((flags & (parent.FLAG_OPTIMIZE_INVALIDATE | parent.FLAG_ANIMATION_DONE)) == |
| 12410 | parent.FLAG_OPTIMIZE_INVALIDATE) { |
| 12411 | parent.mGroupFlags |= parent.FLAG_INVALIDATE_REQUIRED; |
| 12412 | } else if ((flags & parent.FLAG_INVALIDATE_REQUIRED) == 0) { |
| 12413 | // The child need to draw an animation, potentially offscreen, so |
| 12414 | // make sure we do not cancel invalidate requests |
| 12415 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 12416 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 12417 | } |
| 12418 | } else { |
| 12419 | if (parent.mInvalidateRegion == null) { |
| 12420 | parent.mInvalidateRegion = new RectF(); |
| 12421 | } |
| 12422 | final RectF region = parent.mInvalidateRegion; |
| 12423 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 12424 | invalidationTransform); |
| 12425 | |
| 12426 | // The child need to draw an animation, potentially offscreen, so |
| 12427 | // make sure we do not cancel invalidate requests |
| 12428 | parent.mPrivateFlags |= DRAW_ANIMATION; |
| 12429 | |
| 12430 | final int left = mLeft + (int) region.left; |
| 12431 | final int top = mTop + (int) region.top; |
| 12432 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 12433 | top + (int) (region.height() + .5f)); |
| 12434 | } |
| 12435 | } |
| 12436 | return more; |
| 12437 | } |
| 12438 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12439 | void setDisplayListProperties() { |
| 12440 | setDisplayListProperties(mDisplayList); |
| 12441 | } |
| 12442 | |
| 12443 | /** |
| 12444 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 12445 | * It sets or resets the current value of all properties on that display list (resetting is |
| 12446 | * necessary when a display list is being re-created, because we need to make sure that |
| 12447 | * previously-set transform values |
| 12448 | */ |
| 12449 | void setDisplayListProperties(DisplayList displayList) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12450 | if (displayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12451 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 12452 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12453 | if (mParent instanceof ViewGroup) { |
| 12454 | displayList.setClipChildren( |
| 12455 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 12456 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12457 | float alpha = 1; |
| 12458 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 12459 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 12460 | ViewGroup parentVG = (ViewGroup) mParent; |
| 12461 | final boolean hasTransform = |
| 12462 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 12463 | if (hasTransform) { |
| 12464 | Transformation transform = parentVG.mChildTransformation; |
| 12465 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 12466 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 12467 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 12468 | alpha = transform.getAlpha(); |
| 12469 | } |
| 12470 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 12471 | displayList.setStaticMatrix(transform.getMatrix()); |
| 12472 | } |
| 12473 | } |
| 12474 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12475 | } |
| 12476 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12477 | alpha *= mTransformationInfo.mAlpha; |
| 12478 | if (alpha < 1) { |
| 12479 | final int multipliedAlpha = (int) (255 * alpha); |
| 12480 | if (onSetAlpha(multipliedAlpha)) { |
| 12481 | alpha = 1; |
| 12482 | } |
| 12483 | } |
| 12484 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12485 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 12486 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 12487 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 12488 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12489 | if (mTransformationInfo.mCamera == null) { |
| 12490 | mTransformationInfo.mCamera = new Camera(); |
| 12491 | mTransformationInfo.matrix3D = new Matrix(); |
| 12492 | } |
| 12493 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12494 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == PIVOT_EXPLICITLY_SET) { |
| 12495 | displayList.setPivotX(getPivotX()); |
| 12496 | displayList.setPivotY(getPivotY()); |
| 12497 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12498 | } else if (alpha < 1) { |
| 12499 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12500 | } |
| 12501 | } |
| 12502 | } |
| 12503 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12504 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12505 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 12506 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 12507 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 12508 | */ |
| 12509 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12510 | boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12511 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12512 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12513 | final int flags = parent.mGroupFlags; |
| 12514 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12515 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12516 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12517 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12518 | } |
| 12519 | |
| 12520 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12521 | boolean concatMatrix = false; |
| 12522 | |
| 12523 | boolean scalingRequired = false; |
| 12524 | boolean caching; |
| 12525 | int layerType = parent.mDrawLayers ? getLayerType() : LAYER_TYPE_NONE; |
| 12526 | |
| 12527 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12528 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 12529 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12530 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12531 | // Auto-scaled apps are not hw-accelerated, no need to set scaling flag on DisplayList |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12532 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 12533 | } else { |
| 12534 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 12535 | } |
| 12536 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12537 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12538 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12539 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12540 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12541 | transformToApply = parent.mChildTransformation; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12542 | } else if (!useDisplayListProperties && |
| 12543 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12544 | final boolean hasTransform = |
| 12545 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12546 | if (hasTransform) { |
| 12547 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 12548 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 12549 | parent.mChildTransformation : null; |
| 12550 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 12551 | } |
| 12552 | } |
| 12553 | |
| 12554 | concatMatrix |= !childHasIdentityMatrix; |
| 12555 | |
| 12556 | // Sets the flag as early as possible to allow draw() implementations |
| 12557 | // to call invalidate() successfully when doing animations |
| 12558 | mPrivateFlags |= DRAWN; |
| 12559 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12560 | if (!concatMatrix && canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12561 | (mPrivateFlags & DRAW_ANIMATION) == 0) { |
| 12562 | return more; |
| 12563 | } |
| 12564 | |
| 12565 | if (hardwareAccelerated) { |
| 12566 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 12567 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
| 12568 | mRecreateDisplayList = (mPrivateFlags & INVALIDATED) == INVALIDATED; |
| 12569 | mPrivateFlags &= ~INVALIDATED; |
| 12570 | } |
| 12571 | |
| 12572 | computeScroll(); |
| 12573 | |
| 12574 | final int sx = mScrollX; |
| 12575 | final int sy = mScrollY; |
| 12576 | |
| 12577 | DisplayList displayList = null; |
| 12578 | Bitmap cache = null; |
| 12579 | boolean hasDisplayList = false; |
| 12580 | if (caching) { |
| 12581 | if (!hardwareAccelerated) { |
| 12582 | if (layerType != LAYER_TYPE_NONE) { |
| 12583 | layerType = LAYER_TYPE_SOFTWARE; |
| 12584 | buildDrawingCache(true); |
| 12585 | } |
| 12586 | cache = getDrawingCache(true); |
| 12587 | } else { |
| 12588 | switch (layerType) { |
| 12589 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12590 | if (useDisplayListProperties) { |
| 12591 | hasDisplayList = canHaveDisplayList(); |
| 12592 | } else { |
| 12593 | buildDrawingCache(true); |
| 12594 | cache = getDrawingCache(true); |
| 12595 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12596 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12597 | case LAYER_TYPE_HARDWARE: |
| 12598 | if (useDisplayListProperties) { |
| 12599 | hasDisplayList = canHaveDisplayList(); |
| 12600 | } |
| 12601 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12602 | case LAYER_TYPE_NONE: |
| 12603 | // Delay getting the display list until animation-driven alpha values are |
| 12604 | // set up and possibly passed on to the view |
| 12605 | hasDisplayList = canHaveDisplayList(); |
| 12606 | break; |
| 12607 | } |
| 12608 | } |
| 12609 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12610 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12611 | if (useDisplayListProperties) { |
| 12612 | displayList = getDisplayList(); |
| 12613 | if (!displayList.isValid()) { |
| 12614 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 12615 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 12616 | // try to use it again. |
| 12617 | displayList = null; |
| 12618 | hasDisplayList = false; |
| 12619 | useDisplayListProperties = false; |
| 12620 | } |
| 12621 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12622 | |
| 12623 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 12624 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 12625 | layerType != LAYER_TYPE_HARDWARE; |
| 12626 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12627 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 12628 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12629 | restoreTo = canvas.save(); |
| 12630 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12631 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12632 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12633 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12634 | if (!useDisplayListProperties) { |
| 12635 | canvas.translate(mLeft, mTop); |
| 12636 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12637 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12638 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12639 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12640 | restoreTo = canvas.save(); |
| 12641 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12642 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 12643 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 12644 | canvas.scale(scale, scale); |
| 12645 | } |
| 12646 | } |
| 12647 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12648 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12649 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix()) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12650 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 12651 | int transX = 0; |
| 12652 | int transY = 0; |
| 12653 | |
| 12654 | if (offsetForScroll) { |
| 12655 | transX = -sx; |
| 12656 | transY = -sy; |
| 12657 | } |
| 12658 | |
| 12659 | if (transformToApply != null) { |
| 12660 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12661 | if (useDisplayListProperties) { |
| 12662 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 12663 | } else { |
| 12664 | // Undo the scroll translation, apply the transformation matrix, |
| 12665 | // then redo the scroll translate to get the correct result. |
| 12666 | canvas.translate(-transX, -transY); |
| 12667 | canvas.concat(transformToApply.getMatrix()); |
| 12668 | canvas.translate(transX, transY); |
| 12669 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12670 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12671 | } |
| 12672 | |
| 12673 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12674 | if (transformAlpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12675 | alpha *= transformToApply.getAlpha(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12676 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12677 | } |
| 12678 | } |
| 12679 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12680 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12681 | canvas.translate(-transX, -transY); |
| 12682 | canvas.concat(getMatrix()); |
| 12683 | canvas.translate(transX, transY); |
| 12684 | } |
| 12685 | } |
| 12686 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12687 | if (alpha < 1) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12688 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12689 | if (hasNoCache) { |
| 12690 | final int multipliedAlpha = (int) (255 * alpha); |
| 12691 | if (!onSetAlpha(multipliedAlpha)) { |
| 12692 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12693 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12694 | layerType != LAYER_TYPE_NONE) { |
| 12695 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 12696 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12697 | if (useDisplayListProperties) { |
| 12698 | displayList.setAlpha(alpha * getAlpha()); |
| 12699 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 12700 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12701 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12702 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 12703 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12704 | } |
| 12705 | } else { |
| 12706 | // Alpha is handled by the child directly, clobber the layer's alpha |
| 12707 | mPrivateFlags |= ALPHA_SET; |
| 12708 | } |
| 12709 | } |
| 12710 | } |
| 12711 | } else if ((mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12712 | onSetAlpha(255); |
| 12713 | mPrivateFlags &= ~ALPHA_SET; |
| 12714 | } |
| 12715 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12716 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 12717 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12718 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12719 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12720 | } else { |
| 12721 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12722 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12723 | } else { |
| 12724 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 12725 | } |
| 12726 | } |
| 12727 | } |
| 12728 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12729 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12730 | displayList = getDisplayList(); |
| 12731 | if (!displayList.isValid()) { |
| 12732 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 12733 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 12734 | // try to use it again. |
| 12735 | displayList = null; |
| 12736 | hasDisplayList = false; |
| 12737 | } |
| 12738 | } |
| 12739 | |
| 12740 | if (hasNoCache) { |
| 12741 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12742 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12743 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12744 | if (layer != null && layer.isValid()) { |
| 12745 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 12746 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12747 | layerRendered = true; |
| 12748 | } else { |
| 12749 | final int scrollX = hasDisplayList ? 0 : sx; |
| 12750 | final int scrollY = hasDisplayList ? 0 : sy; |
| 12751 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12752 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12753 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12754 | } |
| 12755 | } |
| 12756 | |
| 12757 | if (!layerRendered) { |
| 12758 | if (!hasDisplayList) { |
| 12759 | // Fast path for layouts with no backgrounds |
| 12760 | if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) { |
| 12761 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12762 | ViewDebug.trace(parent, ViewDebug.HierarchyTraceType.DRAW); |
| 12763 | } |
| 12764 | mPrivateFlags &= ~DIRTY_MASK; |
| 12765 | dispatchDraw(canvas); |
| 12766 | } else { |
| 12767 | draw(canvas); |
| 12768 | } |
| 12769 | } else { |
| 12770 | mPrivateFlags &= ~DIRTY_MASK; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12771 | ((HardwareCanvas) canvas).drawDisplayList(displayList, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12772 | } |
| 12773 | } |
| 12774 | } else if (cache != null) { |
| 12775 | mPrivateFlags &= ~DIRTY_MASK; |
| 12776 | Paint cachePaint; |
| 12777 | |
| 12778 | if (layerType == LAYER_TYPE_NONE) { |
| 12779 | cachePaint = parent.mCachePaint; |
| 12780 | if (cachePaint == null) { |
| 12781 | cachePaint = new Paint(); |
| 12782 | cachePaint.setDither(false); |
| 12783 | parent.mCachePaint = cachePaint; |
| 12784 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12785 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12786 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12787 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 12788 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12789 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12790 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12791 | } |
| 12792 | } else { |
| 12793 | cachePaint = mLayerPaint; |
| 12794 | cachePaint.setAlpha((int) (alpha * 255)); |
| 12795 | } |
| 12796 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 12797 | } |
| 12798 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12799 | if (restoreTo >= 0) { |
| 12800 | canvas.restoreToCount(restoreTo); |
| 12801 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12802 | |
| 12803 | if (a != null && !more) { |
| 12804 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 12805 | onSetAlpha(255); |
| 12806 | } |
| 12807 | parent.finishAnimatingView(this, a); |
| 12808 | } |
| 12809 | |
| 12810 | if (more && hardwareAccelerated) { |
| 12811 | // invalidation is the trigger to recreate display lists, so if we're using |
| 12812 | // display lists to render, force an invalidate to allow the animation to |
| 12813 | // continue drawing another frame |
| 12814 | parent.invalidate(true); |
| 12815 | if (a.hasAlpha() && (mPrivateFlags & ALPHA_SET) == ALPHA_SET) { |
| 12816 | // alpha animations should cause the child to recreate its display list |
| 12817 | invalidate(true); |
| 12818 | } |
| 12819 | } |
| 12820 | |
| 12821 | mRecreateDisplayList = false; |
| 12822 | |
| 12823 | return more; |
| 12824 | } |
| 12825 | |
| 12826 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12827 | * Manually render this view (and all of its children) to the given Canvas. |
| 12828 | * The view must have already done a full layout before this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12829 | * called. When implementing a view, implement |
| 12830 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 12831 | * If you do need to override this method, call the superclass version. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12832 | * |
| 12833 | * @param canvas The Canvas to which the View is rendered. |
| 12834 | */ |
| 12835 | public void draw(Canvas canvas) { |
| 12836 | if (ViewDebug.TRACE_HIERARCHY) { |
| 12837 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.DRAW); |
| 12838 | } |
| 12839 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12840 | final int privateFlags = mPrivateFlags; |
| 12841 | final boolean dirtyOpaque = (privateFlags & DIRTY_MASK) == DIRTY_OPAQUE && |
| 12842 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
| 12843 | mPrivateFlags = (privateFlags & ~DIRTY_MASK) | DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12845 | /* |
| 12846 | * Draw traversal performs several drawing steps which must be executed |
| 12847 | * in the appropriate order: |
| 12848 | * |
| 12849 | * 1. Draw the background |
| 12850 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 12851 | * 3. Draw view's content |
| 12852 | * 4. Draw children |
| 12853 | * 5. If necessary, draw the fading edges and restore layers |
| 12854 | * 6. Draw decorations (scrollbars for instance) |
| 12855 | */ |
| 12856 | |
| 12857 | // Step 1, draw the background, if needed |
| 12858 | int saveCount; |
| 12859 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12860 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12861 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12862 | if (background != null) { |
| 12863 | final int scrollX = mScrollX; |
| 12864 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12865 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12866 | if (mBackgroundSizeChanged) { |
| 12867 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 12868 | mBackgroundSizeChanged = false; |
| 12869 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12870 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12871 | if ((scrollX | scrollY) == 0) { |
| 12872 | background.draw(canvas); |
| 12873 | } else { |
| 12874 | canvas.translate(scrollX, scrollY); |
| 12875 | background.draw(canvas); |
| 12876 | canvas.translate(-scrollX, -scrollY); |
| 12877 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12878 | } |
| 12879 | } |
| 12880 | |
| 12881 | // skip step 2 & 5 if possible (common case) |
| 12882 | final int viewFlags = mViewFlags; |
| 12883 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 12884 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 12885 | if (!verticalEdges && !horizontalEdges) { |
| 12886 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12887 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12888 | |
| 12889 | // Step 4, draw the children |
| 12890 | dispatchDraw(canvas); |
| 12891 | |
| 12892 | // Step 6, draw decorations (scrollbars) |
| 12893 | onDrawScrollBars(canvas); |
| 12894 | |
| 12895 | // we're done... |
| 12896 | return; |
| 12897 | } |
| 12898 | |
| 12899 | /* |
| 12900 | * Here we do the full fledged routine... |
| 12901 | * (this is an uncommon case where speed matters less, |
| 12902 | * this is why we repeat some of the tests that have been |
| 12903 | * done above) |
| 12904 | */ |
| 12905 | |
| 12906 | boolean drawTop = false; |
| 12907 | boolean drawBottom = false; |
| 12908 | boolean drawLeft = false; |
| 12909 | boolean drawRight = false; |
| 12910 | |
| 12911 | float topFadeStrength = 0.0f; |
| 12912 | float bottomFadeStrength = 0.0f; |
| 12913 | float leftFadeStrength = 0.0f; |
| 12914 | float rightFadeStrength = 0.0f; |
| 12915 | |
| 12916 | // Step 2, save the canvas' layers |
| 12917 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12918 | |
| 12919 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 12920 | if (offsetRequired) { |
| 12921 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12922 | } |
| 12923 | |
| 12924 | int left = mScrollX + paddingLeft; |
| 12925 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12926 | int top = mScrollY + getFadeTop(offsetRequired); |
| 12927 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12928 | |
| 12929 | if (offsetRequired) { |
| 12930 | right += getRightPaddingOffset(); |
| 12931 | bottom += getBottomPaddingOffset(); |
| 12932 | } |
| 12933 | |
| 12934 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12935 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12936 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12937 | |
| 12938 | // clip the fade length if top and bottom fades overlap |
| 12939 | // overlapping fades produce odd-looking artifacts |
| 12940 | if (verticalEdges && (top + length > bottom - length)) { |
| 12941 | length = (bottom - top) / 2; |
| 12942 | } |
| 12943 | |
| 12944 | // also clip horizontal fades if necessary |
| 12945 | if (horizontalEdges && (left + length > right - length)) { |
| 12946 | length = (right - left) / 2; |
| 12947 | } |
| 12948 | |
| 12949 | if (verticalEdges) { |
| 12950 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12951 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12952 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12953 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12954 | } |
| 12955 | |
| 12956 | if (horizontalEdges) { |
| 12957 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12958 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12959 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 12960 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12961 | } |
| 12962 | |
| 12963 | saveCount = canvas.getSaveCount(); |
| 12964 | |
| 12965 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 12966 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12967 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 12968 | |
| 12969 | if (drawTop) { |
| 12970 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 12971 | } |
| 12972 | |
| 12973 | if (drawBottom) { |
| 12974 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 12975 | } |
| 12976 | |
| 12977 | if (drawLeft) { |
| 12978 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 12979 | } |
| 12980 | |
| 12981 | if (drawRight) { |
| 12982 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 12983 | } |
| 12984 | } else { |
| 12985 | scrollabilityCache.setFadeColor(solidColor); |
| 12986 | } |
| 12987 | |
| 12988 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 12989 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12990 | |
| 12991 | // Step 4, draw the children |
| 12992 | dispatchDraw(canvas); |
| 12993 | |
| 12994 | // Step 5, draw the fade effect and restore layers |
| 12995 | final Paint p = scrollabilityCache.paint; |
| 12996 | final Matrix matrix = scrollabilityCache.matrix; |
| 12997 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12998 | |
| 12999 | if (drawTop) { |
| 13000 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 13001 | matrix.postTranslate(left, top); |
| 13002 | fade.setLocalMatrix(matrix); |
| 13003 | canvas.drawRect(left, top, right, top + length, p); |
| 13004 | } |
| 13005 | |
| 13006 | if (drawBottom) { |
| 13007 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 13008 | matrix.postRotate(180); |
| 13009 | matrix.postTranslate(left, bottom); |
| 13010 | fade.setLocalMatrix(matrix); |
| 13011 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 13012 | } |
| 13013 | |
| 13014 | if (drawLeft) { |
| 13015 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 13016 | matrix.postRotate(-90); |
| 13017 | matrix.postTranslate(left, top); |
| 13018 | fade.setLocalMatrix(matrix); |
| 13019 | canvas.drawRect(left, top, left + length, bottom, p); |
| 13020 | } |
| 13021 | |
| 13022 | if (drawRight) { |
| 13023 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 13024 | matrix.postRotate(90); |
| 13025 | matrix.postTranslate(right, top); |
| 13026 | fade.setLocalMatrix(matrix); |
| 13027 | canvas.drawRect(right - length, top, right, bottom, p); |
| 13028 | } |
| 13029 | |
| 13030 | canvas.restoreToCount(saveCount); |
| 13031 | |
| 13032 | // Step 6, draw decorations (scrollbars) |
| 13033 | onDrawScrollBars(canvas); |
| 13034 | } |
| 13035 | |
| 13036 | /** |
| 13037 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 13038 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 13039 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 13040 | * should be set to 0xFF. |
| 13041 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13042 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 13043 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13044 | * |
| 13045 | * @return The known solid color background for this view, or 0 if the color may vary |
| 13046 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13047 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13048 | public int getSolidColor() { |
| 13049 | return 0; |
| 13050 | } |
| 13051 | |
| 13052 | /** |
| 13053 | * Build a human readable string representation of the specified view flags. |
| 13054 | * |
| 13055 | * @param flags the view flags to convert to a string |
| 13056 | * @return a String representing the supplied flags |
| 13057 | */ |
| 13058 | private static String printFlags(int flags) { |
| 13059 | String output = ""; |
| 13060 | int numFlags = 0; |
| 13061 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 13062 | output += "TAKES_FOCUS"; |
| 13063 | numFlags++; |
| 13064 | } |
| 13065 | |
| 13066 | switch (flags & VISIBILITY_MASK) { |
| 13067 | case INVISIBLE: |
| 13068 | if (numFlags > 0) { |
| 13069 | output += " "; |
| 13070 | } |
| 13071 | output += "INVISIBLE"; |
| 13072 | // USELESS HERE numFlags++; |
| 13073 | break; |
| 13074 | case GONE: |
| 13075 | if (numFlags > 0) { |
| 13076 | output += " "; |
| 13077 | } |
| 13078 | output += "GONE"; |
| 13079 | // USELESS HERE numFlags++; |
| 13080 | break; |
| 13081 | default: |
| 13082 | break; |
| 13083 | } |
| 13084 | return output; |
| 13085 | } |
| 13086 | |
| 13087 | /** |
| 13088 | * Build a human readable string representation of the specified private |
| 13089 | * view flags. |
| 13090 | * |
| 13091 | * @param privateFlags the private view flags to convert to a string |
| 13092 | * @return a String representing the supplied flags |
| 13093 | */ |
| 13094 | private static String printPrivateFlags(int privateFlags) { |
| 13095 | String output = ""; |
| 13096 | int numFlags = 0; |
| 13097 | |
| 13098 | if ((privateFlags & WANTS_FOCUS) == WANTS_FOCUS) { |
| 13099 | output += "WANTS_FOCUS"; |
| 13100 | numFlags++; |
| 13101 | } |
| 13102 | |
| 13103 | if ((privateFlags & FOCUSED) == FOCUSED) { |
| 13104 | if (numFlags > 0) { |
| 13105 | output += " "; |
| 13106 | } |
| 13107 | output += "FOCUSED"; |
| 13108 | numFlags++; |
| 13109 | } |
| 13110 | |
| 13111 | if ((privateFlags & SELECTED) == SELECTED) { |
| 13112 | if (numFlags > 0) { |
| 13113 | output += " "; |
| 13114 | } |
| 13115 | output += "SELECTED"; |
| 13116 | numFlags++; |
| 13117 | } |
| 13118 | |
| 13119 | if ((privateFlags & IS_ROOT_NAMESPACE) == IS_ROOT_NAMESPACE) { |
| 13120 | if (numFlags > 0) { |
| 13121 | output += " "; |
| 13122 | } |
| 13123 | output += "IS_ROOT_NAMESPACE"; |
| 13124 | numFlags++; |
| 13125 | } |
| 13126 | |
| 13127 | if ((privateFlags & HAS_BOUNDS) == HAS_BOUNDS) { |
| 13128 | if (numFlags > 0) { |
| 13129 | output += " "; |
| 13130 | } |
| 13131 | output += "HAS_BOUNDS"; |
| 13132 | numFlags++; |
| 13133 | } |
| 13134 | |
| 13135 | if ((privateFlags & DRAWN) == DRAWN) { |
| 13136 | if (numFlags > 0) { |
| 13137 | output += " "; |
| 13138 | } |
| 13139 | output += "DRAWN"; |
| 13140 | // USELESS HERE numFlags++; |
| 13141 | } |
| 13142 | return output; |
| 13143 | } |
| 13144 | |
| 13145 | /** |
| 13146 | * <p>Indicates whether or not this view's layout will be requested during |
| 13147 | * the next hierarchy layout pass.</p> |
| 13148 | * |
| 13149 | * @return true if the layout will be forced during next layout pass |
| 13150 | */ |
| 13151 | public boolean isLayoutRequested() { |
| 13152 | return (mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT; |
| 13153 | } |
| 13154 | |
| 13155 | /** |
| 13156 | * Assign a size and position to a view and all of its |
| 13157 | * descendants |
| 13158 | * |
| 13159 | * <p>This is the second phase of the layout mechanism. |
| 13160 | * (The first is measuring). In this phase, each parent calls |
| 13161 | * layout on all of its children to position them. |
| 13162 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13163 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13164 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13165 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13166 | * Derived classes with children should override |
| 13167 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13168 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13169 | * |
| 13170 | * @param l Left position, relative to parent |
| 13171 | * @param t Top position, relative to parent |
| 13172 | * @param r Right position, relative to parent |
| 13173 | * @param b Bottom position, relative to parent |
| 13174 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 13175 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13176 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13177 | int oldL = mLeft; |
| 13178 | int oldT = mTop; |
| 13179 | int oldB = mBottom; |
| 13180 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13181 | boolean changed = setFrame(l, t, r, b); |
| 13182 | if (changed || (mPrivateFlags & LAYOUT_REQUIRED) == LAYOUT_REQUIRED) { |
| 13183 | if (ViewDebug.TRACE_HIERARCHY) { |
| 13184 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_LAYOUT); |
| 13185 | } |
| 13186 | |
| 13187 | onLayout(changed, l, t, r, b); |
| 13188 | mPrivateFlags &= ~LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13189 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13190 | ListenerInfo li = mListenerInfo; |
| 13191 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13192 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13193 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13194 | int numListeners = listenersCopy.size(); |
| 13195 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 13196 | listenersCopy.get(i).onLayoutChange(this, l, t, r, b, oldL, oldT, oldR, oldB); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13197 | } |
| 13198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13199 | } |
| 13200 | mPrivateFlags &= ~FORCE_LAYOUT; |
| 13201 | } |
| 13202 | |
| 13203 | /** |
| 13204 | * Called from layout when this view should |
| 13205 | * assign a size and position to each of its children. |
| 13206 | * |
| 13207 | * Derived classes with children should override |
| 13208 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13209 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13210 | * @param changed This is a new size or position for this view |
| 13211 | * @param left Left position, relative to parent |
| 13212 | * @param top Top position, relative to parent |
| 13213 | * @param right Right position, relative to parent |
| 13214 | * @param bottom Bottom position, relative to parent |
| 13215 | */ |
| 13216 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 13217 | } |
| 13218 | |
| 13219 | /** |
| 13220 | * Assign a size and position to this view. |
| 13221 | * |
| 13222 | * This is called from layout. |
| 13223 | * |
| 13224 | * @param left Left position, relative to parent |
| 13225 | * @param top Top position, relative to parent |
| 13226 | * @param right Right position, relative to parent |
| 13227 | * @param bottom Bottom position, relative to parent |
| 13228 | * @return true if the new size and position are different than the |
| 13229 | * previous ones |
| 13230 | * {@hide} |
| 13231 | */ |
| 13232 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 13233 | boolean changed = false; |
| 13234 | |
| 13235 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 13236 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13237 | + right + "," + bottom + ")"); |
| 13238 | } |
| 13239 | |
| 13240 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 13241 | changed = true; |
| 13242 | |
| 13243 | // Remember our drawn bit |
| 13244 | int drawn = mPrivateFlags & DRAWN; |
| 13245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13246 | int oldWidth = mRight - mLeft; |
| 13247 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13248 | int newWidth = right - left; |
| 13249 | int newHeight = bottom - top; |
| 13250 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 13251 | |
| 13252 | // Invalidate our old position |
| 13253 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13254 | |
| 13255 | mLeft = left; |
| 13256 | mTop = top; |
| 13257 | mRight = right; |
| 13258 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13259 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13260 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 13261 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13262 | |
| 13263 | mPrivateFlags |= HAS_BOUNDS; |
| 13264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13265 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13266 | if (sizeChanged) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13267 | if ((mPrivateFlags & PIVOT_EXPLICITLY_SET) == 0) { |
| 13268 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13269 | if (mTransformationInfo != null) { |
| 13270 | mTransformationInfo.mMatrixDirty = true; |
| 13271 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13273 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 13274 | } |
| 13275 | |
| 13276 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 13277 | // If we are visible, force the DRAWN bit to on so that |
| 13278 | // this invalidate will go through (at least to our parent). |
| 13279 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13280 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13281 | // the DRAWN bit. |
| 13282 | mPrivateFlags |= DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13283 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 13284 | // parent display list may need to be recreated based on a change in the bounds |
| 13285 | // of any child |
| 13286 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13287 | } |
| 13288 | |
| 13289 | // Reset drawn bit to original value (invalidate turns it off) |
| 13290 | mPrivateFlags |= drawn; |
| 13291 | |
| 13292 | mBackgroundSizeChanged = true; |
| 13293 | } |
| 13294 | return changed; |
| 13295 | } |
| 13296 | |
| 13297 | /** |
| 13298 | * Finalize inflating a view from XML. This is called as the last phase |
| 13299 | * of inflation, after all child views have been added. |
| 13300 | * |
| 13301 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 13302 | * sure to call the super method, so that we get called. |
| 13303 | */ |
| 13304 | protected void onFinishInflate() { |
| 13305 | } |
| 13306 | |
| 13307 | /** |
| 13308 | * Returns the resources associated with this view. |
| 13309 | * |
| 13310 | * @return Resources object. |
| 13311 | */ |
| 13312 | public Resources getResources() { |
| 13313 | return mResources; |
| 13314 | } |
| 13315 | |
| 13316 | /** |
| 13317 | * Invalidates the specified Drawable. |
| 13318 | * |
| 13319 | * @param drawable the drawable to invalidate |
| 13320 | */ |
| 13321 | public void invalidateDrawable(Drawable drawable) { |
| 13322 | if (verifyDrawable(drawable)) { |
| 13323 | final Rect dirty = drawable.getBounds(); |
| 13324 | final int scrollX = mScrollX; |
| 13325 | final int scrollY = mScrollY; |
| 13326 | |
| 13327 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 13328 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 13329 | } |
| 13330 | } |
| 13331 | |
| 13332 | /** |
| 13333 | * Schedules an action on a drawable to occur at a specified time. |
| 13334 | * |
| 13335 | * @param who the recipient of the action |
| 13336 | * @param what the action to run on the drawable |
| 13337 | * @param when the time at which the action must occur. Uses the |
| 13338 | * {@link SystemClock#uptimeMillis} timebase. |
| 13339 | */ |
| 13340 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13341 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13342 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13343 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13344 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 13345 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 13346 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13347 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13348 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13349 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13350 | } |
| 13351 | } |
| 13352 | |
| 13353 | /** |
| 13354 | * Cancels a scheduled action on a drawable. |
| 13355 | * |
| 13356 | * @param who the recipient of the action |
| 13357 | * @param what the action to cancel |
| 13358 | */ |
| 13359 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13360 | if (verifyDrawable(who) && what != null) { |
| 13361 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13362 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13363 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13364 | } else { |
| 13365 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 13366 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13367 | } |
| 13368 | } |
| 13369 | |
| 13370 | /** |
| 13371 | * Unschedule any events associated with the given Drawable. This can be |
| 13372 | * used when selecting a new Drawable into a view, so that the previous |
| 13373 | * one is completely unscheduled. |
| 13374 | * |
| 13375 | * @param who The Drawable to unschedule. |
| 13376 | * |
| 13377 | * @see #drawableStateChanged |
| 13378 | */ |
| 13379 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 13380 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13381 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13382 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13383 | } |
| 13384 | } |
| 13385 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 13386 | /** |
| 13387 | * Return the layout direction of a given Drawable. |
| 13388 | * |
| 13389 | * @param who the Drawable to query |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13390 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 13391 | */ |
| 13392 | public int getResolvedLayoutDirection(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13393 | return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT; |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 13394 | } |
| 13395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13396 | /** |
| 13397 | * If your view subclass is displaying its own Drawable objects, it should |
| 13398 | * override this function and return true for any Drawable it is |
| 13399 | * displaying. This allows animations for those drawables to be |
| 13400 | * scheduled. |
| 13401 | * |
| 13402 | * <p>Be sure to call through to the super class when overriding this |
| 13403 | * function. |
| 13404 | * |
| 13405 | * @param who The Drawable to verify. Return true if it is one you are |
| 13406 | * displaying, else return the result of calling through to the |
| 13407 | * super class. |
| 13408 | * |
| 13409 | * @return boolean If true than the Drawable is being displayed in the |
| 13410 | * view; else false and it is not allowed to animate. |
| 13411 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13412 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 13413 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13414 | */ |
| 13415 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13416 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13417 | } |
| 13418 | |
| 13419 | /** |
| 13420 | * This function is called whenever the state of the view changes in such |
| 13421 | * a way that it impacts the state of drawables being shown. |
| 13422 | * |
| 13423 | * <p>Be sure to call through to the superclass when overriding this |
| 13424 | * function. |
| 13425 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13426 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13427 | */ |
| 13428 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13429 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13430 | if (d != null && d.isStateful()) { |
| 13431 | d.setState(getDrawableState()); |
| 13432 | } |
| 13433 | } |
| 13434 | |
| 13435 | /** |
| 13436 | * Call this to force a view to update its drawable state. This will cause |
| 13437 | * drawableStateChanged to be called on this view. Views that are interested |
| 13438 | * in the new state should call getDrawableState. |
| 13439 | * |
| 13440 | * @see #drawableStateChanged |
| 13441 | * @see #getDrawableState |
| 13442 | */ |
| 13443 | public void refreshDrawableState() { |
| 13444 | mPrivateFlags |= DRAWABLE_STATE_DIRTY; |
| 13445 | drawableStateChanged(); |
| 13446 | |
| 13447 | ViewParent parent = mParent; |
| 13448 | if (parent != null) { |
| 13449 | parent.childDrawableStateChanged(this); |
| 13450 | } |
| 13451 | } |
| 13452 | |
| 13453 | /** |
| 13454 | * Return an array of resource IDs of the drawable states representing the |
| 13455 | * current state of the view. |
| 13456 | * |
| 13457 | * @return The current drawable state |
| 13458 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13459 | * @see Drawable#setState(int[]) |
| 13460 | * @see #drawableStateChanged() |
| 13461 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13462 | */ |
| 13463 | public final int[] getDrawableState() { |
| 13464 | if ((mDrawableState != null) && ((mPrivateFlags & DRAWABLE_STATE_DIRTY) == 0)) { |
| 13465 | return mDrawableState; |
| 13466 | } else { |
| 13467 | mDrawableState = onCreateDrawableState(0); |
| 13468 | mPrivateFlags &= ~DRAWABLE_STATE_DIRTY; |
| 13469 | return mDrawableState; |
| 13470 | } |
| 13471 | } |
| 13472 | |
| 13473 | /** |
| 13474 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 13475 | * this view. This is called by the view |
| 13476 | * system when the cached Drawable state is determined to be invalid. To |
| 13477 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 13478 | * |
| 13479 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 13480 | * would like in the returned array in which you can place your own |
| 13481 | * states. |
| 13482 | * |
| 13483 | * @return Returns an array holding the current {@link Drawable} state of |
| 13484 | * the view. |
| 13485 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13486 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13487 | */ |
| 13488 | protected int[] onCreateDrawableState(int extraSpace) { |
| 13489 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 13490 | mParent instanceof View) { |
| 13491 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 13492 | } |
| 13493 | |
| 13494 | int[] drawableState; |
| 13495 | |
| 13496 | int privateFlags = mPrivateFlags; |
| 13497 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13498 | int viewStateIndex = 0; |
| 13499 | if ((privateFlags & PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
| 13500 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 13501 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Neel Parekh | e537858 | 2010-10-06 11:36:50 -0700 | [diff] [blame] | 13502 | if ((privateFlags & SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13503 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
| 13504 | if ((privateFlags & ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 13505 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 13506 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 13507 | // This is set if HW acceleration is requested, even if the current |
| 13508 | // process doesn't allow it. This is just to allow app preview |
| 13509 | // windows to better match their app. |
| 13510 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 13511 | } |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 13512 | if ((privateFlags & HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13513 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 13514 | final int privateFlags2 = mPrivateFlags2; |
| 13515 | if ((privateFlags2 & DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 13516 | if ((privateFlags2 & DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
| 13517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13518 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 13519 | |
| 13520 | //noinspection ConstantIfStatement |
| 13521 | if (false) { |
| 13522 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 13523 | Log.i("View", toString() |
| 13524 | + " pressed=" + ((privateFlags & PRESSED) != 0) |
| 13525 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 13526 | + " fo=" + hasFocus() |
| 13527 | + " sl=" + ((privateFlags & SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13528 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13529 | + ": " + Arrays.toString(drawableState)); |
| 13530 | } |
| 13531 | |
| 13532 | if (extraSpace == 0) { |
| 13533 | return drawableState; |
| 13534 | } |
| 13535 | |
| 13536 | final int[] fullState; |
| 13537 | if (drawableState != null) { |
| 13538 | fullState = new int[drawableState.length + extraSpace]; |
| 13539 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 13540 | } else { |
| 13541 | fullState = new int[extraSpace]; |
| 13542 | } |
| 13543 | |
| 13544 | return fullState; |
| 13545 | } |
| 13546 | |
| 13547 | /** |
| 13548 | * Merge your own state values in <var>additionalState</var> into the base |
| 13549 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13550 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13551 | * |
| 13552 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 13553 | * {@link #onCreateDrawableState(int)}, which will be modified to also hold your |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13554 | * own additional state values. |
| 13555 | * |
| 13556 | * @param additionalState The additional state values you would like |
| 13557 | * added to <var>baseState</var>; this array is not modified. |
| 13558 | * |
| 13559 | * @return As a convenience, the <var>baseState</var> array you originally |
| 13560 | * passed into the function is returned. |
| 13561 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13562 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13563 | */ |
| 13564 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 13565 | final int N = baseState.length; |
| 13566 | int i = N - 1; |
| 13567 | while (i >= 0 && baseState[i] == 0) { |
| 13568 | i--; |
| 13569 | } |
| 13570 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 13571 | return baseState; |
| 13572 | } |
| 13573 | |
| 13574 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 13575 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 13576 | * on all Drawable objects associated with this view. |
| 13577 | */ |
| 13578 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13579 | if (mBackground != null) { |
| 13580 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 13581 | } |
| 13582 | } |
| 13583 | |
| 13584 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13585 | * Sets the background color for this view. |
| 13586 | * @param color the color of the background |
| 13587 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 13588 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13589 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13590 | if (mBackground instanceof ColorDrawable) { |
| 13591 | ((ColorDrawable) mBackground).setColor(color); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 13592 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13593 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 13594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13595 | } |
| 13596 | |
| 13597 | /** |
| 13598 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 13599 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13600 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13601 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13602 | * @attr ref android.R.styleable#View_background |
| 13603 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 13604 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13605 | public void setBackgroundResource(int resid) { |
| 13606 | if (resid != 0 && resid == mBackgroundResource) { |
| 13607 | return; |
| 13608 | } |
| 13609 | |
| 13610 | Drawable d= null; |
| 13611 | if (resid != 0) { |
| 13612 | d = mResources.getDrawable(resid); |
| 13613 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13614 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13615 | |
| 13616 | mBackgroundResource = resid; |
| 13617 | } |
| 13618 | |
| 13619 | /** |
| 13620 | * Set the background to a given Drawable, or remove the background. If the |
| 13621 | * background has padding, this View's padding is set to the background's |
| 13622 | * padding. However, when a background is removed, this View's padding isn't |
| 13623 | * touched. If setting the padding is desired, please use |
| 13624 | * {@link #setPadding(int, int, int, int)}. |
| 13625 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13626 | * @param background The Drawable to use as the background, or null to remove the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13627 | * background |
| 13628 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13629 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 13630 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13631 | setBackgroundDrawable(background); |
| 13632 | } |
| 13633 | |
| 13634 | /** |
| 13635 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 13636 | */ |
| 13637 | @Deprecated |
| 13638 | public void setBackgroundDrawable(Drawable background) { |
| 13639 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 13640 | return; |
| 13641 | } |
| 13642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13643 | boolean requestLayout = false; |
| 13644 | |
| 13645 | mBackgroundResource = 0; |
| 13646 | |
| 13647 | /* |
| 13648 | * Regardless of whether we're setting a new background or not, we want |
| 13649 | * to clear the previous drawable. |
| 13650 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13651 | if (mBackground != null) { |
| 13652 | mBackground.setCallback(null); |
| 13653 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13654 | } |
| 13655 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13656 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13657 | Rect padding = sThreadLocal.get(); |
| 13658 | if (padding == null) { |
| 13659 | padding = new Rect(); |
| 13660 | sThreadLocal.set(padding); |
| 13661 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13662 | if (background.getPadding(padding)) { |
| 13663 | switch (background.getResolvedLayoutDirectionSelf()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13664 | case LAYOUT_DIRECTION_RTL: |
| 13665 | setPadding(padding.right, padding.top, padding.left, padding.bottom); |
| 13666 | break; |
| 13667 | case LAYOUT_DIRECTION_LTR: |
| 13668 | default: |
| 13669 | setPadding(padding.left, padding.top, padding.right, padding.bottom); |
| 13670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13671 | } |
| 13672 | |
| 13673 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 13674 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13675 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 13676 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13677 | requestLayout = true; |
| 13678 | } |
| 13679 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13680 | background.setCallback(this); |
| 13681 | if (background.isStateful()) { |
| 13682 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13683 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13684 | background.setVisible(getVisibility() == VISIBLE, false); |
| 13685 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13686 | |
| 13687 | if ((mPrivateFlags & SKIP_DRAW) != 0) { |
| 13688 | mPrivateFlags &= ~SKIP_DRAW; |
| 13689 | mPrivateFlags |= ONLY_DRAWS_BACKGROUND; |
| 13690 | requestLayout = true; |
| 13691 | } |
| 13692 | } else { |
| 13693 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13694 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13695 | |
| 13696 | if ((mPrivateFlags & ONLY_DRAWS_BACKGROUND) != 0) { |
| 13697 | /* |
| 13698 | * This view ONLY drew the background before and we're removing |
| 13699 | * the background, so now it won't draw anything |
| 13700 | * (hence we SKIP_DRAW) |
| 13701 | */ |
| 13702 | mPrivateFlags &= ~ONLY_DRAWS_BACKGROUND; |
| 13703 | mPrivateFlags |= SKIP_DRAW; |
| 13704 | } |
| 13705 | |
| 13706 | /* |
| 13707 | * When the background is set, we try to apply its padding to this |
| 13708 | * View. When the background is removed, we don't touch this View's |
| 13709 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 13710 | * requestLayout(), the invalidate() below is sufficient. |
| 13711 | */ |
| 13712 | |
| 13713 | // The old background's minimum size could have affected this |
| 13714 | // View's layout, so let's requestLayout |
| 13715 | requestLayout = true; |
| 13716 | } |
| 13717 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 13718 | computeOpaqueFlags(); |
| 13719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13720 | if (requestLayout) { |
| 13721 | requestLayout(); |
| 13722 | } |
| 13723 | |
| 13724 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13725 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13726 | } |
| 13727 | |
| 13728 | /** |
| 13729 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13730 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13731 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13732 | * |
| 13733 | * @see #setBackground(Drawable) |
| 13734 | * |
| 13735 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13736 | */ |
| 13737 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13738 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13739 | } |
| 13740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13741 | /** |
| 13742 | * Sets the padding. The view may add on the space required to display |
| 13743 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 13744 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 13745 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 13746 | * from the values set in this call. |
| 13747 | * |
| 13748 | * @attr ref android.R.styleable#View_padding |
| 13749 | * @attr ref android.R.styleable#View_paddingBottom |
| 13750 | * @attr ref android.R.styleable#View_paddingLeft |
| 13751 | * @attr ref android.R.styleable#View_paddingRight |
| 13752 | * @attr ref android.R.styleable#View_paddingTop |
| 13753 | * @param left the left padding in pixels |
| 13754 | * @param top the top padding in pixels |
| 13755 | * @param right the right padding in pixels |
| 13756 | * @param bottom the bottom padding in pixels |
| 13757 | */ |
| 13758 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13759 | mUserPaddingStart = -1; |
| 13760 | mUserPaddingEnd = -1; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13761 | mUserPaddingRelative = false; |
| 13762 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13763 | internalSetPadding(left, top, right, bottom); |
| 13764 | } |
| 13765 | |
| 13766 | private void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13767 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13768 | mUserPaddingRight = right; |
| 13769 | mUserPaddingBottom = bottom; |
| 13770 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13771 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13772 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13773 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13774 | // Common case is there are no scroll bars. |
| 13775 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13776 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13777 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13778 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13779 | switch (mVerticalScrollbarPosition) { |
| 13780 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13781 | if (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
| 13782 | left += offset; |
| 13783 | } else { |
| 13784 | right += offset; |
| 13785 | } |
| 13786 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13787 | case SCROLLBAR_POSITION_RIGHT: |
| 13788 | right += offset; |
| 13789 | break; |
| 13790 | case SCROLLBAR_POSITION_LEFT: |
| 13791 | left += offset; |
| 13792 | break; |
| 13793 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13794 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 13795 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13796 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 13797 | ? 0 : getHorizontalScrollbarHeight(); |
| 13798 | } |
| 13799 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13800 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13801 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13802 | changed = true; |
| 13803 | mPaddingLeft = left; |
| 13804 | } |
| 13805 | if (mPaddingTop != top) { |
| 13806 | changed = true; |
| 13807 | mPaddingTop = top; |
| 13808 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13809 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13810 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13811 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13812 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13813 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13814 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 13815 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13816 | } |
| 13817 | |
| 13818 | if (changed) { |
| 13819 | requestLayout(); |
| 13820 | } |
| 13821 | } |
| 13822 | |
| 13823 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13824 | * Sets the relative padding. The view may add on the space required to display |
| 13825 | * the scrollbars, depending on the style and visibility of the scrollbars. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13826 | * from the values set in this call. |
| 13827 | * |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13828 | * @param start the start padding in pixels |
| 13829 | * @param top the top padding in pixels |
| 13830 | * @param end the end padding in pixels |
| 13831 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13832 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13833 | */ |
| 13834 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13835 | mUserPaddingStart = start; |
| 13836 | mUserPaddingEnd = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13837 | mUserPaddingRelative = true; |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 13838 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13839 | switch(getResolvedLayoutDirection()) { |
| 13840 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13841 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13842 | break; |
| 13843 | case LAYOUT_DIRECTION_LTR: |
| 13844 | default: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 13845 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13846 | } |
| 13847 | } |
| 13848 | |
| 13849 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13850 | * Returns the top padding of this view. |
| 13851 | * |
| 13852 | * @return the top padding in pixels |
| 13853 | */ |
| 13854 | public int getPaddingTop() { |
| 13855 | return mPaddingTop; |
| 13856 | } |
| 13857 | |
| 13858 | /** |
| 13859 | * Returns the bottom padding of this view. If there are inset and enabled |
| 13860 | * scrollbars, this value may include the space required to display the |
| 13861 | * scrollbars as well. |
| 13862 | * |
| 13863 | * @return the bottom padding in pixels |
| 13864 | */ |
| 13865 | public int getPaddingBottom() { |
| 13866 | return mPaddingBottom; |
| 13867 | } |
| 13868 | |
| 13869 | /** |
| 13870 | * Returns the left padding of this view. If there are inset and enabled |
| 13871 | * scrollbars, this value may include the space required to display the |
| 13872 | * scrollbars as well. |
| 13873 | * |
| 13874 | * @return the left padding in pixels |
| 13875 | */ |
| 13876 | public int getPaddingLeft() { |
| 13877 | return mPaddingLeft; |
| 13878 | } |
| 13879 | |
| 13880 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13881 | * Returns the start padding of this view depending on its resolved layout direction. |
| 13882 | * If there are inset and enabled scrollbars, this value may include the space |
| 13883 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13884 | * |
| 13885 | * @return the start padding in pixels |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13886 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13887 | */ |
| 13888 | public int getPaddingStart() { |
| 13889 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13890 | mPaddingRight : mPaddingLeft; |
| 13891 | } |
| 13892 | |
| 13893 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13894 | * Returns the right padding of this view. If there are inset and enabled |
| 13895 | * scrollbars, this value may include the space required to display the |
| 13896 | * scrollbars as well. |
| 13897 | * |
| 13898 | * @return the right padding in pixels |
| 13899 | */ |
| 13900 | public int getPaddingRight() { |
| 13901 | return mPaddingRight; |
| 13902 | } |
| 13903 | |
| 13904 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 13905 | * Returns the end padding of this view depending on its resolved layout direction. |
| 13906 | * If there are inset and enabled scrollbars, this value may include the space |
| 13907 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13908 | * |
| 13909 | * @return the end padding in pixels |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13910 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13911 | */ |
| 13912 | public int getPaddingEnd() { |
| 13913 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 13914 | mPaddingLeft : mPaddingRight; |
| 13915 | } |
| 13916 | |
| 13917 | /** |
| 13918 | * Return if the padding as been set thru relative values |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13919 | * {@link #setPaddingRelative(int, int, int, int)} |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13920 | * |
| 13921 | * @return true if the padding is relative or false if it is not. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 13922 | * @hide |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 13923 | */ |
| 13924 | public boolean isPaddingRelative() { |
| 13925 | return mUserPaddingRelative; |
| 13926 | } |
| 13927 | |
| 13928 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 13929 | * @hide |
| 13930 | */ |
Philip Milne | 7a23b49 | 2012-04-24 22:12:36 -0700 | [diff] [blame] | 13931 | public Insets getOpticalInsets() { |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 13932 | if (mLayoutInsets == null) { |
Philip Milne | bbd51f1 | 2012-04-18 15:09:05 -0700 | [diff] [blame] | 13933 | mLayoutInsets = (mBackground == null) ? Insets.NONE : mBackground.getLayoutInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 13934 | } |
| 13935 | return mLayoutInsets; |
| 13936 | } |
| 13937 | |
| 13938 | /** |
| 13939 | * @hide |
| 13940 | */ |
| 13941 | public void setLayoutInsets(Insets layoutInsets) { |
| 13942 | mLayoutInsets = layoutInsets; |
| 13943 | } |
| 13944 | |
| 13945 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13946 | * Changes the selection state of this view. A view can be selected or not. |
| 13947 | * Note that selection is not the same as focus. Views are typically |
| 13948 | * selected in the context of an AdapterView like ListView or GridView; |
| 13949 | * the selected view is the view that is highlighted. |
| 13950 | * |
| 13951 | * @param selected true if the view must be selected, false otherwise |
| 13952 | */ |
| 13953 | public void setSelected(boolean selected) { |
| 13954 | if (((mPrivateFlags & SELECTED) != 0) != selected) { |
| 13955 | mPrivateFlags = (mPrivateFlags & ~SELECTED) | (selected ? SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 13956 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 13957 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13958 | refreshDrawableState(); |
| 13959 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 13960 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 13961 | notifyAccessibilityStateChanged(); |
| 13962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13963 | } |
| 13964 | } |
| 13965 | |
| 13966 | /** |
| 13967 | * Dispatch setSelected to all of this View's children. |
| 13968 | * |
| 13969 | * @see #setSelected(boolean) |
| 13970 | * |
| 13971 | * @param selected The new selected state |
| 13972 | */ |
| 13973 | protected void dispatchSetSelected(boolean selected) { |
| 13974 | } |
| 13975 | |
| 13976 | /** |
| 13977 | * Indicates the selection state of this view. |
| 13978 | * |
| 13979 | * @return true if the view is selected, false otherwise |
| 13980 | */ |
| 13981 | @ViewDebug.ExportedProperty |
| 13982 | public boolean isSelected() { |
| 13983 | return (mPrivateFlags & SELECTED) != 0; |
| 13984 | } |
| 13985 | |
| 13986 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 13987 | * Changes the activated state of this view. A view can be activated or not. |
| 13988 | * Note that activation is not the same as selection. Selection is |
| 13989 | * a transient property, representing the view (hierarchy) the user is |
| 13990 | * currently interacting with. Activation is a longer-term state that the |
| 13991 | * user can move views in and out of. For example, in a list view with |
| 13992 | * single or multiple selection enabled, the views in the current selection |
| 13993 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 13994 | * here.) The activated state is propagated down to children of the view it |
| 13995 | * is set on. |
| 13996 | * |
| 13997 | * @param activated true if the view must be activated, false otherwise |
| 13998 | */ |
| 13999 | public void setActivated(boolean activated) { |
| 14000 | if (((mPrivateFlags & ACTIVATED) != 0) != activated) { |
| 14001 | mPrivateFlags = (mPrivateFlags & ~ACTIVATED) | (activated ? ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14002 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14003 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 14004 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14005 | } |
| 14006 | } |
| 14007 | |
| 14008 | /** |
| 14009 | * Dispatch setActivated to all of this View's children. |
| 14010 | * |
| 14011 | * @see #setActivated(boolean) |
| 14012 | * |
| 14013 | * @param activated The new activated state |
| 14014 | */ |
| 14015 | protected void dispatchSetActivated(boolean activated) { |
| 14016 | } |
| 14017 | |
| 14018 | /** |
| 14019 | * Indicates the activation state of this view. |
| 14020 | * |
| 14021 | * @return true if the view is activated, false otherwise |
| 14022 | */ |
| 14023 | @ViewDebug.ExportedProperty |
| 14024 | public boolean isActivated() { |
| 14025 | return (mPrivateFlags & ACTIVATED) != 0; |
| 14026 | } |
| 14027 | |
| 14028 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14029 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 14030 | * observer can be used to get notifications when global events, like |
| 14031 | * layout, happen. |
| 14032 | * |
| 14033 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 14034 | * valid for the lifetime of this View. If the caller of this method keeps |
| 14035 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 14036 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 14037 | * |
| 14038 | * @return The ViewTreeObserver for this view's hierarchy. |
| 14039 | */ |
| 14040 | public ViewTreeObserver getViewTreeObserver() { |
| 14041 | if (mAttachInfo != null) { |
| 14042 | return mAttachInfo.mTreeObserver; |
| 14043 | } |
| 14044 | if (mFloatingTreeObserver == null) { |
| 14045 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 14046 | } |
| 14047 | return mFloatingTreeObserver; |
| 14048 | } |
| 14049 | |
| 14050 | /** |
| 14051 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 14052 | * |
| 14053 | * @return the topmost view containing this view |
| 14054 | */ |
| 14055 | public View getRootView() { |
| 14056 | if (mAttachInfo != null) { |
| 14057 | final View v = mAttachInfo.mRootView; |
| 14058 | if (v != null) { |
| 14059 | return v; |
| 14060 | } |
| 14061 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14063 | View parent = this; |
| 14064 | |
| 14065 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 14066 | parent = (View) parent.mParent; |
| 14067 | } |
| 14068 | |
| 14069 | return parent; |
| 14070 | } |
| 14071 | |
| 14072 | /** |
| 14073 | * <p>Computes the coordinates of this view on the screen. The argument |
| 14074 | * must be an array of two integers. After the method returns, the array |
| 14075 | * contains the x and y location in that order.</p> |
| 14076 | * |
| 14077 | * @param location an array of two integers in which to hold the coordinates |
| 14078 | */ |
| 14079 | public void getLocationOnScreen(int[] location) { |
| 14080 | getLocationInWindow(location); |
| 14081 | |
| 14082 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 14083 | if (info != null) { |
| 14084 | location[0] += info.mWindowLeft; |
| 14085 | location[1] += info.mWindowTop; |
| 14086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14087 | } |
| 14088 | |
| 14089 | /** |
| 14090 | * <p>Computes the coordinates of this view in its window. The argument |
| 14091 | * must be an array of two integers. After the method returns, the array |
| 14092 | * contains the x and y location in that order.</p> |
| 14093 | * |
| 14094 | * @param location an array of two integers in which to hold the coordinates |
| 14095 | */ |
| 14096 | public void getLocationInWindow(int[] location) { |
| 14097 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14098 | throw new IllegalArgumentException("location must be an array of two integers"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14099 | } |
| 14100 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 14101 | if (mAttachInfo == null) { |
| 14102 | // When the view is not attached to a window, this method does not make sense |
| 14103 | location[0] = location[1] = 0; |
| 14104 | return; |
| 14105 | } |
| 14106 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14107 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 14108 | position[0] = position[1] = 0.0f; |
| 14109 | |
| 14110 | if (!hasIdentityMatrix()) { |
| 14111 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14112 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14113 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14114 | position[0] += mLeft; |
| 14115 | position[1] += mTop; |
| 14116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14117 | ViewParent viewParent = mParent; |
| 14118 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14119 | final View view = (View) viewParent; |
| 14120 | |
| 14121 | position[0] -= view.mScrollX; |
| 14122 | position[1] -= view.mScrollY; |
| 14123 | |
| 14124 | if (!view.hasIdentityMatrix()) { |
| 14125 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14126 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14127 | |
| 14128 | position[0] += view.mLeft; |
| 14129 | position[1] += view.mTop; |
| 14130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14131 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14132 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14133 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14134 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14135 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14136 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 14137 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14138 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14139 | |
| 14140 | location[0] = (int) (position[0] + 0.5f); |
| 14141 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14142 | } |
| 14143 | |
| 14144 | /** |
| 14145 | * {@hide} |
| 14146 | * @param id the id of the view to be found |
| 14147 | * @return the view of the specified id, null if cannot be found |
| 14148 | */ |
| 14149 | protected View findViewTraversal(int id) { |
| 14150 | if (id == mID) { |
| 14151 | return this; |
| 14152 | } |
| 14153 | return null; |
| 14154 | } |
| 14155 | |
| 14156 | /** |
| 14157 | * {@hide} |
| 14158 | * @param tag the tag of the view to be found |
| 14159 | * @return the view of specified tag, null if cannot be found |
| 14160 | */ |
| 14161 | protected View findViewWithTagTraversal(Object tag) { |
| 14162 | if (tag != null && tag.equals(mTag)) { |
| 14163 | return this; |
| 14164 | } |
| 14165 | return null; |
| 14166 | } |
| 14167 | |
| 14168 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14169 | * {@hide} |
| 14170 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14171 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14172 | * @return The first view that matches the predicate or null. |
| 14173 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14174 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14175 | if (predicate.apply(this)) { |
| 14176 | return this; |
| 14177 | } |
| 14178 | return null; |
| 14179 | } |
| 14180 | |
| 14181 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14182 | * Look for a child view with the given id. If this view has the given |
| 14183 | * id, return this view. |
| 14184 | * |
| 14185 | * @param id The id to search for. |
| 14186 | * @return The view that has the given id in the hierarchy or null |
| 14187 | */ |
| 14188 | public final View findViewById(int id) { |
| 14189 | if (id < 0) { |
| 14190 | return null; |
| 14191 | } |
| 14192 | return findViewTraversal(id); |
| 14193 | } |
| 14194 | |
| 14195 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 14196 | * Finds a view by its unuque and stable accessibility id. |
| 14197 | * |
| 14198 | * @param accessibilityId The searched accessibility id. |
| 14199 | * @return The found view. |
| 14200 | */ |
| 14201 | final View findViewByAccessibilityId(int accessibilityId) { |
| 14202 | if (accessibilityId < 0) { |
| 14203 | return null; |
| 14204 | } |
| 14205 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 14206 | } |
| 14207 | |
| 14208 | /** |
| 14209 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 14210 | * |
| 14211 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 14212 | * boundary since the user can touch the screen at an arbitrary location |
| 14213 | * potentially crossing the root namespace bounday which will send an |
| 14214 | * accessibility event to accessibility services and they should be able |
| 14215 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 14216 | * unique in the window. |
| 14217 | * |
| 14218 | * @param accessibilityId The accessibility id. |
| 14219 | * @return The found view. |
| 14220 | */ |
| 14221 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 14222 | if (getAccessibilityViewId() == accessibilityId) { |
| 14223 | return this; |
| 14224 | } |
| 14225 | return null; |
| 14226 | } |
| 14227 | |
| 14228 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14229 | * Look for a child view with the given tag. If this view has the given |
| 14230 | * tag, return this view. |
| 14231 | * |
| 14232 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 14233 | * @return The View that has the given tag in the hierarchy or null |
| 14234 | */ |
| 14235 | public final View findViewWithTag(Object tag) { |
| 14236 | if (tag == null) { |
| 14237 | return null; |
| 14238 | } |
| 14239 | return findViewWithTagTraversal(tag); |
| 14240 | } |
| 14241 | |
| 14242 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14243 | * {@hide} |
| 14244 | * Look for a child view that matches the specified predicate. |
| 14245 | * If this view matches the predicate, return this view. |
| 14246 | * |
| 14247 | * @param predicate The predicate to evaluate. |
| 14248 | * @return The first view that matches the predicate or null. |
| 14249 | */ |
| 14250 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14251 | return findViewByPredicateTraversal(predicate, null); |
| 14252 | } |
| 14253 | |
| 14254 | /** |
| 14255 | * {@hide} |
| 14256 | * Look for a child view that matches the specified predicate, |
| 14257 | * starting with the specified view and its descendents and then |
| 14258 | * recusively searching the ancestors and siblings of that view |
| 14259 | * until this view is reached. |
| 14260 | * |
| 14261 | * This method is useful in cases where the predicate does not match |
| 14262 | * a single unique view (perhaps multiple views use the same id) |
| 14263 | * and we are trying to find the view that is "closest" in scope to the |
| 14264 | * starting view. |
| 14265 | * |
| 14266 | * @param start The view to start from. |
| 14267 | * @param predicate The predicate to evaluate. |
| 14268 | * @return The first view that matches the predicate or null. |
| 14269 | */ |
| 14270 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 14271 | View childToSkip = null; |
| 14272 | for (;;) { |
| 14273 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 14274 | if (view != null || start == this) { |
| 14275 | return view; |
| 14276 | } |
| 14277 | |
| 14278 | ViewParent parent = start.getParent(); |
| 14279 | if (parent == null || !(parent instanceof View)) { |
| 14280 | return null; |
| 14281 | } |
| 14282 | |
| 14283 | childToSkip = start; |
| 14284 | start = (View) parent; |
| 14285 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14286 | } |
| 14287 | |
| 14288 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14289 | * Sets the identifier for this view. The identifier does not have to be |
| 14290 | * unique in this view's hierarchy. The identifier should be a positive |
| 14291 | * number. |
| 14292 | * |
| 14293 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14294 | * @see #getId() |
| 14295 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14296 | * |
| 14297 | * @param id a number used to identify the view |
| 14298 | * |
| 14299 | * @attr ref android.R.styleable#View_id |
| 14300 | */ |
| 14301 | public void setId(int id) { |
| 14302 | mID = id; |
| 14303 | } |
| 14304 | |
| 14305 | /** |
| 14306 | * {@hide} |
| 14307 | * |
| 14308 | * @param isRoot true if the view belongs to the root namespace, false |
| 14309 | * otherwise |
| 14310 | */ |
| 14311 | public void setIsRootNamespace(boolean isRoot) { |
| 14312 | if (isRoot) { |
| 14313 | mPrivateFlags |= IS_ROOT_NAMESPACE; |
| 14314 | } else { |
| 14315 | mPrivateFlags &= ~IS_ROOT_NAMESPACE; |
| 14316 | } |
| 14317 | } |
| 14318 | |
| 14319 | /** |
| 14320 | * {@hide} |
| 14321 | * |
| 14322 | * @return true if the view belongs to the root namespace, false otherwise |
| 14323 | */ |
| 14324 | public boolean isRootNamespace() { |
| 14325 | return (mPrivateFlags&IS_ROOT_NAMESPACE) != 0; |
| 14326 | } |
| 14327 | |
| 14328 | /** |
| 14329 | * Returns this view's identifier. |
| 14330 | * |
| 14331 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 14332 | * if the view has no ID |
| 14333 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14334 | * @see #setId(int) |
| 14335 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14336 | * @attr ref android.R.styleable#View_id |
| 14337 | */ |
| 14338 | @ViewDebug.CapturedViewProperty |
| 14339 | public int getId() { |
| 14340 | return mID; |
| 14341 | } |
| 14342 | |
| 14343 | /** |
| 14344 | * Returns this view's tag. |
| 14345 | * |
| 14346 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14347 | * |
| 14348 | * @see #setTag(Object) |
| 14349 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14350 | */ |
| 14351 | @ViewDebug.ExportedProperty |
| 14352 | public Object getTag() { |
| 14353 | return mTag; |
| 14354 | } |
| 14355 | |
| 14356 | /** |
| 14357 | * Sets the tag associated with this view. A tag can be used to mark |
| 14358 | * a view in its hierarchy and does not have to be unique within the |
| 14359 | * hierarchy. Tags can also be used to store data within a view without |
| 14360 | * resorting to another data structure. |
| 14361 | * |
| 14362 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14363 | * |
| 14364 | * @see #getTag() |
| 14365 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14366 | */ |
| 14367 | public void setTag(final Object tag) { |
| 14368 | mTag = tag; |
| 14369 | } |
| 14370 | |
| 14371 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14372 | * Returns the tag associated with this view and the specified key. |
| 14373 | * |
| 14374 | * @param key The key identifying the tag |
| 14375 | * |
| 14376 | * @return the Object stored in this view as a tag |
| 14377 | * |
| 14378 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14379 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14380 | */ |
| 14381 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14382 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14383 | return null; |
| 14384 | } |
| 14385 | |
| 14386 | /** |
| 14387 | * Sets a tag associated with this view and a key. A tag can be used |
| 14388 | * to mark a view in its hierarchy and does not have to be unique within |
| 14389 | * the hierarchy. Tags can also be used to store data within a view |
| 14390 | * without resorting to another data structure. |
| 14391 | * |
| 14392 | * The specified key should be an id declared in the resources of the |
Scott Main | dfe5c20 | 2010-06-08 15:54:52 -0700 | [diff] [blame] | 14393 | * application to ensure it is unique (see the <a |
| 14394 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 14395 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14396 | * the Android framework or not associated with any package will cause |
| 14397 | * an {@link IllegalArgumentException} to be thrown. |
| 14398 | * |
| 14399 | * @param key The key identifying the tag |
| 14400 | * @param tag An Object to tag the view with |
| 14401 | * |
| 14402 | * @throws IllegalArgumentException If they specified key is not valid |
| 14403 | * |
| 14404 | * @see #setTag(Object) |
| 14405 | * @see #getTag(int) |
| 14406 | */ |
| 14407 | public void setTag(int key, final Object tag) { |
| 14408 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 14409 | // or a framework id |
| 14410 | if ((key >>> 24) < 2) { |
| 14411 | throw new IllegalArgumentException("The key must be an application-specific " |
| 14412 | + "resource id."); |
| 14413 | } |
| 14414 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14415 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14416 | } |
| 14417 | |
| 14418 | /** |
| 14419 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 14420 | * framework id. |
| 14421 | * |
| 14422 | * @hide |
| 14423 | */ |
| 14424 | public void setTagInternal(int key, Object tag) { |
| 14425 | if ((key >>> 24) != 0x1) { |
| 14426 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 14427 | + "resource id."); |
| 14428 | } |
| 14429 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14430 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14431 | } |
| 14432 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14433 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14434 | if (mKeyedTags == null) { |
| 14435 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14436 | } |
| 14437 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14438 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14439 | } |
| 14440 | |
| 14441 | /** |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 14442 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 14443 | * |
| 14444 | * @hide |
| 14445 | */ |
| 14446 | protected boolean dispatchConsistencyCheck(int consistency) { |
| 14447 | return onConsistencyCheck(consistency); |
| 14448 | } |
| 14449 | |
| 14450 | /** |
| 14451 | * Method that subclasses should implement to check their consistency. The type of |
| 14452 | * consistency check is indicated by the bit field passed as a parameter. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14453 | * |
Romain Guy | 13922e0 | 2009-05-12 17:56:14 -0700 | [diff] [blame] | 14454 | * @param consistency The type of consistency. See ViewDebug for more information. |
| 14455 | * |
| 14456 | * @throws IllegalStateException if the view is in an inconsistent state. |
| 14457 | * |
| 14458 | * @hide |
| 14459 | */ |
| 14460 | protected boolean onConsistencyCheck(int consistency) { |
| 14461 | boolean result = true; |
| 14462 | |
| 14463 | final boolean checkLayout = (consistency & ViewDebug.CONSISTENCY_LAYOUT) != 0; |
| 14464 | final boolean checkDrawing = (consistency & ViewDebug.CONSISTENCY_DRAWING) != 0; |
| 14465 | |
| 14466 | if (checkLayout) { |
| 14467 | if (getParent() == null) { |
| 14468 | result = false; |
| 14469 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14470 | "View " + this + " does not have a parent."); |
| 14471 | } |
| 14472 | |
| 14473 | if (mAttachInfo == null) { |
| 14474 | result = false; |
| 14475 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14476 | "View " + this + " is not attached to a window."); |
| 14477 | } |
| 14478 | } |
| 14479 | |
| 14480 | if (checkDrawing) { |
| 14481 | // Do not check the DIRTY/DRAWN flags because views can call invalidate() |
| 14482 | // from their draw() method |
| 14483 | |
| 14484 | if ((mPrivateFlags & DRAWN) != DRAWN && |
| 14485 | (mPrivateFlags & DRAWING_CACHE_VALID) == DRAWING_CACHE_VALID) { |
| 14486 | result = false; |
| 14487 | android.util.Log.d(ViewDebug.CONSISTENCY_LOG_TAG, |
| 14488 | "View " + this + " was invalidated but its drawing cache is valid."); |
| 14489 | } |
| 14490 | } |
| 14491 | |
| 14492 | return result; |
| 14493 | } |
| 14494 | |
| 14495 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14496 | * Prints information about this view in the log output, with the tag |
| 14497 | * {@link #VIEW_LOG_TAG}. |
| 14498 | * |
| 14499 | * @hide |
| 14500 | */ |
| 14501 | public void debug() { |
| 14502 | debug(0); |
| 14503 | } |
| 14504 | |
| 14505 | /** |
| 14506 | * Prints information about this view in the log output, with the tag |
| 14507 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 14508 | * indentation defined by the <code>depth</code>. |
| 14509 | * |
| 14510 | * @param depth the indentation level |
| 14511 | * |
| 14512 | * @hide |
| 14513 | */ |
| 14514 | protected void debug(int depth) { |
| 14515 | String output = debugIndent(depth - 1); |
| 14516 | |
| 14517 | output += "+ " + this; |
| 14518 | int id = getId(); |
| 14519 | if (id != -1) { |
| 14520 | output += " (id=" + id + ")"; |
| 14521 | } |
| 14522 | Object tag = getTag(); |
| 14523 | if (tag != null) { |
| 14524 | output += " (tag=" + tag + ")"; |
| 14525 | } |
| 14526 | Log.d(VIEW_LOG_TAG, output); |
| 14527 | |
| 14528 | if ((mPrivateFlags & FOCUSED) != 0) { |
| 14529 | output = debugIndent(depth) + " FOCUSED"; |
| 14530 | Log.d(VIEW_LOG_TAG, output); |
| 14531 | } |
| 14532 | |
| 14533 | output = debugIndent(depth); |
| 14534 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 14535 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 14536 | + "} "; |
| 14537 | Log.d(VIEW_LOG_TAG, output); |
| 14538 | |
| 14539 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 14540 | || mPaddingBottom != 0) { |
| 14541 | output = debugIndent(depth); |
| 14542 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 14543 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 14544 | Log.d(VIEW_LOG_TAG, output); |
| 14545 | } |
| 14546 | |
| 14547 | output = debugIndent(depth); |
| 14548 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 14549 | " mMeasureHeight=" + mMeasuredHeight; |
| 14550 | Log.d(VIEW_LOG_TAG, output); |
| 14551 | |
| 14552 | output = debugIndent(depth); |
| 14553 | if (mLayoutParams == null) { |
| 14554 | output += "BAD! no layout params"; |
| 14555 | } else { |
| 14556 | output = mLayoutParams.debug(output); |
| 14557 | } |
| 14558 | Log.d(VIEW_LOG_TAG, output); |
| 14559 | |
| 14560 | output = debugIndent(depth); |
| 14561 | output += "flags={"; |
| 14562 | output += View.printFlags(mViewFlags); |
| 14563 | output += "}"; |
| 14564 | Log.d(VIEW_LOG_TAG, output); |
| 14565 | |
| 14566 | output = debugIndent(depth); |
| 14567 | output += "privateFlags={"; |
| 14568 | output += View.printPrivateFlags(mPrivateFlags); |
| 14569 | output += "}"; |
| 14570 | Log.d(VIEW_LOG_TAG, output); |
| 14571 | } |
| 14572 | |
| 14573 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 14574 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14575 | * |
| 14576 | * @param depth the indentation level |
| 14577 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 14578 | * |
| 14579 | * @hide |
| 14580 | */ |
| 14581 | protected static String debugIndent(int depth) { |
| 14582 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 14583 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 14584 | spaces.append(' ').append(' '); |
| 14585 | } |
| 14586 | return spaces.toString(); |
| 14587 | } |
| 14588 | |
| 14589 | /** |
| 14590 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 14591 | * boundary. If this widget does not support baseline alignment, this |
| 14592 | * method returns -1. </p> |
| 14593 | * |
| 14594 | * @return the offset of the baseline within the widget's bounds or -1 |
| 14595 | * if baseline alignment is not supported |
| 14596 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 14597 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14598 | public int getBaseline() { |
| 14599 | return -1; |
| 14600 | } |
| 14601 | |
| 14602 | /** |
| 14603 | * Call this when something has changed which has invalidated the |
| 14604 | * layout of this view. This will schedule a layout pass of the view |
| 14605 | * tree. |
| 14606 | */ |
| 14607 | public void requestLayout() { |
| 14608 | if (ViewDebug.TRACE_HIERARCHY) { |
| 14609 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.REQUEST_LAYOUT); |
| 14610 | } |
| 14611 | |
| 14612 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 14613 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14614 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 14615 | if (mLayoutParams != null) { |
| 14616 | mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); |
| 14617 | } |
| 14618 | |
| 14619 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 14620 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14621 | } |
| 14622 | } |
| 14623 | |
| 14624 | /** |
| 14625 | * Forces this view to be laid out during the next layout pass. |
| 14626 | * This method does not call requestLayout() or forceLayout() |
| 14627 | * on the parent. |
| 14628 | */ |
| 14629 | public void forceLayout() { |
| 14630 | mPrivateFlags |= FORCE_LAYOUT; |
Chet Haase | 5af048c | 2011-01-24 17:00:32 -0800 | [diff] [blame] | 14631 | mPrivateFlags |= INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14632 | } |
| 14633 | |
| 14634 | /** |
| 14635 | * <p> |
| 14636 | * This is called to find out how big a view should be. The parent |
| 14637 | * supplies constraint information in the width and height parameters. |
| 14638 | * </p> |
| 14639 | * |
| 14640 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 14641 | * The actual measurement work of a view is performed in |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14642 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 14643 | * {@link #onMeasure(int, int)} can and must be overridden by subclasses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14644 | * </p> |
| 14645 | * |
| 14646 | * |
| 14647 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 14648 | * parent |
| 14649 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 14650 | * parent |
| 14651 | * |
| 14652 | * @see #onMeasure(int, int) |
| 14653 | */ |
| 14654 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
| 14655 | if ((mPrivateFlags & FORCE_LAYOUT) == FORCE_LAYOUT || |
| 14656 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 14657 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 14658 | |
| 14659 | // first clears the measured dimension flag |
| 14660 | mPrivateFlags &= ~MEASURED_DIMENSION_SET; |
| 14661 | |
| 14662 | if (ViewDebug.TRACE_HIERARCHY) { |
| 14663 | ViewDebug.trace(this, ViewDebug.HierarchyTraceType.ON_MEASURE); |
| 14664 | } |
| 14665 | |
| 14666 | // measure ourselves, this should set the measured dimension flag back |
| 14667 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 14668 | |
| 14669 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 14670 | // an exception to warn the developer |
| 14671 | if ((mPrivateFlags & MEASURED_DIMENSION_SET) != MEASURED_DIMENSION_SET) { |
| 14672 | throw new IllegalStateException("onMeasure() did not set the" |
| 14673 | + " measured dimension by calling" |
| 14674 | + " setMeasuredDimension()"); |
| 14675 | } |
| 14676 | |
| 14677 | mPrivateFlags |= LAYOUT_REQUIRED; |
| 14678 | } |
| 14679 | |
| 14680 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 14681 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 14682 | } |
| 14683 | |
| 14684 | /** |
| 14685 | * <p> |
| 14686 | * Measure the view and its content to determine the measured width and the |
| 14687 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 14688 | * should be overriden by subclasses to provide accurate and efficient |
| 14689 | * measurement of their contents. |
| 14690 | * </p> |
| 14691 | * |
| 14692 | * <p> |
| 14693 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 14694 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 14695 | * measured width and height of this view. Failure to do so will trigger an |
| 14696 | * <code>IllegalStateException</code>, thrown by |
| 14697 | * {@link #measure(int, int)}. Calling the superclass' |
| 14698 | * {@link #onMeasure(int, int)} is a valid use. |
| 14699 | * </p> |
| 14700 | * |
| 14701 | * <p> |
| 14702 | * The base class implementation of measure defaults to the background size, |
| 14703 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 14704 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 14705 | * their content. |
| 14706 | * </p> |
| 14707 | * |
| 14708 | * <p> |
| 14709 | * If this method is overridden, it is the subclass's responsibility to make |
| 14710 | * sure the measured height and width are at least the view's minimum height |
| 14711 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 14712 | * {@link #getSuggestedMinimumWidth()}). |
| 14713 | * </p> |
| 14714 | * |
| 14715 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 14716 | * The requirements are encoded with |
| 14717 | * {@link android.view.View.MeasureSpec}. |
| 14718 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 14719 | * The requirements are encoded with |
| 14720 | * {@link android.view.View.MeasureSpec}. |
| 14721 | * |
| 14722 | * @see #getMeasuredWidth() |
| 14723 | * @see #getMeasuredHeight() |
| 14724 | * @see #setMeasuredDimension(int, int) |
| 14725 | * @see #getSuggestedMinimumHeight() |
| 14726 | * @see #getSuggestedMinimumWidth() |
| 14727 | * @see android.view.View.MeasureSpec#getMode(int) |
| 14728 | * @see android.view.View.MeasureSpec#getSize(int) |
| 14729 | */ |
| 14730 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 14731 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 14732 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 14733 | } |
| 14734 | |
| 14735 | /** |
| 14736 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 14737 | * measured width and measured height. Failing to do so will trigger an |
| 14738 | * exception at measurement time.</p> |
| 14739 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14740 | * @param measuredWidth The measured width of this view. May be a complex |
| 14741 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14742 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 14743 | * @param measuredHeight The measured height of this view. May be a complex |
| 14744 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 14745 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14746 | */ |
| 14747 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 14748 | mMeasuredWidth = measuredWidth; |
| 14749 | mMeasuredHeight = measuredHeight; |
| 14750 | |
| 14751 | mPrivateFlags |= MEASURED_DIMENSION_SET; |
| 14752 | } |
| 14753 | |
| 14754 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14755 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 14756 | * @param curState The current state as returned from a view or the result |
| 14757 | * of combining multiple views. |
| 14758 | * @param newState The new view state to combine. |
| 14759 | * @return Returns a new integer reflecting the combination of the two |
| 14760 | * states. |
| 14761 | */ |
| 14762 | public static int combineMeasuredStates(int curState, int newState) { |
| 14763 | return curState | newState; |
| 14764 | } |
| 14765 | |
| 14766 | /** |
| 14767 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 14768 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 14769 | */ |
| 14770 | public static int resolveSize(int size, int measureSpec) { |
| 14771 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 14772 | } |
| 14773 | |
| 14774 | /** |
| 14775 | * Utility to reconcile a desired size and state, with constraints imposed |
| 14776 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 14777 | * is imposed by the constraints. The returned value is a compound integer, |
| 14778 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 14779 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 14780 | * size is smaller than the size the view wants to be. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14781 | * |
| 14782 | * @param size How big the view wants to be |
| 14783 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14784 | * @return Size information bit mask as defined by |
| 14785 | * {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14786 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14787 | public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14788 | int result = size; |
| 14789 | int specMode = MeasureSpec.getMode(measureSpec); |
| 14790 | int specSize = MeasureSpec.getSize(measureSpec); |
| 14791 | switch (specMode) { |
| 14792 | case MeasureSpec.UNSPECIFIED: |
| 14793 | result = size; |
| 14794 | break; |
| 14795 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14796 | if (specSize < size) { |
| 14797 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 14798 | } else { |
| 14799 | result = size; |
| 14800 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14801 | break; |
| 14802 | case MeasureSpec.EXACTLY: |
| 14803 | result = specSize; |
| 14804 | break; |
| 14805 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 14806 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14807 | } |
| 14808 | |
| 14809 | /** |
| 14810 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14811 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14812 | * by the MeasureSpec. |
| 14813 | * |
| 14814 | * @param size Default size for this view |
| 14815 | * @param measureSpec Constraints imposed by the parent |
| 14816 | * @return The size this view should be. |
| 14817 | */ |
| 14818 | public static int getDefaultSize(int size, int measureSpec) { |
| 14819 | int result = size; |
| 14820 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 14821 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14822 | |
| 14823 | switch (specMode) { |
| 14824 | case MeasureSpec.UNSPECIFIED: |
| 14825 | result = size; |
| 14826 | break; |
| 14827 | case MeasureSpec.AT_MOST: |
| 14828 | case MeasureSpec.EXACTLY: |
| 14829 | result = specSize; |
| 14830 | break; |
| 14831 | } |
| 14832 | return result; |
| 14833 | } |
| 14834 | |
| 14835 | /** |
| 14836 | * Returns the suggested minimum height that the view should use. This |
| 14837 | * returns the maximum of the view's minimum height |
| 14838 | * and the background's minimum height |
| 14839 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 14840 | * <p> |
| 14841 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14842 | * ensure the returned height is within the requirements of the parent. |
| 14843 | * |
| 14844 | * @return The suggested minimum height of the view. |
| 14845 | */ |
| 14846 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14847 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14848 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14849 | } |
| 14850 | |
| 14851 | /** |
| 14852 | * Returns the suggested minimum width that the view should use. This |
| 14853 | * returns the maximum of the view's minimum width) |
| 14854 | * and the background's minimum width |
| 14855 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 14856 | * <p> |
| 14857 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 14858 | * ensure the returned width is within the requirements of the parent. |
| 14859 | * |
| 14860 | * @return The suggested minimum width of the view. |
| 14861 | */ |
| 14862 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14863 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 14864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14865 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14866 | /** |
| 14867 | * Returns the minimum height of the view. |
| 14868 | * |
| 14869 | * @return the minimum height the view will try to be. |
| 14870 | * |
| 14871 | * @see #setMinimumHeight(int) |
| 14872 | * |
| 14873 | * @attr ref android.R.styleable#View_minHeight |
| 14874 | */ |
| 14875 | public int getMinimumHeight() { |
| 14876 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14877 | } |
| 14878 | |
| 14879 | /** |
| 14880 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 14881 | * be able to achieve this minimum height (for example, if its parent layout |
| 14882 | * constrains it with less available height). |
| 14883 | * |
| 14884 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14885 | * |
| 14886 | * @see #getMinimumHeight() |
| 14887 | * |
| 14888 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14889 | */ |
| 14890 | public void setMinimumHeight(int minHeight) { |
| 14891 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14892 | requestLayout(); |
| 14893 | } |
| 14894 | |
| 14895 | /** |
| 14896 | * Returns the minimum width of the view. |
| 14897 | * |
| 14898 | * @return the minimum width the view will try to be. |
| 14899 | * |
| 14900 | * @see #setMinimumWidth(int) |
| 14901 | * |
| 14902 | * @attr ref android.R.styleable#View_minWidth |
| 14903 | */ |
| 14904 | public int getMinimumWidth() { |
| 14905 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14906 | } |
| 14907 | |
| 14908 | /** |
| 14909 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 14910 | * be able to achieve this minimum width (for example, if its parent layout |
| 14911 | * constrains it with less available width). |
| 14912 | * |
| 14913 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14914 | * |
| 14915 | * @see #getMinimumWidth() |
| 14916 | * |
| 14917 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14918 | */ |
| 14919 | public void setMinimumWidth(int minWidth) { |
| 14920 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14921 | requestLayout(); |
| 14922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14923 | } |
| 14924 | |
| 14925 | /** |
| 14926 | * Get the animation currently associated with this view. |
| 14927 | * |
| 14928 | * @return The animation that is currently playing or |
| 14929 | * scheduled to play for this view. |
| 14930 | */ |
| 14931 | public Animation getAnimation() { |
| 14932 | return mCurrentAnimation; |
| 14933 | } |
| 14934 | |
| 14935 | /** |
| 14936 | * Start the specified animation now. |
| 14937 | * |
| 14938 | * @param animation the animation to start now |
| 14939 | */ |
| 14940 | public void startAnimation(Animation animation) { |
| 14941 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 14942 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14943 | invalidateParentCaches(); |
| 14944 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14945 | } |
| 14946 | |
| 14947 | /** |
| 14948 | * Cancels any animations for this view. |
| 14949 | */ |
| 14950 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14951 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 14952 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 14953 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14954 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14955 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14956 | } |
| 14957 | |
| 14958 | /** |
| 14959 | * Sets the next animation to play for this view. |
| 14960 | * If you want the animation to play immediately, use |
| 14961 | * startAnimation. This method provides allows fine-grained |
| 14962 | * control over the start time and invalidation, but you |
| 14963 | * must make sure that 1) the animation has a start time set, and |
| 14964 | * 2) the view will be invalidated when the animation is supposed to |
| 14965 | * start. |
| 14966 | * |
| 14967 | * @param animation The next animation, or null. |
| 14968 | */ |
| 14969 | public void setAnimation(Animation animation) { |
| 14970 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14972 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14973 | // If the screen is off assume the animation start time is now instead of |
| 14974 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 14975 | // would cause the animation to start when the screen turns back on |
| 14976 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 14977 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 14978 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 14979 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14980 | animation.reset(); |
| 14981 | } |
| 14982 | } |
| 14983 | |
| 14984 | /** |
| 14985 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 14986 | * currently associated with this view. If you override this method, |
| 14987 | * always call super.onAnimationStart(); |
| 14988 | * |
| 14989 | * @see #setAnimation(android.view.animation.Animation) |
| 14990 | * @see #getAnimation() |
| 14991 | */ |
| 14992 | protected void onAnimationStart() { |
| 14993 | mPrivateFlags |= ANIMATION_STARTED; |
| 14994 | } |
| 14995 | |
| 14996 | /** |
| 14997 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 14998 | * currently associated with this view. If you override this method, |
| 14999 | * always call super.onAnimationEnd(); |
| 15000 | * |
| 15001 | * @see #setAnimation(android.view.animation.Animation) |
| 15002 | * @see #getAnimation() |
| 15003 | */ |
| 15004 | protected void onAnimationEnd() { |
| 15005 | mPrivateFlags &= ~ANIMATION_STARTED; |
| 15006 | } |
| 15007 | |
| 15008 | /** |
| 15009 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 15010 | * draw themselves with the specified alpha should return true, and then |
| 15011 | * respect that alpha when their onDraw() is called. If this returns false |
| 15012 | * then the view may be redirected to draw into an offscreen buffer to |
| 15013 | * fulfill the request, which will look fine, but may be slower than if the |
| 15014 | * subclass handles it internally. The default implementation returns false. |
| 15015 | * |
| 15016 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 15017 | * @return true if the view can draw with the specified alpha. |
| 15018 | */ |
| 15019 | protected boolean onSetAlpha(int alpha) { |
| 15020 | return false; |
| 15021 | } |
| 15022 | |
| 15023 | /** |
| 15024 | * This is used by the RootView to perform an optimization when |
| 15025 | * the view hierarchy contains one or several SurfaceView. |
| 15026 | * SurfaceView is always considered transparent, but its children are not, |
| 15027 | * therefore all View objects remove themselves from the global transparent |
| 15028 | * region (passed as a parameter to this function). |
| 15029 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15030 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15031 | * |
| 15032 | * @return Returns true if the effective visibility of the view at this |
| 15033 | * point is opaque, regardless of the transparent region; returns false |
| 15034 | * if it is possible for underlying windows to be seen behind the view. |
| 15035 | * |
| 15036 | * {@hide} |
| 15037 | */ |
| 15038 | public boolean gatherTransparentRegion(Region region) { |
| 15039 | final AttachInfo attachInfo = mAttachInfo; |
| 15040 | if (region != null && attachInfo != null) { |
| 15041 | final int pflags = mPrivateFlags; |
| 15042 | if ((pflags & SKIP_DRAW) == 0) { |
| 15043 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 15044 | // remove it from the transparent region. |
| 15045 | final int[] location = attachInfo.mTransparentLocation; |
| 15046 | getLocationInWindow(location); |
| 15047 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 15048 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15049 | } else if ((pflags & ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15050 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 15051 | // exists, so we remove the background drawable's non-transparent |
| 15052 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15053 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15054 | } |
| 15055 | } |
| 15056 | return true; |
| 15057 | } |
| 15058 | |
| 15059 | /** |
| 15060 | * Play a sound effect for this view. |
| 15061 | * |
| 15062 | * <p>The framework will play sound effects for some built in actions, such as |
| 15063 | * clicking, but you may wish to play these effects in your widget, |
| 15064 | * for instance, for internal navigation. |
| 15065 | * |
| 15066 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 15067 | * {@link #isSoundEffectsEnabled()} is true. |
| 15068 | * |
| 15069 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 15070 | */ |
| 15071 | public void playSoundEffect(int soundConstant) { |
| 15072 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 15073 | return; |
| 15074 | } |
| 15075 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 15076 | } |
| 15077 | |
| 15078 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15079 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15080 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15081 | * <p>Provide haptic feedback to the user for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15082 | * |
| 15083 | * <p>The framework will provide haptic feedback for some built in actions, |
| 15084 | * such as long presses, but you may wish to provide feedback for your |
| 15085 | * own widget. |
| 15086 | * |
| 15087 | * <p>The feedback will only be performed if |
| 15088 | * {@link #isHapticFeedbackEnabled()} is true. |
| 15089 | * |
| 15090 | * @param feedbackConstant One of the constants defined in |
| 15091 | * {@link HapticFeedbackConstants} |
| 15092 | */ |
| 15093 | public boolean performHapticFeedback(int feedbackConstant) { |
| 15094 | return performHapticFeedback(feedbackConstant, 0); |
| 15095 | } |
| 15096 | |
| 15097 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15098 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15099 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15100 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15101 | * |
| 15102 | * @param feedbackConstant One of the constants defined in |
| 15103 | * {@link HapticFeedbackConstants} |
| 15104 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 15105 | */ |
| 15106 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 15107 | if (mAttachInfo == null) { |
| 15108 | return false; |
| 15109 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 15110 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15111 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15112 | && !isHapticFeedbackEnabled()) { |
| 15113 | return false; |
| 15114 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15115 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 15116 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15117 | } |
| 15118 | |
| 15119 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15120 | * Request that the visibility of the status bar or other screen/window |
| 15121 | * decorations be changed. |
| 15122 | * |
| 15123 | * <p>This method is used to put the over device UI into temporary modes |
| 15124 | * where the user's attention is focused more on the application content, |
| 15125 | * by dimming or hiding surrounding system affordances. This is typically |
| 15126 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 15127 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 15128 | * to be placed behind the action bar (and with these flags other system |
| 15129 | * affordances) so that smooth transitions between hiding and showing them |
| 15130 | * can be done. |
| 15131 | * |
| 15132 | * <p>Two representative examples of the use of system UI visibility is |
| 15133 | * implementing a content browsing application (like a magazine reader) |
| 15134 | * and a video playing application. |
| 15135 | * |
| 15136 | * <p>The first code shows a typical implementation of a View in a content |
| 15137 | * browsing application. In this implementation, the application goes |
| 15138 | * into a content-oriented mode by hiding the status bar and action bar, |
| 15139 | * and putting the navigation elements into lights out mode. The user can |
| 15140 | * then interact with content while in this mode. Such an application should |
| 15141 | * provide an easy way for the user to toggle out of the mode (such as to |
| 15142 | * check information in the status bar or access notifications). In the |
| 15143 | * implementation here, this is done simply by tapping on the content. |
| 15144 | * |
| 15145 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 15146 | * content} |
| 15147 | * |
| 15148 | * <p>This second code sample shows a typical implementation of a View |
| 15149 | * in a video playing application. In this situation, while the video is |
| 15150 | * playing the application would like to go into a complete full-screen mode, |
| 15151 | * to use as much of the display as possible for the video. When in this state |
| 15152 | * the user can not interact with the application; the system intercepts |
| 15153 | * touching on the screen to pop the UI out of full screen mode. |
| 15154 | * |
| 15155 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 15156 | * content} |
| 15157 | * |
| 15158 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15159 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15160 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15161 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15162 | */ |
| 15163 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 15164 | if (visibility != mSystemUiVisibility) { |
| 15165 | mSystemUiVisibility = visibility; |
| 15166 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15167 | mParent.recomputeViewAttributes(this); |
| 15168 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15169 | } |
| 15170 | } |
| 15171 | |
| 15172 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15173 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 15174 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15175 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15176 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15177 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15178 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 15179 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15180 | return mSystemUiVisibility; |
| 15181 | } |
| 15182 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15183 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 15184 | * Returns the current system UI visibility that is currently set for |
| 15185 | * the entire window. This is the combination of the |
| 15186 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 15187 | * views in the window. |
| 15188 | */ |
| 15189 | public int getWindowSystemUiVisibility() { |
| 15190 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 15191 | } |
| 15192 | |
| 15193 | /** |
| 15194 | * Override to find out when the window's requested system UI visibility |
| 15195 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 15196 | * This is different from the callbacks recieved through |
| 15197 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 15198 | * in that this is only telling you about the local request of the window, |
| 15199 | * not the actual values applied by the system. |
| 15200 | */ |
| 15201 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 15202 | } |
| 15203 | |
| 15204 | /** |
| 15205 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 15206 | * the view hierarchy. |
| 15207 | */ |
| 15208 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 15209 | onWindowSystemUiVisibilityChanged(visible); |
| 15210 | } |
| 15211 | |
| 15212 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15213 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 15214 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 15215 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15216 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15217 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15218 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15219 | mParent.recomputeViewAttributes(this); |
| 15220 | } |
| 15221 | } |
| 15222 | |
| 15223 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15224 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 15225 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15226 | */ |
| 15227 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15228 | ListenerInfo li = mListenerInfo; |
| 15229 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 15230 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 15231 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15232 | } |
| 15233 | } |
| 15234 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15235 | void updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 15236 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 15237 | if (val != mSystemUiVisibility) { |
| 15238 | setSystemUiVisibility(val); |
| 15239 | } |
| 15240 | } |
| 15241 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 15242 | /** @hide */ |
| 15243 | public void setDisabledSystemUiVisibility(int flags) { |
| 15244 | if (mAttachInfo != null) { |
| 15245 | if (mAttachInfo.mDisabledSystemUiVisibility != flags) { |
| 15246 | mAttachInfo.mDisabledSystemUiVisibility = flags; |
| 15247 | if (mParent != null) { |
| 15248 | mParent.recomputeViewAttributes(this); |
| 15249 | } |
| 15250 | } |
| 15251 | } |
| 15252 | } |
| 15253 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15254 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15255 | * Creates an image that the system displays during the drag and drop |
| 15256 | * operation. This is called a "drag shadow". The default implementation |
| 15257 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 15258 | * appearance as the given View. The default also positions the center of the drag shadow |
| 15259 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 15260 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 15261 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 15262 | * default is an invisible drag shadow. |
| 15263 | * <p> |
| 15264 | * You are not required to use the View you provide to the constructor as the basis of the |
| 15265 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 15266 | * anything you want as the drag shadow. |
| 15267 | * </p> |
| 15268 | * <p> |
| 15269 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 15270 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 15271 | * size and position of the drag shadow. It uses this data to construct a |
| 15272 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 15273 | * so that your application can draw the shadow image in the Canvas. |
| 15274 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 15275 | * |
| 15276 | * <div class="special reference"> |
| 15277 | * <h3>Developer Guides</h3> |
| 15278 | * <p>For a guide to implementing drag and drop features, read the |
| 15279 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 15280 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15281 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15282 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15283 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15284 | |
| 15285 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15286 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 15287 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 15288 | * over the center of the View. |
| 15289 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15290 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15291 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15292 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15293 | } |
| 15294 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15295 | /** |
| 15296 | * Construct a shadow builder object with no associated View. This |
| 15297 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 15298 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 15299 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15300 | * reference to any View object. If they are not overridden, then the result is an |
| 15301 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15302 | */ |
| 15303 | public DragShadowBuilder() { |
| 15304 | mView = new WeakReference<View>(null); |
| 15305 | } |
| 15306 | |
| 15307 | /** |
| 15308 | * Returns the View object that had been passed to the |
| 15309 | * {@link #View.DragShadowBuilder(View)} |
| 15310 | * constructor. If that View parameter was {@code null} or if the |
| 15311 | * {@link #View.DragShadowBuilder()} |
| 15312 | * constructor was used to instantiate the builder object, this method will return |
| 15313 | * null. |
| 15314 | * |
| 15315 | * @return The View object associate with this builder object. |
| 15316 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15317 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15318 | final public View getView() { |
| 15319 | return mView.get(); |
| 15320 | } |
| 15321 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15322 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15323 | * Provides the metrics for the shadow image. These include the dimensions of |
| 15324 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15325 | * be centered under the touch location while dragging. |
| 15326 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15327 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15328 | * same as the dimensions of the View itself and centers the shadow under |
| 15329 | * the touch point. |
| 15330 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15331 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15332 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 15333 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 15334 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 15335 | * image. |
| 15336 | * |
| 15337 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 15338 | * shadow image that should be underneath the touch point during the drag and drop |
| 15339 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 15340 | * X coordinate and {@link android.graphics.Point#y} to the Y coordinate of this position. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15341 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15342 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15343 | final View view = mView.get(); |
| 15344 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15345 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 15346 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15347 | } else { |
| 15348 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 15349 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15350 | } |
| 15351 | |
| 15352 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15353 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 15354 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15355 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15356 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15357 | * @param canvas A {@link android.graphics.Canvas} object in which to draw the shadow image. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15358 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15359 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15360 | final View view = mView.get(); |
| 15361 | if (view != null) { |
| 15362 | view.draw(canvas); |
| 15363 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15364 | Log.e(View.VIEW_LOG_TAG, "Asked to draw drag shadow but no view"); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15365 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15366 | } |
| 15367 | } |
| 15368 | |
| 15369 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15370 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 15371 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 15372 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 15373 | * to get metrics for the drag shadow, and then calls the object's |
| 15374 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 15375 | * <p> |
| 15376 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 15377 | * drag events to all the View objects in your application that are currently visible. It does |
| 15378 | * this either by calling the View object's drag listener (an implementation of |
| 15379 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 15380 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 15381 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 15382 | * {@link android.view.DragEvent#getAction()} value of |
| 15383 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 15384 | * </p> |
| 15385 | * <p> |
| 15386 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 15387 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 15388 | * be related to the View the user selected for dragging. |
| 15389 | * </p> |
| 15390 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 15391 | * transferred by the drag and drop operation. |
| 15392 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 15393 | * drag shadow. |
| 15394 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 15395 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 15396 | * current drag. |
| 15397 | * <p> |
| 15398 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 15399 | * to the target Views. For example, it can contain flags that differentiate between a |
| 15400 | * a copy operation and a move operation. |
| 15401 | * </p> |
| 15402 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 15403 | * so the parameter should be set to 0. |
| 15404 | * @return {@code true} if the method completes successfully, or |
| 15405 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 15406 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15407 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15408 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15409 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15410 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15411 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15412 | } |
| 15413 | boolean okay = false; |
| 15414 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15415 | Point shadowSize = new Point(); |
| 15416 | Point shadowTouchPoint = new Point(); |
| 15417 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15418 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15419 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 15420 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 15421 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15422 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15423 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15424 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15425 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 15426 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15427 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15428 | Surface surface = new Surface(); |
| 15429 | try { |
| 15430 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15431 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15432 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token=" + token |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15433 | + " surface=" + surface); |
| 15434 | if (token != null) { |
| 15435 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15436 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15437 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15438 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15439 | } finally { |
| 15440 | surface.unlockCanvasAndPost(canvas); |
| 15441 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15442 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15443 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 15444 | |
| 15445 | // Cache the local state object for delivery with DragEvents |
| 15446 | root.setLocalDragState(myLocalState); |
| 15447 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15448 | // repurpose 'shadowSize' for the last touch point |
| 15449 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15450 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15451 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15452 | shadowSize.x, shadowSize.y, |
| 15453 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15454 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 15455 | |
| 15456 | // Off and running! Release our local surface instance; the drag |
| 15457 | // shadow surface is now managed by the system process. |
| 15458 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15459 | } |
| 15460 | } catch (Exception e) { |
| 15461 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 15462 | surface.destroy(); |
| 15463 | } |
| 15464 | |
| 15465 | return okay; |
| 15466 | } |
| 15467 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15468 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15469 | * Handles drag events sent by the system following a call to |
| 15470 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 15471 | *<p> |
| 15472 | * When the system calls this method, it passes a |
| 15473 | * {@link android.view.DragEvent} object. A call to |
| 15474 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 15475 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 15476 | * operation. |
| 15477 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 15478 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 15479 | * in DragEvent, indicating the type of drag event represented by this object. |
| 15480 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 15481 | * <p> |
| 15482 | * The method should return {@code true} in response to an action type of |
| 15483 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 15484 | * operation. |
| 15485 | * </p> |
| 15486 | * <p> |
| 15487 | * The method should also return {@code true} in response to an action type of |
| 15488 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 15489 | * {@code false} if it didn't. |
| 15490 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15491 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 15492 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15493 | return false; |
| 15494 | } |
| 15495 | |
| 15496 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15497 | * Detects if this View is enabled and has a drag event listener. |
| 15498 | * If both are true, then it calls the drag event listener with the |
| 15499 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 15500 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 15501 | * <p> |
| 15502 | * For all other cases, the method calls the |
| 15503 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 15504 | * method and returns its result. |
| 15505 | * </p> |
| 15506 | * <p> |
| 15507 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 15508 | * event listener. However, if the View has a listener and the listener returns true, then |
| 15509 | * onDragEvent() is not called. |
| 15510 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15511 | */ |
| 15512 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 15513 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15514 | ListenerInfo li = mListenerInfo; |
| 15515 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 15516 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 15517 | return true; |
| 15518 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15519 | return onDragEvent(event); |
| 15520 | } |
| 15521 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 15522 | boolean canAcceptDrag() { |
| 15523 | return (mPrivateFlags2 & DRAG_CAN_ACCEPT) != 0; |
| 15524 | } |
| 15525 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15526 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15527 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 15528 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 15529 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15530 | */ |
| 15531 | public void onCloseSystemDialogs(String reason) { |
| 15532 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15533 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 15534 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15535 | * Given a Drawable whose bounds have been set to draw into this view, |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15536 | * update a Region being computed for |
| 15537 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15538 | * that any non-transparent parts of the Drawable are removed from the |
| 15539 | * given transparent region. |
| 15540 | * |
| 15541 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 15542 | * @param region A Region holding the current transparency information, |
| 15543 | * where any parts of the region that are set are considered to be |
| 15544 | * transparent. On return, this region will be modified to have the |
| 15545 | * transparency information reduced by the corresponding parts of the |
| 15546 | * Drawable that are not transparent. |
| 15547 | * {@hide} |
| 15548 | */ |
| 15549 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 15550 | if (DBG) { |
| 15551 | Log.i("View", "Getting transparent region for: " + this); |
| 15552 | } |
| 15553 | final Region r = dr.getTransparentRegion(); |
| 15554 | final Rect db = dr.getBounds(); |
| 15555 | final AttachInfo attachInfo = mAttachInfo; |
| 15556 | if (r != null && attachInfo != null) { |
| 15557 | final int w = getRight()-getLeft(); |
| 15558 | final int h = getBottom()-getTop(); |
| 15559 | if (db.left > 0) { |
| 15560 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 15561 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 15562 | } |
| 15563 | if (db.right < w) { |
| 15564 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 15565 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 15566 | } |
| 15567 | if (db.top > 0) { |
| 15568 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 15569 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 15570 | } |
| 15571 | if (db.bottom < h) { |
| 15572 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 15573 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 15574 | } |
| 15575 | final int[] location = attachInfo.mTransparentLocation; |
| 15576 | getLocationInWindow(location); |
| 15577 | r.translate(location[0], location[1]); |
| 15578 | region.op(r, Region.Op.INTERSECT); |
| 15579 | } else { |
| 15580 | region.op(db, Region.Op.DIFFERENCE); |
| 15581 | } |
| 15582 | } |
| 15583 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15584 | private void checkForLongClick(int delayOffset) { |
| 15585 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 15586 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15587 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 15588 | if (mPendingCheckForLongPress == null) { |
| 15589 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 15590 | } |
| 15591 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 15592 | postDelayed(mPendingCheckForLongPress, |
| 15593 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15595 | } |
| 15596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15597 | /** |
| 15598 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 15599 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 15600 | * |
| 15601 | * @param context The Context object for your activity or application. |
| 15602 | * @param resource The resource ID to inflate |
| 15603 | * @param root A view group that will be the parent. Used to properly inflate the |
| 15604 | * layout_* parameters. |
| 15605 | * @see LayoutInflater |
| 15606 | */ |
| 15607 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 15608 | LayoutInflater factory = LayoutInflater.from(context); |
| 15609 | return factory.inflate(resource, root); |
| 15610 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 15611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15612 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 15613 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 15614 | * content boundaries. Views that call this method should override |
| 15615 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 15616 | * results of an over-scroll operation. |
| 15617 | * |
| 15618 | * Views can use this method to handle any touch or fling-based scrolling. |
| 15619 | * |
| 15620 | * @param deltaX Change in X in pixels |
| 15621 | * @param deltaY Change in Y in pixels |
| 15622 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 15623 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 15624 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 15625 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 15626 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 15627 | * along the X axis. |
| 15628 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 15629 | * along the Y axis. |
| 15630 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 15631 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 15632 | * axis, false otherwise. |
| 15633 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 15634 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 15635 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 15636 | int scrollX, int scrollY, |
| 15637 | int scrollRangeX, int scrollRangeY, |
| 15638 | int maxOverScrollX, int maxOverScrollY, |
| 15639 | boolean isTouchEvent) { |
| 15640 | final int overScrollMode = mOverScrollMode; |
| 15641 | final boolean canScrollHorizontal = |
| 15642 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 15643 | final boolean canScrollVertical = |
| 15644 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 15645 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 15646 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 15647 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 15648 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 15649 | |
| 15650 | int newScrollX = scrollX + deltaX; |
| 15651 | if (!overScrollHorizontal) { |
| 15652 | maxOverScrollX = 0; |
| 15653 | } |
| 15654 | |
| 15655 | int newScrollY = scrollY + deltaY; |
| 15656 | if (!overScrollVertical) { |
| 15657 | maxOverScrollY = 0; |
| 15658 | } |
| 15659 | |
| 15660 | // Clamp values if at the limits and record |
| 15661 | final int left = -maxOverScrollX; |
| 15662 | final int right = maxOverScrollX + scrollRangeX; |
| 15663 | final int top = -maxOverScrollY; |
| 15664 | final int bottom = maxOverScrollY + scrollRangeY; |
| 15665 | |
| 15666 | boolean clampedX = false; |
| 15667 | if (newScrollX > right) { |
| 15668 | newScrollX = right; |
| 15669 | clampedX = true; |
| 15670 | } else if (newScrollX < left) { |
| 15671 | newScrollX = left; |
| 15672 | clampedX = true; |
| 15673 | } |
| 15674 | |
| 15675 | boolean clampedY = false; |
| 15676 | if (newScrollY > bottom) { |
| 15677 | newScrollY = bottom; |
| 15678 | clampedY = true; |
| 15679 | } else if (newScrollY < top) { |
| 15680 | newScrollY = top; |
| 15681 | clampedY = true; |
| 15682 | } |
| 15683 | |
| 15684 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 15685 | |
| 15686 | return clampedX || clampedY; |
| 15687 | } |
| 15688 | |
| 15689 | /** |
| 15690 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 15691 | * respond to the results of an over-scroll operation. |
| 15692 | * |
| 15693 | * @param scrollX New X scroll value in pixels |
| 15694 | * @param scrollY New Y scroll value in pixels |
| 15695 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 15696 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 15697 | */ |
| 15698 | protected void onOverScrolled(int scrollX, int scrollY, |
| 15699 | boolean clampedX, boolean clampedY) { |
| 15700 | // Intentionally empty. |
| 15701 | } |
| 15702 | |
| 15703 | /** |
| 15704 | * Returns the over-scroll mode for this view. The result will be |
| 15705 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 15706 | * (allow over-scrolling only if the view content is larger than the container), |
| 15707 | * or {@link #OVER_SCROLL_NEVER}. |
| 15708 | * |
| 15709 | * @return This view's over-scroll mode. |
| 15710 | */ |
| 15711 | public int getOverScrollMode() { |
| 15712 | return mOverScrollMode; |
| 15713 | } |
| 15714 | |
| 15715 | /** |
| 15716 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 15717 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 15718 | * (allow over-scrolling only if the view content is larger than the container), |
| 15719 | * or {@link #OVER_SCROLL_NEVER}. |
| 15720 | * |
| 15721 | * Setting the over-scroll mode of a view will have an effect only if the |
| 15722 | * view is capable of scrolling. |
| 15723 | * |
| 15724 | * @param overScrollMode The new over-scroll mode for this view. |
| 15725 | */ |
| 15726 | public void setOverScrollMode(int overScrollMode) { |
| 15727 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 15728 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 15729 | overScrollMode != OVER_SCROLL_NEVER) { |
| 15730 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 15731 | } |
| 15732 | mOverScrollMode = overScrollMode; |
| 15733 | } |
| 15734 | |
| 15735 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 15736 | * Gets a scale factor that determines the distance the view should scroll |
| 15737 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 15738 | * @return The vertical scroll scale factor. |
| 15739 | * @hide |
| 15740 | */ |
| 15741 | protected float getVerticalScrollFactor() { |
| 15742 | if (mVerticalScrollFactor == 0) { |
| 15743 | TypedValue outValue = new TypedValue(); |
| 15744 | if (!mContext.getTheme().resolveAttribute( |
| 15745 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 15746 | throw new IllegalStateException( |
| 15747 | "Expected theme to define listPreferredItemHeight."); |
| 15748 | } |
| 15749 | mVerticalScrollFactor = outValue.getDimension( |
| 15750 | mContext.getResources().getDisplayMetrics()); |
| 15751 | } |
| 15752 | return mVerticalScrollFactor; |
| 15753 | } |
| 15754 | |
| 15755 | /** |
| 15756 | * Gets a scale factor that determines the distance the view should scroll |
| 15757 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 15758 | * @return The horizontal scroll scale factor. |
| 15759 | * @hide |
| 15760 | */ |
| 15761 | protected float getHorizontalScrollFactor() { |
| 15762 | // TODO: Should use something else. |
| 15763 | return getVerticalScrollFactor(); |
| 15764 | } |
| 15765 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15766 | /** |
| 15767 | * Return the value specifying the text direction or policy that was set with |
| 15768 | * {@link #setTextDirection(int)}. |
| 15769 | * |
| 15770 | * @return the defined text direction. It can be one of: |
| 15771 | * |
| 15772 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15773 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15774 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15775 | * {@link #TEXT_DIRECTION_LTR}, |
| 15776 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15777 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15778 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15779 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15780 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15781 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 15782 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 15783 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 15784 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 15785 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 15786 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 15787 | }) |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15788 | public int getTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15789 | return (mPrivateFlags2 & TEXT_DIRECTION_MASK) >> TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15790 | } |
| 15791 | |
| 15792 | /** |
| 15793 | * Set the text direction. |
| 15794 | * |
| 15795 | * @param textDirection the direction to set. Should be one of: |
| 15796 | * |
| 15797 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 15798 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15799 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 15800 | * {@link #TEXT_DIRECTION_LTR}, |
| 15801 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15802 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15803 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15804 | */ |
| 15805 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15806 | if (getTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15807 | // Reset the current text direction and the resolved one |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15808 | mPrivateFlags2 &= ~TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15809 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15810 | // Set the new text direction |
| 15811 | mPrivateFlags2 |= ((textDirection << TEXT_DIRECTION_MASK_SHIFT) & TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15812 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15813 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 15814 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15815 | } |
| 15816 | } |
| 15817 | |
| 15818 | /** |
| 15819 | * Return the resolved text direction. |
| 15820 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15821 | * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches |
| 15822 | * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds |
| 15823 | * up the parent chain of the view. if there is no parent, then it will return the default |
| 15824 | * {@link #TEXT_DIRECTION_FIRST_STRONG}. |
| 15825 | * |
| 15826 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15827 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 15828 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 15829 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15830 | * {@link #TEXT_DIRECTION_LTR}, |
| 15831 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15832 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15833 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15834 | */ |
| 15835 | public int getResolvedTextDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 15836 | // The text direction will be resolved only if needed |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15837 | if ((mPrivateFlags2 & TEXT_DIRECTION_RESOLVED) != TEXT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15838 | resolveTextDirection(); |
| 15839 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15840 | return (mPrivateFlags2 & TEXT_DIRECTION_RESOLVED_MASK) >> TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15841 | } |
| 15842 | |
| 15843 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15844 | * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when |
| 15845 | * resolution is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15846 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15847 | */ |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15848 | public void resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15849 | // Reset any previous text direction resolution |
| 15850 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
| 15851 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15852 | if (hasRtlSupport()) { |
| 15853 | // Set resolved text direction flag depending on text direction flag |
| 15854 | final int textDirection = getTextDirection(); |
| 15855 | switch(textDirection) { |
| 15856 | case TEXT_DIRECTION_INHERIT: |
| 15857 | if (canResolveTextDirection()) { |
| 15858 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15859 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15860 | // Set current resolved direction to the same value as the parent's one |
| 15861 | final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); |
| 15862 | switch (parentResolvedDirection) { |
| 15863 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15864 | case TEXT_DIRECTION_ANY_RTL: |
| 15865 | case TEXT_DIRECTION_LTR: |
| 15866 | case TEXT_DIRECTION_RTL: |
| 15867 | case TEXT_DIRECTION_LOCALE: |
| 15868 | mPrivateFlags2 |= |
| 15869 | (parentResolvedDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15870 | break; |
| 15871 | default: |
| 15872 | // Default resolved direction is "first strong" heuristic |
| 15873 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 15874 | } |
| 15875 | } else { |
| 15876 | // We cannot do the resolution if there is no parent, so use the default one |
| 15877 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15878 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15879 | break; |
| 15880 | case TEXT_DIRECTION_FIRST_STRONG: |
| 15881 | case TEXT_DIRECTION_ANY_RTL: |
| 15882 | case TEXT_DIRECTION_LTR: |
| 15883 | case TEXT_DIRECTION_RTL: |
| 15884 | case TEXT_DIRECTION_LOCALE: |
| 15885 | // Resolved direction is the same as text direction |
| 15886 | mPrivateFlags2 |= (textDirection << TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 15887 | break; |
| 15888 | default: |
| 15889 | // Default resolved direction is "first strong" heuristic |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15890 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 15891 | } |
| 15892 | } else { |
| 15893 | // Default resolved direction is "first strong" heuristic |
| 15894 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15895 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15896 | |
| 15897 | // Set to resolved |
| 15898 | mPrivateFlags2 |= TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15899 | onResolvedTextDirectionChanged(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15900 | } |
| 15901 | |
| 15902 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15903 | * Called when text direction has been resolved. Subclasses that care about text direction |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15904 | * resolution should override this method. |
| 15905 | * |
| 15906 | * The default implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15907 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15908 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15909 | public void onResolvedTextDirectionChanged() { |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15910 | } |
| 15911 | |
| 15912 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15913 | * Check if text direction resolution can be done. |
| 15914 | * |
| 15915 | * @return true if text direction resolution can be done otherwise return false. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15916 | * @hide |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15917 | */ |
| 15918 | public boolean canResolveTextDirection() { |
| 15919 | switch (getTextDirection()) { |
| 15920 | case TEXT_DIRECTION_INHERIT: |
| 15921 | return (mParent != null) && (mParent instanceof ViewGroup); |
| 15922 | default: |
| 15923 | return true; |
| 15924 | } |
| 15925 | } |
| 15926 | |
| 15927 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15928 | * Reset resolved text direction. Text direction can be resolved with a call to |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15929 | * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15930 | * reset is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15931 | * @hide |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15932 | */ |
| 15933 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 15934 | mPrivateFlags2 &= ~(TEXT_DIRECTION_RESOLVED | TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15935 | onResolvedTextDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15936 | } |
| 15937 | |
| 15938 | /** |
| 15939 | * Called when text direction is reset. Subclasses that care about text direction reset should |
| 15940 | * override this method and do a reset of the text direction of their children. The default |
| 15941 | * implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15942 | * @hide |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 15943 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 15944 | public void onResolvedTextDirectionReset() { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 15945 | } |
| 15946 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15947 | /** |
| 15948 | * Return the value specifying the text alignment or policy that was set with |
| 15949 | * {@link #setTextAlignment(int)}. |
| 15950 | * |
| 15951 | * @return the defined text alignment. It can be one of: |
| 15952 | * |
| 15953 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15954 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15955 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15956 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15957 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15958 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15959 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15960 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15961 | */ |
| 15962 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 15963 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 15964 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 15965 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 15966 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 15967 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 15968 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 15969 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 15970 | }) |
| 15971 | public int getTextAlignment() { |
| 15972 | return (mPrivateFlags2 & TEXT_ALIGNMENT_MASK) >> TEXT_ALIGNMENT_MASK_SHIFT; |
| 15973 | } |
| 15974 | |
| 15975 | /** |
| 15976 | * Set the text alignment. |
| 15977 | * |
| 15978 | * @param textAlignment The text alignment to set. Should be one of |
| 15979 | * |
| 15980 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 15981 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 15982 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 15983 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 15984 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 15985 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 15986 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 15987 | * |
| 15988 | * @attr ref android.R.styleable#View_textAlignment |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 15989 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 15990 | */ |
| 15991 | public void setTextAlignment(int textAlignment) { |
| 15992 | if (textAlignment != getTextAlignment()) { |
| 15993 | // Reset the current and resolved text alignment |
| 15994 | mPrivateFlags2 &= ~TEXT_ALIGNMENT_MASK; |
| 15995 | resetResolvedTextAlignment(); |
| 15996 | // Set the new text alignment |
| 15997 | mPrivateFlags2 |= ((textAlignment << TEXT_ALIGNMENT_MASK_SHIFT) & TEXT_ALIGNMENT_MASK); |
| 15998 | // Refresh |
| 15999 | requestLayout(); |
| 16000 | invalidate(true); |
| 16001 | } |
| 16002 | } |
| 16003 | |
| 16004 | /** |
| 16005 | * Return the resolved text alignment. |
| 16006 | * |
| 16007 | * The resolved text alignment. This needs resolution if the value is |
| 16008 | * TEXT_ALIGNMENT_INHERIT. The resolution matches {@link #setTextAlignment(int)} if it is |
| 16009 | * not TEXT_ALIGNMENT_INHERIT, otherwise resolution proceeds up the parent chain of the view. |
| 16010 | * |
| 16011 | * @return the resolved text alignment. Returns one of: |
| 16012 | * |
| 16013 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16014 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16015 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16016 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16017 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16018 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16019 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16020 | */ |
| 16021 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16022 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16023 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16024 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16025 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16026 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16027 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16028 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16029 | }) |
| 16030 | public int getResolvedTextAlignment() { |
| 16031 | // If text alignment is not resolved, then resolve it |
| 16032 | if ((mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED) != TEXT_ALIGNMENT_RESOLVED) { |
| 16033 | resolveTextAlignment(); |
| 16034 | } |
| 16035 | return (mPrivateFlags2 & TEXT_ALIGNMENT_RESOLVED_MASK) >> TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
| 16036 | } |
| 16037 | |
| 16038 | /** |
| 16039 | * Resolve the text alignment. Will call {@link View#onResolvedTextAlignmentChanged} when |
| 16040 | * resolution is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16041 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16042 | */ |
| 16043 | public void resolveTextAlignment() { |
| 16044 | // Reset any previous text alignment resolution |
| 16045 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 16046 | |
| 16047 | if (hasRtlSupport()) { |
| 16048 | // Set resolved text alignment flag depending on text alignment flag |
| 16049 | final int textAlignment = getTextAlignment(); |
| 16050 | switch (textAlignment) { |
| 16051 | case TEXT_ALIGNMENT_INHERIT: |
| 16052 | // Check if we can resolve the text alignment |
| 16053 | if (canResolveLayoutDirection() && mParent instanceof View) { |
| 16054 | View view = (View) mParent; |
| 16055 | |
| 16056 | final int parentResolvedTextAlignment = view.getResolvedTextAlignment(); |
| 16057 | switch (parentResolvedTextAlignment) { |
| 16058 | case TEXT_ALIGNMENT_GRAVITY: |
| 16059 | case TEXT_ALIGNMENT_TEXT_START: |
| 16060 | case TEXT_ALIGNMENT_TEXT_END: |
| 16061 | case TEXT_ALIGNMENT_CENTER: |
| 16062 | case TEXT_ALIGNMENT_VIEW_START: |
| 16063 | case TEXT_ALIGNMENT_VIEW_END: |
| 16064 | // Resolved text alignment is the same as the parent resolved |
| 16065 | // text alignment |
| 16066 | mPrivateFlags2 |= |
| 16067 | (parentResolvedTextAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 16068 | break; |
| 16069 | default: |
| 16070 | // Use default resolved text alignment |
| 16071 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16072 | } |
| 16073 | } |
| 16074 | else { |
| 16075 | // We cannot do the resolution if there is no parent so use the default |
| 16076 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16077 | } |
| 16078 | break; |
| 16079 | case TEXT_ALIGNMENT_GRAVITY: |
| 16080 | case TEXT_ALIGNMENT_TEXT_START: |
| 16081 | case TEXT_ALIGNMENT_TEXT_END: |
| 16082 | case TEXT_ALIGNMENT_CENTER: |
| 16083 | case TEXT_ALIGNMENT_VIEW_START: |
| 16084 | case TEXT_ALIGNMENT_VIEW_END: |
| 16085 | // Resolved text alignment is the same as text alignment |
| 16086 | mPrivateFlags2 |= (textAlignment << TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 16087 | break; |
| 16088 | default: |
| 16089 | // Use default resolved text alignment |
| 16090 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16091 | } |
| 16092 | } else { |
| 16093 | // Use default resolved text alignment |
| 16094 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 16095 | } |
| 16096 | |
| 16097 | // Set the resolved |
| 16098 | mPrivateFlags2 |= TEXT_ALIGNMENT_RESOLVED; |
| 16099 | onResolvedTextAlignmentChanged(); |
| 16100 | } |
| 16101 | |
| 16102 | /** |
| 16103 | * Check if text alignment resolution can be done. |
| 16104 | * |
| 16105 | * @return true if text alignment resolution can be done otherwise return false. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16106 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16107 | */ |
| 16108 | public boolean canResolveTextAlignment() { |
| 16109 | switch (getTextAlignment()) { |
| 16110 | case TEXT_DIRECTION_INHERIT: |
| 16111 | return (mParent != null); |
| 16112 | default: |
| 16113 | return true; |
| 16114 | } |
| 16115 | } |
| 16116 | |
| 16117 | /** |
| 16118 | * Called when text alignment has been resolved. Subclasses that care about text alignment |
| 16119 | * resolution should override this method. |
| 16120 | * |
| 16121 | * The default implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16122 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16123 | */ |
| 16124 | public void onResolvedTextAlignmentChanged() { |
| 16125 | } |
| 16126 | |
| 16127 | /** |
| 16128 | * Reset resolved text alignment. Text alignment can be resolved with a call to |
| 16129 | * getResolvedTextAlignment(). Will call {@link View#onResolvedTextAlignmentReset} when |
| 16130 | * reset is done. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16131 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16132 | */ |
| 16133 | public void resetResolvedTextAlignment() { |
| 16134 | // Reset any previous text alignment resolution |
| 16135 | mPrivateFlags2 &= ~(TEXT_ALIGNMENT_RESOLVED | TEXT_ALIGNMENT_RESOLVED_MASK); |
| 16136 | onResolvedTextAlignmentReset(); |
| 16137 | } |
| 16138 | |
| 16139 | /** |
| 16140 | * Called when text alignment is reset. Subclasses that care about text alignment reset should |
| 16141 | * override this method and do a reset of the text alignment of their children. The default |
| 16142 | * implementation does nothing. |
Fabrice Di Meglio | 66388dc | 2012-05-03 18:51:57 -0700 | [diff] [blame] | 16143 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16144 | */ |
| 16145 | public void onResolvedTextAlignmentReset() { |
| 16146 | } |
| 16147 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16148 | // |
| 16149 | // Properties |
| 16150 | // |
| 16151 | /** |
| 16152 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 16153 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 16154 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16155 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16156 | @Override |
| 16157 | public void setValue(View object, float value) { |
| 16158 | object.setAlpha(value); |
| 16159 | } |
| 16160 | |
| 16161 | @Override |
| 16162 | public Float get(View object) { |
| 16163 | return object.getAlpha(); |
| 16164 | } |
| 16165 | }; |
| 16166 | |
| 16167 | /** |
| 16168 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 16169 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 16170 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16171 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16172 | @Override |
| 16173 | public void setValue(View object, float value) { |
| 16174 | object.setTranslationX(value); |
| 16175 | } |
| 16176 | |
| 16177 | @Override |
| 16178 | public Float get(View object) { |
| 16179 | return object.getTranslationX(); |
| 16180 | } |
| 16181 | }; |
| 16182 | |
| 16183 | /** |
| 16184 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 16185 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 16186 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16187 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16188 | @Override |
| 16189 | public void setValue(View object, float value) { |
| 16190 | object.setTranslationY(value); |
| 16191 | } |
| 16192 | |
| 16193 | @Override |
| 16194 | public Float get(View object) { |
| 16195 | return object.getTranslationY(); |
| 16196 | } |
| 16197 | }; |
| 16198 | |
| 16199 | /** |
| 16200 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 16201 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 16202 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16203 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16204 | @Override |
| 16205 | public void setValue(View object, float value) { |
| 16206 | object.setX(value); |
| 16207 | } |
| 16208 | |
| 16209 | @Override |
| 16210 | public Float get(View object) { |
| 16211 | return object.getX(); |
| 16212 | } |
| 16213 | }; |
| 16214 | |
| 16215 | /** |
| 16216 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 16217 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 16218 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16219 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16220 | @Override |
| 16221 | public void setValue(View object, float value) { |
| 16222 | object.setY(value); |
| 16223 | } |
| 16224 | |
| 16225 | @Override |
| 16226 | public Float get(View object) { |
| 16227 | return object.getY(); |
| 16228 | } |
| 16229 | }; |
| 16230 | |
| 16231 | /** |
| 16232 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 16233 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 16234 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16235 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16236 | @Override |
| 16237 | public void setValue(View object, float value) { |
| 16238 | object.setRotation(value); |
| 16239 | } |
| 16240 | |
| 16241 | @Override |
| 16242 | public Float get(View object) { |
| 16243 | return object.getRotation(); |
| 16244 | } |
| 16245 | }; |
| 16246 | |
| 16247 | /** |
| 16248 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 16249 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 16250 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16251 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16252 | @Override |
| 16253 | public void setValue(View object, float value) { |
| 16254 | object.setRotationX(value); |
| 16255 | } |
| 16256 | |
| 16257 | @Override |
| 16258 | public Float get(View object) { |
| 16259 | return object.getRotationX(); |
| 16260 | } |
| 16261 | }; |
| 16262 | |
| 16263 | /** |
| 16264 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 16265 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 16266 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16267 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16268 | @Override |
| 16269 | public void setValue(View object, float value) { |
| 16270 | object.setRotationY(value); |
| 16271 | } |
| 16272 | |
| 16273 | @Override |
| 16274 | public Float get(View object) { |
| 16275 | return object.getRotationY(); |
| 16276 | } |
| 16277 | }; |
| 16278 | |
| 16279 | /** |
| 16280 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 16281 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 16282 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16283 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16284 | @Override |
| 16285 | public void setValue(View object, float value) { |
| 16286 | object.setScaleX(value); |
| 16287 | } |
| 16288 | |
| 16289 | @Override |
| 16290 | public Float get(View object) { |
| 16291 | return object.getScaleX(); |
| 16292 | } |
| 16293 | }; |
| 16294 | |
| 16295 | /** |
| 16296 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 16297 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 16298 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16299 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16300 | @Override |
| 16301 | public void setValue(View object, float value) { |
| 16302 | object.setScaleY(value); |
| 16303 | } |
| 16304 | |
| 16305 | @Override |
| 16306 | public Float get(View object) { |
| 16307 | return object.getScaleY(); |
| 16308 | } |
| 16309 | }; |
| 16310 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16311 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16312 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 16313 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 16314 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 16315 | * modes: |
| 16316 | * <dl> |
| 16317 | * <dt>UNSPECIFIED</dt> |
| 16318 | * <dd> |
| 16319 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 16320 | * it wants. |
| 16321 | * </dd> |
| 16322 | * |
| 16323 | * <dt>EXACTLY</dt> |
| 16324 | * <dd> |
| 16325 | * The parent has determined an exact size for the child. The child is going to be |
| 16326 | * given those bounds regardless of how big it wants to be. |
| 16327 | * </dd> |
| 16328 | * |
| 16329 | * <dt>AT_MOST</dt> |
| 16330 | * <dd> |
| 16331 | * The child can be as large as it wants up to the specified size. |
| 16332 | * </dd> |
| 16333 | * </dl> |
| 16334 | * |
| 16335 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 16336 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 16337 | */ |
| 16338 | public static class MeasureSpec { |
| 16339 | private static final int MODE_SHIFT = 30; |
| 16340 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 16341 | |
| 16342 | /** |
| 16343 | * Measure specification mode: The parent has not imposed any constraint |
| 16344 | * on the child. It can be whatever size it wants. |
| 16345 | */ |
| 16346 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 16347 | |
| 16348 | /** |
| 16349 | * Measure specification mode: The parent has determined an exact size |
| 16350 | * for the child. The child is going to be given those bounds regardless |
| 16351 | * of how big it wants to be. |
| 16352 | */ |
| 16353 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 16354 | |
| 16355 | /** |
| 16356 | * Measure specification mode: The child can be as large as it wants up |
| 16357 | * to the specified size. |
| 16358 | */ |
| 16359 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 16360 | |
| 16361 | /** |
| 16362 | * Creates a measure specification based on the supplied size and mode. |
| 16363 | * |
| 16364 | * The mode must always be one of the following: |
| 16365 | * <ul> |
| 16366 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 16367 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 16368 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 16369 | * </ul> |
| 16370 | * |
| 16371 | * @param size the size of the measure specification |
| 16372 | * @param mode the mode of the measure specification |
| 16373 | * @return the measure specification based on size and mode |
| 16374 | */ |
| 16375 | public static int makeMeasureSpec(int size, int mode) { |
| 16376 | return size + mode; |
| 16377 | } |
| 16378 | |
| 16379 | /** |
| 16380 | * Extracts the mode from the supplied measure specification. |
| 16381 | * |
| 16382 | * @param measureSpec the measure specification to extract the mode from |
| 16383 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 16384 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 16385 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 16386 | */ |
| 16387 | public static int getMode(int measureSpec) { |
| 16388 | return (measureSpec & MODE_MASK); |
| 16389 | } |
| 16390 | |
| 16391 | /** |
| 16392 | * Extracts the size from the supplied measure specification. |
| 16393 | * |
| 16394 | * @param measureSpec the measure specification to extract the size from |
| 16395 | * @return the size in pixels defined in the supplied measure specification |
| 16396 | */ |
| 16397 | public static int getSize(int measureSpec) { |
| 16398 | return (measureSpec & ~MODE_MASK); |
| 16399 | } |
| 16400 | |
| 16401 | /** |
| 16402 | * Returns a String representation of the specified measure |
| 16403 | * specification. |
| 16404 | * |
| 16405 | * @param measureSpec the measure specification to convert to a String |
| 16406 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 16407 | */ |
| 16408 | public static String toString(int measureSpec) { |
| 16409 | int mode = getMode(measureSpec); |
| 16410 | int size = getSize(measureSpec); |
| 16411 | |
| 16412 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 16413 | |
| 16414 | if (mode == UNSPECIFIED) |
| 16415 | sb.append("UNSPECIFIED "); |
| 16416 | else if (mode == EXACTLY) |
| 16417 | sb.append("EXACTLY "); |
| 16418 | else if (mode == AT_MOST) |
| 16419 | sb.append("AT_MOST "); |
| 16420 | else |
| 16421 | sb.append(mode).append(" "); |
| 16422 | |
| 16423 | sb.append(size); |
| 16424 | return sb.toString(); |
| 16425 | } |
| 16426 | } |
| 16427 | |
| 16428 | class CheckForLongPress implements Runnable { |
| 16429 | |
| 16430 | private int mOriginalWindowAttachCount; |
| 16431 | |
| 16432 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 16433 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16434 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 16435 | if (performLongClick()) { |
| 16436 | mHasPerformedLongPress = true; |
| 16437 | } |
| 16438 | } |
| 16439 | } |
| 16440 | |
| 16441 | public void rememberWindowAttachCount() { |
| 16442 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 16443 | } |
| 16444 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16445 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16446 | private final class CheckForTap implements Runnable { |
| 16447 | public void run() { |
| 16448 | mPrivateFlags &= ~PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 16449 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16450 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16451 | } |
| 16452 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16453 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 16454 | private final class PerformClick implements Runnable { |
| 16455 | public void run() { |
| 16456 | performClick(); |
| 16457 | } |
| 16458 | } |
| 16459 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16460 | /** @hide */ |
| 16461 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 16462 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 16463 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16465 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 16466 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 16467 | * specific properties on this View. |
| 16468 | * |
| 16469 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 16470 | */ |
| 16471 | public ViewPropertyAnimator animate() { |
| 16472 | if (mAnimator == null) { |
| 16473 | mAnimator = new ViewPropertyAnimator(this); |
| 16474 | } |
| 16475 | return mAnimator; |
| 16476 | } |
| 16477 | |
| 16478 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16479 | * Interface definition for a callback to be invoked when a key event is |
| 16480 | * dispatched to this view. The callback will be invoked before the key |
| 16481 | * event is given to the view. |
| 16482 | */ |
| 16483 | public interface OnKeyListener { |
| 16484 | /** |
| 16485 | * Called when a key is dispatched to a view. This allows listeners to |
| 16486 | * get a chance to respond before the target view. |
| 16487 | * |
| 16488 | * @param v The view the key has been dispatched to. |
| 16489 | * @param keyCode The code for the physical key that was pressed |
| 16490 | * @param event The KeyEvent object containing full information about |
| 16491 | * the event. |
| 16492 | * @return True if the listener has consumed the event, false otherwise. |
| 16493 | */ |
| 16494 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 16495 | } |
| 16496 | |
| 16497 | /** |
| 16498 | * Interface definition for a callback to be invoked when a touch event is |
| 16499 | * dispatched to this view. The callback will be invoked before the touch |
| 16500 | * event is given to the view. |
| 16501 | */ |
| 16502 | public interface OnTouchListener { |
| 16503 | /** |
| 16504 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 16505 | * get a chance to respond before the target view. |
| 16506 | * |
| 16507 | * @param v The view the touch event has been dispatched to. |
| 16508 | * @param event The MotionEvent object containing full information about |
| 16509 | * the event. |
| 16510 | * @return True if the listener has consumed the event, false otherwise. |
| 16511 | */ |
| 16512 | boolean onTouch(View v, MotionEvent event); |
| 16513 | } |
| 16514 | |
| 16515 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 16516 | * Interface definition for a callback to be invoked when a hover event is |
| 16517 | * dispatched to this view. The callback will be invoked before the hover |
| 16518 | * event is given to the view. |
| 16519 | */ |
| 16520 | public interface OnHoverListener { |
| 16521 | /** |
| 16522 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 16523 | * get a chance to respond before the target view. |
| 16524 | * |
| 16525 | * @param v The view the hover event has been dispatched to. |
| 16526 | * @param event The MotionEvent object containing full information about |
| 16527 | * the event. |
| 16528 | * @return True if the listener has consumed the event, false otherwise. |
| 16529 | */ |
| 16530 | boolean onHover(View v, MotionEvent event); |
| 16531 | } |
| 16532 | |
| 16533 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16534 | * Interface definition for a callback to be invoked when a generic motion event is |
| 16535 | * dispatched to this view. The callback will be invoked before the generic motion |
| 16536 | * event is given to the view. |
| 16537 | */ |
| 16538 | public interface OnGenericMotionListener { |
| 16539 | /** |
| 16540 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 16541 | * get a chance to respond before the target view. |
| 16542 | * |
| 16543 | * @param v The view the generic motion event has been dispatched to. |
| 16544 | * @param event The MotionEvent object containing full information about |
| 16545 | * the event. |
| 16546 | * @return True if the listener has consumed the event, false otherwise. |
| 16547 | */ |
| 16548 | boolean onGenericMotion(View v, MotionEvent event); |
| 16549 | } |
| 16550 | |
| 16551 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16552 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 16553 | */ |
| 16554 | public interface OnLongClickListener { |
| 16555 | /** |
| 16556 | * Called when a view has been clicked and held. |
| 16557 | * |
| 16558 | * @param v The view that was clicked and held. |
| 16559 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 16560 | * @return true if the callback consumed the long click, false otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16561 | */ |
| 16562 | boolean onLongClick(View v); |
| 16563 | } |
| 16564 | |
| 16565 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16566 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 16567 | * to this view. The callback will be invoked before the hosting view's own |
| 16568 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 16569 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 16570 | * |
| 16571 | * <div class="special reference"> |
| 16572 | * <h3>Developer Guides</h3> |
| 16573 | * <p>For a guide to implementing drag and drop features, read the |
| 16574 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 16575 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16576 | */ |
| 16577 | public interface OnDragListener { |
| 16578 | /** |
| 16579 | * Called when a drag event is dispatched to a view. This allows listeners |
| 16580 | * to get a chance to override base View behavior. |
| 16581 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16582 | * @param v The View that received the drag event. |
| 16583 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 16584 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 16585 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 16586 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16587 | */ |
| 16588 | boolean onDrag(View v, DragEvent event); |
| 16589 | } |
| 16590 | |
| 16591 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16592 | * Interface definition for a callback to be invoked when the focus state of |
| 16593 | * a view changed. |
| 16594 | */ |
| 16595 | public interface OnFocusChangeListener { |
| 16596 | /** |
| 16597 | * Called when the focus state of a view has changed. |
| 16598 | * |
| 16599 | * @param v The view whose state has changed. |
| 16600 | * @param hasFocus The new focus state of v. |
| 16601 | */ |
| 16602 | void onFocusChange(View v, boolean hasFocus); |
| 16603 | } |
| 16604 | |
| 16605 | /** |
| 16606 | * Interface definition for a callback to be invoked when a view is clicked. |
| 16607 | */ |
| 16608 | public interface OnClickListener { |
| 16609 | /** |
| 16610 | * Called when a view has been clicked. |
| 16611 | * |
| 16612 | * @param v The view that was clicked. |
| 16613 | */ |
| 16614 | void onClick(View v); |
| 16615 | } |
| 16616 | |
| 16617 | /** |
| 16618 | * Interface definition for a callback to be invoked when the context menu |
| 16619 | * for this view is being built. |
| 16620 | */ |
| 16621 | public interface OnCreateContextMenuListener { |
| 16622 | /** |
| 16623 | * Called when the context menu for this view is being built. It is not |
| 16624 | * safe to hold onto the menu after this method returns. |
| 16625 | * |
| 16626 | * @param menu The context menu that is being built |
| 16627 | * @param v The view for which the context menu is being built |
| 16628 | * @param menuInfo Extra information about the item for which the |
| 16629 | * context menu should be shown. This information will vary |
| 16630 | * depending on the class of v. |
| 16631 | */ |
| 16632 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 16633 | } |
| 16634 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16635 | /** |
| 16636 | * Interface definition for a callback to be invoked when the status bar changes |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16637 | * visibility. This reports <strong>global</strong> changes to the system UI |
| 16638 | * state, not just what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16639 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 16640 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16641 | */ |
| 16642 | public interface OnSystemUiVisibilityChangeListener { |
| 16643 | /** |
| 16644 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 16645 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16646 | * |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 16647 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16648 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the |
| 16649 | * <strong>global</strong> state of the UI visibility flags, not what your |
| 16650 | * app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16651 | */ |
| 16652 | public void onSystemUiVisibilityChange(int visibility); |
| 16653 | } |
| 16654 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 16655 | /** |
| 16656 | * Interface definition for a callback to be invoked when this view is attached |
| 16657 | * or detached from its window. |
| 16658 | */ |
| 16659 | public interface OnAttachStateChangeListener { |
| 16660 | /** |
| 16661 | * Called when the view is attached to a window. |
| 16662 | * @param v The view that was attached |
| 16663 | */ |
| 16664 | public void onViewAttachedToWindow(View v); |
| 16665 | /** |
| 16666 | * Called when the view is detached from a window. |
| 16667 | * @param v The view that was detached |
| 16668 | */ |
| 16669 | public void onViewDetachedFromWindow(View v); |
| 16670 | } |
| 16671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16672 | private final class UnsetPressedState implements Runnable { |
| 16673 | public void run() { |
| 16674 | setPressed(false); |
| 16675 | } |
| 16676 | } |
| 16677 | |
| 16678 | /** |
| 16679 | * Base class for derived classes that want to save and restore their own |
| 16680 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 16681 | */ |
| 16682 | public static class BaseSavedState extends AbsSavedState { |
| 16683 | /** |
| 16684 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 16685 | * |
| 16686 | * @param source |
| 16687 | */ |
| 16688 | public BaseSavedState(Parcel source) { |
| 16689 | super(source); |
| 16690 | } |
| 16691 | |
| 16692 | /** |
| 16693 | * Constructor called by derived classes when creating their SavedState objects |
| 16694 | * |
| 16695 | * @param superState The state of the superclass of this view |
| 16696 | */ |
| 16697 | public BaseSavedState(Parcelable superState) { |
| 16698 | super(superState); |
| 16699 | } |
| 16700 | |
| 16701 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 16702 | new Parcelable.Creator<BaseSavedState>() { |
| 16703 | public BaseSavedState createFromParcel(Parcel in) { |
| 16704 | return new BaseSavedState(in); |
| 16705 | } |
| 16706 | |
| 16707 | public BaseSavedState[] newArray(int size) { |
| 16708 | return new BaseSavedState[size]; |
| 16709 | } |
| 16710 | }; |
| 16711 | } |
| 16712 | |
| 16713 | /** |
| 16714 | * A set of information given to a view when it is attached to its parent |
| 16715 | * window. |
| 16716 | */ |
| 16717 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16718 | interface Callbacks { |
| 16719 | void playSoundEffect(int effectId); |
| 16720 | boolean performHapticFeedback(int effectId, boolean always); |
| 16721 | } |
| 16722 | |
| 16723 | /** |
| 16724 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 16725 | * to a Handler. This class contains the target (View) to invalidate and |
| 16726 | * the coordinates of the dirty rectangle. |
| 16727 | * |
| 16728 | * For performance purposes, this class also implements a pool of up to |
| 16729 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 16730 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16731 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16732 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16733 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 16734 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 16735 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16736 | public InvalidateInfo newInstance() { |
| 16737 | return new InvalidateInfo(); |
| 16738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16739 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16740 | public void onAcquired(InvalidateInfo element) { |
| 16741 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16742 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16743 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 16744 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16745 | } |
| 16746 | }, POOL_LIMIT) |
| 16747 | ); |
| 16748 | |
| 16749 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16750 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16751 | |
| 16752 | View target; |
| 16753 | |
| 16754 | int left; |
| 16755 | int top; |
| 16756 | int right; |
| 16757 | int bottom; |
| 16758 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16759 | public void setNextPoolable(InvalidateInfo element) { |
| 16760 | mNext = element; |
| 16761 | } |
| 16762 | |
| 16763 | public InvalidateInfo getNextPoolable() { |
| 16764 | return mNext; |
| 16765 | } |
| 16766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16767 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16768 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16769 | } |
| 16770 | |
| 16771 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 16772 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16773 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 16774 | |
| 16775 | public boolean isPooled() { |
| 16776 | return mIsPooled; |
| 16777 | } |
| 16778 | |
| 16779 | public void setPooled(boolean isPooled) { |
| 16780 | mIsPooled = isPooled; |
| 16781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16782 | } |
| 16783 | |
| 16784 | final IWindowSession mSession; |
| 16785 | |
| 16786 | final IWindow mWindow; |
| 16787 | |
| 16788 | final IBinder mWindowToken; |
| 16789 | |
| 16790 | final Callbacks mRootCallbacks; |
| 16791 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 16792 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 16793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16794 | /** |
| 16795 | * The top view of the hierarchy. |
| 16796 | */ |
| 16797 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16799 | IBinder mPanelParentWindowToken; |
| 16800 | Surface mSurface; |
| 16801 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16802 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 16803 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 16804 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16805 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 16806 | boolean mScreenOn; |
| 16807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16808 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16809 | * Scale factor used by the compatibility mode |
| 16810 | */ |
| 16811 | float mApplicationScale; |
| 16812 | |
| 16813 | /** |
| 16814 | * Indicates whether the application is in compatibility mode |
| 16815 | */ |
| 16816 | boolean mScalingRequired; |
| 16817 | |
| 16818 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16819 | * If set, ViewAncestor doesn't use its lame animation for when the window resizes. |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16820 | */ |
| 16821 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16822 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16823 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16824 | * Left position of this view's window |
| 16825 | */ |
| 16826 | int mWindowLeft; |
| 16827 | |
| 16828 | /** |
| 16829 | * Top position of this view's window |
| 16830 | */ |
| 16831 | int mWindowTop; |
| 16832 | |
| 16833 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16834 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16835 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 16836 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 16837 | |
| 16838 | /** |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 16839 | * Describes the parts of the window that are currently completely |
| 16840 | * obscured by system UI elements. |
| 16841 | */ |
| 16842 | final Rect mSystemInsets = new Rect(); |
| 16843 | |
| 16844 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16845 | * For windows that are full-screen but using insets to layout inside |
| 16846 | * of the screen decorations, these are the current insets for the |
| 16847 | * content of the window. |
| 16848 | */ |
| 16849 | final Rect mContentInsets = new Rect(); |
| 16850 | |
| 16851 | /** |
| 16852 | * For windows that are full-screen but using insets to layout inside |
| 16853 | * of the screen decorations, these are the current insets for the |
| 16854 | * actual visible parts of the window. |
| 16855 | */ |
| 16856 | final Rect mVisibleInsets = new Rect(); |
| 16857 | |
| 16858 | /** |
| 16859 | * The internal insets given by this window. This value is |
| 16860 | * supplied by the client (through |
| 16861 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 16862 | * be given to the window manager when changed to be used in laying |
| 16863 | * out windows behind it. |
| 16864 | */ |
| 16865 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 16866 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 16867 | |
| 16868 | /** |
| 16869 | * All views in the window's hierarchy that serve as scroll containers, |
| 16870 | * used to determine if the window can be resized or must be panned |
| 16871 | * to adjust for a soft input area. |
| 16872 | */ |
| 16873 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 16874 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 16875 | final KeyEvent.DispatcherState mKeyDispatchState |
| 16876 | = new KeyEvent.DispatcherState(); |
| 16877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16878 | /** |
| 16879 | * Indicates whether the view's window currently has the focus. |
| 16880 | */ |
| 16881 | boolean mHasWindowFocus; |
| 16882 | |
| 16883 | /** |
| 16884 | * The current visibility of the window. |
| 16885 | */ |
| 16886 | int mWindowVisibility; |
| 16887 | |
| 16888 | /** |
| 16889 | * Indicates the time at which drawing started to occur. |
| 16890 | */ |
| 16891 | long mDrawingTime; |
| 16892 | |
| 16893 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 16894 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 16895 | */ |
| 16896 | boolean mIgnoreDirtyState; |
| 16897 | |
| 16898 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 16899 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 16900 | * to avoid clearing that flag prematurely. |
| 16901 | */ |
| 16902 | boolean mSetIgnoreDirtyState = false; |
| 16903 | |
| 16904 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16905 | * Indicates whether the view's window is currently in touch mode. |
| 16906 | */ |
| 16907 | boolean mInTouchMode; |
| 16908 | |
| 16909 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16910 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16911 | * the next time it performs a traversal |
| 16912 | */ |
| 16913 | boolean mRecomputeGlobalAttributes; |
| 16914 | |
| 16915 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16916 | * Always report new attributes at next traversal. |
| 16917 | */ |
| 16918 | boolean mForceReportNewAttributes; |
| 16919 | |
| 16920 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16921 | * Set during a traveral if any views want to keep the screen on. |
| 16922 | */ |
| 16923 | boolean mKeepScreenOn; |
| 16924 | |
| 16925 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16926 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 16927 | */ |
| 16928 | int mSystemUiVisibility; |
| 16929 | |
| 16930 | /** |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 16931 | * Hack to force certain system UI visibility flags to be cleared. |
| 16932 | */ |
| 16933 | int mDisabledSystemUiVisibility; |
| 16934 | |
| 16935 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16936 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 16937 | * attached. |
| 16938 | */ |
| 16939 | boolean mHasSystemUiListeners; |
| 16940 | |
| 16941 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16942 | * Set if the visibility of any views has changed. |
| 16943 | */ |
| 16944 | boolean mViewVisibilityChanged; |
| 16945 | |
| 16946 | /** |
| 16947 | * Set to true if a view has been scrolled. |
| 16948 | */ |
| 16949 | boolean mViewScrollChanged; |
| 16950 | |
| 16951 | /** |
| 16952 | * Global to the view hierarchy used as a temporary for dealing with |
| 16953 | * x/y points in the transparent region computations. |
| 16954 | */ |
| 16955 | final int[] mTransparentLocation = new int[2]; |
| 16956 | |
| 16957 | /** |
| 16958 | * Global to the view hierarchy used as a temporary for dealing with |
| 16959 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 16960 | */ |
| 16961 | final int[] mInvalidateChildLocation = new int[2]; |
| 16962 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16963 | |
| 16964 | /** |
| 16965 | * Global to the view hierarchy used as a temporary for dealing with |
| 16966 | * x/y location when view is transformed. |
| 16967 | */ |
| 16968 | final float[] mTmpTransformLocation = new float[2]; |
| 16969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16970 | /** |
| 16971 | * The view tree observer used to dispatch global events like |
| 16972 | * layout, pre-draw, touch mode change, etc. |
| 16973 | */ |
| 16974 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 16975 | |
| 16976 | /** |
| 16977 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 16978 | */ |
| 16979 | Canvas mCanvas; |
| 16980 | |
| 16981 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 16982 | * The view root impl. |
| 16983 | */ |
| 16984 | final ViewRootImpl mViewRootImpl; |
| 16985 | |
| 16986 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16987 | * A Handler supplied by a view's {@link android.view.ViewRootImpl}. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16988 | * handler can be used to pump events in the UI events queue. |
| 16989 | */ |
| 16990 | final Handler mHandler; |
| 16991 | |
| 16992 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16993 | * Temporary for use in computing invalidate rectangles while |
| 16994 | * calling up the hierarchy. |
| 16995 | */ |
| 16996 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 16997 | |
| 16998 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 16999 | * Temporary for use in computing hit areas with transformed views |
| 17000 | */ |
| 17001 | final RectF mTmpTransformRect = new RectF(); |
| 17002 | |
| 17003 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17004 | * Temporary list for use in collecting focusable descendents of a view. |
| 17005 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17006 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17008 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17009 | * The id of the window for accessibility purposes. |
| 17010 | */ |
| 17011 | int mAccessibilityWindowId = View.NO_ID; |
| 17012 | |
| 17013 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17014 | * Whether to ingore not exposed for accessibility Views when |
| 17015 | * reporting the view tree to accessibility services. |
| 17016 | */ |
| 17017 | boolean mIncludeNotImportantViews; |
| 17018 | |
| 17019 | /** |
| 17020 | * The drawable for highlighting accessibility focus. |
| 17021 | */ |
| 17022 | Drawable mAccessibilityFocusDrawable; |
| 17023 | |
| 17024 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17025 | * Show where the margins, bounds and layout bounds are for each view. |
| 17026 | */ |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 17027 | final boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17028 | |
| 17029 | /** |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 17030 | * Point used to compute visible regions. |
| 17031 | */ |
| 17032 | final Point mPoint = new Point(); |
| 17033 | |
| 17034 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17035 | * Creates a new set of attachment information with the specified |
| 17036 | * events handler and thread. |
| 17037 | * |
| 17038 | * @param handler the events handler the view must use |
| 17039 | */ |
| 17040 | AttachInfo(IWindowSession session, IWindow window, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17041 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17042 | mSession = session; |
| 17043 | mWindow = window; |
| 17044 | mWindowToken = window.asBinder(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17045 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17046 | mHandler = handler; |
| 17047 | mRootCallbacks = effectPlayer; |
| 17048 | } |
| 17049 | } |
| 17050 | |
| 17051 | /** |
| 17052 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 17053 | * is supported. This avoids keeping too many unused fields in most |
| 17054 | * instances of View.</p> |
| 17055 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17056 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17057 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17058 | /** |
| 17059 | * Scrollbars are not visible |
| 17060 | */ |
| 17061 | public static final int OFF = 0; |
| 17062 | |
| 17063 | /** |
| 17064 | * Scrollbars are visible |
| 17065 | */ |
| 17066 | public static final int ON = 1; |
| 17067 | |
| 17068 | /** |
| 17069 | * Scrollbars are fading away |
| 17070 | */ |
| 17071 | public static final int FADING = 2; |
| 17072 | |
| 17073 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17075 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17076 | public int scrollBarDefaultDelayBeforeFade; |
| 17077 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17078 | |
| 17079 | public int scrollBarSize; |
| 17080 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17081 | public float[] interpolatorValues; |
| 17082 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17083 | |
| 17084 | public final Paint paint; |
| 17085 | public final Matrix matrix; |
| 17086 | public Shader shader; |
| 17087 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17088 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 17089 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17090 | private static final float[] OPAQUE = { 255 }; |
| 17091 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17092 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17093 | /** |
| 17094 | * When fading should start. This time moves into the future every time |
| 17095 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 17096 | */ |
| 17097 | public long fadeStartTime; |
| 17098 | |
| 17099 | |
| 17100 | /** |
| 17101 | * The current state of the scrollbars: ON, OFF, or FADING |
| 17102 | */ |
| 17103 | public int state = OFF; |
| 17104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17105 | private int mLastColor; |
| 17106 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17107 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17108 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 17109 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17110 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 17111 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17112 | |
| 17113 | paint = new Paint(); |
| 17114 | matrix = new Matrix(); |
| 17115 | // use use a height of 1, and then wack the matrix each time we |
| 17116 | // actually use it. |
| 17117 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17119 | paint.setShader(shader); |
| 17120 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17121 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17122 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17124 | public void setFadeColor(int color) { |
| 17125 | if (color != 0 && color != mLastColor) { |
| 17126 | mLastColor = color; |
| 17127 | color |= 0xFF000000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17128 | |
Romain Guy | e55e1a7 | 2009-08-27 10:42:26 -0700 | [diff] [blame] | 17129 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 17130 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17132 | paint.setShader(shader); |
| 17133 | // Restore the default transfer mode (src_over) |
| 17134 | paint.setXfermode(null); |
| 17135 | } |
| 17136 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17137 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17138 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 17139 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17140 | if (now >= fadeStartTime) { |
| 17141 | |
| 17142 | // the animation fades the scrollbars out by changing |
| 17143 | // the opacity (alpha) from fully opaque to fully |
| 17144 | // transparent |
| 17145 | int nextFrame = (int) now; |
| 17146 | int framesCount = 0; |
| 17147 | |
| 17148 | Interpolator interpolator = scrollBarInterpolator; |
| 17149 | |
| 17150 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17151 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17152 | |
| 17153 | // End transparent |
| 17154 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17155 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17156 | |
| 17157 | state = FADING; |
| 17158 | |
| 17159 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 17160 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17161 | } |
| 17162 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17163 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17164 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17165 | /** |
| 17166 | * Resuable callback for sending |
| 17167 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 17168 | */ |
| 17169 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 17170 | public volatile boolean mIsPending; |
| 17171 | |
| 17172 | public void run() { |
| 17173 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 17174 | mIsPending = false; |
| 17175 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17176 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17177 | |
| 17178 | /** |
| 17179 | * <p> |
| 17180 | * This class represents a delegate that can be registered in a {@link View} |
| 17181 | * to enhance accessibility support via composition rather via inheritance. |
| 17182 | * It is specifically targeted to widget developers that extend basic View |
| 17183 | * classes i.e. classes in package android.view, that would like their |
| 17184 | * applications to be backwards compatible. |
| 17185 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 17186 | * <div class="special reference"> |
| 17187 | * <h3>Developer Guides</h3> |
| 17188 | * <p>For more information about making applications accessible, read the |
| 17189 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 17190 | * developer guide.</p> |
| 17191 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17192 | * <p> |
| 17193 | * A scenario in which a developer would like to use an accessibility delegate |
| 17194 | * is overriding a method introduced in a later API version then the minimal API |
| 17195 | * version supported by the application. For example, the method |
| 17196 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 17197 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 17198 | * developer would like his application to run on API version 4 devices (assuming |
| 17199 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 17200 | * of this method, instead of overriding the method which would break the application's |
| 17201 | * backwards compatibility, he can override the corresponding method in this |
| 17202 | * delegate and register the delegate in the target View if the API version of |
| 17203 | * the system is high enough i.e. the API version is same or higher to the API |
| 17204 | * version that introduced |
| 17205 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 17206 | * </p> |
| 17207 | * <p> |
| 17208 | * Here is an example implementation: |
| 17209 | * </p> |
| 17210 | * <code><pre><p> |
| 17211 | * if (Build.VERSION.SDK_INT >= 14) { |
| 17212 | * // If the API version is equal of higher than the version in |
| 17213 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 17214 | * // register a delegate with a customized implementation. |
| 17215 | * View view = findViewById(R.id.view_id); |
| 17216 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 17217 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 17218 | * AccessibilityNodeInfo info) { |
| 17219 | * // Let the default implementation populate the info. |
| 17220 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 17221 | * // Set some other information. |
| 17222 | * info.setEnabled(host.isEnabled()); |
| 17223 | * } |
| 17224 | * }); |
| 17225 | * } |
| 17226 | * </code></pre></p> |
| 17227 | * <p> |
| 17228 | * This delegate contains methods that correspond to the accessibility methods |
| 17229 | * in View. If a delegate has been specified the implementation in View hands |
| 17230 | * off handling to the corresponding method in this delegate. The default |
| 17231 | * implementation the delegate methods behaves exactly as the corresponding |
| 17232 | * method in View for the case of no accessibility delegate been set. Hence, |
| 17233 | * to customize the behavior of a View method, clients can override only the |
| 17234 | * corresponding delegate method without altering the behavior of the rest |
| 17235 | * accessibility related methods of the host view. |
| 17236 | * </p> |
| 17237 | */ |
| 17238 | public static class AccessibilityDelegate { |
| 17239 | |
| 17240 | /** |
| 17241 | * Sends an accessibility event of the given type. If accessibility is not |
| 17242 | * enabled this method has no effect. |
| 17243 | * <p> |
| 17244 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 17245 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 17246 | * been set. |
| 17247 | * </p> |
| 17248 | * |
| 17249 | * @param host The View hosting the delegate. |
| 17250 | * @param eventType The type of the event to send. |
| 17251 | * |
| 17252 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 17253 | */ |
| 17254 | public void sendAccessibilityEvent(View host, int eventType) { |
| 17255 | host.sendAccessibilityEventInternal(eventType); |
| 17256 | } |
| 17257 | |
| 17258 | /** |
| 17259 | * Sends an accessibility event. This method behaves exactly as |
| 17260 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 17261 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 17262 | * accessibility is enabled. |
| 17263 | * <p> |
| 17264 | * The default implementation behaves as |
| 17265 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17266 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 17267 | * the case of no accessibility delegate been set. |
| 17268 | * </p> |
| 17269 | * |
| 17270 | * @param host The View hosting the delegate. |
| 17271 | * @param event The event to send. |
| 17272 | * |
| 17273 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17274 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17275 | */ |
| 17276 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 17277 | host.sendAccessibilityEventUncheckedInternal(event); |
| 17278 | } |
| 17279 | |
| 17280 | /** |
| 17281 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 17282 | * to its children for adding their text content to the event. |
| 17283 | * <p> |
| 17284 | * The default implementation behaves as |
| 17285 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17286 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17287 | * the case of no accessibility delegate been set. |
| 17288 | * </p> |
| 17289 | * |
| 17290 | * @param host The View hosting the delegate. |
| 17291 | * @param event The event. |
| 17292 | * @return True if the event population was completed. |
| 17293 | * |
| 17294 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17295 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17296 | */ |
| 17297 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17298 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 17299 | } |
| 17300 | |
| 17301 | /** |
| 17302 | * Gives a chance to the host View to populate the accessibility event with its |
| 17303 | * text content. |
| 17304 | * <p> |
| 17305 | * The default implementation behaves as |
| 17306 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17307 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17308 | * the case of no accessibility delegate been set. |
| 17309 | * </p> |
| 17310 | * |
| 17311 | * @param host The View hosting the delegate. |
| 17312 | * @param event The accessibility event which to populate. |
| 17313 | * |
| 17314 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17315 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17316 | */ |
| 17317 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17318 | host.onPopulateAccessibilityEventInternal(event); |
| 17319 | } |
| 17320 | |
| 17321 | /** |
| 17322 | * Initializes an {@link AccessibilityEvent} with information about the |
| 17323 | * the host View which is the event source. |
| 17324 | * <p> |
| 17325 | * The default implementation behaves as |
| 17326 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17327 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 17328 | * the case of no accessibility delegate been set. |
| 17329 | * </p> |
| 17330 | * |
| 17331 | * @param host The View hosting the delegate. |
| 17332 | * @param event The event to initialize. |
| 17333 | * |
| 17334 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17335 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17336 | */ |
| 17337 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17338 | host.onInitializeAccessibilityEventInternal(event); |
| 17339 | } |
| 17340 | |
| 17341 | /** |
| 17342 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 17343 | * <p> |
| 17344 | * The default implementation behaves as |
| 17345 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17346 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 17347 | * the case of no accessibility delegate been set. |
| 17348 | * </p> |
| 17349 | * |
| 17350 | * @param host The View hosting the delegate. |
| 17351 | * @param info The instance to initialize. |
| 17352 | * |
| 17353 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17354 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17355 | */ |
| 17356 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 17357 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 17358 | } |
| 17359 | |
| 17360 | /** |
| 17361 | * Called when a child of the host View has requested sending an |
| 17362 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 17363 | * to augment the event. |
| 17364 | * <p> |
| 17365 | * The default implementation behaves as |
| 17366 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17367 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 17368 | * the case of no accessibility delegate been set. |
| 17369 | * </p> |
| 17370 | * |
| 17371 | * @param host The View hosting the delegate. |
| 17372 | * @param child The child which requests sending the event. |
| 17373 | * @param event The event to be sent. |
| 17374 | * @return True if the event should be sent |
| 17375 | * |
| 17376 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17377 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17378 | */ |
| 17379 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 17380 | AccessibilityEvent event) { |
| 17381 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 17382 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 17383 | |
| 17384 | /** |
| 17385 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 17386 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 17387 | * that explore the window content. |
| 17388 | * <p> |
| 17389 | * The default implementation behaves as |
| 17390 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 17391 | * the case of no accessibility delegate been set. |
| 17392 | * </p> |
| 17393 | * |
| 17394 | * @return The provider. |
| 17395 | * |
| 17396 | * @see AccessibilityNodeProvider |
| 17397 | */ |
| 17398 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 17399 | return null; |
| 17400 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17401 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17402 | } |