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; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 42 | import android.hardware.display.DisplayManager; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 43 | import android.hardware.display.DisplayManagerGlobal; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 44 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Handler; |
| 46 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.Parcel; |
| 48 | import android.os.Parcelable; |
| 49 | import android.os.RemoteException; |
| 50 | import android.os.SystemClock; |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 51 | import android.os.SystemProperties; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 53 | import android.util.FloatProperty; |
| 54 | import android.util.LocaleUtil; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.util.Log; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 56 | import android.util.Pool; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 57 | import android.util.Poolable; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 58 | import android.util.PoolableManager; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 59 | import android.util.Pools; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 60 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 61 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 62 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.view.ContextMenu.ContextMenuInfo; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 64 | import android.view.AccessibilityIterators.TextSegmentIterator; |
| 65 | import android.view.AccessibilityIterators.CharacterTextSegmentIterator; |
| 66 | import android.view.AccessibilityIterators.WordTextSegmentIterator; |
| 67 | import android.view.AccessibilityIterators.ParagraphTextSegmentIterator; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 68 | import android.view.accessibility.AccessibilityEvent; |
| 69 | import android.view.accessibility.AccessibilityEventSource; |
| 70 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 71 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 72 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 74 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 75 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 76 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.view.inputmethod.InputConnection; |
| 78 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.widget.ScrollBarDrawable; |
| 80 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 81 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 82 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 83 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 84 | import com.android.internal.R; |
| 85 | import com.android.internal.util.Predicate; |
| 86 | import com.android.internal.view.menu.MenuBuilder; |
| 87 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 88 | import java.lang.ref.WeakReference; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 89 | import java.lang.reflect.InvocationTargetException; |
| 90 | import java.lang.reflect.Method; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import java.util.ArrayList; |
| 92 | import java.util.Arrays; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 93 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 94 | import java.util.concurrent.CopyOnWriteArrayList; |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 95 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * <p> |
| 99 | * This class represents the basic building block for user interface components. A View |
| 100 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 101 | * 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] | 102 | * 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] | 103 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 104 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 105 | * their layout properties. |
| 106 | * </p> |
| 107 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 108 | * <div class="special reference"> |
| 109 | * <h3>Developer Guides</h3> |
| 110 | * <p>For information about using this class to develop your application's user interface, |
| 111 | * 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] | 112 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 113 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | * <a name="Using"></a> |
| 115 | * <h3>Using Views</h3> |
| 116 | * <p> |
| 117 | * All of the views in a window are arranged in a single tree. You can add views |
| 118 | * either from code or by specifying a tree of views in one or more XML layout |
| 119 | * files. There are many specialized subclasses of views that act as controls or |
| 120 | * are capable of displaying text, images, or other content. |
| 121 | * </p> |
| 122 | * <p> |
| 123 | * Once you have created a tree of views, there are typically a few types of |
| 124 | * common operations you may wish to perform: |
| 125 | * <ul> |
| 126 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 127 | * {@link android.widget.TextView}. The available properties and the methods |
| 128 | * that set them will vary among the different subclasses of views. Note that |
| 129 | * properties that are known at build time can be set in the XML layout |
| 130 | * files.</li> |
| 131 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 132 | * response to user input. To force focus to a specific view, call |
| 133 | * {@link #requestFocus}.</li> |
| 134 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 135 | * that will be notified when something interesting happens to the view. For |
| 136 | * example, all views will let you set a listener to be notified when the view |
| 137 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 138 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 139 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 140 | * 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] | 141 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 142 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | * </ul> |
| 144 | * </p> |
| 145 | * <p><em> |
| 146 | * Note: The Android framework is responsible for measuring, laying out and |
| 147 | * drawing views. You should not call methods that perform these actions on |
| 148 | * views yourself unless you are actually implementing a |
| 149 | * {@link android.view.ViewGroup}. |
| 150 | * </em></p> |
| 151 | * |
| 152 | * <a name="Lifecycle"></a> |
| 153 | * <h3>Implementing a Custom View</h3> |
| 154 | * |
| 155 | * <p> |
| 156 | * To implement a custom view, you will usually begin by providing overrides for |
| 157 | * some of the standard methods that the framework calls on all views. You do |
| 158 | * not need to override all of these methods. In fact, you can start by just |
| 159 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 160 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 161 | * <thead> |
| 162 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 163 | * </thead> |
| 164 | * |
| 165 | * <tbody> |
| 166 | * <tr> |
| 167 | * <td rowspan="2">Creation</td> |
| 168 | * <td>Constructors</td> |
| 169 | * <td>There is a form of the constructor that are called when the view |
| 170 | * is created from code and a form that is called when the view is |
| 171 | * inflated from a layout file. The second form should parse and apply |
| 172 | * any attributes defined in the layout file. |
| 173 | * </td> |
| 174 | * </tr> |
| 175 | * <tr> |
| 176 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 177 | * <td>Called after a view and all of its children has been inflated |
| 178 | * from XML.</td> |
| 179 | * </tr> |
| 180 | * |
| 181 | * <tr> |
| 182 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 183 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | * <td>Called to determine the size requirements for this view and 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 #onLayout(boolean, 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 this view should assign a size and position to all |
| 191 | * of its children. |
| 192 | * </td> |
| 193 | * </tr> |
| 194 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 195 | * <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] | 196 | * <td>Called when the size of this view has changed. |
| 197 | * </td> |
| 198 | * </tr> |
| 199 | * |
| 200 | * <tr> |
| 201 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 202 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | * <td>Called when the view should render its content. |
| 204 | * </td> |
| 205 | * </tr> |
| 206 | * |
| 207 | * <tr> |
| 208 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 209 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 210 | * <td>Called when a new hardware key event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | * </td> |
| 212 | * </tr> |
| 213 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 214 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 215 | * <td>Called when a hardware key up event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | * </td> |
| 217 | * </tr> |
| 218 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 219 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | * <td>Called when a trackball motion event occurs. |
| 221 | * </td> |
| 222 | * </tr> |
| 223 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 224 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | * <td>Called when a touch screen motion event occurs. |
| 226 | * </td> |
| 227 | * </tr> |
| 228 | * |
| 229 | * <tr> |
| 230 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 231 | * <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] | 232 | * <td>Called when the view gains or loses focus. |
| 233 | * </td> |
| 234 | * </tr> |
| 235 | * |
| 236 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 237 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | * <td>Called when the window containing the view gains or loses focus. |
| 239 | * </td> |
| 240 | * </tr> |
| 241 | * |
| 242 | * <tr> |
| 243 | * <td rowspan="3">Attaching</td> |
| 244 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 245 | * <td>Called when the view is attached to a window. |
| 246 | * </td> |
| 247 | * </tr> |
| 248 | * |
| 249 | * <tr> |
| 250 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 251 | * <td>Called when the view is detached from its window. |
| 252 | * </td> |
| 253 | * </tr> |
| 254 | * |
| 255 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 256 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | * <td>Called when the visibility of the window containing the view |
| 258 | * has changed. |
| 259 | * </td> |
| 260 | * </tr> |
| 261 | * </tbody> |
| 262 | * |
| 263 | * </table> |
| 264 | * </p> |
| 265 | * |
| 266 | * <a name="IDs"></a> |
| 267 | * <h3>IDs</h3> |
| 268 | * Views may have an integer id associated with them. These ids are typically |
| 269 | * assigned in the layout XML files, and are used to find specific views within |
| 270 | * the view tree. A common pattern is to: |
| 271 | * <ul> |
| 272 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 273 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 274 | * <Button |
| 275 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | * android:layout_width="wrap_content" |
| 277 | * android:layout_height="wrap_content" |
| 278 | * android:text="@string/my_button_text"/> |
| 279 | * </pre></li> |
| 280 | * <li>From the onCreate method of an Activity, find the Button |
| 281 | * <pre class="prettyprint"> |
| 282 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 283 | * </pre></li> |
| 284 | * </ul> |
| 285 | * <p> |
| 286 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 287 | * ensure that they are at least unique within the part of the tree you are |
| 288 | * searching. |
| 289 | * </p> |
| 290 | * |
| 291 | * <a name="Position"></a> |
| 292 | * <h3>Position</h3> |
| 293 | * <p> |
| 294 | * The geometry of a view is that of a rectangle. A view has a location, |
| 295 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 296 | * two dimensions, expressed as a width and a height. The unit for location |
| 297 | * and dimensions is the pixel. |
| 298 | * </p> |
| 299 | * |
| 300 | * <p> |
| 301 | * It is possible to retrieve the location of a view by invoking the methods |
| 302 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 303 | * coordinate of the rectangle representing the view. The latter returns the |
| 304 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 305 | * both return the location of the view relative to its parent. For instance, |
| 306 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 307 | * right of the left edge of its direct parent. |
| 308 | * </p> |
| 309 | * |
| 310 | * <p> |
| 311 | * In addition, several convenience methods are offered to avoid unnecessary |
| 312 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 313 | * These methods return the coordinates of the right and bottom edges of the |
| 314 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 315 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 316 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 317 | * </p> |
| 318 | * |
| 319 | * <a name="SizePaddingMargins"></a> |
| 320 | * <h3>Size, padding and margins</h3> |
| 321 | * <p> |
| 322 | * The size of a view is expressed with a width and a height. A view actually |
| 323 | * possess two pairs of width and height values. |
| 324 | * </p> |
| 325 | * |
| 326 | * <p> |
| 327 | * The first pair is known as <em>measured width</em> and |
| 328 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 329 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 330 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 331 | * and {@link #getMeasuredHeight()}. |
| 332 | * </p> |
| 333 | * |
| 334 | * <p> |
| 335 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 336 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 337 | * dimensions define the actual size of the view on screen, at drawing time and |
| 338 | * after layout. These values may, but do not have to, be different from the |
| 339 | * measured width and height. The width and height can be obtained by calling |
| 340 | * {@link #getWidth()} and {@link #getHeight()}. |
| 341 | * </p> |
| 342 | * |
| 343 | * <p> |
| 344 | * To measure its dimensions, a view takes into account its padding. The padding |
| 345 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 346 | * Padding can be used to offset the content of the view by a specific amount of |
| 347 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 348 | * 2 pixels to the right of the left edge. Padding can be set using the |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 349 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 350 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 351 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 352 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | * </p> |
| 354 | * |
| 355 | * <p> |
| 356 | * Even though a view can define a padding, it does not provide any support for |
| 357 | * margins. However, view groups provide such a support. Refer to |
| 358 | * {@link android.view.ViewGroup} and |
| 359 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 360 | * </p> |
| 361 | * |
| 362 | * <a name="Layout"></a> |
| 363 | * <h3>Layout</h3> |
| 364 | * <p> |
| 365 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 366 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 367 | * of the view tree. Each view pushes dimension specifications down the tree |
| 368 | * during the recursion. At the end of the measure pass, every view has stored |
| 369 | * its measurements. The second pass happens in |
| 370 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 371 | * this pass each parent is responsible for positioning all of its children |
| 372 | * using the sizes computed in the measure pass. |
| 373 | * </p> |
| 374 | * |
| 375 | * <p> |
| 376 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 377 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 378 | * that view's descendants. A view's measured width and measured height values |
| 379 | * must respect the constraints imposed by the view's parents. This guarantees |
| 380 | * that at the end of the measure pass, all parents accept all of their |
| 381 | * children's measurements. A parent view may call measure() more than once on |
| 382 | * its children. For example, the parent may measure each child once with |
| 383 | * unspecified dimensions to find out how big they want to be, then call |
| 384 | * measure() on them again with actual numbers if the sum of all the children's |
| 385 | * unconstrained sizes is too big or too small. |
| 386 | * </p> |
| 387 | * |
| 388 | * <p> |
| 389 | * The measure pass uses two classes to communicate dimensions. The |
| 390 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 391 | * want to be measured and positioned. The base LayoutParams class just |
| 392 | * describes how big the view wants to be for both width and height. For each |
| 393 | * dimension, it can specify one of: |
| 394 | * <ul> |
| 395 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 396 | * <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] | 397 | * (minus padding) |
| 398 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 399 | * enclose its content (plus padding). |
| 400 | * </ul> |
| 401 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 402 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 403 | * an X and Y value. |
| 404 | * </p> |
| 405 | * |
| 406 | * <p> |
| 407 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 408 | * child. A MeasureSpec can be in one of three modes: |
| 409 | * <ul> |
| 410 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 411 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 412 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 413 | * tall the child view wants to be given a width of 240 pixels. |
| 414 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 415 | * child. The child must use this size, and guarantee that all of its |
| 416 | * descendants will fit within this size. |
| 417 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 418 | * child. The child must gurantee that it and all of its descendants will fit |
| 419 | * within this size. |
| 420 | * </ul> |
| 421 | * </p> |
| 422 | * |
| 423 | * <p> |
| 424 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 425 | * called by a view on itself when it believes that is can no longer fit within |
| 426 | * its current bounds. |
| 427 | * </p> |
| 428 | * |
| 429 | * <a name="Drawing"></a> |
| 430 | * <h3>Drawing</h3> |
| 431 | * <p> |
| 432 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 433 | * 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] | 434 | * this means that parents will draw before (i.e., behind) their children, with |
| 435 | * siblings drawn in the order they appear in the tree. |
| 436 | * If you set a background drawable for a View, then the View will draw it for you |
| 437 | * before calling back to its <code>onDraw()</code> method. |
| 438 | * </p> |
| 439 | * |
| 440 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 441 | * 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] | 442 | * </p> |
| 443 | * |
| 444 | * <p> |
| 445 | * To force a view to draw, call {@link #invalidate()}. |
| 446 | * </p> |
| 447 | * |
| 448 | * <a name="EventHandlingThreading"></a> |
| 449 | * <h3>Event Handling and Threading</h3> |
| 450 | * <p> |
| 451 | * The basic cycle of a view is as follows: |
| 452 | * <ol> |
| 453 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 454 | * handles the event and notifies any listeners.</li> |
| 455 | * <li>If in the course of processing the event, the view's bounds may need |
| 456 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 457 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 458 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 459 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 460 | * the framework will take care of measuring, laying out, and drawing the tree |
| 461 | * as appropriate.</li> |
| 462 | * </ol> |
| 463 | * </p> |
| 464 | * |
| 465 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 466 | * the UI thread when calling any method on any view.</em> |
| 467 | * If you are doing work on other threads and want to update the state of a view |
| 468 | * from that thread, you should use a {@link Handler}. |
| 469 | * </p> |
| 470 | * |
| 471 | * <a name="FocusHandling"></a> |
| 472 | * <h3>Focus Handling</h3> |
| 473 | * <p> |
| 474 | * The framework will handle routine focus movement in response to user input. |
| 475 | * This includes changing the focus as views are removed or hidden, or as new |
| 476 | * views become available. Views indicate their willingness to take focus |
| 477 | * through the {@link #isFocusable} method. To change whether a view can take |
| 478 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 479 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 480 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 481 | * </p> |
| 482 | * <p> |
| 483 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 484 | * given direction. In rare cases, the default algorithm may not match the |
| 485 | * intended behavior of the developer. In these situations, you can provide |
| 486 | * explicit overrides by using these XML attributes in the layout file: |
| 487 | * <pre> |
| 488 | * nextFocusDown |
| 489 | * nextFocusLeft |
| 490 | * nextFocusRight |
| 491 | * nextFocusUp |
| 492 | * </pre> |
| 493 | * </p> |
| 494 | * |
| 495 | * |
| 496 | * <p> |
| 497 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 498 | * </p> |
| 499 | * |
| 500 | * <a name="TouchMode"></a> |
| 501 | * <h3>Touch Mode</h3> |
| 502 | * <p> |
| 503 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 504 | * necessary to give focus to actionable items such as buttons so the user can see |
| 505 | * what will take input. If the device has touch capabilities, however, and the user |
| 506 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 507 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 508 | * for interaction named 'touch mode'. |
| 509 | * </p> |
| 510 | * <p> |
| 511 | * For a touch capable device, once the user touches the screen, the device |
| 512 | * will enter touch mode. From this point onward, only views for which |
| 513 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 514 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 515 | * only fire the on click listeners. |
| 516 | * </p> |
| 517 | * <p> |
| 518 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 519 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 520 | * with the user interface without touching the screen again. |
| 521 | * </p> |
| 522 | * <p> |
| 523 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 524 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 525 | * </p> |
| 526 | * |
| 527 | * <a name="Scrolling"></a> |
| 528 | * <h3>Scrolling</h3> |
| 529 | * <p> |
| 530 | * The framework provides basic support for views that wish to internally |
| 531 | * scroll their content. This includes keeping track of the X and Y scroll |
| 532 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 533 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 534 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | * </p> |
| 536 | * |
| 537 | * <a name="Tags"></a> |
| 538 | * <h3>Tags</h3> |
| 539 | * <p> |
| 540 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 541 | * extra piece of information that can be associated with a view. They are most |
| 542 | * often used as a convenience to store data related to views in the views |
| 543 | * themselves rather than by putting them in a separate structure. |
| 544 | * </p> |
| 545 | * |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 546 | * <a name="Properties"></a> |
| 547 | * <h3>Properties</h3> |
| 548 | * <p> |
| 549 | * The View class exposes an {@link #ALPHA} property, as well as several transform-related |
| 550 | * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are |
| 551 | * available both in the {@link Property} form as well as in similarly-named setter/getter |
| 552 | * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can |
| 553 | * be used to set persistent state associated with these rendering-related properties on the view. |
| 554 | * The properties and methods can also be used in conjunction with |
| 555 | * {@link android.animation.Animator Animator}-based animations, described more in the |
| 556 | * <a href="#Animation">Animation</a> section. |
| 557 | * </p> |
| 558 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | * <a name="Animation"></a> |
| 560 | * <h3>Animation</h3> |
| 561 | * <p> |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 562 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 563 | * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based |
| 564 | * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and |
| 565 | * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 |
| 566 | * {@link android.view.animation.Animation Animation}-based classes, which instead animate only |
| 567 | * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class |
| 568 | * makes animating these View properties particularly easy and efficient. |
| 569 | * </p> |
| 570 | * <p> |
| 571 | * 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] | 572 | * You can attach an {@link Animation} object to a view using |
| 573 | * {@link #setAnimation(Animation)} or |
| 574 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 575 | * rotation, translation and alpha of a view over time. If the animation is |
| 576 | * attached to a view that has children, the animation will affect the entire |
| 577 | * subtree rooted by that node. When an animation is started, the framework will |
| 578 | * take care of redrawing the appropriate views until the animation completes. |
| 579 | * </p> |
| 580 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 581 | * <a name="Security"></a> |
| 582 | * <h3>Security</h3> |
| 583 | * <p> |
| 584 | * Sometimes it is essential that an application be able to verify that an action |
| 585 | * is being performed with the full knowledge and consent of the user, such as |
| 586 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 587 | * Unfortunately, a malicious application could try to spoof the user into |
| 588 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 589 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 590 | * improve the security of views that provide access to sensitive functionality. |
| 591 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 592 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 593 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 594 | * will discard touches that are received whenever the view's window is obscured by |
| 595 | * another visible window. As a result, the view will not receive touches whenever a |
| 596 | * toast, dialog or other window appears above the view's window. |
| 597 | * </p><p> |
| 598 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 599 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 600 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 601 | * </p> |
| 602 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 603 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 604 | * @attr ref android.R.styleable#View_background |
| 605 | * @attr ref android.R.styleable#View_clickable |
| 606 | * @attr ref android.R.styleable#View_contentDescription |
| 607 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 608 | * @attr ref android.R.styleable#View_duplicateParentState |
| 609 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 610 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 611 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 612 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 613 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 615 | * @attr ref android.R.styleable#View_isScrollContainer |
| 616 | * @attr ref android.R.styleable#View_focusable |
| 617 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 618 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 619 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 620 | * @attr ref android.R.styleable#View_layerType |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 621 | * @attr ref android.R.styleable#View_longClickable |
| 622 | * @attr ref android.R.styleable#View_minHeight |
| 623 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | * @attr ref android.R.styleable#View_nextFocusDown |
| 625 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 626 | * @attr ref android.R.styleable#View_nextFocusRight |
| 627 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 628 | * @attr ref android.R.styleable#View_onClick |
| 629 | * @attr ref android.R.styleable#View_padding |
| 630 | * @attr ref android.R.styleable#View_paddingBottom |
| 631 | * @attr ref android.R.styleable#View_paddingLeft |
| 632 | * @attr ref android.R.styleable#View_paddingRight |
| 633 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 634 | * @attr ref android.R.styleable#View_paddingStart |
| 635 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 636 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 637 | * @attr ref android.R.styleable#View_rotation |
| 638 | * @attr ref android.R.styleable#View_rotationX |
| 639 | * @attr ref android.R.styleable#View_rotationY |
| 640 | * @attr ref android.R.styleable#View_scaleX |
| 641 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | * @attr ref android.R.styleable#View_scrollX |
| 643 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 644 | * @attr ref android.R.styleable#View_scrollbarSize |
| 645 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 646 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 647 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 648 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 650 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 652 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 653 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 654 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 655 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 656 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 657 | * @attr ref android.R.styleable#View_textAlignment |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 658 | * @attr ref android.R.styleable#View_transformPivotX |
| 659 | * @attr ref android.R.styleable#View_transformPivotY |
| 660 | * @attr ref android.R.styleable#View_translationX |
| 661 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 662 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | * |
| 664 | * @see android.view.ViewGroup |
| 665 | */ |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 666 | public class View implements Drawable.Callback, KeyEvent.Callback, |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 667 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | private static final boolean DBG = false; |
| 669 | |
| 670 | /** |
| 671 | * The logging tag used by this class with android.util.Log. |
| 672 | */ |
| 673 | protected static final String VIEW_LOG_TAG = "View"; |
| 674 | |
| 675 | /** |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 676 | * When set to true, apps will draw debugging information about their layouts. |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 677 | * |
| 678 | * @hide |
| 679 | */ |
| 680 | public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout"; |
| 681 | |
| 682 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | * Used to mark a View that has no ID. |
| 684 | */ |
| 685 | public static final int NO_ID = -1; |
| 686 | |
| 687 | /** |
| 688 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 689 | * calling setFlags. |
| 690 | */ |
| 691 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 692 | |
| 693 | /** |
| 694 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 695 | * setFlags. |
| 696 | */ |
| 697 | private static final int FOCUSABLE = 0x00000001; |
| 698 | |
| 699 | /** |
| 700 | * Mask for use with setFlags indicating bits used for focus. |
| 701 | */ |
| 702 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 703 | |
| 704 | /** |
| 705 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 706 | */ |
| 707 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 708 | |
| 709 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 710 | * This view is visible. |
| 711 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 712 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | */ |
| 714 | public static final int VISIBLE = 0x00000000; |
| 715 | |
| 716 | /** |
| 717 | * 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] | 718 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 719 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | */ |
| 721 | public static final int INVISIBLE = 0x00000004; |
| 722 | |
| 723 | /** |
| 724 | * 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] | 725 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 726 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | */ |
| 728 | public static final int GONE = 0x00000008; |
| 729 | |
| 730 | /** |
| 731 | * Mask for use with setFlags indicating bits used for visibility. |
| 732 | * {@hide} |
| 733 | */ |
| 734 | static final int VISIBILITY_MASK = 0x0000000C; |
| 735 | |
| 736 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 737 | |
| 738 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 739 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | * Use with ENABLED_MASK when calling setFlags. |
| 741 | * {@hide} |
| 742 | */ |
| 743 | static final int ENABLED = 0x00000000; |
| 744 | |
| 745 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 746 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | * Use with ENABLED_MASK when calling setFlags. |
| 748 | * {@hide} |
| 749 | */ |
| 750 | static final int DISABLED = 0x00000020; |
| 751 | |
| 752 | /** |
| 753 | * Mask for use with setFlags indicating bits used for indicating whether |
| 754 | * this view is enabled |
| 755 | * {@hide} |
| 756 | */ |
| 757 | static final int ENABLED_MASK = 0x00000020; |
| 758 | |
| 759 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 760 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 761 | * called and further optimizations will be performed. It is okay to have |
| 762 | * 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] | 763 | * {@hide} |
| 764 | */ |
| 765 | static final int WILL_NOT_DRAW = 0x00000080; |
| 766 | |
| 767 | /** |
| 768 | * Mask for use with setFlags indicating bits used for indicating whether |
| 769 | * this view is will draw |
| 770 | * {@hide} |
| 771 | */ |
| 772 | static final int DRAW_MASK = 0x00000080; |
| 773 | |
| 774 | /** |
| 775 | * <p>This view doesn't show scrollbars.</p> |
| 776 | * {@hide} |
| 777 | */ |
| 778 | static final int SCROLLBARS_NONE = 0x00000000; |
| 779 | |
| 780 | /** |
| 781 | * <p>This view shows horizontal scrollbars.</p> |
| 782 | * {@hide} |
| 783 | */ |
| 784 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 785 | |
| 786 | /** |
| 787 | * <p>This view shows vertical scrollbars.</p> |
| 788 | * {@hide} |
| 789 | */ |
| 790 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 791 | |
| 792 | /** |
| 793 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 794 | * scrollbars are enabled.</p> |
| 795 | * {@hide} |
| 796 | */ |
| 797 | static final int SCROLLBARS_MASK = 0x00000300; |
| 798 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 799 | /** |
| 800 | * Indicates that the view should filter touches when its window is obscured. |
| 801 | * Refer to the class comments for more information about this security feature. |
| 802 | * {@hide} |
| 803 | */ |
| 804 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 805 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 806 | /** |
| 807 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 808 | * that they are optional and should be skipped if the window has |
| 809 | * requested system UI flags that ignore those insets for layout. |
| 810 | */ |
| 811 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | |
| 813 | /** |
| 814 | * <p>This view doesn't show fading edges.</p> |
| 815 | * {@hide} |
| 816 | */ |
| 817 | static final int FADING_EDGE_NONE = 0x00000000; |
| 818 | |
| 819 | /** |
| 820 | * <p>This view shows horizontal fading edges.</p> |
| 821 | * {@hide} |
| 822 | */ |
| 823 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 824 | |
| 825 | /** |
| 826 | * <p>This view shows vertical fading edges.</p> |
| 827 | * {@hide} |
| 828 | */ |
| 829 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 830 | |
| 831 | /** |
| 832 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 833 | * fading edges are enabled.</p> |
| 834 | * {@hide} |
| 835 | */ |
| 836 | static final int FADING_EDGE_MASK = 0x00003000; |
| 837 | |
| 838 | /** |
| 839 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 840 | * to clicks by notifying the OnClickListener.<p> |
| 841 | * {@hide} |
| 842 | */ |
| 843 | static final int CLICKABLE = 0x00004000; |
| 844 | |
| 845 | /** |
| 846 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 847 | * {@hide} |
| 848 | */ |
| 849 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 850 | |
| 851 | /** |
| 852 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 853 | * {@hide} |
| 854 | */ |
| 855 | static final int SAVE_DISABLED = 0x000010000; |
| 856 | |
| 857 | /** |
| 858 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 859 | * property.</p> |
| 860 | * {@hide} |
| 861 | */ |
| 862 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 863 | |
| 864 | /** |
| 865 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 866 | * {@hide} |
| 867 | */ |
| 868 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 869 | |
| 870 | /** |
| 871 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 872 | * {@hide} |
| 873 | */ |
| 874 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 875 | |
| 876 | /** |
| 877 | * <p>Enables low quality mode for the drawing cache.</p> |
| 878 | */ |
| 879 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 880 | |
| 881 | /** |
| 882 | * <p>Enables high quality mode for the drawing cache.</p> |
| 883 | */ |
| 884 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 885 | |
| 886 | /** |
| 887 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 888 | */ |
| 889 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 890 | |
| 891 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 892 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 893 | }; |
| 894 | |
| 895 | /** |
| 896 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 897 | * quality property.</p> |
| 898 | * {@hide} |
| 899 | */ |
| 900 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 901 | |
| 902 | /** |
| 903 | * <p> |
| 904 | * Indicates this view can be long clicked. When long clickable, a View |
| 905 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 906 | * context menu. |
| 907 | * </p> |
| 908 | * {@hide} |
| 909 | */ |
| 910 | static final int LONG_CLICKABLE = 0x00200000; |
| 911 | |
| 912 | /** |
| 913 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 914 | * and ignores its original internal states.</p> |
| 915 | * |
| 916 | * @hide |
| 917 | */ |
| 918 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 919 | |
| 920 | /** |
| 921 | * The scrollbar style to display the scrollbars inside the content area, |
| 922 | * without increasing the padding. The scrollbars will be overlaid with |
| 923 | * translucency on the view's content. |
| 924 | */ |
| 925 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 926 | |
| 927 | /** |
| 928 | * The scrollbar style to display the scrollbars inside the padded area, |
| 929 | * increasing the padding of the view. The scrollbars will not overlap the |
| 930 | * content area of the view. |
| 931 | */ |
| 932 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 933 | |
| 934 | /** |
| 935 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 936 | * without increasing the padding. The scrollbars will be overlaid with |
| 937 | * translucency. |
| 938 | */ |
| 939 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 940 | |
| 941 | /** |
| 942 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 943 | * increasing the padding of the view. The scrollbars will only overlap the |
| 944 | * background, if any. |
| 945 | */ |
| 946 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 947 | |
| 948 | /** |
| 949 | * Mask to check if the scrollbar style is overlay or inset. |
| 950 | * {@hide} |
| 951 | */ |
| 952 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 953 | |
| 954 | /** |
| 955 | * Mask to check if the scrollbar style is inside or outside. |
| 956 | * {@hide} |
| 957 | */ |
| 958 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 959 | |
| 960 | /** |
| 961 | * Mask for scrollbar style. |
| 962 | * {@hide} |
| 963 | */ |
| 964 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 965 | |
| 966 | /** |
| 967 | * View flag indicating that the screen should remain on while the |
| 968 | * window containing this view is visible to the user. This effectively |
| 969 | * takes care of automatically setting the WindowManager's |
| 970 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 971 | */ |
| 972 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 973 | |
| 974 | /** |
| 975 | * View flag indicating whether this view should have sound effects enabled |
| 976 | * for events such as clicking and touching. |
| 977 | */ |
| 978 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 979 | |
| 980 | /** |
| 981 | * View flag indicating whether this view should have haptic feedback |
| 982 | * enabled for events such as long presses. |
| 983 | */ |
| 984 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 985 | |
| 986 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 987 | * <p>Indicates that the view hierarchy should stop saving state when |
| 988 | * it reaches this view. If state saving is initiated immediately at |
| 989 | * the view, it will be allowed. |
| 990 | * {@hide} |
| 991 | */ |
| 992 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 993 | |
| 994 | /** |
| 995 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 996 | * {@hide} |
| 997 | */ |
| 998 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 999 | |
| 1000 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1001 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1002 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1003 | */ |
| 1004 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1005 | |
| 1006 | /** |
| 1007 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1008 | * should add only Views focusable in touch mode. |
| 1009 | */ |
| 1010 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1011 | |
| 1012 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1013 | * 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] | 1014 | * item. |
| 1015 | */ |
| 1016 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1017 | |
| 1018 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1019 | * 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] | 1020 | * item. |
| 1021 | */ |
| 1022 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1023 | |
| 1024 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1025 | * 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] | 1026 | */ |
| 1027 | public static final int FOCUS_LEFT = 0x00000011; |
| 1028 | |
| 1029 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1030 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | */ |
| 1032 | public static final int FOCUS_UP = 0x00000021; |
| 1033 | |
| 1034 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1035 | * 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] | 1036 | */ |
| 1037 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1038 | |
| 1039 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1040 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | */ |
| 1042 | public static final int FOCUS_DOWN = 0x00000082; |
| 1043 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1044 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1045 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1046 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1047 | */ |
| 1048 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1049 | |
| 1050 | /** |
| 1051 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1052 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1053 | */ |
| 1054 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1055 | |
| 1056 | /** |
| 1057 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1058 | * for functions that combine both width and height into a single int, |
| 1059 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1060 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1061 | */ |
| 1062 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1063 | |
| 1064 | /** |
| 1065 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1066 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1067 | * is smaller that the space the view would like to have. |
| 1068 | */ |
| 1069 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1070 | |
| 1071 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | * Base View state sets |
| 1073 | */ |
| 1074 | // Singles |
| 1075 | /** |
| 1076 | * Indicates the view has no states set. States are used with |
| 1077 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1078 | * view depending on its state. |
| 1079 | * |
| 1080 | * @see android.graphics.drawable.Drawable |
| 1081 | * @see #getDrawableState() |
| 1082 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1083 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | /** |
| 1085 | * Indicates the view is enabled. States are used with |
| 1086 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1087 | * view depending on its state. |
| 1088 | * |
| 1089 | * @see android.graphics.drawable.Drawable |
| 1090 | * @see #getDrawableState() |
| 1091 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1092 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | /** |
| 1094 | * Indicates the view is focused. States are used with |
| 1095 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1096 | * view depending on its state. |
| 1097 | * |
| 1098 | * @see android.graphics.drawable.Drawable |
| 1099 | * @see #getDrawableState() |
| 1100 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1101 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | /** |
| 1103 | * Indicates the view is selected. States are used with |
| 1104 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1105 | * view depending on its state. |
| 1106 | * |
| 1107 | * @see android.graphics.drawable.Drawable |
| 1108 | * @see #getDrawableState() |
| 1109 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1110 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | /** |
| 1112 | * Indicates the view is pressed. 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 | * @hide |
| 1119 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1120 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | /** |
| 1122 | * Indicates the view's window has focus. States are used with |
| 1123 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1124 | * view depending on its state. |
| 1125 | * |
| 1126 | * @see android.graphics.drawable.Drawable |
| 1127 | * @see #getDrawableState() |
| 1128 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1129 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | // Doubles |
| 1131 | /** |
| 1132 | * Indicates the view is enabled and has the focus. |
| 1133 | * |
| 1134 | * @see #ENABLED_STATE_SET |
| 1135 | * @see #FOCUSED_STATE_SET |
| 1136 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1137 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | /** |
| 1139 | * Indicates the view is enabled and selected. |
| 1140 | * |
| 1141 | * @see #ENABLED_STATE_SET |
| 1142 | * @see #SELECTED_STATE_SET |
| 1143 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1144 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | /** |
| 1146 | * Indicates the view is enabled and that its window has focus. |
| 1147 | * |
| 1148 | * @see #ENABLED_STATE_SET |
| 1149 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1150 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1151 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | /** |
| 1153 | * Indicates the view is focused and selected. |
| 1154 | * |
| 1155 | * @see #FOCUSED_STATE_SET |
| 1156 | * @see #SELECTED_STATE_SET |
| 1157 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1158 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | /** |
| 1160 | * Indicates the view has the focus and that its window has the focus. |
| 1161 | * |
| 1162 | * @see #FOCUSED_STATE_SET |
| 1163 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1164 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1165 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | /** |
| 1167 | * Indicates the view is selected and that its window has the focus. |
| 1168 | * |
| 1169 | * @see #SELECTED_STATE_SET |
| 1170 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1171 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1172 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | // Triples |
| 1174 | /** |
| 1175 | * Indicates the view is enabled, focused and selected. |
| 1176 | * |
| 1177 | * @see #ENABLED_STATE_SET |
| 1178 | * @see #FOCUSED_STATE_SET |
| 1179 | * @see #SELECTED_STATE_SET |
| 1180 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1181 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | /** |
| 1183 | * Indicates the view is enabled, focused and its window has the focus. |
| 1184 | * |
| 1185 | * @see #ENABLED_STATE_SET |
| 1186 | * @see #FOCUSED_STATE_SET |
| 1187 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1188 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1189 | 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] | 1190 | /** |
| 1191 | * Indicates the view is enabled, selected and its window has the focus. |
| 1192 | * |
| 1193 | * @see #ENABLED_STATE_SET |
| 1194 | * @see #SELECTED_STATE_SET |
| 1195 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1196 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1197 | 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] | 1198 | /** |
| 1199 | * Indicates the view is focused, selected and its window has the focus. |
| 1200 | * |
| 1201 | * @see #FOCUSED_STATE_SET |
| 1202 | * @see #SELECTED_STATE_SET |
| 1203 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1204 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1205 | 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] | 1206 | /** |
| 1207 | * Indicates the view is enabled, focused, selected and its window |
| 1208 | * has the focus. |
| 1209 | * |
| 1210 | * @see #ENABLED_STATE_SET |
| 1211 | * @see #FOCUSED_STATE_SET |
| 1212 | * @see #SELECTED_STATE_SET |
| 1213 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1214 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1215 | 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] | 1216 | /** |
| 1217 | * Indicates the view is pressed and its window has the focus. |
| 1218 | * |
| 1219 | * @see #PRESSED_STATE_SET |
| 1220 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1221 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1222 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | /** |
| 1224 | * Indicates the view is pressed and selected. |
| 1225 | * |
| 1226 | * @see #PRESSED_STATE_SET |
| 1227 | * @see #SELECTED_STATE_SET |
| 1228 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1229 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | /** |
| 1231 | * Indicates the view is pressed, selected and its window has the focus. |
| 1232 | * |
| 1233 | * @see #PRESSED_STATE_SET |
| 1234 | * @see #SELECTED_STATE_SET |
| 1235 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1236 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1237 | 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] | 1238 | /** |
| 1239 | * Indicates the view is pressed and focused. |
| 1240 | * |
| 1241 | * @see #PRESSED_STATE_SET |
| 1242 | * @see #FOCUSED_STATE_SET |
| 1243 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1244 | protected static final int[] PRESSED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | /** |
| 1246 | * Indicates the view is pressed, focused and its window has the focus. |
| 1247 | * |
| 1248 | * @see #PRESSED_STATE_SET |
| 1249 | * @see #FOCUSED_STATE_SET |
| 1250 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1251 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1252 | 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] | 1253 | /** |
| 1254 | * Indicates the view is pressed, focused and selected. |
| 1255 | * |
| 1256 | * @see #PRESSED_STATE_SET |
| 1257 | * @see #SELECTED_STATE_SET |
| 1258 | * @see #FOCUSED_STATE_SET |
| 1259 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1260 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | /** |
| 1262 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1263 | * |
| 1264 | * @see #PRESSED_STATE_SET |
| 1265 | * @see #FOCUSED_STATE_SET |
| 1266 | * @see #SELECTED_STATE_SET |
| 1267 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1268 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1269 | 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] | 1270 | /** |
| 1271 | * Indicates the view is pressed and enabled. |
| 1272 | * |
| 1273 | * @see #PRESSED_STATE_SET |
| 1274 | * @see #ENABLED_STATE_SET |
| 1275 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1276 | protected static final int[] PRESSED_ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | /** |
| 1278 | * Indicates the view is pressed, enabled and its window has the focus. |
| 1279 | * |
| 1280 | * @see #PRESSED_STATE_SET |
| 1281 | * @see #ENABLED_STATE_SET |
| 1282 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1283 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1284 | 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] | 1285 | /** |
| 1286 | * Indicates the view is pressed, enabled and selected. |
| 1287 | * |
| 1288 | * @see #PRESSED_STATE_SET |
| 1289 | * @see #ENABLED_STATE_SET |
| 1290 | * @see #SELECTED_STATE_SET |
| 1291 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1292 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | /** |
| 1294 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1295 | * focus. |
| 1296 | * |
| 1297 | * @see #PRESSED_STATE_SET |
| 1298 | * @see #ENABLED_STATE_SET |
| 1299 | * @see #SELECTED_STATE_SET |
| 1300 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1301 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1302 | 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] | 1303 | /** |
| 1304 | * Indicates the view is pressed, enabled and focused. |
| 1305 | * |
| 1306 | * @see #PRESSED_STATE_SET |
| 1307 | * @see #ENABLED_STATE_SET |
| 1308 | * @see #FOCUSED_STATE_SET |
| 1309 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1310 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | /** |
| 1312 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1313 | * focus. |
| 1314 | * |
| 1315 | * @see #PRESSED_STATE_SET |
| 1316 | * @see #ENABLED_STATE_SET |
| 1317 | * @see #FOCUSED_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_FOCUSED_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, focused and selected. |
| 1323 | * |
| 1324 | * @see #PRESSED_STATE_SET |
| 1325 | * @see #ENABLED_STATE_SET |
| 1326 | * @see #SELECTED_STATE_SET |
| 1327 | * @see #FOCUSED_STATE_SET |
| 1328 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1329 | 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] | 1330 | /** |
| 1331 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1332 | * has the focus. |
| 1333 | * |
| 1334 | * @see #PRESSED_STATE_SET |
| 1335 | * @see #ENABLED_STATE_SET |
| 1336 | * @see #SELECTED_STATE_SET |
| 1337 | * @see #FOCUSED_STATE_SET |
| 1338 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1339 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1340 | 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] | 1341 | |
| 1342 | /** |
| 1343 | * The order here is very important to {@link #getDrawableState()} |
| 1344 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1345 | private static final int[][] VIEW_STATE_SETS; |
| 1346 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1347 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1348 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1349 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1350 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1351 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1352 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1353 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1354 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1355 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1356 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1357 | |
| 1358 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1359 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1360 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1361 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1362 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1363 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1364 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1365 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1366 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1367 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1368 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | }; |
| 1370 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1371 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1372 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1373 | throw new IllegalStateException( |
| 1374 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1375 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1376 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1377 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1378 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1379 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1380 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1381 | orderedIds[i * 2] = viewState; |
| 1382 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1386 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1387 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1388 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1389 | int numBits = Integer.bitCount(i); |
| 1390 | int[] set = new int[numBits]; |
| 1391 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1392 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1393 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1394 | set[pos++] = orderedIds[j]; |
| 1395 | } |
| 1396 | } |
| 1397 | VIEW_STATE_SETS[i] = set; |
| 1398 | } |
| 1399 | |
| 1400 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1401 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1402 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1403 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1404 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1405 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1406 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1407 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1408 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1409 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1410 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1411 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1412 | | VIEW_STATE_FOCUSED]; |
| 1413 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1414 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1416 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1417 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1418 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1419 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1420 | | VIEW_STATE_ENABLED]; |
| 1421 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1422 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1423 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1424 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1425 | | VIEW_STATE_ENABLED]; |
| 1426 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1427 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1428 | | VIEW_STATE_ENABLED]; |
| 1429 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1430 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1431 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1432 | |
| 1433 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1434 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1436 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1437 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1438 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1439 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1440 | | VIEW_STATE_PRESSED]; |
| 1441 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1442 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1443 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1444 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1445 | | VIEW_STATE_PRESSED]; |
| 1446 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1447 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1448 | | VIEW_STATE_PRESSED]; |
| 1449 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1450 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1451 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1452 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1453 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1454 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1456 | | VIEW_STATE_PRESSED]; |
| 1457 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1458 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1459 | | VIEW_STATE_PRESSED]; |
| 1460 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1461 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1462 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1463 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1464 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1465 | | VIEW_STATE_PRESSED]; |
| 1466 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1467 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1468 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1469 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1470 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1471 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1472 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1473 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1474 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1475 | | VIEW_STATE_PRESSED]; |
| 1476 | } |
| 1477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1479 | * Accessibility event types that are dispatched for text population. |
| 1480 | */ |
| 1481 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1482 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1483 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1484 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1485 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1486 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1487 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1488 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1489 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1490 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1491 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED |
| 1492 | | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1493 | |
| 1494 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1496 | * be extended in the future to hold our own class with more than just |
| 1497 | * a Rect. :) |
| 1498 | */ |
| 1499 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1500 | |
| 1501 | /** |
| 1502 | * Map used to store views' tags. |
| 1503 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1504 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1507 | * The next available accessiiblity id. |
| 1508 | */ |
| 1509 | private static int sNextAccessibilityViewId; |
| 1510 | |
| 1511 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | * The animation currently associated with this view. |
| 1513 | * @hide |
| 1514 | */ |
| 1515 | protected Animation mCurrentAnimation = null; |
| 1516 | |
| 1517 | /** |
| 1518 | * Width as measured during measure pass. |
| 1519 | * {@hide} |
| 1520 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1521 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1522 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | |
| 1524 | /** |
| 1525 | * Height as measured during measure pass. |
| 1526 | * {@hide} |
| 1527 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1528 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1529 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | |
| 1531 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1532 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1533 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1534 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1535 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1536 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1537 | * |
| 1538 | * {@hide} |
| 1539 | */ |
| 1540 | boolean mRecreateDisplayList = false; |
| 1541 | |
| 1542 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | * The view's identifier. |
| 1544 | * {@hide} |
| 1545 | * |
| 1546 | * @see #setId(int) |
| 1547 | * @see #getId() |
| 1548 | */ |
| 1549 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1550 | int mID = NO_ID; |
| 1551 | |
| 1552 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1553 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1554 | */ |
| 1555 | int mAccessibilityViewId = NO_ID; |
| 1556 | |
| 1557 | /** |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1558 | * @hide |
| 1559 | */ |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 1560 | private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1561 | |
| 1562 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | * The view's tag. |
| 1564 | * {@hide} |
| 1565 | * |
| 1566 | * @see #setTag(Object) |
| 1567 | * @see #getTag() |
| 1568 | */ |
| 1569 | protected Object mTag; |
| 1570 | |
| 1571 | // for mPrivateFlags: |
| 1572 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1573 | static final int PFLAG_WANTS_FOCUS = 0x00000001; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1575 | static final int PFLAG_FOCUSED = 0x00000002; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1577 | static final int PFLAG_SELECTED = 0x00000004; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1579 | static final int PFLAG_IS_ROOT_NAMESPACE = 0x00000008; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1581 | static final int PFLAG_HAS_BOUNDS = 0x00000010; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1583 | static final int PFLAG_DRAWN = 0x00000020; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | /** |
| 1585 | * When this flag is set, this view is running an animation on behalf of its |
| 1586 | * children and should therefore not cancel invalidate requests, even if they |
| 1587 | * lie outside of this view's bounds. |
| 1588 | * |
| 1589 | * {@hide} |
| 1590 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1591 | static final int PFLAG_DRAW_ANIMATION = 0x00000040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1593 | static final int PFLAG_SKIP_DRAW = 0x00000080; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1594 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1595 | static final int PFLAG_ONLY_DRAWS_BACKGROUND = 0x00000100; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1597 | static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1599 | static final int PFLAG_DRAWABLE_STATE_DIRTY = 0x00000400; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1601 | static final int PFLAG_MEASURED_DIMENSION_SET = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1603 | static final int PFLAG_FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1604 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1605 | static final int PFLAG_LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1607 | private static final int PFLAG_PRESSED = 0x00004000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | |
| 1609 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1610 | static final int PFLAG_DRAWING_CACHE_VALID = 0x00008000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | /** |
| 1612 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1613 | * more) after its animation has completed. |
| 1614 | * {@hide} |
| 1615 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1616 | static final int PFLAG_ANIMATION_STARTED = 0x00010000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1618 | private static final int PFLAG_SAVE_STATE_CALLED = 0x00020000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1619 | |
| 1620 | /** |
| 1621 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1622 | * the alpha must be restored. |
| 1623 | * {@hide} |
| 1624 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1625 | static final int PFLAG_ALPHA_SET = 0x00040000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | |
| 1627 | /** |
| 1628 | * Set by {@link #setScrollContainer(boolean)}. |
| 1629 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1630 | static final int PFLAG_SCROLL_CONTAINER = 0x00080000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | |
| 1632 | /** |
| 1633 | * Set by {@link #setScrollContainer(boolean)}. |
| 1634 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1635 | static final int PFLAG_SCROLL_CONTAINER_ADDED = 0x00100000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | |
| 1637 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1638 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1639 | * |
| 1640 | * @hide |
| 1641 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1642 | static final int PFLAG_DIRTY = 0x00200000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1643 | |
| 1644 | /** |
| 1645 | * View flag indicating whether this view was invalidated by an opaque |
| 1646 | * invalidate request. |
| 1647 | * |
| 1648 | * @hide |
| 1649 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1650 | static final int PFLAG_DIRTY_OPAQUE = 0x00400000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1651 | |
| 1652 | /** |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1653 | * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}. |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1654 | * |
| 1655 | * @hide |
| 1656 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1657 | static final int PFLAG_DIRTY_MASK = 0x00600000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1658 | |
| 1659 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1660 | * Indicates whether the background is opaque. |
| 1661 | * |
| 1662 | * @hide |
| 1663 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1664 | static final int PFLAG_OPAQUE_BACKGROUND = 0x00800000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1665 | |
| 1666 | /** |
| 1667 | * Indicates whether the scrollbars are opaque. |
| 1668 | * |
| 1669 | * @hide |
| 1670 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1671 | static final int PFLAG_OPAQUE_SCROLLBARS = 0x01000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1672 | |
| 1673 | /** |
| 1674 | * Indicates whether the view is opaque. |
| 1675 | * |
| 1676 | * @hide |
| 1677 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1678 | static final int PFLAG_OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1679 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1680 | /** |
| 1681 | * Indicates a prepressed state; |
| 1682 | * the short time between ACTION_DOWN and recognizing |
| 1683 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1684 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1685 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1686 | * @hide |
| 1687 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1688 | private static final int PFLAG_PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1689 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1690 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1691 | * Indicates whether the view is temporarily detached. |
| 1692 | * |
| 1693 | * @hide |
| 1694 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1695 | static final int PFLAG_CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1696 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1697 | /** |
| 1698 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1699 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1700 | * @hide |
| 1701 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1702 | private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1703 | |
| 1704 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1705 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1706 | * @hide |
| 1707 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1708 | private static final int PFLAG_HOVERED = 0x10000000; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1709 | |
| 1710 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1711 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1712 | * for transform operations |
| 1713 | * |
| 1714 | * @hide |
| 1715 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1716 | private static final int PFLAG_PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1717 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1718 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1719 | static final int PFLAG_ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1720 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1721 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1722 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1723 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1724 | * a view's display list (as opposed to just returning a reference to its existing |
| 1725 | * display list). |
| 1726 | * |
| 1727 | * @hide |
| 1728 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1729 | static final int PFLAG_INVALIDATED = 0x80000000; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1730 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1731 | /* Masks for mPrivateFlags2 */ |
| 1732 | |
| 1733 | /** |
| 1734 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1735 | * Cleared when the drag operation concludes. |
| 1736 | * @hide |
| 1737 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1738 | static final int PFLAG2_DRAG_CAN_ACCEPT = 0x00000001; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1739 | |
| 1740 | /** |
| 1741 | * Indicates that this view is currently directly under the drag location in a |
| 1742 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1743 | * the drag exits the view, or when the drag operation concludes. |
| 1744 | * @hide |
| 1745 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1746 | static final int PFLAG2_DRAG_HOVERED = 0x00000002; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1747 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1748 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1749 | * Horizontal layout direction of this view is from Left to Right. |
| 1750 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1751 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1752 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1753 | |
| 1754 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1755 | * Horizontal layout direction of this view is from Right to Left. |
| 1756 | * Use with {@link #setLayoutDirection}. |
| 1757 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1758 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1759 | |
| 1760 | /** |
| 1761 | * Horizontal layout direction of this view is inherited from its parent. |
| 1762 | * Use with {@link #setLayoutDirection}. |
| 1763 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1764 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1765 | |
| 1766 | /** |
| 1767 | * Horizontal layout direction of this view is from deduced from the default language |
| 1768 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1769 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1770 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1771 | |
| 1772 | /** |
| 1773 | * 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] | 1774 | * @hide |
| 1775 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1776 | static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1777 | |
| 1778 | /** |
| 1779 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1780 | * @hide |
| 1781 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1782 | static final int PFLAG2_LAYOUT_DIRECTION_MASK = 0x00000003 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1783 | |
| 1784 | /** |
| 1785 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1786 | * right-to-left direction. |
| 1787 | * @hide |
| 1788 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1789 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL = 4 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1790 | |
| 1791 | /** |
| 1792 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1793 | * @hide |
| 1794 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1795 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED = 8 << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1796 | |
| 1797 | /** |
| 1798 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1799 | * @hide |
| 1800 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1801 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C |
| 1802 | << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1803 | |
| 1804 | /* |
| 1805 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1806 | * flag value. |
| 1807 | * @hide |
| 1808 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1809 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1810 | LAYOUT_DIRECTION_LTR, |
| 1811 | LAYOUT_DIRECTION_RTL, |
| 1812 | LAYOUT_DIRECTION_INHERIT, |
| 1813 | LAYOUT_DIRECTION_LOCALE |
| 1814 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1815 | |
| 1816 | /** |
| 1817 | * Default horizontal layout direction. |
| 1818 | * @hide |
| 1819 | */ |
| 1820 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1821 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1822 | /** |
| 1823 | * Indicates that the view is tracking some sort of transient state |
| 1824 | * that the app should not need to be aware of, but that the framework |
| 1825 | * should take special care to preserve. |
| 1826 | * |
| 1827 | * @hide |
| 1828 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1829 | static final int PFLAG2_HAS_TRANSIENT_STATE = 0x00000100; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1830 | |
| 1831 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1832 | /** |
| 1833 | * Text direction is inherited thru {@link ViewGroup} |
| 1834 | */ |
| 1835 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1836 | |
| 1837 | /** |
| 1838 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1839 | * determines the paragraph direction. If there is no strong directional character, the |
| 1840 | * paragraph direction is the view's resolved layout direction. |
| 1841 | */ |
| 1842 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1843 | |
| 1844 | /** |
| 1845 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1846 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1847 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1848 | */ |
| 1849 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1850 | |
| 1851 | /** |
| 1852 | * Text direction is forced to LTR. |
| 1853 | */ |
| 1854 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1855 | |
| 1856 | /** |
| 1857 | * Text direction is forced to RTL. |
| 1858 | */ |
| 1859 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1860 | |
| 1861 | /** |
| 1862 | * Text direction is coming from the system Locale. |
| 1863 | */ |
| 1864 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1865 | |
| 1866 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1867 | * Default text direction is inherited |
| 1868 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1869 | public static int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1870 | |
| 1871 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1872 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1873 | * @hide |
| 1874 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1875 | static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1876 | |
| 1877 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1878 | * Mask for use with private flags indicating bits used for text direction. |
| 1879 | * @hide |
| 1880 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1881 | static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007 |
| 1882 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1883 | |
| 1884 | /** |
| 1885 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1886 | * flag value. |
| 1887 | * @hide |
| 1888 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1889 | private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = { |
| 1890 | TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1891 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1892 | TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1893 | TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1894 | TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1895 | TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1896 | }; |
| 1897 | |
| 1898 | /** |
| 1899 | * Indicates whether the view text direction has been resolved. |
| 1900 | * @hide |
| 1901 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1902 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008 |
| 1903 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1904 | |
| 1905 | /** |
| 1906 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1907 | * @hide |
| 1908 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1909 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1910 | |
| 1911 | /** |
| 1912 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1913 | * @hide |
| 1914 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1915 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 |
| 1916 | << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1917 | |
| 1918 | /** |
| 1919 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1920 | * @hide |
| 1921 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1922 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1923 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1924 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1925 | /* |
| 1926 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1927 | * Use with {@link #setTextAlignment(int)} |
| 1928 | */ |
| 1929 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1930 | |
| 1931 | /** |
| 1932 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1933 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1934 | * |
| 1935 | * Use with {@link #setTextAlignment(int)} |
| 1936 | */ |
| 1937 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1938 | |
| 1939 | /** |
| 1940 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1941 | * |
| 1942 | * Use with {@link #setTextAlignment(int)} |
| 1943 | */ |
| 1944 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1945 | |
| 1946 | /** |
| 1947 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1948 | * |
| 1949 | * Use with {@link #setTextAlignment(int)} |
| 1950 | */ |
| 1951 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1952 | |
| 1953 | /** |
| 1954 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 1955 | * |
| 1956 | * Use with {@link #setTextAlignment(int)} |
| 1957 | */ |
| 1958 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 1959 | |
| 1960 | /** |
| 1961 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 1962 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 1963 | * |
| 1964 | * Use with {@link #setTextAlignment(int)} |
| 1965 | */ |
| 1966 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 1967 | |
| 1968 | /** |
| 1969 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 1970 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 1971 | * |
| 1972 | * Use with {@link #setTextAlignment(int)} |
| 1973 | */ |
| 1974 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 1975 | |
| 1976 | /** |
| 1977 | * Default text alignment is inherited |
| 1978 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1979 | public static int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1980 | |
| 1981 | /** |
| 1982 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1983 | * @hide |
| 1984 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1985 | static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1986 | |
| 1987 | /** |
| 1988 | * Mask for use with private flags indicating bits used for text alignment. |
| 1989 | * @hide |
| 1990 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1991 | static final int PFLAG2_TEXT_ALIGNMENT_MASK = 0x00000007 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1992 | |
| 1993 | /** |
| 1994 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 1995 | * flag value. |
| 1996 | * @hide |
| 1997 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1998 | private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = { |
| 1999 | TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2000 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2001 | TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2002 | TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2003 | TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2004 | TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2005 | TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2006 | }; |
| 2007 | |
| 2008 | /** |
| 2009 | * Indicates whether the view text alignment has been resolved. |
| 2010 | * @hide |
| 2011 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2012 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED = 0x00000008 << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2013 | |
| 2014 | /** |
| 2015 | * Bit shift to get the resolved text alignment. |
| 2016 | * @hide |
| 2017 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2018 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2019 | |
| 2020 | /** |
| 2021 | * Mask for use with private flags indicating bits used for text alignment. |
| 2022 | * @hide |
| 2023 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2024 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 |
| 2025 | << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2026 | |
| 2027 | /** |
| 2028 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2029 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2030 | private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2031 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2032 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2033 | // Accessiblity constants for mPrivateFlags2 |
| 2034 | |
| 2035 | /** |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2036 | * Shift for the bits in {@link #mPrivateFlags2} related to the |
| 2037 | * "importantForAccessibility" attribute. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2038 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2039 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2040 | |
| 2041 | /** |
| 2042 | * Automatically determine whether a view is important for accessibility. |
| 2043 | */ |
| 2044 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2045 | |
| 2046 | /** |
| 2047 | * The view is important for accessibility. |
| 2048 | */ |
| 2049 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2050 | |
| 2051 | /** |
| 2052 | * The view is not important for accessibility. |
| 2053 | */ |
| 2054 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2055 | |
| 2056 | /** |
| 2057 | * The default whether the view is important for accessiblity. |
| 2058 | */ |
| 2059 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2060 | |
| 2061 | /** |
| 2062 | * Mask for obtainig the bits which specify how to determine |
| 2063 | * whether a view is important for accessibility. |
| 2064 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2065 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2066 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2067 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2068 | |
| 2069 | /** |
| 2070 | * Flag indicating whether a view has accessibility focus. |
| 2071 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2072 | static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x00000040 << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2073 | |
| 2074 | /** |
| 2075 | * Flag indicating whether a view state for accessibility has changed. |
| 2076 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2077 | static final int PFLAG2_ACCESSIBILITY_STATE_CHANGED = 0x00000080 |
| 2078 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2079 | |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 2080 | /** |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2081 | * Flag indicating whether a view failed the quickReject() check in draw(). This condition |
| 2082 | * is used to check whether later changes to the view's transform should invalidate the |
| 2083 | * view to force the quickReject test to run again. |
| 2084 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2085 | static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000; |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2086 | |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2087 | /** |
| 2088 | * Flag indicating that start/end padding has been resolved into left/right padding |
| 2089 | * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()} |
| 2090 | * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved |
| 2091 | * during measurement. In some special cases this is required such as when an adapter-based |
| 2092 | * view measures prospective children without attaching them to a window. |
| 2093 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2094 | static final int PFLAG2_PADDING_RESOLVED = 0x20000000; |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2095 | |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 2096 | // There are a couple of flags left in mPrivateFlags2 |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2097 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2098 | /* End of masks for mPrivateFlags2 */ |
| 2099 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2100 | /* Masks for mPrivateFlags3 */ |
| 2101 | |
| 2102 | /** |
| 2103 | * Flag indicating that view has a transform animation set on it. This is used to track whether |
| 2104 | * an animation is cleared between successive frames, in order to tell the associated |
| 2105 | * DisplayList to clear its animation matrix. |
| 2106 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2107 | static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2108 | |
| 2109 | /** |
| 2110 | * Flag indicating that view has an alpha animation set on it. This is used to track whether an |
| 2111 | * animation is cleared between successive frames, in order to tell the associated |
| 2112 | * DisplayList to restore its alpha value. |
| 2113 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2114 | static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2115 | |
| 2116 | |
| 2117 | /* End of masks for mPrivateFlags3 */ |
| 2118 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2119 | static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2120 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2121 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2122 | * Always allow a user to over-scroll this view, provided it is a |
| 2123 | * view that can scroll. |
| 2124 | * |
| 2125 | * @see #getOverScrollMode() |
| 2126 | * @see #setOverScrollMode(int) |
| 2127 | */ |
| 2128 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2129 | |
| 2130 | /** |
| 2131 | * Allow a user to over-scroll this view only if the content is large |
| 2132 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2133 | * |
| 2134 | * @see #getOverScrollMode() |
| 2135 | * @see #setOverScrollMode(int) |
| 2136 | */ |
| 2137 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2138 | |
| 2139 | /** |
| 2140 | * Never allow a user to over-scroll this view. |
| 2141 | * |
| 2142 | * @see #getOverScrollMode() |
| 2143 | * @see #setOverScrollMode(int) |
| 2144 | */ |
| 2145 | public static final int OVER_SCROLL_NEVER = 2; |
| 2146 | |
| 2147 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2148 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2149 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2150 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2151 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2152 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2153 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2154 | |
| 2155 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2156 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2157 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2158 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2159 | * <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] | 2160 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2161 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2162 | * <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] | 2163 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2164 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2165 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2166 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2167 | |
| 2168 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2169 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2170 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2171 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2172 | * <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] | 2173 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2174 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2175 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2176 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2177 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2178 | * window flags) for displaying content using every last pixel on the display. |
| 2179 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2180 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2181 | * interaction will cause them to reappear immediately. When this happens, both |
| 2182 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2183 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2184 | * |
| 2185 | * @see #setSystemUiVisibility(int) |
| 2186 | */ |
| 2187 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2188 | |
| 2189 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2190 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2191 | * into the normal fullscreen mode so that its content can take over the screen |
| 2192 | * while still allowing the user to interact with the application. |
| 2193 | * |
| 2194 | * <p>This has the same visual effect as |
| 2195 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2196 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2197 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2198 | * hidden while the user is in the View's window, focusing the experience on |
| 2199 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2200 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2201 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2202 | * hide the action bar. |
| 2203 | * |
| 2204 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2205 | * it is a transient state -- that is, the application does this at certain |
| 2206 | * points in its user interaction where it wants to allow the user to focus |
| 2207 | * on content, but not as a continuous state. For situations where the application |
| 2208 | * would like to simply stay full screen the entire time (such as a game that |
| 2209 | * wants to take over the screen), the |
| 2210 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2211 | * is usually a better approach. The state set here will be removed by the system |
| 2212 | * in various situations (such as the user moving to another application) like |
| 2213 | * the other system UI states. |
| 2214 | * |
| 2215 | * <p>When using this flag, the application should provide some easy facility |
| 2216 | * for the user to go out of it. A common example would be in an e-book |
| 2217 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2218 | * decorations that had been hidden while the user was immersed in reading |
| 2219 | * the book. |
| 2220 | * |
| 2221 | * @see #setSystemUiVisibility(int) |
| 2222 | */ |
| 2223 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2224 | |
| 2225 | /** |
| 2226 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2227 | * flags, we would like a stable view of the content insets given to |
| 2228 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2229 | * will always represent the worst case that the application can expect |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2230 | * as a continuous state. In the stock Android UI this is the space for |
| 2231 | * the system bar, nav bar, and status bar, but not more transient elements |
| 2232 | * such as an input method. |
| 2233 | * |
| 2234 | * The stable layout your UI sees is based on the system UI modes you can |
| 2235 | * switch to. That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 2236 | * then you will get a stable layout for changes of the |
| 2237 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify |
| 2238 | * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and |
| 2239 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition |
| 2240 | * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} |
| 2241 | * with a stable layout. (Note that you should avoid using |
| 2242 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.) |
| 2243 | * |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 2244 | * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN} |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2245 | * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}), |
| 2246 | * then a hidden status bar will be considered a "stable" state for purposes |
| 2247 | * here. This allows your UI to continually hide the status bar, while still |
| 2248 | * using the system UI flags to hide the action bar while still retaining |
| 2249 | * a stable layout. Note that changing the window fullscreen flag will never |
| 2250 | * provide a stable layout for a clean transition. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2251 | * |
| 2252 | * <p>If you are using ActionBar in |
| 2253 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2254 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2255 | * insets it adds to those given to the application. |
| 2256 | */ |
| 2257 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2258 | |
| 2259 | /** |
| 2260 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2261 | * to be layed out as if it has requested |
| 2262 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2263 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2264 | * the expense that some of its user interface may be covered by screen |
| 2265 | * decorations when they are shown. You can perform layout of your inner |
| 2266 | * UI elements to account for the navagation system UI through the |
| 2267 | * {@link #fitSystemWindows(Rect)} method. |
| 2268 | */ |
| 2269 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2270 | |
| 2271 | /** |
| 2272 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2273 | * to be layed out as if it has requested |
| 2274 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2275 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2276 | * the expense that some of its user interface may be covered by screen |
| 2277 | * decorations when they are shown. You can perform layout of your inner |
| 2278 | * UI elements to account for non-fullscreen system UI through the |
| 2279 | * {@link #fitSystemWindows(Rect)} method. |
| 2280 | */ |
| 2281 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2282 | |
| 2283 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2284 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2285 | */ |
| 2286 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2287 | |
| 2288 | /** |
| 2289 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2290 | */ |
| 2291 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2292 | |
| 2293 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2294 | * @hide |
| 2295 | * |
| 2296 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2297 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2298 | * |
| 2299 | * Flag to make the status bar not expandable. Unless you also |
| 2300 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2301 | */ |
| 2302 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2303 | |
| 2304 | /** |
| 2305 | * @hide |
| 2306 | * |
| 2307 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2308 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2309 | * |
| 2310 | * Flag to hide notification icons and scrolling ticker text. |
| 2311 | */ |
| 2312 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2313 | |
| 2314 | /** |
| 2315 | * @hide |
| 2316 | * |
| 2317 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2318 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2319 | * |
| 2320 | * Flag to disable incoming notification alerts. This will not block |
| 2321 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2322 | */ |
| 2323 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2324 | |
| 2325 | /** |
| 2326 | * @hide |
| 2327 | * |
| 2328 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2329 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2330 | * |
| 2331 | * Flag to hide only the scrolling ticker. Note that |
| 2332 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2333 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2334 | */ |
| 2335 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2336 | |
| 2337 | /** |
| 2338 | * @hide |
| 2339 | * |
| 2340 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2341 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2342 | * |
| 2343 | * Flag to hide the center system info area. |
| 2344 | */ |
| 2345 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2346 | |
| 2347 | /** |
| 2348 | * @hide |
| 2349 | * |
| 2350 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2351 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2352 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2353 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2354 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2355 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2356 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2357 | |
| 2358 | /** |
| 2359 | * @hide |
| 2360 | * |
| 2361 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2362 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2363 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2364 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2365 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2366 | */ |
| 2367 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2368 | |
| 2369 | /** |
| 2370 | * @hide |
| 2371 | * |
| 2372 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2373 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2374 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2375 | * Flag to hide only the clock. You might use this if your activity has |
| 2376 | * its own clock making the status bar's clock redundant. |
| 2377 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2378 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2379 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2380 | /** |
| 2381 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2382 | * |
| 2383 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2384 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2385 | * |
| 2386 | * Flag to hide only the recent apps button. Don't use this |
| 2387 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2388 | */ |
| 2389 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2390 | |
| 2391 | /** |
| 2392 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2393 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2394 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2395 | |
| 2396 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2397 | * These are the system UI flags that can be cleared by events outside |
| 2398 | * of an application. Currently this is just the ability to tap on the |
| 2399 | * screen while hiding the navigation bar to have it return. |
| 2400 | * @hide |
| 2401 | */ |
| 2402 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2403 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2404 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2405 | |
| 2406 | /** |
| 2407 | * Flags that can impact the layout in relation to system UI. |
| 2408 | */ |
| 2409 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2410 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2411 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2412 | |
| 2413 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2414 | * Find views that render the specified text. |
| 2415 | * |
| 2416 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2417 | */ |
| 2418 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2419 | |
| 2420 | /** |
| 2421 | * Find find views that contain the specified content description. |
| 2422 | * |
| 2423 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2424 | */ |
| 2425 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2426 | |
| 2427 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2428 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2429 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2430 | * text. If this flag is set Views with providers are automatically |
| 2431 | * added and it is a responsibility of the client to call the APIs of |
| 2432 | * the provider to determine whether the virtual tree rooted at this View |
| 2433 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2434 | * represeting the virtual views with this text. |
| 2435 | * |
| 2436 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2437 | * |
| 2438 | * @hide |
| 2439 | */ |
| 2440 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2441 | |
| 2442 | /** |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2443 | * The undefined cursor position. |
| 2444 | */ |
| 2445 | private static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1; |
| 2446 | |
| 2447 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2448 | * Indicates that the screen has changed state and is now off. |
| 2449 | * |
| 2450 | * @see #onScreenStateChanged(int) |
| 2451 | */ |
| 2452 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2453 | |
| 2454 | /** |
| 2455 | * Indicates that the screen has changed state and is now on. |
| 2456 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2457 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2458 | */ |
| 2459 | public static final int SCREEN_STATE_ON = 0x1; |
| 2460 | |
| 2461 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2462 | * Controls the over-scroll mode for this view. |
| 2463 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2464 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2465 | * and {@link #OVER_SCROLL_NEVER}. |
| 2466 | */ |
| 2467 | private int mOverScrollMode; |
| 2468 | |
| 2469 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | * The parent this view is attached to. |
| 2471 | * {@hide} |
| 2472 | * |
| 2473 | * @see #getParent() |
| 2474 | */ |
| 2475 | protected ViewParent mParent; |
| 2476 | |
| 2477 | /** |
| 2478 | * {@hide} |
| 2479 | */ |
| 2480 | AttachInfo mAttachInfo; |
| 2481 | |
| 2482 | /** |
| 2483 | * {@hide} |
| 2484 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2485 | @ViewDebug.ExportedProperty(flagMapping = { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2486 | @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2487 | name = "FORCE_LAYOUT"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2488 | @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2489 | name = "LAYOUT_REQUIRED"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2490 | @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2491 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2492 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true), |
| 2493 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2494 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2495 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY") |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2496 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2498 | int mPrivateFlags2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2499 | int mPrivateFlags3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | |
| 2501 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2502 | * This view's request for the visibility of the status bar. |
| 2503 | * @hide |
| 2504 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2505 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2506 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2507 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2508 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2509 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2510 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2511 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2512 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2513 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2514 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2515 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2516 | int mSystemUiVisibility; |
| 2517 | |
| 2518 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 2519 | * Reference count for transient state. |
| 2520 | * @see #setHasTransientState(boolean) |
| 2521 | */ |
| 2522 | int mTransientStateCount = 0; |
| 2523 | |
| 2524 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | * Count of how many windows this view has been attached to. |
| 2526 | */ |
| 2527 | int mWindowAttachCount; |
| 2528 | |
| 2529 | /** |
| 2530 | * The layout parameters associated with this view and used by the parent |
| 2531 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2532 | * laid out. |
| 2533 | * {@hide} |
| 2534 | */ |
| 2535 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2536 | |
| 2537 | /** |
| 2538 | * The view flags hold various views states. |
| 2539 | * {@hide} |
| 2540 | */ |
| 2541 | @ViewDebug.ExportedProperty |
| 2542 | int mViewFlags; |
| 2543 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2544 | static class TransformationInfo { |
| 2545 | /** |
| 2546 | * The transform matrix for the View. This transform is calculated internally |
| 2547 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2548 | * is used by default. Do *not* use this variable directly; instead call |
| 2549 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2550 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2551 | */ |
| 2552 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2553 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2554 | /** |
| 2555 | * The transform matrix for the View. This transform is calculated internally |
| 2556 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2557 | * is used by default. Do *not* use this variable directly; instead call |
| 2558 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2559 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2560 | */ |
| 2561 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2562 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2563 | /** |
| 2564 | * An internal variable that tracks whether we need to recalculate the |
| 2565 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2566 | * have changed since the matrix was last calculated. |
| 2567 | */ |
| 2568 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2569 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2570 | /** |
| 2571 | * An internal variable that tracks whether we need to recalculate the |
| 2572 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2573 | * have changed since the matrix was last calculated. |
| 2574 | */ |
| 2575 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2576 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2577 | /** |
| 2578 | * A variable that tracks whether we need to recalculate the |
| 2579 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2580 | * have changed since the matrix was last calculated. This variable |
| 2581 | * is only valid after a call to updateMatrix() or to a function that |
| 2582 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2583 | */ |
| 2584 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2585 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2586 | /** |
| 2587 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2588 | */ |
| 2589 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2590 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2591 | /** |
| 2592 | * This matrix is used when computing the matrix for 3D rotations. |
| 2593 | */ |
| 2594 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2595 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2596 | /** |
| 2597 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2598 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2599 | * set), so thes values are only used then as well. |
| 2600 | */ |
| 2601 | private int mPrevWidth = -1; |
| 2602 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2603 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2604 | /** |
| 2605 | * The degrees rotation around the vertical axis through the pivot point. |
| 2606 | */ |
| 2607 | @ViewDebug.ExportedProperty |
| 2608 | float mRotationY = 0f; |
| 2609 | |
| 2610 | /** |
| 2611 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2612 | */ |
| 2613 | @ViewDebug.ExportedProperty |
| 2614 | float mRotationX = 0f; |
| 2615 | |
| 2616 | /** |
| 2617 | * The degrees rotation around the pivot point. |
| 2618 | */ |
| 2619 | @ViewDebug.ExportedProperty |
| 2620 | float mRotation = 0f; |
| 2621 | |
| 2622 | /** |
| 2623 | * The amount of translation of the object away from its left property (post-layout). |
| 2624 | */ |
| 2625 | @ViewDebug.ExportedProperty |
| 2626 | float mTranslationX = 0f; |
| 2627 | |
| 2628 | /** |
| 2629 | * The amount of translation of the object away from its top property (post-layout). |
| 2630 | */ |
| 2631 | @ViewDebug.ExportedProperty |
| 2632 | float mTranslationY = 0f; |
| 2633 | |
| 2634 | /** |
| 2635 | * The amount of scale in the x direction around the pivot point. A |
| 2636 | * value of 1 means no scaling is applied. |
| 2637 | */ |
| 2638 | @ViewDebug.ExportedProperty |
| 2639 | float mScaleX = 1f; |
| 2640 | |
| 2641 | /** |
| 2642 | * The amount of scale in the y direction around the pivot point. A |
| 2643 | * value of 1 means no scaling is applied. |
| 2644 | */ |
| 2645 | @ViewDebug.ExportedProperty |
| 2646 | float mScaleY = 1f; |
| 2647 | |
| 2648 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2649 | * 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] | 2650 | */ |
| 2651 | @ViewDebug.ExportedProperty |
| 2652 | float mPivotX = 0f; |
| 2653 | |
| 2654 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2655 | * 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] | 2656 | */ |
| 2657 | @ViewDebug.ExportedProperty |
| 2658 | float mPivotY = 0f; |
| 2659 | |
| 2660 | /** |
| 2661 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2662 | * completely transparent and 1 means completely opaque. |
| 2663 | */ |
| 2664 | @ViewDebug.ExportedProperty |
| 2665 | float mAlpha = 1f; |
| 2666 | } |
| 2667 | |
| 2668 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2669 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2670 | private boolean mLastIsOpaque; |
| 2671 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2672 | /** |
| 2673 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2674 | * zero. |
| 2675 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2676 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2677 | |
| 2678 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | * The distance in pixels from the left edge of this view's parent |
| 2680 | * to the left edge of this view. |
| 2681 | * {@hide} |
| 2682 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2683 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | protected int mLeft; |
| 2685 | /** |
| 2686 | * The distance in pixels from the left edge of this view's parent |
| 2687 | * to the right edge of this view. |
| 2688 | * {@hide} |
| 2689 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2690 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | protected int mRight; |
| 2692 | /** |
| 2693 | * The distance in pixels from the top edge of this view's parent |
| 2694 | * to the top edge of this view. |
| 2695 | * {@hide} |
| 2696 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2697 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2698 | protected int mTop; |
| 2699 | /** |
| 2700 | * The distance in pixels from the top edge of this view's parent |
| 2701 | * to the bottom edge of this view. |
| 2702 | * {@hide} |
| 2703 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2704 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | protected int mBottom; |
| 2706 | |
| 2707 | /** |
| 2708 | * The offset, in pixels, by which the content of this view is scrolled |
| 2709 | * horizontally. |
| 2710 | * {@hide} |
| 2711 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2712 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2713 | protected int mScrollX; |
| 2714 | /** |
| 2715 | * The offset, in pixels, by which the content of this view is scrolled |
| 2716 | * vertically. |
| 2717 | * {@hide} |
| 2718 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2719 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | protected int mScrollY; |
| 2721 | |
| 2722 | /** |
| 2723 | * The left padding in pixels, that is the distance in pixels between the |
| 2724 | * left edge of this view and the left edge of its content. |
| 2725 | * {@hide} |
| 2726 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2727 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2728 | protected int mPaddingLeft; |
| 2729 | /** |
| 2730 | * The right padding in pixels, that is the distance in pixels between the |
| 2731 | * right edge of this view and the right edge of its content. |
| 2732 | * {@hide} |
| 2733 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2734 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | protected int mPaddingRight; |
| 2736 | /** |
| 2737 | * The top padding in pixels, that is the distance in pixels between the |
| 2738 | * top edge of this view and the top edge of its content. |
| 2739 | * {@hide} |
| 2740 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2741 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | protected int mPaddingTop; |
| 2743 | /** |
| 2744 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2745 | * bottom edge of this view and the bottom edge of its content. |
| 2746 | * {@hide} |
| 2747 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2748 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2749 | protected int mPaddingBottom; |
| 2750 | |
| 2751 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2752 | * The layout insets in pixels, that is the distance in pixels between the |
| 2753 | * visible edges of this view its bounds. |
| 2754 | */ |
| 2755 | private Insets mLayoutInsets; |
| 2756 | |
| 2757 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2758 | * Briefly describes the view and is primarily used for accessibility support. |
| 2759 | */ |
| 2760 | private CharSequence mContentDescription; |
| 2761 | |
| 2762 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | * 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] | 2764 | * |
| 2765 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2766 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2767 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2768 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2769 | |
| 2770 | /** |
| 2771 | * 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] | 2772 | * |
| 2773 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2775 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2776 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2778 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2779 | * 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] | 2780 | * |
| 2781 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2782 | */ |
| 2783 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2784 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2785 | |
| 2786 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2787 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2788 | * |
| 2789 | */ |
| 2790 | @ViewDebug.ExportedProperty(category = "padding") |
| 2791 | int mUserPaddingStart; |
| 2792 | |
| 2793 | /** |
| 2794 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2795 | * |
| 2796 | */ |
| 2797 | @ViewDebug.ExportedProperty(category = "padding") |
| 2798 | int mUserPaddingEnd; |
| 2799 | |
| 2800 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2801 | * Whether a left padding has been defined during layout inflation. |
| 2802 | * |
| 2803 | * @hide |
| 2804 | */ |
| 2805 | boolean mUserPaddingLeftDefined = false; |
| 2806 | |
| 2807 | /** |
| 2808 | * Whether a right padding has been defined during layout inflation. |
| 2809 | * |
| 2810 | * @hide |
| 2811 | */ |
| 2812 | boolean mUserPaddingRightDefined = false; |
| 2813 | |
| 2814 | /** |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 2815 | * Default undefined padding |
| 2816 | */ |
| 2817 | private static final int UNDEFINED_PADDING = Integer.MIN_VALUE; |
| 2818 | |
| 2819 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2820 | * @hide |
| 2821 | */ |
| 2822 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2823 | /** |
| 2824 | * @hide |
| 2825 | */ |
| 2826 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2827 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2828 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | |
| 2830 | private int mBackgroundResource; |
| 2831 | private boolean mBackgroundSizeChanged; |
| 2832 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2833 | static class ListenerInfo { |
| 2834 | /** |
| 2835 | * Listener used to dispatch focus change events. |
| 2836 | * This field should be made private, so it is hidden from the SDK. |
| 2837 | * {@hide} |
| 2838 | */ |
| 2839 | protected OnFocusChangeListener mOnFocusChangeListener; |
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 | /** |
| 2842 | * Listeners for layout change events. |
| 2843 | */ |
| 2844 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2845 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2846 | /** |
| 2847 | * Listeners for attach events. |
| 2848 | */ |
| 2849 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2850 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2851 | /** |
| 2852 | * Listener used to dispatch click events. |
| 2853 | * This field should be made private, so it is hidden from the SDK. |
| 2854 | * {@hide} |
| 2855 | */ |
| 2856 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2858 | /** |
| 2859 | * Listener used to dispatch long click events. |
| 2860 | * This field should be made private, so it is hidden from the SDK. |
| 2861 | * {@hide} |
| 2862 | */ |
| 2863 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2864 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2865 | /** |
| 2866 | * Listener used to build the context menu. |
| 2867 | * This field should be made private, so it is hidden from the SDK. |
| 2868 | * {@hide} |
| 2869 | */ |
| 2870 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2872 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2874 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2876 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2877 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2878 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2879 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2880 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2881 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2882 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2883 | } |
| 2884 | |
| 2885 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | /** |
| 2888 | * The application environment this view lives in. |
| 2889 | * This field should be made private, so it is hidden from the SDK. |
| 2890 | * {@hide} |
| 2891 | */ |
| 2892 | protected Context mContext; |
| 2893 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2894 | private final Resources mResources; |
| 2895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | private ScrollabilityCache mScrollCache; |
| 2897 | |
| 2898 | private int[] mDrawableState = null; |
| 2899 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2900 | /** |
| 2901 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2902 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2903 | * @hide |
| 2904 | */ |
| 2905 | public boolean mCachingFailed; |
| 2906 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2907 | private Bitmap mDrawingCache; |
| 2908 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 2909 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 2910 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | |
| 2912 | /** |
| 2913 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 2914 | * the user may specify which view to go to next. |
| 2915 | */ |
| 2916 | private int mNextFocusLeftId = View.NO_ID; |
| 2917 | |
| 2918 | /** |
| 2919 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 2920 | * the user may specify which view to go to next. |
| 2921 | */ |
| 2922 | private int mNextFocusRightId = View.NO_ID; |
| 2923 | |
| 2924 | /** |
| 2925 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 2926 | * the user may specify which view to go to next. |
| 2927 | */ |
| 2928 | private int mNextFocusUpId = View.NO_ID; |
| 2929 | |
| 2930 | /** |
| 2931 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 2932 | * the user may specify which view to go to next. |
| 2933 | */ |
| 2934 | private int mNextFocusDownId = View.NO_ID; |
| 2935 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 2936 | /** |
| 2937 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 2938 | * the user may specify which view to go to next. |
| 2939 | */ |
| 2940 | int mNextFocusForwardId = View.NO_ID; |
| 2941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2943 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 2944 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 2945 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | private UnsetPressedState mUnsetPressedState; |
| 2948 | |
| 2949 | /** |
| 2950 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 2951 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 2952 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 2953 | * should not be invoked. |
| 2954 | */ |
| 2955 | private boolean mHasPerformedLongPress; |
| 2956 | |
| 2957 | /** |
| 2958 | * The minimum height of the view. We'll try our best to have the height |
| 2959 | * of this view to at least this amount. |
| 2960 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2961 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | private int mMinHeight; |
| 2963 | |
| 2964 | /** |
| 2965 | * The minimum width of the view. We'll try our best to have the width |
| 2966 | * of this view to at least this amount. |
| 2967 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2968 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | private int mMinWidth; |
| 2970 | |
| 2971 | /** |
| 2972 | * The delegate to handle touch events that are physically in this view |
| 2973 | * but should be handled by another view. |
| 2974 | */ |
| 2975 | private TouchDelegate mTouchDelegate = null; |
| 2976 | |
| 2977 | /** |
| 2978 | * Solid color to use as a background when creating the drawing cache. Enables |
| 2979 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 2980 | */ |
| 2981 | private int mDrawingCacheBackgroundColor = 0; |
| 2982 | |
| 2983 | /** |
| 2984 | * Special tree observer used when mAttachInfo is null. |
| 2985 | */ |
| 2986 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2987 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 2988 | /** |
| 2989 | * Cache the touch slop from the context that created the view. |
| 2990 | */ |
| 2991 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 2994 | * Object that handles automatic animation of view properties. |
| 2995 | */ |
| 2996 | private ViewPropertyAnimator mAnimator = null; |
| 2997 | |
| 2998 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 2999 | * Flag indicating that a drag can cross window boundaries. When |
| 3000 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 3001 | * with this flag set, all visible applications will be able to participate |
| 3002 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 3003 | * |
| 3004 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 3005 | */ |
| 3006 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 3007 | |
| 3008 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3009 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 3010 | */ |
| 3011 | private float mVerticalScrollFactor; |
| 3012 | |
| 3013 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3014 | * Position of the vertical scroll bar. |
| 3015 | */ |
| 3016 | private int mVerticalScrollbarPosition; |
| 3017 | |
| 3018 | /** |
| 3019 | * Position the scroll bar at the default position as determined by the system. |
| 3020 | */ |
| 3021 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 3022 | |
| 3023 | /** |
| 3024 | * Position the scroll bar along the left edge. |
| 3025 | */ |
| 3026 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 3027 | |
| 3028 | /** |
| 3029 | * Position the scroll bar along the right edge. |
| 3030 | */ |
| 3031 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 3032 | |
| 3033 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3034 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3035 | * |
| 3036 | * @see #getLayerType() |
| 3037 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3038 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3039 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3040 | */ |
| 3041 | public static final int LAYER_TYPE_NONE = 0; |
| 3042 | |
| 3043 | /** |
| 3044 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 3045 | * by a bitmap and causes the view to be rendered using Android's software |
| 3046 | * rendering pipeline, even if hardware acceleration is enabled.</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>Software layers have various usages:</p> |
| 3049 | * <p>When the application is not using hardware acceleration, a software layer |
| 3050 | * is useful to apply a specific color filter and/or blending mode and/or |
| 3051 | * translucency to a view and all its children.</p> |
| 3052 | * <p>When the application is using hardware acceleration, a software layer |
| 3053 | * is useful to render drawing primitives not supported by the hardware |
| 3054 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 3055 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3056 | * when animating a complex view tree with a translation, a software layer can |
| 3057 | * be used to render the view tree only once.</p> |
| 3058 | * <p>Software layers should be avoided when the affected view tree updates |
| 3059 | * often. Every update will require to re-render the software layer, which can |
| 3060 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3061 | * since the layer will have to be uploaded into a hardware texture after every |
| 3062 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3063 | * |
| 3064 | * @see #getLayerType() |
| 3065 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3066 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3067 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3068 | */ |
| 3069 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3070 | |
| 3071 | /** |
| 3072 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3073 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3074 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3075 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3076 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3077 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3078 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3079 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3080 | * 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] | 3081 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3082 | * texture and reduce the complexity of drawing operations. For instance, |
| 3083 | * when animating a complex view tree with a translation, a hardware layer can |
| 3084 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3085 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3086 | * rotation transformations are applied on a view. It can also be used to |
| 3087 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3088 | * |
| 3089 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3090 | * @see #setLayerType(int, android.graphics.Paint) |
| 3091 | * @see #LAYER_TYPE_NONE |
| 3092 | * @see #LAYER_TYPE_SOFTWARE |
| 3093 | */ |
| 3094 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3095 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3096 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3097 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3098 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3099 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3100 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3101 | int mLayerType = LAYER_TYPE_NONE; |
| 3102 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3103 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3104 | |
| 3105 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3106 | * Set to true when the view is sending hover accessibility events because it |
| 3107 | * is the innermost hovered view. |
| 3108 | */ |
| 3109 | private boolean mSendingHoverAccessibilityEvents; |
| 3110 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3111 | /** |
| 3112 | * Delegate for injecting accessiblity functionality. |
| 3113 | */ |
| 3114 | AccessibilityDelegate mAccessibilityDelegate; |
| 3115 | |
| 3116 | /** |
| 3117 | * Consistency verifier for debugging purposes. |
| 3118 | * @hide |
| 3119 | */ |
| 3120 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3121 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3122 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3123 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 3124 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 3125 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3126 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3127 | * Simple constructor to use when creating a view from code. |
| 3128 | * |
| 3129 | * @param context The Context the view is running in, through which it can |
| 3130 | * access the current theme, resources, etc. |
| 3131 | */ |
| 3132 | public View(Context context) { |
| 3133 | mContext = context; |
| 3134 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3135 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3136 | // Set layout and text direction defaults |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3137 | mPrivateFlags2 = (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) | |
| 3138 | (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) | |
| 3139 | (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | |
| 3140 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3141 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3142 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3143 | mUserPaddingStart = UNDEFINED_PADDING; |
| 3144 | mUserPaddingEnd = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | /** |
| 3148 | * Constructor that is called when inflating a view from XML. This is called |
| 3149 | * when a view is being constructed from an XML file, supplying attributes |
| 3150 | * that were specified in the XML file. This version uses a default style of |
| 3151 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3152 | * and the given AttributeSet. |
| 3153 | * |
| 3154 | * <p> |
| 3155 | * The method onFinishInflate() will be called after all children have been |
| 3156 | * added. |
| 3157 | * |
| 3158 | * @param context The Context the view is running in, through which it can |
| 3159 | * access the current theme, resources, etc. |
| 3160 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3161 | * @see #View(Context, AttributeSet, int) |
| 3162 | */ |
| 3163 | public View(Context context, AttributeSet attrs) { |
| 3164 | this(context, attrs, 0); |
| 3165 | } |
| 3166 | |
| 3167 | /** |
| 3168 | * Perform inflation from XML and apply a class-specific base style. This |
| 3169 | * constructor of View allows subclasses to use their own base style when |
| 3170 | * they are inflating. For example, a Button class's constructor would call |
| 3171 | * this version of the super class constructor and supply |
| 3172 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3173 | * the theme's button style to modify all of the base view attributes (in |
| 3174 | * particular its background) as well as the Button class's attributes. |
| 3175 | * |
| 3176 | * @param context The Context the view is running in, through which it can |
| 3177 | * access the current theme, resources, etc. |
| 3178 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3179 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3180 | * will be applied (beyond what is included in the theme). This may |
| 3181 | * either be an attribute resource, whose value will be retrieved |
| 3182 | * from the current theme, or an explicit style resource. |
| 3183 | * @see #View(Context, AttributeSet) |
| 3184 | */ |
| 3185 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3186 | this(context); |
| 3187 | |
| 3188 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3189 | defStyle, 0); |
| 3190 | |
| 3191 | Drawable background = null; |
| 3192 | |
| 3193 | int leftPadding = -1; |
| 3194 | int topPadding = -1; |
| 3195 | int rightPadding = -1; |
| 3196 | int bottomPadding = -1; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3197 | int startPadding = UNDEFINED_PADDING; |
| 3198 | int endPadding = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | |
| 3200 | int padding = -1; |
| 3201 | |
| 3202 | int viewFlagValues = 0; |
| 3203 | int viewFlagMasks = 0; |
| 3204 | |
| 3205 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | int x = 0; |
| 3208 | int y = 0; |
| 3209 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3210 | float tx = 0; |
| 3211 | float ty = 0; |
| 3212 | float rotation = 0; |
| 3213 | float rotationX = 0; |
| 3214 | float rotationY = 0; |
| 3215 | float sx = 1f; |
| 3216 | float sy = 1f; |
| 3217 | boolean transformSet = false; |
| 3218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3220 | int overScrollMode = mOverScrollMode; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3221 | boolean initializeScrollbars = false; |
| 3222 | |
| 3223 | final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
| 3224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | final int N = a.getIndexCount(); |
| 3226 | for (int i = 0; i < N; i++) { |
| 3227 | int attr = a.getIndex(i); |
| 3228 | switch (attr) { |
| 3229 | case com.android.internal.R.styleable.View_background: |
| 3230 | background = a.getDrawable(attr); |
| 3231 | break; |
| 3232 | case com.android.internal.R.styleable.View_padding: |
| 3233 | padding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3234 | mUserPaddingLeftDefined = true; |
| 3235 | mUserPaddingRightDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | break; |
| 3237 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3238 | leftPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3239 | mUserPaddingLeftDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3240 | break; |
| 3241 | case com.android.internal.R.styleable.View_paddingTop: |
| 3242 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3243 | break; |
| 3244 | case com.android.internal.R.styleable.View_paddingRight: |
| 3245 | rightPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3246 | mUserPaddingRightDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | break; |
| 3248 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3249 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3250 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3251 | case com.android.internal.R.styleable.View_paddingStart: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3252 | startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3253 | break; |
| 3254 | case com.android.internal.R.styleable.View_paddingEnd: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3255 | endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3256 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | case com.android.internal.R.styleable.View_scrollX: |
| 3258 | x = a.getDimensionPixelOffset(attr, 0); |
| 3259 | break; |
| 3260 | case com.android.internal.R.styleable.View_scrollY: |
| 3261 | y = a.getDimensionPixelOffset(attr, 0); |
| 3262 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3263 | case com.android.internal.R.styleable.View_alpha: |
| 3264 | setAlpha(a.getFloat(attr, 1f)); |
| 3265 | break; |
| 3266 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3267 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3268 | break; |
| 3269 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3270 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3271 | break; |
| 3272 | case com.android.internal.R.styleable.View_translationX: |
| 3273 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3274 | transformSet = true; |
| 3275 | break; |
| 3276 | case com.android.internal.R.styleable.View_translationY: |
| 3277 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3278 | transformSet = true; |
| 3279 | break; |
| 3280 | case com.android.internal.R.styleable.View_rotation: |
| 3281 | rotation = a.getFloat(attr, 0); |
| 3282 | transformSet = true; |
| 3283 | break; |
| 3284 | case com.android.internal.R.styleable.View_rotationX: |
| 3285 | rotationX = a.getFloat(attr, 0); |
| 3286 | transformSet = true; |
| 3287 | break; |
| 3288 | case com.android.internal.R.styleable.View_rotationY: |
| 3289 | rotationY = a.getFloat(attr, 0); |
| 3290 | transformSet = true; |
| 3291 | break; |
| 3292 | case com.android.internal.R.styleable.View_scaleX: |
| 3293 | sx = a.getFloat(attr, 1f); |
| 3294 | transformSet = true; |
| 3295 | break; |
| 3296 | case com.android.internal.R.styleable.View_scaleY: |
| 3297 | sy = a.getFloat(attr, 1f); |
| 3298 | transformSet = true; |
| 3299 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | case com.android.internal.R.styleable.View_id: |
| 3301 | mID = a.getResourceId(attr, NO_ID); |
| 3302 | break; |
| 3303 | case com.android.internal.R.styleable.View_tag: |
| 3304 | mTag = a.getText(attr); |
| 3305 | break; |
| 3306 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3307 | if (a.getBoolean(attr, false)) { |
| 3308 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3309 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3310 | } |
| 3311 | break; |
| 3312 | case com.android.internal.R.styleable.View_focusable: |
| 3313 | if (a.getBoolean(attr, false)) { |
| 3314 | viewFlagValues |= FOCUSABLE; |
| 3315 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3316 | } |
| 3317 | break; |
| 3318 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3319 | if (a.getBoolean(attr, false)) { |
| 3320 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3321 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3322 | } |
| 3323 | break; |
| 3324 | case com.android.internal.R.styleable.View_clickable: |
| 3325 | if (a.getBoolean(attr, false)) { |
| 3326 | viewFlagValues |= CLICKABLE; |
| 3327 | viewFlagMasks |= CLICKABLE; |
| 3328 | } |
| 3329 | break; |
| 3330 | case com.android.internal.R.styleable.View_longClickable: |
| 3331 | if (a.getBoolean(attr, false)) { |
| 3332 | viewFlagValues |= LONG_CLICKABLE; |
| 3333 | viewFlagMasks |= LONG_CLICKABLE; |
| 3334 | } |
| 3335 | break; |
| 3336 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3337 | if (!a.getBoolean(attr, true)) { |
| 3338 | viewFlagValues |= SAVE_DISABLED; |
| 3339 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3340 | } |
| 3341 | break; |
| 3342 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3343 | if (a.getBoolean(attr, false)) { |
| 3344 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3345 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3346 | } |
| 3347 | break; |
| 3348 | case com.android.internal.R.styleable.View_visibility: |
| 3349 | final int visibility = a.getInt(attr, 0); |
| 3350 | if (visibility != 0) { |
| 3351 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3352 | viewFlagMasks |= VISIBILITY_MASK; |
| 3353 | } |
| 3354 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3355 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3356 | // Clear any layout direction flags (included resolved bits) already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3357 | mPrivateFlags2 &= ~(PFLAG2_LAYOUT_DIRECTION_MASK | PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3358 | // 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] | 3359 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3360 | final int value = (layoutDirection != -1) ? |
| 3361 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3362 | mPrivateFlags2 |= (value << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3363 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3365 | final int cacheQuality = a.getInt(attr, 0); |
| 3366 | if (cacheQuality != 0) { |
| 3367 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3368 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3369 | } |
| 3370 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3371 | case com.android.internal.R.styleable.View_contentDescription: |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 3372 | setContentDescription(a.getString(attr)); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3373 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3375 | if (!a.getBoolean(attr, true)) { |
| 3376 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3377 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3378 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3379 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3381 | if (!a.getBoolean(attr, true)) { |
| 3382 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3383 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3384 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3385 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | case R.styleable.View_scrollbars: |
| 3387 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3388 | if (scrollbars != SCROLLBARS_NONE) { |
| 3389 | viewFlagValues |= scrollbars; |
| 3390 | viewFlagMasks |= SCROLLBARS_MASK; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3391 | initializeScrollbars = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | } |
| 3393 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3394 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | case R.styleable.View_fadingEdge: |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3396 | if (targetSdkVersion >= ICE_CREAM_SANDWICH) { |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3397 | // Ignore the attribute starting with ICS |
| 3398 | break; |
| 3399 | } |
| 3400 | // With builds < ICS, fall through and apply fading edges |
| 3401 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3403 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3404 | viewFlagValues |= fadingEdge; |
| 3405 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3406 | initializeFadingEdge(a); |
| 3407 | } |
| 3408 | break; |
| 3409 | case R.styleable.View_scrollbarStyle: |
| 3410 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3411 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3412 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3413 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3414 | } |
| 3415 | break; |
| 3416 | case R.styleable.View_isScrollContainer: |
| 3417 | setScrollContainer = true; |
| 3418 | if (a.getBoolean(attr, false)) { |
| 3419 | setScrollContainer(true); |
| 3420 | } |
| 3421 | break; |
| 3422 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3423 | if (a.getBoolean(attr, false)) { |
| 3424 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3425 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3426 | } |
| 3427 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3428 | case R.styleable.View_filterTouchesWhenObscured: |
| 3429 | if (a.getBoolean(attr, false)) { |
| 3430 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3431 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3432 | } |
| 3433 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3434 | case R.styleable.View_nextFocusLeft: |
| 3435 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3436 | break; |
| 3437 | case R.styleable.View_nextFocusRight: |
| 3438 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3439 | break; |
| 3440 | case R.styleable.View_nextFocusUp: |
| 3441 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3442 | break; |
| 3443 | case R.styleable.View_nextFocusDown: |
| 3444 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3445 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3446 | case R.styleable.View_nextFocusForward: |
| 3447 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3448 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | case R.styleable.View_minWidth: |
| 3450 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3451 | break; |
| 3452 | case R.styleable.View_minHeight: |
| 3453 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3454 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3455 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3456 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3457 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3458 | + "be used within a restricted context"); |
| 3459 | } |
| 3460 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3461 | final String handlerName = a.getString(attr); |
| 3462 | if (handlerName != null) { |
| 3463 | setOnClickListener(new OnClickListener() { |
| 3464 | private Method mHandler; |
| 3465 | |
| 3466 | public void onClick(View v) { |
| 3467 | if (mHandler == null) { |
| 3468 | try { |
| 3469 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3470 | View.class); |
| 3471 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3472 | int id = getId(); |
| 3473 | String idText = id == NO_ID ? "" : " with id '" |
| 3474 | + getContext().getResources().getResourceEntryName( |
| 3475 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3476 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3477 | handlerName + "(View) in the activity " |
| 3478 | + getContext().getClass() + " for onClick handler" |
| 3479 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | try { |
| 3484 | mHandler.invoke(getContext(), View.this); |
| 3485 | } catch (IllegalAccessException e) { |
| 3486 | throw new IllegalStateException("Could not execute non " |
| 3487 | + "public method of the activity", e); |
| 3488 | } catch (InvocationTargetException e) { |
| 3489 | throw new IllegalStateException("Could not execute " |
| 3490 | + "method of the activity", e); |
| 3491 | } |
| 3492 | } |
| 3493 | }); |
| 3494 | } |
| 3495 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3496 | case R.styleable.View_overScrollMode: |
| 3497 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3498 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3499 | case R.styleable.View_verticalScrollbarPosition: |
| 3500 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3501 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3502 | case R.styleable.View_layerType: |
| 3503 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3504 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3505 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3506 | // Clear any text direction flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3507 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3508 | // Set the text direction flags depending on the value of the attribute |
| 3509 | final int textDirection = a.getInt(attr, -1); |
| 3510 | if (textDirection != -1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3511 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_FLAGS[textDirection]; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3512 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3513 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3514 | case R.styleable.View_textAlignment: |
| 3515 | // Clear any text alignment flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3516 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3517 | // Set the text alignment flag depending on the value of the attribute |
| 3518 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3519 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_FLAGS[textAlignment]; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3520 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3521 | case R.styleable.View_importantForAccessibility: |
| 3522 | setImportantForAccessibility(a.getInt(attr, |
| 3523 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 3524 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | } |
| 3526 | } |
| 3527 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3528 | setOverScrollMode(overScrollMode); |
| 3529 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3530 | // Cache start/end user padding as we cannot fully resolve padding here (we dont have yet |
| 3531 | // the resolved layout direction). Those cached values will be used later during padding |
| 3532 | // resolution. |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3533 | mUserPaddingStart = startPadding; |
| 3534 | mUserPaddingEnd = endPadding; |
| 3535 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3536 | if (background != null) { |
| 3537 | setBackground(background); |
| 3538 | } |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3540 | if (padding >= 0) { |
| 3541 | leftPadding = padding; |
| 3542 | topPadding = padding; |
| 3543 | rightPadding = padding; |
| 3544 | bottomPadding = padding; |
| 3545 | } |
| 3546 | |
| 3547 | // If the user specified the padding (either with android:padding or |
| 3548 | // android:paddingLeft/Top/Right/Bottom), use this padding, otherwise |
| 3549 | // use the default padding or the padding from the background drawable |
| 3550 | // (stored at this point in mPadding*) |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3551 | internalSetPadding(leftPadding >= 0 ? leftPadding : mPaddingLeft, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | topPadding >= 0 ? topPadding : mPaddingTop, |
| 3553 | rightPadding >= 0 ? rightPadding : mPaddingRight, |
| 3554 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3555 | |
| 3556 | if (viewFlagMasks != 0) { |
| 3557 | setFlags(viewFlagValues, viewFlagMasks); |
| 3558 | } |
| 3559 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3560 | if (initializeScrollbars) { |
| 3561 | initializeScrollbars(a); |
| 3562 | } |
| 3563 | |
| 3564 | a.recycle(); |
| 3565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | // Needs to be called after mViewFlags is set |
| 3567 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3568 | recomputePadding(); |
| 3569 | } |
| 3570 | |
| 3571 | if (x != 0 || y != 0) { |
| 3572 | scrollTo(x, y); |
| 3573 | } |
| 3574 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3575 | if (transformSet) { |
| 3576 | setTranslationX(tx); |
| 3577 | setTranslationY(ty); |
| 3578 | setRotation(rotation); |
| 3579 | setRotationX(rotationX); |
| 3580 | setRotationY(rotationY); |
| 3581 | setScaleX(sx); |
| 3582 | setScaleY(sy); |
| 3583 | } |
| 3584 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3586 | setScrollContainer(true); |
| 3587 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3588 | |
| 3589 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | /** |
| 3593 | * Non-public constructor for use in testing |
| 3594 | */ |
| 3595 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3596 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | } |
| 3598 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3599 | public String toString() { |
| 3600 | StringBuilder out = new StringBuilder(128); |
| 3601 | out.append(getClass().getName()); |
| 3602 | out.append('{'); |
| 3603 | out.append(Integer.toHexString(System.identityHashCode(this))); |
| 3604 | out.append(' '); |
| 3605 | switch (mViewFlags&VISIBILITY_MASK) { |
| 3606 | case VISIBLE: out.append('V'); break; |
| 3607 | case INVISIBLE: out.append('I'); break; |
| 3608 | case GONE: out.append('G'); break; |
| 3609 | default: out.append('.'); break; |
| 3610 | } |
| 3611 | out.append((mViewFlags&FOCUSABLE_MASK) == FOCUSABLE ? 'F' : '.'); |
| 3612 | out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.'); |
| 3613 | out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D'); |
| 3614 | out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.'); |
| 3615 | out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.'); |
| 3616 | out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.'); |
| 3617 | out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.'); |
| 3618 | out.append(' '); |
| 3619 | out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.'); |
| 3620 | out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.'); |
| 3621 | out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.'); |
| 3622 | if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) { |
| 3623 | out.append('p'); |
| 3624 | } else { |
| 3625 | out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.'); |
| 3626 | } |
| 3627 | out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.'); |
| 3628 | out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.'); |
| 3629 | out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.'); |
| 3630 | out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.'); |
| 3631 | out.append(' '); |
| 3632 | out.append(mLeft); |
| 3633 | out.append(','); |
| 3634 | out.append(mTop); |
| 3635 | out.append('-'); |
| 3636 | out.append(mRight); |
| 3637 | out.append(','); |
| 3638 | out.append(mBottom); |
| 3639 | final int id = getId(); |
| 3640 | if (id != NO_ID) { |
| 3641 | out.append(" #"); |
| 3642 | out.append(Integer.toHexString(id)); |
| 3643 | final Resources r = mResources; |
| 3644 | if (id != 0 && r != null) { |
| 3645 | try { |
| 3646 | String pkgname; |
| 3647 | switch (id&0xff000000) { |
| 3648 | case 0x7f000000: |
| 3649 | pkgname="app"; |
| 3650 | break; |
| 3651 | case 0x01000000: |
| 3652 | pkgname="android"; |
| 3653 | break; |
| 3654 | default: |
| 3655 | pkgname = r.getResourcePackageName(id); |
| 3656 | break; |
| 3657 | } |
| 3658 | String typename = r.getResourceTypeName(id); |
| 3659 | String entryname = r.getResourceEntryName(id); |
| 3660 | out.append(" "); |
| 3661 | out.append(pkgname); |
| 3662 | out.append(":"); |
| 3663 | out.append(typename); |
| 3664 | out.append("/"); |
| 3665 | out.append(entryname); |
| 3666 | } catch (Resources.NotFoundException e) { |
| 3667 | } |
| 3668 | } |
| 3669 | } |
| 3670 | out.append("}"); |
| 3671 | return out.toString(); |
| 3672 | } |
| 3673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | /** |
| 3675 | * <p> |
| 3676 | * Initializes the fading edges from a given set of styled attributes. This |
| 3677 | * method should be called by subclasses that need fading edges 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 fading edges from |
| 3684 | */ |
| 3685 | protected void initializeFadingEdge(TypedArray a) { |
| 3686 | initScrollCache(); |
| 3687 | |
| 3688 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3689 | R.styleable.View_fadingEdgeLength, |
| 3690 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3691 | } |
| 3692 | |
| 3693 | /** |
| 3694 | * Returns the size of the vertical faded edges used to indicate that more |
| 3695 | * content in this view is visible. |
| 3696 | * |
| 3697 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3698 | * faded edges are not enabled for this view. |
| 3699 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3700 | */ |
| 3701 | public int getVerticalFadingEdgeLength() { |
| 3702 | if (isVerticalFadingEdgeEnabled()) { |
| 3703 | ScrollabilityCache cache = mScrollCache; |
| 3704 | if (cache != null) { |
| 3705 | return cache.fadingEdgeLength; |
| 3706 | } |
| 3707 | } |
| 3708 | return 0; |
| 3709 | } |
| 3710 | |
| 3711 | /** |
| 3712 | * Set the size of the faded edge used to indicate that more content in this |
| 3713 | * 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] | 3714 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3715 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3716 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3717 | * |
| 3718 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3719 | * content in this view is visible. |
| 3720 | */ |
| 3721 | public void setFadingEdgeLength(int length) { |
| 3722 | initScrollCache(); |
| 3723 | mScrollCache.fadingEdgeLength = length; |
| 3724 | } |
| 3725 | |
| 3726 | /** |
| 3727 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3728 | * content in this view is visible. |
| 3729 | * |
| 3730 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3731 | * faded edges are not enabled for this view. |
| 3732 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3733 | */ |
| 3734 | public int getHorizontalFadingEdgeLength() { |
| 3735 | if (isHorizontalFadingEdgeEnabled()) { |
| 3736 | ScrollabilityCache cache = mScrollCache; |
| 3737 | if (cache != null) { |
| 3738 | return cache.fadingEdgeLength; |
| 3739 | } |
| 3740 | } |
| 3741 | return 0; |
| 3742 | } |
| 3743 | |
| 3744 | /** |
| 3745 | * Returns the width of the vertical scrollbar. |
| 3746 | * |
| 3747 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3748 | * is no vertical scrollbar. |
| 3749 | */ |
| 3750 | public int getVerticalScrollbarWidth() { |
| 3751 | ScrollabilityCache cache = mScrollCache; |
| 3752 | if (cache != null) { |
| 3753 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3754 | if (scrollBar != null) { |
| 3755 | int size = scrollBar.getSize(true); |
| 3756 | if (size <= 0) { |
| 3757 | size = cache.scrollBarSize; |
| 3758 | } |
| 3759 | return size; |
| 3760 | } |
| 3761 | return 0; |
| 3762 | } |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
| 3766 | /** |
| 3767 | * Returns the height of the horizontal scrollbar. |
| 3768 | * |
| 3769 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3770 | * there is no horizontal scrollbar. |
| 3771 | */ |
| 3772 | protected int getHorizontalScrollbarHeight() { |
| 3773 | ScrollabilityCache cache = mScrollCache; |
| 3774 | if (cache != null) { |
| 3775 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3776 | if (scrollBar != null) { |
| 3777 | int size = scrollBar.getSize(false); |
| 3778 | if (size <= 0) { |
| 3779 | size = cache.scrollBarSize; |
| 3780 | } |
| 3781 | return size; |
| 3782 | } |
| 3783 | return 0; |
| 3784 | } |
| 3785 | return 0; |
| 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * <p> |
| 3790 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3791 | * method should be called by subclasses that need scrollbars and when an |
| 3792 | * instance of these subclasses is created programmatically rather than |
| 3793 | * being inflated from XML. This method is automatically called when the XML |
| 3794 | * is inflated. |
| 3795 | * </p> |
| 3796 | * |
| 3797 | * @param a the styled attributes set to initialize the scrollbars from |
| 3798 | */ |
| 3799 | protected void initializeScrollbars(TypedArray a) { |
| 3800 | initScrollCache(); |
| 3801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3803 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3804 | if (scrollabilityCache.scrollBar == null) { |
| 3805 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3806 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3807 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3808 | 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] | 3809 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3810 | if (!fadeScrollbars) { |
| 3811 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3812 | } |
| 3813 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3814 | |
| 3815 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3816 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3817 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3818 | .getScrollBarFadeDuration()); |
| 3819 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3820 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3821 | ViewConfiguration.getScrollDefaultDelay()); |
| 3822 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3825 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3826 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3827 | |
| 3828 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3829 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3830 | |
| 3831 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3832 | if (thumb != null) { |
| 3833 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3834 | } |
| 3835 | |
| 3836 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3837 | false); |
| 3838 | if (alwaysDraw) { |
| 3839 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3840 | } |
| 3841 | |
| 3842 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3843 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3844 | |
| 3845 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3846 | if (thumb != null) { |
| 3847 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3848 | } |
| 3849 | |
| 3850 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3851 | false); |
| 3852 | if (alwaysDraw) { |
| 3853 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3854 | } |
| 3855 | |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 3856 | // Apply layout direction to the new Drawables if needed |
| 3857 | final int layoutDirection = getResolvedLayoutDirection(); |
| 3858 | if (track != null) { |
| 3859 | track.setLayoutDirection(layoutDirection); |
| 3860 | } |
| 3861 | if (thumb != null) { |
| 3862 | thumb.setLayoutDirection(layoutDirection); |
| 3863 | } |
| 3864 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3866 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | /** |
| 3870 | * <p> |
| 3871 | * Initalizes the scrollability cache if necessary. |
| 3872 | * </p> |
| 3873 | */ |
| 3874 | private void initScrollCache() { |
| 3875 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3876 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | } |
| 3878 | } |
| 3879 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 3880 | private ScrollabilityCache getScrollCache() { |
| 3881 | initScrollCache(); |
| 3882 | return mScrollCache; |
| 3883 | } |
| 3884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3886 | * Set the position of the vertical scroll bar. Should be one of |
| 3887 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 3888 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 3889 | * |
| 3890 | * @param position Where the vertical scroll bar should be positioned. |
| 3891 | */ |
| 3892 | public void setVerticalScrollbarPosition(int position) { |
| 3893 | if (mVerticalScrollbarPosition != position) { |
| 3894 | mVerticalScrollbarPosition = position; |
| 3895 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3896 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | /** |
| 3901 | * @return The position where the vertical scroll bar will show, if applicable. |
| 3902 | * @see #setVerticalScrollbarPosition(int) |
| 3903 | */ |
| 3904 | public int getVerticalScrollbarPosition() { |
| 3905 | return mVerticalScrollbarPosition; |
| 3906 | } |
| 3907 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3908 | ListenerInfo getListenerInfo() { |
| 3909 | if (mListenerInfo != null) { |
| 3910 | return mListenerInfo; |
| 3911 | } |
| 3912 | mListenerInfo = new ListenerInfo(); |
| 3913 | return mListenerInfo; |
| 3914 | } |
| 3915 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3916 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3917 | * Register a callback to be invoked when focus of this view changed. |
| 3918 | * |
| 3919 | * @param l The callback that will run. |
| 3920 | */ |
| 3921 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3922 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3926 | * Add a listener that will be called when the bounds of the view change due to |
| 3927 | * layout processing. |
| 3928 | * |
| 3929 | * @param listener The listener that will be called when layout bounds change. |
| 3930 | */ |
| 3931 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3932 | ListenerInfo li = getListenerInfo(); |
| 3933 | if (li.mOnLayoutChangeListeners == null) { |
| 3934 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3935 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3936 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 3937 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 3938 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
| 3941 | /** |
| 3942 | * Remove a listener for layout changes. |
| 3943 | * |
| 3944 | * @param listener The listener for layout bounds change. |
| 3945 | */ |
| 3946 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3947 | ListenerInfo li = mListenerInfo; |
| 3948 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3949 | return; |
| 3950 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3951 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3955 | * Add a listener for attach state changes. |
| 3956 | * |
| 3957 | * This listener will be called whenever this view is attached or detached |
| 3958 | * from a window. Remove the listener using |
| 3959 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 3960 | * |
| 3961 | * @param listener Listener to attach |
| 3962 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3963 | */ |
| 3964 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3965 | ListenerInfo li = getListenerInfo(); |
| 3966 | if (li.mOnAttachStateChangeListeners == null) { |
| 3967 | li.mOnAttachStateChangeListeners |
| 3968 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3969 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3970 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3971 | } |
| 3972 | |
| 3973 | /** |
| 3974 | * Remove a listener for attach state changes. The listener will receive no further |
| 3975 | * notification of window attach/detach events. |
| 3976 | * |
| 3977 | * @param listener Listener to remove |
| 3978 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 3979 | */ |
| 3980 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3981 | ListenerInfo li = mListenerInfo; |
| 3982 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3983 | return; |
| 3984 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3985 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | * Returns the focus-change callback registered for this view. |
| 3990 | * |
| 3991 | * @return The callback, or null if one is not registered. |
| 3992 | */ |
| 3993 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 3994 | ListenerInfo li = mListenerInfo; |
| 3995 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | /** |
| 3999 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 4000 | * clickable, it becomes clickable. |
| 4001 | * |
| 4002 | * @param l The callback that will run |
| 4003 | * |
| 4004 | * @see #setClickable(boolean) |
| 4005 | */ |
| 4006 | public void setOnClickListener(OnClickListener l) { |
| 4007 | if (!isClickable()) { |
| 4008 | setClickable(true); |
| 4009 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4010 | getListenerInfo().mOnClickListener = l; |
| 4011 | } |
| 4012 | |
| 4013 | /** |
| 4014 | * Return whether this view has an attached OnClickListener. Returns |
| 4015 | * true if there is a listener, false if there is none. |
| 4016 | */ |
| 4017 | public boolean hasOnClickListeners() { |
| 4018 | ListenerInfo li = mListenerInfo; |
| 4019 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | /** |
| 4023 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 4024 | * long clickable, it becomes long clickable. |
| 4025 | * |
| 4026 | * @param l The callback that will run |
| 4027 | * |
| 4028 | * @see #setLongClickable(boolean) |
| 4029 | */ |
| 4030 | public void setOnLongClickListener(OnLongClickListener l) { |
| 4031 | if (!isLongClickable()) { |
| 4032 | setLongClickable(true); |
| 4033 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4034 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | /** |
| 4038 | * Register a callback to be invoked when the context menu for this view is |
| 4039 | * being built. If this view is not long clickable, it becomes long clickable. |
| 4040 | * |
| 4041 | * @param l The callback that will run |
| 4042 | * |
| 4043 | */ |
| 4044 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 4045 | if (!isLongClickable()) { |
| 4046 | setLongClickable(true); |
| 4047 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4048 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4052 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 4053 | * actions associated with clicking: reporting accessibility event, playing |
| 4054 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | * |
| 4056 | * @return True there was an assigned OnClickListener that was called, false |
| 4057 | * otherwise is returned. |
| 4058 | */ |
| 4059 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4060 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 4061 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4062 | ListenerInfo li = mListenerInfo; |
| 4063 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4065 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | return true; |
| 4067 | } |
| 4068 | |
| 4069 | return false; |
| 4070 | } |
| 4071 | |
| 4072 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4073 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 4074 | * this only calls the listener, and does not do any associated clicking |
| 4075 | * actions like reporting an accessibility event. |
| 4076 | * |
| 4077 | * @return True there was an assigned OnClickListener that was called, false |
| 4078 | * otherwise is returned. |
| 4079 | */ |
| 4080 | public boolean callOnClick() { |
| 4081 | ListenerInfo li = mListenerInfo; |
| 4082 | if (li != null && li.mOnClickListener != null) { |
| 4083 | li.mOnClickListener.onClick(this); |
| 4084 | return true; |
| 4085 | } |
| 4086 | return false; |
| 4087 | } |
| 4088 | |
| 4089 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4090 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 4091 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4093 | * @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] | 4094 | */ |
| 4095 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4096 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 4097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4099 | ListenerInfo li = mListenerInfo; |
| 4100 | if (li != null && li.mOnLongClickListener != null) { |
| 4101 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | } |
| 4103 | if (!handled) { |
| 4104 | handled = showContextMenu(); |
| 4105 | } |
| 4106 | if (handled) { |
| 4107 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 4108 | } |
| 4109 | return handled; |
| 4110 | } |
| 4111 | |
| 4112 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4113 | * Performs button-related actions during a touch down event. |
| 4114 | * |
| 4115 | * @param event The event. |
| 4116 | * @return True if the down was consumed. |
| 4117 | * |
| 4118 | * @hide |
| 4119 | */ |
| 4120 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 4121 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 4122 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 4123 | return true; |
| 4124 | } |
| 4125 | } |
| 4126 | return false; |
| 4127 | } |
| 4128 | |
| 4129 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | * Bring up the context menu for this view. |
| 4131 | * |
| 4132 | * @return Whether a context menu was displayed. |
| 4133 | */ |
| 4134 | public boolean showContextMenu() { |
| 4135 | return getParent().showContextMenuForChild(this); |
| 4136 | } |
| 4137 | |
| 4138 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4139 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 4140 | * |
| 4141 | * @param x The referenced x coordinate. |
| 4142 | * @param y The referenced y coordinate. |
| 4143 | * @param metaState The keyboard modifiers that were pressed. |
| 4144 | * @return Whether a context menu was displayed. |
| 4145 | * |
| 4146 | * @hide |
| 4147 | */ |
| 4148 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4149 | return showContextMenu(); |
| 4150 | } |
| 4151 | |
| 4152 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4153 | * Start an action mode. |
| 4154 | * |
| 4155 | * @param callback Callback that will control the lifecycle of the action mode |
| 4156 | * @return The new action mode if it is started, null otherwise |
| 4157 | * |
| 4158 | * @see ActionMode |
| 4159 | */ |
| 4160 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4161 | ViewParent parent = getParent(); |
| 4162 | if (parent == null) return null; |
| 4163 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 4167 | * Register a callback to be invoked when a hardware key is pressed in this view. |
| 4168 | * Key presses in software input methods will generally not trigger the methods of |
| 4169 | * this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | * @param l the key listener to attach to this view |
| 4171 | */ |
| 4172 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4173 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | /** |
| 4177 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4178 | * @param l the touch listener to attach to this view |
| 4179 | */ |
| 4180 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4181 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4185 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4186 | * @param l the generic motion listener to attach to this view |
| 4187 | */ |
| 4188 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4189 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4193 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4194 | * @param l the hover listener to attach to this view |
| 4195 | */ |
| 4196 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4197 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4201 | * Register a drag event listener callback object for this View. The parameter is |
| 4202 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4203 | * View, the system calls the |
| 4204 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4205 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4206 | */ |
| 4207 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4208 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4212 | * Give this view focus. This will cause |
| 4213 | * {@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] | 4214 | * |
| 4215 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4216 | * gives it focus no matter what. It should only be called internally by framework |
| 4217 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4218 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4219 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4220 | * {@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] | 4221 | * focus moved when requestFocus() is called. It may not always |
| 4222 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4223 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4224 | * prior in this View's coordinate system. |
| 4225 | */ |
| 4226 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4227 | if (DBG) { |
| 4228 | System.out.println(this + " requestFocus()"); |
| 4229 | } |
| 4230 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4231 | if ((mPrivateFlags & PFLAG_FOCUSED) == 0) { |
| 4232 | mPrivateFlags |= PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | |
| 4234 | if (mParent != null) { |
| 4235 | mParent.requestChildFocus(this, this); |
| 4236 | } |
| 4237 | |
| 4238 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4239 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4240 | |
| 4241 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4242 | notifyAccessibilityStateChanged(); |
| 4243 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | } |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Request that a rectangle of this view be visible on the screen, |
| 4249 | * scrolling if necessary just enough. |
| 4250 | * |
| 4251 | * <p>A View should call this if it maintains some notion of which part |
| 4252 | * of its content is interesting. For example, a text editing view |
| 4253 | * should call this when its cursor moves. |
| 4254 | * |
| 4255 | * @param rectangle The rectangle. |
| 4256 | * @return Whether any parent scrolled. |
| 4257 | */ |
| 4258 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4259 | return requestRectangleOnScreen(rectangle, false); |
| 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * Request that a rectangle of this view be visible on the screen, |
| 4264 | * scrolling if necessary just enough. |
| 4265 | * |
| 4266 | * <p>A View should call this if it maintains some notion of which part |
| 4267 | * of its content is interesting. For example, a text editing view |
| 4268 | * should call this when its cursor moves. |
| 4269 | * |
| 4270 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4271 | * animated. |
| 4272 | * |
| 4273 | * @param rectangle The rectangle. |
| 4274 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4275 | * @return Whether any parent scrolled. |
| 4276 | */ |
| 4277 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
| 4278 | View child = this; |
| 4279 | ViewParent parent = mParent; |
| 4280 | boolean scrolled = false; |
| 4281 | while (parent != null) { |
| 4282 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4283 | rectangle, immediate); |
| 4284 | |
| 4285 | // offset rect so next call has the rectangle in the |
| 4286 | // coordinate system of its direct child. |
| 4287 | rectangle.offset(child.getLeft(), child.getTop()); |
| 4288 | rectangle.offset(-child.getScrollX(), -child.getScrollY()); |
| 4289 | |
| 4290 | if (!(parent instanceof View)) { |
| 4291 | break; |
| 4292 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | child = (View) parent; |
| 4295 | parent = child.getParent(); |
| 4296 | } |
| 4297 | return scrolled; |
| 4298 | } |
| 4299 | |
| 4300 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4301 | * Called when this view wants to give up focus. If focus is cleared |
| 4302 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4303 | * <p> |
| 4304 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4305 | * 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] | 4306 | * View is the first from the top that can take focus, then all callbacks |
| 4307 | * related to clearing focus will be invoked after wich the framework will |
| 4308 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4309 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | */ |
| 4311 | public void clearFocus() { |
| 4312 | if (DBG) { |
| 4313 | System.out.println(this + " clearFocus()"); |
| 4314 | } |
| 4315 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4316 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4317 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | |
| 4319 | if (mParent != null) { |
| 4320 | mParent.clearChildFocus(this); |
| 4321 | } |
| 4322 | |
| 4323 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4326 | |
| 4327 | ensureInputFocusOnFirstFocusable(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4330 | notifyAccessibilityStateChanged(); |
| 4331 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| 4333 | } |
| 4334 | |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4335 | void ensureInputFocusOnFirstFocusable() { |
| 4336 | View root = getRootView(); |
| 4337 | if (root != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4338 | root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | } |
| 4340 | } |
| 4341 | |
| 4342 | /** |
| 4343 | * Called internally by the view system when a new view is getting focus. |
| 4344 | * This is what clears the old focus. |
| 4345 | */ |
| 4346 | void unFocus() { |
| 4347 | if (DBG) { |
| 4348 | System.out.println(this + " unFocus()"); |
| 4349 | } |
| 4350 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4351 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4352 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4353 | |
| 4354 | onFocusChanged(false, 0, null); |
| 4355 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4356 | |
| 4357 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4358 | notifyAccessibilityStateChanged(); |
| 4359 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4365 | * view that has focus. |
| 4366 | * |
| 4367 | * @return True if this view has or contains focus, false otherwise. |
| 4368 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4369 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | public boolean hasFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4371 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | /** |
| 4375 | * Returns true if this view is focusable or if it contains a reachable View |
| 4376 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4377 | * is a View whose parents do not block descendants focus. |
| 4378 | * |
| 4379 | * Only {@link #VISIBLE} views are considered focusable. |
| 4380 | * |
| 4381 | * @return True if the view is focusable or if the view contains a focusable |
| 4382 | * View, false otherwise. |
| 4383 | * |
| 4384 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4385 | */ |
| 4386 | public boolean hasFocusable() { |
| 4387 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4388 | } |
| 4389 | |
| 4390 | /** |
| 4391 | * Called by the view system when the focus state of this view changes. |
| 4392 | * When the focus change event is caused by directional navigation, direction |
| 4393 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4394 | * When overriding, be sure to call up through to the super class so that |
| 4395 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4396 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | * @param gainFocus True if the View has focus; false otherwise. |
| 4398 | * @param direction The direction focus has moved when requestFocus() |
| 4399 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4400 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4401 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4402 | * 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] | 4403 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4404 | * system, of the previously focused view. If applicable, this will be |
| 4405 | * passed in as finer grained information about where the focus is coming |
| 4406 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4407 | */ |
| 4408 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4409 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4410 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4411 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4412 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4413 | } |
| 4414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4416 | if (!gainFocus) { |
| 4417 | if (isPressed()) { |
| 4418 | setPressed(false); |
| 4419 | } |
| 4420 | if (imm != null && mAttachInfo != null |
| 4421 | && mAttachInfo.mHasWindowFocus) { |
| 4422 | imm.focusOut(this); |
| 4423 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4424 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | } else if (imm != null && mAttachInfo != null |
| 4426 | && mAttachInfo.mHasWindowFocus) { |
| 4427 | imm.focusIn(this); |
| 4428 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4429 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4430 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4431 | ListenerInfo li = mListenerInfo; |
| 4432 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4433 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4434 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4435 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4436 | if (mAttachInfo != null) { |
| 4437 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | } |
| 4440 | |
| 4441 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4442 | * Sends an accessibility event of the given type. If accessiiblity is |
| 4443 | * not enabled this method has no effect. The default implementation calls |
| 4444 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4445 | * to populate information about the event source (this View), then calls |
| 4446 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4447 | * populate the text content of the event source including its descendants, |
| 4448 | * and last calls |
| 4449 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4450 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4451 | * <p> |
| 4452 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4453 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4454 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4455 | * responsible for handling this call. |
| 4456 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4457 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4458 | * @param eventType The type of the event to send, as defined by several types from |
| 4459 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4460 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4461 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4462 | * |
| 4463 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4464 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4465 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4466 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4467 | */ |
| 4468 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4469 | if (mAccessibilityDelegate != null) { |
| 4470 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4471 | } else { |
| 4472 | sendAccessibilityEventInternal(eventType); |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4477 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4478 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4479 | * sort of a context change for which none of the events representing UI transitions |
| 4480 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4481 | * is not enabled this method does nothing. |
| 4482 | * |
| 4483 | * @param text The announcement text. |
| 4484 | */ |
| 4485 | public void announceForAccessibility(CharSequence text) { |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4486 | if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) { |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4487 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4488 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4489 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4490 | event.getText().add(text); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4491 | event.setContentDescription(null); |
| 4492 | mParent.requestSendAccessibilityEvent(this, event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4493 | } |
| 4494 | } |
| 4495 | |
| 4496 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4497 | * @see #sendAccessibilityEvent(int) |
| 4498 | * |
| 4499 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4500 | */ |
| 4501 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4502 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4503 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4504 | } |
| 4505 | } |
| 4506 | |
| 4507 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4508 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4509 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4510 | * perform a check whether accessibility is enabled. |
| 4511 | * <p> |
| 4512 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4513 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4514 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4515 | * is responsible for handling this call. |
| 4516 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4517 | * |
| 4518 | * @param event The event to send. |
| 4519 | * |
| 4520 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4521 | */ |
| 4522 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4523 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4524 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4525 | } else { |
| 4526 | sendAccessibilityEventUncheckedInternal(event); |
| 4527 | } |
| 4528 | } |
| 4529 | |
| 4530 | /** |
| 4531 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4532 | * |
| 4533 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4534 | */ |
| 4535 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4536 | if (!isShown()) { |
| 4537 | return; |
| 4538 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4539 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4540 | // Only a subset of accessibility events populates text content. |
| 4541 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4542 | dispatchPopulateAccessibilityEvent(event); |
| 4543 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4544 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4545 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4549 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4550 | * to its children for adding their text content to the event. Note that the |
| 4551 | * event text is populated in a separate dispatch path since we add to the |
| 4552 | * 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] | 4553 | * A typical implementation will call |
| 4554 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4555 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4556 | * on each child. Override this method if custom population of the event text |
| 4557 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4558 | * <p> |
| 4559 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4560 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4561 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4562 | * is responsible for handling this call. |
| 4563 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4564 | * <p> |
| 4565 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4566 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4567 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4568 | * |
| 4569 | * @param event The event. |
| 4570 | * |
| 4571 | * @return True if the event population was completed. |
| 4572 | */ |
| 4573 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4574 | if (mAccessibilityDelegate != null) { |
| 4575 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4576 | } else { |
| 4577 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | /** |
| 4582 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4583 | * |
| 4584 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4585 | */ |
| 4586 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4587 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4588 | return false; |
| 4589 | } |
| 4590 | |
| 4591 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4592 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4593 | * 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] | 4594 | * text content. While this method is free to modify event |
| 4595 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4596 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4597 | * <p> |
| 4598 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4599 | * to the text added by the super implementation: |
| 4600 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4601 | * super.onPopulateAccessibilityEvent(event); |
| 4602 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4603 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4604 | * mCurrentDate.getTimeInMillis(), flags); |
| 4605 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4606 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4607 | * <p> |
| 4608 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4609 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4610 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4611 | * is responsible for handling this call. |
| 4612 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4613 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4614 | * information to the event, in case the default implementation has basic information to add. |
| 4615 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4616 | * |
| 4617 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4618 | * |
| 4619 | * @see #sendAccessibilityEvent(int) |
| 4620 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4621 | */ |
| 4622 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4623 | if (mAccessibilityDelegate != null) { |
| 4624 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4625 | } else { |
| 4626 | onPopulateAccessibilityEventInternal(event); |
| 4627 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4631 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4632 | * |
| 4633 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4634 | */ |
| 4635 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4636 | |
| 4637 | } |
| 4638 | |
| 4639 | /** |
| 4640 | * Initializes an {@link AccessibilityEvent} with information about |
| 4641 | * this View which is the event source. In other words, the source of |
| 4642 | * an accessibility event is the view whose state change triggered firing |
| 4643 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4644 | * <p> |
| 4645 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4646 | * to properties set by the super implementation: |
| 4647 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4648 | * super.onInitializeAccessibilityEvent(event); |
| 4649 | * event.setPassword(true); |
| 4650 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4651 | * <p> |
| 4652 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4653 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4654 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4655 | * is responsible for handling this call. |
| 4656 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4657 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4658 | * information to the event, in case the default implementation has basic information to add. |
| 4659 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4660 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4661 | * |
| 4662 | * @see #sendAccessibilityEvent(int) |
| 4663 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4664 | */ |
| 4665 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4666 | if (mAccessibilityDelegate != null) { |
| 4667 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4668 | } else { |
| 4669 | onInitializeAccessibilityEventInternal(event); |
| 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | /** |
| 4674 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4675 | * |
| 4676 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4677 | */ |
| 4678 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4679 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4680 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4681 | event.setPackageName(getContext().getPackageName()); |
| 4682 | event.setEnabled(isEnabled()); |
| 4683 | event.setContentDescription(mContentDescription); |
| 4684 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4685 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4686 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4687 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4688 | FOCUSABLES_ALL); |
| 4689 | event.setItemCount(focusablesTempList.size()); |
| 4690 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4691 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4696 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4697 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4698 | * This method is responsible for obtaining an accessibility node info from a |
| 4699 | * pool of reusable instances and calling |
| 4700 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4701 | * initialize the former. |
| 4702 | * <p> |
| 4703 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4704 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4705 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4706 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4707 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4708 | * |
| 4709 | * @see AccessibilityNodeInfo |
| 4710 | */ |
| 4711 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4712 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4713 | if (provider != null) { |
| 4714 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4715 | } else { |
| 4716 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4717 | onInitializeAccessibilityNodeInfo(info); |
| 4718 | return info; |
| 4719 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4724 | * The base implementation sets: |
| 4725 | * <ul> |
| 4726 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4727 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4728 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4729 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4730 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4731 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4732 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4733 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4734 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4735 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4736 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4737 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4738 | * </ul> |
| 4739 | * <p> |
| 4740 | * Subclasses should override this method, call the super implementation, |
| 4741 | * and set additional attributes. |
| 4742 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4743 | * <p> |
| 4744 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4745 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4746 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4747 | * is responsible for handling this call. |
| 4748 | * </p> |
| 4749 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4750 | * @param info The instance to initialize. |
| 4751 | */ |
| 4752 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4753 | if (mAccessibilityDelegate != null) { |
| 4754 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4755 | } else { |
| 4756 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4757 | } |
| 4758 | } |
| 4759 | |
| 4760 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4761 | * Gets the location of this view in screen coordintates. |
| 4762 | * |
| 4763 | * @param outRect The output location |
| 4764 | */ |
| 4765 | private void getBoundsOnScreen(Rect outRect) { |
| 4766 | if (mAttachInfo == null) { |
| 4767 | return; |
| 4768 | } |
| 4769 | |
| 4770 | RectF position = mAttachInfo.mTmpTransformRect; |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4771 | position.set(0, 0, mRight - mLeft, mBottom - mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4772 | |
| 4773 | if (!hasIdentityMatrix()) { |
| 4774 | getMatrix().mapRect(position); |
| 4775 | } |
| 4776 | |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4777 | position.offset(mLeft, mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4778 | |
| 4779 | ViewParent parent = mParent; |
| 4780 | while (parent instanceof View) { |
| 4781 | View parentView = (View) parent; |
| 4782 | |
| 4783 | position.offset(-parentView.mScrollX, -parentView.mScrollY); |
| 4784 | |
| 4785 | if (!parentView.hasIdentityMatrix()) { |
| 4786 | parentView.getMatrix().mapRect(position); |
| 4787 | } |
| 4788 | |
| 4789 | position.offset(parentView.mLeft, parentView.mTop); |
| 4790 | |
| 4791 | parent = parentView.mParent; |
| 4792 | } |
| 4793 | |
| 4794 | if (parent instanceof ViewRootImpl) { |
| 4795 | ViewRootImpl viewRootImpl = (ViewRootImpl) parent; |
| 4796 | position.offset(0, -viewRootImpl.mCurScrollY); |
| 4797 | } |
| 4798 | |
| 4799 | position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 4800 | |
| 4801 | outRect.set((int) (position.left + 0.5f), (int) (position.top + 0.5f), |
| 4802 | (int) (position.right + 0.5f), (int) (position.bottom + 0.5f)); |
| 4803 | } |
| 4804 | |
| 4805 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4806 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4807 | * |
| 4808 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4809 | */ |
| 4810 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4811 | Rect bounds = mAttachInfo.mTmpInvalRect; |
Svetoslav Ganov | 983119a | 2012-07-03 21:04:10 -0700 | [diff] [blame] | 4812 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4813 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4814 | info.setBoundsInParent(bounds); |
| 4815 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4816 | getBoundsOnScreen(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4817 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4818 | |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 4819 | ViewParent parent = getParentForAccessibility(); |
| 4820 | if (parent instanceof View) { |
| 4821 | info.setParent((View) parent); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4824 | info.setVisibleToUser(isVisibleToUser()); |
| 4825 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4826 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4827 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4828 | info.setContentDescription(getContentDescription()); |
| 4829 | |
| 4830 | info.setEnabled(isEnabled()); |
| 4831 | info.setClickable(isClickable()); |
| 4832 | info.setFocusable(isFocusable()); |
| 4833 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4834 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4835 | info.setSelected(isSelected()); |
| 4836 | info.setLongClickable(isLongClickable()); |
| 4837 | |
| 4838 | // TODO: These make sense only if we are in an AdapterView but all |
| 4839 | // views can be selected. Maybe from accessiiblity perspective |
| 4840 | // we should report as selectable view in an AdapterView. |
| 4841 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 4842 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 4843 | |
| 4844 | if (isFocusable()) { |
| 4845 | if (isFocused()) { |
| 4846 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 4847 | } else { |
| 4848 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 4849 | } |
| 4850 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4851 | |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 4852 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 4853 | info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 4854 | } else { |
| 4855 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); |
| 4856 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4857 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 4858 | if (isClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4859 | info.addAction(AccessibilityNodeInfo.ACTION_CLICK); |
| 4860 | } |
| 4861 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 4862 | if (isLongClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4863 | info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK); |
| 4864 | } |
| 4865 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 4866 | if (mContentDescription != null && mContentDescription.length() > 0) { |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 4867 | info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); |
| 4868 | info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); |
| 4869 | info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 4870 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
| 4871 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH); |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 4872 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4876 | * Computes whether this view is visible to the user. Such a view is |
| 4877 | * attached, visible, all its predecessors are visible, it is not clipped |
| 4878 | * entirely by its predecessors, and has an alpha greater than zero. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 4879 | * |
| 4880 | * @return Whether the view is visible on the screen. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 4881 | * |
| 4882 | * @hide |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 4883 | */ |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 4884 | protected boolean isVisibleToUser() { |
| 4885 | return isVisibleToUser(null); |
| 4886 | } |
| 4887 | |
| 4888 | /** |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 4889 | * Computes whether the given portion of this view is visible to the user. |
| 4890 | * Such a view is attached, visible, all its predecessors are visible, |
| 4891 | * has an alpha greater than zero, and the specified portion is not |
| 4892 | * clipped entirely by its predecessors. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 4893 | * |
| 4894 | * @param boundInView the portion of the view to test; coordinates should be relative; may be |
| 4895 | * <code>null</code>, and the entire view will be tested in this case. |
| 4896 | * When <code>true</code> is returned by the function, the actual visible |
| 4897 | * region will be stored in this parameter; that is, if boundInView is fully |
| 4898 | * contained within the view, no modification will be made, otherwise regions |
| 4899 | * outside of the visible area of the view will be clipped. |
| 4900 | * |
| 4901 | * @return Whether the specified portion of the view is visible on the screen. |
| 4902 | * |
| 4903 | * @hide |
| 4904 | */ |
| 4905 | protected boolean isVisibleToUser(Rect boundInView) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 4906 | if (mAttachInfo != null) { |
| 4907 | Rect visibleRect = mAttachInfo.mTmpInvalRect; |
| 4908 | Point offset = mAttachInfo.mPoint; |
| 4909 | // The first two checks are made also made by isShown() which |
| 4910 | // however traverses the tree up to the parent to catch that. |
| 4911 | // Therefore, we do some fail fast check to minimize the up |
| 4912 | // tree traversal. |
| 4913 | boolean isVisible = mAttachInfo.mWindowVisibility == View.VISIBLE |
| 4914 | && getAlpha() > 0 |
| 4915 | && isShown() |
| 4916 | && getGlobalVisibleRect(visibleRect, offset); |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 4917 | if (isVisible && boundInView != null) { |
| 4918 | visibleRect.offset(-offset.x, -offset.y); |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 4919 | // isVisible is always true here, use a simple assignment |
| 4920 | isVisible = boundInView.intersect(visibleRect); |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 4921 | } |
| 4922 | return isVisible; |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | return false; |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | /** |
alanv | b72fe7a | 2012-08-27 16:44:25 -0700 | [diff] [blame] | 4929 | * Returns the delegate for implementing accessibility support via |
| 4930 | * composition. For more details see {@link AccessibilityDelegate}. |
| 4931 | * |
| 4932 | * @return The delegate, or null if none set. |
| 4933 | * |
| 4934 | * @hide |
| 4935 | */ |
| 4936 | public AccessibilityDelegate getAccessibilityDelegate() { |
| 4937 | return mAccessibilityDelegate; |
| 4938 | } |
| 4939 | |
| 4940 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4941 | * Sets a delegate for implementing accessibility support via compositon as |
| 4942 | * opposed to inheritance. The delegate's primary use is for implementing |
| 4943 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 4944 | * |
| 4945 | * @param delegate The delegate instance. |
| 4946 | * |
| 4947 | * @see AccessibilityDelegate |
| 4948 | */ |
| 4949 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 4950 | mAccessibilityDelegate = delegate; |
| 4951 | } |
| 4952 | |
| 4953 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4954 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 4955 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 4956 | * that explore the window content. |
| 4957 | * <p> |
| 4958 | * If this method returns an instance, this instance is responsible for managing |
| 4959 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 4960 | * View including the one representing the View itself. Similarly the returned |
| 4961 | * instance is responsible for performing accessibility actions on any virtual |
| 4962 | * view or the root view itself. |
| 4963 | * </p> |
| 4964 | * <p> |
| 4965 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4966 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4967 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 4968 | * is responsible for handling this call. |
| 4969 | * </p> |
| 4970 | * |
| 4971 | * @return The provider. |
| 4972 | * |
| 4973 | * @see AccessibilityNodeProvider |
| 4974 | */ |
| 4975 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 4976 | if (mAccessibilityDelegate != null) { |
| 4977 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 4978 | } else { |
| 4979 | return null; |
| 4980 | } |
| 4981 | } |
| 4982 | |
| 4983 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4984 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 4985 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 4986 | * |
| 4987 | * @return The view accessibility id. |
| 4988 | * |
| 4989 | * @hide |
| 4990 | */ |
| 4991 | public int getAccessibilityViewId() { |
| 4992 | if (mAccessibilityViewId == NO_ID) { |
| 4993 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 4994 | } |
| 4995 | return mAccessibilityViewId; |
| 4996 | } |
| 4997 | |
| 4998 | /** |
| 4999 | * Gets the unique identifier of the window in which this View reseides. |
| 5000 | * |
| 5001 | * @return The window accessibility id. |
| 5002 | * |
| 5003 | * @hide |
| 5004 | */ |
| 5005 | public int getAccessibilityWindowId() { |
| 5006 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 5007 | } |
| 5008 | |
| 5009 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5010 | * Gets the {@link View} description. It briefly describes the view and is |
| 5011 | * primarily used for accessibility support. Set this property to enable |
| 5012 | * better accessibility support for your application. This is especially |
| 5013 | * true for views that do not have textual representation (For example, |
| 5014 | * ImageButton). |
| 5015 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5016 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5017 | * |
| 5018 | * @attr ref android.R.styleable#View_contentDescription |
| 5019 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5020 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5021 | public CharSequence getContentDescription() { |
| 5022 | return mContentDescription; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
| 5026 | * Sets the {@link View} description. It briefly describes the view and is |
| 5027 | * primarily used for accessibility support. Set this property to enable |
| 5028 | * better accessibility support for your application. This is especially |
| 5029 | * true for views that do not have textual representation (For example, |
| 5030 | * ImageButton). |
| 5031 | * |
| 5032 | * @param contentDescription The content description. |
| 5033 | * |
| 5034 | * @attr ref android.R.styleable#View_contentDescription |
| 5035 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 5036 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5037 | public void setContentDescription(CharSequence contentDescription) { |
| 5038 | mContentDescription = contentDescription; |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 5039 | final boolean nonEmptyDesc = contentDescription != null && contentDescription.length() > 0; |
| 5040 | if (nonEmptyDesc && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 5041 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 5042 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5046 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 5047 | * focus within its window. This method can be used to clear any state tied to the |
| 5048 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 5049 | * loses focus, this method can be used to cancel the press. |
| 5050 | * |
| 5051 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 5052 | * |
| 5053 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5054 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5055 | * |
| 5056 | * @hide pending API council approval |
| 5057 | */ |
| 5058 | protected void onFocusLost() { |
| 5059 | resetPressedState(); |
| 5060 | } |
| 5061 | |
| 5062 | private void resetPressedState() { |
| 5063 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5064 | return; |
| 5065 | } |
| 5066 | |
| 5067 | if (isPressed()) { |
| 5068 | setPressed(false); |
| 5069 | |
| 5070 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5071 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5072 | } |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5077 | * Returns true if this view has focus |
| 5078 | * |
| 5079 | * @return True if this view has focus, false otherwise. |
| 5080 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5081 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5082 | public boolean isFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5083 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | /** |
| 5087 | * Find the view in the hierarchy rooted at this view that currently has |
| 5088 | * focus. |
| 5089 | * |
| 5090 | * @return The view that currently has focus, or null if no focused view can |
| 5091 | * be found. |
| 5092 | */ |
| 5093 | public View findFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5094 | return (mPrivateFlags & PFLAG_FOCUSED) != 0 ? this : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5098 | * Indicates whether this view is one of the set of scrollable containers in |
| 5099 | * its window. |
| 5100 | * |
| 5101 | * @return whether this view is one of the set of scrollable containers in |
| 5102 | * its window |
| 5103 | * |
| 5104 | * @attr ref android.R.styleable#View_isScrollContainer |
| 5105 | */ |
| 5106 | public boolean isScrollContainer() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5107 | return (mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5111 | * Change whether this view is one of the set of scrollable containers in |
| 5112 | * its window. This will be used to determine whether the window can |
| 5113 | * resize or must pan when a soft input area is open -- scrollable |
| 5114 | * containers allow the window to use resize mode since the container |
| 5115 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5116 | * |
| 5117 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | */ |
| 5119 | public void setScrollContainer(boolean isScrollContainer) { |
| 5120 | if (isScrollContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5121 | if (mAttachInfo != null && (mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5122 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5123 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5125 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5126 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5127 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5128 | mAttachInfo.mScrollContainers.remove(this); |
| 5129 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5130 | mPrivateFlags &= ~(PFLAG_SCROLL_CONTAINER|PFLAG_SCROLL_CONTAINER_ADDED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | /** |
| 5135 | * Returns the quality of the drawing cache. |
| 5136 | * |
| 5137 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5138 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5139 | * |
| 5140 | * @see #setDrawingCacheQuality(int) |
| 5141 | * @see #setDrawingCacheEnabled(boolean) |
| 5142 | * @see #isDrawingCacheEnabled() |
| 5143 | * |
| 5144 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5145 | */ |
| 5146 | public int getDrawingCacheQuality() { |
| 5147 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 5148 | } |
| 5149 | |
| 5150 | /** |
| 5151 | * Set the drawing cache quality of this view. This value is used only when the |
| 5152 | * drawing cache is enabled |
| 5153 | * |
| 5154 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5155 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5156 | * |
| 5157 | * @see #getDrawingCacheQuality() |
| 5158 | * @see #setDrawingCacheEnabled(boolean) |
| 5159 | * @see #isDrawingCacheEnabled() |
| 5160 | * |
| 5161 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5162 | */ |
| 5163 | public void setDrawingCacheQuality(int quality) { |
| 5164 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 5165 | } |
| 5166 | |
| 5167 | /** |
| 5168 | * Returns whether the screen should remain on, corresponding to the current |
| 5169 | * value of {@link #KEEP_SCREEN_ON}. |
| 5170 | * |
| 5171 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 5172 | * |
| 5173 | * @see #setKeepScreenOn(boolean) |
| 5174 | * |
| 5175 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5176 | */ |
| 5177 | public boolean getKeepScreenOn() { |
| 5178 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 5179 | } |
| 5180 | |
| 5181 | /** |
| 5182 | * Controls whether the screen should remain on, modifying the |
| 5183 | * value of {@link #KEEP_SCREEN_ON}. |
| 5184 | * |
| 5185 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 5186 | * |
| 5187 | * @see #getKeepScreenOn() |
| 5188 | * |
| 5189 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5190 | */ |
| 5191 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 5192 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 5193 | } |
| 5194 | |
| 5195 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5196 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5197 | * @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] | 5198 | * |
| 5199 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5200 | */ |
| 5201 | public int getNextFocusLeftId() { |
| 5202 | return mNextFocusLeftId; |
| 5203 | } |
| 5204 | |
| 5205 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5206 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5207 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 5208 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5209 | * |
| 5210 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5211 | */ |
| 5212 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 5213 | mNextFocusLeftId = nextFocusLeftId; |
| 5214 | } |
| 5215 | |
| 5216 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5217 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5218 | * @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] | 5219 | * |
| 5220 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5221 | */ |
| 5222 | public int getNextFocusRightId() { |
| 5223 | return mNextFocusRightId; |
| 5224 | } |
| 5225 | |
| 5226 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5227 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5228 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 5229 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | * |
| 5231 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5232 | */ |
| 5233 | public void setNextFocusRightId(int nextFocusRightId) { |
| 5234 | mNextFocusRightId = nextFocusRightId; |
| 5235 | } |
| 5236 | |
| 5237 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5238 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5239 | * @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] | 5240 | * |
| 5241 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5242 | */ |
| 5243 | public int getNextFocusUpId() { |
| 5244 | return mNextFocusUpId; |
| 5245 | } |
| 5246 | |
| 5247 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5248 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5249 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 5250 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | * |
| 5252 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5253 | */ |
| 5254 | public void setNextFocusUpId(int nextFocusUpId) { |
| 5255 | mNextFocusUpId = nextFocusUpId; |
| 5256 | } |
| 5257 | |
| 5258 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5259 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5260 | * @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] | 5261 | * |
| 5262 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5263 | */ |
| 5264 | public int getNextFocusDownId() { |
| 5265 | return mNextFocusDownId; |
| 5266 | } |
| 5267 | |
| 5268 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5269 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5270 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5271 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5272 | * |
| 5273 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5274 | */ |
| 5275 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5276 | mNextFocusDownId = nextFocusDownId; |
| 5277 | } |
| 5278 | |
| 5279 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5280 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5281 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5282 | * |
| 5283 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5284 | */ |
| 5285 | public int getNextFocusForwardId() { |
| 5286 | return mNextFocusForwardId; |
| 5287 | } |
| 5288 | |
| 5289 | /** |
| 5290 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5291 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5292 | * decide automatically. |
| 5293 | * |
| 5294 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5295 | */ |
| 5296 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5297 | mNextFocusForwardId = nextFocusForwardId; |
| 5298 | } |
| 5299 | |
| 5300 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5301 | * Returns the visibility of this view and all of its ancestors |
| 5302 | * |
| 5303 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5304 | */ |
| 5305 | public boolean isShown() { |
| 5306 | View current = this; |
| 5307 | //noinspection ConstantConditions |
| 5308 | do { |
| 5309 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5310 | return false; |
| 5311 | } |
| 5312 | ViewParent parent = current.mParent; |
| 5313 | if (parent == null) { |
| 5314 | return false; // We are not attached to the view root |
| 5315 | } |
| 5316 | if (!(parent instanceof View)) { |
| 5317 | return true; |
| 5318 | } |
| 5319 | current = (View) parent; |
| 5320 | } while (current != null); |
| 5321 | |
| 5322 | return false; |
| 5323 | } |
| 5324 | |
| 5325 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5326 | * Called by the view hierarchy when the content insets for a window have |
| 5327 | * changed, to allow it to adjust its content to fit within those windows. |
| 5328 | * The content insets tell you the space that the status bar, input method, |
| 5329 | * 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] | 5330 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5331 | * <p>You do not normally need to deal with this function, since the default |
| 5332 | * window decoration given to applications takes care of applying it to the |
| 5333 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5334 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5335 | * and your content can be placed under those system elements. You can then |
| 5336 | * use this method within your view hierarchy if you have parts of your UI |
| 5337 | * 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] | 5338 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5339 | * <p>The default implementation of this method simply applies the content |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5340 | * inset's to the view's padding, consuming that content (modifying the |
| 5341 | * insets to be 0), and returning true. This behavior is off by default, but can |
| 5342 | * be enabled through {@link #setFitsSystemWindows(boolean)}. |
| 5343 | * |
| 5344 | * <p>This function's traversal down the hierarchy is depth-first. The same content |
| 5345 | * insets object is propagated down the hierarchy, so any changes made to it will |
| 5346 | * be seen by all following views (including potentially ones above in |
| 5347 | * the hierarchy since this is a depth-first traversal). The first view |
| 5348 | * that returns true will abort the entire traversal. |
| 5349 | * |
| 5350 | * <p>The default implementation works well for a situation where it is |
| 5351 | * used with a container that covers the entire window, allowing it to |
| 5352 | * apply the appropriate insets to its content on all edges. If you need |
| 5353 | * a more complicated layout (such as two different views fitting system |
| 5354 | * windows, one on the top of the window, and one on the bottom), |
| 5355 | * you can override the method and handle the insets however you would like. |
| 5356 | * Note that the insets provided by the framework are always relative to the |
| 5357 | * far edges of the window, not accounting for the location of the called view |
| 5358 | * within that window. (In fact when this method is called you do not yet know |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5359 | * where the layout will place the view, as it is done before layout happens.) |
| 5360 | * |
| 5361 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5362 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5363 | * call to continue to your children, you must be sure to call the super |
| 5364 | * implementation. |
| 5365 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5366 | * <p>Here is a sample layout that makes use of fitting system windows |
| 5367 | * to have controls for a video view placed inside of the window decorations |
| 5368 | * that it hides and shows. This can be used with code like the second |
| 5369 | * sample (video player) shown in {@link #setSystemUiVisibility(int)}. |
| 5370 | * |
| 5371 | * {@sample development/samples/ApiDemos/res/layout/video_player.xml complete} |
| 5372 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5373 | * @param insets Current content insets of the window. Prior to |
| 5374 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5375 | * the insets or else you and Android will be unhappy. |
| 5376 | * |
| 5377 | * @return Return true if this view applied the insets and it should not |
| 5378 | * continue propagating further down the hierarchy, false otherwise. |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5379 | * @see #getFitsSystemWindows() |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5380 | * @see #setFitsSystemWindows(boolean) |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5381 | * @see #setSystemUiVisibility(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | */ |
| 5383 | protected boolean fitSystemWindows(Rect insets) { |
| 5384 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 5385 | mUserPaddingStart = UNDEFINED_PADDING; |
| 5386 | mUserPaddingEnd = UNDEFINED_PADDING; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5387 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5388 | || mAttachInfo == null |
| 5389 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5390 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5391 | return true; |
| 5392 | } else { |
| 5393 | internalSetPadding(0, 0, 0, 0); |
| 5394 | return false; |
| 5395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | } |
| 5397 | return false; |
| 5398 | } |
| 5399 | |
| 5400 | /** |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5401 | * Sets whether or not this view should account for system screen decorations |
| 5402 | * such as the status bar and inset its content; that is, controlling whether |
| 5403 | * the default implementation of {@link #fitSystemWindows(Rect)} will be |
| 5404 | * executed. See that method for more details. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5405 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5406 | * <p>Note that if you are providing your own implementation of |
| 5407 | * {@link #fitSystemWindows(Rect)}, then there is no need to set this |
| 5408 | * flag to true -- your implementation will be overriding the default |
| 5409 | * implementation that checks this flag. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5410 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5411 | * @param fitSystemWindows If true, then the default implementation of |
| 5412 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5413 | * |
| 5414 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5415 | * @see #getFitsSystemWindows() |
| 5416 | * @see #fitSystemWindows(Rect) |
| 5417 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5418 | */ |
| 5419 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5420 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5421 | } |
| 5422 | |
| 5423 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5424 | * Check for state of {@link #setFitsSystemWindows(boolean). If this method |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5425 | * returns true, the default implementation of {@link #fitSystemWindows(Rect)} |
| 5426 | * will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5427 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5428 | * @return Returns true if the default implementation of |
| 5429 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5430 | * |
| 5431 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5432 | * @see #setFitsSystemWindows() |
| 5433 | * @see #fitSystemWindows(Rect) |
| 5434 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5435 | */ |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5436 | public boolean getFitsSystemWindows() { |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5437 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5438 | } |
| 5439 | |
Dianne Hackborn | b1b55e6 | 2012-05-10 16:25:54 -0700 | [diff] [blame] | 5440 | /** @hide */ |
| 5441 | public boolean fitsSystemWindows() { |
| 5442 | return getFitsSystemWindows(); |
| 5443 | } |
| 5444 | |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5445 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5446 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5447 | */ |
| 5448 | public void requestFitSystemWindows() { |
| 5449 | if (mParent != null) { |
| 5450 | mParent.requestFitSystemWindows(); |
| 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | /** |
| 5455 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5456 | * @hide |
| 5457 | */ |
| 5458 | public void makeOptionalFitsSystemWindows() { |
| 5459 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5460 | } |
| 5461 | |
| 5462 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5463 | * Returns the visibility status for this view. |
| 5464 | * |
| 5465 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5466 | * @attr ref android.R.styleable#View_visibility |
| 5467 | */ |
| 5468 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5469 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5470 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5471 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5472 | }) |
| 5473 | public int getVisibility() { |
| 5474 | return mViewFlags & VISIBILITY_MASK; |
| 5475 | } |
| 5476 | |
| 5477 | /** |
| 5478 | * Set the enabled state of this view. |
| 5479 | * |
| 5480 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5481 | * @attr ref android.R.styleable#View_visibility |
| 5482 | */ |
| 5483 | @RemotableViewMethod |
| 5484 | public void setVisibility(int visibility) { |
| 5485 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5486 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | /** |
| 5490 | * Returns the enabled status for this view. The interpretation of the |
| 5491 | * enabled state varies by subclass. |
| 5492 | * |
| 5493 | * @return True if this view is enabled, false otherwise. |
| 5494 | */ |
| 5495 | @ViewDebug.ExportedProperty |
| 5496 | public boolean isEnabled() { |
| 5497 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5498 | } |
| 5499 | |
| 5500 | /** |
| 5501 | * Set the enabled state of this view. The interpretation of the enabled |
| 5502 | * state varies by subclass. |
| 5503 | * |
| 5504 | * @param enabled True if this view is enabled, false otherwise. |
| 5505 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5506 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5508 | if (enabled == isEnabled()) return; |
| 5509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5510 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5511 | |
| 5512 | /* |
| 5513 | * The View most likely has to change its appearance, so refresh |
| 5514 | * the drawable state. |
| 5515 | */ |
| 5516 | refreshDrawableState(); |
| 5517 | |
| 5518 | // Invalidate too, since the default behavior for views is to be |
| 5519 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5520 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * Set whether this view can receive the focus. |
| 5525 | * |
| 5526 | * Setting this to false will also ensure that this view is not focusable |
| 5527 | * in touch mode. |
| 5528 | * |
| 5529 | * @param focusable If true, this view can receive the focus. |
| 5530 | * |
| 5531 | * @see #setFocusableInTouchMode(boolean) |
| 5532 | * @attr ref android.R.styleable#View_focusable |
| 5533 | */ |
| 5534 | public void setFocusable(boolean focusable) { |
| 5535 | if (!focusable) { |
| 5536 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5537 | } |
| 5538 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5539 | } |
| 5540 | |
| 5541 | /** |
| 5542 | * Set whether this view can receive focus while in touch mode. |
| 5543 | * |
| 5544 | * Setting this to true will also ensure that this view is focusable. |
| 5545 | * |
| 5546 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5547 | * in touch mode. |
| 5548 | * |
| 5549 | * @see #setFocusable(boolean) |
| 5550 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5551 | */ |
| 5552 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5553 | // Focusable in touch mode should always be set before the focusable flag |
| 5554 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5555 | // which, in touch mode, will not successfully request focus on this view |
| 5556 | // because the focusable in touch mode flag is not set |
| 5557 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5558 | if (focusableInTouchMode) { |
| 5559 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5560 | } |
| 5561 | } |
| 5562 | |
| 5563 | /** |
| 5564 | * Set whether this view should have sound effects enabled for events such as |
| 5565 | * clicking and touching. |
| 5566 | * |
| 5567 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5568 | * for instance, a dial key that plays dtmf tones. |
| 5569 | * |
| 5570 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5571 | * @see #isSoundEffectsEnabled() |
| 5572 | * @see #playSoundEffect(int) |
| 5573 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5574 | */ |
| 5575 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5576 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5577 | } |
| 5578 | |
| 5579 | /** |
| 5580 | * @return whether this view should have sound effects enabled for events such as |
| 5581 | * clicking and touching. |
| 5582 | * |
| 5583 | * @see #setSoundEffectsEnabled(boolean) |
| 5584 | * @see #playSoundEffect(int) |
| 5585 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5586 | */ |
| 5587 | @ViewDebug.ExportedProperty |
| 5588 | public boolean isSoundEffectsEnabled() { |
| 5589 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5590 | } |
| 5591 | |
| 5592 | /** |
| 5593 | * Set whether this view should have haptic feedback for events such as |
| 5594 | * long presses. |
| 5595 | * |
| 5596 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5597 | * its own haptic feedback. |
| 5598 | * |
| 5599 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5600 | * @see #isHapticFeedbackEnabled() |
| 5601 | * @see #performHapticFeedback(int) |
| 5602 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5603 | */ |
| 5604 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5605 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5606 | } |
| 5607 | |
| 5608 | /** |
| 5609 | * @return whether this view should have haptic feedback enabled for events |
| 5610 | * long presses. |
| 5611 | * |
| 5612 | * @see #setHapticFeedbackEnabled(boolean) |
| 5613 | * @see #performHapticFeedback(int) |
| 5614 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5615 | */ |
| 5616 | @ViewDebug.ExportedProperty |
| 5617 | public boolean isHapticFeedbackEnabled() { |
| 5618 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5619 | } |
| 5620 | |
| 5621 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5622 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5623 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5624 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5625 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5626 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5627 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5628 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5629 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5630 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5631 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5632 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5633 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5634 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5635 | }) |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5636 | public int getLayoutDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5637 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5638 | } |
| 5639 | |
| 5640 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5641 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5642 | * 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] | 5643 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5644 | * @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5645 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5646 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5647 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5648 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5649 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5650 | */ |
| 5651 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5652 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5653 | if (getLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5654 | // Reset the current layout direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5655 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 5656 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5657 | // Reset padding resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5658 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5659 | // Set the new layout direction (filtered) |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5660 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5661 | ((layoutDirection << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) & PFLAG2_LAYOUT_DIRECTION_MASK); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5662 | resolveRtlProperties(); |
| 5663 | // ... and ask for a layout pass |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5664 | requestLayout(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5665 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5669 | * Returns the resolved layout direction for this view. |
| 5670 | * |
| 5671 | * @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] | 5672 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5673 | */ |
| 5674 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5675 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5676 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5677 | }) |
| 5678 | public int getResolvedLayoutDirection() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5679 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 5680 | if (targetSdkVersion < JELLY_BEAN_MR1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5681 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5682 | return LAYOUT_DIRECTION_LTR; |
| 5683 | } |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 5684 | // The layout direction will be resolved only if needed |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5685 | if ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED) != PFLAG2_LAYOUT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 5686 | resolveLayoutDirection(); |
| 5687 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5688 | return ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) == PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ? |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5689 | LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 5690 | } |
| 5691 | |
| 5692 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5693 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5694 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5695 | * |
| 5696 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5697 | */ |
| 5698 | @ViewDebug.ExportedProperty(category = "layout") |
| 5699 | public boolean isLayoutRtl() { |
| 5700 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL); |
| 5701 | } |
| 5702 | |
| 5703 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5704 | * Indicates whether the view is currently tracking transient state that the |
| 5705 | * app should not need to concern itself with saving and restoring, but that |
| 5706 | * the framework should take special note to preserve when possible. |
| 5707 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5708 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5709 | * data source, such as an adapter binding item views in a list. This may be |
| 5710 | * because the view is performing an animation, tracking user selection |
| 5711 | * of content, or similar.</p> |
| 5712 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5713 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5714 | */ |
| 5715 | @ViewDebug.ExportedProperty(category = "layout") |
| 5716 | public boolean hasTransientState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5717 | return (mPrivateFlags2 & PFLAG2_HAS_TRANSIENT_STATE) == PFLAG2_HAS_TRANSIENT_STATE; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5718 | } |
| 5719 | |
| 5720 | /** |
| 5721 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5722 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 5723 | * so every call to setHasTransientState(true) should be paired with a later call |
| 5724 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5725 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5726 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5727 | * data source, such as an adapter binding item views in a list. This may be |
| 5728 | * because the view is performing an animation, tracking user selection |
| 5729 | * of content, or similar.</p> |
| 5730 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5731 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5732 | */ |
| 5733 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5734 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 5735 | mTransientStateCount - 1; |
| 5736 | if (mTransientStateCount < 0) { |
| 5737 | mTransientStateCount = 0; |
| 5738 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 5739 | "unmatched pair of setHasTransientState calls"); |
| 5740 | } |
| 5741 | if ((hasTransientState && mTransientStateCount == 1) || |
Adam Powell | 057a585 | 2012-05-11 10:28:38 -0700 | [diff] [blame] | 5742 | (!hasTransientState && mTransientStateCount == 0)) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5743 | // update flag if we've just incremented up from 0 or decremented down to 0 |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5744 | mPrivateFlags2 = (mPrivateFlags2 & ~PFLAG2_HAS_TRANSIENT_STATE) | |
| 5745 | (hasTransientState ? PFLAG2_HAS_TRANSIENT_STATE : 0); |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 5746 | if (mParent != null) { |
| 5747 | try { |
| 5748 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 5749 | } catch (AbstractMethodError e) { |
| 5750 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 5751 | " does not fully implement ViewParent", e); |
| 5752 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5753 | } |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | * If this view doesn't do any drawing on its own, set this flag to |
| 5759 | * allow further optimizations. By default, this flag is not set on |
| 5760 | * View, but could be set on some View subclasses such as ViewGroup. |
| 5761 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5762 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 5763 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | * |
| 5765 | * @param willNotDraw whether or not this View draw on its own |
| 5766 | */ |
| 5767 | public void setWillNotDraw(boolean willNotDraw) { |
| 5768 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 5769 | } |
| 5770 | |
| 5771 | /** |
| 5772 | * Returns whether or not this View draws on its own. |
| 5773 | * |
| 5774 | * @return true if this view has nothing to draw, false otherwise |
| 5775 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5776 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | public boolean willNotDraw() { |
| 5778 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 5779 | } |
| 5780 | |
| 5781 | /** |
| 5782 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 5783 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 5784 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 5785 | * unnecessary usage of the memory. |
| 5786 | * |
| 5787 | * @param willNotCacheDrawing true if this view does not cache its |
| 5788 | * drawing, false otherwise |
| 5789 | */ |
| 5790 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 5791 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * Returns whether or not this View can cache its drawing or not. |
| 5796 | * |
| 5797 | * @return true if this view does not cache its drawing, false otherwise |
| 5798 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5799 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5800 | public boolean willNotCacheDrawing() { |
| 5801 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 5802 | } |
| 5803 | |
| 5804 | /** |
| 5805 | * Indicates whether this view reacts to click events or not. |
| 5806 | * |
| 5807 | * @return true if the view is clickable, false otherwise |
| 5808 | * |
| 5809 | * @see #setClickable(boolean) |
| 5810 | * @attr ref android.R.styleable#View_clickable |
| 5811 | */ |
| 5812 | @ViewDebug.ExportedProperty |
| 5813 | public boolean isClickable() { |
| 5814 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 5815 | } |
| 5816 | |
| 5817 | /** |
| 5818 | * Enables or disables click events for this view. When a view |
| 5819 | * is clickable it will change its state to "pressed" on every click. |
| 5820 | * Subclasses should set the view clickable to visually react to |
| 5821 | * user's clicks. |
| 5822 | * |
| 5823 | * @param clickable true to make the view clickable, false otherwise |
| 5824 | * |
| 5825 | * @see #isClickable() |
| 5826 | * @attr ref android.R.styleable#View_clickable |
| 5827 | */ |
| 5828 | public void setClickable(boolean clickable) { |
| 5829 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 5830 | } |
| 5831 | |
| 5832 | /** |
| 5833 | * Indicates whether this view reacts to long click events or not. |
| 5834 | * |
| 5835 | * @return true if the view is long clickable, false otherwise |
| 5836 | * |
| 5837 | * @see #setLongClickable(boolean) |
| 5838 | * @attr ref android.R.styleable#View_longClickable |
| 5839 | */ |
| 5840 | public boolean isLongClickable() { |
| 5841 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 5842 | } |
| 5843 | |
| 5844 | /** |
| 5845 | * Enables or disables long click events for this view. When a view is long |
| 5846 | * clickable it reacts to the user holding down the button for a longer |
| 5847 | * duration than a tap. This event can either launch the listener or a |
| 5848 | * context menu. |
| 5849 | * |
| 5850 | * @param longClickable true to make the view long clickable, false otherwise |
| 5851 | * @see #isLongClickable() |
| 5852 | * @attr ref android.R.styleable#View_longClickable |
| 5853 | */ |
| 5854 | public void setLongClickable(boolean longClickable) { |
| 5855 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 5856 | } |
| 5857 | |
| 5858 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 5859 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5860 | * |
| 5861 | * @see #isClickable() |
| 5862 | * @see #setClickable(boolean) |
| 5863 | * |
| 5864 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 5865 | * the View's internal state from a previously set "pressed" state. |
| 5866 | */ |
| 5867 | public void setPressed(boolean pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5868 | final boolean needsRefresh = pressed != ((mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 5869 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5870 | if (pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5871 | mPrivateFlags |= PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5872 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5873 | mPrivateFlags &= ~PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 5875 | |
| 5876 | if (needsRefresh) { |
| 5877 | refreshDrawableState(); |
| 5878 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5879 | dispatchSetPressed(pressed); |
| 5880 | } |
| 5881 | |
| 5882 | /** |
| 5883 | * Dispatch setPressed to all of this View's children. |
| 5884 | * |
| 5885 | * @see #setPressed(boolean) |
| 5886 | * |
| 5887 | * @param pressed The new pressed state |
| 5888 | */ |
| 5889 | protected void dispatchSetPressed(boolean pressed) { |
| 5890 | } |
| 5891 | |
| 5892 | /** |
| 5893 | * Indicates whether the view is currently in pressed state. Unless |
| 5894 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 5895 | * the pressed state. |
| 5896 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5897 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5898 | * @see #isClickable() |
| 5899 | * @see #setClickable(boolean) |
| 5900 | * |
| 5901 | * @return true if the view is currently pressed, false otherwise |
| 5902 | */ |
| 5903 | public boolean isPressed() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5904 | return (mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * Indicates whether this view will save its state (that is, |
| 5909 | * whether its {@link #onSaveInstanceState} method will be called). |
| 5910 | * |
| 5911 | * @return Returns true if the view state saving is enabled, else false. |
| 5912 | * |
| 5913 | * @see #setSaveEnabled(boolean) |
| 5914 | * @attr ref android.R.styleable#View_saveEnabled |
| 5915 | */ |
| 5916 | public boolean isSaveEnabled() { |
| 5917 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 5918 | } |
| 5919 | |
| 5920 | /** |
| 5921 | * Controls whether the saving of this view's state is |
| 5922 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 5923 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 5924 | * 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] | 5925 | * for its state to be saved. This flag can only disable the |
| 5926 | * saving of this view; any child views may still have their state saved. |
| 5927 | * |
| 5928 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5929 | * (the default) to allow it. |
| 5930 | * |
| 5931 | * @see #isSaveEnabled() |
| 5932 | * @see #setId(int) |
| 5933 | * @see #onSaveInstanceState() |
| 5934 | * @attr ref android.R.styleable#View_saveEnabled |
| 5935 | */ |
| 5936 | public void setSaveEnabled(boolean enabled) { |
| 5937 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 5938 | } |
| 5939 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5940 | /** |
| 5941 | * Gets whether the framework should discard touches when the view's |
| 5942 | * window is obscured by another visible window. |
| 5943 | * Refer to the {@link View} security documentation for more details. |
| 5944 | * |
| 5945 | * @return True if touch filtering is enabled. |
| 5946 | * |
| 5947 | * @see #setFilterTouchesWhenObscured(boolean) |
| 5948 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5949 | */ |
| 5950 | @ViewDebug.ExportedProperty |
| 5951 | public boolean getFilterTouchesWhenObscured() { |
| 5952 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 5953 | } |
| 5954 | |
| 5955 | /** |
| 5956 | * Sets whether the framework should discard touches when the view's |
| 5957 | * window is obscured by another visible window. |
| 5958 | * Refer to the {@link View} security documentation for more details. |
| 5959 | * |
| 5960 | * @param enabled True if touch filtering should be enabled. |
| 5961 | * |
| 5962 | * @see #getFilterTouchesWhenObscured |
| 5963 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 5964 | */ |
| 5965 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 5966 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 5967 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 5968 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5969 | |
| 5970 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 5971 | * Indicates whether the entire hierarchy under this view will save its |
| 5972 | * state when a state saving traversal occurs from its parent. The default |
| 5973 | * is true; if false, these views will not be saved unless |
| 5974 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5975 | * |
| 5976 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 5977 | * |
| 5978 | * @see #setSaveFromParentEnabled(boolean) |
| 5979 | */ |
| 5980 | public boolean isSaveFromParentEnabled() { |
| 5981 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 5982 | } |
| 5983 | |
| 5984 | /** |
| 5985 | * Controls whether the entire hierarchy under this view will save its |
| 5986 | * state when a state saving traversal occurs from its parent. The default |
| 5987 | * is true; if false, these views will not be saved unless |
| 5988 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 5989 | * |
| 5990 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 5991 | * (the default) to allow it. |
| 5992 | * |
| 5993 | * @see #isSaveFromParentEnabled() |
| 5994 | * @see #setId(int) |
| 5995 | * @see #onSaveInstanceState() |
| 5996 | */ |
| 5997 | public void setSaveFromParentEnabled(boolean enabled) { |
| 5998 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 5999 | } |
| 6000 | |
| 6001 | |
| 6002 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | * Returns whether this View is able to take focus. |
| 6004 | * |
| 6005 | * @return True if this view can take focus, or false otherwise. |
| 6006 | * @attr ref android.R.styleable#View_focusable |
| 6007 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6008 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6009 | public final boolean isFocusable() { |
| 6010 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 6011 | } |
| 6012 | |
| 6013 | /** |
| 6014 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 6015 | * For example, a button would like focus when the user is navigating via a D-pad |
| 6016 | * so that the user can click on it, but once the user starts touching the screen, |
| 6017 | * the button shouldn't take focus |
| 6018 | * @return Whether the view is focusable in touch mode. |
| 6019 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 6020 | */ |
| 6021 | @ViewDebug.ExportedProperty |
| 6022 | public final boolean isFocusableInTouchMode() { |
| 6023 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 6024 | } |
| 6025 | |
| 6026 | /** |
| 6027 | * Find the nearest view in the specified direction that can take focus. |
| 6028 | * This does not actually give focus to that view. |
| 6029 | * |
| 6030 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6031 | * |
| 6032 | * @return The nearest focusable in the specified direction, or null if none |
| 6033 | * can be found. |
| 6034 | */ |
| 6035 | public View focusSearch(int direction) { |
| 6036 | if (mParent != null) { |
| 6037 | return mParent.focusSearch(this, direction); |
| 6038 | } else { |
| 6039 | return null; |
| 6040 | } |
| 6041 | } |
| 6042 | |
| 6043 | /** |
| 6044 | * This method is the last chance for the focused view and its ancestors to |
| 6045 | * respond to an arrow key. This is called when the focused view did not |
| 6046 | * consume the key internally, nor could the view system find a new view in |
| 6047 | * the requested direction to give focus to. |
| 6048 | * |
| 6049 | * @param focused The currently focused view. |
| 6050 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 6051 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 6052 | * @return True if the this view consumed this unhandled move. |
| 6053 | */ |
| 6054 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 6055 | return false; |
| 6056 | } |
| 6057 | |
| 6058 | /** |
| 6059 | * 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] | 6060 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6062 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 6063 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6064 | * @return The user specified next view, or null if there is none. |
| 6065 | */ |
| 6066 | View findUserSetNextFocus(View root, int direction) { |
| 6067 | switch (direction) { |
| 6068 | case FOCUS_LEFT: |
| 6069 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6070 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | case FOCUS_RIGHT: |
| 6072 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6073 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6074 | case FOCUS_UP: |
| 6075 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6076 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | case FOCUS_DOWN: |
| 6078 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6079 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6080 | case FOCUS_FORWARD: |
| 6081 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6082 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6083 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 6084 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6085 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6086 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6087 | @Override |
| 6088 | public boolean apply(View t) { |
| 6089 | return t.mNextFocusForwardId == id; |
| 6090 | } |
| 6091 | }); |
| 6092 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6093 | } |
| 6094 | return null; |
| 6095 | } |
| 6096 | |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6097 | private View findViewInsideOutShouldExist(View root, final int childViewId) { |
| 6098 | View result = root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
| 6099 | @Override |
| 6100 | public boolean apply(View t) { |
| 6101 | return t.mID == childViewId; |
| 6102 | } |
| 6103 | }); |
| 6104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6105 | if (result == null) { |
| 6106 | Log.w(VIEW_LOG_TAG, "couldn't find next focus view specified " |
| 6107 | + "by user for id " + childViewId); |
| 6108 | } |
| 6109 | return result; |
| 6110 | } |
| 6111 | |
| 6112 | /** |
| 6113 | * Find and return all focusable views that are descendants of this view, |
| 6114 | * possibly including this view if it is focusable itself. |
| 6115 | * |
| 6116 | * @param direction The direction of the focus |
| 6117 | * @return A list of focusable views |
| 6118 | */ |
| 6119 | public ArrayList<View> getFocusables(int direction) { |
| 6120 | ArrayList<View> result = new ArrayList<View>(24); |
| 6121 | addFocusables(result, direction); |
| 6122 | return result; |
| 6123 | } |
| 6124 | |
| 6125 | /** |
| 6126 | * Add any focusable views that are descendants of this view (possibly |
| 6127 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 6128 | * only add views that are also focusable in touch mode. |
| 6129 | * |
| 6130 | * @param views Focusable views found so far |
| 6131 | * @param direction The direction of the focus |
| 6132 | */ |
| 6133 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6134 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 6135 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6136 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6137 | /** |
| 6138 | * Adds any focusable views that are descendants of this view (possibly |
| 6139 | * including this view if it is focusable itself) to views. This method |
| 6140 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6141 | * only views focusable in touch mode if we are in touch mode or |
| 6142 | * only views that can take accessibility focus if accessibility is enabeld |
| 6143 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6144 | * |
| 6145 | * @param views Focusable views found so far or null if all we are interested is |
| 6146 | * the number of focusables. |
| 6147 | * @param direction The direction of the focus. |
| 6148 | * @param focusableMode The type of focusables to be added. |
| 6149 | * |
| 6150 | * @see #FOCUSABLES_ALL |
| 6151 | * @see #FOCUSABLES_TOUCH_MODE |
| 6152 | */ |
| 6153 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6154 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6155 | return; |
| 6156 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6157 | if (!isFocusable()) { |
| 6158 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6159 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6160 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 6161 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 6162 | return; |
| 6163 | } |
| 6164 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6168 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6169 | * The search is performed by either the text that the View renders or the content |
| 6170 | * description that describes the view for accessibility purposes and the view does |
| 6171 | * not render or both. Clients can specify how the search is to be performed via |
| 6172 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 6173 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6174 | * |
| 6175 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6176 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6177 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6178 | * @see #FIND_VIEWS_WITH_TEXT |
| 6179 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 6180 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6181 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6182 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6183 | if (getAccessibilityNodeProvider() != null) { |
| 6184 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 6185 | outViews.add(this); |
| 6186 | } |
| 6187 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6188 | && (searched != null && searched.length() > 0) |
| 6189 | && (mContentDescription != null && mContentDescription.length() > 0)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6190 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 6191 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 6192 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 6193 | outViews.add(this); |
| 6194 | } |
| 6195 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6196 | } |
| 6197 | |
| 6198 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6199 | * Find and return all touchable views that are descendants of this view, |
| 6200 | * possibly including this view if it is touchable itself. |
| 6201 | * |
| 6202 | * @return A list of touchable views |
| 6203 | */ |
| 6204 | public ArrayList<View> getTouchables() { |
| 6205 | ArrayList<View> result = new ArrayList<View>(); |
| 6206 | addTouchables(result); |
| 6207 | return result; |
| 6208 | } |
| 6209 | |
| 6210 | /** |
| 6211 | * Add any touchable views that are descendants of this view (possibly |
| 6212 | * including this view if it is touchable itself) to views. |
| 6213 | * |
| 6214 | * @param views Touchable views found so far |
| 6215 | */ |
| 6216 | public void addTouchables(ArrayList<View> views) { |
| 6217 | final int viewFlags = mViewFlags; |
| 6218 | |
| 6219 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 6220 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 6221 | views.add(this); |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6226 | * Returns whether this View is accessibility focused. |
| 6227 | * |
| 6228 | * @return True if this View is accessibility focused. |
| 6229 | */ |
| 6230 | boolean isAccessibilityFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6231 | return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | /** |
| 6235 | * Call this to try to give accessibility focus to this view. |
| 6236 | * |
| 6237 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 6238 | * returns false or the view is no visible or the view already has accessibility |
| 6239 | * focus. |
| 6240 | * |
| 6241 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6242 | * have focus, and you want your parent to look for the next one. |
| 6243 | * |
| 6244 | * @return Whether this view actually took accessibility focus. |
| 6245 | * |
| 6246 | * @hide |
| 6247 | */ |
| 6248 | public boolean requestAccessibilityFocus() { |
Svetoslav Ganov | 07b726c | 2012-04-30 12:24:57 -0700 | [diff] [blame] | 6249 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 6250 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6251 | return false; |
| 6252 | } |
| 6253 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6254 | return false; |
| 6255 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6256 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) == 0) { |
| 6257 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6258 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6259 | if (viewRootImpl != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6260 | viewRootImpl.setAccessibilityFocus(this, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6261 | } |
| 6262 | invalidate(); |
| 6263 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 6264 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6265 | return true; |
| 6266 | } |
| 6267 | return false; |
| 6268 | } |
| 6269 | |
| 6270 | /** |
| 6271 | * Call this to try to clear accessibility focus of this view. |
| 6272 | * |
| 6273 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6274 | * have focus, and you want your parent to look for the next one. |
| 6275 | * |
| 6276 | * @hide |
| 6277 | */ |
| 6278 | public void clearAccessibilityFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6279 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6280 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6281 | invalidate(); |
| 6282 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 6283 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6284 | } |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6285 | // Clear the global reference of accessibility focus if this |
| 6286 | // view or any of its descendants had accessibility focus. |
| 6287 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6288 | if (viewRootImpl != null) { |
| 6289 | View focusHost = viewRootImpl.getAccessibilityFocusedHost(); |
| 6290 | if (focusHost != null && ViewRootImpl.isViewDescendantOf(focusHost, this)) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6291 | viewRootImpl.setAccessibilityFocus(null, null); |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6292 | } |
| 6293 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 6296 | private void sendAccessibilityHoverEvent(int eventType) { |
| 6297 | // Since we are not delivering to a client accessibility events from not |
| 6298 | // important views (unless the clinet request that) we need to fire the |
| 6299 | // event from the deepest view exposed to the client. As a consequence if |
| 6300 | // the user crosses a not exposed view the client will see enter and exit |
| 6301 | // of the exposed predecessor followed by and enter and exit of that same |
| 6302 | // predecessor when entering and exiting the not exposed descendant. This |
| 6303 | // is fine since the client has a clear idea which view is hovered at the |
| 6304 | // price of a couple more events being sent. This is a simple and |
| 6305 | // working solution. |
| 6306 | View source = this; |
| 6307 | while (true) { |
| 6308 | if (source.includeForAccessibility()) { |
| 6309 | source.sendAccessibilityEvent(eventType); |
| 6310 | return; |
| 6311 | } |
| 6312 | ViewParent parent = source.getParent(); |
| 6313 | if (parent instanceof View) { |
| 6314 | source = (View) parent; |
| 6315 | } else { |
| 6316 | return; |
| 6317 | } |
| 6318 | } |
| 6319 | } |
| 6320 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6321 | /** |
| 6322 | * Clears accessibility focus without calling any callback methods |
| 6323 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6324 | * is used for clearing accessibility focus when giving this focus to |
| 6325 | * another view. |
| 6326 | */ |
| 6327 | void clearAccessibilityFocusNoCallbacks() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6328 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6329 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6330 | invalidate(); |
| 6331 | } |
| 6332 | } |
| 6333 | |
| 6334 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6335 | * Call this to try to give focus to a specific view or to one of its |
| 6336 | * descendants. |
| 6337 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6338 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6339 | * false), or if it is focusable and it is not focusable in touch mode |
| 6340 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6342 | * 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] | 6343 | * have focus, and you want your parent to look for the next one. |
| 6344 | * |
| 6345 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6346 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6347 | * |
| 6348 | * @return Whether this view or one of its descendants actually took focus. |
| 6349 | */ |
| 6350 | public final boolean requestFocus() { |
| 6351 | return requestFocus(View.FOCUS_DOWN); |
| 6352 | } |
| 6353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | /** |
| 6355 | * Call this to try to give focus to a specific view or to one of its |
| 6356 | * descendants and give it a hint about what direction focus is heading. |
| 6357 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6358 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6359 | * false), or if it is focusable and it is not focusable in touch mode |
| 6360 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6362 | * 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] | 6363 | * have focus, and you want your parent to look for the next one. |
| 6364 | * |
| 6365 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6366 | * <code>null</code> set for the previously focused rectangle. |
| 6367 | * |
| 6368 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6369 | * @return Whether this view or one of its descendants actually took focus. |
| 6370 | */ |
| 6371 | public final boolean requestFocus(int direction) { |
| 6372 | return requestFocus(direction, null); |
| 6373 | } |
| 6374 | |
| 6375 | /** |
| 6376 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6377 | * and give it hints about the direction and a specific rectangle that the focus |
| 6378 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6379 | * about where focus is coming from, and therefore, where to show selection, or |
| 6380 | * forward focus change internally. |
| 6381 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6382 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6383 | * false), or if it is focusable and it is not focusable in touch mode |
| 6384 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | * |
| 6386 | * A View will not take focus if it is not visible. |
| 6387 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6388 | * A View will not take focus if one of its parents has |
| 6389 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6390 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6392 | * 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] | 6393 | * have focus, and you want your parent to look for the next one. |
| 6394 | * |
| 6395 | * You may wish to override this method if your custom {@link View} has an internal |
| 6396 | * {@link View} that it wishes to forward the request to. |
| 6397 | * |
| 6398 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6399 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6400 | * to give a finer grained hint about where focus is coming from. May be null |
| 6401 | * if there is no hint. |
| 6402 | * @return Whether this view or one of its descendants actually took focus. |
| 6403 | */ |
| 6404 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6405 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6406 | } |
| 6407 | |
| 6408 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | // need to be focusable |
| 6410 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6411 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6412 | return false; |
| 6413 | } |
| 6414 | |
| 6415 | // need to be focusable in touch mode if in touch mode |
| 6416 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6417 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6418 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | // need to not have any parents blocking us |
| 6422 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6423 | return false; |
| 6424 | } |
| 6425 | |
| 6426 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6427 | return true; |
| 6428 | } |
| 6429 | |
| 6430 | /** |
| 6431 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6432 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6433 | * touch mode to request focus when they are touched. |
| 6434 | * |
| 6435 | * @return Whether this view or one of its descendants actually took focus. |
| 6436 | * |
| 6437 | * @see #isInTouchMode() |
| 6438 | * |
| 6439 | */ |
| 6440 | public final boolean requestFocusFromTouch() { |
| 6441 | // Leave touch mode if we need to |
| 6442 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6443 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6444 | if (viewRoot != null) { |
| 6445 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | } |
| 6447 | } |
| 6448 | return requestFocus(View.FOCUS_DOWN); |
| 6449 | } |
| 6450 | |
| 6451 | /** |
| 6452 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6453 | */ |
| 6454 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6455 | ViewParent ancestor = mParent; |
| 6456 | while (ancestor instanceof ViewGroup) { |
| 6457 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6458 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6459 | return true; |
| 6460 | } else { |
| 6461 | ancestor = vgAncestor.getParent(); |
| 6462 | } |
| 6463 | } |
| 6464 | return false; |
| 6465 | } |
| 6466 | |
| 6467 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6468 | * Gets the mode for determining whether this View is important for accessibility |
| 6469 | * which is if it fires accessibility events and if it is reported to |
| 6470 | * accessibility services that query the screen. |
| 6471 | * |
| 6472 | * @return The mode for determining whether a View is important for accessibility. |
| 6473 | * |
| 6474 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6475 | * |
| 6476 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6477 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6478 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6479 | */ |
| 6480 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 6481 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, to = "auto"), |
| 6482 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, to = "yes"), |
| 6483 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, to = "no") |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6484 | }) |
| 6485 | public int getImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6486 | return (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6487 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | /** |
| 6491 | * Sets how to determine whether this view is important for accessibility |
| 6492 | * which is if it fires accessibility events and if it is reported to |
| 6493 | * accessibility services that query the screen. |
| 6494 | * |
| 6495 | * @param mode How to determine whether this view is important for accessibility. |
| 6496 | * |
| 6497 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6498 | * |
| 6499 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6500 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6501 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6502 | */ |
| 6503 | public void setImportantForAccessibility(int mode) { |
| 6504 | if (mode != getImportantForAccessibility()) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6505 | mPrivateFlags2 &= ~PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6506 | mPrivateFlags2 |= (mode << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6507 | & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6508 | notifyAccessibilityStateChanged(); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /** |
| 6513 | * Gets whether this view should be exposed for accessibility. |
| 6514 | * |
| 6515 | * @return Whether the view is exposed for accessibility. |
| 6516 | * |
| 6517 | * @hide |
| 6518 | */ |
| 6519 | public boolean isImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6520 | final int mode = (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6521 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6522 | switch (mode) { |
| 6523 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6524 | return true; |
| 6525 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6526 | return false; |
| 6527 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
Svetoslav Ganov | 34caec9 | 2012-07-19 18:07:58 -0700 | [diff] [blame] | 6528 | return isActionableForAccessibility() || hasListenersForAccessibility() |
| 6529 | || getAccessibilityNodeProvider() != null; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6530 | default: |
| 6531 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6532 | + mode); |
| 6533 | } |
| 6534 | } |
| 6535 | |
| 6536 | /** |
| 6537 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6538 | * accessibility is not necessary the immediate parent. It is the first |
| 6539 | * predecessor that is important for accessibility. |
| 6540 | * |
| 6541 | * @return The parent for accessibility purposes. |
| 6542 | */ |
| 6543 | public ViewParent getParentForAccessibility() { |
| 6544 | if (mParent instanceof View) { |
| 6545 | View parentView = (View) mParent; |
| 6546 | if (parentView.includeForAccessibility()) { |
| 6547 | return mParent; |
| 6548 | } else { |
| 6549 | return mParent.getParentForAccessibility(); |
| 6550 | } |
| 6551 | } |
| 6552 | return null; |
| 6553 | } |
| 6554 | |
| 6555 | /** |
| 6556 | * Adds the children of a given View for accessibility. Since some Views are |
| 6557 | * not important for accessibility the children for accessibility are not |
| 6558 | * necessarily direct children of the riew, rather they are the first level of |
| 6559 | * descendants important for accessibility. |
| 6560 | * |
| 6561 | * @param children The list of children for accessibility. |
| 6562 | */ |
| 6563 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6564 | if (includeForAccessibility()) { |
| 6565 | children.add(this); |
| 6566 | } |
| 6567 | } |
| 6568 | |
| 6569 | /** |
| 6570 | * Whether to regard this view for accessibility. A view is regarded for |
| 6571 | * accessibility if it is important for accessibility or the querying |
| 6572 | * accessibility service has explicitly requested that view not |
| 6573 | * important for accessibility are regarded. |
| 6574 | * |
| 6575 | * @return Whether to regard the view for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6576 | * |
| 6577 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6578 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6579 | public boolean includeForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6580 | if (mAttachInfo != null) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 6581 | return mAttachInfo.mIncludeNotImportantViews || isImportantForAccessibility(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6582 | } |
| 6583 | return false; |
| 6584 | } |
| 6585 | |
| 6586 | /** |
| 6587 | * Returns whether the View is considered actionable from |
| 6588 | * accessibility perspective. Such view are important for |
| 6589 | * accessiiblity. |
| 6590 | * |
| 6591 | * @return True if the view is actionable for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6592 | * |
| 6593 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6594 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6595 | public boolean isActionableForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6596 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6597 | } |
| 6598 | |
| 6599 | /** |
| 6600 | * Returns whether the View has registered callbacks wich makes it |
| 6601 | * important for accessiiblity. |
| 6602 | * |
| 6603 | * @return True if the view is actionable for accessibility. |
| 6604 | */ |
| 6605 | private boolean hasListenersForAccessibility() { |
| 6606 | ListenerInfo info = getListenerInfo(); |
| 6607 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6608 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6609 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6610 | } |
| 6611 | |
| 6612 | /** |
| 6613 | * Notifies accessibility services that some view's important for |
| 6614 | * accessibility state has changed. Note that such notifications |
| 6615 | * are made at most once every |
| 6616 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6617 | * to avoid unnecessary load to the system. Also once a view has |
| 6618 | * made a notifucation this method is a NOP until the notification has |
| 6619 | * been sent to clients. |
| 6620 | * |
| 6621 | * @hide |
| 6622 | * |
| 6623 | * TODO: Makse sure this method is called for any view state change |
| 6624 | * that is interesting for accessilility purposes. |
| 6625 | */ |
| 6626 | public void notifyAccessibilityStateChanged() { |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 6627 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6628 | return; |
| 6629 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6630 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6631 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6632 | if (mParent != null) { |
| 6633 | mParent.childAccessibilityStateChanged(this); |
| 6634 | } |
| 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | /** |
| 6639 | * Reset the state indicating the this view has requested clients |
| 6640 | * interested in its accessiblity state to be notified. |
| 6641 | * |
| 6642 | * @hide |
| 6643 | */ |
| 6644 | public void resetAccessibilityStateChanged() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6645 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | /** |
| 6649 | * Performs the specified accessibility action on the view. For |
| 6650 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6651 | * <p> |
| 6652 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 6653 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 6654 | * {@link AccessibilityDelegate#performAccessibilityAction(View, int, Bundle)} |
| 6655 | * is responsible for handling this call. |
| 6656 | * </p> |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6657 | * |
| 6658 | * @param action The action to perform. |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6659 | * @param arguments Optional action arguments. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6660 | * @return Whether the action was performed. |
| 6661 | */ |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6662 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6663 | if (mAccessibilityDelegate != null) { |
| 6664 | return mAccessibilityDelegate.performAccessibilityAction(this, action, arguments); |
| 6665 | } else { |
| 6666 | return performAccessibilityActionInternal(action, arguments); |
| 6667 | } |
| 6668 | } |
| 6669 | |
| 6670 | /** |
| 6671 | * @see #performAccessibilityAction(int, Bundle) |
| 6672 | * |
| 6673 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 6674 | */ |
| 6675 | boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6676 | switch (action) { |
| 6677 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6678 | if (isClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6679 | return performClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6680 | } |
| 6681 | } break; |
| 6682 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6683 | if (isLongClickable()) { |
Svetoslav Ganov | 773f262 | 2012-05-05 19:59:42 -0700 | [diff] [blame] | 6684 | return performLongClick(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6685 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6686 | } break; |
| 6687 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6688 | if (!hasFocus()) { |
| 6689 | // Get out of touch mode since accessibility |
| 6690 | // wants to move focus around. |
| 6691 | getViewRootImpl().ensureTouchMode(false); |
| 6692 | return requestFocus(); |
| 6693 | } |
| 6694 | } break; |
| 6695 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6696 | if (hasFocus()) { |
| 6697 | clearFocus(); |
| 6698 | return !isFocused(); |
| 6699 | } |
| 6700 | } break; |
| 6701 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6702 | if (!isSelected()) { |
| 6703 | setSelected(true); |
| 6704 | return isSelected(); |
| 6705 | } |
| 6706 | } break; |
| 6707 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6708 | if (isSelected()) { |
| 6709 | setSelected(false); |
| 6710 | return !isSelected(); |
| 6711 | } |
| 6712 | } break; |
| 6713 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 6714 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6715 | return requestAccessibilityFocus(); |
| 6716 | } |
| 6717 | } break; |
| 6718 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 6719 | if (isAccessibilityFocused()) { |
| 6720 | clearAccessibilityFocus(); |
| 6721 | return true; |
| 6722 | } |
| 6723 | } break; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6724 | case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: { |
| 6725 | if (arguments != null) { |
| 6726 | final int granularity = arguments.getInt( |
| 6727 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6728 | return nextAtGranularity(granularity); |
| 6729 | } |
| 6730 | } break; |
| 6731 | case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { |
| 6732 | if (arguments != null) { |
| 6733 | final int granularity = arguments.getInt( |
| 6734 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
| 6735 | return previousAtGranularity(granularity); |
| 6736 | } |
| 6737 | } break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6738 | } |
| 6739 | return false; |
| 6740 | } |
| 6741 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6742 | private boolean nextAtGranularity(int granularity) { |
| 6743 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 6744 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6745 | return false; |
| 6746 | } |
| 6747 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 6748 | if (iterator == null) { |
| 6749 | return false; |
| 6750 | } |
| 6751 | final int current = getAccessibilityCursorPosition(); |
| 6752 | final int[] range = iterator.following(current); |
| 6753 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6754 | return false; |
| 6755 | } |
| 6756 | final int start = range[0]; |
| 6757 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6758 | setAccessibilityCursorPosition(end); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6759 | sendViewTextTraversedAtGranularityEvent( |
| 6760 | AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, |
| 6761 | granularity, start, end); |
| 6762 | return true; |
| 6763 | } |
| 6764 | |
| 6765 | private boolean previousAtGranularity(int granularity) { |
| 6766 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 6767 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6768 | return false; |
| 6769 | } |
| 6770 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 6771 | if (iterator == null) { |
| 6772 | return false; |
| 6773 | } |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6774 | int current = getAccessibilityCursorPosition(); |
| 6775 | if (current == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 6776 | current = text.length(); |
| 6777 | } else if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 6778 | // When traversing by character we always put the cursor after the character |
| 6779 | // to ease edit and have to compensate before asking the for previous segment. |
| 6780 | current--; |
| 6781 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6782 | final int[] range = iterator.preceding(current); |
| 6783 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6784 | return false; |
| 6785 | } |
| 6786 | final int start = range[0]; |
| 6787 | final int end = range[1]; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 6788 | // Always put the cursor after the character to ease edit. |
| 6789 | if (granularity == AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER) { |
| 6790 | setAccessibilityCursorPosition(end); |
| 6791 | } else { |
| 6792 | setAccessibilityCursorPosition(start); |
| 6793 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6794 | sendViewTextTraversedAtGranularityEvent( |
| 6795 | AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, |
| 6796 | granularity, start, end); |
| 6797 | return true; |
| 6798 | } |
| 6799 | |
| 6800 | /** |
| 6801 | * Gets the text reported for accessibility purposes. |
| 6802 | * |
| 6803 | * @return The accessibility text. |
| 6804 | * |
| 6805 | * @hide |
| 6806 | */ |
| 6807 | public CharSequence getIterableTextForAccessibility() { |
| 6808 | return mContentDescription; |
| 6809 | } |
| 6810 | |
| 6811 | /** |
| 6812 | * @hide |
| 6813 | */ |
| 6814 | public int getAccessibilityCursorPosition() { |
| 6815 | return mAccessibilityCursorPosition; |
| 6816 | } |
| 6817 | |
| 6818 | /** |
| 6819 | * @hide |
| 6820 | */ |
| 6821 | public void setAccessibilityCursorPosition(int position) { |
| 6822 | mAccessibilityCursorPosition = position; |
| 6823 | } |
| 6824 | |
| 6825 | private void sendViewTextTraversedAtGranularityEvent(int action, int granularity, |
| 6826 | int fromIndex, int toIndex) { |
| 6827 | if (mParent == null) { |
| 6828 | return; |
| 6829 | } |
| 6830 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 6831 | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY); |
| 6832 | onInitializeAccessibilityEvent(event); |
| 6833 | onPopulateAccessibilityEvent(event); |
| 6834 | event.setFromIndex(fromIndex); |
| 6835 | event.setToIndex(toIndex); |
| 6836 | event.setAction(action); |
| 6837 | event.setMovementGranularity(granularity); |
| 6838 | mParent.requestSendAccessibilityEvent(this, event); |
| 6839 | } |
| 6840 | |
| 6841 | /** |
| 6842 | * @hide |
| 6843 | */ |
| 6844 | public TextSegmentIterator getIteratorForGranularity(int granularity) { |
| 6845 | switch (granularity) { |
| 6846 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER: { |
| 6847 | CharSequence text = getIterableTextForAccessibility(); |
| 6848 | if (text != null && text.length() > 0) { |
| 6849 | CharacterTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 6850 | CharacterTextSegmentIterator.getInstance( |
| 6851 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6852 | iterator.initialize(text.toString()); |
| 6853 | return iterator; |
| 6854 | } |
| 6855 | } break; |
| 6856 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD: { |
| 6857 | CharSequence text = getIterableTextForAccessibility(); |
| 6858 | if (text != null && text.length() > 0) { |
| 6859 | WordTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 6860 | WordTextSegmentIterator.getInstance( |
| 6861 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6862 | iterator.initialize(text.toString()); |
| 6863 | return iterator; |
| 6864 | } |
| 6865 | } break; |
| 6866 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH: { |
| 6867 | CharSequence text = getIterableTextForAccessibility(); |
| 6868 | if (text != null && text.length() > 0) { |
| 6869 | ParagraphTextSegmentIterator iterator = |
| 6870 | ParagraphTextSegmentIterator.getInstance(); |
| 6871 | iterator.initialize(text.toString()); |
| 6872 | return iterator; |
| 6873 | } |
| 6874 | } break; |
| 6875 | } |
| 6876 | return null; |
| 6877 | } |
| 6878 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6879 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6880 | * @hide |
| 6881 | */ |
| 6882 | public void dispatchStartTemporaryDetach() { |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 6883 | clearAccessibilityFocus(); |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 6884 | clearDisplayList(); |
| 6885 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6886 | onStartTemporaryDetach(); |
| 6887 | } |
| 6888 | |
| 6889 | /** |
| 6890 | * 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] | 6891 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 6892 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6893 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6894 | */ |
| 6895 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6896 | removeUnsetPressCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6897 | mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | /** |
| 6901 | * @hide |
| 6902 | */ |
| 6903 | public void dispatchFinishTemporaryDetach() { |
| 6904 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6905 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6906 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | /** |
| 6908 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 6909 | * changing the view. |
| 6910 | */ |
| 6911 | public void onFinishTemporaryDetach() { |
| 6912 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6913 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6915 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 6916 | * for this view's window. Returns null if the view is not currently attached |
| 6917 | * 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] | 6918 | * just use the standard high-level event callbacks like |
| 6919 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6920 | */ |
| 6921 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 6922 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 6923 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 6924 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 6925 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | * Dispatch a key event before it is processed by any input method |
| 6927 | * associated with the view hierarchy. This can be used to intercept |
| 6928 | * key events in special situations before the IME consumes them; a |
| 6929 | * typical example would be handling the BACK key to update the application's |
| 6930 | * UI instead of allowing the IME to see it and close itself. |
| 6931 | * |
| 6932 | * @param event The key event to be dispatched. |
| 6933 | * @return True if the event was handled, false otherwise. |
| 6934 | */ |
| 6935 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 6936 | return onKeyPreIme(event.getKeyCode(), event); |
| 6937 | } |
| 6938 | |
| 6939 | /** |
| 6940 | * Dispatch a key event to the next view on the focus path. This path runs |
| 6941 | * from the top of the view tree down to the currently focused view. If this |
| 6942 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 6943 | * the next node down the focus path. This method also fires any key |
| 6944 | * listeners. |
| 6945 | * |
| 6946 | * @param event The key event to be dispatched. |
| 6947 | * @return True if the event was handled, false otherwise. |
| 6948 | */ |
| 6949 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6950 | if (mInputEventConsistencyVerifier != null) { |
| 6951 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 6952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6953 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6954 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 6955 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6956 | ListenerInfo li = mListenerInfo; |
| 6957 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6958 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6959 | return true; |
| 6960 | } |
| 6961 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6962 | if (event.dispatch(this, mAttachInfo != null |
| 6963 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 6964 | return true; |
| 6965 | } |
| 6966 | |
| 6967 | if (mInputEventConsistencyVerifier != null) { |
| 6968 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 6969 | } |
| 6970 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | /** |
| 6974 | * Dispatches a key shortcut event. |
| 6975 | * |
| 6976 | * @param event The key event to be dispatched. |
| 6977 | * @return True if the event was handled by the view, false otherwise. |
| 6978 | */ |
| 6979 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 6980 | return onKeyShortcut(event.getKeyCode(), event); |
| 6981 | } |
| 6982 | |
| 6983 | /** |
| 6984 | * Pass the touch screen motion event down to the target view, or this |
| 6985 | * view if it is the target. |
| 6986 | * |
| 6987 | * @param event The motion event to be dispatched. |
| 6988 | * @return True if the event was handled by the view, false otherwise. |
| 6989 | */ |
| 6990 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 6991 | if (mInputEventConsistencyVerifier != null) { |
| 6992 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 6993 | } |
| 6994 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 6995 | if (onFilterTouchEventForSecurity(event)) { |
| 6996 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 6997 | ListenerInfo li = mListenerInfo; |
| 6998 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 6999 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7000 | return true; |
| 7001 | } |
| 7002 | |
| 7003 | if (onTouchEvent(event)) { |
| 7004 | return true; |
| 7005 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7006 | } |
| 7007 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7008 | if (mInputEventConsistencyVerifier != null) { |
| 7009 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7010 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7011 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7015 | * Filter the touch event to apply security policies. |
| 7016 | * |
| 7017 | * @param event The motion event to be filtered. |
| 7018 | * @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] | 7019 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7020 | * @see #getFilterTouchesWhenObscured |
| 7021 | */ |
| 7022 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7023 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7024 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 7025 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 7026 | // Window is obscured, drop this touch. |
| 7027 | return false; |
| 7028 | } |
| 7029 | return true; |
| 7030 | } |
| 7031 | |
| 7032 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7033 | * Pass a trackball motion event down to the focused view. |
| 7034 | * |
| 7035 | * @param event The motion event to be dispatched. |
| 7036 | * @return True if the event was handled by the view, false otherwise. |
| 7037 | */ |
| 7038 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7039 | if (mInputEventConsistencyVerifier != null) { |
| 7040 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 7041 | } |
| 7042 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7043 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7047 | * Dispatch a generic motion event. |
| 7048 | * <p> |
| 7049 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7050 | * 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] | 7051 | * 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] | 7052 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7053 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7054 | * |
| 7055 | * @param event The motion event to be dispatched. |
| 7056 | * @return True if the event was handled by the view, false otherwise. |
| 7057 | */ |
| 7058 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7059 | if (mInputEventConsistencyVerifier != null) { |
| 7060 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 7061 | } |
| 7062 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7063 | final int source = event.getSource(); |
| 7064 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7065 | final int action = event.getAction(); |
| 7066 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 7067 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 7068 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 7069 | if (dispatchHoverEvent(event)) { |
| 7070 | return true; |
| 7071 | } |
| 7072 | } else if (dispatchGenericPointerEvent(event)) { |
| 7073 | return true; |
| 7074 | } |
| 7075 | } else if (dispatchGenericFocusedEvent(event)) { |
| 7076 | return true; |
| 7077 | } |
| 7078 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7079 | if (dispatchGenericMotionEventInternal(event)) { |
| 7080 | return true; |
| 7081 | } |
| 7082 | |
| 7083 | if (mInputEventConsistencyVerifier != null) { |
| 7084 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7085 | } |
| 7086 | return false; |
| 7087 | } |
| 7088 | |
| 7089 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 7090 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7091 | ListenerInfo li = mListenerInfo; |
| 7092 | if (li != null && li.mOnGenericMotionListener != null |
| 7093 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7094 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7095 | return true; |
| 7096 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7097 | |
| 7098 | if (onGenericMotionEvent(event)) { |
| 7099 | return true; |
| 7100 | } |
| 7101 | |
| 7102 | if (mInputEventConsistencyVerifier != null) { |
| 7103 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7104 | } |
| 7105 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7109 | * Dispatch a hover event. |
| 7110 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7111 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7112 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7113 | * </p> |
| 7114 | * |
| 7115 | * @param event The motion event to be dispatched. |
| 7116 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7117 | */ |
| 7118 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7119 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7120 | ListenerInfo li = mListenerInfo; |
| 7121 | if (li != null && li.mOnHoverListener != null |
| 7122 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7123 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7124 | return true; |
| 7125 | } |
| 7126 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7127 | return onHoverEvent(event); |
| 7128 | } |
| 7129 | |
| 7130 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7131 | * Returns true if the view has a child to which it has recently sent |
| 7132 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 7133 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 7134 | * @hide |
| 7135 | */ |
| 7136 | protected boolean hasHoveredChild() { |
| 7137 | return false; |
| 7138 | } |
| 7139 | |
| 7140 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7141 | * Dispatch a generic motion event to the view under the first pointer. |
| 7142 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7143 | * Do not call this method directly. |
| 7144 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7145 | * </p> |
| 7146 | * |
| 7147 | * @param event The motion event to be dispatched. |
| 7148 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7149 | */ |
| 7150 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 7151 | return false; |
| 7152 | } |
| 7153 | |
| 7154 | /** |
| 7155 | * Dispatch a generic motion event to the currently focused view. |
| 7156 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7157 | * Do not call this method directly. |
| 7158 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7159 | * </p> |
| 7160 | * |
| 7161 | * @param event The motion event to be dispatched. |
| 7162 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7163 | */ |
| 7164 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 7165 | return false; |
| 7166 | } |
| 7167 | |
| 7168 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7169 | * Dispatch a pointer event. |
| 7170 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7171 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 7172 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 7173 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7174 | * and should not be expected to handle other pointing device features. |
| 7175 | * </p> |
| 7176 | * |
| 7177 | * @param event The motion event to be dispatched. |
| 7178 | * @return True if the event was handled by the view, false otherwise. |
| 7179 | * @hide |
| 7180 | */ |
| 7181 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 7182 | if (event.isTouchEvent()) { |
| 7183 | return dispatchTouchEvent(event); |
| 7184 | } else { |
| 7185 | return dispatchGenericMotionEvent(event); |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | * Called when the window containing this view gains or loses window focus. |
| 7191 | * ViewGroups should override to route to their children. |
| 7192 | * |
| 7193 | * @param hasFocus True if the window containing this view now has focus, |
| 7194 | * false otherwise. |
| 7195 | */ |
| 7196 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 7197 | onWindowFocusChanged(hasFocus); |
| 7198 | } |
| 7199 | |
| 7200 | /** |
| 7201 | * Called when the window containing this view gains or loses focus. Note |
| 7202 | * that this is separate from view focus: to receive key events, both |
| 7203 | * your view and its window must have focus. If a window is displayed |
| 7204 | * on top of yours that takes input focus, then your own window will lose |
| 7205 | * focus but the view focus will remain unchanged. |
| 7206 | * |
| 7207 | * @param hasWindowFocus True if the window containing this view now has |
| 7208 | * focus, false otherwise. |
| 7209 | */ |
| 7210 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 7211 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 7212 | if (!hasWindowFocus) { |
| 7213 | if (isPressed()) { |
| 7214 | setPressed(false); |
| 7215 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7216 | if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | imm.focusOut(this); |
| 7218 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7219 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 7220 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 7221 | onFocusLost(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7222 | } else if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | imm.focusIn(this); |
| 7224 | } |
| 7225 | refreshDrawableState(); |
| 7226 | } |
| 7227 | |
| 7228 | /** |
| 7229 | * Returns true if this view is in a window that currently has window focus. |
| 7230 | * Note that this is not the same as the view itself having focus. |
| 7231 | * |
| 7232 | * @return True if this view is in a window that currently has window focus. |
| 7233 | */ |
| 7234 | public boolean hasWindowFocus() { |
| 7235 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 7236 | } |
| 7237 | |
| 7238 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7239 | * Dispatch a view visibility change down the view hierarchy. |
| 7240 | * ViewGroups should override to route to their children. |
| 7241 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7242 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7243 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7244 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7245 | */ |
| 7246 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 7247 | onVisibilityChanged(changedView, visibility); |
| 7248 | } |
| 7249 | |
| 7250 | /** |
| 7251 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 7252 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7253 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7254 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7255 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7256 | */ |
| 7257 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7258 | if (visibility == VISIBLE) { |
| 7259 | if (mAttachInfo != null) { |
| 7260 | initialAwakenScrollBars(); |
| 7261 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7262 | mPrivateFlags |= PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7263 | } |
| 7264 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7265 | } |
| 7266 | |
| 7267 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7268 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 7269 | * a View moves out of the screen, it might receives a display hint indicating |
| 7270 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7271 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7272 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7273 | * @param hint A hint about whether or not this view is displayed: |
| 7274 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7275 | */ |
| 7276 | public void dispatchDisplayHint(int hint) { |
| 7277 | onDisplayHint(hint); |
| 7278 | } |
| 7279 | |
| 7280 | /** |
| 7281 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 7282 | * a View moves out of the screen, it might receives a display hint indicating |
| 7283 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7284 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7285 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7286 | * @param hint A hint about whether or not this view is displayed: |
| 7287 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7288 | */ |
| 7289 | protected void onDisplayHint(int hint) { |
| 7290 | } |
| 7291 | |
| 7292 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7293 | * Dispatch a window visibility change down the view hierarchy. |
| 7294 | * ViewGroups should override to route to their children. |
| 7295 | * |
| 7296 | * @param visibility The new visibility of the window. |
| 7297 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7298 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | */ |
| 7300 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 7301 | onWindowVisibilityChanged(visibility); |
| 7302 | } |
| 7303 | |
| 7304 | /** |
| 7305 | * Called when the window containing has change its visibility |
| 7306 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 7307 | * that this tells you whether or not your window is being made visible |
| 7308 | * to the window manager; this does <em>not</em> tell you whether or not |
| 7309 | * your window is obscured by other windows on the screen, even if it |
| 7310 | * is itself visible. |
| 7311 | * |
| 7312 | * @param visibility The new visibility of the window. |
| 7313 | */ |
| 7314 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7315 | if (visibility == VISIBLE) { |
| 7316 | initialAwakenScrollBars(); |
| 7317 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7318 | } |
| 7319 | |
| 7320 | /** |
| 7321 | * Returns the current visibility of the window this view is attached to |
| 7322 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 7323 | * |
| 7324 | * @return Returns the current visibility of the view's window. |
| 7325 | */ |
| 7326 | public int getWindowVisibility() { |
| 7327 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 7328 | } |
| 7329 | |
| 7330 | /** |
| 7331 | * Retrieve the overall visible display size in which the window this view is |
| 7332 | * attached to has been positioned in. This takes into account screen |
| 7333 | * decorations above the window, for both cases where the window itself |
| 7334 | * is being position inside of them or the window is being placed under |
| 7335 | * then and covered insets are used for the window to position its content |
| 7336 | * inside. In effect, this tells you the available area where content can |
| 7337 | * be placed and remain visible to users. |
| 7338 | * |
| 7339 | * <p>This function requires an IPC back to the window manager to retrieve |
| 7340 | * the requested information, so should not be used in performance critical |
| 7341 | * code like drawing. |
| 7342 | * |
| 7343 | * @param outRect Filled in with the visible display frame. If the view |
| 7344 | * is not attached to a window, this is simply the raw display size. |
| 7345 | */ |
| 7346 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 7347 | if (mAttachInfo != null) { |
| 7348 | try { |
| 7349 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 7350 | } catch (RemoteException e) { |
| 7351 | return; |
| 7352 | } |
| 7353 | // XXX This is really broken, and probably all needs to be done |
| 7354 | // in the window manager, and we need to know more about whether |
| 7355 | // we want the area behind or in front of the IME. |
| 7356 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 7357 | outRect.left += insets.left; |
| 7358 | outRect.top += insets.top; |
| 7359 | outRect.right -= insets.right; |
| 7360 | outRect.bottom -= insets.bottom; |
| 7361 | return; |
| 7362 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7363 | // The view is not attached to a display so we don't have a context. |
| 7364 | // Make a best guess about the display size. |
| 7365 | Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 7366 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7367 | } |
| 7368 | |
| 7369 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7370 | * Dispatch a notification about a resource configuration change down |
| 7371 | * the view hierarchy. |
| 7372 | * ViewGroups should override to route to their children. |
| 7373 | * |
| 7374 | * @param newConfig The new resource configuration. |
| 7375 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7376 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7377 | */ |
| 7378 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 7379 | onConfigurationChanged(newConfig); |
| 7380 | } |
| 7381 | |
| 7382 | /** |
| 7383 | * Called when the current configuration of the resources being used |
| 7384 | * by the application have changed. You can use this to decide when |
| 7385 | * to reload resources that can changed based on orientation and other |
| 7386 | * configuration characterstics. You only need to use this if you are |
| 7387 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 7388 | * recreating the activity instance upon a configuration change. |
| 7389 | * |
| 7390 | * @param newConfig The new resource configuration. |
| 7391 | */ |
| 7392 | protected void onConfigurationChanged(Configuration newConfig) { |
| 7393 | } |
| 7394 | |
| 7395 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7396 | * Private function to aggregate all per-view attributes in to the view |
| 7397 | * root. |
| 7398 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7399 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7400 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | } |
| 7402 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7403 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7404 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7405 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7406 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7407 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7408 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7409 | ListenerInfo li = mListenerInfo; |
| 7410 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7411 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7412 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | } |
| 7414 | } |
| 7415 | |
| 7416 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7417 | final AttachInfo ai = mAttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | if (ai != null) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7419 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 7420 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | ai.mRecomputeGlobalAttributes = true; |
| 7422 | } |
| 7423 | } |
| 7424 | } |
| 7425 | |
| 7426 | /** |
| 7427 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 7428 | * once the user begins interacting with the device by touch, and affects various |
| 7429 | * things like whether focus is always visible to the user. |
| 7430 | * |
| 7431 | * @return Whether the device is in touch mode. |
| 7432 | */ |
| 7433 | @ViewDebug.ExportedProperty |
| 7434 | public boolean isInTouchMode() { |
| 7435 | if (mAttachInfo != null) { |
| 7436 | return mAttachInfo.mInTouchMode; |
| 7437 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7438 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | /** |
| 7443 | * Returns the context the view is running in, through which it can |
| 7444 | * access the current theme, resources, etc. |
| 7445 | * |
| 7446 | * @return The view's Context. |
| 7447 | */ |
| 7448 | @ViewDebug.CapturedViewProperty |
| 7449 | public final Context getContext() { |
| 7450 | return mContext; |
| 7451 | } |
| 7452 | |
| 7453 | /** |
| 7454 | * Handle a key event before it is processed by any input method |
| 7455 | * associated with the view hierarchy. This can be used to intercept |
| 7456 | * key events in special situations before the IME consumes them; a |
| 7457 | * typical example would be handling the BACK key to update the application's |
| 7458 | * UI instead of allowing the IME to see it and close itself. |
| 7459 | * |
| 7460 | * @param keyCode The value in event.getKeyCode(). |
| 7461 | * @param event Description of the key event. |
| 7462 | * @return If you handled the event, return true. If you want to allow the |
| 7463 | * event to be handled by the next receiver, return false. |
| 7464 | */ |
| 7465 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7466 | return false; |
| 7467 | } |
| 7468 | |
| 7469 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7470 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7471 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7472 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7473 | * is released, if the view is enabled and clickable. |
| 7474 | * |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7475 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7476 | * although some may elect to do so in some situations. Do not rely on this to |
| 7477 | * catch software key presses. |
| 7478 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7479 | * @param keyCode A key code that represents the button pressed, from |
| 7480 | * {@link android.view.KeyEvent}. |
| 7481 | * @param event The KeyEvent object that defines the button action. |
| 7482 | */ |
| 7483 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7484 | boolean result = false; |
| 7485 | |
| 7486 | switch (keyCode) { |
| 7487 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7488 | case KeyEvent.KEYCODE_ENTER: { |
| 7489 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7490 | return true; |
| 7491 | } |
| 7492 | // Long clickable items don't necessarily have to be clickable |
| 7493 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7494 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7495 | (event.getRepeatCount() == 0)) { |
| 7496 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7497 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7498 | return true; |
| 7499 | } |
| 7500 | break; |
| 7501 | } |
| 7502 | } |
| 7503 | return result; |
| 7504 | } |
| 7505 | |
| 7506 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7507 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7508 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7509 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7510 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7511 | * although some may elect to do so in some situations. Do not rely on this to |
| 7512 | * catch software key presses. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7513 | */ |
| 7514 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7515 | return false; |
| 7516 | } |
| 7517 | |
| 7518 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7519 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7520 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7521 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7522 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7523 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7524 | * although some may elect to do so in some situations. Do not rely on this to |
| 7525 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | * |
| 7527 | * @param keyCode A key code that represents the button pressed, from |
| 7528 | * {@link android.view.KeyEvent}. |
| 7529 | * @param event The KeyEvent object that defines the button action. |
| 7530 | */ |
| 7531 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7532 | boolean result = false; |
| 7533 | |
| 7534 | switch (keyCode) { |
| 7535 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7536 | case KeyEvent.KEYCODE_ENTER: { |
| 7537 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7538 | return true; |
| 7539 | } |
| 7540 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7541 | setPressed(false); |
| 7542 | |
| 7543 | if (!mHasPerformedLongPress) { |
| 7544 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7545 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7546 | |
| 7547 | result = performClick(); |
| 7548 | } |
| 7549 | } |
| 7550 | break; |
| 7551 | } |
| 7552 | } |
| 7553 | return result; |
| 7554 | } |
| 7555 | |
| 7556 | /** |
| 7557 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7558 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7559 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7560 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7561 | * although some may elect to do so in some situations. Do not rely on this to |
| 7562 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7563 | * |
| 7564 | * @param keyCode A key code that represents the button pressed, from |
| 7565 | * {@link android.view.KeyEvent}. |
| 7566 | * @param repeatCount The number of times the action was made. |
| 7567 | * @param event The KeyEvent object that defines the button action. |
| 7568 | */ |
| 7569 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7570 | return false; |
| 7571 | } |
| 7572 | |
| 7573 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7574 | * Called on the focused view when a key shortcut event is not handled. |
| 7575 | * Override this method to implement local key shortcuts for the View. |
| 7576 | * Key shortcuts can also be implemented by setting the |
| 7577 | * {@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] | 7578 | * |
| 7579 | * @param keyCode The value in event.getKeyCode(). |
| 7580 | * @param event Description of the key event. |
| 7581 | * @return If you handled the event, return true. If you want to allow the |
| 7582 | * event to be handled by the next receiver, return false. |
| 7583 | */ |
| 7584 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7585 | return false; |
| 7586 | } |
| 7587 | |
| 7588 | /** |
| 7589 | * Check whether the called view is a text editor, in which case it |
| 7590 | * would make sense to automatically display a soft input window for |
| 7591 | * it. Subclasses should override this if they implement |
| 7592 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7593 | * a call on that method would return a non-null InputConnection, and |
| 7594 | * they are really a first-class editor that the user would normally |
| 7595 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7596 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7597 | * <p>The default implementation always returns false. This does |
| 7598 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7599 | * will not be called or the user can not otherwise perform edits on your |
| 7600 | * view; it is just a hint to the system that this is not the primary |
| 7601 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7602 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | * @return Returns true if this view is a text editor, else false. |
| 7604 | */ |
| 7605 | public boolean onCheckIsTextEditor() { |
| 7606 | return false; |
| 7607 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | /** |
| 7610 | * Create a new InputConnection for an InputMethod to interact |
| 7611 | * with the view. The default implementation returns null, since it doesn't |
| 7612 | * support input methods. You can override this to implement such support. |
| 7613 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7614 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7615 | * <p>When implementing this, you probably also want to implement |
| 7616 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7617 | * non-null InputConnection. |
| 7618 | * |
| 7619 | * @param outAttrs Fill in with attribute information about the connection. |
| 7620 | */ |
| 7621 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7622 | return null; |
| 7623 | } |
| 7624 | |
| 7625 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7626 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7627 | * when a view who is not the current |
| 7628 | * input connection target is trying to make a call on the manager. The |
| 7629 | * default implementation returns false; you can override this to return |
| 7630 | * true for certain views if you are performing InputConnection proxying |
| 7631 | * to them. |
| 7632 | * @param view The View that is making the InputMethodManager call. |
| 7633 | * @return Return true to allow the call, false to reject. |
| 7634 | */ |
| 7635 | public boolean checkInputConnectionProxy(View view) { |
| 7636 | return false; |
| 7637 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7638 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7639 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7640 | * Show the context menu for this view. It is not safe to hold on to the |
| 7641 | * menu after returning from this method. |
| 7642 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7643 | * You should normally not overload this method. Overload |
| 7644 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7645 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7646 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7647 | * @param menu The context menu to populate |
| 7648 | */ |
| 7649 | public void createContextMenu(ContextMenu menu) { |
| 7650 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7651 | |
| 7652 | // Sets the current menu info so all items added to menu will have |
| 7653 | // my extra info set. |
| 7654 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7655 | |
| 7656 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7657 | ListenerInfo li = mListenerInfo; |
| 7658 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7659 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | // Clear the extra information so subsequent items that aren't mine don't |
| 7663 | // have my extra info. |
| 7664 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7665 | |
| 7666 | if (mParent != null) { |
| 7667 | mParent.createContextMenu(menu); |
| 7668 | } |
| 7669 | } |
| 7670 | |
| 7671 | /** |
| 7672 | * Views should implement this if they have extra information to associate |
| 7673 | * with the context menu. The return result is supplied as a parameter to |
| 7674 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7675 | * callback. |
| 7676 | * |
| 7677 | * @return Extra information about the item for which the context menu |
| 7678 | * should be shown. This information will vary across different |
| 7679 | * subclasses of View. |
| 7680 | */ |
| 7681 | protected ContextMenuInfo getContextMenuInfo() { |
| 7682 | return null; |
| 7683 | } |
| 7684 | |
| 7685 | /** |
| 7686 | * Views should implement this if the view itself is going to add items to |
| 7687 | * the context menu. |
| 7688 | * |
| 7689 | * @param menu the context menu to populate |
| 7690 | */ |
| 7691 | protected void onCreateContextMenu(ContextMenu menu) { |
| 7692 | } |
| 7693 | |
| 7694 | /** |
| 7695 | * Implement this method to handle trackball motion events. The |
| 7696 | * <em>relative</em> movement of the trackball since the last event |
| 7697 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 7698 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 7699 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 7700 | * they will often be fractional values, representing the more fine-grained |
| 7701 | * movement information available from a trackball). |
| 7702 | * |
| 7703 | * @param event The motion event. |
| 7704 | * @return True if the event was handled, false otherwise. |
| 7705 | */ |
| 7706 | public boolean onTrackballEvent(MotionEvent event) { |
| 7707 | return false; |
| 7708 | } |
| 7709 | |
| 7710 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7711 | * Implement this method to handle generic motion events. |
| 7712 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7713 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 7714 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7715 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 7716 | * the class of input that was received. Implementations of this method |
| 7717 | * must examine the bits in the source before processing the event. |
| 7718 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7719 | * </p><p> |
| 7720 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7721 | * are delivered to the view under the pointer. All other generic motion events are |
| 7722 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7723 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7724 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7725 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7726 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 7727 | * // process the joystick movement... |
| 7728 | * return true; |
| 7729 | * } |
| 7730 | * } |
| 7731 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7732 | * switch (event.getAction()) { |
| 7733 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 7734 | * // process the mouse hover movement... |
| 7735 | * return true; |
| 7736 | * case MotionEvent.ACTION_SCROLL: |
| 7737 | * // process the scroll wheel movement... |
| 7738 | * return true; |
| 7739 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7740 | * } |
| 7741 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 7742 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7743 | * |
| 7744 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7745 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7746 | */ |
| 7747 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 7748 | return false; |
| 7749 | } |
| 7750 | |
| 7751 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7752 | * Implement this method to handle hover events. |
| 7753 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7754 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 7755 | * bounds of a view and the view is not currently being touched. |
| 7756 | * Hover events are represented as pointer events with action |
| 7757 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 7758 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 7759 | * </p> |
| 7760 | * <ul> |
| 7761 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 7762 | * when the pointer enters the bounds of the view.</li> |
| 7763 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 7764 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 7765 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 7766 | * when the pointer has exited the bounds of the view or when the pointer is |
| 7767 | * about to go down due to a button click, tap, or similar user action that |
| 7768 | * causes the view to be touched.</li> |
| 7769 | * </ul> |
| 7770 | * <p> |
| 7771 | * The view should implement this method to return true to indicate that it is |
| 7772 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7773 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7774 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 7775 | * 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] | 7776 | * is enabled and is clickable. The default implementation also sends hover |
| 7777 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7778 | * </p> |
| 7779 | * |
| 7780 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7781 | * @return True if the view handled the hover event. |
| 7782 | * |
| 7783 | * @see #isHovered |
| 7784 | * @see #setHovered |
| 7785 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7786 | */ |
| 7787 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7788 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 7789 | // the window. This code ensures that we only send accessibility events for |
| 7790 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7791 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7792 | if (!mSendingHoverAccessibilityEvents) { |
| 7793 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 7794 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 7795 | && !hasHoveredChild() |
| 7796 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 7797 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7798 | mSendingHoverAccessibilityEvents = true; |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7799 | } |
| 7800 | } else { |
| 7801 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7802 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7803 | && !pointInView(event.getX(), event.getY()))) { |
| 7804 | mSendingHoverAccessibilityEvents = false; |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 7805 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7806 | // If the window does not have input focus we take away accessibility |
| 7807 | // focus as soon as the user stop hovering over the view. |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 7808 | if (mAttachInfo != null && !mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7809 | getViewRootImpl().setAccessibilityFocus(null, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7810 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7811 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7812 | } |
| 7813 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7814 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 7815 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7816 | case MotionEvent.ACTION_HOVER_ENTER: |
| 7817 | setHovered(true); |
| 7818 | break; |
| 7819 | case MotionEvent.ACTION_HOVER_EXIT: |
| 7820 | setHovered(false); |
| 7821 | break; |
| 7822 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 7823 | |
| 7824 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 7825 | // This is to provide compatibility with existing applications that |
| 7826 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 7827 | // break because of the new default handling for hoverable views |
| 7828 | // in onHoverEvent. |
| 7829 | // Note that onGenericMotionEvent will be called by default when |
| 7830 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 7831 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7832 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7833 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7834 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7835 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7836 | } |
| 7837 | |
| 7838 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7839 | * Returns true if the view should handle {@link #onHoverEvent} |
| 7840 | * by calling {@link #setHovered} to change its hovered state. |
| 7841 | * |
| 7842 | * @return True if the view is hoverable. |
| 7843 | */ |
| 7844 | private boolean isHoverable() { |
| 7845 | final int viewFlags = mViewFlags; |
| 7846 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 7847 | return false; |
| 7848 | } |
| 7849 | |
| 7850 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 7851 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 7852 | } |
| 7853 | |
| 7854 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7855 | * Returns true if the view is currently hovered. |
| 7856 | * |
| 7857 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7858 | * |
| 7859 | * @see #setHovered |
| 7860 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7861 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7862 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7863 | public boolean isHovered() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7864 | return (mPrivateFlags & PFLAG_HOVERED) != 0; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | /** |
| 7868 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7869 | * <p> |
| 7870 | * Calling this method also changes the drawable state of the view. This |
| 7871 | * enables the view to react to hover by using different drawable resources |
| 7872 | * to change its appearance. |
| 7873 | * </p><p> |
| 7874 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 7875 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7876 | * |
| 7877 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7878 | * |
| 7879 | * @see #isHovered |
| 7880 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7881 | */ |
| 7882 | public void setHovered(boolean hovered) { |
| 7883 | if (hovered) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7884 | if ((mPrivateFlags & PFLAG_HOVERED) == 0) { |
| 7885 | mPrivateFlags |= PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7886 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7887 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7888 | } |
| 7889 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7890 | if ((mPrivateFlags & PFLAG_HOVERED) != 0) { |
| 7891 | mPrivateFlags &= ~PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7892 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7893 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7894 | } |
| 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7899 | * Implement this method to handle hover state changes. |
| 7900 | * <p> |
| 7901 | * This method is called whenever the hover state changes as a result of a |
| 7902 | * call to {@link #setHovered}. |
| 7903 | * </p> |
| 7904 | * |
| 7905 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 7906 | * |
| 7907 | * @see #isHovered |
| 7908 | * @see #setHovered |
| 7909 | */ |
| 7910 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7911 | } |
| 7912 | |
| 7913 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7914 | * Implement this method to handle touch screen motion events. |
| 7915 | * |
| 7916 | * @param event The motion event. |
| 7917 | * @return True if the event was handled, false otherwise. |
| 7918 | */ |
| 7919 | public boolean onTouchEvent(MotionEvent event) { |
| 7920 | final int viewFlags = mViewFlags; |
| 7921 | |
| 7922 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7923 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7924 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 7925 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | // A disabled view that is clickable still consumes the touch |
| 7927 | // events, it just doesn't respond to them. |
| 7928 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7929 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 7930 | } |
| 7931 | |
| 7932 | if (mTouchDelegate != null) { |
| 7933 | if (mTouchDelegate.onTouchEvent(event)) { |
| 7934 | return true; |
| 7935 | } |
| 7936 | } |
| 7937 | |
| 7938 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 7939 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 7940 | switch (event.getAction()) { |
| 7941 | case MotionEvent.ACTION_UP: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7942 | boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0; |
| 7943 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7944 | // take focus if we don't have it already and we should in |
| 7945 | // touch mode. |
| 7946 | boolean focusTaken = false; |
| 7947 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 7948 | focusTaken = requestFocus(); |
| 7949 | } |
| 7950 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7951 | if (prepressed) { |
| 7952 | // The button is being released before we actually |
| 7953 | // showed it as pressed. Make it show the pressed |
| 7954 | // state now (before scheduling the click) to ensure |
| 7955 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 7956 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 7957 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | if (!mHasPerformedLongPress) { |
| 7960 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7961 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7962 | |
| 7963 | // Only perform take click actions if we were in the pressed state |
| 7964 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 7965 | // Use a Runnable and post this rather than calling |
| 7966 | // performClick directly. This lets other visual state |
| 7967 | // of the view update before click actions start. |
| 7968 | if (mPerformClick == null) { |
| 7969 | mPerformClick = new PerformClick(); |
| 7970 | } |
| 7971 | if (!post(mPerformClick)) { |
| 7972 | performClick(); |
| 7973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | } |
| 7975 | } |
| 7976 | |
| 7977 | if (mUnsetPressedState == null) { |
| 7978 | mUnsetPressedState = new UnsetPressedState(); |
| 7979 | } |
| 7980 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7981 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7982 | postDelayed(mUnsetPressedState, |
| 7983 | ViewConfiguration.getPressedStateDuration()); |
| 7984 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7985 | // If the post failed, unpress right now |
| 7986 | mUnsetPressedState.run(); |
| 7987 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 7988 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | } |
| 7990 | break; |
| 7991 | |
| 7992 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 7993 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7994 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 7995 | if (performButtonActionOnTouchDown(event)) { |
| 7996 | break; |
| 7997 | } |
| 7998 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7999 | // 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] | 8000 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8001 | |
| 8002 | // For views inside a scrolling container, delay the pressed feedback for |
| 8003 | // a short period in case this is a scroll. |
| 8004 | if (isInScrollingContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8005 | mPrivateFlags |= PFLAG_PREPRESSED; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8006 | if (mPendingCheckForTap == null) { |
| 8007 | mPendingCheckForTap = new CheckForTap(); |
| 8008 | } |
| 8009 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 8010 | } else { |
| 8011 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8012 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8013 | checkForLongClick(0); |
| 8014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | break; |
| 8016 | |
| 8017 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8018 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8019 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | break; |
| 8021 | |
| 8022 | case MotionEvent.ACTION_MOVE: |
| 8023 | final int x = (int) event.getX(); |
| 8024 | final int y = (int) event.getY(); |
| 8025 | |
| 8026 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8027 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8029 | removeTapCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8030 | if ((mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8031 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8032 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8034 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | } |
| 8037 | break; |
| 8038 | } |
| 8039 | return true; |
| 8040 | } |
| 8041 | |
| 8042 | return false; |
| 8043 | } |
| 8044 | |
| 8045 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 8046 | * @hide |
| 8047 | */ |
| 8048 | public boolean isInScrollingContainer() { |
| 8049 | ViewParent p = getParent(); |
| 8050 | while (p != null && p instanceof ViewGroup) { |
| 8051 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 8052 | return true; |
| 8053 | } |
| 8054 | p = p.getParent(); |
| 8055 | } |
| 8056 | return false; |
| 8057 | } |
| 8058 | |
| 8059 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8060 | * Remove the longpress detection timer. |
| 8061 | */ |
| 8062 | private void removeLongPressCallback() { |
| 8063 | if (mPendingCheckForLongPress != null) { |
| 8064 | removeCallbacks(mPendingCheckForLongPress); |
| 8065 | } |
| 8066 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 8067 | |
| 8068 | /** |
| 8069 | * Remove the pending click action |
| 8070 | */ |
| 8071 | private void removePerformClickCallback() { |
| 8072 | if (mPerformClick != null) { |
| 8073 | removeCallbacks(mPerformClick); |
| 8074 | } |
| 8075 | } |
| 8076 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8077 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8078 | * Remove the prepress detection timer. |
| 8079 | */ |
| 8080 | private void removeUnsetPressCallback() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8081 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 && mUnsetPressedState != null) { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8082 | setPressed(false); |
| 8083 | removeCallbacks(mUnsetPressedState); |
| 8084 | } |
| 8085 | } |
| 8086 | |
| 8087 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8088 | * Remove the tap detection timer. |
| 8089 | */ |
| 8090 | private void removeTapCallback() { |
| 8091 | if (mPendingCheckForTap != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8092 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8093 | removeCallbacks(mPendingCheckForTap); |
| 8094 | } |
| 8095 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8096 | |
| 8097 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | * Cancels a pending long press. Your subclass can use this if you |
| 8099 | * want the context menu to come up if the user presses and holds |
| 8100 | * at the same place, but you don't want it to come up if they press |
| 8101 | * and then move around enough to cause scrolling. |
| 8102 | */ |
| 8103 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8104 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 8105 | |
| 8106 | /* |
| 8107 | * The prepressed state handled by the tap callback is a display |
| 8108 | * construct, but the tap callback will post a long press callback |
| 8109 | * less its own timeout. Remove it here. |
| 8110 | */ |
| 8111 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8112 | } |
| 8113 | |
| 8114 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8115 | * Remove the pending callback for sending a |
| 8116 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 8117 | */ |
| 8118 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 8119 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 8120 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
Svetoslav Ganov | 4a812ae | 2012-05-29 16:46:10 -0700 | [diff] [blame] | 8121 | mSendViewScrolledAccessibilityEvent.mIsPending = false; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8122 | } |
| 8123 | } |
| 8124 | |
| 8125 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8126 | * Sets the TouchDelegate for this View. |
| 8127 | */ |
| 8128 | public void setTouchDelegate(TouchDelegate delegate) { |
| 8129 | mTouchDelegate = delegate; |
| 8130 | } |
| 8131 | |
| 8132 | /** |
| 8133 | * Gets the TouchDelegate for this View. |
| 8134 | */ |
| 8135 | public TouchDelegate getTouchDelegate() { |
| 8136 | return mTouchDelegate; |
| 8137 | } |
| 8138 | |
| 8139 | /** |
| 8140 | * Set flags controlling behavior of this view. |
| 8141 | * |
| 8142 | * @param flags Constant indicating the value which should be set |
| 8143 | * @param mask Constant indicating the bit range that should be changed |
| 8144 | */ |
| 8145 | void setFlags(int flags, int mask) { |
| 8146 | int old = mViewFlags; |
| 8147 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 8148 | |
| 8149 | int changed = mViewFlags ^ old; |
| 8150 | if (changed == 0) { |
| 8151 | return; |
| 8152 | } |
| 8153 | int privateFlags = mPrivateFlags; |
| 8154 | |
| 8155 | /* Check if the FOCUSABLE bit has changed */ |
| 8156 | if (((changed & FOCUSABLE_MASK) != 0) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8157 | ((privateFlags & PFLAG_HAS_BOUNDS) !=0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8159 | && ((privateFlags & PFLAG_FOCUSED) != 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8160 | /* Give up focus if we are no longer focusable */ |
| 8161 | clearFocus(); |
| 8162 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8163 | && ((privateFlags & PFLAG_FOCUSED) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | /* |
| 8165 | * Tell the view system that we are now available to take focus |
| 8166 | * if no one else already has it. |
| 8167 | */ |
| 8168 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 8169 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8170 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8171 | notifyAccessibilityStateChanged(); |
| 8172 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8173 | } |
| 8174 | |
| 8175 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 8176 | if ((changed & VISIBILITY_MASK) != 0) { |
| 8177 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8178 | * 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] | 8179 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 8180 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8181 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8182 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8183 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8184 | |
| 8185 | needGlobalAttributesUpdate(true); |
| 8186 | |
| 8187 | // a view becoming visible is worth notifying the parent |
| 8188 | // about in case nothing has focus. even if this specific view |
| 8189 | // isn't focusable, it may contain something that is, so let |
| 8190 | // the root view try to give this focus if nothing else does. |
| 8191 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 8192 | mParent.focusableViewAvailable(this); |
| 8193 | } |
| 8194 | } |
| 8195 | } |
| 8196 | |
| 8197 | /* Check if the GONE bit has changed */ |
| 8198 | if ((changed & GONE) != 0) { |
| 8199 | needGlobalAttributesUpdate(false); |
| 8200 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8202 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 8203 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8204 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8205 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8206 | if (mParent instanceof View) { |
| 8207 | // GONE views noop invalidation, so invalidate the parent |
| 8208 | ((View) mParent).invalidate(true); |
| 8209 | } |
| 8210 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 8211 | // time it is visible and gets invalidated |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8212 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | } |
| 8214 | if (mAttachInfo != null) { |
| 8215 | mAttachInfo.mViewVisibilityChanged = true; |
| 8216 | } |
| 8217 | } |
| 8218 | |
| 8219 | /* Check if the VISIBLE bit has changed */ |
| 8220 | if ((changed & INVISIBLE) != 0) { |
| 8221 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 8222 | /* |
| 8223 | * If this view is becoming invisible, set the DRAWN flag so that |
| 8224 | * the next invalidate() will not be skipped. |
| 8225 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8226 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8227 | |
| 8228 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8229 | // 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] | 8230 | if (getRootView() != this) { |
| 8231 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8232 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | } |
| 8234 | } |
| 8235 | if (mAttachInfo != null) { |
| 8236 | mAttachInfo.mViewVisibilityChanged = true; |
| 8237 | } |
| 8238 | } |
| 8239 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8240 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8241 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 8242 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 8243 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8244 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 8245 | } else if (mParent != null) { |
| 8246 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8247 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8248 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 8249 | } |
| 8250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8251 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 8252 | destroyDrawingCache(); |
| 8253 | } |
| 8254 | |
| 8255 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 8256 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8257 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8258 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8259 | } |
| 8260 | |
| 8261 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 8262 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8263 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | if ((changed & DRAW_MASK) != 0) { |
| 8267 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8268 | if (mBackground != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8269 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 8270 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8271 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8272 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8273 | } |
| 8274 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8275 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8276 | } |
| 8277 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8278 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8279 | } |
| 8280 | |
| 8281 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8282 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8283 | mParent.recomputeViewAttributes(this); |
| 8284 | } |
| 8285 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8286 | |
| 8287 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 8288 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 8289 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 8290 | notifyAccessibilityStateChanged(); |
| 8291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8292 | } |
| 8293 | |
| 8294 | /** |
| 8295 | * Change the view's z order in the tree, so it's on top of other sibling |
| 8296 | * views |
| 8297 | */ |
| 8298 | public void bringToFront() { |
| 8299 | if (mParent != null) { |
| 8300 | mParent.bringChildToFront(this); |
| 8301 | } |
| 8302 | } |
| 8303 | |
| 8304 | /** |
| 8305 | * This is called in response to an internal scroll in this view (i.e., the |
| 8306 | * view scrolled its own contents). This is typically as a result of |
| 8307 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 8308 | * called. |
| 8309 | * |
| 8310 | * @param l Current horizontal scroll origin. |
| 8311 | * @param t Current vertical scroll origin. |
| 8312 | * @param oldl Previous horizontal scroll origin. |
| 8313 | * @param oldt Previous vertical scroll origin. |
| 8314 | */ |
| 8315 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8316 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8317 | postSendViewScrolledAccessibilityEventCallback(); |
| 8318 | } |
| 8319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | mBackgroundSizeChanged = true; |
| 8321 | |
| 8322 | final AttachInfo ai = mAttachInfo; |
| 8323 | if (ai != null) { |
| 8324 | ai.mViewScrollChanged = true; |
| 8325 | } |
| 8326 | } |
| 8327 | |
| 8328 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8329 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 8330 | * changes due to layout processing. |
| 8331 | */ |
| 8332 | public interface OnLayoutChangeListener { |
| 8333 | /** |
| 8334 | * Called when the focus state of a view has changed. |
| 8335 | * |
| 8336 | * @param v The view whose state has changed. |
| 8337 | * @param left The new value of the view's left property. |
| 8338 | * @param top The new value of the view's top property. |
| 8339 | * @param right The new value of the view's right property. |
| 8340 | * @param bottom The new value of the view's bottom property. |
| 8341 | * @param oldLeft The previous value of the view's left property. |
| 8342 | * @param oldTop The previous value of the view's top property. |
| 8343 | * @param oldRight The previous value of the view's right property. |
| 8344 | * @param oldBottom The previous value of the view's bottom property. |
| 8345 | */ |
| 8346 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 8347 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 8348 | } |
| 8349 | |
| 8350 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8351 | * This is called during layout when the size of this view has changed. If |
| 8352 | * you were just added to the view hierarchy, you're called with the old |
| 8353 | * values of 0. |
| 8354 | * |
| 8355 | * @param w Current width of this view. |
| 8356 | * @param h Current height of this view. |
| 8357 | * @param oldw Old width of this view. |
| 8358 | * @param oldh Old height of this view. |
| 8359 | */ |
| 8360 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 8361 | } |
| 8362 | |
| 8363 | /** |
| 8364 | * Called by draw to draw the child views. This may be overridden |
| 8365 | * by derived classes to gain control just before its children are drawn |
| 8366 | * (but after its own view has been drawn). |
| 8367 | * @param canvas the canvas on which to draw the view |
| 8368 | */ |
| 8369 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * Gets the parent of this view. Note that the parent is a |
| 8375 | * ViewParent and not necessarily a View. |
| 8376 | * |
| 8377 | * @return Parent of this view. |
| 8378 | */ |
| 8379 | public final ViewParent getParent() { |
| 8380 | return mParent; |
| 8381 | } |
| 8382 | |
| 8383 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 8384 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 8385 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8386 | * invalidated. |
| 8387 | * @param value the x position to scroll to |
| 8388 | */ |
| 8389 | public void setScrollX(int value) { |
| 8390 | scrollTo(value, mScrollY); |
| 8391 | } |
| 8392 | |
| 8393 | /** |
| 8394 | * Set the vertical scrolled position of your view. This will cause a call to |
| 8395 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8396 | * invalidated. |
| 8397 | * @param value the y position to scroll to |
| 8398 | */ |
| 8399 | public void setScrollY(int value) { |
| 8400 | scrollTo(mScrollX, value); |
| 8401 | } |
| 8402 | |
| 8403 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8404 | * Return the scrolled left position of this view. This is the left edge of |
| 8405 | * the displayed part of your view. You do not need to draw any pixels |
| 8406 | * farther left, since those are outside of the frame of your view on |
| 8407 | * screen. |
| 8408 | * |
| 8409 | * @return The left edge of the displayed part of your view, in pixels. |
| 8410 | */ |
| 8411 | public final int getScrollX() { |
| 8412 | return mScrollX; |
| 8413 | } |
| 8414 | |
| 8415 | /** |
| 8416 | * Return the scrolled top position of this view. This is the top edge of |
| 8417 | * the displayed part of your view. You do not need to draw any pixels above |
| 8418 | * it, since those are outside of the frame of your view on screen. |
| 8419 | * |
| 8420 | * @return The top edge of the displayed part of your view, in pixels. |
| 8421 | */ |
| 8422 | public final int getScrollY() { |
| 8423 | return mScrollY; |
| 8424 | } |
| 8425 | |
| 8426 | /** |
| 8427 | * Return the width of the your view. |
| 8428 | * |
| 8429 | * @return The width of your view, in pixels. |
| 8430 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8431 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | public final int getWidth() { |
| 8433 | return mRight - mLeft; |
| 8434 | } |
| 8435 | |
| 8436 | /** |
| 8437 | * Return the height of your view. |
| 8438 | * |
| 8439 | * @return The height of your view, in pixels. |
| 8440 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8441 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8442 | public final int getHeight() { |
| 8443 | return mBottom - mTop; |
| 8444 | } |
| 8445 | |
| 8446 | /** |
| 8447 | * Return the visible drawing bounds of your view. Fills in the output |
| 8448 | * rectangle with the values from getScrollX(), getScrollY(), |
| 8449 | * getWidth(), and getHeight(). |
| 8450 | * |
| 8451 | * @param outRect The (scrolled) drawing bounds of the view. |
| 8452 | */ |
| 8453 | public void getDrawingRect(Rect outRect) { |
| 8454 | outRect.left = mScrollX; |
| 8455 | outRect.top = mScrollY; |
| 8456 | outRect.right = mScrollX + (mRight - mLeft); |
| 8457 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 8458 | } |
| 8459 | |
| 8460 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8461 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 8462 | * raw width component (that is the result is masked by |
| 8463 | * {@link #MEASURED_SIZE_MASK}). |
| 8464 | * |
| 8465 | * @return The raw measured width of this view. |
| 8466 | */ |
| 8467 | public final int getMeasuredWidth() { |
| 8468 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8469 | } |
| 8470 | |
| 8471 | /** |
| 8472 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8473 | * 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] | 8474 | * 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] | 8475 | * This should be used during measurement and layout calculations only. Use |
| 8476 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8477 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8478 | * @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] | 8479 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8480 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8481 | return mMeasuredWidth; |
| 8482 | } |
| 8483 | |
| 8484 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8485 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8486 | * raw width component (that is the result is masked by |
| 8487 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8489 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8490 | */ |
| 8491 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8492 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8493 | } |
| 8494 | |
| 8495 | /** |
| 8496 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8497 | * 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] | 8498 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8499 | * This should be used during measurement and layout calculations only. Use |
| 8500 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8501 | * |
| 8502 | * @return The measured width of this view as a bit mask. |
| 8503 | */ |
| 8504 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8505 | return mMeasuredHeight; |
| 8506 | } |
| 8507 | |
| 8508 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8509 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8510 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8511 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8512 | * and the height component is at the shifted bits |
| 8513 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8514 | */ |
| 8515 | public final int getMeasuredState() { |
| 8516 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8517 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8518 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8519 | } |
| 8520 | |
| 8521 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8522 | * The transform matrix of this view, which is calculated based on the current |
| 8523 | * roation, scale, and pivot properties. |
| 8524 | * |
| 8525 | * @see #getRotation() |
| 8526 | * @see #getScaleX() |
| 8527 | * @see #getScaleY() |
| 8528 | * @see #getPivotX() |
| 8529 | * @see #getPivotY() |
| 8530 | * @return The current transform matrix for the view |
| 8531 | */ |
| 8532 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8533 | if (mTransformationInfo != null) { |
| 8534 | updateMatrix(); |
| 8535 | return mTransformationInfo.mMatrix; |
| 8536 | } |
| 8537 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8538 | } |
| 8539 | |
| 8540 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8541 | * Utility function to determine if the value is far enough away from zero to be |
| 8542 | * considered non-zero. |
| 8543 | * @param value A floating point value to check for zero-ness |
| 8544 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8545 | */ |
| 8546 | private static boolean nonzero(float value) { |
| 8547 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8548 | } |
| 8549 | |
| 8550 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8551 | * Returns true if the transform matrix is the identity matrix. |
| 8552 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8553 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8554 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8555 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8556 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8557 | if (mTransformationInfo != null) { |
| 8558 | updateMatrix(); |
| 8559 | return mTransformationInfo.mMatrixIsIdentity; |
| 8560 | } |
| 8561 | return true; |
| 8562 | } |
| 8563 | |
| 8564 | void ensureTransformationInfo() { |
| 8565 | if (mTransformationInfo == null) { |
| 8566 | mTransformationInfo = new TransformationInfo(); |
| 8567 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8568 | } |
| 8569 | |
| 8570 | /** |
| 8571 | * Recomputes the transform matrix if necessary. |
| 8572 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8573 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8574 | final TransformationInfo info = mTransformationInfo; |
| 8575 | if (info == null) { |
| 8576 | return; |
| 8577 | } |
| 8578 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8579 | // transform-related properties have changed since the last time someone |
| 8580 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8581 | |
| 8582 | // Figure out if we need to update the pivot point |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8583 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8584 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8585 | info.mPrevWidth = mRight - mLeft; |
| 8586 | info.mPrevHeight = mBottom - mTop; |
| 8587 | info.mPivotX = info.mPrevWidth / 2f; |
| 8588 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8589 | } |
| 8590 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8591 | info.mMatrix.reset(); |
| 8592 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8593 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8594 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8595 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8596 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8597 | if (info.mCamera == null) { |
| 8598 | info.mCamera = new Camera(); |
| 8599 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8600 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8601 | info.mCamera.save(); |
| 8602 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8603 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8604 | info.mCamera.getMatrix(info.matrix3D); |
| 8605 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8606 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8607 | info.mPivotY + info.mTranslationY); |
| 8608 | info.mMatrix.postConcat(info.matrix3D); |
| 8609 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8610 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8611 | info.mMatrixDirty = false; |
| 8612 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8613 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8614 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8615 | } |
| 8616 | |
| 8617 | /** |
Tobias Dubois | defdb1e | 2010-12-15 11:35:30 +0100 | [diff] [blame] | 8618 | * When searching for a view to focus this rectangle is used when considering if this view is |
| 8619 | * a good candidate for receiving focus. |
| 8620 | * |
| 8621 | * By default, the rectangle is the {@link #getDrawingRect}) of the view. |
| 8622 | * |
| 8623 | * @param r The rectangle to fill in, in this view's coordinates. |
| 8624 | */ |
| 8625 | public void getFocusRect(Rect r) { |
| 8626 | getDrawingRect(r); |
| 8627 | } |
| 8628 | |
| 8629 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8630 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8631 | * We cache the matrix to avoid recalculating it when transform properties |
| 8632 | * have not changed. |
| 8633 | * |
| 8634 | * @return The inverse of the current matrix of this view. |
| 8635 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8636 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8637 | final TransformationInfo info = mTransformationInfo; |
| 8638 | if (info != null) { |
| 8639 | updateMatrix(); |
| 8640 | if (info.mInverseMatrixDirty) { |
| 8641 | if (info.mInverseMatrix == null) { |
| 8642 | info.mInverseMatrix = new Matrix(); |
| 8643 | } |
| 8644 | info.mMatrix.invert(info.mInverseMatrix); |
| 8645 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8646 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8647 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8648 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8649 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8653 | * Gets the distance along the Z axis from the camera to this view. |
| 8654 | * |
| 8655 | * @see #setCameraDistance(float) |
| 8656 | * |
| 8657 | * @return The distance along the Z axis. |
| 8658 | */ |
| 8659 | public float getCameraDistance() { |
| 8660 | ensureTransformationInfo(); |
| 8661 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8662 | final TransformationInfo info = mTransformationInfo; |
| 8663 | if (info.mCamera == null) { |
| 8664 | info.mCamera = new Camera(); |
| 8665 | info.matrix3D = new Matrix(); |
| 8666 | } |
| 8667 | return -(info.mCamera.getLocationZ() * dpi); |
| 8668 | } |
| 8669 | |
| 8670 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8671 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8672 | * views are drawn) from the camera to this view. The camera's distance |
| 8673 | * affects 3D transformations, for instance rotations around the X and Y |
| 8674 | * 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] | 8675 | * 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] | 8676 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8677 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8678 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8679 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8680 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8681 | * For example, a large distance will result in a large viewing angle, and there |
| 8682 | * 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] | 8683 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8684 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8685 | * behind the camera (which is why the recommendation is to use a distance at |
| 8686 | * 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] | 8687 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8688 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8689 | * on the screen density. For instance, on a medium density display, the |
| 8690 | * default distance is 1280. On a high density display, the default distance |
| 8691 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8692 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8693 | * <p>If you want to specify a distance that leads to visually consistent |
| 8694 | * results across various densities, use the following formula:</p> |
| 8695 | * <pre> |
| 8696 | * float scale = context.getResources().getDisplayMetrics().density; |
| 8697 | * view.setCameraDistance(distance * scale); |
| 8698 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8699 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8700 | * <p>The density scale factor of a high density display is 1.5, |
| 8701 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8702 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8703 | * @param distance The distance in "depth pixels", if negative the opposite |
| 8704 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8705 | * |
| 8706 | * @see #setRotationX(float) |
| 8707 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8708 | */ |
| 8709 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8710 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8711 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8712 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8713 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8714 | final TransformationInfo info = mTransformationInfo; |
| 8715 | if (info.mCamera == null) { |
| 8716 | info.mCamera = new Camera(); |
| 8717 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8718 | } |
| 8719 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8720 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 8721 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8722 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8723 | invalidateViewProperty(false, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8724 | if (mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 8725 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8726 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8727 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8728 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8729 | invalidateParentIfNeeded(); |
| 8730 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8731 | } |
| 8732 | |
| 8733 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8734 | * The degrees that the view is rotated around the pivot point. |
| 8735 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8736 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8737 | * @see #getPivotX() |
| 8738 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8739 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8740 | * @return The degrees of rotation. |
| 8741 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8742 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8743 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8744 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8745 | } |
| 8746 | |
| 8747 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8748 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 8749 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8750 | * |
| 8751 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8752 | * |
| 8753 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8754 | * @see #getPivotX() |
| 8755 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8756 | * @see #setRotationX(float) |
| 8757 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8758 | * |
| 8759 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8760 | */ |
| 8761 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8762 | ensureTransformationInfo(); |
| 8763 | final TransformationInfo info = mTransformationInfo; |
| 8764 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8765 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8766 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8767 | info.mRotation = rotation; |
| 8768 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8769 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8770 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8771 | mDisplayList.setRotation(rotation); |
| 8772 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8773 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8774 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8775 | invalidateParentIfNeeded(); |
| 8776 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8777 | } |
| 8778 | } |
| 8779 | |
| 8780 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8781 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 8782 | * |
| 8783 | * @see #getPivotX() |
| 8784 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8785 | * @see #setRotationY(float) |
| 8786 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8787 | * @return The degrees of Y rotation. |
| 8788 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8789 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8790 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8791 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8792 | } |
| 8793 | |
| 8794 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8795 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 8796 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 8797 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8798 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8799 | * When rotating large views, it is recommended to adjust the camera distance |
| 8800 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8801 | * |
| 8802 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8803 | * |
| 8804 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8805 | * @see #getPivotX() |
| 8806 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8807 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8808 | * @see #setRotationX(float) |
| 8809 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8810 | * |
| 8811 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8812 | */ |
| 8813 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8814 | ensureTransformationInfo(); |
| 8815 | final TransformationInfo info = mTransformationInfo; |
| 8816 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8817 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8818 | info.mRotationY = rotationY; |
| 8819 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8820 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8821 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8822 | mDisplayList.setRotationY(rotationY); |
| 8823 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8824 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8825 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8826 | invalidateParentIfNeeded(); |
| 8827 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8828 | } |
| 8829 | } |
| 8830 | |
| 8831 | /** |
| 8832 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8833 | * |
| 8834 | * @see #getPivotX() |
| 8835 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8836 | * @see #setRotationX(float) |
| 8837 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8838 | * @return The degrees of X rotation. |
| 8839 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8840 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8841 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8842 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8843 | } |
| 8844 | |
| 8845 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8846 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 8847 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 8848 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8849 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8850 | * When rotating large views, it is recommended to adjust the camera distance |
| 8851 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8852 | * |
| 8853 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8854 | * |
| 8855 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8856 | * @see #getPivotX() |
| 8857 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8858 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8859 | * @see #setRotationY(float) |
| 8860 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8861 | * |
| 8862 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8863 | */ |
| 8864 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8865 | ensureTransformationInfo(); |
| 8866 | final TransformationInfo info = mTransformationInfo; |
| 8867 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8868 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8869 | info.mRotationX = rotationX; |
| 8870 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8871 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8872 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8873 | mDisplayList.setRotationX(rotationX); |
| 8874 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8875 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8876 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8877 | invalidateParentIfNeeded(); |
| 8878 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8879 | } |
| 8880 | } |
| 8881 | |
| 8882 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8883 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 8884 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 8885 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8886 | * <p>By default, this is 1.0f. |
| 8887 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8888 | * @see #getPivotX() |
| 8889 | * @see #getPivotY() |
| 8890 | * @return The scaling factor. |
| 8891 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8892 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8893 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8894 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8895 | } |
| 8896 | |
| 8897 | /** |
| 8898 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 8899 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8900 | * |
| 8901 | * @param scaleX The scaling factor. |
| 8902 | * @see #getPivotX() |
| 8903 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8904 | * |
| 8905 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8906 | */ |
| 8907 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8908 | ensureTransformationInfo(); |
| 8909 | final TransformationInfo info = mTransformationInfo; |
| 8910 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8911 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8912 | info.mScaleX = scaleX; |
| 8913 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8914 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8915 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8916 | mDisplayList.setScaleX(scaleX); |
| 8917 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8918 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8919 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8920 | invalidateParentIfNeeded(); |
| 8921 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8922 | } |
| 8923 | } |
| 8924 | |
| 8925 | /** |
| 8926 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 8927 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 8928 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 8929 | * <p>By default, this is 1.0f. |
| 8930 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8931 | * @see #getPivotX() |
| 8932 | * @see #getPivotY() |
| 8933 | * @return The scaling factor. |
| 8934 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8935 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8936 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8937 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8938 | } |
| 8939 | |
| 8940 | /** |
| 8941 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 8942 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 8943 | * |
| 8944 | * @param scaleY The scaling factor. |
| 8945 | * @see #getPivotX() |
| 8946 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8947 | * |
| 8948 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8949 | */ |
| 8950 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8951 | ensureTransformationInfo(); |
| 8952 | final TransformationInfo info = mTransformationInfo; |
| 8953 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8954 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8955 | info.mScaleY = scaleY; |
| 8956 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 8957 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 8958 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8959 | mDisplayList.setScaleY(scaleY); |
| 8960 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8961 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 8962 | // View was rejected last time it was drawn by its parent; this may have changed |
| 8963 | invalidateParentIfNeeded(); |
| 8964 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8965 | } |
| 8966 | } |
| 8967 | |
| 8968 | /** |
| 8969 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 8970 | * and {@link #setScaleX(float) scaled}. |
| 8971 | * |
| 8972 | * @see #getRotation() |
| 8973 | * @see #getScaleX() |
| 8974 | * @see #getScaleY() |
| 8975 | * @see #getPivotY() |
| 8976 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8977 | * |
| 8978 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8979 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 8980 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8981 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8982 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8983 | } |
| 8984 | |
| 8985 | /** |
| 8986 | * Sets the x location of the point around which the view is |
| 8987 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8988 | * By default, the pivot point is centered on the object. |
| 8989 | * Setting this property disables this behavior and causes the view to use only the |
| 8990 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8991 | * |
| 8992 | * @param pivotX The x location of the pivot point. |
| 8993 | * @see #getRotation() |
| 8994 | * @see #getScaleX() |
| 8995 | * @see #getScaleY() |
| 8996 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 8997 | * |
| 8998 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8999 | */ |
| 9000 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9001 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9002 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9003 | final TransformationInfo info = mTransformationInfo; |
| 9004 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9005 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9006 | info.mPivotX = pivotX; |
| 9007 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9008 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9009 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9010 | mDisplayList.setPivotX(pivotX); |
| 9011 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9012 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9013 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9014 | invalidateParentIfNeeded(); |
| 9015 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | /** |
| 9020 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 9021 | * and {@link #setScaleY(float) scaled}. |
| 9022 | * |
| 9023 | * @see #getRotation() |
| 9024 | * @see #getScaleX() |
| 9025 | * @see #getScaleY() |
| 9026 | * @see #getPivotY() |
| 9027 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9028 | * |
| 9029 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9030 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9031 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9032 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9033 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9034 | } |
| 9035 | |
| 9036 | /** |
| 9037 | * 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] | 9038 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 9039 | * Setting this property disables this behavior and causes the view to use only the |
| 9040 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9041 | * |
| 9042 | * @param pivotY The y location of the pivot point. |
| 9043 | * @see #getRotation() |
| 9044 | * @see #getScaleX() |
| 9045 | * @see #getScaleY() |
| 9046 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9047 | * |
| 9048 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9049 | */ |
| 9050 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9051 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9052 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9053 | final TransformationInfo info = mTransformationInfo; |
| 9054 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9055 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9056 | info.mPivotY = pivotY; |
| 9057 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9058 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9059 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9060 | mDisplayList.setPivotY(pivotY); |
| 9061 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9062 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9063 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9064 | invalidateParentIfNeeded(); |
| 9065 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9066 | } |
| 9067 | } |
| 9068 | |
| 9069 | /** |
| 9070 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9071 | * completely transparent and 1 means the view is completely opaque. |
| 9072 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9073 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9074 | * @return The opacity of the view. |
| 9075 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9076 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9077 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9078 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9079 | } |
| 9080 | |
| 9081 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 9082 | * Returns whether this View has content which overlaps. This function, intended to be |
| 9083 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 9084 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 9085 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 9086 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 9087 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 9088 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 9089 | * an ImageView with only the foreground image. The default implementation returns true; |
| 9090 | * subclasses should override if they have cases which can be optimized. |
| 9091 | * |
| 9092 | * @return true if the content in this view might overlap, false otherwise. |
| 9093 | */ |
| 9094 | public boolean hasOverlappingRendering() { |
| 9095 | return true; |
| 9096 | } |
| 9097 | |
| 9098 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9099 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9100 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9101 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9102 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 9103 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 9104 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9105 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9106 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9107 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 9108 | * performance implications. It is generally best to use the alpha property sparingly and |
| 9109 | * transiently, as in the case of fading animations.</p> |
| 9110 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9111 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9112 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9113 | * @see #setLayerType(int, android.graphics.Paint) |
| 9114 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9115 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9116 | */ |
| 9117 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9118 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9119 | if (mTransformationInfo.mAlpha != alpha) { |
| 9120 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9121 | if (onSetAlpha((int) (alpha * 255))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9122 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9123 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9124 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9125 | invalidate(true); |
| 9126 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9127 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9128 | invalidateViewProperty(true, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9129 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9130 | mDisplayList.setAlpha(alpha); |
| 9131 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9132 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9133 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9134 | } |
| 9135 | |
| 9136 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9137 | * Faster version of setAlpha() which performs the same steps except there are |
| 9138 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 9139 | * on the parent and this object. The return value indicates whether the subclass handles |
| 9140 | * alpha (the return value for onSetAlpha()). |
| 9141 | * |
| 9142 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9143 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 9144 | * 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] | 9145 | */ |
| 9146 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9147 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9148 | if (mTransformationInfo.mAlpha != alpha) { |
| 9149 | mTransformationInfo.mAlpha = alpha; |
| 9150 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 9151 | if (subclassHandlesAlpha) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9152 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9153 | return true; |
| 9154 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9155 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9156 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9157 | mDisplayList.setAlpha(alpha); |
| 9158 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9159 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9160 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9161 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9162 | } |
| 9163 | |
| 9164 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9165 | * Top position of this view relative to its parent. |
| 9166 | * |
| 9167 | * @return The top of this view, in pixels. |
| 9168 | */ |
| 9169 | @ViewDebug.CapturedViewProperty |
| 9170 | public final int getTop() { |
| 9171 | return mTop; |
| 9172 | } |
| 9173 | |
| 9174 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9175 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 9176 | * by the layout system and should not generally be called otherwise, because the property |
| 9177 | * may be changed at any time by the layout. |
| 9178 | * |
| 9179 | * @param top The top of this view, in pixels. |
| 9180 | */ |
| 9181 | public final void setTop(int top) { |
| 9182 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9183 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9184 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9185 | || mTransformationInfo.mMatrixIsIdentity; |
| 9186 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9187 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9188 | int minTop; |
| 9189 | int yLoc; |
| 9190 | if (top < mTop) { |
| 9191 | minTop = top; |
| 9192 | yLoc = top - mTop; |
| 9193 | } else { |
| 9194 | minTop = mTop; |
| 9195 | yLoc = 0; |
| 9196 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9197 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9198 | } |
| 9199 | } else { |
| 9200 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9201 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9202 | } |
| 9203 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9204 | int width = mRight - mLeft; |
| 9205 | int oldHeight = mBottom - mTop; |
| 9206 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9207 | mTop = top; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9208 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9209 | mDisplayList.setTop(mTop); |
| 9210 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9211 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9212 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9213 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9214 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9215 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9216 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9217 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9218 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9219 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9220 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9221 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9222 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9223 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9224 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9225 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9226 | invalidateParentIfNeeded(); |
| 9227 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9228 | } |
| 9229 | } |
| 9230 | |
| 9231 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9232 | * Bottom position of this view relative to its parent. |
| 9233 | * |
| 9234 | * @return The bottom of this view, in pixels. |
| 9235 | */ |
| 9236 | @ViewDebug.CapturedViewProperty |
| 9237 | public final int getBottom() { |
| 9238 | return mBottom; |
| 9239 | } |
| 9240 | |
| 9241 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9242 | * True if this view has changed since the last time being drawn. |
| 9243 | * |
| 9244 | * @return The dirty state of this view. |
| 9245 | */ |
| 9246 | public boolean isDirty() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9247 | return (mPrivateFlags & PFLAG_DIRTY_MASK) != 0; |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9248 | } |
| 9249 | |
| 9250 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9251 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 9252 | * called by the layout system and should not generally be called otherwise, because the |
| 9253 | * property may be changed at any time by the layout. |
| 9254 | * |
| 9255 | * @param bottom The bottom of this view, in pixels. |
| 9256 | */ |
| 9257 | public final void setBottom(int bottom) { |
| 9258 | if (bottom != mBottom) { |
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 | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9263 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9264 | int maxBottom; |
| 9265 | if (bottom < mBottom) { |
| 9266 | maxBottom = mBottom; |
| 9267 | } else { |
| 9268 | maxBottom = bottom; |
| 9269 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9270 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9271 | } |
| 9272 | } else { |
| 9273 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9274 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9275 | } |
| 9276 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9277 | int width = mRight - mLeft; |
| 9278 | int oldHeight = mBottom - mTop; |
| 9279 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9280 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9281 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9282 | mDisplayList.setBottom(mBottom); |
| 9283 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9284 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9285 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9286 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9287 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9288 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9289 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9290 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9291 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9292 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9293 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9294 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9295 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9296 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9297 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9298 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9299 | invalidateParentIfNeeded(); |
| 9300 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9301 | } |
| 9302 | } |
| 9303 | |
| 9304 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | * Left position of this view relative to its parent. |
| 9306 | * |
| 9307 | * @return The left edge of this view, in pixels. |
| 9308 | */ |
| 9309 | @ViewDebug.CapturedViewProperty |
| 9310 | public final int getLeft() { |
| 9311 | return mLeft; |
| 9312 | } |
| 9313 | |
| 9314 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9315 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 9316 | * by the layout system and should not generally be called otherwise, because the property |
| 9317 | * may be changed at any time by the layout. |
| 9318 | * |
| 9319 | * @param left The bottom of this view, in pixels. |
| 9320 | */ |
| 9321 | public final void setLeft(int left) { |
| 9322 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9323 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9324 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9325 | || mTransformationInfo.mMatrixIsIdentity; |
| 9326 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9327 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9328 | int minLeft; |
| 9329 | int xLoc; |
| 9330 | if (left < mLeft) { |
| 9331 | minLeft = left; |
| 9332 | xLoc = left - mLeft; |
| 9333 | } else { |
| 9334 | minLeft = mLeft; |
| 9335 | xLoc = 0; |
| 9336 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9337 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9338 | } |
| 9339 | } else { |
| 9340 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9341 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9342 | } |
| 9343 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9344 | int oldWidth = mRight - mLeft; |
| 9345 | int height = mBottom - mTop; |
| 9346 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9347 | mLeft = left; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9348 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9349 | mDisplayList.setLeft(left); |
| 9350 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9351 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9352 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9353 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9354 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9355 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9356 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9357 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9358 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9359 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9360 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9361 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9362 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9363 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9364 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9365 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9366 | invalidateParentIfNeeded(); |
| 9367 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9368 | } |
| 9369 | } |
| 9370 | |
| 9371 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9372 | * Right position of this view relative to its parent. |
| 9373 | * |
| 9374 | * @return The right edge of this view, in pixels. |
| 9375 | */ |
| 9376 | @ViewDebug.CapturedViewProperty |
| 9377 | public final int getRight() { |
| 9378 | return mRight; |
| 9379 | } |
| 9380 | |
| 9381 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9382 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 9383 | * by the layout system and should not generally be called otherwise, because the property |
| 9384 | * may be changed at any time by the layout. |
| 9385 | * |
| 9386 | * @param right The bottom of this view, in pixels. |
| 9387 | */ |
| 9388 | public final void setRight(int right) { |
| 9389 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9390 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9391 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9392 | || mTransformationInfo.mMatrixIsIdentity; |
| 9393 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9394 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9395 | int maxRight; |
| 9396 | if (right < mRight) { |
| 9397 | maxRight = mRight; |
| 9398 | } else { |
| 9399 | maxRight = right; |
| 9400 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9401 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9402 | } |
| 9403 | } else { |
| 9404 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9405 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9406 | } |
| 9407 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9408 | int oldWidth = mRight - mLeft; |
| 9409 | int height = mBottom - mTop; |
| 9410 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9411 | mRight = right; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9412 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9413 | mDisplayList.setRight(mRight); |
| 9414 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9415 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9416 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9417 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9418 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9419 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9420 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9421 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9422 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9423 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9424 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9425 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9426 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9427 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9428 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9429 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9430 | invalidateParentIfNeeded(); |
| 9431 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9432 | } |
| 9433 | } |
| 9434 | |
| 9435 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9436 | * The visual x position of this view, in pixels. This is equivalent to the |
| 9437 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9438 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9439 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9440 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9441 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9442 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9443 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9444 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9445 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9446 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9447 | /** |
| 9448 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 9449 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 9450 | * the x value passed in and the current {@link #getLeft() left} property. |
| 9451 | * |
| 9452 | * @param x The visual x position of this view, in pixels. |
| 9453 | */ |
| 9454 | public void setX(float x) { |
| 9455 | setTranslationX(x - mLeft); |
| 9456 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9457 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9458 | /** |
| 9459 | * The visual y position of this view, in pixels. This is equivalent to the |
| 9460 | * {@link #setTranslationY(float) translationY} property plus the current |
| 9461 | * {@link #getTop() top} property. |
| 9462 | * |
| 9463 | * @return The visual y position of this view, in pixels. |
| 9464 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9465 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9466 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9467 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9468 | } |
| 9469 | |
| 9470 | /** |
| 9471 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 9472 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 9473 | * the y value passed in and the current {@link #getTop() top} property. |
| 9474 | * |
| 9475 | * @param y The visual y position of this view, in pixels. |
| 9476 | */ |
| 9477 | public void setY(float y) { |
| 9478 | setTranslationY(y - mTop); |
| 9479 | } |
| 9480 | |
| 9481 | |
| 9482 | /** |
| 9483 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9484 | * This position is post-layout, in addition to wherever the object's |
| 9485 | * layout placed it. |
| 9486 | * |
| 9487 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 9488 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9489 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9490 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9491 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9496 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9497 | * layout placed it. |
| 9498 | * |
| 9499 | * @param translationX The horizontal position of this view relative to its left position, |
| 9500 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9501 | * |
| 9502 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9503 | */ |
| 9504 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9505 | ensureTransformationInfo(); |
| 9506 | final TransformationInfo info = mTransformationInfo; |
| 9507 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9508 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9509 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9510 | info.mTranslationX = translationX; |
| 9511 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9512 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9513 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9514 | mDisplayList.setTranslationX(translationX); |
| 9515 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9516 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9517 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9518 | invalidateParentIfNeeded(); |
| 9519 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9520 | } |
| 9521 | } |
| 9522 | |
| 9523 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9524 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 9525 | * This position is post-layout, in addition to wherever the object's |
| 9526 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9527 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9528 | * @return The vertical position of this view relative to its top position, |
| 9529 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9530 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9531 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9532 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9533 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9534 | } |
| 9535 | |
| 9536 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9537 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9538 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9539 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9540 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9541 | * @param translationY The vertical position of this view relative to its top position, |
| 9542 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9543 | * |
| 9544 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9545 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9546 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9547 | ensureTransformationInfo(); |
| 9548 | final TransformationInfo info = mTransformationInfo; |
| 9549 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9550 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9551 | info.mTranslationY = translationY; |
| 9552 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9553 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9554 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9555 | mDisplayList.setTranslationY(translationY); |
| 9556 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9557 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9558 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9559 | invalidateParentIfNeeded(); |
| 9560 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9561 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9562 | } |
| 9563 | |
| 9564 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | * Hit rectangle in parent's coordinates |
| 9566 | * |
| 9567 | * @param outRect The hit rectangle of the view. |
| 9568 | */ |
| 9569 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9570 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9571 | final TransformationInfo info = mTransformationInfo; |
| 9572 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9573 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9574 | } else { |
| 9575 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9576 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9577 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9578 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9579 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9580 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9581 | } |
| 9582 | } |
| 9583 | |
| 9584 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9585 | * Determines whether the given point, in local coordinates is inside the view. |
| 9586 | */ |
| 9587 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9588 | return localX >= 0 && localX < (mRight - mLeft) |
| 9589 | && localY >= 0 && localY < (mBottom - mTop); |
| 9590 | } |
| 9591 | |
| 9592 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9593 | * Utility method to determine whether the given point, in local coordinates, |
| 9594 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9595 | * This method is called while processing touch-move events to determine if the event |
| 9596 | * is still within the view. |
| 9597 | */ |
| 9598 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9599 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9600 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9601 | } |
| 9602 | |
| 9603 | /** |
| 9604 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9605 | * starting from the rectangle filled in by this method. |
| 9606 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9607 | * By default, the rectange is the {@link #getDrawingRect(android.graphics.Rect)}) |
| 9608 | * of the view. However, if your view maintains some idea of internal selection, |
| 9609 | * such as a cursor, or a selected row or column, you should override this method and |
| 9610 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9611 | * |
| 9612 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9613 | */ |
| 9614 | public void getFocusedRect(Rect r) { |
| 9615 | getDrawingRect(r); |
| 9616 | } |
| 9617 | |
| 9618 | /** |
| 9619 | * If some part of this view is not clipped by any of its parents, then |
| 9620 | * 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] | 9621 | * coordinates (without taking possible View rotations into account), offset |
| 9622 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9623 | * 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] | 9624 | * |
| 9625 | * @param r If true is returned, r holds the global coordinates of the |
| 9626 | * visible portion of this view. |
| 9627 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9628 | * between this view and its root. globalOffet may be null. |
| 9629 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9630 | * root level. |
| 9631 | */ |
| 9632 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9633 | int width = mRight - mLeft; |
| 9634 | int height = mBottom - mTop; |
| 9635 | if (width > 0 && height > 0) { |
| 9636 | r.set(0, 0, width, height); |
| 9637 | if (globalOffset != null) { |
| 9638 | globalOffset.set(-mScrollX, -mScrollY); |
| 9639 | } |
| 9640 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9641 | } |
| 9642 | return false; |
| 9643 | } |
| 9644 | |
| 9645 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9646 | return getGlobalVisibleRect(r, null); |
| 9647 | } |
| 9648 | |
| 9649 | public final boolean getLocalVisibleRect(Rect r) { |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 9650 | final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9651 | if (getGlobalVisibleRect(r, offset)) { |
| 9652 | r.offset(-offset.x, -offset.y); // make r local |
| 9653 | return true; |
| 9654 | } |
| 9655 | return false; |
| 9656 | } |
| 9657 | |
| 9658 | /** |
| 9659 | * Offset this view's vertical location by the specified number of pixels. |
| 9660 | * |
| 9661 | * @param offset the number of pixels to offset the view by |
| 9662 | */ |
| 9663 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9664 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9665 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9666 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9667 | || mTransformationInfo.mMatrixIsIdentity; |
| 9668 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9669 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9670 | invalidateViewProperty(false, false); |
| 9671 | } else { |
| 9672 | final ViewParent p = mParent; |
| 9673 | if (p != null && mAttachInfo != null) { |
| 9674 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9675 | int minTop; |
| 9676 | int maxBottom; |
| 9677 | int yLoc; |
| 9678 | if (offset < 0) { |
| 9679 | minTop = mTop + offset; |
| 9680 | maxBottom = mBottom; |
| 9681 | yLoc = offset; |
| 9682 | } else { |
| 9683 | minTop = mTop; |
| 9684 | maxBottom = mBottom + offset; |
| 9685 | yLoc = 0; |
| 9686 | } |
| 9687 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9688 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9689 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9690 | } |
| 9691 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9692 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9693 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9694 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9695 | mTop += offset; |
| 9696 | mBottom += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9697 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9698 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9699 | invalidateViewProperty(false, false); |
| 9700 | } else { |
| 9701 | if (!matrixIsIdentity) { |
| 9702 | invalidateViewProperty(false, true); |
| 9703 | } |
| 9704 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9705 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9707 | } |
| 9708 | |
| 9709 | /** |
| 9710 | * Offset this view's horizontal location by the specified amount of pixels. |
| 9711 | * |
| 9712 | * @param offset the numer of pixels to offset the view by |
| 9713 | */ |
| 9714 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9715 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9716 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9717 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9718 | || mTransformationInfo.mMatrixIsIdentity; |
| 9719 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9720 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9721 | invalidateViewProperty(false, false); |
| 9722 | } else { |
| 9723 | final ViewParent p = mParent; |
| 9724 | if (p != null && mAttachInfo != null) { |
| 9725 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9726 | int minLeft; |
| 9727 | int maxRight; |
| 9728 | if (offset < 0) { |
| 9729 | minLeft = mLeft + offset; |
| 9730 | maxRight = mRight; |
| 9731 | } else { |
| 9732 | minLeft = mLeft; |
| 9733 | maxRight = mRight + offset; |
| 9734 | } |
| 9735 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 9736 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9737 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9738 | } |
| 9739 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9740 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9741 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9742 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9743 | mLeft += offset; |
| 9744 | mRight += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9745 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9746 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9747 | invalidateViewProperty(false, false); |
| 9748 | } else { |
| 9749 | if (!matrixIsIdentity) { |
| 9750 | invalidateViewProperty(false, true); |
| 9751 | } |
| 9752 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9753 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9754 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * Get the LayoutParams associated with this view. All views should have |
| 9759 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 9760 | * view specifying how it should be arranged. There are many subclasses of |
| 9761 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 9762 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9763 | * |
| 9764 | * This method may return null if this View is not attached to a parent |
| 9765 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 9766 | * was not invoked successfully. When a View is attached to a parent |
| 9767 | * ViewGroup, this method must not return null. |
| 9768 | * |
| 9769 | * @return The LayoutParams associated with this view, or null if no |
| 9770 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 9772 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9773 | public ViewGroup.LayoutParams getLayoutParams() { |
| 9774 | return mLayoutParams; |
| 9775 | } |
| 9776 | |
| 9777 | /** |
| 9778 | * Set the layout parameters associated with this view. These supply |
| 9779 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 9780 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 9781 | * correspond to the different subclasses of ViewGroup that are responsible |
| 9782 | * for arranging their children. |
| 9783 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9784 | * @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] | 9785 | */ |
| 9786 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 9787 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 9788 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9789 | } |
| 9790 | mLayoutParams = params; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 9791 | resolveLayoutParams(); |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 9792 | if (mParent instanceof ViewGroup) { |
| 9793 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 9794 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | requestLayout(); |
| 9796 | } |
| 9797 | |
| 9798 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 9799 | * Resolve the layout parameters depending on the resolved layout direction |
| 9800 | */ |
| 9801 | private void resolveLayoutParams() { |
| 9802 | if (mLayoutParams != null) { |
| 9803 | mLayoutParams.onResolveLayoutDirection(getResolvedLayoutDirection()); |
| 9804 | } |
| 9805 | } |
| 9806 | |
| 9807 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | * Set the scrolled position of your view. This will cause a call to |
| 9809 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9810 | * invalidated. |
| 9811 | * @param x the x position to scroll to |
| 9812 | * @param y the y position to scroll to |
| 9813 | */ |
| 9814 | public void scrollTo(int x, int y) { |
| 9815 | if (mScrollX != x || mScrollY != y) { |
| 9816 | int oldX = mScrollX; |
| 9817 | int oldY = mScrollY; |
| 9818 | mScrollX = x; |
| 9819 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9820 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9821 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9822 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9823 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9824 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | } |
| 9826 | } |
| 9827 | |
| 9828 | /** |
| 9829 | * Move the scrolled position of your view. This will cause a call to |
| 9830 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 9831 | * invalidated. |
| 9832 | * @param x the amount of pixels to scroll by horizontally |
| 9833 | * @param y the amount of pixels to scroll by vertically |
| 9834 | */ |
| 9835 | public void scrollBy(int x, int y) { |
| 9836 | scrollTo(mScrollX + x, mScrollY + y); |
| 9837 | } |
| 9838 | |
| 9839 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9840 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 9841 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 9842 | * provides animated scrolling, the start delay should equal the duration |
| 9843 | * of the scrolling animation.</p> |
| 9844 | * |
| 9845 | * <p>The animation starts only if at least one of the scrollbars is |
| 9846 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9847 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9848 | * this method returns true, and false otherwise. If the animation is |
| 9849 | * started, this method calls {@link #invalidate()}; in that case the |
| 9850 | * caller should not call {@link #invalidate()}.</p> |
| 9851 | * |
| 9852 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9853 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9854 | * |
| 9855 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 9856 | * and {@link #scrollTo(int, int)}.</p> |
| 9857 | * |
| 9858 | * @return true if the animation is played, false otherwise |
| 9859 | * |
| 9860 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9861 | * @see #scrollBy(int, int) |
| 9862 | * @see #scrollTo(int, int) |
| 9863 | * @see #isHorizontalScrollBarEnabled() |
| 9864 | * @see #isVerticalScrollBarEnabled() |
| 9865 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9866 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9867 | */ |
| 9868 | protected boolean awakenScrollBars() { |
| 9869 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9870 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9871 | } |
| 9872 | |
| 9873 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 9874 | * Trigger the scrollbars to draw. |
| 9875 | * This method differs from awakenScrollBars() only in its default duration. |
| 9876 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 9877 | * usual to give the user more of a chance to notice them. |
| 9878 | * |
| 9879 | * @return true if the animation is played, false otherwise. |
| 9880 | */ |
| 9881 | private boolean initialAwakenScrollBars() { |
| 9882 | return mScrollCache != null && |
| 9883 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 9884 | } |
| 9885 | |
| 9886 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9887 | * <p> |
| 9888 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9889 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9890 | * provides animated scrolling, the start delay should equal the duration of |
| 9891 | * the scrolling animation. |
| 9892 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9893 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9894 | * <p> |
| 9895 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9896 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9897 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9898 | * this method returns true, and false otherwise. If the animation is |
| 9899 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 9900 | * should not call {@link #invalidate()}. |
| 9901 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9902 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9903 | * <p> |
| 9904 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 9905 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9906 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9907 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9908 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9909 | * should start; when the delay is 0, the animation starts |
| 9910 | * immediately |
| 9911 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9912 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9913 | * @see #scrollBy(int, int) |
| 9914 | * @see #scrollTo(int, int) |
| 9915 | * @see #isHorizontalScrollBarEnabled() |
| 9916 | * @see #isVerticalScrollBarEnabled() |
| 9917 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9918 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9919 | */ |
| 9920 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9921 | return awakenScrollBars(startDelay, true); |
| 9922 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9923 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9924 | /** |
| 9925 | * <p> |
| 9926 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 9927 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 9928 | * provides animated scrolling, the start delay should equal the duration of |
| 9929 | * the scrolling animation. |
| 9930 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9931 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9932 | * <p> |
| 9933 | * The animation starts only if at least one of the scrollbars is enabled, |
| 9934 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 9935 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 9936 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9937 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9938 | * is set to true; in that case the caller |
| 9939 | * should not call {@link #invalidate()}. |
| 9940 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9941 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9942 | * <p> |
| 9943 | * This method should be invoked everytime a subclass directly updates the |
| 9944 | * scroll parameters. |
| 9945 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9946 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9947 | * @param startDelay the delay, in milliseconds, after which the animation |
| 9948 | * should start; when the delay is 0, the animation starts |
| 9949 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9950 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9951 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9952 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9953 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9954 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9955 | * @see #scrollBy(int, int) |
| 9956 | * @see #scrollTo(int, int) |
| 9957 | * @see #isHorizontalScrollBarEnabled() |
| 9958 | * @see #isVerticalScrollBarEnabled() |
| 9959 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 9960 | * @see #setVerticalScrollBarEnabled(boolean) |
| 9961 | */ |
| 9962 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9963 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9964 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9965 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 9966 | return false; |
| 9967 | } |
| 9968 | |
| 9969 | if (scrollCache.scrollBar == null) { |
| 9970 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 9971 | } |
| 9972 | |
| 9973 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 9974 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9975 | if (invalidate) { |
| 9976 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 9977 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 9978 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9979 | |
| 9980 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 9981 | // FIXME: this is copied from WindowManagerService. |
| 9982 | // We should get this value from the system when it |
| 9983 | // is possible to do so. |
| 9984 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 9985 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 9986 | } |
| 9987 | |
| 9988 | // Tell mScrollCache when we should start fading. This may |
| 9989 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 9990 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 9991 | scrollCache.fadeStartTime = fadeStartTime; |
| 9992 | scrollCache.state = ScrollabilityCache.ON; |
| 9993 | |
| 9994 | // Schedule our fader to run, unscheduling any old ones first |
| 9995 | if (mAttachInfo != null) { |
| 9996 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 9997 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 9998 | } |
| 9999 | |
| 10000 | return true; |
| 10001 | } |
| 10002 | |
| 10003 | return false; |
| 10004 | } |
| 10005 | |
| 10006 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10007 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 10008 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 10009 | */ |
| 10010 | private boolean skipInvalidate() { |
| 10011 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 10012 | (!(mParent instanceof ViewGroup) || |
| 10013 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 10014 | } |
| 10015 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10016 | * 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] | 10017 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 10018 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 10019 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10020 | * |
| 10021 | * WARNING: This method is destructive to dirty. |
| 10022 | * @param dirty the rectangle representing the bounds of the dirty region |
| 10023 | */ |
| 10024 | public void invalidate(Rect dirty) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10025 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10026 | return; |
| 10027 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10028 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10029 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10030 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10031 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10032 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10033 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10034 | final ViewParent p = mParent; |
| 10035 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10036 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10037 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10038 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10039 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10040 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10041 | p.invalidateChild(this, null); |
| 10042 | return; |
| 10043 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 10044 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10045 | if (p != null && ai != null) { |
| 10046 | final int scrollX = mScrollX; |
| 10047 | final int scrollY = mScrollY; |
| 10048 | final Rect r = ai.mTmpInvalRect; |
| 10049 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 10050 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 10051 | mParent.invalidateChild(this, r); |
| 10052 | } |
| 10053 | } |
| 10054 | } |
| 10055 | |
| 10056 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10057 | * 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] | 10058 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10059 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 10060 | * will be called at some point in the future. This must be called from |
| 10061 | * 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] | 10062 | * @param l the left position of the dirty region |
| 10063 | * @param t the top position of the dirty region |
| 10064 | * @param r the right position of the dirty region |
| 10065 | * @param b the bottom position of the dirty region |
| 10066 | */ |
| 10067 | public void invalidate(int l, int t, int r, int b) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10068 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10069 | return; |
| 10070 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10071 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10072 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10073 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10074 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10075 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10076 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10077 | final ViewParent p = mParent; |
| 10078 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10079 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10080 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10081 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10082 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10083 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10084 | p.invalidateChild(this, null); |
| 10085 | return; |
| 10086 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10087 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10088 | if (p != null && ai != null && l < r && t < b) { |
| 10089 | final int scrollX = mScrollX; |
| 10090 | final int scrollY = mScrollY; |
| 10091 | final Rect tmpr = ai.mTmpInvalRect; |
| 10092 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 10093 | p.invalidateChild(this, tmpr); |
| 10094 | } |
| 10095 | } |
| 10096 | } |
| 10097 | |
| 10098 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10099 | * Invalidate the whole view. If the view is visible, |
| 10100 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 10101 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 10102 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | */ |
| 10104 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10105 | invalidate(true); |
| 10106 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10107 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10108 | /** |
| 10109 | * This is where the invalidate() work actually happens. A full invalidate() |
| 10110 | * causes the drawing cache to be invalidated, but this function can be called with |
| 10111 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 10112 | * need it (for example, a component that remains at the same dimensions with the same |
| 10113 | * content). |
| 10114 | * |
| 10115 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 10116 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 10117 | * View's contents or dimensions have not changed. |
| 10118 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 10119 | void invalidate(boolean invalidateCache) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10120 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10121 | return; |
| 10122 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10123 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10124 | (invalidateCache && (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) || |
| 10125 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED || isOpaque() != mLastIsOpaque) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10126 | mLastIsOpaque = isOpaque(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10127 | mPrivateFlags &= ~PFLAG_DRAWN; |
| 10128 | mPrivateFlags |= PFLAG_DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10129 | if (invalidateCache) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10130 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10131 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10132 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 10134 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10135 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10136 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10137 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10138 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10139 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10140 | p.invalidateChild(this, null); |
| 10141 | return; |
| 10142 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10143 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 10144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10145 | if (p != null && ai != null) { |
| 10146 | final Rect r = ai.mTmpInvalRect; |
| 10147 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10148 | // Don't call invalidate -- we don't want to internally scroll |
| 10149 | // our own bounds |
| 10150 | p.invalidateChild(this, r); |
| 10151 | } |
| 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10156 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 10157 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 10158 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 10159 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 10160 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 10161 | * |
| 10162 | * The method also handles normal invalidation logic if display list properties are not |
| 10163 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 10164 | * backup approach, to handle these cases used in the various property-setting methods. |
| 10165 | * |
| 10166 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 10167 | * are not being used in this view |
| 10168 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 10169 | * list properties are not being used in this view |
| 10170 | */ |
| 10171 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10172 | if (mDisplayList == null || (mPrivateFlags & PFLAG_DRAW_ANIMATION) == PFLAG_DRAW_ANIMATION) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10173 | if (invalidateParent) { |
| 10174 | invalidateParentCaches(); |
| 10175 | } |
| 10176 | if (forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10177 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10178 | } |
| 10179 | invalidate(false); |
| 10180 | } else { |
| 10181 | final AttachInfo ai = mAttachInfo; |
| 10182 | final ViewParent p = mParent; |
| 10183 | if (p != null && ai != null) { |
| 10184 | final Rect r = ai.mTmpInvalRect; |
| 10185 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10186 | if (mParent instanceof ViewGroup) { |
| 10187 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 10188 | } else { |
| 10189 | mParent.invalidateChild(this, r); |
| 10190 | } |
| 10191 | } |
| 10192 | } |
| 10193 | } |
| 10194 | |
| 10195 | /** |
| 10196 | * Utility method to transform a given Rect by the current matrix of this view. |
| 10197 | */ |
| 10198 | void transformRect(final Rect rect) { |
| 10199 | if (!getMatrix().isIdentity()) { |
| 10200 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 10201 | boundingRect.set(rect); |
| 10202 | getMatrix().mapRect(boundingRect); |
| 10203 | rect.set((int) (boundingRect.left - 0.5f), |
| 10204 | (int) (boundingRect.top - 0.5f), |
| 10205 | (int) (boundingRect.right + 0.5f), |
| 10206 | (int) (boundingRect.bottom + 0.5f)); |
| 10207 | } |
| 10208 | } |
| 10209 | |
| 10210 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10211 | * 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] | 10212 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10213 | * 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] | 10214 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 10215 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10216 | * |
| 10217 | * @hide |
| 10218 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10219 | protected void invalidateParentCaches() { |
| 10220 | if (mParent instanceof View) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10221 | ((View) mParent).mPrivateFlags |= PFLAG_INVALIDATED; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10222 | } |
| 10223 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10224 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10225 | /** |
| 10226 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 10227 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10228 | * which is necessary when various parent-managed properties of the view change, such as |
| 10229 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 10230 | * an invalidation event to the parent. |
| 10231 | * |
| 10232 | * @hide |
| 10233 | */ |
| 10234 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10235 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10236 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10237 | } |
| 10238 | } |
| 10239 | |
| 10240 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10241 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 10242 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 10243 | * |
| 10244 | * Subclasses of View should override this method whenever possible to indicate |
| 10245 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 10246 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 10247 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10248 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10249 | * @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] | 10250 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10251 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10252 | public boolean isOpaque() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10253 | return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK && |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 10254 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1.0f) >= 1.0f); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10255 | } |
| 10256 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10257 | /** |
| 10258 | * @hide |
| 10259 | */ |
| 10260 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10261 | // Opaque if: |
| 10262 | // - Has a background |
| 10263 | // - Background is opaque |
| 10264 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 10265 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10266 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10267 | mPrivateFlags |= PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10268 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10269 | mPrivateFlags &= ~PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10270 | } |
| 10271 | |
| 10272 | final int flags = mViewFlags; |
| 10273 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 10274 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10275 | mPrivateFlags |= PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10276 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10277 | mPrivateFlags &= ~PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10278 | } |
| 10279 | } |
| 10280 | |
| 10281 | /** |
| 10282 | * @hide |
| 10283 | */ |
| 10284 | protected boolean hasOpaqueScrollbars() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10285 | return (mPrivateFlags & PFLAG_OPAQUE_SCROLLBARS) == PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10286 | } |
| 10287 | |
| 10288 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10289 | * @return A handler associated with the thread running the View. This |
| 10290 | * handler can be used to pump events in the UI events queue. |
| 10291 | */ |
| 10292 | public Handler getHandler() { |
| 10293 | if (mAttachInfo != null) { |
| 10294 | return mAttachInfo.mHandler; |
| 10295 | } |
| 10296 | return null; |
| 10297 | } |
| 10298 | |
| 10299 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10300 | * Gets the view root associated with the View. |
| 10301 | * @return The view root, or null if none. |
| 10302 | * @hide |
| 10303 | */ |
| 10304 | public ViewRootImpl getViewRootImpl() { |
| 10305 | if (mAttachInfo != null) { |
| 10306 | return mAttachInfo.mViewRootImpl; |
| 10307 | } |
| 10308 | return null; |
| 10309 | } |
| 10310 | |
| 10311 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10312 | * <p>Causes the Runnable to be added to the message queue. |
| 10313 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10314 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10315 | * <p>This method can be invoked from outside of the UI thread |
| 10316 | * 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] | 10317 | * |
| 10318 | * @param action The Runnable that will be executed. |
| 10319 | * |
| 10320 | * @return Returns true if the Runnable was successfully placed in to the |
| 10321 | * message queue. Returns false on failure, usually because the |
| 10322 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10323 | * |
| 10324 | * @see #postDelayed |
| 10325 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10326 | */ |
| 10327 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10328 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10329 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10330 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10331 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10332 | // Assume that post will succeed later |
| 10333 | ViewRootImpl.getRunQueue().post(action); |
| 10334 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10335 | } |
| 10336 | |
| 10337 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10338 | * <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] | 10339 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10340 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10341 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10342 | * <p>This method can be invoked from outside of the UI thread |
| 10343 | * 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] | 10344 | * |
| 10345 | * @param action The Runnable that will be executed. |
| 10346 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10347 | * will be executed. |
| 10348 | * |
| 10349 | * @return true if the Runnable was successfully placed in to the |
| 10350 | * message queue. Returns false on failure, usually because the |
| 10351 | * looper processing the message queue is exiting. Note that a |
| 10352 | * result of true does not mean the Runnable will be processed -- |
| 10353 | * if the looper is quit before the delivery time of the message |
| 10354 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10355 | * |
| 10356 | * @see #post |
| 10357 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10358 | */ |
| 10359 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10360 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10361 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10362 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10363 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10364 | // Assume that post will succeed later |
| 10365 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10366 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10367 | } |
| 10368 | |
| 10369 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10370 | * <p>Causes the Runnable to execute on the next animation time step. |
| 10371 | * The runnable will be run on the user interface thread.</p> |
| 10372 | * |
| 10373 | * <p>This method can be invoked from outside of the UI thread |
| 10374 | * only when this View is attached to a window.</p> |
| 10375 | * |
| 10376 | * @param action The Runnable that will be executed. |
| 10377 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10378 | * @see #postOnAnimationDelayed |
| 10379 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10380 | */ |
| 10381 | public void postOnAnimation(Runnable action) { |
| 10382 | final AttachInfo attachInfo = mAttachInfo; |
| 10383 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10384 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 10385 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10386 | } else { |
| 10387 | // Assume that post will succeed later |
| 10388 | ViewRootImpl.getRunQueue().post(action); |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | /** |
| 10393 | * <p>Causes the Runnable to execute on the next animation time step, |
| 10394 | * after the specified amount of time elapses. |
| 10395 | * The runnable will be run on the user interface thread.</p> |
| 10396 | * |
| 10397 | * <p>This method can be invoked from outside of the UI thread |
| 10398 | * only when this View is attached to a window.</p> |
| 10399 | * |
| 10400 | * @param action The Runnable that will be executed. |
| 10401 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10402 | * will be executed. |
| 10403 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10404 | * @see #postOnAnimation |
| 10405 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10406 | */ |
| 10407 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 10408 | final AttachInfo attachInfo = mAttachInfo; |
| 10409 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10410 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 10411 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10412 | } else { |
| 10413 | // Assume that post will succeed later |
| 10414 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10415 | } |
| 10416 | } |
| 10417 | |
| 10418 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10419 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10420 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10421 | * <p>This method can be invoked from outside of the UI thread |
| 10422 | * 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] | 10423 | * |
| 10424 | * @param action The Runnable to remove from the message handling queue |
| 10425 | * |
| 10426 | * @return true if this view could ask the Handler to remove the Runnable, |
| 10427 | * false otherwise. When the returned value is true, the Runnable |
| 10428 | * may or may not have been actually removed from the message queue |
| 10429 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10430 | * |
| 10431 | * @see #post |
| 10432 | * @see #postDelayed |
| 10433 | * @see #postOnAnimation |
| 10434 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | */ |
| 10436 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10437 | if (action != null) { |
| 10438 | final AttachInfo attachInfo = mAttachInfo; |
| 10439 | if (attachInfo != null) { |
| 10440 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10441 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 10442 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10443 | } else { |
| 10444 | // Assume that post will succeed later |
| 10445 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 10446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10448 | return true; |
| 10449 | } |
| 10450 | |
| 10451 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10452 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 10453 | * 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] | 10454 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10455 | * <p>This method can be invoked from outside of the UI thread |
| 10456 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10457 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10458 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10459 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10460 | */ |
| 10461 | public void postInvalidate() { |
| 10462 | postInvalidateDelayed(0); |
| 10463 | } |
| 10464 | |
| 10465 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10466 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10467 | * 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] | 10468 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10469 | * <p>This method can be invoked from outside of the UI thread |
| 10470 | * 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] | 10471 | * |
| 10472 | * @param left The left coordinate of the rectangle to invalidate. |
| 10473 | * @param top The top coordinate of the rectangle to invalidate. |
| 10474 | * @param right The right coordinate of the rectangle to invalidate. |
| 10475 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10476 | * |
| 10477 | * @see #invalidate(int, int, int, int) |
| 10478 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10479 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10480 | */ |
| 10481 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 10482 | postInvalidateDelayed(0, left, top, right, bottom); |
| 10483 | } |
| 10484 | |
| 10485 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10486 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 10487 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10488 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10489 | * <p>This method can be invoked from outside of the UI thread |
| 10490 | * 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] | 10491 | * |
| 10492 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10493 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10494 | * |
| 10495 | * @see #invalidate() |
| 10496 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | */ |
| 10498 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 10499 | // We try only with the AttachInfo because there's no point in invalidating |
| 10500 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10501 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10502 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10503 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | } |
| 10505 | } |
| 10506 | |
| 10507 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10508 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10509 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10510 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10511 | * <p>This method can be invoked from outside of the UI thread |
| 10512 | * 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] | 10513 | * |
| 10514 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10515 | * invalidation by |
| 10516 | * @param left The left coordinate of the rectangle to invalidate. |
| 10517 | * @param top The top coordinate of the rectangle to invalidate. |
| 10518 | * @param right The right coordinate of the rectangle to invalidate. |
| 10519 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10520 | * |
| 10521 | * @see #invalidate(int, int, int, int) |
| 10522 | * @see #invalidate(Rect) |
| 10523 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10524 | */ |
| 10525 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 10526 | int right, int bottom) { |
| 10527 | |
| 10528 | // We try only with the AttachInfo because there's no point in invalidating |
| 10529 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10530 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10531 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10532 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10533 | info.target = this; |
| 10534 | info.left = left; |
| 10535 | info.top = top; |
| 10536 | info.right = right; |
| 10537 | info.bottom = bottom; |
| 10538 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10539 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10540 | } |
| 10541 | } |
| 10542 | |
| 10543 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10544 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10545 | * next display frame.</p> |
| 10546 | * |
| 10547 | * <p>This method can be invoked from outside of the UI thread |
| 10548 | * only when this View is attached to a window.</p> |
| 10549 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10550 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10551 | */ |
| 10552 | public void postInvalidateOnAnimation() { |
| 10553 | // We try only with the AttachInfo because there's no point in invalidating |
| 10554 | // if we are not attached to our window |
| 10555 | final AttachInfo attachInfo = mAttachInfo; |
| 10556 | if (attachInfo != null) { |
| 10557 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10558 | } |
| 10559 | } |
| 10560 | |
| 10561 | /** |
| 10562 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10563 | * time step, typically the next display frame.</p> |
| 10564 | * |
| 10565 | * <p>This method can be invoked from outside of the UI thread |
| 10566 | * only when this View is attached to a window.</p> |
| 10567 | * |
| 10568 | * @param left The left coordinate of the rectangle to invalidate. |
| 10569 | * @param top The top coordinate of the rectangle to invalidate. |
| 10570 | * @param right The right coordinate of the rectangle to invalidate. |
| 10571 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10572 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10573 | * @see #invalidate(int, int, int, int) |
| 10574 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10575 | */ |
| 10576 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10577 | // We try only with the AttachInfo because there's no point in invalidating |
| 10578 | // if we are not attached to our window |
| 10579 | final AttachInfo attachInfo = mAttachInfo; |
| 10580 | if (attachInfo != null) { |
| 10581 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.acquire(); |
| 10582 | info.target = this; |
| 10583 | info.left = left; |
| 10584 | info.top = top; |
| 10585 | info.right = right; |
| 10586 | info.bottom = bottom; |
| 10587 | |
| 10588 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10589 | } |
| 10590 | } |
| 10591 | |
| 10592 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10593 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10594 | * This event is sent at most once every |
| 10595 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10596 | */ |
| 10597 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10598 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10599 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10600 | } |
| 10601 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10602 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10603 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10604 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10605 | } |
| 10606 | } |
| 10607 | |
| 10608 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10609 | * Called by a parent to request that a child update its values for mScrollX |
| 10610 | * and mScrollY if necessary. This will typically be done if the child is |
| 10611 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10612 | * object. |
| 10613 | */ |
| 10614 | public void computeScroll() { |
| 10615 | } |
| 10616 | |
| 10617 | /** |
| 10618 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10619 | * scrolled horizontally.</p> |
| 10620 | * |
| 10621 | * @return true if the horizontal edges should are faded on scroll, false |
| 10622 | * otherwise |
| 10623 | * |
| 10624 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10625 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10626 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | */ |
| 10628 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10629 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10630 | } |
| 10631 | |
| 10632 | /** |
| 10633 | * <p>Define whether the horizontal edges should be faded when this view |
| 10634 | * is scrolled horizontally.</p> |
| 10635 | * |
| 10636 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10637 | * be faded when the view is scrolled |
| 10638 | * horizontally |
| 10639 | * |
| 10640 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10641 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10642 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | */ |
| 10644 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10645 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10646 | if (horizontalFadingEdgeEnabled) { |
| 10647 | initScrollCache(); |
| 10648 | } |
| 10649 | |
| 10650 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10651 | } |
| 10652 | } |
| 10653 | |
| 10654 | /** |
| 10655 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10656 | * scrolled horizontally.</p> |
| 10657 | * |
| 10658 | * @return true if the vertical edges should are faded on scroll, false |
| 10659 | * otherwise |
| 10660 | * |
| 10661 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10662 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10663 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | */ |
| 10665 | public boolean isVerticalFadingEdgeEnabled() { |
| 10666 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10667 | } |
| 10668 | |
| 10669 | /** |
| 10670 | * <p>Define whether the vertical edges should be faded when this view |
| 10671 | * is scrolled vertically.</p> |
| 10672 | * |
| 10673 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10674 | * be faded when the view is scrolled |
| 10675 | * vertically |
| 10676 | * |
| 10677 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10678 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10679 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10680 | */ |
| 10681 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10682 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10683 | if (verticalFadingEdgeEnabled) { |
| 10684 | initScrollCache(); |
| 10685 | } |
| 10686 | |
| 10687 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10688 | } |
| 10689 | } |
| 10690 | |
| 10691 | /** |
| 10692 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10693 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10694 | * returns 0.0 or 1.0 but no value in between. |
| 10695 | * |
| 10696 | * Subclasses should override this method to provide a smoother fade transition |
| 10697 | * when scrolling occurs. |
| 10698 | * |
| 10699 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10700 | */ |
| 10701 | protected float getTopFadingEdgeStrength() { |
| 10702 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10703 | } |
| 10704 | |
| 10705 | /** |
| 10706 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 10707 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10708 | * returns 0.0 or 1.0 but no value in between. |
| 10709 | * |
| 10710 | * Subclasses should override this method to provide a smoother fade transition |
| 10711 | * when scrolling occurs. |
| 10712 | * |
| 10713 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 10714 | */ |
| 10715 | protected float getBottomFadingEdgeStrength() { |
| 10716 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 10717 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 10718 | } |
| 10719 | |
| 10720 | /** |
| 10721 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 10722 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10723 | * returns 0.0 or 1.0 but no value in between. |
| 10724 | * |
| 10725 | * Subclasses should override this method to provide a smoother fade transition |
| 10726 | * when scrolling occurs. |
| 10727 | * |
| 10728 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 10729 | */ |
| 10730 | protected float getLeftFadingEdgeStrength() { |
| 10731 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 10732 | } |
| 10733 | |
| 10734 | /** |
| 10735 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 10736 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10737 | * returns 0.0 or 1.0 but no value in between. |
| 10738 | * |
| 10739 | * Subclasses should override this method to provide a smoother fade transition |
| 10740 | * when scrolling occurs. |
| 10741 | * |
| 10742 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 10743 | */ |
| 10744 | protected float getRightFadingEdgeStrength() { |
| 10745 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 10746 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 10747 | } |
| 10748 | |
| 10749 | /** |
| 10750 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 10751 | * scrollbar is not drawn by default.</p> |
| 10752 | * |
| 10753 | * @return true if the horizontal scrollbar should be painted, false |
| 10754 | * otherwise |
| 10755 | * |
| 10756 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10757 | */ |
| 10758 | public boolean isHorizontalScrollBarEnabled() { |
| 10759 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 10760 | } |
| 10761 | |
| 10762 | /** |
| 10763 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 10764 | * scrollbar is not drawn by default.</p> |
| 10765 | * |
| 10766 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 10767 | * be painted |
| 10768 | * |
| 10769 | * @see #isHorizontalScrollBarEnabled() |
| 10770 | */ |
| 10771 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 10772 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 10773 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10774 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10775 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10776 | } |
| 10777 | } |
| 10778 | |
| 10779 | /** |
| 10780 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 10781 | * scrollbar is not drawn by default.</p> |
| 10782 | * |
| 10783 | * @return true if the vertical scrollbar should be painted, false |
| 10784 | * otherwise |
| 10785 | * |
| 10786 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10787 | */ |
| 10788 | public boolean isVerticalScrollBarEnabled() { |
| 10789 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 10790 | } |
| 10791 | |
| 10792 | /** |
| 10793 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 10794 | * scrollbar is not drawn by default.</p> |
| 10795 | * |
| 10796 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 10797 | * be painted |
| 10798 | * |
| 10799 | * @see #isVerticalScrollBarEnabled() |
| 10800 | */ |
| 10801 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 10802 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 10803 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10804 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10805 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10806 | } |
| 10807 | } |
| 10808 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10809 | /** |
| 10810 | * @hide |
| 10811 | */ |
| 10812 | protected void recomputePadding() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 10813 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10815 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10816 | /** |
| 10817 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10818 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10819 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10820 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10821 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10822 | */ |
| 10823 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 10824 | initScrollCache(); |
| 10825 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 10826 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10827 | if (fadeScrollbars) { |
| 10828 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 10829 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10830 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 10831 | } |
| 10832 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10834 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10835 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10836 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10837 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10838 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10839 | * |
| 10840 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10841 | */ |
| 10842 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10843 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10844 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10845 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 10846 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10847 | * |
| 10848 | * Returns the delay before scrollbars fade. |
| 10849 | * |
| 10850 | * @return the delay before scrollbars fade |
| 10851 | * |
| 10852 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10853 | */ |
| 10854 | public int getScrollBarDefaultDelayBeforeFade() { |
| 10855 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 10856 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 10857 | } |
| 10858 | |
| 10859 | /** |
| 10860 | * Define the delay before scrollbars fade. |
| 10861 | * |
| 10862 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 10863 | * |
| 10864 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 10865 | */ |
| 10866 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 10867 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 10868 | } |
| 10869 | |
| 10870 | /** |
| 10871 | * |
| 10872 | * Returns the scrollbar fade duration. |
| 10873 | * |
| 10874 | * @return the scrollbar fade duration |
| 10875 | * |
| 10876 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10877 | */ |
| 10878 | public int getScrollBarFadeDuration() { |
| 10879 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 10880 | mScrollCache.scrollBarFadeDuration; |
| 10881 | } |
| 10882 | |
| 10883 | /** |
| 10884 | * Define the scrollbar fade duration. |
| 10885 | * |
| 10886 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 10887 | * |
| 10888 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 10889 | */ |
| 10890 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 10891 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 10892 | } |
| 10893 | |
| 10894 | /** |
| 10895 | * |
| 10896 | * Returns the scrollbar size. |
| 10897 | * |
| 10898 | * @return the scrollbar size |
| 10899 | * |
| 10900 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10901 | */ |
| 10902 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 10903 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10904 | mScrollCache.scrollBarSize; |
| 10905 | } |
| 10906 | |
| 10907 | /** |
| 10908 | * Define the scrollbar size. |
| 10909 | * |
| 10910 | * @param scrollBarSize - the scrollbar size |
| 10911 | * |
| 10912 | * @attr ref android.R.styleable#View_scrollbarSize |
| 10913 | */ |
| 10914 | public void setScrollBarSize(int scrollBarSize) { |
| 10915 | getScrollCache().scrollBarSize = scrollBarSize; |
| 10916 | } |
| 10917 | |
| 10918 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10919 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 10920 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 10921 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 10922 | * if a view has a background drawable and you want to draw the scrollbars |
| 10923 | * inside the padding specified by the drawable, you can use |
| 10924 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 10925 | * appear at the edge of the view, ignoring the padding, then you can use |
| 10926 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 10927 | * @param style the style of the scrollbars. Should be one of |
| 10928 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 10929 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 10930 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10931 | * @see #SCROLLBARS_INSIDE_INSET |
| 10932 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10933 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10934 | * |
| 10935 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10936 | */ |
| 10937 | public void setScrollBarStyle(int style) { |
| 10938 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 10939 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10940 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 10941 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | } |
| 10943 | } |
| 10944 | |
| 10945 | /** |
| 10946 | * <p>Returns the current scrollbar style.</p> |
| 10947 | * @return the current scrollbar style |
| 10948 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 10949 | * @see #SCROLLBARS_INSIDE_INSET |
| 10950 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 10951 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10952 | * |
| 10953 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10954 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 10955 | @ViewDebug.ExportedProperty(mapping = { |
| 10956 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 10957 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 10958 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 10959 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 10960 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10961 | public int getScrollBarStyle() { |
| 10962 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 10963 | } |
| 10964 | |
| 10965 | /** |
| 10966 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 10967 | * represents.</p> |
| 10968 | * |
| 10969 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10970 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 10971 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 10972 | * |
| 10973 | * <p>The default range is the drawing width of this view.</p> |
| 10974 | * |
| 10975 | * @return the total horizontal range represented by the horizontal |
| 10976 | * scrollbar |
| 10977 | * |
| 10978 | * @see #computeHorizontalScrollExtent() |
| 10979 | * @see #computeHorizontalScrollOffset() |
| 10980 | * @see android.widget.ScrollBarDrawable |
| 10981 | */ |
| 10982 | protected int computeHorizontalScrollRange() { |
| 10983 | return getWidth(); |
| 10984 | } |
| 10985 | |
| 10986 | /** |
| 10987 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 10988 | * within the horizontal range. This value is used to compute the position |
| 10989 | * of the thumb within the scrollbar's track.</p> |
| 10990 | * |
| 10991 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 10992 | * units used by {@link #computeHorizontalScrollRange()} and |
| 10993 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 10994 | * |
| 10995 | * <p>The default offset is the scroll offset of this view.</p> |
| 10996 | * |
| 10997 | * @return the horizontal offset of the scrollbar's thumb |
| 10998 | * |
| 10999 | * @see #computeHorizontalScrollRange() |
| 11000 | * @see #computeHorizontalScrollExtent() |
| 11001 | * @see android.widget.ScrollBarDrawable |
| 11002 | */ |
| 11003 | protected int computeHorizontalScrollOffset() { |
| 11004 | return mScrollX; |
| 11005 | } |
| 11006 | |
| 11007 | /** |
| 11008 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 11009 | * within the horizontal range. This value is used to compute the length |
| 11010 | * of the thumb within the scrollbar's track.</p> |
| 11011 | * |
| 11012 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11013 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11014 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11015 | * |
| 11016 | * <p>The default extent is the drawing width of this view.</p> |
| 11017 | * |
| 11018 | * @return the horizontal extent of the scrollbar's thumb |
| 11019 | * |
| 11020 | * @see #computeHorizontalScrollRange() |
| 11021 | * @see #computeHorizontalScrollOffset() |
| 11022 | * @see android.widget.ScrollBarDrawable |
| 11023 | */ |
| 11024 | protected int computeHorizontalScrollExtent() { |
| 11025 | return getWidth(); |
| 11026 | } |
| 11027 | |
| 11028 | /** |
| 11029 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 11030 | * |
| 11031 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11032 | * units used by {@link #computeVerticalScrollExtent()} and |
| 11033 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11034 | * |
| 11035 | * @return the total vertical range represented by the vertical scrollbar |
| 11036 | * |
| 11037 | * <p>The default range is the drawing height of this view.</p> |
| 11038 | * |
| 11039 | * @see #computeVerticalScrollExtent() |
| 11040 | * @see #computeVerticalScrollOffset() |
| 11041 | * @see android.widget.ScrollBarDrawable |
| 11042 | */ |
| 11043 | protected int computeVerticalScrollRange() { |
| 11044 | return getHeight(); |
| 11045 | } |
| 11046 | |
| 11047 | /** |
| 11048 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 11049 | * within the horizontal range. This value is used to compute the position |
| 11050 | * of the thumb within the scrollbar's track.</p> |
| 11051 | * |
| 11052 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11053 | * units used by {@link #computeVerticalScrollRange()} and |
| 11054 | * {@link #computeVerticalScrollExtent()}.</p> |
| 11055 | * |
| 11056 | * <p>The default offset is the scroll offset of this view.</p> |
| 11057 | * |
| 11058 | * @return the vertical offset of the scrollbar's thumb |
| 11059 | * |
| 11060 | * @see #computeVerticalScrollRange() |
| 11061 | * @see #computeVerticalScrollExtent() |
| 11062 | * @see android.widget.ScrollBarDrawable |
| 11063 | */ |
| 11064 | protected int computeVerticalScrollOffset() { |
| 11065 | return mScrollY; |
| 11066 | } |
| 11067 | |
| 11068 | /** |
| 11069 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 11070 | * within the vertical range. This value is used to compute the length |
| 11071 | * of the thumb within the scrollbar's track.</p> |
| 11072 | * |
| 11073 | * <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] | 11074 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11075 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11076 | * |
| 11077 | * <p>The default extent is the drawing height of this view.</p> |
| 11078 | * |
| 11079 | * @return the vertical extent of the scrollbar's thumb |
| 11080 | * |
| 11081 | * @see #computeVerticalScrollRange() |
| 11082 | * @see #computeVerticalScrollOffset() |
| 11083 | * @see android.widget.ScrollBarDrawable |
| 11084 | */ |
| 11085 | protected int computeVerticalScrollExtent() { |
| 11086 | return getHeight(); |
| 11087 | } |
| 11088 | |
| 11089 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 11090 | * Check if this view can be scrolled horizontally in a certain direction. |
| 11091 | * |
| 11092 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 11093 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11094 | */ |
| 11095 | public boolean canScrollHorizontally(int direction) { |
| 11096 | final int offset = computeHorizontalScrollOffset(); |
| 11097 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 11098 | if (range == 0) return false; |
| 11099 | if (direction < 0) { |
| 11100 | return offset > 0; |
| 11101 | } else { |
| 11102 | return offset < range - 1; |
| 11103 | } |
| 11104 | } |
| 11105 | |
| 11106 | /** |
| 11107 | * Check if this view can be scrolled vertically in a certain direction. |
| 11108 | * |
| 11109 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 11110 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11111 | */ |
| 11112 | public boolean canScrollVertically(int direction) { |
| 11113 | final int offset = computeVerticalScrollOffset(); |
| 11114 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 11115 | if (range == 0) return false; |
| 11116 | if (direction < 0) { |
| 11117 | return offset > 0; |
| 11118 | } else { |
| 11119 | return offset < range - 1; |
| 11120 | } |
| 11121 | } |
| 11122 | |
| 11123 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11124 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 11125 | * scrollbars are painted only if they have been awakened first.</p> |
| 11126 | * |
| 11127 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11128 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11129 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11130 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 11131 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11132 | // scrollbars are drawn only when the animation is running |
| 11133 | final ScrollabilityCache cache = mScrollCache; |
| 11134 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11135 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11136 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11137 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11138 | if (state == ScrollabilityCache.OFF) { |
| 11139 | return; |
| 11140 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11141 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11142 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11143 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11144 | if (state == ScrollabilityCache.FADING) { |
| 11145 | // We're fading -- get our fade interpolation |
| 11146 | if (cache.interpolatorValues == null) { |
| 11147 | cache.interpolatorValues = new float[1]; |
| 11148 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11149 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11150 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11151 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11152 | // Stops the animation if we're done |
| 11153 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 11154 | Interpolator.Result.FREEZE_END) { |
| 11155 | cache.state = ScrollabilityCache.OFF; |
| 11156 | } else { |
| 11157 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 11158 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11159 | |
| 11160 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11161 | // drawing. We only want this when we're fading so that |
| 11162 | // we prevent excessive redraws |
| 11163 | invalidate = true; |
| 11164 | } else { |
| 11165 | // We're just on -- but we may have been fading before so |
| 11166 | // reset alpha |
| 11167 | cache.scrollBar.setAlpha(255); |
| 11168 | } |
| 11169 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11171 | final int viewFlags = mViewFlags; |
| 11172 | |
| 11173 | final boolean drawHorizontalScrollBar = |
| 11174 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 11175 | final boolean drawVerticalScrollBar = |
| 11176 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 11177 | && !isVerticalScrollBarHidden(); |
| 11178 | |
| 11179 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 11180 | final int width = mRight - mLeft; |
| 11181 | final int height = mBottom - mTop; |
| 11182 | |
| 11183 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11184 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11185 | final int scrollX = mScrollX; |
| 11186 | final int scrollY = mScrollY; |
| 11187 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 11188 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11189 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11191 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11192 | int size = scrollBar.getSize(false); |
| 11193 | if (size <= 0) { |
| 11194 | size = cache.scrollBarSize; |
| 11195 | } |
| 11196 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11197 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11198 | computeHorizontalScrollOffset(), |
| 11199 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11200 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11201 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11202 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11203 | left = scrollX + (mPaddingLeft & inside); |
| 11204 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 11205 | bottom = top + size; |
| 11206 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11207 | if (invalidate) { |
| 11208 | invalidate(left, top, right, bottom); |
| 11209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11210 | } |
| 11211 | |
| 11212 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11213 | int size = scrollBar.getSize(true); |
| 11214 | if (size <= 0) { |
| 11215 | size = cache.scrollBarSize; |
| 11216 | } |
| 11217 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11218 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 11219 | computeVerticalScrollOffset(), |
| 11220 | computeVerticalScrollExtent(), true); |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 11221 | int verticalScrollbarPosition = mVerticalScrollbarPosition; |
| 11222 | if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) { |
| 11223 | verticalScrollbarPosition = isLayoutRtl() ? |
| 11224 | SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT; |
| 11225 | } |
| 11226 | switch (verticalScrollbarPosition) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11227 | default: |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11228 | case SCROLLBAR_POSITION_RIGHT: |
| 11229 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 11230 | break; |
| 11231 | case SCROLLBAR_POSITION_LEFT: |
| 11232 | left = scrollX + (mUserPaddingLeft & inside); |
| 11233 | break; |
| 11234 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11235 | top = scrollY + (mPaddingTop & inside); |
| 11236 | right = left + size; |
| 11237 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 11238 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11239 | if (invalidate) { |
| 11240 | invalidate(left, top, right, bottom); |
| 11241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11242 | } |
| 11243 | } |
| 11244 | } |
| 11245 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11247 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11248 | * 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] | 11249 | * FastScroller is visible. |
| 11250 | * @return whether to temporarily hide the vertical scrollbar |
| 11251 | * @hide |
| 11252 | */ |
| 11253 | protected boolean isVerticalScrollBarHidden() { |
| 11254 | return false; |
| 11255 | } |
| 11256 | |
| 11257 | /** |
| 11258 | * <p>Draw the horizontal scrollbar if |
| 11259 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 11260 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11261 | * @param canvas the canvas on which to draw the scrollbar |
| 11262 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11263 | * |
| 11264 | * @see #isHorizontalScrollBarEnabled() |
| 11265 | * @see #computeHorizontalScrollRange() |
| 11266 | * @see #computeHorizontalScrollExtent() |
| 11267 | * @see #computeHorizontalScrollOffset() |
| 11268 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11269 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11270 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11271 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11272 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11273 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11274 | scrollBar.draw(canvas); |
| 11275 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11276 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11277 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11278 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 11279 | * returns true.</p> |
| 11280 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11281 | * @param canvas the canvas on which to draw the scrollbar |
| 11282 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11283 | * |
| 11284 | * @see #isVerticalScrollBarEnabled() |
| 11285 | * @see #computeVerticalScrollRange() |
| 11286 | * @see #computeVerticalScrollExtent() |
| 11287 | * @see #computeVerticalScrollOffset() |
| 11288 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11289 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11290 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11291 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11292 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11293 | scrollBar.setBounds(l, t, r, b); |
| 11294 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11295 | } |
| 11296 | |
| 11297 | /** |
| 11298 | * Implement this to do your drawing. |
| 11299 | * |
| 11300 | * @param canvas the canvas on which the background will be drawn |
| 11301 | */ |
| 11302 | protected void onDraw(Canvas canvas) { |
| 11303 | } |
| 11304 | |
| 11305 | /* |
| 11306 | * Caller is responsible for calling requestLayout if necessary. |
| 11307 | * (This allows addViewInLayout to not request a new layout.) |
| 11308 | */ |
| 11309 | void assignParent(ViewParent parent) { |
| 11310 | if (mParent == null) { |
| 11311 | mParent = parent; |
| 11312 | } else if (parent == null) { |
| 11313 | mParent = null; |
| 11314 | } else { |
| 11315 | throw new RuntimeException("view " + this + " being added, but" |
| 11316 | + " it already has a parent"); |
| 11317 | } |
| 11318 | } |
| 11319 | |
| 11320 | /** |
| 11321 | * This is called when the view is attached to a window. At this point it |
| 11322 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11323 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 11324 | * however it may be called any time before the first onDraw -- including |
| 11325 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11326 | * |
| 11327 | * @see #onDetachedFromWindow() |
| 11328 | */ |
| 11329 | protected void onAttachedToWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11330 | if ((mPrivateFlags & PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11331 | mParent.requestTransparentRegion(this); |
| 11332 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11333 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11334 | if ((mPrivateFlags & PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11335 | initialAwakenScrollBars(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11336 | mPrivateFlags &= ~PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11337 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11338 | |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 11339 | jumpDrawablesToCurrentState(); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11340 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11341 | resolveRtlProperties(); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11342 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11343 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 11344 | if (isFocused()) { |
| 11345 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 11346 | imm.focusIn(this); |
| 11347 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11348 | |
| 11349 | if (mAttachInfo != null && mDisplayList != null) { |
| 11350 | mAttachInfo.mViewRootImpl.dequeueDisplayList(mDisplayList); |
| 11351 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11352 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 11353 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11354 | void resolveRtlProperties() { |
| 11355 | // Order is important here: LayoutDirection MUST be resolved first... |
| 11356 | resolveLayoutDirection(); |
| 11357 | // ... then we can resolve the others properties depending on the resolved LayoutDirection. |
| 11358 | resolvePadding(); |
| 11359 | resolveLayoutParams(); |
| 11360 | resolveTextDirection(); |
| 11361 | resolveTextAlignment(); |
| 11362 | } |
| 11363 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11364 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 11365 | * @see #onScreenStateChanged(int) |
| 11366 | */ |
| 11367 | void dispatchScreenStateChanged(int screenState) { |
| 11368 | onScreenStateChanged(screenState); |
| 11369 | } |
| 11370 | |
| 11371 | /** |
| 11372 | * This method is called whenever the state of the screen this view is |
| 11373 | * attached to changes. A state change will usually occurs when the screen |
| 11374 | * turns on or off (whether it happens automatically or the user does it |
| 11375 | * manually.) |
| 11376 | * |
| 11377 | * @param screenState The new state of the screen. Can be either |
| 11378 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 11379 | */ |
| 11380 | public void onScreenStateChanged(int screenState) { |
| 11381 | } |
| 11382 | |
| 11383 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11384 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 11385 | */ |
| 11386 | private boolean hasRtlSupport() { |
| 11387 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 11388 | } |
| 11389 | |
| 11390 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11391 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 11392 | * 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] | 11393 | * Will call {@link View#onResolvedLayoutDirectionChanged} when resolution is done. |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11394 | */ |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11395 | public void resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11396 | // Clear any previous layout direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11397 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11398 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11399 | if (hasRtlSupport()) { |
| 11400 | // Set resolved depending on layout direction |
| 11401 | switch (getLayoutDirection()) { |
| 11402 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11403 | // We cannot resolve yet. LTR is by default and let the resolution happen again |
| 11404 | // later to get the correct resolved value |
| 11405 | if (!canResolveLayoutDirection()) return; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11406 | |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11407 | ViewGroup viewGroup = ((ViewGroup) mParent); |
| 11408 | |
| 11409 | // We cannot resolve yet on the parent too. LTR is by default and let the |
| 11410 | // resolution happen again later |
| 11411 | if (!viewGroup.canResolveLayoutDirection()) return; |
| 11412 | |
| 11413 | if (viewGroup.getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11414 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11415 | } |
| 11416 | break; |
| 11417 | case LAYOUT_DIRECTION_RTL: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11418 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11419 | break; |
| 11420 | case LAYOUT_DIRECTION_LOCALE: |
| 11421 | if(isLayoutDirectionRtl(Locale.getDefault())) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11422 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11423 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11424 | break; |
| 11425 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11426 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11427 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11428 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11429 | |
| 11430 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11431 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11432 | onResolvedLayoutDirectionChanged(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11433 | } |
| 11434 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11435 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11436 | * Called when layout direction has been resolved. |
| 11437 | * |
| 11438 | * The default implementation does nothing. |
| 11439 | */ |
| 11440 | public void onResolvedLayoutDirectionChanged() { |
| 11441 | } |
| 11442 | |
| 11443 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11444 | * Return if padding has been resolved |
| 11445 | */ |
| 11446 | boolean isPaddingResolved() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11447 | return (mPrivateFlags2 & PFLAG2_PADDING_RESOLVED) != 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11448 | } |
| 11449 | |
| 11450 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11451 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11452 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11453 | public void resolvePadding() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11454 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 11455 | if (targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport()) { |
| 11456 | // Pre Jelly Bean MR1 case (compatibility mode) OR no RTL support case: |
| 11457 | // left / right padding are used if defined. If they are not defined and start / end |
| 11458 | // padding are defined (e.g. in Frameworks resources), then we use start / end and |
| 11459 | // resolve them as left / right (layout direction is not taken into account). |
| 11460 | if (!mUserPaddingLeftDefined && mUserPaddingStart != UNDEFINED_PADDING) { |
| 11461 | mUserPaddingLeft = mUserPaddingStart; |
| 11462 | } |
| 11463 | if (!mUserPaddingRightDefined && mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11464 | mUserPaddingRight = mUserPaddingEnd; |
| 11465 | } |
| 11466 | |
| 11467 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11468 | |
| 11469 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, |
| 11470 | mUserPaddingBottom); |
| 11471 | } else { |
| 11472 | // Post Jelly Bean MR1 case: we need to take the resolved layout direction into account. |
| 11473 | // If start / end padding are defined, they will be resolved (hence overriding) to |
| 11474 | // left / right or right / left depending on the resolved layout direction. |
| 11475 | // If start / end padding are not defined, use the left / right ones. |
| 11476 | int resolvedLayoutDirection = getResolvedLayoutDirection(); |
| 11477 | switch (resolvedLayoutDirection) { |
| 11478 | case LAYOUT_DIRECTION_RTL: |
| 11479 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11480 | mUserPaddingRight = mUserPaddingStart; |
| 11481 | } |
| 11482 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11483 | mUserPaddingLeft = mUserPaddingEnd; |
| 11484 | } |
| 11485 | break; |
| 11486 | case LAYOUT_DIRECTION_LTR: |
| 11487 | default: |
| 11488 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11489 | mUserPaddingLeft = mUserPaddingStart; |
| 11490 | } |
| 11491 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11492 | mUserPaddingRight = mUserPaddingEnd; |
| 11493 | } |
| 11494 | } |
| 11495 | |
| 11496 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11497 | |
| 11498 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, |
| 11499 | mUserPaddingBottom); |
| 11500 | onPaddingChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11501 | } |
| 11502 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11503 | mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11504 | } |
| 11505 | |
| 11506 | /** |
| 11507 | * Resolve padding depending on the layout direction. Subclasses that care about |
| 11508 | * padding resolution should override this method. The default implementation does |
| 11509 | * nothing. |
| 11510 | * |
| 11511 | * @param layoutDirection the direction of the layout |
| 11512 | * |
Fabrice Di Meglio | e8dc07d | 2012-03-09 17:10:19 -0800 | [diff] [blame] | 11513 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 11514 | * @see {@link #LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11515 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11516 | public void onPaddingChanged(int layoutDirection) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11517 | } |
| 11518 | |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11519 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11520 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11521 | * |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11522 | * @return true if layout direction resolution can be done otherwise return false. |
Fabrice Di Meglio | 2273b1e | 2011-09-07 15:17:40 -0700 | [diff] [blame] | 11523 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11524 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11525 | switch (getLayoutDirection()) { |
| 11526 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11527 | return (mParent != null) && (mParent instanceof ViewGroup); |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11528 | default: |
| 11529 | return true; |
| 11530 | } |
| 11531 | } |
| 11532 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11533 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11534 | * Reset the resolved layout direction. Will call {@link View#onResolvedLayoutDirectionReset} |
| 11535 | * when reset is done. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11536 | */ |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11537 | public void resetResolvedLayoutDirection() { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 11538 | // Reset the current resolved bits |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11539 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11540 | onResolvedLayoutDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 11541 | // Reset also the text direction |
| 11542 | resetResolvedTextDirection(); |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11543 | } |
| 11544 | |
| 11545 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11546 | * Called during reset of resolved layout direction. |
| 11547 | * |
| 11548 | * Subclasses need to override this method to clear cached information that depends on the |
| 11549 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 11550 | * |
| 11551 | * The default implementation does nothing. |
| 11552 | */ |
| 11553 | public void onResolvedLayoutDirectionReset() { |
| 11554 | } |
| 11555 | |
| 11556 | /** |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11557 | * Check if a Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11558 | * |
| 11559 | * @param locale Locale to check |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 11560 | * @return true if the Locale uses an RTL script. |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11561 | */ |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 11562 | protected static boolean isLayoutDirectionRtl(Locale locale) { |
Fabrice Di Meglio | 3fb824b | 2012-02-28 17:58:31 -0800 | [diff] [blame] | 11563 | return (LAYOUT_DIRECTION_RTL == LocaleUtil.getLayoutDirectionFromLocale(locale)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11564 | } |
| 11565 | |
| 11566 | /** |
| 11567 | * This is called when the view is detached from a window. At this point it |
| 11568 | * no longer has a surface for drawing. |
| 11569 | * |
| 11570 | * @see #onAttachedToWindow() |
| 11571 | */ |
| 11572 | protected void onDetachedFromWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11573 | mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11574 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11575 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11576 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11577 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11578 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11581 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11582 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11583 | |
| 11584 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11585 | if (mDisplayList != null) { |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11586 | mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11587 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11588 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11589 | } else { |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 11590 | // Should never happen |
| 11591 | clearDisplayList(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11592 | } |
| 11593 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11594 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11595 | |
| 11596 | resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 11597 | resetResolvedTextAlignment(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11598 | resetAccessibilityStateChanged(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11599 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11600 | } |
| 11601 | |
| 11602 | /** |
| 11603 | * @return The number of times this view has been attached to a window |
| 11604 | */ |
| 11605 | protected int getWindowAttachCount() { |
| 11606 | return mWindowAttachCount; |
| 11607 | } |
| 11608 | |
| 11609 | /** |
| 11610 | * Retrieve a unique token identifying the window this view is attached to. |
| 11611 | * @return Return the window's token for use in |
| 11612 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11613 | */ |
| 11614 | public IBinder getWindowToken() { |
| 11615 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11616 | } |
| 11617 | |
| 11618 | /** |
| 11619 | * Retrieve a unique token identifying the top-level "real" window of |
| 11620 | * the window that this view is attached to. That is, this is like |
| 11621 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11622 | * window (attached to another containing window), then the token of |
| 11623 | * the containing window is returned instead. |
| 11624 | * |
| 11625 | * @return Returns the associated window token, either |
| 11626 | * {@link #getWindowToken()} or the containing window's token. |
| 11627 | */ |
| 11628 | public IBinder getApplicationWindowToken() { |
| 11629 | AttachInfo ai = mAttachInfo; |
| 11630 | if (ai != null) { |
| 11631 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11632 | if (appWindowToken == null) { |
| 11633 | appWindowToken = ai.mWindowToken; |
| 11634 | } |
| 11635 | return appWindowToken; |
| 11636 | } |
| 11637 | return null; |
| 11638 | } |
| 11639 | |
| 11640 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 11641 | * Gets the logical display to which the view's window has been attached. |
| 11642 | * |
| 11643 | * @return The logical display, or null if the view is not currently attached to a window. |
| 11644 | */ |
| 11645 | public Display getDisplay() { |
| 11646 | return mAttachInfo != null ? mAttachInfo.mDisplay : null; |
| 11647 | } |
| 11648 | |
| 11649 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11650 | * Retrieve private session object this view hierarchy is using to |
| 11651 | * communicate with the window manager. |
| 11652 | * @return the session object to communicate with the window manager |
| 11653 | */ |
| 11654 | /*package*/ IWindowSession getWindowSession() { |
| 11655 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11656 | } |
| 11657 | |
| 11658 | /** |
| 11659 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11660 | * this view |
| 11661 | */ |
| 11662 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 11663 | //System.out.println("Attached! " + this); |
| 11664 | mAttachInfo = info; |
| 11665 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11666 | // We will need to evaluate the drawable state at least once. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11667 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11668 | if (mFloatingTreeObserver != null) { |
| 11669 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 11670 | mFloatingTreeObserver = null; |
| 11671 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11672 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11673 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11674 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11675 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 11676 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11677 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11678 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11679 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11680 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11681 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11682 | if (listeners != null && listeners.size() > 0) { |
| 11683 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11684 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11685 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11686 | // the array from being modified while we iterate it. |
| 11687 | for (OnAttachStateChangeListener listener : listeners) { |
| 11688 | listener.onViewAttachedToWindow(this); |
| 11689 | } |
| 11690 | } |
| 11691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11692 | int vis = info.mWindowVisibility; |
| 11693 | if (vis != GONE) { |
| 11694 | onWindowVisibilityChanged(vis); |
| 11695 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11696 | if ((mPrivateFlags&PFLAG_DRAWABLE_STATE_DIRTY) != 0) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 11697 | // If nobody has evaluated the drawable state yet, then do it now. |
| 11698 | refreshDrawableState(); |
| 11699 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11700 | } |
| 11701 | |
| 11702 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11703 | AttachInfo info = mAttachInfo; |
| 11704 | if (info != null) { |
| 11705 | int vis = info.mWindowVisibility; |
| 11706 | if (vis != GONE) { |
| 11707 | onWindowVisibilityChanged(GONE); |
| 11708 | } |
| 11709 | } |
| 11710 | |
| 11711 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11712 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11713 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11714 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 11715 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 11716 | if (listeners != null && listeners.size() > 0) { |
| 11717 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 11718 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 11719 | // could mutate the list by calling the various add/remove methods. This prevents |
| 11720 | // the array from being modified while we iterate it. |
| 11721 | for (OnAttachStateChangeListener listener : listeners) { |
| 11722 | listener.onViewDetachedFromWindow(this); |
| 11723 | } |
| 11724 | } |
| 11725 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11726 | if ((mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11727 | mAttachInfo.mScrollContainers.remove(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11728 | mPrivateFlags &= ~PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11729 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 11730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11731 | mAttachInfo = null; |
| 11732 | } |
| 11733 | |
| 11734 | /** |
| 11735 | * Store this view hierarchy's frozen state into the given container. |
| 11736 | * |
| 11737 | * @param container The SparseArray in which to save the view's state. |
| 11738 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11739 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11740 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11741 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11742 | */ |
| 11743 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 11744 | dispatchSaveInstanceState(container); |
| 11745 | } |
| 11746 | |
| 11747 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11748 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 11749 | * this view and its children. May be overridden to modify how freezing happens to a |
| 11750 | * 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] | 11751 | * |
| 11752 | * @param container The SparseArray in which to save the view's state. |
| 11753 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11754 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11755 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11756 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11757 | */ |
| 11758 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 11759 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11760 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11761 | Parcelable state = onSaveInstanceState(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11762 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11763 | throw new IllegalStateException( |
| 11764 | "Derived class did not call super.onSaveInstanceState()"); |
| 11765 | } |
| 11766 | if (state != null) { |
| 11767 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 11768 | // + ": " + state); |
| 11769 | container.put(mID, state); |
| 11770 | } |
| 11771 | } |
| 11772 | } |
| 11773 | |
| 11774 | /** |
| 11775 | * Hook allowing a view to generate a representation of its internal state |
| 11776 | * that can later be used to create a new instance with that same state. |
| 11777 | * This state should only contain information that is not persistent or can |
| 11778 | * not be reconstructed later. For example, you will never store your |
| 11779 | * current position on screen because that will be computed again when a |
| 11780 | * new instance of the view is placed in its view hierarchy. |
| 11781 | * <p> |
| 11782 | * Some examples of things you may store here: the current cursor position |
| 11783 | * in a text view (but usually not the text itself since that is stored in a |
| 11784 | * content provider or other persistent storage), the currently selected |
| 11785 | * item in a list view. |
| 11786 | * |
| 11787 | * @return Returns a Parcelable object containing the view's current dynamic |
| 11788 | * state, or null if there is nothing interesting to save. The |
| 11789 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11790 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 11791 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11792 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11793 | * @see #setSaveEnabled(boolean) |
| 11794 | */ |
| 11795 | protected Parcelable onSaveInstanceState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11796 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11797 | return BaseSavedState.EMPTY_STATE; |
| 11798 | } |
| 11799 | |
| 11800 | /** |
| 11801 | * Restore this view hierarchy's frozen state from the given container. |
| 11802 | * |
| 11803 | * @param container The SparseArray which holds previously frozen states. |
| 11804 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11805 | * @see #saveHierarchyState(android.util.SparseArray) |
| 11806 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 11807 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11808 | */ |
| 11809 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 11810 | dispatchRestoreInstanceState(container); |
| 11811 | } |
| 11812 | |
| 11813 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11814 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 11815 | * state for this view and its children. May be overridden to modify how restoring |
| 11816 | * happens to a view's children; for example, some views may want to not store state |
| 11817 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11818 | * |
| 11819 | * @param container The SparseArray which holds previously saved state. |
| 11820 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11821 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 11822 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11823 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11824 | */ |
| 11825 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 11826 | if (mID != NO_ID) { |
| 11827 | Parcelable state = container.get(mID); |
| 11828 | if (state != null) { |
| 11829 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 11830 | // + ": " + state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11831 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11832 | onRestoreInstanceState(state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11833 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11834 | throw new IllegalStateException( |
| 11835 | "Derived class did not call super.onRestoreInstanceState()"); |
| 11836 | } |
| 11837 | } |
| 11838 | } |
| 11839 | } |
| 11840 | |
| 11841 | /** |
| 11842 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 11843 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 11844 | * null state. |
| 11845 | * |
| 11846 | * @param state The frozen state that had previously been returned by |
| 11847 | * {@link #onSaveInstanceState}. |
| 11848 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11849 | * @see #onSaveInstanceState() |
| 11850 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 11851 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11852 | */ |
| 11853 | protected void onRestoreInstanceState(Parcelable state) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11854 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11855 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11856 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 11857 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11858 | + "when two views of different type have the same id in the same hierarchy. " |
| 11859 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 11860 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11861 | } |
| 11862 | } |
| 11863 | |
| 11864 | /** |
| 11865 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 11866 | * |
| 11867 | * @return the drawing start time in milliseconds |
| 11868 | */ |
| 11869 | public long getDrawingTime() { |
| 11870 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 11871 | } |
| 11872 | |
| 11873 | /** |
| 11874 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 11875 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 11876 | * than from its own internal properties.</p> |
| 11877 | * |
| 11878 | * <p>Note: in the current implementation, setting this property to true after the |
| 11879 | * view was added to a ViewGroup might have no effect at all. This property should |
| 11880 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 11881 | * |
| 11882 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 11883 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11884 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 11885 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 11886 | * 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] | 11887 | * |
| 11888 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 11889 | * to disable it. |
| 11890 | * |
| 11891 | * @see #getDrawableState() |
| 11892 | * @see #isDuplicateParentStateEnabled() |
| 11893 | */ |
| 11894 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 11895 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 11896 | } |
| 11897 | |
| 11898 | /** |
| 11899 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 11900 | * |
| 11901 | * @return True if this view's drawable state is duplicated from the parent, |
| 11902 | * false otherwise |
| 11903 | * |
| 11904 | * @see #getDrawableState() |
| 11905 | * @see #setDuplicateParentStateEnabled(boolean) |
| 11906 | */ |
| 11907 | public boolean isDuplicateParentStateEnabled() { |
| 11908 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 11909 | } |
| 11910 | |
| 11911 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11912 | * <p>Specifies the type of layer backing this view. The layer can be |
| 11913 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 11914 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11915 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11916 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 11917 | * instance that controls how the layer is composed on screen. The following |
| 11918 | * properties of the paint are taken into account when composing the layer:</p> |
| 11919 | * <ul> |
| 11920 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 11921 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 11922 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 11923 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11924 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11925 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 11926 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 11927 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 11928 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 11929 | * the desired alpha value.<p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11930 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11931 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 11932 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 11933 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11934 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11935 | * @param layerType The ype of layer to use with this view, must be one of |
| 11936 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 11937 | * {@link #LAYER_TYPE_HARDWARE} |
| 11938 | * @param paint The paint used to compose the layer. This argument is optional |
| 11939 | * and can be null. It is ignored when the layer type is |
| 11940 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11941 | * |
| 11942 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11943 | * @see #LAYER_TYPE_NONE |
| 11944 | * @see #LAYER_TYPE_SOFTWARE |
| 11945 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11946 | * @see #setAlpha(float) |
| 11947 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11948 | * @attr ref android.R.styleable#View_layerType |
| 11949 | */ |
| 11950 | public void setLayerType(int layerType, Paint paint) { |
| 11951 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11952 | 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] | 11953 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 11954 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 11955 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11956 | if (layerType == mLayerType) { |
| 11957 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 11958 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11959 | invalidateParentCaches(); |
| 11960 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 11961 | } |
| 11962 | return; |
| 11963 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11964 | |
| 11965 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11966 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 11967 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11968 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 11969 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11970 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 11971 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11972 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11973 | default: |
| 11974 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11975 | } |
| 11976 | |
| 11977 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 11978 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 11979 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 11980 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11981 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 11982 | invalidateParentCaches(); |
| 11983 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11984 | } |
| 11985 | |
| 11986 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11987 | * Indicates whether this view has a static layer. A view with layer type |
| 11988 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 11989 | * dynamic. |
| 11990 | */ |
| 11991 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 11992 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 11993 | } |
| 11994 | |
| 11995 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 11996 | * Indicates what type of layer is currently associated with this view. By default |
| 11997 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 11998 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 11999 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12000 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12001 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12002 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12003 | * |
| 12004 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12005 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12006 | * @see #LAYER_TYPE_NONE |
| 12007 | * @see #LAYER_TYPE_SOFTWARE |
| 12008 | * @see #LAYER_TYPE_HARDWARE |
| 12009 | */ |
| 12010 | public int getLayerType() { |
| 12011 | return mLayerType; |
| 12012 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12013 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12014 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12015 | * Forces this view's layer to be created and this view to be rendered |
| 12016 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 12017 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12018 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12019 | * This method can for instance be used to render a view into its layer before |
| 12020 | * starting an animation. If this view is complex, rendering into the layer |
| 12021 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12022 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12023 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12024 | * |
| 12025 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12026 | */ |
| 12027 | public void buildLayer() { |
| 12028 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 12029 | |
| 12030 | if (mAttachInfo == null) { |
| 12031 | throw new IllegalStateException("This view must be attached to a window first"); |
| 12032 | } |
| 12033 | |
| 12034 | switch (mLayerType) { |
| 12035 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12036 | if (mAttachInfo.mHardwareRenderer != null && |
| 12037 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 12038 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12039 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12040 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12041 | break; |
| 12042 | case LAYER_TYPE_SOFTWARE: |
| 12043 | buildDrawingCache(true); |
| 12044 | break; |
| 12045 | } |
| 12046 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12047 | |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12048 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12049 | * <p>Returns a hardware layer that can be used to draw this view again |
| 12050 | * without executing its draw method.</p> |
| 12051 | * |
| 12052 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 12053 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12054 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 12055 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 12056 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12057 | return null; |
| 12058 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12059 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12060 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12061 | |
| 12062 | final int width = mRight - mLeft; |
| 12063 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12064 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12065 | if (width == 0 || height == 0) { |
| 12066 | return null; |
| 12067 | } |
| 12068 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12069 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12070 | if (mHardwareLayer == null) { |
| 12071 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 12072 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 12073 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12074 | } else { |
| 12075 | if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
| 12076 | mHardwareLayer.resize(width, height); |
| 12077 | mLocalDirtyRect.set(0, 0, width, height); |
| 12078 | } |
| 12079 | |
| 12080 | // This should not be necessary but applications that change |
| 12081 | // the parameters of their background drawable without calling |
| 12082 | // this.setBackground(Drawable) can leave the view in a bad state |
| 12083 | // (for instance isOpaque() returns true, but the background is |
| 12084 | // not opaque.) |
| 12085 | computeOpaqueFlags(); |
| 12086 | |
| 12087 | final boolean opaque = isOpaque(); |
| 12088 | if (mHardwareLayer.isOpaque() != opaque) { |
| 12089 | mHardwareLayer.setOpaque(opaque); |
| 12090 | mLocalDirtyRect.set(0, 0, width, height); |
| 12091 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12092 | } |
| 12093 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 12094 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 12095 | if (!mHardwareLayer.isValid()) { |
| 12096 | return null; |
| 12097 | } |
| 12098 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12099 | mHardwareLayer.redraw(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12100 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12101 | } |
| 12102 | |
| 12103 | return mHardwareLayer; |
| 12104 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12105 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12106 | /** |
| 12107 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12108 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12109 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12110 | * |
| 12111 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12112 | * @see #LAYER_TYPE_HARDWARE |
| 12113 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12114 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12115 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12116 | AttachInfo info = mAttachInfo; |
| 12117 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12118 | info.mHardwareRenderer.isEnabled() && |
| 12119 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12120 | mHardwareLayer.destroy(); |
| 12121 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12122 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12123 | invalidate(true); |
| 12124 | invalidateParentCaches(); |
| 12125 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12126 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12127 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12128 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12129 | } |
| 12130 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12131 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12132 | * Destroys all hardware rendering resources. This method is invoked |
| 12133 | * when the system needs to reclaim resources. Upon execution of this |
| 12134 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12135 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12136 | * Note: you <strong>must</strong> call |
| 12137 | * <code>super.destroyHardwareResources()</code> when overriding |
| 12138 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12139 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12140 | * @hide |
| 12141 | */ |
| 12142 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12143 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12144 | } |
| 12145 | |
| 12146 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12147 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 12148 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 12149 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 12150 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 12151 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 12152 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12153 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12154 | * <p>Enabling the drawing cache is similar to |
| 12155 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12156 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 12157 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 12158 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 12159 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 12160 | * for information on how to enable software and hardware layers.</p> |
| 12161 | * |
| 12162 | * <p>This API can be used to manually generate |
| 12163 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 12164 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12165 | * |
| 12166 | * @param enabled true to enable the drawing cache, false otherwise |
| 12167 | * |
| 12168 | * @see #isDrawingCacheEnabled() |
| 12169 | * @see #getDrawingCache() |
| 12170 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12171 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12172 | */ |
| 12173 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12174 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12175 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 12176 | } |
| 12177 | |
| 12178 | /** |
| 12179 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 12180 | * |
| 12181 | * @return true if the drawing cache is enabled |
| 12182 | * |
| 12183 | * @see #setDrawingCacheEnabled(boolean) |
| 12184 | * @see #getDrawingCache() |
| 12185 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12186 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12187 | public boolean isDrawingCacheEnabled() { |
| 12188 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 12189 | } |
| 12190 | |
| 12191 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12192 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 12193 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12194 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12195 | * @hide |
| 12196 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12197 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12198 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12199 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.PFLAG_DIRTY_MASK) + |
| 12200 | ") DRAWN(" + (mPrivateFlags & PFLAG_DRAWN) + ")" + " CACHE_VALID(" + |
| 12201 | (mPrivateFlags & View.PFLAG_DRAWING_CACHE_VALID) + |
| 12202 | ") INVALIDATED(" + (mPrivateFlags & PFLAG_INVALIDATED) + ")"); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12203 | if (clear) { |
| 12204 | mPrivateFlags &= clearMask; |
| 12205 | } |
| 12206 | if (this instanceof ViewGroup) { |
| 12207 | ViewGroup parent = (ViewGroup) this; |
| 12208 | final int count = parent.getChildCount(); |
| 12209 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 12210 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12211 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 12212 | } |
| 12213 | } |
| 12214 | } |
| 12215 | |
| 12216 | /** |
| 12217 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 12218 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 12219 | * to recreate its own display list, which would happen if it went through the normal |
| 12220 | * draw/dispatchDraw mechanisms. |
| 12221 | * |
| 12222 | * @hide |
| 12223 | */ |
| 12224 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12225 | |
| 12226 | /** |
| 12227 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 12228 | * This method checks these conditions and returns the appropriate result. |
| 12229 | * |
| 12230 | * @return true if view has the ability to create a display list, false otherwise. |
| 12231 | * |
| 12232 | * @hide |
| 12233 | */ |
| 12234 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12235 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12236 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12237 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12238 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 12239 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 12240 | * is not supported or this this has not been attached to a window. |
| 12241 | * |
| 12242 | * @hide |
| 12243 | */ |
| 12244 | public HardwareRenderer getHardwareRenderer() { |
| 12245 | if (mAttachInfo != null) { |
| 12246 | return mAttachInfo.mHardwareRenderer; |
| 12247 | } |
| 12248 | return null; |
| 12249 | } |
| 12250 | |
| 12251 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12252 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 12253 | * Otherwise, the same display list will be returned (after having been rendered into |
| 12254 | * along the way, depending on the invalidation state of the view). |
| 12255 | * |
| 12256 | * @param displayList The previous version of this displayList, could be null. |
| 12257 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 12258 | * the view will avoid creating a layer inside the resulting display list. |
| 12259 | * @return A new or reused DisplayList object. |
| 12260 | */ |
| 12261 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 12262 | if (!canHaveDisplayList()) { |
| 12263 | return null; |
| 12264 | } |
| 12265 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12266 | if (((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12267 | displayList == null || !displayList.isValid() || |
| 12268 | (!isLayer && mRecreateDisplayList))) { |
| 12269 | // Don't need to recreate the display list, just need to tell our |
| 12270 | // children to restore/recreate theirs |
| 12271 | if (displayList != null && displayList.isValid() && |
| 12272 | !isLayer && !mRecreateDisplayList) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12273 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12274 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12275 | dispatchGetDisplayList(); |
| 12276 | |
| 12277 | return displayList; |
| 12278 | } |
| 12279 | |
| 12280 | if (!isLayer) { |
| 12281 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 12282 | // we copy in child display lists into ours in drawChild() |
| 12283 | mRecreateDisplayList = true; |
| 12284 | } |
| 12285 | if (displayList == null) { |
| 12286 | final String name = getClass().getSimpleName(); |
| 12287 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 12288 | // If we're creating a new display list, make sure our parent gets invalidated |
| 12289 | // since they will need to recreate their display list to account for this |
| 12290 | // new child display list. |
| 12291 | invalidateParentCaches(); |
| 12292 | } |
| 12293 | |
| 12294 | boolean caching = false; |
| 12295 | final HardwareCanvas canvas = displayList.start(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12296 | int width = mRight - mLeft; |
| 12297 | int height = mBottom - mTop; |
| 12298 | |
| 12299 | try { |
| 12300 | canvas.setViewport(width, height); |
| 12301 | // The dirty rect should always be null for a display list |
| 12302 | canvas.onPreDraw(null); |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 12303 | int layerType = getLayerType(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12304 | if (!isLayer && layerType != LAYER_TYPE_NONE) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12305 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12306 | final HardwareLayer layer = getHardwareLayer(); |
| 12307 | if (layer != null && layer.isValid()) { |
| 12308 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12309 | } else { |
| 12310 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 12311 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 12312 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12313 | } |
| 12314 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12315 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12316 | buildDrawingCache(true); |
| 12317 | Bitmap cache = getDrawingCache(true); |
| 12318 | if (cache != null) { |
| 12319 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 12320 | caching = true; |
| 12321 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12322 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12323 | } else { |
| 12324 | |
| 12325 | computeScroll(); |
| 12326 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12327 | canvas.translate(-mScrollX, -mScrollY); |
| 12328 | if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12329 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12330 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12331 | } |
| 12332 | |
| 12333 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12334 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12335 | dispatchDraw(canvas); |
| 12336 | } else { |
| 12337 | draw(canvas); |
| 12338 | } |
| 12339 | } |
| 12340 | } finally { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12341 | canvas.onPostDraw(); |
| 12342 | |
| 12343 | displayList.end(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12344 | displayList.setCaching(caching); |
| 12345 | if (isLayer) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12346 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 12347 | } else { |
| 12348 | setDisplayListProperties(displayList); |
| 12349 | } |
| 12350 | } |
| 12351 | } else if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12352 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12353 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12354 | } |
| 12355 | |
| 12356 | return displayList; |
| 12357 | } |
| 12358 | |
| 12359 | /** |
| 12360 | * Get the DisplayList for the HardwareLayer |
| 12361 | * |
| 12362 | * @param layer The HardwareLayer whose DisplayList we want |
| 12363 | * @return A DisplayList fopr the specified HardwareLayer |
| 12364 | */ |
| 12365 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 12366 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 12367 | layer.setDisplayList(displayList); |
| 12368 | return displayList; |
| 12369 | } |
| 12370 | |
| 12371 | |
| 12372 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12373 | * <p>Returns a display list that can be used to draw this view again |
| 12374 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12375 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12376 | * @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] | 12377 | * |
| 12378 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12379 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12380 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12381 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12382 | return mDisplayList; |
| 12383 | } |
| 12384 | |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 12385 | private void clearDisplayList() { |
| 12386 | if (mDisplayList != null) { |
| 12387 | mDisplayList.invalidate(); |
| 12388 | mDisplayList.clear(); |
| 12389 | } |
| 12390 | } |
| 12391 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12392 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12393 | * <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] | 12394 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12395 | * @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] | 12396 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12397 | * @see #getDrawingCache(boolean) |
| 12398 | */ |
| 12399 | public Bitmap getDrawingCache() { |
| 12400 | return getDrawingCache(false); |
| 12401 | } |
| 12402 | |
| 12403 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12404 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 12405 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 12406 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 12407 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 12408 | * request the drawing cache by calling this method and draw it on screen if the |
| 12409 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12410 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12411 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12412 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12413 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12414 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12415 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12416 | * size than the view. This implies that your application must be able to handle this |
| 12417 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12418 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12419 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 12420 | * the current density of the screen when the application is in compatibility |
| 12421 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12422 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12423 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12424 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12425 | * @see #setDrawingCacheEnabled(boolean) |
| 12426 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12427 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12428 | * @see #destroyDrawingCache() |
| 12429 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12430 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12431 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 12432 | return null; |
| 12433 | } |
| 12434 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12435 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12436 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12437 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12438 | } |
| 12439 | |
| 12440 | /** |
| 12441 | * <p>Frees the resources used by the drawing cache. If you call |
| 12442 | * {@link #buildDrawingCache()} manually without calling |
| 12443 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12444 | * should cleanup the cache with this method afterwards.</p> |
| 12445 | * |
| 12446 | * @see #setDrawingCacheEnabled(boolean) |
| 12447 | * @see #buildDrawingCache() |
| 12448 | * @see #getDrawingCache() |
| 12449 | */ |
| 12450 | public void destroyDrawingCache() { |
| 12451 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12452 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12453 | mDrawingCache = null; |
| 12454 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12455 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12456 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12457 | mUnscaledDrawingCache = null; |
| 12458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12459 | } |
| 12460 | |
| 12461 | /** |
| 12462 | * 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] | 12463 | * 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] | 12464 | * view will always be drawn on top of a solid color. |
| 12465 | * |
| 12466 | * @param color The background color to use for the drawing cache's bitmap |
| 12467 | * |
| 12468 | * @see #setDrawingCacheEnabled(boolean) |
| 12469 | * @see #buildDrawingCache() |
| 12470 | * @see #getDrawingCache() |
| 12471 | */ |
| 12472 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12473 | if (color != mDrawingCacheBackgroundColor) { |
| 12474 | mDrawingCacheBackgroundColor = color; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12475 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12476 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12477 | } |
| 12478 | |
| 12479 | /** |
| 12480 | * @see #setDrawingCacheBackgroundColor(int) |
| 12481 | * |
| 12482 | * @return The background color to used for the drawing cache's bitmap |
| 12483 | */ |
| 12484 | public int getDrawingCacheBackgroundColor() { |
| 12485 | return mDrawingCacheBackgroundColor; |
| 12486 | } |
| 12487 | |
| 12488 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12489 | * <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] | 12490 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12491 | * @see #buildDrawingCache(boolean) |
| 12492 | */ |
| 12493 | public void buildDrawingCache() { |
| 12494 | buildDrawingCache(false); |
| 12495 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 12496 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12497 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12498 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 12499 | * |
| 12500 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 12501 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12502 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12503 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12504 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12505 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12506 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12507 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12508 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12509 | * size than the view. This implies that your application must be able to handle this |
| 12510 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12511 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12512 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 12513 | * 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] | 12514 | * 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] | 12515 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12516 | * |
| 12517 | * @see #getDrawingCache() |
| 12518 | * @see #destroyDrawingCache() |
| 12519 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12520 | public void buildDrawingCache(boolean autoScale) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12521 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12522 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12523 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12524 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12525 | int width = mRight - mLeft; |
| 12526 | int height = mBottom - mTop; |
| 12527 | |
| 12528 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12529 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12530 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12531 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12532 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 12533 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12535 | |
| 12536 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12537 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12538 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12539 | |
| 12540 | if (width <= 0 || height <= 0 || |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12541 | // Projected bitmap size in bytes |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12542 | (width * height * (opaque && !use32BitCache ? 2 : 4) > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12543 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { |
| 12544 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12545 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12546 | return; |
| 12547 | } |
| 12548 | |
| 12549 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12550 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12551 | |
| 12552 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12553 | Bitmap.Config quality; |
| 12554 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12555 | // Never pick ARGB_4444 because it looks awful |
| 12556 | // 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] | 12557 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 12558 | case DRAWING_CACHE_QUALITY_AUTO: |
| 12559 | quality = Bitmap.Config.ARGB_8888; |
| 12560 | break; |
| 12561 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12562 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12563 | break; |
| 12564 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12565 | quality = Bitmap.Config.ARGB_8888; |
| 12566 | break; |
| 12567 | default: |
| 12568 | quality = Bitmap.Config.ARGB_8888; |
| 12569 | break; |
| 12570 | } |
| 12571 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12572 | // Optimization for translucent windows |
| 12573 | // 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] | 12574 | 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] | 12575 | } |
| 12576 | |
| 12577 | // Try to cleanup memory |
| 12578 | if (bitmap != null) bitmap.recycle(); |
| 12579 | |
| 12580 | try { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12581 | bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12582 | width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12583 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12584 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12585 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12586 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12587 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12588 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12589 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12590 | } catch (OutOfMemoryError e) { |
| 12591 | // If there is not enough memory to create the bitmap cache, just |
| 12592 | // ignore the issue as bitmap caches are not required to draw the |
| 12593 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12594 | if (autoScale) { |
| 12595 | mDrawingCache = null; |
| 12596 | } else { |
| 12597 | mUnscaledDrawingCache = null; |
| 12598 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12599 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12600 | return; |
| 12601 | } |
| 12602 | |
| 12603 | clear = drawingCacheBackgroundColor != 0; |
| 12604 | } |
| 12605 | |
| 12606 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12607 | if (attachInfo != null) { |
| 12608 | canvas = attachInfo.mCanvas; |
| 12609 | if (canvas == null) { |
| 12610 | canvas = new Canvas(); |
| 12611 | } |
| 12612 | canvas.setBitmap(bitmap); |
| 12613 | // Temporarily clobber the cached Canvas in case one of our children |
| 12614 | // is also using a drawing cache. Without this, the children would |
| 12615 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12616 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 12617 | attachInfo.mCanvas = null; |
| 12618 | } else { |
| 12619 | // This case should hopefully never or seldom happen |
| 12620 | canvas = new Canvas(bitmap); |
| 12621 | } |
| 12622 | |
| 12623 | if (clear) { |
| 12624 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 12625 | } |
| 12626 | |
| 12627 | computeScroll(); |
| 12628 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12629 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12630 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12631 | final float scale = attachInfo.mApplicationScale; |
| 12632 | canvas.scale(scale, scale); |
| 12633 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12635 | canvas.translate(-mScrollX, -mScrollY); |
| 12636 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12637 | mPrivateFlags |= PFLAG_DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12638 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 12639 | mLayerType != LAYER_TYPE_NONE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12640 | mPrivateFlags |= PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12642 | |
| 12643 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12644 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 12645 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12646 | dispatchDraw(canvas); |
| 12647 | } else { |
| 12648 | draw(canvas); |
| 12649 | } |
| 12650 | |
| 12651 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12652 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12653 | |
| 12654 | if (attachInfo != null) { |
| 12655 | // Restore the cached Canvas for our siblings |
| 12656 | attachInfo.mCanvas = canvas; |
| 12657 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12658 | } |
| 12659 | } |
| 12660 | |
| 12661 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12662 | * Create a snapshot of the view into a bitmap. We should probably make |
| 12663 | * some form of this public, but should think about the API. |
| 12664 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 12665 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12666 | int width = mRight - mLeft; |
| 12667 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12668 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12669 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 12670 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12671 | width = (int) ((width * scale) + 0.5f); |
| 12672 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12673 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12674 | Bitmap bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12675 | width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12676 | if (bitmap == null) { |
| 12677 | throw new OutOfMemoryError(); |
| 12678 | } |
| 12679 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 12680 | Resources resources = getResources(); |
| 12681 | if (resources != null) { |
| 12682 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 12683 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12684 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12685 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12686 | if (attachInfo != null) { |
| 12687 | canvas = attachInfo.mCanvas; |
| 12688 | if (canvas == null) { |
| 12689 | canvas = new Canvas(); |
| 12690 | } |
| 12691 | canvas.setBitmap(bitmap); |
| 12692 | // Temporarily clobber the cached Canvas in case one of our children |
| 12693 | // is also using a drawing cache. Without this, the children would |
| 12694 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 12695 | // things would happen (invisible views, corrupted drawings, etc.) |
| 12696 | attachInfo.mCanvas = null; |
| 12697 | } else { |
| 12698 | // This case should hopefully never or seldom happen |
| 12699 | canvas = new Canvas(bitmap); |
| 12700 | } |
| 12701 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12702 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12703 | bitmap.eraseColor(backgroundColor); |
| 12704 | } |
| 12705 | |
| 12706 | computeScroll(); |
| 12707 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 12708 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12709 | canvas.translate(-mScrollX, -mScrollY); |
| 12710 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12711 | // Temporarily remove the dirty mask |
| 12712 | int flags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12713 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12714 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12715 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12716 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12717 | dispatchDraw(canvas); |
| 12718 | } else { |
| 12719 | draw(canvas); |
| 12720 | } |
| 12721 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 12722 | mPrivateFlags = flags; |
| 12723 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12724 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 12725 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12726 | |
| 12727 | if (attachInfo != null) { |
| 12728 | // Restore the cached Canvas for our siblings |
| 12729 | attachInfo.mCanvas = canvas; |
| 12730 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12731 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 12732 | return bitmap; |
| 12733 | } |
| 12734 | |
| 12735 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12736 | * Indicates whether this View is currently in edit mode. A View is usually |
| 12737 | * in edit mode when displayed within a developer tool. For instance, if |
| 12738 | * this View is being drawn by a visual user interface builder, this method |
| 12739 | * should return true. |
| 12740 | * |
| 12741 | * Subclasses should check the return value of this method to provide |
| 12742 | * different behaviors if their normal behavior might interfere with the |
| 12743 | * host environment. For instance: the class spawns a thread in its |
| 12744 | * constructor, the drawing code relies on device-specific features, etc. |
| 12745 | * |
| 12746 | * This method is usually checked in the drawing code of custom widgets. |
| 12747 | * |
| 12748 | * @return True if this View is in edit mode, false otherwise. |
| 12749 | */ |
| 12750 | public boolean isInEditMode() { |
| 12751 | return false; |
| 12752 | } |
| 12753 | |
| 12754 | /** |
| 12755 | * If the View draws content inside its padding and enables fading edges, |
| 12756 | * it needs to support padding offsets. Padding offsets are added to the |
| 12757 | * fading edges to extend the length of the fade so that it covers pixels |
| 12758 | * drawn inside the padding. |
| 12759 | * |
| 12760 | * Subclasses of this class should override this method if they need |
| 12761 | * to draw content inside the padding. |
| 12762 | * |
| 12763 | * @return True if padding offset must be applied, false otherwise. |
| 12764 | * |
| 12765 | * @see #getLeftPaddingOffset() |
| 12766 | * @see #getRightPaddingOffset() |
| 12767 | * @see #getTopPaddingOffset() |
| 12768 | * @see #getBottomPaddingOffset() |
| 12769 | * |
| 12770 | * @since CURRENT |
| 12771 | */ |
| 12772 | protected boolean isPaddingOffsetRequired() { |
| 12773 | return false; |
| 12774 | } |
| 12775 | |
| 12776 | /** |
| 12777 | * Amount by which to extend the left fading region. Called only when |
| 12778 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12779 | * |
| 12780 | * @return The left padding offset in pixels. |
| 12781 | * |
| 12782 | * @see #isPaddingOffsetRequired() |
| 12783 | * |
| 12784 | * @since CURRENT |
| 12785 | */ |
| 12786 | protected int getLeftPaddingOffset() { |
| 12787 | return 0; |
| 12788 | } |
| 12789 | |
| 12790 | /** |
| 12791 | * Amount by which to extend the right fading region. Called only when |
| 12792 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12793 | * |
| 12794 | * @return The right padding offset in pixels. |
| 12795 | * |
| 12796 | * @see #isPaddingOffsetRequired() |
| 12797 | * |
| 12798 | * @since CURRENT |
| 12799 | */ |
| 12800 | protected int getRightPaddingOffset() { |
| 12801 | return 0; |
| 12802 | } |
| 12803 | |
| 12804 | /** |
| 12805 | * Amount by which to extend the top fading region. Called only when |
| 12806 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12807 | * |
| 12808 | * @return The top padding offset in pixels. |
| 12809 | * |
| 12810 | * @see #isPaddingOffsetRequired() |
| 12811 | * |
| 12812 | * @since CURRENT |
| 12813 | */ |
| 12814 | protected int getTopPaddingOffset() { |
| 12815 | return 0; |
| 12816 | } |
| 12817 | |
| 12818 | /** |
| 12819 | * Amount by which to extend the bottom fading region. Called only when |
| 12820 | * {@link #isPaddingOffsetRequired()} returns true. |
| 12821 | * |
| 12822 | * @return The bottom padding offset in pixels. |
| 12823 | * |
| 12824 | * @see #isPaddingOffsetRequired() |
| 12825 | * |
| 12826 | * @since CURRENT |
| 12827 | */ |
| 12828 | protected int getBottomPaddingOffset() { |
| 12829 | return 0; |
| 12830 | } |
| 12831 | |
| 12832 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12833 | * @hide |
| 12834 | * @param offsetRequired |
| 12835 | */ |
| 12836 | protected int getFadeTop(boolean offsetRequired) { |
| 12837 | int top = mPaddingTop; |
| 12838 | if (offsetRequired) top += getTopPaddingOffset(); |
| 12839 | return top; |
| 12840 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12841 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12842 | /** |
| 12843 | * @hide |
| 12844 | * @param offsetRequired |
| 12845 | */ |
| 12846 | protected int getFadeHeight(boolean offsetRequired) { |
| 12847 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12848 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12849 | return mBottom - mTop - mPaddingBottom - padding; |
| 12850 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12851 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 12852 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12853 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12854 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12855 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12856 | * <p>Even if this method returns true, it does not mean that every call |
| 12857 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 12858 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 12859 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12860 | * window is hardware accelerated, |
| 12861 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 12862 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12863 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12864 | * @return True if the view is attached to a window and the window is |
| 12865 | * hardware accelerated; false in any other case. |
| 12866 | */ |
| 12867 | public boolean isHardwareAccelerated() { |
| 12868 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 12869 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12870 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 12871 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12872 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 12873 | * case of an active Animation being run on the view. |
| 12874 | */ |
| 12875 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 12876 | Animation a, boolean scalingRequired) { |
| 12877 | Transformation invalidationTransform; |
| 12878 | final int flags = parent.mGroupFlags; |
| 12879 | final boolean initialized = a.isInitialized(); |
| 12880 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 12881 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12882 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 12883 | if (mAttachInfo != null) a.setListenerHandler(mAttachInfo.mHandler); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12884 | onAnimationStart(); |
| 12885 | } |
| 12886 | |
| 12887 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 12888 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 12889 | if (parent.mInvalidationTransformation == null) { |
| 12890 | parent.mInvalidationTransformation = new Transformation(); |
| 12891 | } |
| 12892 | invalidationTransform = parent.mInvalidationTransformation; |
| 12893 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 12894 | } else { |
| 12895 | invalidationTransform = parent.mChildTransformation; |
| 12896 | } |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 12897 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12898 | if (more) { |
| 12899 | if (!a.willChangeBounds()) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 12900 | if ((flags & (ViewGroup.FLAG_OPTIMIZE_INVALIDATE | ViewGroup.FLAG_ANIMATION_DONE)) == |
| 12901 | ViewGroup.FLAG_OPTIMIZE_INVALIDATE) { |
| 12902 | parent.mGroupFlags |= ViewGroup.FLAG_INVALIDATE_REQUIRED; |
| 12903 | } else if ((flags & ViewGroup.FLAG_INVALIDATE_REQUIRED) == 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12904 | // The child need to draw an animation, potentially offscreen, so |
| 12905 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12906 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12907 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 12908 | } |
| 12909 | } else { |
| 12910 | if (parent.mInvalidateRegion == null) { |
| 12911 | parent.mInvalidateRegion = new RectF(); |
| 12912 | } |
| 12913 | final RectF region = parent.mInvalidateRegion; |
| 12914 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 12915 | invalidationTransform); |
| 12916 | |
| 12917 | // The child need to draw an animation, potentially offscreen, so |
| 12918 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12919 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12920 | |
| 12921 | final int left = mLeft + (int) region.left; |
| 12922 | final int top = mTop + (int) region.top; |
| 12923 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 12924 | top + (int) (region.height() + .5f)); |
| 12925 | } |
| 12926 | } |
| 12927 | return more; |
| 12928 | } |
| 12929 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12930 | /** |
| 12931 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 12932 | * It sets or resets the current value of all properties on that display list (resetting is |
| 12933 | * necessary when a display list is being re-created, because we need to make sure that |
| 12934 | * previously-set transform values |
| 12935 | */ |
| 12936 | void setDisplayListProperties(DisplayList displayList) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12937 | if (displayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12938 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 12939 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12940 | if (mParent instanceof ViewGroup) { |
| 12941 | displayList.setClipChildren( |
| 12942 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 12943 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12944 | float alpha = 1; |
| 12945 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 12946 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 12947 | ViewGroup parentVG = (ViewGroup) mParent; |
| 12948 | final boolean hasTransform = |
| 12949 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 12950 | if (hasTransform) { |
| 12951 | Transformation transform = parentVG.mChildTransformation; |
| 12952 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 12953 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 12954 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 12955 | alpha = transform.getAlpha(); |
| 12956 | } |
| 12957 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 12958 | displayList.setStaticMatrix(transform.getMatrix()); |
| 12959 | } |
| 12960 | } |
| 12961 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12962 | } |
| 12963 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12964 | alpha *= mTransformationInfo.mAlpha; |
| 12965 | if (alpha < 1) { |
| 12966 | final int multipliedAlpha = (int) (255 * alpha); |
| 12967 | if (onSetAlpha(multipliedAlpha)) { |
| 12968 | alpha = 1; |
| 12969 | } |
| 12970 | } |
| 12971 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12972 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 12973 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 12974 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 12975 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12976 | if (mTransformationInfo.mCamera == null) { |
| 12977 | mTransformationInfo.mCamera = new Camera(); |
| 12978 | mTransformationInfo.matrix3D = new Matrix(); |
| 12979 | } |
| 12980 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12981 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == PFLAG_PIVOT_EXPLICITLY_SET) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12982 | displayList.setPivotX(getPivotX()); |
| 12983 | displayList.setPivotY(getPivotY()); |
| 12984 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 12985 | } else if (alpha < 1) { |
| 12986 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12987 | } |
| 12988 | } |
| 12989 | } |
| 12990 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 12991 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12992 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 12993 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 12994 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 12995 | */ |
| 12996 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12997 | boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12998 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 12999 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13000 | final int flags = parent.mGroupFlags; |
| 13001 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13002 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13003 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13004 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13005 | } |
| 13006 | |
| 13007 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13008 | boolean concatMatrix = false; |
| 13009 | |
| 13010 | boolean scalingRequired = false; |
| 13011 | boolean caching; |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 13012 | int layerType = getLayerType(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13013 | |
| 13014 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13015 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 13016 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13017 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13018 | // 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] | 13019 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 13020 | } else { |
| 13021 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 13022 | } |
| 13023 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13024 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13025 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13026 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13027 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13028 | if (concatMatrix) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13029 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13030 | } |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13031 | transformToApply = parent.mChildTransformation; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13032 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13033 | if ((mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_TRANSFORM) == PFLAG3_VIEW_IS_ANIMATING_TRANSFORM && |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13034 | mDisplayList != null) { |
| 13035 | // No longer animating: clear out old animation matrix |
| 13036 | mDisplayList.setAnimationMatrix(null); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13037 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13038 | } |
| 13039 | if (!useDisplayListProperties && |
| 13040 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13041 | final boolean hasTransform = |
| 13042 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
| 13043 | if (hasTransform) { |
| 13044 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 13045 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 13046 | parent.mChildTransformation : null; |
| 13047 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 13048 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13049 | } |
| 13050 | } |
| 13051 | |
| 13052 | concatMatrix |= !childHasIdentityMatrix; |
| 13053 | |
| 13054 | // Sets the flag as early as possible to allow draw() implementations |
| 13055 | // to call invalidate() successfully when doing animations |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13056 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13057 | |
Romain Guy | fbb4321 | 2012-08-30 15:19:27 -0700 | [diff] [blame] | 13058 | if (!concatMatrix && |
| 13059 | (flags & (ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS | |
| 13060 | ViewGroup.FLAG_CLIP_CHILDREN)) == ViewGroup.FLAG_CLIP_CHILDREN && |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 13061 | canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13062 | (mPrivateFlags & PFLAG_DRAW_ANIMATION) == 0) { |
| 13063 | mPrivateFlags2 |= PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13064 | return more; |
| 13065 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13066 | mPrivateFlags2 &= ~PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13067 | |
| 13068 | if (hardwareAccelerated) { |
| 13069 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 13070 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13071 | mRecreateDisplayList = (mPrivateFlags & PFLAG_INVALIDATED) == PFLAG_INVALIDATED; |
| 13072 | mPrivateFlags &= ~PFLAG_INVALIDATED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13073 | } |
| 13074 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13075 | DisplayList displayList = null; |
| 13076 | Bitmap cache = null; |
| 13077 | boolean hasDisplayList = false; |
| 13078 | if (caching) { |
| 13079 | if (!hardwareAccelerated) { |
| 13080 | if (layerType != LAYER_TYPE_NONE) { |
| 13081 | layerType = LAYER_TYPE_SOFTWARE; |
| 13082 | buildDrawingCache(true); |
| 13083 | } |
| 13084 | cache = getDrawingCache(true); |
| 13085 | } else { |
| 13086 | switch (layerType) { |
| 13087 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13088 | if (useDisplayListProperties) { |
| 13089 | hasDisplayList = canHaveDisplayList(); |
| 13090 | } else { |
| 13091 | buildDrawingCache(true); |
| 13092 | cache = getDrawingCache(true); |
| 13093 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13094 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13095 | case LAYER_TYPE_HARDWARE: |
| 13096 | if (useDisplayListProperties) { |
| 13097 | hasDisplayList = canHaveDisplayList(); |
| 13098 | } |
| 13099 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13100 | case LAYER_TYPE_NONE: |
| 13101 | // Delay getting the display list until animation-driven alpha values are |
| 13102 | // set up and possibly passed on to the view |
| 13103 | hasDisplayList = canHaveDisplayList(); |
| 13104 | break; |
| 13105 | } |
| 13106 | } |
| 13107 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13108 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13109 | if (useDisplayListProperties) { |
| 13110 | displayList = getDisplayList(); |
| 13111 | if (!displayList.isValid()) { |
| 13112 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13113 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13114 | // try to use it again. |
| 13115 | displayList = null; |
| 13116 | hasDisplayList = false; |
| 13117 | useDisplayListProperties = false; |
| 13118 | } |
| 13119 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13120 | |
Chet Haase | 526057b | 2012-07-12 17:50:41 -0700 | [diff] [blame] | 13121 | int sx = 0; |
| 13122 | int sy = 0; |
| 13123 | if (!hasDisplayList) { |
| 13124 | computeScroll(); |
| 13125 | sx = mScrollX; |
| 13126 | sy = mScrollY; |
| 13127 | } |
| 13128 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13129 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 13130 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 13131 | layerType != LAYER_TYPE_HARDWARE; |
| 13132 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13133 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13134 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13135 | restoreTo = canvas.save(); |
| 13136 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13137 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13138 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13139 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13140 | if (!useDisplayListProperties) { |
| 13141 | canvas.translate(mLeft, mTop); |
| 13142 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13143 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13144 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13145 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13146 | restoreTo = canvas.save(); |
| 13147 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13148 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 13149 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 13150 | canvas.scale(scale, scale); |
| 13151 | } |
| 13152 | } |
| 13153 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13154 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13155 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix() || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13156 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13157 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 13158 | int transX = 0; |
| 13159 | int transY = 0; |
| 13160 | |
| 13161 | if (offsetForScroll) { |
| 13162 | transX = -sx; |
| 13163 | transY = -sy; |
| 13164 | } |
| 13165 | |
| 13166 | if (transformToApply != null) { |
| 13167 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13168 | if (useDisplayListProperties) { |
| 13169 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 13170 | } else { |
| 13171 | // Undo the scroll translation, apply the transformation matrix, |
| 13172 | // then redo the scroll translate to get the correct result. |
| 13173 | canvas.translate(-transX, -transY); |
| 13174 | canvas.concat(transformToApply.getMatrix()); |
| 13175 | canvas.translate(transX, transY); |
| 13176 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13177 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13178 | } |
| 13179 | |
| 13180 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13181 | if (transformAlpha < 1) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13182 | alpha *= transformAlpha; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13183 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13184 | } |
| 13185 | } |
| 13186 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13187 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13188 | canvas.translate(-transX, -transY); |
| 13189 | canvas.concat(getMatrix()); |
| 13190 | canvas.translate(transX, transY); |
| 13191 | } |
| 13192 | } |
| 13193 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13194 | // Deal with alpha if it is or used to be <1 |
| 13195 | if (alpha < 1 || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13196 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13197 | if (alpha < 1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13198 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13199 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13200 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13201 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13202 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13203 | if (hasNoCache) { |
| 13204 | final int multipliedAlpha = (int) (255 * alpha); |
| 13205 | if (!onSetAlpha(multipliedAlpha)) { |
| 13206 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13207 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13208 | layerType != LAYER_TYPE_NONE) { |
| 13209 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 13210 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13211 | if (useDisplayListProperties) { |
| 13212 | displayList.setAlpha(alpha * getAlpha()); |
| 13213 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13214 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13215 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13216 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 13217 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13218 | } |
| 13219 | } else { |
| 13220 | // Alpha is handled by the child directly, clobber the layer's alpha |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13221 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13222 | } |
| 13223 | } |
| 13224 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13225 | } else if ((mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13226 | onSetAlpha(255); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13227 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13228 | } |
| 13229 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13230 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 13231 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13232 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13233 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13234 | } else { |
| 13235 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13236 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13237 | } else { |
| 13238 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 13239 | } |
| 13240 | } |
| 13241 | } |
| 13242 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13243 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13244 | displayList = getDisplayList(); |
| 13245 | if (!displayList.isValid()) { |
| 13246 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13247 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13248 | // try to use it again. |
| 13249 | displayList = null; |
| 13250 | hasDisplayList = false; |
| 13251 | } |
| 13252 | } |
| 13253 | |
| 13254 | if (hasNoCache) { |
| 13255 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13256 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 13257 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13258 | if (layer != null && layer.isValid()) { |
| 13259 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 13260 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 13261 | layerRendered = true; |
| 13262 | } else { |
| 13263 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13264 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13265 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13266 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13267 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 13268 | } |
| 13269 | } |
| 13270 | |
| 13271 | if (!layerRendered) { |
| 13272 | if (!hasDisplayList) { |
| 13273 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13274 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 13275 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13276 | dispatchDraw(canvas); |
| 13277 | } else { |
| 13278 | draw(canvas); |
| 13279 | } |
| 13280 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13281 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13282 | ((HardwareCanvas) canvas).drawDisplayList(displayList, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13283 | } |
| 13284 | } |
| 13285 | } else if (cache != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13286 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13287 | Paint cachePaint; |
| 13288 | |
| 13289 | if (layerType == LAYER_TYPE_NONE) { |
| 13290 | cachePaint = parent.mCachePaint; |
| 13291 | if (cachePaint == null) { |
| 13292 | cachePaint = new Paint(); |
| 13293 | cachePaint.setDither(false); |
| 13294 | parent.mCachePaint = cachePaint; |
| 13295 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13296 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13297 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13298 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 13299 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13300 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13301 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13302 | } |
| 13303 | } else { |
| 13304 | cachePaint = mLayerPaint; |
| 13305 | cachePaint.setAlpha((int) (alpha * 255)); |
| 13306 | } |
| 13307 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 13308 | } |
| 13309 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13310 | if (restoreTo >= 0) { |
| 13311 | canvas.restoreToCount(restoreTo); |
| 13312 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13313 | |
| 13314 | if (a != null && !more) { |
| 13315 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 13316 | onSetAlpha(255); |
| 13317 | } |
| 13318 | parent.finishAnimatingView(this, a); |
| 13319 | } |
| 13320 | |
| 13321 | if (more && hardwareAccelerated) { |
| 13322 | // invalidation is the trigger to recreate display lists, so if we're using |
| 13323 | // display lists to render, force an invalidate to allow the animation to |
| 13324 | // continue drawing another frame |
| 13325 | parent.invalidate(true); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13326 | if (a.hasAlpha() && (mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13327 | // alpha animations should cause the child to recreate its display list |
| 13328 | invalidate(true); |
| 13329 | } |
| 13330 | } |
| 13331 | |
| 13332 | mRecreateDisplayList = false; |
| 13333 | |
| 13334 | return more; |
| 13335 | } |
| 13336 | |
| 13337 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13338 | * Manually render this view (and all of its children) to the given Canvas. |
| 13339 | * 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] | 13340 | * called. When implementing a view, implement |
| 13341 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 13342 | * 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] | 13343 | * |
| 13344 | * @param canvas The Canvas to which the View is rendered. |
| 13345 | */ |
| 13346 | public void draw(Canvas canvas) { |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13347 | final int privateFlags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13348 | final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE && |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13349 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13350 | mPrivateFlags = (privateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13352 | /* |
| 13353 | * Draw traversal performs several drawing steps which must be executed |
| 13354 | * in the appropriate order: |
| 13355 | * |
| 13356 | * 1. Draw the background |
| 13357 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 13358 | * 3. Draw view's content |
| 13359 | * 4. Draw children |
| 13360 | * 5. If necessary, draw the fading edges and restore layers |
| 13361 | * 6. Draw decorations (scrollbars for instance) |
| 13362 | */ |
| 13363 | |
| 13364 | // Step 1, draw the background, if needed |
| 13365 | int saveCount; |
| 13366 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13367 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13368 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13369 | if (background != null) { |
| 13370 | final int scrollX = mScrollX; |
| 13371 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13372 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13373 | if (mBackgroundSizeChanged) { |
| 13374 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 13375 | mBackgroundSizeChanged = false; |
| 13376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13377 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13378 | if ((scrollX | scrollY) == 0) { |
| 13379 | background.draw(canvas); |
| 13380 | } else { |
| 13381 | canvas.translate(scrollX, scrollY); |
| 13382 | background.draw(canvas); |
| 13383 | canvas.translate(-scrollX, -scrollY); |
| 13384 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13385 | } |
| 13386 | } |
| 13387 | |
| 13388 | // skip step 2 & 5 if possible (common case) |
| 13389 | final int viewFlags = mViewFlags; |
| 13390 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 13391 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 13392 | if (!verticalEdges && !horizontalEdges) { |
| 13393 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13394 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13395 | |
| 13396 | // Step 4, draw the children |
| 13397 | dispatchDraw(canvas); |
| 13398 | |
| 13399 | // Step 6, draw decorations (scrollbars) |
| 13400 | onDrawScrollBars(canvas); |
| 13401 | |
| 13402 | // we're done... |
| 13403 | return; |
| 13404 | } |
| 13405 | |
| 13406 | /* |
| 13407 | * Here we do the full fledged routine... |
| 13408 | * (this is an uncommon case where speed matters less, |
| 13409 | * this is why we repeat some of the tests that have been |
| 13410 | * done above) |
| 13411 | */ |
| 13412 | |
| 13413 | boolean drawTop = false; |
| 13414 | boolean drawBottom = false; |
| 13415 | boolean drawLeft = false; |
| 13416 | boolean drawRight = false; |
| 13417 | |
| 13418 | float topFadeStrength = 0.0f; |
| 13419 | float bottomFadeStrength = 0.0f; |
| 13420 | float leftFadeStrength = 0.0f; |
| 13421 | float rightFadeStrength = 0.0f; |
| 13422 | |
| 13423 | // Step 2, save the canvas' layers |
| 13424 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13425 | |
| 13426 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 13427 | if (offsetRequired) { |
| 13428 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13429 | } |
| 13430 | |
| 13431 | int left = mScrollX + paddingLeft; |
| 13432 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13433 | int top = mScrollY + getFadeTop(offsetRequired); |
| 13434 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13435 | |
| 13436 | if (offsetRequired) { |
| 13437 | right += getRightPaddingOffset(); |
| 13438 | bottom += getBottomPaddingOffset(); |
| 13439 | } |
| 13440 | |
| 13441 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13442 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13443 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13444 | |
| 13445 | // clip the fade length if top and bottom fades overlap |
| 13446 | // overlapping fades produce odd-looking artifacts |
| 13447 | if (verticalEdges && (top + length > bottom - length)) { |
| 13448 | length = (bottom - top) / 2; |
| 13449 | } |
| 13450 | |
| 13451 | // also clip horizontal fades if necessary |
| 13452 | if (horizontalEdges && (left + length > right - length)) { |
| 13453 | length = (right - left) / 2; |
| 13454 | } |
| 13455 | |
| 13456 | if (verticalEdges) { |
| 13457 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13458 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13459 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13460 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13461 | } |
| 13462 | |
| 13463 | if (horizontalEdges) { |
| 13464 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13465 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13466 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13467 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13468 | } |
| 13469 | |
| 13470 | saveCount = canvas.getSaveCount(); |
| 13471 | |
| 13472 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13473 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13474 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 13475 | |
| 13476 | if (drawTop) { |
| 13477 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 13478 | } |
| 13479 | |
| 13480 | if (drawBottom) { |
| 13481 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 13482 | } |
| 13483 | |
| 13484 | if (drawLeft) { |
| 13485 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 13486 | } |
| 13487 | |
| 13488 | if (drawRight) { |
| 13489 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 13490 | } |
| 13491 | } else { |
| 13492 | scrollabilityCache.setFadeColor(solidColor); |
| 13493 | } |
| 13494 | |
| 13495 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13496 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13497 | |
| 13498 | // Step 4, draw the children |
| 13499 | dispatchDraw(canvas); |
| 13500 | |
| 13501 | // Step 5, draw the fade effect and restore layers |
| 13502 | final Paint p = scrollabilityCache.paint; |
| 13503 | final Matrix matrix = scrollabilityCache.matrix; |
| 13504 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13505 | |
| 13506 | if (drawTop) { |
| 13507 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 13508 | matrix.postTranslate(left, top); |
| 13509 | fade.setLocalMatrix(matrix); |
| 13510 | canvas.drawRect(left, top, right, top + length, p); |
| 13511 | } |
| 13512 | |
| 13513 | if (drawBottom) { |
| 13514 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 13515 | matrix.postRotate(180); |
| 13516 | matrix.postTranslate(left, bottom); |
| 13517 | fade.setLocalMatrix(matrix); |
| 13518 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 13519 | } |
| 13520 | |
| 13521 | if (drawLeft) { |
| 13522 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 13523 | matrix.postRotate(-90); |
| 13524 | matrix.postTranslate(left, top); |
| 13525 | fade.setLocalMatrix(matrix); |
| 13526 | canvas.drawRect(left, top, left + length, bottom, p); |
| 13527 | } |
| 13528 | |
| 13529 | if (drawRight) { |
| 13530 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 13531 | matrix.postRotate(90); |
| 13532 | matrix.postTranslate(right, top); |
| 13533 | fade.setLocalMatrix(matrix); |
| 13534 | canvas.drawRect(right - length, top, right, bottom, p); |
| 13535 | } |
| 13536 | |
| 13537 | canvas.restoreToCount(saveCount); |
| 13538 | |
| 13539 | // Step 6, draw decorations (scrollbars) |
| 13540 | onDrawScrollBars(canvas); |
| 13541 | } |
| 13542 | |
| 13543 | /** |
| 13544 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 13545 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 13546 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 13547 | * should be set to 0xFF. |
| 13548 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13549 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 13550 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13551 | * |
| 13552 | * @return The known solid color background for this view, or 0 if the color may vary |
| 13553 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13554 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13555 | public int getSolidColor() { |
| 13556 | return 0; |
| 13557 | } |
| 13558 | |
| 13559 | /** |
| 13560 | * Build a human readable string representation of the specified view flags. |
| 13561 | * |
| 13562 | * @param flags the view flags to convert to a string |
| 13563 | * @return a String representing the supplied flags |
| 13564 | */ |
| 13565 | private static String printFlags(int flags) { |
| 13566 | String output = ""; |
| 13567 | int numFlags = 0; |
| 13568 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 13569 | output += "TAKES_FOCUS"; |
| 13570 | numFlags++; |
| 13571 | } |
| 13572 | |
| 13573 | switch (flags & VISIBILITY_MASK) { |
| 13574 | case INVISIBLE: |
| 13575 | if (numFlags > 0) { |
| 13576 | output += " "; |
| 13577 | } |
| 13578 | output += "INVISIBLE"; |
| 13579 | // USELESS HERE numFlags++; |
| 13580 | break; |
| 13581 | case GONE: |
| 13582 | if (numFlags > 0) { |
| 13583 | output += " "; |
| 13584 | } |
| 13585 | output += "GONE"; |
| 13586 | // USELESS HERE numFlags++; |
| 13587 | break; |
| 13588 | default: |
| 13589 | break; |
| 13590 | } |
| 13591 | return output; |
| 13592 | } |
| 13593 | |
| 13594 | /** |
| 13595 | * Build a human readable string representation of the specified private |
| 13596 | * view flags. |
| 13597 | * |
| 13598 | * @param privateFlags the private view flags to convert to a string |
| 13599 | * @return a String representing the supplied flags |
| 13600 | */ |
| 13601 | private static String printPrivateFlags(int privateFlags) { |
| 13602 | String output = ""; |
| 13603 | int numFlags = 0; |
| 13604 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13605 | if ((privateFlags & PFLAG_WANTS_FOCUS) == PFLAG_WANTS_FOCUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13606 | output += "WANTS_FOCUS"; |
| 13607 | numFlags++; |
| 13608 | } |
| 13609 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13610 | if ((privateFlags & PFLAG_FOCUSED) == PFLAG_FOCUSED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13611 | if (numFlags > 0) { |
| 13612 | output += " "; |
| 13613 | } |
| 13614 | output += "FOCUSED"; |
| 13615 | numFlags++; |
| 13616 | } |
| 13617 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13618 | if ((privateFlags & PFLAG_SELECTED) == PFLAG_SELECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13619 | if (numFlags > 0) { |
| 13620 | output += " "; |
| 13621 | } |
| 13622 | output += "SELECTED"; |
| 13623 | numFlags++; |
| 13624 | } |
| 13625 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13626 | if ((privateFlags & PFLAG_IS_ROOT_NAMESPACE) == PFLAG_IS_ROOT_NAMESPACE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13627 | if (numFlags > 0) { |
| 13628 | output += " "; |
| 13629 | } |
| 13630 | output += "IS_ROOT_NAMESPACE"; |
| 13631 | numFlags++; |
| 13632 | } |
| 13633 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13634 | if ((privateFlags & PFLAG_HAS_BOUNDS) == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13635 | if (numFlags > 0) { |
| 13636 | output += " "; |
| 13637 | } |
| 13638 | output += "HAS_BOUNDS"; |
| 13639 | numFlags++; |
| 13640 | } |
| 13641 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13642 | if ((privateFlags & PFLAG_DRAWN) == PFLAG_DRAWN) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13643 | if (numFlags > 0) { |
| 13644 | output += " "; |
| 13645 | } |
| 13646 | output += "DRAWN"; |
| 13647 | // USELESS HERE numFlags++; |
| 13648 | } |
| 13649 | return output; |
| 13650 | } |
| 13651 | |
| 13652 | /** |
| 13653 | * <p>Indicates whether or not this view's layout will be requested during |
| 13654 | * the next hierarchy layout pass.</p> |
| 13655 | * |
| 13656 | * @return true if the layout will be forced during next layout pass |
| 13657 | */ |
| 13658 | public boolean isLayoutRequested() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13659 | return (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13660 | } |
| 13661 | |
| 13662 | /** |
| 13663 | * Assign a size and position to a view and all of its |
| 13664 | * descendants |
| 13665 | * |
| 13666 | * <p>This is the second phase of the layout mechanism. |
| 13667 | * (The first is measuring). In this phase, each parent calls |
| 13668 | * layout on all of its children to position them. |
| 13669 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13670 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13671 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13672 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13673 | * Derived classes with children should override |
| 13674 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13675 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13676 | * |
| 13677 | * @param l Left position, relative to parent |
| 13678 | * @param t Top position, relative to parent |
| 13679 | * @param r Right position, relative to parent |
| 13680 | * @param b Bottom position, relative to parent |
| 13681 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 13682 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 13683 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13684 | int oldL = mLeft; |
| 13685 | int oldT = mTop; |
| 13686 | int oldB = mBottom; |
| 13687 | int oldR = mRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13688 | boolean changed = setFrame(l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13689 | if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13690 | onLayout(changed, l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13691 | mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13692 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13693 | ListenerInfo li = mListenerInfo; |
| 13694 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13695 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 13696 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13697 | int numListeners = listenersCopy.size(); |
| 13698 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 13699 | 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] | 13700 | } |
| 13701 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13702 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13703 | mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13704 | } |
| 13705 | |
| 13706 | /** |
| 13707 | * Called from layout when this view should |
| 13708 | * assign a size and position to each of its children. |
| 13709 | * |
| 13710 | * Derived classes with children should override |
| 13711 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 13712 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13713 | * @param changed This is a new size or position for this view |
| 13714 | * @param left Left position, relative to parent |
| 13715 | * @param top Top position, relative to parent |
| 13716 | * @param right Right position, relative to parent |
| 13717 | * @param bottom Bottom position, relative to parent |
| 13718 | */ |
| 13719 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 13720 | } |
| 13721 | |
| 13722 | /** |
| 13723 | * Assign a size and position to this view. |
| 13724 | * |
| 13725 | * This is called from layout. |
| 13726 | * |
| 13727 | * @param left Left position, relative to parent |
| 13728 | * @param top Top position, relative to parent |
| 13729 | * @param right Right position, relative to parent |
| 13730 | * @param bottom Bottom position, relative to parent |
| 13731 | * @return true if the new size and position are different than the |
| 13732 | * previous ones |
| 13733 | * {@hide} |
| 13734 | */ |
| 13735 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 13736 | boolean changed = false; |
| 13737 | |
| 13738 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 13739 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13740 | + right + "," + bottom + ")"); |
| 13741 | } |
| 13742 | |
| 13743 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 13744 | changed = true; |
| 13745 | |
| 13746 | // Remember our drawn bit |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13747 | int drawn = mPrivateFlags & PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13748 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13749 | int oldWidth = mRight - mLeft; |
| 13750 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13751 | int newWidth = right - left; |
| 13752 | int newHeight = bottom - top; |
| 13753 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 13754 | |
| 13755 | // Invalidate our old position |
| 13756 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13757 | |
| 13758 | mLeft = left; |
| 13759 | mTop = top; |
| 13760 | mRight = right; |
| 13761 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13762 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13763 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 13764 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13765 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13766 | mPrivateFlags |= PFLAG_HAS_BOUNDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13768 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13769 | if (sizeChanged) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13770 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13771 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 13772 | if (mTransformationInfo != null) { |
| 13773 | mTransformationInfo.mMatrixDirty = true; |
| 13774 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13775 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13776 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 13777 | } |
| 13778 | |
| 13779 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 13780 | // If we are visible, force the DRAWN bit to on so that |
| 13781 | // this invalidate will go through (at least to our parent). |
| 13782 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 13783 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13784 | // the DRAWN bit. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13785 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 13786 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 13787 | // parent display list may need to be recreated based on a change in the bounds |
| 13788 | // of any child |
| 13789 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13790 | } |
| 13791 | |
| 13792 | // Reset drawn bit to original value (invalidate turns it off) |
| 13793 | mPrivateFlags |= drawn; |
| 13794 | |
| 13795 | mBackgroundSizeChanged = true; |
| 13796 | } |
| 13797 | return changed; |
| 13798 | } |
| 13799 | |
| 13800 | /** |
| 13801 | * Finalize inflating a view from XML. This is called as the last phase |
| 13802 | * of inflation, after all child views have been added. |
| 13803 | * |
| 13804 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 13805 | * sure to call the super method, so that we get called. |
| 13806 | */ |
| 13807 | protected void onFinishInflate() { |
| 13808 | } |
| 13809 | |
| 13810 | /** |
| 13811 | * Returns the resources associated with this view. |
| 13812 | * |
| 13813 | * @return Resources object. |
| 13814 | */ |
| 13815 | public Resources getResources() { |
| 13816 | return mResources; |
| 13817 | } |
| 13818 | |
| 13819 | /** |
| 13820 | * Invalidates the specified Drawable. |
| 13821 | * |
| 13822 | * @param drawable the drawable to invalidate |
| 13823 | */ |
| 13824 | public void invalidateDrawable(Drawable drawable) { |
| 13825 | if (verifyDrawable(drawable)) { |
| 13826 | final Rect dirty = drawable.getBounds(); |
| 13827 | final int scrollX = mScrollX; |
| 13828 | final int scrollY = mScrollY; |
| 13829 | |
| 13830 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 13831 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 13832 | } |
| 13833 | } |
| 13834 | |
| 13835 | /** |
| 13836 | * Schedules an action on a drawable to occur at a specified time. |
| 13837 | * |
| 13838 | * @param who the recipient of the action |
| 13839 | * @param what the action to run on the drawable |
| 13840 | * @param when the time at which the action must occur. Uses the |
| 13841 | * {@link SystemClock#uptimeMillis} timebase. |
| 13842 | */ |
| 13843 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13844 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13845 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13846 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13847 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 13848 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 13849 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13850 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 13851 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13853 | } |
| 13854 | } |
| 13855 | |
| 13856 | /** |
| 13857 | * Cancels a scheduled action on a drawable. |
| 13858 | * |
| 13859 | * @param who the recipient of the action |
| 13860 | * @param what the action to cancel |
| 13861 | */ |
| 13862 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13863 | if (verifyDrawable(who) && what != null) { |
| 13864 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13865 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13866 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 13867 | } else { |
| 13868 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 13869 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13870 | } |
| 13871 | } |
| 13872 | |
| 13873 | /** |
| 13874 | * Unschedule any events associated with the given Drawable. This can be |
| 13875 | * used when selecting a new Drawable into a view, so that the previous |
| 13876 | * one is completely unscheduled. |
| 13877 | * |
| 13878 | * @param who The Drawable to unschedule. |
| 13879 | * |
| 13880 | * @see #drawableStateChanged |
| 13881 | */ |
| 13882 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 13883 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 13884 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 13885 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13886 | } |
| 13887 | } |
| 13888 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 13889 | /** |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 13890 | * Resolve the Drawables depending on the layout direction. This is implicitly supposing |
| 13891 | * that the View directionality can and will be resolved before its Drawables. |
| 13892 | * |
| 13893 | * Will call {@link View#onResolveDrawables} when resolution is done. |
| 13894 | */ |
| 13895 | public void resolveDrawables() { |
| 13896 | if (mBackground != null) { |
| 13897 | mBackground.setLayoutDirection(getResolvedLayoutDirection()); |
| 13898 | } |
| 13899 | onResolveDrawables(getResolvedLayoutDirection()); |
| 13900 | } |
| 13901 | |
| 13902 | /** |
| 13903 | * Called when layout direction has been resolved. |
| 13904 | * |
| 13905 | * The default implementation does nothing. |
| 13906 | * |
| 13907 | * @param layoutDirection The resolved layout direction. |
| 13908 | * |
| 13909 | * @see {@link #LAYOUT_DIRECTION_LTR} |
| 13910 | * @see {@link #LAYOUT_DIRECTION_RTL} |
| 13911 | */ |
| 13912 | public void onResolveDrawables(int layoutDirection) { |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 13913 | } |
| 13914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13915 | /** |
| 13916 | * If your view subclass is displaying its own Drawable objects, it should |
| 13917 | * override this function and return true for any Drawable it is |
| 13918 | * displaying. This allows animations for those drawables to be |
| 13919 | * scheduled. |
| 13920 | * |
| 13921 | * <p>Be sure to call through to the super class when overriding this |
| 13922 | * function. |
| 13923 | * |
| 13924 | * @param who The Drawable to verify. Return true if it is one you are |
| 13925 | * displaying, else return the result of calling through to the |
| 13926 | * super class. |
| 13927 | * |
| 13928 | * @return boolean If true than the Drawable is being displayed in the |
| 13929 | * view; else false and it is not allowed to animate. |
| 13930 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13931 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 13932 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13933 | */ |
| 13934 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13935 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13936 | } |
| 13937 | |
| 13938 | /** |
| 13939 | * This function is called whenever the state of the view changes in such |
| 13940 | * a way that it impacts the state of drawables being shown. |
| 13941 | * |
| 13942 | * <p>Be sure to call through to the superclass when overriding this |
| 13943 | * function. |
| 13944 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13945 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13946 | */ |
| 13947 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13948 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13949 | if (d != null && d.isStateful()) { |
| 13950 | d.setState(getDrawableState()); |
| 13951 | } |
| 13952 | } |
| 13953 | |
| 13954 | /** |
| 13955 | * Call this to force a view to update its drawable state. This will cause |
| 13956 | * drawableStateChanged to be called on this view. Views that are interested |
| 13957 | * in the new state should call getDrawableState. |
| 13958 | * |
| 13959 | * @see #drawableStateChanged |
| 13960 | * @see #getDrawableState |
| 13961 | */ |
| 13962 | public void refreshDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13963 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13964 | drawableStateChanged(); |
| 13965 | |
| 13966 | ViewParent parent = mParent; |
| 13967 | if (parent != null) { |
| 13968 | parent.childDrawableStateChanged(this); |
| 13969 | } |
| 13970 | } |
| 13971 | |
| 13972 | /** |
| 13973 | * Return an array of resource IDs of the drawable states representing the |
| 13974 | * current state of the view. |
| 13975 | * |
| 13976 | * @return The current drawable state |
| 13977 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13978 | * @see Drawable#setState(int[]) |
| 13979 | * @see #drawableStateChanged() |
| 13980 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13981 | */ |
| 13982 | public final int[] getDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13983 | if ((mDrawableState != null) && ((mPrivateFlags & PFLAG_DRAWABLE_STATE_DIRTY) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13984 | return mDrawableState; |
| 13985 | } else { |
| 13986 | mDrawableState = onCreateDrawableState(0); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13987 | mPrivateFlags &= ~PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13988 | return mDrawableState; |
| 13989 | } |
| 13990 | } |
| 13991 | |
| 13992 | /** |
| 13993 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 13994 | * this view. This is called by the view |
| 13995 | * system when the cached Drawable state is determined to be invalid. To |
| 13996 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 13997 | * |
| 13998 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 13999 | * would like in the returned array in which you can place your own |
| 14000 | * states. |
| 14001 | * |
| 14002 | * @return Returns an array holding the current {@link Drawable} state of |
| 14003 | * the view. |
| 14004 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14005 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14006 | */ |
| 14007 | protected int[] onCreateDrawableState(int extraSpace) { |
| 14008 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 14009 | mParent instanceof View) { |
| 14010 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 14011 | } |
| 14012 | |
| 14013 | int[] drawableState; |
| 14014 | |
| 14015 | int privateFlags = mPrivateFlags; |
| 14016 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14017 | int viewStateIndex = 0; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14018 | if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14019 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 14020 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14021 | if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14022 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14023 | if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 14024 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 14025 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14026 | // This is set if HW acceleration is requested, even if the current |
| 14027 | // process doesn't allow it. This is just to allow app preview |
| 14028 | // windows to better match their app. |
| 14029 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 14030 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14031 | if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14032 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14033 | final int privateFlags2 = mPrivateFlags2; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14034 | if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 14035 | if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14037 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 14038 | |
| 14039 | //noinspection ConstantIfStatement |
| 14040 | if (false) { |
| 14041 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 14042 | Log.i("View", toString() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14043 | + " pressed=" + ((privateFlags & PFLAG_PRESSED) != 0) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14044 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 14045 | + " fo=" + hasFocus() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14046 | + " sl=" + ((privateFlags & PFLAG_SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14047 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14048 | + ": " + Arrays.toString(drawableState)); |
| 14049 | } |
| 14050 | |
| 14051 | if (extraSpace == 0) { |
| 14052 | return drawableState; |
| 14053 | } |
| 14054 | |
| 14055 | final int[] fullState; |
| 14056 | if (drawableState != null) { |
| 14057 | fullState = new int[drawableState.length + extraSpace]; |
| 14058 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 14059 | } else { |
| 14060 | fullState = new int[extraSpace]; |
| 14061 | } |
| 14062 | |
| 14063 | return fullState; |
| 14064 | } |
| 14065 | |
| 14066 | /** |
| 14067 | * Merge your own state values in <var>additionalState</var> into the base |
| 14068 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14069 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14070 | * |
| 14071 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14072 | * {@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] | 14073 | * own additional state values. |
| 14074 | * |
| 14075 | * @param additionalState The additional state values you would like |
| 14076 | * added to <var>baseState</var>; this array is not modified. |
| 14077 | * |
| 14078 | * @return As a convenience, the <var>baseState</var> array you originally |
| 14079 | * passed into the function is returned. |
| 14080 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14081 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14082 | */ |
| 14083 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 14084 | final int N = baseState.length; |
| 14085 | int i = N - 1; |
| 14086 | while (i >= 0 && baseState[i] == 0) { |
| 14087 | i--; |
| 14088 | } |
| 14089 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 14090 | return baseState; |
| 14091 | } |
| 14092 | |
| 14093 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14094 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 14095 | * on all Drawable objects associated with this view. |
| 14096 | */ |
| 14097 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14098 | if (mBackground != null) { |
| 14099 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14100 | } |
| 14101 | } |
| 14102 | |
| 14103 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14104 | * Sets the background color for this view. |
| 14105 | * @param color the color of the background |
| 14106 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14107 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14108 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14109 | if (mBackground instanceof ColorDrawable) { |
Romain Guy | 5f49c30 | 2012-09-06 16:33:31 -0700 | [diff] [blame^] | 14110 | ((ColorDrawable) mBackground.mutate()).setColor(color); |
Romain Guy | 7d3082a | 2012-07-11 17:52:54 -0700 | [diff] [blame] | 14111 | computeOpaqueFlags(); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14112 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14113 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14115 | } |
| 14116 | |
| 14117 | /** |
| 14118 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 14119 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14120 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14121 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14122 | * @attr ref android.R.styleable#View_background |
| 14123 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14124 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14125 | public void setBackgroundResource(int resid) { |
| 14126 | if (resid != 0 && resid == mBackgroundResource) { |
| 14127 | return; |
| 14128 | } |
| 14129 | |
| 14130 | Drawable d= null; |
| 14131 | if (resid != 0) { |
| 14132 | d = mResources.getDrawable(resid); |
| 14133 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14134 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14135 | |
| 14136 | mBackgroundResource = resid; |
| 14137 | } |
| 14138 | |
| 14139 | /** |
| 14140 | * Set the background to a given Drawable, or remove the background. If the |
| 14141 | * background has padding, this View's padding is set to the background's |
| 14142 | * padding. However, when a background is removed, this View's padding isn't |
| 14143 | * touched. If setting the padding is desired, please use |
| 14144 | * {@link #setPadding(int, int, int, int)}. |
| 14145 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14146 | * @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] | 14147 | * background |
| 14148 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14149 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14150 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14151 | setBackgroundDrawable(background); |
| 14152 | } |
| 14153 | |
| 14154 | /** |
| 14155 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 14156 | */ |
| 14157 | @Deprecated |
| 14158 | public void setBackgroundDrawable(Drawable background) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 14159 | computeOpaqueFlags(); |
| 14160 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14161 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 14162 | return; |
| 14163 | } |
| 14164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14165 | boolean requestLayout = false; |
| 14166 | |
| 14167 | mBackgroundResource = 0; |
| 14168 | |
| 14169 | /* |
| 14170 | * Regardless of whether we're setting a new background or not, we want |
| 14171 | * to clear the previous drawable. |
| 14172 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14173 | if (mBackground != null) { |
| 14174 | mBackground.setCallback(null); |
| 14175 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14176 | } |
| 14177 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14178 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14179 | Rect padding = sThreadLocal.get(); |
| 14180 | if (padding == null) { |
| 14181 | padding = new Rect(); |
| 14182 | sThreadLocal.set(padding); |
| 14183 | } |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14184 | background.setLayoutDirection(getResolvedLayoutDirection()); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14185 | if (background.getPadding(padding)) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14186 | // Reset padding resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14187 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14188 | switch (background.getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14189 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14190 | internalSetPadding(padding.right, padding.top, padding.left, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14191 | break; |
| 14192 | case LAYOUT_DIRECTION_LTR: |
| 14193 | default: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14194 | internalSetPadding(padding.left, padding.top, padding.right, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14195 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14196 | } |
| 14197 | |
| 14198 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 14199 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14200 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 14201 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14202 | requestLayout = true; |
| 14203 | } |
| 14204 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14205 | background.setCallback(this); |
| 14206 | if (background.isStateful()) { |
| 14207 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14208 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14209 | background.setVisible(getVisibility() == VISIBLE, false); |
| 14210 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14211 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14212 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { |
| 14213 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 14214 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14215 | requestLayout = true; |
| 14216 | } |
| 14217 | } else { |
| 14218 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14219 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14220 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14221 | if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14222 | /* |
| 14223 | * This view ONLY drew the background before and we're removing |
| 14224 | * the background, so now it won't draw anything |
| 14225 | * (hence we SKIP_DRAW) |
| 14226 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14227 | mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; |
| 14228 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14229 | } |
| 14230 | |
| 14231 | /* |
| 14232 | * When the background is set, we try to apply its padding to this |
| 14233 | * View. When the background is removed, we don't touch this View's |
| 14234 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 14235 | * requestLayout(), the invalidate() below is sufficient. |
| 14236 | */ |
| 14237 | |
| 14238 | // The old background's minimum size could have affected this |
| 14239 | // View's layout, so let's requestLayout |
| 14240 | requestLayout = true; |
| 14241 | } |
| 14242 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 14243 | computeOpaqueFlags(); |
| 14244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14245 | if (requestLayout) { |
| 14246 | requestLayout(); |
| 14247 | } |
| 14248 | |
| 14249 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14250 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14251 | } |
| 14252 | |
| 14253 | /** |
| 14254 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14255 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14256 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14257 | * |
| 14258 | * @see #setBackground(Drawable) |
| 14259 | * |
| 14260 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14261 | */ |
| 14262 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14263 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14264 | } |
| 14265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14266 | /** |
| 14267 | * Sets the padding. The view may add on the space required to display |
| 14268 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14269 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 14270 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 14271 | * from the values set in this call. |
| 14272 | * |
| 14273 | * @attr ref android.R.styleable#View_padding |
| 14274 | * @attr ref android.R.styleable#View_paddingBottom |
| 14275 | * @attr ref android.R.styleable#View_paddingLeft |
| 14276 | * @attr ref android.R.styleable#View_paddingRight |
| 14277 | * @attr ref android.R.styleable#View_paddingTop |
| 14278 | * @param left the left padding in pixels |
| 14279 | * @param top the top padding in pixels |
| 14280 | * @param right the right padding in pixels |
| 14281 | * @param bottom the bottom padding in pixels |
| 14282 | */ |
| 14283 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14284 | // Reset padding resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14285 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14286 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14287 | mUserPaddingStart = UNDEFINED_PADDING; |
| 14288 | mUserPaddingEnd = UNDEFINED_PADDING; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14289 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14290 | internalSetPadding(left, top, right, bottom); |
| 14291 | } |
| 14292 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14293 | /** |
| 14294 | * @hide |
| 14295 | */ |
| 14296 | protected void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14297 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14298 | mUserPaddingRight = right; |
| 14299 | mUserPaddingBottom = bottom; |
| 14300 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14301 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14302 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14303 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14304 | // Common case is there are no scroll bars. |
| 14305 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14306 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14307 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14308 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14309 | switch (mVerticalScrollbarPosition) { |
| 14310 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 14311 | if (isLayoutRtl()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14312 | left += offset; |
| 14313 | } else { |
| 14314 | right += offset; |
| 14315 | } |
| 14316 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14317 | case SCROLLBAR_POSITION_RIGHT: |
| 14318 | right += offset; |
| 14319 | break; |
| 14320 | case SCROLLBAR_POSITION_LEFT: |
| 14321 | left += offset; |
| 14322 | break; |
| 14323 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14324 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14325 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14326 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 14327 | ? 0 : getHorizontalScrollbarHeight(); |
| 14328 | } |
| 14329 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14330 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14331 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14332 | changed = true; |
| 14333 | mPaddingLeft = left; |
| 14334 | } |
| 14335 | if (mPaddingTop != top) { |
| 14336 | changed = true; |
| 14337 | mPaddingTop = top; |
| 14338 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14339 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14340 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14341 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14342 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14343 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14344 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14345 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14346 | } |
| 14347 | |
| 14348 | if (changed) { |
| 14349 | requestLayout(); |
| 14350 | } |
| 14351 | } |
| 14352 | |
| 14353 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14354 | * Sets the relative padding. The view may add on the space required to display |
| 14355 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14356 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 14357 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 14358 | * from the values set in this call. |
| 14359 | * |
| 14360 | * @attr ref android.R.styleable#View_padding |
| 14361 | * @attr ref android.R.styleable#View_paddingBottom |
| 14362 | * @attr ref android.R.styleable#View_paddingStart |
| 14363 | * @attr ref android.R.styleable#View_paddingEnd |
| 14364 | * @attr ref android.R.styleable#View_paddingTop |
| 14365 | * @param start the start padding in pixels |
| 14366 | * @param top the top padding in pixels |
| 14367 | * @param end the end padding in pixels |
| 14368 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14369 | */ |
| 14370 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14371 | // Reset padding resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14372 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14373 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 14374 | mUserPaddingStart = start; |
| 14375 | mUserPaddingEnd = end; |
| 14376 | |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14377 | switch(getResolvedLayoutDirection()) { |
| 14378 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14379 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14380 | break; |
| 14381 | case LAYOUT_DIRECTION_LTR: |
| 14382 | default: |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14383 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14384 | } |
| 14385 | } |
| 14386 | |
| 14387 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14388 | * Returns the top padding of this view. |
| 14389 | * |
| 14390 | * @return the top padding in pixels |
| 14391 | */ |
| 14392 | public int getPaddingTop() { |
| 14393 | return mPaddingTop; |
| 14394 | } |
| 14395 | |
| 14396 | /** |
| 14397 | * Returns the bottom padding of this view. If there are inset and enabled |
| 14398 | * scrollbars, this value may include the space required to display the |
| 14399 | * scrollbars as well. |
| 14400 | * |
| 14401 | * @return the bottom padding in pixels |
| 14402 | */ |
| 14403 | public int getPaddingBottom() { |
| 14404 | return mPaddingBottom; |
| 14405 | } |
| 14406 | |
| 14407 | /** |
| 14408 | * Returns the left padding of this view. If there are inset and enabled |
| 14409 | * scrollbars, this value may include the space required to display the |
| 14410 | * scrollbars as well. |
| 14411 | * |
| 14412 | * @return the left padding in pixels |
| 14413 | */ |
| 14414 | public int getPaddingLeft() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14415 | if (!isPaddingResolved()) { |
| 14416 | resolvePadding(); |
| 14417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14418 | return mPaddingLeft; |
| 14419 | } |
| 14420 | |
| 14421 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14422 | * Returns the start padding of this view depending on its resolved layout direction. |
| 14423 | * If there are inset and enabled scrollbars, this value may include the space |
| 14424 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14425 | * |
| 14426 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14427 | */ |
| 14428 | public int getPaddingStart() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14429 | if (!isPaddingResolved()) { |
| 14430 | resolvePadding(); |
| 14431 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14432 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 14433 | mPaddingRight : mPaddingLeft; |
| 14434 | } |
| 14435 | |
| 14436 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14437 | * Returns the right padding of this view. If there are inset and enabled |
| 14438 | * scrollbars, this value may include the space required to display the |
| 14439 | * scrollbars as well. |
| 14440 | * |
| 14441 | * @return the right padding in pixels |
| 14442 | */ |
| 14443 | public int getPaddingRight() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14444 | if (!isPaddingResolved()) { |
| 14445 | resolvePadding(); |
| 14446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14447 | return mPaddingRight; |
| 14448 | } |
| 14449 | |
| 14450 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14451 | * Returns the end padding of this view depending on its resolved layout direction. |
| 14452 | * If there are inset and enabled scrollbars, this value may include the space |
| 14453 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14454 | * |
| 14455 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14456 | */ |
| 14457 | public int getPaddingEnd() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14458 | if (!isPaddingResolved()) { |
| 14459 | resolvePadding(); |
| 14460 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14461 | return (getResolvedLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
| 14462 | mPaddingLeft : mPaddingRight; |
| 14463 | } |
| 14464 | |
| 14465 | /** |
| 14466 | * Return if the padding as been set thru relative values |
| 14467 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 14468 | * @attr ref android.R.styleable#View_paddingStart or |
| 14469 | * @attr ref android.R.styleable#View_paddingEnd |
| 14470 | * |
| 14471 | * @return true if the padding is relative or false if it is not. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14472 | */ |
| 14473 | public boolean isPaddingRelative() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14474 | return (mUserPaddingStart != UNDEFINED_PADDING || mUserPaddingEnd != UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14475 | } |
| 14476 | |
| 14477 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14478 | * @hide |
| 14479 | */ |
Philip Milne | 7a23b49 | 2012-04-24 22:12:36 -0700 | [diff] [blame] | 14480 | public Insets getOpticalInsets() { |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14481 | if (mLayoutInsets == null) { |
Philip Milne | bbd51f1 | 2012-04-18 15:09:05 -0700 | [diff] [blame] | 14482 | mLayoutInsets = (mBackground == null) ? Insets.NONE : mBackground.getLayoutInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14483 | } |
| 14484 | return mLayoutInsets; |
| 14485 | } |
| 14486 | |
| 14487 | /** |
| 14488 | * @hide |
| 14489 | */ |
| 14490 | public void setLayoutInsets(Insets layoutInsets) { |
| 14491 | mLayoutInsets = layoutInsets; |
| 14492 | } |
| 14493 | |
| 14494 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14495 | * Changes the selection state of this view. A view can be selected or not. |
| 14496 | * Note that selection is not the same as focus. Views are typically |
| 14497 | * selected in the context of an AdapterView like ListView or GridView; |
| 14498 | * the selected view is the view that is highlighted. |
| 14499 | * |
| 14500 | * @param selected true if the view must be selected, false otherwise |
| 14501 | */ |
| 14502 | public void setSelected(boolean selected) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14503 | if (((mPrivateFlags & PFLAG_SELECTED) != 0) != selected) { |
| 14504 | mPrivateFlags = (mPrivateFlags & ~PFLAG_SELECTED) | (selected ? PFLAG_SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 14505 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14506 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14507 | refreshDrawableState(); |
| 14508 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14509 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 14510 | notifyAccessibilityStateChanged(); |
| 14511 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14512 | } |
| 14513 | } |
| 14514 | |
| 14515 | /** |
| 14516 | * Dispatch setSelected to all of this View's children. |
| 14517 | * |
| 14518 | * @see #setSelected(boolean) |
| 14519 | * |
| 14520 | * @param selected The new selected state |
| 14521 | */ |
| 14522 | protected void dispatchSetSelected(boolean selected) { |
| 14523 | } |
| 14524 | |
| 14525 | /** |
| 14526 | * Indicates the selection state of this view. |
| 14527 | * |
| 14528 | * @return true if the view is selected, false otherwise |
| 14529 | */ |
| 14530 | @ViewDebug.ExportedProperty |
| 14531 | public boolean isSelected() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14532 | return (mPrivateFlags & PFLAG_SELECTED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14533 | } |
| 14534 | |
| 14535 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14536 | * Changes the activated state of this view. A view can be activated or not. |
| 14537 | * Note that activation is not the same as selection. Selection is |
| 14538 | * a transient property, representing the view (hierarchy) the user is |
| 14539 | * currently interacting with. Activation is a longer-term state that the |
| 14540 | * user can move views in and out of. For example, in a list view with |
| 14541 | * single or multiple selection enabled, the views in the current selection |
| 14542 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 14543 | * here.) The activated state is propagated down to children of the view it |
| 14544 | * is set on. |
| 14545 | * |
| 14546 | * @param activated true if the view must be activated, false otherwise |
| 14547 | */ |
| 14548 | public void setActivated(boolean activated) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14549 | if (((mPrivateFlags & PFLAG_ACTIVATED) != 0) != activated) { |
| 14550 | mPrivateFlags = (mPrivateFlags & ~PFLAG_ACTIVATED) | (activated ? PFLAG_ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14551 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14552 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 14553 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14554 | } |
| 14555 | } |
| 14556 | |
| 14557 | /** |
| 14558 | * Dispatch setActivated to all of this View's children. |
| 14559 | * |
| 14560 | * @see #setActivated(boolean) |
| 14561 | * |
| 14562 | * @param activated The new activated state |
| 14563 | */ |
| 14564 | protected void dispatchSetActivated(boolean activated) { |
| 14565 | } |
| 14566 | |
| 14567 | /** |
| 14568 | * Indicates the activation state of this view. |
| 14569 | * |
| 14570 | * @return true if the view is activated, false otherwise |
| 14571 | */ |
| 14572 | @ViewDebug.ExportedProperty |
| 14573 | public boolean isActivated() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14574 | return (mPrivateFlags & PFLAG_ACTIVATED) != 0; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14575 | } |
| 14576 | |
| 14577 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14578 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 14579 | * observer can be used to get notifications when global events, like |
| 14580 | * layout, happen. |
| 14581 | * |
| 14582 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 14583 | * valid for the lifetime of this View. If the caller of this method keeps |
| 14584 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 14585 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 14586 | * |
| 14587 | * @return The ViewTreeObserver for this view's hierarchy. |
| 14588 | */ |
| 14589 | public ViewTreeObserver getViewTreeObserver() { |
| 14590 | if (mAttachInfo != null) { |
| 14591 | return mAttachInfo.mTreeObserver; |
| 14592 | } |
| 14593 | if (mFloatingTreeObserver == null) { |
| 14594 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 14595 | } |
| 14596 | return mFloatingTreeObserver; |
| 14597 | } |
| 14598 | |
| 14599 | /** |
| 14600 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 14601 | * |
| 14602 | * @return the topmost view containing this view |
| 14603 | */ |
| 14604 | public View getRootView() { |
| 14605 | if (mAttachInfo != null) { |
| 14606 | final View v = mAttachInfo.mRootView; |
| 14607 | if (v != null) { |
| 14608 | return v; |
| 14609 | } |
| 14610 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14612 | View parent = this; |
| 14613 | |
| 14614 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 14615 | parent = (View) parent.mParent; |
| 14616 | } |
| 14617 | |
| 14618 | return parent; |
| 14619 | } |
| 14620 | |
| 14621 | /** |
| 14622 | * <p>Computes the coordinates of this view on the screen. The argument |
| 14623 | * must be an array of two integers. After the method returns, the array |
| 14624 | * contains the x and y location in that order.</p> |
| 14625 | * |
| 14626 | * @param location an array of two integers in which to hold the coordinates |
| 14627 | */ |
| 14628 | public void getLocationOnScreen(int[] location) { |
| 14629 | getLocationInWindow(location); |
| 14630 | |
| 14631 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 14632 | if (info != null) { |
| 14633 | location[0] += info.mWindowLeft; |
| 14634 | location[1] += info.mWindowTop; |
| 14635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14636 | } |
| 14637 | |
| 14638 | /** |
| 14639 | * <p>Computes the coordinates of this view in its window. The argument |
| 14640 | * must be an array of two integers. After the method returns, the array |
| 14641 | * contains the x and y location in that order.</p> |
| 14642 | * |
| 14643 | * @param location an array of two integers in which to hold the coordinates |
| 14644 | */ |
| 14645 | public void getLocationInWindow(int[] location) { |
| 14646 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14647 | 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] | 14648 | } |
| 14649 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 14650 | if (mAttachInfo == null) { |
| 14651 | // When the view is not attached to a window, this method does not make sense |
| 14652 | location[0] = location[1] = 0; |
| 14653 | return; |
| 14654 | } |
| 14655 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14656 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 14657 | position[0] = position[1] = 0.0f; |
| 14658 | |
| 14659 | if (!hasIdentityMatrix()) { |
| 14660 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14661 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14662 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14663 | position[0] += mLeft; |
| 14664 | position[1] += mTop; |
| 14665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14666 | ViewParent viewParent = mParent; |
| 14667 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14668 | final View view = (View) viewParent; |
| 14669 | |
| 14670 | position[0] -= view.mScrollX; |
| 14671 | position[1] -= view.mScrollY; |
| 14672 | |
| 14673 | if (!view.hasIdentityMatrix()) { |
| 14674 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14675 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14676 | |
| 14677 | position[0] += view.mLeft; |
| 14678 | position[1] += view.mTop; |
| 14679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14680 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14681 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14682 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 14683 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14684 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14685 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 14686 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14687 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 14688 | |
| 14689 | location[0] = (int) (position[0] + 0.5f); |
| 14690 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14691 | } |
| 14692 | |
| 14693 | /** |
| 14694 | * {@hide} |
| 14695 | * @param id the id of the view to be found |
| 14696 | * @return the view of the specified id, null if cannot be found |
| 14697 | */ |
| 14698 | protected View findViewTraversal(int id) { |
| 14699 | if (id == mID) { |
| 14700 | return this; |
| 14701 | } |
| 14702 | return null; |
| 14703 | } |
| 14704 | |
| 14705 | /** |
| 14706 | * {@hide} |
| 14707 | * @param tag the tag of the view to be found |
| 14708 | * @return the view of specified tag, null if cannot be found |
| 14709 | */ |
| 14710 | protected View findViewWithTagTraversal(Object tag) { |
| 14711 | if (tag != null && tag.equals(mTag)) { |
| 14712 | return this; |
| 14713 | } |
| 14714 | return null; |
| 14715 | } |
| 14716 | |
| 14717 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14718 | * {@hide} |
| 14719 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14720 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14721 | * @return The first view that matches the predicate or null. |
| 14722 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14723 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14724 | if (predicate.apply(this)) { |
| 14725 | return this; |
| 14726 | } |
| 14727 | return null; |
| 14728 | } |
| 14729 | |
| 14730 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14731 | * Look for a child view with the given id. If this view has the given |
| 14732 | * id, return this view. |
| 14733 | * |
| 14734 | * @param id The id to search for. |
| 14735 | * @return The view that has the given id in the hierarchy or null |
| 14736 | */ |
| 14737 | public final View findViewById(int id) { |
| 14738 | if (id < 0) { |
| 14739 | return null; |
| 14740 | } |
| 14741 | return findViewTraversal(id); |
| 14742 | } |
| 14743 | |
| 14744 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 14745 | * Finds a view by its unuque and stable accessibility id. |
| 14746 | * |
| 14747 | * @param accessibilityId The searched accessibility id. |
| 14748 | * @return The found view. |
| 14749 | */ |
| 14750 | final View findViewByAccessibilityId(int accessibilityId) { |
| 14751 | if (accessibilityId < 0) { |
| 14752 | return null; |
| 14753 | } |
| 14754 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 14755 | } |
| 14756 | |
| 14757 | /** |
| 14758 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 14759 | * |
| 14760 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 14761 | * boundary since the user can touch the screen at an arbitrary location |
| 14762 | * potentially crossing the root namespace bounday which will send an |
| 14763 | * accessibility event to accessibility services and they should be able |
| 14764 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 14765 | * unique in the window. |
| 14766 | * |
| 14767 | * @param accessibilityId The accessibility id. |
| 14768 | * @return The found view. |
| 14769 | */ |
| 14770 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 14771 | if (getAccessibilityViewId() == accessibilityId) { |
| 14772 | return this; |
| 14773 | } |
| 14774 | return null; |
| 14775 | } |
| 14776 | |
| 14777 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14778 | * Look for a child view with the given tag. If this view has the given |
| 14779 | * tag, return this view. |
| 14780 | * |
| 14781 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 14782 | * @return The View that has the given tag in the hierarchy or null |
| 14783 | */ |
| 14784 | public final View findViewWithTag(Object tag) { |
| 14785 | if (tag == null) { |
| 14786 | return null; |
| 14787 | } |
| 14788 | return findViewWithTagTraversal(tag); |
| 14789 | } |
| 14790 | |
| 14791 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14792 | * {@hide} |
| 14793 | * Look for a child view that matches the specified predicate. |
| 14794 | * If this view matches the predicate, return this view. |
| 14795 | * |
| 14796 | * @param predicate The predicate to evaluate. |
| 14797 | * @return The first view that matches the predicate or null. |
| 14798 | */ |
| 14799 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 14800 | return findViewByPredicateTraversal(predicate, null); |
| 14801 | } |
| 14802 | |
| 14803 | /** |
| 14804 | * {@hide} |
| 14805 | * Look for a child view that matches the specified predicate, |
| 14806 | * starting with the specified view and its descendents and then |
| 14807 | * recusively searching the ancestors and siblings of that view |
| 14808 | * until this view is reached. |
| 14809 | * |
| 14810 | * This method is useful in cases where the predicate does not match |
| 14811 | * a single unique view (perhaps multiple views use the same id) |
| 14812 | * and we are trying to find the view that is "closest" in scope to the |
| 14813 | * starting view. |
| 14814 | * |
| 14815 | * @param start The view to start from. |
| 14816 | * @param predicate The predicate to evaluate. |
| 14817 | * @return The first view that matches the predicate or null. |
| 14818 | */ |
| 14819 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 14820 | View childToSkip = null; |
| 14821 | for (;;) { |
| 14822 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 14823 | if (view != null || start == this) { |
| 14824 | return view; |
| 14825 | } |
| 14826 | |
| 14827 | ViewParent parent = start.getParent(); |
| 14828 | if (parent == null || !(parent instanceof View)) { |
| 14829 | return null; |
| 14830 | } |
| 14831 | |
| 14832 | childToSkip = start; |
| 14833 | start = (View) parent; |
| 14834 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 14835 | } |
| 14836 | |
| 14837 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14838 | * Sets the identifier for this view. The identifier does not have to be |
| 14839 | * unique in this view's hierarchy. The identifier should be a positive |
| 14840 | * number. |
| 14841 | * |
| 14842 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14843 | * @see #getId() |
| 14844 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14845 | * |
| 14846 | * @param id a number used to identify the view |
| 14847 | * |
| 14848 | * @attr ref android.R.styleable#View_id |
| 14849 | */ |
| 14850 | public void setId(int id) { |
| 14851 | mID = id; |
| 14852 | } |
| 14853 | |
| 14854 | /** |
| 14855 | * {@hide} |
| 14856 | * |
| 14857 | * @param isRoot true if the view belongs to the root namespace, false |
| 14858 | * otherwise |
| 14859 | */ |
| 14860 | public void setIsRootNamespace(boolean isRoot) { |
| 14861 | if (isRoot) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14862 | mPrivateFlags |= PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14863 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14864 | mPrivateFlags &= ~PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14865 | } |
| 14866 | } |
| 14867 | |
| 14868 | /** |
| 14869 | * {@hide} |
| 14870 | * |
| 14871 | * @return true if the view belongs to the root namespace, false otherwise |
| 14872 | */ |
| 14873 | public boolean isRootNamespace() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14874 | return (mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14875 | } |
| 14876 | |
| 14877 | /** |
| 14878 | * Returns this view's identifier. |
| 14879 | * |
| 14880 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 14881 | * if the view has no ID |
| 14882 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14883 | * @see #setId(int) |
| 14884 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14885 | * @attr ref android.R.styleable#View_id |
| 14886 | */ |
| 14887 | @ViewDebug.CapturedViewProperty |
| 14888 | public int getId() { |
| 14889 | return mID; |
| 14890 | } |
| 14891 | |
| 14892 | /** |
| 14893 | * Returns this view's tag. |
| 14894 | * |
| 14895 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14896 | * |
| 14897 | * @see #setTag(Object) |
| 14898 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14899 | */ |
| 14900 | @ViewDebug.ExportedProperty |
| 14901 | public Object getTag() { |
| 14902 | return mTag; |
| 14903 | } |
| 14904 | |
| 14905 | /** |
| 14906 | * Sets the tag associated with this view. A tag can be used to mark |
| 14907 | * a view in its hierarchy and does not have to be unique within the |
| 14908 | * hierarchy. Tags can also be used to store data within a view without |
| 14909 | * resorting to another data structure. |
| 14910 | * |
| 14911 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14912 | * |
| 14913 | * @see #getTag() |
| 14914 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14915 | */ |
| 14916 | public void setTag(final Object tag) { |
| 14917 | mTag = tag; |
| 14918 | } |
| 14919 | |
| 14920 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14921 | * Returns the tag associated with this view and the specified key. |
| 14922 | * |
| 14923 | * @param key The key identifying the tag |
| 14924 | * |
| 14925 | * @return the Object stored in this view as a tag |
| 14926 | * |
| 14927 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14928 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14929 | */ |
| 14930 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14931 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14932 | return null; |
| 14933 | } |
| 14934 | |
| 14935 | /** |
| 14936 | * Sets a tag associated with this view and a key. A tag can be used |
| 14937 | * to mark a view in its hierarchy and does not have to be unique within |
| 14938 | * the hierarchy. Tags can also be used to store data within a view |
| 14939 | * without resorting to another data structure. |
| 14940 | * |
| 14941 | * 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] | 14942 | * application to ensure it is unique (see the <a |
| 14943 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 14944 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14945 | * the Android framework or not associated with any package will cause |
| 14946 | * an {@link IllegalArgumentException} to be thrown. |
| 14947 | * |
| 14948 | * @param key The key identifying the tag |
| 14949 | * @param tag An Object to tag the view with |
| 14950 | * |
| 14951 | * @throws IllegalArgumentException If they specified key is not valid |
| 14952 | * |
| 14953 | * @see #setTag(Object) |
| 14954 | * @see #getTag(int) |
| 14955 | */ |
| 14956 | public void setTag(int key, final Object tag) { |
| 14957 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 14958 | // or a framework id |
| 14959 | if ((key >>> 24) < 2) { |
| 14960 | throw new IllegalArgumentException("The key must be an application-specific " |
| 14961 | + "resource id."); |
| 14962 | } |
| 14963 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14964 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14965 | } |
| 14966 | |
| 14967 | /** |
| 14968 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 14969 | * framework id. |
| 14970 | * |
| 14971 | * @hide |
| 14972 | */ |
| 14973 | public void setTagInternal(int key, Object tag) { |
| 14974 | if ((key >>> 24) != 0x1) { |
| 14975 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 14976 | + "resource id."); |
| 14977 | } |
| 14978 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14979 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14980 | } |
| 14981 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 14982 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14983 | if (mKeyedTags == null) { |
| 14984 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14985 | } |
| 14986 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 14987 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 14988 | } |
| 14989 | |
| 14990 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14991 | * Prints information about this view in the log output, with the tag |
| 14992 | * {@link #VIEW_LOG_TAG}. |
| 14993 | * |
| 14994 | * @hide |
| 14995 | */ |
| 14996 | public void debug() { |
| 14997 | debug(0); |
| 14998 | } |
| 14999 | |
| 15000 | /** |
| 15001 | * Prints information about this view in the log output, with the tag |
| 15002 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 15003 | * indentation defined by the <code>depth</code>. |
| 15004 | * |
| 15005 | * @param depth the indentation level |
| 15006 | * |
| 15007 | * @hide |
| 15008 | */ |
| 15009 | protected void debug(int depth) { |
| 15010 | String output = debugIndent(depth - 1); |
| 15011 | |
| 15012 | output += "+ " + this; |
| 15013 | int id = getId(); |
| 15014 | if (id != -1) { |
| 15015 | output += " (id=" + id + ")"; |
| 15016 | } |
| 15017 | Object tag = getTag(); |
| 15018 | if (tag != null) { |
| 15019 | output += " (tag=" + tag + ")"; |
| 15020 | } |
| 15021 | Log.d(VIEW_LOG_TAG, output); |
| 15022 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15023 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15024 | output = debugIndent(depth) + " FOCUSED"; |
| 15025 | Log.d(VIEW_LOG_TAG, output); |
| 15026 | } |
| 15027 | |
| 15028 | output = debugIndent(depth); |
| 15029 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 15030 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 15031 | + "} "; |
| 15032 | Log.d(VIEW_LOG_TAG, output); |
| 15033 | |
| 15034 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 15035 | || mPaddingBottom != 0) { |
| 15036 | output = debugIndent(depth); |
| 15037 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 15038 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 15039 | Log.d(VIEW_LOG_TAG, output); |
| 15040 | } |
| 15041 | |
| 15042 | output = debugIndent(depth); |
| 15043 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 15044 | " mMeasureHeight=" + mMeasuredHeight; |
| 15045 | Log.d(VIEW_LOG_TAG, output); |
| 15046 | |
| 15047 | output = debugIndent(depth); |
| 15048 | if (mLayoutParams == null) { |
| 15049 | output += "BAD! no layout params"; |
| 15050 | } else { |
| 15051 | output = mLayoutParams.debug(output); |
| 15052 | } |
| 15053 | Log.d(VIEW_LOG_TAG, output); |
| 15054 | |
| 15055 | output = debugIndent(depth); |
| 15056 | output += "flags={"; |
| 15057 | output += View.printFlags(mViewFlags); |
| 15058 | output += "}"; |
| 15059 | Log.d(VIEW_LOG_TAG, output); |
| 15060 | |
| 15061 | output = debugIndent(depth); |
| 15062 | output += "privateFlags={"; |
| 15063 | output += View.printPrivateFlags(mPrivateFlags); |
| 15064 | output += "}"; |
| 15065 | Log.d(VIEW_LOG_TAG, output); |
| 15066 | } |
| 15067 | |
| 15068 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 15069 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15070 | * |
| 15071 | * @param depth the indentation level |
| 15072 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 15073 | * |
| 15074 | * @hide |
| 15075 | */ |
| 15076 | protected static String debugIndent(int depth) { |
| 15077 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 15078 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 15079 | spaces.append(' ').append(' '); |
| 15080 | } |
| 15081 | return spaces.toString(); |
| 15082 | } |
| 15083 | |
| 15084 | /** |
| 15085 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 15086 | * boundary. If this widget does not support baseline alignment, this |
| 15087 | * method returns -1. </p> |
| 15088 | * |
| 15089 | * @return the offset of the baseline within the widget's bounds or -1 |
| 15090 | * if baseline alignment is not supported |
| 15091 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 15092 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15093 | public int getBaseline() { |
| 15094 | return -1; |
| 15095 | } |
| 15096 | |
| 15097 | /** |
| 15098 | * Call this when something has changed which has invalidated the |
| 15099 | * layout of this view. This will schedule a layout pass of the view |
| 15100 | * tree. |
| 15101 | */ |
| 15102 | public void requestLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15103 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15104 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15105 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 15106 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 15107 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15108 | } |
| 15109 | } |
| 15110 | |
| 15111 | /** |
| 15112 | * Forces this view to be laid out during the next layout pass. |
| 15113 | * This method does not call requestLayout() or forceLayout() |
| 15114 | * on the parent. |
| 15115 | */ |
| 15116 | public void forceLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15117 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15118 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15119 | } |
| 15120 | |
| 15121 | /** |
| 15122 | * <p> |
| 15123 | * This is called to find out how big a view should be. The parent |
| 15124 | * supplies constraint information in the width and height parameters. |
| 15125 | * </p> |
| 15126 | * |
| 15127 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15128 | * 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] | 15129 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15130 | * {@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] | 15131 | * </p> |
| 15132 | * |
| 15133 | * |
| 15134 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 15135 | * parent |
| 15136 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 15137 | * parent |
| 15138 | * |
| 15139 | * @see #onMeasure(int, int) |
| 15140 | */ |
| 15141 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15142 | if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15143 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 15144 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 15145 | |
| 15146 | // first clears the measured dimension flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15147 | mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15148 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 15149 | if (!isPaddingResolved()) { |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 15150 | resolvePadding(); |
| 15151 | } |
| 15152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15153 | // measure ourselves, this should set the measured dimension flag back |
| 15154 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 15155 | |
| 15156 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 15157 | // an exception to warn the developer |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15158 | if ((mPrivateFlags & PFLAG_MEASURED_DIMENSION_SET) != PFLAG_MEASURED_DIMENSION_SET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15159 | throw new IllegalStateException("onMeasure() did not set the" |
| 15160 | + " measured dimension by calling" |
| 15161 | + " setMeasuredDimension()"); |
| 15162 | } |
| 15163 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15164 | mPrivateFlags |= PFLAG_LAYOUT_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15165 | } |
| 15166 | |
| 15167 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 15168 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 15169 | } |
| 15170 | |
| 15171 | /** |
| 15172 | * <p> |
| 15173 | * Measure the view and its content to determine the measured width and the |
| 15174 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 15175 | * should be overriden by subclasses to provide accurate and efficient |
| 15176 | * measurement of their contents. |
| 15177 | * </p> |
| 15178 | * |
| 15179 | * <p> |
| 15180 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 15181 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 15182 | * measured width and height of this view. Failure to do so will trigger an |
| 15183 | * <code>IllegalStateException</code>, thrown by |
| 15184 | * {@link #measure(int, int)}. Calling the superclass' |
| 15185 | * {@link #onMeasure(int, int)} is a valid use. |
| 15186 | * </p> |
| 15187 | * |
| 15188 | * <p> |
| 15189 | * The base class implementation of measure defaults to the background size, |
| 15190 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 15191 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 15192 | * their content. |
| 15193 | * </p> |
| 15194 | * |
| 15195 | * <p> |
| 15196 | * If this method is overridden, it is the subclass's responsibility to make |
| 15197 | * sure the measured height and width are at least the view's minimum height |
| 15198 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 15199 | * {@link #getSuggestedMinimumWidth()}). |
| 15200 | * </p> |
| 15201 | * |
| 15202 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 15203 | * The requirements are encoded with |
| 15204 | * {@link android.view.View.MeasureSpec}. |
| 15205 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 15206 | * The requirements are encoded with |
| 15207 | * {@link android.view.View.MeasureSpec}. |
| 15208 | * |
| 15209 | * @see #getMeasuredWidth() |
| 15210 | * @see #getMeasuredHeight() |
| 15211 | * @see #setMeasuredDimension(int, int) |
| 15212 | * @see #getSuggestedMinimumHeight() |
| 15213 | * @see #getSuggestedMinimumWidth() |
| 15214 | * @see android.view.View.MeasureSpec#getMode(int) |
| 15215 | * @see android.view.View.MeasureSpec#getSize(int) |
| 15216 | */ |
| 15217 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 15218 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 15219 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 15220 | } |
| 15221 | |
| 15222 | /** |
| 15223 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 15224 | * measured width and measured height. Failing to do so will trigger an |
| 15225 | * exception at measurement time.</p> |
| 15226 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15227 | * @param measuredWidth The measured width of this view. May be a complex |
| 15228 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15229 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 15230 | * @param measuredHeight The measured height of this view. May be a complex |
| 15231 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15232 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15233 | */ |
| 15234 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
| 15235 | mMeasuredWidth = measuredWidth; |
| 15236 | mMeasuredHeight = measuredHeight; |
| 15237 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15238 | mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15239 | } |
| 15240 | |
| 15241 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15242 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 15243 | * @param curState The current state as returned from a view or the result |
| 15244 | * of combining multiple views. |
| 15245 | * @param newState The new view state to combine. |
| 15246 | * @return Returns a new integer reflecting the combination of the two |
| 15247 | * states. |
| 15248 | */ |
| 15249 | public static int combineMeasuredStates(int curState, int newState) { |
| 15250 | return curState | newState; |
| 15251 | } |
| 15252 | |
| 15253 | /** |
| 15254 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 15255 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 15256 | */ |
| 15257 | public static int resolveSize(int size, int measureSpec) { |
| 15258 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 15259 | } |
| 15260 | |
| 15261 | /** |
| 15262 | * Utility to reconcile a desired size and state, with constraints imposed |
| 15263 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 15264 | * is imposed by the constraints. The returned value is a compound integer, |
| 15265 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 15266 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 15267 | * 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] | 15268 | * |
| 15269 | * @param size How big the view wants to be |
| 15270 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15271 | * @return Size information bit mask as defined by |
| 15272 | * {@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] | 15273 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15274 | 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] | 15275 | int result = size; |
| 15276 | int specMode = MeasureSpec.getMode(measureSpec); |
| 15277 | int specSize = MeasureSpec.getSize(measureSpec); |
| 15278 | switch (specMode) { |
| 15279 | case MeasureSpec.UNSPECIFIED: |
| 15280 | result = size; |
| 15281 | break; |
| 15282 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15283 | if (specSize < size) { |
| 15284 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 15285 | } else { |
| 15286 | result = size; |
| 15287 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15288 | break; |
| 15289 | case MeasureSpec.EXACTLY: |
| 15290 | result = specSize; |
| 15291 | break; |
| 15292 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15293 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15294 | } |
| 15295 | |
| 15296 | /** |
| 15297 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15298 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15299 | * by the MeasureSpec. |
| 15300 | * |
| 15301 | * @param size Default size for this view |
| 15302 | * @param measureSpec Constraints imposed by the parent |
| 15303 | * @return The size this view should be. |
| 15304 | */ |
| 15305 | public static int getDefaultSize(int size, int measureSpec) { |
| 15306 | int result = size; |
| 15307 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15308 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15309 | |
| 15310 | switch (specMode) { |
| 15311 | case MeasureSpec.UNSPECIFIED: |
| 15312 | result = size; |
| 15313 | break; |
| 15314 | case MeasureSpec.AT_MOST: |
| 15315 | case MeasureSpec.EXACTLY: |
| 15316 | result = specSize; |
| 15317 | break; |
| 15318 | } |
| 15319 | return result; |
| 15320 | } |
| 15321 | |
| 15322 | /** |
| 15323 | * Returns the suggested minimum height that the view should use. This |
| 15324 | * returns the maximum of the view's minimum height |
| 15325 | * and the background's minimum height |
| 15326 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 15327 | * <p> |
| 15328 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15329 | * ensure the returned height is within the requirements of the parent. |
| 15330 | * |
| 15331 | * @return The suggested minimum height of the view. |
| 15332 | */ |
| 15333 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15334 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15336 | } |
| 15337 | |
| 15338 | /** |
| 15339 | * Returns the suggested minimum width that the view should use. This |
| 15340 | * returns the maximum of the view's minimum width) |
| 15341 | * and the background's minimum width |
| 15342 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 15343 | * <p> |
| 15344 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15345 | * ensure the returned width is within the requirements of the parent. |
| 15346 | * |
| 15347 | * @return The suggested minimum width of the view. |
| 15348 | */ |
| 15349 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15350 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 15351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15352 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15353 | /** |
| 15354 | * Returns the minimum height of the view. |
| 15355 | * |
| 15356 | * @return the minimum height the view will try to be. |
| 15357 | * |
| 15358 | * @see #setMinimumHeight(int) |
| 15359 | * |
| 15360 | * @attr ref android.R.styleable#View_minHeight |
| 15361 | */ |
| 15362 | public int getMinimumHeight() { |
| 15363 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15364 | } |
| 15365 | |
| 15366 | /** |
| 15367 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 15368 | * be able to achieve this minimum height (for example, if its parent layout |
| 15369 | * constrains it with less available height). |
| 15370 | * |
| 15371 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15372 | * |
| 15373 | * @see #getMinimumHeight() |
| 15374 | * |
| 15375 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15376 | */ |
| 15377 | public void setMinimumHeight(int minHeight) { |
| 15378 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15379 | requestLayout(); |
| 15380 | } |
| 15381 | |
| 15382 | /** |
| 15383 | * Returns the minimum width of the view. |
| 15384 | * |
| 15385 | * @return the minimum width the view will try to be. |
| 15386 | * |
| 15387 | * @see #setMinimumWidth(int) |
| 15388 | * |
| 15389 | * @attr ref android.R.styleable#View_minWidth |
| 15390 | */ |
| 15391 | public int getMinimumWidth() { |
| 15392 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15393 | } |
| 15394 | |
| 15395 | /** |
| 15396 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 15397 | * be able to achieve this minimum width (for example, if its parent layout |
| 15398 | * constrains it with less available width). |
| 15399 | * |
| 15400 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15401 | * |
| 15402 | * @see #getMinimumWidth() |
| 15403 | * |
| 15404 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15405 | */ |
| 15406 | public void setMinimumWidth(int minWidth) { |
| 15407 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15408 | requestLayout(); |
| 15409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15410 | } |
| 15411 | |
| 15412 | /** |
| 15413 | * Get the animation currently associated with this view. |
| 15414 | * |
| 15415 | * @return The animation that is currently playing or |
| 15416 | * scheduled to play for this view. |
| 15417 | */ |
| 15418 | public Animation getAnimation() { |
| 15419 | return mCurrentAnimation; |
| 15420 | } |
| 15421 | |
| 15422 | /** |
| 15423 | * Start the specified animation now. |
| 15424 | * |
| 15425 | * @param animation the animation to start now |
| 15426 | */ |
| 15427 | public void startAnimation(Animation animation) { |
| 15428 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 15429 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15430 | invalidateParentCaches(); |
| 15431 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15432 | } |
| 15433 | |
| 15434 | /** |
| 15435 | * Cancels any animations for this view. |
| 15436 | */ |
| 15437 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15438 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 15439 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15440 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15441 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15442 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15443 | } |
| 15444 | |
| 15445 | /** |
| 15446 | * Sets the next animation to play for this view. |
| 15447 | * If you want the animation to play immediately, use |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15448 | * {@link #startAnimation(android.view.animation.Animation)} instead. |
| 15449 | * This method provides allows fine-grained |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15450 | * control over the start time and invalidation, but you |
| 15451 | * must make sure that 1) the animation has a start time set, and |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15452 | * 2) the view's parent (which controls animations on its children) |
| 15453 | * will be invalidated when the animation is supposed to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15454 | * start. |
| 15455 | * |
| 15456 | * @param animation The next animation, or null. |
| 15457 | */ |
| 15458 | public void setAnimation(Animation animation) { |
| 15459 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15461 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15462 | // If the screen is off assume the animation start time is now instead of |
| 15463 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 15464 | // would cause the animation to start when the screen turns back on |
| 15465 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 15466 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 15467 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 15468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15469 | animation.reset(); |
| 15470 | } |
| 15471 | } |
| 15472 | |
| 15473 | /** |
| 15474 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 15475 | * currently associated with this view. If you override this method, |
| 15476 | * always call super.onAnimationStart(); |
| 15477 | * |
| 15478 | * @see #setAnimation(android.view.animation.Animation) |
| 15479 | * @see #getAnimation() |
| 15480 | */ |
| 15481 | protected void onAnimationStart() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15482 | mPrivateFlags |= PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15483 | } |
| 15484 | |
| 15485 | /** |
| 15486 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 15487 | * currently associated with this view. If you override this method, |
| 15488 | * always call super.onAnimationEnd(); |
| 15489 | * |
| 15490 | * @see #setAnimation(android.view.animation.Animation) |
| 15491 | * @see #getAnimation() |
| 15492 | */ |
| 15493 | protected void onAnimationEnd() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15494 | mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15495 | } |
| 15496 | |
| 15497 | /** |
| 15498 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 15499 | * draw themselves with the specified alpha should return true, and then |
| 15500 | * respect that alpha when their onDraw() is called. If this returns false |
| 15501 | * then the view may be redirected to draw into an offscreen buffer to |
| 15502 | * fulfill the request, which will look fine, but may be slower than if the |
| 15503 | * subclass handles it internally. The default implementation returns false. |
| 15504 | * |
| 15505 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 15506 | * @return true if the view can draw with the specified alpha. |
| 15507 | */ |
| 15508 | protected boolean onSetAlpha(int alpha) { |
| 15509 | return false; |
| 15510 | } |
| 15511 | |
| 15512 | /** |
| 15513 | * This is used by the RootView to perform an optimization when |
| 15514 | * the view hierarchy contains one or several SurfaceView. |
| 15515 | * SurfaceView is always considered transparent, but its children are not, |
| 15516 | * therefore all View objects remove themselves from the global transparent |
| 15517 | * region (passed as a parameter to this function). |
| 15518 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 15519 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15520 | * |
| 15521 | * @return Returns true if the effective visibility of the view at this |
| 15522 | * point is opaque, regardless of the transparent region; returns false |
| 15523 | * if it is possible for underlying windows to be seen behind the view. |
| 15524 | * |
| 15525 | * {@hide} |
| 15526 | */ |
| 15527 | public boolean gatherTransparentRegion(Region region) { |
| 15528 | final AttachInfo attachInfo = mAttachInfo; |
| 15529 | if (region != null && attachInfo != null) { |
| 15530 | final int pflags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15531 | if ((pflags & PFLAG_SKIP_DRAW) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15532 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 15533 | // remove it from the transparent region. |
| 15534 | final int[] location = attachInfo.mTransparentLocation; |
| 15535 | getLocationInWindow(location); |
| 15536 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 15537 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15538 | } else if ((pflags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0 && mBackground != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15539 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 15540 | // exists, so we remove the background drawable's non-transparent |
| 15541 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15542 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15543 | } |
| 15544 | } |
| 15545 | return true; |
| 15546 | } |
| 15547 | |
| 15548 | /** |
| 15549 | * Play a sound effect for this view. |
| 15550 | * |
| 15551 | * <p>The framework will play sound effects for some built in actions, such as |
| 15552 | * clicking, but you may wish to play these effects in your widget, |
| 15553 | * for instance, for internal navigation. |
| 15554 | * |
| 15555 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 15556 | * {@link #isSoundEffectsEnabled()} is true. |
| 15557 | * |
| 15558 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 15559 | */ |
| 15560 | public void playSoundEffect(int soundConstant) { |
| 15561 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 15562 | return; |
| 15563 | } |
| 15564 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 15565 | } |
| 15566 | |
| 15567 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15568 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15569 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15570 | * <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] | 15571 | * |
| 15572 | * <p>The framework will provide haptic feedback for some built in actions, |
| 15573 | * such as long presses, but you may wish to provide feedback for your |
| 15574 | * own widget. |
| 15575 | * |
| 15576 | * <p>The feedback will only be performed if |
| 15577 | * {@link #isHapticFeedbackEnabled()} is true. |
| 15578 | * |
| 15579 | * @param feedbackConstant One of the constants defined in |
| 15580 | * {@link HapticFeedbackConstants} |
| 15581 | */ |
| 15582 | public boolean performHapticFeedback(int feedbackConstant) { |
| 15583 | return performHapticFeedback(feedbackConstant, 0); |
| 15584 | } |
| 15585 | |
| 15586 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15587 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15588 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 15589 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15590 | * |
| 15591 | * @param feedbackConstant One of the constants defined in |
| 15592 | * {@link HapticFeedbackConstants} |
| 15593 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 15594 | */ |
| 15595 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 15596 | if (mAttachInfo == null) { |
| 15597 | return false; |
| 15598 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 15599 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15600 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15601 | && !isHapticFeedbackEnabled()) { |
| 15602 | return false; |
| 15603 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 15604 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 15605 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15606 | } |
| 15607 | |
| 15608 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15609 | * Request that the visibility of the status bar or other screen/window |
| 15610 | * decorations be changed. |
| 15611 | * |
| 15612 | * <p>This method is used to put the over device UI into temporary modes |
| 15613 | * where the user's attention is focused more on the application content, |
| 15614 | * by dimming or hiding surrounding system affordances. This is typically |
| 15615 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 15616 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 15617 | * to be placed behind the action bar (and with these flags other system |
| 15618 | * affordances) so that smooth transitions between hiding and showing them |
| 15619 | * can be done. |
| 15620 | * |
| 15621 | * <p>Two representative examples of the use of system UI visibility is |
| 15622 | * implementing a content browsing application (like a magazine reader) |
| 15623 | * and a video playing application. |
| 15624 | * |
| 15625 | * <p>The first code shows a typical implementation of a View in a content |
| 15626 | * browsing application. In this implementation, the application goes |
| 15627 | * into a content-oriented mode by hiding the status bar and action bar, |
| 15628 | * and putting the navigation elements into lights out mode. The user can |
| 15629 | * then interact with content while in this mode. Such an application should |
| 15630 | * provide an easy way for the user to toggle out of the mode (such as to |
| 15631 | * check information in the status bar or access notifications). In the |
| 15632 | * implementation here, this is done simply by tapping on the content. |
| 15633 | * |
| 15634 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 15635 | * content} |
| 15636 | * |
| 15637 | * <p>This second code sample shows a typical implementation of a View |
| 15638 | * in a video playing application. In this situation, while the video is |
| 15639 | * playing the application would like to go into a complete full-screen mode, |
| 15640 | * to use as much of the display as possible for the video. When in this state |
| 15641 | * the user can not interact with the application; the system intercepts |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 15642 | * touching on the screen to pop the UI out of full screen mode. See |
| 15643 | * {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code. |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15644 | * |
| 15645 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 15646 | * content} |
| 15647 | * |
| 15648 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15649 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15650 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15651 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15652 | */ |
| 15653 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 15654 | if (visibility != mSystemUiVisibility) { |
| 15655 | mSystemUiVisibility = visibility; |
| 15656 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15657 | mParent.recomputeViewAttributes(this); |
| 15658 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15659 | } |
| 15660 | } |
| 15661 | |
| 15662 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 15663 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 15664 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 15665 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 15666 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 15667 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15668 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 15669 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15670 | return mSystemUiVisibility; |
| 15671 | } |
| 15672 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15673 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 15674 | * Returns the current system UI visibility that is currently set for |
| 15675 | * the entire window. This is the combination of the |
| 15676 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 15677 | * views in the window. |
| 15678 | */ |
| 15679 | public int getWindowSystemUiVisibility() { |
| 15680 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 15681 | } |
| 15682 | |
| 15683 | /** |
| 15684 | * Override to find out when the window's requested system UI visibility |
| 15685 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 15686 | * This is different from the callbacks recieved through |
| 15687 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 15688 | * in that this is only telling you about the local request of the window, |
| 15689 | * not the actual values applied by the system. |
| 15690 | */ |
| 15691 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 15692 | } |
| 15693 | |
| 15694 | /** |
| 15695 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 15696 | * the view hierarchy. |
| 15697 | */ |
| 15698 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 15699 | onWindowSystemUiVisibilityChanged(visible); |
| 15700 | } |
| 15701 | |
| 15702 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 15703 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 15704 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 15705 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15706 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15707 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15708 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 15709 | mParent.recomputeViewAttributes(this); |
| 15710 | } |
| 15711 | } |
| 15712 | |
| 15713 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15714 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 15715 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15716 | */ |
| 15717 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 15718 | ListenerInfo li = mListenerInfo; |
| 15719 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 15720 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 15721 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15722 | } |
| 15723 | } |
| 15724 | |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 15725 | boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15726 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 15727 | if (val != mSystemUiVisibility) { |
| 15728 | setSystemUiVisibility(val); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 15729 | return true; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15730 | } |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 15731 | return false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 15732 | } |
| 15733 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 15734 | /** @hide */ |
| 15735 | public void setDisabledSystemUiVisibility(int flags) { |
| 15736 | if (mAttachInfo != null) { |
| 15737 | if (mAttachInfo.mDisabledSystemUiVisibility != flags) { |
| 15738 | mAttachInfo.mDisabledSystemUiVisibility = flags; |
| 15739 | if (mParent != null) { |
| 15740 | mParent.recomputeViewAttributes(this); |
| 15741 | } |
| 15742 | } |
| 15743 | } |
| 15744 | } |
| 15745 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 15746 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15747 | * Creates an image that the system displays during the drag and drop |
| 15748 | * operation. This is called a "drag shadow". The default implementation |
| 15749 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 15750 | * appearance as the given View. The default also positions the center of the drag shadow |
| 15751 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 15752 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 15753 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 15754 | * default is an invisible drag shadow. |
| 15755 | * <p> |
| 15756 | * You are not required to use the View you provide to the constructor as the basis of the |
| 15757 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 15758 | * anything you want as the drag shadow. |
| 15759 | * </p> |
| 15760 | * <p> |
| 15761 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 15762 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 15763 | * size and position of the drag shadow. It uses this data to construct a |
| 15764 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 15765 | * so that your application can draw the shadow image in the Canvas. |
| 15766 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 15767 | * |
| 15768 | * <div class="special reference"> |
| 15769 | * <h3>Developer Guides</h3> |
| 15770 | * <p>For a guide to implementing drag and drop features, read the |
| 15771 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 15772 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15773 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15774 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15775 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15776 | |
| 15777 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15778 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 15779 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 15780 | * over the center of the View. |
| 15781 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15782 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15783 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15784 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15785 | } |
| 15786 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15787 | /** |
| 15788 | * Construct a shadow builder object with no associated View. This |
| 15789 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 15790 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 15791 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15792 | * reference to any View object. If they are not overridden, then the result is an |
| 15793 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 15794 | */ |
| 15795 | public DragShadowBuilder() { |
| 15796 | mView = new WeakReference<View>(null); |
| 15797 | } |
| 15798 | |
| 15799 | /** |
| 15800 | * Returns the View object that had been passed to the |
| 15801 | * {@link #View.DragShadowBuilder(View)} |
| 15802 | * constructor. If that View parameter was {@code null} or if the |
| 15803 | * {@link #View.DragShadowBuilder()} |
| 15804 | * constructor was used to instantiate the builder object, this method will return |
| 15805 | * null. |
| 15806 | * |
| 15807 | * @return The View object associate with this builder object. |
| 15808 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 15809 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15810 | final public View getView() { |
| 15811 | return mView.get(); |
| 15812 | } |
| 15813 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15814 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15815 | * Provides the metrics for the shadow image. These include the dimensions of |
| 15816 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15817 | * be centered under the touch location while dragging. |
| 15818 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15819 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15820 | * same as the dimensions of the View itself and centers the shadow under |
| 15821 | * the touch point. |
| 15822 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15823 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15824 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 15825 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 15826 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 15827 | * image. |
| 15828 | * |
| 15829 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 15830 | * shadow image that should be underneath the touch point during the drag and drop |
| 15831 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 15832 | * 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] | 15833 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15834 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15835 | final View view = mView.get(); |
| 15836 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15837 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 15838 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15839 | } else { |
| 15840 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 15841 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15842 | } |
| 15843 | |
| 15844 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15845 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 15846 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15847 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15848 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15849 | * @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] | 15850 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15851 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 15852 | final View view = mView.get(); |
| 15853 | if (view != null) { |
| 15854 | view.draw(canvas); |
| 15855 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15856 | 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] | 15857 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15858 | } |
| 15859 | } |
| 15860 | |
| 15861 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15862 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 15863 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 15864 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 15865 | * to get metrics for the drag shadow, and then calls the object's |
| 15866 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 15867 | * <p> |
| 15868 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 15869 | * drag events to all the View objects in your application that are currently visible. It does |
| 15870 | * this either by calling the View object's drag listener (an implementation of |
| 15871 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 15872 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 15873 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 15874 | * {@link android.view.DragEvent#getAction()} value of |
| 15875 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 15876 | * </p> |
| 15877 | * <p> |
| 15878 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 15879 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 15880 | * be related to the View the user selected for dragging. |
| 15881 | * </p> |
| 15882 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 15883 | * transferred by the drag and drop operation. |
| 15884 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 15885 | * drag shadow. |
| 15886 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 15887 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 15888 | * current drag. |
| 15889 | * <p> |
| 15890 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 15891 | * to the target Views. For example, it can contain flags that differentiate between a |
| 15892 | * a copy operation and a move operation. |
| 15893 | * </p> |
| 15894 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 15895 | * so the parameter should be set to 0. |
| 15896 | * @return {@code true} if the method completes successfully, or |
| 15897 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 15898 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15899 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15900 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15901 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15902 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15903 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15904 | } |
| 15905 | boolean okay = false; |
| 15906 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15907 | Point shadowSize = new Point(); |
| 15908 | Point shadowTouchPoint = new Point(); |
| 15909 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15910 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15911 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 15912 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 15913 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15914 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15915 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15916 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15917 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 15918 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 15919 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15920 | Surface surface = new Surface(); |
| 15921 | try { |
| 15922 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 15923 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15924 | 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] | 15925 | + " surface=" + surface); |
| 15926 | if (token != null) { |
| 15927 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15928 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 15929 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15930 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 15931 | } finally { |
| 15932 | surface.unlockCanvasAndPost(canvas); |
| 15933 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15934 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15935 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 15936 | |
| 15937 | // Cache the local state object for delivery with DragEvents |
| 15938 | root.setLocalDragState(myLocalState); |
| 15939 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15940 | // repurpose 'shadowSize' for the last touch point |
| 15941 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15942 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15943 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 15944 | shadowSize.x, shadowSize.y, |
| 15945 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 15946 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 15947 | |
| 15948 | // Off and running! Release our local surface instance; the drag |
| 15949 | // shadow surface is now managed by the system process. |
| 15950 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15951 | } |
| 15952 | } catch (Exception e) { |
| 15953 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 15954 | surface.destroy(); |
| 15955 | } |
| 15956 | |
| 15957 | return okay; |
| 15958 | } |
| 15959 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15960 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15961 | * Handles drag events sent by the system following a call to |
| 15962 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 15963 | *<p> |
| 15964 | * When the system calls this method, it passes a |
| 15965 | * {@link android.view.DragEvent} object. A call to |
| 15966 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 15967 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 15968 | * operation. |
| 15969 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 15970 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 15971 | * in DragEvent, indicating the type of drag event represented by this object. |
| 15972 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 15973 | * <p> |
| 15974 | * The method should return {@code true} in response to an action type of |
| 15975 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 15976 | * operation. |
| 15977 | * </p> |
| 15978 | * <p> |
| 15979 | * The method should also return {@code true} in response to an action type of |
| 15980 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 15981 | * {@code false} if it didn't. |
| 15982 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15983 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 15984 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 15985 | return false; |
| 15986 | } |
| 15987 | |
| 15988 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 15989 | * Detects if this View is enabled and has a drag event listener. |
| 15990 | * If both are true, then it calls the drag event listener with the |
| 15991 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 15992 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 15993 | * <p> |
| 15994 | * For all other cases, the method calls the |
| 15995 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 15996 | * method and returns its result. |
| 15997 | * </p> |
| 15998 | * <p> |
| 15999 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 16000 | * event listener. However, if the View has a listener and the listener returns true, then |
| 16001 | * onDragEvent() is not called. |
| 16002 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16003 | */ |
| 16004 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 16005 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16006 | ListenerInfo li = mListenerInfo; |
| 16007 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 16008 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16009 | return true; |
| 16010 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16011 | return onDragEvent(event); |
| 16012 | } |
| 16013 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16014 | boolean canAcceptDrag() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16015 | return (mPrivateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16016 | } |
| 16017 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16018 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16019 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 16020 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 16021 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16022 | */ |
| 16023 | public void onCloseSystemDialogs(String reason) { |
| 16024 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16025 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16026 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16027 | * 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] | 16028 | * update a Region being computed for |
| 16029 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16030 | * that any non-transparent parts of the Drawable are removed from the |
| 16031 | * given transparent region. |
| 16032 | * |
| 16033 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 16034 | * @param region A Region holding the current transparency information, |
| 16035 | * where any parts of the region that are set are considered to be |
| 16036 | * transparent. On return, this region will be modified to have the |
| 16037 | * transparency information reduced by the corresponding parts of the |
| 16038 | * Drawable that are not transparent. |
| 16039 | * {@hide} |
| 16040 | */ |
| 16041 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 16042 | if (DBG) { |
| 16043 | Log.i("View", "Getting transparent region for: " + this); |
| 16044 | } |
| 16045 | final Region r = dr.getTransparentRegion(); |
| 16046 | final Rect db = dr.getBounds(); |
| 16047 | final AttachInfo attachInfo = mAttachInfo; |
| 16048 | if (r != null && attachInfo != null) { |
| 16049 | final int w = getRight()-getLeft(); |
| 16050 | final int h = getBottom()-getTop(); |
| 16051 | if (db.left > 0) { |
| 16052 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 16053 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 16054 | } |
| 16055 | if (db.right < w) { |
| 16056 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 16057 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 16058 | } |
| 16059 | if (db.top > 0) { |
| 16060 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 16061 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 16062 | } |
| 16063 | if (db.bottom < h) { |
| 16064 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 16065 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 16066 | } |
| 16067 | final int[] location = attachInfo.mTransparentLocation; |
| 16068 | getLocationInWindow(location); |
| 16069 | r.translate(location[0], location[1]); |
| 16070 | region.op(r, Region.Op.INTERSECT); |
| 16071 | } else { |
| 16072 | region.op(db, Region.Op.DIFFERENCE); |
| 16073 | } |
| 16074 | } |
| 16075 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16076 | private void checkForLongClick(int delayOffset) { |
| 16077 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 16078 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16079 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16080 | if (mPendingCheckForLongPress == null) { |
| 16081 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 16082 | } |
| 16083 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 16084 | postDelayed(mPendingCheckForLongPress, |
| 16085 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16087 | } |
| 16088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16089 | /** |
| 16090 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 16091 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 16092 | * |
| 16093 | * @param context The Context object for your activity or application. |
| 16094 | * @param resource The resource ID to inflate |
| 16095 | * @param root A view group that will be the parent. Used to properly inflate the |
| 16096 | * layout_* parameters. |
| 16097 | * @see LayoutInflater |
| 16098 | */ |
| 16099 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 16100 | LayoutInflater factory = LayoutInflater.from(context); |
| 16101 | return factory.inflate(resource, root); |
| 16102 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 16103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16104 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16105 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 16106 | * content boundaries. Views that call this method should override |
| 16107 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 16108 | * results of an over-scroll operation. |
| 16109 | * |
| 16110 | * Views can use this method to handle any touch or fling-based scrolling. |
| 16111 | * |
| 16112 | * @param deltaX Change in X in pixels |
| 16113 | * @param deltaY Change in Y in pixels |
| 16114 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 16115 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 16116 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 16117 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 16118 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 16119 | * along the X axis. |
| 16120 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 16121 | * along the Y axis. |
| 16122 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 16123 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 16124 | * axis, false otherwise. |
| 16125 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 16126 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16127 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 16128 | int scrollX, int scrollY, |
| 16129 | int scrollRangeX, int scrollRangeY, |
| 16130 | int maxOverScrollX, int maxOverScrollY, |
| 16131 | boolean isTouchEvent) { |
| 16132 | final int overScrollMode = mOverScrollMode; |
| 16133 | final boolean canScrollHorizontal = |
| 16134 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 16135 | final boolean canScrollVertical = |
| 16136 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 16137 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16138 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 16139 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16140 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 16141 | |
| 16142 | int newScrollX = scrollX + deltaX; |
| 16143 | if (!overScrollHorizontal) { |
| 16144 | maxOverScrollX = 0; |
| 16145 | } |
| 16146 | |
| 16147 | int newScrollY = scrollY + deltaY; |
| 16148 | if (!overScrollVertical) { |
| 16149 | maxOverScrollY = 0; |
| 16150 | } |
| 16151 | |
| 16152 | // Clamp values if at the limits and record |
| 16153 | final int left = -maxOverScrollX; |
| 16154 | final int right = maxOverScrollX + scrollRangeX; |
| 16155 | final int top = -maxOverScrollY; |
| 16156 | final int bottom = maxOverScrollY + scrollRangeY; |
| 16157 | |
| 16158 | boolean clampedX = false; |
| 16159 | if (newScrollX > right) { |
| 16160 | newScrollX = right; |
| 16161 | clampedX = true; |
| 16162 | } else if (newScrollX < left) { |
| 16163 | newScrollX = left; |
| 16164 | clampedX = true; |
| 16165 | } |
| 16166 | |
| 16167 | boolean clampedY = false; |
| 16168 | if (newScrollY > bottom) { |
| 16169 | newScrollY = bottom; |
| 16170 | clampedY = true; |
| 16171 | } else if (newScrollY < top) { |
| 16172 | newScrollY = top; |
| 16173 | clampedY = true; |
| 16174 | } |
| 16175 | |
| 16176 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 16177 | |
| 16178 | return clampedX || clampedY; |
| 16179 | } |
| 16180 | |
| 16181 | /** |
| 16182 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 16183 | * respond to the results of an over-scroll operation. |
| 16184 | * |
| 16185 | * @param scrollX New X scroll value in pixels |
| 16186 | * @param scrollY New Y scroll value in pixels |
| 16187 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 16188 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 16189 | */ |
| 16190 | protected void onOverScrolled(int scrollX, int scrollY, |
| 16191 | boolean clampedX, boolean clampedY) { |
| 16192 | // Intentionally empty. |
| 16193 | } |
| 16194 | |
| 16195 | /** |
| 16196 | * Returns the over-scroll mode for this view. The result will be |
| 16197 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16198 | * (allow over-scrolling only if the view content is larger than the container), |
| 16199 | * or {@link #OVER_SCROLL_NEVER}. |
| 16200 | * |
| 16201 | * @return This view's over-scroll mode. |
| 16202 | */ |
| 16203 | public int getOverScrollMode() { |
| 16204 | return mOverScrollMode; |
| 16205 | } |
| 16206 | |
| 16207 | /** |
| 16208 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 16209 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16210 | * (allow over-scrolling only if the view content is larger than the container), |
| 16211 | * or {@link #OVER_SCROLL_NEVER}. |
| 16212 | * |
| 16213 | * Setting the over-scroll mode of a view will have an effect only if the |
| 16214 | * view is capable of scrolling. |
| 16215 | * |
| 16216 | * @param overScrollMode The new over-scroll mode for this view. |
| 16217 | */ |
| 16218 | public void setOverScrollMode(int overScrollMode) { |
| 16219 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 16220 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 16221 | overScrollMode != OVER_SCROLL_NEVER) { |
| 16222 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 16223 | } |
| 16224 | mOverScrollMode = overScrollMode; |
| 16225 | } |
| 16226 | |
| 16227 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16228 | * Gets a scale factor that determines the distance the view should scroll |
| 16229 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16230 | * @return The vertical scroll scale factor. |
| 16231 | * @hide |
| 16232 | */ |
| 16233 | protected float getVerticalScrollFactor() { |
| 16234 | if (mVerticalScrollFactor == 0) { |
| 16235 | TypedValue outValue = new TypedValue(); |
| 16236 | if (!mContext.getTheme().resolveAttribute( |
| 16237 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 16238 | throw new IllegalStateException( |
| 16239 | "Expected theme to define listPreferredItemHeight."); |
| 16240 | } |
| 16241 | mVerticalScrollFactor = outValue.getDimension( |
| 16242 | mContext.getResources().getDisplayMetrics()); |
| 16243 | } |
| 16244 | return mVerticalScrollFactor; |
| 16245 | } |
| 16246 | |
| 16247 | /** |
| 16248 | * Gets a scale factor that determines the distance the view should scroll |
| 16249 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16250 | * @return The horizontal scroll scale factor. |
| 16251 | * @hide |
| 16252 | */ |
| 16253 | protected float getHorizontalScrollFactor() { |
| 16254 | // TODO: Should use something else. |
| 16255 | return getVerticalScrollFactor(); |
| 16256 | } |
| 16257 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16258 | /** |
| 16259 | * Return the value specifying the text direction or policy that was set with |
| 16260 | * {@link #setTextDirection(int)}. |
| 16261 | * |
| 16262 | * @return the defined text direction. It can be one of: |
| 16263 | * |
| 16264 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16265 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16266 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16267 | * {@link #TEXT_DIRECTION_LTR}, |
| 16268 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16269 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16270 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16271 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16272 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 16273 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 16274 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 16275 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 16276 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 16277 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 16278 | }) |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16279 | public int getTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16280 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16281 | } |
| 16282 | |
| 16283 | /** |
| 16284 | * Set the text direction. |
| 16285 | * |
| 16286 | * @param textDirection the direction to set. Should be one of: |
| 16287 | * |
| 16288 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16289 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16290 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16291 | * {@link #TEXT_DIRECTION_LTR}, |
| 16292 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16293 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16294 | */ |
| 16295 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16296 | if (getTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16297 | // Reset the current text direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16298 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16299 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16300 | // Set the new text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16301 | mPrivateFlags2 |= ((textDirection << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) & PFLAG2_TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16302 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16303 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16304 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16305 | } |
| 16306 | } |
| 16307 | |
| 16308 | /** |
| 16309 | * Return the resolved text direction. |
| 16310 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16311 | * This needs resolution if the value is TEXT_DIRECTION_INHERIT. The resolution matches |
| 16312 | * {@link #getTextDirection()}if it is not TEXT_DIRECTION_INHERIT, otherwise resolution proceeds |
| 16313 | * up the parent chain of the view. if there is no parent, then it will return the default |
| 16314 | * {@link #TEXT_DIRECTION_FIRST_STRONG}. |
| 16315 | * |
| 16316 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16317 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 16318 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16319 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16320 | * {@link #TEXT_DIRECTION_LTR}, |
| 16321 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16322 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16323 | */ |
| 16324 | public int getResolvedTextDirection() { |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 16325 | // The text direction will be resolved only if needed |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16326 | if ((mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) != PFLAG2_TEXT_DIRECTION_RESOLVED) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16327 | resolveTextDirection(); |
| 16328 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16329 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED_MASK) >> PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16330 | } |
| 16331 | |
| 16332 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 16333 | * Resolve the text direction. Will call {@link View#onResolvedTextDirectionChanged} when |
| 16334 | * resolution is done. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16335 | */ |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16336 | public void resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16337 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16338 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16339 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16340 | if (hasRtlSupport()) { |
| 16341 | // Set resolved text direction flag depending on text direction flag |
| 16342 | final int textDirection = getTextDirection(); |
| 16343 | switch(textDirection) { |
| 16344 | case TEXT_DIRECTION_INHERIT: |
| 16345 | if (canResolveTextDirection()) { |
| 16346 | ViewGroup viewGroup = ((ViewGroup) mParent); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16347 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16348 | // Set current resolved direction to the same value as the parent's one |
| 16349 | final int parentResolvedDirection = viewGroup.getResolvedTextDirection(); |
| 16350 | switch (parentResolvedDirection) { |
| 16351 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16352 | case TEXT_DIRECTION_ANY_RTL: |
| 16353 | case TEXT_DIRECTION_LTR: |
| 16354 | case TEXT_DIRECTION_RTL: |
| 16355 | case TEXT_DIRECTION_LOCALE: |
| 16356 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16357 | (parentResolvedDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16358 | break; |
| 16359 | default: |
| 16360 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16361 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16362 | } |
| 16363 | } else { |
| 16364 | // We cannot do the resolution if there is no parent, so use the default one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16365 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16366 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16367 | break; |
| 16368 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16369 | case TEXT_DIRECTION_ANY_RTL: |
| 16370 | case TEXT_DIRECTION_LTR: |
| 16371 | case TEXT_DIRECTION_RTL: |
| 16372 | case TEXT_DIRECTION_LOCALE: |
| 16373 | // Resolved direction is the same as text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16374 | mPrivateFlags2 |= (textDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16375 | break; |
| 16376 | default: |
| 16377 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16378 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16379 | } |
| 16380 | } else { |
| 16381 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16382 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16383 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16384 | |
| 16385 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16386 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 16387 | onResolvedTextDirectionChanged(); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16388 | } |
| 16389 | |
| 16390 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16391 | * 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] | 16392 | * resolution should override this method. |
| 16393 | * |
| 16394 | * The default implementation does nothing. |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16395 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 16396 | public void onResolvedTextDirectionChanged() { |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16397 | } |
| 16398 | |
| 16399 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16400 | * Check if text direction resolution can be done. |
| 16401 | * |
| 16402 | * @return true if text direction resolution can be done otherwise return false. |
| 16403 | */ |
| 16404 | public boolean canResolveTextDirection() { |
| 16405 | switch (getTextDirection()) { |
| 16406 | case TEXT_DIRECTION_INHERIT: |
| 16407 | return (mParent != null) && (mParent instanceof ViewGroup); |
| 16408 | default: |
| 16409 | return true; |
| 16410 | } |
| 16411 | } |
| 16412 | |
| 16413 | /** |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16414 | * 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] | 16415 | * getResolvedTextDirection(). Will call {@link View#onResolvedTextDirectionReset} when |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16416 | * reset is done. |
| 16417 | */ |
| 16418 | public void resetResolvedTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16419 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 16420 | onResolvedTextDirectionReset(); |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16421 | } |
| 16422 | |
| 16423 | /** |
| 16424 | * Called when text direction is reset. Subclasses that care about text direction reset should |
| 16425 | * override this method and do a reset of the text direction of their children. The default |
| 16426 | * implementation does nothing. |
| 16427 | */ |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 16428 | public void onResolvedTextDirectionReset() { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16429 | } |
| 16430 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16431 | /** |
| 16432 | * Return the value specifying the text alignment or policy that was set with |
| 16433 | * {@link #setTextAlignment(int)}. |
| 16434 | * |
| 16435 | * @return the defined text alignment. It can be one of: |
| 16436 | * |
| 16437 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16438 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16439 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16440 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16441 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16442 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16443 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16444 | */ |
| 16445 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16446 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16447 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16448 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16449 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16450 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16451 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16452 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16453 | }) |
| 16454 | public int getTextAlignment() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16455 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16456 | } |
| 16457 | |
| 16458 | /** |
| 16459 | * Set the text alignment. |
| 16460 | * |
| 16461 | * @param textAlignment The text alignment to set. Should be one of |
| 16462 | * |
| 16463 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16464 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16465 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16466 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16467 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16468 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16469 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16470 | * |
| 16471 | * @attr ref android.R.styleable#View_textAlignment |
| 16472 | */ |
| 16473 | public void setTextAlignment(int textAlignment) { |
| 16474 | if (textAlignment != getTextAlignment()) { |
| 16475 | // Reset the current and resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16476 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16477 | resetResolvedTextAlignment(); |
| 16478 | // Set the new text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16479 | mPrivateFlags2 |= ((textAlignment << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) & PFLAG2_TEXT_ALIGNMENT_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16480 | // Refresh |
| 16481 | requestLayout(); |
| 16482 | invalidate(true); |
| 16483 | } |
| 16484 | } |
| 16485 | |
| 16486 | /** |
| 16487 | * Return the resolved text alignment. |
| 16488 | * |
| 16489 | * The resolved text alignment. This needs resolution if the value is |
| 16490 | * TEXT_ALIGNMENT_INHERIT. The resolution matches {@link #setTextAlignment(int)} if it is |
| 16491 | * not TEXT_ALIGNMENT_INHERIT, otherwise resolution proceeds up the parent chain of the view. |
| 16492 | * |
| 16493 | * @return the resolved text alignment. Returns one of: |
| 16494 | * |
| 16495 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16496 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16497 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16498 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16499 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16500 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 16501 | */ |
| 16502 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16503 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16504 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16505 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16506 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16507 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16508 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16509 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16510 | }) |
| 16511 | public int getResolvedTextAlignment() { |
| 16512 | // If text alignment is not resolved, then resolve it |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16513 | if ((mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED) != PFLAG2_TEXT_ALIGNMENT_RESOLVED) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16514 | resolveTextAlignment(); |
| 16515 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16516 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >> PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16517 | } |
| 16518 | |
| 16519 | /** |
| 16520 | * Resolve the text alignment. Will call {@link View#onResolvedTextAlignmentChanged} when |
| 16521 | * resolution is done. |
| 16522 | */ |
| 16523 | public void resolveTextAlignment() { |
| 16524 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16525 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16526 | |
| 16527 | if (hasRtlSupport()) { |
| 16528 | // Set resolved text alignment flag depending on text alignment flag |
| 16529 | final int textAlignment = getTextAlignment(); |
| 16530 | switch (textAlignment) { |
| 16531 | case TEXT_ALIGNMENT_INHERIT: |
| 16532 | // Check if we can resolve the text alignment |
| 16533 | if (canResolveLayoutDirection() && mParent instanceof View) { |
| 16534 | View view = (View) mParent; |
| 16535 | |
| 16536 | final int parentResolvedTextAlignment = view.getResolvedTextAlignment(); |
| 16537 | switch (parentResolvedTextAlignment) { |
| 16538 | case TEXT_ALIGNMENT_GRAVITY: |
| 16539 | case TEXT_ALIGNMENT_TEXT_START: |
| 16540 | case TEXT_ALIGNMENT_TEXT_END: |
| 16541 | case TEXT_ALIGNMENT_CENTER: |
| 16542 | case TEXT_ALIGNMENT_VIEW_START: |
| 16543 | case TEXT_ALIGNMENT_VIEW_END: |
| 16544 | // Resolved text alignment is the same as the parent resolved |
| 16545 | // text alignment |
| 16546 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16547 | (parentResolvedTextAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16548 | break; |
| 16549 | default: |
| 16550 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16551 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16552 | } |
| 16553 | } |
| 16554 | else { |
| 16555 | // We cannot do the resolution if there is no parent so use the default |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16556 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16557 | } |
| 16558 | break; |
| 16559 | case TEXT_ALIGNMENT_GRAVITY: |
| 16560 | case TEXT_ALIGNMENT_TEXT_START: |
| 16561 | case TEXT_ALIGNMENT_TEXT_END: |
| 16562 | case TEXT_ALIGNMENT_CENTER: |
| 16563 | case TEXT_ALIGNMENT_VIEW_START: |
| 16564 | case TEXT_ALIGNMENT_VIEW_END: |
| 16565 | // Resolved text alignment is the same as text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16566 | mPrivateFlags2 |= (textAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16567 | break; |
| 16568 | default: |
| 16569 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16570 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16571 | } |
| 16572 | } else { |
| 16573 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16574 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16575 | } |
| 16576 | |
| 16577 | // Set the resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16578 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16579 | onResolvedTextAlignmentChanged(); |
| 16580 | } |
| 16581 | |
| 16582 | /** |
| 16583 | * Check if text alignment resolution can be done. |
| 16584 | * |
| 16585 | * @return true if text alignment resolution can be done otherwise return false. |
| 16586 | */ |
| 16587 | public boolean canResolveTextAlignment() { |
| 16588 | switch (getTextAlignment()) { |
| 16589 | case TEXT_DIRECTION_INHERIT: |
| 16590 | return (mParent != null); |
| 16591 | default: |
| 16592 | return true; |
| 16593 | } |
| 16594 | } |
| 16595 | |
| 16596 | /** |
| 16597 | * Called when text alignment has been resolved. Subclasses that care about text alignment |
| 16598 | * resolution should override this method. |
| 16599 | * |
| 16600 | * The default implementation does nothing. |
| 16601 | */ |
| 16602 | public void onResolvedTextAlignmentChanged() { |
| 16603 | } |
| 16604 | |
| 16605 | /** |
| 16606 | * Reset resolved text alignment. Text alignment can be resolved with a call to |
| 16607 | * getResolvedTextAlignment(). Will call {@link View#onResolvedTextAlignmentReset} when |
| 16608 | * reset is done. |
| 16609 | */ |
| 16610 | public void resetResolvedTextAlignment() { |
| 16611 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16612 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16613 | onResolvedTextAlignmentReset(); |
| 16614 | } |
| 16615 | |
| 16616 | /** |
| 16617 | * Called when text alignment is reset. Subclasses that care about text alignment reset should |
| 16618 | * override this method and do a reset of the text alignment of their children. The default |
| 16619 | * implementation does nothing. |
| 16620 | */ |
| 16621 | public void onResolvedTextAlignmentReset() { |
| 16622 | } |
| 16623 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 16624 | /** |
| 16625 | * Generate a value suitable for use in {@link #setId(int)}. |
| 16626 | * This value will not collide with ID values generated at build time by aapt for R.id. |
| 16627 | * |
| 16628 | * @return a generated ID value |
| 16629 | */ |
| 16630 | public static int generateViewId() { |
| 16631 | for (;;) { |
| 16632 | final int result = sNextGeneratedId.get(); |
| 16633 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 16634 | int newValue = result + 1; |
| 16635 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 16636 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 16637 | return result; |
| 16638 | } |
| 16639 | } |
| 16640 | } |
| 16641 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16642 | // |
| 16643 | // Properties |
| 16644 | // |
| 16645 | /** |
| 16646 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 16647 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 16648 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16649 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16650 | @Override |
| 16651 | public void setValue(View object, float value) { |
| 16652 | object.setAlpha(value); |
| 16653 | } |
| 16654 | |
| 16655 | @Override |
| 16656 | public Float get(View object) { |
| 16657 | return object.getAlpha(); |
| 16658 | } |
| 16659 | }; |
| 16660 | |
| 16661 | /** |
| 16662 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 16663 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 16664 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16665 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16666 | @Override |
| 16667 | public void setValue(View object, float value) { |
| 16668 | object.setTranslationX(value); |
| 16669 | } |
| 16670 | |
| 16671 | @Override |
| 16672 | public Float get(View object) { |
| 16673 | return object.getTranslationX(); |
| 16674 | } |
| 16675 | }; |
| 16676 | |
| 16677 | /** |
| 16678 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 16679 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 16680 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16681 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16682 | @Override |
| 16683 | public void setValue(View object, float value) { |
| 16684 | object.setTranslationY(value); |
| 16685 | } |
| 16686 | |
| 16687 | @Override |
| 16688 | public Float get(View object) { |
| 16689 | return object.getTranslationY(); |
| 16690 | } |
| 16691 | }; |
| 16692 | |
| 16693 | /** |
| 16694 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 16695 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 16696 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16697 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16698 | @Override |
| 16699 | public void setValue(View object, float value) { |
| 16700 | object.setX(value); |
| 16701 | } |
| 16702 | |
| 16703 | @Override |
| 16704 | public Float get(View object) { |
| 16705 | return object.getX(); |
| 16706 | } |
| 16707 | }; |
| 16708 | |
| 16709 | /** |
| 16710 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 16711 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 16712 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16713 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16714 | @Override |
| 16715 | public void setValue(View object, float value) { |
| 16716 | object.setY(value); |
| 16717 | } |
| 16718 | |
| 16719 | @Override |
| 16720 | public Float get(View object) { |
| 16721 | return object.getY(); |
| 16722 | } |
| 16723 | }; |
| 16724 | |
| 16725 | /** |
| 16726 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 16727 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 16728 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16729 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16730 | @Override |
| 16731 | public void setValue(View object, float value) { |
| 16732 | object.setRotation(value); |
| 16733 | } |
| 16734 | |
| 16735 | @Override |
| 16736 | public Float get(View object) { |
| 16737 | return object.getRotation(); |
| 16738 | } |
| 16739 | }; |
| 16740 | |
| 16741 | /** |
| 16742 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 16743 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 16744 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16745 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16746 | @Override |
| 16747 | public void setValue(View object, float value) { |
| 16748 | object.setRotationX(value); |
| 16749 | } |
| 16750 | |
| 16751 | @Override |
| 16752 | public Float get(View object) { |
| 16753 | return object.getRotationX(); |
| 16754 | } |
| 16755 | }; |
| 16756 | |
| 16757 | /** |
| 16758 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 16759 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 16760 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16761 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16762 | @Override |
| 16763 | public void setValue(View object, float value) { |
| 16764 | object.setRotationY(value); |
| 16765 | } |
| 16766 | |
| 16767 | @Override |
| 16768 | public Float get(View object) { |
| 16769 | return object.getRotationY(); |
| 16770 | } |
| 16771 | }; |
| 16772 | |
| 16773 | /** |
| 16774 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 16775 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 16776 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16777 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16778 | @Override |
| 16779 | public void setValue(View object, float value) { |
| 16780 | object.setScaleX(value); |
| 16781 | } |
| 16782 | |
| 16783 | @Override |
| 16784 | public Float get(View object) { |
| 16785 | return object.getScaleX(); |
| 16786 | } |
| 16787 | }; |
| 16788 | |
| 16789 | /** |
| 16790 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 16791 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 16792 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 16793 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 16794 | @Override |
| 16795 | public void setValue(View object, float value) { |
| 16796 | object.setScaleY(value); |
| 16797 | } |
| 16798 | |
| 16799 | @Override |
| 16800 | public Float get(View object) { |
| 16801 | return object.getScaleY(); |
| 16802 | } |
| 16803 | }; |
| 16804 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16805 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16806 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 16807 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 16808 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 16809 | * modes: |
| 16810 | * <dl> |
| 16811 | * <dt>UNSPECIFIED</dt> |
| 16812 | * <dd> |
| 16813 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 16814 | * it wants. |
| 16815 | * </dd> |
| 16816 | * |
| 16817 | * <dt>EXACTLY</dt> |
| 16818 | * <dd> |
| 16819 | * The parent has determined an exact size for the child. The child is going to be |
| 16820 | * given those bounds regardless of how big it wants to be. |
| 16821 | * </dd> |
| 16822 | * |
| 16823 | * <dt>AT_MOST</dt> |
| 16824 | * <dd> |
| 16825 | * The child can be as large as it wants up to the specified size. |
| 16826 | * </dd> |
| 16827 | * </dl> |
| 16828 | * |
| 16829 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 16830 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 16831 | */ |
| 16832 | public static class MeasureSpec { |
| 16833 | private static final int MODE_SHIFT = 30; |
| 16834 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 16835 | |
| 16836 | /** |
| 16837 | * Measure specification mode: The parent has not imposed any constraint |
| 16838 | * on the child. It can be whatever size it wants. |
| 16839 | */ |
| 16840 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 16841 | |
| 16842 | /** |
| 16843 | * Measure specification mode: The parent has determined an exact size |
| 16844 | * for the child. The child is going to be given those bounds regardless |
| 16845 | * of how big it wants to be. |
| 16846 | */ |
| 16847 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 16848 | |
| 16849 | /** |
| 16850 | * Measure specification mode: The child can be as large as it wants up |
| 16851 | * to the specified size. |
| 16852 | */ |
| 16853 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 16854 | |
| 16855 | /** |
| 16856 | * Creates a measure specification based on the supplied size and mode. |
| 16857 | * |
| 16858 | * The mode must always be one of the following: |
| 16859 | * <ul> |
| 16860 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 16861 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 16862 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 16863 | * </ul> |
| 16864 | * |
| 16865 | * @param size the size of the measure specification |
| 16866 | * @param mode the mode of the measure specification |
| 16867 | * @return the measure specification based on size and mode |
| 16868 | */ |
| 16869 | public static int makeMeasureSpec(int size, int mode) { |
| 16870 | return size + mode; |
| 16871 | } |
| 16872 | |
| 16873 | /** |
| 16874 | * Extracts the mode from the supplied measure specification. |
| 16875 | * |
| 16876 | * @param measureSpec the measure specification to extract the mode from |
| 16877 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 16878 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 16879 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 16880 | */ |
| 16881 | public static int getMode(int measureSpec) { |
| 16882 | return (measureSpec & MODE_MASK); |
| 16883 | } |
| 16884 | |
| 16885 | /** |
| 16886 | * Extracts the size from the supplied measure specification. |
| 16887 | * |
| 16888 | * @param measureSpec the measure specification to extract the size from |
| 16889 | * @return the size in pixels defined in the supplied measure specification |
| 16890 | */ |
| 16891 | public static int getSize(int measureSpec) { |
| 16892 | return (measureSpec & ~MODE_MASK); |
| 16893 | } |
| 16894 | |
| 16895 | /** |
| 16896 | * Returns a String representation of the specified measure |
| 16897 | * specification. |
| 16898 | * |
| 16899 | * @param measureSpec the measure specification to convert to a String |
| 16900 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 16901 | */ |
| 16902 | public static String toString(int measureSpec) { |
| 16903 | int mode = getMode(measureSpec); |
| 16904 | int size = getSize(measureSpec); |
| 16905 | |
| 16906 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 16907 | |
| 16908 | if (mode == UNSPECIFIED) |
| 16909 | sb.append("UNSPECIFIED "); |
| 16910 | else if (mode == EXACTLY) |
| 16911 | sb.append("EXACTLY "); |
| 16912 | else if (mode == AT_MOST) |
| 16913 | sb.append("AT_MOST "); |
| 16914 | else |
| 16915 | sb.append(mode).append(" "); |
| 16916 | |
| 16917 | sb.append(size); |
| 16918 | return sb.toString(); |
| 16919 | } |
| 16920 | } |
| 16921 | |
| 16922 | class CheckForLongPress implements Runnable { |
| 16923 | |
| 16924 | private int mOriginalWindowAttachCount; |
| 16925 | |
| 16926 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 16927 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16928 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 16929 | if (performLongClick()) { |
| 16930 | mHasPerformedLongPress = true; |
| 16931 | } |
| 16932 | } |
| 16933 | } |
| 16934 | |
| 16935 | public void rememberWindowAttachCount() { |
| 16936 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 16937 | } |
| 16938 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16939 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16940 | private final class CheckForTap implements Runnable { |
| 16941 | public void run() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16942 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 16943 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16944 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 16945 | } |
| 16946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16947 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 16948 | private final class PerformClick implements Runnable { |
| 16949 | public void run() { |
| 16950 | performClick(); |
| 16951 | } |
| 16952 | } |
| 16953 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 16954 | /** @hide */ |
| 16955 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 16956 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 16957 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16959 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 16960 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 16961 | * specific properties on this View. |
| 16962 | * |
| 16963 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 16964 | */ |
| 16965 | public ViewPropertyAnimator animate() { |
| 16966 | if (mAnimator == null) { |
| 16967 | mAnimator = new ViewPropertyAnimator(this); |
| 16968 | } |
| 16969 | return mAnimator; |
| 16970 | } |
| 16971 | |
| 16972 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 16973 | * Interface definition for a callback to be invoked when a hardware key event is |
| 16974 | * dispatched to this view. The callback will be invoked before the key event is |
| 16975 | * given to the view. This is only useful for hardware keyboards; a software input |
| 16976 | * method has no obligation to trigger this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16977 | */ |
| 16978 | public interface OnKeyListener { |
| 16979 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 16980 | * Called when a hardware key is dispatched to a view. This allows listeners to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16981 | * get a chance to respond before the target view. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 16982 | * <p>Key presses in software keyboards will generally NOT trigger this method, |
| 16983 | * although some may elect to do so in some situations. Do not assume a |
| 16984 | * software input method has to be key-based; even if it is, it may use key presses |
| 16985 | * in a different way than you expect, so there is no way to reliably catch soft |
| 16986 | * input key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16987 | * |
| 16988 | * @param v The view the key has been dispatched to. |
| 16989 | * @param keyCode The code for the physical key that was pressed |
| 16990 | * @param event The KeyEvent object containing full information about |
| 16991 | * the event. |
| 16992 | * @return True if the listener has consumed the event, false otherwise. |
| 16993 | */ |
| 16994 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 16995 | } |
| 16996 | |
| 16997 | /** |
| 16998 | * Interface definition for a callback to be invoked when a touch event is |
| 16999 | * dispatched to this view. The callback will be invoked before the touch |
| 17000 | * event is given to the view. |
| 17001 | */ |
| 17002 | public interface OnTouchListener { |
| 17003 | /** |
| 17004 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 17005 | * get a chance to respond before the target view. |
| 17006 | * |
| 17007 | * @param v The view the touch event has been dispatched to. |
| 17008 | * @param event The MotionEvent object containing full information about |
| 17009 | * the event. |
| 17010 | * @return True if the listener has consumed the event, false otherwise. |
| 17011 | */ |
| 17012 | boolean onTouch(View v, MotionEvent event); |
| 17013 | } |
| 17014 | |
| 17015 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 17016 | * Interface definition for a callback to be invoked when a hover event is |
| 17017 | * dispatched to this view. The callback will be invoked before the hover |
| 17018 | * event is given to the view. |
| 17019 | */ |
| 17020 | public interface OnHoverListener { |
| 17021 | /** |
| 17022 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 17023 | * get a chance to respond before the target view. |
| 17024 | * |
| 17025 | * @param v The view the hover event has been dispatched to. |
| 17026 | * @param event The MotionEvent object containing full information about |
| 17027 | * the event. |
| 17028 | * @return True if the listener has consumed the event, false otherwise. |
| 17029 | */ |
| 17030 | boolean onHover(View v, MotionEvent event); |
| 17031 | } |
| 17032 | |
| 17033 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17034 | * Interface definition for a callback to be invoked when a generic motion event is |
| 17035 | * dispatched to this view. The callback will be invoked before the generic motion |
| 17036 | * event is given to the view. |
| 17037 | */ |
| 17038 | public interface OnGenericMotionListener { |
| 17039 | /** |
| 17040 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 17041 | * get a chance to respond before the target view. |
| 17042 | * |
| 17043 | * @param v The view the generic motion event has been dispatched to. |
| 17044 | * @param event The MotionEvent object containing full information about |
| 17045 | * the event. |
| 17046 | * @return True if the listener has consumed the event, false otherwise. |
| 17047 | */ |
| 17048 | boolean onGenericMotion(View v, MotionEvent event); |
| 17049 | } |
| 17050 | |
| 17051 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17052 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 17053 | */ |
| 17054 | public interface OnLongClickListener { |
| 17055 | /** |
| 17056 | * Called when a view has been clicked and held. |
| 17057 | * |
| 17058 | * @param v The view that was clicked and held. |
| 17059 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 17060 | * @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] | 17061 | */ |
| 17062 | boolean onLongClick(View v); |
| 17063 | } |
| 17064 | |
| 17065 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17066 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 17067 | * to this view. The callback will be invoked before the hosting view's own |
| 17068 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 17069 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 17070 | * |
| 17071 | * <div class="special reference"> |
| 17072 | * <h3>Developer Guides</h3> |
| 17073 | * <p>For a guide to implementing drag and drop features, read the |
| 17074 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 17075 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17076 | */ |
| 17077 | public interface OnDragListener { |
| 17078 | /** |
| 17079 | * Called when a drag event is dispatched to a view. This allows listeners |
| 17080 | * to get a chance to override base View behavior. |
| 17081 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17082 | * @param v The View that received the drag event. |
| 17083 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 17084 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 17085 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 17086 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17087 | */ |
| 17088 | boolean onDrag(View v, DragEvent event); |
| 17089 | } |
| 17090 | |
| 17091 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17092 | * Interface definition for a callback to be invoked when the focus state of |
| 17093 | * a view changed. |
| 17094 | */ |
| 17095 | public interface OnFocusChangeListener { |
| 17096 | /** |
| 17097 | * Called when the focus state of a view has changed. |
| 17098 | * |
| 17099 | * @param v The view whose state has changed. |
| 17100 | * @param hasFocus The new focus state of v. |
| 17101 | */ |
| 17102 | void onFocusChange(View v, boolean hasFocus); |
| 17103 | } |
| 17104 | |
| 17105 | /** |
| 17106 | * Interface definition for a callback to be invoked when a view is clicked. |
| 17107 | */ |
| 17108 | public interface OnClickListener { |
| 17109 | /** |
| 17110 | * Called when a view has been clicked. |
| 17111 | * |
| 17112 | * @param v The view that was clicked. |
| 17113 | */ |
| 17114 | void onClick(View v); |
| 17115 | } |
| 17116 | |
| 17117 | /** |
| 17118 | * Interface definition for a callback to be invoked when the context menu |
| 17119 | * for this view is being built. |
| 17120 | */ |
| 17121 | public interface OnCreateContextMenuListener { |
| 17122 | /** |
| 17123 | * Called when the context menu for this view is being built. It is not |
| 17124 | * safe to hold onto the menu after this method returns. |
| 17125 | * |
| 17126 | * @param menu The context menu that is being built |
| 17127 | * @param v The view for which the context menu is being built |
| 17128 | * @param menuInfo Extra information about the item for which the |
| 17129 | * context menu should be shown. This information will vary |
| 17130 | * depending on the class of v. |
| 17131 | */ |
| 17132 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 17133 | } |
| 17134 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17135 | /** |
| 17136 | * 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] | 17137 | * visibility. This reports <strong>global</strong> changes to the system UI |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17138 | * state, not what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17139 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 17140 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17141 | */ |
| 17142 | public interface OnSystemUiVisibilityChangeListener { |
| 17143 | /** |
| 17144 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 17145 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17146 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17147 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 17148 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, and {@link #SYSTEM_UI_FLAG_FULLSCREEN}. |
| 17149 | * This tells you the <strong>global</strong> state of these UI visibility |
| 17150 | * flags, not what your app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17151 | */ |
| 17152 | public void onSystemUiVisibilityChange(int visibility); |
| 17153 | } |
| 17154 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 17155 | /** |
| 17156 | * Interface definition for a callback to be invoked when this view is attached |
| 17157 | * or detached from its window. |
| 17158 | */ |
| 17159 | public interface OnAttachStateChangeListener { |
| 17160 | /** |
| 17161 | * Called when the view is attached to a window. |
| 17162 | * @param v The view that was attached |
| 17163 | */ |
| 17164 | public void onViewAttachedToWindow(View v); |
| 17165 | /** |
| 17166 | * Called when the view is detached from a window. |
| 17167 | * @param v The view that was detached |
| 17168 | */ |
| 17169 | public void onViewDetachedFromWindow(View v); |
| 17170 | } |
| 17171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17172 | private final class UnsetPressedState implements Runnable { |
| 17173 | public void run() { |
| 17174 | setPressed(false); |
| 17175 | } |
| 17176 | } |
| 17177 | |
| 17178 | /** |
| 17179 | * Base class for derived classes that want to save and restore their own |
| 17180 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 17181 | */ |
| 17182 | public static class BaseSavedState extends AbsSavedState { |
| 17183 | /** |
| 17184 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 17185 | * |
| 17186 | * @param source |
| 17187 | */ |
| 17188 | public BaseSavedState(Parcel source) { |
| 17189 | super(source); |
| 17190 | } |
| 17191 | |
| 17192 | /** |
| 17193 | * Constructor called by derived classes when creating their SavedState objects |
| 17194 | * |
| 17195 | * @param superState The state of the superclass of this view |
| 17196 | */ |
| 17197 | public BaseSavedState(Parcelable superState) { |
| 17198 | super(superState); |
| 17199 | } |
| 17200 | |
| 17201 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 17202 | new Parcelable.Creator<BaseSavedState>() { |
| 17203 | public BaseSavedState createFromParcel(Parcel in) { |
| 17204 | return new BaseSavedState(in); |
| 17205 | } |
| 17206 | |
| 17207 | public BaseSavedState[] newArray(int size) { |
| 17208 | return new BaseSavedState[size]; |
| 17209 | } |
| 17210 | }; |
| 17211 | } |
| 17212 | |
| 17213 | /** |
| 17214 | * A set of information given to a view when it is attached to its parent |
| 17215 | * window. |
| 17216 | */ |
| 17217 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17218 | interface Callbacks { |
| 17219 | void playSoundEffect(int effectId); |
| 17220 | boolean performHapticFeedback(int effectId, boolean always); |
| 17221 | } |
| 17222 | |
| 17223 | /** |
| 17224 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 17225 | * to a Handler. This class contains the target (View) to invalidate and |
| 17226 | * the coordinates of the dirty rectangle. |
| 17227 | * |
| 17228 | * For performance purposes, this class also implements a pool of up to |
| 17229 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 17230 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17231 | */ |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17232 | static class InvalidateInfo implements Poolable<InvalidateInfo> { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17233 | private static final int POOL_LIMIT = 10; |
Romain Guy | 2e9bbce | 2009-04-01 10:40:10 -0700 | [diff] [blame] | 17234 | private static final Pool<InvalidateInfo> sPool = Pools.synchronizedPool( |
| 17235 | Pools.finitePool(new PoolableManager<InvalidateInfo>() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17236 | public InvalidateInfo newInstance() { |
| 17237 | return new InvalidateInfo(); |
| 17238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17239 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17240 | public void onAcquired(InvalidateInfo element) { |
| 17241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17242 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17243 | public void onReleased(InvalidateInfo element) { |
Romain Guy | 40c18f5 | 2011-09-01 17:01:18 -0700 | [diff] [blame] | 17244 | element.target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17245 | } |
| 17246 | }, POOL_LIMIT) |
| 17247 | ); |
| 17248 | |
| 17249 | private InvalidateInfo mNext; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17250 | private boolean mIsPooled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17251 | |
| 17252 | View target; |
| 17253 | |
| 17254 | int left; |
| 17255 | int top; |
| 17256 | int right; |
| 17257 | int bottom; |
| 17258 | |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17259 | public void setNextPoolable(InvalidateInfo element) { |
| 17260 | mNext = element; |
| 17261 | } |
| 17262 | |
| 17263 | public InvalidateInfo getNextPoolable() { |
| 17264 | return mNext; |
| 17265 | } |
| 17266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17267 | static InvalidateInfo acquire() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17268 | return sPool.acquire(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17269 | } |
| 17270 | |
| 17271 | void release() { |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17272 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17273 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17274 | |
| 17275 | public boolean isPooled() { |
| 17276 | return mIsPooled; |
| 17277 | } |
| 17278 | |
| 17279 | public void setPooled(boolean isPooled) { |
| 17280 | mIsPooled = isPooled; |
| 17281 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17282 | } |
| 17283 | |
| 17284 | final IWindowSession mSession; |
| 17285 | |
| 17286 | final IWindow mWindow; |
| 17287 | |
| 17288 | final IBinder mWindowToken; |
| 17289 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17290 | final Display mDisplay; |
| 17291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17292 | final Callbacks mRootCallbacks; |
| 17293 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 17294 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 17295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17296 | /** |
| 17297 | * The top view of the hierarchy. |
| 17298 | */ |
| 17299 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17301 | IBinder mPanelParentWindowToken; |
| 17302 | Surface mSurface; |
| 17303 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17304 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 17305 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17306 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17307 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 17308 | boolean mScreenOn; |
| 17309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17310 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17311 | * Scale factor used by the compatibility mode |
| 17312 | */ |
| 17313 | float mApplicationScale; |
| 17314 | |
| 17315 | /** |
| 17316 | * Indicates whether the application is in compatibility mode |
| 17317 | */ |
| 17318 | boolean mScalingRequired; |
| 17319 | |
| 17320 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17321 | * 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] | 17322 | */ |
| 17323 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17324 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17325 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17326 | * Left position of this view's window |
| 17327 | */ |
| 17328 | int mWindowLeft; |
| 17329 | |
| 17330 | /** |
| 17331 | * Top position of this view's window |
| 17332 | */ |
| 17333 | int mWindowTop; |
| 17334 | |
| 17335 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17336 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17337 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17338 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17339 | |
| 17340 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17341 | * For windows that are full-screen but using insets to layout inside |
| 17342 | * of the screen decorations, these are the current insets for the |
| 17343 | * content of the window. |
| 17344 | */ |
| 17345 | final Rect mContentInsets = new Rect(); |
| 17346 | |
| 17347 | /** |
| 17348 | * For windows that are full-screen but using insets to layout inside |
| 17349 | * of the screen decorations, these are the current insets for the |
| 17350 | * actual visible parts of the window. |
| 17351 | */ |
| 17352 | final Rect mVisibleInsets = new Rect(); |
| 17353 | |
| 17354 | /** |
| 17355 | * The internal insets given by this window. This value is |
| 17356 | * supplied by the client (through |
| 17357 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 17358 | * be given to the window manager when changed to be used in laying |
| 17359 | * out windows behind it. |
| 17360 | */ |
| 17361 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 17362 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 17363 | |
| 17364 | /** |
| 17365 | * All views in the window's hierarchy that serve as scroll containers, |
| 17366 | * used to determine if the window can be resized or must be panned |
| 17367 | * to adjust for a soft input area. |
| 17368 | */ |
| 17369 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 17370 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 17371 | final KeyEvent.DispatcherState mKeyDispatchState |
| 17372 | = new KeyEvent.DispatcherState(); |
| 17373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17374 | /** |
| 17375 | * Indicates whether the view's window currently has the focus. |
| 17376 | */ |
| 17377 | boolean mHasWindowFocus; |
| 17378 | |
| 17379 | /** |
| 17380 | * The current visibility of the window. |
| 17381 | */ |
| 17382 | int mWindowVisibility; |
| 17383 | |
| 17384 | /** |
| 17385 | * Indicates the time at which drawing started to occur. |
| 17386 | */ |
| 17387 | long mDrawingTime; |
| 17388 | |
| 17389 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 17390 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 17391 | */ |
| 17392 | boolean mIgnoreDirtyState; |
| 17393 | |
| 17394 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 17395 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 17396 | * to avoid clearing that flag prematurely. |
| 17397 | */ |
| 17398 | boolean mSetIgnoreDirtyState = false; |
| 17399 | |
| 17400 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17401 | * Indicates whether the view's window is currently in touch mode. |
| 17402 | */ |
| 17403 | boolean mInTouchMode; |
| 17404 | |
| 17405 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17406 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17407 | * the next time it performs a traversal |
| 17408 | */ |
| 17409 | boolean mRecomputeGlobalAttributes; |
| 17410 | |
| 17411 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 17412 | * Always report new attributes at next traversal. |
| 17413 | */ |
| 17414 | boolean mForceReportNewAttributes; |
| 17415 | |
| 17416 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17417 | * Set during a traveral if any views want to keep the screen on. |
| 17418 | */ |
| 17419 | boolean mKeepScreenOn; |
| 17420 | |
| 17421 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17422 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 17423 | */ |
| 17424 | int mSystemUiVisibility; |
| 17425 | |
| 17426 | /** |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 17427 | * Hack to force certain system UI visibility flags to be cleared. |
| 17428 | */ |
| 17429 | int mDisabledSystemUiVisibility; |
| 17430 | |
| 17431 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17432 | * Last global system UI visibility reported by the window manager. |
| 17433 | */ |
| 17434 | int mGlobalSystemUiVisibility; |
| 17435 | |
| 17436 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17437 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 17438 | * attached. |
| 17439 | */ |
| 17440 | boolean mHasSystemUiListeners; |
| 17441 | |
| 17442 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17443 | * Set if the visibility of any views has changed. |
| 17444 | */ |
| 17445 | boolean mViewVisibilityChanged; |
| 17446 | |
| 17447 | /** |
| 17448 | * Set to true if a view has been scrolled. |
| 17449 | */ |
| 17450 | boolean mViewScrollChanged; |
| 17451 | |
| 17452 | /** |
| 17453 | * Global to the view hierarchy used as a temporary for dealing with |
| 17454 | * x/y points in the transparent region computations. |
| 17455 | */ |
| 17456 | final int[] mTransparentLocation = new int[2]; |
| 17457 | |
| 17458 | /** |
| 17459 | * Global to the view hierarchy used as a temporary for dealing with |
| 17460 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 17461 | */ |
| 17462 | final int[] mInvalidateChildLocation = new int[2]; |
| 17463 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17464 | |
| 17465 | /** |
| 17466 | * Global to the view hierarchy used as a temporary for dealing with |
| 17467 | * x/y location when view is transformed. |
| 17468 | */ |
| 17469 | final float[] mTmpTransformLocation = new float[2]; |
| 17470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17471 | /** |
| 17472 | * The view tree observer used to dispatch global events like |
| 17473 | * layout, pre-draw, touch mode change, etc. |
| 17474 | */ |
| 17475 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 17476 | |
| 17477 | /** |
| 17478 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 17479 | */ |
| 17480 | Canvas mCanvas; |
| 17481 | |
| 17482 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17483 | * The view root impl. |
| 17484 | */ |
| 17485 | final ViewRootImpl mViewRootImpl; |
| 17486 | |
| 17487 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 17488 | * 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] | 17489 | * handler can be used to pump events in the UI events queue. |
| 17490 | */ |
| 17491 | final Handler mHandler; |
| 17492 | |
| 17493 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17494 | * Temporary for use in computing invalidate rectangles while |
| 17495 | * calling up the hierarchy. |
| 17496 | */ |
| 17497 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17498 | |
| 17499 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 17500 | * Temporary for use in computing hit areas with transformed views |
| 17501 | */ |
| 17502 | final RectF mTmpTransformRect = new RectF(); |
| 17503 | |
| 17504 | /** |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 17505 | * Temporary for use in transforming invalidation rect |
| 17506 | */ |
| 17507 | final Matrix mTmpMatrix = new Matrix(); |
| 17508 | |
| 17509 | /** |
| 17510 | * Temporary for use in transforming invalidation rect |
| 17511 | */ |
| 17512 | final Transformation mTmpTransformation = new Transformation(); |
| 17513 | |
| 17514 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17515 | * Temporary list for use in collecting focusable descendents of a view. |
| 17516 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17517 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 17518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17519 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 17520 | * The id of the window for accessibility purposes. |
| 17521 | */ |
| 17522 | int mAccessibilityWindowId = View.NO_ID; |
| 17523 | |
| 17524 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 17525 | * Whether to ingore not exposed for accessibility Views when |
| 17526 | * reporting the view tree to accessibility services. |
| 17527 | */ |
| 17528 | boolean mIncludeNotImportantViews; |
| 17529 | |
| 17530 | /** |
| 17531 | * The drawable for highlighting accessibility focus. |
| 17532 | */ |
| 17533 | Drawable mAccessibilityFocusDrawable; |
| 17534 | |
| 17535 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17536 | * Show where the margins, bounds and layout bounds are for each view. |
| 17537 | */ |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 17538 | boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 17539 | |
| 17540 | /** |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 17541 | * Point used to compute visible regions. |
| 17542 | */ |
| 17543 | final Point mPoint = new Point(); |
| 17544 | |
| 17545 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17546 | * Creates a new set of attachment information with the specified |
| 17547 | * events handler and thread. |
| 17548 | * |
| 17549 | * @param handler the events handler the view must use |
| 17550 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17551 | AttachInfo(IWindowSession session, IWindow window, Display display, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17552 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17553 | mSession = session; |
| 17554 | mWindow = window; |
| 17555 | mWindowToken = window.asBinder(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17556 | mDisplay = display; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 17557 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17558 | mHandler = handler; |
| 17559 | mRootCallbacks = effectPlayer; |
| 17560 | } |
| 17561 | } |
| 17562 | |
| 17563 | /** |
| 17564 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 17565 | * is supported. This avoids keeping too many unused fields in most |
| 17566 | * instances of View.</p> |
| 17567 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17568 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17569 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17570 | /** |
| 17571 | * Scrollbars are not visible |
| 17572 | */ |
| 17573 | public static final int OFF = 0; |
| 17574 | |
| 17575 | /** |
| 17576 | * Scrollbars are visible |
| 17577 | */ |
| 17578 | public static final int ON = 1; |
| 17579 | |
| 17580 | /** |
| 17581 | * Scrollbars are fading away |
| 17582 | */ |
| 17583 | public static final int FADING = 2; |
| 17584 | |
| 17585 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17587 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17588 | public int scrollBarDefaultDelayBeforeFade; |
| 17589 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17590 | |
| 17591 | public int scrollBarSize; |
| 17592 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17593 | public float[] interpolatorValues; |
| 17594 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17595 | |
| 17596 | public final Paint paint; |
| 17597 | public final Matrix matrix; |
| 17598 | public Shader shader; |
| 17599 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17600 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 17601 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17602 | private static final float[] OPAQUE = { 255 }; |
| 17603 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17604 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17605 | /** |
| 17606 | * When fading should start. This time moves into the future every time |
| 17607 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 17608 | */ |
| 17609 | public long fadeStartTime; |
| 17610 | |
| 17611 | |
| 17612 | /** |
| 17613 | * The current state of the scrollbars: ON, OFF, or FADING |
| 17614 | */ |
| 17615 | public int state = OFF; |
| 17616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17617 | private int mLastColor; |
| 17618 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17619 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17620 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 17621 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17622 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 17623 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17624 | |
| 17625 | paint = new Paint(); |
| 17626 | matrix = new Matrix(); |
| 17627 | // use use a height of 1, and then wack the matrix each time we |
| 17628 | // actually use it. |
| 17629 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17630 | paint.setShader(shader); |
| 17631 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 17632 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17633 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17634 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17636 | public void setFadeColor(int color) { |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 17637 | if (color != mLastColor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17638 | mLastColor = color; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17639 | |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 17640 | if (color != 0) { |
| 17641 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 17642 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
| 17643 | paint.setShader(shader); |
| 17644 | // Restore the default transfer mode (src_over) |
| 17645 | paint.setXfermode(null); |
| 17646 | } else { |
| 17647 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
| 17648 | paint.setShader(shader); |
| 17649 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
| 17650 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17651 | } |
| 17652 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17653 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17654 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 17655 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17656 | if (now >= fadeStartTime) { |
| 17657 | |
| 17658 | // the animation fades the scrollbars out by changing |
| 17659 | // the opacity (alpha) from fully opaque to fully |
| 17660 | // transparent |
| 17661 | int nextFrame = (int) now; |
| 17662 | int framesCount = 0; |
| 17663 | |
| 17664 | Interpolator interpolator = scrollBarInterpolator; |
| 17665 | |
| 17666 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17667 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17668 | |
| 17669 | // End transparent |
| 17670 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 17671 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17672 | |
| 17673 | state = FADING; |
| 17674 | |
| 17675 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 17676 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17677 | } |
| 17678 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17679 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 17680 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 17681 | /** |
| 17682 | * Resuable callback for sending |
| 17683 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 17684 | */ |
| 17685 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 17686 | public volatile boolean mIsPending; |
| 17687 | |
| 17688 | public void run() { |
| 17689 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 17690 | mIsPending = false; |
| 17691 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17692 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17693 | |
| 17694 | /** |
| 17695 | * <p> |
| 17696 | * This class represents a delegate that can be registered in a {@link View} |
| 17697 | * to enhance accessibility support via composition rather via inheritance. |
| 17698 | * It is specifically targeted to widget developers that extend basic View |
| 17699 | * classes i.e. classes in package android.view, that would like their |
| 17700 | * applications to be backwards compatible. |
| 17701 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 17702 | * <div class="special reference"> |
| 17703 | * <h3>Developer Guides</h3> |
| 17704 | * <p>For more information about making applications accessible, read the |
| 17705 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 17706 | * developer guide.</p> |
| 17707 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17708 | * <p> |
| 17709 | * A scenario in which a developer would like to use an accessibility delegate |
| 17710 | * is overriding a method introduced in a later API version then the minimal API |
| 17711 | * version supported by the application. For example, the method |
| 17712 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 17713 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 17714 | * developer would like his application to run on API version 4 devices (assuming |
| 17715 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 17716 | * of this method, instead of overriding the method which would break the application's |
| 17717 | * backwards compatibility, he can override the corresponding method in this |
| 17718 | * delegate and register the delegate in the target View if the API version of |
| 17719 | * the system is high enough i.e. the API version is same or higher to the API |
| 17720 | * version that introduced |
| 17721 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 17722 | * </p> |
| 17723 | * <p> |
| 17724 | * Here is an example implementation: |
| 17725 | * </p> |
| 17726 | * <code><pre><p> |
| 17727 | * if (Build.VERSION.SDK_INT >= 14) { |
| 17728 | * // If the API version is equal of higher than the version in |
| 17729 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 17730 | * // register a delegate with a customized implementation. |
| 17731 | * View view = findViewById(R.id.view_id); |
| 17732 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 17733 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 17734 | * AccessibilityNodeInfo info) { |
| 17735 | * // Let the default implementation populate the info. |
| 17736 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 17737 | * // Set some other information. |
| 17738 | * info.setEnabled(host.isEnabled()); |
| 17739 | * } |
| 17740 | * }); |
| 17741 | * } |
| 17742 | * </code></pre></p> |
| 17743 | * <p> |
| 17744 | * This delegate contains methods that correspond to the accessibility methods |
| 17745 | * in View. If a delegate has been specified the implementation in View hands |
| 17746 | * off handling to the corresponding method in this delegate. The default |
| 17747 | * implementation the delegate methods behaves exactly as the corresponding |
| 17748 | * method in View for the case of no accessibility delegate been set. Hence, |
| 17749 | * to customize the behavior of a View method, clients can override only the |
| 17750 | * corresponding delegate method without altering the behavior of the rest |
| 17751 | * accessibility related methods of the host view. |
| 17752 | * </p> |
| 17753 | */ |
| 17754 | public static class AccessibilityDelegate { |
| 17755 | |
| 17756 | /** |
| 17757 | * Sends an accessibility event of the given type. If accessibility is not |
| 17758 | * enabled this method has no effect. |
| 17759 | * <p> |
| 17760 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 17761 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 17762 | * been set. |
| 17763 | * </p> |
| 17764 | * |
| 17765 | * @param host The View hosting the delegate. |
| 17766 | * @param eventType The type of the event to send. |
| 17767 | * |
| 17768 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 17769 | */ |
| 17770 | public void sendAccessibilityEvent(View host, int eventType) { |
| 17771 | host.sendAccessibilityEventInternal(eventType); |
| 17772 | } |
| 17773 | |
| 17774 | /** |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 17775 | * Performs the specified accessibility action on the view. For |
| 17776 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 17777 | * <p> |
| 17778 | * The default implementation behaves as |
| 17779 | * {@link View#performAccessibilityAction(int, Bundle) |
| 17780 | * View#performAccessibilityAction(int, Bundle)} for the case of |
| 17781 | * no accessibility delegate been set. |
| 17782 | * </p> |
| 17783 | * |
| 17784 | * @param action The action to perform. |
| 17785 | * @return Whether the action was performed. |
| 17786 | * |
| 17787 | * @see View#performAccessibilityAction(int, Bundle) |
| 17788 | * View#performAccessibilityAction(int, Bundle) |
| 17789 | */ |
| 17790 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 17791 | return host.performAccessibilityActionInternal(action, args); |
| 17792 | } |
| 17793 | |
| 17794 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17795 | * Sends an accessibility event. This method behaves exactly as |
| 17796 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 17797 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 17798 | * accessibility is enabled. |
| 17799 | * <p> |
| 17800 | * The default implementation behaves as |
| 17801 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17802 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 17803 | * the case of no accessibility delegate been set. |
| 17804 | * </p> |
| 17805 | * |
| 17806 | * @param host The View hosting the delegate. |
| 17807 | * @param event The event to send. |
| 17808 | * |
| 17809 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17810 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 17811 | */ |
| 17812 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 17813 | host.sendAccessibilityEventUncheckedInternal(event); |
| 17814 | } |
| 17815 | |
| 17816 | /** |
| 17817 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 17818 | * to its children for adding their text content to the event. |
| 17819 | * <p> |
| 17820 | * The default implementation behaves as |
| 17821 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17822 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17823 | * the case of no accessibility delegate been set. |
| 17824 | * </p> |
| 17825 | * |
| 17826 | * @param host The View hosting the delegate. |
| 17827 | * @param event The event. |
| 17828 | * @return True if the event population was completed. |
| 17829 | * |
| 17830 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17831 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 17832 | */ |
| 17833 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17834 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 17835 | } |
| 17836 | |
| 17837 | /** |
| 17838 | * Gives a chance to the host View to populate the accessibility event with its |
| 17839 | * text content. |
| 17840 | * <p> |
| 17841 | * The default implementation behaves as |
| 17842 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17843 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 17844 | * the case of no accessibility delegate been set. |
| 17845 | * </p> |
| 17846 | * |
| 17847 | * @param host The View hosting the delegate. |
| 17848 | * @param event The accessibility event which to populate. |
| 17849 | * |
| 17850 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17851 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 17852 | */ |
| 17853 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17854 | host.onPopulateAccessibilityEventInternal(event); |
| 17855 | } |
| 17856 | |
| 17857 | /** |
| 17858 | * Initializes an {@link AccessibilityEvent} with information about the |
| 17859 | * the host View which is the event source. |
| 17860 | * <p> |
| 17861 | * The default implementation behaves as |
| 17862 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17863 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 17864 | * the case of no accessibility delegate been set. |
| 17865 | * </p> |
| 17866 | * |
| 17867 | * @param host The View hosting the delegate. |
| 17868 | * @param event The event to initialize. |
| 17869 | * |
| 17870 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17871 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 17872 | */ |
| 17873 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 17874 | host.onInitializeAccessibilityEventInternal(event); |
| 17875 | } |
| 17876 | |
| 17877 | /** |
| 17878 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 17879 | * <p> |
| 17880 | * The default implementation behaves as |
| 17881 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17882 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 17883 | * the case of no accessibility delegate been set. |
| 17884 | * </p> |
| 17885 | * |
| 17886 | * @param host The View hosting the delegate. |
| 17887 | * @param info The instance to initialize. |
| 17888 | * |
| 17889 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17890 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 17891 | */ |
| 17892 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 17893 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 17894 | } |
| 17895 | |
| 17896 | /** |
| 17897 | * Called when a child of the host View has requested sending an |
| 17898 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 17899 | * to augment the event. |
| 17900 | * <p> |
| 17901 | * The default implementation behaves as |
| 17902 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17903 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 17904 | * the case of no accessibility delegate been set. |
| 17905 | * </p> |
| 17906 | * |
| 17907 | * @param host The View hosting the delegate. |
| 17908 | * @param child The child which requests sending the event. |
| 17909 | * @param event The event to be sent. |
| 17910 | * @return True if the event should be sent |
| 17911 | * |
| 17912 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17913 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 17914 | */ |
| 17915 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 17916 | AccessibilityEvent event) { |
| 17917 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 17918 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 17919 | |
| 17920 | /** |
| 17921 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 17922 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 17923 | * that explore the window content. |
| 17924 | * <p> |
| 17925 | * The default implementation behaves as |
| 17926 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 17927 | * the case of no accessibility delegate been set. |
| 17928 | * </p> |
| 17929 | * |
| 17930 | * @return The provider. |
| 17931 | * |
| 17932 | * @see AccessibilityNodeProvider |
| 17933 | */ |
| 17934 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 17935 | return null; |
| 17936 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 17937 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17938 | } |