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 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 19 | import android.app.ActivityThread; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 20 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 22 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.res.Resources; |
| 24 | import android.content.res.TypedArray; |
| 25 | import android.graphics.Bitmap; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 26 | import android.graphics.Camera; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.graphics.Canvas; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 28 | import android.graphics.Insets; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 29 | import android.graphics.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.graphics.LinearGradient; |
| 31 | import android.graphics.Matrix; |
| 32 | import android.graphics.Paint; |
| 33 | import android.graphics.PixelFormat; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 34 | import android.graphics.Point; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.graphics.PorterDuff; |
| 36 | import android.graphics.PorterDuffXfermode; |
| 37 | import android.graphics.Rect; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 38 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.graphics.Region; |
| 40 | import android.graphics.Shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.graphics.drawable.ColorDrawable; |
| 42 | import android.graphics.drawable.Drawable; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 43 | import android.hardware.display.DisplayManagerGlobal; |
Adam Powell | 7da4b73 | 2012-12-07 15:28:33 -0800 | [diff] [blame] | 44 | import android.os.Build; |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 45 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.os.Handler; |
| 47 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.os.Parcel; |
| 49 | import android.os.Parcelable; |
| 50 | import android.os.RemoteException; |
| 51 | import android.os.SystemClock; |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 52 | import android.os.SystemProperties; |
Fabrice Di Meglio | d3d9f3f | 2012-09-18 12:55:32 -0700 | [diff] [blame] | 53 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.util.AttributeSet; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 55 | import android.util.FloatProperty; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.util.Log; |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 57 | import android.util.Pools.SynchronizedPool; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 58 | import android.util.Property; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 59 | import android.util.SparseArray; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 60 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.view.ContextMenu.ContextMenuInfo; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 62 | import android.view.AccessibilityIterators.TextSegmentIterator; |
| 63 | import android.view.AccessibilityIterators.CharacterTextSegmentIterator; |
| 64 | import android.view.AccessibilityIterators.WordTextSegmentIterator; |
| 65 | import android.view.AccessibilityIterators.ParagraphTextSegmentIterator; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 66 | import android.view.accessibility.AccessibilityEvent; |
| 67 | import android.view.accessibility.AccessibilityEventSource; |
| 68 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 69 | import android.view.accessibility.AccessibilityNodeInfo; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 70 | import android.view.accessibility.AccessibilityNodeProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.view.animation.Animation; |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 72 | import android.view.animation.AnimationUtils; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 73 | import android.view.animation.Transformation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 74 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.view.inputmethod.InputConnection; |
| 76 | import android.view.inputmethod.InputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | import android.widget.ScrollBarDrawable; |
| 78 | |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 79 | import static android.os.Build.VERSION_CODES.*; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 80 | import static java.lang.Math.max; |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 81 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 82 | import com.android.internal.R; |
| 83 | import com.android.internal.util.Predicate; |
| 84 | import com.android.internal.view.menu.MenuBuilder; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 85 | import com.google.android.collect.Lists; |
| 86 | import com.google.android.collect.Maps; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 87 | |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 88 | import java.lang.ref.WeakReference; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 89 | import java.lang.reflect.Field; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 90 | import java.lang.reflect.InvocationTargetException; |
| 91 | import java.lang.reflect.Method; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 92 | import java.lang.reflect.Modifier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import java.util.ArrayList; |
| 94 | import java.util.Arrays; |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 95 | import java.util.Collections; |
| 96 | import java.util.HashMap; |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 97 | import java.util.Locale; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 98 | import java.util.concurrent.CopyOnWriteArrayList; |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 99 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * <p> |
| 103 | * This class represents the basic building block for user interface components. A View |
| 104 | * occupies a rectangular area on the screen and is responsible for drawing and |
| 105 | * 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] | 106 | * 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] | 107 | * {@link android.view.ViewGroup} subclass is the base class for <em>layouts</em>, which |
| 108 | * are invisible containers that hold other Views (or other ViewGroups) and define |
| 109 | * their layout properties. |
| 110 | * </p> |
| 111 | * |
Joe Fernandez | b54e7a3 | 2011-10-03 15:09:50 -0700 | [diff] [blame] | 112 | * <div class="special reference"> |
| 113 | * <h3>Developer Guides</h3> |
| 114 | * <p>For information about using this class to develop your application's user interface, |
| 115 | * 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] | 116 | * </div> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 117 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | * <a name="Using"></a> |
| 119 | * <h3>Using Views</h3> |
| 120 | * <p> |
| 121 | * All of the views in a window are arranged in a single tree. You can add views |
| 122 | * either from code or by specifying a tree of views in one or more XML layout |
| 123 | * files. There are many specialized subclasses of views that act as controls or |
| 124 | * are capable of displaying text, images, or other content. |
| 125 | * </p> |
| 126 | * <p> |
| 127 | * Once you have created a tree of views, there are typically a few types of |
| 128 | * common operations you may wish to perform: |
| 129 | * <ul> |
| 130 | * <li><strong>Set properties:</strong> for example setting the text of a |
| 131 | * {@link android.widget.TextView}. The available properties and the methods |
| 132 | * that set them will vary among the different subclasses of views. Note that |
| 133 | * properties that are known at build time can be set in the XML layout |
| 134 | * files.</li> |
| 135 | * <li><strong>Set focus:</strong> The framework will handled moving focus in |
| 136 | * response to user input. To force focus to a specific view, call |
| 137 | * {@link #requestFocus}.</li> |
| 138 | * <li><strong>Set up listeners:</strong> Views allow clients to set listeners |
| 139 | * that will be notified when something interesting happens to the view. For |
| 140 | * example, all views will let you set a listener to be notified when the view |
| 141 | * gains or loses focus. You can register such a listener using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 142 | * {@link #setOnFocusChangeListener(android.view.View.OnFocusChangeListener)}. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 143 | * Other view subclasses offer more specialized listeners. For example, a Button |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 144 | * 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] | 145 | * <li><strong>Set visibility:</strong> You can hide or show views using |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 146 | * {@link #setVisibility(int)}.</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | * </ul> |
| 148 | * </p> |
| 149 | * <p><em> |
| 150 | * Note: The Android framework is responsible for measuring, laying out and |
| 151 | * drawing views. You should not call methods that perform these actions on |
| 152 | * views yourself unless you are actually implementing a |
| 153 | * {@link android.view.ViewGroup}. |
| 154 | * </em></p> |
| 155 | * |
| 156 | * <a name="Lifecycle"></a> |
| 157 | * <h3>Implementing a Custom View</h3> |
| 158 | * |
| 159 | * <p> |
| 160 | * To implement a custom view, you will usually begin by providing overrides for |
| 161 | * some of the standard methods that the framework calls on all views. You do |
| 162 | * not need to override all of these methods. In fact, you can start by just |
| 163 | * overriding {@link #onDraw(android.graphics.Canvas)}. |
| 164 | * <table border="2" width="85%" align="center" cellpadding="5"> |
| 165 | * <thead> |
| 166 | * <tr><th>Category</th> <th>Methods</th> <th>Description</th></tr> |
| 167 | * </thead> |
| 168 | * |
| 169 | * <tbody> |
| 170 | * <tr> |
| 171 | * <td rowspan="2">Creation</td> |
| 172 | * <td>Constructors</td> |
| 173 | * <td>There is a form of the constructor that are called when the view |
| 174 | * is created from code and a form that is called when the view is |
| 175 | * inflated from a layout file. The second form should parse and apply |
| 176 | * any attributes defined in the layout file. |
| 177 | * </td> |
| 178 | * </tr> |
| 179 | * <tr> |
| 180 | * <td><code>{@link #onFinishInflate()}</code></td> |
| 181 | * <td>Called after a view and all of its children has been inflated |
| 182 | * from XML.</td> |
| 183 | * </tr> |
| 184 | * |
| 185 | * <tr> |
| 186 | * <td rowspan="3">Layout</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 187 | * <td><code>{@link #onMeasure(int, int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | * <td>Called to determine the size requirements for this view and all |
| 189 | * of its children. |
| 190 | * </td> |
| 191 | * </tr> |
| 192 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 193 | * <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] | 194 | * <td>Called when this view should assign a size and position to all |
| 195 | * of its children. |
| 196 | * </td> |
| 197 | * </tr> |
| 198 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 199 | * <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] | 200 | * <td>Called when the size of this view has changed. |
| 201 | * </td> |
| 202 | * </tr> |
| 203 | * |
| 204 | * <tr> |
| 205 | * <td>Drawing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 206 | * <td><code>{@link #onDraw(android.graphics.Canvas)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | * <td>Called when the view should render its content. |
| 208 | * </td> |
| 209 | * </tr> |
| 210 | * |
| 211 | * <tr> |
| 212 | * <td rowspan="4">Event processing</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 213 | * <td><code>{@link #onKeyDown(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 214 | * <td>Called when a new hardware key event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | * </td> |
| 216 | * </tr> |
| 217 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 218 | * <td><code>{@link #onKeyUp(int, KeyEvent)}</code></td> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 219 | * <td>Called when a hardware key up event occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | * </td> |
| 221 | * </tr> |
| 222 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 223 | * <td><code>{@link #onTrackballEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | * <td>Called when a trackball motion event occurs. |
| 225 | * </td> |
| 226 | * </tr> |
| 227 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 228 | * <td><code>{@link #onTouchEvent(MotionEvent)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | * <td>Called when a touch screen motion event occurs. |
| 230 | * </td> |
| 231 | * </tr> |
| 232 | * |
| 233 | * <tr> |
| 234 | * <td rowspan="2">Focus</td> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 235 | * <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] | 236 | * <td>Called when the view gains or loses focus. |
| 237 | * </td> |
| 238 | * </tr> |
| 239 | * |
| 240 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 241 | * <td><code>{@link #onWindowFocusChanged(boolean)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | * <td>Called when the window containing the view gains or loses focus. |
| 243 | * </td> |
| 244 | * </tr> |
| 245 | * |
| 246 | * <tr> |
| 247 | * <td rowspan="3">Attaching</td> |
| 248 | * <td><code>{@link #onAttachedToWindow()}</code></td> |
| 249 | * <td>Called when the view is attached to a window. |
| 250 | * </td> |
| 251 | * </tr> |
| 252 | * |
| 253 | * <tr> |
| 254 | * <td><code>{@link #onDetachedFromWindow}</code></td> |
| 255 | * <td>Called when the view is detached from its window. |
| 256 | * </td> |
| 257 | * </tr> |
| 258 | * |
| 259 | * <tr> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 260 | * <td><code>{@link #onWindowVisibilityChanged(int)}</code></td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | * <td>Called when the visibility of the window containing the view |
| 262 | * has changed. |
| 263 | * </td> |
| 264 | * </tr> |
| 265 | * </tbody> |
| 266 | * |
| 267 | * </table> |
| 268 | * </p> |
| 269 | * |
| 270 | * <a name="IDs"></a> |
| 271 | * <h3>IDs</h3> |
| 272 | * Views may have an integer id associated with them. These ids are typically |
| 273 | * assigned in the layout XML files, and are used to find specific views within |
| 274 | * the view tree. A common pattern is to: |
| 275 | * <ul> |
| 276 | * <li>Define a Button in the layout file and assign it a unique ID. |
| 277 | * <pre> |
Gilles Debunne | 0243caf | 2010-08-24 23:06:35 -0700 | [diff] [blame] | 278 | * <Button |
| 279 | * android:id="@+id/my_button" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | * android:layout_width="wrap_content" |
| 281 | * android:layout_height="wrap_content" |
| 282 | * android:text="@string/my_button_text"/> |
| 283 | * </pre></li> |
| 284 | * <li>From the onCreate method of an Activity, find the Button |
| 285 | * <pre class="prettyprint"> |
| 286 | * Button myButton = (Button) findViewById(R.id.my_button); |
| 287 | * </pre></li> |
| 288 | * </ul> |
| 289 | * <p> |
| 290 | * View IDs need not be unique throughout the tree, but it is good practice to |
| 291 | * ensure that they are at least unique within the part of the tree you are |
| 292 | * searching. |
| 293 | * </p> |
| 294 | * |
| 295 | * <a name="Position"></a> |
| 296 | * <h3>Position</h3> |
| 297 | * <p> |
| 298 | * The geometry of a view is that of a rectangle. A view has a location, |
| 299 | * expressed as a pair of <em>left</em> and <em>top</em> coordinates, and |
| 300 | * two dimensions, expressed as a width and a height. The unit for location |
| 301 | * and dimensions is the pixel. |
| 302 | * </p> |
| 303 | * |
| 304 | * <p> |
| 305 | * It is possible to retrieve the location of a view by invoking the methods |
| 306 | * {@link #getLeft()} and {@link #getTop()}. The former returns the left, or X, |
| 307 | * coordinate of the rectangle representing the view. The latter returns the |
| 308 | * top, or Y, coordinate of the rectangle representing the view. These methods |
| 309 | * both return the location of the view relative to its parent. For instance, |
| 310 | * when getLeft() returns 20, that means the view is located 20 pixels to the |
| 311 | * right of the left edge of its direct parent. |
| 312 | * </p> |
| 313 | * |
| 314 | * <p> |
| 315 | * In addition, several convenience methods are offered to avoid unnecessary |
| 316 | * computations, namely {@link #getRight()} and {@link #getBottom()}. |
| 317 | * These methods return the coordinates of the right and bottom edges of the |
| 318 | * rectangle representing the view. For instance, calling {@link #getRight()} |
| 319 | * is similar to the following computation: <code>getLeft() + getWidth()</code> |
| 320 | * (see <a href="#SizePaddingMargins">Size</a> for more information about the width.) |
| 321 | * </p> |
| 322 | * |
| 323 | * <a name="SizePaddingMargins"></a> |
| 324 | * <h3>Size, padding and margins</h3> |
| 325 | * <p> |
| 326 | * The size of a view is expressed with a width and a height. A view actually |
| 327 | * possess two pairs of width and height values. |
| 328 | * </p> |
| 329 | * |
| 330 | * <p> |
| 331 | * The first pair is known as <em>measured width</em> and |
| 332 | * <em>measured height</em>. These dimensions define how big a view wants to be |
| 333 | * within its parent (see <a href="#Layout">Layout</a> for more details.) The |
| 334 | * measured dimensions can be obtained by calling {@link #getMeasuredWidth()} |
| 335 | * and {@link #getMeasuredHeight()}. |
| 336 | * </p> |
| 337 | * |
| 338 | * <p> |
| 339 | * The second pair is simply known as <em>width</em> and <em>height</em>, or |
| 340 | * sometimes <em>drawing width</em> and <em>drawing height</em>. These |
| 341 | * dimensions define the actual size of the view on screen, at drawing time and |
| 342 | * after layout. These values may, but do not have to, be different from the |
| 343 | * measured width and height. The width and height can be obtained by calling |
| 344 | * {@link #getWidth()} and {@link #getHeight()}. |
| 345 | * </p> |
| 346 | * |
| 347 | * <p> |
| 348 | * To measure its dimensions, a view takes into account its padding. The padding |
| 349 | * is expressed in pixels for the left, top, right and bottom parts of the view. |
| 350 | * Padding can be used to offset the content of the view by a specific amount of |
| 351 | * pixels. For instance, a left padding of 2 will push the view's content by |
| 352 | * 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] | 353 | * {@link #setPadding(int, int, int, int)} or {@link #setPaddingRelative(int, int, int, int)} |
| 354 | * method and queried by calling {@link #getPaddingLeft()}, {@link #getPaddingTop()}, |
| 355 | * {@link #getPaddingRight()}, {@link #getPaddingBottom()}, {@link #getPaddingStart()}, |
| 356 | * {@link #getPaddingEnd()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | * </p> |
| 358 | * |
| 359 | * <p> |
| 360 | * Even though a view can define a padding, it does not provide any support for |
| 361 | * margins. However, view groups provide such a support. Refer to |
| 362 | * {@link android.view.ViewGroup} and |
| 363 | * {@link android.view.ViewGroup.MarginLayoutParams} for further information. |
| 364 | * </p> |
| 365 | * |
| 366 | * <a name="Layout"></a> |
| 367 | * <h3>Layout</h3> |
| 368 | * <p> |
| 369 | * Layout is a two pass process: a measure pass and a layout pass. The measuring |
| 370 | * pass is implemented in {@link #measure(int, int)} and is a top-down traversal |
| 371 | * of the view tree. Each view pushes dimension specifications down the tree |
| 372 | * during the recursion. At the end of the measure pass, every view has stored |
| 373 | * its measurements. The second pass happens in |
| 374 | * {@link #layout(int,int,int,int)} and is also top-down. During |
| 375 | * this pass each parent is responsible for positioning all of its children |
| 376 | * using the sizes computed in the measure pass. |
| 377 | * </p> |
| 378 | * |
| 379 | * <p> |
| 380 | * When a view's measure() method returns, its {@link #getMeasuredWidth()} and |
| 381 | * {@link #getMeasuredHeight()} values must be set, along with those for all of |
| 382 | * that view's descendants. A view's measured width and measured height values |
| 383 | * must respect the constraints imposed by the view's parents. This guarantees |
| 384 | * that at the end of the measure pass, all parents accept all of their |
| 385 | * children's measurements. A parent view may call measure() more than once on |
| 386 | * its children. For example, the parent may measure each child once with |
| 387 | * unspecified dimensions to find out how big they want to be, then call |
| 388 | * measure() on them again with actual numbers if the sum of all the children's |
| 389 | * unconstrained sizes is too big or too small. |
| 390 | * </p> |
| 391 | * |
| 392 | * <p> |
| 393 | * The measure pass uses two classes to communicate dimensions. The |
| 394 | * {@link MeasureSpec} class is used by views to tell their parents how they |
| 395 | * want to be measured and positioned. The base LayoutParams class just |
| 396 | * describes how big the view wants to be for both width and height. For each |
| 397 | * dimension, it can specify one of: |
| 398 | * <ul> |
| 399 | * <li> an exact number |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 400 | * <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] | 401 | * (minus padding) |
| 402 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough to |
| 403 | * enclose its content (plus padding). |
| 404 | * </ul> |
| 405 | * There are subclasses of LayoutParams for different subclasses of ViewGroup. |
| 406 | * For example, AbsoluteLayout has its own subclass of LayoutParams which adds |
| 407 | * an X and Y value. |
| 408 | * </p> |
| 409 | * |
| 410 | * <p> |
| 411 | * MeasureSpecs are used to push requirements down the tree from parent to |
| 412 | * child. A MeasureSpec can be in one of three modes: |
| 413 | * <ul> |
| 414 | * <li>UNSPECIFIED: This is used by a parent to determine the desired dimension |
| 415 | * of a child view. For example, a LinearLayout may call measure() on its child |
| 416 | * with the height set to UNSPECIFIED and a width of EXACTLY 240 to find out how |
| 417 | * tall the child view wants to be given a width of 240 pixels. |
| 418 | * <li>EXACTLY: This is used by the parent to impose an exact size on the |
| 419 | * child. The child must use this size, and guarantee that all of its |
| 420 | * descendants will fit within this size. |
| 421 | * <li>AT_MOST: This is used by the parent to impose a maximum size on the |
| 422 | * child. The child must gurantee that it and all of its descendants will fit |
| 423 | * within this size. |
| 424 | * </ul> |
| 425 | * </p> |
| 426 | * |
| 427 | * <p> |
| 428 | * To intiate a layout, call {@link #requestLayout}. This method is typically |
| 429 | * called by a view on itself when it believes that is can no longer fit within |
| 430 | * its current bounds. |
| 431 | * </p> |
| 432 | * |
| 433 | * <a name="Drawing"></a> |
| 434 | * <h3>Drawing</h3> |
| 435 | * <p> |
| 436 | * Drawing is handled by walking the tree and rendering each view that |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 437 | * 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] | 438 | * this means that parents will draw before (i.e., behind) their children, with |
| 439 | * siblings drawn in the order they appear in the tree. |
| 440 | * If you set a background drawable for a View, then the View will draw it for you |
| 441 | * before calling back to its <code>onDraw()</code> method. |
| 442 | * </p> |
| 443 | * |
| 444 | * <p> |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 445 | * 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] | 446 | * </p> |
| 447 | * |
| 448 | * <p> |
| 449 | * To force a view to draw, call {@link #invalidate()}. |
| 450 | * </p> |
| 451 | * |
| 452 | * <a name="EventHandlingThreading"></a> |
| 453 | * <h3>Event Handling and Threading</h3> |
| 454 | * <p> |
| 455 | * The basic cycle of a view is as follows: |
| 456 | * <ol> |
| 457 | * <li>An event comes in and is dispatched to the appropriate view. The view |
| 458 | * handles the event and notifies any listeners.</li> |
| 459 | * <li>If in the course of processing the event, the view's bounds may need |
| 460 | * to be changed, the view will call {@link #requestLayout()}.</li> |
| 461 | * <li>Similarly, if in the course of processing the event the view's appearance |
| 462 | * may need to be changed, the view will call {@link #invalidate()}.</li> |
| 463 | * <li>If either {@link #requestLayout()} or {@link #invalidate()} were called, |
| 464 | * the framework will take care of measuring, laying out, and drawing the tree |
| 465 | * as appropriate.</li> |
| 466 | * </ol> |
| 467 | * </p> |
| 468 | * |
| 469 | * <p><em>Note: The entire view tree is single threaded. You must always be on |
| 470 | * the UI thread when calling any method on any view.</em> |
| 471 | * If you are doing work on other threads and want to update the state of a view |
| 472 | * from that thread, you should use a {@link Handler}. |
| 473 | * </p> |
| 474 | * |
| 475 | * <a name="FocusHandling"></a> |
| 476 | * <h3>Focus Handling</h3> |
| 477 | * <p> |
| 478 | * The framework will handle routine focus movement in response to user input. |
| 479 | * This includes changing the focus as views are removed or hidden, or as new |
| 480 | * views become available. Views indicate their willingness to take focus |
| 481 | * through the {@link #isFocusable} method. To change whether a view can take |
| 482 | * focus, call {@link #setFocusable(boolean)}. When in touch mode (see notes below) |
| 483 | * views indicate whether they still would like focus via {@link #isFocusableInTouchMode} |
| 484 | * and can change this via {@link #setFocusableInTouchMode(boolean)}. |
| 485 | * </p> |
| 486 | * <p> |
| 487 | * Focus movement is based on an algorithm which finds the nearest neighbor in a |
| 488 | * given direction. In rare cases, the default algorithm may not match the |
| 489 | * intended behavior of the developer. In these situations, you can provide |
| 490 | * explicit overrides by using these XML attributes in the layout file: |
| 491 | * <pre> |
| 492 | * nextFocusDown |
| 493 | * nextFocusLeft |
| 494 | * nextFocusRight |
| 495 | * nextFocusUp |
| 496 | * </pre> |
| 497 | * </p> |
| 498 | * |
| 499 | * |
| 500 | * <p> |
| 501 | * To get a particular view to take focus, call {@link #requestFocus()}. |
| 502 | * </p> |
| 503 | * |
| 504 | * <a name="TouchMode"></a> |
| 505 | * <h3>Touch Mode</h3> |
| 506 | * <p> |
| 507 | * When a user is navigating a user interface via directional keys such as a D-pad, it is |
| 508 | * necessary to give focus to actionable items such as buttons so the user can see |
| 509 | * what will take input. If the device has touch capabilities, however, and the user |
| 510 | * begins interacting with the interface by touching it, it is no longer necessary to |
| 511 | * always highlight, or give focus to, a particular view. This motivates a mode |
| 512 | * for interaction named 'touch mode'. |
| 513 | * </p> |
| 514 | * <p> |
| 515 | * For a touch capable device, once the user touches the screen, the device |
| 516 | * will enter touch mode. From this point onward, only views for which |
| 517 | * {@link #isFocusableInTouchMode} is true will be focusable, such as text editing widgets. |
| 518 | * Other views that are touchable, like buttons, will not take focus when touched; they will |
| 519 | * only fire the on click listeners. |
| 520 | * </p> |
| 521 | * <p> |
| 522 | * Any time a user hits a directional key, such as a D-pad direction, the view device will |
| 523 | * exit touch mode, and find a view to take focus, so that the user may resume interacting |
| 524 | * with the user interface without touching the screen again. |
| 525 | * </p> |
| 526 | * <p> |
| 527 | * The touch mode state is maintained across {@link android.app.Activity}s. Call |
| 528 | * {@link #isInTouchMode} to see whether the device is currently in touch mode. |
| 529 | * </p> |
| 530 | * |
| 531 | * <a name="Scrolling"></a> |
| 532 | * <h3>Scrolling</h3> |
| 533 | * <p> |
| 534 | * The framework provides basic support for views that wish to internally |
| 535 | * scroll their content. This includes keeping track of the X and Y scroll |
| 536 | * offset as well as mechanisms for drawing scrollbars. See |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 537 | * {@link #scrollBy(int, int)}, {@link #scrollTo(int, int)}, and |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 538 | * {@link #awakenScrollBars()} for more details. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | * </p> |
| 540 | * |
| 541 | * <a name="Tags"></a> |
| 542 | * <h3>Tags</h3> |
| 543 | * <p> |
| 544 | * Unlike IDs, tags are not used to identify views. Tags are essentially an |
| 545 | * extra piece of information that can be associated with a view. They are most |
| 546 | * often used as a convenience to store data related to views in the views |
| 547 | * themselves rather than by putting them in a separate structure. |
| 548 | * </p> |
| 549 | * |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 550 | * <a name="Properties"></a> |
| 551 | * <h3>Properties</h3> |
| 552 | * <p> |
| 553 | * The View class exposes an {@link #ALPHA} property, as well as several transform-related |
| 554 | * properties, such as {@link #TRANSLATION_X} and {@link #TRANSLATION_Y}. These properties are |
| 555 | * available both in the {@link Property} form as well as in similarly-named setter/getter |
| 556 | * methods (such as {@link #setAlpha(float)} for {@link #ALPHA}). These properties can |
| 557 | * be used to set persistent state associated with these rendering-related properties on the view. |
| 558 | * The properties and methods can also be used in conjunction with |
| 559 | * {@link android.animation.Animator Animator}-based animations, described more in the |
| 560 | * <a href="#Animation">Animation</a> section. |
| 561 | * </p> |
| 562 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | * <a name="Animation"></a> |
| 564 | * <h3>Animation</h3> |
| 565 | * <p> |
Chet Haase | cb150fe | 2012-05-03 15:15:05 -0700 | [diff] [blame] | 566 | * Starting with Android 3.0, the preferred way of animating views is to use the |
| 567 | * {@link android.animation} package APIs. These {@link android.animation.Animator Animator}-based |
| 568 | * classes change actual properties of the View object, such as {@link #setAlpha(float) alpha} and |
| 569 | * {@link #setTranslationX(float) translationX}. This behavior is contrasted to that of the pre-3.0 |
| 570 | * {@link android.view.animation.Animation Animation}-based classes, which instead animate only |
| 571 | * how the view is drawn on the display. In particular, the {@link ViewPropertyAnimator} class |
| 572 | * makes animating these View properties particularly easy and efficient. |
| 573 | * </p> |
| 574 | * <p> |
| 575 | * 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] | 576 | * You can attach an {@link Animation} object to a view using |
| 577 | * {@link #setAnimation(Animation)} or |
| 578 | * {@link #startAnimation(Animation)}. The animation can alter the scale, |
| 579 | * rotation, translation and alpha of a view over time. If the animation is |
| 580 | * attached to a view that has children, the animation will affect the entire |
| 581 | * subtree rooted by that node. When an animation is started, the framework will |
| 582 | * take care of redrawing the appropriate views until the animation completes. |
| 583 | * </p> |
| 584 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 585 | * <a name="Security"></a> |
| 586 | * <h3>Security</h3> |
| 587 | * <p> |
| 588 | * Sometimes it is essential that an application be able to verify that an action |
| 589 | * is being performed with the full knowledge and consent of the user, such as |
| 590 | * granting a permission request, making a purchase or clicking on an advertisement. |
| 591 | * Unfortunately, a malicious application could try to spoof the user into |
| 592 | * performing these actions, unaware, by concealing the intended purpose of the view. |
| 593 | * As a remedy, the framework offers a touch filtering mechanism that can be used to |
| 594 | * improve the security of views that provide access to sensitive functionality. |
| 595 | * </p><p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 596 | * To enable touch filtering, call {@link #setFilterTouchesWhenObscured(boolean)} or set the |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 597 | * android:filterTouchesWhenObscured layout attribute to true. When enabled, the framework |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 598 | * will discard touches that are received whenever the view's window is obscured by |
| 599 | * another visible window. As a result, the view will not receive touches whenever a |
| 600 | * toast, dialog or other window appears above the view's window. |
| 601 | * </p><p> |
| 602 | * For more fine-grained control over security, consider overriding the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 603 | * {@link #onFilterTouchEventForSecurity(MotionEvent)} method to implement your own |
| 604 | * security policy. See also {@link MotionEvent#FLAG_WINDOW_IS_OBSCURED}. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 605 | * </p> |
| 606 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 607 | * @attr ref android.R.styleable#View_alpha |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 608 | * @attr ref android.R.styleable#View_background |
| 609 | * @attr ref android.R.styleable#View_clickable |
| 610 | * @attr ref android.R.styleable#View_contentDescription |
| 611 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 612 | * @attr ref android.R.styleable#View_duplicateParentState |
| 613 | * @attr ref android.R.styleable#View_id |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 614 | * @attr ref android.R.styleable#View_requiresFadingEdge |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 615 | * @attr ref android.R.styleable#View_fadeScrollbars |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 616 | * @attr ref android.R.styleable#View_fadingEdgeLength |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 617 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 619 | * @attr ref android.R.styleable#View_isScrollContainer |
| 620 | * @attr ref android.R.styleable#View_focusable |
| 621 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 622 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 623 | * @attr ref android.R.styleable#View_keepScreenOn |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 624 | * @attr ref android.R.styleable#View_layerType |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 625 | * @attr ref android.R.styleable#View_layoutDirection |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 626 | * @attr ref android.R.styleable#View_longClickable |
| 627 | * @attr ref android.R.styleable#View_minHeight |
| 628 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | * @attr ref android.R.styleable#View_nextFocusDown |
| 630 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 631 | * @attr ref android.R.styleable#View_nextFocusRight |
| 632 | * @attr ref android.R.styleable#View_nextFocusUp |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 633 | * @attr ref android.R.styleable#View_onClick |
| 634 | * @attr ref android.R.styleable#View_padding |
| 635 | * @attr ref android.R.styleable#View_paddingBottom |
| 636 | * @attr ref android.R.styleable#View_paddingLeft |
| 637 | * @attr ref android.R.styleable#View_paddingRight |
| 638 | * @attr ref android.R.styleable#View_paddingTop |
Fabrice Di Meglio | 101d5aa | 2012-02-16 18:36:06 -0800 | [diff] [blame] | 639 | * @attr ref android.R.styleable#View_paddingStart |
| 640 | * @attr ref android.R.styleable#View_paddingEnd |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 641 | * @attr ref android.R.styleable#View_saveEnabled |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 642 | * @attr ref android.R.styleable#View_rotation |
| 643 | * @attr ref android.R.styleable#View_rotationX |
| 644 | * @attr ref android.R.styleable#View_rotationY |
| 645 | * @attr ref android.R.styleable#View_scaleX |
| 646 | * @attr ref android.R.styleable#View_scaleY |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | * @attr ref android.R.styleable#View_scrollX |
| 648 | * @attr ref android.R.styleable#View_scrollY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 649 | * @attr ref android.R.styleable#View_scrollbarSize |
| 650 | * @attr ref android.R.styleable#View_scrollbarStyle |
| 651 | * @attr ref android.R.styleable#View_scrollbars |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 652 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 653 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | * @attr ref android.R.styleable#View_scrollbarTrackHorizontal |
| 655 | * @attr ref android.R.styleable#View_scrollbarThumbHorizontal |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | * @attr ref android.R.styleable#View_scrollbarThumbVertical |
| 657 | * @attr ref android.R.styleable#View_scrollbarTrackVertical |
| 658 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawHorizontalTrack |
| 659 | * @attr ref android.R.styleable#View_scrollbarAlwaysDrawVerticalTrack |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 660 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 661 | * @attr ref android.R.styleable#View_tag |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 662 | * @attr ref android.R.styleable#View_textAlignment |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 663 | * @attr ref android.R.styleable#View_textDirection |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 664 | * @attr ref android.R.styleable#View_transformPivotX |
| 665 | * @attr ref android.R.styleable#View_transformPivotY |
| 666 | * @attr ref android.R.styleable#View_translationX |
| 667 | * @attr ref android.R.styleable#View_translationY |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 668 | * @attr ref android.R.styleable#View_visibility |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | * |
| 670 | * @see android.view.ViewGroup |
| 671 | */ |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 672 | public class View implements Drawable.Callback, KeyEvent.Callback, |
Adam Powell | 8fc54f9 | 2011-09-07 16:40:45 -0700 | [diff] [blame] | 673 | AccessibilityEventSource { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | private static final boolean DBG = false; |
| 675 | |
| 676 | /** |
| 677 | * The logging tag used by this class with android.util.Log. |
| 678 | */ |
| 679 | protected static final String VIEW_LOG_TAG = "View"; |
| 680 | |
| 681 | /** |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 682 | * When set to true, apps will draw debugging information about their layouts. |
Romain Guy | 4b8c4f8 | 2012-04-27 15:48:35 -0700 | [diff] [blame] | 683 | * |
| 684 | * @hide |
| 685 | */ |
| 686 | public static final String DEBUG_LAYOUT_PROPERTY = "debug.layout"; |
| 687 | |
| 688 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | * Used to mark a View that has no ID. |
| 690 | */ |
| 691 | public static final int NO_ID = -1; |
| 692 | |
Adam Powell | 7da4b73 | 2012-12-07 15:28:33 -0800 | [diff] [blame] | 693 | private static boolean sUseBrokenMakeMeasureSpec = false; |
| 694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | /** |
| 696 | * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when |
| 697 | * calling setFlags. |
| 698 | */ |
| 699 | private static final int NOT_FOCUSABLE = 0x00000000; |
| 700 | |
| 701 | /** |
| 702 | * This view wants keystrokes. Use with TAKES_FOCUS_MASK when calling |
| 703 | * setFlags. |
| 704 | */ |
| 705 | private static final int FOCUSABLE = 0x00000001; |
| 706 | |
| 707 | /** |
| 708 | * Mask for use with setFlags indicating bits used for focus. |
| 709 | */ |
| 710 | private static final int FOCUSABLE_MASK = 0x00000001; |
| 711 | |
| 712 | /** |
| 713 | * This view will adjust its padding to fit sytem windows (e.g. status bar) |
| 714 | */ |
| 715 | private static final int FITS_SYSTEM_WINDOWS = 0x00000002; |
| 716 | |
| 717 | /** |
Scott Main | 812634c2 | 2011-07-27 13:22:35 -0700 | [diff] [blame] | 718 | * This view is visible. |
| 719 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 720 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | */ |
| 722 | public static final int VISIBLE = 0x00000000; |
| 723 | |
| 724 | /** |
| 725 | * 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] | 726 | * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 727 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 728 | */ |
| 729 | public static final int INVISIBLE = 0x00000004; |
| 730 | |
| 731 | /** |
| 732 | * 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] | 733 | * purposes. Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code |
| 734 | * android:visibility}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | */ |
| 736 | public static final int GONE = 0x00000008; |
| 737 | |
| 738 | /** |
| 739 | * Mask for use with setFlags indicating bits used for visibility. |
| 740 | * {@hide} |
| 741 | */ |
| 742 | static final int VISIBILITY_MASK = 0x0000000C; |
| 743 | |
| 744 | private static final int[] VISIBILITY_FLAGS = {VISIBLE, INVISIBLE, GONE}; |
| 745 | |
| 746 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 747 | * This view is enabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | * Use with ENABLED_MASK when calling setFlags. |
| 749 | * {@hide} |
| 750 | */ |
| 751 | static final int ENABLED = 0x00000000; |
| 752 | |
| 753 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 754 | * This view is disabled. Interpretation varies by subclass. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | * Use with ENABLED_MASK when calling setFlags. |
| 756 | * {@hide} |
| 757 | */ |
| 758 | static final int DISABLED = 0x00000020; |
| 759 | |
| 760 | /** |
| 761 | * Mask for use with setFlags indicating bits used for indicating whether |
| 762 | * this view is enabled |
| 763 | * {@hide} |
| 764 | */ |
| 765 | static final int ENABLED_MASK = 0x00000020; |
| 766 | |
| 767 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 768 | * This view won't draw. {@link #onDraw(android.graphics.Canvas)} won't be |
| 769 | * called and further optimizations will be performed. It is okay to have |
| 770 | * 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] | 771 | * {@hide} |
| 772 | */ |
| 773 | static final int WILL_NOT_DRAW = 0x00000080; |
| 774 | |
| 775 | /** |
| 776 | * Mask for use with setFlags indicating bits used for indicating whether |
| 777 | * this view is will draw |
| 778 | * {@hide} |
| 779 | */ |
| 780 | static final int DRAW_MASK = 0x00000080; |
| 781 | |
| 782 | /** |
| 783 | * <p>This view doesn't show scrollbars.</p> |
| 784 | * {@hide} |
| 785 | */ |
| 786 | static final int SCROLLBARS_NONE = 0x00000000; |
| 787 | |
| 788 | /** |
| 789 | * <p>This view shows horizontal scrollbars.</p> |
| 790 | * {@hide} |
| 791 | */ |
| 792 | static final int SCROLLBARS_HORIZONTAL = 0x00000100; |
| 793 | |
| 794 | /** |
| 795 | * <p>This view shows vertical scrollbars.</p> |
| 796 | * {@hide} |
| 797 | */ |
| 798 | static final int SCROLLBARS_VERTICAL = 0x00000200; |
| 799 | |
| 800 | /** |
| 801 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 802 | * scrollbars are enabled.</p> |
| 803 | * {@hide} |
| 804 | */ |
| 805 | static final int SCROLLBARS_MASK = 0x00000300; |
| 806 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 807 | /** |
| 808 | * Indicates that the view should filter touches when its window is obscured. |
| 809 | * Refer to the class comments for more information about this security feature. |
| 810 | * {@hide} |
| 811 | */ |
| 812 | static final int FILTER_TOUCHES_WHEN_OBSCURED = 0x00000400; |
| 813 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 814 | /** |
| 815 | * Set for framework elements that use FITS_SYSTEM_WINDOWS, to indicate |
| 816 | * that they are optional and should be skipped if the window has |
| 817 | * requested system UI flags that ignore those insets for layout. |
| 818 | */ |
| 819 | static final int OPTIONAL_FITS_SYSTEM_WINDOWS = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | |
| 821 | /** |
| 822 | * <p>This view doesn't show fading edges.</p> |
| 823 | * {@hide} |
| 824 | */ |
| 825 | static final int FADING_EDGE_NONE = 0x00000000; |
| 826 | |
| 827 | /** |
| 828 | * <p>This view shows horizontal fading edges.</p> |
| 829 | * {@hide} |
| 830 | */ |
| 831 | static final int FADING_EDGE_HORIZONTAL = 0x00001000; |
| 832 | |
| 833 | /** |
| 834 | * <p>This view shows vertical fading edges.</p> |
| 835 | * {@hide} |
| 836 | */ |
| 837 | static final int FADING_EDGE_VERTICAL = 0x00002000; |
| 838 | |
| 839 | /** |
| 840 | * <p>Mask for use with setFlags indicating bits used for indicating which |
| 841 | * fading edges are enabled.</p> |
| 842 | * {@hide} |
| 843 | */ |
| 844 | static final int FADING_EDGE_MASK = 0x00003000; |
| 845 | |
| 846 | /** |
| 847 | * <p>Indicates this view can be clicked. When clickable, a View reacts |
| 848 | * to clicks by notifying the OnClickListener.<p> |
| 849 | * {@hide} |
| 850 | */ |
| 851 | static final int CLICKABLE = 0x00004000; |
| 852 | |
| 853 | /** |
| 854 | * <p>Indicates this view is caching its drawing into a bitmap.</p> |
| 855 | * {@hide} |
| 856 | */ |
| 857 | static final int DRAWING_CACHE_ENABLED = 0x00008000; |
| 858 | |
| 859 | /** |
| 860 | * <p>Indicates that no icicle should be saved for this view.<p> |
| 861 | * {@hide} |
| 862 | */ |
| 863 | static final int SAVE_DISABLED = 0x000010000; |
| 864 | |
| 865 | /** |
| 866 | * <p>Mask for use with setFlags indicating bits used for the saveEnabled |
| 867 | * property.</p> |
| 868 | * {@hide} |
| 869 | */ |
| 870 | static final int SAVE_DISABLED_MASK = 0x000010000; |
| 871 | |
| 872 | /** |
| 873 | * <p>Indicates that no drawing cache should ever be created for this view.<p> |
| 874 | * {@hide} |
| 875 | */ |
| 876 | static final int WILL_NOT_CACHE_DRAWING = 0x000020000; |
| 877 | |
| 878 | /** |
| 879 | * <p>Indicates this view can take / keep focus when int touch mode.</p> |
| 880 | * {@hide} |
| 881 | */ |
| 882 | static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; |
| 883 | |
| 884 | /** |
| 885 | * <p>Enables low quality mode for the drawing cache.</p> |
| 886 | */ |
| 887 | public static final int DRAWING_CACHE_QUALITY_LOW = 0x00080000; |
| 888 | |
| 889 | /** |
| 890 | * <p>Enables high quality mode for the drawing cache.</p> |
| 891 | */ |
| 892 | public static final int DRAWING_CACHE_QUALITY_HIGH = 0x00100000; |
| 893 | |
| 894 | /** |
| 895 | * <p>Enables automatic quality mode for the drawing cache.</p> |
| 896 | */ |
| 897 | public static final int DRAWING_CACHE_QUALITY_AUTO = 0x00000000; |
| 898 | |
| 899 | private static final int[] DRAWING_CACHE_QUALITY_FLAGS = { |
| 900 | DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH |
| 901 | }; |
| 902 | |
| 903 | /** |
| 904 | * <p>Mask for use with setFlags indicating bits used for the cache |
| 905 | * quality property.</p> |
| 906 | * {@hide} |
| 907 | */ |
| 908 | static final int DRAWING_CACHE_QUALITY_MASK = 0x00180000; |
| 909 | |
| 910 | /** |
| 911 | * <p> |
| 912 | * Indicates this view can be long clicked. When long clickable, a View |
| 913 | * reacts to long clicks by notifying the OnLongClickListener or showing a |
| 914 | * context menu. |
| 915 | * </p> |
| 916 | * {@hide} |
| 917 | */ |
| 918 | static final int LONG_CLICKABLE = 0x00200000; |
| 919 | |
| 920 | /** |
| 921 | * <p>Indicates that this view gets its drawable states from its direct parent |
| 922 | * and ignores its original internal states.</p> |
| 923 | * |
| 924 | * @hide |
| 925 | */ |
| 926 | static final int DUPLICATE_PARENT_STATE = 0x00400000; |
| 927 | |
| 928 | /** |
| 929 | * The scrollbar style to display the scrollbars inside the content area, |
| 930 | * without increasing the padding. The scrollbars will be overlaid with |
| 931 | * translucency on the view's content. |
| 932 | */ |
| 933 | public static final int SCROLLBARS_INSIDE_OVERLAY = 0; |
| 934 | |
| 935 | /** |
| 936 | * The scrollbar style to display the scrollbars inside the padded area, |
| 937 | * increasing the padding of the view. The scrollbars will not overlap the |
| 938 | * content area of the view. |
| 939 | */ |
| 940 | public static final int SCROLLBARS_INSIDE_INSET = 0x01000000; |
| 941 | |
| 942 | /** |
| 943 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 944 | * without increasing the padding. The scrollbars will be overlaid with |
| 945 | * translucency. |
| 946 | */ |
| 947 | public static final int SCROLLBARS_OUTSIDE_OVERLAY = 0x02000000; |
| 948 | |
| 949 | /** |
| 950 | * The scrollbar style to display the scrollbars at the edge of the view, |
| 951 | * increasing the padding of the view. The scrollbars will only overlap the |
| 952 | * background, if any. |
| 953 | */ |
| 954 | public static final int SCROLLBARS_OUTSIDE_INSET = 0x03000000; |
| 955 | |
| 956 | /** |
| 957 | * Mask to check if the scrollbar style is overlay or inset. |
| 958 | * {@hide} |
| 959 | */ |
| 960 | static final int SCROLLBARS_INSET_MASK = 0x01000000; |
| 961 | |
| 962 | /** |
| 963 | * Mask to check if the scrollbar style is inside or outside. |
| 964 | * {@hide} |
| 965 | */ |
| 966 | static final int SCROLLBARS_OUTSIDE_MASK = 0x02000000; |
| 967 | |
| 968 | /** |
| 969 | * Mask for scrollbar style. |
| 970 | * {@hide} |
| 971 | */ |
| 972 | static final int SCROLLBARS_STYLE_MASK = 0x03000000; |
| 973 | |
| 974 | /** |
| 975 | * View flag indicating that the screen should remain on while the |
| 976 | * window containing this view is visible to the user. This effectively |
| 977 | * takes care of automatically setting the WindowManager's |
| 978 | * {@link WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON}. |
| 979 | */ |
| 980 | public static final int KEEP_SCREEN_ON = 0x04000000; |
| 981 | |
| 982 | /** |
| 983 | * View flag indicating whether this view should have sound effects enabled |
| 984 | * for events such as clicking and touching. |
| 985 | */ |
| 986 | public static final int SOUND_EFFECTS_ENABLED = 0x08000000; |
| 987 | |
| 988 | /** |
| 989 | * View flag indicating whether this view should have haptic feedback |
| 990 | * enabled for events such as long presses. |
| 991 | */ |
| 992 | public static final int HAPTIC_FEEDBACK_ENABLED = 0x10000000; |
| 993 | |
| 994 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 995 | * <p>Indicates that the view hierarchy should stop saving state when |
| 996 | * it reaches this view. If state saving is initiated immediately at |
| 997 | * the view, it will be allowed. |
| 998 | * {@hide} |
| 999 | */ |
| 1000 | static final int PARENT_SAVE_DISABLED = 0x20000000; |
| 1001 | |
| 1002 | /** |
| 1003 | * <p>Mask for use with setFlags indicating bits used for PARENT_SAVE_DISABLED.</p> |
| 1004 | * {@hide} |
| 1005 | */ |
| 1006 | static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; |
| 1007 | |
| 1008 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1009 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1010 | * should add all focusable Views regardless if they are focusable in touch mode. |
| 1011 | */ |
| 1012 | public static final int FOCUSABLES_ALL = 0x00000000; |
| 1013 | |
| 1014 | /** |
| 1015 | * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} |
| 1016 | * should add only Views focusable in touch mode. |
| 1017 | */ |
| 1018 | public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; |
| 1019 | |
| 1020 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1021 | * 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] | 1022 | * item. |
| 1023 | */ |
| 1024 | public static final int FOCUS_BACKWARD = 0x00000001; |
| 1025 | |
| 1026 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1027 | * 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] | 1028 | * item. |
| 1029 | */ |
| 1030 | public static final int FOCUS_FORWARD = 0x00000002; |
| 1031 | |
| 1032 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1033 | * 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] | 1034 | */ |
| 1035 | public static final int FOCUS_LEFT = 0x00000011; |
| 1036 | |
| 1037 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1038 | * Use with {@link #focusSearch(int)}. Move focus up. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | */ |
| 1040 | public static final int FOCUS_UP = 0x00000021; |
| 1041 | |
| 1042 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1043 | * 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] | 1044 | */ |
| 1045 | public static final int FOCUS_RIGHT = 0x00000042; |
| 1046 | |
| 1047 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 1048 | * Use with {@link #focusSearch(int)}. Move focus down. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | */ |
| 1050 | public static final int FOCUS_DOWN = 0x00000082; |
| 1051 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1052 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1053 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1054 | * {@link #getMeasuredWidthAndState()} that provide the actual measured size. |
| 1055 | */ |
| 1056 | public static final int MEASURED_SIZE_MASK = 0x00ffffff; |
| 1057 | |
| 1058 | /** |
| 1059 | * Bits of {@link #getMeasuredWidthAndState()} and |
| 1060 | * {@link #getMeasuredWidthAndState()} that provide the additional state bits. |
| 1061 | */ |
| 1062 | public static final int MEASURED_STATE_MASK = 0xff000000; |
| 1063 | |
| 1064 | /** |
| 1065 | * Bit shift of {@link #MEASURED_STATE_MASK} to get to the height bits |
| 1066 | * for functions that combine both width and height into a single int, |
| 1067 | * such as {@link #getMeasuredState()} and the childState argument of |
| 1068 | * {@link #resolveSizeAndState(int, int, int)}. |
| 1069 | */ |
| 1070 | public static final int MEASURED_HEIGHT_STATE_SHIFT = 16; |
| 1071 | |
| 1072 | /** |
| 1073 | * Bit of {@link #getMeasuredWidthAndState()} and |
| 1074 | * {@link #getMeasuredWidthAndState()} that indicates the measured size |
| 1075 | * is smaller that the space the view would like to have. |
| 1076 | */ |
| 1077 | public static final int MEASURED_STATE_TOO_SMALL = 0x01000000; |
| 1078 | |
| 1079 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | * Base View state sets |
| 1081 | */ |
| 1082 | // Singles |
| 1083 | /** |
| 1084 | * Indicates the view has no states set. States are used with |
| 1085 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1086 | * view depending on its state. |
| 1087 | * |
| 1088 | * @see android.graphics.drawable.Drawable |
| 1089 | * @see #getDrawableState() |
| 1090 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1091 | protected static final int[] EMPTY_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | /** |
| 1093 | * Indicates the view is enabled. States are used with |
| 1094 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1095 | * view depending on its state. |
| 1096 | * |
| 1097 | * @see android.graphics.drawable.Drawable |
| 1098 | * @see #getDrawableState() |
| 1099 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1100 | protected static final int[] ENABLED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | /** |
| 1102 | * Indicates the view is focused. States are used with |
| 1103 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1104 | * view depending on its state. |
| 1105 | * |
| 1106 | * @see android.graphics.drawable.Drawable |
| 1107 | * @see #getDrawableState() |
| 1108 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1109 | protected static final int[] FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | /** |
| 1111 | * Indicates the view is selected. States are used with |
| 1112 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1113 | * view depending on its state. |
| 1114 | * |
| 1115 | * @see android.graphics.drawable.Drawable |
| 1116 | * @see #getDrawableState() |
| 1117 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1118 | protected static final int[] SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | /** |
| 1120 | * Indicates the view is pressed. States are used with |
| 1121 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1122 | * view depending on its state. |
| 1123 | * |
| 1124 | * @see android.graphics.drawable.Drawable |
| 1125 | * @see #getDrawableState() |
| 1126 | * @hide |
| 1127 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1128 | protected static final int[] PRESSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | /** |
| 1130 | * Indicates the view's window has focus. States are used with |
| 1131 | * {@link android.graphics.drawable.Drawable} to change the drawing of the |
| 1132 | * view depending on its state. |
| 1133 | * |
| 1134 | * @see android.graphics.drawable.Drawable |
| 1135 | * @see #getDrawableState() |
| 1136 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1137 | protected static final int[] WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | // Doubles |
| 1139 | /** |
| 1140 | * Indicates the view is enabled and has the focus. |
| 1141 | * |
| 1142 | * @see #ENABLED_STATE_SET |
| 1143 | * @see #FOCUSED_STATE_SET |
| 1144 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1145 | protected static final int[] ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | /** |
| 1147 | * Indicates the view is enabled and selected. |
| 1148 | * |
| 1149 | * @see #ENABLED_STATE_SET |
| 1150 | * @see #SELECTED_STATE_SET |
| 1151 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1152 | protected static final int[] ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | /** |
| 1154 | * Indicates the view is enabled and that its window has focus. |
| 1155 | * |
| 1156 | * @see #ENABLED_STATE_SET |
| 1157 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1158 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1159 | protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | /** |
| 1161 | * Indicates the view is focused and selected. |
| 1162 | * |
| 1163 | * @see #FOCUSED_STATE_SET |
| 1164 | * @see #SELECTED_STATE_SET |
| 1165 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1166 | protected static final int[] FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | /** |
| 1168 | * Indicates the view has the focus and that its window has the focus. |
| 1169 | * |
| 1170 | * @see #FOCUSED_STATE_SET |
| 1171 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1172 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1173 | protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | /** |
| 1175 | * Indicates the view is selected and that its window has the focus. |
| 1176 | * |
| 1177 | * @see #SELECTED_STATE_SET |
| 1178 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1179 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1180 | protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | // Triples |
| 1182 | /** |
| 1183 | * Indicates the view is enabled, focused and selected. |
| 1184 | * |
| 1185 | * @see #ENABLED_STATE_SET |
| 1186 | * @see #FOCUSED_STATE_SET |
| 1187 | * @see #SELECTED_STATE_SET |
| 1188 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1189 | protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1190 | /** |
| 1191 | * Indicates the view is enabled, focused and its window has the focus. |
| 1192 | * |
| 1193 | * @see #ENABLED_STATE_SET |
| 1194 | * @see #FOCUSED_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_FOCUSED_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 enabled, selected and its window has the focus. |
| 1200 | * |
| 1201 | * @see #ENABLED_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[] ENABLED_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 focused, selected and its window has the focus. |
| 1208 | * |
| 1209 | * @see #FOCUSED_STATE_SET |
| 1210 | * @see #SELECTED_STATE_SET |
| 1211 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1212 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1213 | 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] | 1214 | /** |
| 1215 | * Indicates the view is enabled, focused, selected and its window |
| 1216 | * has the focus. |
| 1217 | * |
| 1218 | * @see #ENABLED_STATE_SET |
| 1219 | * @see #FOCUSED_STATE_SET |
| 1220 | * @see #SELECTED_STATE_SET |
| 1221 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1222 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1223 | 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] | 1224 | /** |
| 1225 | * Indicates the view is pressed and its window has the focus. |
| 1226 | * |
| 1227 | * @see #PRESSED_STATE_SET |
| 1228 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1229 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1230 | protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | /** |
| 1232 | * Indicates the view is pressed and selected. |
| 1233 | * |
| 1234 | * @see #PRESSED_STATE_SET |
| 1235 | * @see #SELECTED_STATE_SET |
| 1236 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1237 | protected static final int[] PRESSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | /** |
| 1239 | * Indicates the view is pressed, selected and its window has the focus. |
| 1240 | * |
| 1241 | * @see #PRESSED_STATE_SET |
| 1242 | * @see #SELECTED_STATE_SET |
| 1243 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1244 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1245 | 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] | 1246 | /** |
| 1247 | * Indicates the view is pressed and focused. |
| 1248 | * |
| 1249 | * @see #PRESSED_STATE_SET |
| 1250 | * @see #FOCUSED_STATE_SET |
| 1251 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1252 | protected static final int[] PRESSED_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 its window has the focus. |
| 1255 | * |
| 1256 | * @see #PRESSED_STATE_SET |
| 1257 | * @see #FOCUSED_STATE_SET |
| 1258 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1259 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1260 | 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] | 1261 | /** |
| 1262 | * Indicates the view is pressed, focused and selected. |
| 1263 | * |
| 1264 | * @see #PRESSED_STATE_SET |
| 1265 | * @see #SELECTED_STATE_SET |
| 1266 | * @see #FOCUSED_STATE_SET |
| 1267 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1268 | protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | /** |
| 1270 | * Indicates the view is pressed, focused, selected and its window has the focus. |
| 1271 | * |
| 1272 | * @see #PRESSED_STATE_SET |
| 1273 | * @see #FOCUSED_STATE_SET |
| 1274 | * @see #SELECTED_STATE_SET |
| 1275 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1276 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1277 | 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] | 1278 | /** |
| 1279 | * Indicates the view is pressed and enabled. |
| 1280 | * |
| 1281 | * @see #PRESSED_STATE_SET |
| 1282 | * @see #ENABLED_STATE_SET |
| 1283 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1284 | protected static final int[] PRESSED_ENABLED_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 its window has the focus. |
| 1287 | * |
| 1288 | * @see #PRESSED_STATE_SET |
| 1289 | * @see #ENABLED_STATE_SET |
| 1290 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1291 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1292 | 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] | 1293 | /** |
| 1294 | * Indicates the view is pressed, enabled and selected. |
| 1295 | * |
| 1296 | * @see #PRESSED_STATE_SET |
| 1297 | * @see #ENABLED_STATE_SET |
| 1298 | * @see #SELECTED_STATE_SET |
| 1299 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1300 | protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | /** |
| 1302 | * Indicates the view is pressed, enabled, selected and its window has the |
| 1303 | * focus. |
| 1304 | * |
| 1305 | * @see #PRESSED_STATE_SET |
| 1306 | * @see #ENABLED_STATE_SET |
| 1307 | * @see #SELECTED_STATE_SET |
| 1308 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1309 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1310 | 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] | 1311 | /** |
| 1312 | * Indicates the view is pressed, enabled and focused. |
| 1313 | * |
| 1314 | * @see #PRESSED_STATE_SET |
| 1315 | * @see #ENABLED_STATE_SET |
| 1316 | * @see #FOCUSED_STATE_SET |
| 1317 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1318 | protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | /** |
| 1320 | * Indicates the view is pressed, enabled, focused and its window has the |
| 1321 | * focus. |
| 1322 | * |
| 1323 | * @see #PRESSED_STATE_SET |
| 1324 | * @see #ENABLED_STATE_SET |
| 1325 | * @see #FOCUSED_STATE_SET |
| 1326 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1327 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1328 | 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] | 1329 | /** |
| 1330 | * Indicates the view is pressed, enabled, focused and selected. |
| 1331 | * |
| 1332 | * @see #PRESSED_STATE_SET |
| 1333 | * @see #ENABLED_STATE_SET |
| 1334 | * @see #SELECTED_STATE_SET |
| 1335 | * @see #FOCUSED_STATE_SET |
| 1336 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1337 | 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] | 1338 | /** |
| 1339 | * Indicates the view is pressed, enabled, focused, selected and its window |
| 1340 | * has the focus. |
| 1341 | * |
| 1342 | * @see #PRESSED_STATE_SET |
| 1343 | * @see #ENABLED_STATE_SET |
| 1344 | * @see #SELECTED_STATE_SET |
| 1345 | * @see #FOCUSED_STATE_SET |
| 1346 | * @see #WINDOW_FOCUSED_STATE_SET |
| 1347 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1348 | 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] | 1349 | |
| 1350 | /** |
| 1351 | * The order here is very important to {@link #getDrawableState()} |
| 1352 | */ |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1353 | private static final int[][] VIEW_STATE_SETS; |
| 1354 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1355 | static final int VIEW_STATE_WINDOW_FOCUSED = 1; |
| 1356 | static final int VIEW_STATE_SELECTED = 1 << 1; |
| 1357 | static final int VIEW_STATE_FOCUSED = 1 << 2; |
| 1358 | static final int VIEW_STATE_ENABLED = 1 << 3; |
| 1359 | static final int VIEW_STATE_PRESSED = 1 << 4; |
| 1360 | static final int VIEW_STATE_ACTIVATED = 1 << 5; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1361 | static final int VIEW_STATE_ACCELERATED = 1 << 6; |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1362 | static final int VIEW_STATE_HOVERED = 1 << 7; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1363 | static final int VIEW_STATE_DRAG_CAN_ACCEPT = 1 << 8; |
| 1364 | static final int VIEW_STATE_DRAG_HOVERED = 1 << 9; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1365 | |
| 1366 | static final int[] VIEW_STATE_IDS = new int[] { |
| 1367 | R.attr.state_window_focused, VIEW_STATE_WINDOW_FOCUSED, |
| 1368 | R.attr.state_selected, VIEW_STATE_SELECTED, |
| 1369 | R.attr.state_focused, VIEW_STATE_FOCUSED, |
| 1370 | R.attr.state_enabled, VIEW_STATE_ENABLED, |
| 1371 | R.attr.state_pressed, VIEW_STATE_PRESSED, |
| 1372 | R.attr.state_activated, VIEW_STATE_ACTIVATED, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1373 | R.attr.state_accelerated, VIEW_STATE_ACCELERATED, |
PY Laligand | c33d8d49e | 2011-03-14 18:22:53 -0700 | [diff] [blame] | 1374 | R.attr.state_hovered, VIEW_STATE_HOVERED, |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1375 | R.attr.state_drag_can_accept, VIEW_STATE_DRAG_CAN_ACCEPT, |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1376 | R.attr.state_drag_hovered, VIEW_STATE_DRAG_HOVERED |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | }; |
| 1378 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1379 | static { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1380 | if ((VIEW_STATE_IDS.length/2) != R.styleable.ViewDrawableStates.length) { |
| 1381 | throw new IllegalStateException( |
| 1382 | "VIEW_STATE_IDs array length does not match ViewDrawableStates style array"); |
| 1383 | } |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1384 | int[] orderedIds = new int[VIEW_STATE_IDS.length]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1385 | for (int i = 0; i < R.styleable.ViewDrawableStates.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1386 | int viewState = R.styleable.ViewDrawableStates[i]; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1387 | for (int j = 0; j<VIEW_STATE_IDS.length; j += 2) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1388 | if (VIEW_STATE_IDS[j] == viewState) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1389 | orderedIds[i * 2] = viewState; |
| 1390 | orderedIds[i * 2 + 1] = VIEW_STATE_IDS[j + 1]; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | } |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1394 | final int NUM_BITS = VIEW_STATE_IDS.length / 2; |
| 1395 | VIEW_STATE_SETS = new int[1 << NUM_BITS][]; |
| 1396 | for (int i = 0; i < VIEW_STATE_SETS.length; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1397 | int numBits = Integer.bitCount(i); |
| 1398 | int[] set = new int[numBits]; |
| 1399 | int pos = 0; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1400 | for (int j = 0; j < orderedIds.length; j += 2) { |
| 1401 | if ((i & orderedIds[j+1]) != 0) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1402 | set[pos++] = orderedIds[j]; |
| 1403 | } |
| 1404 | } |
| 1405 | VIEW_STATE_SETS[i] = set; |
| 1406 | } |
| 1407 | |
| 1408 | EMPTY_STATE_SET = VIEW_STATE_SETS[0]; |
| 1409 | WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_WINDOW_FOCUSED]; |
| 1410 | SELECTED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_SELECTED]; |
| 1411 | SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1412 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED]; |
| 1413 | FOCUSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_FOCUSED]; |
| 1414 | FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1415 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED]; |
| 1416 | FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1417 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED]; |
| 1418 | FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1419 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1420 | | VIEW_STATE_FOCUSED]; |
| 1421 | ENABLED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_ENABLED]; |
| 1422 | ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1423 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED]; |
| 1424 | ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1425 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED]; |
| 1426 | ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1427 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1428 | | VIEW_STATE_ENABLED]; |
| 1429 | ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1430 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED]; |
| 1431 | ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1432 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1433 | | VIEW_STATE_ENABLED]; |
| 1434 | ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1435 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1436 | | VIEW_STATE_ENABLED]; |
| 1437 | ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1438 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1439 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED]; |
| 1440 | |
| 1441 | PRESSED_STATE_SET = VIEW_STATE_SETS[VIEW_STATE_PRESSED]; |
| 1442 | PRESSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1443 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_PRESSED]; |
| 1444 | PRESSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1445 | VIEW_STATE_SELECTED | VIEW_STATE_PRESSED]; |
| 1446 | PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1447 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1448 | | VIEW_STATE_PRESSED]; |
| 1449 | PRESSED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1450 | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1451 | PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1452 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1453 | | VIEW_STATE_PRESSED]; |
| 1454 | PRESSED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1455 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1456 | | VIEW_STATE_PRESSED]; |
| 1457 | PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1458 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1459 | | VIEW_STATE_FOCUSED | VIEW_STATE_PRESSED]; |
| 1460 | PRESSED_ENABLED_STATE_SET = VIEW_STATE_SETS[ |
| 1461 | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1462 | PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1463 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_ENABLED |
| 1464 | | VIEW_STATE_PRESSED]; |
| 1465 | PRESSED_ENABLED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1466 | VIEW_STATE_SELECTED | VIEW_STATE_ENABLED |
| 1467 | | VIEW_STATE_PRESSED]; |
| 1468 | PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1469 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1470 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1471 | PRESSED_ENABLED_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1472 | VIEW_STATE_FOCUSED | VIEW_STATE_ENABLED |
| 1473 | | VIEW_STATE_PRESSED]; |
| 1474 | PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1475 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_FOCUSED |
| 1476 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1477 | PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET = VIEW_STATE_SETS[ |
| 1478 | VIEW_STATE_SELECTED | VIEW_STATE_FOCUSED |
| 1479 | | VIEW_STATE_ENABLED | VIEW_STATE_PRESSED]; |
| 1480 | PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET = VIEW_STATE_SETS[ |
| 1481 | VIEW_STATE_WINDOW_FOCUSED | VIEW_STATE_SELECTED |
| 1482 | | VIEW_STATE_FOCUSED| VIEW_STATE_ENABLED |
| 1483 | | VIEW_STATE_PRESSED]; |
| 1484 | } |
| 1485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | /** |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1487 | * Accessibility event types that are dispatched for text population. |
| 1488 | */ |
| 1489 | private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES = |
| 1490 | AccessibilityEvent.TYPE_VIEW_CLICKED |
| 1491 | | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED |
| 1492 | | AccessibilityEvent.TYPE_VIEW_SELECTED |
| 1493 | | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 1494 | | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED |
| 1495 | | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER |
Svetoslav Ganov | 9920f4f | 2011-10-07 18:39:11 -0700 | [diff] [blame] | 1496 | | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT |
Svetoslav Ganov | 84dd52e | 2011-11-18 10:24:00 -0800 | [diff] [blame] | 1497 | | AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1498 | | AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1499 | | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED |
| 1500 | | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY; |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 1501 | |
| 1502 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | * Temporary Rect currently for use in setBackground(). This will probably |
| 1504 | * be extended in the future to hold our own class with more than just |
| 1505 | * a Rect. :) |
| 1506 | */ |
| 1507 | static final ThreadLocal<Rect> sThreadLocal = new ThreadLocal<Rect>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1508 | |
| 1509 | /** |
| 1510 | * Map used to store views' tags. |
| 1511 | */ |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 1512 | private SparseArray<Object> mKeyedTags; |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 1513 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 1515 | * The next available accessibility id. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1516 | */ |
| 1517 | private static int sNextAccessibilityViewId; |
| 1518 | |
| 1519 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1520 | * The animation currently associated with this view. |
| 1521 | * @hide |
| 1522 | */ |
| 1523 | protected Animation mCurrentAnimation = null; |
| 1524 | |
| 1525 | /** |
| 1526 | * Width as measured during measure pass. |
| 1527 | * {@hide} |
| 1528 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1529 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1530 | int mMeasuredWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | |
| 1532 | /** |
| 1533 | * Height as measured during measure pass. |
| 1534 | * {@hide} |
| 1535 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 1536 | @ViewDebug.ExportedProperty(category = "measurement") |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 1537 | int mMeasuredHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | |
| 1539 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1540 | * Flag to indicate that this view was marked INVALIDATED, or had its display list |
| 1541 | * invalidated, prior to the current drawing iteration. If true, the view must re-draw |
| 1542 | * its display list. This flag, used only when hw accelerated, allows us to clear the |
| 1543 | * flag while retaining this information until it's needed (at getDisplayList() time and |
| 1544 | * in drawChild(), when we decide to draw a view's children's display lists into our own). |
| 1545 | * |
| 1546 | * {@hide} |
| 1547 | */ |
| 1548 | boolean mRecreateDisplayList = false; |
| 1549 | |
| 1550 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | * The view's identifier. |
| 1552 | * {@hide} |
| 1553 | * |
| 1554 | * @see #setId(int) |
| 1555 | * @see #getId() |
| 1556 | */ |
| 1557 | @ViewDebug.ExportedProperty(resolveId = true) |
| 1558 | int mID = NO_ID; |
| 1559 | |
| 1560 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 1561 | * The stable ID of this view for accessibility purposes. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1562 | */ |
| 1563 | int mAccessibilityViewId = NO_ID; |
| 1564 | |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 1565 | private int mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 1566 | |
| 1567 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | * The view's tag. |
| 1569 | * {@hide} |
| 1570 | * |
| 1571 | * @see #setTag(Object) |
| 1572 | * @see #getTag() |
| 1573 | */ |
| 1574 | protected Object mTag; |
| 1575 | |
| 1576 | // for mPrivateFlags: |
| 1577 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1578 | static final int PFLAG_WANTS_FOCUS = 0x00000001; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1580 | static final int PFLAG_FOCUSED = 0x00000002; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1582 | static final int PFLAG_SELECTED = 0x00000004; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1584 | static final int PFLAG_IS_ROOT_NAMESPACE = 0x00000008; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1586 | static final int PFLAG_HAS_BOUNDS = 0x00000010; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1588 | static final int PFLAG_DRAWN = 0x00000020; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | /** |
| 1590 | * When this flag is set, this view is running an animation on behalf of its |
| 1591 | * children and should therefore not cancel invalidate requests, even if they |
| 1592 | * lie outside of this view's bounds. |
| 1593 | * |
| 1594 | * {@hide} |
| 1595 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1596 | static final int PFLAG_DRAW_ANIMATION = 0x00000040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1598 | static final int PFLAG_SKIP_DRAW = 0x00000080; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1600 | static final int PFLAG_ONLY_DRAWS_BACKGROUND = 0x00000100; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1602 | static final int PFLAG_REQUEST_TRANSPARENT_REGIONS = 0x00000200; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1604 | static final int PFLAG_DRAWABLE_STATE_DIRTY = 0x00000400; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1606 | static final int PFLAG_MEASURED_DIMENSION_SET = 0x00000800; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1608 | static final int PFLAG_FORCE_LAYOUT = 0x00001000; |
Konstantin Lopyrev | c6dc457 | 2010-08-06 15:01:52 -0700 | [diff] [blame] | 1609 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1610 | static final int PFLAG_LAYOUT_REQUIRED = 0x00002000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1611 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1612 | private static final int PFLAG_PRESSED = 0x00004000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | |
| 1614 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1615 | static final int PFLAG_DRAWING_CACHE_VALID = 0x00008000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1616 | /** |
| 1617 | * Flag used to indicate that this view should be drawn once more (and only once |
| 1618 | * more) after its animation has completed. |
| 1619 | * {@hide} |
| 1620 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1621 | static final int PFLAG_ANIMATION_STARTED = 0x00010000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1623 | private static final int PFLAG_SAVE_STATE_CALLED = 0x00020000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | |
| 1625 | /** |
| 1626 | * Indicates that the View returned true when onSetAlpha() was called and that |
| 1627 | * the alpha must be restored. |
| 1628 | * {@hide} |
| 1629 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1630 | static final int PFLAG_ALPHA_SET = 0x00040000; |
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 = 0x00080000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | |
| 1637 | /** |
| 1638 | * Set by {@link #setScrollContainer(boolean)}. |
| 1639 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1640 | static final int PFLAG_SCROLL_CONTAINER_ADDED = 0x00100000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | |
| 1642 | /** |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1643 | * View flag indicating whether this view was invalidated (fully or partially.) |
| 1644 | * |
| 1645 | * @hide |
| 1646 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1647 | static final int PFLAG_DIRTY = 0x00200000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1648 | |
| 1649 | /** |
| 1650 | * View flag indicating whether this view was invalidated by an opaque |
| 1651 | * invalidate request. |
| 1652 | * |
| 1653 | * @hide |
| 1654 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1655 | static final int PFLAG_DIRTY_OPAQUE = 0x00400000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1656 | |
| 1657 | /** |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1658 | * Mask for {@link #PFLAG_DIRTY} and {@link #PFLAG_DIRTY_OPAQUE}. |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1659 | * |
| 1660 | * @hide |
| 1661 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1662 | static final int PFLAG_DIRTY_MASK = 0x00600000; |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 1663 | |
| 1664 | /** |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1665 | * Indicates whether the background is opaque. |
| 1666 | * |
| 1667 | * @hide |
| 1668 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1669 | static final int PFLAG_OPAQUE_BACKGROUND = 0x00800000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1670 | |
| 1671 | /** |
| 1672 | * Indicates whether the scrollbars are opaque. |
| 1673 | * |
| 1674 | * @hide |
| 1675 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1676 | static final int PFLAG_OPAQUE_SCROLLBARS = 0x01000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1677 | |
| 1678 | /** |
| 1679 | * Indicates whether the view is opaque. |
| 1680 | * |
| 1681 | * @hide |
| 1682 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1683 | static final int PFLAG_OPAQUE_MASK = 0x01800000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1684 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1685 | /** |
| 1686 | * Indicates a prepressed state; |
| 1687 | * the short time between ACTION_DOWN and recognizing |
| 1688 | * a 'real' press. Prepressed is used to recognize quick taps |
| 1689 | * even when they are shorter than ViewConfiguration.getTapTimeout(). |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1690 | * |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 1691 | * @hide |
| 1692 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1693 | private static final int PFLAG_PREPRESSED = 0x02000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1694 | |
Adam Powell | c9fbaab | 2010-02-16 17:16:19 -0800 | [diff] [blame] | 1695 | /** |
Romain Guy | 8afa515 | 2010-02-26 11:56:30 -0800 | [diff] [blame] | 1696 | * Indicates whether the view is temporarily detached. |
| 1697 | * |
| 1698 | * @hide |
| 1699 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1700 | static final int PFLAG_CANCEL_NEXT_UP_EVENT = 0x04000000; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1701 | |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1702 | /** |
| 1703 | * Indicates that we should awaken scroll bars once attached |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 1704 | * |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 1705 | * @hide |
| 1706 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1707 | private static final int PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH = 0x08000000; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 1708 | |
| 1709 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1710 | * Indicates that the view has received HOVER_ENTER. Cleared on HOVER_EXIT. |
| 1711 | * @hide |
| 1712 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1713 | private static final int PFLAG_HOVERED = 0x10000000; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1714 | |
| 1715 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1716 | * Indicates that pivotX or pivotY were explicitly set and we should not assume the center |
| 1717 | * for transform operations |
| 1718 | * |
| 1719 | * @hide |
| 1720 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1721 | private static final int PFLAG_PIVOT_EXPLICITLY_SET = 0x20000000; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1722 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1723 | /** {@hide} */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1724 | static final int PFLAG_ACTIVATED = 0x40000000; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 1725 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 1726 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1727 | * Indicates that this view was specifically invalidated, not just dirtied because some |
| 1728 | * child view was invalidated. The flag is used to determine when we need to recreate |
| 1729 | * a view's display list (as opposed to just returning a reference to its existing |
| 1730 | * display list). |
| 1731 | * |
| 1732 | * @hide |
| 1733 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1734 | static final int PFLAG_INVALIDATED = 0x80000000; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 1735 | |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1736 | /** |
| 1737 | * Masks for mPrivateFlags2, as generated by dumpFlags(): |
| 1738 | * |
| 1739 | * -------|-------|-------|-------| |
| 1740 | * PFLAG2_TEXT_ALIGNMENT_FLAGS[0] |
| 1741 | * PFLAG2_TEXT_DIRECTION_FLAGS[0] |
| 1742 | * 1 PFLAG2_DRAG_CAN_ACCEPT |
| 1743 | * 1 PFLAG2_DRAG_HOVERED |
| 1744 | * 1 PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT |
| 1745 | * 11 PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
| 1746 | * 1 1 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT |
| 1747 | * 11 PFLAG2_LAYOUT_DIRECTION_MASK |
| 1748 | * 11 1 PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
| 1749 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL |
| 1750 | * 1 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT |
| 1751 | * 1 1 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT |
| 1752 | * 1 PFLAG2_LAYOUT_DIRECTION_RESOLVED |
| 1753 | * 11 PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK |
| 1754 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[1] |
| 1755 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[2] |
| 1756 | * 11 PFLAG2_TEXT_DIRECTION_FLAGS[3] |
| 1757 | * 1 PFLAG2_TEXT_DIRECTION_FLAGS[4] |
| 1758 | * 1 1 PFLAG2_TEXT_DIRECTION_FLAGS[5] |
| 1759 | * 111 PFLAG2_TEXT_DIRECTION_MASK |
| 1760 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED |
| 1761 | * 1 PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT |
| 1762 | * 111 PFLAG2_TEXT_DIRECTION_RESOLVED_MASK |
| 1763 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[1] |
| 1764 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[2] |
| 1765 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[3] |
| 1766 | * 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[4] |
| 1767 | * 1 1 PFLAG2_TEXT_ALIGNMENT_FLAGS[5] |
| 1768 | * 11 PFLAG2_TEXT_ALIGNMENT_FLAGS[6] |
| 1769 | * 111 PFLAG2_TEXT_ALIGNMENT_MASK |
| 1770 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED |
| 1771 | * 1 PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT |
| 1772 | * 111 PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK |
| 1773 | * 11 PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK |
| 1774 | * 1 PFLAG2_HAS_TRANSIENT_STATE |
| 1775 | * 1 PFLAG2_ACCESSIBILITY_FOCUSED |
| 1776 | * 1 PFLAG2_ACCESSIBILITY_STATE_CHANGED |
| 1777 | * 1 PFLAG2_VIEW_QUICK_REJECTED |
| 1778 | * 1 PFLAG2_PADDING_RESOLVED |
| 1779 | * -------|-------|-------|-------| |
| 1780 | */ |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1781 | |
| 1782 | /** |
| 1783 | * Indicates that this view has reported that it can accept the current drag's content. |
| 1784 | * Cleared when the drag operation concludes. |
| 1785 | * @hide |
| 1786 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1787 | static final int PFLAG2_DRAG_CAN_ACCEPT = 0x00000001; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1788 | |
| 1789 | /** |
| 1790 | * Indicates that this view is currently directly under the drag location in a |
| 1791 | * drag-and-drop operation involving content that it can accept. Cleared when |
| 1792 | * the drag exits the view, or when the drag operation concludes. |
| 1793 | * @hide |
| 1794 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1795 | static final int PFLAG2_DRAG_HOVERED = 0x00000002; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1796 | |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1797 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1798 | * Horizontal layout direction of this view is from Left to Right. |
| 1799 | * Use with {@link #setLayoutDirection}. |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 1800 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1801 | public static final int LAYOUT_DIRECTION_LTR = 0; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1802 | |
| 1803 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1804 | * Horizontal layout direction of this view is from Right to Left. |
| 1805 | * Use with {@link #setLayoutDirection}. |
| 1806 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1807 | public static final int LAYOUT_DIRECTION_RTL = 1; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1808 | |
| 1809 | /** |
| 1810 | * Horizontal layout direction of this view is inherited from its parent. |
| 1811 | * Use with {@link #setLayoutDirection}. |
| 1812 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1813 | public static final int LAYOUT_DIRECTION_INHERIT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1814 | |
| 1815 | /** |
| 1816 | * Horizontal layout direction of this view is from deduced from the default language |
| 1817 | * script for the locale. Use with {@link #setLayoutDirection}. |
| 1818 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1819 | public static final int LAYOUT_DIRECTION_LOCALE = 3; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1820 | |
| 1821 | /** |
| 1822 | * 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] | 1823 | * @hide |
| 1824 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1825 | static final int PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT = 2; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1826 | |
| 1827 | /** |
| 1828 | * Mask for use with private flags indicating bits used for horizontal layout direction. |
| 1829 | * @hide |
| 1830 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1831 | 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] | 1832 | |
| 1833 | /** |
| 1834 | * Indicates whether the view horizontal layout direction has been resolved and drawn to the |
| 1835 | * right-to-left direction. |
| 1836 | * @hide |
| 1837 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1838 | 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] | 1839 | |
| 1840 | /** |
| 1841 | * Indicates whether the view horizontal layout direction has been resolved. |
| 1842 | * @hide |
| 1843 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1844 | 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] | 1845 | |
| 1846 | /** |
| 1847 | * Mask for use with private flags indicating bits used for resolved horizontal layout direction. |
| 1848 | * @hide |
| 1849 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1850 | static final int PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK = 0x0000000C |
| 1851 | << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1852 | |
| 1853 | /* |
| 1854 | * Array of horizontal layout direction flags for mapping attribute "layoutDirection" to correct |
| 1855 | * flag value. |
| 1856 | * @hide |
| 1857 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1858 | private static final int[] LAYOUT_DIRECTION_FLAGS = { |
| 1859 | LAYOUT_DIRECTION_LTR, |
| 1860 | LAYOUT_DIRECTION_RTL, |
| 1861 | LAYOUT_DIRECTION_INHERIT, |
| 1862 | LAYOUT_DIRECTION_LOCALE |
| 1863 | }; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1864 | |
| 1865 | /** |
| 1866 | * Default horizontal layout direction. |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 1867 | */ |
| 1868 | private static final int LAYOUT_DIRECTION_DEFAULT = LAYOUT_DIRECTION_INHERIT; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 1869 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1870 | /** |
| 1871 | * Indicates that the view is tracking some sort of transient state |
| 1872 | * that the app should not need to be aware of, but that the framework |
| 1873 | * should take special care to preserve. |
| 1874 | * |
| 1875 | * @hide |
| 1876 | */ |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 1877 | static final int PFLAG2_HAS_TRANSIENT_STATE = 0x1 << 22; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1878 | |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1879 | /** |
| 1880 | * Text direction is inherited thru {@link ViewGroup} |
| 1881 | */ |
| 1882 | public static final int TEXT_DIRECTION_INHERIT = 0; |
| 1883 | |
| 1884 | /** |
| 1885 | * Text direction is using "first strong algorithm". The first strong directional character |
| 1886 | * determines the paragraph direction. If there is no strong directional character, the |
| 1887 | * paragraph direction is the view's resolved layout direction. |
| 1888 | */ |
| 1889 | public static final int TEXT_DIRECTION_FIRST_STRONG = 1; |
| 1890 | |
| 1891 | /** |
| 1892 | * Text direction is using "any-RTL" algorithm. The paragraph direction is RTL if it contains |
| 1893 | * any strong RTL character, otherwise it is LTR if it contains any strong LTR characters. |
| 1894 | * If there are neither, the paragraph direction is the view's resolved layout direction. |
| 1895 | */ |
| 1896 | public static final int TEXT_DIRECTION_ANY_RTL = 2; |
| 1897 | |
| 1898 | /** |
| 1899 | * Text direction is forced to LTR. |
| 1900 | */ |
| 1901 | public static final int TEXT_DIRECTION_LTR = 3; |
| 1902 | |
| 1903 | /** |
| 1904 | * Text direction is forced to RTL. |
| 1905 | */ |
| 1906 | public static final int TEXT_DIRECTION_RTL = 4; |
| 1907 | |
| 1908 | /** |
| 1909 | * Text direction is coming from the system Locale. |
| 1910 | */ |
| 1911 | public static final int TEXT_DIRECTION_LOCALE = 5; |
| 1912 | |
| 1913 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1914 | * Default text direction is inherited |
| 1915 | */ |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 1916 | private static final int TEXT_DIRECTION_DEFAULT = TEXT_DIRECTION_INHERIT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1917 | |
| 1918 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1919 | * Bit shift to get the horizontal layout direction. (bits after LAYOUT_DIRECTION_RESOLVED) |
| 1920 | * @hide |
| 1921 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1922 | static final int PFLAG2_TEXT_DIRECTION_MASK_SHIFT = 6; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1923 | |
| 1924 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1925 | * Mask for use with private flags indicating bits used for text direction. |
| 1926 | * @hide |
| 1927 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1928 | static final int PFLAG2_TEXT_DIRECTION_MASK = 0x00000007 |
| 1929 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1930 | |
| 1931 | /** |
| 1932 | * Array of text direction flags for mapping attribute "textDirection" to correct |
| 1933 | * flag value. |
| 1934 | * @hide |
| 1935 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1936 | private static final int[] PFLAG2_TEXT_DIRECTION_FLAGS = { |
| 1937 | TEXT_DIRECTION_INHERIT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1938 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1939 | TEXT_DIRECTION_ANY_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1940 | TEXT_DIRECTION_LTR << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1941 | TEXT_DIRECTION_RTL << PFLAG2_TEXT_DIRECTION_MASK_SHIFT, |
| 1942 | TEXT_DIRECTION_LOCALE << PFLAG2_TEXT_DIRECTION_MASK_SHIFT |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1943 | }; |
| 1944 | |
| 1945 | /** |
| 1946 | * Indicates whether the view text direction has been resolved. |
| 1947 | * @hide |
| 1948 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1949 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED = 0x00000008 |
| 1950 | << PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1951 | |
| 1952 | /** |
| 1953 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 1954 | * @hide |
| 1955 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1956 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT = 10; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1957 | |
| 1958 | /** |
| 1959 | * Mask for use with private flags indicating bits used for resolved text direction. |
| 1960 | * @hide |
| 1961 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1962 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_MASK = 0x00000007 |
| 1963 | << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1964 | |
| 1965 | /** |
| 1966 | * Indicates whether the view text direction has been resolved to the "first strong" heuristic. |
| 1967 | * @hide |
| 1968 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1969 | static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT = |
| 1970 | TEXT_DIRECTION_FIRST_STRONG << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 1971 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 1972 | /* |
| 1973 | * Default text alignment. The text alignment of this View is inherited from its parent. |
| 1974 | * Use with {@link #setTextAlignment(int)} |
| 1975 | */ |
| 1976 | public static final int TEXT_ALIGNMENT_INHERIT = 0; |
| 1977 | |
| 1978 | /** |
| 1979 | * Default for the root view. The gravity determines the text alignment, ALIGN_NORMAL, |
| 1980 | * ALIGN_CENTER, or ALIGN_OPPOSITE, which are relative to each paragraph’s text direction. |
| 1981 | * |
| 1982 | * Use with {@link #setTextAlignment(int)} |
| 1983 | */ |
| 1984 | public static final int TEXT_ALIGNMENT_GRAVITY = 1; |
| 1985 | |
| 1986 | /** |
| 1987 | * Align to the start of the paragraph, e.g. ALIGN_NORMAL. |
| 1988 | * |
| 1989 | * Use with {@link #setTextAlignment(int)} |
| 1990 | */ |
| 1991 | public static final int TEXT_ALIGNMENT_TEXT_START = 2; |
| 1992 | |
| 1993 | /** |
| 1994 | * Align to the end of the paragraph, e.g. ALIGN_OPPOSITE. |
| 1995 | * |
| 1996 | * Use with {@link #setTextAlignment(int)} |
| 1997 | */ |
| 1998 | public static final int TEXT_ALIGNMENT_TEXT_END = 3; |
| 1999 | |
| 2000 | /** |
| 2001 | * Center the paragraph, e.g. ALIGN_CENTER. |
| 2002 | * |
| 2003 | * Use with {@link #setTextAlignment(int)} |
| 2004 | */ |
| 2005 | public static final int TEXT_ALIGNMENT_CENTER = 4; |
| 2006 | |
| 2007 | /** |
| 2008 | * Align to the start of the view, which is ALIGN_LEFT if the view’s resolved |
| 2009 | * layoutDirection is LTR, and ALIGN_RIGHT otherwise. |
| 2010 | * |
| 2011 | * Use with {@link #setTextAlignment(int)} |
| 2012 | */ |
| 2013 | public static final int TEXT_ALIGNMENT_VIEW_START = 5; |
| 2014 | |
| 2015 | /** |
| 2016 | * Align to the end of the view, which is ALIGN_RIGHT if the view’s resolved |
| 2017 | * layoutDirection is LTR, and ALIGN_LEFT otherwise. |
| 2018 | * |
| 2019 | * Use with {@link #setTextAlignment(int)} |
| 2020 | */ |
| 2021 | public static final int TEXT_ALIGNMENT_VIEW_END = 6; |
| 2022 | |
| 2023 | /** |
| 2024 | * Default text alignment is inherited |
| 2025 | */ |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 2026 | private static final int TEXT_ALIGNMENT_DEFAULT = TEXT_ALIGNMENT_GRAVITY; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2027 | |
| 2028 | /** |
| 2029 | * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED) |
| 2030 | * @hide |
| 2031 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2032 | static final int PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT = 13; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2033 | |
| 2034 | /** |
| 2035 | * Mask for use with private flags indicating bits used for text alignment. |
| 2036 | * @hide |
| 2037 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2038 | 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] | 2039 | |
| 2040 | /** |
| 2041 | * Array of text direction flags for mapping attribute "textAlignment" to correct |
| 2042 | * flag value. |
| 2043 | * @hide |
| 2044 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2045 | private static final int[] PFLAG2_TEXT_ALIGNMENT_FLAGS = { |
| 2046 | TEXT_ALIGNMENT_INHERIT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2047 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2048 | TEXT_ALIGNMENT_TEXT_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2049 | TEXT_ALIGNMENT_TEXT_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2050 | TEXT_ALIGNMENT_CENTER << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2051 | TEXT_ALIGNMENT_VIEW_START << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT, |
| 2052 | TEXT_ALIGNMENT_VIEW_END << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2053 | }; |
| 2054 | |
| 2055 | /** |
| 2056 | * Indicates whether the view text alignment has been resolved. |
| 2057 | * @hide |
| 2058 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2059 | 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] | 2060 | |
| 2061 | /** |
| 2062 | * Bit shift to get the resolved text alignment. |
| 2063 | * @hide |
| 2064 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2065 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT = 17; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2066 | |
| 2067 | /** |
| 2068 | * Mask for use with private flags indicating bits used for text alignment. |
| 2069 | * @hide |
| 2070 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2071 | static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK = 0x00000007 |
| 2072 | << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2073 | |
| 2074 | /** |
| 2075 | * Indicates whether if the view text alignment has been resolved to gravity |
| 2076 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2077 | private static final int PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT = |
| 2078 | TEXT_ALIGNMENT_GRAVITY << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 2079 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2080 | // Accessiblity constants for mPrivateFlags2 |
| 2081 | |
| 2082 | /** |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2083 | * Shift for the bits in {@link #mPrivateFlags2} related to the |
| 2084 | * "importantForAccessibility" attribute. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2085 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2086 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT = 20; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2087 | |
| 2088 | /** |
| 2089 | * Automatically determine whether a view is important for accessibility. |
| 2090 | */ |
| 2091 | public static final int IMPORTANT_FOR_ACCESSIBILITY_AUTO = 0x00000000; |
| 2092 | |
| 2093 | /** |
| 2094 | * The view is important for accessibility. |
| 2095 | */ |
| 2096 | public static final int IMPORTANT_FOR_ACCESSIBILITY_YES = 0x00000001; |
| 2097 | |
| 2098 | /** |
| 2099 | * The view is not important for accessibility. |
| 2100 | */ |
| 2101 | public static final int IMPORTANT_FOR_ACCESSIBILITY_NO = 0x00000002; |
| 2102 | |
| 2103 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 2104 | * The default whether the view is important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2105 | */ |
| 2106 | static final int IMPORTANT_FOR_ACCESSIBILITY_DEFAULT = IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 2107 | |
| 2108 | /** |
| 2109 | * Mask for obtainig the bits which specify how to determine |
| 2110 | * whether a view is important for accessibility. |
| 2111 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2112 | static final int PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK = (IMPORTANT_FOR_ACCESSIBILITY_AUTO |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2113 | | IMPORTANT_FOR_ACCESSIBILITY_YES | IMPORTANT_FOR_ACCESSIBILITY_NO) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2114 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2115 | |
| 2116 | /** |
| 2117 | * Flag indicating whether a view has accessibility focus. |
| 2118 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2119 | static final int PFLAG2_ACCESSIBILITY_FOCUSED = 0x00000040 << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2120 | |
| 2121 | /** |
| 2122 | * Flag indicating whether a view state for accessibility has changed. |
| 2123 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2124 | static final int PFLAG2_ACCESSIBILITY_STATE_CHANGED = 0x00000080 |
| 2125 | << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 2126 | |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 2127 | /** |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2128 | * Flag indicating whether a view failed the quickReject() check in draw(). This condition |
| 2129 | * is used to check whether later changes to the view's transform should invalidate the |
| 2130 | * view to force the quickReject test to run again. |
| 2131 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2132 | static final int PFLAG2_VIEW_QUICK_REJECTED = 0x10000000; |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 2133 | |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2134 | /** |
| 2135 | * Flag indicating that start/end padding has been resolved into left/right padding |
| 2136 | * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()} |
| 2137 | * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved |
| 2138 | * during measurement. In some special cases this is required such as when an adapter-based |
| 2139 | * view measures prospective children without attaching them to a window. |
| 2140 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2141 | static final int PFLAG2_PADDING_RESOLVED = 0x20000000; |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 2142 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2143 | /** |
| 2144 | * Flag indicating that the start/end drawables has been resolved into left/right ones. |
| 2145 | */ |
| 2146 | static final int PFLAG2_DRAWABLE_RESOLVED = 0x40000000; |
| 2147 | |
| 2148 | /** |
| 2149 | * Group of bits indicating that RTL properties resolution is done. |
| 2150 | */ |
| 2151 | static final int ALL_RTL_PROPERTIES_RESOLVED = PFLAG2_LAYOUT_DIRECTION_RESOLVED | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 2152 | PFLAG2_TEXT_DIRECTION_RESOLVED | |
| 2153 | PFLAG2_TEXT_ALIGNMENT_RESOLVED | |
| 2154 | PFLAG2_PADDING_RESOLVED | |
| 2155 | PFLAG2_DRAWABLE_RESOLVED; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 2156 | |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 2157 | // There are a couple of flags left in mPrivateFlags2 |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 2158 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2159 | /* End of masks for mPrivateFlags2 */ |
| 2160 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2161 | /* Masks for mPrivateFlags3 */ |
| 2162 | |
| 2163 | /** |
| 2164 | * Flag indicating that view has a transform animation set on it. This is used to track whether |
| 2165 | * an animation is cleared between successive frames, in order to tell the associated |
| 2166 | * DisplayList to clear its animation matrix. |
| 2167 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2168 | static final int PFLAG3_VIEW_IS_ANIMATING_TRANSFORM = 0x1; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2169 | |
| 2170 | /** |
| 2171 | * Flag indicating that view has an alpha animation set on it. This is used to track whether an |
| 2172 | * animation is cleared between successive frames, in order to tell the associated |
| 2173 | * DisplayList to restore its alpha value. |
| 2174 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2175 | static final int PFLAG3_VIEW_IS_ANIMATING_ALPHA = 0x2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2176 | |
| 2177 | |
| 2178 | /* End of masks for mPrivateFlags3 */ |
| 2179 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2180 | static final int DRAG_MASK = PFLAG2_DRAG_CAN_ACCEPT | PFLAG2_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2181 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 2182 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2183 | * Always allow a user to over-scroll this view, provided it is a |
| 2184 | * view that can scroll. |
| 2185 | * |
| 2186 | * @see #getOverScrollMode() |
| 2187 | * @see #setOverScrollMode(int) |
| 2188 | */ |
| 2189 | public static final int OVER_SCROLL_ALWAYS = 0; |
| 2190 | |
| 2191 | /** |
| 2192 | * Allow a user to over-scroll this view only if the content is large |
| 2193 | * enough to meaningfully scroll, provided it is a view that can scroll. |
| 2194 | * |
| 2195 | * @see #getOverScrollMode() |
| 2196 | * @see #setOverScrollMode(int) |
| 2197 | */ |
| 2198 | public static final int OVER_SCROLL_IF_CONTENT_SCROLLS = 1; |
| 2199 | |
| 2200 | /** |
| 2201 | * Never allow a user to over-scroll this view. |
| 2202 | * |
| 2203 | * @see #getOverScrollMode() |
| 2204 | * @see #setOverScrollMode(int) |
| 2205 | */ |
| 2206 | public static final int OVER_SCROLL_NEVER = 2; |
| 2207 | |
| 2208 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2209 | * Special constant for {@link #setSystemUiVisibility(int)}: View has |
| 2210 | * requested the system UI (status bar) to be visible (the default). |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2211 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2212 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2213 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2214 | public static final int SYSTEM_UI_FLAG_VISIBLE = 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2215 | |
| 2216 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2217 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested the |
| 2218 | * system UI to enter an unobtrusive "low profile" mode. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2219 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2220 | * <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] | 2221 | * "immersive" application where the usual system chrome is deemed too distracting. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2222 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2223 | * <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] | 2224 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2225 | * @see #setSystemUiVisibility(int) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2226 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2227 | public static final int SYSTEM_UI_FLAG_LOW_PROFILE = 0x00000001; |
| 2228 | |
| 2229 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2230 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested that the |
| 2231 | * system navigation be temporarily hidden. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2232 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2233 | * <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] | 2234 | * {@link #SYSTEM_UI_FLAG_LOW_PROFILE}; on devices that draw essential navigation controls |
| 2235 | * (Home, Back, and the like) on screen, <code>SYSTEM_UI_FLAG_HIDE_NAVIGATION</code> will cause |
| 2236 | * those to disappear. This is useful (in conjunction with the |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2237 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN FLAG_FULLSCREEN} and |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2238 | * {@link android.view.WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN FLAG_LAYOUT_IN_SCREEN} |
| 2239 | * window flags) for displaying content using every last pixel on the display. |
| 2240 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2241 | * <p>There is a limitation: because navigation controls are so important, the least user |
| 2242 | * interaction will cause them to reappear immediately. When this happens, both |
| 2243 | * this flag and {@link #SYSTEM_UI_FLAG_FULLSCREEN} will be cleared automatically, |
| 2244 | * so that both elements reappear at the same time. |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2245 | * |
| 2246 | * @see #setSystemUiVisibility(int) |
| 2247 | */ |
| 2248 | public static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = 0x00000002; |
| 2249 | |
| 2250 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2251 | * Flag for {@link #setSystemUiVisibility(int)}: View has requested to go |
| 2252 | * into the normal fullscreen mode so that its content can take over the screen |
| 2253 | * while still allowing the user to interact with the application. |
| 2254 | * |
| 2255 | * <p>This has the same visual effect as |
| 2256 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN |
| 2257 | * WindowManager.LayoutParams.FLAG_FULLSCREEN}, |
| 2258 | * meaning that non-critical screen decorations (such as the status bar) will be |
| 2259 | * hidden while the user is in the View's window, focusing the experience on |
| 2260 | * that content. Unlike the window flag, if you are using ActionBar in |
| 2261 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2262 | * Window.FEATURE_ACTION_BAR_OVERLAY}, then enabling this flag will also |
| 2263 | * hide the action bar. |
| 2264 | * |
| 2265 | * <p>This approach to going fullscreen is best used over the window flag when |
| 2266 | * it is a transient state -- that is, the application does this at certain |
| 2267 | * points in its user interaction where it wants to allow the user to focus |
| 2268 | * on content, but not as a continuous state. For situations where the application |
| 2269 | * would like to simply stay full screen the entire time (such as a game that |
| 2270 | * wants to take over the screen), the |
| 2271 | * {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN window flag} |
| 2272 | * is usually a better approach. The state set here will be removed by the system |
| 2273 | * in various situations (such as the user moving to another application) like |
| 2274 | * the other system UI states. |
| 2275 | * |
| 2276 | * <p>When using this flag, the application should provide some easy facility |
| 2277 | * for the user to go out of it. A common example would be in an e-book |
| 2278 | * reader, where tapping on the screen brings back whatever screen and UI |
| 2279 | * decorations that had been hidden while the user was immersed in reading |
| 2280 | * the book. |
| 2281 | * |
| 2282 | * @see #setSystemUiVisibility(int) |
| 2283 | */ |
| 2284 | public static final int SYSTEM_UI_FLAG_FULLSCREEN = 0x00000004; |
| 2285 | |
| 2286 | /** |
| 2287 | * Flag for {@link #setSystemUiVisibility(int)}: When using other layout |
| 2288 | * flags, we would like a stable view of the content insets given to |
| 2289 | * {@link #fitSystemWindows(Rect)}. This means that the insets seen there |
| 2290 | * will always represent the worst case that the application can expect |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2291 | * as a continuous state. In the stock Android UI this is the space for |
| 2292 | * the system bar, nav bar, and status bar, but not more transient elements |
| 2293 | * such as an input method. |
| 2294 | * |
| 2295 | * The stable layout your UI sees is based on the system UI modes you can |
| 2296 | * switch to. That is, if you specify {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 2297 | * then you will get a stable layout for changes of the |
| 2298 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN} mode; if you specify |
| 2299 | * {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} and |
| 2300 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, then you can transition |
| 2301 | * to {@link #SYSTEM_UI_FLAG_FULLSCREEN} and {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION} |
| 2302 | * with a stable layout. (Note that you should avoid using |
| 2303 | * {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} by itself.) |
| 2304 | * |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 2305 | * If you have set the window flag {@link WindowManager.LayoutParams#FLAG_FULLSCREEN} |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2306 | * to hide the status bar (instead of using {@link #SYSTEM_UI_FLAG_FULLSCREEN}), |
| 2307 | * then a hidden status bar will be considered a "stable" state for purposes |
| 2308 | * here. This allows your UI to continually hide the status bar, while still |
| 2309 | * using the system UI flags to hide the action bar while still retaining |
| 2310 | * a stable layout. Note that changing the window fullscreen flag will never |
| 2311 | * provide a stable layout for a clean transition. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2312 | * |
| 2313 | * <p>If you are using ActionBar in |
| 2314 | * overlay mode with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 2315 | * Window.FEATURE_ACTION_BAR_OVERLAY}, this flag will also impact the |
| 2316 | * insets it adds to those given to the application. |
| 2317 | */ |
| 2318 | public static final int SYSTEM_UI_FLAG_LAYOUT_STABLE = 0x00000100; |
| 2319 | |
| 2320 | /** |
| 2321 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2322 | * to be layed out as if it has requested |
| 2323 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, even if it currently hasn't. This |
| 2324 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2325 | * the expense that some of its user interface may be covered by screen |
| 2326 | * decorations when they are shown. You can perform layout of your inner |
| 2327 | * UI elements to account for the navagation system UI through the |
| 2328 | * {@link #fitSystemWindows(Rect)} method. |
| 2329 | */ |
| 2330 | public static final int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION = 0x00000200; |
| 2331 | |
| 2332 | /** |
| 2333 | * Flag for {@link #setSystemUiVisibility(int)}: View would like its window |
| 2334 | * to be layed out as if it has requested |
| 2335 | * {@link #SYSTEM_UI_FLAG_FULLSCREEN}, even if it currently hasn't. This |
| 2336 | * allows it to avoid artifacts when switching in and out of that mode, at |
| 2337 | * the expense that some of its user interface may be covered by screen |
| 2338 | * decorations when they are shown. You can perform layout of your inner |
| 2339 | * UI elements to account for non-fullscreen system UI through the |
| 2340 | * {@link #fitSystemWindows(Rect)} method. |
| 2341 | */ |
| 2342 | public static final int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN = 0x00000400; |
| 2343 | |
| 2344 | /** |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2345 | * @deprecated Use {@link #SYSTEM_UI_FLAG_LOW_PROFILE} instead. |
| 2346 | */ |
| 2347 | public static final int STATUS_BAR_HIDDEN = SYSTEM_UI_FLAG_LOW_PROFILE; |
| 2348 | |
| 2349 | /** |
| 2350 | * @deprecated Use {@link #SYSTEM_UI_FLAG_VISIBLE} instead. |
| 2351 | */ |
| 2352 | public static final int STATUS_BAR_VISIBLE = SYSTEM_UI_FLAG_VISIBLE; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2353 | |
| 2354 | /** |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2355 | * @hide |
| 2356 | * |
| 2357 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2358 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2359 | * |
| 2360 | * Flag to make the status bar not expandable. Unless you also |
| 2361 | * set {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS}, new notifications will continue to show. |
| 2362 | */ |
| 2363 | public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000; |
| 2364 | |
| 2365 | /** |
| 2366 | * @hide |
| 2367 | * |
| 2368 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2369 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2370 | * |
| 2371 | * Flag to hide notification icons and scrolling ticker text. |
| 2372 | */ |
| 2373 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000; |
| 2374 | |
| 2375 | /** |
| 2376 | * @hide |
| 2377 | * |
| 2378 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2379 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2380 | * |
| 2381 | * Flag to disable incoming notification alerts. This will not block |
| 2382 | * icons, but it will block sound, vibrating and other visual or aural notifications. |
| 2383 | */ |
| 2384 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000; |
| 2385 | |
| 2386 | /** |
| 2387 | * @hide |
| 2388 | * |
| 2389 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2390 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2391 | * |
| 2392 | * Flag to hide only the scrolling ticker. Note that |
| 2393 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_ICONS} implies |
| 2394 | * {@link #STATUS_BAR_DISABLE_NOTIFICATION_TICKER}. |
| 2395 | */ |
| 2396 | public static final int STATUS_BAR_DISABLE_NOTIFICATION_TICKER = 0x00080000; |
| 2397 | |
| 2398 | /** |
| 2399 | * @hide |
| 2400 | * |
| 2401 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2402 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2403 | * |
| 2404 | * Flag to hide the center system info area. |
| 2405 | */ |
| 2406 | public static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000; |
| 2407 | |
| 2408 | /** |
| 2409 | * @hide |
| 2410 | * |
| 2411 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2412 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2413 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2414 | * Flag to hide only the home button. Don't use this |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2415 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2416 | */ |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2417 | public static final int STATUS_BAR_DISABLE_HOME = 0x00200000; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2418 | |
| 2419 | /** |
| 2420 | * @hide |
| 2421 | * |
| 2422 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2423 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2424 | * |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2425 | * Flag to hide only the back button. Don't use this |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2426 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2427 | */ |
| 2428 | public static final int STATUS_BAR_DISABLE_BACK = 0x00400000; |
| 2429 | |
| 2430 | /** |
| 2431 | * @hide |
| 2432 | * |
| 2433 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2434 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2435 | * |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2436 | * Flag to hide only the clock. You might use this if your activity has |
| 2437 | * its own clock making the status bar's clock redundant. |
| 2438 | */ |
Joe Onorato | 6478adc | 2011-01-27 21:15:01 -0800 | [diff] [blame] | 2439 | public static final int STATUS_BAR_DISABLE_CLOCK = 0x00800000; |
| 2440 | |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2441 | /** |
| 2442 | * @hide |
Daniel Sandler | dba9356 | 2011-10-06 16:39:58 -0400 | [diff] [blame] | 2443 | * |
| 2444 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2445 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2446 | * |
| 2447 | * Flag to hide only the recent apps button. Don't use this |
| 2448 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2449 | */ |
| 2450 | public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000; |
| 2451 | |
| 2452 | /** |
| 2453 | * @hide |
Daniel Sandler | d5483c3 | 2012-10-19 16:44:15 -0400 | [diff] [blame] | 2454 | * |
| 2455 | * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked |
| 2456 | * out of the public fields to keep the undefined bits out of the developer's way. |
| 2457 | * |
| 2458 | * Flag to disable the global search gesture. Don't use this |
| 2459 | * unless you're a special part of the system UI (i.e., setup wizard, keyguard). |
| 2460 | */ |
| 2461 | public static final int STATUS_BAR_DISABLE_SEARCH = 0x02000000; |
| 2462 | |
| 2463 | /** |
| 2464 | * @hide |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2465 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2466 | public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF; |
Joe Onorato | 7bb8eeb | 2011-01-27 16:00:58 -0800 | [diff] [blame] | 2467 | |
| 2468 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2469 | * These are the system UI flags that can be cleared by events outside |
| 2470 | * of an application. Currently this is just the ability to tap on the |
| 2471 | * screen while hiding the navigation bar to have it return. |
| 2472 | * @hide |
| 2473 | */ |
| 2474 | public static final int SYSTEM_UI_CLEARABLE_FLAGS = |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2475 | SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 2476 | | SYSTEM_UI_FLAG_FULLSCREEN; |
| 2477 | |
| 2478 | /** |
| 2479 | * Flags that can impact the layout in relation to system UI. |
| 2480 | */ |
| 2481 | public static final int SYSTEM_UI_LAYOUT_FLAGS = |
| 2482 | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 2483 | | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 2484 | |
| 2485 | /** |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 2486 | * Find views that render the specified text. |
| 2487 | * |
| 2488 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2489 | */ |
| 2490 | public static final int FIND_VIEWS_WITH_TEXT = 0x00000001; |
| 2491 | |
| 2492 | /** |
| 2493 | * Find find views that contain the specified content description. |
| 2494 | * |
| 2495 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2496 | */ |
| 2497 | public static final int FIND_VIEWS_WITH_CONTENT_DESCRIPTION = 0x00000002; |
| 2498 | |
| 2499 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 2500 | * Find views that contain {@link AccessibilityNodeProvider}. Such |
| 2501 | * a View is a root of virtual view hierarchy and may contain the searched |
| 2502 | * text. If this flag is set Views with providers are automatically |
| 2503 | * added and it is a responsibility of the client to call the APIs of |
| 2504 | * the provider to determine whether the virtual tree rooted at this View |
| 2505 | * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s |
| 2506 | * represeting the virtual views with this text. |
| 2507 | * |
| 2508 | * @see #findViewsWithText(ArrayList, CharSequence, int) |
| 2509 | * |
| 2510 | * @hide |
| 2511 | */ |
| 2512 | public static final int FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS = 0x00000004; |
| 2513 | |
| 2514 | /** |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2515 | * The undefined cursor position. |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 2516 | * |
| 2517 | * @hide |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2518 | */ |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 2519 | public static final int ACCESSIBILITY_CURSOR_POSITION_UNDEFINED = -1; |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 2520 | |
| 2521 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2522 | * Indicates that the screen has changed state and is now off. |
| 2523 | * |
| 2524 | * @see #onScreenStateChanged(int) |
| 2525 | */ |
| 2526 | public static final int SCREEN_STATE_OFF = 0x0; |
| 2527 | |
| 2528 | /** |
| 2529 | * Indicates that the screen has changed state and is now on. |
| 2530 | * |
Romain Guy | 1e3d313 | 2012-03-08 15:55:56 -0800 | [diff] [blame] | 2531 | * @see #onScreenStateChanged(int) |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 2532 | */ |
| 2533 | public static final int SCREEN_STATE_ON = 0x1; |
| 2534 | |
| 2535 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 2536 | * Controls the over-scroll mode for this view. |
| 2537 | * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, |
| 2538 | * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, |
| 2539 | * and {@link #OVER_SCROLL_NEVER}. |
| 2540 | */ |
| 2541 | private int mOverScrollMode; |
| 2542 | |
| 2543 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | * The parent this view is attached to. |
| 2545 | * {@hide} |
| 2546 | * |
| 2547 | * @see #getParent() |
| 2548 | */ |
| 2549 | protected ViewParent mParent; |
| 2550 | |
| 2551 | /** |
| 2552 | * {@hide} |
| 2553 | */ |
| 2554 | AttachInfo mAttachInfo; |
| 2555 | |
| 2556 | /** |
| 2557 | * {@hide} |
| 2558 | */ |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2559 | @ViewDebug.ExportedProperty(flagMapping = { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2560 | @ViewDebug.FlagToString(mask = PFLAG_FORCE_LAYOUT, equals = PFLAG_FORCE_LAYOUT, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2561 | name = "FORCE_LAYOUT"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2562 | @ViewDebug.FlagToString(mask = PFLAG_LAYOUT_REQUIRED, equals = PFLAG_LAYOUT_REQUIRED, |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2563 | name = "LAYOUT_REQUIRED"), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2564 | @ViewDebug.FlagToString(mask = PFLAG_DRAWING_CACHE_VALID, equals = PFLAG_DRAWING_CACHE_VALID, |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 2565 | name = "DRAWING_CACHE_INVALID", outputIf = false), |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2566 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "DRAWN", outputIf = true), |
| 2567 | @ViewDebug.FlagToString(mask = PFLAG_DRAWN, equals = PFLAG_DRAWN, name = "NOT_DRAWN", outputIf = false), |
| 2568 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY_OPAQUE, name = "DIRTY_OPAQUE"), |
| 2569 | @ViewDebug.FlagToString(mask = PFLAG_DIRTY_MASK, equals = PFLAG_DIRTY, name = "DIRTY") |
Romain Guy | 809a7f6 | 2009-05-14 15:44:42 -0700 | [diff] [blame] | 2570 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2571 | int mPrivateFlags; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 2572 | int mPrivateFlags2; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 2573 | int mPrivateFlags3; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | |
| 2575 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2576 | * This view's request for the visibility of the status bar. |
| 2577 | * @hide |
| 2578 | */ |
Daniel Sandler | 60ee256 | 2011-07-22 12:34:33 -0400 | [diff] [blame] | 2579 | @ViewDebug.ExportedProperty(flagMapping = { |
| 2580 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2581 | equals = SYSTEM_UI_FLAG_LOW_PROFILE, |
| 2582 | name = "SYSTEM_UI_FLAG_LOW_PROFILE", outputIf = true), |
| 2583 | @ViewDebug.FlagToString(mask = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2584 | equals = SYSTEM_UI_FLAG_HIDE_NAVIGATION, |
| 2585 | name = "SYSTEM_UI_FLAG_HIDE_NAVIGATION", outputIf = true), |
| 2586 | @ViewDebug.FlagToString(mask = PUBLIC_STATUS_BAR_VISIBILITY_MASK, |
| 2587 | equals = SYSTEM_UI_FLAG_VISIBLE, |
| 2588 | name = "SYSTEM_UI_FLAG_VISIBLE", outputIf = true) |
| 2589 | }) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2590 | int mSystemUiVisibility; |
| 2591 | |
| 2592 | /** |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 2593 | * Reference count for transient state. |
| 2594 | * @see #setHasTransientState(boolean) |
| 2595 | */ |
| 2596 | int mTransientStateCount = 0; |
| 2597 | |
| 2598 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | * Count of how many windows this view has been attached to. |
| 2600 | */ |
| 2601 | int mWindowAttachCount; |
| 2602 | |
| 2603 | /** |
| 2604 | * The layout parameters associated with this view and used by the parent |
| 2605 | * {@link android.view.ViewGroup} to determine how this view should be |
| 2606 | * laid out. |
| 2607 | * {@hide} |
| 2608 | */ |
| 2609 | protected ViewGroup.LayoutParams mLayoutParams; |
| 2610 | |
| 2611 | /** |
| 2612 | * The view flags hold various views states. |
| 2613 | * {@hide} |
| 2614 | */ |
| 2615 | @ViewDebug.ExportedProperty |
| 2616 | int mViewFlags; |
| 2617 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2618 | static class TransformationInfo { |
| 2619 | /** |
| 2620 | * The transform matrix for the View. This transform is calculated internally |
| 2621 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2622 | * is used by default. Do *not* use this variable directly; instead call |
| 2623 | * getMatrix(), which will automatically recalculate the matrix if necessary |
| 2624 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2625 | */ |
| 2626 | private final Matrix mMatrix = new Matrix(); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2627 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2628 | /** |
| 2629 | * The transform matrix for the View. This transform is calculated internally |
| 2630 | * based on the rotation, scaleX, and scaleY properties. The identity matrix |
| 2631 | * is used by default. Do *not* use this variable directly; instead call |
| 2632 | * getInverseMatrix(), which will automatically recalculate the matrix if necessary |
| 2633 | * to get the correct matrix based on the latest rotation and scale properties. |
| 2634 | */ |
| 2635 | private Matrix mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2636 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2637 | /** |
| 2638 | * An internal variable that tracks whether we need to recalculate the |
| 2639 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2640 | * have changed since the matrix was last calculated. |
| 2641 | */ |
| 2642 | boolean mMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2643 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2644 | /** |
| 2645 | * An internal variable that tracks whether we need to recalculate the |
| 2646 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2647 | * have changed since the matrix was last calculated. |
| 2648 | */ |
| 2649 | private boolean mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2650 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2651 | /** |
| 2652 | * A variable that tracks whether we need to recalculate the |
| 2653 | * transform matrix, based on whether the rotation or scaleX/Y properties |
| 2654 | * have changed since the matrix was last calculated. This variable |
| 2655 | * is only valid after a call to updateMatrix() or to a function that |
| 2656 | * calls it such as getMatrix(), hasIdentityMatrix() and getInverseMatrix(). |
| 2657 | */ |
| 2658 | private boolean mMatrixIsIdentity = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 2659 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2660 | /** |
| 2661 | * The Camera object is used to compute a 3D matrix when rotationX or rotationY are set. |
| 2662 | */ |
| 2663 | private Camera mCamera = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2664 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2665 | /** |
| 2666 | * This matrix is used when computing the matrix for 3D rotations. |
| 2667 | */ |
| 2668 | private Matrix matrix3D = null; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2669 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2670 | /** |
| 2671 | * These prev values are used to recalculate a centered pivot point when necessary. The |
| 2672 | * pivot point is only used in matrix operations (when rotation, scale, or translation are |
| 2673 | * set), so thes values are only used then as well. |
| 2674 | */ |
| 2675 | private int mPrevWidth = -1; |
| 2676 | private int mPrevHeight = -1; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2677 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 2678 | /** |
| 2679 | * The degrees rotation around the vertical axis through the pivot point. |
| 2680 | */ |
| 2681 | @ViewDebug.ExportedProperty |
| 2682 | float mRotationY = 0f; |
| 2683 | |
| 2684 | /** |
| 2685 | * The degrees rotation around the horizontal axis through the pivot point. |
| 2686 | */ |
| 2687 | @ViewDebug.ExportedProperty |
| 2688 | float mRotationX = 0f; |
| 2689 | |
| 2690 | /** |
| 2691 | * The degrees rotation around the pivot point. |
| 2692 | */ |
| 2693 | @ViewDebug.ExportedProperty |
| 2694 | float mRotation = 0f; |
| 2695 | |
| 2696 | /** |
| 2697 | * The amount of translation of the object away from its left property (post-layout). |
| 2698 | */ |
| 2699 | @ViewDebug.ExportedProperty |
| 2700 | float mTranslationX = 0f; |
| 2701 | |
| 2702 | /** |
| 2703 | * The amount of translation of the object away from its top property (post-layout). |
| 2704 | */ |
| 2705 | @ViewDebug.ExportedProperty |
| 2706 | float mTranslationY = 0f; |
| 2707 | |
| 2708 | /** |
| 2709 | * The amount of scale in the x direction around the pivot point. A |
| 2710 | * value of 1 means no scaling is applied. |
| 2711 | */ |
| 2712 | @ViewDebug.ExportedProperty |
| 2713 | float mScaleX = 1f; |
| 2714 | |
| 2715 | /** |
| 2716 | * The amount of scale in the y direction around the pivot point. A |
| 2717 | * value of 1 means no scaling is applied. |
| 2718 | */ |
| 2719 | @ViewDebug.ExportedProperty |
| 2720 | float mScaleY = 1f; |
| 2721 | |
| 2722 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2723 | * 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] | 2724 | */ |
| 2725 | @ViewDebug.ExportedProperty |
| 2726 | float mPivotX = 0f; |
| 2727 | |
| 2728 | /** |
Chet Haase | a33de55 | 2012-02-03 16:28:24 -0800 | [diff] [blame] | 2729 | * 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] | 2730 | */ |
| 2731 | @ViewDebug.ExportedProperty |
| 2732 | float mPivotY = 0f; |
| 2733 | |
| 2734 | /** |
| 2735 | * The opacity of the View. This is a value from 0 to 1, where 0 means |
| 2736 | * completely transparent and 1 means completely opaque. |
| 2737 | */ |
| 2738 | @ViewDebug.ExportedProperty |
| 2739 | float mAlpha = 1f; |
| 2740 | } |
| 2741 | |
| 2742 | TransformationInfo mTransformationInfo; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2743 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 2744 | private boolean mLastIsOpaque; |
| 2745 | |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2746 | /** |
| 2747 | * Convenience value to check for float values that are close enough to zero to be considered |
| 2748 | * zero. |
| 2749 | */ |
Romain Guy | 2542d19 | 2010-08-18 11:47:12 -0700 | [diff] [blame] | 2750 | private static final float NONZERO_EPSILON = .001f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 2751 | |
| 2752 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | * The distance in pixels from the left edge of this view's parent |
| 2754 | * to the left edge of this view. |
| 2755 | * {@hide} |
| 2756 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2757 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | protected int mLeft; |
| 2759 | /** |
| 2760 | * The distance in pixels from the left edge of this view's parent |
| 2761 | * to the right edge of this view. |
| 2762 | * {@hide} |
| 2763 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2764 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2765 | protected int mRight; |
| 2766 | /** |
| 2767 | * The distance in pixels from the top edge of this view's parent |
| 2768 | * to the top edge of this view. |
| 2769 | * {@hide} |
| 2770 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2771 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2772 | protected int mTop; |
| 2773 | /** |
| 2774 | * The distance in pixels from the top edge of this view's parent |
| 2775 | * to the bottom edge of this view. |
| 2776 | * {@hide} |
| 2777 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2778 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2779 | protected int mBottom; |
| 2780 | |
| 2781 | /** |
| 2782 | * The offset, in pixels, by which the content of this view is scrolled |
| 2783 | * horizontally. |
| 2784 | * {@hide} |
| 2785 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2786 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2787 | protected int mScrollX; |
| 2788 | /** |
| 2789 | * The offset, in pixels, by which the content of this view is scrolled |
| 2790 | * vertically. |
| 2791 | * {@hide} |
| 2792 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2793 | @ViewDebug.ExportedProperty(category = "scrolling") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | protected int mScrollY; |
| 2795 | |
| 2796 | /** |
| 2797 | * The left padding in pixels, that is the distance in pixels between the |
| 2798 | * left edge of this view and the left edge of its content. |
| 2799 | * {@hide} |
| 2800 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2801 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2802 | protected int mPaddingLeft = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | /** |
| 2804 | * The right padding in pixels, that is the distance in pixels between the |
| 2805 | * right edge of this view and the right edge of its content. |
| 2806 | * {@hide} |
| 2807 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2808 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 2809 | protected int mPaddingRight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | /** |
| 2811 | * The top padding in pixels, that is the distance in pixels between the |
| 2812 | * top edge of this view and the top edge of its content. |
| 2813 | * {@hide} |
| 2814 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2815 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | protected int mPaddingTop; |
| 2817 | /** |
| 2818 | * The bottom padding in pixels, that is the distance in pixels between the |
| 2819 | * bottom edge of this view and the bottom edge of its content. |
| 2820 | * {@hide} |
| 2821 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2822 | @ViewDebug.ExportedProperty(category = "padding") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | protected int mPaddingBottom; |
| 2824 | |
| 2825 | /** |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 2826 | * The layout insets in pixels, that is the distance in pixels between the |
| 2827 | * visible edges of this view its bounds. |
| 2828 | */ |
| 2829 | private Insets mLayoutInsets; |
| 2830 | |
| 2831 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 2832 | * Briefly describes the view and is primarily used for accessibility support. |
| 2833 | */ |
| 2834 | private CharSequence mContentDescription; |
| 2835 | |
| 2836 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 2837 | * Specifies the id of a view for which this view serves as a label for |
| 2838 | * accessibility purposes. |
| 2839 | */ |
| 2840 | private int mLabelForId = View.NO_ID; |
| 2841 | |
| 2842 | /** |
| 2843 | * Predicate for matching labeled view id with its label for |
| 2844 | * accessibility purposes. |
| 2845 | */ |
| 2846 | private MatchLabelForPredicate mMatchLabelForPredicate; |
| 2847 | |
| 2848 | /** |
| 2849 | * Predicate for matching a view by its id. |
| 2850 | */ |
| 2851 | private MatchIdPredicate mMatchIdPredicate; |
| 2852 | |
| 2853 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | * 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] | 2855 | * |
| 2856 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2858 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2859 | protected int mUserPaddingRight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | |
| 2861 | /** |
| 2862 | * 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] | 2863 | * |
| 2864 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 2866 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2867 | protected int mUserPaddingBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2869 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2870 | * 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] | 2871 | * |
| 2872 | * @hide |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2873 | */ |
| 2874 | @ViewDebug.ExportedProperty(category = "padding") |
Fabrice Di Meglio | 54d6962 | 2011-07-15 16:46:44 -0700 | [diff] [blame] | 2875 | protected int mUserPaddingLeft; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 2876 | |
| 2877 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 2878 | * Cache the paddingStart set by the user to append to the scrollbar's size. |
| 2879 | * |
| 2880 | */ |
| 2881 | @ViewDebug.ExportedProperty(category = "padding") |
| 2882 | int mUserPaddingStart; |
| 2883 | |
| 2884 | /** |
| 2885 | * Cache the paddingEnd set by the user to append to the scrollbar's size. |
| 2886 | * |
| 2887 | */ |
| 2888 | @ViewDebug.ExportedProperty(category = "padding") |
| 2889 | int mUserPaddingEnd; |
| 2890 | |
| 2891 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2892 | * Cache initial left padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2893 | * |
| 2894 | * @hide |
| 2895 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2896 | int mUserPaddingLeftInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2897 | |
| 2898 | /** |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 2899 | * Cache initial right padding. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2900 | * |
| 2901 | * @hide |
| 2902 | */ |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 2903 | int mUserPaddingRightInitial = 0; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 2904 | |
| 2905 | /** |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 2906 | * Default undefined padding |
| 2907 | */ |
| 2908 | private static final int UNDEFINED_PADDING = Integer.MIN_VALUE; |
| 2909 | |
| 2910 | /** |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2911 | * @hide |
| 2912 | */ |
| 2913 | int mOldWidthMeasureSpec = Integer.MIN_VALUE; |
| 2914 | /** |
| 2915 | * @hide |
| 2916 | */ |
| 2917 | int mOldHeightMeasureSpec = Integer.MIN_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2918 | |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 2919 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "bg_") |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2920 | private Drawable mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | |
| 2922 | private int mBackgroundResource; |
| 2923 | private boolean mBackgroundSizeChanged; |
| 2924 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2925 | static class ListenerInfo { |
| 2926 | /** |
| 2927 | * Listener used to dispatch focus change events. |
| 2928 | * This field should be made private, so it is hidden from the SDK. |
| 2929 | * {@hide} |
| 2930 | */ |
| 2931 | protected OnFocusChangeListener mOnFocusChangeListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2932 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2933 | /** |
| 2934 | * Listeners for layout change events. |
| 2935 | */ |
| 2936 | private ArrayList<OnLayoutChangeListener> mOnLayoutChangeListeners; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 2937 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2938 | /** |
| 2939 | * Listeners for attach events. |
| 2940 | */ |
| 2941 | private CopyOnWriteArrayList<OnAttachStateChangeListener> mOnAttachStateChangeListeners; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 2942 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2943 | /** |
| 2944 | * Listener used to dispatch click events. |
| 2945 | * This field should be made private, so it is hidden from the SDK. |
| 2946 | * {@hide} |
| 2947 | */ |
| 2948 | public OnClickListener mOnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2950 | /** |
| 2951 | * Listener used to dispatch long click events. |
| 2952 | * This field should be made private, so it is hidden from the SDK. |
| 2953 | * {@hide} |
| 2954 | */ |
| 2955 | protected OnLongClickListener mOnLongClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2957 | /** |
| 2958 | * Listener used to build the context menu. |
| 2959 | * This field should be made private, so it is hidden from the SDK. |
| 2960 | * {@hide} |
| 2961 | */ |
| 2962 | protected OnCreateContextMenuListener mOnCreateContextMenuListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2964 | private OnKeyListener mOnKeyListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2966 | private OnTouchListener mOnTouchListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2967 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2968 | private OnHoverListener mOnHoverListener; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2969 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2970 | private OnGenericMotionListener mOnGenericMotionListener; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2971 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2972 | private OnDragListener mOnDragListener; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 2973 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 2974 | private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener; |
| 2975 | } |
| 2976 | |
| 2977 | ListenerInfo mListenerInfo; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | /** |
| 2980 | * The application environment this view lives in. |
| 2981 | * This field should be made private, so it is hidden from the SDK. |
| 2982 | * {@hide} |
| 2983 | */ |
| 2984 | protected Context mContext; |
| 2985 | |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 2986 | private final Resources mResources; |
| 2987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | private ScrollabilityCache mScrollCache; |
| 2989 | |
| 2990 | private int[] mDrawableState = null; |
| 2991 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2992 | /** |
| 2993 | * Set to true when drawing cache is enabled and cannot be created. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 2994 | * |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 2995 | * @hide |
| 2996 | */ |
| 2997 | public boolean mCachingFailed; |
| 2998 | |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 2999 | private Bitmap mDrawingCache; |
| 3000 | private Bitmap mUnscaledDrawingCache; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 3001 | private HardwareLayer mHardwareLayer; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 3002 | DisplayList mDisplayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3003 | |
| 3004 | /** |
| 3005 | * When this view has focus and the next focus is {@link #FOCUS_LEFT}, |
| 3006 | * the user may specify which view to go to next. |
| 3007 | */ |
| 3008 | private int mNextFocusLeftId = View.NO_ID; |
| 3009 | |
| 3010 | /** |
| 3011 | * When this view has focus and the next focus is {@link #FOCUS_RIGHT}, |
| 3012 | * the user may specify which view to go to next. |
| 3013 | */ |
| 3014 | private int mNextFocusRightId = View.NO_ID; |
| 3015 | |
| 3016 | /** |
| 3017 | * When this view has focus and the next focus is {@link #FOCUS_UP}, |
| 3018 | * the user may specify which view to go to next. |
| 3019 | */ |
| 3020 | private int mNextFocusUpId = View.NO_ID; |
| 3021 | |
| 3022 | /** |
| 3023 | * When this view has focus and the next focus is {@link #FOCUS_DOWN}, |
| 3024 | * the user may specify which view to go to next. |
| 3025 | */ |
| 3026 | private int mNextFocusDownId = View.NO_ID; |
| 3027 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3028 | /** |
| 3029 | * When this view has focus and the next focus is {@link #FOCUS_FORWARD}, |
| 3030 | * the user may specify which view to go to next. |
| 3031 | */ |
| 3032 | int mNextFocusForwardId = View.NO_ID; |
| 3033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | private CheckForLongPress mPendingCheckForLongPress; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3035 | private CheckForTap mPendingCheckForTap = null; |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 3036 | private PerformClick mPerformClick; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 3037 | private SendViewScrolledAccessibilityEvent mSendViewScrolledAccessibilityEvent; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3039 | private UnsetPressedState mUnsetPressedState; |
| 3040 | |
| 3041 | /** |
| 3042 | * Whether the long press's action has been invoked. The tap's action is invoked on the |
| 3043 | * up event while a long press is invoked as soon as the long press duration is reached, so |
| 3044 | * a long press could be performed before the tap is checked, in which case the tap's action |
| 3045 | * should not be invoked. |
| 3046 | */ |
| 3047 | private boolean mHasPerformedLongPress; |
| 3048 | |
| 3049 | /** |
| 3050 | * The minimum height of the view. We'll try our best to have the height |
| 3051 | * of this view to at least this amount. |
| 3052 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3053 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | private int mMinHeight; |
| 3055 | |
| 3056 | /** |
| 3057 | * The minimum width of the view. We'll try our best to have the width |
| 3058 | * of this view to at least this amount. |
| 3059 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 3060 | @ViewDebug.ExportedProperty(category = "measurement") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | private int mMinWidth; |
| 3062 | |
| 3063 | /** |
| 3064 | * The delegate to handle touch events that are physically in this view |
| 3065 | * but should be handled by another view. |
| 3066 | */ |
| 3067 | private TouchDelegate mTouchDelegate = null; |
| 3068 | |
| 3069 | /** |
| 3070 | * Solid color to use as a background when creating the drawing cache. Enables |
| 3071 | * the cache to use 16 bit bitmaps instead of 32 bit. |
| 3072 | */ |
| 3073 | private int mDrawingCacheBackgroundColor = 0; |
| 3074 | |
| 3075 | /** |
| 3076 | * Special tree observer used when mAttachInfo is null. |
| 3077 | */ |
| 3078 | private ViewTreeObserver mFloatingTreeObserver; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3079 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3080 | /** |
| 3081 | * Cache the touch slop from the context that created the view. |
| 3082 | */ |
| 3083 | private int mTouchSlop; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 3086 | * Object that handles automatic animation of view properties. |
| 3087 | */ |
| 3088 | private ViewPropertyAnimator mAnimator = null; |
| 3089 | |
| 3090 | /** |
Christopher Tate | 251602f | 2011-01-28 17:54:12 -0800 | [diff] [blame] | 3091 | * Flag indicating that a drag can cross window boundaries. When |
| 3092 | * {@link #startDrag(ClipData, DragShadowBuilder, Object, int)} is called |
| 3093 | * with this flag set, all visible applications will be able to participate |
| 3094 | * in the drag operation and receive the dragged content. |
Christopher Tate | 7f9ff9d | 2011-02-14 17:31:13 -0800 | [diff] [blame] | 3095 | * |
| 3096 | * @hide |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 3097 | */ |
| 3098 | public static final int DRAG_FLAG_GLOBAL = 1; |
| 3099 | |
| 3100 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3101 | * Vertical scroll factor cached by {@link #getVerticalScrollFactor}. |
| 3102 | */ |
| 3103 | private float mVerticalScrollFactor; |
| 3104 | |
| 3105 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3106 | * Position of the vertical scroll bar. |
| 3107 | */ |
| 3108 | private int mVerticalScrollbarPosition; |
| 3109 | |
| 3110 | /** |
| 3111 | * Position the scroll bar at the default position as determined by the system. |
| 3112 | */ |
| 3113 | public static final int SCROLLBAR_POSITION_DEFAULT = 0; |
| 3114 | |
| 3115 | /** |
| 3116 | * Position the scroll bar along the left edge. |
| 3117 | */ |
| 3118 | public static final int SCROLLBAR_POSITION_LEFT = 1; |
| 3119 | |
| 3120 | /** |
| 3121 | * Position the scroll bar along the right edge. |
| 3122 | */ |
| 3123 | public static final int SCROLLBAR_POSITION_RIGHT = 2; |
| 3124 | |
| 3125 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3126 | * Indicates that the view does not have a layer. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3127 | * |
| 3128 | * @see #getLayerType() |
| 3129 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3130 | * @see #LAYER_TYPE_SOFTWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3131 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3132 | */ |
| 3133 | public static final int LAYER_TYPE_NONE = 0; |
| 3134 | |
| 3135 | /** |
| 3136 | * <p>Indicates that the view has a software layer. A software layer is backed |
| 3137 | * by a bitmap and causes the view to be rendered using Android's software |
| 3138 | * rendering pipeline, even if hardware acceleration is enabled.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3139 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3140 | * <p>Software layers have various usages:</p> |
| 3141 | * <p>When the application is not using hardware acceleration, a software layer |
| 3142 | * is useful to apply a specific color filter and/or blending mode and/or |
| 3143 | * translucency to a view and all its children.</p> |
| 3144 | * <p>When the application is using hardware acceleration, a software layer |
| 3145 | * is useful to render drawing primitives not supported by the hardware |
| 3146 | * accelerated pipeline. It can also be used to cache a complex view tree |
| 3147 | * into a texture and reduce the complexity of drawing operations. For instance, |
| 3148 | * when animating a complex view tree with a translation, a software layer can |
| 3149 | * be used to render the view tree only once.</p> |
| 3150 | * <p>Software layers should be avoided when the affected view tree updates |
| 3151 | * often. Every update will require to re-render the software layer, which can |
| 3152 | * potentially be slow (particularly when hardware acceleration is turned on |
| 3153 | * since the layer will have to be uploaded into a hardware texture after every |
| 3154 | * update.)</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3155 | * |
| 3156 | * @see #getLayerType() |
| 3157 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3158 | * @see #LAYER_TYPE_NONE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3159 | * @see #LAYER_TYPE_HARDWARE |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3160 | */ |
| 3161 | public static final int LAYER_TYPE_SOFTWARE = 1; |
| 3162 | |
| 3163 | /** |
| 3164 | * <p>Indicates that the view has a hardware layer. A hardware layer is backed |
| 3165 | * by a hardware specific texture (generally Frame Buffer Objects or FBO on |
| 3166 | * OpenGL hardware) and causes the view to be rendered using Android's hardware |
| 3167 | * rendering pipeline, but only if hardware acceleration is turned on for the |
| 3168 | * view hierarchy. When hardware acceleration is turned off, hardware layers |
| 3169 | * behave exactly as {@link #LAYER_TYPE_SOFTWARE software layers}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3170 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3171 | * <p>A hardware layer is useful to apply a specific color filter and/or |
| 3172 | * 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] | 3173 | * <p>A hardware layer can be used to cache a complex view tree into a |
| 3174 | * texture and reduce the complexity of drawing operations. For instance, |
| 3175 | * when animating a complex view tree with a translation, a hardware layer can |
| 3176 | * be used to render the view tree only once.</p> |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3177 | * <p>A hardware layer can also be used to increase the rendering quality when |
| 3178 | * rotation transformations are applied on a view. It can also be used to |
| 3179 | * prevent potential clipping issues when applying 3D transforms on a view.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3180 | * |
| 3181 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3182 | * @see #setLayerType(int, android.graphics.Paint) |
| 3183 | * @see #LAYER_TYPE_NONE |
| 3184 | * @see #LAYER_TYPE_SOFTWARE |
| 3185 | */ |
| 3186 | public static final int LAYER_TYPE_HARDWARE = 2; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3187 | |
Romain Guy | 3aaff3a | 2011-01-12 14:18:47 -0800 | [diff] [blame] | 3188 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
| 3189 | @ViewDebug.IntToString(from = LAYER_TYPE_NONE, to = "NONE"), |
| 3190 | @ViewDebug.IntToString(from = LAYER_TYPE_SOFTWARE, to = "SOFTWARE"), |
| 3191 | @ViewDebug.IntToString(from = LAYER_TYPE_HARDWARE, to = "HARDWARE") |
| 3192 | }) |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3193 | int mLayerType = LAYER_TYPE_NONE; |
| 3194 | Paint mLayerPaint; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 3195 | Rect mLocalDirtyRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3196 | |
| 3197 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3198 | * Set to true when the view is sending hover accessibility events because it |
| 3199 | * is the innermost hovered view. |
| 3200 | */ |
| 3201 | private boolean mSendingHoverAccessibilityEvents; |
| 3202 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3203 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 3204 | * Delegate for injecting accessibility functionality. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3205 | */ |
| 3206 | AccessibilityDelegate mAccessibilityDelegate; |
| 3207 | |
| 3208 | /** |
| 3209 | * Consistency verifier for debugging purposes. |
| 3210 | * @hide |
| 3211 | */ |
| 3212 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 3213 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 3214 | new InputEventConsistencyVerifier(this, 0) : null; |
| 3215 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 3216 | private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1); |
| 3217 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 3218 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | * Simple constructor to use when creating a view from code. |
| 3220 | * |
| 3221 | * @param context The Context the view is running in, through which it can |
| 3222 | * access the current theme, resources, etc. |
| 3223 | */ |
| 3224 | public View(Context context) { |
| 3225 | mContext = context; |
| 3226 | mResources = context != null ? context.getResources() : null; |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3227 | mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED; |
Fabrice Di Meglio | 72898e9 | 2012-10-25 11:22:39 -0700 | [diff] [blame] | 3228 | // Set some flags defaults |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3229 | mPrivateFlags2 = |
| 3230 | (LAYOUT_DIRECTION_DEFAULT << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3231 | (TEXT_DIRECTION_DEFAULT << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3232 | (PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3233 | (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3234 | (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3235 | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 3236 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3237 | setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3238 | mUserPaddingStart = UNDEFINED_PADDING; |
| 3239 | mUserPaddingEnd = UNDEFINED_PADDING; |
Adam Powell | 7da4b73 | 2012-12-07 15:28:33 -0800 | [diff] [blame] | 3240 | |
| 3241 | if (!sUseBrokenMakeMeasureSpec && context.getApplicationInfo().targetSdkVersion <= |
| 3242 | Build.VERSION_CODES.JELLY_BEAN_MR1 ) { |
| 3243 | // Older apps may need this compatibility hack for measurement. |
| 3244 | sUseBrokenMakeMeasureSpec = true; |
| 3245 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | /** |
| 3249 | * Constructor that is called when inflating a view from XML. This is called |
| 3250 | * when a view is being constructed from an XML file, supplying attributes |
| 3251 | * that were specified in the XML file. This version uses a default style of |
| 3252 | * 0, so the only attribute values applied are those in the Context's Theme |
| 3253 | * and the given AttributeSet. |
| 3254 | * |
| 3255 | * <p> |
| 3256 | * The method onFinishInflate() will be called after all children have been |
| 3257 | * added. |
| 3258 | * |
| 3259 | * @param context The Context the view is running in, through which it can |
| 3260 | * access the current theme, resources, etc. |
| 3261 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3262 | * @see #View(Context, AttributeSet, int) |
| 3263 | */ |
| 3264 | public View(Context context, AttributeSet attrs) { |
| 3265 | this(context, attrs, 0); |
| 3266 | } |
| 3267 | |
| 3268 | /** |
| 3269 | * Perform inflation from XML and apply a class-specific base style. This |
| 3270 | * constructor of View allows subclasses to use their own base style when |
| 3271 | * they are inflating. For example, a Button class's constructor would call |
| 3272 | * this version of the super class constructor and supply |
| 3273 | * <code>R.attr.buttonStyle</code> for <var>defStyle</var>; this allows |
| 3274 | * the theme's button style to modify all of the base view attributes (in |
| 3275 | * particular its background) as well as the Button class's attributes. |
| 3276 | * |
| 3277 | * @param context The Context the view is running in, through which it can |
| 3278 | * access the current theme, resources, etc. |
| 3279 | * @param attrs The attributes of the XML tag that is inflating the view. |
| 3280 | * @param defStyle The default style to apply to this view. If 0, no style |
| 3281 | * will be applied (beyond what is included in the theme). This may |
| 3282 | * either be an attribute resource, whose value will be retrieved |
| 3283 | * from the current theme, or an explicit style resource. |
| 3284 | * @see #View(Context, AttributeSet) |
| 3285 | */ |
| 3286 | public View(Context context, AttributeSet attrs, int defStyle) { |
| 3287 | this(context); |
| 3288 | |
| 3289 | TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.View, |
| 3290 | defStyle, 0); |
| 3291 | |
| 3292 | Drawable background = null; |
| 3293 | |
| 3294 | int leftPadding = -1; |
| 3295 | int topPadding = -1; |
| 3296 | int rightPadding = -1; |
| 3297 | int bottomPadding = -1; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3298 | int startPadding = UNDEFINED_PADDING; |
| 3299 | int endPadding = UNDEFINED_PADDING; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | |
| 3301 | int padding = -1; |
| 3302 | |
| 3303 | int viewFlagValues = 0; |
| 3304 | int viewFlagMasks = 0; |
| 3305 | |
| 3306 | boolean setScrollContainer = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | int x = 0; |
| 3309 | int y = 0; |
| 3310 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3311 | float tx = 0; |
| 3312 | float ty = 0; |
| 3313 | float rotation = 0; |
| 3314 | float rotationX = 0; |
| 3315 | float rotationY = 0; |
| 3316 | float sx = 1f; |
| 3317 | float sy = 1f; |
| 3318 | boolean transformSet = false; |
| 3319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | int scrollbarStyle = SCROLLBARS_INSIDE_OVERLAY; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3321 | int overScrollMode = mOverScrollMode; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3322 | boolean initializeScrollbars = false; |
| 3323 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3324 | boolean leftPaddingDefined = false; |
| 3325 | boolean rightPaddingDefined = false; |
| 3326 | boolean startPaddingDefined = false; |
| 3327 | boolean endPaddingDefined = false; |
| 3328 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3329 | final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
| 3330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | final int N = a.getIndexCount(); |
| 3332 | for (int i = 0; i < N; i++) { |
| 3333 | int attr = a.getIndex(i); |
| 3334 | switch (attr) { |
| 3335 | case com.android.internal.R.styleable.View_background: |
| 3336 | background = a.getDrawable(attr); |
| 3337 | break; |
| 3338 | case com.android.internal.R.styleable.View_padding: |
| 3339 | padding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3340 | mUserPaddingLeftInitial = padding; |
| 3341 | mUserPaddingRightInitial = padding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3342 | leftPaddingDefined = true; |
| 3343 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | break; |
| 3345 | case com.android.internal.R.styleable.View_paddingLeft: |
| 3346 | leftPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3347 | mUserPaddingLeftInitial = leftPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3348 | leftPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | break; |
| 3350 | case com.android.internal.R.styleable.View_paddingTop: |
| 3351 | topPadding = a.getDimensionPixelSize(attr, -1); |
| 3352 | break; |
| 3353 | case com.android.internal.R.styleable.View_paddingRight: |
| 3354 | rightPadding = a.getDimensionPixelSize(attr, -1); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3355 | mUserPaddingRightInitial = rightPadding; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3356 | rightPaddingDefined = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3357 | break; |
| 3358 | case com.android.internal.R.styleable.View_paddingBottom: |
| 3359 | bottomPadding = a.getDimensionPixelSize(attr, -1); |
| 3360 | break; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3361 | case com.android.internal.R.styleable.View_paddingStart: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3362 | startPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3363 | startPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3364 | break; |
| 3365 | case com.android.internal.R.styleable.View_paddingEnd: |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3366 | endPadding = a.getDimensionPixelSize(attr, UNDEFINED_PADDING); |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3367 | endPaddingDefined = true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 3368 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | case com.android.internal.R.styleable.View_scrollX: |
| 3370 | x = a.getDimensionPixelOffset(attr, 0); |
| 3371 | break; |
| 3372 | case com.android.internal.R.styleable.View_scrollY: |
| 3373 | y = a.getDimensionPixelOffset(attr, 0); |
| 3374 | break; |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3375 | case com.android.internal.R.styleable.View_alpha: |
| 3376 | setAlpha(a.getFloat(attr, 1f)); |
| 3377 | break; |
| 3378 | case com.android.internal.R.styleable.View_transformPivotX: |
| 3379 | setPivotX(a.getDimensionPixelOffset(attr, 0)); |
| 3380 | break; |
| 3381 | case com.android.internal.R.styleable.View_transformPivotY: |
| 3382 | setPivotY(a.getDimensionPixelOffset(attr, 0)); |
| 3383 | break; |
| 3384 | case com.android.internal.R.styleable.View_translationX: |
| 3385 | tx = a.getDimensionPixelOffset(attr, 0); |
| 3386 | transformSet = true; |
| 3387 | break; |
| 3388 | case com.android.internal.R.styleable.View_translationY: |
| 3389 | ty = a.getDimensionPixelOffset(attr, 0); |
| 3390 | transformSet = true; |
| 3391 | break; |
| 3392 | case com.android.internal.R.styleable.View_rotation: |
| 3393 | rotation = a.getFloat(attr, 0); |
| 3394 | transformSet = true; |
| 3395 | break; |
| 3396 | case com.android.internal.R.styleable.View_rotationX: |
| 3397 | rotationX = a.getFloat(attr, 0); |
| 3398 | transformSet = true; |
| 3399 | break; |
| 3400 | case com.android.internal.R.styleable.View_rotationY: |
| 3401 | rotationY = a.getFloat(attr, 0); |
| 3402 | transformSet = true; |
| 3403 | break; |
| 3404 | case com.android.internal.R.styleable.View_scaleX: |
| 3405 | sx = a.getFloat(attr, 1f); |
| 3406 | transformSet = true; |
| 3407 | break; |
| 3408 | case com.android.internal.R.styleable.View_scaleY: |
| 3409 | sy = a.getFloat(attr, 1f); |
| 3410 | transformSet = true; |
| 3411 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | case com.android.internal.R.styleable.View_id: |
| 3413 | mID = a.getResourceId(attr, NO_ID); |
| 3414 | break; |
| 3415 | case com.android.internal.R.styleable.View_tag: |
| 3416 | mTag = a.getText(attr); |
| 3417 | break; |
| 3418 | case com.android.internal.R.styleable.View_fitsSystemWindows: |
| 3419 | if (a.getBoolean(attr, false)) { |
| 3420 | viewFlagValues |= FITS_SYSTEM_WINDOWS; |
| 3421 | viewFlagMasks |= FITS_SYSTEM_WINDOWS; |
| 3422 | } |
| 3423 | break; |
| 3424 | case com.android.internal.R.styleable.View_focusable: |
| 3425 | if (a.getBoolean(attr, false)) { |
| 3426 | viewFlagValues |= FOCUSABLE; |
| 3427 | viewFlagMasks |= FOCUSABLE_MASK; |
| 3428 | } |
| 3429 | break; |
| 3430 | case com.android.internal.R.styleable.View_focusableInTouchMode: |
| 3431 | if (a.getBoolean(attr, false)) { |
| 3432 | viewFlagValues |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE; |
| 3433 | viewFlagMasks |= FOCUSABLE_IN_TOUCH_MODE | FOCUSABLE_MASK; |
| 3434 | } |
| 3435 | break; |
| 3436 | case com.android.internal.R.styleable.View_clickable: |
| 3437 | if (a.getBoolean(attr, false)) { |
| 3438 | viewFlagValues |= CLICKABLE; |
| 3439 | viewFlagMasks |= CLICKABLE; |
| 3440 | } |
| 3441 | break; |
| 3442 | case com.android.internal.R.styleable.View_longClickable: |
| 3443 | if (a.getBoolean(attr, false)) { |
| 3444 | viewFlagValues |= LONG_CLICKABLE; |
| 3445 | viewFlagMasks |= LONG_CLICKABLE; |
| 3446 | } |
| 3447 | break; |
| 3448 | case com.android.internal.R.styleable.View_saveEnabled: |
| 3449 | if (!a.getBoolean(attr, true)) { |
| 3450 | viewFlagValues |= SAVE_DISABLED; |
| 3451 | viewFlagMasks |= SAVE_DISABLED_MASK; |
| 3452 | } |
| 3453 | break; |
| 3454 | case com.android.internal.R.styleable.View_duplicateParentState: |
| 3455 | if (a.getBoolean(attr, false)) { |
| 3456 | viewFlagValues |= DUPLICATE_PARENT_STATE; |
| 3457 | viewFlagMasks |= DUPLICATE_PARENT_STATE; |
| 3458 | } |
| 3459 | break; |
| 3460 | case com.android.internal.R.styleable.View_visibility: |
| 3461 | final int visibility = a.getInt(attr, 0); |
| 3462 | if (visibility != 0) { |
| 3463 | viewFlagValues |= VISIBILITY_FLAGS[visibility]; |
| 3464 | viewFlagMasks |= VISIBILITY_MASK; |
| 3465 | } |
| 3466 | break; |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 3467 | case com.android.internal.R.styleable.View_layoutDirection: |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3468 | // Clear any layout direction flags (included resolved bits) already set |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 3469 | mPrivateFlags2 &= |
| 3470 | ~(PFLAG2_LAYOUT_DIRECTION_MASK | PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3471 | // 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] | 3472 | final int layoutDirection = a.getInt(attr, -1); |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 3473 | final int value = (layoutDirection != -1) ? |
| 3474 | LAYOUT_DIRECTION_FLAGS[layoutDirection] : LAYOUT_DIRECTION_DEFAULT; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3475 | mPrivateFlags2 |= (value << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT); |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 3476 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | case com.android.internal.R.styleable.View_drawingCacheQuality: |
| 3478 | final int cacheQuality = a.getInt(attr, 0); |
| 3479 | if (cacheQuality != 0) { |
| 3480 | viewFlagValues |= DRAWING_CACHE_QUALITY_FLAGS[cacheQuality]; |
| 3481 | viewFlagMasks |= DRAWING_CACHE_QUALITY_MASK; |
| 3482 | } |
| 3483 | break; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3484 | case com.android.internal.R.styleable.View_contentDescription: |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 3485 | setContentDescription(a.getString(attr)); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3486 | break; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 3487 | case com.android.internal.R.styleable.View_labelFor: |
| 3488 | setLabelFor(a.getResourceId(attr, NO_ID)); |
| 3489 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | case com.android.internal.R.styleable.View_soundEffectsEnabled: |
| 3491 | if (!a.getBoolean(attr, true)) { |
| 3492 | viewFlagValues &= ~SOUND_EFFECTS_ENABLED; |
| 3493 | viewFlagMasks |= SOUND_EFFECTS_ENABLED; |
| 3494 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3495 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | case com.android.internal.R.styleable.View_hapticFeedbackEnabled: |
| 3497 | if (!a.getBoolean(attr, true)) { |
| 3498 | viewFlagValues &= ~HAPTIC_FEEDBACK_ENABLED; |
| 3499 | viewFlagMasks |= HAPTIC_FEEDBACK_ENABLED; |
| 3500 | } |
Karl Rosaen | 61ab270 | 2009-06-23 11:10:25 -0700 | [diff] [blame] | 3501 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | case R.styleable.View_scrollbars: |
| 3503 | final int scrollbars = a.getInt(attr, SCROLLBARS_NONE); |
| 3504 | if (scrollbars != SCROLLBARS_NONE) { |
| 3505 | viewFlagValues |= scrollbars; |
| 3506 | viewFlagMasks |= SCROLLBARS_MASK; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3507 | initializeScrollbars = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | } |
| 3509 | break; |
Romain Guy | 2a9fa89 | 2011-09-28 16:50:02 -0700 | [diff] [blame] | 3510 | //noinspection deprecation |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | case R.styleable.View_fadingEdge: |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3512 | if (targetSdkVersion >= ICE_CREAM_SANDWICH) { |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 3513 | // Ignore the attribute starting with ICS |
| 3514 | break; |
| 3515 | } |
| 3516 | // With builds < ICS, fall through and apply fading edges |
| 3517 | case R.styleable.View_requiresFadingEdge: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | final int fadingEdge = a.getInt(attr, FADING_EDGE_NONE); |
| 3519 | if (fadingEdge != FADING_EDGE_NONE) { |
| 3520 | viewFlagValues |= fadingEdge; |
| 3521 | viewFlagMasks |= FADING_EDGE_MASK; |
| 3522 | initializeFadingEdge(a); |
| 3523 | } |
| 3524 | break; |
| 3525 | case R.styleable.View_scrollbarStyle: |
| 3526 | scrollbarStyle = a.getInt(attr, SCROLLBARS_INSIDE_OVERLAY); |
| 3527 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3528 | viewFlagValues |= scrollbarStyle & SCROLLBARS_STYLE_MASK; |
| 3529 | viewFlagMasks |= SCROLLBARS_STYLE_MASK; |
| 3530 | } |
| 3531 | break; |
| 3532 | case R.styleable.View_isScrollContainer: |
| 3533 | setScrollContainer = true; |
| 3534 | if (a.getBoolean(attr, false)) { |
| 3535 | setScrollContainer(true); |
| 3536 | } |
| 3537 | break; |
| 3538 | case com.android.internal.R.styleable.View_keepScreenOn: |
| 3539 | if (a.getBoolean(attr, false)) { |
| 3540 | viewFlagValues |= KEEP_SCREEN_ON; |
| 3541 | viewFlagMasks |= KEEP_SCREEN_ON; |
| 3542 | } |
| 3543 | break; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 3544 | case R.styleable.View_filterTouchesWhenObscured: |
| 3545 | if (a.getBoolean(attr, false)) { |
| 3546 | viewFlagValues |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3547 | viewFlagMasks |= FILTER_TOUCHES_WHEN_OBSCURED; |
| 3548 | } |
| 3549 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | case R.styleable.View_nextFocusLeft: |
| 3551 | mNextFocusLeftId = a.getResourceId(attr, View.NO_ID); |
| 3552 | break; |
| 3553 | case R.styleable.View_nextFocusRight: |
| 3554 | mNextFocusRightId = a.getResourceId(attr, View.NO_ID); |
| 3555 | break; |
| 3556 | case R.styleable.View_nextFocusUp: |
| 3557 | mNextFocusUpId = a.getResourceId(attr, View.NO_ID); |
| 3558 | break; |
| 3559 | case R.styleable.View_nextFocusDown: |
| 3560 | mNextFocusDownId = a.getResourceId(attr, View.NO_ID); |
| 3561 | break; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 3562 | case R.styleable.View_nextFocusForward: |
| 3563 | mNextFocusForwardId = a.getResourceId(attr, View.NO_ID); |
| 3564 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | case R.styleable.View_minWidth: |
| 3566 | mMinWidth = a.getDimensionPixelSize(attr, 0); |
| 3567 | break; |
| 3568 | case R.styleable.View_minHeight: |
| 3569 | mMinHeight = a.getDimensionPixelSize(attr, 0); |
| 3570 | break; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3571 | case R.styleable.View_onClick: |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3572 | if (context.isRestricted()) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3573 | throw new IllegalStateException("The android:onClick attribute cannot " |
Romain Guy | 870e09f | 2009-07-06 16:35:25 -0700 | [diff] [blame] | 3574 | + "be used within a restricted context"); |
| 3575 | } |
| 3576 | |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3577 | final String handlerName = a.getString(attr); |
| 3578 | if (handlerName != null) { |
| 3579 | setOnClickListener(new OnClickListener() { |
| 3580 | private Method mHandler; |
| 3581 | |
| 3582 | public void onClick(View v) { |
| 3583 | if (mHandler == null) { |
| 3584 | try { |
| 3585 | mHandler = getContext().getClass().getMethod(handlerName, |
| 3586 | View.class); |
| 3587 | } catch (NoSuchMethodException e) { |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3588 | int id = getId(); |
| 3589 | String idText = id == NO_ID ? "" : " with id '" |
| 3590 | + getContext().getResources().getResourceEntryName( |
| 3591 | id) + "'"; |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3592 | throw new IllegalStateException("Could not find a method " + |
Joe Onorato | 42e14d7 | 2010-03-11 14:51:17 -0800 | [diff] [blame] | 3593 | handlerName + "(View) in the activity " |
| 3594 | + getContext().getClass() + " for onClick handler" |
| 3595 | + " on view " + View.this.getClass() + idText, e); |
Romain Guy | 9a81736 | 2009-05-01 10:57:14 -0700 | [diff] [blame] | 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | try { |
| 3600 | mHandler.invoke(getContext(), View.this); |
| 3601 | } catch (IllegalAccessException e) { |
| 3602 | throw new IllegalStateException("Could not execute non " |
| 3603 | + "public method of the activity", e); |
| 3604 | } catch (InvocationTargetException e) { |
| 3605 | throw new IllegalStateException("Could not execute " |
| 3606 | + "method of the activity", e); |
| 3607 | } |
| 3608 | } |
| 3609 | }); |
| 3610 | } |
| 3611 | break; |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3612 | case R.styleable.View_overScrollMode: |
| 3613 | overScrollMode = a.getInt(attr, OVER_SCROLL_IF_CONTENT_SCROLLS); |
| 3614 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 3615 | case R.styleable.View_verticalScrollbarPosition: |
| 3616 | mVerticalScrollbarPosition = a.getInt(attr, SCROLLBAR_POSITION_DEFAULT); |
| 3617 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 3618 | case R.styleable.View_layerType: |
| 3619 | setLayerType(a.getInt(attr, LAYER_TYPE_NONE), null); |
| 3620 | break; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3621 | case R.styleable.View_textDirection: |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3622 | // Clear any text direction flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3623 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3624 | // Set the text direction flags depending on the value of the attribute |
| 3625 | final int textDirection = a.getInt(attr, -1); |
| 3626 | if (textDirection != -1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3627 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_FLAGS[textDirection]; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 3628 | } |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 3629 | break; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3630 | case R.styleable.View_textAlignment: |
| 3631 | // Clear any text alignment flag already set |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3632 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3633 | // Set the text alignment flag depending on the value of the attribute |
| 3634 | final int textAlignment = a.getInt(attr, TEXT_ALIGNMENT_DEFAULT); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3635 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_FLAGS[textAlignment]; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 3636 | break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3637 | case R.styleable.View_importantForAccessibility: |
| 3638 | setImportantForAccessibility(a.getInt(attr, |
| 3639 | IMPORTANT_FOR_ACCESSIBILITY_DEFAULT)); |
Svetoslav Ganov | 8678347 | 2012-06-06 21:12:20 -0700 | [diff] [blame] | 3640 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } |
| 3642 | } |
| 3643 | |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 3644 | setOverScrollMode(overScrollMode); |
| 3645 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3646 | // Cache start/end user padding as we cannot fully resolve padding here (we dont have yet |
| 3647 | // the resolved layout direction). Those cached values will be used later during padding |
| 3648 | // resolution. |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 3649 | mUserPaddingStart = startPadding; |
| 3650 | mUserPaddingEnd = endPadding; |
| 3651 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 3652 | if (background != null) { |
| 3653 | setBackground(background); |
| 3654 | } |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 3655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | if (padding >= 0) { |
| 3657 | leftPadding = padding; |
| 3658 | topPadding = padding; |
| 3659 | rightPadding = padding; |
| 3660 | bottomPadding = padding; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 3661 | mUserPaddingLeftInitial = padding; |
| 3662 | mUserPaddingRightInitial = padding; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3665 | if (isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3666 | // RTL compatibility mode: pre Jelly Bean MR1 case OR no RTL support case. |
| 3667 | // left / right padding are used if defined (meaning here nothing to do). If they are not |
| 3668 | // defined and start / end padding are defined (e.g. in Frameworks resources), then we use |
| 3669 | // start / end and resolve them as left / right (layout direction is not taken into account). |
| 3670 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3671 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3672 | // defined. |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3673 | if (!leftPaddingDefined && startPaddingDefined) { |
| 3674 | leftPadding = startPadding; |
| 3675 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3676 | mUserPaddingLeftInitial = (leftPadding >= 0) ? leftPadding : mUserPaddingLeftInitial; |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3677 | if (!rightPaddingDefined && endPaddingDefined) { |
| 3678 | rightPadding = endPadding; |
| 3679 | } |
Fabrice Di Meglio | 6e6d781 | 2012-10-01 15:32:01 -0700 | [diff] [blame] | 3680 | mUserPaddingRightInitial = (rightPadding >= 0) ? rightPadding : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3681 | } else { |
| 3682 | // Jelly Bean MR1 and after case: if start/end defined, they will override any left/right |
| 3683 | // values defined. Otherwise, left /right values are used. |
| 3684 | // Padding from the background drawable is stored at this point in mUserPaddingLeftInitial |
| 3685 | // and mUserPaddingRightInitial) so drawable padding will be used as ultimate default if |
| 3686 | // defined. |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 3687 | if (leftPaddingDefined) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3688 | mUserPaddingLeftInitial = leftPadding; |
| 3689 | } |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 3690 | if (rightPaddingDefined) { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 3691 | mUserPaddingRightInitial = rightPadding; |
| 3692 | } |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
Fabrice Di Meglio | 3e27c34 | 2012-09-20 17:56:58 -0700 | [diff] [blame] | 3695 | internalSetPadding( |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3696 | mUserPaddingLeftInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3697 | topPadding >= 0 ? topPadding : mPaddingTop, |
Fabrice Di Meglio | 75aefb8 | 2012-09-27 19:55:18 -0700 | [diff] [blame] | 3698 | mUserPaddingRightInitial, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | bottomPadding >= 0 ? bottomPadding : mPaddingBottom); |
| 3700 | |
| 3701 | if (viewFlagMasks != 0) { |
| 3702 | setFlags(viewFlagValues, viewFlagMasks); |
| 3703 | } |
| 3704 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3705 | if (initializeScrollbars) { |
| 3706 | initializeScrollbars(a); |
| 3707 | } |
| 3708 | |
| 3709 | a.recycle(); |
| 3710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | // Needs to be called after mViewFlags is set |
| 3712 | if (scrollbarStyle != SCROLLBARS_INSIDE_OVERLAY) { |
| 3713 | recomputePadding(); |
| 3714 | } |
| 3715 | |
| 3716 | if (x != 0 || y != 0) { |
| 3717 | scrollTo(x, y); |
| 3718 | } |
| 3719 | |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 3720 | if (transformSet) { |
| 3721 | setTranslationX(tx); |
| 3722 | setTranslationY(ty); |
| 3723 | setRotation(rotation); |
| 3724 | setRotationX(rotationX); |
| 3725 | setRotationY(rotationY); |
| 3726 | setScaleX(sx); |
| 3727 | setScaleY(sy); |
| 3728 | } |
| 3729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | if (!setScrollContainer && (viewFlagValues&SCROLLBARS_VERTICAL) != 0) { |
| 3731 | setScrollContainer(true); |
| 3732 | } |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 3733 | |
| 3734 | computeOpaqueFlags(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | /** |
| 3738 | * Non-public constructor for use in testing |
| 3739 | */ |
| 3740 | View() { |
Dianne Hackborn | ab0f485 | 2011-09-12 16:59:06 -0700 | [diff] [blame] | 3741 | mResources = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | } |
| 3743 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3744 | public String toString() { |
| 3745 | StringBuilder out = new StringBuilder(128); |
| 3746 | out.append(getClass().getName()); |
| 3747 | out.append('{'); |
| 3748 | out.append(Integer.toHexString(System.identityHashCode(this))); |
| 3749 | out.append(' '); |
| 3750 | switch (mViewFlags&VISIBILITY_MASK) { |
| 3751 | case VISIBLE: out.append('V'); break; |
| 3752 | case INVISIBLE: out.append('I'); break; |
| 3753 | case GONE: out.append('G'); break; |
| 3754 | default: out.append('.'); break; |
| 3755 | } |
| 3756 | out.append((mViewFlags&FOCUSABLE_MASK) == FOCUSABLE ? 'F' : '.'); |
| 3757 | out.append((mViewFlags&ENABLED_MASK) == ENABLED ? 'E' : '.'); |
| 3758 | out.append((mViewFlags&DRAW_MASK) == WILL_NOT_DRAW ? '.' : 'D'); |
| 3759 | out.append((mViewFlags&SCROLLBARS_HORIZONTAL) != 0 ? 'H' : '.'); |
| 3760 | out.append((mViewFlags&SCROLLBARS_VERTICAL) != 0 ? 'V' : '.'); |
| 3761 | out.append((mViewFlags&CLICKABLE) != 0 ? 'C' : '.'); |
| 3762 | out.append((mViewFlags&LONG_CLICKABLE) != 0 ? 'L' : '.'); |
| 3763 | out.append(' '); |
| 3764 | out.append((mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0 ? 'R' : '.'); |
| 3765 | out.append((mPrivateFlags&PFLAG_FOCUSED) != 0 ? 'F' : '.'); |
| 3766 | out.append((mPrivateFlags&PFLAG_SELECTED) != 0 ? 'S' : '.'); |
| 3767 | if ((mPrivateFlags&PFLAG_PREPRESSED) != 0) { |
| 3768 | out.append('p'); |
| 3769 | } else { |
| 3770 | out.append((mPrivateFlags&PFLAG_PRESSED) != 0 ? 'P' : '.'); |
| 3771 | } |
| 3772 | out.append((mPrivateFlags&PFLAG_HOVERED) != 0 ? 'H' : '.'); |
| 3773 | out.append((mPrivateFlags&PFLAG_ACTIVATED) != 0 ? 'A' : '.'); |
| 3774 | out.append((mPrivateFlags&PFLAG_INVALIDATED) != 0 ? 'I' : '.'); |
| 3775 | out.append((mPrivateFlags&PFLAG_DIRTY_MASK) != 0 ? 'D' : '.'); |
| 3776 | out.append(' '); |
| 3777 | out.append(mLeft); |
| 3778 | out.append(','); |
| 3779 | out.append(mTop); |
| 3780 | out.append('-'); |
| 3781 | out.append(mRight); |
| 3782 | out.append(','); |
| 3783 | out.append(mBottom); |
| 3784 | final int id = getId(); |
| 3785 | if (id != NO_ID) { |
| 3786 | out.append(" #"); |
| 3787 | out.append(Integer.toHexString(id)); |
| 3788 | final Resources r = mResources; |
| 3789 | if (id != 0 && r != null) { |
| 3790 | try { |
| 3791 | String pkgname; |
| 3792 | switch (id&0xff000000) { |
| 3793 | case 0x7f000000: |
| 3794 | pkgname="app"; |
| 3795 | break; |
| 3796 | case 0x01000000: |
| 3797 | pkgname="android"; |
| 3798 | break; |
| 3799 | default: |
| 3800 | pkgname = r.getResourcePackageName(id); |
| 3801 | break; |
| 3802 | } |
| 3803 | String typename = r.getResourceTypeName(id); |
| 3804 | String entryname = r.getResourceEntryName(id); |
| 3805 | out.append(" "); |
| 3806 | out.append(pkgname); |
| 3807 | out.append(":"); |
| 3808 | out.append(typename); |
| 3809 | out.append("/"); |
| 3810 | out.append(entryname); |
| 3811 | } catch (Resources.NotFoundException e) { |
| 3812 | } |
| 3813 | } |
| 3814 | } |
| 3815 | out.append("}"); |
| 3816 | return out.toString(); |
| 3817 | } |
| 3818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | /** |
| 3820 | * <p> |
| 3821 | * Initializes the fading edges from a given set of styled attributes. This |
| 3822 | * method should be called by subclasses that need fading edges and when an |
| 3823 | * instance of these subclasses is created programmatically rather than |
| 3824 | * being inflated from XML. This method is automatically called when the XML |
| 3825 | * is inflated. |
| 3826 | * </p> |
| 3827 | * |
| 3828 | * @param a the styled attributes set to initialize the fading edges from |
| 3829 | */ |
| 3830 | protected void initializeFadingEdge(TypedArray a) { |
| 3831 | initScrollCache(); |
| 3832 | |
| 3833 | mScrollCache.fadingEdgeLength = a.getDimensionPixelSize( |
| 3834 | R.styleable.View_fadingEdgeLength, |
| 3835 | ViewConfiguration.get(mContext).getScaledFadingEdgeLength()); |
| 3836 | } |
| 3837 | |
| 3838 | /** |
| 3839 | * Returns the size of the vertical faded edges used to indicate that more |
| 3840 | * content in this view is visible. |
| 3841 | * |
| 3842 | * @return The size in pixels of the vertical faded edge or 0 if vertical |
| 3843 | * faded edges are not enabled for this view. |
| 3844 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3845 | */ |
| 3846 | public int getVerticalFadingEdgeLength() { |
| 3847 | if (isVerticalFadingEdgeEnabled()) { |
| 3848 | ScrollabilityCache cache = mScrollCache; |
| 3849 | if (cache != null) { |
| 3850 | return cache.fadingEdgeLength; |
| 3851 | } |
| 3852 | } |
| 3853 | return 0; |
| 3854 | } |
| 3855 | |
| 3856 | /** |
| 3857 | * Set the size of the faded edge used to indicate that more content in this |
| 3858 | * 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] | 3859 | * {@link #setVerticalFadingEdgeEnabled(boolean)} or |
| 3860 | * {@link #setHorizontalFadingEdgeEnabled(boolean)} to enable the fading edge |
| 3861 | * for the vertical or horizontal fading edges. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | * |
| 3863 | * @param length The size in pixels of the faded edge used to indicate that more |
| 3864 | * content in this view is visible. |
| 3865 | */ |
| 3866 | public void setFadingEdgeLength(int length) { |
| 3867 | initScrollCache(); |
| 3868 | mScrollCache.fadingEdgeLength = length; |
| 3869 | } |
| 3870 | |
| 3871 | /** |
| 3872 | * Returns the size of the horizontal faded edges used to indicate that more |
| 3873 | * content in this view is visible. |
| 3874 | * |
| 3875 | * @return The size in pixels of the horizontal faded edge or 0 if horizontal |
| 3876 | * faded edges are not enabled for this view. |
| 3877 | * @attr ref android.R.styleable#View_fadingEdgeLength |
| 3878 | */ |
| 3879 | public int getHorizontalFadingEdgeLength() { |
| 3880 | if (isHorizontalFadingEdgeEnabled()) { |
| 3881 | ScrollabilityCache cache = mScrollCache; |
| 3882 | if (cache != null) { |
| 3883 | return cache.fadingEdgeLength; |
| 3884 | } |
| 3885 | } |
| 3886 | return 0; |
| 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Returns the width of the vertical scrollbar. |
| 3891 | * |
| 3892 | * @return The width in pixels of the vertical scrollbar or 0 if there |
| 3893 | * is no vertical scrollbar. |
| 3894 | */ |
| 3895 | public int getVerticalScrollbarWidth() { |
| 3896 | ScrollabilityCache cache = mScrollCache; |
| 3897 | if (cache != null) { |
| 3898 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3899 | if (scrollBar != null) { |
| 3900 | int size = scrollBar.getSize(true); |
| 3901 | if (size <= 0) { |
| 3902 | size = cache.scrollBarSize; |
| 3903 | } |
| 3904 | return size; |
| 3905 | } |
| 3906 | return 0; |
| 3907 | } |
| 3908 | return 0; |
| 3909 | } |
| 3910 | |
| 3911 | /** |
| 3912 | * Returns the height of the horizontal scrollbar. |
| 3913 | * |
| 3914 | * @return The height in pixels of the horizontal scrollbar or 0 if |
| 3915 | * there is no horizontal scrollbar. |
| 3916 | */ |
| 3917 | protected int getHorizontalScrollbarHeight() { |
| 3918 | ScrollabilityCache cache = mScrollCache; |
| 3919 | if (cache != null) { |
| 3920 | ScrollBarDrawable scrollBar = cache.scrollBar; |
| 3921 | if (scrollBar != null) { |
| 3922 | int size = scrollBar.getSize(false); |
| 3923 | if (size <= 0) { |
| 3924 | size = cache.scrollBarSize; |
| 3925 | } |
| 3926 | return size; |
| 3927 | } |
| 3928 | return 0; |
| 3929 | } |
| 3930 | return 0; |
| 3931 | } |
| 3932 | |
| 3933 | /** |
| 3934 | * <p> |
| 3935 | * Initializes the scrollbars from a given set of styled attributes. This |
| 3936 | * method should be called by subclasses that need scrollbars and when an |
| 3937 | * instance of these subclasses is created programmatically rather than |
| 3938 | * being inflated from XML. This method is automatically called when the XML |
| 3939 | * is inflated. |
| 3940 | * </p> |
| 3941 | * |
| 3942 | * @param a the styled attributes set to initialize the scrollbars from |
| 3943 | */ |
| 3944 | protected void initializeScrollbars(TypedArray a) { |
| 3945 | initScrollCache(); |
| 3946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3947 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3948 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3949 | if (scrollabilityCache.scrollBar == null) { |
| 3950 | scrollabilityCache.scrollBar = new ScrollBarDrawable(); |
| 3951 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3952 | |
Romain Guy | 8bda248 | 2010-03-02 11:42:11 -0800 | [diff] [blame] | 3953 | 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] | 3954 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3955 | if (!fadeScrollbars) { |
| 3956 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 3957 | } |
| 3958 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3959 | |
| 3960 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 3961 | scrollabilityCache.scrollBarFadeDuration = a.getInt( |
| 3962 | R.styleable.View_scrollbarFadeDuration, ViewConfiguration |
| 3963 | .getScrollBarFadeDuration()); |
| 3964 | scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( |
| 3965 | R.styleable.View_scrollbarDefaultDelayBeforeFade, |
| 3966 | ViewConfiguration.getScrollDefaultDelay()); |
| 3967 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 3968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( |
| 3970 | com.android.internal.R.styleable.View_scrollbarSize, |
| 3971 | ViewConfiguration.get(mContext).getScaledScrollBarSize()); |
| 3972 | |
| 3973 | Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); |
| 3974 | scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); |
| 3975 | |
| 3976 | Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); |
| 3977 | if (thumb != null) { |
| 3978 | scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); |
| 3979 | } |
| 3980 | |
| 3981 | boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, |
| 3982 | false); |
| 3983 | if (alwaysDraw) { |
| 3984 | scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); |
| 3985 | } |
| 3986 | |
| 3987 | track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); |
| 3988 | scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); |
| 3989 | |
| 3990 | thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); |
| 3991 | if (thumb != null) { |
| 3992 | scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); |
| 3993 | } |
| 3994 | |
| 3995 | alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, |
| 3996 | false); |
| 3997 | if (alwaysDraw) { |
| 3998 | scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); |
| 3999 | } |
| 4000 | |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 4001 | // Apply layout direction to the new Drawables if needed |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 4002 | final int layoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 4003 | if (track != null) { |
| 4004 | track.setLayoutDirection(layoutDirection); |
| 4005 | } |
| 4006 | if (thumb != null) { |
| 4007 | thumb.setLayoutDirection(layoutDirection); |
| 4008 | } |
| 4009 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | // Re-apply user/background padding so that scrollbar(s) get added |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4011 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | /** |
| 4015 | * <p> |
| 4016 | * Initalizes the scrollability cache if necessary. |
| 4017 | * </p> |
| 4018 | */ |
| 4019 | private void initScrollCache() { |
| 4020 | if (mScrollCache == null) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 4021 | mScrollCache = new ScrollabilityCache(ViewConfiguration.get(mContext), this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | } |
| 4023 | } |
| 4024 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 4025 | private ScrollabilityCache getScrollCache() { |
| 4026 | initScrollCache(); |
| 4027 | return mScrollCache; |
| 4028 | } |
| 4029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | /** |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4031 | * Set the position of the vertical scroll bar. Should be one of |
| 4032 | * {@link #SCROLLBAR_POSITION_DEFAULT}, {@link #SCROLLBAR_POSITION_LEFT} or |
| 4033 | * {@link #SCROLLBAR_POSITION_RIGHT}. |
| 4034 | * |
| 4035 | * @param position Where the vertical scroll bar should be positioned. |
| 4036 | */ |
| 4037 | public void setVerticalScrollbarPosition(int position) { |
| 4038 | if (mVerticalScrollbarPosition != position) { |
| 4039 | mVerticalScrollbarPosition = position; |
| 4040 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 4041 | resolvePadding(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * @return The position where the vertical scroll bar will show, if applicable. |
| 4047 | * @see #setVerticalScrollbarPosition(int) |
| 4048 | */ |
| 4049 | public int getVerticalScrollbarPosition() { |
| 4050 | return mVerticalScrollbarPosition; |
| 4051 | } |
| 4052 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4053 | ListenerInfo getListenerInfo() { |
| 4054 | if (mListenerInfo != null) { |
| 4055 | return mListenerInfo; |
| 4056 | } |
| 4057 | mListenerInfo = new ListenerInfo(); |
| 4058 | return mListenerInfo; |
| 4059 | } |
| 4060 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 4061 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4062 | * Register a callback to be invoked when focus of this view changed. |
| 4063 | * |
| 4064 | * @param l The callback that will run. |
| 4065 | */ |
| 4066 | public void setOnFocusChangeListener(OnFocusChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4067 | getListenerInfo().mOnFocusChangeListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | } |
| 4069 | |
| 4070 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4071 | * Add a listener that will be called when the bounds of the view change due to |
| 4072 | * layout processing. |
| 4073 | * |
| 4074 | * @param listener The listener that will be called when layout bounds change. |
| 4075 | */ |
| 4076 | public void addOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4077 | ListenerInfo li = getListenerInfo(); |
| 4078 | if (li.mOnLayoutChangeListeners == null) { |
| 4079 | li.mOnLayoutChangeListeners = new ArrayList<OnLayoutChangeListener>(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4080 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4081 | if (!li.mOnLayoutChangeListeners.contains(listener)) { |
| 4082 | li.mOnLayoutChangeListeners.add(listener); |
Chet Haase | 1a76dcd | 2011-10-06 11:16:40 -0700 | [diff] [blame] | 4083 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * Remove a listener for layout changes. |
| 4088 | * |
| 4089 | * @param listener The listener for layout bounds change. |
| 4090 | */ |
| 4091 | public void removeOnLayoutChangeListener(OnLayoutChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4092 | ListenerInfo li = mListenerInfo; |
| 4093 | if (li == null || li.mOnLayoutChangeListeners == null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4094 | return; |
| 4095 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4096 | li.mOnLayoutChangeListeners.remove(listener); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | /** |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4100 | * Add a listener for attach state changes. |
| 4101 | * |
| 4102 | * This listener will be called whenever this view is attached or detached |
| 4103 | * from a window. Remove the listener using |
| 4104 | * {@link #removeOnAttachStateChangeListener(OnAttachStateChangeListener)}. |
| 4105 | * |
| 4106 | * @param listener Listener to attach |
| 4107 | * @see #removeOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4108 | */ |
| 4109 | public void addOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4110 | ListenerInfo li = getListenerInfo(); |
| 4111 | if (li.mOnAttachStateChangeListeners == null) { |
| 4112 | li.mOnAttachStateChangeListeners |
| 4113 | = new CopyOnWriteArrayList<OnAttachStateChangeListener>(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4114 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4115 | li.mOnAttachStateChangeListeners.add(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | /** |
| 4119 | * Remove a listener for attach state changes. The listener will receive no further |
| 4120 | * notification of window attach/detach events. |
| 4121 | * |
| 4122 | * @param listener Listener to remove |
| 4123 | * @see #addOnAttachStateChangeListener(OnAttachStateChangeListener) |
| 4124 | */ |
| 4125 | public void removeOnAttachStateChangeListener(OnAttachStateChangeListener listener) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4126 | ListenerInfo li = mListenerInfo; |
| 4127 | if (li == null || li.mOnAttachStateChangeListeners == null) { |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4128 | return; |
| 4129 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4130 | li.mOnAttachStateChangeListeners.remove(listener); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | * Returns the focus-change callback registered for this view. |
| 4135 | * |
| 4136 | * @return The callback, or null if one is not registered. |
| 4137 | */ |
| 4138 | public OnFocusChangeListener getOnFocusChangeListener() { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4139 | ListenerInfo li = mListenerInfo; |
| 4140 | return li != null ? li.mOnFocusChangeListener : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /** |
| 4144 | * Register a callback to be invoked when this view is clicked. If this view is not |
| 4145 | * clickable, it becomes clickable. |
| 4146 | * |
| 4147 | * @param l The callback that will run |
| 4148 | * |
| 4149 | * @see #setClickable(boolean) |
| 4150 | */ |
| 4151 | public void setOnClickListener(OnClickListener l) { |
| 4152 | if (!isClickable()) { |
| 4153 | setClickable(true); |
| 4154 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4155 | getListenerInfo().mOnClickListener = l; |
| 4156 | } |
| 4157 | |
| 4158 | /** |
| 4159 | * Return whether this view has an attached OnClickListener. Returns |
| 4160 | * true if there is a listener, false if there is none. |
| 4161 | */ |
| 4162 | public boolean hasOnClickListeners() { |
| 4163 | ListenerInfo li = mListenerInfo; |
| 4164 | return (li != null && li.mOnClickListener != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | /** |
| 4168 | * Register a callback to be invoked when this view is clicked and held. If this view is not |
| 4169 | * long clickable, it becomes long clickable. |
| 4170 | * |
| 4171 | * @param l The callback that will run |
| 4172 | * |
| 4173 | * @see #setLongClickable(boolean) |
| 4174 | */ |
| 4175 | public void setOnLongClickListener(OnLongClickListener l) { |
| 4176 | if (!isLongClickable()) { |
| 4177 | setLongClickable(true); |
| 4178 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4179 | getListenerInfo().mOnLongClickListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | /** |
| 4183 | * Register a callback to be invoked when the context menu for this view is |
| 4184 | * being built. If this view is not long clickable, it becomes long clickable. |
| 4185 | * |
| 4186 | * @param l The callback that will run |
| 4187 | * |
| 4188 | */ |
| 4189 | public void setOnCreateContextMenuListener(OnCreateContextMenuListener l) { |
| 4190 | if (!isLongClickable()) { |
| 4191 | setLongClickable(true); |
| 4192 | } |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4193 | getListenerInfo().mOnCreateContextMenuListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4197 | * Call this view's OnClickListener, if it is defined. Performs all normal |
| 4198 | * actions associated with clicking: reporting accessibility event, playing |
| 4199 | * a sound, etc. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | * |
| 4201 | * @return True there was an assigned OnClickListener that was called, false |
| 4202 | * otherwise is returned. |
| 4203 | */ |
| 4204 | public boolean performClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4205 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); |
| 4206 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4207 | ListenerInfo li = mListenerInfo; |
| 4208 | if (li != null && li.mOnClickListener != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | playSoundEffect(SoundEffectConstants.CLICK); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4210 | li.mOnClickListener.onClick(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4211 | return true; |
| 4212 | } |
| 4213 | |
| 4214 | return false; |
| 4215 | } |
| 4216 | |
| 4217 | /** |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4218 | * Directly call any attached OnClickListener. Unlike {@link #performClick()}, |
| 4219 | * this only calls the listener, and does not do any associated clicking |
| 4220 | * actions like reporting an accessibility event. |
| 4221 | * |
| 4222 | * @return True there was an assigned OnClickListener that was called, false |
| 4223 | * otherwise is returned. |
| 4224 | */ |
| 4225 | public boolean callOnClick() { |
| 4226 | ListenerInfo li = mListenerInfo; |
| 4227 | if (li != null && li.mOnClickListener != null) { |
| 4228 | li.mOnClickListener.onClick(this); |
| 4229 | return true; |
| 4230 | } |
| 4231 | return false; |
| 4232 | } |
| 4233 | |
| 4234 | /** |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4235 | * Call this view's OnLongClickListener, if it is defined. Invokes the context menu if the |
| 4236 | * OnLongClickListener did not consume the event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 4238 | * @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] | 4239 | */ |
| 4240 | public boolean performLongClick() { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4241 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); |
| 4242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | boolean handled = false; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4244 | ListenerInfo li = mListenerInfo; |
| 4245 | if (li != null && li.mOnLongClickListener != null) { |
| 4246 | handled = li.mOnLongClickListener.onLongClick(View.this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | } |
| 4248 | if (!handled) { |
| 4249 | handled = showContextMenu(); |
| 4250 | } |
| 4251 | if (handled) { |
| 4252 | performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
| 4253 | } |
| 4254 | return handled; |
| 4255 | } |
| 4256 | |
| 4257 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4258 | * Performs button-related actions during a touch down event. |
| 4259 | * |
| 4260 | * @param event The event. |
| 4261 | * @return True if the down was consumed. |
| 4262 | * |
| 4263 | * @hide |
| 4264 | */ |
| 4265 | protected boolean performButtonActionOnTouchDown(MotionEvent event) { |
| 4266 | if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) { |
| 4267 | if (showContextMenu(event.getX(), event.getY(), event.getMetaState())) { |
| 4268 | return true; |
| 4269 | } |
| 4270 | } |
| 4271 | return false; |
| 4272 | } |
| 4273 | |
| 4274 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4275 | * Bring up the context menu for this view. |
| 4276 | * |
| 4277 | * @return Whether a context menu was displayed. |
| 4278 | */ |
| 4279 | public boolean showContextMenu() { |
| 4280 | return getParent().showContextMenuForChild(this); |
| 4281 | } |
| 4282 | |
| 4283 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 4284 | * Bring up the context menu for this view, referring to the item under the specified point. |
| 4285 | * |
| 4286 | * @param x The referenced x coordinate. |
| 4287 | * @param y The referenced y coordinate. |
| 4288 | * @param metaState The keyboard modifiers that were pressed. |
| 4289 | * @return Whether a context menu was displayed. |
| 4290 | * |
| 4291 | * @hide |
| 4292 | */ |
| 4293 | public boolean showContextMenu(float x, float y, int metaState) { |
| 4294 | return showContextMenu(); |
| 4295 | } |
| 4296 | |
| 4297 | /** |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4298 | * Start an action mode. |
| 4299 | * |
| 4300 | * @param callback Callback that will control the lifecycle of the action mode |
| 4301 | * @return The new action mode if it is started, null otherwise |
| 4302 | * |
| 4303 | * @see ActionMode |
| 4304 | */ |
| 4305 | public ActionMode startActionMode(ActionMode.Callback callback) { |
John Reck | 5160e2a | 2012-02-22 09:35:12 -0800 | [diff] [blame] | 4306 | ViewParent parent = getParent(); |
| 4307 | if (parent == null) return null; |
| 4308 | return parent.startActionModeForChild(this, callback); |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 4312 | * Register a callback to be invoked when a hardware key is pressed in this view. |
| 4313 | * Key presses in software input methods will generally not trigger the methods of |
| 4314 | * this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | * @param l the key listener to attach to this view |
| 4316 | */ |
| 4317 | public void setOnKeyListener(OnKeyListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4318 | getListenerInfo().mOnKeyListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | /** |
| 4322 | * Register a callback to be invoked when a touch event is sent to this view. |
| 4323 | * @param l the touch listener to attach to this view |
| 4324 | */ |
| 4325 | public void setOnTouchListener(OnTouchListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4326 | getListenerInfo().mOnTouchListener = l; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4330 | * Register a callback to be invoked when a generic motion event is sent to this view. |
| 4331 | * @param l the generic motion listener to attach to this view |
| 4332 | */ |
| 4333 | public void setOnGenericMotionListener(OnGenericMotionListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4334 | getListenerInfo().mOnGenericMotionListener = l; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 4335 | } |
| 4336 | |
| 4337 | /** |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4338 | * Register a callback to be invoked when a hover event is sent to this view. |
| 4339 | * @param l the hover listener to attach to this view |
| 4340 | */ |
| 4341 | public void setOnHoverListener(OnHoverListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4342 | getListenerInfo().mOnHoverListener = l; |
Jeff Brown | 53ca3f1 | 2011-06-27 18:36:00 -0700 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4346 | * Register a drag event listener callback object for this View. The parameter is |
| 4347 | * an implementation of {@link android.view.View.OnDragListener}. To send a drag event to a |
| 4348 | * View, the system calls the |
| 4349 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent)} method. |
| 4350 | * @param l An implementation of {@link android.view.View.OnDragListener}. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4351 | */ |
| 4352 | public void setOnDragListener(OnDragListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4353 | getListenerInfo().mOnDragListener = l; |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 4357 | * Give this view focus. This will cause |
| 4358 | * {@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] | 4359 | * |
| 4360 | * Note: this does not check whether this {@link View} should get focus, it just |
| 4361 | * gives it focus no matter what. It should only be called internally by framework |
| 4362 | * code that knows what it is doing, namely {@link #requestFocus(int, Rect)}. |
| 4363 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 4364 | * @param direction values are {@link View#FOCUS_UP}, {@link View#FOCUS_DOWN}, |
| 4365 | * {@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] | 4366 | * focus moved when requestFocus() is called. It may not always |
| 4367 | * apply, in which case use the default View.FOCUS_DOWN. |
| 4368 | * @param previouslyFocusedRect The rectangle of the view that had focus |
| 4369 | * prior in this View's coordinate system. |
| 4370 | */ |
| 4371 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 4372 | if (DBG) { |
| 4373 | System.out.println(this + " requestFocus()"); |
| 4374 | } |
| 4375 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4376 | if ((mPrivateFlags & PFLAG_FOCUSED) == 0) { |
| 4377 | mPrivateFlags |= PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4379 | View oldFocus = (mAttachInfo != null) ? getRootView().findFocus() : null; |
| 4380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | if (mParent != null) { |
| 4382 | mParent.requestChildFocus(this, this); |
| 4383 | } |
| 4384 | |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4385 | if (mAttachInfo != null) { |
| 4386 | mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, this); |
| 4387 | } |
| 4388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | onFocusChanged(true, direction, previouslyFocusedRect); |
| 4390 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4391 | |
| 4392 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4393 | notifyAccessibilityStateChanged(); |
| 4394 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | /** |
| 4399 | * Request that a rectangle of this view be visible on the screen, |
| 4400 | * scrolling if necessary just enough. |
| 4401 | * |
| 4402 | * <p>A View should call this if it maintains some notion of which part |
| 4403 | * of its content is interesting. For example, a text editing view |
| 4404 | * should call this when its cursor moves. |
| 4405 | * |
| 4406 | * @param rectangle The rectangle. |
| 4407 | * @return Whether any parent scrolled. |
| 4408 | */ |
| 4409 | public boolean requestRectangleOnScreen(Rect rectangle) { |
| 4410 | return requestRectangleOnScreen(rectangle, false); |
| 4411 | } |
| 4412 | |
| 4413 | /** |
| 4414 | * Request that a rectangle of this view be visible on the screen, |
| 4415 | * scrolling if necessary just enough. |
| 4416 | * |
| 4417 | * <p>A View should call this if it maintains some notion of which part |
| 4418 | * of its content is interesting. For example, a text editing view |
| 4419 | * should call this when its cursor moves. |
| 4420 | * |
| 4421 | * <p>When <code>immediate</code> is set to true, scrolling will not be |
| 4422 | * animated. |
| 4423 | * |
| 4424 | * @param rectangle The rectangle. |
| 4425 | * @param immediate True to forbid animated scrolling, false otherwise |
| 4426 | * @return Whether any parent scrolled. |
| 4427 | */ |
| 4428 | public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) { |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4429 | if (mParent == null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4430 | return false; |
| 4431 | } |
| 4432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | View child = this; |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4434 | |
Svetoslav Ganov | 989ae75 | 2012-09-25 15:16:48 -0700 | [diff] [blame] | 4435 | RectF position = (mAttachInfo != null) ? mAttachInfo.mTmpTransformRect : new RectF(); |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4436 | position.set(rectangle); |
| 4437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | ViewParent parent = mParent; |
| 4439 | boolean scrolled = false; |
| 4440 | while (parent != null) { |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4441 | rectangle.set((int) position.left, (int) position.top, |
| 4442 | (int) position.right, (int) position.bottom); |
| 4443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | scrolled |= parent.requestChildRectangleOnScreen(child, |
| 4445 | rectangle, immediate); |
| 4446 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4447 | if (!child.hasIdentityMatrix()) { |
| 4448 | child.getMatrix().mapRect(position); |
| 4449 | } |
| 4450 | |
| 4451 | position.offset(child.mLeft, child.mTop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | |
| 4453 | if (!(parent instanceof View)) { |
| 4454 | break; |
| 4455 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4456 | |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4457 | View parentView = (View) parent; |
| 4458 | |
| 4459 | position.offset(-parentView.getScrollX(), -parentView.getScrollY()); |
| 4460 | |
| 4461 | child = parentView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | parent = child.getParent(); |
| 4463 | } |
Svetoslav Ganov | ee6c6ae | 2012-09-10 19:56:06 -0700 | [diff] [blame] | 4464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | return scrolled; |
| 4466 | } |
| 4467 | |
| 4468 | /** |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4469 | * Called when this view wants to give up focus. If focus is cleared |
| 4470 | * {@link #onFocusChanged(boolean, int, android.graphics.Rect)} is called. |
| 4471 | * <p> |
| 4472 | * <strong>Note:</strong> When a View clears focus the framework is trying |
| 4473 | * 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] | 4474 | * View is the first from the top that can take focus, then all callbacks |
| 4475 | * related to clearing focus will be invoked after wich the framework will |
| 4476 | * give focus to this view. |
Svetoslav Ganov | 13fd561 | 2012-02-01 17:01:12 -0800 | [diff] [blame] | 4477 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | */ |
| 4479 | public void clearFocus() { |
| 4480 | if (DBG) { |
| 4481 | System.out.println(this + " clearFocus()"); |
| 4482 | } |
| 4483 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4484 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4485 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4486 | |
| 4487 | if (mParent != null) { |
| 4488 | mParent.clearChildFocus(this); |
| 4489 | } |
| 4490 | |
| 4491 | onFocusChanged(false, 0, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | refreshDrawableState(); |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4494 | |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4495 | if (!rootViewRequestFocus()) { |
| 4496 | notifyGlobalFocusCleared(this); |
| 4497 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4498 | |
| 4499 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4500 | notifyAccessibilityStateChanged(); |
| 4501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
| 4503 | } |
| 4504 | |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4505 | void notifyGlobalFocusCleared(View oldFocus) { |
| 4506 | if (oldFocus != null && mAttachInfo != null) { |
| 4507 | mAttachInfo.mTreeObserver.dispatchOnGlobalFocusChange(oldFocus, null); |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | boolean rootViewRequestFocus() { |
Svetoslav Ganov | 57cadf2 | 2012-04-04 16:44:39 -0700 | [diff] [blame] | 4512 | View root = getRootView(); |
| 4513 | if (root != null) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4514 | return root.requestFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4516 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * Called internally by the view system when a new view is getting focus. |
| 4521 | * This is what clears the old focus. |
| 4522 | */ |
| 4523 | void unFocus() { |
| 4524 | if (DBG) { |
| 4525 | System.out.println(this + " unFocus()"); |
| 4526 | } |
| 4527 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4528 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
| 4529 | mPrivateFlags &= ~PFLAG_FOCUSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4530 | |
| 4531 | onFocusChanged(false, 0, null); |
| 4532 | refreshDrawableState(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4533 | |
| 4534 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4535 | notifyAccessibilityStateChanged(); |
| 4536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * Returns true if this view has focus iteself, or is the ancestor of the |
| 4542 | * view that has focus. |
| 4543 | * |
| 4544 | * @return True if this view has or contains focus, false otherwise. |
| 4545 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 4546 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | public boolean hasFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4548 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | /** |
| 4552 | * Returns true if this view is focusable or if it contains a reachable View |
| 4553 | * for which {@link #hasFocusable()} returns true. A "reachable hasFocusable()" |
| 4554 | * is a View whose parents do not block descendants focus. |
| 4555 | * |
| 4556 | * Only {@link #VISIBLE} views are considered focusable. |
| 4557 | * |
| 4558 | * @return True if the view is focusable or if the view contains a focusable |
| 4559 | * View, false otherwise. |
| 4560 | * |
| 4561 | * @see ViewGroup#FOCUS_BLOCK_DESCENDANTS |
| 4562 | */ |
| 4563 | public boolean hasFocusable() { |
| 4564 | return (mViewFlags & VISIBILITY_MASK) == VISIBLE && isFocusable(); |
| 4565 | } |
| 4566 | |
| 4567 | /** |
| 4568 | * Called by the view system when the focus state of this view changes. |
| 4569 | * When the focus change event is caused by directional navigation, direction |
| 4570 | * and previouslyFocusedRect provide insight into where the focus is coming from. |
| 4571 | * When overriding, be sure to call up through to the super class so that |
| 4572 | * the standard focus handling will occur. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4573 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4574 | * @param gainFocus True if the View has focus; false otherwise. |
| 4575 | * @param direction The direction focus has moved when requestFocus() |
| 4576 | * is called to give this view focus. Values are |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4577 | * {@link #FOCUS_UP}, {@link #FOCUS_DOWN}, {@link #FOCUS_LEFT}, |
| 4578 | * {@link #FOCUS_RIGHT}, {@link #FOCUS_FORWARD}, or {@link #FOCUS_BACKWARD}. |
| 4579 | * 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] | 4580 | * @param previouslyFocusedRect The rectangle, in this view's coordinate |
| 4581 | * system, of the previously focused view. If applicable, this will be |
| 4582 | * passed in as finer grained information about where the focus is coming |
| 4583 | * from (in addition to direction). Will be <code>null</code> otherwise. |
| 4584 | */ |
| 4585 | protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4586 | if (gainFocus) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4587 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4588 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4589 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4590 | } |
| 4591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4593 | if (!gainFocus) { |
| 4594 | if (isPressed()) { |
| 4595 | setPressed(false); |
| 4596 | } |
| 4597 | if (imm != null && mAttachInfo != null |
| 4598 | && mAttachInfo.mHasWindowFocus) { |
| 4599 | imm.focusOut(this); |
| 4600 | } |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 4601 | onFocusLost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | } else if (imm != null && mAttachInfo != null |
| 4603 | && mAttachInfo.mHasWindowFocus) { |
| 4604 | imm.focusIn(this); |
| 4605 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4606 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 4607 | invalidate(true); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 4608 | ListenerInfo li = mListenerInfo; |
| 4609 | if (li != null && li.mOnFocusChangeListener != null) { |
| 4610 | li.mOnFocusChangeListener.onFocusChange(this, gainFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 4612 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 4613 | if (mAttachInfo != null) { |
| 4614 | mAttachInfo.mKeyDispatchState.reset(this); |
| 4615 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 4619 | * Sends an accessibility event of the given type. If accessibility is |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4620 | * not enabled this method has no effect. The default implementation calls |
| 4621 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first |
| 4622 | * to populate information about the event source (this View), then calls |
| 4623 | * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to |
| 4624 | * populate the text content of the event source including its descendants, |
| 4625 | * and last calls |
| 4626 | * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)} |
| 4627 | * on its parent to resuest sending of the event to interested parties. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4628 | * <p> |
| 4629 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4630 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4631 | * {@link AccessibilityDelegate#sendAccessibilityEvent(View, int)} is |
| 4632 | * responsible for handling this call. |
| 4633 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4634 | * |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4635 | * @param eventType The type of the event to send, as defined by several types from |
| 4636 | * {@link android.view.accessibility.AccessibilityEvent}, such as |
| 4637 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_CLICKED} or |
| 4638 | * {@link android.view.accessibility.AccessibilityEvent#TYPE_VIEW_HOVER_ENTER}. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4639 | * |
| 4640 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4641 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4642 | * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent) |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4643 | * @see AccessibilityDelegate |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4644 | */ |
| 4645 | public void sendAccessibilityEvent(int eventType) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4646 | if (mAccessibilityDelegate != null) { |
| 4647 | mAccessibilityDelegate.sendAccessibilityEvent(this, eventType); |
| 4648 | } else { |
| 4649 | sendAccessibilityEventInternal(eventType); |
| 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | /** |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4654 | * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT} |
| 4655 | * {@link AccessibilityEvent} to make an announcement which is related to some |
| 4656 | * sort of a context change for which none of the events representing UI transitions |
| 4657 | * is a good fit. For example, announcing a new page in a book. If accessibility |
| 4658 | * is not enabled this method does nothing. |
| 4659 | * |
| 4660 | * @param text The announcement text. |
| 4661 | */ |
| 4662 | public void announceForAccessibility(CharSequence text) { |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4663 | if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) { |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4664 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 4665 | AccessibilityEvent.TYPE_ANNOUNCEMENT); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4666 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4667 | event.getText().add(text); |
Svetoslav Ganov | 7a82b2b | 2012-07-02 18:33:23 -0700 | [diff] [blame] | 4668 | event.setContentDescription(null); |
| 4669 | mParent.requestSendAccessibilityEvent(this, event); |
Svetoslav Ganov | 51ab90c | 2012-03-09 10:54:49 -0800 | [diff] [blame] | 4670 | } |
| 4671 | } |
| 4672 | |
| 4673 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4674 | * @see #sendAccessibilityEvent(int) |
| 4675 | * |
| 4676 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4677 | */ |
| 4678 | void sendAccessibilityEventInternal(int eventType) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4679 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 4680 | sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType)); |
| 4681 | } |
| 4682 | } |
| 4683 | |
| 4684 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4685 | * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but |
| 4686 | * takes as an argument an empty {@link AccessibilityEvent} and does not |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4687 | * perform a check whether accessibility is enabled. |
| 4688 | * <p> |
| 4689 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4690 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4691 | * {@link AccessibilityDelegate#sendAccessibilityEventUnchecked(View, AccessibilityEvent)} |
| 4692 | * is responsible for handling this call. |
| 4693 | * </p> |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4694 | * |
| 4695 | * @param event The event to send. |
| 4696 | * |
| 4697 | * @see #sendAccessibilityEvent(int) |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4698 | */ |
| 4699 | public void sendAccessibilityEventUnchecked(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4700 | if (mAccessibilityDelegate != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4701 | mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event); |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4702 | } else { |
| 4703 | sendAccessibilityEventUncheckedInternal(event); |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * @see #sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 4709 | * |
| 4710 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4711 | */ |
| 4712 | void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 9cd1eca | 2011-01-13 14:24:02 -0800 | [diff] [blame] | 4713 | if (!isShown()) { |
| 4714 | return; |
| 4715 | } |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4716 | onInitializeAccessibilityEvent(event); |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4717 | // Only a subset of accessibility events populates text content. |
| 4718 | if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) { |
| 4719 | dispatchPopulateAccessibilityEvent(event); |
| 4720 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4721 | // In the beginning we called #isShown(), so we know that getParent() is not null. |
| 4722 | getParent().requestSendAccessibilityEvent(this, event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | /** |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4726 | * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then |
| 4727 | * to its children for adding their text content to the event. Note that the |
| 4728 | * event text is populated in a separate dispatch path since we add to the |
| 4729 | * 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] | 4730 | * A typical implementation will call |
| 4731 | * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view |
| 4732 | * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
| 4733 | * on each child. Override this method if custom population of the event text |
| 4734 | * content is required. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4735 | * <p> |
| 4736 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4737 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4738 | * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4739 | * is responsible for handling this call. |
| 4740 | * </p> |
Svetoslav Ganov | 82e236d | 2011-09-29 19:31:06 -0700 | [diff] [blame] | 4741 | * <p> |
| 4742 | * <em>Note:</em> Accessibility events of certain types are not dispatched for |
| 4743 | * populating the event text via this method. For details refer to {@link AccessibilityEvent}. |
| 4744 | * </p> |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4745 | * |
| 4746 | * @param event The event. |
| 4747 | * |
| 4748 | * @return True if the event population was completed. |
| 4749 | */ |
| 4750 | public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4751 | if (mAccessibilityDelegate != null) { |
| 4752 | return mAccessibilityDelegate.dispatchPopulateAccessibilityEvent(this, event); |
| 4753 | } else { |
| 4754 | return dispatchPopulateAccessibilityEventInternal(event); |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | /** |
| 4759 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4760 | * |
| 4761 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4762 | */ |
| 4763 | boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4764 | onPopulateAccessibilityEvent(event); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 4765 | return false; |
| 4766 | } |
| 4767 | |
| 4768 | /** |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4769 | * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4770 | * 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] | 4771 | * text content. While this method is free to modify event |
| 4772 | * attributes other than text content, doing so should normally be performed in |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4773 | * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}. |
| 4774 | * <p> |
| 4775 | * Example: Adding formatted date string to an accessibility event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4776 | * to the text added by the super implementation: |
| 4777 | * <pre> public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4778 | * super.onPopulateAccessibilityEvent(event); |
| 4779 | * final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; |
| 4780 | * String selectedDateUtterance = DateUtils.formatDateTime(mContext, |
| 4781 | * mCurrentDate.getTimeInMillis(), flags); |
| 4782 | * event.getText().add(selectedDateUtterance); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4783 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4784 | * <p> |
| 4785 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4786 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4787 | * {@link AccessibilityDelegate#onPopulateAccessibilityEvent(View, AccessibilityEvent)} |
| 4788 | * is responsible for handling this call. |
| 4789 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4790 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4791 | * information to the event, in case the default implementation has basic information to add. |
| 4792 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4793 | * |
| 4794 | * @param event The accessibility event which to populate. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4795 | * |
| 4796 | * @see #sendAccessibilityEvent(int) |
| 4797 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4798 | */ |
| 4799 | public void onPopulateAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4800 | if (mAccessibilityDelegate != null) { |
| 4801 | mAccessibilityDelegate.onPopulateAccessibilityEvent(this, event); |
| 4802 | } else { |
| 4803 | onPopulateAccessibilityEventInternal(event); |
| 4804 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4808 | * @see #onPopulateAccessibilityEvent(AccessibilityEvent) |
| 4809 | * |
| 4810 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4811 | */ |
| 4812 | void onPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
| 4813 | |
| 4814 | } |
| 4815 | |
| 4816 | /** |
| 4817 | * Initializes an {@link AccessibilityEvent} with information about |
| 4818 | * this View which is the event source. In other words, the source of |
| 4819 | * an accessibility event is the view whose state change triggered firing |
| 4820 | * the event. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4821 | * <p> |
| 4822 | * Example: Setting the password property of an event in addition |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4823 | * to properties set by the super implementation: |
| 4824 | * <pre> public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 4825 | * super.onInitializeAccessibilityEvent(event); |
| 4826 | * event.setPassword(true); |
| 4827 | * }</pre> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4828 | * <p> |
| 4829 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4830 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4831 | * {@link AccessibilityDelegate#onInitializeAccessibilityEvent(View, AccessibilityEvent)} |
| 4832 | * is responsible for handling this call. |
| 4833 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 4834 | * <p class="note"><strong>Note:</strong> Always call the super implementation before adding |
| 4835 | * information to the event, in case the default implementation has basic information to add. |
| 4836 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4837 | * @param event The event to initialize. |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4838 | * |
| 4839 | * @see #sendAccessibilityEvent(int) |
| 4840 | * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 4841 | */ |
| 4842 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4843 | if (mAccessibilityDelegate != null) { |
| 4844 | mAccessibilityDelegate.onInitializeAccessibilityEvent(this, event); |
| 4845 | } else { |
| 4846 | onInitializeAccessibilityEventInternal(event); |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | /** |
| 4851 | * @see #onInitializeAccessibilityEvent(AccessibilityEvent) |
| 4852 | * |
| 4853 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4854 | */ |
| 4855 | void onInitializeAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4856 | event.setSource(this); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 4857 | event.setClassName(View.class.getName()); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4858 | event.setPackageName(getContext().getPackageName()); |
| 4859 | event.setEnabled(isEnabled()); |
| 4860 | event.setContentDescription(mContentDescription); |
| 4861 | |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4862 | if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 4863 | ArrayList<View> focusablesTempList = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | d9ee72f | 2011-10-05 22:26:05 -0700 | [diff] [blame] | 4864 | getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, |
| 4865 | FOCUSABLES_ALL); |
| 4866 | event.setItemCount(focusablesTempList.size()); |
| 4867 | event.setCurrentItemIndex(focusablesTempList.indexOf(this)); |
| 4868 | focusablesTempList.clear(); |
Svetoslav Ganov | 3040132 | 2011-05-12 18:53:45 -0700 | [diff] [blame] | 4869 | } |
| 4870 | } |
| 4871 | |
| 4872 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4873 | * Returns an {@link AccessibilityNodeInfo} representing this view from the |
| 4874 | * point of view of an {@link android.accessibilityservice.AccessibilityService}. |
| 4875 | * This method is responsible for obtaining an accessibility node info from a |
| 4876 | * pool of reusable instances and calling |
| 4877 | * {@link #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} on this view to |
| 4878 | * initialize the former. |
| 4879 | * <p> |
| 4880 | * Note: The client is responsible for recycling the obtained instance by calling |
| 4881 | * {@link AccessibilityNodeInfo#recycle()} to minimize object creation. |
| 4882 | * </p> |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4883 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4884 | * @return A populated {@link AccessibilityNodeInfo}. |
| 4885 | * |
| 4886 | * @see AccessibilityNodeInfo |
| 4887 | */ |
| 4888 | public AccessibilityNodeInfo createAccessibilityNodeInfo() { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 4889 | AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); |
| 4890 | if (provider != null) { |
| 4891 | return provider.createAccessibilityNodeInfo(View.NO_ID); |
| 4892 | } else { |
| 4893 | AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(this); |
| 4894 | onInitializeAccessibilityNodeInfo(info); |
| 4895 | return info; |
| 4896 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | /** |
| 4900 | * Initializes an {@link AccessibilityNodeInfo} with information about this view. |
| 4901 | * The base implementation sets: |
| 4902 | * <ul> |
| 4903 | * <li>{@link AccessibilityNodeInfo#setParent(View)},</li> |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4904 | * <li>{@link AccessibilityNodeInfo#setBoundsInParent(Rect)},</li> |
| 4905 | * <li>{@link AccessibilityNodeInfo#setBoundsInScreen(Rect)},</li> |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4906 | * <li>{@link AccessibilityNodeInfo#setPackageName(CharSequence)},</li> |
| 4907 | * <li>{@link AccessibilityNodeInfo#setClassName(CharSequence)},</li> |
| 4908 | * <li>{@link AccessibilityNodeInfo#setContentDescription(CharSequence)},</li> |
| 4909 | * <li>{@link AccessibilityNodeInfo#setEnabled(boolean)},</li> |
| 4910 | * <li>{@link AccessibilityNodeInfo#setClickable(boolean)},</li> |
| 4911 | * <li>{@link AccessibilityNodeInfo#setFocusable(boolean)},</li> |
| 4912 | * <li>{@link AccessibilityNodeInfo#setFocused(boolean)},</li> |
| 4913 | * <li>{@link AccessibilityNodeInfo#setLongClickable(boolean)},</li> |
| 4914 | * <li>{@link AccessibilityNodeInfo#setSelected(boolean)},</li> |
| 4915 | * </ul> |
| 4916 | * <p> |
| 4917 | * Subclasses should override this method, call the super implementation, |
| 4918 | * and set additional attributes. |
| 4919 | * </p> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4920 | * <p> |
| 4921 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 4922 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 4923 | * {@link AccessibilityDelegate#onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo)} |
| 4924 | * is responsible for handling this call. |
| 4925 | * </p> |
| 4926 | * |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4927 | * @param info The instance to initialize. |
| 4928 | */ |
| 4929 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4930 | if (mAccessibilityDelegate != null) { |
| 4931 | mAccessibilityDelegate.onInitializeAccessibilityNodeInfo(this, info); |
| 4932 | } else { |
| 4933 | onInitializeAccessibilityNodeInfoInternal(info); |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4938 | * Gets the location of this view in screen coordintates. |
| 4939 | * |
| 4940 | * @param outRect The output location |
| 4941 | */ |
Svetoslav Ganov | 78bd983 | 2012-10-15 19:12:29 -0700 | [diff] [blame] | 4942 | void getBoundsOnScreen(Rect outRect) { |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4943 | if (mAttachInfo == null) { |
| 4944 | return; |
| 4945 | } |
| 4946 | |
| 4947 | RectF position = mAttachInfo.mTmpTransformRect; |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4948 | position.set(0, 0, mRight - mLeft, mBottom - mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4949 | |
| 4950 | if (!hasIdentityMatrix()) { |
| 4951 | getMatrix().mapRect(position); |
| 4952 | } |
| 4953 | |
Svetoslav Ganov | 14b2b74 | 2012-05-08 16:36:34 -0700 | [diff] [blame] | 4954 | position.offset(mLeft, mTop); |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4955 | |
| 4956 | ViewParent parent = mParent; |
| 4957 | while (parent instanceof View) { |
| 4958 | View parentView = (View) parent; |
| 4959 | |
| 4960 | position.offset(-parentView.mScrollX, -parentView.mScrollY); |
| 4961 | |
| 4962 | if (!parentView.hasIdentityMatrix()) { |
| 4963 | parentView.getMatrix().mapRect(position); |
| 4964 | } |
| 4965 | |
| 4966 | position.offset(parentView.mLeft, parentView.mTop); |
| 4967 | |
| 4968 | parent = parentView.mParent; |
| 4969 | } |
| 4970 | |
| 4971 | if (parent instanceof ViewRootImpl) { |
| 4972 | ViewRootImpl viewRootImpl = (ViewRootImpl) parent; |
| 4973 | position.offset(0, -viewRootImpl.mCurScrollY); |
| 4974 | } |
| 4975 | |
| 4976 | position.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 4977 | |
| 4978 | outRect.set((int) (position.left + 0.5f), (int) (position.top + 0.5f), |
| 4979 | (int) (position.right + 0.5f), (int) (position.bottom + 0.5f)); |
| 4980 | } |
| 4981 | |
| 4982 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 4983 | * @see #onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 4984 | * |
| 4985 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 4986 | */ |
| 4987 | void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4988 | Rect bounds = mAttachInfo.mTmpInvalRect; |
Svetoslav Ganov | 983119a | 2012-07-03 21:04:10 -0700 | [diff] [blame] | 4989 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4990 | getDrawingRect(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4991 | info.setBoundsInParent(bounds); |
| 4992 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 4993 | getBoundsOnScreen(bounds); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 4994 | info.setBoundsInScreen(bounds); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4995 | |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 4996 | ViewParent parent = getParentForAccessibility(); |
| 4997 | if (parent instanceof View) { |
| 4998 | info.setParent((View) parent); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 4999 | } |
| 5000 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5001 | if (mID != View.NO_ID) { |
| 5002 | View rootView = getRootView(); |
| 5003 | if (rootView == null) { |
| 5004 | rootView = this; |
| 5005 | } |
| 5006 | View label = rootView.findLabelForView(this, mID); |
| 5007 | if (label != null) { |
| 5008 | info.setLabeledBy(label); |
| 5009 | } |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 5010 | |
| 5011 | if ((mAttachInfo.mAccessibilityFetchFlags |
| 5012 | & AccessibilityNodeInfo.FLAG_REPORT_VIEW_IDS) != 0) { |
| 5013 | String viewId = null; |
| 5014 | try { |
| 5015 | viewId = getResources().getResourceName(mID); |
| 5016 | } catch (Resources.NotFoundException nfe) { |
| 5017 | /* ignore */ |
| 5018 | } |
| 5019 | if (viewId == null) { |
| 5020 | try { |
| 5021 | viewId = ((Context) ActivityThread.currentActivityThread() |
| 5022 | .getSystemContext()).getResources().getResourceName(mID); |
| 5023 | } catch (Resources.NotFoundException nfe) { |
| 5024 | /* ignore */ |
| 5025 | } |
| 5026 | } |
| 5027 | info.setViewId(viewId); |
| 5028 | } |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | if (mLabelForId != View.NO_ID) { |
| 5032 | View rootView = getRootView(); |
| 5033 | if (rootView == null) { |
| 5034 | rootView = this; |
| 5035 | } |
| 5036 | View labeled = rootView.findViewInsideOutShouldExist(this, mLabelForId); |
| 5037 | if (labeled != null) { |
| 5038 | info.setLabelFor(labeled); |
| 5039 | } |
| 5040 | } |
| 5041 | |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 5042 | info.setVisibleToUser(isVisibleToUser()); |
| 5043 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5044 | info.setPackageName(mContext.getPackageName()); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 5045 | info.setClassName(View.class.getName()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5046 | info.setContentDescription(getContentDescription()); |
| 5047 | |
| 5048 | info.setEnabled(isEnabled()); |
| 5049 | info.setClickable(isClickable()); |
| 5050 | info.setFocusable(isFocusable()); |
| 5051 | info.setFocused(isFocused()); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5052 | info.setAccessibilityFocused(isAccessibilityFocused()); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5053 | info.setSelected(isSelected()); |
| 5054 | info.setLongClickable(isLongClickable()); |
| 5055 | |
| 5056 | // TODO: These make sense only if we are in an AdapterView but all |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 5057 | // views can be selected. Maybe from accessibility perspective |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5058 | // we should report as selectable view in an AdapterView. |
| 5059 | info.addAction(AccessibilityNodeInfo.ACTION_SELECT); |
| 5060 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_SELECTION); |
| 5061 | |
| 5062 | if (isFocusable()) { |
| 5063 | if (isFocused()) { |
| 5064 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_FOCUS); |
| 5065 | } else { |
| 5066 | info.addAction(AccessibilityNodeInfo.ACTION_FOCUS); |
| 5067 | } |
| 5068 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5069 | |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5070 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 5071 | info.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 02afe2c | 2012-05-07 17:51:59 -0700 | [diff] [blame] | 5072 | } else { |
| 5073 | info.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS); |
| 5074 | } |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5075 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5076 | if (isClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5077 | info.addAction(AccessibilityNodeInfo.ACTION_CLICK); |
| 5078 | } |
| 5079 | |
Svetoslav Ganov | fb1e80a | 2012-05-16 17:33:19 -0700 | [diff] [blame] | 5080 | if (isLongClickable() && isEnabled()) { |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5081 | info.addAction(AccessibilityNodeInfo.ACTION_LONG_CLICK); |
| 5082 | } |
| 5083 | |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5084 | if (mContentDescription != null && mContentDescription.length() > 0) { |
Svetoslav Ganov | 2b435aa | 2012-05-04 17:16:37 -0700 | [diff] [blame] | 5085 | info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY); |
| 5086 | info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY); |
| 5087 | info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 5088 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD |
| 5089 | | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH); |
Svetoslav Ganov | cfcff98 | 2012-04-28 15:31:09 -0700 | [diff] [blame] | 5090 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5091 | } |
| 5092 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5093 | private View findLabelForView(View view, int labeledId) { |
| 5094 | if (mMatchLabelForPredicate == null) { |
| 5095 | mMatchLabelForPredicate = new MatchLabelForPredicate(); |
| 5096 | } |
| 5097 | mMatchLabelForPredicate.mLabeledId = labeledId; |
| 5098 | return findViewByPredicateInsideOut(view, mMatchLabelForPredicate); |
| 5099 | } |
| 5100 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5101 | /** |
Svetoslav Ganov | 0a1bb6d | 2012-05-07 11:54:39 -0700 | [diff] [blame] | 5102 | * Computes whether this view is visible to the user. Such a view is |
| 5103 | * attached, visible, all its predecessors are visible, it is not clipped |
| 5104 | * entirely by its predecessors, and has an alpha greater than zero. |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5105 | * |
| 5106 | * @return Whether the view is visible on the screen. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5107 | * |
| 5108 | * @hide |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5109 | */ |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5110 | protected boolean isVisibleToUser() { |
| 5111 | return isVisibleToUser(null); |
| 5112 | } |
| 5113 | |
| 5114 | /** |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5115 | * Computes whether the given portion of this view is visible to the user. |
| 5116 | * Such a view is attached, visible, all its predecessors are visible, |
| 5117 | * has an alpha greater than zero, and the specified portion is not |
| 5118 | * clipped entirely by its predecessors. |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5119 | * |
| 5120 | * @param boundInView the portion of the view to test; coordinates should be relative; may be |
| 5121 | * <code>null</code>, and the entire view will be tested in this case. |
| 5122 | * When <code>true</code> is returned by the function, the actual visible |
| 5123 | * region will be stored in this parameter; that is, if boundInView is fully |
| 5124 | * contained within the view, no modification will be made, otherwise regions |
| 5125 | * outside of the visible area of the view will be clipped. |
| 5126 | * |
| 5127 | * @return Whether the specified portion of the view is visible on the screen. |
| 5128 | * |
| 5129 | * @hide |
| 5130 | */ |
| 5131 | protected boolean isVisibleToUser(Rect boundInView) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5132 | if (mAttachInfo != null) { |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5133 | // Attached to invisible window means this view is not visible. |
| 5134 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 5135 | return false; |
| 5136 | } |
| 5137 | // An invisible predecessor or one with alpha zero means |
| 5138 | // that this view is not visible to the user. |
| 5139 | Object current = this; |
| 5140 | while (current instanceof View) { |
| 5141 | View view = (View) current; |
| 5142 | // We have attach info so this view is attached and there is no |
| 5143 | // need to check whether we reach to ViewRootImpl on the way up. |
| 5144 | if (view.getAlpha() <= 0 || view.getVisibility() != VISIBLE) { |
| 5145 | return false; |
| 5146 | } |
| 5147 | current = view.mParent; |
| 5148 | } |
| 5149 | // Check if the view is entirely covered by its predecessors. |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5150 | Rect visibleRect = mAttachInfo.mTmpInvalRect; |
| 5151 | Point offset = mAttachInfo.mPoint; |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5152 | if (!getGlobalVisibleRect(visibleRect, offset)) { |
| 5153 | return false; |
Guang Zhu | 0d607fb | 2012-05-11 19:34:56 -0700 | [diff] [blame] | 5154 | } |
Svetoslav Ganov | 11f19f1 | 2012-11-02 16:03:06 -0700 | [diff] [blame] | 5155 | // Check if the visible portion intersects the rectangle of interest. |
| 5156 | if (boundInView != null) { |
| 5157 | visibleRect.offset(-offset.x, -offset.y); |
| 5158 | return boundInView.intersect(visibleRect); |
| 5159 | } |
| 5160 | return true; |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5161 | } |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5162 | return false; |
Svetoslav Ganov | 749e796 | 2012-04-19 17:13:46 -0700 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | /** |
alanv | b72fe7a | 2012-08-27 16:44:25 -0700 | [diff] [blame] | 5166 | * Returns the delegate for implementing accessibility support via |
| 5167 | * composition. For more details see {@link AccessibilityDelegate}. |
| 5168 | * |
| 5169 | * @return The delegate, or null if none set. |
| 5170 | * |
| 5171 | * @hide |
| 5172 | */ |
| 5173 | public AccessibilityDelegate getAccessibilityDelegate() { |
| 5174 | return mAccessibilityDelegate; |
| 5175 | } |
| 5176 | |
| 5177 | /** |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 5178 | * Sets a delegate for implementing accessibility support via composition as |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 5179 | * opposed to inheritance. The delegate's primary use is for implementing |
| 5180 | * backwards compatible widgets. For more details see {@link AccessibilityDelegate}. |
| 5181 | * |
| 5182 | * @param delegate The delegate instance. |
| 5183 | * |
| 5184 | * @see AccessibilityDelegate |
| 5185 | */ |
| 5186 | public void setAccessibilityDelegate(AccessibilityDelegate delegate) { |
| 5187 | mAccessibilityDelegate = delegate; |
| 5188 | } |
| 5189 | |
| 5190 | /** |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 5191 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 5192 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 5193 | * that explore the window content. |
| 5194 | * <p> |
| 5195 | * If this method returns an instance, this instance is responsible for managing |
| 5196 | * {@link AccessibilityNodeInfo}s describing the virtual sub-tree rooted at this |
| 5197 | * View including the one representing the View itself. Similarly the returned |
| 5198 | * instance is responsible for performing accessibility actions on any virtual |
| 5199 | * view or the root view itself. |
| 5200 | * </p> |
| 5201 | * <p> |
| 5202 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 5203 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 5204 | * {@link AccessibilityDelegate#getAccessibilityNodeProvider(View)} |
| 5205 | * is responsible for handling this call. |
| 5206 | * </p> |
| 5207 | * |
| 5208 | * @return The provider. |
| 5209 | * |
| 5210 | * @see AccessibilityNodeProvider |
| 5211 | */ |
| 5212 | public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| 5213 | if (mAccessibilityDelegate != null) { |
| 5214 | return mAccessibilityDelegate.getAccessibilityNodeProvider(this); |
| 5215 | } else { |
| 5216 | return null; |
| 5217 | } |
| 5218 | } |
| 5219 | |
| 5220 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5221 | * Gets the unique identifier of this view on the screen for accessibility purposes. |
| 5222 | * If this {@link View} is not attached to any window, {@value #NO_ID} is returned. |
| 5223 | * |
| 5224 | * @return The view accessibility id. |
| 5225 | * |
| 5226 | * @hide |
| 5227 | */ |
| 5228 | public int getAccessibilityViewId() { |
| 5229 | if (mAccessibilityViewId == NO_ID) { |
| 5230 | mAccessibilityViewId = sNextAccessibilityViewId++; |
| 5231 | } |
| 5232 | return mAccessibilityViewId; |
| 5233 | } |
| 5234 | |
| 5235 | /** |
| 5236 | * Gets the unique identifier of the window in which this View reseides. |
| 5237 | * |
| 5238 | * @return The window accessibility id. |
| 5239 | * |
| 5240 | * @hide |
| 5241 | */ |
| 5242 | public int getAccessibilityWindowId() { |
| 5243 | return mAttachInfo != null ? mAttachInfo.mAccessibilityWindowId : NO_ID; |
| 5244 | } |
| 5245 | |
| 5246 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5247 | * Gets the {@link View} description. It briefly describes the view and is |
| 5248 | * primarily used for accessibility support. Set this property to enable |
| 5249 | * better accessibility support for your application. This is especially |
| 5250 | * true for views that do not have textual representation (For example, |
| 5251 | * ImageButton). |
| 5252 | * |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5253 | * @return The content description. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5254 | * |
| 5255 | * @attr ref android.R.styleable#View_contentDescription |
| 5256 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5257 | @ViewDebug.ExportedProperty(category = "accessibility") |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5258 | public CharSequence getContentDescription() { |
| 5259 | return mContentDescription; |
| 5260 | } |
| 5261 | |
| 5262 | /** |
| 5263 | * Sets the {@link View} description. It briefly describes the view and is |
| 5264 | * primarily used for accessibility support. Set this property to enable |
| 5265 | * better accessibility support for your application. This is especially |
| 5266 | * true for views that do not have textual representation (For example, |
| 5267 | * ImageButton). |
| 5268 | * |
| 5269 | * @param contentDescription The content description. |
| 5270 | * |
| 5271 | * @attr ref android.R.styleable#View_contentDescription |
| 5272 | */ |
Svetoslav Ganov | e261e28 | 2011-10-18 17:47:04 -0700 | [diff] [blame] | 5273 | @RemotableViewMethod |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5274 | public void setContentDescription(CharSequence contentDescription) { |
Svetoslav Ganov | b708f77 | 2012-10-10 21:25:55 -0700 | [diff] [blame] | 5275 | if (mContentDescription == null) { |
| 5276 | if (contentDescription == null) { |
| 5277 | return; |
| 5278 | } |
| 5279 | } else if (mContentDescription.equals(contentDescription)) { |
| 5280 | return; |
| 5281 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5282 | mContentDescription = contentDescription; |
Svetoslav Ganov | e47957a | 2012-06-05 14:46:50 -0700 | [diff] [blame] | 5283 | final boolean nonEmptyDesc = contentDescription != null && contentDescription.length() > 0; |
| 5284 | if (nonEmptyDesc && getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 5285 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 5286 | } |
Svetoslav Ganov | b708f77 | 2012-10-10 21:25:55 -0700 | [diff] [blame] | 5287 | notifyAccessibilityStateChanged(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /** |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 5291 | * Gets the id of a view for which this view serves as a label for |
| 5292 | * accessibility purposes. |
| 5293 | * |
| 5294 | * @return The labeled view id. |
| 5295 | */ |
| 5296 | @ViewDebug.ExportedProperty(category = "accessibility") |
| 5297 | public int getLabelFor() { |
| 5298 | return mLabelForId; |
| 5299 | } |
| 5300 | |
| 5301 | /** |
| 5302 | * Sets the id of a view for which this view serves as a label for |
| 5303 | * accessibility purposes. |
| 5304 | * |
| 5305 | * @param id The labeled view id. |
| 5306 | */ |
| 5307 | @RemotableViewMethod |
| 5308 | public void setLabelFor(int id) { |
| 5309 | mLabelForId = id; |
| 5310 | if (mLabelForId != View.NO_ID |
| 5311 | && mID == View.NO_ID) { |
| 5312 | mID = generateViewId(); |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | /** |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5317 | * Invoked whenever this view loses focus, either by losing window focus or by losing |
| 5318 | * focus within its window. This method can be used to clear any state tied to the |
| 5319 | * focus. For instance, if a button is held pressed with the trackball and the window |
| 5320 | * loses focus, this method can be used to cancel the press. |
| 5321 | * |
| 5322 | * Subclasses of View overriding this method should always call super.onFocusLost(). |
| 5323 | * |
| 5324 | * @see #onFocusChanged(boolean, int, android.graphics.Rect) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5325 | * @see #onWindowFocusChanged(boolean) |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5326 | * |
| 5327 | * @hide pending API council approval |
| 5328 | */ |
| 5329 | protected void onFocusLost() { |
| 5330 | resetPressedState(); |
| 5331 | } |
| 5332 | |
| 5333 | private void resetPressedState() { |
| 5334 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 5335 | return; |
| 5336 | } |
| 5337 | |
| 5338 | if (isPressed()) { |
| 5339 | setPressed(false); |
| 5340 | |
| 5341 | if (!mHasPerformedLongPress) { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 5342 | removeLongPressCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 5343 | } |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5348 | * Returns true if this view has focus |
| 5349 | * |
| 5350 | * @return True if this view has focus, false otherwise. |
| 5351 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 5352 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5353 | public boolean isFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5354 | return (mPrivateFlags & PFLAG_FOCUSED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | /** |
| 5358 | * Find the view in the hierarchy rooted at this view that currently has |
| 5359 | * focus. |
| 5360 | * |
| 5361 | * @return The view that currently has focus, or null if no focused view can |
| 5362 | * be found. |
| 5363 | */ |
| 5364 | public View findFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5365 | return (mPrivateFlags & PFLAG_FOCUSED) != 0 ? this : null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5369 | * Indicates whether this view is one of the set of scrollable containers in |
| 5370 | * its window. |
| 5371 | * |
| 5372 | * @return whether this view is one of the set of scrollable containers in |
| 5373 | * its window |
| 5374 | * |
| 5375 | * @attr ref android.R.styleable#View_isScrollContainer |
| 5376 | */ |
| 5377 | public boolean isScrollContainer() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5378 | return (mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | * Change whether this view is one of the set of scrollable containers in |
| 5383 | * its window. This will be used to determine whether the window can |
| 5384 | * resize or must pan when a soft input area is open -- scrollable |
| 5385 | * containers allow the window to use resize mode since the container |
| 5386 | * will appropriately shrink. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5387 | * |
| 5388 | * @attr ref android.R.styleable#View_isScrollContainer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | */ |
| 5390 | public void setScrollContainer(boolean isScrollContainer) { |
| 5391 | if (isScrollContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5392 | if (mAttachInfo != null && (mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5393 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5394 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5395 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5396 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5398 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5399 | mAttachInfo.mScrollContainers.remove(this); |
| 5400 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5401 | mPrivateFlags &= ~(PFLAG_SCROLL_CONTAINER|PFLAG_SCROLL_CONTAINER_ADDED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | } |
| 5403 | } |
| 5404 | |
| 5405 | /** |
| 5406 | * Returns the quality of the drawing cache. |
| 5407 | * |
| 5408 | * @return One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5409 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5410 | * |
| 5411 | * @see #setDrawingCacheQuality(int) |
| 5412 | * @see #setDrawingCacheEnabled(boolean) |
| 5413 | * @see #isDrawingCacheEnabled() |
| 5414 | * |
| 5415 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5416 | */ |
| 5417 | public int getDrawingCacheQuality() { |
| 5418 | return mViewFlags & DRAWING_CACHE_QUALITY_MASK; |
| 5419 | } |
| 5420 | |
| 5421 | /** |
| 5422 | * Set the drawing cache quality of this view. This value is used only when the |
| 5423 | * drawing cache is enabled |
| 5424 | * |
| 5425 | * @param quality One of {@link #DRAWING_CACHE_QUALITY_AUTO}, |
| 5426 | * {@link #DRAWING_CACHE_QUALITY_LOW}, or {@link #DRAWING_CACHE_QUALITY_HIGH} |
| 5427 | * |
| 5428 | * @see #getDrawingCacheQuality() |
| 5429 | * @see #setDrawingCacheEnabled(boolean) |
| 5430 | * @see #isDrawingCacheEnabled() |
| 5431 | * |
| 5432 | * @attr ref android.R.styleable#View_drawingCacheQuality |
| 5433 | */ |
| 5434 | public void setDrawingCacheQuality(int quality) { |
| 5435 | setFlags(quality, DRAWING_CACHE_QUALITY_MASK); |
| 5436 | } |
| 5437 | |
| 5438 | /** |
| 5439 | * Returns whether the screen should remain on, corresponding to the current |
| 5440 | * value of {@link #KEEP_SCREEN_ON}. |
| 5441 | * |
| 5442 | * @return Returns true if {@link #KEEP_SCREEN_ON} is set. |
| 5443 | * |
| 5444 | * @see #setKeepScreenOn(boolean) |
| 5445 | * |
| 5446 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5447 | */ |
| 5448 | public boolean getKeepScreenOn() { |
| 5449 | return (mViewFlags & KEEP_SCREEN_ON) != 0; |
| 5450 | } |
| 5451 | |
| 5452 | /** |
| 5453 | * Controls whether the screen should remain on, modifying the |
| 5454 | * value of {@link #KEEP_SCREEN_ON}. |
| 5455 | * |
| 5456 | * @param keepScreenOn Supply true to set {@link #KEEP_SCREEN_ON}. |
| 5457 | * |
| 5458 | * @see #getKeepScreenOn() |
| 5459 | * |
| 5460 | * @attr ref android.R.styleable#View_keepScreenOn |
| 5461 | */ |
| 5462 | public void setKeepScreenOn(boolean keepScreenOn) { |
| 5463 | setFlags(keepScreenOn ? KEEP_SCREEN_ON : 0, KEEP_SCREEN_ON); |
| 5464 | } |
| 5465 | |
| 5466 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5467 | * Gets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5468 | * @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] | 5469 | * |
| 5470 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5471 | */ |
| 5472 | public int getNextFocusLeftId() { |
| 5473 | return mNextFocusLeftId; |
| 5474 | } |
| 5475 | |
| 5476 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5477 | * Sets the id of the view to use when the next focus is {@link #FOCUS_LEFT}. |
| 5478 | * @param nextFocusLeftId The next focus ID, or {@link #NO_ID} if the framework should |
| 5479 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5480 | * |
| 5481 | * @attr ref android.R.styleable#View_nextFocusLeft |
| 5482 | */ |
| 5483 | public void setNextFocusLeftId(int nextFocusLeftId) { |
| 5484 | mNextFocusLeftId = nextFocusLeftId; |
| 5485 | } |
| 5486 | |
| 5487 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5488 | * Gets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5489 | * @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] | 5490 | * |
| 5491 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5492 | */ |
| 5493 | public int getNextFocusRightId() { |
| 5494 | return mNextFocusRightId; |
| 5495 | } |
| 5496 | |
| 5497 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5498 | * Sets the id of the view to use when the next focus is {@link #FOCUS_RIGHT}. |
| 5499 | * @param nextFocusRightId The next focus ID, or {@link #NO_ID} if the framework should |
| 5500 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | * |
| 5502 | * @attr ref android.R.styleable#View_nextFocusRight |
| 5503 | */ |
| 5504 | public void setNextFocusRightId(int nextFocusRightId) { |
| 5505 | mNextFocusRightId = nextFocusRightId; |
| 5506 | } |
| 5507 | |
| 5508 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5509 | * Gets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5510 | * @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] | 5511 | * |
| 5512 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5513 | */ |
| 5514 | public int getNextFocusUpId() { |
| 5515 | return mNextFocusUpId; |
| 5516 | } |
| 5517 | |
| 5518 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5519 | * Sets the id of the view to use when the next focus is {@link #FOCUS_UP}. |
| 5520 | * @param nextFocusUpId The next focus ID, or {@link #NO_ID} if the framework should |
| 5521 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5522 | * |
| 5523 | * @attr ref android.R.styleable#View_nextFocusUp |
| 5524 | */ |
| 5525 | public void setNextFocusUpId(int nextFocusUpId) { |
| 5526 | mNextFocusUpId = nextFocusUpId; |
| 5527 | } |
| 5528 | |
| 5529 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5530 | * Gets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5531 | * @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] | 5532 | * |
| 5533 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5534 | */ |
| 5535 | public int getNextFocusDownId() { |
| 5536 | return mNextFocusDownId; |
| 5537 | } |
| 5538 | |
| 5539 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5540 | * Sets the id of the view to use when the next focus is {@link #FOCUS_DOWN}. |
| 5541 | * @param nextFocusDownId The next focus ID, or {@link #NO_ID} if the framework should |
| 5542 | * decide automatically. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | * |
| 5544 | * @attr ref android.R.styleable#View_nextFocusDown |
| 5545 | */ |
| 5546 | public void setNextFocusDownId(int nextFocusDownId) { |
| 5547 | mNextFocusDownId = nextFocusDownId; |
| 5548 | } |
| 5549 | |
| 5550 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5551 | * Gets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5552 | * @return The next focus ID, or {@link #NO_ID} if the framework should decide automatically. |
| 5553 | * |
| 5554 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5555 | */ |
| 5556 | public int getNextFocusForwardId() { |
| 5557 | return mNextFocusForwardId; |
| 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * Sets the id of the view to use when the next focus is {@link #FOCUS_FORWARD}. |
| 5562 | * @param nextFocusForwardId The next focus ID, or {@link #NO_ID} if the framework should |
| 5563 | * decide automatically. |
| 5564 | * |
| 5565 | * @attr ref android.R.styleable#View_nextFocusForward |
| 5566 | */ |
| 5567 | public void setNextFocusForwardId(int nextFocusForwardId) { |
| 5568 | mNextFocusForwardId = nextFocusForwardId; |
| 5569 | } |
| 5570 | |
| 5571 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5572 | * Returns the visibility of this view and all of its ancestors |
| 5573 | * |
| 5574 | * @return True if this view and all of its ancestors are {@link #VISIBLE} |
| 5575 | */ |
| 5576 | public boolean isShown() { |
| 5577 | View current = this; |
| 5578 | //noinspection ConstantConditions |
| 5579 | do { |
| 5580 | if ((current.mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 5581 | return false; |
| 5582 | } |
| 5583 | ViewParent parent = current.mParent; |
| 5584 | if (parent == null) { |
| 5585 | return false; // We are not attached to the view root |
| 5586 | } |
| 5587 | if (!(parent instanceof View)) { |
| 5588 | return true; |
| 5589 | } |
| 5590 | current = (View) parent; |
| 5591 | } while (current != null); |
| 5592 | |
| 5593 | return false; |
| 5594 | } |
| 5595 | |
| 5596 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5597 | * Called by the view hierarchy when the content insets for a window have |
| 5598 | * changed, to allow it to adjust its content to fit within those windows. |
| 5599 | * The content insets tell you the space that the status bar, input method, |
| 5600 | * 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] | 5601 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5602 | * <p>You do not normally need to deal with this function, since the default |
| 5603 | * window decoration given to applications takes care of applying it to the |
| 5604 | * content of the window. If you use {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN} |
| 5605 | * or {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION} this will not be the case, |
| 5606 | * and your content can be placed under those system elements. You can then |
| 5607 | * use this method within your view hierarchy if you have parts of your UI |
| 5608 | * 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] | 5609 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5610 | * <p>The default implementation of this method simply applies the content |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5611 | * inset's to the view's padding, consuming that content (modifying the |
| 5612 | * insets to be 0), and returning true. This behavior is off by default, but can |
| 5613 | * be enabled through {@link #setFitsSystemWindows(boolean)}. |
| 5614 | * |
| 5615 | * <p>This function's traversal down the hierarchy is depth-first. The same content |
| 5616 | * insets object is propagated down the hierarchy, so any changes made to it will |
| 5617 | * be seen by all following views (including potentially ones above in |
| 5618 | * the hierarchy since this is a depth-first traversal). The first view |
| 5619 | * that returns true will abort the entire traversal. |
| 5620 | * |
| 5621 | * <p>The default implementation works well for a situation where it is |
| 5622 | * used with a container that covers the entire window, allowing it to |
| 5623 | * apply the appropriate insets to its content on all edges. If you need |
| 5624 | * a more complicated layout (such as two different views fitting system |
| 5625 | * windows, one on the top of the window, and one on the bottom), |
| 5626 | * you can override the method and handle the insets however you would like. |
| 5627 | * Note that the insets provided by the framework are always relative to the |
| 5628 | * far edges of the window, not accounting for the location of the called view |
| 5629 | * 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] | 5630 | * where the layout will place the view, as it is done before layout happens.) |
| 5631 | * |
| 5632 | * <p>Note: unlike many View methods, there is no dispatch phase to this |
| 5633 | * call. If you are overriding it in a ViewGroup and want to allow the |
| 5634 | * call to continue to your children, you must be sure to call the super |
| 5635 | * implementation. |
| 5636 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5637 | * <p>Here is a sample layout that makes use of fitting system windows |
| 5638 | * to have controls for a video view placed inside of the window decorations |
| 5639 | * that it hides and shows. This can be used with code like the second |
| 5640 | * sample (video player) shown in {@link #setSystemUiVisibility(int)}. |
| 5641 | * |
| 5642 | * {@sample development/samples/ApiDemos/res/layout/video_player.xml complete} |
| 5643 | * |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5644 | * @param insets Current content insets of the window. Prior to |
| 5645 | * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} you must not modify |
| 5646 | * the insets or else you and Android will be unhappy. |
| 5647 | * |
| 5648 | * @return Return true if this view applied the insets and it should not |
| 5649 | * continue propagating further down the hierarchy, false otherwise. |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5650 | * @see #getFitsSystemWindows() |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 5651 | * @see #setFitsSystemWindows(boolean) |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5652 | * @see #setSystemUiVisibility(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | */ |
| 5654 | protected boolean fitSystemWindows(Rect insets) { |
| 5655 | if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 5656 | mUserPaddingStart = UNDEFINED_PADDING; |
| 5657 | mUserPaddingEnd = UNDEFINED_PADDING; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5658 | if ((mViewFlags & OPTIONAL_FITS_SYSTEM_WINDOWS) == 0 |
| 5659 | || mAttachInfo == null |
| 5660 | || (mAttachInfo.mSystemUiVisibility & SYSTEM_UI_LAYOUT_FLAGS) == 0) { |
| 5661 | internalSetPadding(insets.left, insets.top, insets.right, insets.bottom); |
| 5662 | return true; |
| 5663 | } else { |
| 5664 | internalSetPadding(0, 0, 0, 0); |
| 5665 | return false; |
| 5666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | } |
| 5668 | return false; |
| 5669 | } |
| 5670 | |
| 5671 | /** |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5672 | * Sets whether or not this view should account for system screen decorations |
| 5673 | * such as the status bar and inset its content; that is, controlling whether |
| 5674 | * the default implementation of {@link #fitSystemWindows(Rect)} will be |
| 5675 | * executed. See that method for more details. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5676 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5677 | * <p>Note that if you are providing your own implementation of |
| 5678 | * {@link #fitSystemWindows(Rect)}, then there is no need to set this |
| 5679 | * flag to true -- your implementation will be overriding the default |
| 5680 | * implementation that checks this flag. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5681 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5682 | * @param fitSystemWindows If true, then the default implementation of |
| 5683 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5684 | * |
| 5685 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5686 | * @see #getFitsSystemWindows() |
| 5687 | * @see #fitSystemWindows(Rect) |
| 5688 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5689 | */ |
| 5690 | public void setFitsSystemWindows(boolean fitSystemWindows) { |
| 5691 | setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS); |
| 5692 | } |
| 5693 | |
| 5694 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5695 | * Check for state of {@link #setFitsSystemWindows(boolean). If this method |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5696 | * returns true, the default implementation of {@link #fitSystemWindows(Rect)} |
| 5697 | * will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5698 | * |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5699 | * @return Returns true if the default implementation of |
| 5700 | * {@link #fitSystemWindows(Rect)} will be executed. |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5701 | * |
| 5702 | * @attr ref android.R.styleable#View_fitsSystemWindows |
Dianne Hackborn | d5333f9 | 2012-05-18 10:51:35 -0700 | [diff] [blame] | 5703 | * @see #setFitsSystemWindows() |
| 5704 | * @see #fitSystemWindows(Rect) |
| 5705 | * @see #setSystemUiVisibility(int) |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5706 | */ |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5707 | public boolean getFitsSystemWindows() { |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5708 | return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS; |
| 5709 | } |
| 5710 | |
Dianne Hackborn | b1b55e6 | 2012-05-10 16:25:54 -0700 | [diff] [blame] | 5711 | /** @hide */ |
| 5712 | public boolean fitsSystemWindows() { |
| 5713 | return getFitsSystemWindows(); |
| 5714 | } |
| 5715 | |
Adam Powell | 0bd1d0a | 2011-07-22 19:35:06 -0700 | [diff] [blame] | 5716 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5717 | * Ask that a new dispatch of {@link #fitSystemWindows(Rect)} be performed. |
| 5718 | */ |
| 5719 | public void requestFitSystemWindows() { |
| 5720 | if (mParent != null) { |
| 5721 | mParent.requestFitSystemWindows(); |
| 5722 | } |
| 5723 | } |
| 5724 | |
| 5725 | /** |
| 5726 | * For use by PhoneWindow to make its own system window fitting optional. |
| 5727 | * @hide |
| 5728 | */ |
| 5729 | public void makeOptionalFitsSystemWindows() { |
| 5730 | setFlags(OPTIONAL_FITS_SYSTEM_WINDOWS, OPTIONAL_FITS_SYSTEM_WINDOWS); |
| 5731 | } |
| 5732 | |
| 5733 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5734 | * Returns the visibility status for this view. |
| 5735 | * |
| 5736 | * @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5737 | * @attr ref android.R.styleable#View_visibility |
| 5738 | */ |
| 5739 | @ViewDebug.ExportedProperty(mapping = { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5740 | @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), |
| 5741 | @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), |
| 5742 | @ViewDebug.IntToString(from = GONE, to = "GONE") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | }) |
| 5744 | public int getVisibility() { |
| 5745 | return mViewFlags & VISIBILITY_MASK; |
| 5746 | } |
| 5747 | |
| 5748 | /** |
| 5749 | * Set the enabled state of this view. |
| 5750 | * |
| 5751 | * @param visibility One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}. |
| 5752 | * @attr ref android.R.styleable#View_visibility |
| 5753 | */ |
| 5754 | @RemotableViewMethod |
| 5755 | public void setVisibility(int visibility) { |
| 5756 | setFlags(visibility, VISIBILITY_MASK); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 5757 | if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /** |
| 5761 | * Returns the enabled status for this view. The interpretation of the |
| 5762 | * enabled state varies by subclass. |
| 5763 | * |
| 5764 | * @return True if this view is enabled, false otherwise. |
| 5765 | */ |
| 5766 | @ViewDebug.ExportedProperty |
| 5767 | public boolean isEnabled() { |
| 5768 | return (mViewFlags & ENABLED_MASK) == ENABLED; |
| 5769 | } |
| 5770 | |
| 5771 | /** |
| 5772 | * Set the enabled state of this view. The interpretation of the enabled |
| 5773 | * state varies by subclass. |
| 5774 | * |
| 5775 | * @param enabled True if this view is enabled, false otherwise. |
| 5776 | */ |
Jeff Sharkey | 2b95c24 | 2010-02-08 17:40:30 -0800 | [diff] [blame] | 5777 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | public void setEnabled(boolean enabled) { |
Amith Yamasani | a2ef00b | 2009-07-30 16:14:34 -0700 | [diff] [blame] | 5779 | if (enabled == isEnabled()) return; |
| 5780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5781 | setFlags(enabled ? ENABLED : DISABLED, ENABLED_MASK); |
| 5782 | |
| 5783 | /* |
| 5784 | * The View most likely has to change its appearance, so refresh |
| 5785 | * the drawable state. |
| 5786 | */ |
| 5787 | refreshDrawableState(); |
| 5788 | |
| 5789 | // Invalidate too, since the default behavior for views is to be |
| 5790 | // be drawn at 50% alpha rather than to change the drawable. |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 5791 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | } |
| 5793 | |
| 5794 | /** |
| 5795 | * Set whether this view can receive the focus. |
| 5796 | * |
| 5797 | * Setting this to false will also ensure that this view is not focusable |
| 5798 | * in touch mode. |
| 5799 | * |
| 5800 | * @param focusable If true, this view can receive the focus. |
| 5801 | * |
| 5802 | * @see #setFocusableInTouchMode(boolean) |
| 5803 | * @attr ref android.R.styleable#View_focusable |
| 5804 | */ |
| 5805 | public void setFocusable(boolean focusable) { |
| 5806 | if (!focusable) { |
| 5807 | setFlags(0, FOCUSABLE_IN_TOUCH_MODE); |
| 5808 | } |
| 5809 | setFlags(focusable ? FOCUSABLE : NOT_FOCUSABLE, FOCUSABLE_MASK); |
| 5810 | } |
| 5811 | |
| 5812 | /** |
| 5813 | * Set whether this view can receive focus while in touch mode. |
| 5814 | * |
| 5815 | * Setting this to true will also ensure that this view is focusable. |
| 5816 | * |
| 5817 | * @param focusableInTouchMode If true, this view can receive the focus while |
| 5818 | * in touch mode. |
| 5819 | * |
| 5820 | * @see #setFocusable(boolean) |
| 5821 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 5822 | */ |
| 5823 | public void setFocusableInTouchMode(boolean focusableInTouchMode) { |
| 5824 | // Focusable in touch mode should always be set before the focusable flag |
| 5825 | // otherwise, setting the focusable flag will trigger a focusableViewAvailable() |
| 5826 | // which, in touch mode, will not successfully request focus on this view |
| 5827 | // because the focusable in touch mode flag is not set |
| 5828 | setFlags(focusableInTouchMode ? FOCUSABLE_IN_TOUCH_MODE : 0, FOCUSABLE_IN_TOUCH_MODE); |
| 5829 | if (focusableInTouchMode) { |
| 5830 | setFlags(FOCUSABLE, FOCUSABLE_MASK); |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | /** |
| 5835 | * Set whether this view should have sound effects enabled for events such as |
| 5836 | * clicking and touching. |
| 5837 | * |
| 5838 | * <p>You may wish to disable sound effects for a view if you already play sounds, |
| 5839 | * for instance, a dial key that plays dtmf tones. |
| 5840 | * |
| 5841 | * @param soundEffectsEnabled whether sound effects are enabled for this view. |
| 5842 | * @see #isSoundEffectsEnabled() |
| 5843 | * @see #playSoundEffect(int) |
| 5844 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5845 | */ |
| 5846 | public void setSoundEffectsEnabled(boolean soundEffectsEnabled) { |
| 5847 | setFlags(soundEffectsEnabled ? SOUND_EFFECTS_ENABLED: 0, SOUND_EFFECTS_ENABLED); |
| 5848 | } |
| 5849 | |
| 5850 | /** |
| 5851 | * @return whether this view should have sound effects enabled for events such as |
| 5852 | * clicking and touching. |
| 5853 | * |
| 5854 | * @see #setSoundEffectsEnabled(boolean) |
| 5855 | * @see #playSoundEffect(int) |
| 5856 | * @attr ref android.R.styleable#View_soundEffectsEnabled |
| 5857 | */ |
| 5858 | @ViewDebug.ExportedProperty |
| 5859 | public boolean isSoundEffectsEnabled() { |
| 5860 | return SOUND_EFFECTS_ENABLED == (mViewFlags & SOUND_EFFECTS_ENABLED); |
| 5861 | } |
| 5862 | |
| 5863 | /** |
| 5864 | * Set whether this view should have haptic feedback for events such as |
| 5865 | * long presses. |
| 5866 | * |
| 5867 | * <p>You may wish to disable haptic feedback if your view already controls |
| 5868 | * its own haptic feedback. |
| 5869 | * |
| 5870 | * @param hapticFeedbackEnabled whether haptic feedback enabled for this view. |
| 5871 | * @see #isHapticFeedbackEnabled() |
| 5872 | * @see #performHapticFeedback(int) |
| 5873 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5874 | */ |
| 5875 | public void setHapticFeedbackEnabled(boolean hapticFeedbackEnabled) { |
| 5876 | setFlags(hapticFeedbackEnabled ? HAPTIC_FEEDBACK_ENABLED: 0, HAPTIC_FEEDBACK_ENABLED); |
| 5877 | } |
| 5878 | |
| 5879 | /** |
| 5880 | * @return whether this view should have haptic feedback enabled for events |
| 5881 | * long presses. |
| 5882 | * |
| 5883 | * @see #setHapticFeedbackEnabled(boolean) |
| 5884 | * @see #performHapticFeedback(int) |
| 5885 | * @attr ref android.R.styleable#View_hapticFeedbackEnabled |
| 5886 | */ |
| 5887 | @ViewDebug.ExportedProperty |
| 5888 | public boolean isHapticFeedbackEnabled() { |
| 5889 | return HAPTIC_FEEDBACK_ENABLED == (mViewFlags & HAPTIC_FEEDBACK_ENABLED); |
| 5890 | } |
| 5891 | |
| 5892 | /** |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5893 | * Returns the layout direction for this view. |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5894 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5895 | * @return One of {@link #LAYOUT_DIRECTION_LTR}, |
| 5896 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5897 | * {@link #LAYOUT_DIRECTION_INHERIT} or |
| 5898 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 5899 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5900 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5901 | * |
| 5902 | * @hide |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5903 | */ |
Fabrice Di Meglio | bce84d2 | 2011-06-02 15:57:01 -0700 | [diff] [blame] | 5904 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5905 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "LTR"), |
| 5906 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RTL"), |
| 5907 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), |
| 5908 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5909 | }) |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5910 | public int getRawLayoutDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5911 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | /** |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5915 | * Set the layout direction for this view. This will propagate a reset of layout direction |
| 5916 | * 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] | 5917 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5918 | * @param layoutDirection the layout direction to set. Should be one of: |
| 5919 | * |
| 5920 | * {@link #LAYOUT_DIRECTION_LTR}, |
| 5921 | * {@link #LAYOUT_DIRECTION_RTL}, |
| 5922 | * {@link #LAYOUT_DIRECTION_INHERIT}, |
| 5923 | * {@link #LAYOUT_DIRECTION_LOCALE}. |
| 5924 | * |
| 5925 | * Resolution will be done if the value is set to LAYOUT_DIRECTION_INHERIT. The resolution |
| 5926 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 5927 | * will return the default {@link #LAYOUT_DIRECTION_LTR}. |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5928 | * |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5929 | * @attr ref android.R.styleable#View_layoutDirection |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5930 | */ |
| 5931 | @RemotableViewMethod |
Fabrice Di Meglio | c46f7ff | 2011-06-06 18:23:10 -0700 | [diff] [blame] | 5932 | public void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5933 | if (getRawLayoutDirection() != layoutDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 5934 | // Reset the current layout direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5935 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 5936 | resetRtlProperties(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5937 | // Set the new layout direction (filtered) |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5938 | mPrivateFlags2 |= |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5939 | ((layoutDirection << PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) & PFLAG2_LAYOUT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5940 | // We need to resolve all RTL properties as they all depend on layout direction |
| 5941 | resolveRtlPropertiesIfNeeded(); |
Fabrice Di Meglio | acb1c12 | 2012-10-02 14:18:55 -0700 | [diff] [blame] | 5942 | requestLayout(); |
| 5943 | invalidate(true); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 5944 | } |
Cibu Johny | 7632cb9 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | /** |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5948 | * Returns the resolved layout direction for this view. |
| 5949 | * |
| 5950 | * @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] | 5951 | * {@link #LAYOUT_DIRECTION_LTR} if the layout direction is not RTL. |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5952 | * |
| 5953 | * For compatibility, this will return {@link #LAYOUT_DIRECTION_LTR} if API version |
| 5954 | * is lower than {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 5955 | * |
| 5956 | * @attr ref android.R.styleable#View_layoutDirection |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5957 | */ |
| 5958 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5959 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), |
| 5960 | @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5961 | }) |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5962 | public int getLayoutDirection() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5963 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 5964 | if (targetSdkVersion < JELLY_BEAN_MR1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5965 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 5966 | return LAYOUT_DIRECTION_LTR; |
| 5967 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 5968 | return ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) == |
| 5969 | PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | /** |
Fabrice Di Meglio | edc1e59 | 2012-03-15 17:28:47 -0700 | [diff] [blame] | 5973 | * Indicates whether or not this view's layout is right-to-left. This is resolved from |
| 5974 | * layout attribute and/or the inherited value from the parent |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5975 | * |
| 5976 | * @return true if the layout is right-to-left. |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 5977 | * |
| 5978 | * @hide |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5979 | */ |
| 5980 | @ViewDebug.ExportedProperty(category = "layout") |
| 5981 | public boolean isLayoutRtl() { |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 5982 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5986 | * Indicates whether the view is currently tracking transient state that the |
| 5987 | * app should not need to concern itself with saving and restoring, but that |
| 5988 | * the framework should take special note to preserve when possible. |
| 5989 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 5990 | * <p>A view with transient state cannot be trivially rebound from an external |
| 5991 | * data source, such as an adapter binding item views in a list. This may be |
| 5992 | * because the view is performing an animation, tracking user selection |
| 5993 | * of content, or similar.</p> |
| 5994 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5995 | * @return true if the view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5996 | */ |
| 5997 | @ViewDebug.ExportedProperty(category = "layout") |
| 5998 | public boolean hasTransientState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5999 | return (mPrivateFlags2 & PFLAG2_HAS_TRANSIENT_STATE) == PFLAG2_HAS_TRANSIENT_STATE; |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | /** |
| 6003 | * Set whether this view is currently tracking transient state that the |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 6004 | * framework should attempt to preserve when possible. This flag is reference counted, |
| 6005 | * so every call to setHasTransientState(true) should be paired with a later call |
| 6006 | * to setHasTransientState(false). |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6007 | * |
Adam Powell | 785c447 | 2012-05-02 21:25:39 -0700 | [diff] [blame] | 6008 | * <p>A view with transient state cannot be trivially rebound from an external |
| 6009 | * data source, such as an adapter binding item views in a list. This may be |
| 6010 | * because the view is performing an animation, tracking user selection |
| 6011 | * of content, or similar.</p> |
| 6012 | * |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6013 | * @param hasTransientState true if this view has transient state |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6014 | */ |
| 6015 | public void setHasTransientState(boolean hasTransientState) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 6016 | mTransientStateCount = hasTransientState ? mTransientStateCount + 1 : |
| 6017 | mTransientStateCount - 1; |
| 6018 | if (mTransientStateCount < 0) { |
| 6019 | mTransientStateCount = 0; |
| 6020 | Log.e(VIEW_LOG_TAG, "hasTransientState decremented below 0: " + |
| 6021 | "unmatched pair of setHasTransientState calls"); |
| 6022 | } |
| 6023 | if ((hasTransientState && mTransientStateCount == 1) || |
Adam Powell | 057a585 | 2012-05-11 10:28:38 -0700 | [diff] [blame] | 6024 | (!hasTransientState && mTransientStateCount == 0)) { |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 6025 | // 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] | 6026 | mPrivateFlags2 = (mPrivateFlags2 & ~PFLAG2_HAS_TRANSIENT_STATE) | |
| 6027 | (hasTransientState ? PFLAG2_HAS_TRANSIENT_STATE : 0); |
Chet Haase | 563d4f2 | 2012-04-18 16:20:08 -0700 | [diff] [blame] | 6028 | if (mParent != null) { |
| 6029 | try { |
| 6030 | mParent.childHasTransientStateChanged(this, hasTransientState); |
| 6031 | } catch (AbstractMethodError e) { |
| 6032 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 6033 | " does not fully implement ViewParent", e); |
| 6034 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6035 | } |
| 6036 | } |
| 6037 | } |
| 6038 | |
| 6039 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6040 | * If this view doesn't do any drawing on its own, set this flag to |
| 6041 | * allow further optimizations. By default, this flag is not set on |
| 6042 | * View, but could be set on some View subclasses such as ViewGroup. |
| 6043 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6044 | * Typically, if you override {@link #onDraw(android.graphics.Canvas)} |
| 6045 | * you should clear this flag. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6046 | * |
| 6047 | * @param willNotDraw whether or not this View draw on its own |
| 6048 | */ |
| 6049 | public void setWillNotDraw(boolean willNotDraw) { |
| 6050 | setFlags(willNotDraw ? WILL_NOT_DRAW : 0, DRAW_MASK); |
| 6051 | } |
| 6052 | |
| 6053 | /** |
| 6054 | * Returns whether or not this View draws on its own. |
| 6055 | * |
| 6056 | * @return true if this view has nothing to draw, false otherwise |
| 6057 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6058 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6059 | public boolean willNotDraw() { |
| 6060 | return (mViewFlags & DRAW_MASK) == WILL_NOT_DRAW; |
| 6061 | } |
| 6062 | |
| 6063 | /** |
| 6064 | * When a View's drawing cache is enabled, drawing is redirected to an |
| 6065 | * offscreen bitmap. Some views, like an ImageView, must be able to |
| 6066 | * bypass this mechanism if they already draw a single bitmap, to avoid |
| 6067 | * unnecessary usage of the memory. |
| 6068 | * |
| 6069 | * @param willNotCacheDrawing true if this view does not cache its |
| 6070 | * drawing, false otherwise |
| 6071 | */ |
| 6072 | public void setWillNotCacheDrawing(boolean willNotCacheDrawing) { |
| 6073 | setFlags(willNotCacheDrawing ? WILL_NOT_CACHE_DRAWING : 0, WILL_NOT_CACHE_DRAWING); |
| 6074 | } |
| 6075 | |
| 6076 | /** |
| 6077 | * Returns whether or not this View can cache its drawing or not. |
| 6078 | * |
| 6079 | * @return true if this view does not cache its drawing, false otherwise |
| 6080 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6081 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6082 | public boolean willNotCacheDrawing() { |
| 6083 | return (mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING; |
| 6084 | } |
| 6085 | |
| 6086 | /** |
| 6087 | * Indicates whether this view reacts to click events or not. |
| 6088 | * |
| 6089 | * @return true if the view is clickable, false otherwise |
| 6090 | * |
| 6091 | * @see #setClickable(boolean) |
| 6092 | * @attr ref android.R.styleable#View_clickable |
| 6093 | */ |
| 6094 | @ViewDebug.ExportedProperty |
| 6095 | public boolean isClickable() { |
| 6096 | return (mViewFlags & CLICKABLE) == CLICKABLE; |
| 6097 | } |
| 6098 | |
| 6099 | /** |
| 6100 | * Enables or disables click events for this view. When a view |
| 6101 | * is clickable it will change its state to "pressed" on every click. |
| 6102 | * Subclasses should set the view clickable to visually react to |
| 6103 | * user's clicks. |
| 6104 | * |
| 6105 | * @param clickable true to make the view clickable, false otherwise |
| 6106 | * |
| 6107 | * @see #isClickable() |
| 6108 | * @attr ref android.R.styleable#View_clickable |
| 6109 | */ |
| 6110 | public void setClickable(boolean clickable) { |
| 6111 | setFlags(clickable ? CLICKABLE : 0, CLICKABLE); |
| 6112 | } |
| 6113 | |
| 6114 | /** |
| 6115 | * Indicates whether this view reacts to long click events or not. |
| 6116 | * |
| 6117 | * @return true if the view is long clickable, false otherwise |
| 6118 | * |
| 6119 | * @see #setLongClickable(boolean) |
| 6120 | * @attr ref android.R.styleable#View_longClickable |
| 6121 | */ |
| 6122 | public boolean isLongClickable() { |
| 6123 | return (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 6124 | } |
| 6125 | |
| 6126 | /** |
| 6127 | * Enables or disables long click events for this view. When a view is long |
| 6128 | * clickable it reacts to the user holding down the button for a longer |
| 6129 | * duration than a tap. This event can either launch the listener or a |
| 6130 | * context menu. |
| 6131 | * |
| 6132 | * @param longClickable true to make the view long clickable, false otherwise |
| 6133 | * @see #isLongClickable() |
| 6134 | * @attr ref android.R.styleable#View_longClickable |
| 6135 | */ |
| 6136 | public void setLongClickable(boolean longClickable) { |
| 6137 | setFlags(longClickable ? LONG_CLICKABLE : 0, LONG_CLICKABLE); |
| 6138 | } |
| 6139 | |
| 6140 | /** |
Chet Haase | 49afa5b | 2010-08-23 11:39:53 -0700 | [diff] [blame] | 6141 | * Sets the pressed state for this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | * |
| 6143 | * @see #isClickable() |
| 6144 | * @see #setClickable(boolean) |
| 6145 | * |
| 6146 | * @param pressed Pass true to set the View's internal state to "pressed", or false to reverts |
| 6147 | * the View's internal state from a previously set "pressed" state. |
| 6148 | */ |
| 6149 | public void setPressed(boolean pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6150 | final boolean needsRefresh = pressed != ((mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED); |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 6151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | if (pressed) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6153 | mPrivateFlags |= PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6155 | mPrivateFlags &= ~PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6156 | } |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 6157 | |
| 6158 | if (needsRefresh) { |
| 6159 | refreshDrawableState(); |
| 6160 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | dispatchSetPressed(pressed); |
| 6162 | } |
| 6163 | |
| 6164 | /** |
| 6165 | * Dispatch setPressed to all of this View's children. |
| 6166 | * |
| 6167 | * @see #setPressed(boolean) |
| 6168 | * |
| 6169 | * @param pressed The new pressed state |
| 6170 | */ |
| 6171 | protected void dispatchSetPressed(boolean pressed) { |
| 6172 | } |
| 6173 | |
| 6174 | /** |
| 6175 | * Indicates whether the view is currently in pressed state. Unless |
| 6176 | * {@link #setPressed(boolean)} is explicitly called, only clickable views can enter |
| 6177 | * the pressed state. |
| 6178 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 6179 | * @see #setPressed(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | * @see #isClickable() |
| 6181 | * @see #setClickable(boolean) |
| 6182 | * |
| 6183 | * @return true if the view is currently pressed, false otherwise |
| 6184 | */ |
| 6185 | public boolean isPressed() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6186 | return (mPrivateFlags & PFLAG_PRESSED) == PFLAG_PRESSED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | /** |
| 6190 | * Indicates whether this view will save its state (that is, |
| 6191 | * whether its {@link #onSaveInstanceState} method will be called). |
| 6192 | * |
| 6193 | * @return Returns true if the view state saving is enabled, else false. |
| 6194 | * |
| 6195 | * @see #setSaveEnabled(boolean) |
| 6196 | * @attr ref android.R.styleable#View_saveEnabled |
| 6197 | */ |
| 6198 | public boolean isSaveEnabled() { |
| 6199 | return (mViewFlags & SAVE_DISABLED_MASK) != SAVE_DISABLED; |
| 6200 | } |
| 6201 | |
| 6202 | /** |
| 6203 | * Controls whether the saving of this view's state is |
| 6204 | * enabled (that is, whether its {@link #onSaveInstanceState} method |
| 6205 | * will be called). Note that even if freezing is enabled, the |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6206 | * 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] | 6207 | * for its state to be saved. This flag can only disable the |
| 6208 | * saving of this view; any child views may still have their state saved. |
| 6209 | * |
| 6210 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6211 | * (the default) to allow it. |
| 6212 | * |
| 6213 | * @see #isSaveEnabled() |
| 6214 | * @see #setId(int) |
| 6215 | * @see #onSaveInstanceState() |
| 6216 | * @attr ref android.R.styleable#View_saveEnabled |
| 6217 | */ |
| 6218 | public void setSaveEnabled(boolean enabled) { |
| 6219 | setFlags(enabled ? 0 : SAVE_DISABLED, SAVE_DISABLED_MASK); |
| 6220 | } |
| 6221 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6222 | /** |
| 6223 | * Gets whether the framework should discard touches when the view's |
| 6224 | * window is obscured by another visible window. |
| 6225 | * Refer to the {@link View} security documentation for more details. |
| 6226 | * |
| 6227 | * @return True if touch filtering is enabled. |
| 6228 | * |
| 6229 | * @see #setFilterTouchesWhenObscured(boolean) |
| 6230 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6231 | */ |
| 6232 | @ViewDebug.ExportedProperty |
| 6233 | public boolean getFilterTouchesWhenObscured() { |
| 6234 | return (mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0; |
| 6235 | } |
| 6236 | |
| 6237 | /** |
| 6238 | * Sets whether the framework should discard touches when the view's |
| 6239 | * window is obscured by another visible window. |
| 6240 | * Refer to the {@link View} security documentation for more details. |
| 6241 | * |
| 6242 | * @param enabled True if touch filtering should be enabled. |
| 6243 | * |
| 6244 | * @see #getFilterTouchesWhenObscured |
| 6245 | * @attr ref android.R.styleable#View_filterTouchesWhenObscured |
| 6246 | */ |
| 6247 | public void setFilterTouchesWhenObscured(boolean enabled) { |
| 6248 | setFlags(enabled ? 0 : FILTER_TOUCHES_WHEN_OBSCURED, |
| 6249 | FILTER_TOUCHES_WHEN_OBSCURED); |
| 6250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6251 | |
| 6252 | /** |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 6253 | * Indicates whether the entire hierarchy under this view will save its |
| 6254 | * state when a state saving traversal occurs from its parent. The default |
| 6255 | * is true; if false, these views will not be saved unless |
| 6256 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6257 | * |
| 6258 | * @return Returns true if the view state saving from parent is enabled, else false. |
| 6259 | * |
| 6260 | * @see #setSaveFromParentEnabled(boolean) |
| 6261 | */ |
| 6262 | public boolean isSaveFromParentEnabled() { |
| 6263 | return (mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED; |
| 6264 | } |
| 6265 | |
| 6266 | /** |
| 6267 | * Controls whether the entire hierarchy under this view will save its |
| 6268 | * state when a state saving traversal occurs from its parent. The default |
| 6269 | * is true; if false, these views will not be saved unless |
| 6270 | * {@link #saveHierarchyState(SparseArray)} is called directly on this view. |
| 6271 | * |
| 6272 | * @param enabled Set to false to <em>disable</em> state saving, or true |
| 6273 | * (the default) to allow it. |
| 6274 | * |
| 6275 | * @see #isSaveFromParentEnabled() |
| 6276 | * @see #setId(int) |
| 6277 | * @see #onSaveInstanceState() |
| 6278 | */ |
| 6279 | public void setSaveFromParentEnabled(boolean enabled) { |
| 6280 | setFlags(enabled ? 0 : PARENT_SAVE_DISABLED, PARENT_SAVE_DISABLED_MASK); |
| 6281 | } |
| 6282 | |
| 6283 | |
| 6284 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | * Returns whether this View is able to take focus. |
| 6286 | * |
| 6287 | * @return True if this view can take focus, or false otherwise. |
| 6288 | * @attr ref android.R.styleable#View_focusable |
| 6289 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6290 | @ViewDebug.ExportedProperty(category = "focus") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6291 | public final boolean isFocusable() { |
| 6292 | return FOCUSABLE == (mViewFlags & FOCUSABLE_MASK); |
| 6293 | } |
| 6294 | |
| 6295 | /** |
| 6296 | * When a view is focusable, it may not want to take focus when in touch mode. |
| 6297 | * For example, a button would like focus when the user is navigating via a D-pad |
| 6298 | * so that the user can click on it, but once the user starts touching the screen, |
| 6299 | * the button shouldn't take focus |
| 6300 | * @return Whether the view is focusable in touch mode. |
| 6301 | * @attr ref android.R.styleable#View_focusableInTouchMode |
| 6302 | */ |
| 6303 | @ViewDebug.ExportedProperty |
| 6304 | public final boolean isFocusableInTouchMode() { |
| 6305 | return FOCUSABLE_IN_TOUCH_MODE == (mViewFlags & FOCUSABLE_IN_TOUCH_MODE); |
| 6306 | } |
| 6307 | |
| 6308 | /** |
| 6309 | * Find the nearest view in the specified direction that can take focus. |
| 6310 | * This does not actually give focus to that view. |
| 6311 | * |
| 6312 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6313 | * |
| 6314 | * @return The nearest focusable in the specified direction, or null if none |
| 6315 | * can be found. |
| 6316 | */ |
| 6317 | public View focusSearch(int direction) { |
| 6318 | if (mParent != null) { |
| 6319 | return mParent.focusSearch(this, direction); |
| 6320 | } else { |
| 6321 | return null; |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | /** |
| 6326 | * This method is the last chance for the focused view and its ancestors to |
| 6327 | * respond to an arrow key. This is called when the focused view did not |
| 6328 | * consume the key internally, nor could the view system find a new view in |
| 6329 | * the requested direction to give focus to. |
| 6330 | * |
| 6331 | * @param focused The currently focused view. |
| 6332 | * @param direction The direction focus wants to move. One of FOCUS_UP, |
| 6333 | * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. |
| 6334 | * @return True if the this view consumed this unhandled move. |
| 6335 | */ |
| 6336 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 6337 | return false; |
| 6338 | } |
| 6339 | |
| 6340 | /** |
| 6341 | * 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] | 6342 | * use the root to look up the view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6343 | * @param root The root view of the hierarchy containing this view. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6344 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, |
| 6345 | * or FOCUS_BACKWARD. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | * @return The user specified next view, or null if there is none. |
| 6347 | */ |
| 6348 | View findUserSetNextFocus(View root, int direction) { |
| 6349 | switch (direction) { |
| 6350 | case FOCUS_LEFT: |
| 6351 | if (mNextFocusLeftId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6352 | return findViewInsideOutShouldExist(root, mNextFocusLeftId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6353 | case FOCUS_RIGHT: |
| 6354 | if (mNextFocusRightId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6355 | return findViewInsideOutShouldExist(root, mNextFocusRightId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | case FOCUS_UP: |
| 6357 | if (mNextFocusUpId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6358 | return findViewInsideOutShouldExist(root, mNextFocusUpId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | case FOCUS_DOWN: |
| 6360 | if (mNextFocusDownId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6361 | return findViewInsideOutShouldExist(root, mNextFocusDownId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6362 | case FOCUS_FORWARD: |
| 6363 | if (mNextFocusForwardId == View.NO_ID) return null; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6364 | return findViewInsideOutShouldExist(root, mNextFocusForwardId); |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6365 | case FOCUS_BACKWARD: { |
John Reck | 1ecebbb | 2012-03-06 16:08:54 -0800 | [diff] [blame] | 6366 | if (mID == View.NO_ID) return null; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6367 | final int id = mID; |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 6368 | return root.findViewByPredicateInsideOut(this, new Predicate<View>() { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 6369 | @Override |
| 6370 | public boolean apply(View t) { |
| 6371 | return t.mNextFocusForwardId == id; |
| 6372 | } |
| 6373 | }); |
| 6374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | } |
| 6376 | return null; |
| 6377 | } |
| 6378 | |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6379 | private View findViewInsideOutShouldExist(View root, int id) { |
| 6380 | if (mMatchIdPredicate == null) { |
| 6381 | mMatchIdPredicate = new MatchIdPredicate(); |
| 6382 | } |
| 6383 | mMatchIdPredicate.mId = id; |
| 6384 | View result = root.findViewByPredicateInsideOut(this, mMatchIdPredicate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | if (result == null) { |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 6386 | Log.w(VIEW_LOG_TAG, "couldn't find view with id " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | } |
| 6388 | return result; |
| 6389 | } |
| 6390 | |
| 6391 | /** |
| 6392 | * Find and return all focusable views that are descendants of this view, |
| 6393 | * possibly including this view if it is focusable itself. |
| 6394 | * |
| 6395 | * @param direction The direction of the focus |
| 6396 | * @return A list of focusable views |
| 6397 | */ |
| 6398 | public ArrayList<View> getFocusables(int direction) { |
| 6399 | ArrayList<View> result = new ArrayList<View>(24); |
| 6400 | addFocusables(result, direction); |
| 6401 | return result; |
| 6402 | } |
| 6403 | |
| 6404 | /** |
| 6405 | * Add any focusable views that are descendants of this view (possibly |
| 6406 | * including this view if it is focusable itself) to views. If we are in touch mode, |
| 6407 | * only add views that are also focusable in touch mode. |
| 6408 | * |
| 6409 | * @param views Focusable views found so far |
| 6410 | * @param direction The direction of the focus |
| 6411 | */ |
| 6412 | public void addFocusables(ArrayList<View> views, int direction) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6413 | addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); |
| 6414 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6416 | /** |
| 6417 | * Adds any focusable views that are descendants of this view (possibly |
| 6418 | * including this view if it is focusable itself) to views. This method |
| 6419 | * adds all focusable views regardless if we are in touch mode or |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6420 | * only views focusable in touch mode if we are in touch mode or |
| 6421 | * only views that can take accessibility focus if accessibility is enabeld |
| 6422 | * depending on the focusable mode paramater. |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6423 | * |
| 6424 | * @param views Focusable views found so far or null if all we are interested is |
| 6425 | * the number of focusables. |
| 6426 | * @param direction The direction of the focus. |
| 6427 | * @param focusableMode The type of focusables to be added. |
| 6428 | * |
| 6429 | * @see #FOCUSABLES_ALL |
| 6430 | * @see #FOCUSABLES_TOUCH_MODE |
| 6431 | */ |
| 6432 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6433 | if (views == null) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6434 | return; |
| 6435 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6436 | if (!isFocusable()) { |
| 6437 | return; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6438 | } |
Svetoslav Ganov | 3cb889c | 2012-04-16 19:10:30 -0700 | [diff] [blame] | 6439 | if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE |
| 6440 | && isInTouchMode() && !isFocusableInTouchMode()) { |
| 6441 | return; |
| 6442 | } |
| 6443 | views.add(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6447 | * Finds the Views that contain given text. The containment is case insensitive. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6448 | * The search is performed by either the text that the View renders or the content |
| 6449 | * description that describes the view for accessibility purposes and the view does |
| 6450 | * not render or both. Clients can specify how the search is to be performed via |
| 6451 | * passing the {@link #FIND_VIEWS_WITH_TEXT} and |
| 6452 | * {@link #FIND_VIEWS_WITH_CONTENT_DESCRIPTION} flags. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6453 | * |
| 6454 | * @param outViews The output list of matching Views. |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6455 | * @param searched The text to match against. |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6456 | * |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6457 | * @see #FIND_VIEWS_WITH_TEXT |
| 6458 | * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION |
| 6459 | * @see #setContentDescription(CharSequence) |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6460 | */ |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6461 | public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 6462 | if (getAccessibilityNodeProvider() != null) { |
| 6463 | if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { |
| 6464 | outViews.add(this); |
| 6465 | } |
| 6466 | } else if ((flags & FIND_VIEWS_WITH_CONTENT_DESCRIPTION) != 0 |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6467 | && (searched != null && searched.length() > 0) |
| 6468 | && (mContentDescription != null && mContentDescription.length() > 0)) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 6469 | String searchedLowerCase = searched.toString().toLowerCase(); |
| 6470 | String contentDescriptionLowerCase = mContentDescription.toString().toLowerCase(); |
| 6471 | if (contentDescriptionLowerCase.contains(searchedLowerCase)) { |
| 6472 | outViews.add(this); |
| 6473 | } |
| 6474 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6478 | * Find and return all touchable views that are descendants of this view, |
| 6479 | * possibly including this view if it is touchable itself. |
| 6480 | * |
| 6481 | * @return A list of touchable views |
| 6482 | */ |
| 6483 | public ArrayList<View> getTouchables() { |
| 6484 | ArrayList<View> result = new ArrayList<View>(); |
| 6485 | addTouchables(result); |
| 6486 | return result; |
| 6487 | } |
| 6488 | |
| 6489 | /** |
| 6490 | * Add any touchable views that are descendants of this view (possibly |
| 6491 | * including this view if it is touchable itself) to views. |
| 6492 | * |
| 6493 | * @param views Touchable views found so far |
| 6494 | */ |
| 6495 | public void addTouchables(ArrayList<View> views) { |
| 6496 | final int viewFlags = mViewFlags; |
| 6497 | |
| 6498 | if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) |
| 6499 | && (viewFlags & ENABLED_MASK) == ENABLED) { |
| 6500 | views.add(this); |
| 6501 | } |
| 6502 | } |
| 6503 | |
| 6504 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6505 | * Returns whether this View is accessibility focused. |
| 6506 | * |
| 6507 | * @return True if this View is accessibility focused. |
| 6508 | */ |
| 6509 | boolean isAccessibilityFocused() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6510 | return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6511 | } |
| 6512 | |
| 6513 | /** |
| 6514 | * Call this to try to give accessibility focus to this view. |
| 6515 | * |
| 6516 | * A view will not actually take focus if {@link AccessibilityManager#isEnabled()} |
| 6517 | * returns false or the view is no visible or the view already has accessibility |
| 6518 | * focus. |
| 6519 | * |
| 6520 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6521 | * have focus, and you want your parent to look for the next one. |
| 6522 | * |
| 6523 | * @return Whether this view actually took accessibility focus. |
| 6524 | * |
| 6525 | * @hide |
| 6526 | */ |
| 6527 | public boolean requestAccessibilityFocus() { |
Svetoslav Ganov | 07b726c | 2012-04-30 12:24:57 -0700 | [diff] [blame] | 6528 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 6529 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6530 | return false; |
| 6531 | } |
| 6532 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6533 | return false; |
| 6534 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6535 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) == 0) { |
| 6536 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6537 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6538 | if (viewRootImpl != null) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6539 | viewRootImpl.setAccessibilityFocus(this, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6540 | } |
| 6541 | invalidate(); |
| 6542 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED); |
| 6543 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6544 | return true; |
| 6545 | } |
| 6546 | return false; |
| 6547 | } |
| 6548 | |
| 6549 | /** |
| 6550 | * Call this to try to clear accessibility focus of this view. |
| 6551 | * |
| 6552 | * See also {@link #focusSearch(int)}, which is what you call to say that you |
| 6553 | * have focus, and you want your parent to look for the next one. |
| 6554 | * |
| 6555 | * @hide |
| 6556 | */ |
| 6557 | public void clearAccessibilityFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6558 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6559 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6560 | invalidate(); |
| 6561 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED); |
| 6562 | notifyAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6563 | } |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6564 | // Clear the global reference of accessibility focus if this |
| 6565 | // view or any of its descendants had accessibility focus. |
| 6566 | ViewRootImpl viewRootImpl = getViewRootImpl(); |
| 6567 | if (viewRootImpl != null) { |
| 6568 | View focusHost = viewRootImpl.getAccessibilityFocusedHost(); |
| 6569 | if (focusHost != null && ViewRootImpl.isViewDescendantOf(focusHost, this)) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6570 | viewRootImpl.setAccessibilityFocus(null, null); |
Svetoslav Ganov | c00d008 | 2012-05-22 18:37:49 -0700 | [diff] [blame] | 6571 | } |
| 6572 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6573 | } |
| 6574 | |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 6575 | private void sendAccessibilityHoverEvent(int eventType) { |
| 6576 | // Since we are not delivering to a client accessibility events from not |
| 6577 | // important views (unless the clinet request that) we need to fire the |
| 6578 | // event from the deepest view exposed to the client. As a consequence if |
| 6579 | // the user crosses a not exposed view the client will see enter and exit |
| 6580 | // of the exposed predecessor followed by and enter and exit of that same |
| 6581 | // predecessor when entering and exiting the not exposed descendant. This |
| 6582 | // is fine since the client has a clear idea which view is hovered at the |
| 6583 | // price of a couple more events being sent. This is a simple and |
| 6584 | // working solution. |
| 6585 | View source = this; |
| 6586 | while (true) { |
| 6587 | if (source.includeForAccessibility()) { |
| 6588 | source.sendAccessibilityEvent(eventType); |
| 6589 | return; |
| 6590 | } |
| 6591 | ViewParent parent = source.getParent(); |
| 6592 | if (parent instanceof View) { |
| 6593 | source = (View) parent; |
| 6594 | } else { |
| 6595 | return; |
| 6596 | } |
| 6597 | } |
| 6598 | } |
| 6599 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6600 | /** |
| 6601 | * Clears accessibility focus without calling any callback methods |
| 6602 | * normally invoked in {@link #clearAccessibilityFocus()}. This method |
| 6603 | * is used for clearing accessibility focus when giving this focus to |
| 6604 | * another view. |
| 6605 | */ |
| 6606 | void clearAccessibilityFocusNoCallbacks() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6607 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) { |
| 6608 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6609 | invalidate(); |
| 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6614 | * Call this to try to give focus to a specific view or to one of its |
| 6615 | * descendants. |
| 6616 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6617 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6618 | * false), or if it is focusable and it is not focusable in touch mode |
| 6619 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6621 | * 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] | 6622 | * have focus, and you want your parent to look for the next one. |
| 6623 | * |
| 6624 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with arguments |
| 6625 | * {@link #FOCUS_DOWN} and <code>null</code>. |
| 6626 | * |
| 6627 | * @return Whether this view or one of its descendants actually took focus. |
| 6628 | */ |
| 6629 | public final boolean requestFocus() { |
| 6630 | return requestFocus(View.FOCUS_DOWN); |
| 6631 | } |
| 6632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | /** |
| 6634 | * Call this to try to give focus to a specific view or to one of its |
| 6635 | * descendants and give it a hint about what direction focus is heading. |
| 6636 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6637 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6638 | * false), or if it is focusable and it is not focusable in touch mode |
| 6639 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6640 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6641 | * 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] | 6642 | * have focus, and you want your parent to look for the next one. |
| 6643 | * |
| 6644 | * This is equivalent to calling {@link #requestFocus(int, Rect)} with |
| 6645 | * <code>null</code> set for the previously focused rectangle. |
| 6646 | * |
| 6647 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6648 | * @return Whether this view or one of its descendants actually took focus. |
| 6649 | */ |
| 6650 | public final boolean requestFocus(int direction) { |
| 6651 | return requestFocus(direction, null); |
| 6652 | } |
| 6653 | |
| 6654 | /** |
| 6655 | * Call this to try to give focus to a specific view or to one of its descendants |
| 6656 | * and give it hints about the direction and a specific rectangle that the focus |
| 6657 | * is coming from. The rectangle can help give larger views a finer grained hint |
| 6658 | * about where focus is coming from, and therefore, where to show selection, or |
| 6659 | * forward focus change internally. |
| 6660 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6661 | * A view will not actually take focus if it is not focusable ({@link #isFocusable} returns |
| 6662 | * false), or if it is focusable and it is not focusable in touch mode |
| 6663 | * ({@link #isFocusableInTouchMode}) while the device is in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | * |
| 6665 | * A View will not take focus if it is not visible. |
| 6666 | * |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 6667 | * A View will not take focus if one of its parents has |
| 6668 | * {@link android.view.ViewGroup#getDescendantFocusability()} equal to |
| 6669 | * {@link ViewGroup#FOCUS_BLOCK_DESCENDANTS}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | * |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 6671 | * 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] | 6672 | * have focus, and you want your parent to look for the next one. |
| 6673 | * |
| 6674 | * You may wish to override this method if your custom {@link View} has an internal |
| 6675 | * {@link View} that it wishes to forward the request to. |
| 6676 | * |
| 6677 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 6678 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 6679 | * to give a finer grained hint about where focus is coming from. May be null |
| 6680 | * if there is no hint. |
| 6681 | * @return Whether this view or one of its descendants actually took focus. |
| 6682 | */ |
| 6683 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6684 | return requestFocusNoSearch(direction, previouslyFocusedRect); |
| 6685 | } |
| 6686 | |
| 6687 | private boolean requestFocusNoSearch(int direction, Rect previouslyFocusedRect) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6688 | // need to be focusable |
| 6689 | if ((mViewFlags & FOCUSABLE_MASK) != FOCUSABLE || |
| 6690 | (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 6691 | return false; |
| 6692 | } |
| 6693 | |
| 6694 | // need to be focusable in touch mode if in touch mode |
| 6695 | if (isInTouchMode() && |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6696 | (FOCUSABLE_IN_TOUCH_MODE != (mViewFlags & FOCUSABLE_IN_TOUCH_MODE))) { |
| 6697 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | // need to not have any parents blocking us |
| 6701 | if (hasAncestorThatBlocksDescendantFocus()) { |
| 6702 | return false; |
| 6703 | } |
| 6704 | |
| 6705 | handleFocusGainInternal(direction, previouslyFocusedRect); |
| 6706 | return true; |
| 6707 | } |
| 6708 | |
| 6709 | /** |
| 6710 | * Call this to try to give focus to a specific view or to one of its descendants. This is a |
| 6711 | * special variant of {@link #requestFocus() } that will allow views that are not focuable in |
| 6712 | * touch mode to request focus when they are touched. |
| 6713 | * |
| 6714 | * @return Whether this view or one of its descendants actually took focus. |
| 6715 | * |
| 6716 | * @see #isInTouchMode() |
| 6717 | * |
| 6718 | */ |
| 6719 | public final boolean requestFocusFromTouch() { |
| 6720 | // Leave touch mode if we need to |
| 6721 | if (isInTouchMode()) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6722 | ViewRootImpl viewRoot = getViewRootImpl(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6723 | if (viewRoot != null) { |
| 6724 | viewRoot.ensureTouchMode(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | } |
| 6726 | } |
| 6727 | return requestFocus(View.FOCUS_DOWN); |
| 6728 | } |
| 6729 | |
| 6730 | /** |
| 6731 | * @return Whether any ancestor of this view blocks descendant focus. |
| 6732 | */ |
| 6733 | private boolean hasAncestorThatBlocksDescendantFocus() { |
| 6734 | ViewParent ancestor = mParent; |
| 6735 | while (ancestor instanceof ViewGroup) { |
| 6736 | final ViewGroup vgAncestor = (ViewGroup) ancestor; |
| 6737 | if (vgAncestor.getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS) { |
| 6738 | return true; |
| 6739 | } else { |
| 6740 | ancestor = vgAncestor.getParent(); |
| 6741 | } |
| 6742 | } |
| 6743 | return false; |
| 6744 | } |
| 6745 | |
| 6746 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6747 | * Gets the mode for determining whether this View is important for accessibility |
| 6748 | * which is if it fires accessibility events and if it is reported to |
| 6749 | * accessibility services that query the screen. |
| 6750 | * |
| 6751 | * @return The mode for determining whether a View is important for accessibility. |
| 6752 | * |
| 6753 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6754 | * |
| 6755 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6756 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6757 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6758 | */ |
| 6759 | @ViewDebug.ExportedProperty(category = "accessibility", mapping = { |
Svetoslav Ganov | f9817f7 | 2012-05-22 18:10:31 -0700 | [diff] [blame] | 6760 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_AUTO, to = "auto"), |
| 6761 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_YES, to = "yes"), |
| 6762 | @ViewDebug.IntToString(from = IMPORTANT_FOR_ACCESSIBILITY_NO, to = "no") |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6763 | }) |
| 6764 | public int getImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6765 | return (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6766 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | /** |
| 6770 | * Sets how to determine whether this view is important for accessibility |
| 6771 | * which is if it fires accessibility events and if it is reported to |
| 6772 | * accessibility services that query the screen. |
| 6773 | * |
| 6774 | * @param mode How to determine whether this view is important for accessibility. |
| 6775 | * |
| 6776 | * @attr ref android.R.styleable#View_importantForAccessibility |
| 6777 | * |
| 6778 | * @see #IMPORTANT_FOR_ACCESSIBILITY_YES |
| 6779 | * @see #IMPORTANT_FOR_ACCESSIBILITY_NO |
| 6780 | * @see #IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 6781 | */ |
| 6782 | public void setImportantForAccessibility(int mode) { |
| 6783 | if (mode != getImportantForAccessibility()) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6784 | mPrivateFlags2 &= ~PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
| 6785 | mPrivateFlags2 |= (mode << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT) |
| 6786 | & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6787 | notifyAccessibilityStateChanged(); |
| 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | /** |
| 6792 | * Gets whether this view should be exposed for accessibility. |
| 6793 | * |
| 6794 | * @return Whether the view is exposed for accessibility. |
| 6795 | * |
| 6796 | * @hide |
| 6797 | */ |
| 6798 | public boolean isImportantForAccessibility() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6799 | final int mode = (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) |
| 6800 | >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6801 | switch (mode) { |
| 6802 | case IMPORTANT_FOR_ACCESSIBILITY_YES: |
| 6803 | return true; |
| 6804 | case IMPORTANT_FOR_ACCESSIBILITY_NO: |
| 6805 | return false; |
| 6806 | case IMPORTANT_FOR_ACCESSIBILITY_AUTO: |
Svetoslav Ganov | 34caec9 | 2012-07-19 18:07:58 -0700 | [diff] [blame] | 6807 | return isActionableForAccessibility() || hasListenersForAccessibility() |
| 6808 | || getAccessibilityNodeProvider() != null; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6809 | default: |
| 6810 | throw new IllegalArgumentException("Unknow important for accessibility mode: " |
| 6811 | + mode); |
| 6812 | } |
| 6813 | } |
| 6814 | |
| 6815 | /** |
| 6816 | * Gets the parent for accessibility purposes. Note that the parent for |
| 6817 | * accessibility is not necessary the immediate parent. It is the first |
| 6818 | * predecessor that is important for accessibility. |
| 6819 | * |
| 6820 | * @return The parent for accessibility purposes. |
| 6821 | */ |
| 6822 | public ViewParent getParentForAccessibility() { |
| 6823 | if (mParent instanceof View) { |
| 6824 | View parentView = (View) mParent; |
| 6825 | if (parentView.includeForAccessibility()) { |
| 6826 | return mParent; |
| 6827 | } else { |
| 6828 | return mParent.getParentForAccessibility(); |
| 6829 | } |
| 6830 | } |
| 6831 | return null; |
| 6832 | } |
| 6833 | |
| 6834 | /** |
| 6835 | * Adds the children of a given View for accessibility. Since some Views are |
| 6836 | * not important for accessibility the children for accessibility are not |
| 6837 | * necessarily direct children of the riew, rather they are the first level of |
| 6838 | * descendants important for accessibility. |
| 6839 | * |
| 6840 | * @param children The list of children for accessibility. |
| 6841 | */ |
| 6842 | public void addChildrenForAccessibility(ArrayList<View> children) { |
| 6843 | if (includeForAccessibility()) { |
| 6844 | children.add(this); |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | /** |
| 6849 | * Whether to regard this view for accessibility. A view is regarded for |
| 6850 | * accessibility if it is important for accessibility or the querying |
| 6851 | * accessibility service has explicitly requested that view not |
| 6852 | * important for accessibility are regarded. |
| 6853 | * |
| 6854 | * @return Whether to regard the view for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6855 | * |
| 6856 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6857 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6858 | public boolean includeForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6859 | if (mAttachInfo != null) { |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 6860 | return (mAttachInfo.mAccessibilityFetchFlags |
| 6861 | & AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0 |
| 6862 | || isImportantForAccessibility(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6863 | } |
| 6864 | return false; |
| 6865 | } |
| 6866 | |
| 6867 | /** |
| 6868 | * Returns whether the View is considered actionable from |
| 6869 | * accessibility perspective. Such view are important for |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6870 | * accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6871 | * |
| 6872 | * @return True if the view is actionable for accessibility. |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6873 | * |
| 6874 | * @hide |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6875 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 6876 | public boolean isActionableForAccessibility() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6877 | return (isClickable() || isLongClickable() || isFocusable()); |
| 6878 | } |
| 6879 | |
| 6880 | /** |
| 6881 | * Returns whether the View has registered callbacks wich makes it |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6882 | * important for accessibility. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6883 | * |
| 6884 | * @return True if the view is actionable for accessibility. |
| 6885 | */ |
| 6886 | private boolean hasListenersForAccessibility() { |
| 6887 | ListenerInfo info = getListenerInfo(); |
| 6888 | return mTouchDelegate != null || info.mOnKeyListener != null |
| 6889 | || info.mOnTouchListener != null || info.mOnGenericMotionListener != null |
| 6890 | || info.mOnHoverListener != null || info.mOnDragListener != null; |
| 6891 | } |
| 6892 | |
| 6893 | /** |
| 6894 | * Notifies accessibility services that some view's important for |
| 6895 | * accessibility state has changed. Note that such notifications |
| 6896 | * are made at most once every |
| 6897 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} |
| 6898 | * to avoid unnecessary load to the system. Also once a view has |
| 6899 | * made a notifucation this method is a NOP until the notification has |
| 6900 | * been sent to clients. |
| 6901 | * |
| 6902 | * @hide |
| 6903 | * |
| 6904 | * TODO: Makse sure this method is called for any view state change |
| 6905 | * that is interesting for accessilility purposes. |
| 6906 | */ |
| 6907 | public void notifyAccessibilityStateChanged() { |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 6908 | if (!AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 6909 | return; |
| 6910 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6911 | if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_STATE_CHANGED) == 0) { |
| 6912 | mPrivateFlags2 |= PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6913 | if (mParent != null) { |
| 6914 | mParent.childAccessibilityStateChanged(this); |
| 6915 | } |
| 6916 | } |
| 6917 | } |
| 6918 | |
| 6919 | /** |
| 6920 | * Reset the state indicating the this view has requested clients |
Fabrice Di Meglio | 69542e4 | 2012-09-18 19:34:34 -0700 | [diff] [blame] | 6921 | * interested in its accessibility state to be notified. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6922 | * |
| 6923 | * @hide |
| 6924 | */ |
| 6925 | public void resetAccessibilityStateChanged() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6926 | mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_STATE_CHANGED; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | /** |
| 6930 | * Performs the specified accessibility action on the view. For |
| 6931 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6932 | * <p> |
| 6933 | * If an {@link AccessibilityDelegate} has been specified via calling |
| 6934 | * {@link #setAccessibilityDelegate(AccessibilityDelegate)} its |
| 6935 | * {@link AccessibilityDelegate#performAccessibilityAction(View, int, Bundle)} |
| 6936 | * is responsible for handling this call. |
| 6937 | * </p> |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6938 | * |
| 6939 | * @param action The action to perform. |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6940 | * @param arguments Optional action arguments. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6941 | * @return Whether the action was performed. |
| 6942 | */ |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 6943 | public boolean performAccessibilityAction(int action, Bundle arguments) { |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 6944 | if (mAccessibilityDelegate != null) { |
| 6945 | return mAccessibilityDelegate.performAccessibilityAction(this, action, arguments); |
| 6946 | } else { |
| 6947 | return performAccessibilityActionInternal(action, arguments); |
| 6948 | } |
| 6949 | } |
| 6950 | |
| 6951 | /** |
| 6952 | * @see #performAccessibilityAction(int, Bundle) |
| 6953 | * |
| 6954 | * Note: Called from the default {@link AccessibilityDelegate}. |
| 6955 | */ |
| 6956 | boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6957 | switch (action) { |
| 6958 | case AccessibilityNodeInfo.ACTION_CLICK: { |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6959 | if (isClickable()) { |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6960 | performClick(); |
| 6961 | return true; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6962 | } |
| 6963 | } break; |
| 6964 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: { |
| 6965 | if (isLongClickable()) { |
Svetoslav Ganov | 96985fc | 2012-10-09 16:25:54 -0700 | [diff] [blame] | 6966 | performLongClick(); |
| 6967 | return true; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 6968 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6969 | } break; |
| 6970 | case AccessibilityNodeInfo.ACTION_FOCUS: { |
| 6971 | if (!hasFocus()) { |
| 6972 | // Get out of touch mode since accessibility |
| 6973 | // wants to move focus around. |
| 6974 | getViewRootImpl().ensureTouchMode(false); |
| 6975 | return requestFocus(); |
| 6976 | } |
| 6977 | } break; |
| 6978 | case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS: { |
| 6979 | if (hasFocus()) { |
| 6980 | clearFocus(); |
| 6981 | return !isFocused(); |
| 6982 | } |
| 6983 | } break; |
| 6984 | case AccessibilityNodeInfo.ACTION_SELECT: { |
| 6985 | if (!isSelected()) { |
| 6986 | setSelected(true); |
| 6987 | return isSelected(); |
| 6988 | } |
| 6989 | } break; |
| 6990 | case AccessibilityNodeInfo.ACTION_CLEAR_SELECTION: { |
| 6991 | if (isSelected()) { |
| 6992 | setSelected(false); |
| 6993 | return !isSelected(); |
| 6994 | } |
| 6995 | } break; |
| 6996 | case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS: { |
Svetoslav Ganov | 27e2da7 | 2012-07-02 18:12:00 -0700 | [diff] [blame] | 6997 | if (!isAccessibilityFocused()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6998 | return requestAccessibilityFocus(); |
| 6999 | } |
| 7000 | } break; |
| 7001 | case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS: { |
| 7002 | if (isAccessibilityFocused()) { |
| 7003 | clearAccessibilityFocus(); |
| 7004 | return true; |
| 7005 | } |
| 7006 | } break; |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7007 | case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: { |
| 7008 | if (arguments != null) { |
| 7009 | final int granularity = arguments.getInt( |
| 7010 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7011 | final boolean extendSelection = arguments.getBoolean( |
| 7012 | AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN); |
| 7013 | return nextAtGranularity(granularity, extendSelection); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7014 | } |
| 7015 | } break; |
| 7016 | case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { |
| 7017 | if (arguments != null) { |
| 7018 | final int granularity = arguments.getInt( |
| 7019 | AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT); |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7020 | final boolean extendSelection = arguments.getBoolean( |
| 7021 | AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN); |
| 7022 | return previousAtGranularity(granularity, extendSelection); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7023 | } |
| 7024 | } break; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7025 | } |
| 7026 | return false; |
| 7027 | } |
| 7028 | |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7029 | private boolean nextAtGranularity(int granularity, boolean extendSelection) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7030 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 7031 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7032 | return false; |
| 7033 | } |
| 7034 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 7035 | if (iterator == null) { |
| 7036 | return false; |
| 7037 | } |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7038 | int current = getAccessibilitySelectionEnd(); |
| 7039 | if (current == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 7040 | current = 0; |
| 7041 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7042 | final int[] range = iterator.following(current); |
| 7043 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7044 | return false; |
| 7045 | } |
| 7046 | final int start = range[0]; |
| 7047 | final int end = range[1]; |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7048 | if (extendSelection && isAccessibilitySelectionExtendable()) { |
| 7049 | int selectionStart = getAccessibilitySelectionStart(); |
| 7050 | if (selectionStart == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 7051 | selectionStart = start; |
| 7052 | } |
| 7053 | setAccessibilitySelection(selectionStart, end); |
| 7054 | } else { |
| 7055 | setAccessibilitySelection(end, end); |
| 7056 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7057 | sendViewTextTraversedAtGranularityEvent( |
| 7058 | AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, |
| 7059 | granularity, start, end); |
| 7060 | return true; |
| 7061 | } |
| 7062 | |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7063 | private boolean previousAtGranularity(int granularity, boolean extendSelection) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7064 | CharSequence text = getIterableTextForAccessibility(); |
Svetoslav Ganov | 64899e5 | 2012-05-15 21:09:30 -0700 | [diff] [blame] | 7065 | if (text == null || text.length() == 0) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7066 | return false; |
| 7067 | } |
| 7068 | TextSegmentIterator iterator = getIteratorForGranularity(granularity); |
| 7069 | if (iterator == null) { |
| 7070 | return false; |
| 7071 | } |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7072 | int current = getAccessibilitySelectionStart(); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7073 | if (current == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 7074 | current = text.length(); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7075 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7076 | final int[] range = iterator.preceding(current); |
| 7077 | if (range == null) { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7078 | return false; |
| 7079 | } |
| 7080 | final int start = range[0]; |
| 7081 | final int end = range[1]; |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7082 | if (extendSelection && isAccessibilitySelectionExtendable()) { |
| 7083 | int selectionEnd = getAccessibilitySelectionEnd(); |
| 7084 | if (selectionEnd == ACCESSIBILITY_CURSOR_POSITION_UNDEFINED) { |
| 7085 | selectionEnd = end; |
| 7086 | } |
| 7087 | setAccessibilitySelection(start, selectionEnd); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7088 | } else { |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7089 | setAccessibilitySelection(start, start); |
Svetoslav Ganov | 39f2aee | 2012-05-29 09:15:30 -0700 | [diff] [blame] | 7090 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7091 | sendViewTextTraversedAtGranularityEvent( |
| 7092 | AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, |
| 7093 | granularity, start, end); |
| 7094 | return true; |
| 7095 | } |
| 7096 | |
| 7097 | /** |
| 7098 | * Gets the text reported for accessibility purposes. |
| 7099 | * |
| 7100 | * @return The accessibility text. |
| 7101 | * |
| 7102 | * @hide |
| 7103 | */ |
| 7104 | public CharSequence getIterableTextForAccessibility() { |
Svetoslav Ganov | 05282aa | 2012-09-06 18:59:29 -0700 | [diff] [blame] | 7105 | return getContentDescription(); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | /** |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7109 | * Gets whether accessibility selection can be extended. |
| 7110 | * |
| 7111 | * @return If selection is extensible. |
| 7112 | * |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7113 | * @hide |
| 7114 | */ |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7115 | public boolean isAccessibilitySelectionExtendable() { |
| 7116 | return false; |
| 7117 | } |
| 7118 | |
| 7119 | /** |
| 7120 | * @hide |
| 7121 | */ |
| 7122 | public int getAccessibilitySelectionStart() { |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7123 | return mAccessibilityCursorPosition; |
| 7124 | } |
| 7125 | |
| 7126 | /** |
| 7127 | * @hide |
| 7128 | */ |
Svetoslav | 7c51284 | 2013-01-30 23:02:08 -0800 | [diff] [blame] | 7129 | public int getAccessibilitySelectionEnd() { |
| 7130 | return getAccessibilitySelectionStart(); |
| 7131 | } |
| 7132 | |
| 7133 | /** |
| 7134 | * @hide |
| 7135 | */ |
| 7136 | public void setAccessibilitySelection(int start, int end) { |
| 7137 | if (start >= 0 && start == end && end <= getIterableTextForAccessibility().length()) { |
| 7138 | mAccessibilityCursorPosition = start; |
| 7139 | } else { |
| 7140 | mAccessibilityCursorPosition = ACCESSIBILITY_CURSOR_POSITION_UNDEFINED; |
| 7141 | } |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | private void sendViewTextTraversedAtGranularityEvent(int action, int granularity, |
| 7145 | int fromIndex, int toIndex) { |
| 7146 | if (mParent == null) { |
| 7147 | return; |
| 7148 | } |
| 7149 | AccessibilityEvent event = AccessibilityEvent.obtain( |
| 7150 | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY); |
| 7151 | onInitializeAccessibilityEvent(event); |
| 7152 | onPopulateAccessibilityEvent(event); |
| 7153 | event.setFromIndex(fromIndex); |
| 7154 | event.setToIndex(toIndex); |
| 7155 | event.setAction(action); |
| 7156 | event.setMovementGranularity(granularity); |
| 7157 | mParent.requestSendAccessibilityEvent(this, event); |
| 7158 | } |
| 7159 | |
| 7160 | /** |
| 7161 | * @hide |
| 7162 | */ |
| 7163 | public TextSegmentIterator getIteratorForGranularity(int granularity) { |
| 7164 | switch (granularity) { |
| 7165 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER: { |
| 7166 | CharSequence text = getIterableTextForAccessibility(); |
| 7167 | if (text != null && text.length() > 0) { |
| 7168 | CharacterTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7169 | CharacterTextSegmentIterator.getInstance( |
| 7170 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7171 | iterator.initialize(text.toString()); |
| 7172 | return iterator; |
| 7173 | } |
| 7174 | } break; |
| 7175 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD: { |
| 7176 | CharSequence text = getIterableTextForAccessibility(); |
| 7177 | if (text != null && text.length() > 0) { |
| 7178 | WordTextSegmentIterator iterator = |
Svetoslav Ganov | bbd3155 | 2012-06-11 12:08:18 -0700 | [diff] [blame] | 7179 | WordTextSegmentIterator.getInstance( |
| 7180 | mContext.getResources().getConfiguration().locale); |
Svetoslav Ganov | 6d17a93 | 2012-04-27 19:30:38 -0700 | [diff] [blame] | 7181 | iterator.initialize(text.toString()); |
| 7182 | return iterator; |
| 7183 | } |
| 7184 | } break; |
| 7185 | case AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH: { |
| 7186 | CharSequence text = getIterableTextForAccessibility(); |
| 7187 | if (text != null && text.length() > 0) { |
| 7188 | ParagraphTextSegmentIterator iterator = |
| 7189 | ParagraphTextSegmentIterator.getInstance(); |
| 7190 | iterator.initialize(text.toString()); |
| 7191 | return iterator; |
| 7192 | } |
| 7193 | } break; |
| 7194 | } |
| 7195 | return null; |
| 7196 | } |
| 7197 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7198 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7199 | * @hide |
| 7200 | */ |
| 7201 | public void dispatchStartTemporaryDetach() { |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 7202 | clearAccessibilityFocus(); |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 7203 | clearDisplayList(); |
| 7204 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7205 | onStartTemporaryDetach(); |
| 7206 | } |
| 7207 | |
| 7208 | /** |
| 7209 | * 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] | 7210 | * {@link ViewGroup#detachViewFromParent(View) ViewGroup.detachViewFromParent}. |
| 7211 | * It will either be followed by {@link #onFinishTemporaryDetach()} or |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7212 | * {@link #onDetachedFromWindow()} when the container is done. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7213 | */ |
| 7214 | public void onStartTemporaryDetach() { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7215 | removeUnsetPressCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7216 | mPrivateFlags |= PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 7217 | } |
| 7218 | |
| 7219 | /** |
| 7220 | * @hide |
| 7221 | */ |
| 7222 | public void dispatchFinishTemporaryDetach() { |
| 7223 | onFinishTemporaryDetach(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | /** |
| 7227 | * Called after {@link #onStartTemporaryDetach} when the container is done |
| 7228 | * changing the view. |
| 7229 | */ |
| 7230 | public void onFinishTemporaryDetach() { |
| 7231 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7234 | * Return the global {@link KeyEvent.DispatcherState KeyEvent.DispatcherState} |
| 7235 | * for this view's window. Returns null if the view is not currently attached |
| 7236 | * 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] | 7237 | * just use the standard high-level event callbacks like |
| 7238 | * {@link #onKeyDown(int, KeyEvent)}. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7239 | */ |
| 7240 | public KeyEvent.DispatcherState getKeyDispatcherState() { |
| 7241 | return mAttachInfo != null ? mAttachInfo.mKeyDispatchState : null; |
| 7242 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7243 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7244 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | * Dispatch a key event before it is processed by any input method |
| 7246 | * associated with the view hierarchy. This can be used to intercept |
| 7247 | * key events in special situations before the IME consumes them; a |
| 7248 | * typical example would be handling the BACK key to update the application's |
| 7249 | * UI instead of allowing the IME to see it and close itself. |
| 7250 | * |
| 7251 | * @param event The key event to be dispatched. |
| 7252 | * @return True if the event was handled, false otherwise. |
| 7253 | */ |
| 7254 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
| 7255 | return onKeyPreIme(event.getKeyCode(), event); |
| 7256 | } |
| 7257 | |
| 7258 | /** |
| 7259 | * Dispatch a key event to the next view on the focus path. This path runs |
| 7260 | * from the top of the view tree down to the currently focused view. If this |
| 7261 | * view has focus, it will dispatch to itself. Otherwise it will dispatch |
| 7262 | * the next node down the focus path. This method also fires any key |
| 7263 | * listeners. |
| 7264 | * |
| 7265 | * @param event The key event to be dispatched. |
| 7266 | * @return True if the event was handled, false otherwise. |
| 7267 | */ |
| 7268 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7269 | if (mInputEventConsistencyVerifier != null) { |
| 7270 | mInputEventConsistencyVerifier.onKeyEvent(event, 0); |
| 7271 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7272 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7273 | // Give any attached key listener a first crack at the event. |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7274 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7275 | ListenerInfo li = mListenerInfo; |
| 7276 | if (li != null && li.mOnKeyListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7277 | && li.mOnKeyListener.onKey(this, event.getKeyCode(), event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | return true; |
| 7279 | } |
| 7280 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7281 | if (event.dispatch(this, mAttachInfo != null |
| 7282 | ? mAttachInfo.mKeyDispatchState : null, this)) { |
| 7283 | return true; |
| 7284 | } |
| 7285 | |
| 7286 | if (mInputEventConsistencyVerifier != null) { |
| 7287 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7288 | } |
| 7289 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7290 | } |
| 7291 | |
| 7292 | /** |
| 7293 | * Dispatches a key shortcut event. |
| 7294 | * |
| 7295 | * @param event The key event to be dispatched. |
| 7296 | * @return True if the event was handled by the view, false otherwise. |
| 7297 | */ |
| 7298 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 7299 | return onKeyShortcut(event.getKeyCode(), event); |
| 7300 | } |
| 7301 | |
| 7302 | /** |
| 7303 | * Pass the touch screen motion event down to the target view, or this |
| 7304 | * view if it is the target. |
| 7305 | * |
| 7306 | * @param event The motion event to be dispatched. |
| 7307 | * @return True if the event was handled by the view, false otherwise. |
| 7308 | */ |
| 7309 | public boolean dispatchTouchEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7310 | if (mInputEventConsistencyVerifier != null) { |
| 7311 | mInputEventConsistencyVerifier.onTouchEvent(event, 0); |
| 7312 | } |
| 7313 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7314 | if (onFilterTouchEventForSecurity(event)) { |
| 7315 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7316 | ListenerInfo li = mListenerInfo; |
| 7317 | if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7318 | && li.mOnTouchListener.onTouch(this, event)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7319 | return true; |
| 7320 | } |
| 7321 | |
| 7322 | if (onTouchEvent(event)) { |
| 7323 | return true; |
| 7324 | } |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7327 | if (mInputEventConsistencyVerifier != null) { |
| 7328 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7330 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7331 | } |
| 7332 | |
| 7333 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7334 | * Filter the touch event to apply security policies. |
| 7335 | * |
| 7336 | * @param event The motion event to be filtered. |
| 7337 | * @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] | 7338 | * |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7339 | * @see #getFilterTouchesWhenObscured |
| 7340 | */ |
| 7341 | public boolean onFilterTouchEventForSecurity(MotionEvent event) { |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 7342 | //noinspection RedundantIfStatement |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 7343 | if ((mViewFlags & FILTER_TOUCHES_WHEN_OBSCURED) != 0 |
| 7344 | && (event.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0) { |
| 7345 | // Window is obscured, drop this touch. |
| 7346 | return false; |
| 7347 | } |
| 7348 | return true; |
| 7349 | } |
| 7350 | |
| 7351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7352 | * Pass a trackball motion event down to the focused view. |
| 7353 | * |
| 7354 | * @param event The motion event to be dispatched. |
| 7355 | * @return True if the event was handled by the view, false otherwise. |
| 7356 | */ |
| 7357 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7358 | if (mInputEventConsistencyVerifier != null) { |
| 7359 | mInputEventConsistencyVerifier.onTrackballEvent(event, 0); |
| 7360 | } |
| 7361 | |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7362 | return onTrackballEvent(event); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7363 | } |
| 7364 | |
| 7365 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7366 | * Dispatch a generic motion event. |
| 7367 | * <p> |
| 7368 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 7369 | * 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] | 7370 | * 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] | 7371 | * to {@link #onHoverEvent(MotionEvent)}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7372 | * </p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7373 | * |
| 7374 | * @param event The motion event to be dispatched. |
| 7375 | * @return True if the event was handled by the view, false otherwise. |
| 7376 | */ |
| 7377 | public boolean dispatchGenericMotionEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 7378 | if (mInputEventConsistencyVerifier != null) { |
| 7379 | mInputEventConsistencyVerifier.onGenericMotionEvent(event, 0); |
| 7380 | } |
| 7381 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7382 | final int source = event.getSource(); |
| 7383 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 7384 | final int action = event.getAction(); |
| 7385 | if (action == MotionEvent.ACTION_HOVER_ENTER |
| 7386 | || action == MotionEvent.ACTION_HOVER_MOVE |
| 7387 | || action == MotionEvent.ACTION_HOVER_EXIT) { |
| 7388 | if (dispatchHoverEvent(event)) { |
| 7389 | return true; |
| 7390 | } |
| 7391 | } else if (dispatchGenericPointerEvent(event)) { |
| 7392 | return true; |
| 7393 | } |
| 7394 | } else if (dispatchGenericFocusedEvent(event)) { |
| 7395 | return true; |
| 7396 | } |
| 7397 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7398 | if (dispatchGenericMotionEventInternal(event)) { |
| 7399 | return true; |
| 7400 | } |
| 7401 | |
| 7402 | if (mInputEventConsistencyVerifier != null) { |
| 7403 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7404 | } |
| 7405 | return false; |
| 7406 | } |
| 7407 | |
| 7408 | private boolean dispatchGenericMotionEventInternal(MotionEvent event) { |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 7409 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7410 | ListenerInfo li = mListenerInfo; |
| 7411 | if (li != null && li.mOnGenericMotionListener != null |
| 7412 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7413 | && li.mOnGenericMotionListener.onGenericMotion(this, event)) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7414 | return true; |
| 7415 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 7416 | |
| 7417 | if (onGenericMotionEvent(event)) { |
| 7418 | return true; |
| 7419 | } |
| 7420 | |
| 7421 | if (mInputEventConsistencyVerifier != null) { |
| 7422 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 0); |
| 7423 | } |
| 7424 | return false; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7428 | * Dispatch a hover event. |
| 7429 | * <p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7430 | * Do not call this method directly. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7431 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7432 | * </p> |
| 7433 | * |
| 7434 | * @param event The motion event to be dispatched. |
| 7435 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7436 | */ |
| 7437 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 7438 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7439 | ListenerInfo li = mListenerInfo; |
| 7440 | if (li != null && li.mOnHoverListener != null |
| 7441 | && (mViewFlags & ENABLED_MASK) == ENABLED |
| 7442 | && li.mOnHoverListener.onHover(this, event)) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 7443 | return true; |
| 7444 | } |
| 7445 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7446 | return onHoverEvent(event); |
| 7447 | } |
| 7448 | |
| 7449 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 7450 | * Returns true if the view has a child to which it has recently sent |
| 7451 | * {@link MotionEvent#ACTION_HOVER_ENTER}. If this view is hovered and |
| 7452 | * it does not have a hovered child, then it must be the innermost hovered view. |
| 7453 | * @hide |
| 7454 | */ |
| 7455 | protected boolean hasHoveredChild() { |
| 7456 | return false; |
| 7457 | } |
| 7458 | |
| 7459 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7460 | * Dispatch a generic motion event to the view under the first pointer. |
| 7461 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7462 | * Do not call this method directly. |
| 7463 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7464 | * </p> |
| 7465 | * |
| 7466 | * @param event The motion event to be dispatched. |
| 7467 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7468 | */ |
| 7469 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 7470 | return false; |
| 7471 | } |
| 7472 | |
| 7473 | /** |
| 7474 | * Dispatch a generic motion event to the currently focused view. |
| 7475 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7476 | * Do not call this method directly. |
| 7477 | * Call {@link #dispatchGenericMotionEvent(MotionEvent)} instead. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7478 | * </p> |
| 7479 | * |
| 7480 | * @param event The motion event to be dispatched. |
| 7481 | * @return True if the event was handled by the view, false otherwise. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 7482 | */ |
| 7483 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
| 7484 | return false; |
| 7485 | } |
| 7486 | |
| 7487 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7488 | * Dispatch a pointer event. |
| 7489 | * <p> |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 7490 | * Dispatches touch related pointer events to {@link #onTouchEvent(MotionEvent)} and all |
| 7491 | * other events to {@link #onGenericMotionEvent(MotionEvent)}. This separation of concerns |
| 7492 | * reinforces the invariant that {@link #onTouchEvent(MotionEvent)} is really about touches |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 7493 | * and should not be expected to handle other pointing device features. |
| 7494 | * </p> |
| 7495 | * |
| 7496 | * @param event The motion event to be dispatched. |
| 7497 | * @return True if the event was handled by the view, false otherwise. |
| 7498 | * @hide |
| 7499 | */ |
| 7500 | public final boolean dispatchPointerEvent(MotionEvent event) { |
| 7501 | if (event.isTouchEvent()) { |
| 7502 | return dispatchTouchEvent(event); |
| 7503 | } else { |
| 7504 | return dispatchGenericMotionEvent(event); |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | * Called when the window containing this view gains or loses window focus. |
| 7510 | * ViewGroups should override to route to their children. |
| 7511 | * |
| 7512 | * @param hasFocus True if the window containing this view now has focus, |
| 7513 | * false otherwise. |
| 7514 | */ |
| 7515 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 7516 | onWindowFocusChanged(hasFocus); |
| 7517 | } |
| 7518 | |
| 7519 | /** |
| 7520 | * Called when the window containing this view gains or loses focus. Note |
| 7521 | * that this is separate from view focus: to receive key events, both |
| 7522 | * your view and its window must have focus. If a window is displayed |
| 7523 | * on top of yours that takes input focus, then your own window will lose |
| 7524 | * focus but the view focus will remain unchanged. |
| 7525 | * |
| 7526 | * @param hasWindowFocus True if the window containing this view now has |
| 7527 | * focus, false otherwise. |
| 7528 | */ |
| 7529 | public void onWindowFocusChanged(boolean hasWindowFocus) { |
| 7530 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 7531 | if (!hasWindowFocus) { |
| 7532 | if (isPressed()) { |
| 7533 | setPressed(false); |
| 7534 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7535 | if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7536 | imm.focusOut(this); |
| 7537 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7538 | removeLongPressCallback(); |
Tony Wu | 26edf20 | 2010-09-13 19:54:00 +0800 | [diff] [blame] | 7539 | removeTapCallback(); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 7540 | onFocusLost(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7541 | } else if (imm != null && (mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7542 | imm.focusIn(this); |
| 7543 | } |
| 7544 | refreshDrawableState(); |
| 7545 | } |
| 7546 | |
| 7547 | /** |
| 7548 | * Returns true if this view is in a window that currently has window focus. |
| 7549 | * Note that this is not the same as the view itself having focus. |
| 7550 | * |
| 7551 | * @return True if this view is in a window that currently has window focus. |
| 7552 | */ |
| 7553 | public boolean hasWindowFocus() { |
| 7554 | return mAttachInfo != null && mAttachInfo.mHasWindowFocus; |
| 7555 | } |
| 7556 | |
| 7557 | /** |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7558 | * Dispatch a view visibility change down the view hierarchy. |
| 7559 | * ViewGroups should override to route to their children. |
| 7560 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7561 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7562 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7563 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7564 | */ |
| 7565 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 7566 | onVisibilityChanged(changedView, visibility); |
| 7567 | } |
| 7568 | |
| 7569 | /** |
| 7570 | * Called when the visibility of the view or an ancestor of the view is changed. |
| 7571 | * @param changedView The view whose visibility changed. Could be 'this' or |
| 7572 | * an ancestor view. |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7573 | * @param visibility The new visibility of changedView: {@link #VISIBLE}, |
| 7574 | * {@link #INVISIBLE} or {@link #GONE}. |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7575 | */ |
| 7576 | protected void onVisibilityChanged(View changedView, int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7577 | if (visibility == VISIBLE) { |
| 7578 | if (mAttachInfo != null) { |
| 7579 | initialAwakenScrollBars(); |
| 7580 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7581 | mPrivateFlags |= PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7582 | } |
| 7583 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 7584 | } |
| 7585 | |
| 7586 | /** |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7587 | * Dispatch a hint about whether this view is displayed. For instance, when |
| 7588 | * a View moves out of the screen, it might receives a display hint indicating |
| 7589 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7590 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7591 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7592 | * @param hint A hint about whether or not this view is displayed: |
| 7593 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7594 | */ |
| 7595 | public void dispatchDisplayHint(int hint) { |
| 7596 | onDisplayHint(hint); |
| 7597 | } |
| 7598 | |
| 7599 | /** |
| 7600 | * Gives this view a hint about whether is displayed or not. For instance, when |
| 7601 | * a View moves out of the screen, it might receives a display hint indicating |
| 7602 | * the view is not displayed. Applications should not <em>rely</em> on this hint |
| 7603 | * as there is no guarantee that they will receive one. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 7604 | * |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 7605 | * @param hint A hint about whether or not this view is displayed: |
| 7606 | * {@link #VISIBLE} or {@link #INVISIBLE}. |
| 7607 | */ |
| 7608 | protected void onDisplayHint(int hint) { |
| 7609 | } |
| 7610 | |
| 7611 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7612 | * Dispatch a window visibility change down the view hierarchy. |
| 7613 | * ViewGroups should override to route to their children. |
| 7614 | * |
| 7615 | * @param visibility The new visibility of the window. |
| 7616 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7617 | * @see #onWindowVisibilityChanged(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7618 | */ |
| 7619 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 7620 | onWindowVisibilityChanged(visibility); |
| 7621 | } |
| 7622 | |
| 7623 | /** |
| 7624 | * Called when the window containing has change its visibility |
| 7625 | * (between {@link #GONE}, {@link #INVISIBLE}, and {@link #VISIBLE}). Note |
| 7626 | * that this tells you whether or not your window is being made visible |
| 7627 | * to the window manager; this does <em>not</em> tell you whether or not |
| 7628 | * your window is obscured by other windows on the screen, even if it |
| 7629 | * is itself visible. |
| 7630 | * |
| 7631 | * @param visibility The new visibility of the window. |
| 7632 | */ |
| 7633 | protected void onWindowVisibilityChanged(int visibility) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 7634 | if (visibility == VISIBLE) { |
| 7635 | initialAwakenScrollBars(); |
| 7636 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | } |
| 7638 | |
| 7639 | /** |
| 7640 | * Returns the current visibility of the window this view is attached to |
| 7641 | * (either {@link #GONE}, {@link #INVISIBLE}, or {@link #VISIBLE}). |
| 7642 | * |
| 7643 | * @return Returns the current visibility of the view's window. |
| 7644 | */ |
| 7645 | public int getWindowVisibility() { |
| 7646 | return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; |
| 7647 | } |
| 7648 | |
| 7649 | /** |
| 7650 | * Retrieve the overall visible display size in which the window this view is |
| 7651 | * attached to has been positioned in. This takes into account screen |
| 7652 | * decorations above the window, for both cases where the window itself |
| 7653 | * is being position inside of them or the window is being placed under |
| 7654 | * then and covered insets are used for the window to position its content |
| 7655 | * inside. In effect, this tells you the available area where content can |
| 7656 | * be placed and remain visible to users. |
| 7657 | * |
| 7658 | * <p>This function requires an IPC back to the window manager to retrieve |
| 7659 | * the requested information, so should not be used in performance critical |
| 7660 | * code like drawing. |
| 7661 | * |
| 7662 | * @param outRect Filled in with the visible display frame. If the view |
| 7663 | * is not attached to a window, this is simply the raw display size. |
| 7664 | */ |
| 7665 | public void getWindowVisibleDisplayFrame(Rect outRect) { |
| 7666 | if (mAttachInfo != null) { |
| 7667 | try { |
| 7668 | mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); |
| 7669 | } catch (RemoteException e) { |
| 7670 | return; |
| 7671 | } |
| 7672 | // XXX This is really broken, and probably all needs to be done |
| 7673 | // in the window manager, and we need to know more about whether |
| 7674 | // we want the area behind or in front of the IME. |
| 7675 | final Rect insets = mAttachInfo.mVisibleInsets; |
| 7676 | outRect.left += insets.left; |
| 7677 | outRect.top += insets.top; |
| 7678 | outRect.right -= insets.right; |
| 7679 | outRect.bottom -= insets.bottom; |
| 7680 | return; |
| 7681 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 7682 | // The view is not attached to a display so we don't have a context. |
| 7683 | // Make a best guess about the display size. |
| 7684 | Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 7685 | d.getRectSize(outRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | /** |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7689 | * Dispatch a notification about a resource configuration change down |
| 7690 | * the view hierarchy. |
| 7691 | * ViewGroups should override to route to their children. |
| 7692 | * |
| 7693 | * @param newConfig The new resource configuration. |
| 7694 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 7695 | * @see #onConfigurationChanged(android.content.res.Configuration) |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7696 | */ |
| 7697 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 7698 | onConfigurationChanged(newConfig); |
| 7699 | } |
| 7700 | |
| 7701 | /** |
| 7702 | * Called when the current configuration of the resources being used |
| 7703 | * by the application have changed. You can use this to decide when |
| 7704 | * to reload resources that can changed based on orientation and other |
| 7705 | * configuration characterstics. You only need to use this if you are |
| 7706 | * not relying on the normal {@link android.app.Activity} mechanism of |
| 7707 | * recreating the activity instance upon a configuration change. |
| 7708 | * |
| 7709 | * @param newConfig The new resource configuration. |
| 7710 | */ |
| 7711 | protected void onConfigurationChanged(Configuration newConfig) { |
| 7712 | } |
| 7713 | |
| 7714 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | * Private function to aggregate all per-view attributes in to the view |
| 7716 | * root. |
| 7717 | */ |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7718 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7719 | performCollectViewAttributes(attachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7720 | } |
| 7721 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7722 | void performCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 7723 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7724 | if ((mViewFlags & KEEP_SCREEN_ON) == KEEP_SCREEN_ON) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7725 | attachInfo.mKeepScreenOn = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7726 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7727 | attachInfo.mSystemUiVisibility |= mSystemUiVisibility; |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7728 | ListenerInfo li = mListenerInfo; |
| 7729 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 7730 | attachInfo.mHasSystemUiListeners = true; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7731 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | } |
| 7733 | } |
| 7734 | |
| 7735 | void needGlobalAttributesUpdate(boolean force) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7736 | final AttachInfo ai = mAttachInfo; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 7737 | if (ai != null && !ai.mRecomputeGlobalAttributes) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7738 | if (force || ai.mKeepScreenOn || (ai.mSystemUiVisibility != 0) |
| 7739 | || ai.mHasSystemUiListeners) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | ai.mRecomputeGlobalAttributes = true; |
| 7741 | } |
| 7742 | } |
| 7743 | } |
| 7744 | |
| 7745 | /** |
| 7746 | * Returns whether the device is currently in touch mode. Touch mode is entered |
| 7747 | * once the user begins interacting with the device by touch, and affects various |
| 7748 | * things like whether focus is always visible to the user. |
| 7749 | * |
| 7750 | * @return Whether the device is in touch mode. |
| 7751 | */ |
| 7752 | @ViewDebug.ExportedProperty |
| 7753 | public boolean isInTouchMode() { |
| 7754 | if (mAttachInfo != null) { |
| 7755 | return mAttachInfo.mInTouchMode; |
| 7756 | } else { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7757 | return ViewRootImpl.isInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | } |
| 7759 | } |
| 7760 | |
| 7761 | /** |
| 7762 | * Returns the context the view is running in, through which it can |
| 7763 | * access the current theme, resources, etc. |
| 7764 | * |
| 7765 | * @return The view's Context. |
| 7766 | */ |
| 7767 | @ViewDebug.CapturedViewProperty |
| 7768 | public final Context getContext() { |
| 7769 | return mContext; |
| 7770 | } |
| 7771 | |
| 7772 | /** |
| 7773 | * Handle a key event before it is processed by any input method |
| 7774 | * associated with the view hierarchy. This can be used to intercept |
| 7775 | * key events in special situations before the IME consumes them; a |
| 7776 | * typical example would be handling the BACK key to update the application's |
| 7777 | * UI instead of allowing the IME to see it and close itself. |
| 7778 | * |
| 7779 | * @param keyCode The value in event.getKeyCode(). |
| 7780 | * @param event Description of the key event. |
| 7781 | * @return If you handled the event, return true. If you want to allow the |
| 7782 | * event to be handled by the next receiver, return false. |
| 7783 | */ |
| 7784 | public boolean onKeyPreIme(int keyCode, KeyEvent event) { |
| 7785 | return false; |
| 7786 | } |
| 7787 | |
| 7788 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7789 | * Default implementation of {@link KeyEvent.Callback#onKeyDown(int, KeyEvent) |
| 7790 | * KeyEvent.Callback.onKeyDown()}: perform press of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or {@link KeyEvent#KEYCODE_ENTER} |
| 7792 | * is released, if the view is enabled and clickable. |
| 7793 | * |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7794 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7795 | * although some may elect to do so in some situations. Do not rely on this to |
| 7796 | * catch software key presses. |
| 7797 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7798 | * @param keyCode A key code that represents the button pressed, from |
| 7799 | * {@link android.view.KeyEvent}. |
| 7800 | * @param event The KeyEvent object that defines the button action. |
| 7801 | */ |
| 7802 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 7803 | boolean result = false; |
| 7804 | |
| 7805 | switch (keyCode) { |
| 7806 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7807 | case KeyEvent.KEYCODE_ENTER: { |
| 7808 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7809 | return true; |
| 7810 | } |
| 7811 | // Long clickable items don't necessarily have to be clickable |
| 7812 | if (((mViewFlags & CLICKABLE) == CLICKABLE || |
| 7813 | (mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) && |
| 7814 | (event.getRepeatCount() == 0)) { |
| 7815 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7816 | checkForLongClick(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | return true; |
| 7818 | } |
| 7819 | break; |
| 7820 | } |
| 7821 | } |
| 7822 | return result; |
| 7823 | } |
| 7824 | |
| 7825 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7826 | * Default implementation of {@link KeyEvent.Callback#onKeyLongPress(int, KeyEvent) |
| 7827 | * KeyEvent.Callback.onKeyLongPress()}: always returns false (doesn't handle |
| 7828 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7829 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7830 | * although some may elect to do so in some situations. Do not rely on this to |
| 7831 | * catch software key presses. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 7832 | */ |
| 7833 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 7834 | return false; |
| 7835 | } |
| 7836 | |
| 7837 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 7838 | * Default implementation of {@link KeyEvent.Callback#onKeyUp(int, KeyEvent) |
| 7839 | * KeyEvent.Callback.onKeyUp()}: perform clicking of the view |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | * when {@link KeyEvent#KEYCODE_DPAD_CENTER} or |
| 7841 | * {@link KeyEvent#KEYCODE_ENTER} is released. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7842 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7843 | * although some may elect to do so in some situations. Do not rely on this to |
| 7844 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7845 | * |
| 7846 | * @param keyCode A key code that represents the button pressed, from |
| 7847 | * {@link android.view.KeyEvent}. |
| 7848 | * @param event The KeyEvent object that defines the button action. |
| 7849 | */ |
| 7850 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 7851 | boolean result = false; |
| 7852 | |
| 7853 | switch (keyCode) { |
| 7854 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 7855 | case KeyEvent.KEYCODE_ENTER: { |
| 7856 | if ((mViewFlags & ENABLED_MASK) == DISABLED) { |
| 7857 | return true; |
| 7858 | } |
| 7859 | if ((mViewFlags & CLICKABLE) == CLICKABLE && isPressed()) { |
| 7860 | setPressed(false); |
| 7861 | |
| 7862 | if (!mHasPerformedLongPress) { |
| 7863 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 7864 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | |
| 7866 | result = performClick(); |
| 7867 | } |
| 7868 | } |
| 7869 | break; |
| 7870 | } |
| 7871 | } |
| 7872 | return result; |
| 7873 | } |
| 7874 | |
| 7875 | /** |
| 7876 | * Default implementation of {@link KeyEvent.Callback#onKeyMultiple(int, int, KeyEvent) |
| 7877 | * KeyEvent.Callback.onKeyMultiple()}: always returns false (doesn't handle |
| 7878 | * the event). |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 7879 | * <p>Key presses in software keyboards will generally NOT trigger this listener, |
| 7880 | * although some may elect to do so in some situations. Do not rely on this to |
| 7881 | * catch software key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | * |
| 7883 | * @param keyCode A key code that represents the button pressed, from |
| 7884 | * {@link android.view.KeyEvent}. |
| 7885 | * @param repeatCount The number of times the action was made. |
| 7886 | * @param event The KeyEvent object that defines the button action. |
| 7887 | */ |
| 7888 | public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) { |
| 7889 | return false; |
| 7890 | } |
| 7891 | |
| 7892 | /** |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 7893 | * Called on the focused view when a key shortcut event is not handled. |
| 7894 | * Override this method to implement local key shortcuts for the View. |
| 7895 | * Key shortcuts can also be implemented by setting the |
| 7896 | * {@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] | 7897 | * |
| 7898 | * @param keyCode The value in event.getKeyCode(). |
| 7899 | * @param event Description of the key event. |
| 7900 | * @return If you handled the event, return true. If you want to allow the |
| 7901 | * event to be handled by the next receiver, return false. |
| 7902 | */ |
| 7903 | public boolean onKeyShortcut(int keyCode, KeyEvent event) { |
| 7904 | return false; |
| 7905 | } |
| 7906 | |
| 7907 | /** |
| 7908 | * Check whether the called view is a text editor, in which case it |
| 7909 | * would make sense to automatically display a soft input window for |
| 7910 | * it. Subclasses should override this if they implement |
| 7911 | * {@link #onCreateInputConnection(EditorInfo)} to return true if |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7912 | * a call on that method would return a non-null InputConnection, and |
| 7913 | * they are really a first-class editor that the user would normally |
| 7914 | * start typing on when the go into a window containing your view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7915 | * |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7916 | * <p>The default implementation always returns false. This does |
| 7917 | * <em>not</em> mean that its {@link #onCreateInputConnection(EditorInfo)} |
| 7918 | * will not be called or the user can not otherwise perform edits on your |
| 7919 | * view; it is just a hint to the system that this is not the primary |
| 7920 | * purpose of this view. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7921 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7922 | * @return Returns true if this view is a text editor, else false. |
| 7923 | */ |
| 7924 | public boolean onCheckIsTextEditor() { |
| 7925 | return false; |
| 7926 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7928 | /** |
| 7929 | * Create a new InputConnection for an InputMethod to interact |
| 7930 | * with the view. The default implementation returns null, since it doesn't |
| 7931 | * support input methods. You can override this to implement such support. |
| 7932 | * This is only needed for views that take focus and text input. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7933 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | * <p>When implementing this, you probably also want to implement |
| 7935 | * {@link #onCheckIsTextEditor()} to indicate you will return a |
| 7936 | * non-null InputConnection. |
| 7937 | * |
| 7938 | * @param outAttrs Fill in with attribute information about the connection. |
| 7939 | */ |
| 7940 | public InputConnection onCreateInputConnection(EditorInfo outAttrs) { |
| 7941 | return null; |
| 7942 | } |
| 7943 | |
| 7944 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7945 | * Called by the {@link android.view.inputmethod.InputMethodManager} |
| 7946 | * when a view who is not the current |
| 7947 | * input connection target is trying to make a call on the manager. The |
| 7948 | * default implementation returns false; you can override this to return |
| 7949 | * true for certain views if you are performing InputConnection proxying |
| 7950 | * to them. |
| 7951 | * @param view The View that is making the InputMethodManager call. |
| 7952 | * @return Return true to allow the call, false to reject. |
| 7953 | */ |
| 7954 | public boolean checkInputConnectionProxy(View view) { |
| 7955 | return false; |
| 7956 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7957 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 7958 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | * Show the context menu for this view. It is not safe to hold on to the |
| 7960 | * menu after returning from this method. |
| 7961 | * |
Gilles Debunne | f788a9f | 2010-07-22 10:17:23 -0700 | [diff] [blame] | 7962 | * You should normally not overload this method. Overload |
| 7963 | * {@link #onCreateContextMenu(ContextMenu)} or define an |
| 7964 | * {@link OnCreateContextMenuListener} to add items to the context menu. |
| 7965 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7966 | * @param menu The context menu to populate |
| 7967 | */ |
| 7968 | public void createContextMenu(ContextMenu menu) { |
| 7969 | ContextMenuInfo menuInfo = getContextMenuInfo(); |
| 7970 | |
| 7971 | // Sets the current menu info so all items added to menu will have |
| 7972 | // my extra info set. |
| 7973 | ((MenuBuilder)menu).setCurrentMenuInfo(menuInfo); |
| 7974 | |
| 7975 | onCreateContextMenu(menu); |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 7976 | ListenerInfo li = mListenerInfo; |
| 7977 | if (li != null && li.mOnCreateContextMenuListener != null) { |
| 7978 | li.mOnCreateContextMenuListener.onCreateContextMenu(menu, this, menuInfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7979 | } |
| 7980 | |
| 7981 | // Clear the extra information so subsequent items that aren't mine don't |
| 7982 | // have my extra info. |
| 7983 | ((MenuBuilder)menu).setCurrentMenuInfo(null); |
| 7984 | |
| 7985 | if (mParent != null) { |
| 7986 | mParent.createContextMenu(menu); |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | /** |
| 7991 | * Views should implement this if they have extra information to associate |
| 7992 | * with the context menu. The return result is supplied as a parameter to |
| 7993 | * the {@link OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} |
| 7994 | * callback. |
| 7995 | * |
| 7996 | * @return Extra information about the item for which the context menu |
| 7997 | * should be shown. This information will vary across different |
| 7998 | * subclasses of View. |
| 7999 | */ |
| 8000 | protected ContextMenuInfo getContextMenuInfo() { |
| 8001 | return null; |
| 8002 | } |
| 8003 | |
| 8004 | /** |
| 8005 | * Views should implement this if the view itself is going to add items to |
| 8006 | * the context menu. |
| 8007 | * |
| 8008 | * @param menu the context menu to populate |
| 8009 | */ |
| 8010 | protected void onCreateContextMenu(ContextMenu menu) { |
| 8011 | } |
| 8012 | |
| 8013 | /** |
| 8014 | * Implement this method to handle trackball motion events. The |
| 8015 | * <em>relative</em> movement of the trackball since the last event |
| 8016 | * can be retrieve with {@link MotionEvent#getX MotionEvent.getX()} and |
| 8017 | * {@link MotionEvent#getY MotionEvent.getY()}. These are normalized so |
| 8018 | * that a movement of 1 corresponds to the user pressing one DPAD key (so |
| 8019 | * they will often be fractional values, representing the more fine-grained |
| 8020 | * movement information available from a trackball). |
| 8021 | * |
| 8022 | * @param event The motion event. |
| 8023 | * @return True if the event was handled, false otherwise. |
| 8024 | */ |
| 8025 | public boolean onTrackballEvent(MotionEvent event) { |
| 8026 | return false; |
| 8027 | } |
| 8028 | |
| 8029 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8030 | * Implement this method to handle generic motion events. |
| 8031 | * <p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 8032 | * Generic motion events describe joystick movements, mouse hovers, track pad |
| 8033 | * touches, scroll wheel movements and other input events. The |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8034 | * {@link MotionEvent#getSource() source} of the motion event specifies |
| 8035 | * the class of input that was received. Implementations of this method |
| 8036 | * must examine the bits in the source before processing the event. |
| 8037 | * The following code example shows how this is done. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 8038 | * </p><p> |
| 8039 | * Generic motion events with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 8040 | * are delivered to the view under the pointer. All other generic motion events are |
| 8041 | * delivered to the focused view. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8042 | * </p> |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 8043 | * <pre> public boolean onGenericMotionEvent(MotionEvent event) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8044 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 8045 | * if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 8046 | * // process the joystick movement... |
| 8047 | * return true; |
| 8048 | * } |
| 8049 | * } |
| 8050 | * if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 8051 | * switch (event.getAction()) { |
| 8052 | * case MotionEvent.ACTION_HOVER_MOVE: |
| 8053 | * // process the mouse hover movement... |
| 8054 | * return true; |
| 8055 | * case MotionEvent.ACTION_SCROLL: |
| 8056 | * // process the scroll wheel movement... |
| 8057 | * return true; |
| 8058 | * } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8059 | * } |
| 8060 | * return super.onGenericMotionEvent(event); |
Scott Main | b303d83 | 2011-10-12 16:45:18 -0700 | [diff] [blame] | 8061 | * }</pre> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8062 | * |
| 8063 | * @param event The generic motion event being processed. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8064 | * @return True if the event was handled, false otherwise. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 8065 | */ |
| 8066 | public boolean onGenericMotionEvent(MotionEvent event) { |
| 8067 | return false; |
| 8068 | } |
| 8069 | |
| 8070 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8071 | * Implement this method to handle hover events. |
| 8072 | * <p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8073 | * This method is called whenever a pointer is hovering into, over, or out of the |
| 8074 | * bounds of a view and the view is not currently being touched. |
| 8075 | * Hover events are represented as pointer events with action |
| 8076 | * {@link MotionEvent#ACTION_HOVER_ENTER}, {@link MotionEvent#ACTION_HOVER_MOVE}, |
| 8077 | * or {@link MotionEvent#ACTION_HOVER_EXIT}. |
| 8078 | * </p> |
| 8079 | * <ul> |
| 8080 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_ENTER} |
| 8081 | * when the pointer enters the bounds of the view.</li> |
| 8082 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_MOVE} |
| 8083 | * when the pointer has already entered the bounds of the view and has moved.</li> |
| 8084 | * <li>The view receives a hover event with action {@link MotionEvent#ACTION_HOVER_EXIT} |
| 8085 | * when the pointer has exited the bounds of the view or when the pointer is |
| 8086 | * about to go down due to a button click, tap, or similar user action that |
| 8087 | * causes the view to be touched.</li> |
| 8088 | * </ul> |
| 8089 | * <p> |
| 8090 | * The view should implement this method to return true to indicate that it is |
| 8091 | * handling the hover event, such as by changing its drawable state. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8092 | * </p><p> |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8093 | * The default implementation calls {@link #setHovered} to update the hovered state |
| 8094 | * 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] | 8095 | * is enabled and is clickable. The default implementation also sends hover |
| 8096 | * accessibility events. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8097 | * </p> |
| 8098 | * |
| 8099 | * @param event The motion event that describes the hover. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8100 | * @return True if the view handled the hover event. |
| 8101 | * |
| 8102 | * @see #isHovered |
| 8103 | * @see #setHovered |
| 8104 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8105 | */ |
| 8106 | public boolean onHoverEvent(MotionEvent event) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8107 | // The root view may receive hover (or touch) events that are outside the bounds of |
| 8108 | // the window. This code ensures that we only send accessibility events for |
| 8109 | // hovers that are actually within the bounds of the root view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8110 | final int action = event.getActionMasked(); |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8111 | if (!mSendingHoverAccessibilityEvents) { |
| 8112 | if ((action == MotionEvent.ACTION_HOVER_ENTER |
| 8113 | || action == MotionEvent.ACTION_HOVER_MOVE) |
| 8114 | && !hasHoveredChild() |
| 8115 | && pointInView(event.getX(), event.getY())) { |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8116 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_ENTER); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8117 | mSendingHoverAccessibilityEvents = true; |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8118 | } |
| 8119 | } else { |
| 8120 | if (action == MotionEvent.ACTION_HOVER_EXIT |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8121 | || (action == MotionEvent.ACTION_MOVE |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8122 | && !pointInView(event.getX(), event.getY()))) { |
| 8123 | mSendingHoverAccessibilityEvents = false; |
Svetoslav Ganov | 8ffe8b3 | 2012-06-15 10:31:31 -0700 | [diff] [blame] | 8124 | sendAccessibilityHoverEvent(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8125 | // If the window does not have input focus we take away accessibility |
| 8126 | // focus as soon as the user stop hovering over the view. |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 8127 | if (mAttachInfo != null && !mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 8128 | getViewRootImpl().setAccessibilityFocus(null, null); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8129 | } |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8130 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8133 | if (isHoverable()) { |
Svetoslav Ganov | 4c1c101 | 2011-08-31 18:39:18 -0700 | [diff] [blame] | 8134 | switch (action) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8135 | case MotionEvent.ACTION_HOVER_ENTER: |
| 8136 | setHovered(true); |
| 8137 | break; |
| 8138 | case MotionEvent.ACTION_HOVER_EXIT: |
| 8139 | setHovered(false); |
| 8140 | break; |
| 8141 | } |
Jeff Brown | a1b2418 | 2011-07-28 13:38:24 -0700 | [diff] [blame] | 8142 | |
| 8143 | // Dispatch the event to onGenericMotionEvent before returning true. |
| 8144 | // This is to provide compatibility with existing applications that |
| 8145 | // handled HOVER_MOVE events in onGenericMotionEvent and that would |
| 8146 | // break because of the new default handling for hoverable views |
| 8147 | // in onHoverEvent. |
| 8148 | // Note that onGenericMotionEvent will be called by default when |
| 8149 | // onHoverEvent returns false (refer to dispatchGenericMotionEvent). |
| 8150 | dispatchGenericMotionEventInternal(event); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8151 | return true; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8152 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8153 | |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 8154 | return false; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8155 | } |
| 8156 | |
| 8157 | /** |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8158 | * Returns true if the view should handle {@link #onHoverEvent} |
| 8159 | * by calling {@link #setHovered} to change its hovered state. |
| 8160 | * |
| 8161 | * @return True if the view is hoverable. |
| 8162 | */ |
| 8163 | private boolean isHoverable() { |
| 8164 | final int viewFlags = mViewFlags; |
| 8165 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
| 8166 | return false; |
| 8167 | } |
| 8168 | |
| 8169 | return (viewFlags & CLICKABLE) == CLICKABLE |
| 8170 | || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE; |
| 8171 | } |
| 8172 | |
| 8173 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8174 | * Returns true if the view is currently hovered. |
| 8175 | * |
| 8176 | * @return True if the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8177 | * |
| 8178 | * @see #setHovered |
| 8179 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8180 | */ |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8181 | @ViewDebug.ExportedProperty |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8182 | public boolean isHovered() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8183 | return (mPrivateFlags & PFLAG_HOVERED) != 0; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8184 | } |
| 8185 | |
| 8186 | /** |
| 8187 | * Sets whether the view is currently hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8188 | * <p> |
| 8189 | * Calling this method also changes the drawable state of the view. This |
| 8190 | * enables the view to react to hover by using different drawable resources |
| 8191 | * to change its appearance. |
| 8192 | * </p><p> |
| 8193 | * The {@link #onHoverChanged} method is called when the hovered state changes. |
| 8194 | * </p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8195 | * |
| 8196 | * @param hovered True if the view is hovered. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8197 | * |
| 8198 | * @see #isHovered |
| 8199 | * @see #onHoverChanged |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8200 | */ |
| 8201 | public void setHovered(boolean hovered) { |
| 8202 | if (hovered) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8203 | if ((mPrivateFlags & PFLAG_HOVERED) == 0) { |
| 8204 | mPrivateFlags |= PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8205 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8206 | onHoverChanged(true); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8207 | } |
| 8208 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8209 | if ((mPrivateFlags & PFLAG_HOVERED) != 0) { |
| 8210 | mPrivateFlags &= ~PFLAG_HOVERED; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8211 | refreshDrawableState(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8212 | onHoverChanged(false); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 8213 | } |
| 8214 | } |
| 8215 | } |
| 8216 | |
| 8217 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8218 | * Implement this method to handle hover state changes. |
| 8219 | * <p> |
| 8220 | * This method is called whenever the hover state changes as a result of a |
| 8221 | * call to {@link #setHovered}. |
| 8222 | * </p> |
| 8223 | * |
| 8224 | * @param hovered The current hover state, as returned by {@link #isHovered}. |
| 8225 | * |
| 8226 | * @see #isHovered |
| 8227 | * @see #setHovered |
| 8228 | */ |
| 8229 | public void onHoverChanged(boolean hovered) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 8230 | } |
| 8231 | |
| 8232 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | * Implement this method to handle touch screen motion events. |
| 8234 | * |
| 8235 | * @param event The motion event. |
| 8236 | * @return True if the event was handled, false otherwise. |
| 8237 | */ |
| 8238 | public boolean onTouchEvent(MotionEvent event) { |
| 8239 | final int viewFlags = mViewFlags; |
| 8240 | |
| 8241 | if ((viewFlags & ENABLED_MASK) == DISABLED) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8242 | if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8243 | setPressed(false); |
Svetoslav Ganov | 77b80c0 | 2011-03-15 20:52:58 -0700 | [diff] [blame] | 8244 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8245 | // A disabled view that is clickable still consumes the touch |
| 8246 | // events, it just doesn't respond to them. |
| 8247 | return (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8248 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)); |
| 8249 | } |
| 8250 | |
| 8251 | if (mTouchDelegate != null) { |
| 8252 | if (mTouchDelegate.onTouchEvent(event)) { |
| 8253 | return true; |
| 8254 | } |
| 8255 | } |
| 8256 | |
| 8257 | if (((viewFlags & CLICKABLE) == CLICKABLE || |
| 8258 | (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) { |
| 8259 | switch (event.getAction()) { |
| 8260 | case MotionEvent.ACTION_UP: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8261 | boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0; |
| 8262 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8263 | // take focus if we don't have it already and we should in |
| 8264 | // touch mode. |
| 8265 | boolean focusTaken = false; |
| 8266 | if (isFocusable() && isFocusableInTouchMode() && !isFocused()) { |
| 8267 | focusTaken = requestFocus(); |
| 8268 | } |
| 8269 | |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8270 | if (prepressed) { |
| 8271 | // The button is being released before we actually |
| 8272 | // showed it as pressed. Make it show the pressed |
| 8273 | // state now (before scheduling the click) to ensure |
| 8274 | // the user sees it. |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8275 | setPressed(true); |
Dianne Hackborn | be1f622 | 2011-01-20 15:24:28 -0800 | [diff] [blame] | 8276 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | if (!mHasPerformedLongPress) { |
| 8279 | // This is a tap, so remove the longpress check |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8280 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8281 | |
| 8282 | // Only perform take click actions if we were in the pressed state |
| 8283 | if (!focusTaken) { |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 8284 | // Use a Runnable and post this rather than calling |
| 8285 | // performClick directly. This lets other visual state |
| 8286 | // of the view update before click actions start. |
| 8287 | if (mPerformClick == null) { |
| 8288 | mPerformClick = new PerformClick(); |
| 8289 | } |
| 8290 | if (!post(mPerformClick)) { |
| 8291 | performClick(); |
| 8292 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8293 | } |
| 8294 | } |
| 8295 | |
| 8296 | if (mUnsetPressedState == null) { |
| 8297 | mUnsetPressedState = new UnsetPressedState(); |
| 8298 | } |
| 8299 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8300 | if (prepressed) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8301 | postDelayed(mUnsetPressedState, |
| 8302 | ViewConfiguration.getPressedStateDuration()); |
| 8303 | } else if (!post(mUnsetPressedState)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8304 | // If the post failed, unpress right now |
| 8305 | mUnsetPressedState.run(); |
| 8306 | } |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8307 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8308 | } |
| 8309 | break; |
| 8310 | |
| 8311 | case MotionEvent.ACTION_DOWN: |
Adam Powell | 3b02339 | 2010-03-11 16:30:28 -0800 | [diff] [blame] | 8312 | mHasPerformedLongPress = false; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8313 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 8314 | if (performButtonActionOnTouchDown(event)) { |
| 8315 | break; |
| 8316 | } |
| 8317 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8318 | // 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] | 8319 | boolean isInScrollingContainer = isInScrollingContainer(); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8320 | |
| 8321 | // For views inside a scrolling container, delay the pressed feedback for |
| 8322 | // a short period in case this is a scroll. |
| 8323 | if (isInScrollingContainer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8324 | mPrivateFlags |= PFLAG_PREPRESSED; |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8325 | if (mPendingCheckForTap == null) { |
| 8326 | mPendingCheckForTap = new CheckForTap(); |
| 8327 | } |
| 8328 | postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); |
| 8329 | } else { |
| 8330 | // Not inside a scrolling container, so show the feedback right away |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8331 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 8332 | checkForLongClick(0); |
| 8333 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8334 | break; |
| 8335 | |
| 8336 | case MotionEvent.ACTION_CANCEL: |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8337 | setPressed(false); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8338 | removeTapCallback(); |
Adam Powell | 5311c44 | 2012-10-22 12:15:49 -0700 | [diff] [blame] | 8339 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | break; |
| 8341 | |
| 8342 | case MotionEvent.ACTION_MOVE: |
| 8343 | final int x = (int) event.getX(); |
| 8344 | final int y = (int) event.getY(); |
| 8345 | |
| 8346 | // Be lenient about moving outside of buttons |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8347 | if (!pointInView(x, y, mTouchSlop)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8348 | // Outside button |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8349 | removeTapCallback(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8350 | if ((mPrivateFlags & PFLAG_PRESSED) != 0) { |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8351 | // Remove any future long press/tap checks |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8352 | removeLongPressCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 8354 | setPressed(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8355 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8356 | } |
| 8357 | break; |
| 8358 | } |
| 8359 | return true; |
| 8360 | } |
| 8361 | |
| 8362 | return false; |
| 8363 | } |
| 8364 | |
| 8365 | /** |
Adam Powell | 1029866 | 2011-08-14 18:26:30 -0700 | [diff] [blame] | 8366 | * @hide |
| 8367 | */ |
| 8368 | public boolean isInScrollingContainer() { |
| 8369 | ViewParent p = getParent(); |
| 8370 | while (p != null && p instanceof ViewGroup) { |
| 8371 | if (((ViewGroup) p).shouldDelayChildPressedState()) { |
| 8372 | return true; |
| 8373 | } |
| 8374 | p = p.getParent(); |
| 8375 | } |
| 8376 | return false; |
| 8377 | } |
| 8378 | |
| 8379 | /** |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8380 | * Remove the longpress detection timer. |
| 8381 | */ |
| 8382 | private void removeLongPressCallback() { |
| 8383 | if (mPendingCheckForLongPress != null) { |
| 8384 | removeCallbacks(mPendingCheckForLongPress); |
| 8385 | } |
| 8386 | } |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 8387 | |
| 8388 | /** |
| 8389 | * Remove the pending click action |
| 8390 | */ |
| 8391 | private void removePerformClickCallback() { |
| 8392 | if (mPerformClick != null) { |
| 8393 | removeCallbacks(mPerformClick); |
| 8394 | } |
| 8395 | } |
| 8396 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8397 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8398 | * Remove the prepress detection timer. |
| 8399 | */ |
| 8400 | private void removeUnsetPressCallback() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8401 | if ((mPrivateFlags & PFLAG_PRESSED) != 0 && mUnsetPressedState != null) { |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 8402 | setPressed(false); |
| 8403 | removeCallbacks(mUnsetPressedState); |
| 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | /** |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8408 | * Remove the tap detection timer. |
| 8409 | */ |
| 8410 | private void removeTapCallback() { |
| 8411 | if (mPendingCheckForTap != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8412 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 8413 | removeCallbacks(mPendingCheckForTap); |
| 8414 | } |
| 8415 | } |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8416 | |
| 8417 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | * Cancels a pending long press. Your subclass can use this if you |
| 8419 | * want the context menu to come up if the user presses and holds |
| 8420 | * at the same place, but you don't want it to come up if they press |
| 8421 | * and then move around enough to cause scrolling. |
| 8422 | */ |
| 8423 | public void cancelLongPress() { |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 8424 | removeLongPressCallback(); |
Adam Powell | 732ebb1 | 2010-02-02 15:28:14 -0800 | [diff] [blame] | 8425 | |
| 8426 | /* |
| 8427 | * The prepressed state handled by the tap callback is a display |
| 8428 | * construct, but the tap callback will post a long press callback |
| 8429 | * less its own timeout. Remove it here. |
| 8430 | */ |
| 8431 | removeTapCallback(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8432 | } |
| 8433 | |
| 8434 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8435 | * Remove the pending callback for sending a |
| 8436 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 8437 | */ |
| 8438 | private void removeSendViewScrolledAccessibilityEventCallback() { |
| 8439 | if (mSendViewScrolledAccessibilityEvent != null) { |
| 8440 | removeCallbacks(mSendViewScrolledAccessibilityEvent); |
Svetoslav Ganov | 4a812ae | 2012-05-29 16:46:10 -0700 | [diff] [blame] | 8441 | mSendViewScrolledAccessibilityEvent.mIsPending = false; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8446 | * Sets the TouchDelegate for this View. |
| 8447 | */ |
| 8448 | public void setTouchDelegate(TouchDelegate delegate) { |
| 8449 | mTouchDelegate = delegate; |
| 8450 | } |
| 8451 | |
| 8452 | /** |
| 8453 | * Gets the TouchDelegate for this View. |
| 8454 | */ |
| 8455 | public TouchDelegate getTouchDelegate() { |
| 8456 | return mTouchDelegate; |
| 8457 | } |
| 8458 | |
| 8459 | /** |
| 8460 | * Set flags controlling behavior of this view. |
| 8461 | * |
| 8462 | * @param flags Constant indicating the value which should be set |
| 8463 | * @param mask Constant indicating the bit range that should be changed |
| 8464 | */ |
| 8465 | void setFlags(int flags, int mask) { |
| 8466 | int old = mViewFlags; |
| 8467 | mViewFlags = (mViewFlags & ~mask) | (flags & mask); |
| 8468 | |
| 8469 | int changed = mViewFlags ^ old; |
| 8470 | if (changed == 0) { |
| 8471 | return; |
| 8472 | } |
| 8473 | int privateFlags = mPrivateFlags; |
| 8474 | |
| 8475 | /* Check if the FOCUSABLE bit has changed */ |
| 8476 | if (((changed & FOCUSABLE_MASK) != 0) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8477 | ((privateFlags & PFLAG_HAS_BOUNDS) !=0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8478 | if (((old & FOCUSABLE_MASK) == FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8479 | && ((privateFlags & PFLAG_FOCUSED) != 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8480 | /* Give up focus if we are no longer focusable */ |
| 8481 | clearFocus(); |
| 8482 | } else if (((old & FOCUSABLE_MASK) == NOT_FOCUSABLE) |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8483 | && ((privateFlags & PFLAG_FOCUSED) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8484 | /* |
| 8485 | * Tell the view system that we are now available to take focus |
| 8486 | * if no one else already has it. |
| 8487 | */ |
| 8488 | if (mParent != null) mParent.focusableViewAvailable(this); |
| 8489 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8490 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8491 | notifyAccessibilityStateChanged(); |
| 8492 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | } |
| 8494 | |
| 8495 | if ((flags & VISIBILITY_MASK) == VISIBLE) { |
| 8496 | if ((changed & VISIBILITY_MASK) != 0) { |
| 8497 | /* |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8498 | * 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] | 8499 | * it was not visible. Marking it drawn ensures that the invalidation will |
| 8500 | * go through. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8501 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8502 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 4324ead | 2011-08-24 21:31:03 -0700 | [diff] [blame] | 8503 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8504 | |
| 8505 | needGlobalAttributesUpdate(true); |
| 8506 | |
| 8507 | // a view becoming visible is worth notifying the parent |
| 8508 | // about in case nothing has focus. even if this specific view |
| 8509 | // isn't focusable, it may contain something that is, so let |
| 8510 | // the root view try to give this focus if nothing else does. |
| 8511 | if ((mParent != null) && (mBottom > mTop) && (mRight > mLeft)) { |
| 8512 | mParent.focusableViewAvailable(this); |
| 8513 | } |
| 8514 | } |
| 8515 | } |
| 8516 | |
| 8517 | /* Check if the GONE bit has changed */ |
| 8518 | if ((changed & GONE) != 0) { |
| 8519 | needGlobalAttributesUpdate(false); |
| 8520 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8521 | |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8522 | if (((mViewFlags & VISIBILITY_MASK) == GONE)) { |
| 8523 | if (hasFocus()) clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8524 | clearAccessibilityFocus(); |
Romain Guy | ecd80ee | 2009-12-03 17:13:02 -0800 | [diff] [blame] | 8525 | destroyDrawingCache(); |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 8526 | if (mParent instanceof View) { |
| 8527 | // GONE views noop invalidation, so invalidate the parent |
| 8528 | ((View) mParent).invalidate(true); |
| 8529 | } |
| 8530 | // Mark the view drawn to ensure that it gets invalidated properly the next |
| 8531 | // time it is visible and gets invalidated |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8532 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8533 | } |
| 8534 | if (mAttachInfo != null) { |
| 8535 | mAttachInfo.mViewVisibilityChanged = true; |
| 8536 | } |
| 8537 | } |
| 8538 | |
| 8539 | /* Check if the VISIBLE bit has changed */ |
| 8540 | if ((changed & INVISIBLE) != 0) { |
| 8541 | needGlobalAttributesUpdate(false); |
Chet Haase | c8a9a70 | 2011-06-17 12:13:42 -0700 | [diff] [blame] | 8542 | /* |
| 8543 | * If this view is becoming invisible, set the DRAWN flag so that |
| 8544 | * the next invalidate() will not be skipped. |
| 8545 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8546 | mPrivateFlags |= PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | |
| 8548 | if (((mViewFlags & VISIBILITY_MASK) == INVISIBLE) && hasFocus()) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8549 | // 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] | 8550 | if (getRootView() != this) { |
| 8551 | clearFocus(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8552 | clearAccessibilityFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | } |
| 8554 | } |
| 8555 | if (mAttachInfo != null) { |
| 8556 | mAttachInfo.mViewVisibilityChanged = true; |
| 8557 | } |
| 8558 | } |
| 8559 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8560 | if ((changed & VISIBILITY_MASK) != 0) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8561 | if (mParent instanceof ViewGroup) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 8562 | ((ViewGroup) mParent).onChildVisibilityChanged(this, |
| 8563 | (changed & VISIBILITY_MASK), (flags & VISIBILITY_MASK)); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8564 | ((View) mParent).invalidate(true); |
Chet Haase | e4e6e20 | 2011-08-29 14:34:30 -0700 | [diff] [blame] | 8565 | } else if (mParent != null) { |
| 8566 | mParent.invalidateChild(this, null); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 8567 | } |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 8568 | dispatchVisibilityChanged(this, (flags & VISIBILITY_MASK)); |
| 8569 | } |
| 8570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | if ((changed & WILL_NOT_CACHE_DRAWING) != 0) { |
| 8572 | destroyDrawingCache(); |
| 8573 | } |
| 8574 | |
| 8575 | if ((changed & DRAWING_CACHE_ENABLED) != 0) { |
| 8576 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8577 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8578 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8579 | } |
| 8580 | |
| 8581 | if ((changed & DRAWING_CACHE_QUALITY_MASK) != 0) { |
| 8582 | destroyDrawingCache(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8583 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | if ((changed & DRAW_MASK) != 0) { |
| 8587 | if ((mViewFlags & WILL_NOT_DRAW) != 0) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8588 | if (mBackground != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8589 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 8590 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8591 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8592 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | } |
| 8594 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8595 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | } |
| 8597 | requestLayout(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 8598 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | } |
| 8600 | |
| 8601 | if ((changed & KEEP_SCREEN_ON) != 0) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8602 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | mParent.recomputeViewAttributes(this); |
| 8604 | } |
| 8605 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8606 | |
| 8607 | if (AccessibilityManager.getInstance(mContext).isEnabled() |
| 8608 | && ((changed & FOCUSABLE) != 0 || (changed & CLICKABLE) != 0 |
| 8609 | || (changed & LONG_CLICKABLE) != 0 || (changed & ENABLED) != 0)) { |
| 8610 | notifyAccessibilityStateChanged(); |
| 8611 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8612 | } |
| 8613 | |
| 8614 | /** |
| 8615 | * Change the view's z order in the tree, so it's on top of other sibling |
| 8616 | * views |
| 8617 | */ |
| 8618 | public void bringToFront() { |
| 8619 | if (mParent != null) { |
| 8620 | mParent.bringChildToFront(this); |
| 8621 | } |
| 8622 | } |
| 8623 | |
| 8624 | /** |
| 8625 | * This is called in response to an internal scroll in this view (i.e., the |
| 8626 | * view scrolled its own contents). This is typically as a result of |
| 8627 | * {@link #scrollBy(int, int)} or {@link #scrollTo(int, int)} having been |
| 8628 | * called. |
| 8629 | * |
| 8630 | * @param l Current horizontal scroll origin. |
| 8631 | * @param t Current vertical scroll origin. |
| 8632 | * @param oldl Previous horizontal scroll origin. |
| 8633 | * @param oldt Previous vertical scroll origin. |
| 8634 | */ |
| 8635 | protected void onScrollChanged(int l, int t, int oldl, int oldt) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 8636 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 8637 | postSendViewScrolledAccessibilityEventCallback(); |
| 8638 | } |
| 8639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8640 | mBackgroundSizeChanged = true; |
| 8641 | |
| 8642 | final AttachInfo ai = mAttachInfo; |
| 8643 | if (ai != null) { |
| 8644 | ai.mViewScrollChanged = true; |
| 8645 | } |
| 8646 | } |
| 8647 | |
| 8648 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 8649 | * Interface definition for a callback to be invoked when the layout bounds of a view |
| 8650 | * changes due to layout processing. |
| 8651 | */ |
| 8652 | public interface OnLayoutChangeListener { |
| 8653 | /** |
| 8654 | * Called when the focus state of a view has changed. |
| 8655 | * |
| 8656 | * @param v The view whose state has changed. |
| 8657 | * @param left The new value of the view's left property. |
| 8658 | * @param top The new value of the view's top property. |
| 8659 | * @param right The new value of the view's right property. |
| 8660 | * @param bottom The new value of the view's bottom property. |
| 8661 | * @param oldLeft The previous value of the view's left property. |
| 8662 | * @param oldTop The previous value of the view's top property. |
| 8663 | * @param oldRight The previous value of the view's right property. |
| 8664 | * @param oldBottom The previous value of the view's bottom property. |
| 8665 | */ |
| 8666 | void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 8667 | int oldLeft, int oldTop, int oldRight, int oldBottom); |
| 8668 | } |
| 8669 | |
| 8670 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | * This is called during layout when the size of this view has changed. If |
| 8672 | * you were just added to the view hierarchy, you're called with the old |
| 8673 | * values of 0. |
| 8674 | * |
| 8675 | * @param w Current width of this view. |
| 8676 | * @param h Current height of this view. |
| 8677 | * @param oldw Old width of this view. |
| 8678 | * @param oldh Old height of this view. |
| 8679 | */ |
| 8680 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
| 8681 | } |
| 8682 | |
| 8683 | /** |
| 8684 | * Called by draw to draw the child views. This may be overridden |
| 8685 | * by derived classes to gain control just before its children are drawn |
| 8686 | * (but after its own view has been drawn). |
| 8687 | * @param canvas the canvas on which to draw the view |
| 8688 | */ |
| 8689 | protected void dispatchDraw(Canvas canvas) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8691 | } |
| 8692 | |
| 8693 | /** |
| 8694 | * Gets the parent of this view. Note that the parent is a |
| 8695 | * ViewParent and not necessarily a View. |
| 8696 | * |
| 8697 | * @return Parent of this view. |
| 8698 | */ |
| 8699 | public final ViewParent getParent() { |
| 8700 | return mParent; |
| 8701 | } |
| 8702 | |
| 8703 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 8704 | * Set the horizontal scrolled position of your view. This will cause a call to |
| 8705 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8706 | * invalidated. |
| 8707 | * @param value the x position to scroll to |
| 8708 | */ |
| 8709 | public void setScrollX(int value) { |
| 8710 | scrollTo(value, mScrollY); |
| 8711 | } |
| 8712 | |
| 8713 | /** |
| 8714 | * Set the vertical scrolled position of your view. This will cause a call to |
| 8715 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 8716 | * invalidated. |
| 8717 | * @param value the y position to scroll to |
| 8718 | */ |
| 8719 | public void setScrollY(int value) { |
| 8720 | scrollTo(mScrollX, value); |
| 8721 | } |
| 8722 | |
| 8723 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8724 | * Return the scrolled left position of this view. This is the left edge of |
| 8725 | * the displayed part of your view. You do not need to draw any pixels |
| 8726 | * farther left, since those are outside of the frame of your view on |
| 8727 | * screen. |
| 8728 | * |
| 8729 | * @return The left edge of the displayed part of your view, in pixels. |
| 8730 | */ |
| 8731 | public final int getScrollX() { |
| 8732 | return mScrollX; |
| 8733 | } |
| 8734 | |
| 8735 | /** |
| 8736 | * Return the scrolled top position of this view. This is the top edge of |
| 8737 | * the displayed part of your view. You do not need to draw any pixels above |
| 8738 | * it, since those are outside of the frame of your view on screen. |
| 8739 | * |
| 8740 | * @return The top edge of the displayed part of your view, in pixels. |
| 8741 | */ |
| 8742 | public final int getScrollY() { |
| 8743 | return mScrollY; |
| 8744 | } |
| 8745 | |
| 8746 | /** |
| 8747 | * Return the width of the your view. |
| 8748 | * |
| 8749 | * @return The width of your view, in pixels. |
| 8750 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8751 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8752 | public final int getWidth() { |
| 8753 | return mRight - mLeft; |
| 8754 | } |
| 8755 | |
| 8756 | /** |
| 8757 | * Return the height of your view. |
| 8758 | * |
| 8759 | * @return The height of your view, in pixels. |
| 8760 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 8761 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8762 | public final int getHeight() { |
| 8763 | return mBottom - mTop; |
| 8764 | } |
| 8765 | |
| 8766 | /** |
| 8767 | * Return the visible drawing bounds of your view. Fills in the output |
| 8768 | * rectangle with the values from getScrollX(), getScrollY(), |
Svetoslav Ganov | 78bd983 | 2012-10-15 19:12:29 -0700 | [diff] [blame] | 8769 | * getWidth(), and getHeight(). These bounds do not account for any |
| 8770 | * transformation properties currently set on the view, such as |
| 8771 | * {@link #setScaleX(float)} or {@link #setRotation(float)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8772 | * |
| 8773 | * @param outRect The (scrolled) drawing bounds of the view. |
| 8774 | */ |
| 8775 | public void getDrawingRect(Rect outRect) { |
| 8776 | outRect.left = mScrollX; |
| 8777 | outRect.top = mScrollY; |
| 8778 | outRect.right = mScrollX + (mRight - mLeft); |
| 8779 | outRect.bottom = mScrollY + (mBottom - mTop); |
| 8780 | } |
| 8781 | |
| 8782 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8783 | * Like {@link #getMeasuredWidthAndState()}, but only returns the |
| 8784 | * raw width component (that is the result is masked by |
| 8785 | * {@link #MEASURED_SIZE_MASK}). |
| 8786 | * |
| 8787 | * @return The raw measured width of this view. |
| 8788 | */ |
| 8789 | public final int getMeasuredWidth() { |
| 8790 | return mMeasuredWidth & MEASURED_SIZE_MASK; |
| 8791 | } |
| 8792 | |
| 8793 | /** |
| 8794 | * Return the full width measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8795 | * 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] | 8796 | * 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] | 8797 | * This should be used during measurement and layout calculations only. Use |
| 8798 | * {@link #getWidth()} to see how wide a view is after layout. |
| 8799 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8800 | * @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] | 8801 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8802 | public final int getMeasuredWidthAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8803 | return mMeasuredWidth; |
| 8804 | } |
| 8805 | |
| 8806 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8807 | * Like {@link #getMeasuredHeightAndState()}, but only returns the |
| 8808 | * raw width component (that is the result is masked by |
| 8809 | * {@link #MEASURED_SIZE_MASK}). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8810 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8811 | * @return The raw measured height of this view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8812 | */ |
| 8813 | public final int getMeasuredHeight() { |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8814 | return mMeasuredHeight & MEASURED_SIZE_MASK; |
| 8815 | } |
| 8816 | |
| 8817 | /** |
| 8818 | * Return the full height measurement information for this view as computed |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 8819 | * 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] | 8820 | * as defined by {@link #MEASURED_SIZE_MASK} and {@link #MEASURED_STATE_TOO_SMALL}. |
| 8821 | * This should be used during measurement and layout calculations only. Use |
| 8822 | * {@link #getHeight()} to see how wide a view is after layout. |
| 8823 | * |
| 8824 | * @return The measured width of this view as a bit mask. |
| 8825 | */ |
| 8826 | public final int getMeasuredHeightAndState() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8827 | return mMeasuredHeight; |
| 8828 | } |
| 8829 | |
| 8830 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 8831 | * Return only the state bits of {@link #getMeasuredWidthAndState()} |
| 8832 | * and {@link #getMeasuredHeightAndState()}, combined into one integer. |
| 8833 | * The width component is in the regular bits {@link #MEASURED_STATE_MASK} |
| 8834 | * and the height component is at the shifted bits |
| 8835 | * {@link #MEASURED_HEIGHT_STATE_SHIFT}>>{@link #MEASURED_STATE_MASK}. |
| 8836 | */ |
| 8837 | public final int getMeasuredState() { |
| 8838 | return (mMeasuredWidth&MEASURED_STATE_MASK) |
| 8839 | | ((mMeasuredHeight>>MEASURED_HEIGHT_STATE_SHIFT) |
| 8840 | & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); |
| 8841 | } |
| 8842 | |
| 8843 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8844 | * The transform matrix of this view, which is calculated based on the current |
| 8845 | * roation, scale, and pivot properties. |
| 8846 | * |
| 8847 | * @see #getRotation() |
| 8848 | * @see #getScaleX() |
| 8849 | * @see #getScaleY() |
| 8850 | * @see #getPivotX() |
| 8851 | * @see #getPivotY() |
| 8852 | * @return The current transform matrix for the view |
| 8853 | */ |
| 8854 | public Matrix getMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8855 | if (mTransformationInfo != null) { |
| 8856 | updateMatrix(); |
| 8857 | return mTransformationInfo.mMatrix; |
| 8858 | } |
| 8859 | return Matrix.IDENTITY_MATRIX; |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8860 | } |
| 8861 | |
| 8862 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8863 | * Utility function to determine if the value is far enough away from zero to be |
| 8864 | * considered non-zero. |
| 8865 | * @param value A floating point value to check for zero-ness |
| 8866 | * @return whether the passed-in value is far enough away from zero to be considered non-zero |
| 8867 | */ |
| 8868 | private static boolean nonzero(float value) { |
| 8869 | return (value < -NONZERO_EPSILON || value > NONZERO_EPSILON); |
| 8870 | } |
| 8871 | |
| 8872 | /** |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8873 | * Returns true if the transform matrix is the identity matrix. |
| 8874 | * Recomputes the matrix if necessary. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 8875 | * |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 8876 | * @return True if the transform matrix is the identity matrix, false otherwise. |
| 8877 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8878 | final boolean hasIdentityMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8879 | if (mTransformationInfo != null) { |
| 8880 | updateMatrix(); |
| 8881 | return mTransformationInfo.mMatrixIsIdentity; |
| 8882 | } |
| 8883 | return true; |
| 8884 | } |
| 8885 | |
| 8886 | void ensureTransformationInfo() { |
| 8887 | if (mTransformationInfo == null) { |
| 8888 | mTransformationInfo = new TransformationInfo(); |
| 8889 | } |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | /** |
| 8893 | * Recomputes the transform matrix if necessary. |
| 8894 | */ |
Romain Guy | 2fe9a8f | 2010-10-04 20:17:01 -0700 | [diff] [blame] | 8895 | private void updateMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8896 | final TransformationInfo info = mTransformationInfo; |
| 8897 | if (info == null) { |
| 8898 | return; |
| 8899 | } |
| 8900 | if (info.mMatrixDirty) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8901 | // transform-related properties have changed since the last time someone |
| 8902 | // asked for the matrix; recalculate it with the current values |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8903 | |
| 8904 | // Figure out if we need to update the pivot point |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 8905 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8906 | if ((mRight - mLeft) != info.mPrevWidth || (mBottom - mTop) != info.mPrevHeight) { |
| 8907 | info.mPrevWidth = mRight - mLeft; |
| 8908 | info.mPrevHeight = mBottom - mTop; |
| 8909 | info.mPivotX = info.mPrevWidth / 2f; |
| 8910 | info.mPivotY = info.mPrevHeight / 2f; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8911 | } |
| 8912 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8913 | info.mMatrix.reset(); |
| 8914 | if (!nonzero(info.mRotationX) && !nonzero(info.mRotationY)) { |
| 8915 | info.mMatrix.setTranslate(info.mTranslationX, info.mTranslationY); |
| 8916 | info.mMatrix.preRotate(info.mRotation, info.mPivotX, info.mPivotY); |
| 8917 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 8918 | } else { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8919 | if (info.mCamera == null) { |
| 8920 | info.mCamera = new Camera(); |
| 8921 | info.matrix3D = new Matrix(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8922 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8923 | info.mCamera.save(); |
| 8924 | info.mMatrix.preScale(info.mScaleX, info.mScaleY, info.mPivotX, info.mPivotY); |
| 8925 | info.mCamera.rotate(info.mRotationX, info.mRotationY, -info.mRotation); |
| 8926 | info.mCamera.getMatrix(info.matrix3D); |
| 8927 | info.matrix3D.preTranslate(-info.mPivotX, -info.mPivotY); |
| 8928 | info.matrix3D.postTranslate(info.mPivotX + info.mTranslationX, |
| 8929 | info.mPivotY + info.mTranslationY); |
| 8930 | info.mMatrix.postConcat(info.matrix3D); |
| 8931 | info.mCamera.restore(); |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 8932 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8933 | info.mMatrixDirty = false; |
| 8934 | info.mMatrixIsIdentity = info.mMatrix.isIdentity(); |
| 8935 | info.mInverseMatrixDirty = true; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8936 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8937 | } |
| 8938 | |
Tobias Dubois | defdb1e | 2010-12-15 11:35:30 +0100 | [diff] [blame] | 8939 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8940 | * Utility method to retrieve the inverse of the current mMatrix property. |
| 8941 | * We cache the matrix to avoid recalculating it when transform properties |
| 8942 | * have not changed. |
| 8943 | * |
| 8944 | * @return The inverse of the current matrix of this view. |
| 8945 | */ |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 8946 | final Matrix getInverseMatrix() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8947 | final TransformationInfo info = mTransformationInfo; |
| 8948 | if (info != null) { |
| 8949 | updateMatrix(); |
| 8950 | if (info.mInverseMatrixDirty) { |
| 8951 | if (info.mInverseMatrix == null) { |
| 8952 | info.mInverseMatrix = new Matrix(); |
| 8953 | } |
| 8954 | info.mMatrix.invert(info.mInverseMatrix); |
| 8955 | info.mInverseMatrixDirty = false; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8956 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8957 | return info.mInverseMatrix; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8958 | } |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 8959 | return Matrix.IDENTITY_MATRIX; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 8960 | } |
| 8961 | |
| 8962 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 8963 | * Gets the distance along the Z axis from the camera to this view. |
| 8964 | * |
| 8965 | * @see #setCameraDistance(float) |
| 8966 | * |
| 8967 | * @return The distance along the Z axis. |
| 8968 | */ |
| 8969 | public float getCameraDistance() { |
| 8970 | ensureTransformationInfo(); |
| 8971 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
| 8972 | final TransformationInfo info = mTransformationInfo; |
| 8973 | if (info.mCamera == null) { |
| 8974 | info.mCamera = new Camera(); |
| 8975 | info.matrix3D = new Matrix(); |
| 8976 | } |
| 8977 | return -(info.mCamera.getLocationZ() * dpi); |
| 8978 | } |
| 8979 | |
| 8980 | /** |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8981 | * <p>Sets the distance along the Z axis (orthogonal to the X/Y plane on which |
| 8982 | * views are drawn) from the camera to this view. The camera's distance |
| 8983 | * affects 3D transformations, for instance rotations around the X and Y |
| 8984 | * 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] | 8985 | * 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] | 8986 | * use a camera distance that's greater than the height (X axis rotation) or |
| 8987 | * the width (Y axis rotation) of this view.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 8988 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8989 | * <p>The distance of the camera from the view plane can have an affect on the |
| 8990 | * perspective distortion of the view when it is rotated around the x or y axis. |
| 8991 | * For example, a large distance will result in a large viewing angle, and there |
| 8992 | * 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] | 8993 | * distance may cause much more perspective distortion upon rotation, and can |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8994 | * also result in some drawing artifacts if the rotated view ends up partially |
| 8995 | * behind the camera (which is why the recommendation is to use a distance at |
| 8996 | * 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] | 8997 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 8998 | * <p>The distance is expressed in "depth pixels." The default distance depends |
| 8999 | * on the screen density. For instance, on a medium density display, the |
| 9000 | * default distance is 1280. On a high density display, the default distance |
| 9001 | * is 1920.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9002 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9003 | * <p>If you want to specify a distance that leads to visually consistent |
| 9004 | * results across various densities, use the following formula:</p> |
| 9005 | * <pre> |
| 9006 | * float scale = context.getResources().getDisplayMetrics().density; |
| 9007 | * view.setCameraDistance(distance * scale); |
| 9008 | * </pre> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9009 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9010 | * <p>The density scale factor of a high density display is 1.5, |
| 9011 | * and 1920 = 1280 * 1.5.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9012 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9013 | * @param distance The distance in "depth pixels", if negative the opposite |
| 9014 | * value is used |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9015 | * |
| 9016 | * @see #setRotationX(float) |
| 9017 | * @see #setRotationY(float) |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9018 | */ |
| 9019 | public void setCameraDistance(float distance) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9020 | invalidateViewProperty(true, false); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9021 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9022 | ensureTransformationInfo(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9023 | final float dpi = mResources.getDisplayMetrics().densityDpi; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9024 | final TransformationInfo info = mTransformationInfo; |
| 9025 | if (info.mCamera == null) { |
| 9026 | info.mCamera = new Camera(); |
| 9027 | info.matrix3D = new Matrix(); |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9028 | } |
| 9029 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9030 | info.mCamera.setLocation(0.0f, 0.0f, -Math.abs(distance) / dpi); |
| 9031 | info.mMatrixDirty = true; |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9032 | |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9033 | invalidateViewProperty(false, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9034 | if (mDisplayList != null) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 9035 | mDisplayList.setCameraDistance(-Math.abs(distance) / dpi); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9036 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9037 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9038 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9039 | invalidateParentIfNeeded(); |
| 9040 | } |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9041 | } |
| 9042 | |
| 9043 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9044 | * The degrees that the view is rotated around the pivot point. |
| 9045 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9046 | * @see #setRotation(float) |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9047 | * @see #getPivotX() |
| 9048 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9049 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9050 | * @return The degrees of rotation. |
| 9051 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9052 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9053 | public float getRotation() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9054 | return mTransformationInfo != null ? mTransformationInfo.mRotation : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9055 | } |
| 9056 | |
| 9057 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9058 | * Sets the degrees that the view is rotated around the pivot point. Increasing values |
| 9059 | * result in clockwise rotation. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9060 | * |
| 9061 | * @param rotation The degrees of rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9062 | * |
| 9063 | * @see #getRotation() |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9064 | * @see #getPivotX() |
| 9065 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9066 | * @see #setRotationX(float) |
| 9067 | * @see #setRotationY(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9068 | * |
| 9069 | * @attr ref android.R.styleable#View_rotation |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9070 | */ |
| 9071 | public void setRotation(float rotation) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9072 | ensureTransformationInfo(); |
| 9073 | final TransformationInfo info = mTransformationInfo; |
| 9074 | if (info.mRotation != rotation) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9075 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9076 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9077 | info.mRotation = rotation; |
| 9078 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9079 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9080 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9081 | mDisplayList.setRotation(rotation); |
| 9082 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9083 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9084 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9085 | invalidateParentIfNeeded(); |
| 9086 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9087 | } |
| 9088 | } |
| 9089 | |
| 9090 | /** |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9091 | * The degrees that the view is rotated around the vertical axis through the pivot point. |
| 9092 | * |
| 9093 | * @see #getPivotX() |
| 9094 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9095 | * @see #setRotationY(float) |
| 9096 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9097 | * @return The degrees of Y rotation. |
| 9098 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9099 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9100 | public float getRotationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9101 | return mTransformationInfo != null ? mTransformationInfo.mRotationY : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9102 | } |
| 9103 | |
| 9104 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9105 | * Sets the degrees that the view is rotated around the vertical axis through the pivot point. |
| 9106 | * Increasing values result in counter-clockwise rotation from the viewpoint of looking |
| 9107 | * down the y axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9108 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9109 | * When rotating large views, it is recommended to adjust the camera distance |
| 9110 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9111 | * |
| 9112 | * @param rotationY The degrees of Y rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9113 | * |
| 9114 | * @see #getRotationY() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9115 | * @see #getPivotX() |
| 9116 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9117 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9118 | * @see #setRotationX(float) |
| 9119 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9120 | * |
| 9121 | * @attr ref android.R.styleable#View_rotationY |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9122 | */ |
| 9123 | public void setRotationY(float rotationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9124 | ensureTransformationInfo(); |
| 9125 | final TransformationInfo info = mTransformationInfo; |
| 9126 | if (info.mRotationY != rotationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9127 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9128 | info.mRotationY = rotationY; |
| 9129 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9130 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9131 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9132 | mDisplayList.setRotationY(rotationY); |
| 9133 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9134 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9135 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9136 | invalidateParentIfNeeded(); |
| 9137 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9138 | } |
| 9139 | } |
| 9140 | |
| 9141 | /** |
| 9142 | * The degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9143 | * |
| 9144 | * @see #getPivotX() |
| 9145 | * @see #getPivotY() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9146 | * @see #setRotationX(float) |
| 9147 | * |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9148 | * @return The degrees of X rotation. |
| 9149 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9150 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9151 | public float getRotationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9152 | return mTransformationInfo != null ? mTransformationInfo.mRotationX : 0; |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9153 | } |
| 9154 | |
| 9155 | /** |
Chet Haase | 897247b | 2010-09-09 14:54:47 -0700 | [diff] [blame] | 9156 | * Sets the degrees that the view is rotated around the horizontal axis through the pivot point. |
| 9157 | * Increasing values result in clockwise rotation from the viewpoint of looking down the |
| 9158 | * x axis. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9159 | * |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9160 | * When rotating large views, it is recommended to adjust the camera distance |
| 9161 | * accordingly. Refer to {@link #setCameraDistance(float)} for more information. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9162 | * |
| 9163 | * @param rotationX The degrees of X rotation. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9164 | * |
| 9165 | * @see #getRotationX() |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9166 | * @see #getPivotX() |
| 9167 | * @see #getPivotY() |
Romain Guy | a5364ee | 2011-02-24 14:46:04 -0800 | [diff] [blame] | 9168 | * @see #setRotation(float) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9169 | * @see #setRotationY(float) |
| 9170 | * @see #setCameraDistance(float) |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9171 | * |
| 9172 | * @attr ref android.R.styleable#View_rotationX |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9173 | */ |
| 9174 | public void setRotationX(float rotationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9175 | ensureTransformationInfo(); |
| 9176 | final TransformationInfo info = mTransformationInfo; |
| 9177 | if (info.mRotationX != rotationX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9178 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9179 | info.mRotationX = rotationX; |
| 9180 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9181 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9182 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9183 | mDisplayList.setRotationX(rotationX); |
| 9184 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9185 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9186 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9187 | invalidateParentIfNeeded(); |
| 9188 | } |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9189 | } |
| 9190 | } |
| 9191 | |
| 9192 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9193 | * The amount that the view is scaled in x around the pivot point, as a proportion of |
| 9194 | * the view's unscaled width. A value of 1, the default, means that no scaling is applied. |
| 9195 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9196 | * <p>By default, this is 1.0f. |
| 9197 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9198 | * @see #getPivotX() |
| 9199 | * @see #getPivotY() |
| 9200 | * @return The scaling factor. |
| 9201 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9202 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9203 | public float getScaleX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9204 | return mTransformationInfo != null ? mTransformationInfo.mScaleX : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9205 | } |
| 9206 | |
| 9207 | /** |
| 9208 | * Sets the amount that the view is scaled in x around the pivot point, as a proportion of |
| 9209 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9210 | * |
| 9211 | * @param scaleX The scaling factor. |
| 9212 | * @see #getPivotX() |
| 9213 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9214 | * |
| 9215 | * @attr ref android.R.styleable#View_scaleX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9216 | */ |
| 9217 | public void setScaleX(float scaleX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9218 | ensureTransformationInfo(); |
| 9219 | final TransformationInfo info = mTransformationInfo; |
| 9220 | if (info.mScaleX != scaleX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9221 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9222 | info.mScaleX = scaleX; |
| 9223 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9224 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9225 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9226 | mDisplayList.setScaleX(scaleX); |
| 9227 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9228 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9229 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9230 | invalidateParentIfNeeded(); |
| 9231 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9232 | } |
| 9233 | } |
| 9234 | |
| 9235 | /** |
| 9236 | * The amount that the view is scaled in y around the pivot point, as a proportion of |
| 9237 | * the view's unscaled height. A value of 1, the default, means that no scaling is applied. |
| 9238 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9239 | * <p>By default, this is 1.0f. |
| 9240 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9241 | * @see #getPivotX() |
| 9242 | * @see #getPivotY() |
| 9243 | * @return The scaling factor. |
| 9244 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9245 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9246 | public float getScaleY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9247 | return mTransformationInfo != null ? mTransformationInfo.mScaleY : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9248 | } |
| 9249 | |
| 9250 | /** |
| 9251 | * Sets the amount that the view is scaled in Y around the pivot point, as a proportion of |
| 9252 | * the view's unscaled width. A value of 1 means that no scaling is applied. |
| 9253 | * |
| 9254 | * @param scaleY The scaling factor. |
| 9255 | * @see #getPivotX() |
| 9256 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9257 | * |
| 9258 | * @attr ref android.R.styleable#View_scaleY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9259 | */ |
| 9260 | public void setScaleY(float scaleY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9261 | ensureTransformationInfo(); |
| 9262 | final TransformationInfo info = mTransformationInfo; |
| 9263 | if (info.mScaleY != scaleY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9264 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9265 | info.mScaleY = scaleY; |
| 9266 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9267 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9268 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9269 | mDisplayList.setScaleY(scaleY); |
| 9270 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9271 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9272 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9273 | invalidateParentIfNeeded(); |
| 9274 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9275 | } |
| 9276 | } |
| 9277 | |
| 9278 | /** |
| 9279 | * The x location of the point around which the view is {@link #setRotation(float) rotated} |
| 9280 | * and {@link #setScaleX(float) scaled}. |
| 9281 | * |
| 9282 | * @see #getRotation() |
| 9283 | * @see #getScaleX() |
| 9284 | * @see #getScaleY() |
| 9285 | * @see #getPivotY() |
| 9286 | * @return The x location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9287 | * |
| 9288 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9289 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9290 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9291 | public float getPivotX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9292 | return mTransformationInfo != null ? mTransformationInfo.mPivotX : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9293 | } |
| 9294 | |
| 9295 | /** |
| 9296 | * Sets the x location of the point around which the view is |
| 9297 | * {@link #setRotation(float) rotated} and {@link #setScaleX(float) scaled}. |
Chet Haase | fd2b002 | 2010-08-06 13:08:56 -0700 | [diff] [blame] | 9298 | * By default, the pivot point is centered on the object. |
| 9299 | * Setting this property disables this behavior and causes the view to use only the |
| 9300 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9301 | * |
| 9302 | * @param pivotX The x location of the pivot point. |
| 9303 | * @see #getRotation() |
| 9304 | * @see #getScaleX() |
| 9305 | * @see #getScaleY() |
| 9306 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9307 | * |
| 9308 | * @attr ref android.R.styleable#View_transformPivotX |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9309 | */ |
| 9310 | public void setPivotX(float pivotX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9311 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9312 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9313 | final TransformationInfo info = mTransformationInfo; |
| 9314 | if (info.mPivotX != pivotX) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9315 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9316 | info.mPivotX = pivotX; |
| 9317 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9318 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9319 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9320 | mDisplayList.setPivotX(pivotX); |
| 9321 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9322 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9323 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9324 | invalidateParentIfNeeded(); |
| 9325 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9326 | } |
| 9327 | } |
| 9328 | |
| 9329 | /** |
| 9330 | * The y location of the point around which the view is {@link #setRotation(float) rotated} |
| 9331 | * and {@link #setScaleY(float) scaled}. |
| 9332 | * |
| 9333 | * @see #getRotation() |
| 9334 | * @see #getScaleX() |
| 9335 | * @see #getScaleY() |
| 9336 | * @see #getPivotY() |
| 9337 | * @return The y location of the pivot point. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 9338 | * |
| 9339 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9340 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9341 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9342 | public float getPivotY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9343 | return mTransformationInfo != null ? mTransformationInfo.mPivotY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9344 | } |
| 9345 | |
| 9346 | /** |
| 9347 | * 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] | 9348 | * and {@link #setScaleY(float) scaled}. By default, the pivot point is centered on the object. |
| 9349 | * Setting this property disables this behavior and causes the view to use only the |
| 9350 | * explicitly set pivotX and pivotY values. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9351 | * |
| 9352 | * @param pivotY The y location of the pivot point. |
| 9353 | * @see #getRotation() |
| 9354 | * @see #getScaleX() |
| 9355 | * @see #getScaleY() |
| 9356 | * @see #getPivotY() |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9357 | * |
| 9358 | * @attr ref android.R.styleable#View_transformPivotY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9359 | */ |
| 9360 | public void setPivotY(float pivotY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9361 | ensureTransformationInfo(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9362 | mPrivateFlags |= PFLAG_PIVOT_EXPLICITLY_SET; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9363 | final TransformationInfo info = mTransformationInfo; |
| 9364 | if (info.mPivotY != pivotY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9365 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9366 | info.mPivotY = pivotY; |
| 9367 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9368 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9369 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9370 | mDisplayList.setPivotY(pivotY); |
| 9371 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9372 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9373 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9374 | invalidateParentIfNeeded(); |
| 9375 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9376 | } |
| 9377 | } |
| 9378 | |
| 9379 | /** |
| 9380 | * The opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9381 | * completely transparent and 1 means the view is completely opaque. |
| 9382 | * |
Joe Onorato | 9316232 | 2010-09-16 15:42:01 -0400 | [diff] [blame] | 9383 | * <p>By default this is 1.0f. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9384 | * @return The opacity of the view. |
| 9385 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9386 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9387 | public float getAlpha() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9388 | return mTransformationInfo != null ? mTransformationInfo.mAlpha : 1; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9389 | } |
| 9390 | |
| 9391 | /** |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 9392 | * Returns whether this View has content which overlaps. This function, intended to be |
| 9393 | * overridden by specific View types, is an optimization when alpha is set on a view. If |
| 9394 | * rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer |
| 9395 | * and then composited it into place, which can be expensive. If the view has no overlapping |
| 9396 | * rendering, the view can draw each primitive with the appropriate alpha value directly. |
| 9397 | * An example of overlapping rendering is a TextView with a background image, such as a |
| 9398 | * Button. An example of non-overlapping rendering is a TextView with no background, or |
| 9399 | * an ImageView with only the foreground image. The default implementation returns true; |
| 9400 | * subclasses should override if they have cases which can be optimized. |
| 9401 | * |
| 9402 | * @return true if the content in this view might overlap, false otherwise. |
| 9403 | */ |
| 9404 | public boolean hasOverlappingRendering() { |
| 9405 | return true; |
| 9406 | } |
| 9407 | |
| 9408 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9409 | * <p>Sets the opacity of the view. This is a value from 0 to 1, where 0 means the view is |
| 9410 | * completely transparent and 1 means the view is completely opaque.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9411 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 9412 | * <p>If this view overrides {@link #onSetAlpha(int)} to return true, then this view is |
| 9413 | * responsible for applying the opacity itself. Otherwise, calling this method is |
| 9414 | * equivalent to calling {@link #setLayerType(int, android.graphics.Paint)} and |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9415 | * setting a hardware layer.</p> |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9416 | * |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9417 | * <p>Note that setting alpha to a translucent value (0 < alpha < 1) may have |
| 9418 | * performance implications. It is generally best to use the alpha property sparingly and |
| 9419 | * transiently, as in the case of fading animations.</p> |
| 9420 | * |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9421 | * @param alpha The opacity of the view. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9422 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9423 | * @see #setLayerType(int, android.graphics.Paint) |
| 9424 | * |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9425 | * @attr ref android.R.styleable#View_alpha |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9426 | */ |
| 9427 | public void setAlpha(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9428 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9429 | if (mTransformationInfo.mAlpha != alpha) { |
| 9430 | mTransformationInfo.mAlpha = alpha; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9431 | if (onSetAlpha((int) (alpha * 255))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9432 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9433 | // subclass is handling alpha - don't optimize rendering cache invalidation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9434 | invalidateParentCaches(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9435 | invalidate(true); |
| 9436 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9437 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9438 | invalidateViewProperty(true, false); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9439 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9440 | mDisplayList.setAlpha(alpha); |
| 9441 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9442 | } |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9443 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9444 | } |
| 9445 | |
| 9446 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9447 | * Faster version of setAlpha() which performs the same steps except there are |
| 9448 | * no calls to invalidate(). The caller of this function should perform proper invalidation |
| 9449 | * on the parent and this object. The return value indicates whether the subclass handles |
| 9450 | * alpha (the return value for onSetAlpha()). |
| 9451 | * |
| 9452 | * @param alpha The new value for the alpha property |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9453 | * @return true if the View subclass handles alpha (the return value for onSetAlpha()) and |
| 9454 | * 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] | 9455 | */ |
| 9456 | boolean setAlphaNoInvalidation(float alpha) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9457 | ensureTransformationInfo(); |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9458 | if (mTransformationInfo.mAlpha != alpha) { |
| 9459 | mTransformationInfo.mAlpha = alpha; |
| 9460 | boolean subclassHandlesAlpha = onSetAlpha((int) (alpha * 255)); |
| 9461 | if (subclassHandlesAlpha) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9462 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9463 | return true; |
| 9464 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9465 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9466 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9467 | mDisplayList.setAlpha(alpha); |
| 9468 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9469 | } |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9470 | } |
Michael Jurka | a7a7eed | 2012-01-17 06:06:17 -0800 | [diff] [blame] | 9471 | return false; |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 9472 | } |
| 9473 | |
| 9474 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9475 | * Top position of this view relative to its parent. |
| 9476 | * |
| 9477 | * @return The top of this view, in pixels. |
| 9478 | */ |
| 9479 | @ViewDebug.CapturedViewProperty |
| 9480 | public final int getTop() { |
| 9481 | return mTop; |
| 9482 | } |
| 9483 | |
| 9484 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9485 | * Sets the top position of this view relative to its parent. This method is meant to be called |
| 9486 | * by the layout system and should not generally be called otherwise, because the property |
| 9487 | * may be changed at any time by the layout. |
| 9488 | * |
| 9489 | * @param top The top of this view, in pixels. |
| 9490 | */ |
| 9491 | public final void setTop(int top) { |
| 9492 | if (top != mTop) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9493 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9494 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9495 | || mTransformationInfo.mMatrixIsIdentity; |
| 9496 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9497 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9498 | int minTop; |
| 9499 | int yLoc; |
| 9500 | if (top < mTop) { |
| 9501 | minTop = top; |
| 9502 | yLoc = top - mTop; |
| 9503 | } else { |
| 9504 | minTop = mTop; |
| 9505 | yLoc = 0; |
| 9506 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9507 | invalidate(0, yLoc, mRight - mLeft, mBottom - minTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9508 | } |
| 9509 | } else { |
| 9510 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9511 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9512 | } |
| 9513 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9514 | int width = mRight - mLeft; |
| 9515 | int oldHeight = mBottom - mTop; |
| 9516 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9517 | mTop = top; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9518 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9519 | mDisplayList.setTop(mTop); |
| 9520 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9521 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9522 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9523 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9524 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9525 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9526 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9527 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9528 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9529 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9530 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9531 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9532 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9533 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9534 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9535 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9536 | invalidateParentIfNeeded(); |
| 9537 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9538 | } |
| 9539 | } |
| 9540 | |
| 9541 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9542 | * Bottom position of this view relative to its parent. |
| 9543 | * |
| 9544 | * @return The bottom of this view, in pixels. |
| 9545 | */ |
| 9546 | @ViewDebug.CapturedViewProperty |
| 9547 | public final int getBottom() { |
| 9548 | return mBottom; |
| 9549 | } |
| 9550 | |
| 9551 | /** |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9552 | * True if this view has changed since the last time being drawn. |
| 9553 | * |
| 9554 | * @return The dirty state of this view. |
| 9555 | */ |
| 9556 | public boolean isDirty() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9557 | return (mPrivateFlags & PFLAG_DIRTY_MASK) != 0; |
Michael Jurka | dab559a | 2011-01-04 20:31:51 -0800 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9561 | * Sets the bottom position of this view relative to its parent. This method is meant to be |
| 9562 | * called by the layout system and should not generally be called otherwise, because the |
| 9563 | * property may be changed at any time by the layout. |
| 9564 | * |
| 9565 | * @param bottom The bottom of this view, in pixels. |
| 9566 | */ |
| 9567 | public final void setBottom(int bottom) { |
| 9568 | if (bottom != mBottom) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9569 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9570 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9571 | || mTransformationInfo.mMatrixIsIdentity; |
| 9572 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9573 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9574 | int maxBottom; |
| 9575 | if (bottom < mBottom) { |
| 9576 | maxBottom = mBottom; |
| 9577 | } else { |
| 9578 | maxBottom = bottom; |
| 9579 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9580 | invalidate(0, 0, mRight - mLeft, maxBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9581 | } |
| 9582 | } else { |
| 9583 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9584 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9585 | } |
| 9586 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9587 | int width = mRight - mLeft; |
| 9588 | int oldHeight = mBottom - mTop; |
| 9589 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9590 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9591 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9592 | mDisplayList.setBottom(mBottom); |
| 9593 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9594 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9595 | onSizeChanged(width, mBottom - mTop, width, oldHeight); |
| 9596 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9597 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9598 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9599 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9600 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9601 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9602 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9603 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9604 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9605 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9606 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9607 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9608 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9609 | invalidateParentIfNeeded(); |
| 9610 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9611 | } |
| 9612 | } |
| 9613 | |
| 9614 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | * Left position of this view relative to its parent. |
| 9616 | * |
| 9617 | * @return The left edge of this view, in pixels. |
| 9618 | */ |
| 9619 | @ViewDebug.CapturedViewProperty |
| 9620 | public final int getLeft() { |
| 9621 | return mLeft; |
| 9622 | } |
| 9623 | |
| 9624 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9625 | * Sets the left position of this view relative to its parent. This method is meant to be called |
| 9626 | * by the layout system and should not generally be called otherwise, because the property |
| 9627 | * may be changed at any time by the layout. |
| 9628 | * |
| 9629 | * @param left The bottom of this view, in pixels. |
| 9630 | */ |
| 9631 | public final void setLeft(int left) { |
| 9632 | if (left != mLeft) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9633 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9634 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9635 | || mTransformationInfo.mMatrixIsIdentity; |
| 9636 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9637 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9638 | int minLeft; |
| 9639 | int xLoc; |
| 9640 | if (left < mLeft) { |
| 9641 | minLeft = left; |
| 9642 | xLoc = left - mLeft; |
| 9643 | } else { |
| 9644 | minLeft = mLeft; |
| 9645 | xLoc = 0; |
| 9646 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9647 | invalidate(xLoc, 0, mRight - minLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9648 | } |
| 9649 | } else { |
| 9650 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9651 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9652 | } |
| 9653 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9654 | int oldWidth = mRight - mLeft; |
| 9655 | int height = mBottom - mTop; |
| 9656 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9657 | mLeft = left; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9658 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9659 | mDisplayList.setLeft(left); |
| 9660 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9661 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9662 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9663 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9664 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9665 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9666 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9667 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9668 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9669 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9670 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9671 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9672 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9673 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9674 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9675 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9676 | invalidateParentIfNeeded(); |
| 9677 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9682 | * Right position of this view relative to its parent. |
| 9683 | * |
| 9684 | * @return The right edge of this view, in pixels. |
| 9685 | */ |
| 9686 | @ViewDebug.CapturedViewProperty |
| 9687 | public final int getRight() { |
| 9688 | return mRight; |
| 9689 | } |
| 9690 | |
| 9691 | /** |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9692 | * Sets the right position of this view relative to its parent. This method is meant to be called |
| 9693 | * by the layout system and should not generally be called otherwise, because the property |
| 9694 | * may be changed at any time by the layout. |
| 9695 | * |
| 9696 | * @param right The bottom of this view, in pixels. |
| 9697 | */ |
| 9698 | public final void setRight(int right) { |
| 9699 | if (right != mRight) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9700 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9701 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9702 | || mTransformationInfo.mMatrixIsIdentity; |
| 9703 | if (matrixIsIdentity) { |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9704 | if (mAttachInfo != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9705 | int maxRight; |
| 9706 | if (right < mRight) { |
| 9707 | maxRight = mRight; |
| 9708 | } else { |
| 9709 | maxRight = right; |
| 9710 | } |
Chet Haase | e9140a7 | 2011-02-16 16:23:29 -0800 | [diff] [blame] | 9711 | invalidate(0, 0, maxRight - mLeft, mBottom - mTop); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9712 | } |
| 9713 | } else { |
| 9714 | // Double-invalidation is necessary to capture view's old and new areas |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9715 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9716 | } |
| 9717 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9718 | int oldWidth = mRight - mLeft; |
| 9719 | int height = mBottom - mTop; |
| 9720 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9721 | mRight = right; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9722 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9723 | mDisplayList.setRight(mRight); |
| 9724 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9725 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 9726 | onSizeChanged(mRight - mLeft, height, oldWidth, height); |
| 9727 | |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9728 | if (!matrixIsIdentity) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9729 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9730 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9731 | mTransformationInfo.mMatrixDirty = true; |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 9732 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9733 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 9734 | invalidate(true); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9735 | } |
Chet Haase | 55dbb65 | 2010-12-21 20:15:08 -0800 | [diff] [blame] | 9736 | mBackgroundSizeChanged = true; |
Chet Haase | 678e0ad | 2011-01-25 09:37:18 -0800 | [diff] [blame] | 9737 | invalidateParentIfNeeded(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9738 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9739 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9740 | invalidateParentIfNeeded(); |
| 9741 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 9742 | } |
| 9743 | } |
| 9744 | |
| 9745 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9746 | * The visual x position of this view, in pixels. This is equivalent to the |
| 9747 | * {@link #setTranslationX(float) translationX} property plus the current |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 9748 | * {@link #getLeft() left} property. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9749 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9750 | * @return The visual x position of this view, in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9751 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9752 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9753 | public float getX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9754 | return mLeft + (mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9755 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9756 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9757 | /** |
| 9758 | * Sets the visual x position of this view, in pixels. This is equivalent to setting the |
| 9759 | * {@link #setTranslationX(float) translationX} property to be the difference between |
| 9760 | * the x value passed in and the current {@link #getLeft() left} property. |
| 9761 | * |
| 9762 | * @param x The visual x position of this view, in pixels. |
| 9763 | */ |
| 9764 | public void setX(float x) { |
| 9765 | setTranslationX(x - mLeft); |
| 9766 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9767 | |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9768 | /** |
| 9769 | * The visual y position of this view, in pixels. This is equivalent to the |
| 9770 | * {@link #setTranslationY(float) translationY} property plus the current |
| 9771 | * {@link #getTop() top} property. |
| 9772 | * |
| 9773 | * @return The visual y position of this view, in pixels. |
| 9774 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9775 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9776 | public float getY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9777 | return mTop + (mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0); |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * Sets the visual y position of this view, in pixels. This is equivalent to setting the |
| 9782 | * {@link #setTranslationY(float) translationY} property to be the difference between |
| 9783 | * the y value passed in and the current {@link #getTop() top} property. |
| 9784 | * |
| 9785 | * @param y The visual y position of this view, in pixels. |
| 9786 | */ |
| 9787 | public void setY(float y) { |
| 9788 | setTranslationY(y - mTop); |
| 9789 | } |
| 9790 | |
| 9791 | |
| 9792 | /** |
| 9793 | * The horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9794 | * This position is post-layout, in addition to wherever the object's |
| 9795 | * layout placed it. |
| 9796 | * |
| 9797 | * @return The horizontal position of this view relative to its left position, in pixels. |
| 9798 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9799 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9800 | public float getTranslationX() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9801 | return mTransformationInfo != null ? mTransformationInfo.mTranslationX : 0; |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9802 | } |
| 9803 | |
| 9804 | /** |
| 9805 | * Sets the horizontal location of this view relative to its {@link #getLeft() left} position. |
| 9806 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9807 | * layout placed it. |
| 9808 | * |
| 9809 | * @param translationX The horizontal position of this view relative to its left position, |
| 9810 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9811 | * |
| 9812 | * @attr ref android.R.styleable#View_translationX |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9813 | */ |
| 9814 | public void setTranslationX(float translationX) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9815 | ensureTransformationInfo(); |
| 9816 | final TransformationInfo info = mTransformationInfo; |
| 9817 | if (info.mTranslationX != translationX) { |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9818 | // Double-invalidation is necessary to capture view's old and new areas |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9819 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9820 | info.mTranslationX = translationX; |
| 9821 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9822 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9823 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9824 | mDisplayList.setTranslationX(translationX); |
| 9825 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9826 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9827 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9828 | invalidateParentIfNeeded(); |
| 9829 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9830 | } |
| 9831 | } |
| 9832 | |
| 9833 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9834 | * The horizontal location of this view relative to its {@link #getTop() top} position. |
| 9835 | * This position is post-layout, in addition to wherever the object's |
| 9836 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9837 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9838 | * @return The vertical position of this view relative to its top position, |
| 9839 | * in pixels. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9840 | */ |
Chet Haase | a553113 | 2012-02-02 13:41:44 -0800 | [diff] [blame] | 9841 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9842 | public float getTranslationY() { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9843 | return mTransformationInfo != null ? mTransformationInfo.mTranslationY : 0; |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9844 | } |
| 9845 | |
| 9846 | /** |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9847 | * Sets the vertical location of this view relative to its {@link #getTop() top} position. |
| 9848 | * This effectively positions the object post-layout, in addition to wherever the object's |
| 9849 | * layout placed it. |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9850 | * |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9851 | * @param translationY The vertical position of this view relative to its top position, |
| 9852 | * in pixels. |
Chet Haase | 7306668 | 2010-11-29 15:55:32 -0800 | [diff] [blame] | 9853 | * |
| 9854 | * @attr ref android.R.styleable#View_translationY |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9855 | */ |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9856 | public void setTranslationY(float translationY) { |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9857 | ensureTransformationInfo(); |
| 9858 | final TransformationInfo info = mTransformationInfo; |
| 9859 | if (info.mTranslationY != translationY) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9860 | invalidateViewProperty(true, false); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9861 | info.mTranslationY = translationY; |
| 9862 | info.mMatrixDirty = true; |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9863 | invalidateViewProperty(false, true); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9864 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 9865 | mDisplayList.setTranslationY(translationY); |
| 9866 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 9867 | if ((mPrivateFlags2 & PFLAG2_VIEW_QUICK_REJECTED) == PFLAG2_VIEW_QUICK_REJECTED) { |
Chet Haase | 1a3ab17 | 2012-05-11 08:41:20 -0700 | [diff] [blame] | 9868 | // View was rejected last time it was drawn by its parent; this may have changed |
| 9869 | invalidateParentIfNeeded(); |
| 9870 | } |
Chet Haase | df030d2 | 2010-07-30 17:22:38 -0700 | [diff] [blame] | 9871 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9872 | } |
| 9873 | |
| 9874 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9875 | * Hit rectangle in parent's coordinates |
| 9876 | * |
| 9877 | * @param outRect The hit rectangle of the view. |
| 9878 | */ |
| 9879 | public void getHitRect(Rect outRect) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9880 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9881 | final TransformationInfo info = mTransformationInfo; |
| 9882 | if (info == null || info.mMatrixIsIdentity || mAttachInfo == null) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9883 | outRect.set(mLeft, mTop, mRight, mBottom); |
| 9884 | } else { |
| 9885 | final RectF tmpRect = mAttachInfo.mTmpTransformRect; |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9886 | tmpRect.set(-info.mPivotX, -info.mPivotY, |
| 9887 | getWidth() - info.mPivotX, getHeight() - info.mPivotY); |
| 9888 | info.mMatrix.mapRect(tmpRect); |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9889 | outRect.set((int) tmpRect.left + mLeft, (int) tmpRect.top + mTop, |
| 9890 | (int) tmpRect.right + mLeft, (int) tmpRect.bottom + mTop); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9891 | } |
| 9892 | } |
| 9893 | |
| 9894 | /** |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9895 | * Determines whether the given point, in local coordinates is inside the view. |
| 9896 | */ |
| 9897 | /*package*/ final boolean pointInView(float localX, float localY) { |
| 9898 | return localX >= 0 && localX < (mRight - mLeft) |
| 9899 | && localY >= 0 && localY < (mBottom - mTop); |
| 9900 | } |
| 9901 | |
| 9902 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9903 | * Utility method to determine whether the given point, in local coordinates, |
| 9904 | * is inside the view, where the area of the view is expanded by the slop factor. |
| 9905 | * This method is called while processing touch-move events to determine if the event |
| 9906 | * is still within the view. |
| 9907 | */ |
| 9908 | private boolean pointInView(float localX, float localY, float slop) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 9909 | return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 9910 | localY < ((mBottom - mTop) + slop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9911 | } |
| 9912 | |
| 9913 | /** |
| 9914 | * When a view has focus and the user navigates away from it, the next view is searched for |
| 9915 | * starting from the rectangle filled in by this method. |
| 9916 | * |
Fabrice Di Meglio | c11f77f | 2012-09-18 15:33:07 -0700 | [diff] [blame] | 9917 | * By default, the rectangle is the {@link #getDrawingRect(android.graphics.Rect)}) |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 9918 | * of the view. However, if your view maintains some idea of internal selection, |
| 9919 | * such as a cursor, or a selected row or column, you should override this method and |
| 9920 | * fill in a more specific rectangle. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9921 | * |
| 9922 | * @param r The rectangle to fill in, in this view's coordinates. |
| 9923 | */ |
| 9924 | public void getFocusedRect(Rect r) { |
| 9925 | getDrawingRect(r); |
| 9926 | } |
| 9927 | |
| 9928 | /** |
| 9929 | * If some part of this view is not clipped by any of its parents, then |
| 9930 | * 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] | 9931 | * coordinates (without taking possible View rotations into account), offset |
| 9932 | * it by -globalOffset (e.g. r.offset(-globalOffset.x, -globalOffset.y)). |
| 9933 | * 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] | 9934 | * |
| 9935 | * @param r If true is returned, r holds the global coordinates of the |
| 9936 | * visible portion of this view. |
| 9937 | * @param globalOffset If true is returned, globalOffset holds the dx,dy |
| 9938 | * between this view and its root. globalOffet may be null. |
| 9939 | * @return true if r is non-empty (i.e. part of the view is visible at the |
| 9940 | * root level. |
| 9941 | */ |
| 9942 | public boolean getGlobalVisibleRect(Rect r, Point globalOffset) { |
| 9943 | int width = mRight - mLeft; |
| 9944 | int height = mBottom - mTop; |
| 9945 | if (width > 0 && height > 0) { |
| 9946 | r.set(0, 0, width, height); |
| 9947 | if (globalOffset != null) { |
| 9948 | globalOffset.set(-mScrollX, -mScrollY); |
| 9949 | } |
| 9950 | return mParent == null || mParent.getChildVisibleRect(this, r, globalOffset); |
| 9951 | } |
| 9952 | return false; |
| 9953 | } |
| 9954 | |
| 9955 | public final boolean getGlobalVisibleRect(Rect r) { |
| 9956 | return getGlobalVisibleRect(r, null); |
| 9957 | } |
| 9958 | |
| 9959 | public final boolean getLocalVisibleRect(Rect r) { |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 9960 | final Point offset = mAttachInfo != null ? mAttachInfo.mPoint : new Point(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9961 | if (getGlobalVisibleRect(r, offset)) { |
| 9962 | r.offset(-offset.x, -offset.y); // make r local |
| 9963 | return true; |
| 9964 | } |
| 9965 | return false; |
| 9966 | } |
| 9967 | |
| 9968 | /** |
| 9969 | * Offset this view's vertical location by the specified number of pixels. |
| 9970 | * |
| 9971 | * @param offset the number of pixels to offset the view by |
| 9972 | */ |
| 9973 | public void offsetTopAndBottom(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 9974 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 9975 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 9976 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 9977 | || mTransformationInfo.mMatrixIsIdentity; |
| 9978 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 9979 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 9980 | invalidateViewProperty(false, false); |
| 9981 | } else { |
| 9982 | final ViewParent p = mParent; |
| 9983 | if (p != null && mAttachInfo != null) { |
| 9984 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 9985 | int minTop; |
| 9986 | int maxBottom; |
| 9987 | int yLoc; |
| 9988 | if (offset < 0) { |
| 9989 | minTop = mTop + offset; |
| 9990 | maxBottom = mBottom; |
| 9991 | yLoc = offset; |
| 9992 | } else { |
| 9993 | minTop = mTop; |
| 9994 | maxBottom = mBottom + offset; |
| 9995 | yLoc = 0; |
| 9996 | } |
| 9997 | r.set(0, yLoc, mRight - mLeft, maxBottom - minTop); |
| 9998 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 9999 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10000 | } |
| 10001 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10002 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10003 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 10004 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10005 | mTop += offset; |
| 10006 | mBottom += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 10007 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10008 | mDisplayList.offsetTopBottom(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10009 | invalidateViewProperty(false, false); |
| 10010 | } else { |
| 10011 | if (!matrixIsIdentity) { |
| 10012 | invalidateViewProperty(false, true); |
| 10013 | } |
| 10014 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10015 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10017 | } |
| 10018 | |
| 10019 | /** |
| 10020 | * Offset this view's horizontal location by the specified amount of pixels. |
| 10021 | * |
| 10022 | * @param offset the numer of pixels to offset the view by |
| 10023 | */ |
| 10024 | public void offsetLeftAndRight(int offset) { |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10025 | if (offset != 0) { |
Jeff Brown | 8667174 | 2010-09-30 20:00:15 -0700 | [diff] [blame] | 10026 | updateMatrix(); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 10027 | final boolean matrixIsIdentity = mTransformationInfo == null |
| 10028 | || mTransformationInfo.mMatrixIsIdentity; |
| 10029 | if (matrixIsIdentity) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 10030 | if (mDisplayList != null) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10031 | invalidateViewProperty(false, false); |
| 10032 | } else { |
| 10033 | final ViewParent p = mParent; |
| 10034 | if (p != null && mAttachInfo != null) { |
| 10035 | final Rect r = mAttachInfo.mTmpInvalRect; |
| 10036 | int minLeft; |
| 10037 | int maxRight; |
| 10038 | if (offset < 0) { |
| 10039 | minLeft = mLeft + offset; |
| 10040 | maxRight = mRight; |
| 10041 | } else { |
| 10042 | minLeft = mLeft; |
| 10043 | maxRight = mRight + offset; |
| 10044 | } |
| 10045 | r.set(0, 0, maxRight - minLeft, mBottom - mTop); |
| 10046 | p.invalidateChild(this, r); |
Chet Haase | 8fbf8d2 | 2010-07-30 15:01:32 -0700 | [diff] [blame] | 10047 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10048 | } |
| 10049 | } else { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10050 | invalidateViewProperty(false, false); |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10051 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 10052 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10053 | mLeft += offset; |
| 10054 | mRight += offset; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 10055 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10056 | mDisplayList.offsetLeftRight(offset); |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10057 | invalidateViewProperty(false, false); |
| 10058 | } else { |
| 10059 | if (!matrixIsIdentity) { |
| 10060 | invalidateViewProperty(false, true); |
| 10061 | } |
| 10062 | invalidateParentIfNeeded(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 10063 | } |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 10064 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | } |
| 10066 | |
| 10067 | /** |
| 10068 | * Get the LayoutParams associated with this view. All views should have |
| 10069 | * layout parameters. These supply parameters to the <i>parent</i> of this |
| 10070 | * view specifying how it should be arranged. There are many subclasses of |
| 10071 | * ViewGroup.LayoutParams, and these correspond to the different subclasses |
| 10072 | * of ViewGroup that are responsible for arranging their children. |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 10073 | * |
| 10074 | * This method may return null if this View is not attached to a parent |
| 10075 | * ViewGroup or {@link #setLayoutParams(android.view.ViewGroup.LayoutParams)} |
| 10076 | * was not invoked successfully. When a View is attached to a parent |
| 10077 | * ViewGroup, this method must not return null. |
| 10078 | * |
| 10079 | * @return The LayoutParams associated with this view, or null if no |
| 10080 | * parameters have been set yet |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | */ |
Konstantin Lopyrev | 91a7f5f | 2010-08-10 18:54:54 -0700 | [diff] [blame] | 10082 | @ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10083 | public ViewGroup.LayoutParams getLayoutParams() { |
| 10084 | return mLayoutParams; |
| 10085 | } |
| 10086 | |
| 10087 | /** |
| 10088 | * Set the layout parameters associated with this view. These supply |
| 10089 | * parameters to the <i>parent</i> of this view specifying how it should be |
| 10090 | * arranged. There are many subclasses of ViewGroup.LayoutParams, and these |
| 10091 | * correspond to the different subclasses of ViewGroup that are responsible |
| 10092 | * for arranging their children. |
| 10093 | * |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 10094 | * @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] | 10095 | */ |
| 10096 | public void setLayoutParams(ViewGroup.LayoutParams params) { |
| 10097 | if (params == null) { |
Romain Guy | 01c174b | 2011-02-22 11:51:06 -0800 | [diff] [blame] | 10098 | throw new NullPointerException("Layout parameters cannot be null"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10099 | } |
| 10100 | mLayoutParams = params; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10101 | resolveLayoutParams(); |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 10102 | if (mParent instanceof ViewGroup) { |
| 10103 | ((ViewGroup) mParent).onSetLayoutParams(this, params); |
| 10104 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10105 | requestLayout(); |
| 10106 | } |
| 10107 | |
| 10108 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10109 | * Resolve the layout parameters depending on the resolved layout direction |
Fabrice Di Meglio | fcc3348 | 2012-10-18 11:11:51 -0700 | [diff] [blame] | 10110 | * |
| 10111 | * @hide |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10112 | */ |
Fabrice Di Meglio | fcc3348 | 2012-10-18 11:11:51 -0700 | [diff] [blame] | 10113 | public void resolveLayoutParams() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10114 | if (mLayoutParams != null) { |
Fabrice Di Meglio | 2918ab6 | 2012-10-10 16:39:25 -0700 | [diff] [blame] | 10115 | mLayoutParams.resolveLayoutDirection(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 10116 | } |
| 10117 | } |
| 10118 | |
| 10119 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10120 | * Set the scrolled position of your view. This will cause a call to |
| 10121 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10122 | * invalidated. |
| 10123 | * @param x the x position to scroll to |
| 10124 | * @param y the y position to scroll to |
| 10125 | */ |
| 10126 | public void scrollTo(int x, int y) { |
| 10127 | if (mScrollX != x || mScrollY != y) { |
| 10128 | int oldX = mScrollX; |
| 10129 | int oldY = mScrollY; |
| 10130 | mScrollX = x; |
| 10131 | mScrollY = y; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10132 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | onScrollChanged(mScrollX, mScrollY, oldX, oldY); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10134 | if (!awakenScrollBars()) { |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10135 | postInvalidateOnAnimation(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | /** |
| 10141 | * Move the scrolled position of your view. This will cause a call to |
| 10142 | * {@link #onScrollChanged(int, int, int, int)} and the view will be |
| 10143 | * invalidated. |
| 10144 | * @param x the amount of pixels to scroll by horizontally |
| 10145 | * @param y the amount of pixels to scroll by vertically |
| 10146 | */ |
| 10147 | public void scrollBy(int x, int y) { |
| 10148 | scrollTo(mScrollX + x, mScrollY + y); |
| 10149 | } |
| 10150 | |
| 10151 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10152 | * <p>Trigger the scrollbars to draw. When invoked this method starts an |
| 10153 | * animation to fade the scrollbars out after a default delay. If a subclass |
| 10154 | * provides animated scrolling, the start delay should equal the duration |
| 10155 | * of the scrolling animation.</p> |
| 10156 | * |
| 10157 | * <p>The animation starts only if at least one of the scrollbars is |
| 10158 | * enabled, as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10159 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10160 | * this method returns true, and false otherwise. If the animation is |
| 10161 | * started, this method calls {@link #invalidate()}; in that case the |
| 10162 | * caller should not call {@link #invalidate()}.</p> |
| 10163 | * |
| 10164 | * <p>This method should be invoked every time a subclass directly updates |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10165 | * the scroll parameters.</p> |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10166 | * |
| 10167 | * <p>This method is automatically invoked by {@link #scrollBy(int, int)} |
| 10168 | * and {@link #scrollTo(int, int)}.</p> |
| 10169 | * |
| 10170 | * @return true if the animation is played, false otherwise |
| 10171 | * |
| 10172 | * @see #awakenScrollBars(int) |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10173 | * @see #scrollBy(int, int) |
| 10174 | * @see #scrollTo(int, int) |
| 10175 | * @see #isHorizontalScrollBarEnabled() |
| 10176 | * @see #isVerticalScrollBarEnabled() |
| 10177 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10178 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10179 | */ |
| 10180 | protected boolean awakenScrollBars() { |
| 10181 | return mScrollCache != null && |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10182 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade, true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10183 | } |
| 10184 | |
| 10185 | /** |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 10186 | * Trigger the scrollbars to draw. |
| 10187 | * This method differs from awakenScrollBars() only in its default duration. |
| 10188 | * initialAwakenScrollBars() will show the scroll bars for longer than |
| 10189 | * usual to give the user more of a chance to notice them. |
| 10190 | * |
| 10191 | * @return true if the animation is played, false otherwise. |
| 10192 | */ |
| 10193 | private boolean initialAwakenScrollBars() { |
| 10194 | return mScrollCache != null && |
| 10195 | awakenScrollBars(mScrollCache.scrollBarDefaultDelayBeforeFade * 4, true); |
| 10196 | } |
| 10197 | |
| 10198 | /** |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10199 | * <p> |
| 10200 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10201 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10202 | * provides animated scrolling, the start delay should equal the duration of |
| 10203 | * the scrolling animation. |
| 10204 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10205 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10206 | * <p> |
| 10207 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10208 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10209 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10210 | * this method returns true, and false otherwise. If the animation is |
| 10211 | * started, this method calls {@link #invalidate()}; in that case the caller |
| 10212 | * should not call {@link #invalidate()}. |
| 10213 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10214 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10215 | * <p> |
| 10216 | * This method should be invoked everytime a subclass directly updates the |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 10217 | * scroll parameters. |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10218 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10219 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10220 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10221 | * should start; when the delay is 0, the animation starts |
| 10222 | * immediately |
| 10223 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10224 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10225 | * @see #scrollBy(int, int) |
| 10226 | * @see #scrollTo(int, int) |
| 10227 | * @see #isHorizontalScrollBarEnabled() |
| 10228 | * @see #isVerticalScrollBarEnabled() |
| 10229 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10230 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10231 | */ |
| 10232 | protected boolean awakenScrollBars(int startDelay) { |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10233 | return awakenScrollBars(startDelay, true); |
| 10234 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10235 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10236 | /** |
| 10237 | * <p> |
| 10238 | * Trigger the scrollbars to draw. When invoked this method starts an |
| 10239 | * animation to fade the scrollbars out after a fixed delay. If a subclass |
| 10240 | * provides animated scrolling, the start delay should equal the duration of |
| 10241 | * the scrolling animation. |
| 10242 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10243 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10244 | * <p> |
| 10245 | * The animation starts only if at least one of the scrollbars is enabled, |
| 10246 | * as specified by {@link #isHorizontalScrollBarEnabled()} and |
| 10247 | * {@link #isVerticalScrollBarEnabled()}. When the animation is started, |
| 10248 | * this method returns true, and false otherwise. If the animation is |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10249 | * started, this method calls {@link #invalidate()} if the invalidate parameter |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10250 | * is set to true; in that case the caller |
| 10251 | * should not call {@link #invalidate()}. |
| 10252 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10253 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10254 | * <p> |
| 10255 | * This method should be invoked everytime a subclass directly updates the |
| 10256 | * scroll parameters. |
| 10257 | * </p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10258 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10259 | * @param startDelay the delay, in milliseconds, after which the animation |
| 10260 | * should start; when the delay is 0, the animation starts |
| 10261 | * immediately |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10262 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10263 | * @param invalidate Wheter this method should call invalidate |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10264 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10265 | * @return true if the animation is played, false otherwise |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10266 | * |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10267 | * @see #scrollBy(int, int) |
| 10268 | * @see #scrollTo(int, int) |
| 10269 | * @see #isHorizontalScrollBarEnabled() |
| 10270 | * @see #isVerticalScrollBarEnabled() |
| 10271 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 10272 | * @see #setVerticalScrollBarEnabled(boolean) |
| 10273 | */ |
| 10274 | protected boolean awakenScrollBars(int startDelay, boolean invalidate) { |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10275 | final ScrollabilityCache scrollCache = mScrollCache; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10276 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10277 | if (scrollCache == null || !scrollCache.fadeScrollBars) { |
| 10278 | return false; |
| 10279 | } |
| 10280 | |
| 10281 | if (scrollCache.scrollBar == null) { |
| 10282 | scrollCache.scrollBar = new ScrollBarDrawable(); |
| 10283 | } |
| 10284 | |
| 10285 | if (isHorizontalScrollBarEnabled() || isVerticalScrollBarEnabled()) { |
| 10286 | |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10287 | if (invalidate) { |
| 10288 | // Invalidate to show the scrollbars |
Adam Powell | df3ae4f | 2012-04-10 18:55:22 -0700 | [diff] [blame] | 10289 | postInvalidateOnAnimation(); |
Mike Cleron | 290947b | 2009-09-29 18:34:32 -0700 | [diff] [blame] | 10290 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10291 | |
| 10292 | if (scrollCache.state == ScrollabilityCache.OFF) { |
| 10293 | // FIXME: this is copied from WindowManagerService. |
| 10294 | // We should get this value from the system when it |
| 10295 | // is possible to do so. |
| 10296 | final int KEY_REPEAT_FIRST_DELAY = 750; |
| 10297 | startDelay = Math.max(KEY_REPEAT_FIRST_DELAY, startDelay); |
| 10298 | } |
| 10299 | |
| 10300 | // Tell mScrollCache when we should start fading. This may |
| 10301 | // extend the fade start time if one was already scheduled |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 10302 | long fadeStartTime = AnimationUtils.currentAnimationTimeMillis() + startDelay; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 10303 | scrollCache.fadeStartTime = fadeStartTime; |
| 10304 | scrollCache.state = ScrollabilityCache.ON; |
| 10305 | |
| 10306 | // Schedule our fader to run, unscheduling any old ones first |
| 10307 | if (mAttachInfo != null) { |
| 10308 | mAttachInfo.mHandler.removeCallbacks(scrollCache); |
| 10309 | mAttachInfo.mHandler.postAtTime(scrollCache, fadeStartTime); |
| 10310 | } |
| 10311 | |
| 10312 | return true; |
| 10313 | } |
| 10314 | |
| 10315 | return false; |
| 10316 | } |
| 10317 | |
| 10318 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10319 | * Do not invalidate views which are not visible and which are not running an animation. They |
| 10320 | * will not get drawn and they should not set dirty flags as if they will be drawn |
| 10321 | */ |
| 10322 | private boolean skipInvalidate() { |
| 10323 | return (mViewFlags & VISIBILITY_MASK) != VISIBLE && mCurrentAnimation == null && |
| 10324 | (!(mParent instanceof ViewGroup) || |
| 10325 | !((ViewGroup) mParent).isViewTransitioning(this)); |
| 10326 | } |
| 10327 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10328 | * 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] | 10329 | * visible, {@link #onDraw(android.graphics.Canvas)} will be called at some point |
| 10330 | * in the future. This must be called from a UI thread. To call from a non-UI |
| 10331 | * thread, call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10332 | * |
| 10333 | * WARNING: This method is destructive to dirty. |
| 10334 | * @param dirty the rectangle representing the bounds of the dirty region |
| 10335 | */ |
| 10336 | public void invalidate(Rect dirty) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10337 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10338 | return; |
| 10339 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10340 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10341 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10342 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10343 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10344 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10345 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10346 | final ViewParent p = mParent; |
| 10347 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10348 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10349 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10350 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10351 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10352 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10353 | p.invalidateChild(this, null); |
| 10354 | return; |
| 10355 | } |
Romain Guy | af636eb | 2010-12-09 17:47:21 -0800 | [diff] [blame] | 10356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10357 | if (p != null && ai != null) { |
| 10358 | final int scrollX = mScrollX; |
| 10359 | final int scrollY = mScrollY; |
| 10360 | final Rect r = ai.mTmpInvalRect; |
| 10361 | r.set(dirty.left - scrollX, dirty.top - scrollY, |
| 10362 | dirty.right - scrollX, dirty.bottom - scrollY); |
| 10363 | mParent.invalidateChild(this, r); |
| 10364 | } |
| 10365 | } |
| 10366 | } |
| 10367 | |
| 10368 | /** |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 10369 | * 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] | 10370 | * The coordinates of the dirty rect are relative to the view. |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10371 | * If the view is visible, {@link #onDraw(android.graphics.Canvas)} |
| 10372 | * will be called at some point in the future. This must be called from |
| 10373 | * 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] | 10374 | * @param l the left position of the dirty region |
| 10375 | * @param t the top position of the dirty region |
| 10376 | * @param r the right position of the dirty region |
| 10377 | * @param b the bottom position of the dirty region |
| 10378 | */ |
| 10379 | public void invalidate(int l, int t, int r, int b) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10380 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10381 | return; |
| 10382 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10383 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10384 | (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID || |
| 10385 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED) { |
| 10386 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 10387 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10388 | mPrivateFlags |= PFLAG_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | final ViewParent p = mParent; |
| 10390 | final AttachInfo ai = mAttachInfo; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10391 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10392 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10393 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10394 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10395 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10396 | p.invalidateChild(this, null); |
| 10397 | return; |
| 10398 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10399 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10400 | if (p != null && ai != null && l < r && t < b) { |
| 10401 | final int scrollX = mScrollX; |
| 10402 | final int scrollY = mScrollY; |
| 10403 | final Rect tmpr = ai.mTmpInvalRect; |
| 10404 | tmpr.set(l - scrollX, t - scrollY, r - scrollX, b - scrollY); |
| 10405 | p.invalidateChild(this, tmpr); |
| 10406 | } |
| 10407 | } |
| 10408 | } |
| 10409 | |
| 10410 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 10411 | * Invalidate the whole view. If the view is visible, |
| 10412 | * {@link #onDraw(android.graphics.Canvas)} will be called at some point in |
| 10413 | * the future. This must be called from a UI thread. To call from a non-UI thread, |
| 10414 | * call {@link #postInvalidate()}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | */ |
| 10416 | public void invalidate() { |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10417 | invalidate(true); |
| 10418 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10419 | |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10420 | /** |
| 10421 | * This is where the invalidate() work actually happens. A full invalidate() |
| 10422 | * causes the drawing cache to be invalidated, but this function can be called with |
| 10423 | * invalidateCache set to false to skip that invalidation step for cases that do not |
| 10424 | * need it (for example, a component that remains at the same dimensions with the same |
| 10425 | * content). |
| 10426 | * |
| 10427 | * @param invalidateCache Whether the drawing cache for this view should be invalidated as |
| 10428 | * well. This is usually true for a full invalidate, but may be set to false if the |
| 10429 | * View's contents or dimensions have not changed. |
| 10430 | */ |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 10431 | void invalidate(boolean invalidateCache) { |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 10432 | if (skipInvalidate()) { |
Chet Haase | a68c5cf | 2011-08-22 14:27:51 -0700 | [diff] [blame] | 10433 | return; |
| 10434 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10435 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_HAS_BOUNDS)) == (PFLAG_DRAWN | PFLAG_HAS_BOUNDS) || |
| 10436 | (invalidateCache && (mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == PFLAG_DRAWING_CACHE_VALID) || |
| 10437 | (mPrivateFlags & PFLAG_INVALIDATED) != PFLAG_INVALIDATED || isOpaque() != mLastIsOpaque) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10438 | mLastIsOpaque = isOpaque(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10439 | mPrivateFlags &= ~PFLAG_DRAWN; |
| 10440 | mPrivateFlags |= PFLAG_DIRTY; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10441 | if (invalidateCache) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10442 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 10443 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Chet Haase | ed03270 | 2010-10-01 14:05:54 -0700 | [diff] [blame] | 10444 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10445 | final AttachInfo ai = mAttachInfo; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 10446 | final ViewParent p = mParent; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10447 | //noinspection PointlessBooleanExpression,ConstantConditions |
| 10448 | if (!HardwareRenderer.RENDER_DIRTY_REGIONS) { |
| 10449 | if (p != null && ai != null && ai.mHardwareAccelerated) { |
| 10450 | // fast-track for GL-enabled applications; just invalidate the whole hierarchy |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 10451 | // with a null dirty rect, which tells the ViewAncestor to redraw everything |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 10452 | p.invalidateChild(this, null); |
| 10453 | return; |
| 10454 | } |
Chet Haase | f2f7d8f | 2010-12-03 14:08:14 -0800 | [diff] [blame] | 10455 | } |
Michael Jurka | ebefea4 | 2010-11-15 16:04:01 -0800 | [diff] [blame] | 10456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | if (p != null && ai != null) { |
| 10458 | final Rect r = ai.mTmpInvalRect; |
| 10459 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10460 | // Don't call invalidate -- we don't want to internally scroll |
| 10461 | // our own bounds |
| 10462 | p.invalidateChild(this, r); |
| 10463 | } |
| 10464 | } |
| 10465 | } |
| 10466 | |
| 10467 | /** |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10468 | * Quick invalidation for View property changes (alpha, translationXY, etc.). We don't want to |
| 10469 | * set any flags or handle all of the cases handled by the default invalidation methods. |
| 10470 | * Instead, we just want to schedule a traversal in ViewRootImpl with the appropriate |
| 10471 | * dirty rect. This method calls into fast invalidation methods in ViewGroup that |
| 10472 | * walk up the hierarchy, transforming the dirty rect as necessary. |
| 10473 | * |
| 10474 | * The method also handles normal invalidation logic if display list properties are not |
| 10475 | * being used in this view. The invalidateParent and forceRedraw flags are used by that |
| 10476 | * backup approach, to handle these cases used in the various property-setting methods. |
| 10477 | * |
| 10478 | * @param invalidateParent Force a call to invalidateParentCaches() if display list properties |
| 10479 | * are not being used in this view |
| 10480 | * @param forceRedraw Mark the view as DRAWN to force the invalidation to propagate, if display |
| 10481 | * list properties are not being used in this view |
| 10482 | */ |
| 10483 | void invalidateViewProperty(boolean invalidateParent, boolean forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10484 | if (mDisplayList == null || (mPrivateFlags & PFLAG_DRAW_ANIMATION) == PFLAG_DRAW_ANIMATION) { |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10485 | if (invalidateParent) { |
| 10486 | invalidateParentCaches(); |
| 10487 | } |
| 10488 | if (forceRedraw) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10489 | mPrivateFlags |= PFLAG_DRAWN; // force another invalidation with the new orientation |
Chet Haase | 9d1992d | 2012-03-13 11:03:25 -0700 | [diff] [blame] | 10490 | } |
| 10491 | invalidate(false); |
| 10492 | } else { |
| 10493 | final AttachInfo ai = mAttachInfo; |
| 10494 | final ViewParent p = mParent; |
| 10495 | if (p != null && ai != null) { |
| 10496 | final Rect r = ai.mTmpInvalRect; |
| 10497 | r.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 10498 | if (mParent instanceof ViewGroup) { |
| 10499 | ((ViewGroup) mParent).invalidateChildFast(this, r); |
| 10500 | } else { |
| 10501 | mParent.invalidateChild(this, r); |
| 10502 | } |
| 10503 | } |
| 10504 | } |
| 10505 | } |
| 10506 | |
| 10507 | /** |
| 10508 | * Utility method to transform a given Rect by the current matrix of this view. |
| 10509 | */ |
| 10510 | void transformRect(final Rect rect) { |
| 10511 | if (!getMatrix().isIdentity()) { |
| 10512 | RectF boundingRect = mAttachInfo.mTmpTransformRect; |
| 10513 | boundingRect.set(rect); |
| 10514 | getMatrix().mapRect(boundingRect); |
| 10515 | rect.set((int) (boundingRect.left - 0.5f), |
| 10516 | (int) (boundingRect.top - 0.5f), |
| 10517 | (int) (boundingRect.right + 0.5f), |
| 10518 | (int) (boundingRect.bottom + 0.5f)); |
| 10519 | } |
| 10520 | } |
| 10521 | |
| 10522 | /** |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10523 | * 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] | 10524 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10525 | * 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] | 10526 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method only |
| 10527 | * clears the parent caches and does not causes an invalidate event. |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10528 | * |
| 10529 | * @hide |
| 10530 | */ |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10531 | protected void invalidateParentCaches() { |
| 10532 | if (mParent instanceof View) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10533 | ((View) mParent).mPrivateFlags |= PFLAG_INVALIDATED; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10534 | } |
| 10535 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 10536 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10537 | /** |
| 10538 | * Used to indicate that the parent of this view should be invalidated. This functionality |
| 10539 | * is used to force the parent to rebuild its display list (when hardware-accelerated), |
| 10540 | * which is necessary when various parent-managed properties of the view change, such as |
| 10541 | * alpha, translationX/Y, scrollX/Y, scaleX/Y, and rotation/X/Y. This method will propagate |
| 10542 | * an invalidation event to the parent. |
| 10543 | * |
| 10544 | * @hide |
| 10545 | */ |
| 10546 | protected void invalidateParentIfNeeded() { |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10547 | if (isHardwareAccelerated() && mParent instanceof View) { |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 10548 | ((View) mParent).invalidate(true); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 10549 | } |
| 10550 | } |
| 10551 | |
| 10552 | /** |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10553 | * Indicates whether this View is opaque. An opaque View guarantees that it will |
| 10554 | * draw all the pixels overlapping its bounds using a fully opaque color. |
| 10555 | * |
| 10556 | * Subclasses of View should override this method whenever possible to indicate |
| 10557 | * whether an instance is opaque. Opaque Views are treated in a special way by |
| 10558 | * the View hierarchy, possibly allowing it to perform optimizations during |
| 10559 | * invalidate/draw passes. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 10560 | * |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10561 | * @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] | 10562 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 10563 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10564 | public boolean isOpaque() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10565 | return (mPrivateFlags & PFLAG_OPAQUE_MASK) == PFLAG_OPAQUE_MASK && |
Romain Guy | f877308 | 2012-07-12 18:01:00 -0700 | [diff] [blame] | 10566 | ((mTransformationInfo != null ? mTransformationInfo.mAlpha : 1.0f) >= 1.0f); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10567 | } |
| 10568 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 10569 | /** |
| 10570 | * @hide |
| 10571 | */ |
| 10572 | protected void computeOpaqueFlags() { |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10573 | // Opaque if: |
| 10574 | // - Has a background |
| 10575 | // - Background is opaque |
| 10576 | // - Doesn't have scrollbars or scrollbars are inside overlay |
| 10577 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10578 | if (mBackground != null && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10579 | mPrivateFlags |= PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10580 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10581 | mPrivateFlags &= ~PFLAG_OPAQUE_BACKGROUND; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10582 | } |
| 10583 | |
| 10584 | final int flags = mViewFlags; |
| 10585 | if (((flags & SCROLLBARS_VERTICAL) == 0 && (flags & SCROLLBARS_HORIZONTAL) == 0) || |
| 10586 | (flags & SCROLLBARS_STYLE_MASK) == SCROLLBARS_INSIDE_OVERLAY) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10587 | mPrivateFlags |= PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10588 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10589 | mPrivateFlags &= ~PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 10590 | } |
| 10591 | } |
| 10592 | |
| 10593 | /** |
| 10594 | * @hide |
| 10595 | */ |
| 10596 | protected boolean hasOpaqueScrollbars() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 10597 | return (mPrivateFlags & PFLAG_OPAQUE_SCROLLBARS) == PFLAG_OPAQUE_SCROLLBARS; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 10598 | } |
| 10599 | |
| 10600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10601 | * @return A handler associated with the thread running the View. This |
| 10602 | * handler can be used to pump events in the UI events queue. |
| 10603 | */ |
| 10604 | public Handler getHandler() { |
| 10605 | if (mAttachInfo != null) { |
| 10606 | return mAttachInfo.mHandler; |
| 10607 | } |
| 10608 | return null; |
| 10609 | } |
| 10610 | |
| 10611 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10612 | * Gets the view root associated with the View. |
| 10613 | * @return The view root, or null if none. |
| 10614 | * @hide |
| 10615 | */ |
| 10616 | public ViewRootImpl getViewRootImpl() { |
| 10617 | if (mAttachInfo != null) { |
| 10618 | return mAttachInfo.mViewRootImpl; |
| 10619 | } |
| 10620 | return null; |
| 10621 | } |
| 10622 | |
| 10623 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10624 | * <p>Causes the Runnable to be added to the message queue. |
| 10625 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10626 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10627 | * @param action The Runnable that will be executed. |
| 10628 | * |
| 10629 | * @return Returns true if the Runnable was successfully placed in to the |
| 10630 | * message queue. Returns false on failure, usually because the |
| 10631 | * looper processing the message queue is exiting. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10632 | * |
| 10633 | * @see #postDelayed |
| 10634 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10635 | */ |
| 10636 | public boolean post(Runnable action) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10637 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10638 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10639 | return attachInfo.mHandler.post(action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10641 | // Assume that post will succeed later |
| 10642 | ViewRootImpl.getRunQueue().post(action); |
| 10643 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10644 | } |
| 10645 | |
| 10646 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10647 | * <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] | 10648 | * after the specified amount of time elapses. |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10649 | * The runnable will be run on the user interface thread.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10650 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10651 | * @param action The Runnable that will be executed. |
| 10652 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10653 | * will be executed. |
| 10654 | * |
| 10655 | * @return true if the Runnable was successfully placed in to the |
| 10656 | * message queue. Returns false on failure, usually because the |
| 10657 | * looper processing the message queue is exiting. Note that a |
| 10658 | * result of true does not mean the Runnable will be processed -- |
| 10659 | * if the looper is quit before the delivery time of the message |
| 10660 | * occurs then the message will be dropped. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10661 | * |
| 10662 | * @see #post |
| 10663 | * @see #removeCallbacks |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | */ |
| 10665 | public boolean postDelayed(Runnable action, long delayMillis) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10666 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10667 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10668 | return attachInfo.mHandler.postDelayed(action, delayMillis); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10669 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10670 | // Assume that post will succeed later |
| 10671 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10672 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10673 | } |
| 10674 | |
| 10675 | /** |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10676 | * <p>Causes the Runnable to execute on the next animation time step. |
| 10677 | * The runnable will be run on the user interface thread.</p> |
| 10678 | * |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10679 | * @param action The Runnable that will be executed. |
| 10680 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10681 | * @see #postOnAnimationDelayed |
| 10682 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10683 | */ |
| 10684 | public void postOnAnimation(Runnable action) { |
| 10685 | final AttachInfo attachInfo = mAttachInfo; |
| 10686 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10687 | attachInfo.mViewRootImpl.mChoreographer.postCallback( |
| 10688 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10689 | } else { |
| 10690 | // Assume that post will succeed later |
| 10691 | ViewRootImpl.getRunQueue().post(action); |
| 10692 | } |
| 10693 | } |
| 10694 | |
| 10695 | /** |
| 10696 | * <p>Causes the Runnable to execute on the next animation time step, |
| 10697 | * after the specified amount of time elapses. |
| 10698 | * The runnable will be run on the user interface thread.</p> |
| 10699 | * |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10700 | * @param action The Runnable that will be executed. |
| 10701 | * @param delayMillis The delay (in milliseconds) until the Runnable |
| 10702 | * will be executed. |
| 10703 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10704 | * @see #postOnAnimation |
| 10705 | * @see #removeCallbacks |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10706 | */ |
| 10707 | public void postOnAnimationDelayed(Runnable action, long delayMillis) { |
| 10708 | final AttachInfo attachInfo = mAttachInfo; |
| 10709 | if (attachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10710 | attachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 10711 | Choreographer.CALLBACK_ANIMATION, action, null, delayMillis); |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 10712 | } else { |
| 10713 | // Assume that post will succeed later |
| 10714 | ViewRootImpl.getRunQueue().postDelayed(action, delayMillis); |
| 10715 | } |
| 10716 | } |
| 10717 | |
| 10718 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10719 | * <p>Removes the specified Runnable from the message queue.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10720 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10721 | * @param action The Runnable to remove from the message handling queue |
| 10722 | * |
| 10723 | * @return true if this view could ask the Handler to remove the Runnable, |
| 10724 | * false otherwise. When the returned value is true, the Runnable |
| 10725 | * may or may not have been actually removed from the message queue |
| 10726 | * (for instance, if the Runnable was not in the queue already.) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10727 | * |
| 10728 | * @see #post |
| 10729 | * @see #postDelayed |
| 10730 | * @see #postOnAnimation |
| 10731 | * @see #postOnAnimationDelayed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10732 | */ |
| 10733 | public boolean removeCallbacks(Runnable action) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10734 | if (action != null) { |
| 10735 | final AttachInfo attachInfo = mAttachInfo; |
| 10736 | if (attachInfo != null) { |
| 10737 | attachInfo.mHandler.removeCallbacks(action); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 10738 | attachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 10739 | Choreographer.CALLBACK_ANIMATION, action, null); |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 10740 | } else { |
| 10741 | // Assume that post will succeed later |
| 10742 | ViewRootImpl.getRunQueue().removeCallbacks(action); |
| 10743 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10745 | return true; |
| 10746 | } |
| 10747 | |
| 10748 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10749 | * <p>Cause an invalidate to happen on a subsequent cycle through the event loop. |
| 10750 | * 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] | 10751 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10752 | * <p>This method can be invoked from outside of the UI thread |
| 10753 | * only when this View is attached to a window.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10754 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10755 | * @see #invalidate() |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10756 | * @see #postInvalidateDelayed(long) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10757 | */ |
| 10758 | public void postInvalidate() { |
| 10759 | postInvalidateDelayed(0); |
| 10760 | } |
| 10761 | |
| 10762 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10763 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10764 | * 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] | 10765 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10766 | * <p>This method can be invoked from outside of the UI thread |
| 10767 | * 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] | 10768 | * |
| 10769 | * @param left The left coordinate of the rectangle to invalidate. |
| 10770 | * @param top The top coordinate of the rectangle to invalidate. |
| 10771 | * @param right The right coordinate of the rectangle to invalidate. |
| 10772 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10773 | * |
| 10774 | * @see #invalidate(int, int, int, int) |
| 10775 | * @see #invalidate(Rect) |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10776 | * @see #postInvalidateDelayed(long, int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10777 | */ |
| 10778 | public void postInvalidate(int left, int top, int right, int bottom) { |
| 10779 | postInvalidateDelayed(0, left, top, right, bottom); |
| 10780 | } |
| 10781 | |
| 10782 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10783 | * <p>Cause an invalidate to happen on a subsequent cycle through the event |
| 10784 | * loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10785 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10786 | * <p>This method can be invoked from outside of the UI thread |
| 10787 | * 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] | 10788 | * |
| 10789 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10790 | * invalidation by |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10791 | * |
| 10792 | * @see #invalidate() |
| 10793 | * @see #postInvalidate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10794 | */ |
| 10795 | public void postInvalidateDelayed(long delayMilliseconds) { |
| 10796 | // We try only with the AttachInfo because there's no point in invalidating |
| 10797 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10798 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10799 | if (attachInfo != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10800 | attachInfo.mViewRootImpl.dispatchInvalidateDelayed(this, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10801 | } |
| 10802 | } |
| 10803 | |
| 10804 | /** |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10805 | * <p>Cause an invalidate of the specified area to happen on a subsequent cycle |
| 10806 | * through the event loop. Waits for the specified amount of time.</p> |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10807 | * |
Romain Guy | e63a4f3 | 2011-08-11 11:33:31 -0700 | [diff] [blame] | 10808 | * <p>This method can be invoked from outside of the UI thread |
| 10809 | * 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] | 10810 | * |
| 10811 | * @param delayMilliseconds the duration in milliseconds to delay the |
| 10812 | * invalidation by |
| 10813 | * @param left The left coordinate of the rectangle to invalidate. |
| 10814 | * @param top The top coordinate of the rectangle to invalidate. |
| 10815 | * @param right The right coordinate of the rectangle to invalidate. |
| 10816 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10817 | * |
| 10818 | * @see #invalidate(int, int, int, int) |
| 10819 | * @see #invalidate(Rect) |
| 10820 | * @see #postInvalidate(int, int, int, int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10821 | */ |
| 10822 | public void postInvalidateDelayed(long delayMilliseconds, int left, int top, |
| 10823 | int right, int bottom) { |
| 10824 | |
| 10825 | // We try only with the AttachInfo because there's no point in invalidating |
| 10826 | // if we are not attached to our window |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10827 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | c5a43a2 | 2011-03-24 13:28:56 -0700 | [diff] [blame] | 10828 | if (attachInfo != null) { |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 10829 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.obtain(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10830 | info.target = this; |
| 10831 | info.left = left; |
| 10832 | info.top = top; |
| 10833 | info.right = right; |
| 10834 | info.bottom = bottom; |
| 10835 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 10836 | attachInfo.mViewRootImpl.dispatchInvalidateRectDelayed(info, delayMilliseconds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10837 | } |
| 10838 | } |
| 10839 | |
| 10840 | /** |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10841 | * <p>Cause an invalidate to happen on the next animation time step, typically the |
| 10842 | * next display frame.</p> |
| 10843 | * |
| 10844 | * <p>This method can be invoked from outside of the UI thread |
| 10845 | * only when this View is attached to a window.</p> |
| 10846 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10847 | * @see #invalidate() |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10848 | */ |
| 10849 | public void postInvalidateOnAnimation() { |
| 10850 | // We try only with the AttachInfo because there's no point in invalidating |
| 10851 | // if we are not attached to our window |
| 10852 | final AttachInfo attachInfo = mAttachInfo; |
| 10853 | if (attachInfo != null) { |
| 10854 | attachInfo.mViewRootImpl.dispatchInvalidateOnAnimation(this); |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | /** |
| 10859 | * <p>Cause an invalidate of the specified area to happen on the next animation |
| 10860 | * time step, typically the next display frame.</p> |
| 10861 | * |
| 10862 | * <p>This method can be invoked from outside of the UI thread |
| 10863 | * only when this View is attached to a window.</p> |
| 10864 | * |
| 10865 | * @param left The left coordinate of the rectangle to invalidate. |
| 10866 | * @param top The top coordinate of the rectangle to invalidate. |
| 10867 | * @param right The right coordinate of the rectangle to invalidate. |
| 10868 | * @param bottom The bottom coordinate of the rectangle to invalidate. |
| 10869 | * |
Jeff Brown | 4d6a82d | 2012-04-11 14:23:51 -0700 | [diff] [blame] | 10870 | * @see #invalidate(int, int, int, int) |
| 10871 | * @see #invalidate(Rect) |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10872 | */ |
| 10873 | public void postInvalidateOnAnimation(int left, int top, int right, int bottom) { |
| 10874 | // We try only with the AttachInfo because there's no point in invalidating |
| 10875 | // if we are not attached to our window |
| 10876 | final AttachInfo attachInfo = mAttachInfo; |
| 10877 | if (attachInfo != null) { |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 10878 | final AttachInfo.InvalidateInfo info = AttachInfo.InvalidateInfo.obtain(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 10879 | info.target = this; |
| 10880 | info.left = left; |
| 10881 | info.top = top; |
| 10882 | info.right = right; |
| 10883 | info.bottom = bottom; |
| 10884 | |
| 10885 | attachInfo.mViewRootImpl.dispatchInvalidateRectOnAnimation(info); |
| 10886 | } |
| 10887 | } |
| 10888 | |
| 10889 | /** |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 10890 | * Post a callback to send a {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} event. |
| 10891 | * This event is sent at most once every |
| 10892 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
| 10893 | */ |
| 10894 | private void postSendViewScrolledAccessibilityEventCallback() { |
| 10895 | if (mSendViewScrolledAccessibilityEvent == null) { |
| 10896 | mSendViewScrolledAccessibilityEvent = new SendViewScrolledAccessibilityEvent(); |
| 10897 | } |
| 10898 | if (!mSendViewScrolledAccessibilityEvent.mIsPending) { |
| 10899 | mSendViewScrolledAccessibilityEvent.mIsPending = true; |
| 10900 | postDelayed(mSendViewScrolledAccessibilityEvent, |
| 10901 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval()); |
| 10902 | } |
| 10903 | } |
| 10904 | |
| 10905 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10906 | * Called by a parent to request that a child update its values for mScrollX |
| 10907 | * and mScrollY if necessary. This will typically be done if the child is |
| 10908 | * animating a scroll using a {@link android.widget.Scroller Scroller} |
| 10909 | * object. |
| 10910 | */ |
| 10911 | public void computeScroll() { |
| 10912 | } |
| 10913 | |
| 10914 | /** |
| 10915 | * <p>Indicate whether the horizontal edges are faded when the view is |
| 10916 | * scrolled horizontally.</p> |
| 10917 | * |
| 10918 | * @return true if the horizontal edges should are faded on scroll, false |
| 10919 | * otherwise |
| 10920 | * |
| 10921 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10922 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10923 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | */ |
| 10925 | public boolean isHorizontalFadingEdgeEnabled() { |
| 10926 | return (mViewFlags & FADING_EDGE_HORIZONTAL) == FADING_EDGE_HORIZONTAL; |
| 10927 | } |
| 10928 | |
| 10929 | /** |
| 10930 | * <p>Define whether the horizontal edges should be faded when this view |
| 10931 | * is scrolled horizontally.</p> |
| 10932 | * |
| 10933 | * @param horizontalFadingEdgeEnabled true if the horizontal edges should |
| 10934 | * be faded when the view is scrolled |
| 10935 | * horizontally |
| 10936 | * |
| 10937 | * @see #isHorizontalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10938 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10939 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10940 | */ |
| 10941 | public void setHorizontalFadingEdgeEnabled(boolean horizontalFadingEdgeEnabled) { |
| 10942 | if (isHorizontalFadingEdgeEnabled() != horizontalFadingEdgeEnabled) { |
| 10943 | if (horizontalFadingEdgeEnabled) { |
| 10944 | initScrollCache(); |
| 10945 | } |
| 10946 | |
| 10947 | mViewFlags ^= FADING_EDGE_HORIZONTAL; |
| 10948 | } |
| 10949 | } |
| 10950 | |
| 10951 | /** |
| 10952 | * <p>Indicate whether the vertical edges are faded when the view is |
| 10953 | * scrolled horizontally.</p> |
| 10954 | * |
| 10955 | * @return true if the vertical edges should are faded on scroll, false |
| 10956 | * otherwise |
| 10957 | * |
| 10958 | * @see #setVerticalFadingEdgeEnabled(boolean) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10959 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10960 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10961 | */ |
| 10962 | public boolean isVerticalFadingEdgeEnabled() { |
| 10963 | return (mViewFlags & FADING_EDGE_VERTICAL) == FADING_EDGE_VERTICAL; |
| 10964 | } |
| 10965 | |
| 10966 | /** |
| 10967 | * <p>Define whether the vertical edges should be faded when this view |
| 10968 | * is scrolled vertically.</p> |
| 10969 | * |
| 10970 | * @param verticalFadingEdgeEnabled true if the vertical edges should |
| 10971 | * be faded when the view is scrolled |
| 10972 | * vertically |
| 10973 | * |
| 10974 | * @see #isVerticalFadingEdgeEnabled() |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 10975 | * |
Romain Guy | 1ef3fdb | 2011-09-09 15:30:30 -0700 | [diff] [blame] | 10976 | * @attr ref android.R.styleable#View_requiresFadingEdge |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10977 | */ |
| 10978 | public void setVerticalFadingEdgeEnabled(boolean verticalFadingEdgeEnabled) { |
| 10979 | if (isVerticalFadingEdgeEnabled() != verticalFadingEdgeEnabled) { |
| 10980 | if (verticalFadingEdgeEnabled) { |
| 10981 | initScrollCache(); |
| 10982 | } |
| 10983 | |
| 10984 | mViewFlags ^= FADING_EDGE_VERTICAL; |
| 10985 | } |
| 10986 | } |
| 10987 | |
| 10988 | /** |
| 10989 | * Returns the strength, or intensity, of the top faded edge. The strength is |
| 10990 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 10991 | * returns 0.0 or 1.0 but no value in between. |
| 10992 | * |
| 10993 | * Subclasses should override this method to provide a smoother fade transition |
| 10994 | * when scrolling occurs. |
| 10995 | * |
| 10996 | * @return the intensity of the top fade as a float between 0.0f and 1.0f |
| 10997 | */ |
| 10998 | protected float getTopFadingEdgeStrength() { |
| 10999 | return computeVerticalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 11000 | } |
| 11001 | |
| 11002 | /** |
| 11003 | * Returns the strength, or intensity, of the bottom faded edge. The strength is |
| 11004 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 11005 | * returns 0.0 or 1.0 but no value in between. |
| 11006 | * |
| 11007 | * Subclasses should override this method to provide a smoother fade transition |
| 11008 | * when scrolling occurs. |
| 11009 | * |
| 11010 | * @return the intensity of the bottom fade as a float between 0.0f and 1.0f |
| 11011 | */ |
| 11012 | protected float getBottomFadingEdgeStrength() { |
| 11013 | return computeVerticalScrollOffset() + computeVerticalScrollExtent() < |
| 11014 | computeVerticalScrollRange() ? 1.0f : 0.0f; |
| 11015 | } |
| 11016 | |
| 11017 | /** |
| 11018 | * Returns the strength, or intensity, of the left faded edge. The strength is |
| 11019 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 11020 | * returns 0.0 or 1.0 but no value in between. |
| 11021 | * |
| 11022 | * Subclasses should override this method to provide a smoother fade transition |
| 11023 | * when scrolling occurs. |
| 11024 | * |
| 11025 | * @return the intensity of the left fade as a float between 0.0f and 1.0f |
| 11026 | */ |
| 11027 | protected float getLeftFadingEdgeStrength() { |
| 11028 | return computeHorizontalScrollOffset() > 0 ? 1.0f : 0.0f; |
| 11029 | } |
| 11030 | |
| 11031 | /** |
| 11032 | * Returns the strength, or intensity, of the right faded edge. The strength is |
| 11033 | * a value between 0.0 (no fade) and 1.0 (full fade). The default implementation |
| 11034 | * returns 0.0 or 1.0 but no value in between. |
| 11035 | * |
| 11036 | * Subclasses should override this method to provide a smoother fade transition |
| 11037 | * when scrolling occurs. |
| 11038 | * |
| 11039 | * @return the intensity of the right fade as a float between 0.0f and 1.0f |
| 11040 | */ |
| 11041 | protected float getRightFadingEdgeStrength() { |
| 11042 | return computeHorizontalScrollOffset() + computeHorizontalScrollExtent() < |
| 11043 | computeHorizontalScrollRange() ? 1.0f : 0.0f; |
| 11044 | } |
| 11045 | |
| 11046 | /** |
| 11047 | * <p>Indicate whether the horizontal scrollbar should be drawn or not. The |
| 11048 | * scrollbar is not drawn by default.</p> |
| 11049 | * |
| 11050 | * @return true if the horizontal scrollbar should be painted, false |
| 11051 | * otherwise |
| 11052 | * |
| 11053 | * @see #setHorizontalScrollBarEnabled(boolean) |
| 11054 | */ |
| 11055 | public boolean isHorizontalScrollBarEnabled() { |
| 11056 | return (mViewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 11057 | } |
| 11058 | |
| 11059 | /** |
| 11060 | * <p>Define whether the horizontal scrollbar should be drawn or not. The |
| 11061 | * scrollbar is not drawn by default.</p> |
| 11062 | * |
| 11063 | * @param horizontalScrollBarEnabled true if the horizontal scrollbar should |
| 11064 | * be painted |
| 11065 | * |
| 11066 | * @see #isHorizontalScrollBarEnabled() |
| 11067 | */ |
| 11068 | public void setHorizontalScrollBarEnabled(boolean horizontalScrollBarEnabled) { |
| 11069 | if (isHorizontalScrollBarEnabled() != horizontalScrollBarEnabled) { |
| 11070 | mViewFlags ^= SCROLLBARS_HORIZONTAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11071 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11072 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11073 | } |
| 11074 | } |
| 11075 | |
| 11076 | /** |
| 11077 | * <p>Indicate whether the vertical scrollbar should be drawn or not. The |
| 11078 | * scrollbar is not drawn by default.</p> |
| 11079 | * |
| 11080 | * @return true if the vertical scrollbar should be painted, false |
| 11081 | * otherwise |
| 11082 | * |
| 11083 | * @see #setVerticalScrollBarEnabled(boolean) |
| 11084 | */ |
| 11085 | public boolean isVerticalScrollBarEnabled() { |
| 11086 | return (mViewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL; |
| 11087 | } |
| 11088 | |
| 11089 | /** |
| 11090 | * <p>Define whether the vertical scrollbar should be drawn or not. The |
| 11091 | * scrollbar is not drawn by default.</p> |
| 11092 | * |
| 11093 | * @param verticalScrollBarEnabled true if the vertical scrollbar should |
| 11094 | * be painted |
| 11095 | * |
| 11096 | * @see #isVerticalScrollBarEnabled() |
| 11097 | */ |
| 11098 | public void setVerticalScrollBarEnabled(boolean verticalScrollBarEnabled) { |
| 11099 | if (isVerticalScrollBarEnabled() != verticalScrollBarEnabled) { |
| 11100 | mViewFlags ^= SCROLLBARS_VERTICAL; |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11101 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11102 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11103 | } |
| 11104 | } |
| 11105 | |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11106 | /** |
| 11107 | * @hide |
| 11108 | */ |
| 11109 | protected void recomputePadding() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 11110 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11111 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11112 | |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11113 | /** |
| 11114 | * Define whether scrollbars will fade when the view is not scrolling. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11115 | * |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11116 | * @param fadeScrollbars wheter to enable fading |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11117 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11118 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11119 | */ |
| 11120 | public void setScrollbarFadingEnabled(boolean fadeScrollbars) { |
| 11121 | initScrollCache(); |
| 11122 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
| 11123 | scrollabilityCache.fadeScrollBars = fadeScrollbars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11124 | if (fadeScrollbars) { |
| 11125 | scrollabilityCache.state = ScrollabilityCache.OFF; |
| 11126 | } else { |
Mike Cleron | fe81d38 | 2009-09-28 14:22:16 -0700 | [diff] [blame] | 11127 | scrollabilityCache.state = ScrollabilityCache.ON; |
| 11128 | } |
| 11129 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11131 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11132 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11133 | * Returns true if scrollbars will fade when this view is not scrolling |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11134 | * |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11135 | * @return true if scrollbar fading is enabled |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11136 | * |
| 11137 | * @attr ref android.R.styleable#View_fadeScrollbars |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11138 | */ |
| 11139 | public boolean isScrollbarFadingEnabled() { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11140 | return mScrollCache != null && mScrollCache.fadeScrollBars; |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11141 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11142 | |
Mike Cleron | 52f0a64 | 2009-09-28 18:21:37 -0700 | [diff] [blame] | 11143 | /** |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11144 | * |
| 11145 | * Returns the delay before scrollbars fade. |
| 11146 | * |
| 11147 | * @return the delay before scrollbars fade |
| 11148 | * |
| 11149 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11150 | */ |
| 11151 | public int getScrollBarDefaultDelayBeforeFade() { |
| 11152 | return mScrollCache == null ? ViewConfiguration.getScrollDefaultDelay() : |
| 11153 | mScrollCache.scrollBarDefaultDelayBeforeFade; |
| 11154 | } |
| 11155 | |
| 11156 | /** |
| 11157 | * Define the delay before scrollbars fade. |
| 11158 | * |
| 11159 | * @param scrollBarDefaultDelayBeforeFade - the delay before scrollbars fade |
| 11160 | * |
| 11161 | * @attr ref android.R.styleable#View_scrollbarDefaultDelayBeforeFade |
| 11162 | */ |
| 11163 | public void setScrollBarDefaultDelayBeforeFade(int scrollBarDefaultDelayBeforeFade) { |
| 11164 | getScrollCache().scrollBarDefaultDelayBeforeFade = scrollBarDefaultDelayBeforeFade; |
| 11165 | } |
| 11166 | |
| 11167 | /** |
| 11168 | * |
| 11169 | * Returns the scrollbar fade duration. |
| 11170 | * |
| 11171 | * @return the scrollbar fade duration |
| 11172 | * |
| 11173 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11174 | */ |
| 11175 | public int getScrollBarFadeDuration() { |
| 11176 | return mScrollCache == null ? ViewConfiguration.getScrollBarFadeDuration() : |
| 11177 | mScrollCache.scrollBarFadeDuration; |
| 11178 | } |
| 11179 | |
| 11180 | /** |
| 11181 | * Define the scrollbar fade duration. |
| 11182 | * |
| 11183 | * @param scrollBarFadeDuration - the scrollbar fade duration |
| 11184 | * |
| 11185 | * @attr ref android.R.styleable#View_scrollbarFadeDuration |
| 11186 | */ |
| 11187 | public void setScrollBarFadeDuration(int scrollBarFadeDuration) { |
| 11188 | getScrollCache().scrollBarFadeDuration = scrollBarFadeDuration; |
| 11189 | } |
| 11190 | |
| 11191 | /** |
| 11192 | * |
| 11193 | * Returns the scrollbar size. |
| 11194 | * |
| 11195 | * @return the scrollbar size |
| 11196 | * |
| 11197 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11198 | */ |
| 11199 | public int getScrollBarSize() { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 11200 | return mScrollCache == null ? ViewConfiguration.get(mContext).getScaledScrollBarSize() : |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11201 | mScrollCache.scrollBarSize; |
| 11202 | } |
| 11203 | |
| 11204 | /** |
| 11205 | * Define the scrollbar size. |
| 11206 | * |
| 11207 | * @param scrollBarSize - the scrollbar size |
| 11208 | * |
| 11209 | * @attr ref android.R.styleable#View_scrollbarSize |
| 11210 | */ |
| 11211 | public void setScrollBarSize(int scrollBarSize) { |
| 11212 | getScrollCache().scrollBarSize = scrollBarSize; |
| 11213 | } |
| 11214 | |
| 11215 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11216 | * <p>Specify the style of the scrollbars. The scrollbars can be overlaid or |
| 11217 | * inset. When inset, they add to the padding of the view. And the scrollbars |
| 11218 | * can be drawn inside the padding area or on the edge of the view. For example, |
| 11219 | * if a view has a background drawable and you want to draw the scrollbars |
| 11220 | * inside the padding specified by the drawable, you can use |
| 11221 | * SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to |
| 11222 | * appear at the edge of the view, ignoring the padding, then you can use |
| 11223 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.</p> |
| 11224 | * @param style the style of the scrollbars. Should be one of |
| 11225 | * SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, |
| 11226 | * SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. |
| 11227 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11228 | * @see #SCROLLBARS_INSIDE_INSET |
| 11229 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11230 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11231 | * |
| 11232 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11233 | */ |
| 11234 | public void setScrollBarStyle(int style) { |
| 11235 | if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { |
| 11236 | mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 11237 | computeOpaqueFlags(); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11238 | resolvePadding(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11239 | } |
| 11240 | } |
| 11241 | |
| 11242 | /** |
| 11243 | * <p>Returns the current scrollbar style.</p> |
| 11244 | * @return the current scrollbar style |
| 11245 | * @see #SCROLLBARS_INSIDE_OVERLAY |
| 11246 | * @see #SCROLLBARS_INSIDE_INSET |
| 11247 | * @see #SCROLLBARS_OUTSIDE_OVERLAY |
| 11248 | * @see #SCROLLBARS_OUTSIDE_INSET |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 11249 | * |
| 11250 | * @attr ref android.R.styleable#View_scrollbarStyle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11251 | */ |
Jeff Sharkey | 010d7e5 | 2011-08-08 21:05:02 -0700 | [diff] [blame] | 11252 | @ViewDebug.ExportedProperty(mapping = { |
| 11253 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_OVERLAY, to = "INSIDE_OVERLAY"), |
| 11254 | @ViewDebug.IntToString(from = SCROLLBARS_INSIDE_INSET, to = "INSIDE_INSET"), |
| 11255 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), |
| 11256 | @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") |
| 11257 | }) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11258 | public int getScrollBarStyle() { |
| 11259 | return mViewFlags & SCROLLBARS_STYLE_MASK; |
| 11260 | } |
| 11261 | |
| 11262 | /** |
| 11263 | * <p>Compute the horizontal range that the horizontal scrollbar |
| 11264 | * represents.</p> |
| 11265 | * |
| 11266 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11267 | * units used by {@link #computeHorizontalScrollExtent()} and |
| 11268 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11269 | * |
| 11270 | * <p>The default range is the drawing width of this view.</p> |
| 11271 | * |
| 11272 | * @return the total horizontal range represented by the horizontal |
| 11273 | * scrollbar |
| 11274 | * |
| 11275 | * @see #computeHorizontalScrollExtent() |
| 11276 | * @see #computeHorizontalScrollOffset() |
| 11277 | * @see android.widget.ScrollBarDrawable |
| 11278 | */ |
| 11279 | protected int computeHorizontalScrollRange() { |
| 11280 | return getWidth(); |
| 11281 | } |
| 11282 | |
| 11283 | /** |
| 11284 | * <p>Compute the horizontal offset of the horizontal scrollbar's thumb |
| 11285 | * within the horizontal range. This value is used to compute the position |
| 11286 | * of the thumb within the scrollbar's track.</p> |
| 11287 | * |
| 11288 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11289 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11290 | * {@link #computeHorizontalScrollExtent()}.</p> |
| 11291 | * |
| 11292 | * <p>The default offset is the scroll offset of this view.</p> |
| 11293 | * |
| 11294 | * @return the horizontal offset of the scrollbar's thumb |
| 11295 | * |
| 11296 | * @see #computeHorizontalScrollRange() |
| 11297 | * @see #computeHorizontalScrollExtent() |
| 11298 | * @see android.widget.ScrollBarDrawable |
| 11299 | */ |
| 11300 | protected int computeHorizontalScrollOffset() { |
| 11301 | return mScrollX; |
| 11302 | } |
| 11303 | |
| 11304 | /** |
| 11305 | * <p>Compute the horizontal extent of the horizontal scrollbar's thumb |
| 11306 | * within the horizontal range. This value is used to compute the length |
| 11307 | * of the thumb within the scrollbar's track.</p> |
| 11308 | * |
| 11309 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11310 | * units used by {@link #computeHorizontalScrollRange()} and |
| 11311 | * {@link #computeHorizontalScrollOffset()}.</p> |
| 11312 | * |
| 11313 | * <p>The default extent is the drawing width of this view.</p> |
| 11314 | * |
| 11315 | * @return the horizontal extent of the scrollbar's thumb |
| 11316 | * |
| 11317 | * @see #computeHorizontalScrollRange() |
| 11318 | * @see #computeHorizontalScrollOffset() |
| 11319 | * @see android.widget.ScrollBarDrawable |
| 11320 | */ |
| 11321 | protected int computeHorizontalScrollExtent() { |
| 11322 | return getWidth(); |
| 11323 | } |
| 11324 | |
| 11325 | /** |
| 11326 | * <p>Compute the vertical range that the vertical scrollbar represents.</p> |
| 11327 | * |
| 11328 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11329 | * units used by {@link #computeVerticalScrollExtent()} and |
| 11330 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11331 | * |
| 11332 | * @return the total vertical range represented by the vertical scrollbar |
| 11333 | * |
| 11334 | * <p>The default range is the drawing height of this view.</p> |
| 11335 | * |
| 11336 | * @see #computeVerticalScrollExtent() |
| 11337 | * @see #computeVerticalScrollOffset() |
| 11338 | * @see android.widget.ScrollBarDrawable |
| 11339 | */ |
| 11340 | protected int computeVerticalScrollRange() { |
| 11341 | return getHeight(); |
| 11342 | } |
| 11343 | |
| 11344 | /** |
| 11345 | * <p>Compute the vertical offset of the vertical scrollbar's thumb |
| 11346 | * within the horizontal range. This value is used to compute the position |
| 11347 | * of the thumb within the scrollbar's track.</p> |
| 11348 | * |
| 11349 | * <p>The range is expressed in arbitrary units that must be the same as the |
| 11350 | * units used by {@link #computeVerticalScrollRange()} and |
| 11351 | * {@link #computeVerticalScrollExtent()}.</p> |
| 11352 | * |
| 11353 | * <p>The default offset is the scroll offset of this view.</p> |
| 11354 | * |
| 11355 | * @return the vertical offset of the scrollbar's thumb |
| 11356 | * |
| 11357 | * @see #computeVerticalScrollRange() |
| 11358 | * @see #computeVerticalScrollExtent() |
| 11359 | * @see android.widget.ScrollBarDrawable |
| 11360 | */ |
| 11361 | protected int computeVerticalScrollOffset() { |
| 11362 | return mScrollY; |
| 11363 | } |
| 11364 | |
| 11365 | /** |
| 11366 | * <p>Compute the vertical extent of the horizontal scrollbar's thumb |
| 11367 | * within the vertical range. This value is used to compute the length |
| 11368 | * of the thumb within the scrollbar's track.</p> |
| 11369 | * |
| 11370 | * <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] | 11371 | * units used by {@link #computeVerticalScrollRange()} and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11372 | * {@link #computeVerticalScrollOffset()}.</p> |
| 11373 | * |
| 11374 | * <p>The default extent is the drawing height of this view.</p> |
| 11375 | * |
| 11376 | * @return the vertical extent of the scrollbar's thumb |
| 11377 | * |
| 11378 | * @see #computeVerticalScrollRange() |
| 11379 | * @see #computeVerticalScrollOffset() |
| 11380 | * @see android.widget.ScrollBarDrawable |
| 11381 | */ |
| 11382 | protected int computeVerticalScrollExtent() { |
| 11383 | return getHeight(); |
| 11384 | } |
| 11385 | |
| 11386 | /** |
Adam Powell | 6915944 | 2011-06-13 17:53:06 -0700 | [diff] [blame] | 11387 | * Check if this view can be scrolled horizontally in a certain direction. |
| 11388 | * |
| 11389 | * @param direction Negative to check scrolling left, positive to check scrolling right. |
| 11390 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11391 | */ |
| 11392 | public boolean canScrollHorizontally(int direction) { |
| 11393 | final int offset = computeHorizontalScrollOffset(); |
| 11394 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent(); |
| 11395 | if (range == 0) return false; |
| 11396 | if (direction < 0) { |
| 11397 | return offset > 0; |
| 11398 | } else { |
| 11399 | return offset < range - 1; |
| 11400 | } |
| 11401 | } |
| 11402 | |
| 11403 | /** |
| 11404 | * Check if this view can be scrolled vertically in a certain direction. |
| 11405 | * |
| 11406 | * @param direction Negative to check scrolling up, positive to check scrolling down. |
| 11407 | * @return true if this view can be scrolled in the specified direction, false otherwise. |
| 11408 | */ |
| 11409 | public boolean canScrollVertically(int direction) { |
| 11410 | final int offset = computeVerticalScrollOffset(); |
| 11411 | final int range = computeVerticalScrollRange() - computeVerticalScrollExtent(); |
| 11412 | if (range == 0) return false; |
| 11413 | if (direction < 0) { |
| 11414 | return offset > 0; |
| 11415 | } else { |
| 11416 | return offset < range - 1; |
| 11417 | } |
| 11418 | } |
| 11419 | |
| 11420 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11421 | * <p>Request the drawing of the horizontal and the vertical scrollbar. The |
| 11422 | * scrollbars are painted only if they have been awakened first.</p> |
| 11423 | * |
| 11424 | * @param canvas the canvas on which to draw the scrollbars |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11425 | * |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11426 | * @see #awakenScrollBars(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11427 | */ |
Romain Guy | 1d5b3a6 | 2009-11-05 18:44:12 -0800 | [diff] [blame] | 11428 | protected final void onDrawScrollBars(Canvas canvas) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11429 | // scrollbars are drawn only when the animation is running |
| 11430 | final ScrollabilityCache cache = mScrollCache; |
| 11431 | if (cache != null) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11432 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11433 | int state = cache.state; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11434 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11435 | if (state == ScrollabilityCache.OFF) { |
| 11436 | return; |
| 11437 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11438 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11439 | boolean invalidate = false; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11440 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11441 | if (state == ScrollabilityCache.FADING) { |
| 11442 | // We're fading -- get our fade interpolation |
| 11443 | if (cache.interpolatorValues == null) { |
| 11444 | cache.interpolatorValues = new float[1]; |
| 11445 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11446 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11447 | float[] values = cache.interpolatorValues; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11448 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11449 | // Stops the animation if we're done |
| 11450 | if (cache.scrollBarInterpolator.timeToValues(values) == |
| 11451 | Interpolator.Result.FREEZE_END) { |
| 11452 | cache.state = ScrollabilityCache.OFF; |
| 11453 | } else { |
| 11454 | cache.scrollBar.setAlpha(Math.round(values[0])); |
| 11455 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11456 | |
| 11457 | // This will make the scroll bars inval themselves after |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11458 | // drawing. We only want this when we're fading so that |
| 11459 | // we prevent excessive redraws |
| 11460 | invalidate = true; |
| 11461 | } else { |
| 11462 | // We're just on -- but we may have been fading before so |
| 11463 | // reset alpha |
| 11464 | cache.scrollBar.setAlpha(255); |
| 11465 | } |
| 11466 | |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11468 | final int viewFlags = mViewFlags; |
| 11469 | |
| 11470 | final boolean drawHorizontalScrollBar = |
| 11471 | (viewFlags & SCROLLBARS_HORIZONTAL) == SCROLLBARS_HORIZONTAL; |
| 11472 | final boolean drawVerticalScrollBar = |
| 11473 | (viewFlags & SCROLLBARS_VERTICAL) == SCROLLBARS_VERTICAL |
| 11474 | && !isVerticalScrollBarHidden(); |
| 11475 | |
| 11476 | if (drawVerticalScrollBar || drawHorizontalScrollBar) { |
| 11477 | final int width = mRight - mLeft; |
| 11478 | final int height = mBottom - mTop; |
| 11479 | |
| 11480 | final ScrollBarDrawable scrollBar = cache.scrollBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11481 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11482 | final int scrollX = mScrollX; |
| 11483 | final int scrollY = mScrollY; |
| 11484 | final int inside = (viewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0; |
| 11485 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11486 | int left, top, right, bottom; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11488 | if (drawHorizontalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11489 | int size = scrollBar.getSize(false); |
| 11490 | if (size <= 0) { |
| 11491 | size = cache.scrollBarSize; |
| 11492 | } |
| 11493 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11494 | scrollBar.setParameters(computeHorizontalScrollRange(), |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11495 | computeHorizontalScrollOffset(), |
| 11496 | computeHorizontalScrollExtent(), false); |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11497 | final int verticalScrollBarGap = drawVerticalScrollBar ? |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11498 | getVerticalScrollbarWidth() : 0; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 11499 | top = scrollY + height - size - (mUserPaddingBottom & inside); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11500 | left = scrollX + (mPaddingLeft & inside); |
| 11501 | right = scrollX + width - (mUserPaddingRight & inside) - verticalScrollBarGap; |
| 11502 | bottom = top + size; |
| 11503 | onDrawHorizontalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11504 | if (invalidate) { |
| 11505 | invalidate(left, top, right, bottom); |
| 11506 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11507 | } |
| 11508 | |
| 11509 | if (drawVerticalScrollBar) { |
Adam Powell | 3ba6774 | 2011-01-27 14:16:55 -0800 | [diff] [blame] | 11510 | int size = scrollBar.getSize(true); |
| 11511 | if (size <= 0) { |
| 11512 | size = cache.scrollBarSize; |
| 11513 | } |
| 11514 | |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11515 | scrollBar.setParameters(computeVerticalScrollRange(), |
| 11516 | computeVerticalScrollOffset(), |
| 11517 | computeVerticalScrollExtent(), true); |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 11518 | int verticalScrollbarPosition = mVerticalScrollbarPosition; |
| 11519 | if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) { |
| 11520 | verticalScrollbarPosition = isLayoutRtl() ? |
| 11521 | SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT; |
| 11522 | } |
| 11523 | switch (verticalScrollbarPosition) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11524 | default: |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 11525 | case SCROLLBAR_POSITION_RIGHT: |
| 11526 | left = scrollX + width - size - (mUserPaddingRight & inside); |
| 11527 | break; |
| 11528 | case SCROLLBAR_POSITION_LEFT: |
| 11529 | left = scrollX + (mUserPaddingLeft & inside); |
| 11530 | break; |
| 11531 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11532 | top = scrollY + (mPaddingTop & inside); |
| 11533 | right = left + size; |
| 11534 | bottom = scrollY + height - (mUserPaddingBottom & inside); |
| 11535 | onDrawVerticalScrollBar(canvas, scrollBar, left, top, right, bottom); |
| 11536 | if (invalidate) { |
| 11537 | invalidate(left, top, right, bottom); |
| 11538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11539 | } |
| 11540 | } |
| 11541 | } |
| 11542 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11544 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 11545 | * 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] | 11546 | * FastScroller is visible. |
| 11547 | * @return whether to temporarily hide the vertical scrollbar |
| 11548 | * @hide |
| 11549 | */ |
| 11550 | protected boolean isVerticalScrollBarHidden() { |
| 11551 | return false; |
| 11552 | } |
| 11553 | |
| 11554 | /** |
| 11555 | * <p>Draw the horizontal scrollbar if |
| 11556 | * {@link #isHorizontalScrollBarEnabled()} returns true.</p> |
| 11557 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11558 | * @param canvas the canvas on which to draw the scrollbar |
| 11559 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11560 | * |
| 11561 | * @see #isHorizontalScrollBarEnabled() |
| 11562 | * @see #computeHorizontalScrollRange() |
| 11563 | * @see #computeHorizontalScrollExtent() |
| 11564 | * @see #computeHorizontalScrollOffset() |
| 11565 | * @see android.widget.ScrollBarDrawable |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 11566 | * @hide |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11567 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11568 | protected void onDrawHorizontalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11569 | int l, int t, int r, int b) { |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11570 | scrollBar.setBounds(l, t, r, b); |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11571 | scrollBar.draw(canvas); |
| 11572 | } |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11573 | |
Mike Reed | 4d6fe5f | 2009-09-03 13:29:05 -0400 | [diff] [blame] | 11574 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11575 | * <p>Draw the vertical scrollbar if {@link #isVerticalScrollBarEnabled()} |
| 11576 | * returns true.</p> |
| 11577 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11578 | * @param canvas the canvas on which to draw the scrollbar |
| 11579 | * @param scrollBar the scrollbar's drawable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11580 | * |
| 11581 | * @see #isVerticalScrollBarEnabled() |
| 11582 | * @see #computeVerticalScrollRange() |
| 11583 | * @see #computeVerticalScrollExtent() |
| 11584 | * @see #computeVerticalScrollOffset() |
| 11585 | * @see android.widget.ScrollBarDrawable |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11586 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11587 | */ |
Romain Guy | 8fb9542 | 2010-08-17 18:38:51 -0700 | [diff] [blame] | 11588 | protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, |
| 11589 | int l, int t, int r, int b) { |
Mike Reed | e8853fc | 2009-09-04 14:01:48 -0400 | [diff] [blame] | 11590 | scrollBar.setBounds(l, t, r, b); |
| 11591 | scrollBar.draw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11592 | } |
| 11593 | |
| 11594 | /** |
| 11595 | * Implement this to do your drawing. |
| 11596 | * |
| 11597 | * @param canvas the canvas on which the background will be drawn |
| 11598 | */ |
| 11599 | protected void onDraw(Canvas canvas) { |
| 11600 | } |
| 11601 | |
| 11602 | /* |
| 11603 | * Caller is responsible for calling requestLayout if necessary. |
| 11604 | * (This allows addViewInLayout to not request a new layout.) |
| 11605 | */ |
| 11606 | void assignParent(ViewParent parent) { |
| 11607 | if (mParent == null) { |
| 11608 | mParent = parent; |
| 11609 | } else if (parent == null) { |
| 11610 | mParent = null; |
| 11611 | } else { |
| 11612 | throw new RuntimeException("view " + this + " being added, but" |
| 11613 | + " it already has a parent"); |
| 11614 | } |
| 11615 | } |
| 11616 | |
| 11617 | /** |
| 11618 | * This is called when the view is attached to a window. At this point it |
| 11619 | * has a Surface and will start drawing. Note that this function is |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 11620 | * guaranteed to be called before {@link #onDraw(android.graphics.Canvas)}, |
| 11621 | * however it may be called any time before the first onDraw -- including |
| 11622 | * before or after {@link #onMeasure(int, int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11623 | * |
| 11624 | * @see #onDetachedFromWindow() |
| 11625 | */ |
| 11626 | protected void onAttachedToWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11627 | if ((mPrivateFlags & PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11628 | mParent.requestTransparentRegion(this); |
| 11629 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11630 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11631 | if ((mPrivateFlags & PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) { |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11632 | initialAwakenScrollBars(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11633 | mPrivateFlags &= ~PFLAG_AWAKEN_SCROLL_BARS_ON_ATTACH; |
Adam Powell | 8568c3a | 2010-04-19 14:26:11 -0700 | [diff] [blame] | 11634 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11635 | |
Chet Haase | a9b61ac | 2010-12-20 07:40:25 -0800 | [diff] [blame] | 11636 | jumpDrawablesToCurrentState(); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11637 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11638 | clearAccessibilityFocus(); |
Amith Yamasani | 4503c8d | 2011-06-17 12:36:14 -0700 | [diff] [blame] | 11639 | if (isFocused()) { |
| 11640 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 11641 | imm.focusIn(this); |
| 11642 | } |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11643 | |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 11644 | if (mDisplayList != null) { |
| 11645 | mDisplayList.setDirty(false); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11646 | } |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11647 | } |
Cibu Johny | 8666663 | 2010-02-22 13:01:02 -0800 | [diff] [blame] | 11648 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11649 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11650 | * Resolve all RTL related properties. |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11651 | * |
| 11652 | * @hide |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11653 | */ |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11654 | public void resolveRtlPropertiesIfNeeded() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11655 | if (!needRtlPropertiesResolution()) return; |
| 11656 | |
| 11657 | // Order is important here: LayoutDirection MUST be resolved first |
| 11658 | if (!isLayoutDirectionResolved()) { |
| 11659 | resolveLayoutDirection(); |
| 11660 | resolveLayoutParams(); |
| 11661 | } |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11662 | // ... then we can resolve the others properties depending on the resolved LayoutDirection. |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11663 | if (!isTextDirectionResolved()) { |
| 11664 | resolveTextDirection(); |
| 11665 | } |
| 11666 | if (!isTextAlignmentResolved()) { |
| 11667 | resolveTextAlignment(); |
| 11668 | } |
| 11669 | if (!isPaddingResolved()) { |
| 11670 | resolvePadding(); |
| 11671 | } |
| 11672 | if (!isDrawablesResolved()) { |
| 11673 | resolveDrawables(); |
| 11674 | } |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11675 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11676 | } |
| 11677 | |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 11678 | /** |
| 11679 | * Reset resolution of all RTL related properties. |
| 11680 | * |
| 11681 | * @hide |
| 11682 | */ |
| 11683 | public void resetRtlProperties() { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11684 | resetResolvedLayoutDirection(); |
| 11685 | resetResolvedTextDirection(); |
| 11686 | resetResolvedTextAlignment(); |
| 11687 | resetResolvedPadding(); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11688 | resetResolvedDrawables(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11689 | } |
| 11690 | |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11691 | /** |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 11692 | * @see #onScreenStateChanged(int) |
| 11693 | */ |
| 11694 | void dispatchScreenStateChanged(int screenState) { |
| 11695 | onScreenStateChanged(screenState); |
| 11696 | } |
| 11697 | |
| 11698 | /** |
| 11699 | * This method is called whenever the state of the screen this view is |
| 11700 | * attached to changes. A state change will usually occurs when the screen |
| 11701 | * turns on or off (whether it happens automatically or the user does it |
| 11702 | * manually.) |
| 11703 | * |
| 11704 | * @param screenState The new state of the screen. Can be either |
| 11705 | * {@link #SCREEN_STATE_ON} or {@link #SCREEN_STATE_OFF} |
| 11706 | */ |
| 11707 | public void onScreenStateChanged(int screenState) { |
| 11708 | } |
| 11709 | |
| 11710 | /** |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11711 | * Return true if the application tag in the AndroidManifest has set "supportRtl" to true |
| 11712 | */ |
| 11713 | private boolean hasRtlSupport() { |
| 11714 | return mContext.getApplicationInfo().hasRtlSupport(); |
| 11715 | } |
| 11716 | |
| 11717 | /** |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11718 | * Return true if we are in RTL compatibility mode (either before Jelly Bean MR1 or |
| 11719 | * RTL not supported) |
| 11720 | */ |
| 11721 | private boolean isRtlCompatibilityMode() { |
| 11722 | final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; |
| 11723 | return targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport(); |
| 11724 | } |
| 11725 | |
| 11726 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11727 | * @return true if RTL properties need resolution. |
| 11728 | */ |
| 11729 | private boolean needRtlPropertiesResolution() { |
| 11730 | return (mPrivateFlags2 & ALL_RTL_PROPERTIES_RESOLVED) != ALL_RTL_PROPERTIES_RESOLVED; |
| 11731 | } |
| 11732 | |
| 11733 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11734 | * Called when any RTL property (layout direction or text direction or text alignment) has |
| 11735 | * been changed. |
| 11736 | * |
| 11737 | * Subclasses need to override this method to take care of cached information that depends on the |
| 11738 | * resolved layout direction, or to inform child views that inherit their layout direction. |
| 11739 | * |
| 11740 | * The default implementation does nothing. |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11741 | * |
| 11742 | * @param layoutDirection the direction of the layout |
| 11743 | * |
| 11744 | * @see #LAYOUT_DIRECTION_LTR |
| 11745 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11746 | */ |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11747 | public void onRtlPropertiesChanged(int layoutDirection) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11748 | } |
| 11749 | |
| 11750 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11751 | * Resolve and cache the layout direction. LTR is set initially. This is implicitly supposing |
| 11752 | * that the parent directionality can and will be resolved before its children. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11753 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11754 | * @return true if resolution has been done, false otherwise. |
| 11755 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11756 | * @hide |
Fabrice Di Meglio | 4f5aa91 | 2011-05-31 15:20:50 -0700 | [diff] [blame] | 11757 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11758 | public boolean resolveLayoutDirection() { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11759 | // Clear any previous layout direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11760 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11761 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11762 | if (hasRtlSupport()) { |
| 11763 | // Set resolved depending on layout direction |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11764 | switch ((mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> |
| 11765 | PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11766 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11767 | // We cannot resolve yet. LTR is by default and let the resolution happen again |
| 11768 | // later to get the correct resolved value |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11769 | if (!canResolveLayoutDirection()) return false; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11770 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11771 | View parent = ((View) mParent); |
| 11772 | // Parent has not yet resolved, LTR is still the default |
| 11773 | if (!parent.isLayoutDirectionResolved()) return false; |
Fabrice Di Meglio | b93911f | 2012-06-26 19:43:15 -0700 | [diff] [blame] | 11774 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11775 | if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11776 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11777 | } |
| 11778 | break; |
| 11779 | case LAYOUT_DIRECTION_RTL: |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11780 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11781 | break; |
| 11782 | case LAYOUT_DIRECTION_LOCALE: |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11783 | if((LAYOUT_DIRECTION_RTL == |
| 11784 | TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()))) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11785 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL; |
Fabrice Di Meglio | fe7e40d | 2011-07-13 12:47:36 -0700 | [diff] [blame] | 11786 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11787 | break; |
| 11788 | default: |
Fabrice Di Meglio | 22ab775 | 2012-03-23 16:39:26 -0700 | [diff] [blame] | 11789 | // Nothing to do, LTR by default |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 11790 | } |
Fabrice Di Meglio | 26e432d | 2011-06-10 14:19:18 -0700 | [diff] [blame] | 11791 | } |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11792 | |
| 11793 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11794 | mPrivateFlags2 |= PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11795 | return true; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11796 | } |
| 11797 | |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11798 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11799 | * Check if layout direction resolution can be done. |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11800 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11801 | * @return true if layout direction resolution can be done otherwise return false. |
| 11802 | * |
| 11803 | * @hide |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11804 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11805 | public boolean canResolveLayoutDirection() { |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11806 | switch (getRawLayoutDirection()) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11807 | case LAYOUT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 11808 | return (mParent != null) && (mParent instanceof ViewGroup) && |
| 11809 | ((ViewGroup) mParent).canResolveLayoutDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11810 | default: |
| 11811 | return true; |
| 11812 | } |
| 11813 | } |
| 11814 | |
| 11815 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11816 | * Reset the resolved layout direction. Layout direction will be resolved during a call to |
| 11817 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11818 | * |
| 11819 | * @hide |
| 11820 | */ |
| 11821 | public void resetResolvedLayoutDirection() { |
| 11822 | // Reset the current resolved bits |
| 11823 | mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK; |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11824 | } |
| 11825 | |
| 11826 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11827 | * @return true if the layout direction is inherited. |
| 11828 | * |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11829 | * @hide |
| 11830 | */ |
| 11831 | public boolean isLayoutDirectionInherited() { |
| 11832 | return (getRawLayoutDirection() == LAYOUT_DIRECTION_INHERIT); |
| 11833 | } |
| 11834 | |
| 11835 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11836 | * @return true if layout direction has been resolved. |
| 11837 | */ |
| 11838 | private boolean isLayoutDirectionResolved() { |
| 11839 | return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_RESOLVED) == PFLAG2_LAYOUT_DIRECTION_RESOLVED; |
| 11840 | } |
| 11841 | |
| 11842 | /** |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11843 | * Return if padding has been resolved |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11844 | * |
| 11845 | * @hide |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11846 | */ |
| 11847 | boolean isPaddingResolved() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 11848 | return (mPrivateFlags2 & PFLAG2_PADDING_RESOLVED) == PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11849 | } |
| 11850 | |
| 11851 | /** |
Fabrice Di Meglio | dd3ef2c | 2012-03-01 16:37:17 -0800 | [diff] [blame] | 11852 | * Resolve padding depending on layout direction. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11853 | * |
| 11854 | * @hide |
Fabrice Di Meglio | aff599b | 2011-07-20 19:05:01 -0700 | [diff] [blame] | 11855 | */ |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11856 | public void resolvePadding() { |
Fabrice Di Meglio | bbd1029 | 2012-09-27 14:08:49 -0700 | [diff] [blame] | 11857 | if (!isRtlCompatibilityMode()) { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11858 | // Post Jelly Bean MR1 case: we need to take the resolved layout direction into account. |
| 11859 | // If start / end padding are defined, they will be resolved (hence overriding) to |
| 11860 | // left / right or right / left depending on the resolved layout direction. |
| 11861 | // If start / end padding are not defined, use the left / right ones. |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 11862 | int resolvedLayoutDirection = getLayoutDirection(); |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11863 | // Set user padding to initial values ... |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 11864 | mUserPaddingLeft = mUserPaddingLeftInitial; |
| 11865 | mUserPaddingRight = mUserPaddingRightInitial; |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 11866 | // ... then resolve it. |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 11867 | switch (resolvedLayoutDirection) { |
| 11868 | case LAYOUT_DIRECTION_RTL: |
| 11869 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11870 | mUserPaddingRight = mUserPaddingStart; |
| 11871 | } |
| 11872 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11873 | mUserPaddingLeft = mUserPaddingEnd; |
| 11874 | } |
| 11875 | break; |
| 11876 | case LAYOUT_DIRECTION_LTR: |
| 11877 | default: |
| 11878 | if (mUserPaddingStart != UNDEFINED_PADDING) { |
| 11879 | mUserPaddingLeft = mUserPaddingStart; |
| 11880 | } |
| 11881 | if (mUserPaddingEnd != UNDEFINED_PADDING) { |
| 11882 | mUserPaddingRight = mUserPaddingEnd; |
| 11883 | } |
| 11884 | } |
| 11885 | |
| 11886 | mUserPaddingBottom = (mUserPaddingBottom >= 0) ? mUserPaddingBottom : mPaddingBottom; |
| 11887 | |
| 11888 | internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, |
| 11889 | mUserPaddingBottom); |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 11890 | onRtlPropertiesChanged(resolvedLayoutDirection); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 11891 | } |
| 11892 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11893 | mPrivateFlags2 |= PFLAG2_PADDING_RESOLVED; |
Fabrice Di Meglio | ccb1562 | 2012-02-15 15:52:19 -0800 | [diff] [blame] | 11894 | } |
| 11895 | |
| 11896 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 11897 | * Reset the resolved layout direction. |
| 11898 | * |
| 11899 | * @hide |
| 11900 | */ |
| 11901 | public void resetResolvedPadding() { |
| 11902 | mPrivateFlags2 &= ~PFLAG2_PADDING_RESOLVED; |
| 11903 | } |
| 11904 | |
| 11905 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11906 | * This is called when the view is detached from a window. At this point it |
| 11907 | * no longer has a surface for drawing. |
| 11908 | * |
| 11909 | * @see #onAttachedToWindow() |
| 11910 | */ |
| 11911 | protected void onDetachedFromWindow() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 11912 | mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11913 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 11914 | removeUnsetPressCallback(); |
Maryam Garrett | 1549dd1 | 2009-12-15 16:06:36 -0500 | [diff] [blame] | 11915 | removeLongPressCallback(); |
Adam Powell | 3cb8b63 | 2011-01-21 15:34:14 -0800 | [diff] [blame] | 11916 | removePerformClickCallback(); |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 11917 | removeSendViewScrolledAccessibilityEventCallback(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11919 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 11920 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 11921 | destroyLayer(false); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11922 | |
| 11923 | if (mAttachInfo != null) { |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11924 | if (mDisplayList != null) { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 11925 | mDisplayList.setDirty(true); |
Romain Guy | 2a0f228 | 2012-05-08 14:43:12 -0700 | [diff] [blame] | 11926 | mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11927 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 11928 | mAttachInfo.mViewRootImpl.cancelInvalidate(this); |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 11929 | } else { |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 11930 | // Should never happen |
| 11931 | clearDisplayList(); |
Romain Guy | 8dd5b1e | 2011-01-14 17:28:51 -0800 | [diff] [blame] | 11932 | } |
| 11933 | |
Patrick Dubroy | ec84c3a | 2011-01-13 17:55:37 -0800 | [diff] [blame] | 11934 | mCurrentAnimation = null; |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 11935 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 11936 | resetAccessibilityStateChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11937 | } |
| 11938 | |
| 11939 | /** |
| 11940 | * @return The number of times this view has been attached to a window |
| 11941 | */ |
| 11942 | protected int getWindowAttachCount() { |
| 11943 | return mWindowAttachCount; |
| 11944 | } |
| 11945 | |
| 11946 | /** |
| 11947 | * Retrieve a unique token identifying the window this view is attached to. |
| 11948 | * @return Return the window's token for use in |
| 11949 | * {@link WindowManager.LayoutParams#token WindowManager.LayoutParams.token}. |
| 11950 | */ |
| 11951 | public IBinder getWindowToken() { |
| 11952 | return mAttachInfo != null ? mAttachInfo.mWindowToken : null; |
| 11953 | } |
| 11954 | |
| 11955 | /** |
| 11956 | * Retrieve a unique token identifying the top-level "real" window of |
| 11957 | * the window that this view is attached to. That is, this is like |
| 11958 | * {@link #getWindowToken}, except if the window this view in is a panel |
| 11959 | * window (attached to another containing window), then the token of |
| 11960 | * the containing window is returned instead. |
| 11961 | * |
| 11962 | * @return Returns the associated window token, either |
| 11963 | * {@link #getWindowToken()} or the containing window's token. |
| 11964 | */ |
| 11965 | public IBinder getApplicationWindowToken() { |
| 11966 | AttachInfo ai = mAttachInfo; |
| 11967 | if (ai != null) { |
| 11968 | IBinder appWindowToken = ai.mPanelParentWindowToken; |
| 11969 | if (appWindowToken == null) { |
| 11970 | appWindowToken = ai.mWindowToken; |
| 11971 | } |
| 11972 | return appWindowToken; |
| 11973 | } |
| 11974 | return null; |
| 11975 | } |
| 11976 | |
| 11977 | /** |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 11978 | * Gets the logical display to which the view's window has been attached. |
| 11979 | * |
| 11980 | * @return The logical display, or null if the view is not currently attached to a window. |
| 11981 | */ |
| 11982 | public Display getDisplay() { |
| 11983 | return mAttachInfo != null ? mAttachInfo.mDisplay : null; |
| 11984 | } |
| 11985 | |
| 11986 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11987 | * Retrieve private session object this view hierarchy is using to |
| 11988 | * communicate with the window manager. |
| 11989 | * @return the session object to communicate with the window manager |
| 11990 | */ |
| 11991 | /*package*/ IWindowSession getWindowSession() { |
| 11992 | return mAttachInfo != null ? mAttachInfo.mSession : null; |
| 11993 | } |
| 11994 | |
| 11995 | /** |
| 11996 | * @param info the {@link android.view.View.AttachInfo} to associated with |
| 11997 | * this view |
| 11998 | */ |
| 11999 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
| 12000 | //System.out.println("Attached! " + this); |
| 12001 | mAttachInfo = info; |
| 12002 | mWindowAttachCount++; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 12003 | // We will need to evaluate the drawable state at least once. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12004 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12005 | if (mFloatingTreeObserver != null) { |
| 12006 | info.mTreeObserver.merge(mFloatingTreeObserver); |
| 12007 | mFloatingTreeObserver = null; |
| 12008 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12009 | if ((mPrivateFlags&PFLAG_SCROLL_CONTAINER) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12010 | mAttachInfo.mScrollContainers.add(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12011 | mPrivateFlags |= PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12012 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 12013 | performCollectViewAttributes(mAttachInfo, visibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12014 | onAttachedToWindow(); |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 12015 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12016 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 12017 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12018 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 12019 | if (listeners != null && listeners.size() > 0) { |
| 12020 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 12021 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 12022 | // could mutate the list by calling the various add/remove methods. This prevents |
| 12023 | // the array from being modified while we iterate it. |
| 12024 | for (OnAttachStateChangeListener listener : listeners) { |
| 12025 | listener.onViewAttachedToWindow(this); |
| 12026 | } |
| 12027 | } |
| 12028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12029 | int vis = info.mWindowVisibility; |
| 12030 | if (vis != GONE) { |
| 12031 | onWindowVisibilityChanged(vis); |
| 12032 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12033 | if ((mPrivateFlags&PFLAG_DRAWABLE_STATE_DIRTY) != 0) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 12034 | // If nobody has evaluated the drawable state yet, then do it now. |
| 12035 | refreshDrawableState(); |
| 12036 | } |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 12037 | needGlobalAttributesUpdate(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12038 | } |
| 12039 | |
| 12040 | void dispatchDetachedFromWindow() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12041 | AttachInfo info = mAttachInfo; |
| 12042 | if (info != null) { |
| 12043 | int vis = info.mWindowVisibility; |
| 12044 | if (vis != GONE) { |
| 12045 | onWindowVisibilityChanged(GONE); |
| 12046 | } |
| 12047 | } |
| 12048 | |
| 12049 | onDetachedFromWindow(); |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 12050 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12051 | ListenerInfo li = mListenerInfo; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 12052 | final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 12053 | li != null ? li.mOnAttachStateChangeListeners : null; |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 12054 | if (listeners != null && listeners.size() > 0) { |
| 12055 | // NOTE: because of the use of CopyOnWriteArrayList, we *must* use an iterator to |
| 12056 | // perform the dispatching. The iterator is a safe guard against listeners that |
| 12057 | // could mutate the list by calling the various add/remove methods. This prevents |
| 12058 | // the array from being modified while we iterate it. |
| 12059 | for (OnAttachStateChangeListener listener : listeners) { |
| 12060 | listener.onViewDetachedFromWindow(this); |
| 12061 | } |
| 12062 | } |
| 12063 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12064 | if ((mPrivateFlags & PFLAG_SCROLL_CONTAINER_ADDED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12065 | mAttachInfo.mScrollContainers.remove(this); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12066 | mPrivateFlags &= ~PFLAG_SCROLL_CONTAINER_ADDED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12067 | } |
Romain Guy | 01d5edc | 2011-01-28 11:28:53 -0800 | [diff] [blame] | 12068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12069 | mAttachInfo = null; |
| 12070 | } |
| 12071 | |
| 12072 | /** |
| 12073 | * Store this view hierarchy's frozen state into the given container. |
| 12074 | * |
| 12075 | * @param container The SparseArray in which to save the view's state. |
| 12076 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12077 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12078 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 12079 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12080 | */ |
| 12081 | public void saveHierarchyState(SparseArray<Parcelable> container) { |
| 12082 | dispatchSaveInstanceState(container); |
| 12083 | } |
| 12084 | |
| 12085 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12086 | * Called by {@link #saveHierarchyState(android.util.SparseArray)} to store the state for |
| 12087 | * this view and its children. May be overridden to modify how freezing happens to a |
| 12088 | * 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] | 12089 | * |
| 12090 | * @param container The SparseArray in which to save the view's state. |
| 12091 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12092 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 12093 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12094 | * @see #onSaveInstanceState() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12095 | */ |
| 12096 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 12097 | if (mID != NO_ID && (mViewFlags & SAVE_DISABLED_MASK) == 0) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12098 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12099 | Parcelable state = onSaveInstanceState(); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12100 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12101 | throw new IllegalStateException( |
| 12102 | "Derived class did not call super.onSaveInstanceState()"); |
| 12103 | } |
| 12104 | if (state != null) { |
| 12105 | // Log.i("View", "Freezing #" + Integer.toHexString(mID) |
| 12106 | // + ": " + state); |
| 12107 | container.put(mID, state); |
| 12108 | } |
| 12109 | } |
| 12110 | } |
| 12111 | |
| 12112 | /** |
| 12113 | * Hook allowing a view to generate a representation of its internal state |
| 12114 | * that can later be used to create a new instance with that same state. |
| 12115 | * This state should only contain information that is not persistent or can |
| 12116 | * not be reconstructed later. For example, you will never store your |
| 12117 | * current position on screen because that will be computed again when a |
| 12118 | * new instance of the view is placed in its view hierarchy. |
| 12119 | * <p> |
| 12120 | * Some examples of things you may store here: the current cursor position |
| 12121 | * in a text view (but usually not the text itself since that is stored in a |
| 12122 | * content provider or other persistent storage), the currently selected |
| 12123 | * item in a list view. |
| 12124 | * |
| 12125 | * @return Returns a Parcelable object containing the view's current dynamic |
| 12126 | * state, or null if there is nothing interesting to save. The |
| 12127 | * default implementation returns null. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12128 | * @see #onRestoreInstanceState(android.os.Parcelable) |
| 12129 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12130 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12131 | * @see #setSaveEnabled(boolean) |
| 12132 | */ |
| 12133 | protected Parcelable onSaveInstanceState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12134 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12135 | return BaseSavedState.EMPTY_STATE; |
| 12136 | } |
| 12137 | |
| 12138 | /** |
| 12139 | * Restore this view hierarchy's frozen state from the given container. |
| 12140 | * |
| 12141 | * @param container The SparseArray which holds previously frozen states. |
| 12142 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12143 | * @see #saveHierarchyState(android.util.SparseArray) |
| 12144 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
| 12145 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12146 | */ |
| 12147 | public void restoreHierarchyState(SparseArray<Parcelable> container) { |
| 12148 | dispatchRestoreInstanceState(container); |
| 12149 | } |
| 12150 | |
| 12151 | /** |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 12152 | * Called by {@link #restoreHierarchyState(android.util.SparseArray)} to retrieve the |
| 12153 | * state for this view and its children. May be overridden to modify how restoring |
| 12154 | * happens to a view's children; for example, some views may want to not store state |
| 12155 | * for their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12156 | * |
| 12157 | * @param container The SparseArray which holds previously saved state. |
| 12158 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12159 | * @see #dispatchSaveInstanceState(android.util.SparseArray) |
| 12160 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12161 | * @see #onRestoreInstanceState(android.os.Parcelable) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12162 | */ |
| 12163 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 12164 | if (mID != NO_ID) { |
| 12165 | Parcelable state = container.get(mID); |
| 12166 | if (state != null) { |
| 12167 | // Log.i("View", "Restoreing #" + Integer.toHexString(mID) |
| 12168 | // + ": " + state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12169 | mPrivateFlags &= ~PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12170 | onRestoreInstanceState(state); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12171 | if ((mPrivateFlags & PFLAG_SAVE_STATE_CALLED) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12172 | throw new IllegalStateException( |
| 12173 | "Derived class did not call super.onRestoreInstanceState()"); |
| 12174 | } |
| 12175 | } |
| 12176 | } |
| 12177 | } |
| 12178 | |
| 12179 | /** |
| 12180 | * Hook allowing a view to re-apply a representation of its internal state that had previously |
| 12181 | * been generated by {@link #onSaveInstanceState}. This function will never be called with a |
| 12182 | * null state. |
| 12183 | * |
| 12184 | * @param state The frozen state that had previously been returned by |
| 12185 | * {@link #onSaveInstanceState}. |
| 12186 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12187 | * @see #onSaveInstanceState() |
| 12188 | * @see #restoreHierarchyState(android.util.SparseArray) |
| 12189 | * @see #dispatchRestoreInstanceState(android.util.SparseArray) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12190 | */ |
| 12191 | protected void onRestoreInstanceState(Parcelable state) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12192 | mPrivateFlags |= PFLAG_SAVE_STATE_CALLED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12193 | if (state != BaseSavedState.EMPTY_STATE && state != null) { |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12194 | throw new IllegalArgumentException("Wrong state class, expecting View State but " |
| 12195 | + "received " + state.getClass().toString() + " instead. This usually happens " |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12196 | + "when two views of different type have the same id in the same hierarchy. " |
| 12197 | + "This view's id is " + ViewDebug.resolveId(mContext, getId()) + ". Make sure " |
Romain Guy | 237c1ce | 2009-12-08 11:30:25 -0800 | [diff] [blame] | 12198 | + "other views do not use the same id."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12199 | } |
| 12200 | } |
| 12201 | |
| 12202 | /** |
| 12203 | * <p>Return the time at which the drawing of the view hierarchy started.</p> |
| 12204 | * |
| 12205 | * @return the drawing start time in milliseconds |
| 12206 | */ |
| 12207 | public long getDrawingTime() { |
| 12208 | return mAttachInfo != null ? mAttachInfo.mDrawingTime : 0; |
| 12209 | } |
| 12210 | |
| 12211 | /** |
| 12212 | * <p>Enables or disables the duplication of the parent's state into this view. When |
| 12213 | * duplication is enabled, this view gets its drawable state from its parent rather |
| 12214 | * than from its own internal properties.</p> |
| 12215 | * |
| 12216 | * <p>Note: in the current implementation, setting this property to true after the |
| 12217 | * view was added to a ViewGroup might have no effect at all. This property should |
| 12218 | * always be used from XML or set to true before adding this view to a ViewGroup.</p> |
| 12219 | * |
| 12220 | * <p>Note: if this view's parent addStateFromChildren property is enabled and this |
| 12221 | * property is enabled, an exception will be thrown.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12222 | * |
Gilles Debunne | fb81703 | 2011-01-13 13:52:49 -0800 | [diff] [blame] | 12223 | * <p>Note: if the child view uses and updates additionnal states which are unknown to the |
| 12224 | * 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] | 12225 | * |
| 12226 | * @param enabled True to enable duplication of the parent's drawable state, false |
| 12227 | * to disable it. |
| 12228 | * |
| 12229 | * @see #getDrawableState() |
| 12230 | * @see #isDuplicateParentStateEnabled() |
| 12231 | */ |
| 12232 | public void setDuplicateParentStateEnabled(boolean enabled) { |
| 12233 | setFlags(enabled ? DUPLICATE_PARENT_STATE : 0, DUPLICATE_PARENT_STATE); |
| 12234 | } |
| 12235 | |
| 12236 | /** |
| 12237 | * <p>Indicates whether this duplicates its drawable state from its parent.</p> |
| 12238 | * |
| 12239 | * @return True if this view's drawable state is duplicated from the parent, |
| 12240 | * false otherwise |
| 12241 | * |
| 12242 | * @see #getDrawableState() |
| 12243 | * @see #setDuplicateParentStateEnabled(boolean) |
| 12244 | */ |
| 12245 | public boolean isDuplicateParentStateEnabled() { |
| 12246 | return (mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE; |
| 12247 | } |
| 12248 | |
| 12249 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12250 | * <p>Specifies the type of layer backing this view. The layer can be |
| 12251 | * {@link #LAYER_TYPE_NONE disabled}, {@link #LAYER_TYPE_SOFTWARE software} or |
| 12252 | * {@link #LAYER_TYPE_HARDWARE hardware}.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12253 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12254 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12255 | * instance that controls how the layer is composed on screen. The following |
| 12256 | * properties of the paint are taken into account when composing the layer:</p> |
| 12257 | * <ul> |
| 12258 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12259 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12260 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12261 | * </ul> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12262 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12263 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12264 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12265 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12266 | * equivalent to setting a hardware layer on this view and providing a paint with |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12267 | * the desired alpha value.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12268 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12269 | * <p>Refer to the documentation of {@link #LAYER_TYPE_NONE disabled}, |
| 12270 | * {@link #LAYER_TYPE_SOFTWARE software} and {@link #LAYER_TYPE_HARDWARE hardware} |
| 12271 | * for more information on when and how to use layers.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12272 | * |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12273 | * @param layerType The type of layer to use with this view, must be one of |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12274 | * {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12275 | * {@link #LAYER_TYPE_HARDWARE} |
| 12276 | * @param paint The paint used to compose the layer. This argument is optional |
| 12277 | * and can be null. It is ignored when the layer type is |
| 12278 | * {@link #LAYER_TYPE_NONE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12279 | * |
| 12280 | * @see #getLayerType() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12281 | * @see #LAYER_TYPE_NONE |
| 12282 | * @see #LAYER_TYPE_SOFTWARE |
| 12283 | * @see #LAYER_TYPE_HARDWARE |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12284 | * @see #setAlpha(float) |
| 12285 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12286 | * @attr ref android.R.styleable#View_layerType |
| 12287 | */ |
| 12288 | public void setLayerType(int layerType, Paint paint) { |
| 12289 | if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12290 | 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] | 12291 | + "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE"); |
| 12292 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12293 | |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12294 | if (layerType == mLayerType) { |
| 12295 | if (layerType != LAYER_TYPE_NONE && paint != mLayerPaint) { |
| 12296 | mLayerPaint = paint == null ? new Paint() : paint; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12297 | invalidateParentCaches(); |
| 12298 | invalidate(true); |
Romain Guy | d6cd572 | 2011-01-17 14:42:41 -0800 | [diff] [blame] | 12299 | } |
| 12300 | return; |
| 12301 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12302 | |
| 12303 | // Destroy any previous software drawing cache if needed |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12304 | switch (mLayerType) { |
Chet Haase | 6f33e81 | 2011-05-17 12:42:19 -0700 | [diff] [blame] | 12305 | case LAYER_TYPE_HARDWARE: |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12306 | destroyLayer(false); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12307 | // fall through - non-accelerated views may use software layer mechanism instead |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12308 | case LAYER_TYPE_SOFTWARE: |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12309 | destroyDrawingCache(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12310 | break; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12311 | default: |
| 12312 | break; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12313 | } |
| 12314 | |
| 12315 | mLayerType = layerType; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 12316 | final boolean layerDisabled = mLayerType == LAYER_TYPE_NONE; |
| 12317 | mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint); |
| 12318 | mLocalDirtyRect = layerDisabled ? null : new Rect(); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12319 | |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 12320 | invalidateParentCaches(); |
| 12321 | invalidate(true); |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12322 | } |
| 12323 | |
| 12324 | /** |
Chet Haase | d15ebf2 | 2012-09-05 11:40:29 -0700 | [diff] [blame] | 12325 | * Updates the {@link Paint} object used with the current layer (used only if the current |
| 12326 | * layer type is not set to {@link #LAYER_TYPE_NONE}). Changed properties of the Paint |
| 12327 | * provided to {@link #setLayerType(int, android.graphics.Paint)} will be used the next time |
| 12328 | * the View is redrawn, but {@link #setLayerPaint(android.graphics.Paint)} must be called to |
| 12329 | * ensure that the view gets redrawn immediately. |
| 12330 | * |
| 12331 | * <p>A layer is associated with an optional {@link android.graphics.Paint} |
| 12332 | * instance that controls how the layer is composed on screen. The following |
| 12333 | * properties of the paint are taken into account when composing the layer:</p> |
| 12334 | * <ul> |
| 12335 | * <li>{@link android.graphics.Paint#getAlpha() Translucency (alpha)}</li> |
| 12336 | * <li>{@link android.graphics.Paint#getXfermode() Blending mode}</li> |
| 12337 | * <li>{@link android.graphics.Paint#getColorFilter() Color filter}</li> |
| 12338 | * </ul> |
| 12339 | * |
| 12340 | * <p>If this view has an alpha value set to < 1.0 by calling |
| 12341 | * {@link #setAlpha(float)}, the alpha value of the layer's paint is replaced by |
| 12342 | * this view's alpha value. Calling {@link #setAlpha(float)} is therefore |
| 12343 | * equivalent to setting a hardware layer on this view and providing a paint with |
| 12344 | * the desired alpha value.</p> |
| 12345 | * |
| 12346 | * @param paint The paint used to compose the layer. This argument is optional |
| 12347 | * and can be null. It is ignored when the layer type is |
| 12348 | * {@link #LAYER_TYPE_NONE} |
| 12349 | * |
| 12350 | * @see #setLayerType(int, android.graphics.Paint) |
| 12351 | */ |
| 12352 | public void setLayerPaint(Paint paint) { |
| 12353 | int layerType = getLayerType(); |
| 12354 | if (layerType != LAYER_TYPE_NONE) { |
| 12355 | mLayerPaint = paint == null ? new Paint() : paint; |
| 12356 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12357 | HardwareLayer layer = getHardwareLayer(); |
| 12358 | if (layer != null) { |
| 12359 | layer.setLayerPaint(paint); |
| 12360 | } |
| 12361 | invalidateViewProperty(false, false); |
| 12362 | } else { |
| 12363 | invalidate(); |
| 12364 | } |
| 12365 | } |
| 12366 | } |
| 12367 | |
| 12368 | /** |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12369 | * Indicates whether this view has a static layer. A view with layer type |
| 12370 | * {@link #LAYER_TYPE_NONE} is a static layer. Other types of layers are |
| 12371 | * dynamic. |
| 12372 | */ |
| 12373 | boolean hasStaticLayer() { |
Romain Guy | 2bf68f0 | 2012-03-02 13:37:47 -0800 | [diff] [blame] | 12374 | return true; |
Romain Guy | 59c7f80 | 2011-09-29 17:21:45 -0700 | [diff] [blame] | 12375 | } |
| 12376 | |
| 12377 | /** |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12378 | * Indicates what type of layer is currently associated with this view. By default |
| 12379 | * a view does not have a layer, and the layer type is {@link #LAYER_TYPE_NONE}. |
| 12380 | * Refer to the documentation of {@link #setLayerType(int, android.graphics.Paint)} |
| 12381 | * for more information on the different types of layers. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12382 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12383 | * @return {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or |
| 12384 | * {@link #LAYER_TYPE_HARDWARE} |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12385 | * |
| 12386 | * @see #setLayerType(int, android.graphics.Paint) |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12387 | * @see #buildLayer() |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12388 | * @see #LAYER_TYPE_NONE |
| 12389 | * @see #LAYER_TYPE_SOFTWARE |
| 12390 | * @see #LAYER_TYPE_HARDWARE |
| 12391 | */ |
| 12392 | public int getLayerType() { |
| 12393 | return mLayerType; |
| 12394 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12395 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12396 | /** |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12397 | * Forces this view's layer to be created and this view to be rendered |
| 12398 | * into its layer. If this view's layer type is set to {@link #LAYER_TYPE_NONE}, |
| 12399 | * invoking this method will have no effect. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12400 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12401 | * This method can for instance be used to render a view into its layer before |
| 12402 | * starting an animation. If this view is complex, rendering into the layer |
| 12403 | * before starting the animation will avoid skipping frames. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12404 | * |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12405 | * @throws IllegalStateException If this view is not attached to a window |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12406 | * |
| 12407 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12408 | */ |
| 12409 | public void buildLayer() { |
| 12410 | if (mLayerType == LAYER_TYPE_NONE) return; |
| 12411 | |
| 12412 | if (mAttachInfo == null) { |
| 12413 | throw new IllegalStateException("This view must be attached to a window first"); |
| 12414 | } |
| 12415 | |
| 12416 | switch (mLayerType) { |
| 12417 | case LAYER_TYPE_HARDWARE: |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12418 | if (mAttachInfo.mHardwareRenderer != null && |
| 12419 | mAttachInfo.mHardwareRenderer.isEnabled() && |
| 12420 | mAttachInfo.mHardwareRenderer.validate()) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12421 | getHardwareLayer(); |
Romain Guy | d0609e4 | 2011-11-21 17:21:15 -0800 | [diff] [blame] | 12422 | } |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12423 | break; |
| 12424 | case LAYER_TYPE_SOFTWARE: |
| 12425 | buildDrawingCache(true); |
| 12426 | break; |
| 12427 | } |
| 12428 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12429 | |
Romain Guy | f1ae106 | 2011-03-02 18:16:04 -0800 | [diff] [blame] | 12430 | /** |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12431 | * <p>Returns a hardware layer that can be used to draw this view again |
| 12432 | * without executing its draw method.</p> |
| 12433 | * |
| 12434 | * @return A HardwareLayer ready to render, or null if an error occurred. |
| 12435 | */ |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12436 | HardwareLayer getHardwareLayer() { |
Romain Guy | ea83503 | 2011-07-28 19:24:37 -0700 | [diff] [blame] | 12437 | if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null || |
| 12438 | !mAttachInfo.mHardwareRenderer.isEnabled()) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12439 | return null; |
| 12440 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12441 | |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12442 | if (!mAttachInfo.mHardwareRenderer.validate()) return null; |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12443 | |
| 12444 | final int width = mRight - mLeft; |
| 12445 | final int height = mBottom - mTop; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12446 | |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12447 | if (width == 0 || height == 0) { |
| 12448 | return null; |
| 12449 | } |
| 12450 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12451 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || mHardwareLayer == null) { |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12452 | if (mHardwareLayer == null) { |
| 12453 | mHardwareLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer( |
| 12454 | width, height, isOpaque()); |
Michael Jurka | 952e02b | 2012-03-13 18:34:35 -0700 | [diff] [blame] | 12455 | mLocalDirtyRect.set(0, 0, width, height); |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12456 | } else { |
| 12457 | if (mHardwareLayer.getWidth() != width || mHardwareLayer.getHeight() != height) { |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12458 | if (mHardwareLayer.resize(width, height)) { |
| 12459 | mLocalDirtyRect.set(0, 0, width, height); |
| 12460 | } |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12461 | } |
| 12462 | |
| 12463 | // This should not be necessary but applications that change |
| 12464 | // the parameters of their background drawable without calling |
| 12465 | // this.setBackground(Drawable) can leave the view in a bad state |
| 12466 | // (for instance isOpaque() returns true, but the background is |
| 12467 | // not opaque.) |
| 12468 | computeOpaqueFlags(); |
| 12469 | |
| 12470 | final boolean opaque = isOpaque(); |
Chet Haase | 603f6de | 2012-09-14 15:31:25 -0700 | [diff] [blame] | 12471 | if (mHardwareLayer.isValid() && mHardwareLayer.isOpaque() != opaque) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 12472 | mHardwareLayer.setOpaque(opaque); |
| 12473 | mLocalDirtyRect.set(0, 0, width, height); |
| 12474 | } |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12475 | } |
| 12476 | |
Romain Guy | 5cd5c3f | 2011-10-17 17:10:02 -0700 | [diff] [blame] | 12477 | // The layer is not valid if the underlying GPU resources cannot be allocated |
| 12478 | if (!mHardwareLayer.isValid()) { |
| 12479 | return null; |
| 12480 | } |
| 12481 | |
Romain Guy | 11cb642 | 2012-09-21 00:39:43 -0700 | [diff] [blame] | 12482 | mHardwareLayer.setLayerPaint(mLayerPaint); |
| 12483 | mHardwareLayer.redrawLater(getHardwareLayerDisplayList(mHardwareLayer), mLocalDirtyRect); |
| 12484 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 12485 | if (viewRoot != null) viewRoot.pushHardwareLayerUpdate(mHardwareLayer); |
| 12486 | |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 12487 | mLocalDirtyRect.setEmpty(); |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 12488 | } |
| 12489 | |
| 12490 | return mHardwareLayer; |
| 12491 | } |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12492 | |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12493 | /** |
| 12494 | * Destroys this View's hardware layer if possible. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12495 | * |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12496 | * @return True if the layer was destroyed, false otherwise. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12497 | * |
| 12498 | * @see #setLayerType(int, android.graphics.Paint) |
Romain Guy | 589b0bb | 2011-10-10 13:57:47 -0700 | [diff] [blame] | 12499 | * @see #LAYER_TYPE_HARDWARE |
| 12500 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12501 | boolean destroyLayer(boolean valid) { |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12502 | if (mHardwareLayer != null) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12503 | AttachInfo info = mAttachInfo; |
| 12504 | if (info != null && info.mHardwareRenderer != null && |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12505 | info.mHardwareRenderer.isEnabled() && |
| 12506 | (valid || info.mHardwareRenderer.validate())) { |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12507 | mHardwareLayer.destroy(); |
| 12508 | mHardwareLayer = null; |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12509 | |
Chet Haase | 6a2d17f | 2012-09-30 12:14:13 -0700 | [diff] [blame] | 12510 | if (mDisplayList != null) { |
| 12511 | mDisplayList.reset(); |
| 12512 | } |
Romain Guy | 9c4b79a | 2011-11-10 19:23:58 -0800 | [diff] [blame] | 12513 | invalidate(true); |
| 12514 | invalidateParentCaches(); |
| 12515 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12516 | return true; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12517 | } |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 12518 | return false; |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 12519 | } |
| 12520 | |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12521 | /** |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12522 | * Destroys all hardware rendering resources. This method is invoked |
| 12523 | * when the system needs to reclaim resources. Upon execution of this |
| 12524 | * method, you should free any OpenGL resources created by the view. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12525 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12526 | * Note: you <strong>must</strong> call |
| 12527 | * <code>super.destroyHardwareResources()</code> when overriding |
| 12528 | * this method. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 12529 | * |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12530 | * @hide |
| 12531 | */ |
| 12532 | protected void destroyHardwareResources() { |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 12533 | destroyLayer(true); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 12534 | } |
| 12535 | |
| 12536 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12537 | * <p>Enables or disables the drawing cache. When the drawing cache is enabled, the next call |
| 12538 | * to {@link #getDrawingCache()} or {@link #buildDrawingCache()} will draw the view in a |
| 12539 | * bitmap. Calling {@link #draw(android.graphics.Canvas)} will not draw from the cache when |
| 12540 | * the cache is enabled. To benefit from the cache, you must request the drawing cache by |
| 12541 | * calling {@link #getDrawingCache()} and draw it on screen if the returned bitmap is not |
| 12542 | * null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12543 | * |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 12544 | * <p>Enabling the drawing cache is similar to |
| 12545 | * {@link #setLayerType(int, android.graphics.Paint) setting a layer} when hardware |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12546 | * acceleration is turned off. When hardware acceleration is turned on, enabling the |
| 12547 | * drawing cache has no effect on rendering because the system uses a different mechanism |
| 12548 | * for acceleration which ignores the flag. If you want to use a Bitmap for the view, even |
| 12549 | * when hardware acceleration is enabled, see {@link #setLayerType(int, android.graphics.Paint)} |
| 12550 | * for information on how to enable software and hardware layers.</p> |
| 12551 | * |
| 12552 | * <p>This API can be used to manually generate |
| 12553 | * a bitmap copy of this view, by setting the flag to <code>true</code> and calling |
| 12554 | * {@link #getDrawingCache()}.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12555 | * |
| 12556 | * @param enabled true to enable the drawing cache, false otherwise |
| 12557 | * |
| 12558 | * @see #isDrawingCacheEnabled() |
| 12559 | * @see #getDrawingCache() |
| 12560 | * @see #buildDrawingCache() |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12561 | * @see #setLayerType(int, android.graphics.Paint) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12562 | */ |
| 12563 | public void setDrawingCacheEnabled(boolean enabled) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12564 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12565 | setFlags(enabled ? DRAWING_CACHE_ENABLED : 0, DRAWING_CACHE_ENABLED); |
| 12566 | } |
| 12567 | |
| 12568 | /** |
| 12569 | * <p>Indicates whether the drawing cache is enabled for this view.</p> |
| 12570 | * |
| 12571 | * @return true if the drawing cache is enabled |
| 12572 | * |
| 12573 | * @see #setDrawingCacheEnabled(boolean) |
| 12574 | * @see #getDrawingCache() |
| 12575 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 12576 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12577 | public boolean isDrawingCacheEnabled() { |
| 12578 | return (mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED; |
| 12579 | } |
| 12580 | |
| 12581 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12582 | * Debugging utility which recursively outputs the dirty state of a view and its |
| 12583 | * descendants. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12584 | * |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12585 | * @hide |
| 12586 | */ |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12587 | @SuppressWarnings({"UnusedDeclaration"}) |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12588 | public void outputDirtyFlags(String indent, boolean clear, int clearMask) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12589 | Log.d("View", indent + this + " DIRTY(" + (mPrivateFlags & View.PFLAG_DIRTY_MASK) + |
| 12590 | ") DRAWN(" + (mPrivateFlags & PFLAG_DRAWN) + ")" + " CACHE_VALID(" + |
| 12591 | (mPrivateFlags & View.PFLAG_DRAWING_CACHE_VALID) + |
| 12592 | ") INVALIDATED(" + (mPrivateFlags & PFLAG_INVALIDATED) + ")"); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12593 | if (clear) { |
| 12594 | mPrivateFlags &= clearMask; |
| 12595 | } |
| 12596 | if (this instanceof ViewGroup) { |
| 12597 | ViewGroup parent = (ViewGroup) this; |
| 12598 | final int count = parent.getChildCount(); |
| 12599 | for (int i = 0; i < count; i++) { |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 12600 | final View child = parent.getChildAt(i); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12601 | child.outputDirtyFlags(indent + " ", clear, clearMask); |
| 12602 | } |
| 12603 | } |
| 12604 | } |
| 12605 | |
| 12606 | /** |
| 12607 | * This method is used by ViewGroup to cause its children to restore or recreate their |
| 12608 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 12609 | * to recreate its own display list, which would happen if it went through the normal |
| 12610 | * draw/dispatchDraw mechanisms. |
| 12611 | * |
| 12612 | * @hide |
| 12613 | */ |
| 12614 | protected void dispatchGetDisplayList() {} |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12615 | |
| 12616 | /** |
| 12617 | * A view that is not attached or hardware accelerated cannot create a display list. |
| 12618 | * This method checks these conditions and returns the appropriate result. |
| 12619 | * |
| 12620 | * @return true if view has the ability to create a display list, false otherwise. |
| 12621 | * |
| 12622 | * @hide |
| 12623 | */ |
| 12624 | public boolean canHaveDisplayList() { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12625 | return !(mAttachInfo == null || mAttachInfo.mHardwareRenderer == null); |
Chet Haase | f4ac547 | 2011-01-27 10:30:25 -0800 | [diff] [blame] | 12626 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12627 | |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12628 | /** |
Gilles Debunne | b35ab7b | 2011-12-05 15:54:00 -0800 | [diff] [blame] | 12629 | * @return The HardwareRenderer associated with that view or null if hardware rendering |
| 12630 | * is not supported or this this has not been attached to a window. |
| 12631 | * |
| 12632 | * @hide |
| 12633 | */ |
| 12634 | public HardwareRenderer getHardwareRenderer() { |
| 12635 | if (mAttachInfo != null) { |
| 12636 | return mAttachInfo.mHardwareRenderer; |
| 12637 | } |
| 12638 | return null; |
| 12639 | } |
| 12640 | |
| 12641 | /** |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12642 | * Returns a DisplayList. If the incoming displayList is null, one will be created. |
| 12643 | * Otherwise, the same display list will be returned (after having been rendered into |
| 12644 | * along the way, depending on the invalidation state of the view). |
| 12645 | * |
| 12646 | * @param displayList The previous version of this displayList, could be null. |
| 12647 | * @param isLayer Whether the requester of the display list is a layer. If so, |
| 12648 | * the view will avoid creating a layer inside the resulting display list. |
| 12649 | * @return A new or reused DisplayList object. |
| 12650 | */ |
| 12651 | private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) { |
| 12652 | if (!canHaveDisplayList()) { |
| 12653 | return null; |
| 12654 | } |
| 12655 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12656 | if (((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12657 | displayList == null || !displayList.isValid() || |
| 12658 | (!isLayer && mRecreateDisplayList))) { |
| 12659 | // Don't need to recreate the display list, just need to tell our |
| 12660 | // children to restore/recreate theirs |
| 12661 | if (displayList != null && displayList.isValid() && |
| 12662 | !isLayer && !mRecreateDisplayList) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12663 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12664 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12665 | dispatchGetDisplayList(); |
| 12666 | |
| 12667 | return displayList; |
| 12668 | } |
| 12669 | |
| 12670 | if (!isLayer) { |
| 12671 | // If we got here, we're recreating it. Mark it as such to ensure that |
| 12672 | // we copy in child display lists into ours in drawChild() |
| 12673 | mRecreateDisplayList = true; |
| 12674 | } |
| 12675 | if (displayList == null) { |
| 12676 | final String name = getClass().getSimpleName(); |
| 12677 | displayList = mAttachInfo.mHardwareRenderer.createDisplayList(name); |
| 12678 | // If we're creating a new display list, make sure our parent gets invalidated |
| 12679 | // since they will need to recreate their display list to account for this |
| 12680 | // new child display list. |
| 12681 | invalidateParentCaches(); |
| 12682 | } |
| 12683 | |
| 12684 | boolean caching = false; |
| 12685 | final HardwareCanvas canvas = displayList.start(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12686 | int width = mRight - mLeft; |
| 12687 | int height = mBottom - mTop; |
| 12688 | |
| 12689 | try { |
| 12690 | canvas.setViewport(width, height); |
| 12691 | // The dirty rect should always be null for a display list |
| 12692 | canvas.onPreDraw(null); |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 12693 | int layerType = getLayerType(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12694 | if (!isLayer && layerType != LAYER_TYPE_NONE) { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12695 | if (layerType == LAYER_TYPE_HARDWARE) { |
| 12696 | final HardwareLayer layer = getHardwareLayer(); |
| 12697 | if (layer != null && layer.isValid()) { |
| 12698 | canvas.drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 12699 | } else { |
| 12700 | canvas.saveLayer(0, 0, mRight - mLeft, mBottom - mTop, mLayerPaint, |
| 12701 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | |
| 12702 | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 12703 | } |
| 12704 | caching = true; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12705 | } else { |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 12706 | buildDrawingCache(true); |
| 12707 | Bitmap cache = getDrawingCache(true); |
| 12708 | if (cache != null) { |
| 12709 | canvas.drawBitmap(cache, 0, 0, mLayerPaint); |
| 12710 | caching = true; |
| 12711 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12712 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12713 | } else { |
| 12714 | |
| 12715 | computeScroll(); |
| 12716 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12717 | canvas.translate(-mScrollX, -mScrollY); |
| 12718 | if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12719 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12720 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12721 | } |
| 12722 | |
| 12723 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12724 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12725 | dispatchDraw(canvas); |
| 12726 | } else { |
| 12727 | draw(canvas); |
| 12728 | } |
| 12729 | } |
| 12730 | } finally { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12731 | canvas.onPostDraw(); |
| 12732 | |
| 12733 | displayList.end(); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 12734 | displayList.setCaching(caching); |
| 12735 | if (isLayer) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12736 | displayList.setLeftTopRightBottom(0, 0, width, height); |
| 12737 | } else { |
| 12738 | setDisplayListProperties(displayList); |
| 12739 | } |
| 12740 | } |
| 12741 | } else if (!isLayer) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12742 | mPrivateFlags |= PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID; |
| 12743 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12744 | } |
| 12745 | |
| 12746 | return displayList; |
| 12747 | } |
| 12748 | |
| 12749 | /** |
| 12750 | * Get the DisplayList for the HardwareLayer |
| 12751 | * |
| 12752 | * @param layer The HardwareLayer whose DisplayList we want |
| 12753 | * @return A DisplayList fopr the specified HardwareLayer |
| 12754 | */ |
| 12755 | private DisplayList getHardwareLayerDisplayList(HardwareLayer layer) { |
| 12756 | DisplayList displayList = getDisplayList(layer.getDisplayList(), true); |
| 12757 | layer.setDisplayList(displayList); |
| 12758 | return displayList; |
| 12759 | } |
| 12760 | |
| 12761 | |
| 12762 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12763 | * <p>Returns a display list that can be used to draw this view again |
| 12764 | * without executing its draw method.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12765 | * |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12766 | * @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] | 12767 | * |
| 12768 | * @hide |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12769 | */ |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 12770 | public DisplayList getDisplayList() { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 12771 | mDisplayList = getDisplayList(mDisplayList, false); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12772 | return mDisplayList; |
| 12773 | } |
| 12774 | |
Romain Guy | 38c2ece | 2012-05-24 14:20:56 -0700 | [diff] [blame] | 12775 | private void clearDisplayList() { |
| 12776 | if (mDisplayList != null) { |
| 12777 | mDisplayList.invalidate(); |
| 12778 | mDisplayList.clear(); |
| 12779 | } |
| 12780 | } |
| 12781 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 12782 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12783 | * <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] | 12784 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12785 | * @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] | 12786 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12787 | * @see #getDrawingCache(boolean) |
| 12788 | */ |
| 12789 | public Bitmap getDrawingCache() { |
| 12790 | return getDrawingCache(false); |
| 12791 | } |
| 12792 | |
| 12793 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12794 | * <p>Returns the bitmap in which this view drawing is cached. The returned bitmap |
| 12795 | * is null when caching is disabled. If caching is enabled and the cache is not ready, |
| 12796 | * this method will create it. Calling {@link #draw(android.graphics.Canvas)} will not |
| 12797 | * draw from the cache when the cache is enabled. To benefit from the cache, you must |
| 12798 | * request the drawing cache by calling this method and draw it on screen if the |
| 12799 | * returned bitmap is not null.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12800 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12801 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12802 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12803 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12804 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12805 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12806 | * size than the view. This implies that your application must be able to handle this |
| 12807 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12808 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12809 | * @param autoScale Indicates whether the generated bitmap should be scaled based on |
| 12810 | * the current density of the screen when the application is in compatibility |
| 12811 | * mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12812 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12813 | * @return A bitmap representing this view or null if cache is disabled. |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12814 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12815 | * @see #setDrawingCacheEnabled(boolean) |
| 12816 | * @see #isDrawingCacheEnabled() |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12817 | * @see #buildDrawingCache(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12818 | * @see #destroyDrawingCache() |
| 12819 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12820 | public Bitmap getDrawingCache(boolean autoScale) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12821 | if ((mViewFlags & WILL_NOT_CACHE_DRAWING) == WILL_NOT_CACHE_DRAWING) { |
| 12822 | return null; |
| 12823 | } |
| 12824 | if ((mViewFlags & DRAWING_CACHE_ENABLED) == DRAWING_CACHE_ENABLED) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12825 | buildDrawingCache(autoScale); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12826 | } |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12827 | return autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12828 | } |
| 12829 | |
| 12830 | /** |
| 12831 | * <p>Frees the resources used by the drawing cache. If you call |
| 12832 | * {@link #buildDrawingCache()} manually without calling |
| 12833 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12834 | * should cleanup the cache with this method afterwards.</p> |
| 12835 | * |
| 12836 | * @see #setDrawingCacheEnabled(boolean) |
| 12837 | * @see #buildDrawingCache() |
| 12838 | * @see #getDrawingCache() |
| 12839 | */ |
| 12840 | public void destroyDrawingCache() { |
| 12841 | if (mDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12842 | mDrawingCache.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12843 | mDrawingCache = null; |
| 12844 | } |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12845 | if (mUnscaledDrawingCache != null) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12846 | mUnscaledDrawingCache.recycle(); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12847 | mUnscaledDrawingCache = null; |
| 12848 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12849 | } |
| 12850 | |
| 12851 | /** |
| 12852 | * 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] | 12853 | * 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] | 12854 | * view will always be drawn on top of a solid color. |
| 12855 | * |
| 12856 | * @param color The background color to use for the drawing cache's bitmap |
| 12857 | * |
| 12858 | * @see #setDrawingCacheEnabled(boolean) |
| 12859 | * @see #buildDrawingCache() |
| 12860 | * @see #getDrawingCache() |
| 12861 | */ |
| 12862 | public void setDrawingCacheBackgroundColor(int color) { |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12863 | if (color != mDrawingCacheBackgroundColor) { |
| 12864 | mDrawingCacheBackgroundColor = color; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12865 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 52e2ef8 | 2010-01-14 12:11:48 -0800 | [diff] [blame] | 12866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12867 | } |
| 12868 | |
| 12869 | /** |
| 12870 | * @see #setDrawingCacheBackgroundColor(int) |
| 12871 | * |
| 12872 | * @return The background color to used for the drawing cache's bitmap |
| 12873 | */ |
| 12874 | public int getDrawingCacheBackgroundColor() { |
| 12875 | return mDrawingCacheBackgroundColor; |
| 12876 | } |
| 12877 | |
| 12878 | /** |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12879 | * <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] | 12880 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12881 | * @see #buildDrawingCache(boolean) |
| 12882 | */ |
| 12883 | public void buildDrawingCache() { |
| 12884 | buildDrawingCache(false); |
| 12885 | } |
Gilles Debunne | 2ed2eac | 2011-02-24 16:29:48 -0800 | [diff] [blame] | 12886 | |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12887 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12888 | * <p>Forces the drawing cache to be built if the drawing cache is invalid.</p> |
| 12889 | * |
| 12890 | * <p>If you call {@link #buildDrawingCache()} manually without calling |
| 12891 | * {@link #setDrawingCacheEnabled(boolean) setDrawingCacheEnabled(true)}, you |
| 12892 | * should cleanup the cache by calling {@link #destroyDrawingCache()} afterwards.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12893 | * |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12894 | * <p>Note about auto scaling in compatibility mode: When auto scaling is not enabled, |
| 12895 | * this method will create a bitmap of the same size as this view. Because this bitmap |
| 12896 | * will be drawn scaled by the parent ViewGroup, the result on screen might show |
| 12897 | * scaling artifacts. To avoid such artifacts, you should call this method by setting |
| 12898 | * the auto scaling to true. Doing so, however, will generate a bitmap of a different |
| 12899 | * size than the view. This implies that your application must be able to handle this |
| 12900 | * size.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 12901 | * |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 12902 | * <p>You should avoid calling this method when hardware acceleration is enabled. If |
| 12903 | * 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] | 12904 | * 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] | 12905 | * performance.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12906 | * |
| 12907 | * @see #getDrawingCache() |
| 12908 | * @see #destroyDrawingCache() |
| 12909 | */ |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12910 | public void buildDrawingCache(boolean autoScale) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 12911 | if ((mPrivateFlags & PFLAG_DRAWING_CACHE_VALID) == 0 || (autoScale ? |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12912 | mDrawingCache == null : mUnscaledDrawingCache == null)) { |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12913 | mCachingFailed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12914 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12915 | int width = mRight - mLeft; |
| 12916 | int height = mBottom - mTop; |
| 12917 | |
| 12918 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12919 | final boolean scalingRequired = attachInfo != null && attachInfo.mScalingRequired; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12920 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 12921 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12922 | width = (int) ((width * attachInfo.mApplicationScale) + 0.5f); |
| 12923 | height = (int) ((height * attachInfo.mApplicationScale) + 0.5f); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 12924 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12925 | |
| 12926 | final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12927 | final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque(); |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12928 | final boolean use32BitCache = attachInfo != null && attachInfo.mUse32BitDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12929 | |
Romain Guy | af61cc4 | 2012-09-30 10:49:15 -0700 | [diff] [blame] | 12930 | final long projectedBitmapSize = width * height * (opaque && !use32BitCache ? 2 : 4); |
| 12931 | final long drawingCacheSize = |
Chris Craik | 10e9d1d | 2012-09-06 14:42:44 -0700 | [diff] [blame] | 12932 | ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize(); |
| 12933 | if (width <= 0 || height <= 0 || projectedBitmapSize > drawingCacheSize) { |
Chris Craik | 3667aa3 | 2012-09-06 14:56:39 -0700 | [diff] [blame] | 12934 | if (width > 0 && height > 0) { |
| 12935 | Log.w(VIEW_LOG_TAG, "View too large to fit into drawing cache, needs " |
| 12936 | + projectedBitmapSize + " bytes, only " |
| 12937 | + drawingCacheSize + " available"); |
| 12938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12939 | destroyDrawingCache(); |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12940 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12941 | return; |
| 12942 | } |
| 12943 | |
| 12944 | boolean clear = true; |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12945 | Bitmap bitmap = autoScale ? mDrawingCache : mUnscaledDrawingCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12946 | |
| 12947 | if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12948 | Bitmap.Config quality; |
| 12949 | if (!opaque) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12950 | // Never pick ARGB_4444 because it looks awful |
| 12951 | // 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] | 12952 | switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { |
| 12953 | case DRAWING_CACHE_QUALITY_AUTO: |
| 12954 | quality = Bitmap.Config.ARGB_8888; |
| 12955 | break; |
| 12956 | case DRAWING_CACHE_QUALITY_LOW: |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 12957 | quality = Bitmap.Config.ARGB_8888; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12958 | break; |
| 12959 | case DRAWING_CACHE_QUALITY_HIGH: |
| 12960 | quality = Bitmap.Config.ARGB_8888; |
| 12961 | break; |
| 12962 | default: |
| 12963 | quality = Bitmap.Config.ARGB_8888; |
| 12964 | break; |
| 12965 | } |
| 12966 | } else { |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 12967 | // Optimization for translucent windows |
| 12968 | // 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] | 12969 | 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] | 12970 | } |
| 12971 | |
| 12972 | // Try to cleanup memory |
| 12973 | if (bitmap != null) bitmap.recycle(); |
| 12974 | |
| 12975 | try { |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 12976 | bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 12977 | width, height, quality); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 12978 | bitmap.setDensity(getResources().getDisplayMetrics().densityDpi); |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12979 | if (autoScale) { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12980 | mDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12981 | } else { |
Romain Guy | 02890fd | 2010-08-06 17:58:44 -0700 | [diff] [blame] | 12982 | mUnscaledDrawingCache = bitmap; |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12983 | } |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 12984 | if (opaque && use32BitCache) bitmap.setHasAlpha(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12985 | } catch (OutOfMemoryError e) { |
| 12986 | // If there is not enough memory to create the bitmap cache, just |
| 12987 | // ignore the issue as bitmap caches are not required to draw the |
| 12988 | // view hierarchy |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 12989 | if (autoScale) { |
| 12990 | mDrawingCache = null; |
| 12991 | } else { |
| 12992 | mUnscaledDrawingCache = null; |
| 12993 | } |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 12994 | mCachingFailed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12995 | return; |
| 12996 | } |
| 12997 | |
| 12998 | clear = drawingCacheBackgroundColor != 0; |
| 12999 | } |
| 13000 | |
| 13001 | Canvas canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13002 | if (attachInfo != null) { |
| 13003 | canvas = attachInfo.mCanvas; |
| 13004 | if (canvas == null) { |
| 13005 | canvas = new Canvas(); |
| 13006 | } |
| 13007 | canvas.setBitmap(bitmap); |
| 13008 | // Temporarily clobber the cached Canvas in case one of our children |
| 13009 | // is also using a drawing cache. Without this, the children would |
| 13010 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 13011 | // thing would happen (invisible views, corrupted drawings, etc.) |
| 13012 | attachInfo.mCanvas = null; |
| 13013 | } else { |
| 13014 | // This case should hopefully never or seldom happen |
| 13015 | canvas = new Canvas(bitmap); |
| 13016 | } |
| 13017 | |
| 13018 | if (clear) { |
| 13019 | bitmap.eraseColor(drawingCacheBackgroundColor); |
| 13020 | } |
| 13021 | |
| 13022 | computeScroll(); |
| 13023 | final int restoreCount = canvas.save(); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13024 | |
Romain Guy | e112322 | 2009-06-29 14:24:56 -0700 | [diff] [blame] | 13025 | if (autoScale && scalingRequired) { |
Romain Guy | fbd8f69 | 2009-06-26 14:51:58 -0700 | [diff] [blame] | 13026 | final float scale = attachInfo.mApplicationScale; |
| 13027 | canvas.scale(scale, scale); |
| 13028 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13029 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13030 | canvas.translate(-mScrollX, -mScrollY); |
| 13031 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13032 | mPrivateFlags |= PFLAG_DRAWN; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 13033 | if (mAttachInfo == null || !mAttachInfo.mHardwareAccelerated || |
| 13034 | mLayerType != LAYER_TYPE_NONE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13035 | mPrivateFlags |= PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 13036 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13037 | |
| 13038 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13039 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 13040 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13041 | dispatchDraw(canvas); |
| 13042 | } else { |
| 13043 | draw(canvas); |
| 13044 | } |
| 13045 | |
| 13046 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 13047 | canvas.setBitmap(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13048 | |
| 13049 | if (attachInfo != null) { |
| 13050 | // Restore the cached Canvas for our siblings |
| 13051 | attachInfo.mCanvas = canvas; |
| 13052 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13053 | } |
| 13054 | } |
| 13055 | |
| 13056 | /** |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13057 | * Create a snapshot of the view into a bitmap. We should probably make |
| 13058 | * some form of this public, but should think about the API. |
| 13059 | */ |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 13060 | Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipChildren) { |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 13061 | int width = mRight - mLeft; |
| 13062 | int height = mBottom - mTop; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13063 | |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 13064 | final AttachInfo attachInfo = mAttachInfo; |
Romain Guy | 8c11e31 | 2009-09-14 15:15:30 -0700 | [diff] [blame] | 13065 | final float scale = attachInfo != null ? attachInfo.mApplicationScale : 1.0f; |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 13066 | width = (int) ((width * scale) + 0.5f); |
| 13067 | height = (int) ((height * scale) + 0.5f); |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13068 | |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 13069 | Bitmap bitmap = Bitmap.createBitmap(mResources.getDisplayMetrics(), |
| 13070 | width > 0 ? width : 1, height > 0 ? height : 1, quality); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13071 | if (bitmap == null) { |
| 13072 | throw new OutOfMemoryError(); |
| 13073 | } |
| 13074 | |
Romain Guy | c529d8d | 2011-09-06 15:01:39 -0700 | [diff] [blame] | 13075 | Resources resources = getResources(); |
| 13076 | if (resources != null) { |
| 13077 | bitmap.setDensity(resources.getDisplayMetrics().densityDpi); |
| 13078 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13079 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13080 | Canvas canvas; |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13081 | if (attachInfo != null) { |
| 13082 | canvas = attachInfo.mCanvas; |
| 13083 | if (canvas == null) { |
| 13084 | canvas = new Canvas(); |
| 13085 | } |
| 13086 | canvas.setBitmap(bitmap); |
| 13087 | // Temporarily clobber the cached Canvas in case one of our children |
| 13088 | // is also using a drawing cache. Without this, the children would |
| 13089 | // steal the canvas by attaching their own bitmap to it and bad, bad |
| 13090 | // things would happen (invisible views, corrupted drawings, etc.) |
| 13091 | attachInfo.mCanvas = null; |
| 13092 | } else { |
| 13093 | // This case should hopefully never or seldom happen |
| 13094 | canvas = new Canvas(bitmap); |
| 13095 | } |
| 13096 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13097 | if ((backgroundColor & 0xff000000) != 0) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13098 | bitmap.eraseColor(backgroundColor); |
| 13099 | } |
| 13100 | |
| 13101 | computeScroll(); |
| 13102 | final int restoreCount = canvas.save(); |
Dianne Hackborn | 8cae124 | 2009-09-10 14:32:16 -0700 | [diff] [blame] | 13103 | canvas.scale(scale, scale); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13104 | canvas.translate(-mScrollX, -mScrollY); |
| 13105 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13106 | // Temporarily remove the dirty mask |
| 13107 | int flags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13108 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13109 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13110 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13111 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13112 | dispatchDraw(canvas); |
| 13113 | } else { |
| 13114 | draw(canvas); |
| 13115 | } |
| 13116 | |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13117 | mPrivateFlags = flags; |
| 13118 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13119 | canvas.restoreToCount(restoreCount); |
Dianne Hackborn | 6311d0a | 2011-08-02 16:37:58 -0700 | [diff] [blame] | 13120 | canvas.setBitmap(null); |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13121 | |
| 13122 | if (attachInfo != null) { |
| 13123 | // Restore the cached Canvas for our siblings |
| 13124 | attachInfo.mCanvas = canvas; |
| 13125 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 13126 | |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 13127 | return bitmap; |
| 13128 | } |
| 13129 | |
| 13130 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13131 | * Indicates whether this View is currently in edit mode. A View is usually |
| 13132 | * in edit mode when displayed within a developer tool. For instance, if |
| 13133 | * this View is being drawn by a visual user interface builder, this method |
| 13134 | * should return true. |
| 13135 | * |
| 13136 | * Subclasses should check the return value of this method to provide |
| 13137 | * different behaviors if their normal behavior might interfere with the |
| 13138 | * host environment. For instance: the class spawns a thread in its |
| 13139 | * constructor, the drawing code relies on device-specific features, etc. |
| 13140 | * |
| 13141 | * This method is usually checked in the drawing code of custom widgets. |
| 13142 | * |
| 13143 | * @return True if this View is in edit mode, false otherwise. |
| 13144 | */ |
| 13145 | public boolean isInEditMode() { |
| 13146 | return false; |
| 13147 | } |
| 13148 | |
| 13149 | /** |
| 13150 | * If the View draws content inside its padding and enables fading edges, |
| 13151 | * it needs to support padding offsets. Padding offsets are added to the |
| 13152 | * fading edges to extend the length of the fade so that it covers pixels |
| 13153 | * drawn inside the padding. |
| 13154 | * |
| 13155 | * Subclasses of this class should override this method if they need |
| 13156 | * to draw content inside the padding. |
| 13157 | * |
| 13158 | * @return True if padding offset must be applied, false otherwise. |
| 13159 | * |
| 13160 | * @see #getLeftPaddingOffset() |
| 13161 | * @see #getRightPaddingOffset() |
| 13162 | * @see #getTopPaddingOffset() |
| 13163 | * @see #getBottomPaddingOffset() |
| 13164 | * |
| 13165 | * @since CURRENT |
| 13166 | */ |
| 13167 | protected boolean isPaddingOffsetRequired() { |
| 13168 | return false; |
| 13169 | } |
| 13170 | |
| 13171 | /** |
| 13172 | * Amount by which to extend the left fading region. Called only when |
| 13173 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13174 | * |
| 13175 | * @return The left padding offset in pixels. |
| 13176 | * |
| 13177 | * @see #isPaddingOffsetRequired() |
| 13178 | * |
| 13179 | * @since CURRENT |
| 13180 | */ |
| 13181 | protected int getLeftPaddingOffset() { |
| 13182 | return 0; |
| 13183 | } |
| 13184 | |
| 13185 | /** |
| 13186 | * Amount by which to extend the right fading region. Called only when |
| 13187 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13188 | * |
| 13189 | * @return The right padding offset in pixels. |
| 13190 | * |
| 13191 | * @see #isPaddingOffsetRequired() |
| 13192 | * |
| 13193 | * @since CURRENT |
| 13194 | */ |
| 13195 | protected int getRightPaddingOffset() { |
| 13196 | return 0; |
| 13197 | } |
| 13198 | |
| 13199 | /** |
| 13200 | * Amount by which to extend the top fading region. Called only when |
| 13201 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13202 | * |
| 13203 | * @return The top padding offset in pixels. |
| 13204 | * |
| 13205 | * @see #isPaddingOffsetRequired() |
| 13206 | * |
| 13207 | * @since CURRENT |
| 13208 | */ |
| 13209 | protected int getTopPaddingOffset() { |
| 13210 | return 0; |
| 13211 | } |
| 13212 | |
| 13213 | /** |
| 13214 | * Amount by which to extend the bottom fading region. Called only when |
| 13215 | * {@link #isPaddingOffsetRequired()} returns true. |
| 13216 | * |
| 13217 | * @return The bottom padding offset in pixels. |
| 13218 | * |
| 13219 | * @see #isPaddingOffsetRequired() |
| 13220 | * |
| 13221 | * @since CURRENT |
| 13222 | */ |
| 13223 | protected int getBottomPaddingOffset() { |
| 13224 | return 0; |
| 13225 | } |
| 13226 | |
| 13227 | /** |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13228 | * @hide |
| 13229 | * @param offsetRequired |
| 13230 | */ |
| 13231 | protected int getFadeTop(boolean offsetRequired) { |
| 13232 | int top = mPaddingTop; |
| 13233 | if (offsetRequired) top += getTopPaddingOffset(); |
| 13234 | return top; |
| 13235 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13236 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13237 | /** |
| 13238 | * @hide |
| 13239 | * @param offsetRequired |
| 13240 | */ |
| 13241 | protected int getFadeHeight(boolean offsetRequired) { |
| 13242 | int padding = mPaddingTop; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13243 | if (offsetRequired) padding += getTopPaddingOffset(); |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13244 | return mBottom - mTop - mPaddingBottom - padding; |
| 13245 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13246 | |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13247 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13248 | * <p>Indicates whether this view is attached to a hardware accelerated |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13249 | * window or not.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13250 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13251 | * <p>Even if this method returns true, it does not mean that every call |
| 13252 | * to {@link #draw(android.graphics.Canvas)} will be made with an hardware |
| 13253 | * accelerated {@link android.graphics.Canvas}. For instance, if this view |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 13254 | * is drawn onto an offscreen {@link android.graphics.Bitmap} and its |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13255 | * window is hardware accelerated, |
| 13256 | * {@link android.graphics.Canvas#isHardwareAccelerated()} will likely |
| 13257 | * return false, and this method will return true.</p> |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13258 | * |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13259 | * @return True if the view is attached to a window and the window is |
| 13260 | * hardware accelerated; false in any other case. |
| 13261 | */ |
| 13262 | public boolean isHardwareAccelerated() { |
| 13263 | return mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
| 13264 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 13265 | |
Romain Guy | 2bffd26 | 2010-09-12 17:40:02 -0700 | [diff] [blame] | 13266 | /** |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13267 | * Utility function, called by draw(canvas, parent, drawingTime) to handle the less common |
| 13268 | * case of an active Animation being run on the view. |
| 13269 | */ |
| 13270 | private boolean drawAnimation(ViewGroup parent, long drawingTime, |
| 13271 | Animation a, boolean scalingRequired) { |
| 13272 | Transformation invalidationTransform; |
| 13273 | final int flags = parent.mGroupFlags; |
| 13274 | final boolean initialized = a.isInitialized(); |
| 13275 | if (!initialized) { |
Chet Haase | 1fb8a9e | 2012-04-19 09:22:34 -0700 | [diff] [blame] | 13276 | a.initialize(mRight - mLeft, mBottom - mTop, parent.getWidth(), parent.getHeight()); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13277 | a.initializeInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop); |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13278 | if (mAttachInfo != null) a.setListenerHandler(mAttachInfo.mHandler); |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13279 | onAnimationStart(); |
| 13280 | } |
| 13281 | |
| 13282 | boolean more = a.getTransformation(drawingTime, parent.mChildTransformation, 1f); |
| 13283 | if (scalingRequired && mAttachInfo.mApplicationScale != 1f) { |
| 13284 | if (parent.mInvalidationTransformation == null) { |
| 13285 | parent.mInvalidationTransformation = new Transformation(); |
| 13286 | } |
| 13287 | invalidationTransform = parent.mInvalidationTransformation; |
| 13288 | a.getTransformation(drawingTime, invalidationTransform, 1f); |
| 13289 | } else { |
| 13290 | invalidationTransform = parent.mChildTransformation; |
| 13291 | } |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 13292 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13293 | if (more) { |
| 13294 | if (!a.willChangeBounds()) { |
Romain Guy | f0af1d5 | 2012-07-11 18:31:21 -0700 | [diff] [blame] | 13295 | if ((flags & (ViewGroup.FLAG_OPTIMIZE_INVALIDATE | ViewGroup.FLAG_ANIMATION_DONE)) == |
| 13296 | ViewGroup.FLAG_OPTIMIZE_INVALIDATE) { |
| 13297 | parent.mGroupFlags |= ViewGroup.FLAG_INVALIDATE_REQUIRED; |
| 13298 | } else if ((flags & ViewGroup.FLAG_INVALIDATE_REQUIRED) == 0) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13299 | // The child need to draw an animation, potentially offscreen, so |
| 13300 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13301 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13302 | parent.invalidate(mLeft, mTop, mRight, mBottom); |
| 13303 | } |
| 13304 | } else { |
| 13305 | if (parent.mInvalidateRegion == null) { |
| 13306 | parent.mInvalidateRegion = new RectF(); |
| 13307 | } |
| 13308 | final RectF region = parent.mInvalidateRegion; |
| 13309 | a.getInvalidateRegion(0, 0, mRight - mLeft, mBottom - mTop, region, |
| 13310 | invalidationTransform); |
| 13311 | |
| 13312 | // The child need to draw an animation, potentially offscreen, so |
| 13313 | // make sure we do not cancel invalidate requests |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13314 | parent.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13315 | |
| 13316 | final int left = mLeft + (int) region.left; |
| 13317 | final int top = mTop + (int) region.top; |
| 13318 | parent.invalidate(left, top, left + (int) (region.width() + .5f), |
| 13319 | top + (int) (region.height() + .5f)); |
| 13320 | } |
| 13321 | } |
| 13322 | return more; |
| 13323 | } |
| 13324 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13325 | /** |
| 13326 | * This method is called by getDisplayList() when a display list is created or re-rendered. |
| 13327 | * It sets or resets the current value of all properties on that display list (resetting is |
| 13328 | * necessary when a display list is being re-created, because we need to make sure that |
| 13329 | * previously-set transform values |
| 13330 | */ |
| 13331 | void setDisplayListProperties(DisplayList displayList) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13332 | if (displayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13333 | displayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
Chet Haase | db8c9a6 | 2012-03-21 18:54:18 -0700 | [diff] [blame] | 13334 | displayList.setHasOverlappingRendering(hasOverlappingRendering()); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13335 | if (mParent instanceof ViewGroup) { |
| 13336 | displayList.setClipChildren( |
| 13337 | (((ViewGroup)mParent).mGroupFlags & ViewGroup.FLAG_CLIP_CHILDREN) != 0); |
| 13338 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13339 | float alpha = 1; |
| 13340 | if (mParent instanceof ViewGroup && (((ViewGroup) mParent).mGroupFlags & |
| 13341 | ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13342 | ViewGroup parentVG = (ViewGroup) mParent; |
| 13343 | final boolean hasTransform = |
| 13344 | parentVG.getChildStaticTransformation(this, parentVG.mChildTransformation); |
| 13345 | if (hasTransform) { |
| 13346 | Transformation transform = parentVG.mChildTransformation; |
| 13347 | final int transformType = parentVG.mChildTransformation.getTransformationType(); |
| 13348 | if (transformType != Transformation.TYPE_IDENTITY) { |
| 13349 | if ((transformType & Transformation.TYPE_ALPHA) != 0) { |
| 13350 | alpha = transform.getAlpha(); |
| 13351 | } |
| 13352 | if ((transformType & Transformation.TYPE_MATRIX) != 0) { |
| 13353 | displayList.setStaticMatrix(transform.getMatrix()); |
| 13354 | } |
| 13355 | } |
| 13356 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13357 | } |
| 13358 | if (mTransformationInfo != null) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13359 | alpha *= mTransformationInfo.mAlpha; |
| 13360 | if (alpha < 1) { |
| 13361 | final int multipliedAlpha = (int) (255 * alpha); |
| 13362 | if (onSetAlpha(multipliedAlpha)) { |
| 13363 | alpha = 1; |
| 13364 | } |
| 13365 | } |
| 13366 | displayList.setTransformationInfo(alpha, |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13367 | mTransformationInfo.mTranslationX, mTransformationInfo.mTranslationY, |
| 13368 | mTransformationInfo.mRotation, mTransformationInfo.mRotationX, |
| 13369 | mTransformationInfo.mRotationY, mTransformationInfo.mScaleX, |
| 13370 | mTransformationInfo.mScaleY); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13371 | if (mTransformationInfo.mCamera == null) { |
| 13372 | mTransformationInfo.mCamera = new Camera(); |
| 13373 | mTransformationInfo.matrix3D = new Matrix(); |
| 13374 | } |
| 13375 | displayList.setCameraDistance(mTransformationInfo.mCamera.getLocationZ()); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13376 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == PFLAG_PIVOT_EXPLICITLY_SET) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13377 | displayList.setPivotX(getPivotX()); |
| 13378 | displayList.setPivotY(getPivotY()); |
| 13379 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13380 | } else if (alpha < 1) { |
| 13381 | displayList.setAlpha(alpha); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13382 | } |
| 13383 | } |
| 13384 | } |
| 13385 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13386 | /** |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13387 | * This method is called by ViewGroup.drawChild() to have each child view draw itself. |
| 13388 | * This draw() method is an implementation detail and is not intended to be overridden or |
| 13389 | * to be called from anywhere else other than ViewGroup.drawChild(). |
| 13390 | */ |
| 13391 | boolean draw(Canvas canvas, ViewGroup parent, long drawingTime) { |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13392 | boolean useDisplayListProperties = mAttachInfo != null && mAttachInfo.mHardwareAccelerated; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13393 | boolean more = false; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13394 | final boolean childHasIdentityMatrix = hasIdentityMatrix(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13395 | final int flags = parent.mGroupFlags; |
| 13396 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13397 | if ((flags & ViewGroup.FLAG_CLEAR_TRANSFORMATION) == ViewGroup.FLAG_CLEAR_TRANSFORMATION) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13398 | parent.mChildTransformation.clear(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13399 | parent.mGroupFlags &= ~ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13400 | } |
| 13401 | |
| 13402 | Transformation transformToApply = null; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13403 | boolean concatMatrix = false; |
| 13404 | |
| 13405 | boolean scalingRequired = false; |
| 13406 | boolean caching; |
Michael Jurka | ba64974 | 2012-06-28 19:12:58 -0700 | [diff] [blame] | 13407 | int layerType = getLayerType(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13408 | |
| 13409 | final boolean hardwareAccelerated = canvas.isHardwareAccelerated(); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13410 | if ((flags & ViewGroup.FLAG_CHILDREN_DRAWN_WITH_CACHE) != 0 || |
| 13411 | (flags & ViewGroup.FLAG_ALWAYS_DRAWN_WITH_CACHE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13412 | caching = true; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13413 | // 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] | 13414 | if (mAttachInfo != null) scalingRequired = mAttachInfo.mScalingRequired; |
| 13415 | } else { |
| 13416 | caching = (layerType != LAYER_TYPE_NONE) || hardwareAccelerated; |
| 13417 | } |
| 13418 | |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13419 | final Animation a = getAnimation(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13420 | if (a != null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13421 | more = drawAnimation(parent, drawingTime, a, scalingRequired); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13422 | concatMatrix = a.willChangeTransformationMatrix(); |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13423 | if (concatMatrix) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13424 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13425 | } |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13426 | transformToApply = parent.mChildTransformation; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13427 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13428 | if ((mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_TRANSFORM) == PFLAG3_VIEW_IS_ANIMATING_TRANSFORM && |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13429 | mDisplayList != null) { |
| 13430 | // No longer animating: clear out old animation matrix |
| 13431 | mDisplayList.setAnimationMatrix(null); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13432 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_TRANSFORM; |
Chet Haase | afd5c3e | 2012-05-10 13:21:10 -0700 | [diff] [blame] | 13433 | } |
| 13434 | if (!useDisplayListProperties && |
| 13435 | (flags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 13436 | final boolean hasTransform = |
| 13437 | parent.getChildStaticTransformation(this, parent.mChildTransformation); |
| 13438 | if (hasTransform) { |
| 13439 | final int transformType = parent.mChildTransformation.getTransformationType(); |
| 13440 | transformToApply = transformType != Transformation.TYPE_IDENTITY ? |
| 13441 | parent.mChildTransformation : null; |
| 13442 | concatMatrix = (transformType & Transformation.TYPE_MATRIX) != 0; |
| 13443 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13444 | } |
| 13445 | } |
| 13446 | |
| 13447 | concatMatrix |= !childHasIdentityMatrix; |
| 13448 | |
| 13449 | // Sets the flag as early as possible to allow draw() implementations |
| 13450 | // to call invalidate() successfully when doing animations |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13451 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13452 | |
Romain Guy | fbb4321 | 2012-08-30 15:19:27 -0700 | [diff] [blame] | 13453 | if (!concatMatrix && |
| 13454 | (flags & (ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS | |
| 13455 | ViewGroup.FLAG_CLIP_CHILDREN)) == ViewGroup.FLAG_CLIP_CHILDREN && |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 13456 | canvas.quickReject(mLeft, mTop, mRight, mBottom, Canvas.EdgeType.BW) && |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13457 | (mPrivateFlags & PFLAG_DRAW_ANIMATION) == 0) { |
| 13458 | mPrivateFlags2 |= PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13459 | return more; |
| 13460 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13461 | mPrivateFlags2 &= ~PFLAG2_VIEW_QUICK_REJECTED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13462 | |
| 13463 | if (hardwareAccelerated) { |
| 13464 | // Clear INVALIDATED flag to allow invalidation to occur during rendering, but |
| 13465 | // retain the flag's value temporarily in the mRecreateDisplayList flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13466 | mRecreateDisplayList = (mPrivateFlags & PFLAG_INVALIDATED) == PFLAG_INVALIDATED; |
| 13467 | mPrivateFlags &= ~PFLAG_INVALIDATED; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13468 | } |
| 13469 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13470 | DisplayList displayList = null; |
| 13471 | Bitmap cache = null; |
| 13472 | boolean hasDisplayList = false; |
| 13473 | if (caching) { |
| 13474 | if (!hardwareAccelerated) { |
| 13475 | if (layerType != LAYER_TYPE_NONE) { |
| 13476 | layerType = LAYER_TYPE_SOFTWARE; |
| 13477 | buildDrawingCache(true); |
| 13478 | } |
| 13479 | cache = getDrawingCache(true); |
| 13480 | } else { |
| 13481 | switch (layerType) { |
| 13482 | case LAYER_TYPE_SOFTWARE: |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 13483 | if (useDisplayListProperties) { |
| 13484 | hasDisplayList = canHaveDisplayList(); |
| 13485 | } else { |
| 13486 | buildDrawingCache(true); |
| 13487 | cache = getDrawingCache(true); |
| 13488 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13489 | break; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13490 | case LAYER_TYPE_HARDWARE: |
| 13491 | if (useDisplayListProperties) { |
| 13492 | hasDisplayList = canHaveDisplayList(); |
| 13493 | } |
| 13494 | break; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13495 | case LAYER_TYPE_NONE: |
| 13496 | // Delay getting the display list until animation-driven alpha values are |
| 13497 | // set up and possibly passed on to the view |
| 13498 | hasDisplayList = canHaveDisplayList(); |
| 13499 | break; |
| 13500 | } |
| 13501 | } |
| 13502 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13503 | useDisplayListProperties &= hasDisplayList; |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13504 | if (useDisplayListProperties) { |
| 13505 | displayList = getDisplayList(); |
| 13506 | if (!displayList.isValid()) { |
| 13507 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13508 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13509 | // try to use it again. |
| 13510 | displayList = null; |
| 13511 | hasDisplayList = false; |
| 13512 | useDisplayListProperties = false; |
| 13513 | } |
| 13514 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13515 | |
Chet Haase | 526057b | 2012-07-12 17:50:41 -0700 | [diff] [blame] | 13516 | int sx = 0; |
| 13517 | int sy = 0; |
| 13518 | if (!hasDisplayList) { |
| 13519 | computeScroll(); |
| 13520 | sx = mScrollX; |
| 13521 | sy = mScrollY; |
| 13522 | } |
| 13523 | |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13524 | final boolean hasNoCache = cache == null || hasDisplayList; |
| 13525 | final boolean offsetForScroll = cache == null && !hasDisplayList && |
| 13526 | layerType != LAYER_TYPE_HARDWARE; |
| 13527 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13528 | int restoreTo = -1; |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13529 | if (!useDisplayListProperties || transformToApply != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13530 | restoreTo = canvas.save(); |
| 13531 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13532 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13533 | canvas.translate(mLeft - sx, mTop - sy); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13534 | } else { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13535 | if (!useDisplayListProperties) { |
| 13536 | canvas.translate(mLeft, mTop); |
| 13537 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13538 | if (scalingRequired) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13539 | if (useDisplayListProperties) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13540 | // TODO: Might not need this if we put everything inside the DL |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13541 | restoreTo = canvas.save(); |
| 13542 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13543 | // mAttachInfo cannot be null, otherwise scalingRequired == false |
| 13544 | final float scale = 1.0f / mAttachInfo.mApplicationScale; |
| 13545 | canvas.scale(scale, scale); |
| 13546 | } |
| 13547 | } |
| 13548 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13549 | float alpha = useDisplayListProperties ? 1 : getAlpha(); |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13550 | if (transformToApply != null || alpha < 1 || !hasIdentityMatrix() || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13551 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13552 | if (transformToApply != null || !childHasIdentityMatrix) { |
| 13553 | int transX = 0; |
| 13554 | int transY = 0; |
| 13555 | |
| 13556 | if (offsetForScroll) { |
| 13557 | transX = -sx; |
| 13558 | transY = -sy; |
| 13559 | } |
| 13560 | |
| 13561 | if (transformToApply != null) { |
| 13562 | if (concatMatrix) { |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13563 | if (useDisplayListProperties) { |
| 13564 | displayList.setAnimationMatrix(transformToApply.getMatrix()); |
| 13565 | } else { |
| 13566 | // Undo the scroll translation, apply the transformation matrix, |
| 13567 | // then redo the scroll translate to get the correct result. |
| 13568 | canvas.translate(-transX, -transY); |
| 13569 | canvas.concat(transformToApply.getMatrix()); |
| 13570 | canvas.translate(transX, transY); |
| 13571 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13572 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13573 | } |
| 13574 | |
| 13575 | float transformAlpha = transformToApply.getAlpha(); |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13576 | if (transformAlpha < 1) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13577 | alpha *= transformAlpha; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13578 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13579 | } |
| 13580 | } |
| 13581 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13582 | if (!childHasIdentityMatrix && !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13583 | canvas.translate(-transX, -transY); |
| 13584 | canvas.concat(getMatrix()); |
| 13585 | canvas.translate(transX, transY); |
| 13586 | } |
| 13587 | } |
| 13588 | |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13589 | // Deal with alpha if it is or used to be <1 |
| 13590 | if (alpha < 1 || |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13591 | (mPrivateFlags3 & PFLAG3_VIEW_IS_ANIMATING_ALPHA) == PFLAG3_VIEW_IS_ANIMATING_ALPHA) { |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13592 | if (alpha < 1) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13593 | mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13594 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13595 | mPrivateFlags3 &= ~PFLAG3_VIEW_IS_ANIMATING_ALPHA; |
Chet Haase | 2143337 | 2012-06-05 07:54:09 -0700 | [diff] [blame] | 13596 | } |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13597 | parent.mGroupFlags |= ViewGroup.FLAG_CLEAR_TRANSFORMATION; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13598 | if (hasNoCache) { |
| 13599 | final int multipliedAlpha = (int) (255 * alpha); |
| 13600 | if (!onSetAlpha(multipliedAlpha)) { |
| 13601 | int layerFlags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13602 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) != 0 || |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13603 | layerType != LAYER_TYPE_NONE) { |
| 13604 | layerFlags |= Canvas.CLIP_TO_LAYER_SAVE_FLAG; |
| 13605 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13606 | if (useDisplayListProperties) { |
| 13607 | displayList.setAlpha(alpha * getAlpha()); |
| 13608 | } else if (layerType == LAYER_TYPE_NONE) { |
Chet Haase | 89b7f2e | 2012-03-21 11:15:37 -0700 | [diff] [blame] | 13609 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13610 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13611 | canvas.saveLayerAlpha(scrollX, scrollY, scrollX + mRight - mLeft, |
| 13612 | scrollY + mBottom - mTop, multipliedAlpha, layerFlags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13613 | } |
| 13614 | } else { |
| 13615 | // Alpha is handled by the child directly, clobber the layer's alpha |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13616 | mPrivateFlags |= PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13617 | } |
| 13618 | } |
| 13619 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13620 | } else if ((mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13621 | onSetAlpha(255); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13622 | mPrivateFlags &= ~PFLAG_ALPHA_SET; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13623 | } |
| 13624 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13625 | if ((flags & ViewGroup.FLAG_CLIP_CHILDREN) == ViewGroup.FLAG_CLIP_CHILDREN && |
| 13626 | !useDisplayListProperties) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13627 | if (offsetForScroll) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13628 | canvas.clipRect(sx, sy, sx + (mRight - mLeft), sy + (mBottom - mTop)); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13629 | } else { |
| 13630 | if (!scalingRequired || cache == null) { |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13631 | canvas.clipRect(0, 0, mRight - mLeft, mBottom - mTop); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13632 | } else { |
| 13633 | canvas.clipRect(0, 0, cache.getWidth(), cache.getHeight()); |
| 13634 | } |
| 13635 | } |
| 13636 | } |
| 13637 | |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13638 | if (!useDisplayListProperties && hasDisplayList) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13639 | displayList = getDisplayList(); |
| 13640 | if (!displayList.isValid()) { |
| 13641 | // Uncommon, but possible. If a view is removed from the hierarchy during the call |
| 13642 | // to getDisplayList(), the display list will be marked invalid and we should not |
| 13643 | // try to use it again. |
| 13644 | displayList = null; |
| 13645 | hasDisplayList = false; |
| 13646 | } |
| 13647 | } |
| 13648 | |
| 13649 | if (hasNoCache) { |
| 13650 | boolean layerRendered = false; |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13651 | if (layerType == LAYER_TYPE_HARDWARE && !useDisplayListProperties) { |
Michael Jurka | 7e52caf | 2012-03-06 15:57:06 -0800 | [diff] [blame] | 13652 | final HardwareLayer layer = getHardwareLayer(); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13653 | if (layer != null && layer.isValid()) { |
| 13654 | mLayerPaint.setAlpha((int) (alpha * 255)); |
| 13655 | ((HardwareCanvas) canvas).drawHardwareLayer(layer, 0, 0, mLayerPaint); |
| 13656 | layerRendered = true; |
| 13657 | } else { |
| 13658 | final int scrollX = hasDisplayList ? 0 : sx; |
| 13659 | final int scrollY = hasDisplayList ? 0 : sy; |
| 13660 | canvas.saveLayer(scrollX, scrollY, |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 13661 | scrollX + mRight - mLeft, scrollY + mBottom - mTop, mLayerPaint, |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13662 | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG); |
| 13663 | } |
| 13664 | } |
| 13665 | |
| 13666 | if (!layerRendered) { |
| 13667 | if (!hasDisplayList) { |
| 13668 | // Fast path for layouts with no backgrounds |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13669 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) { |
| 13670 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13671 | dispatchDraw(canvas); |
| 13672 | } else { |
| 13673 | draw(canvas); |
| 13674 | } |
| 13675 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13676 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 13677 | ((HardwareCanvas) canvas).drawDisplayList(displayList, null, flags); |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13678 | } |
| 13679 | } |
| 13680 | } else if (cache != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13681 | mPrivateFlags &= ~PFLAG_DIRTY_MASK; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13682 | Paint cachePaint; |
| 13683 | |
| 13684 | if (layerType == LAYER_TYPE_NONE) { |
| 13685 | cachePaint = parent.mCachePaint; |
| 13686 | if (cachePaint == null) { |
| 13687 | cachePaint = new Paint(); |
| 13688 | cachePaint.setDither(false); |
| 13689 | parent.mCachePaint = cachePaint; |
| 13690 | } |
Chet Haase | 9420abd | 2012-03-29 16:28:32 -0700 | [diff] [blame] | 13691 | if (alpha < 1) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13692 | cachePaint.setAlpha((int) (alpha * 255)); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13693 | parent.mGroupFlags |= ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
| 13694 | } else if ((flags & ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE) != 0) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13695 | cachePaint.setAlpha(255); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13696 | parent.mGroupFlags &= ~ViewGroup.FLAG_ALPHA_LOWER_THAN_ONE; |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13697 | } |
| 13698 | } else { |
| 13699 | cachePaint = mLayerPaint; |
| 13700 | cachePaint.setAlpha((int) (alpha * 255)); |
| 13701 | } |
| 13702 | canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint); |
| 13703 | } |
| 13704 | |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 13705 | if (restoreTo >= 0) { |
| 13706 | canvas.restoreToCount(restoreTo); |
| 13707 | } |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13708 | |
| 13709 | if (a != null && !more) { |
| 13710 | if (!hardwareAccelerated && !a.getFillAfter()) { |
| 13711 | onSetAlpha(255); |
| 13712 | } |
| 13713 | parent.finishAnimatingView(this, a); |
| 13714 | } |
| 13715 | |
| 13716 | if (more && hardwareAccelerated) { |
| 13717 | // invalidation is the trigger to recreate display lists, so if we're using |
| 13718 | // display lists to render, force an invalidate to allow the animation to |
| 13719 | // continue drawing another frame |
| 13720 | parent.invalidate(true); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13721 | if (a.hasAlpha() && (mPrivateFlags & PFLAG_ALPHA_SET) == PFLAG_ALPHA_SET) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 13722 | // alpha animations should cause the child to recreate its display list |
| 13723 | invalidate(true); |
| 13724 | } |
| 13725 | } |
| 13726 | |
| 13727 | mRecreateDisplayList = false; |
| 13728 | |
| 13729 | return more; |
| 13730 | } |
| 13731 | |
| 13732 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13733 | * Manually render this view (and all of its children) to the given Canvas. |
| 13734 | * 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] | 13735 | * called. When implementing a view, implement |
| 13736 | * {@link #onDraw(android.graphics.Canvas)} instead of overriding this method. |
| 13737 | * 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] | 13738 | * |
| 13739 | * @param canvas The Canvas to which the View is rendered. |
| 13740 | */ |
| 13741 | public void draw(Canvas canvas) { |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13742 | final int privateFlags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13743 | final boolean dirtyOpaque = (privateFlags & PFLAG_DIRTY_MASK) == PFLAG_DIRTY_OPAQUE && |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 13744 | (mAttachInfo == null || !mAttachInfo.mIgnoreDirtyState); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 13745 | mPrivateFlags = (privateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13747 | /* |
| 13748 | * Draw traversal performs several drawing steps which must be executed |
| 13749 | * in the appropriate order: |
| 13750 | * |
| 13751 | * 1. Draw the background |
| 13752 | * 2. If necessary, save the canvas' layers to prepare for fading |
| 13753 | * 3. Draw view's content |
| 13754 | * 4. Draw children |
| 13755 | * 5. If necessary, draw the fading edges and restore layers |
| 13756 | * 6. Draw decorations (scrollbars for instance) |
| 13757 | */ |
| 13758 | |
| 13759 | // Step 1, draw the background, if needed |
| 13760 | int saveCount; |
| 13761 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13762 | if (!dirtyOpaque) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13763 | final Drawable background = mBackground; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13764 | if (background != null) { |
| 13765 | final int scrollX = mScrollX; |
| 13766 | final int scrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13767 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13768 | if (mBackgroundSizeChanged) { |
| 13769 | background.setBounds(0, 0, mRight - mLeft, mBottom - mTop); |
| 13770 | mBackgroundSizeChanged = false; |
| 13771 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13772 | |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13773 | if ((scrollX | scrollY) == 0) { |
| 13774 | background.draw(canvas); |
| 13775 | } else { |
| 13776 | canvas.translate(scrollX, scrollY); |
| 13777 | background.draw(canvas); |
| 13778 | canvas.translate(-scrollX, -scrollY); |
| 13779 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13780 | } |
| 13781 | } |
| 13782 | |
| 13783 | // skip step 2 & 5 if possible (common case) |
| 13784 | final int viewFlags = mViewFlags; |
| 13785 | boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0; |
| 13786 | boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0; |
| 13787 | if (!verticalEdges && !horizontalEdges) { |
| 13788 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13789 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13790 | |
| 13791 | // Step 4, draw the children |
| 13792 | dispatchDraw(canvas); |
| 13793 | |
| 13794 | // Step 6, draw decorations (scrollbars) |
| 13795 | onDrawScrollBars(canvas); |
| 13796 | |
| 13797 | // we're done... |
| 13798 | return; |
| 13799 | } |
| 13800 | |
| 13801 | /* |
| 13802 | * Here we do the full fledged routine... |
| 13803 | * (this is an uncommon case where speed matters less, |
| 13804 | * this is why we repeat some of the tests that have been |
| 13805 | * done above) |
| 13806 | */ |
| 13807 | |
| 13808 | boolean drawTop = false; |
| 13809 | boolean drawBottom = false; |
| 13810 | boolean drawLeft = false; |
| 13811 | boolean drawRight = false; |
| 13812 | |
| 13813 | float topFadeStrength = 0.0f; |
| 13814 | float bottomFadeStrength = 0.0f; |
| 13815 | float leftFadeStrength = 0.0f; |
| 13816 | float rightFadeStrength = 0.0f; |
| 13817 | |
| 13818 | // Step 2, save the canvas' layers |
| 13819 | int paddingLeft = mPaddingLeft; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13820 | |
| 13821 | final boolean offsetRequired = isPaddingOffsetRequired(); |
| 13822 | if (offsetRequired) { |
| 13823 | paddingLeft += getLeftPaddingOffset(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13824 | } |
| 13825 | |
| 13826 | int left = mScrollX + paddingLeft; |
| 13827 | int right = left + mRight - mLeft - mPaddingRight - paddingLeft; |
Romain Guy | f2fc460 | 2011-07-19 15:20:03 -0700 | [diff] [blame] | 13828 | int top = mScrollY + getFadeTop(offsetRequired); |
| 13829 | int bottom = top + getFadeHeight(offsetRequired); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13830 | |
| 13831 | if (offsetRequired) { |
| 13832 | right += getRightPaddingOffset(); |
| 13833 | bottom += getBottomPaddingOffset(); |
| 13834 | } |
| 13835 | |
| 13836 | final ScrollabilityCache scrollabilityCache = mScrollCache; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13837 | final float fadeHeight = scrollabilityCache.fadingEdgeLength; |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13838 | int length = (int) fadeHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13839 | |
| 13840 | // clip the fade length if top and bottom fades overlap |
| 13841 | // overlapping fades produce odd-looking artifacts |
| 13842 | if (verticalEdges && (top + length > bottom - length)) { |
| 13843 | length = (bottom - top) / 2; |
| 13844 | } |
| 13845 | |
| 13846 | // also clip horizontal fades if necessary |
| 13847 | if (horizontalEdges && (left + length > right - length)) { |
| 13848 | length = (right - left) / 2; |
| 13849 | } |
| 13850 | |
| 13851 | if (verticalEdges) { |
| 13852 | topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13853 | drawTop = topFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13854 | bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13855 | drawBottom = bottomFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13856 | } |
| 13857 | |
| 13858 | if (horizontalEdges) { |
| 13859 | leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13860 | drawLeft = leftFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13861 | rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength())); |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13862 | drawRight = rightFadeStrength * fadeHeight > 1.0f; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13863 | } |
| 13864 | |
| 13865 | saveCount = canvas.getSaveCount(); |
| 13866 | |
| 13867 | int solidColor = getSolidColor(); |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 13868 | if (solidColor == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13869 | final int flags = Canvas.HAS_ALPHA_LAYER_SAVE_FLAG; |
| 13870 | |
| 13871 | if (drawTop) { |
| 13872 | canvas.saveLayer(left, top, right, top + length, null, flags); |
| 13873 | } |
| 13874 | |
| 13875 | if (drawBottom) { |
| 13876 | canvas.saveLayer(left, bottom - length, right, bottom, null, flags); |
| 13877 | } |
| 13878 | |
| 13879 | if (drawLeft) { |
| 13880 | canvas.saveLayer(left, top, left + length, bottom, null, flags); |
| 13881 | } |
| 13882 | |
| 13883 | if (drawRight) { |
| 13884 | canvas.saveLayer(right - length, top, right, bottom, null, flags); |
| 13885 | } |
| 13886 | } else { |
| 13887 | scrollabilityCache.setFadeColor(solidColor); |
| 13888 | } |
| 13889 | |
| 13890 | // Step 3, draw the content |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 13891 | if (!dirtyOpaque) onDraw(canvas); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13892 | |
| 13893 | // Step 4, draw the children |
| 13894 | dispatchDraw(canvas); |
| 13895 | |
| 13896 | // Step 5, draw the fade effect and restore layers |
| 13897 | final Paint p = scrollabilityCache.paint; |
| 13898 | final Matrix matrix = scrollabilityCache.matrix; |
| 13899 | final Shader fade = scrollabilityCache.shader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13900 | |
| 13901 | if (drawTop) { |
| 13902 | matrix.setScale(1, fadeHeight * topFadeStrength); |
| 13903 | matrix.postTranslate(left, top); |
| 13904 | fade.setLocalMatrix(matrix); |
| 13905 | canvas.drawRect(left, top, right, top + length, p); |
| 13906 | } |
| 13907 | |
| 13908 | if (drawBottom) { |
| 13909 | matrix.setScale(1, fadeHeight * bottomFadeStrength); |
| 13910 | matrix.postRotate(180); |
| 13911 | matrix.postTranslate(left, bottom); |
| 13912 | fade.setLocalMatrix(matrix); |
| 13913 | canvas.drawRect(left, bottom - length, right, bottom, p); |
| 13914 | } |
| 13915 | |
| 13916 | if (drawLeft) { |
| 13917 | matrix.setScale(1, fadeHeight * leftFadeStrength); |
| 13918 | matrix.postRotate(-90); |
| 13919 | matrix.postTranslate(left, top); |
| 13920 | fade.setLocalMatrix(matrix); |
| 13921 | canvas.drawRect(left, top, left + length, bottom, p); |
| 13922 | } |
| 13923 | |
| 13924 | if (drawRight) { |
| 13925 | matrix.setScale(1, fadeHeight * rightFadeStrength); |
| 13926 | matrix.postRotate(90); |
| 13927 | matrix.postTranslate(right, top); |
| 13928 | fade.setLocalMatrix(matrix); |
| 13929 | canvas.drawRect(right - length, top, right, bottom, p); |
| 13930 | } |
| 13931 | |
| 13932 | canvas.restoreToCount(saveCount); |
| 13933 | |
| 13934 | // Step 6, draw decorations (scrollbars) |
| 13935 | onDrawScrollBars(canvas); |
| 13936 | } |
| 13937 | |
| 13938 | /** |
| 13939 | * Override this if your view is known to always be drawn on top of a solid color background, |
| 13940 | * and needs to draw fading edges. Returning a non-zero color enables the view system to |
| 13941 | * optimize the drawing of the fading edges. If you do return a non-zero color, the alpha |
| 13942 | * should be set to 0xFF. |
| 13943 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 13944 | * @see #setVerticalFadingEdgeEnabled(boolean) |
| 13945 | * @see #setHorizontalFadingEdgeEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13946 | * |
| 13947 | * @return The known solid color background for this view, or 0 if the color may vary |
| 13948 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 13949 | @ViewDebug.ExportedProperty(category = "drawing") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 13950 | public int getSolidColor() { |
| 13951 | return 0; |
| 13952 | } |
| 13953 | |
| 13954 | /** |
| 13955 | * Build a human readable string representation of the specified view flags. |
| 13956 | * |
| 13957 | * @param flags the view flags to convert to a string |
| 13958 | * @return a String representing the supplied flags |
| 13959 | */ |
| 13960 | private static String printFlags(int flags) { |
| 13961 | String output = ""; |
| 13962 | int numFlags = 0; |
| 13963 | if ((flags & FOCUSABLE_MASK) == FOCUSABLE) { |
| 13964 | output += "TAKES_FOCUS"; |
| 13965 | numFlags++; |
| 13966 | } |
| 13967 | |
| 13968 | switch (flags & VISIBILITY_MASK) { |
| 13969 | case INVISIBLE: |
| 13970 | if (numFlags > 0) { |
| 13971 | output += " "; |
| 13972 | } |
| 13973 | output += "INVISIBLE"; |
| 13974 | // USELESS HERE numFlags++; |
| 13975 | break; |
| 13976 | case GONE: |
| 13977 | if (numFlags > 0) { |
| 13978 | output += " "; |
| 13979 | } |
| 13980 | output += "GONE"; |
| 13981 | // USELESS HERE numFlags++; |
| 13982 | break; |
| 13983 | default: |
| 13984 | break; |
| 13985 | } |
| 13986 | return output; |
| 13987 | } |
| 13988 | |
| 13989 | /** |
| 13990 | * Build a human readable string representation of the specified private |
| 13991 | * view flags. |
| 13992 | * |
| 13993 | * @param privateFlags the private view flags to convert to a string |
| 13994 | * @return a String representing the supplied flags |
| 13995 | */ |
| 13996 | private static String printPrivateFlags(int privateFlags) { |
| 13997 | String output = ""; |
| 13998 | int numFlags = 0; |
| 13999 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14000 | if ((privateFlags & PFLAG_WANTS_FOCUS) == PFLAG_WANTS_FOCUS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14001 | output += "WANTS_FOCUS"; |
| 14002 | numFlags++; |
| 14003 | } |
| 14004 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14005 | if ((privateFlags & PFLAG_FOCUSED) == PFLAG_FOCUSED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14006 | if (numFlags > 0) { |
| 14007 | output += " "; |
| 14008 | } |
| 14009 | output += "FOCUSED"; |
| 14010 | numFlags++; |
| 14011 | } |
| 14012 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14013 | if ((privateFlags & PFLAG_SELECTED) == PFLAG_SELECTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14014 | if (numFlags > 0) { |
| 14015 | output += " "; |
| 14016 | } |
| 14017 | output += "SELECTED"; |
| 14018 | numFlags++; |
| 14019 | } |
| 14020 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14021 | 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] | 14022 | if (numFlags > 0) { |
| 14023 | output += " "; |
| 14024 | } |
| 14025 | output += "IS_ROOT_NAMESPACE"; |
| 14026 | numFlags++; |
| 14027 | } |
| 14028 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14029 | if ((privateFlags & PFLAG_HAS_BOUNDS) == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14030 | if (numFlags > 0) { |
| 14031 | output += " "; |
| 14032 | } |
| 14033 | output += "HAS_BOUNDS"; |
| 14034 | numFlags++; |
| 14035 | } |
| 14036 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14037 | if ((privateFlags & PFLAG_DRAWN) == PFLAG_DRAWN) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14038 | if (numFlags > 0) { |
| 14039 | output += " "; |
| 14040 | } |
| 14041 | output += "DRAWN"; |
| 14042 | // USELESS HERE numFlags++; |
| 14043 | } |
| 14044 | return output; |
| 14045 | } |
| 14046 | |
| 14047 | /** |
| 14048 | * <p>Indicates whether or not this view's layout will be requested during |
| 14049 | * the next hierarchy layout pass.</p> |
| 14050 | * |
| 14051 | * @return true if the layout will be forced during next layout pass |
| 14052 | */ |
| 14053 | public boolean isLayoutRequested() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14054 | return (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14055 | } |
| 14056 | |
| 14057 | /** |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14058 | * Return true if o is a ViewGroup that is laying out using optical bounds. |
| 14059 | * @hide |
| 14060 | */ |
| 14061 | public static boolean isLayoutModeOptical(Object o) { |
| 14062 | return o instanceof ViewGroup && ((ViewGroup) o).isLayoutModeOptical(); |
| 14063 | } |
| 14064 | |
| 14065 | private boolean setOpticalFrame(int left, int top, int right, int bottom) { |
| 14066 | Insets parentInsets = mParent instanceof View ? |
| 14067 | ((View) mParent).getOpticalInsets() : Insets.NONE; |
| 14068 | Insets childInsets = getOpticalInsets(); |
| 14069 | return setFrame( |
| 14070 | left + parentInsets.left - childInsets.left, |
| 14071 | top + parentInsets.top - childInsets.top, |
| 14072 | right + parentInsets.left + childInsets.right, |
| 14073 | bottom + parentInsets.top + childInsets.bottom); |
| 14074 | } |
| 14075 | |
| 14076 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14077 | * Assign a size and position to a view and all of its |
| 14078 | * descendants |
| 14079 | * |
| 14080 | * <p>This is the second phase of the layout mechanism. |
| 14081 | * (The first is measuring). In this phase, each parent calls |
| 14082 | * layout on all of its children to position them. |
| 14083 | * This is typically done using the child measurements |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14084 | * that were stored in the measure pass().</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14085 | * |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14086 | * <p>Derived classes should not override this method. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14087 | * Derived classes with children should override |
| 14088 | * onLayout. In that method, they should |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14089 | * call layout on each of their children.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14090 | * |
| 14091 | * @param l Left position, relative to parent |
| 14092 | * @param t Top position, relative to parent |
| 14093 | * @param r Right position, relative to parent |
| 14094 | * @param b Bottom position, relative to parent |
| 14095 | */ |
Romain Guy | 5429e1d | 2010-09-07 12:38:00 -0700 | [diff] [blame] | 14096 | @SuppressWarnings({"unchecked"}) |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 14097 | public void layout(int l, int t, int r, int b) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14098 | int oldL = mLeft; |
| 14099 | int oldT = mTop; |
| 14100 | int oldB = mBottom; |
| 14101 | int oldR = mRight; |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14102 | boolean changed = isLayoutModeOptical(mParent) ? |
| 14103 | setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14104 | if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14105 | onLayout(changed, l, t, r, b); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14106 | mPrivateFlags &= ~PFLAG_LAYOUT_REQUIRED; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14107 | |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14108 | ListenerInfo li = mListenerInfo; |
| 14109 | if (li != null && li.mOnLayoutChangeListeners != null) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14110 | ArrayList<OnLayoutChangeListener> listenersCopy = |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 14111 | (ArrayList<OnLayoutChangeListener>)li.mOnLayoutChangeListeners.clone(); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14112 | int numListeners = listenersCopy.size(); |
| 14113 | for (int i = 0; i < numListeners; ++i) { |
Chet Haase | 7c608f2 | 2010-10-22 17:54:04 -0700 | [diff] [blame] | 14114 | 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] | 14115 | } |
| 14116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14117 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14118 | mPrivateFlags &= ~PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14119 | } |
| 14120 | |
| 14121 | /** |
| 14122 | * Called from layout when this view should |
| 14123 | * assign a size and position to each of its children. |
| 14124 | * |
| 14125 | * Derived classes with children should override |
| 14126 | * this method and call layout on each of |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 14127 | * their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14128 | * @param changed This is a new size or position for this view |
| 14129 | * @param left Left position, relative to parent |
| 14130 | * @param top Top position, relative to parent |
| 14131 | * @param right Right position, relative to parent |
| 14132 | * @param bottom Bottom position, relative to parent |
| 14133 | */ |
| 14134 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 14135 | } |
| 14136 | |
| 14137 | /** |
| 14138 | * Assign a size and position to this view. |
| 14139 | * |
| 14140 | * This is called from layout. |
| 14141 | * |
| 14142 | * @param left Left position, relative to parent |
| 14143 | * @param top Top position, relative to parent |
| 14144 | * @param right Right position, relative to parent |
| 14145 | * @param bottom Bottom position, relative to parent |
| 14146 | * @return true if the new size and position are different than the |
| 14147 | * previous ones |
| 14148 | * {@hide} |
| 14149 | */ |
| 14150 | protected boolean setFrame(int left, int top, int right, int bottom) { |
| 14151 | boolean changed = false; |
| 14152 | |
| 14153 | if (DBG) { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 14154 | Log.d("View", this + " View.setFrame(" + left + "," + top + "," |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14155 | + right + "," + bottom + ")"); |
| 14156 | } |
| 14157 | |
| 14158 | if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) { |
| 14159 | changed = true; |
| 14160 | |
| 14161 | // Remember our drawn bit |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14162 | int drawn = mPrivateFlags & PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14164 | int oldWidth = mRight - mLeft; |
| 14165 | int oldHeight = mBottom - mTop; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14166 | int newWidth = right - left; |
| 14167 | int newHeight = bottom - top; |
| 14168 | boolean sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight); |
| 14169 | |
| 14170 | // Invalidate our old position |
| 14171 | invalidate(sizeChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14172 | |
| 14173 | mLeft = left; |
| 14174 | mTop = top; |
| 14175 | mRight = right; |
| 14176 | mBottom = bottom; |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 14177 | if (mDisplayList != null) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 14178 | mDisplayList.setLeftTopRightBottom(mLeft, mTop, mRight, mBottom); |
| 14179 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14180 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14181 | mPrivateFlags |= PFLAG_HAS_BOUNDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14183 | |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14184 | if (sizeChanged) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14185 | if ((mPrivateFlags & PFLAG_PIVOT_EXPLICITLY_SET) == 0) { |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14186 | // A change in dimension means an auto-centered pivot point changes, too |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 14187 | if (mTransformationInfo != null) { |
| 14188 | mTransformationInfo.mMatrixDirty = true; |
| 14189 | } |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14191 | onSizeChanged(newWidth, newHeight, oldWidth, oldHeight); |
| 14192 | } |
| 14193 | |
| 14194 | if ((mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 14195 | // If we are visible, force the DRAWN bit to on so that |
| 14196 | // this invalidate will go through (at least to our parent). |
| 14197 | // This is because someone may have invalidated this view |
Chet Haase | 6c7ad5d | 2010-12-28 08:40:00 -0800 | [diff] [blame] | 14198 | // before this call to setFrame came in, thereby clearing |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14199 | // the DRAWN bit. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14200 | mPrivateFlags |= PFLAG_DRAWN; |
Chet Haase | 75755e2 | 2011-07-18 17:48:25 -0700 | [diff] [blame] | 14201 | invalidate(sizeChanged); |
Chet Haase | f28595e | 2011-01-31 18:52:12 -0800 | [diff] [blame] | 14202 | // parent display list may need to be recreated based on a change in the bounds |
| 14203 | // of any child |
| 14204 | invalidateParentCaches(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14205 | } |
| 14206 | |
| 14207 | // Reset drawn bit to original value (invalidate turns it off) |
| 14208 | mPrivateFlags |= drawn; |
| 14209 | |
| 14210 | mBackgroundSizeChanged = true; |
| 14211 | } |
| 14212 | return changed; |
| 14213 | } |
| 14214 | |
| 14215 | /** |
| 14216 | * Finalize inflating a view from XML. This is called as the last phase |
| 14217 | * of inflation, after all child views have been added. |
| 14218 | * |
| 14219 | * <p>Even if the subclass overrides onFinishInflate, they should always be |
| 14220 | * sure to call the super method, so that we get called. |
| 14221 | */ |
| 14222 | protected void onFinishInflate() { |
| 14223 | } |
| 14224 | |
| 14225 | /** |
| 14226 | * Returns the resources associated with this view. |
| 14227 | * |
| 14228 | * @return Resources object. |
| 14229 | */ |
| 14230 | public Resources getResources() { |
| 14231 | return mResources; |
| 14232 | } |
| 14233 | |
| 14234 | /** |
| 14235 | * Invalidates the specified Drawable. |
| 14236 | * |
| 14237 | * @param drawable the drawable to invalidate |
| 14238 | */ |
| 14239 | public void invalidateDrawable(Drawable drawable) { |
| 14240 | if (verifyDrawable(drawable)) { |
| 14241 | final Rect dirty = drawable.getBounds(); |
| 14242 | final int scrollX = mScrollX; |
| 14243 | final int scrollY = mScrollY; |
| 14244 | |
| 14245 | invalidate(dirty.left + scrollX, dirty.top + scrollY, |
| 14246 | dirty.right + scrollX, dirty.bottom + scrollY); |
| 14247 | } |
| 14248 | } |
| 14249 | |
| 14250 | /** |
| 14251 | * Schedules an action on a drawable to occur at a specified time. |
| 14252 | * |
| 14253 | * @param who the recipient of the action |
| 14254 | * @param what the action to run on the drawable |
| 14255 | * @param when the time at which the action must occur. Uses the |
| 14256 | * {@link SystemClock#uptimeMillis} timebase. |
| 14257 | */ |
| 14258 | public void scheduleDrawable(Drawable who, Runnable what, long when) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14259 | if (verifyDrawable(who) && what != null) { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14260 | final long delay = when - SystemClock.uptimeMillis(); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14261 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14262 | mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed( |
| 14263 | Choreographer.CALLBACK_ANIMATION, what, who, |
| 14264 | Choreographer.subtractFrameDelay(delay)); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14265 | } else { |
Jeff Brown | 7ae9d5f | 2012-03-05 19:33:49 -0800 | [diff] [blame] | 14266 | ViewRootImpl.getRunQueue().postDelayed(what, delay); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14268 | } |
| 14269 | } |
| 14270 | |
| 14271 | /** |
| 14272 | * Cancels a scheduled action on a drawable. |
| 14273 | * |
| 14274 | * @param who the recipient of the action |
| 14275 | * @param what the action to cancel |
| 14276 | */ |
| 14277 | public void unscheduleDrawable(Drawable who, Runnable what) { |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14278 | if (verifyDrawable(who) && what != null) { |
| 14279 | if (mAttachInfo != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14280 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14281 | Choreographer.CALLBACK_ANIMATION, what, who); |
Adam Powell | 37419d7 | 2011-11-10 11:32:09 -0800 | [diff] [blame] | 14282 | } else { |
| 14283 | ViewRootImpl.getRunQueue().removeCallbacks(what); |
| 14284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14285 | } |
| 14286 | } |
| 14287 | |
| 14288 | /** |
| 14289 | * Unschedule any events associated with the given Drawable. This can be |
| 14290 | * used when selecting a new Drawable into a view, so that the previous |
| 14291 | * one is completely unscheduled. |
| 14292 | * |
| 14293 | * @param who The Drawable to unschedule. |
| 14294 | * |
| 14295 | * @see #drawableStateChanged |
| 14296 | */ |
| 14297 | public void unscheduleDrawable(Drawable who) { |
Jeff Brown | 43ea54b | 2012-03-09 14:37:48 -0800 | [diff] [blame] | 14298 | if (mAttachInfo != null && who != null) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 14299 | mAttachInfo.mViewRootImpl.mChoreographer.removeCallbacks( |
| 14300 | Choreographer.CALLBACK_ANIMATION, null, who); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14301 | } |
| 14302 | } |
| 14303 | |
Fabrice Di Meglio | c005322 | 2011-06-13 12:16:51 -0700 | [diff] [blame] | 14304 | /** |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14305 | * Resolve the Drawables depending on the layout direction. This is implicitly supposing |
| 14306 | * that the View directionality can and will be resolved before its Drawables. |
| 14307 | * |
| 14308 | * Will call {@link View#onResolveDrawables} when resolution is done. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14309 | * |
| 14310 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14311 | */ |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14312 | protected void resolveDrawables() { |
Fabrice Di Meglio | 1957d28 | 2012-10-25 17:42:39 -0700 | [diff] [blame] | 14313 | if (canResolveLayoutDirection()) { |
| 14314 | if (mBackground != null) { |
| 14315 | mBackground.setLayoutDirection(getLayoutDirection()); |
| 14316 | } |
| 14317 | mPrivateFlags2 |= PFLAG2_DRAWABLE_RESOLVED; |
| 14318 | onResolveDrawables(getLayoutDirection()); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14319 | } |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14320 | } |
| 14321 | |
| 14322 | /** |
| 14323 | * Called when layout direction has been resolved. |
| 14324 | * |
| 14325 | * The default implementation does nothing. |
| 14326 | * |
| 14327 | * @param layoutDirection The resolved layout direction. |
| 14328 | * |
Fabrice Di Meglio | 49b0a9b | 2012-09-18 12:06:13 -0700 | [diff] [blame] | 14329 | * @see #LAYOUT_DIRECTION_LTR |
| 14330 | * @see #LAYOUT_DIRECTION_RTL |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14331 | * |
| 14332 | * @hide |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14333 | */ |
| 14334 | public void onResolveDrawables(int layoutDirection) { |
Fabrice Di Meglio | 6a03640 | 2011-05-23 14:43:23 -0700 | [diff] [blame] | 14335 | } |
| 14336 | |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14337 | /** |
| 14338 | * @hide |
| 14339 | */ |
| 14340 | protected void resetResolvedDrawables() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14341 | mPrivateFlags2 &= ~PFLAG2_DRAWABLE_RESOLVED; |
| 14342 | } |
| 14343 | |
| 14344 | private boolean isDrawablesResolved() { |
| 14345 | return (mPrivateFlags2 & PFLAG2_DRAWABLE_RESOLVED) == PFLAG2_DRAWABLE_RESOLVED; |
| 14346 | } |
| 14347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14348 | /** |
| 14349 | * If your view subclass is displaying its own Drawable objects, it should |
| 14350 | * override this function and return true for any Drawable it is |
| 14351 | * displaying. This allows animations for those drawables to be |
| 14352 | * scheduled. |
| 14353 | * |
| 14354 | * <p>Be sure to call through to the super class when overriding this |
| 14355 | * function. |
| 14356 | * |
| 14357 | * @param who The Drawable to verify. Return true if it is one you are |
| 14358 | * displaying, else return the result of calling through to the |
| 14359 | * super class. |
| 14360 | * |
| 14361 | * @return boolean If true than the Drawable is being displayed in the |
| 14362 | * view; else false and it is not allowed to animate. |
| 14363 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14364 | * @see #unscheduleDrawable(android.graphics.drawable.Drawable) |
| 14365 | * @see #drawableStateChanged() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14366 | */ |
| 14367 | protected boolean verifyDrawable(Drawable who) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14368 | return who == mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14369 | } |
| 14370 | |
| 14371 | /** |
| 14372 | * This function is called whenever the state of the view changes in such |
| 14373 | * a way that it impacts the state of drawables being shown. |
| 14374 | * |
| 14375 | * <p>Be sure to call through to the superclass when overriding this |
| 14376 | * function. |
| 14377 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14378 | * @see Drawable#setState(int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14379 | */ |
| 14380 | protected void drawableStateChanged() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14381 | Drawable d = mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14382 | if (d != null && d.isStateful()) { |
| 14383 | d.setState(getDrawableState()); |
| 14384 | } |
| 14385 | } |
| 14386 | |
| 14387 | /** |
| 14388 | * Call this to force a view to update its drawable state. This will cause |
| 14389 | * drawableStateChanged to be called on this view. Views that are interested |
| 14390 | * in the new state should call getDrawableState. |
| 14391 | * |
| 14392 | * @see #drawableStateChanged |
| 14393 | * @see #getDrawableState |
| 14394 | */ |
| 14395 | public void refreshDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14396 | mPrivateFlags |= PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14397 | drawableStateChanged(); |
| 14398 | |
| 14399 | ViewParent parent = mParent; |
| 14400 | if (parent != null) { |
| 14401 | parent.childDrawableStateChanged(this); |
| 14402 | } |
| 14403 | } |
| 14404 | |
| 14405 | /** |
| 14406 | * Return an array of resource IDs of the drawable states representing the |
| 14407 | * current state of the view. |
| 14408 | * |
| 14409 | * @return The current drawable state |
| 14410 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14411 | * @see Drawable#setState(int[]) |
| 14412 | * @see #drawableStateChanged() |
| 14413 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14414 | */ |
| 14415 | public final int[] getDrawableState() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14416 | if ((mDrawableState != null) && ((mPrivateFlags & PFLAG_DRAWABLE_STATE_DIRTY) == 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14417 | return mDrawableState; |
| 14418 | } else { |
| 14419 | mDrawableState = onCreateDrawableState(0); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14420 | mPrivateFlags &= ~PFLAG_DRAWABLE_STATE_DIRTY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14421 | return mDrawableState; |
| 14422 | } |
| 14423 | } |
| 14424 | |
| 14425 | /** |
| 14426 | * Generate the new {@link android.graphics.drawable.Drawable} state for |
| 14427 | * this view. This is called by the view |
| 14428 | * system when the cached Drawable state is determined to be invalid. To |
| 14429 | * retrieve the current state, you should use {@link #getDrawableState}. |
| 14430 | * |
| 14431 | * @param extraSpace if non-zero, this is the number of extra entries you |
| 14432 | * would like in the returned array in which you can place your own |
| 14433 | * states. |
| 14434 | * |
| 14435 | * @return Returns an array holding the current {@link Drawable} state of |
| 14436 | * the view. |
| 14437 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14438 | * @see #mergeDrawableStates(int[], int[]) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14439 | */ |
| 14440 | protected int[] onCreateDrawableState(int extraSpace) { |
| 14441 | if ((mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE && |
| 14442 | mParent instanceof View) { |
| 14443 | return ((View) mParent).onCreateDrawableState(extraSpace); |
| 14444 | } |
| 14445 | |
| 14446 | int[] drawableState; |
| 14447 | |
| 14448 | int privateFlags = mPrivateFlags; |
| 14449 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14450 | int viewStateIndex = 0; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14451 | if ((privateFlags & PFLAG_PRESSED) != 0) viewStateIndex |= VIEW_STATE_PRESSED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14452 | if ((mViewFlags & ENABLED_MASK) == ENABLED) viewStateIndex |= VIEW_STATE_ENABLED; |
| 14453 | if (isFocused()) viewStateIndex |= VIEW_STATE_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14454 | if ((privateFlags & PFLAG_SELECTED) != 0) viewStateIndex |= VIEW_STATE_SELECTED; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14455 | if (hasWindowFocus()) viewStateIndex |= VIEW_STATE_WINDOW_FOCUSED; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14456 | if ((privateFlags & PFLAG_ACTIVATED) != 0) viewStateIndex |= VIEW_STATE_ACTIVATED; |
Adam Powell | 5a7e94e | 2011-04-25 15:30:43 -0700 | [diff] [blame] | 14457 | if (mAttachInfo != null && mAttachInfo.mHardwareAccelerationRequested && |
| 14458 | HardwareRenderer.isAvailable()) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 14459 | // This is set if HW acceleration is requested, even if the current |
| 14460 | // process doesn't allow it. This is just to allow app preview |
| 14461 | // windows to better match their app. |
| 14462 | viewStateIndex |= VIEW_STATE_ACCELERATED; |
| 14463 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14464 | if ((privateFlags & PFLAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_HOVERED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14465 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14466 | final int privateFlags2 = mPrivateFlags2; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14467 | if ((privateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0) viewStateIndex |= VIEW_STATE_DRAG_CAN_ACCEPT; |
| 14468 | if ((privateFlags2 & PFLAG2_DRAG_HOVERED) != 0) viewStateIndex |= VIEW_STATE_DRAG_HOVERED; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 14469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14470 | drawableState = VIEW_STATE_SETS[viewStateIndex]; |
| 14471 | |
| 14472 | //noinspection ConstantIfStatement |
| 14473 | if (false) { |
| 14474 | Log.i("View", "drawableStateIndex=" + viewStateIndex); |
| 14475 | Log.i("View", toString() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14476 | + " pressed=" + ((privateFlags & PFLAG_PRESSED) != 0) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14477 | + " en=" + ((mViewFlags & ENABLED_MASK) == ENABLED) |
| 14478 | + " fo=" + hasFocus() |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14479 | + " sl=" + ((privateFlags & PFLAG_SELECTED) != 0) |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14480 | + " wf=" + hasWindowFocus() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14481 | + ": " + Arrays.toString(drawableState)); |
| 14482 | } |
| 14483 | |
| 14484 | if (extraSpace == 0) { |
| 14485 | return drawableState; |
| 14486 | } |
| 14487 | |
| 14488 | final int[] fullState; |
| 14489 | if (drawableState != null) { |
| 14490 | fullState = new int[drawableState.length + extraSpace]; |
| 14491 | System.arraycopy(drawableState, 0, fullState, 0, drawableState.length); |
| 14492 | } else { |
| 14493 | fullState = new int[extraSpace]; |
| 14494 | } |
| 14495 | |
| 14496 | return fullState; |
| 14497 | } |
| 14498 | |
| 14499 | /** |
| 14500 | * Merge your own state values in <var>additionalState</var> into the base |
| 14501 | * state values <var>baseState</var> that were returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14502 | * {@link #onCreateDrawableState(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14503 | * |
| 14504 | * @param baseState The base state values returned by |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 14505 | * {@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] | 14506 | * own additional state values. |
| 14507 | * |
| 14508 | * @param additionalState The additional state values you would like |
| 14509 | * added to <var>baseState</var>; this array is not modified. |
| 14510 | * |
| 14511 | * @return As a convenience, the <var>baseState</var> array you originally |
| 14512 | * passed into the function is returned. |
| 14513 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14514 | * @see #onCreateDrawableState(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14515 | */ |
| 14516 | protected static int[] mergeDrawableStates(int[] baseState, int[] additionalState) { |
| 14517 | final int N = baseState.length; |
| 14518 | int i = N - 1; |
| 14519 | while (i >= 0 && baseState[i] == 0) { |
| 14520 | i--; |
| 14521 | } |
| 14522 | System.arraycopy(additionalState, 0, baseState, i + 1, additionalState.length); |
| 14523 | return baseState; |
| 14524 | } |
| 14525 | |
| 14526 | /** |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14527 | * Call {@link Drawable#jumpToCurrentState() Drawable.jumpToCurrentState()} |
| 14528 | * on all Drawable objects associated with this view. |
| 14529 | */ |
| 14530 | public void jumpDrawablesToCurrentState() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14531 | if (mBackground != null) { |
| 14532 | mBackground.jumpToCurrentState(); |
Dianne Hackborn | 079e235 | 2010-10-18 17:02:43 -0700 | [diff] [blame] | 14533 | } |
| 14534 | } |
| 14535 | |
| 14536 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14537 | * Sets the background color for this view. |
| 14538 | * @param color the color of the background |
| 14539 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14540 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14541 | public void setBackgroundColor(int color) { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14542 | if (mBackground instanceof ColorDrawable) { |
Romain Guy | 5f49c30 | 2012-09-06 16:33:31 -0700 | [diff] [blame] | 14543 | ((ColorDrawable) mBackground.mutate()).setColor(color); |
Romain Guy | 7d3082a | 2012-07-11 17:52:54 -0700 | [diff] [blame] | 14544 | computeOpaqueFlags(); |
Romain Guy | f6ae4b8 | 2012-11-27 13:57:27 -0800 | [diff] [blame] | 14545 | mBackgroundResource = 0; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14546 | } else { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14547 | setBackground(new ColorDrawable(color)); |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 14548 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14549 | } |
| 14550 | |
| 14551 | /** |
| 14552 | * Set the background to a given resource. The resource should refer to |
Wink Saville | 7cd88e1 | 2009-08-04 14:45:10 -0700 | [diff] [blame] | 14553 | * a Drawable object or 0 to remove the background. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14554 | * @param resid The identifier of the resource. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14555 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14556 | * @attr ref android.R.styleable#View_background |
| 14557 | */ |
Bjorn Bringert | 8354fa6 | 2010-02-24 23:54:29 +0000 | [diff] [blame] | 14558 | @RemotableViewMethod |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14559 | public void setBackgroundResource(int resid) { |
| 14560 | if (resid != 0 && resid == mBackgroundResource) { |
| 14561 | return; |
| 14562 | } |
| 14563 | |
| 14564 | Drawable d= null; |
| 14565 | if (resid != 0) { |
| 14566 | d = mResources.getDrawable(resid); |
| 14567 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14568 | setBackground(d); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14569 | |
| 14570 | mBackgroundResource = resid; |
| 14571 | } |
| 14572 | |
| 14573 | /** |
| 14574 | * Set the background to a given Drawable, or remove the background. If the |
| 14575 | * background has padding, this View's padding is set to the background's |
| 14576 | * padding. However, when a background is removed, this View's padding isn't |
| 14577 | * touched. If setting the padding is desired, please use |
| 14578 | * {@link #setPadding(int, int, int, int)}. |
| 14579 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14580 | * @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] | 14581 | * background |
| 14582 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14583 | public void setBackground(Drawable background) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 14584 | //noinspection deprecation |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14585 | setBackgroundDrawable(background); |
| 14586 | } |
| 14587 | |
| 14588 | /** |
| 14589 | * @deprecated use {@link #setBackground(Drawable)} instead |
| 14590 | */ |
| 14591 | @Deprecated |
| 14592 | public void setBackgroundDrawable(Drawable background) { |
Romain Guy | 846a533 | 2012-07-11 17:44:57 -0700 | [diff] [blame] | 14593 | computeOpaqueFlags(); |
| 14594 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14595 | if (background == mBackground) { |
Adam Powell | 4d36ec1 | 2011-07-17 16:44:16 -0700 | [diff] [blame] | 14596 | return; |
| 14597 | } |
| 14598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14599 | boolean requestLayout = false; |
| 14600 | |
| 14601 | mBackgroundResource = 0; |
| 14602 | |
| 14603 | /* |
| 14604 | * Regardless of whether we're setting a new background or not, we want |
| 14605 | * to clear the previous drawable. |
| 14606 | */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14607 | if (mBackground != null) { |
| 14608 | mBackground.setCallback(null); |
| 14609 | unscheduleDrawable(mBackground); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14610 | } |
| 14611 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14612 | if (background != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14613 | Rect padding = sThreadLocal.get(); |
| 14614 | if (padding == null) { |
| 14615 | padding = new Rect(); |
| 14616 | sThreadLocal.set(padding); |
| 14617 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 14618 | resetResolvedDrawables(); |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14619 | background.setLayoutDirection(getLayoutDirection()); |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14620 | if (background.getPadding(padding)) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14621 | resetResolvedPadding(); |
Fabrice Di Meglio | b03b434 | 2012-06-04 12:55:30 -0700 | [diff] [blame] | 14622 | switch (background.getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14623 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14624 | mUserPaddingLeftInitial = padding.right; |
| 14625 | mUserPaddingRightInitial = padding.left; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14626 | internalSetPadding(padding.right, padding.top, padding.left, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14627 | break; |
| 14628 | case LAYOUT_DIRECTION_LTR: |
| 14629 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14630 | mUserPaddingLeftInitial = padding.left; |
| 14631 | mUserPaddingRightInitial = padding.right; |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14632 | internalSetPadding(padding.left, padding.top, padding.right, padding.bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14633 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14634 | } |
| 14635 | |
| 14636 | // Compare the minimum sizes of the old Drawable and the new. If there isn't an old or |
| 14637 | // if it has a different minimum size, we should layout again |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14638 | if (mBackground == null || mBackground.getMinimumHeight() != background.getMinimumHeight() || |
| 14639 | mBackground.getMinimumWidth() != background.getMinimumWidth()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14640 | requestLayout = true; |
| 14641 | } |
| 14642 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14643 | background.setCallback(this); |
| 14644 | if (background.isStateful()) { |
| 14645 | background.setState(getDrawableState()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14646 | } |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14647 | background.setVisible(getVisibility() == VISIBLE, false); |
| 14648 | mBackground = background; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14649 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14650 | if ((mPrivateFlags & PFLAG_SKIP_DRAW) != 0) { |
| 14651 | mPrivateFlags &= ~PFLAG_SKIP_DRAW; |
| 14652 | mPrivateFlags |= PFLAG_ONLY_DRAWS_BACKGROUND; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14653 | requestLayout = true; |
| 14654 | } |
| 14655 | } else { |
| 14656 | /* Remove the background */ |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14657 | mBackground = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14658 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14659 | if ((mPrivateFlags & PFLAG_ONLY_DRAWS_BACKGROUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14660 | /* |
| 14661 | * This view ONLY drew the background before and we're removing |
| 14662 | * the background, so now it won't draw anything |
| 14663 | * (hence we SKIP_DRAW) |
| 14664 | */ |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14665 | mPrivateFlags &= ~PFLAG_ONLY_DRAWS_BACKGROUND; |
| 14666 | mPrivateFlags |= PFLAG_SKIP_DRAW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14667 | } |
| 14668 | |
| 14669 | /* |
| 14670 | * When the background is set, we try to apply its padding to this |
| 14671 | * View. When the background is removed, we don't touch this View's |
| 14672 | * padding. This is noted in the Javadocs. Hence, we don't need to |
| 14673 | * requestLayout(), the invalidate() below is sufficient. |
| 14674 | */ |
| 14675 | |
| 14676 | // The old background's minimum size could have affected this |
| 14677 | // View's layout, so let's requestLayout |
| 14678 | requestLayout = true; |
| 14679 | } |
| 14680 | |
Romain Guy | 8f1344f5 | 2009-05-15 16:03:59 -0700 | [diff] [blame] | 14681 | computeOpaqueFlags(); |
| 14682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14683 | if (requestLayout) { |
| 14684 | requestLayout(); |
| 14685 | } |
| 14686 | |
| 14687 | mBackgroundSizeChanged = true; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14688 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14689 | } |
| 14690 | |
| 14691 | /** |
| 14692 | * Gets the background drawable |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14693 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14694 | * @return The drawable used as the background for this view, if any. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14695 | * |
| 14696 | * @see #setBackground(Drawable) |
| 14697 | * |
| 14698 | * @attr ref android.R.styleable#View_background |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14699 | */ |
| 14700 | public Drawable getBackground() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 14701 | return mBackground; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14702 | } |
| 14703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14704 | /** |
| 14705 | * Sets the padding. The view may add on the space required to display |
| 14706 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14707 | * So the values returned from {@link #getPaddingLeft}, {@link #getPaddingTop}, |
| 14708 | * {@link #getPaddingRight} and {@link #getPaddingBottom} may be different |
| 14709 | * from the values set in this call. |
| 14710 | * |
| 14711 | * @attr ref android.R.styleable#View_padding |
| 14712 | * @attr ref android.R.styleable#View_paddingBottom |
| 14713 | * @attr ref android.R.styleable#View_paddingLeft |
| 14714 | * @attr ref android.R.styleable#View_paddingRight |
| 14715 | * @attr ref android.R.styleable#View_paddingTop |
| 14716 | * @param left the left padding in pixels |
| 14717 | * @param top the top padding in pixels |
| 14718 | * @param right the right padding in pixels |
| 14719 | * @param bottom the bottom padding in pixels |
| 14720 | */ |
| 14721 | public void setPadding(int left, int top, int right, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14722 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14723 | |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14724 | mUserPaddingStart = UNDEFINED_PADDING; |
| 14725 | mUserPaddingEnd = UNDEFINED_PADDING; |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14726 | |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14727 | mUserPaddingLeftInitial = left; |
| 14728 | mUserPaddingRightInitial = right; |
| 14729 | |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14730 | internalSetPadding(left, top, right, bottom); |
| 14731 | } |
| 14732 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14733 | /** |
| 14734 | * @hide |
| 14735 | */ |
| 14736 | protected void internalSetPadding(int left, int top, int right, int bottom) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14737 | mUserPaddingLeft = left; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14738 | mUserPaddingRight = right; |
| 14739 | mUserPaddingBottom = bottom; |
| 14740 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14741 | final int viewFlags = mViewFlags; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14742 | boolean changed = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14743 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14744 | // Common case is there are no scroll bars. |
| 14745 | if ((viewFlags & (SCROLLBARS_VERTICAL|SCROLLBARS_HORIZONTAL)) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14746 | if ((viewFlags & SCROLLBARS_VERTICAL) != 0) { |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14747 | final int offset = (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14748 | ? 0 : getVerticalScrollbarWidth(); |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14749 | switch (mVerticalScrollbarPosition) { |
| 14750 | case SCROLLBAR_POSITION_DEFAULT: |
Fabrice Di Meglio | c91b6ca | 2012-06-22 14:51:15 -0700 | [diff] [blame] | 14751 | if (isLayoutRtl()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14752 | left += offset; |
| 14753 | } else { |
| 14754 | right += offset; |
| 14755 | } |
| 14756 | break; |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14757 | case SCROLLBAR_POSITION_RIGHT: |
| 14758 | right += offset; |
| 14759 | break; |
| 14760 | case SCROLLBAR_POSITION_LEFT: |
| 14761 | left += offset; |
| 14762 | break; |
| 14763 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14764 | } |
Adam Powell | 20232d0 | 2010-12-08 21:08:53 -0800 | [diff] [blame] | 14765 | if ((viewFlags & SCROLLBARS_HORIZONTAL) != 0) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14766 | bottom += (viewFlags & SCROLLBARS_INSET_MASK) == 0 |
| 14767 | ? 0 : getHorizontalScrollbarHeight(); |
| 14768 | } |
| 14769 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 14770 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14771 | if (mPaddingLeft != left) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14772 | changed = true; |
| 14773 | mPaddingLeft = left; |
| 14774 | } |
| 14775 | if (mPaddingTop != top) { |
| 14776 | changed = true; |
| 14777 | mPaddingTop = top; |
| 14778 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14779 | if (mPaddingRight != right) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14780 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14781 | mPaddingRight = right; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14782 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14783 | if (mPaddingBottom != bottom) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14784 | changed = true; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 14785 | mPaddingBottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14786 | } |
| 14787 | |
| 14788 | if (changed) { |
| 14789 | requestLayout(); |
| 14790 | } |
| 14791 | } |
| 14792 | |
| 14793 | /** |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14794 | * Sets the relative padding. The view may add on the space required to display |
| 14795 | * the scrollbars, depending on the style and visibility of the scrollbars. |
| 14796 | * So the values returned from {@link #getPaddingStart}, {@link #getPaddingTop}, |
| 14797 | * {@link #getPaddingEnd} and {@link #getPaddingBottom} may be different |
| 14798 | * from the values set in this call. |
| 14799 | * |
| 14800 | * @attr ref android.R.styleable#View_padding |
| 14801 | * @attr ref android.R.styleable#View_paddingBottom |
| 14802 | * @attr ref android.R.styleable#View_paddingStart |
| 14803 | * @attr ref android.R.styleable#View_paddingEnd |
| 14804 | * @attr ref android.R.styleable#View_paddingTop |
| 14805 | * @param start the start padding in pixels |
| 14806 | * @param top the top padding in pixels |
| 14807 | * @param end the end padding in pixels |
| 14808 | * @param bottom the bottom padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14809 | */ |
| 14810 | public void setPaddingRelative(int start, int top, int end, int bottom) { |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 14811 | resetResolvedPadding(); |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14812 | |
Fabrice Di Meglio | f9e3650 | 2011-06-21 18:41:48 -0700 | [diff] [blame] | 14813 | mUserPaddingStart = start; |
| 14814 | mUserPaddingEnd = end; |
| 14815 | |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14816 | switch(getLayoutDirection()) { |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14817 | case LAYOUT_DIRECTION_RTL: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14818 | mUserPaddingLeftInitial = end; |
| 14819 | mUserPaddingRightInitial = start; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14820 | internalSetPadding(end, top, start, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14821 | break; |
| 14822 | case LAYOUT_DIRECTION_LTR: |
| 14823 | default: |
Fabrice Di Meglio | 7e7786a | 2012-09-11 13:34:15 -0700 | [diff] [blame] | 14824 | mUserPaddingLeftInitial = start; |
| 14825 | mUserPaddingRightInitial = end; |
Fabrice Di Meglio | 509708d | 2012-03-06 15:41:11 -0800 | [diff] [blame] | 14826 | internalSetPadding(start, top, end, bottom); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14827 | } |
| 14828 | } |
| 14829 | |
| 14830 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14831 | * Returns the top padding of this view. |
| 14832 | * |
| 14833 | * @return the top padding in pixels |
| 14834 | */ |
| 14835 | public int getPaddingTop() { |
| 14836 | return mPaddingTop; |
| 14837 | } |
| 14838 | |
| 14839 | /** |
| 14840 | * Returns the bottom padding of this view. If there are inset and enabled |
| 14841 | * scrollbars, this value may include the space required to display the |
| 14842 | * scrollbars as well. |
| 14843 | * |
| 14844 | * @return the bottom padding in pixels |
| 14845 | */ |
| 14846 | public int getPaddingBottom() { |
| 14847 | return mPaddingBottom; |
| 14848 | } |
| 14849 | |
| 14850 | /** |
| 14851 | * Returns the left padding of this view. If there are inset and enabled |
| 14852 | * scrollbars, this value may include the space required to display the |
| 14853 | * scrollbars as well. |
| 14854 | * |
| 14855 | * @return the left padding in pixels |
| 14856 | */ |
| 14857 | public int getPaddingLeft() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14858 | if (!isPaddingResolved()) { |
| 14859 | resolvePadding(); |
| 14860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14861 | return mPaddingLeft; |
| 14862 | } |
| 14863 | |
| 14864 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14865 | * Returns the start padding of this view depending on its resolved layout direction. |
| 14866 | * If there are inset and enabled scrollbars, this value may include the space |
| 14867 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14868 | * |
| 14869 | * @return the start padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14870 | */ |
| 14871 | public int getPaddingStart() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14872 | if (!isPaddingResolved()) { |
| 14873 | resolvePadding(); |
| 14874 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14875 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14876 | mPaddingRight : mPaddingLeft; |
| 14877 | } |
| 14878 | |
| 14879 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14880 | * Returns the right padding of this view. If there are inset and enabled |
| 14881 | * scrollbars, this value may include the space required to display the |
| 14882 | * scrollbars as well. |
| 14883 | * |
| 14884 | * @return the right padding in pixels |
| 14885 | */ |
| 14886 | public int getPaddingRight() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14887 | if (!isPaddingResolved()) { |
| 14888 | resolvePadding(); |
| 14889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14890 | return mPaddingRight; |
| 14891 | } |
| 14892 | |
| 14893 | /** |
Fabrice Di Meglio | 30a21e1 | 2012-03-12 13:12:19 -0700 | [diff] [blame] | 14894 | * Returns the end padding of this view depending on its resolved layout direction. |
| 14895 | * If there are inset and enabled scrollbars, this value may include the space |
| 14896 | * required to display the scrollbars as well. |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14897 | * |
| 14898 | * @return the end padding in pixels |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14899 | */ |
| 14900 | public int getPaddingEnd() { |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 14901 | if (!isPaddingResolved()) { |
| 14902 | resolvePadding(); |
| 14903 | } |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 14904 | return (getLayoutDirection() == LAYOUT_DIRECTION_RTL) ? |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14905 | mPaddingLeft : mPaddingRight; |
| 14906 | } |
| 14907 | |
| 14908 | /** |
| 14909 | * Return if the padding as been set thru relative values |
| 14910 | * {@link #setPaddingRelative(int, int, int, int)} or thru |
| 14911 | * @attr ref android.R.styleable#View_paddingStart or |
| 14912 | * @attr ref android.R.styleable#View_paddingEnd |
| 14913 | * |
| 14914 | * @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] | 14915 | */ |
| 14916 | public boolean isPaddingRelative() { |
Fabrice Di Meglio | 016456e | 2012-07-17 20:35:48 -0700 | [diff] [blame] | 14917 | return (mUserPaddingStart != UNDEFINED_PADDING || mUserPaddingEnd != UNDEFINED_PADDING); |
Fabrice Di Meglio | d8703a9 | 2011-06-16 18:54:08 -0700 | [diff] [blame] | 14918 | } |
| 14919 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14920 | Insets computeOpticalInsets() { |
| 14921 | return (mBackground == null) ? Insets.NONE : mBackground.getOpticalInsets(); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14922 | } |
| 14923 | |
| 14924 | /** |
| 14925 | * @hide |
| 14926 | */ |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14927 | public void resetPaddingToInitialValues() { |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14928 | if (isRtlCompatibilityMode()) { |
| 14929 | mPaddingLeft = mUserPaddingLeftInitial; |
| 14930 | mPaddingRight = mUserPaddingRightInitial; |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14931 | return; |
| 14932 | } |
| 14933 | if (isLayoutRtl()) { |
| 14934 | mPaddingLeft = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingLeftInitial; |
| 14935 | mPaddingRight = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14936 | } else { |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 14937 | mPaddingLeft = (mUserPaddingStart >= 0) ? mUserPaddingStart : mUserPaddingLeftInitial; |
| 14938 | mPaddingRight = (mUserPaddingEnd >= 0) ? mUserPaddingEnd : mUserPaddingRightInitial; |
Fabrice Di Meglio | 80766f1 | 2012-10-01 13:13:12 -0700 | [diff] [blame] | 14939 | } |
Fabrice Di Meglio | 47fb191 | 2012-09-28 19:50:18 -0700 | [diff] [blame] | 14940 | } |
| 14941 | |
| 14942 | /** |
| 14943 | * @hide |
| 14944 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 14945 | public Insets getOpticalInsets() { |
| 14946 | if (mLayoutInsets == null) { |
| 14947 | mLayoutInsets = computeOpticalInsets(); |
| 14948 | } |
| 14949 | return mLayoutInsets; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 14950 | } |
| 14951 | |
| 14952 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14953 | * Changes the selection state of this view. A view can be selected or not. |
| 14954 | * Note that selection is not the same as focus. Views are typically |
| 14955 | * selected in the context of an AdapterView like ListView or GridView; |
| 14956 | * the selected view is the view that is highlighted. |
| 14957 | * |
| 14958 | * @param selected true if the view must be selected, false otherwise |
| 14959 | */ |
| 14960 | public void setSelected(boolean selected) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14961 | if (((mPrivateFlags & PFLAG_SELECTED) != 0) != selected) { |
| 14962 | mPrivateFlags = (mPrivateFlags & ~PFLAG_SELECTED) | (selected ? PFLAG_SELECTED : 0); |
Romain Guy | a2431d0 | 2009-04-30 16:30:00 -0700 | [diff] [blame] | 14963 | if (!selected) resetPressedState(); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 14964 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14965 | refreshDrawableState(); |
| 14966 | dispatchSetSelected(selected); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 14967 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 14968 | notifyAccessibilityStateChanged(); |
| 14969 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14970 | } |
| 14971 | } |
| 14972 | |
| 14973 | /** |
| 14974 | * Dispatch setSelected to all of this View's children. |
| 14975 | * |
| 14976 | * @see #setSelected(boolean) |
| 14977 | * |
| 14978 | * @param selected The new selected state |
| 14979 | */ |
| 14980 | protected void dispatchSetSelected(boolean selected) { |
| 14981 | } |
| 14982 | |
| 14983 | /** |
| 14984 | * Indicates the selection state of this view. |
| 14985 | * |
| 14986 | * @return true if the view is selected, false otherwise |
| 14987 | */ |
| 14988 | @ViewDebug.ExportedProperty |
| 14989 | public boolean isSelected() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 14990 | return (mPrivateFlags & PFLAG_SELECTED) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 14991 | } |
| 14992 | |
| 14993 | /** |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 14994 | * Changes the activated state of this view. A view can be activated or not. |
| 14995 | * Note that activation is not the same as selection. Selection is |
| 14996 | * a transient property, representing the view (hierarchy) the user is |
| 14997 | * currently interacting with. Activation is a longer-term state that the |
| 14998 | * user can move views in and out of. For example, in a list view with |
| 14999 | * single or multiple selection enabled, the views in the current selection |
| 15000 | * set are activated. (Um, yeah, we are deeply sorry about the terminology |
| 15001 | * here.) The activated state is propagated down to children of the view it |
| 15002 | * is set on. |
| 15003 | * |
| 15004 | * @param activated true if the view must be activated, false otherwise |
| 15005 | */ |
| 15006 | public void setActivated(boolean activated) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15007 | if (((mPrivateFlags & PFLAG_ACTIVATED) != 0) != activated) { |
| 15008 | mPrivateFlags = (mPrivateFlags & ~PFLAG_ACTIVATED) | (activated ? PFLAG_ACTIVATED : 0); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15009 | invalidate(true); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 15010 | refreshDrawableState(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 15011 | dispatchSetActivated(activated); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 15012 | } |
| 15013 | } |
| 15014 | |
| 15015 | /** |
| 15016 | * Dispatch setActivated to all of this View's children. |
| 15017 | * |
| 15018 | * @see #setActivated(boolean) |
| 15019 | * |
| 15020 | * @param activated The new activated state |
| 15021 | */ |
| 15022 | protected void dispatchSetActivated(boolean activated) { |
| 15023 | } |
| 15024 | |
| 15025 | /** |
| 15026 | * Indicates the activation state of this view. |
| 15027 | * |
| 15028 | * @return true if the view is activated, false otherwise |
| 15029 | */ |
| 15030 | @ViewDebug.ExportedProperty |
| 15031 | public boolean isActivated() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15032 | return (mPrivateFlags & PFLAG_ACTIVATED) != 0; |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 15033 | } |
| 15034 | |
| 15035 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15036 | * Returns the ViewTreeObserver for this view's hierarchy. The view tree |
| 15037 | * observer can be used to get notifications when global events, like |
| 15038 | * layout, happen. |
| 15039 | * |
| 15040 | * The returned ViewTreeObserver observer is not guaranteed to remain |
| 15041 | * valid for the lifetime of this View. If the caller of this method keeps |
| 15042 | * a long-lived reference to ViewTreeObserver, it should always check for |
| 15043 | * the return value of {@link ViewTreeObserver#isAlive()}. |
| 15044 | * |
| 15045 | * @return The ViewTreeObserver for this view's hierarchy. |
| 15046 | */ |
| 15047 | public ViewTreeObserver getViewTreeObserver() { |
| 15048 | if (mAttachInfo != null) { |
| 15049 | return mAttachInfo.mTreeObserver; |
| 15050 | } |
| 15051 | if (mFloatingTreeObserver == null) { |
| 15052 | mFloatingTreeObserver = new ViewTreeObserver(); |
| 15053 | } |
| 15054 | return mFloatingTreeObserver; |
| 15055 | } |
| 15056 | |
| 15057 | /** |
| 15058 | * <p>Finds the topmost view in the current view hierarchy.</p> |
| 15059 | * |
| 15060 | * @return the topmost view containing this view |
| 15061 | */ |
| 15062 | public View getRootView() { |
| 15063 | if (mAttachInfo != null) { |
| 15064 | final View v = mAttachInfo.mRootView; |
| 15065 | if (v != null) { |
| 15066 | return v; |
| 15067 | } |
| 15068 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15070 | View parent = this; |
| 15071 | |
| 15072 | while (parent.mParent != null && parent.mParent instanceof View) { |
| 15073 | parent = (View) parent.mParent; |
| 15074 | } |
| 15075 | |
| 15076 | return parent; |
| 15077 | } |
| 15078 | |
| 15079 | /** |
| 15080 | * <p>Computes the coordinates of this view on the screen. The argument |
| 15081 | * must be an array of two integers. After the method returns, the array |
| 15082 | * contains the x and y location in that order.</p> |
| 15083 | * |
| 15084 | * @param location an array of two integers in which to hold the coordinates |
| 15085 | */ |
| 15086 | public void getLocationOnScreen(int[] location) { |
| 15087 | getLocationInWindow(location); |
| 15088 | |
| 15089 | final AttachInfo info = mAttachInfo; |
Romain Guy | 779398e | 2009-06-16 13:17:50 -0700 | [diff] [blame] | 15090 | if (info != null) { |
| 15091 | location[0] += info.mWindowLeft; |
| 15092 | location[1] += info.mWindowTop; |
| 15093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15094 | } |
| 15095 | |
| 15096 | /** |
| 15097 | * <p>Computes the coordinates of this view in its window. The argument |
| 15098 | * must be an array of two integers. After the method returns, the array |
| 15099 | * contains the x and y location in that order.</p> |
| 15100 | * |
| 15101 | * @param location an array of two integers in which to hold the coordinates |
| 15102 | */ |
| 15103 | public void getLocationInWindow(int[] location) { |
| 15104 | if (location == null || location.length < 2) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15105 | 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] | 15106 | } |
| 15107 | |
Gilles Debunne | 6583ce5 | 2011-12-06 18:09:02 -0800 | [diff] [blame] | 15108 | if (mAttachInfo == null) { |
| 15109 | // When the view is not attached to a window, this method does not make sense |
| 15110 | location[0] = location[1] = 0; |
| 15111 | return; |
| 15112 | } |
| 15113 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15114 | float[] position = mAttachInfo.mTmpTransformLocation; |
| 15115 | position[0] = position[1] = 0.0f; |
| 15116 | |
| 15117 | if (!hasIdentityMatrix()) { |
| 15118 | getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 15119 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15120 | |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15121 | position[0] += mLeft; |
| 15122 | position[1] += mTop; |
| 15123 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15124 | ViewParent viewParent = mParent; |
| 15125 | while (viewParent instanceof View) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15126 | final View view = (View) viewParent; |
| 15127 | |
| 15128 | position[0] -= view.mScrollX; |
| 15129 | position[1] -= view.mScrollY; |
| 15130 | |
| 15131 | if (!view.hasIdentityMatrix()) { |
| 15132 | view.getMatrix().mapPoints(position); |
Dianne Hackborn | ddb715b | 2011-09-09 14:43:39 -0700 | [diff] [blame] | 15133 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15134 | |
| 15135 | position[0] += view.mLeft; |
| 15136 | position[1] += view.mTop; |
| 15137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15138 | viewParent = view.mParent; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 15139 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15140 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 15141 | if (viewParent instanceof ViewRootImpl) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15142 | // *cough* |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15143 | final ViewRootImpl vr = (ViewRootImpl) viewParent; |
| 15144 | position[1] -= vr.mCurScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15145 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 15146 | |
| 15147 | location[0] = (int) (position[0] + 0.5f); |
| 15148 | location[1] = (int) (position[1] + 0.5f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15149 | } |
| 15150 | |
| 15151 | /** |
| 15152 | * {@hide} |
| 15153 | * @param id the id of the view to be found |
| 15154 | * @return the view of the specified id, null if cannot be found |
| 15155 | */ |
| 15156 | protected View findViewTraversal(int id) { |
| 15157 | if (id == mID) { |
| 15158 | return this; |
| 15159 | } |
| 15160 | return null; |
| 15161 | } |
| 15162 | |
| 15163 | /** |
| 15164 | * {@hide} |
| 15165 | * @param tag the tag of the view to be found |
| 15166 | * @return the view of specified tag, null if cannot be found |
| 15167 | */ |
| 15168 | protected View findViewWithTagTraversal(Object tag) { |
| 15169 | if (tag != null && tag.equals(mTag)) { |
| 15170 | return this; |
| 15171 | } |
| 15172 | return null; |
| 15173 | } |
| 15174 | |
| 15175 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15176 | * {@hide} |
| 15177 | * @param predicate The predicate to evaluate. |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15178 | * @param childToSkip If not null, ignores this child during the recursive traversal. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15179 | * @return The first view that matches the predicate or null. |
| 15180 | */ |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15181 | protected View findViewByPredicateTraversal(Predicate<View> predicate, View childToSkip) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15182 | if (predicate.apply(this)) { |
| 15183 | return this; |
| 15184 | } |
| 15185 | return null; |
| 15186 | } |
| 15187 | |
| 15188 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15189 | * Look for a child view with the given id. If this view has the given |
| 15190 | * id, return this view. |
| 15191 | * |
| 15192 | * @param id The id to search for. |
| 15193 | * @return The view that has the given id in the hierarchy or null |
| 15194 | */ |
| 15195 | public final View findViewById(int id) { |
| 15196 | if (id < 0) { |
| 15197 | return null; |
| 15198 | } |
| 15199 | return findViewTraversal(id); |
| 15200 | } |
| 15201 | |
| 15202 | /** |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 15203 | * Finds a view by its unuque and stable accessibility id. |
| 15204 | * |
| 15205 | * @param accessibilityId The searched accessibility id. |
| 15206 | * @return The found view. |
| 15207 | */ |
| 15208 | final View findViewByAccessibilityId(int accessibilityId) { |
| 15209 | if (accessibilityId < 0) { |
| 15210 | return null; |
| 15211 | } |
| 15212 | return findViewByAccessibilityIdTraversal(accessibilityId); |
| 15213 | } |
| 15214 | |
| 15215 | /** |
| 15216 | * Performs the traversal to find a view by its unuque and stable accessibility id. |
| 15217 | * |
| 15218 | * <strong>Note:</strong>This method does not stop at the root namespace |
| 15219 | * boundary since the user can touch the screen at an arbitrary location |
| 15220 | * potentially crossing the root namespace bounday which will send an |
| 15221 | * accessibility event to accessibility services and they should be able |
| 15222 | * to obtain the event source. Also accessibility ids are guaranteed to be |
| 15223 | * unique in the window. |
| 15224 | * |
| 15225 | * @param accessibilityId The accessibility id. |
| 15226 | * @return The found view. |
| 15227 | */ |
| 15228 | View findViewByAccessibilityIdTraversal(int accessibilityId) { |
| 15229 | if (getAccessibilityViewId() == accessibilityId) { |
| 15230 | return this; |
| 15231 | } |
| 15232 | return null; |
| 15233 | } |
| 15234 | |
| 15235 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15236 | * Look for a child view with the given tag. If this view has the given |
| 15237 | * tag, return this view. |
| 15238 | * |
| 15239 | * @param tag The tag to search for, using "tag.equals(getTag())". |
| 15240 | * @return The View that has the given tag in the hierarchy or null |
| 15241 | */ |
| 15242 | public final View findViewWithTag(Object tag) { |
| 15243 | if (tag == null) { |
| 15244 | return null; |
| 15245 | } |
| 15246 | return findViewWithTagTraversal(tag); |
| 15247 | } |
| 15248 | |
| 15249 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15250 | * {@hide} |
| 15251 | * Look for a child view that matches the specified predicate. |
| 15252 | * If this view matches the predicate, return this view. |
| 15253 | * |
| 15254 | * @param predicate The predicate to evaluate. |
| 15255 | * @return The first view that matches the predicate or null. |
| 15256 | */ |
| 15257 | public final View findViewByPredicate(Predicate<View> predicate) { |
Jeff Brown | 4dfbec2 | 2011-08-15 14:55:37 -0700 | [diff] [blame] | 15258 | return findViewByPredicateTraversal(predicate, null); |
| 15259 | } |
| 15260 | |
| 15261 | /** |
| 15262 | * {@hide} |
| 15263 | * Look for a child view that matches the specified predicate, |
| 15264 | * starting with the specified view and its descendents and then |
| 15265 | * recusively searching the ancestors and siblings of that view |
| 15266 | * until this view is reached. |
| 15267 | * |
| 15268 | * This method is useful in cases where the predicate does not match |
| 15269 | * a single unique view (perhaps multiple views use the same id) |
| 15270 | * and we are trying to find the view that is "closest" in scope to the |
| 15271 | * starting view. |
| 15272 | * |
| 15273 | * @param start The view to start from. |
| 15274 | * @param predicate The predicate to evaluate. |
| 15275 | * @return The first view that matches the predicate or null. |
| 15276 | */ |
| 15277 | public final View findViewByPredicateInsideOut(View start, Predicate<View> predicate) { |
| 15278 | View childToSkip = null; |
| 15279 | for (;;) { |
| 15280 | View view = start.findViewByPredicateTraversal(predicate, childToSkip); |
| 15281 | if (view != null || start == this) { |
| 15282 | return view; |
| 15283 | } |
| 15284 | |
| 15285 | ViewParent parent = start.getParent(); |
| 15286 | if (parent == null || !(parent instanceof View)) { |
| 15287 | return null; |
| 15288 | } |
| 15289 | |
| 15290 | childToSkip = start; |
| 15291 | start = (View) parent; |
| 15292 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 15293 | } |
| 15294 | |
| 15295 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15296 | * Sets the identifier for this view. The identifier does not have to be |
| 15297 | * unique in this view's hierarchy. The identifier should be a positive |
| 15298 | * number. |
| 15299 | * |
| 15300 | * @see #NO_ID |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15301 | * @see #getId() |
| 15302 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15303 | * |
| 15304 | * @param id a number used to identify the view |
| 15305 | * |
| 15306 | * @attr ref android.R.styleable#View_id |
| 15307 | */ |
| 15308 | public void setId(int id) { |
| 15309 | mID = id; |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 15310 | if (mID == View.NO_ID && mLabelForId != View.NO_ID) { |
| 15311 | mID = generateViewId(); |
| 15312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15313 | } |
| 15314 | |
| 15315 | /** |
| 15316 | * {@hide} |
| 15317 | * |
| 15318 | * @param isRoot true if the view belongs to the root namespace, false |
| 15319 | * otherwise |
| 15320 | */ |
| 15321 | public void setIsRootNamespace(boolean isRoot) { |
| 15322 | if (isRoot) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15323 | mPrivateFlags |= PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15324 | } else { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15325 | mPrivateFlags &= ~PFLAG_IS_ROOT_NAMESPACE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15326 | } |
| 15327 | } |
| 15328 | |
| 15329 | /** |
| 15330 | * {@hide} |
| 15331 | * |
| 15332 | * @return true if the view belongs to the root namespace, false otherwise |
| 15333 | */ |
| 15334 | public boolean isRootNamespace() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15335 | return (mPrivateFlags&PFLAG_IS_ROOT_NAMESPACE) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15336 | } |
| 15337 | |
| 15338 | /** |
| 15339 | * Returns this view's identifier. |
| 15340 | * |
| 15341 | * @return a positive integer used to identify the view or {@link #NO_ID} |
| 15342 | * if the view has no ID |
| 15343 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15344 | * @see #setId(int) |
| 15345 | * @see #findViewById(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15346 | * @attr ref android.R.styleable#View_id |
| 15347 | */ |
| 15348 | @ViewDebug.CapturedViewProperty |
| 15349 | public int getId() { |
| 15350 | return mID; |
| 15351 | } |
| 15352 | |
| 15353 | /** |
| 15354 | * Returns this view's tag. |
| 15355 | * |
| 15356 | * @return the Object stored in this view as a tag |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15357 | * |
| 15358 | * @see #setTag(Object) |
| 15359 | * @see #getTag(int) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15360 | */ |
| 15361 | @ViewDebug.ExportedProperty |
| 15362 | public Object getTag() { |
| 15363 | return mTag; |
| 15364 | } |
| 15365 | |
| 15366 | /** |
| 15367 | * Sets the tag associated with this view. A tag can be used to mark |
| 15368 | * a view in its hierarchy and does not have to be unique within the |
| 15369 | * hierarchy. Tags can also be used to store data within a view without |
| 15370 | * resorting to another data structure. |
| 15371 | * |
| 15372 | * @param tag an Object to tag the view with |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15373 | * |
| 15374 | * @see #getTag() |
| 15375 | * @see #setTag(int, Object) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15376 | */ |
| 15377 | public void setTag(final Object tag) { |
| 15378 | mTag = tag; |
| 15379 | } |
| 15380 | |
| 15381 | /** |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15382 | * Returns the tag associated with this view and the specified key. |
| 15383 | * |
| 15384 | * @param key The key identifying the tag |
| 15385 | * |
| 15386 | * @return the Object stored in this view as a tag |
| 15387 | * |
| 15388 | * @see #setTag(int, Object) |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 15389 | * @see #getTag() |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15390 | */ |
| 15391 | public Object getTag(int key) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15392 | if (mKeyedTags != null) return mKeyedTags.get(key); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15393 | return null; |
| 15394 | } |
| 15395 | |
| 15396 | /** |
| 15397 | * Sets a tag associated with this view and a key. A tag can be used |
| 15398 | * to mark a view in its hierarchy and does not have to be unique within |
| 15399 | * the hierarchy. Tags can also be used to store data within a view |
| 15400 | * without resorting to another data structure. |
| 15401 | * |
| 15402 | * 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] | 15403 | * application to ensure it is unique (see the <a |
| 15404 | * href={@docRoot}guide/topics/resources/more-resources.html#Id">ID resource type</a>). |
| 15405 | * Keys identified as belonging to |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15406 | * the Android framework or not associated with any package will cause |
| 15407 | * an {@link IllegalArgumentException} to be thrown. |
| 15408 | * |
| 15409 | * @param key The key identifying the tag |
| 15410 | * @param tag An Object to tag the view with |
| 15411 | * |
| 15412 | * @throws IllegalArgumentException If they specified key is not valid |
| 15413 | * |
| 15414 | * @see #setTag(Object) |
| 15415 | * @see #getTag(int) |
| 15416 | */ |
| 15417 | public void setTag(int key, final Object tag) { |
| 15418 | // If the package id is 0x00 or 0x01, it's either an undefined package |
| 15419 | // or a framework id |
| 15420 | if ((key >>> 24) < 2) { |
| 15421 | throw new IllegalArgumentException("The key must be an application-specific " |
| 15422 | + "resource id."); |
| 15423 | } |
| 15424 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15425 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15426 | } |
| 15427 | |
| 15428 | /** |
| 15429 | * Variation of {@link #setTag(int, Object)} that enforces the key to be a |
| 15430 | * framework id. |
| 15431 | * |
| 15432 | * @hide |
| 15433 | */ |
| 15434 | public void setTagInternal(int key, Object tag) { |
| 15435 | if ((key >>> 24) != 0x1) { |
| 15436 | throw new IllegalArgumentException("The key must be a framework-specific " |
| 15437 | + "resource id."); |
| 15438 | } |
| 15439 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15440 | setKeyedTag(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15441 | } |
| 15442 | |
Adam Powell | 2b2f6d6 | 2011-09-23 11:15:39 -0700 | [diff] [blame] | 15443 | private void setKeyedTag(int key, Object tag) { |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15444 | if (mKeyedTags == null) { |
| 15445 | mKeyedTags = new SparseArray<Object>(); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15446 | } |
| 15447 | |
Adam Powell | 7db82ac | 2011-09-22 19:44:04 -0700 | [diff] [blame] | 15448 | mKeyedTags.put(key, tag); |
Romain Guy | d90a331 | 2009-05-06 14:54:28 -0700 | [diff] [blame] | 15449 | } |
| 15450 | |
| 15451 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15452 | * Prints information about this view in the log output, with the tag |
| 15453 | * {@link #VIEW_LOG_TAG}. |
| 15454 | * |
| 15455 | * @hide |
| 15456 | */ |
| 15457 | public void debug() { |
| 15458 | debug(0); |
| 15459 | } |
| 15460 | |
| 15461 | /** |
| 15462 | * Prints information about this view in the log output, with the tag |
| 15463 | * {@link #VIEW_LOG_TAG}. Each line in the output is preceded with an |
| 15464 | * indentation defined by the <code>depth</code>. |
| 15465 | * |
| 15466 | * @param depth the indentation level |
| 15467 | * |
| 15468 | * @hide |
| 15469 | */ |
| 15470 | protected void debug(int depth) { |
| 15471 | String output = debugIndent(depth - 1); |
| 15472 | |
| 15473 | output += "+ " + this; |
| 15474 | int id = getId(); |
| 15475 | if (id != -1) { |
| 15476 | output += " (id=" + id + ")"; |
| 15477 | } |
| 15478 | Object tag = getTag(); |
| 15479 | if (tag != null) { |
| 15480 | output += " (tag=" + tag + ")"; |
| 15481 | } |
| 15482 | Log.d(VIEW_LOG_TAG, output); |
| 15483 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15484 | if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15485 | output = debugIndent(depth) + " FOCUSED"; |
| 15486 | Log.d(VIEW_LOG_TAG, output); |
| 15487 | } |
| 15488 | |
| 15489 | output = debugIndent(depth); |
| 15490 | output += "frame={" + mLeft + ", " + mTop + ", " + mRight |
| 15491 | + ", " + mBottom + "} scroll={" + mScrollX + ", " + mScrollY |
| 15492 | + "} "; |
| 15493 | Log.d(VIEW_LOG_TAG, output); |
| 15494 | |
| 15495 | if (mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 |
| 15496 | || mPaddingBottom != 0) { |
| 15497 | output = debugIndent(depth); |
| 15498 | output += "padding={" + mPaddingLeft + ", " + mPaddingTop |
| 15499 | + ", " + mPaddingRight + ", " + mPaddingBottom + "}"; |
| 15500 | Log.d(VIEW_LOG_TAG, output); |
| 15501 | } |
| 15502 | |
| 15503 | output = debugIndent(depth); |
| 15504 | output += "mMeasureWidth=" + mMeasuredWidth + |
| 15505 | " mMeasureHeight=" + mMeasuredHeight; |
| 15506 | Log.d(VIEW_LOG_TAG, output); |
| 15507 | |
| 15508 | output = debugIndent(depth); |
| 15509 | if (mLayoutParams == null) { |
| 15510 | output += "BAD! no layout params"; |
| 15511 | } else { |
| 15512 | output = mLayoutParams.debug(output); |
| 15513 | } |
| 15514 | Log.d(VIEW_LOG_TAG, output); |
| 15515 | |
| 15516 | output = debugIndent(depth); |
| 15517 | output += "flags={"; |
| 15518 | output += View.printFlags(mViewFlags); |
| 15519 | output += "}"; |
| 15520 | Log.d(VIEW_LOG_TAG, output); |
| 15521 | |
| 15522 | output = debugIndent(depth); |
| 15523 | output += "privateFlags={"; |
| 15524 | output += View.printPrivateFlags(mPrivateFlags); |
| 15525 | output += "}"; |
| 15526 | Log.d(VIEW_LOG_TAG, output); |
| 15527 | } |
| 15528 | |
| 15529 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 15530 | * Creates a string of whitespaces used for indentation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15531 | * |
| 15532 | * @param depth the indentation level |
| 15533 | * @return a String containing (depth * 2 + 3) * 2 white spaces |
| 15534 | * |
| 15535 | * @hide |
| 15536 | */ |
| 15537 | protected static String debugIndent(int depth) { |
| 15538 | StringBuilder spaces = new StringBuilder((depth * 2 + 3) * 2); |
| 15539 | for (int i = 0; i < (depth * 2) + 3; i++) { |
| 15540 | spaces.append(' ').append(' '); |
| 15541 | } |
| 15542 | return spaces.toString(); |
| 15543 | } |
| 15544 | |
| 15545 | /** |
| 15546 | * <p>Return the offset of the widget's text baseline from the widget's top |
| 15547 | * boundary. If this widget does not support baseline alignment, this |
| 15548 | * method returns -1. </p> |
| 15549 | * |
| 15550 | * @return the offset of the baseline within the widget's bounds or -1 |
| 15551 | * if baseline alignment is not supported |
| 15552 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 15553 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15554 | public int getBaseline() { |
| 15555 | return -1; |
| 15556 | } |
| 15557 | |
| 15558 | /** |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15559 | * Returns whether the view hierarchy is currently undergoing a layout pass. This |
| 15560 | * information is useful to avoid situations such as calling {@link #requestLayout()} during |
| 15561 | * a layout pass. |
| 15562 | * |
| 15563 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 15564 | */ |
| 15565 | public boolean isInLayout() { |
| 15566 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 15567 | return (viewRoot != null && viewRoot.isInLayout()); |
| 15568 | } |
| 15569 | |
| 15570 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15571 | * Call this when something has changed which has invalidated the |
| 15572 | * layout of this view. This will schedule a layout pass of the view |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15573 | * tree. This should not be called while the view hierarchy is currently in a layout |
| 15574 | * pass ({@link #isInLayout()}. If layout is happening, the request may be honored at the |
| 15575 | * end of the current layout pass (and then layout will run again) or after the current |
| 15576 | * frame is drawn and the next layout occurs. |
| 15577 | * |
| 15578 | * <p>Subclasses which override this method should call the superclass method to |
| 15579 | * handle possible request-during-layout errors correctly.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15580 | */ |
| 15581 | public void requestLayout() { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 15582 | if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == null) { |
| 15583 | // Only trigger request-during-layout logic if this is the view requesting it, |
| 15584 | // not the views in its parent hierarchy |
| 15585 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 15586 | if (viewRoot != null && viewRoot.isInLayout()) { |
| 15587 | if (!viewRoot.requestLayoutDuringLayout(this)) { |
| 15588 | return; |
| 15589 | } |
| 15590 | } |
| 15591 | mAttachInfo.mViewRequestingLayout = this; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 15592 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 15593 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15594 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15595 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15596 | |
Fabrice Di Meglio | 4a526885 | 2012-03-30 15:56:48 -0700 | [diff] [blame] | 15597 | if (mParent != null && !mParent.isLayoutRequested()) { |
| 15598 | mParent.requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15599 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 15600 | if (mAttachInfo != null && mAttachInfo.mViewRequestingLayout == this) { |
| 15601 | mAttachInfo.mViewRequestingLayout = null; |
| 15602 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15603 | } |
| 15604 | |
| 15605 | /** |
| 15606 | * Forces this view to be laid out during the next layout pass. |
| 15607 | * This method does not call requestLayout() or forceLayout() |
| 15608 | * on the parent. |
| 15609 | */ |
| 15610 | public void forceLayout() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15611 | mPrivateFlags |= PFLAG_FORCE_LAYOUT; |
| 15612 | mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15613 | } |
| 15614 | |
| 15615 | /** |
| 15616 | * <p> |
| 15617 | * This is called to find out how big a view should be. The parent |
| 15618 | * supplies constraint information in the width and height parameters. |
| 15619 | * </p> |
| 15620 | * |
| 15621 | * <p> |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15622 | * 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] | 15623 | * {@link #onMeasure(int, int)}, called by this method. Therefore, only |
Romain Guy | 967e2bf | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 15624 | * {@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] | 15625 | * </p> |
| 15626 | * |
| 15627 | * |
| 15628 | * @param widthMeasureSpec Horizontal space requirements as imposed by the |
| 15629 | * parent |
| 15630 | * @param heightMeasureSpec Vertical space requirements as imposed by the |
| 15631 | * parent |
| 15632 | * |
| 15633 | * @see #onMeasure(int, int) |
| 15634 | */ |
| 15635 | public final void measure(int widthMeasureSpec, int heightMeasureSpec) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 15636 | boolean optical = isLayoutModeOptical(this); |
| 15637 | if (optical != isLayoutModeOptical(mParent)) { |
| 15638 | Insets insets = getOpticalInsets(); |
| 15639 | int oWidth = insets.left + insets.right; |
| 15640 | int oHeight = insets.top + insets.bottom; |
| 15641 | widthMeasureSpec = MeasureSpec.adjust(widthMeasureSpec, optical ? -oWidth : oWidth); |
| 15642 | heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight); |
| 15643 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15644 | if ((mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT || |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15645 | widthMeasureSpec != mOldWidthMeasureSpec || |
| 15646 | heightMeasureSpec != mOldHeightMeasureSpec) { |
| 15647 | |
| 15648 | // first clears the measured dimension flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15649 | mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15650 | |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 15651 | resolveRtlPropertiesIfNeeded(); |
Adam Powell | 0090f20 | 2012-08-07 17:15:30 -0700 | [diff] [blame] | 15652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15653 | // measure ourselves, this should set the measured dimension flag back |
| 15654 | onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 15655 | |
| 15656 | // flag not set, setMeasuredDimension() was not invoked, we raise |
| 15657 | // an exception to warn the developer |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15658 | 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] | 15659 | throw new IllegalStateException("onMeasure() did not set the" |
| 15660 | + " measured dimension by calling" |
| 15661 | + " setMeasuredDimension()"); |
| 15662 | } |
| 15663 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15664 | mPrivateFlags |= PFLAG_LAYOUT_REQUIRED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15665 | } |
| 15666 | |
| 15667 | mOldWidthMeasureSpec = widthMeasureSpec; |
| 15668 | mOldHeightMeasureSpec = heightMeasureSpec; |
| 15669 | } |
| 15670 | |
| 15671 | /** |
| 15672 | * <p> |
| 15673 | * Measure the view and its content to determine the measured width and the |
| 15674 | * measured height. This method is invoked by {@link #measure(int, int)} and |
| 15675 | * should be overriden by subclasses to provide accurate and efficient |
| 15676 | * measurement of their contents. |
| 15677 | * </p> |
| 15678 | * |
| 15679 | * <p> |
| 15680 | * <strong>CONTRACT:</strong> When overriding this method, you |
| 15681 | * <em>must</em> call {@link #setMeasuredDimension(int, int)} to store the |
| 15682 | * measured width and height of this view. Failure to do so will trigger an |
| 15683 | * <code>IllegalStateException</code>, thrown by |
| 15684 | * {@link #measure(int, int)}. Calling the superclass' |
| 15685 | * {@link #onMeasure(int, int)} is a valid use. |
| 15686 | * </p> |
| 15687 | * |
| 15688 | * <p> |
| 15689 | * The base class implementation of measure defaults to the background size, |
| 15690 | * unless a larger size is allowed by the MeasureSpec. Subclasses should |
| 15691 | * override {@link #onMeasure(int, int)} to provide better measurements of |
| 15692 | * their content. |
| 15693 | * </p> |
| 15694 | * |
| 15695 | * <p> |
| 15696 | * If this method is overridden, it is the subclass's responsibility to make |
| 15697 | * sure the measured height and width are at least the view's minimum height |
| 15698 | * and width ({@link #getSuggestedMinimumHeight()} and |
| 15699 | * {@link #getSuggestedMinimumWidth()}). |
| 15700 | * </p> |
| 15701 | * |
| 15702 | * @param widthMeasureSpec horizontal space requirements as imposed by the parent. |
| 15703 | * The requirements are encoded with |
| 15704 | * {@link android.view.View.MeasureSpec}. |
| 15705 | * @param heightMeasureSpec vertical space requirements as imposed by the parent. |
| 15706 | * The requirements are encoded with |
| 15707 | * {@link android.view.View.MeasureSpec}. |
| 15708 | * |
| 15709 | * @see #getMeasuredWidth() |
| 15710 | * @see #getMeasuredHeight() |
| 15711 | * @see #setMeasuredDimension(int, int) |
| 15712 | * @see #getSuggestedMinimumHeight() |
| 15713 | * @see #getSuggestedMinimumWidth() |
| 15714 | * @see android.view.View.MeasureSpec#getMode(int) |
| 15715 | * @see android.view.View.MeasureSpec#getSize(int) |
| 15716 | */ |
| 15717 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 15718 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), |
| 15719 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec)); |
| 15720 | } |
| 15721 | |
| 15722 | /** |
| 15723 | * <p>This mehod must be called by {@link #onMeasure(int, int)} to store the |
| 15724 | * measured width and measured height. Failing to do so will trigger an |
| 15725 | * exception at measurement time.</p> |
| 15726 | * |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15727 | * @param measuredWidth The measured width of this view. May be a complex |
| 15728 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15729 | * {@link #MEASURED_STATE_TOO_SMALL}. |
| 15730 | * @param measuredHeight The measured height of this view. May be a complex |
| 15731 | * bit mask as defined by {@link #MEASURED_SIZE_MASK} and |
| 15732 | * {@link #MEASURED_STATE_TOO_SMALL}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15733 | */ |
| 15734 | protected final void setMeasuredDimension(int measuredWidth, int measuredHeight) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 15735 | boolean optical = isLayoutModeOptical(this); |
| 15736 | if (optical != isLayoutModeOptical(mParent)) { |
| 15737 | Insets insets = getOpticalInsets(); |
| 15738 | int opticalWidth = insets.left + insets.right; |
| 15739 | int opticalHeight = insets.top + insets.bottom; |
| 15740 | |
| 15741 | measuredWidth += optical ? opticalWidth : -opticalWidth; |
| 15742 | measuredHeight += optical ? opticalHeight : -opticalHeight; |
| 15743 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15744 | mMeasuredWidth = measuredWidth; |
| 15745 | mMeasuredHeight = measuredHeight; |
| 15746 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15747 | mPrivateFlags |= PFLAG_MEASURED_DIMENSION_SET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15748 | } |
| 15749 | |
| 15750 | /** |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15751 | * Merge two states as returned by {@link #getMeasuredState()}. |
| 15752 | * @param curState The current state as returned from a view or the result |
| 15753 | * of combining multiple views. |
| 15754 | * @param newState The new view state to combine. |
| 15755 | * @return Returns a new integer reflecting the combination of the two |
| 15756 | * states. |
| 15757 | */ |
| 15758 | public static int combineMeasuredStates(int curState, int newState) { |
| 15759 | return curState | newState; |
| 15760 | } |
| 15761 | |
| 15762 | /** |
| 15763 | * Version of {@link #resolveSizeAndState(int, int, int)} |
| 15764 | * returning only the {@link #MEASURED_SIZE_MASK} bits of the result. |
| 15765 | */ |
| 15766 | public static int resolveSize(int size, int measureSpec) { |
| 15767 | return resolveSizeAndState(size, measureSpec, 0) & MEASURED_SIZE_MASK; |
| 15768 | } |
| 15769 | |
| 15770 | /** |
| 15771 | * Utility to reconcile a desired size and state, with constraints imposed |
| 15772 | * by a MeasureSpec. Will take the desired size, unless a different size |
| 15773 | * is imposed by the constraints. The returned value is a compound integer, |
| 15774 | * with the resolved size in the {@link #MEASURED_SIZE_MASK} bits and |
| 15775 | * optionally the bit {@link #MEASURED_STATE_TOO_SMALL} set if the resulting |
| 15776 | * 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] | 15777 | * |
| 15778 | * @param size How big the view wants to be |
| 15779 | * @param measureSpec Constraints imposed by the parent |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15780 | * @return Size information bit mask as defined by |
| 15781 | * {@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] | 15782 | */ |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15783 | 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] | 15784 | int result = size; |
| 15785 | int specMode = MeasureSpec.getMode(measureSpec); |
| 15786 | int specSize = MeasureSpec.getSize(measureSpec); |
| 15787 | switch (specMode) { |
| 15788 | case MeasureSpec.UNSPECIFIED: |
| 15789 | result = size; |
| 15790 | break; |
| 15791 | case MeasureSpec.AT_MOST: |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15792 | if (specSize < size) { |
| 15793 | result = specSize | MEASURED_STATE_TOO_SMALL; |
| 15794 | } else { |
| 15795 | result = size; |
| 15796 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15797 | break; |
| 15798 | case MeasureSpec.EXACTLY: |
| 15799 | result = specSize; |
| 15800 | break; |
| 15801 | } |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 15802 | return result | (childMeasuredState&MEASURED_STATE_MASK); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15803 | } |
| 15804 | |
| 15805 | /** |
| 15806 | * Utility to return a default size. Uses the supplied size if the |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15807 | * MeasureSpec imposed no constraints. Will get larger if allowed |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15808 | * by the MeasureSpec. |
| 15809 | * |
| 15810 | * @param size Default size for this view |
| 15811 | * @param measureSpec Constraints imposed by the parent |
| 15812 | * @return The size this view should be. |
| 15813 | */ |
| 15814 | public static int getDefaultSize(int size, int measureSpec) { |
| 15815 | int result = size; |
| 15816 | int specMode = MeasureSpec.getMode(measureSpec); |
Romain Guy | 98029c8 | 2011-06-17 15:47:07 -0700 | [diff] [blame] | 15817 | int specSize = MeasureSpec.getSize(measureSpec); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15818 | |
| 15819 | switch (specMode) { |
| 15820 | case MeasureSpec.UNSPECIFIED: |
| 15821 | result = size; |
| 15822 | break; |
| 15823 | case MeasureSpec.AT_MOST: |
| 15824 | case MeasureSpec.EXACTLY: |
| 15825 | result = specSize; |
| 15826 | break; |
| 15827 | } |
| 15828 | return result; |
| 15829 | } |
| 15830 | |
| 15831 | /** |
| 15832 | * Returns the suggested minimum height that the view should use. This |
| 15833 | * returns the maximum of the view's minimum height |
| 15834 | * and the background's minimum height |
| 15835 | * ({@link android.graphics.drawable.Drawable#getMinimumHeight()}). |
| 15836 | * <p> |
| 15837 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15838 | * ensure the returned height is within the requirements of the parent. |
| 15839 | * |
| 15840 | * @return The suggested minimum height of the view. |
| 15841 | */ |
| 15842 | protected int getSuggestedMinimumHeight() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15843 | return (mBackground == null) ? mMinHeight : max(mMinHeight, mBackground.getMinimumHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15845 | } |
| 15846 | |
| 15847 | /** |
| 15848 | * Returns the suggested minimum width that the view should use. This |
| 15849 | * returns the maximum of the view's minimum width) |
| 15850 | * and the background's minimum width |
| 15851 | * ({@link android.graphics.drawable.Drawable#getMinimumWidth()}). |
| 15852 | * <p> |
| 15853 | * When being used in {@link #onMeasure(int, int)}, the caller should still |
| 15854 | * ensure the returned width is within the requirements of the parent. |
| 15855 | * |
| 15856 | * @return The suggested minimum width of the view. |
| 15857 | */ |
| 15858 | protected int getSuggestedMinimumWidth() { |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15859 | return (mBackground == null) ? mMinWidth : max(mMinWidth, mBackground.getMinimumWidth()); |
| 15860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15861 | |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15862 | /** |
| 15863 | * Returns the minimum height of the view. |
| 15864 | * |
| 15865 | * @return the minimum height the view will try to be. |
| 15866 | * |
| 15867 | * @see #setMinimumHeight(int) |
| 15868 | * |
| 15869 | * @attr ref android.R.styleable#View_minHeight |
| 15870 | */ |
| 15871 | public int getMinimumHeight() { |
| 15872 | return mMinHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15873 | } |
| 15874 | |
| 15875 | /** |
| 15876 | * Sets the minimum height of the view. It is not guaranteed the view will |
| 15877 | * be able to achieve this minimum height (for example, if its parent layout |
| 15878 | * constrains it with less available height). |
| 15879 | * |
| 15880 | * @param minHeight The minimum height the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15881 | * |
| 15882 | * @see #getMinimumHeight() |
| 15883 | * |
| 15884 | * @attr ref android.R.styleable#View_minHeight |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15885 | */ |
| 15886 | public void setMinimumHeight(int minHeight) { |
| 15887 | mMinHeight = minHeight; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15888 | requestLayout(); |
| 15889 | } |
| 15890 | |
| 15891 | /** |
| 15892 | * Returns the minimum width of the view. |
| 15893 | * |
| 15894 | * @return the minimum width the view will try to be. |
| 15895 | * |
| 15896 | * @see #setMinimumWidth(int) |
| 15897 | * |
| 15898 | * @attr ref android.R.styleable#View_minWidth |
| 15899 | */ |
| 15900 | public int getMinimumWidth() { |
| 15901 | return mMinWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15902 | } |
| 15903 | |
| 15904 | /** |
| 15905 | * Sets the minimum width of the view. It is not guaranteed the view will |
| 15906 | * be able to achieve this minimum width (for example, if its parent layout |
| 15907 | * constrains it with less available width). |
| 15908 | * |
| 15909 | * @param minWidth The minimum width the view will try to be. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15910 | * |
| 15911 | * @see #getMinimumWidth() |
| 15912 | * |
| 15913 | * @attr ref android.R.styleable#View_minWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15914 | */ |
| 15915 | public void setMinimumWidth(int minWidth) { |
| 15916 | mMinWidth = minWidth; |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 15917 | requestLayout(); |
| 15918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15919 | } |
| 15920 | |
| 15921 | /** |
| 15922 | * Get the animation currently associated with this view. |
| 15923 | * |
| 15924 | * @return The animation that is currently playing or |
| 15925 | * scheduled to play for this view. |
| 15926 | */ |
| 15927 | public Animation getAnimation() { |
| 15928 | return mCurrentAnimation; |
| 15929 | } |
| 15930 | |
| 15931 | /** |
| 15932 | * Start the specified animation now. |
| 15933 | * |
| 15934 | * @param animation the animation to start now |
| 15935 | */ |
| 15936 | public void startAnimation(Animation animation) { |
| 15937 | animation.setStartTime(Animation.START_ON_FIRST_FRAME); |
| 15938 | setAnimation(animation); |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15939 | invalidateParentCaches(); |
| 15940 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15941 | } |
| 15942 | |
| 15943 | /** |
| 15944 | * Cancels any animations for this view. |
| 15945 | */ |
| 15946 | public void clearAnimation() { |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15947 | if (mCurrentAnimation != null) { |
Romain Guy | b4a107d | 2010-02-09 18:50:08 -0800 | [diff] [blame] | 15948 | mCurrentAnimation.detach(); |
Romain Guy | 305a2eb | 2010-02-09 11:30:44 -0800 | [diff] [blame] | 15949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15950 | mCurrentAnimation = null; |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 15951 | invalidateParentIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15952 | } |
| 15953 | |
| 15954 | /** |
| 15955 | * Sets the next animation to play for this view. |
| 15956 | * If you want the animation to play immediately, use |
Chet Haase | 4242893 | 2012-05-11 15:39:07 -0700 | [diff] [blame] | 15957 | * {@link #startAnimation(android.view.animation.Animation)} instead. |
| 15958 | * This method provides allows fine-grained |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15959 | * control over the start time and invalidation, but you |
| 15960 | * 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] | 15961 | * 2) the view's parent (which controls animations on its children) |
| 15962 | * will be invalidated when the animation is supposed to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15963 | * start. |
| 15964 | * |
| 15965 | * @param animation The next animation, or null. |
| 15966 | */ |
| 15967 | public void setAnimation(Animation animation) { |
| 15968 | mCurrentAnimation = animation; |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15970 | if (animation != null) { |
Romain Guy | eb37889 | 2012-04-12 11:33:14 -0700 | [diff] [blame] | 15971 | // If the screen is off assume the animation start time is now instead of |
| 15972 | // the next frame we draw. Keeping the START_ON_FIRST_FRAME start time |
| 15973 | // would cause the animation to start when the screen turns back on |
| 15974 | if (mAttachInfo != null && !mAttachInfo.mScreenOn && |
| 15975 | animation.getStartTime() == Animation.START_ON_FIRST_FRAME) { |
| 15976 | animation.setStartTime(AnimationUtils.currentAnimationTimeMillis()); |
| 15977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15978 | animation.reset(); |
| 15979 | } |
| 15980 | } |
| 15981 | |
| 15982 | /** |
| 15983 | * Invoked by a parent ViewGroup to notify the start of the animation |
| 15984 | * currently associated with this view. If you override this method, |
| 15985 | * always call super.onAnimationStart(); |
| 15986 | * |
| 15987 | * @see #setAnimation(android.view.animation.Animation) |
| 15988 | * @see #getAnimation() |
| 15989 | */ |
| 15990 | protected void onAnimationStart() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 15991 | mPrivateFlags |= PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15992 | } |
| 15993 | |
| 15994 | /** |
| 15995 | * Invoked by a parent ViewGroup to notify the end of the animation |
| 15996 | * currently associated with this view. If you override this method, |
| 15997 | * always call super.onAnimationEnd(); |
| 15998 | * |
| 15999 | * @see #setAnimation(android.view.animation.Animation) |
| 16000 | * @see #getAnimation() |
| 16001 | */ |
| 16002 | protected void onAnimationEnd() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16003 | mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16004 | } |
| 16005 | |
| 16006 | /** |
| 16007 | * Invoked if there is a Transform that involves alpha. Subclass that can |
| 16008 | * draw themselves with the specified alpha should return true, and then |
| 16009 | * respect that alpha when their onDraw() is called. If this returns false |
| 16010 | * then the view may be redirected to draw into an offscreen buffer to |
| 16011 | * fulfill the request, which will look fine, but may be slower than if the |
| 16012 | * subclass handles it internally. The default implementation returns false. |
| 16013 | * |
| 16014 | * @param alpha The alpha (0..255) to apply to the view's drawing |
| 16015 | * @return true if the view can draw with the specified alpha. |
| 16016 | */ |
| 16017 | protected boolean onSetAlpha(int alpha) { |
| 16018 | return false; |
| 16019 | } |
| 16020 | |
| 16021 | /** |
| 16022 | * This is used by the RootView to perform an optimization when |
| 16023 | * the view hierarchy contains one or several SurfaceView. |
| 16024 | * SurfaceView is always considered transparent, but its children are not, |
| 16025 | * therefore all View objects remove themselves from the global transparent |
| 16026 | * region (passed as a parameter to this function). |
| 16027 | * |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 16028 | * @param region The transparent region for this ViewAncestor (window). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16029 | * |
| 16030 | * @return Returns true if the effective visibility of the view at this |
| 16031 | * point is opaque, regardless of the transparent region; returns false |
| 16032 | * if it is possible for underlying windows to be seen behind the view. |
| 16033 | * |
| 16034 | * {@hide} |
| 16035 | */ |
| 16036 | public boolean gatherTransparentRegion(Region region) { |
| 16037 | final AttachInfo attachInfo = mAttachInfo; |
| 16038 | if (region != null && attachInfo != null) { |
| 16039 | final int pflags = mPrivateFlags; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16040 | if ((pflags & PFLAG_SKIP_DRAW) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16041 | // The SKIP_DRAW flag IS NOT set, so this view draws. We need to |
| 16042 | // remove it from the transparent region. |
| 16043 | final int[] location = attachInfo.mTransparentLocation; |
| 16044 | getLocationInWindow(location); |
| 16045 | region.op(location[0], location[1], location[0] + mRight - mLeft, |
| 16046 | location[1] + mBottom - mTop, Region.Op.DIFFERENCE); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16047 | } 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] | 16048 | // The ONLY_DRAWS_BACKGROUND flag IS set and the background drawable |
| 16049 | // exists, so we remove the background drawable's non-transparent |
| 16050 | // parts from this transparent region. |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 16051 | applyDrawableToTransparentRegion(mBackground, region); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16052 | } |
| 16053 | } |
| 16054 | return true; |
| 16055 | } |
| 16056 | |
| 16057 | /** |
| 16058 | * Play a sound effect for this view. |
| 16059 | * |
| 16060 | * <p>The framework will play sound effects for some built in actions, such as |
| 16061 | * clicking, but you may wish to play these effects in your widget, |
| 16062 | * for instance, for internal navigation. |
| 16063 | * |
| 16064 | * <p>The sound effect will only be played if sound effects are enabled by the user, and |
| 16065 | * {@link #isSoundEffectsEnabled()} is true. |
| 16066 | * |
| 16067 | * @param soundConstant One of the constants defined in {@link SoundEffectConstants} |
| 16068 | */ |
| 16069 | public void playSoundEffect(int soundConstant) { |
| 16070 | if (mAttachInfo == null || mAttachInfo.mRootCallbacks == null || !isSoundEffectsEnabled()) { |
| 16071 | return; |
| 16072 | } |
| 16073 | mAttachInfo.mRootCallbacks.playSoundEffect(soundConstant); |
| 16074 | } |
| 16075 | |
| 16076 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16077 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16078 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16079 | * <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] | 16080 | * |
| 16081 | * <p>The framework will provide haptic feedback for some built in actions, |
| 16082 | * such as long presses, but you may wish to provide feedback for your |
| 16083 | * own widget. |
| 16084 | * |
| 16085 | * <p>The feedback will only be performed if |
| 16086 | * {@link #isHapticFeedbackEnabled()} is true. |
| 16087 | * |
| 16088 | * @param feedbackConstant One of the constants defined in |
| 16089 | * {@link HapticFeedbackConstants} |
| 16090 | */ |
| 16091 | public boolean performHapticFeedback(int feedbackConstant) { |
| 16092 | return performHapticFeedback(feedbackConstant, 0); |
| 16093 | } |
| 16094 | |
| 16095 | /** |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16096 | * BZZZTT!!1! |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 16097 | * |
Andy Stadler | f8a7cea | 2009-04-10 16:24:47 -0700 | [diff] [blame] | 16098 | * <p>Like {@link #performHapticFeedback(int)}, with additional options. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16099 | * |
| 16100 | * @param feedbackConstant One of the constants defined in |
| 16101 | * {@link HapticFeedbackConstants} |
| 16102 | * @param flags Additional flags as per {@link HapticFeedbackConstants}. |
| 16103 | */ |
| 16104 | public boolean performHapticFeedback(int feedbackConstant, int flags) { |
| 16105 | if (mAttachInfo == null) { |
| 16106 | return false; |
| 16107 | } |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 16108 | //noinspection SimplifiableIfStatement |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 16109 | if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16110 | && !isHapticFeedbackEnabled()) { |
| 16111 | return false; |
| 16112 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 16113 | return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant, |
| 16114 | (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16115 | } |
| 16116 | |
| 16117 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16118 | * Request that the visibility of the status bar or other screen/window |
| 16119 | * decorations be changed. |
| 16120 | * |
| 16121 | * <p>This method is used to put the over device UI into temporary modes |
| 16122 | * where the user's attention is focused more on the application content, |
| 16123 | * by dimming or hiding surrounding system affordances. This is typically |
| 16124 | * used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY |
| 16125 | * Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content |
| 16126 | * to be placed behind the action bar (and with these flags other system |
| 16127 | * affordances) so that smooth transitions between hiding and showing them |
| 16128 | * can be done. |
| 16129 | * |
| 16130 | * <p>Two representative examples of the use of system UI visibility is |
| 16131 | * implementing a content browsing application (like a magazine reader) |
| 16132 | * and a video playing application. |
| 16133 | * |
| 16134 | * <p>The first code shows a typical implementation of a View in a content |
| 16135 | * browsing application. In this implementation, the application goes |
| 16136 | * into a content-oriented mode by hiding the status bar and action bar, |
| 16137 | * and putting the navigation elements into lights out mode. The user can |
| 16138 | * then interact with content while in this mode. Such an application should |
| 16139 | * provide an easy way for the user to toggle out of the mode (such as to |
| 16140 | * check information in the status bar or access notifications). In the |
| 16141 | * implementation here, this is done simply by tapping on the content. |
| 16142 | * |
| 16143 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java |
| 16144 | * content} |
| 16145 | * |
| 16146 | * <p>This second code sample shows a typical implementation of a View |
| 16147 | * in a video playing application. In this situation, while the video is |
| 16148 | * playing the application would like to go into a complete full-screen mode, |
| 16149 | * to use as much of the display as possible for the video. When in this state |
| 16150 | * the user can not interact with the application; the system intercepts |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16151 | * touching on the screen to pop the UI out of full screen mode. See |
| 16152 | * {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code. |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16153 | * |
| 16154 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java |
| 16155 | * content} |
| 16156 | * |
| 16157 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 16158 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 16159 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 16160 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16161 | */ |
| 16162 | public void setSystemUiVisibility(int visibility) { |
Daniel Sandler | 7052406 | 2011-09-21 00:30:47 -0400 | [diff] [blame] | 16163 | if (visibility != mSystemUiVisibility) { |
| 16164 | mSystemUiVisibility = visibility; |
| 16165 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 16166 | mParent.recomputeViewAttributes(this); |
| 16167 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16168 | } |
| 16169 | } |
| 16170 | |
| 16171 | /** |
Dianne Hackborn | 9801435 | 2012-04-05 18:31:41 -0700 | [diff] [blame] | 16172 | * Returns the last {@link #setSystemUiVisibility(int) that this view has requested. |
| 16173 | * @return Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 16174 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN}, |
| 16175 | * {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION}, |
| 16176 | * and {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16177 | */ |
Joe Onorato | e595cad | 2011-01-24 09:22:12 -0800 | [diff] [blame] | 16178 | public int getSystemUiVisibility() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16179 | return mSystemUiVisibility; |
| 16180 | } |
| 16181 | |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16182 | /** |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 16183 | * Returns the current system UI visibility that is currently set for |
| 16184 | * the entire window. This is the combination of the |
| 16185 | * {@link #setSystemUiVisibility(int)} values supplied by all of the |
| 16186 | * views in the window. |
| 16187 | */ |
| 16188 | public int getWindowSystemUiVisibility() { |
| 16189 | return mAttachInfo != null ? mAttachInfo.mSystemUiVisibility : 0; |
| 16190 | } |
| 16191 | |
| 16192 | /** |
| 16193 | * Override to find out when the window's requested system UI visibility |
| 16194 | * has changed, that is the value returned by {@link #getWindowSystemUiVisibility()}. |
| 16195 | * This is different from the callbacks recieved through |
| 16196 | * {@link #setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener)} |
| 16197 | * in that this is only telling you about the local request of the window, |
| 16198 | * not the actual values applied by the system. |
| 16199 | */ |
| 16200 | public void onWindowSystemUiVisibilityChanged(int visible) { |
| 16201 | } |
| 16202 | |
| 16203 | /** |
| 16204 | * Dispatch callbacks to {@link #onWindowSystemUiVisibilityChanged(int)} down |
| 16205 | * the view hierarchy. |
| 16206 | */ |
| 16207 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 16208 | onWindowSystemUiVisibilityChanged(visible); |
| 16209 | } |
| 16210 | |
| 16211 | /** |
Scott Main | ec6331b | 2011-05-24 16:55:56 -0700 | [diff] [blame] | 16212 | * Set a listener to receive callbacks when the visibility of the system bar changes. |
| 16213 | * @param l The {@link OnSystemUiVisibilityChangeListener} to receive callbacks. |
| 16214 | */ |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16215 | public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeListener l) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16216 | getListenerInfo().mOnSystemUiVisibilityChangeListener = l; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16217 | if (mParent != null && mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 16218 | mParent.recomputeViewAttributes(this); |
| 16219 | } |
| 16220 | } |
| 16221 | |
| 16222 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16223 | * Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down |
| 16224 | * the view hierarchy. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16225 | */ |
| 16226 | public void dispatchSystemUiVisibilityChanged(int visibility) { |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16227 | ListenerInfo li = mListenerInfo; |
| 16228 | if (li != null && li.mOnSystemUiVisibilityChangeListener != null) { |
| 16229 | li.mOnSystemUiVisibilityChangeListener.onSystemUiVisibilityChange( |
Joe Onorato | 6ab77bd | 2011-01-31 11:21:10 -0800 | [diff] [blame] | 16230 | visibility & PUBLIC_STATUS_BAR_VISIBILITY_MASK); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16231 | } |
| 16232 | } |
| 16233 | |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16234 | boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16235 | int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges); |
| 16236 | if (val != mSystemUiVisibility) { |
| 16237 | setSystemUiVisibility(val); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16238 | return true; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16239 | } |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 16240 | return false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 16241 | } |
| 16242 | |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 16243 | /** @hide */ |
| 16244 | public void setDisabledSystemUiVisibility(int flags) { |
| 16245 | if (mAttachInfo != null) { |
| 16246 | if (mAttachInfo.mDisabledSystemUiVisibility != flags) { |
| 16247 | mAttachInfo.mDisabledSystemUiVisibility = flags; |
| 16248 | if (mParent != null) { |
| 16249 | mParent.recomputeViewAttributes(this); |
| 16250 | } |
| 16251 | } |
| 16252 | } |
| 16253 | } |
| 16254 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 16255 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16256 | * Creates an image that the system displays during the drag and drop |
| 16257 | * operation. This is called a "drag shadow". The default implementation |
| 16258 | * for a DragShadowBuilder based on a View returns an image that has exactly the same |
| 16259 | * appearance as the given View. The default also positions the center of the drag shadow |
| 16260 | * directly under the touch point. If no View is provided (the constructor with no parameters |
| 16261 | * is used), and {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} and |
| 16262 | * {@link #onDrawShadow(Canvas) onDrawShadow()} are not overriden, then the |
| 16263 | * default is an invisible drag shadow. |
| 16264 | * <p> |
| 16265 | * You are not required to use the View you provide to the constructor as the basis of the |
| 16266 | * drag shadow. The {@link #onDrawShadow(Canvas) onDrawShadow()} method allows you to draw |
| 16267 | * anything you want as the drag shadow. |
| 16268 | * </p> |
| 16269 | * <p> |
| 16270 | * You pass a DragShadowBuilder object to the system when you start the drag. The system |
| 16271 | * calls {@link #onProvideShadowMetrics(Point,Point) onProvideShadowMetrics()} to get the |
| 16272 | * size and position of the drag shadow. It uses this data to construct a |
| 16273 | * {@link android.graphics.Canvas} object, then it calls {@link #onDrawShadow(Canvas) onDrawShadow()} |
| 16274 | * so that your application can draw the shadow image in the Canvas. |
| 16275 | * </p> |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 16276 | * |
| 16277 | * <div class="special reference"> |
| 16278 | * <h3>Developer Guides</h3> |
| 16279 | * <p>For a guide to implementing drag and drop features, read the |
| 16280 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 16281 | * </div> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16282 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16283 | public static class DragShadowBuilder { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16284 | private final WeakReference<View> mView; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16285 | |
| 16286 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16287 | * Constructs a shadow image builder based on a View. By default, the resulting drag |
| 16288 | * shadow will have the same appearance and dimensions as the View, with the touch point |
| 16289 | * over the center of the View. |
| 16290 | * @param view A View. Any View in scope can be used. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16291 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16292 | public DragShadowBuilder(View view) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16293 | mView = new WeakReference<View>(view); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16294 | } |
| 16295 | |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16296 | /** |
| 16297 | * Construct a shadow builder object with no associated View. This |
| 16298 | * constructor variant is only useful when the {@link #onProvideShadowMetrics(Point, Point)} |
| 16299 | * and {@link #onDrawShadow(Canvas)} methods are also overridden in order |
| 16300 | * to supply the drag shadow's dimensions and appearance without |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16301 | * reference to any View object. If they are not overridden, then the result is an |
| 16302 | * invisible drag shadow. |
Christopher Tate | 17ed60c | 2011-01-18 12:50:26 -0800 | [diff] [blame] | 16303 | */ |
| 16304 | public DragShadowBuilder() { |
| 16305 | mView = new WeakReference<View>(null); |
| 16306 | } |
| 16307 | |
| 16308 | /** |
| 16309 | * Returns the View object that had been passed to the |
| 16310 | * {@link #View.DragShadowBuilder(View)} |
| 16311 | * constructor. If that View parameter was {@code null} or if the |
| 16312 | * {@link #View.DragShadowBuilder()} |
| 16313 | * constructor was used to instantiate the builder object, this method will return |
| 16314 | * null. |
| 16315 | * |
| 16316 | * @return The View object associate with this builder object. |
| 16317 | */ |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 16318 | @SuppressWarnings({"JavadocReference"}) |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16319 | final public View getView() { |
| 16320 | return mView.get(); |
| 16321 | } |
| 16322 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16323 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16324 | * Provides the metrics for the shadow image. These include the dimensions of |
| 16325 | * the shadow image, and the point within that shadow that should |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16326 | * be centered under the touch location while dragging. |
| 16327 | * <p> |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16328 | * The default implementation sets the dimensions of the shadow to be the |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16329 | * same as the dimensions of the View itself and centers the shadow under |
| 16330 | * the touch point. |
| 16331 | * </p> |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16332 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16333 | * @param shadowSize A {@link android.graphics.Point} containing the width and height |
| 16334 | * of the shadow image. Your application must set {@link android.graphics.Point#x} to the |
| 16335 | * desired width and must set {@link android.graphics.Point#y} to the desired height of the |
| 16336 | * image. |
| 16337 | * |
| 16338 | * @param shadowTouchPoint A {@link android.graphics.Point} for the position within the |
| 16339 | * shadow image that should be underneath the touch point during the drag and drop |
| 16340 | * operation. Your application must set {@link android.graphics.Point#x} to the |
| 16341 | * 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] | 16342 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16343 | public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16344 | final View view = mView.get(); |
| 16345 | if (view != null) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16346 | shadowSize.set(view.getWidth(), view.getHeight()); |
| 16347 | shadowTouchPoint.set(shadowSize.x / 2, shadowSize.y / 2); |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16348 | } else { |
| 16349 | Log.e(View.VIEW_LOG_TAG, "Asked for drag thumb metrics but no view"); |
| 16350 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16351 | } |
| 16352 | |
| 16353 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16354 | * Draws the shadow image. The system creates the {@link android.graphics.Canvas} object |
| 16355 | * based on the dimensions it received from the |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16356 | * {@link #onProvideShadowMetrics(Point, Point)} callback. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16357 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16358 | * @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] | 16359 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16360 | public void onDrawShadow(Canvas canvas) { |
Christopher Tate | a037419 | 2010-10-05 13:06:41 -0700 | [diff] [blame] | 16361 | final View view = mView.get(); |
| 16362 | if (view != null) { |
| 16363 | view.draw(canvas); |
| 16364 | } else { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16365 | 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] | 16366 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16367 | } |
| 16368 | } |
| 16369 | |
| 16370 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16371 | * Starts a drag and drop operation. When your application calls this method, it passes a |
| 16372 | * {@link android.view.View.DragShadowBuilder} object to the system. The |
| 16373 | * system calls this object's {@link DragShadowBuilder#onProvideShadowMetrics(Point, Point)} |
| 16374 | * to get metrics for the drag shadow, and then calls the object's |
| 16375 | * {@link DragShadowBuilder#onDrawShadow(Canvas)} to draw the drag shadow itself. |
| 16376 | * <p> |
| 16377 | * Once the system has the drag shadow, it begins the drag and drop operation by sending |
| 16378 | * drag events to all the View objects in your application that are currently visible. It does |
| 16379 | * this either by calling the View object's drag listener (an implementation of |
| 16380 | * {@link android.view.View.OnDragListener#onDrag(View,DragEvent) onDrag()} or by calling the |
| 16381 | * View object's {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} method. |
| 16382 | * Both are passed a {@link android.view.DragEvent} object that has a |
| 16383 | * {@link android.view.DragEvent#getAction()} value of |
| 16384 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED}. |
| 16385 | * </p> |
| 16386 | * <p> |
| 16387 | * Your application can invoke startDrag() on any attached View object. The View object does not |
| 16388 | * need to be the one used in {@link android.view.View.DragShadowBuilder}, nor does it need to |
| 16389 | * be related to the View the user selected for dragging. |
| 16390 | * </p> |
| 16391 | * @param data A {@link android.content.ClipData} object pointing to the data to be |
| 16392 | * transferred by the drag and drop operation. |
| 16393 | * @param shadowBuilder A {@link android.view.View.DragShadowBuilder} object for building the |
| 16394 | * drag shadow. |
| 16395 | * @param myLocalState An {@link java.lang.Object} containing local data about the drag and |
| 16396 | * drop operation. This Object is put into every DragEvent object sent by the system during the |
| 16397 | * current drag. |
| 16398 | * <p> |
| 16399 | * myLocalState is a lightweight mechanism for the sending information from the dragged View |
| 16400 | * to the target Views. For example, it can contain flags that differentiate between a |
| 16401 | * a copy operation and a move operation. |
| 16402 | * </p> |
| 16403 | * @param flags Flags that control the drag and drop operation. No flags are currently defined, |
| 16404 | * so the parameter should be set to 0. |
| 16405 | * @return {@code true} if the method completes successfully, or |
| 16406 | * {@code false} if it fails anywhere. Returning {@code false} means the system was unable to |
| 16407 | * do a drag, and so no drag operation is in progress. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16408 | */ |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16409 | public final boolean startDrag(ClipData data, DragShadowBuilder shadowBuilder, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16410 | Object myLocalState, int flags) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16411 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16412 | Log.d(VIEW_LOG_TAG, "startDrag: data=" + data + " flags=" + flags); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16413 | } |
| 16414 | boolean okay = false; |
| 16415 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16416 | Point shadowSize = new Point(); |
| 16417 | Point shadowTouchPoint = new Point(); |
| 16418 | shadowBuilder.onProvideShadowMetrics(shadowSize, shadowTouchPoint); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16419 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16420 | if ((shadowSize.x < 0) || (shadowSize.y < 0) || |
| 16421 | (shadowTouchPoint.x < 0) || (shadowTouchPoint.y < 0)) { |
| 16422 | throw new IllegalStateException("Drag shadow dimensions must not be negative"); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16423 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16424 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16425 | if (ViewDebug.DEBUG_DRAG) { |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16426 | Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y |
| 16427 | + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 16428 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16429 | Surface surface = new Surface(); |
| 16430 | try { |
| 16431 | IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 16432 | flags, shadowSize.x, shadowSize.y, surface); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16433 | 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] | 16434 | + " surface=" + surface); |
| 16435 | if (token != null) { |
| 16436 | Canvas canvas = surface.lockCanvas(null); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16437 | try { |
Chris Tate | 6b39128 | 2010-10-14 15:48:59 -0700 | [diff] [blame] | 16438 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16439 | shadowBuilder.onDrawShadow(canvas); |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 16440 | } finally { |
| 16441 | surface.unlockCanvasAndPost(canvas); |
| 16442 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16443 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 16444 | final ViewRootImpl root = getViewRootImpl(); |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 16445 | |
| 16446 | // Cache the local state object for delivery with DragEvents |
| 16447 | root.setLocalDragState(myLocalState); |
| 16448 | |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16449 | // repurpose 'shadowSize' for the last touch point |
| 16450 | root.getLastTouchPoint(shadowSize); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16451 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16452 | okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token, |
Christopher Tate | 36d4c3f | 2011-01-07 13:34:24 -0800 | [diff] [blame] | 16453 | shadowSize.x, shadowSize.y, |
| 16454 | shadowTouchPoint.x, shadowTouchPoint.y, data); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 16455 | if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay); |
Christopher Tate | 8f73b5d | 2011-09-12 15:22:12 -0700 | [diff] [blame] | 16456 | |
| 16457 | // Off and running! Release our local surface instance; the drag |
| 16458 | // shadow surface is now managed by the system process. |
| 16459 | surface.release(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16460 | } |
| 16461 | } catch (Exception e) { |
| 16462 | Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e); |
| 16463 | surface.destroy(); |
| 16464 | } |
| 16465 | |
| 16466 | return okay; |
| 16467 | } |
| 16468 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16469 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16470 | * Handles drag events sent by the system following a call to |
| 16471 | * {@link android.view.View#startDrag(ClipData,DragShadowBuilder,Object,int) startDrag()}. |
| 16472 | *<p> |
| 16473 | * When the system calls this method, it passes a |
| 16474 | * {@link android.view.DragEvent} object. A call to |
| 16475 | * {@link android.view.DragEvent#getAction()} returns one of the action type constants defined |
| 16476 | * in DragEvent. The method uses these to determine what is happening in the drag and drop |
| 16477 | * operation. |
| 16478 | * @param event The {@link android.view.DragEvent} sent by the system. |
| 16479 | * The {@link android.view.DragEvent#getAction()} method returns an action type constant defined |
| 16480 | * in DragEvent, indicating the type of drag event represented by this object. |
| 16481 | * @return {@code true} if the method was successful, otherwise {@code false}. |
| 16482 | * <p> |
| 16483 | * The method should return {@code true} in response to an action type of |
| 16484 | * {@link android.view.DragEvent#ACTION_DRAG_STARTED} to receive drag events for the current |
| 16485 | * operation. |
| 16486 | * </p> |
| 16487 | * <p> |
| 16488 | * The method should also return {@code true} in response to an action type of |
| 16489 | * {@link android.view.DragEvent#ACTION_DROP} if it consumed the drop, or |
| 16490 | * {@code false} if it didn't. |
| 16491 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16492 | */ |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 16493 | public boolean onDragEvent(DragEvent event) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16494 | return false; |
| 16495 | } |
| 16496 | |
| 16497 | /** |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16498 | * Detects if this View is enabled and has a drag event listener. |
| 16499 | * If both are true, then it calls the drag event listener with the |
| 16500 | * {@link android.view.DragEvent} it received. If the drag event listener returns |
| 16501 | * {@code true}, then dispatchDragEvent() returns {@code true}. |
| 16502 | * <p> |
| 16503 | * For all other cases, the method calls the |
| 16504 | * {@link android.view.View#onDragEvent(DragEvent) onDragEvent()} drag event handler |
| 16505 | * method and returns its result. |
| 16506 | * </p> |
| 16507 | * <p> |
| 16508 | * This ensures that a drag event is always consumed, even if the View does not have a drag |
| 16509 | * event listener. However, if the View has a listener and the listener returns true, then |
| 16510 | * onDragEvent() is not called. |
| 16511 | * </p> |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16512 | */ |
| 16513 | public boolean dispatchDragEvent(DragEvent event) { |
Romain Guy | 676b173 | 2011-02-14 14:45:33 -0800 | [diff] [blame] | 16514 | //noinspection SimplifiableIfStatement |
Dianne Hackborn | 0500b3c | 2011-11-01 15:28:43 -0700 | [diff] [blame] | 16515 | ListenerInfo li = mListenerInfo; |
| 16516 | if (li != null && li.mOnDragListener != null && (mViewFlags & ENABLED_MASK) == ENABLED |
| 16517 | && li.mOnDragListener.onDrag(this, event)) { |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 16518 | return true; |
| 16519 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16520 | return onDragEvent(event); |
| 16521 | } |
| 16522 | |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16523 | boolean canAcceptDrag() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16524 | return (mPrivateFlags2 & PFLAG2_DRAG_CAN_ACCEPT) != 0; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 16525 | } |
| 16526 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 16527 | /** |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16528 | * This needs to be a better API (NOT ON VIEW) before it is exposed. If |
| 16529 | * it is ever exposed at all. |
Dianne Hackborn | 29e4a3c | 2009-09-30 22:35:40 -0700 | [diff] [blame] | 16530 | * @hide |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16531 | */ |
| 16532 | public void onCloseSystemDialogs(String reason) { |
| 16533 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 16534 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 16535 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16536 | * 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] | 16537 | * update a Region being computed for |
| 16538 | * {@link #gatherTransparentRegion(android.graphics.Region)} so |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16539 | * that any non-transparent parts of the Drawable are removed from the |
| 16540 | * given transparent region. |
| 16541 | * |
| 16542 | * @param dr The Drawable whose transparency is to be applied to the region. |
| 16543 | * @param region A Region holding the current transparency information, |
| 16544 | * where any parts of the region that are set are considered to be |
| 16545 | * transparent. On return, this region will be modified to have the |
| 16546 | * transparency information reduced by the corresponding parts of the |
| 16547 | * Drawable that are not transparent. |
| 16548 | * {@hide} |
| 16549 | */ |
| 16550 | public void applyDrawableToTransparentRegion(Drawable dr, Region region) { |
| 16551 | if (DBG) { |
| 16552 | Log.i("View", "Getting transparent region for: " + this); |
| 16553 | } |
| 16554 | final Region r = dr.getTransparentRegion(); |
| 16555 | final Rect db = dr.getBounds(); |
| 16556 | final AttachInfo attachInfo = mAttachInfo; |
| 16557 | if (r != null && attachInfo != null) { |
| 16558 | final int w = getRight()-getLeft(); |
| 16559 | final int h = getBottom()-getTop(); |
| 16560 | if (db.left > 0) { |
| 16561 | //Log.i("VIEW", "Drawable left " + db.left + " > view 0"); |
| 16562 | r.op(0, 0, db.left, h, Region.Op.UNION); |
| 16563 | } |
| 16564 | if (db.right < w) { |
| 16565 | //Log.i("VIEW", "Drawable right " + db.right + " < view " + w); |
| 16566 | r.op(db.right, 0, w, h, Region.Op.UNION); |
| 16567 | } |
| 16568 | if (db.top > 0) { |
| 16569 | //Log.i("VIEW", "Drawable top " + db.top + " > view 0"); |
| 16570 | r.op(0, 0, w, db.top, Region.Op.UNION); |
| 16571 | } |
| 16572 | if (db.bottom < h) { |
| 16573 | //Log.i("VIEW", "Drawable bottom " + db.bottom + " < view " + h); |
| 16574 | r.op(0, db.bottom, w, h, Region.Op.UNION); |
| 16575 | } |
| 16576 | final int[] location = attachInfo.mTransparentLocation; |
| 16577 | getLocationInWindow(location); |
| 16578 | r.translate(location[0], location[1]); |
| 16579 | region.op(r, Region.Op.INTERSECT); |
| 16580 | } else { |
| 16581 | region.op(db, Region.Op.DIFFERENCE); |
| 16582 | } |
| 16583 | } |
| 16584 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16585 | private void checkForLongClick(int delayOffset) { |
| 16586 | if ((mViewFlags & LONG_CLICKABLE) == LONG_CLICKABLE) { |
| 16587 | mHasPerformedLongPress = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16588 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 16589 | if (mPendingCheckForLongPress == null) { |
| 16590 | mPendingCheckForLongPress = new CheckForLongPress(); |
| 16591 | } |
| 16592 | mPendingCheckForLongPress.rememberWindowAttachCount(); |
| 16593 | postDelayed(mPendingCheckForLongPress, |
| 16594 | ViewConfiguration.getLongPressTimeout() - delayOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16595 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16596 | } |
| 16597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16598 | /** |
| 16599 | * Inflate a view from an XML resource. This convenience method wraps the {@link |
| 16600 | * LayoutInflater} class, which provides a full range of options for view inflation. |
| 16601 | * |
| 16602 | * @param context The Context object for your activity or application. |
| 16603 | * @param resource The resource ID to inflate |
| 16604 | * @param root A view group that will be the parent. Used to properly inflate the |
| 16605 | * layout_* parameters. |
| 16606 | * @see LayoutInflater |
| 16607 | */ |
| 16608 | public static View inflate(Context context, int resource, ViewGroup root) { |
| 16609 | LayoutInflater factory = LayoutInflater.from(context); |
| 16610 | return factory.inflate(resource, root); |
| 16611 | } |
Romain Guy | 33e72ae | 2010-07-17 12:40:29 -0700 | [diff] [blame] | 16612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16613 | /** |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16614 | * Scroll the view with standard behavior for scrolling beyond the normal |
| 16615 | * content boundaries. Views that call this method should override |
| 16616 | * {@link #onOverScrolled(int, int, boolean, boolean)} to respond to the |
| 16617 | * results of an over-scroll operation. |
| 16618 | * |
| 16619 | * Views can use this method to handle any touch or fling-based scrolling. |
| 16620 | * |
| 16621 | * @param deltaX Change in X in pixels |
| 16622 | * @param deltaY Change in Y in pixels |
| 16623 | * @param scrollX Current X scroll value in pixels before applying deltaX |
| 16624 | * @param scrollY Current Y scroll value in pixels before applying deltaY |
| 16625 | * @param scrollRangeX Maximum content scroll range along the X axis |
| 16626 | * @param scrollRangeY Maximum content scroll range along the Y axis |
| 16627 | * @param maxOverScrollX Number of pixels to overscroll by in either direction |
| 16628 | * along the X axis. |
| 16629 | * @param maxOverScrollY Number of pixels to overscroll by in either direction |
| 16630 | * along the Y axis. |
| 16631 | * @param isTouchEvent true if this scroll operation is the result of a touch event. |
| 16632 | * @return true if scrolling was clamped to an over-scroll boundary along either |
| 16633 | * axis, false otherwise. |
| 16634 | */ |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 16635 | @SuppressWarnings({"UnusedParameters"}) |
Adam Powell | 637d337 | 2010-08-25 14:37:03 -0700 | [diff] [blame] | 16636 | protected boolean overScrollBy(int deltaX, int deltaY, |
| 16637 | int scrollX, int scrollY, |
| 16638 | int scrollRangeX, int scrollRangeY, |
| 16639 | int maxOverScrollX, int maxOverScrollY, |
| 16640 | boolean isTouchEvent) { |
| 16641 | final int overScrollMode = mOverScrollMode; |
| 16642 | final boolean canScrollHorizontal = |
| 16643 | computeHorizontalScrollRange() > computeHorizontalScrollExtent(); |
| 16644 | final boolean canScrollVertical = |
| 16645 | computeVerticalScrollRange() > computeVerticalScrollExtent(); |
| 16646 | final boolean overScrollHorizontal = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16647 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollHorizontal); |
| 16648 | final boolean overScrollVertical = overScrollMode == OVER_SCROLL_ALWAYS || |
| 16649 | (overScrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && canScrollVertical); |
| 16650 | |
| 16651 | int newScrollX = scrollX + deltaX; |
| 16652 | if (!overScrollHorizontal) { |
| 16653 | maxOverScrollX = 0; |
| 16654 | } |
| 16655 | |
| 16656 | int newScrollY = scrollY + deltaY; |
| 16657 | if (!overScrollVertical) { |
| 16658 | maxOverScrollY = 0; |
| 16659 | } |
| 16660 | |
| 16661 | // Clamp values if at the limits and record |
| 16662 | final int left = -maxOverScrollX; |
| 16663 | final int right = maxOverScrollX + scrollRangeX; |
| 16664 | final int top = -maxOverScrollY; |
| 16665 | final int bottom = maxOverScrollY + scrollRangeY; |
| 16666 | |
| 16667 | boolean clampedX = false; |
| 16668 | if (newScrollX > right) { |
| 16669 | newScrollX = right; |
| 16670 | clampedX = true; |
| 16671 | } else if (newScrollX < left) { |
| 16672 | newScrollX = left; |
| 16673 | clampedX = true; |
| 16674 | } |
| 16675 | |
| 16676 | boolean clampedY = false; |
| 16677 | if (newScrollY > bottom) { |
| 16678 | newScrollY = bottom; |
| 16679 | clampedY = true; |
| 16680 | } else if (newScrollY < top) { |
| 16681 | newScrollY = top; |
| 16682 | clampedY = true; |
| 16683 | } |
| 16684 | |
| 16685 | onOverScrolled(newScrollX, newScrollY, clampedX, clampedY); |
| 16686 | |
| 16687 | return clampedX || clampedY; |
| 16688 | } |
| 16689 | |
| 16690 | /** |
| 16691 | * Called by {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)} to |
| 16692 | * respond to the results of an over-scroll operation. |
| 16693 | * |
| 16694 | * @param scrollX New X scroll value in pixels |
| 16695 | * @param scrollY New Y scroll value in pixels |
| 16696 | * @param clampedX True if scrollX was clamped to an over-scroll boundary |
| 16697 | * @param clampedY True if scrollY was clamped to an over-scroll boundary |
| 16698 | */ |
| 16699 | protected void onOverScrolled(int scrollX, int scrollY, |
| 16700 | boolean clampedX, boolean clampedY) { |
| 16701 | // Intentionally empty. |
| 16702 | } |
| 16703 | |
| 16704 | /** |
| 16705 | * Returns the over-scroll mode for this view. The result will be |
| 16706 | * one of {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16707 | * (allow over-scrolling only if the view content is larger than the container), |
| 16708 | * or {@link #OVER_SCROLL_NEVER}. |
| 16709 | * |
| 16710 | * @return This view's over-scroll mode. |
| 16711 | */ |
| 16712 | public int getOverScrollMode() { |
| 16713 | return mOverScrollMode; |
| 16714 | } |
| 16715 | |
| 16716 | /** |
| 16717 | * Set the over-scroll mode for this view. Valid over-scroll modes are |
| 16718 | * {@link #OVER_SCROLL_ALWAYS} (default), {@link #OVER_SCROLL_IF_CONTENT_SCROLLS} |
| 16719 | * (allow over-scrolling only if the view content is larger than the container), |
| 16720 | * or {@link #OVER_SCROLL_NEVER}. |
| 16721 | * |
| 16722 | * Setting the over-scroll mode of a view will have an effect only if the |
| 16723 | * view is capable of scrolling. |
| 16724 | * |
| 16725 | * @param overScrollMode The new over-scroll mode for this view. |
| 16726 | */ |
| 16727 | public void setOverScrollMode(int overScrollMode) { |
| 16728 | if (overScrollMode != OVER_SCROLL_ALWAYS && |
| 16729 | overScrollMode != OVER_SCROLL_IF_CONTENT_SCROLLS && |
| 16730 | overScrollMode != OVER_SCROLL_NEVER) { |
| 16731 | throw new IllegalArgumentException("Invalid overscroll mode " + overScrollMode); |
| 16732 | } |
| 16733 | mOverScrollMode = overScrollMode; |
| 16734 | } |
| 16735 | |
| 16736 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 16737 | * Gets a scale factor that determines the distance the view should scroll |
| 16738 | * vertically in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16739 | * @return The vertical scroll scale factor. |
| 16740 | * @hide |
| 16741 | */ |
| 16742 | protected float getVerticalScrollFactor() { |
| 16743 | if (mVerticalScrollFactor == 0) { |
| 16744 | TypedValue outValue = new TypedValue(); |
| 16745 | if (!mContext.getTheme().resolveAttribute( |
| 16746 | com.android.internal.R.attr.listPreferredItemHeight, outValue, true)) { |
| 16747 | throw new IllegalStateException( |
| 16748 | "Expected theme to define listPreferredItemHeight."); |
| 16749 | } |
| 16750 | mVerticalScrollFactor = outValue.getDimension( |
| 16751 | mContext.getResources().getDisplayMetrics()); |
| 16752 | } |
| 16753 | return mVerticalScrollFactor; |
| 16754 | } |
| 16755 | |
| 16756 | /** |
| 16757 | * Gets a scale factor that determines the distance the view should scroll |
| 16758 | * horizontally in response to {@link MotionEvent#ACTION_SCROLL}. |
| 16759 | * @return The horizontal scroll scale factor. |
| 16760 | * @hide |
| 16761 | */ |
| 16762 | protected float getHorizontalScrollFactor() { |
| 16763 | // TODO: Should use something else. |
| 16764 | return getVerticalScrollFactor(); |
| 16765 | } |
| 16766 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16767 | /** |
| 16768 | * Return the value specifying the text direction or policy that was set with |
| 16769 | * {@link #setTextDirection(int)}. |
| 16770 | * |
| 16771 | * @return the defined text direction. It can be one of: |
| 16772 | * |
| 16773 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16774 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16775 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16776 | * {@link #TEXT_DIRECTION_LTR}, |
| 16777 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16778 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16779 | * |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16780 | * @attr ref android.R.styleable#View_textDirection |
| 16781 | * |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16782 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16783 | */ |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16784 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16785 | @ViewDebug.IntToString(from = TEXT_DIRECTION_INHERIT, to = "INHERIT"), |
| 16786 | @ViewDebug.IntToString(from = TEXT_DIRECTION_FIRST_STRONG, to = "FIRST_STRONG"), |
| 16787 | @ViewDebug.IntToString(from = TEXT_DIRECTION_ANY_RTL, to = "ANY_RTL"), |
| 16788 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LTR, to = "LTR"), |
| 16789 | @ViewDebug.IntToString(from = TEXT_DIRECTION_RTL, to = "RTL"), |
| 16790 | @ViewDebug.IntToString(from = TEXT_DIRECTION_LOCALE, to = "LOCALE") |
| 16791 | }) |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16792 | public int getRawTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16793 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_MASK) >> PFLAG2_TEXT_DIRECTION_MASK_SHIFT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16794 | } |
| 16795 | |
| 16796 | /** |
| 16797 | * Set the text direction. |
| 16798 | * |
| 16799 | * @param textDirection the direction to set. Should be one of: |
| 16800 | * |
| 16801 | * {@link #TEXT_DIRECTION_INHERIT}, |
| 16802 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16803 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
| 16804 | * {@link #TEXT_DIRECTION_LTR}, |
| 16805 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16806 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16807 | * |
| 16808 | * Resolution will be done if the value is set to TEXT_DIRECTION_INHERIT. The resolution |
| 16809 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it will |
| 16810 | * return the default {@link #TEXT_DIRECTION_FIRST_STRONG}. |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16811 | * |
| 16812 | * @attr ref android.R.styleable#View_textDirection |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16813 | */ |
| 16814 | public void setTextDirection(int textDirection) { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16815 | if (getRawTextDirection() != textDirection) { |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16816 | // Reset the current text direction and the resolved one |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16817 | mPrivateFlags2 &= ~PFLAG2_TEXT_DIRECTION_MASK; |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16818 | resetResolvedTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16819 | // Set the new text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16820 | mPrivateFlags2 |= ((textDirection << PFLAG2_TEXT_DIRECTION_MASK_SHIFT) & PFLAG2_TEXT_DIRECTION_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16821 | // Do resolution |
| 16822 | resolveTextDirection(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16823 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 16824 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16825 | // Refresh |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16826 | requestLayout(); |
Fabrice Di Meglio | 827d5c0 | 2012-03-23 15:13:41 -0700 | [diff] [blame] | 16827 | invalidate(true); |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16828 | } |
| 16829 | } |
| 16830 | |
| 16831 | /** |
| 16832 | * Return the resolved text direction. |
| 16833 | * |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16834 | * @return the resolved text direction. Returns one of: |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16835 | * |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 16836 | * {@link #TEXT_DIRECTION_FIRST_STRONG} |
| 16837 | * {@link #TEXT_DIRECTION_ANY_RTL}, |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16838 | * {@link #TEXT_DIRECTION_LTR}, |
| 16839 | * {@link #TEXT_DIRECTION_RTL}, |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16840 | * {@link #TEXT_DIRECTION_LOCALE} |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16841 | * |
| 16842 | * @attr ref android.R.styleable#View_textDirection |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16843 | */ |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16844 | public int getTextDirection() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16845 | 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] | 16846 | } |
| 16847 | |
| 16848 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16849 | * Resolve the text direction. |
| 16850 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16851 | * @return true if resolution has been done, false otherwise. |
| 16852 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16853 | * @hide |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16854 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16855 | public boolean resolveTextDirection() { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16856 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16857 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16858 | |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16859 | if (hasRtlSupport()) { |
| 16860 | // Set resolved text direction flag depending on text direction flag |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16861 | final int textDirection = getRawTextDirection(); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16862 | switch(textDirection) { |
| 16863 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16864 | if (!canResolveTextDirection()) { |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16865 | // 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] | 16866 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16867 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16868 | return false; |
| 16869 | } |
| 16870 | |
| 16871 | View parent = ((View) mParent); |
| 16872 | // Parent has not yet resolved, so we still return the default |
| 16873 | if (!parent.isTextDirectionResolved()) { |
| 16874 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 16875 | // Resolution will need to happen again later |
| 16876 | return false; |
| 16877 | } |
| 16878 | |
| 16879 | // Set current resolved direction to the same value as the parent's one |
| 16880 | final int parentResolvedDirection = parent.getTextDirection(); |
| 16881 | switch (parentResolvedDirection) { |
| 16882 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16883 | case TEXT_DIRECTION_ANY_RTL: |
| 16884 | case TEXT_DIRECTION_LTR: |
| 16885 | case TEXT_DIRECTION_RTL: |
| 16886 | case TEXT_DIRECTION_LOCALE: |
| 16887 | mPrivateFlags2 |= |
| 16888 | (parentResolvedDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
| 16889 | break; |
| 16890 | default: |
| 16891 | // Default resolved direction is "first strong" heuristic |
| 16892 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16893 | } |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16894 | break; |
| 16895 | case TEXT_DIRECTION_FIRST_STRONG: |
| 16896 | case TEXT_DIRECTION_ANY_RTL: |
| 16897 | case TEXT_DIRECTION_LTR: |
| 16898 | case TEXT_DIRECTION_RTL: |
| 16899 | case TEXT_DIRECTION_LOCALE: |
| 16900 | // Resolved direction is the same as text direction |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16901 | mPrivateFlags2 |= (textDirection << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16902 | break; |
| 16903 | default: |
| 16904 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16905 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 59dfce8 | 2012-04-02 16:17:20 -0700 | [diff] [blame] | 16906 | } |
| 16907 | } else { |
| 16908 | // Default resolved direction is "first strong" heuristic |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16909 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16910 | } |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16911 | |
| 16912 | // Set to resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16913 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16914 | return true; |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16915 | } |
| 16916 | |
| 16917 | /** |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16918 | * Check if text direction resolution can be done. |
| 16919 | * |
| 16920 | * @return true if text direction resolution can be done otherwise return false. |
| 16921 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16922 | private boolean canResolveTextDirection() { |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16923 | switch (getRawTextDirection()) { |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16924 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 16925 | return (mParent != null) && (mParent instanceof View) && |
| 16926 | ((View) mParent).canResolveTextDirection(); |
Fabrice Di Meglio | b934db7 | 2012-03-20 14:33:01 -0700 | [diff] [blame] | 16927 | default: |
| 16928 | return true; |
| 16929 | } |
| 16930 | } |
| 16931 | |
| 16932 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16933 | * Reset resolved text direction. Text direction will be resolved during a call to |
| 16934 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 16935 | * |
| 16936 | * @hide |
Fabrice Di Meglio | 6d3d505 | 2012-02-15 20:22:56 -0800 | [diff] [blame] | 16937 | */ |
| 16938 | public void resetResolvedTextDirection() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16939 | // Reset any previous text direction resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16940 | mPrivateFlags2 &= ~(PFLAG2_TEXT_DIRECTION_RESOLVED | PFLAG2_TEXT_DIRECTION_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16941 | // Set to default value |
| 16942 | mPrivateFlags2 |= PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 16943 | } |
| 16944 | |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16945 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16946 | * @return true if text direction is inherited. |
| 16947 | * |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 16948 | * @hide |
| 16949 | */ |
| 16950 | public boolean isTextDirectionInherited() { |
| 16951 | return (getRawTextDirection() == TEXT_DIRECTION_INHERIT); |
| 16952 | } |
| 16953 | |
| 16954 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 16955 | * @return true if text direction is resolved. |
| 16956 | */ |
| 16957 | private boolean isTextDirectionResolved() { |
| 16958 | return (mPrivateFlags2 & PFLAG2_TEXT_DIRECTION_RESOLVED) == PFLAG2_TEXT_DIRECTION_RESOLVED; |
| 16959 | } |
| 16960 | |
| 16961 | /** |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16962 | * Return the value specifying the text alignment or policy that was set with |
| 16963 | * {@link #setTextAlignment(int)}. |
| 16964 | * |
| 16965 | * @return the defined text alignment. It can be one of: |
| 16966 | * |
| 16967 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16968 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16969 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 16970 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 16971 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 16972 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 16973 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16974 | * |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 16975 | * @attr ref android.R.styleable#View_textAlignment |
| 16976 | * |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16977 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16978 | */ |
| 16979 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 16980 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 16981 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 16982 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 16983 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 16984 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 16985 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 16986 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 16987 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 16988 | public int getRawTextAlignment() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 16989 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 16990 | } |
| 16991 | |
| 16992 | /** |
| 16993 | * Set the text alignment. |
| 16994 | * |
| 16995 | * @param textAlignment The text alignment to set. Should be one of |
| 16996 | * |
| 16997 | * {@link #TEXT_ALIGNMENT_INHERIT}, |
| 16998 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 16999 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 17000 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 17001 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 17002 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 17003 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
| 17004 | * |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17005 | * Resolution will be done if the value is set to TEXT_ALIGNMENT_INHERIT. The resolution |
| 17006 | * proceeds up the parent chain of the view to get the value. If there is no parent, then it |
| 17007 | * will return the default {@link #TEXT_ALIGNMENT_GRAVITY}. |
| 17008 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17009 | * @attr ref android.R.styleable#View_textAlignment |
| 17010 | */ |
| 17011 | public void setTextAlignment(int textAlignment) { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17012 | if (textAlignment != getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17013 | // Reset the current and resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17014 | mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17015 | resetResolvedTextAlignment(); |
| 17016 | // Set the new text alignment |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17017 | mPrivateFlags2 |= |
| 17018 | ((textAlignment << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) & PFLAG2_TEXT_ALIGNMENT_MASK); |
| 17019 | // Do resolution |
| 17020 | resolveTextAlignment(); |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17021 | // Notify change |
Fabrice Di Meglio | 343e113 | 2012-09-28 18:01:17 -0700 | [diff] [blame] | 17022 | onRtlPropertiesChanged(getLayoutDirection()); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17023 | // Refresh |
| 17024 | requestLayout(); |
| 17025 | invalidate(true); |
| 17026 | } |
| 17027 | } |
| 17028 | |
| 17029 | /** |
| 17030 | * Return the resolved text alignment. |
| 17031 | * |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17032 | * @return the resolved text alignment. Returns one of: |
| 17033 | * |
| 17034 | * {@link #TEXT_ALIGNMENT_GRAVITY}, |
| 17035 | * {@link #TEXT_ALIGNMENT_CENTER}, |
| 17036 | * {@link #TEXT_ALIGNMENT_TEXT_START}, |
| 17037 | * {@link #TEXT_ALIGNMENT_TEXT_END}, |
| 17038 | * {@link #TEXT_ALIGNMENT_VIEW_START}, |
| 17039 | * {@link #TEXT_ALIGNMENT_VIEW_END} |
Fabrice Di Meglio | 7d529cd | 2012-11-14 17:59:06 -0800 | [diff] [blame] | 17040 | * |
| 17041 | * @attr ref android.R.styleable#View_textAlignment |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17042 | */ |
| 17043 | @ViewDebug.ExportedProperty(category = "text", mapping = { |
| 17044 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_INHERIT, to = "INHERIT"), |
| 17045 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_GRAVITY, to = "GRAVITY"), |
| 17046 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_START, to = "TEXT_START"), |
| 17047 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_TEXT_END, to = "TEXT_END"), |
| 17048 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_CENTER, to = "CENTER"), |
| 17049 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), |
| 17050 | @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") |
| 17051 | }) |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17052 | public int getTextAlignment() { |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17053 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >> |
| 17054 | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17055 | } |
| 17056 | |
| 17057 | /** |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17058 | * Resolve the text alignment. |
| 17059 | * |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17060 | * @return true if resolution has been done, false otherwise. |
| 17061 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17062 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17063 | */ |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17064 | public boolean resolveTextAlignment() { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17065 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17066 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17067 | |
| 17068 | if (hasRtlSupport()) { |
| 17069 | // Set resolved text alignment flag depending on text alignment flag |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17070 | final int textAlignment = getRawTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17071 | switch (textAlignment) { |
| 17072 | case TEXT_ALIGNMENT_INHERIT: |
| 17073 | // Check if we can resolve the text alignment |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17074 | if (!canResolveTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17075 | // 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] | 17076 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17077 | // Resolution will need to happen again later |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17078 | return false; |
| 17079 | } |
| 17080 | View parent = (View) mParent; |
| 17081 | |
| 17082 | // Parent has not yet resolved, so we still return the default |
| 17083 | if (!parent.isTextAlignmentResolved()) { |
| 17084 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 17085 | // Resolution will need to happen again later |
| 17086 | return false; |
| 17087 | } |
| 17088 | |
| 17089 | final int parentResolvedTextAlignment = parent.getTextAlignment(); |
| 17090 | switch (parentResolvedTextAlignment) { |
| 17091 | case TEXT_ALIGNMENT_GRAVITY: |
| 17092 | case TEXT_ALIGNMENT_TEXT_START: |
| 17093 | case TEXT_ALIGNMENT_TEXT_END: |
| 17094 | case TEXT_ALIGNMENT_CENTER: |
| 17095 | case TEXT_ALIGNMENT_VIEW_START: |
| 17096 | case TEXT_ALIGNMENT_VIEW_END: |
| 17097 | // Resolved text alignment is the same as the parent resolved |
| 17098 | // text alignment |
| 17099 | mPrivateFlags2 |= |
| 17100 | (parentResolvedTextAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
| 17101 | break; |
| 17102 | default: |
| 17103 | // Use default resolved text alignment |
| 17104 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17105 | } |
| 17106 | break; |
| 17107 | case TEXT_ALIGNMENT_GRAVITY: |
| 17108 | case TEXT_ALIGNMENT_TEXT_START: |
| 17109 | case TEXT_ALIGNMENT_TEXT_END: |
| 17110 | case TEXT_ALIGNMENT_CENTER: |
| 17111 | case TEXT_ALIGNMENT_VIEW_START: |
| 17112 | case TEXT_ALIGNMENT_VIEW_END: |
| 17113 | // Resolved text alignment is the same as text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17114 | mPrivateFlags2 |= (textAlignment << PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17115 | break; |
| 17116 | default: |
| 17117 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17118 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17119 | } |
| 17120 | } else { |
| 17121 | // Use default resolved text alignment |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17122 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17123 | } |
| 17124 | |
| 17125 | // Set the resolved |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17126 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17127 | return true; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17128 | } |
| 17129 | |
| 17130 | /** |
| 17131 | * Check if text alignment resolution can be done. |
| 17132 | * |
| 17133 | * @return true if text alignment resolution can be done otherwise return false. |
| 17134 | */ |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17135 | private boolean canResolveTextAlignment() { |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17136 | switch (getRawTextAlignment()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17137 | case TEXT_DIRECTION_INHERIT: |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 17138 | return (mParent != null) && (mParent instanceof View) && |
| 17139 | ((View) mParent).canResolveTextAlignment(); |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17140 | default: |
| 17141 | return true; |
| 17142 | } |
| 17143 | } |
| 17144 | |
| 17145 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17146 | * Reset resolved text alignment. Text alignment will be resolved during a call to |
| 17147 | * {@link #onMeasure(int, int)}. |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17148 | * |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 17149 | * @hide |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17150 | */ |
| 17151 | public void resetResolvedTextAlignment() { |
| 17152 | // Reset any previous text alignment resolution |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17153 | mPrivateFlags2 &= ~(PFLAG2_TEXT_ALIGNMENT_RESOLVED | PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK); |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17154 | // Set to default |
| 17155 | mPrivateFlags2 |= PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 17156 | } |
| 17157 | |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 17158 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17159 | * @return true if text alignment is inherited. |
| 17160 | * |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 17161 | * @hide |
| 17162 | */ |
| 17163 | public boolean isTextAlignmentInherited() { |
| 17164 | return (getRawTextAlignment() == TEXT_ALIGNMENT_INHERIT); |
| 17165 | } |
| 17166 | |
| 17167 | /** |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 17168 | * @return true if text alignment is resolved. |
| 17169 | */ |
| 17170 | private boolean isTextAlignmentResolved() { |
| 17171 | return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED) == PFLAG2_TEXT_ALIGNMENT_RESOLVED; |
| 17172 | } |
| 17173 | |
| 17174 | /** |
Adam Powell | a9108a2 | 2012-07-18 11:18:09 -0700 | [diff] [blame] | 17175 | * Generate a value suitable for use in {@link #setId(int)}. |
| 17176 | * This value will not collide with ID values generated at build time by aapt for R.id. |
| 17177 | * |
| 17178 | * @return a generated ID value |
| 17179 | */ |
| 17180 | public static int generateViewId() { |
| 17181 | for (;;) { |
| 17182 | final int result = sNextGeneratedId.get(); |
| 17183 | // aapt-generated IDs have the high byte nonzero; clamp to the range under that. |
| 17184 | int newValue = result + 1; |
| 17185 | if (newValue > 0x00FFFFFF) newValue = 1; // Roll over to 1, not 0. |
| 17186 | if (sNextGeneratedId.compareAndSet(result, newValue)) { |
| 17187 | return result; |
| 17188 | } |
| 17189 | } |
| 17190 | } |
| 17191 | |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17192 | // |
| 17193 | // Properties |
| 17194 | // |
| 17195 | /** |
| 17196 | * A Property wrapper around the <code>alpha</code> functionality handled by the |
| 17197 | * {@link View#setAlpha(float)} and {@link View#getAlpha()} methods. |
| 17198 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17199 | public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17200 | @Override |
| 17201 | public void setValue(View object, float value) { |
| 17202 | object.setAlpha(value); |
| 17203 | } |
| 17204 | |
| 17205 | @Override |
| 17206 | public Float get(View object) { |
| 17207 | return object.getAlpha(); |
| 17208 | } |
| 17209 | }; |
| 17210 | |
| 17211 | /** |
| 17212 | * A Property wrapper around the <code>translationX</code> functionality handled by the |
| 17213 | * {@link View#setTranslationX(float)} and {@link View#getTranslationX()} methods. |
| 17214 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17215 | public static final Property<View, Float> TRANSLATION_X = new FloatProperty<View>("translationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17216 | @Override |
| 17217 | public void setValue(View object, float value) { |
| 17218 | object.setTranslationX(value); |
| 17219 | } |
| 17220 | |
| 17221 | @Override |
| 17222 | public Float get(View object) { |
| 17223 | return object.getTranslationX(); |
| 17224 | } |
| 17225 | }; |
| 17226 | |
| 17227 | /** |
| 17228 | * A Property wrapper around the <code>translationY</code> functionality handled by the |
| 17229 | * {@link View#setTranslationY(float)} and {@link View#getTranslationY()} methods. |
| 17230 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17231 | public static final Property<View, Float> TRANSLATION_Y = new FloatProperty<View>("translationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17232 | @Override |
| 17233 | public void setValue(View object, float value) { |
| 17234 | object.setTranslationY(value); |
| 17235 | } |
| 17236 | |
| 17237 | @Override |
| 17238 | public Float get(View object) { |
| 17239 | return object.getTranslationY(); |
| 17240 | } |
| 17241 | }; |
| 17242 | |
| 17243 | /** |
| 17244 | * A Property wrapper around the <code>x</code> functionality handled by the |
| 17245 | * {@link View#setX(float)} and {@link View#getX()} methods. |
| 17246 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17247 | public static final Property<View, Float> X = new FloatProperty<View>("x") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17248 | @Override |
| 17249 | public void setValue(View object, float value) { |
| 17250 | object.setX(value); |
| 17251 | } |
| 17252 | |
| 17253 | @Override |
| 17254 | public Float get(View object) { |
| 17255 | return object.getX(); |
| 17256 | } |
| 17257 | }; |
| 17258 | |
| 17259 | /** |
| 17260 | * A Property wrapper around the <code>y</code> functionality handled by the |
| 17261 | * {@link View#setY(float)} and {@link View#getY()} methods. |
| 17262 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17263 | public static final Property<View, Float> Y = new FloatProperty<View>("y") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17264 | @Override |
| 17265 | public void setValue(View object, float value) { |
| 17266 | object.setY(value); |
| 17267 | } |
| 17268 | |
| 17269 | @Override |
| 17270 | public Float get(View object) { |
| 17271 | return object.getY(); |
| 17272 | } |
| 17273 | }; |
| 17274 | |
| 17275 | /** |
| 17276 | * A Property wrapper around the <code>rotation</code> functionality handled by the |
| 17277 | * {@link View#setRotation(float)} and {@link View#getRotation()} methods. |
| 17278 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17279 | public static final Property<View, Float> ROTATION = new FloatProperty<View>("rotation") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17280 | @Override |
| 17281 | public void setValue(View object, float value) { |
| 17282 | object.setRotation(value); |
| 17283 | } |
| 17284 | |
| 17285 | @Override |
| 17286 | public Float get(View object) { |
| 17287 | return object.getRotation(); |
| 17288 | } |
| 17289 | }; |
| 17290 | |
| 17291 | /** |
| 17292 | * A Property wrapper around the <code>rotationX</code> functionality handled by the |
| 17293 | * {@link View#setRotationX(float)} and {@link View#getRotationX()} methods. |
| 17294 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17295 | public static final Property<View, Float> ROTATION_X = new FloatProperty<View>("rotationX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17296 | @Override |
| 17297 | public void setValue(View object, float value) { |
| 17298 | object.setRotationX(value); |
| 17299 | } |
| 17300 | |
| 17301 | @Override |
| 17302 | public Float get(View object) { |
| 17303 | return object.getRotationX(); |
| 17304 | } |
| 17305 | }; |
| 17306 | |
| 17307 | /** |
| 17308 | * A Property wrapper around the <code>rotationY</code> functionality handled by the |
| 17309 | * {@link View#setRotationY(float)} and {@link View#getRotationY()} methods. |
| 17310 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17311 | public static final Property<View, Float> ROTATION_Y = new FloatProperty<View>("rotationY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17312 | @Override |
| 17313 | public void setValue(View object, float value) { |
| 17314 | object.setRotationY(value); |
| 17315 | } |
| 17316 | |
| 17317 | @Override |
| 17318 | public Float get(View object) { |
| 17319 | return object.getRotationY(); |
| 17320 | } |
| 17321 | }; |
| 17322 | |
| 17323 | /** |
| 17324 | * A Property wrapper around the <code>scaleX</code> functionality handled by the |
| 17325 | * {@link View#setScaleX(float)} and {@link View#getScaleX()} methods. |
| 17326 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17327 | public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17328 | @Override |
| 17329 | public void setValue(View object, float value) { |
| 17330 | object.setScaleX(value); |
| 17331 | } |
| 17332 | |
| 17333 | @Override |
| 17334 | public Float get(View object) { |
| 17335 | return object.getScaleX(); |
| 17336 | } |
| 17337 | }; |
| 17338 | |
| 17339 | /** |
| 17340 | * A Property wrapper around the <code>scaleY</code> functionality handled by the |
| 17341 | * {@link View#setScaleY(float)} and {@link View#getScaleY()} methods. |
| 17342 | */ |
Chet Haase | d47f153 | 2011-12-16 11:18:52 -0800 | [diff] [blame] | 17343 | public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") { |
Chet Haase | b39f051 | 2011-05-24 14:36:40 -0700 | [diff] [blame] | 17344 | @Override |
| 17345 | public void setValue(View object, float value) { |
| 17346 | object.setScaleY(value); |
| 17347 | } |
| 17348 | |
| 17349 | @Override |
| 17350 | public Float get(View object) { |
| 17351 | return object.getScaleY(); |
| 17352 | } |
| 17353 | }; |
| 17354 | |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17355 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17356 | * A MeasureSpec encapsulates the layout requirements passed from parent to child. |
| 17357 | * Each MeasureSpec represents a requirement for either the width or the height. |
| 17358 | * A MeasureSpec is comprised of a size and a mode. There are three possible |
| 17359 | * modes: |
| 17360 | * <dl> |
| 17361 | * <dt>UNSPECIFIED</dt> |
| 17362 | * <dd> |
| 17363 | * The parent has not imposed any constraint on the child. It can be whatever size |
| 17364 | * it wants. |
| 17365 | * </dd> |
| 17366 | * |
| 17367 | * <dt>EXACTLY</dt> |
| 17368 | * <dd> |
| 17369 | * The parent has determined an exact size for the child. The child is going to be |
| 17370 | * given those bounds regardless of how big it wants to be. |
| 17371 | * </dd> |
| 17372 | * |
| 17373 | * <dt>AT_MOST</dt> |
| 17374 | * <dd> |
| 17375 | * The child can be as large as it wants up to the specified size. |
| 17376 | * </dd> |
| 17377 | * </dl> |
| 17378 | * |
| 17379 | * MeasureSpecs are implemented as ints to reduce object allocation. This class |
| 17380 | * is provided to pack and unpack the <size, mode> tuple into the int. |
| 17381 | */ |
| 17382 | public static class MeasureSpec { |
| 17383 | private static final int MODE_SHIFT = 30; |
| 17384 | private static final int MODE_MASK = 0x3 << MODE_SHIFT; |
| 17385 | |
| 17386 | /** |
| 17387 | * Measure specification mode: The parent has not imposed any constraint |
| 17388 | * on the child. It can be whatever size it wants. |
| 17389 | */ |
| 17390 | public static final int UNSPECIFIED = 0 << MODE_SHIFT; |
| 17391 | |
| 17392 | /** |
| 17393 | * Measure specification mode: The parent has determined an exact size |
| 17394 | * for the child. The child is going to be given those bounds regardless |
| 17395 | * of how big it wants to be. |
| 17396 | */ |
| 17397 | public static final int EXACTLY = 1 << MODE_SHIFT; |
| 17398 | |
| 17399 | /** |
| 17400 | * Measure specification mode: The child can be as large as it wants up |
| 17401 | * to the specified size. |
| 17402 | */ |
| 17403 | public static final int AT_MOST = 2 << MODE_SHIFT; |
| 17404 | |
| 17405 | /** |
| 17406 | * Creates a measure specification based on the supplied size and mode. |
| 17407 | * |
| 17408 | * The mode must always be one of the following: |
| 17409 | * <ul> |
| 17410 | * <li>{@link android.view.View.MeasureSpec#UNSPECIFIED}</li> |
| 17411 | * <li>{@link android.view.View.MeasureSpec#EXACTLY}</li> |
| 17412 | * <li>{@link android.view.View.MeasureSpec#AT_MOST}</li> |
| 17413 | * </ul> |
| 17414 | * |
Adam Powell | 2c8cc97 | 2012-12-07 18:04:51 -0800 | [diff] [blame] | 17415 | * <p><strong>Note:</strong> On API level 17 and lower, makeMeasureSpec's |
| 17416 | * implementation was such that the order of arguments did not matter |
| 17417 | * and overflow in either value could impact the resulting MeasureSpec. |
| 17418 | * {@link android.widget.RelativeLayout} was affected by this bug. |
| 17419 | * Apps targeting API levels greater than 17 will get the fixed, more strict |
| 17420 | * behavior.</p> |
| 17421 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17422 | * @param size the size of the measure specification |
| 17423 | * @param mode the mode of the measure specification |
| 17424 | * @return the measure specification based on size and mode |
| 17425 | */ |
| 17426 | public static int makeMeasureSpec(int size, int mode) { |
Adam Powell | 7da4b73 | 2012-12-07 15:28:33 -0800 | [diff] [blame] | 17427 | if (sUseBrokenMakeMeasureSpec) { |
| 17428 | return size + mode; |
| 17429 | } else { |
| 17430 | return (size & ~MODE_MASK) | (mode & MODE_MASK); |
| 17431 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17432 | } |
| 17433 | |
| 17434 | /** |
| 17435 | * Extracts the mode from the supplied measure specification. |
| 17436 | * |
| 17437 | * @param measureSpec the measure specification to extract the mode from |
| 17438 | * @return {@link android.view.View.MeasureSpec#UNSPECIFIED}, |
| 17439 | * {@link android.view.View.MeasureSpec#AT_MOST} or |
| 17440 | * {@link android.view.View.MeasureSpec#EXACTLY} |
| 17441 | */ |
| 17442 | public static int getMode(int measureSpec) { |
| 17443 | return (measureSpec & MODE_MASK); |
| 17444 | } |
| 17445 | |
| 17446 | /** |
| 17447 | * Extracts the size from the supplied measure specification. |
| 17448 | * |
| 17449 | * @param measureSpec the measure specification to extract the size from |
| 17450 | * @return the size in pixels defined in the supplied measure specification |
| 17451 | */ |
| 17452 | public static int getSize(int measureSpec) { |
| 17453 | return (measureSpec & ~MODE_MASK); |
| 17454 | } |
| 17455 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 17456 | static int adjust(int measureSpec, int delta) { |
| 17457 | return makeMeasureSpec(getSize(measureSpec + delta), getMode(measureSpec)); |
| 17458 | } |
| 17459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17460 | /** |
| 17461 | * Returns a String representation of the specified measure |
| 17462 | * specification. |
| 17463 | * |
| 17464 | * @param measureSpec the measure specification to convert to a String |
| 17465 | * @return a String with the following format: "MeasureSpec: MODE SIZE" |
| 17466 | */ |
| 17467 | public static String toString(int measureSpec) { |
| 17468 | int mode = getMode(measureSpec); |
| 17469 | int size = getSize(measureSpec); |
| 17470 | |
| 17471 | StringBuilder sb = new StringBuilder("MeasureSpec: "); |
| 17472 | |
| 17473 | if (mode == UNSPECIFIED) |
| 17474 | sb.append("UNSPECIFIED "); |
| 17475 | else if (mode == EXACTLY) |
| 17476 | sb.append("EXACTLY "); |
| 17477 | else if (mode == AT_MOST) |
| 17478 | sb.append("AT_MOST "); |
| 17479 | else |
| 17480 | sb.append(mode).append(" "); |
| 17481 | |
| 17482 | sb.append(size); |
| 17483 | return sb.toString(); |
| 17484 | } |
| 17485 | } |
| 17486 | |
| 17487 | class CheckForLongPress implements Runnable { |
| 17488 | |
| 17489 | private int mOriginalWindowAttachCount; |
| 17490 | |
| 17491 | public void run() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 17492 | if (isPressed() && (mParent != null) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17493 | && mOriginalWindowAttachCount == mWindowAttachCount) { |
| 17494 | if (performLongClick()) { |
| 17495 | mHasPerformedLongPress = true; |
| 17496 | } |
| 17497 | } |
| 17498 | } |
| 17499 | |
| 17500 | public void rememberWindowAttachCount() { |
| 17501 | mOriginalWindowAttachCount = mWindowAttachCount; |
| 17502 | } |
| 17503 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17504 | |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17505 | private final class CheckForTap implements Runnable { |
| 17506 | public void run() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 17507 | mPrivateFlags &= ~PFLAG_PREPRESSED; |
Adam Powell | 4d6f066 | 2012-02-21 15:11:11 -0800 | [diff] [blame] | 17508 | setPressed(true); |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 17509 | checkForLongClick(ViewConfiguration.getTapTimeout()); |
Adam Powell | e14579b | 2009-12-16 18:39:52 -0800 | [diff] [blame] | 17510 | } |
| 17511 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17512 | |
Adam Powell | a35d768 | 2010-03-12 14:48:13 -0800 | [diff] [blame] | 17513 | private final class PerformClick implements Runnable { |
| 17514 | public void run() { |
| 17515 | performClick(); |
| 17516 | } |
| 17517 | } |
| 17518 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17519 | /** @hide */ |
| 17520 | public void hackTurnOffWindowResizeAnim(boolean off) { |
| 17521 | mAttachInfo.mTurnOffWindowResizeAnim = off; |
| 17522 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17524 | /** |
Chet Haase | a00f386 | 2011-02-22 06:34:40 -0800 | [diff] [blame] | 17525 | * This method returns a ViewPropertyAnimator object, which can be used to animate |
| 17526 | * specific properties on this View. |
| 17527 | * |
| 17528 | * @return ViewPropertyAnimator The ViewPropertyAnimator associated with this View. |
| 17529 | */ |
| 17530 | public ViewPropertyAnimator animate() { |
| 17531 | if (mAnimator == null) { |
| 17532 | mAnimator = new ViewPropertyAnimator(this); |
| 17533 | } |
| 17534 | return mAnimator; |
| 17535 | } |
| 17536 | |
| 17537 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17538 | * Interface definition for a callback to be invoked when a hardware key event is |
| 17539 | * dispatched to this view. The callback will be invoked before the key event is |
| 17540 | * given to the view. This is only useful for hardware keyboards; a software input |
| 17541 | * method has no obligation to trigger this listener. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17542 | */ |
| 17543 | public interface OnKeyListener { |
| 17544 | /** |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17545 | * 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] | 17546 | * get a chance to respond before the target view. |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 17547 | * <p>Key presses in software keyboards will generally NOT trigger this method, |
| 17548 | * although some may elect to do so in some situations. Do not assume a |
| 17549 | * software input method has to be key-based; even if it is, it may use key presses |
| 17550 | * in a different way than you expect, so there is no way to reliably catch soft |
| 17551 | * input key presses. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17552 | * |
| 17553 | * @param v The view the key has been dispatched to. |
| 17554 | * @param keyCode The code for the physical key that was pressed |
| 17555 | * @param event The KeyEvent object containing full information about |
| 17556 | * the event. |
| 17557 | * @return True if the listener has consumed the event, false otherwise. |
| 17558 | */ |
| 17559 | boolean onKey(View v, int keyCode, KeyEvent event); |
| 17560 | } |
| 17561 | |
| 17562 | /** |
| 17563 | * Interface definition for a callback to be invoked when a touch event is |
| 17564 | * dispatched to this view. The callback will be invoked before the touch |
| 17565 | * event is given to the view. |
| 17566 | */ |
| 17567 | public interface OnTouchListener { |
| 17568 | /** |
| 17569 | * Called when a touch event is dispatched to a view. This allows listeners to |
| 17570 | * get a chance to respond before the target view. |
| 17571 | * |
| 17572 | * @param v The view the touch event has been dispatched to. |
| 17573 | * @param event The MotionEvent object containing full information about |
| 17574 | * the event. |
| 17575 | * @return True if the listener has consumed the event, false otherwise. |
| 17576 | */ |
| 17577 | boolean onTouch(View v, MotionEvent event); |
| 17578 | } |
| 17579 | |
| 17580 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 17581 | * Interface definition for a callback to be invoked when a hover event is |
| 17582 | * dispatched to this view. The callback will be invoked before the hover |
| 17583 | * event is given to the view. |
| 17584 | */ |
| 17585 | public interface OnHoverListener { |
| 17586 | /** |
| 17587 | * Called when a hover event is dispatched to a view. This allows listeners to |
| 17588 | * get a chance to respond before the target view. |
| 17589 | * |
| 17590 | * @param v The view the hover event has been dispatched to. |
| 17591 | * @param event The MotionEvent object containing full information about |
| 17592 | * the event. |
| 17593 | * @return True if the listener has consumed the event, false otherwise. |
| 17594 | */ |
| 17595 | boolean onHover(View v, MotionEvent event); |
| 17596 | } |
| 17597 | |
| 17598 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 17599 | * Interface definition for a callback to be invoked when a generic motion event is |
| 17600 | * dispatched to this view. The callback will be invoked before the generic motion |
| 17601 | * event is given to the view. |
| 17602 | */ |
| 17603 | public interface OnGenericMotionListener { |
| 17604 | /** |
| 17605 | * Called when a generic motion event is dispatched to a view. This allows listeners to |
| 17606 | * get a chance to respond before the target view. |
| 17607 | * |
| 17608 | * @param v The view the generic motion event has been dispatched to. |
| 17609 | * @param event The MotionEvent object containing full information about |
| 17610 | * the event. |
| 17611 | * @return True if the listener has consumed the event, false otherwise. |
| 17612 | */ |
| 17613 | boolean onGenericMotion(View v, MotionEvent event); |
| 17614 | } |
| 17615 | |
| 17616 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17617 | * Interface definition for a callback to be invoked when a view has been clicked and held. |
| 17618 | */ |
| 17619 | public interface OnLongClickListener { |
| 17620 | /** |
| 17621 | * Called when a view has been clicked and held. |
| 17622 | * |
| 17623 | * @param v The view that was clicked and held. |
| 17624 | * |
Brad Fitzpatrick | 69ea4e1 | 2011-01-05 11:13:40 -0800 | [diff] [blame] | 17625 | * @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] | 17626 | */ |
| 17627 | boolean onLongClick(View v); |
| 17628 | } |
| 17629 | |
| 17630 | /** |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17631 | * Interface definition for a callback to be invoked when a drag is being dispatched |
| 17632 | * to this view. The callback will be invoked before the hosting view's own |
| 17633 | * onDrag(event) method. If the listener wants to fall back to the hosting view's |
| 17634 | * onDrag(event) behavior, it should return 'false' from this callback. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 17635 | * |
| 17636 | * <div class="special reference"> |
| 17637 | * <h3>Developer Guides</h3> |
| 17638 | * <p>For a guide to implementing drag and drop features, read the |
| 17639 | * <a href="{@docRoot}guide/topics/ui/drag-drop.html">Drag and Drop</a> developer guide.</p> |
| 17640 | * </div> |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17641 | */ |
| 17642 | public interface OnDragListener { |
| 17643 | /** |
| 17644 | * Called when a drag event is dispatched to a view. This allows listeners |
| 17645 | * to get a chance to override base View behavior. |
| 17646 | * |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17647 | * @param v The View that received the drag event. |
| 17648 | * @param event The {@link android.view.DragEvent} object for the drag event. |
| 17649 | * @return {@code true} if the drag event was handled successfully, or {@code false} |
| 17650 | * if the drag event was not handled. Note that {@code false} will trigger the View |
| 17651 | * to call its {@link #onDragEvent(DragEvent) onDragEvent()} handler. |
Chris Tate | 32affef | 2010-10-18 15:29:21 -0700 | [diff] [blame] | 17652 | */ |
| 17653 | boolean onDrag(View v, DragEvent event); |
| 17654 | } |
| 17655 | |
| 17656 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17657 | * Interface definition for a callback to be invoked when the focus state of |
| 17658 | * a view changed. |
| 17659 | */ |
| 17660 | public interface OnFocusChangeListener { |
| 17661 | /** |
| 17662 | * Called when the focus state of a view has changed. |
| 17663 | * |
| 17664 | * @param v The view whose state has changed. |
| 17665 | * @param hasFocus The new focus state of v. |
| 17666 | */ |
| 17667 | void onFocusChange(View v, boolean hasFocus); |
| 17668 | } |
| 17669 | |
| 17670 | /** |
| 17671 | * Interface definition for a callback to be invoked when a view is clicked. |
| 17672 | */ |
| 17673 | public interface OnClickListener { |
| 17674 | /** |
| 17675 | * Called when a view has been clicked. |
| 17676 | * |
| 17677 | * @param v The view that was clicked. |
| 17678 | */ |
| 17679 | void onClick(View v); |
| 17680 | } |
| 17681 | |
| 17682 | /** |
| 17683 | * Interface definition for a callback to be invoked when the context menu |
| 17684 | * for this view is being built. |
| 17685 | */ |
| 17686 | public interface OnCreateContextMenuListener { |
| 17687 | /** |
| 17688 | * Called when the context menu for this view is being built. It is not |
| 17689 | * safe to hold onto the menu after this method returns. |
| 17690 | * |
| 17691 | * @param menu The context menu that is being built |
| 17692 | * @param v The view for which the context menu is being built |
| 17693 | * @param menuInfo Extra information about the item for which the |
| 17694 | * context menu should be shown. This information will vary |
| 17695 | * depending on the class of v. |
| 17696 | */ |
| 17697 | void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo); |
| 17698 | } |
| 17699 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17700 | /** |
| 17701 | * 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] | 17702 | * visibility. This reports <strong>global</strong> changes to the system UI |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17703 | * state, not what the application is requesting. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17704 | * |
Philip Milne | 6c8ea06 | 2012-04-03 17:38:43 -0700 | [diff] [blame] | 17705 | * @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener) |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17706 | */ |
| 17707 | public interface OnSystemUiVisibilityChangeListener { |
| 17708 | /** |
| 17709 | * Called when the status bar changes visibility because of a call to |
Romain Guy | 5c22a8c | 2011-05-13 11:48:45 -0700 | [diff] [blame] | 17710 | * {@link View#setSystemUiVisibility(int)}. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17711 | * |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17712 | * @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE}, |
| 17713 | * {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, and {@link #SYSTEM_UI_FLAG_FULLSCREEN}. |
| 17714 | * This tells you the <strong>global</strong> state of these UI visibility |
| 17715 | * flags, not what your app is currently applying. |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17716 | */ |
| 17717 | public void onSystemUiVisibilityChange(int visibility); |
| 17718 | } |
| 17719 | |
Adam Powell | 4afd62b | 2011-02-18 15:02:18 -0800 | [diff] [blame] | 17720 | /** |
| 17721 | * Interface definition for a callback to be invoked when this view is attached |
| 17722 | * or detached from its window. |
| 17723 | */ |
| 17724 | public interface OnAttachStateChangeListener { |
| 17725 | /** |
| 17726 | * Called when the view is attached to a window. |
| 17727 | * @param v The view that was attached |
| 17728 | */ |
| 17729 | public void onViewAttachedToWindow(View v); |
| 17730 | /** |
| 17731 | * Called when the view is detached from a window. |
| 17732 | * @param v The view that was detached |
| 17733 | */ |
| 17734 | public void onViewDetachedFromWindow(View v); |
| 17735 | } |
| 17736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17737 | private final class UnsetPressedState implements Runnable { |
| 17738 | public void run() { |
| 17739 | setPressed(false); |
| 17740 | } |
| 17741 | } |
| 17742 | |
| 17743 | /** |
| 17744 | * Base class for derived classes that want to save and restore their own |
| 17745 | * state in {@link android.view.View#onSaveInstanceState()}. |
| 17746 | */ |
| 17747 | public static class BaseSavedState extends AbsSavedState { |
| 17748 | /** |
| 17749 | * Constructor used when reading from a parcel. Reads the state of the superclass. |
| 17750 | * |
| 17751 | * @param source |
| 17752 | */ |
| 17753 | public BaseSavedState(Parcel source) { |
| 17754 | super(source); |
| 17755 | } |
| 17756 | |
| 17757 | /** |
| 17758 | * Constructor called by derived classes when creating their SavedState objects |
| 17759 | * |
| 17760 | * @param superState The state of the superclass of this view |
| 17761 | */ |
| 17762 | public BaseSavedState(Parcelable superState) { |
| 17763 | super(superState); |
| 17764 | } |
| 17765 | |
| 17766 | public static final Parcelable.Creator<BaseSavedState> CREATOR = |
| 17767 | new Parcelable.Creator<BaseSavedState>() { |
| 17768 | public BaseSavedState createFromParcel(Parcel in) { |
| 17769 | return new BaseSavedState(in); |
| 17770 | } |
| 17771 | |
| 17772 | public BaseSavedState[] newArray(int size) { |
| 17773 | return new BaseSavedState[size]; |
| 17774 | } |
| 17775 | }; |
| 17776 | } |
| 17777 | |
| 17778 | /** |
| 17779 | * A set of information given to a view when it is attached to its parent |
| 17780 | * window. |
| 17781 | */ |
| 17782 | static class AttachInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17783 | interface Callbacks { |
| 17784 | void playSoundEffect(int effectId); |
| 17785 | boolean performHapticFeedback(int effectId, boolean always); |
| 17786 | } |
| 17787 | |
| 17788 | /** |
| 17789 | * InvalidateInfo is used to post invalidate(int, int, int, int) messages |
| 17790 | * to a Handler. This class contains the target (View) to invalidate and |
| 17791 | * the coordinates of the dirty rectangle. |
| 17792 | * |
| 17793 | * For performance purposes, this class also implements a pool of up to |
| 17794 | * POOL_LIMIT objects that get reused. This reduces memory allocations |
| 17795 | * whenever possible. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17796 | */ |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17797 | static class InvalidateInfo { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17798 | private static final int POOL_LIMIT = 10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17799 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17800 | private static final SynchronizedPool<InvalidateInfo> sPool = |
| 17801 | new SynchronizedPool<InvalidateInfo>(POOL_LIMIT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17802 | |
| 17803 | View target; |
| 17804 | |
| 17805 | int left; |
| 17806 | int top; |
| 17807 | int right; |
| 17808 | int bottom; |
| 17809 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17810 | public static InvalidateInfo obtain() { |
| 17811 | InvalidateInfo instance = sPool.acquire(); |
| 17812 | return (instance != null) ? instance : new InvalidateInfo(); |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17813 | } |
| 17814 | |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 17815 | public void recycle() { |
| 17816 | target = null; |
Romain Guy | d928d68 | 2009-03-31 17:52:16 -0700 | [diff] [blame] | 17817 | sPool.release(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17818 | } |
| 17819 | } |
| 17820 | |
| 17821 | final IWindowSession mSession; |
| 17822 | |
| 17823 | final IWindow mWindow; |
| 17824 | |
| 17825 | final IBinder mWindowToken; |
| 17826 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 17827 | final Display mDisplay; |
| 17828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17829 | final Callbacks mRootCallbacks; |
| 17830 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 17831 | HardwareCanvas mHardwareCanvas; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 17832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17833 | /** |
| 17834 | * The top view of the hierarchy. |
| 17835 | */ |
| 17836 | View mRootView; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17838 | IBinder mPanelParentWindowToken; |
| 17839 | Surface mSurface; |
| 17840 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17841 | boolean mHardwareAccelerated; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 17842 | boolean mHardwareAccelerationRequested; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 17843 | HardwareRenderer mHardwareRenderer; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17844 | |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 17845 | boolean mScreenOn; |
| 17846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17847 | /** |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 17848 | * Scale factor used by the compatibility mode |
| 17849 | */ |
| 17850 | float mApplicationScale; |
| 17851 | |
| 17852 | /** |
| 17853 | * Indicates whether the application is in compatibility mode |
| 17854 | */ |
| 17855 | boolean mScalingRequired; |
| 17856 | |
| 17857 | /** |
Romain Guy | 3d1728c | 2012-10-31 20:31:58 -0700 | [diff] [blame] | 17858 | * If set, ViewRootImpl doesn't use its lame animation for when the window resizes. |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17859 | */ |
| 17860 | boolean mTurnOffWindowResizeAnim; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 17861 | |
Dianne Hackborn | 63042d6 | 2011-01-26 18:56:29 -0800 | [diff] [blame] | 17862 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17863 | * Left position of this view's window |
| 17864 | */ |
| 17865 | int mWindowLeft; |
| 17866 | |
| 17867 | /** |
| 17868 | * Top position of this view's window |
| 17869 | */ |
| 17870 | int mWindowTop; |
| 17871 | |
| 17872 | /** |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17873 | * Indicates whether views need to use 32-bit drawing caches |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17874 | */ |
Adam Powell | 26153a3 | 2010-11-08 15:22:27 -0800 | [diff] [blame] | 17875 | boolean mUse32BitDrawingCache; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 17876 | |
| 17877 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17878 | * For windows that are full-screen but using insets to layout inside |
| 17879 | * of the screen decorations, these are the current insets for the |
| 17880 | * content of the window. |
| 17881 | */ |
| 17882 | final Rect mContentInsets = new Rect(); |
| 17883 | |
| 17884 | /** |
| 17885 | * For windows that are full-screen but using insets to layout inside |
| 17886 | * of the screen decorations, these are the current insets for the |
| 17887 | * actual visible parts of the window. |
| 17888 | */ |
| 17889 | final Rect mVisibleInsets = new Rect(); |
| 17890 | |
| 17891 | /** |
| 17892 | * The internal insets given by this window. This value is |
| 17893 | * supplied by the client (through |
| 17894 | * {@link ViewTreeObserver.OnComputeInternalInsetsListener}) and will |
| 17895 | * be given to the window manager when changed to be used in laying |
| 17896 | * out windows behind it. |
| 17897 | */ |
| 17898 | final ViewTreeObserver.InternalInsetsInfo mGivenInternalInsets |
| 17899 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 17900 | |
| 17901 | /** |
| 17902 | * All views in the window's hierarchy that serve as scroll containers, |
| 17903 | * used to determine if the window can be resized or must be panned |
| 17904 | * to adjust for a soft input area. |
| 17905 | */ |
| 17906 | final ArrayList<View> mScrollContainers = new ArrayList<View>(); |
| 17907 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 17908 | final KeyEvent.DispatcherState mKeyDispatchState |
| 17909 | = new KeyEvent.DispatcherState(); |
| 17910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17911 | /** |
| 17912 | * Indicates whether the view's window currently has the focus. |
| 17913 | */ |
| 17914 | boolean mHasWindowFocus; |
| 17915 | |
| 17916 | /** |
| 17917 | * The current visibility of the window. |
| 17918 | */ |
| 17919 | int mWindowVisibility; |
| 17920 | |
| 17921 | /** |
| 17922 | * Indicates the time at which drawing started to occur. |
| 17923 | */ |
| 17924 | long mDrawingTime; |
| 17925 | |
| 17926 | /** |
Romain Guy | 5bcdff4 | 2009-05-14 21:27:18 -0700 | [diff] [blame] | 17927 | * Indicates whether or not ignoring the DIRTY_MASK flags. |
| 17928 | */ |
| 17929 | boolean mIgnoreDirtyState; |
| 17930 | |
| 17931 | /** |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 17932 | * This flag tracks when the mIgnoreDirtyState flag is set during draw(), |
| 17933 | * to avoid clearing that flag prematurely. |
| 17934 | */ |
| 17935 | boolean mSetIgnoreDirtyState = false; |
| 17936 | |
| 17937 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17938 | * Indicates whether the view's window is currently in touch mode. |
| 17939 | */ |
| 17940 | boolean mInTouchMode; |
| 17941 | |
| 17942 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 17943 | * Indicates that ViewAncestor should trigger a global layout change |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17944 | * the next time it performs a traversal |
| 17945 | */ |
| 17946 | boolean mRecomputeGlobalAttributes; |
| 17947 | |
| 17948 | /** |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 17949 | * Always report new attributes at next traversal. |
| 17950 | */ |
| 17951 | boolean mForceReportNewAttributes; |
| 17952 | |
| 17953 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17954 | * Set during a traveral if any views want to keep the screen on. |
| 17955 | */ |
| 17956 | boolean mKeepScreenOn; |
| 17957 | |
| 17958 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17959 | * Bitwise-or of all of the values that views have passed to setSystemUiVisibility(). |
| 17960 | */ |
| 17961 | int mSystemUiVisibility; |
| 17962 | |
| 17963 | /** |
Dianne Hackborn | 139e5aa | 2012-05-05 20:36:38 -0700 | [diff] [blame] | 17964 | * Hack to force certain system UI visibility flags to be cleared. |
| 17965 | */ |
| 17966 | int mDisabledSystemUiVisibility; |
| 17967 | |
| 17968 | /** |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 17969 | * Last global system UI visibility reported by the window manager. |
| 17970 | */ |
| 17971 | int mGlobalSystemUiVisibility; |
| 17972 | |
| 17973 | /** |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 17974 | * True if a view in this hierarchy has an OnSystemUiVisibilityChangeListener |
| 17975 | * attached. |
| 17976 | */ |
| 17977 | boolean mHasSystemUiListeners; |
| 17978 | |
| 17979 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17980 | * Set if the visibility of any views has changed. |
| 17981 | */ |
| 17982 | boolean mViewVisibilityChanged; |
| 17983 | |
| 17984 | /** |
| 17985 | * Set to true if a view has been scrolled. |
| 17986 | */ |
| 17987 | boolean mViewScrollChanged; |
| 17988 | |
| 17989 | /** |
| 17990 | * Global to the view hierarchy used as a temporary for dealing with |
| 17991 | * x/y points in the transparent region computations. |
| 17992 | */ |
| 17993 | final int[] mTransparentLocation = new int[2]; |
| 17994 | |
| 17995 | /** |
| 17996 | * Global to the view hierarchy used as a temporary for dealing with |
| 17997 | * x/y points in the ViewGroup.invalidateChild implementation. |
| 17998 | */ |
| 17999 | final int[] mInvalidateChildLocation = new int[2]; |
| 18000 | |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 18001 | |
| 18002 | /** |
| 18003 | * Global to the view hierarchy used as a temporary for dealing with |
| 18004 | * x/y location when view is transformed. |
| 18005 | */ |
| 18006 | final float[] mTmpTransformLocation = new float[2]; |
| 18007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18008 | /** |
| 18009 | * The view tree observer used to dispatch global events like |
| 18010 | * layout, pre-draw, touch mode change, etc. |
| 18011 | */ |
| 18012 | final ViewTreeObserver mTreeObserver = new ViewTreeObserver(); |
| 18013 | |
| 18014 | /** |
| 18015 | * A Canvas used by the view hierarchy to perform bitmap caching. |
| 18016 | */ |
| 18017 | Canvas mCanvas; |
| 18018 | |
| 18019 | /** |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 18020 | * The view root impl. |
| 18021 | */ |
| 18022 | final ViewRootImpl mViewRootImpl; |
| 18023 | |
| 18024 | /** |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 18025 | * 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] | 18026 | * handler can be used to pump events in the UI events queue. |
| 18027 | */ |
| 18028 | final Handler mHandler; |
| 18029 | |
| 18030 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18031 | * Temporary for use in computing invalidate rectangles while |
| 18032 | * calling up the hierarchy. |
| 18033 | */ |
| 18034 | final Rect mTmpInvalRect = new Rect(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 18035 | |
| 18036 | /** |
Chet Haase | c3aa361 | 2010-06-17 08:50:37 -0700 | [diff] [blame] | 18037 | * Temporary for use in computing hit areas with transformed views |
| 18038 | */ |
| 18039 | final RectF mTmpTransformRect = new RectF(); |
| 18040 | |
| 18041 | /** |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 18042 | * Temporary for use in transforming invalidation rect |
| 18043 | */ |
| 18044 | final Matrix mTmpMatrix = new Matrix(); |
| 18045 | |
| 18046 | /** |
| 18047 | * Temporary for use in transforming invalidation rect |
| 18048 | */ |
| 18049 | final Transformation mTmpTransformation = new Transformation(); |
| 18050 | |
| 18051 | /** |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 18052 | * Temporary list for use in collecting focusable descendents of a view. |
| 18053 | */ |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 18054 | final ArrayList<View> mTempArrayList = new ArrayList<View>(24); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 18055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18056 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 18057 | * The id of the window for accessibility purposes. |
| 18058 | */ |
| 18059 | int mAccessibilityWindowId = View.NO_ID; |
| 18060 | |
| 18061 | /** |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 18062 | * Flags related to accessibility processing. |
| 18063 | * |
| 18064 | * @see AccessibilityNodeInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS |
| 18065 | * @see AccessibilityNodeInfo#FLAG_REPORT_VIEW_IDS |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 18066 | */ |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 18067 | int mAccessibilityFetchFlags; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 18068 | |
| 18069 | /** |
| 18070 | * The drawable for highlighting accessibility focus. |
| 18071 | */ |
| 18072 | Drawable mAccessibilityFocusDrawable; |
| 18073 | |
| 18074 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 18075 | * Show where the margins, bounds and layout bounds are for each view. |
| 18076 | */ |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 18077 | boolean mDebugLayout = SystemProperties.getBoolean(DEBUG_LAYOUT_PROPERTY, false); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 18078 | |
| 18079 | /** |
Romain Guy | ab4c4f4f | 2012-05-06 13:11:24 -0700 | [diff] [blame] | 18080 | * Point used to compute visible regions. |
| 18081 | */ |
| 18082 | final Point mPoint = new Point(); |
| 18083 | |
| 18084 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 18085 | * Used to track which View originated a requestLayout() call, used when |
| 18086 | * requestLayout() is called during layout. |
| 18087 | */ |
| 18088 | View mViewRequestingLayout; |
| 18089 | |
| 18090 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18091 | * Creates a new set of attachment information with the specified |
| 18092 | * events handler and thread. |
| 18093 | * |
| 18094 | * @param handler the events handler the view must use |
| 18095 | */ |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 18096 | AttachInfo(IWindowSession session, IWindow window, Display display, |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 18097 | ViewRootImpl viewRootImpl, Handler handler, Callbacks effectPlayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18098 | mSession = session; |
| 18099 | mWindow = window; |
| 18100 | mWindowToken = window.asBinder(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 18101 | mDisplay = display; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 18102 | mViewRootImpl = viewRootImpl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18103 | mHandler = handler; |
| 18104 | mRootCallbacks = effectPlayer; |
| 18105 | } |
| 18106 | } |
| 18107 | |
| 18108 | /** |
| 18109 | * <p>ScrollabilityCache holds various fields used by a View when scrolling |
| 18110 | * is supported. This avoids keeping too many unused fields in most |
| 18111 | * instances of View.</p> |
| 18112 | */ |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18113 | private static class ScrollabilityCache implements Runnable { |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18114 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18115 | /** |
| 18116 | * Scrollbars are not visible |
| 18117 | */ |
| 18118 | public static final int OFF = 0; |
| 18119 | |
| 18120 | /** |
| 18121 | * Scrollbars are visible |
| 18122 | */ |
| 18123 | public static final int ON = 1; |
| 18124 | |
| 18125 | /** |
| 18126 | * Scrollbars are fading away |
| 18127 | */ |
| 18128 | public static final int FADING = 2; |
| 18129 | |
| 18130 | public boolean fadeScrollBars; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18132 | public int fadingEdgeLength; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18133 | public int scrollBarDefaultDelayBeforeFade; |
| 18134 | public int scrollBarFadeDuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18135 | |
| 18136 | public int scrollBarSize; |
| 18137 | public ScrollBarDrawable scrollBar; |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18138 | public float[] interpolatorValues; |
| 18139 | public View host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18140 | |
| 18141 | public final Paint paint; |
| 18142 | public final Matrix matrix; |
| 18143 | public Shader shader; |
| 18144 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18145 | public final Interpolator scrollBarInterpolator = new Interpolator(1, 2); |
| 18146 | |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18147 | private static final float[] OPAQUE = { 255 }; |
| 18148 | private static final float[] TRANSPARENT = { 0.0f }; |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18149 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18150 | /** |
| 18151 | * When fading should start. This time moves into the future every time |
| 18152 | * a new scroll happens. Measured based on SystemClock.uptimeMillis() |
| 18153 | */ |
| 18154 | public long fadeStartTime; |
| 18155 | |
| 18156 | |
| 18157 | /** |
| 18158 | * The current state of the scrollbars: ON, OFF, or FADING |
| 18159 | */ |
| 18160 | public int state = OFF; |
| 18161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18162 | private int mLastColor; |
| 18163 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18164 | public ScrollabilityCache(ViewConfiguration configuration, View host) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18165 | fadingEdgeLength = configuration.getScaledFadingEdgeLength(); |
| 18166 | scrollBarSize = configuration.getScaledScrollBarSize(); |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 18167 | scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay(); |
| 18168 | scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18169 | |
| 18170 | paint = new Paint(); |
| 18171 | matrix = new Matrix(); |
| 18172 | // use use a height of 1, and then wack the matrix each time we |
| 18173 | // actually use it. |
| 18174 | 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] | 18175 | paint.setShader(shader); |
| 18176 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18177 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18178 | this.host = host; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18179 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 18180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18181 | public void setFadeColor(int color) { |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18182 | if (color != mLastColor) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18183 | mLastColor = color; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 18184 | |
Romain Guy | d679b57 | 2012-08-29 21:49:00 -0700 | [diff] [blame] | 18185 | if (color != 0) { |
| 18186 | shader = new LinearGradient(0, 0, 0, 1, color | 0xFF000000, |
| 18187 | color & 0x00FFFFFF, Shader.TileMode.CLAMP); |
| 18188 | paint.setShader(shader); |
| 18189 | // Restore the default transfer mode (src_over) |
| 18190 | paint.setXfermode(null); |
| 18191 | } else { |
| 18192 | shader = new LinearGradient(0, 0, 0, 1, 0xFF000000, 0, Shader.TileMode.CLAMP); |
| 18193 | paint.setShader(shader); |
| 18194 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); |
| 18195 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18196 | } |
| 18197 | } |
Joe Malin | 32736f0 | 2011-01-19 16:14:20 -0800 | [diff] [blame] | 18198 | |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18199 | public void run() { |
Mike Cleron | 3ecd58c | 2009-09-28 11:39:02 -0700 | [diff] [blame] | 18200 | long now = AnimationUtils.currentAnimationTimeMillis(); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18201 | if (now >= fadeStartTime) { |
| 18202 | |
| 18203 | // the animation fades the scrollbars out by changing |
| 18204 | // the opacity (alpha) from fully opaque to fully |
| 18205 | // transparent |
| 18206 | int nextFrame = (int) now; |
| 18207 | int framesCount = 0; |
| 18208 | |
| 18209 | Interpolator interpolator = scrollBarInterpolator; |
| 18210 | |
| 18211 | // Start opaque |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18212 | interpolator.setKeyFrame(framesCount++, nextFrame, OPAQUE); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18213 | |
| 18214 | // End transparent |
| 18215 | nextFrame += scrollBarFadeDuration; |
Gilles Debunne | 3dbf55c | 2010-12-16 10:31:51 -0800 | [diff] [blame] | 18216 | interpolator.setKeyFrame(framesCount, nextFrame, TRANSPARENT); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18217 | |
| 18218 | state = FADING; |
| 18219 | |
| 18220 | // Kick off the fade animation |
Romain Guy | 0fd89bf | 2011-01-26 15:41:30 -0800 | [diff] [blame] | 18221 | host.invalidate(true); |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18222 | } |
| 18223 | } |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18224 | } |
Mike Cleron | f116bf8 | 2009-09-27 19:14:12 -0700 | [diff] [blame] | 18225 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 18226 | /** |
| 18227 | * Resuable callback for sending |
| 18228 | * {@link AccessibilityEvent#TYPE_VIEW_SCROLLED} accessibility event. |
| 18229 | */ |
| 18230 | private class SendViewScrolledAccessibilityEvent implements Runnable { |
| 18231 | public volatile boolean mIsPending; |
| 18232 | |
| 18233 | public void run() { |
| 18234 | sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SCROLLED); |
| 18235 | mIsPending = false; |
| 18236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18237 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18238 | |
| 18239 | /** |
| 18240 | * <p> |
| 18241 | * This class represents a delegate that can be registered in a {@link View} |
| 18242 | * to enhance accessibility support via composition rather via inheritance. |
| 18243 | * It is specifically targeted to widget developers that extend basic View |
| 18244 | * classes i.e. classes in package android.view, that would like their |
| 18245 | * applications to be backwards compatible. |
| 18246 | * </p> |
Joe Fernandez | e1302ed | 2012-02-06 14:30:15 -0800 | [diff] [blame] | 18247 | * <div class="special reference"> |
| 18248 | * <h3>Developer Guides</h3> |
| 18249 | * <p>For more information about making applications accessible, read the |
| 18250 | * <a href="{@docRoot}guide/topics/ui/accessibility/index.html">Accessibility</a> |
| 18251 | * developer guide.</p> |
| 18252 | * </div> |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18253 | * <p> |
| 18254 | * A scenario in which a developer would like to use an accessibility delegate |
| 18255 | * is overriding a method introduced in a later API version then the minimal API |
| 18256 | * version supported by the application. For example, the method |
| 18257 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} is not available |
| 18258 | * in API version 4 when the accessibility APIs were first introduced. If a |
| 18259 | * developer would like his application to run on API version 4 devices (assuming |
| 18260 | * all other APIs used by the application are version 4 or lower) and take advantage |
| 18261 | * of this method, instead of overriding the method which would break the application's |
| 18262 | * backwards compatibility, he can override the corresponding method in this |
| 18263 | * delegate and register the delegate in the target View if the API version of |
| 18264 | * the system is high enough i.e. the API version is same or higher to the API |
| 18265 | * version that introduced |
| 18266 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)}. |
| 18267 | * </p> |
| 18268 | * <p> |
| 18269 | * Here is an example implementation: |
| 18270 | * </p> |
| 18271 | * <code><pre><p> |
| 18272 | * if (Build.VERSION.SDK_INT >= 14) { |
| 18273 | * // If the API version is equal of higher than the version in |
| 18274 | * // which onInitializeAccessibilityNodeInfo was introduced we |
| 18275 | * // register a delegate with a customized implementation. |
| 18276 | * View view = findViewById(R.id.view_id); |
| 18277 | * view.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 18278 | * public void onInitializeAccessibilityNodeInfo(View host, |
| 18279 | * AccessibilityNodeInfo info) { |
| 18280 | * // Let the default implementation populate the info. |
| 18281 | * super.onInitializeAccessibilityNodeInfo(host, info); |
| 18282 | * // Set some other information. |
| 18283 | * info.setEnabled(host.isEnabled()); |
| 18284 | * } |
| 18285 | * }); |
| 18286 | * } |
| 18287 | * </code></pre></p> |
| 18288 | * <p> |
| 18289 | * This delegate contains methods that correspond to the accessibility methods |
| 18290 | * in View. If a delegate has been specified the implementation in View hands |
| 18291 | * off handling to the corresponding method in this delegate. The default |
| 18292 | * implementation the delegate methods behaves exactly as the corresponding |
| 18293 | * method in View for the case of no accessibility delegate been set. Hence, |
| 18294 | * to customize the behavior of a View method, clients can override only the |
| 18295 | * corresponding delegate method without altering the behavior of the rest |
| 18296 | * accessibility related methods of the host view. |
| 18297 | * </p> |
| 18298 | */ |
| 18299 | public static class AccessibilityDelegate { |
| 18300 | |
| 18301 | /** |
| 18302 | * Sends an accessibility event of the given type. If accessibility is not |
| 18303 | * enabled this method has no effect. |
| 18304 | * <p> |
| 18305 | * The default implementation behaves as {@link View#sendAccessibilityEvent(int) |
| 18306 | * View#sendAccessibilityEvent(int)} for the case of no accessibility delegate |
| 18307 | * been set. |
| 18308 | * </p> |
| 18309 | * |
| 18310 | * @param host The View hosting the delegate. |
| 18311 | * @param eventType The type of the event to send. |
| 18312 | * |
| 18313 | * @see View#sendAccessibilityEvent(int) View#sendAccessibilityEvent(int) |
| 18314 | */ |
| 18315 | public void sendAccessibilityEvent(View host, int eventType) { |
| 18316 | host.sendAccessibilityEventInternal(eventType); |
| 18317 | } |
| 18318 | |
| 18319 | /** |
alanv | 8eeefef | 2012-05-07 16:57:53 -0700 | [diff] [blame] | 18320 | * Performs the specified accessibility action on the view. For |
| 18321 | * possible accessibility actions look at {@link AccessibilityNodeInfo}. |
| 18322 | * <p> |
| 18323 | * The default implementation behaves as |
| 18324 | * {@link View#performAccessibilityAction(int, Bundle) |
| 18325 | * View#performAccessibilityAction(int, Bundle)} for the case of |
| 18326 | * no accessibility delegate been set. |
| 18327 | * </p> |
| 18328 | * |
| 18329 | * @param action The action to perform. |
| 18330 | * @return Whether the action was performed. |
| 18331 | * |
| 18332 | * @see View#performAccessibilityAction(int, Bundle) |
| 18333 | * View#performAccessibilityAction(int, Bundle) |
| 18334 | */ |
| 18335 | public boolean performAccessibilityAction(View host, int action, Bundle args) { |
| 18336 | return host.performAccessibilityActionInternal(action, args); |
| 18337 | } |
| 18338 | |
| 18339 | /** |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18340 | * Sends an accessibility event. This method behaves exactly as |
| 18341 | * {@link #sendAccessibilityEvent(View, int)} but takes as an argument an |
| 18342 | * empty {@link AccessibilityEvent} and does not perform a check whether |
| 18343 | * accessibility is enabled. |
| 18344 | * <p> |
| 18345 | * The default implementation behaves as |
| 18346 | * {@link View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18347 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent)} for |
| 18348 | * the case of no accessibility delegate been set. |
| 18349 | * </p> |
| 18350 | * |
| 18351 | * @param host The View hosting the delegate. |
| 18352 | * @param event The event to send. |
| 18353 | * |
| 18354 | * @see View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18355 | * View#sendAccessibilityEventUnchecked(AccessibilityEvent) |
| 18356 | */ |
| 18357 | public void sendAccessibilityEventUnchecked(View host, AccessibilityEvent event) { |
| 18358 | host.sendAccessibilityEventUncheckedInternal(event); |
| 18359 | } |
| 18360 | |
| 18361 | /** |
| 18362 | * Dispatches an {@link AccessibilityEvent} to the host {@link View} first and then |
| 18363 | * to its children for adding their text content to the event. |
| 18364 | * <p> |
| 18365 | * The default implementation behaves as |
| 18366 | * {@link View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18367 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18368 | * the case of no accessibility delegate been set. |
| 18369 | * </p> |
| 18370 | * |
| 18371 | * @param host The View hosting the delegate. |
| 18372 | * @param event The event. |
| 18373 | * @return True if the event population was completed. |
| 18374 | * |
| 18375 | * @see View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18376 | * View#dispatchPopulateAccessibilityEvent(AccessibilityEvent) |
| 18377 | */ |
| 18378 | public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18379 | return host.dispatchPopulateAccessibilityEventInternal(event); |
| 18380 | } |
| 18381 | |
| 18382 | /** |
| 18383 | * Gives a chance to the host View to populate the accessibility event with its |
| 18384 | * text content. |
| 18385 | * <p> |
| 18386 | * The default implementation behaves as |
| 18387 | * {@link View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18388 | * View#onPopulateAccessibilityEvent(AccessibilityEvent)} for |
| 18389 | * the case of no accessibility delegate been set. |
| 18390 | * </p> |
| 18391 | * |
| 18392 | * @param host The View hosting the delegate. |
| 18393 | * @param event The accessibility event which to populate. |
| 18394 | * |
| 18395 | * @see View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18396 | * View#onPopulateAccessibilityEvent(AccessibilityEvent) |
| 18397 | */ |
| 18398 | public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18399 | host.onPopulateAccessibilityEventInternal(event); |
| 18400 | } |
| 18401 | |
| 18402 | /** |
| 18403 | * Initializes an {@link AccessibilityEvent} with information about the |
| 18404 | * the host View which is the event source. |
| 18405 | * <p> |
| 18406 | * The default implementation behaves as |
| 18407 | * {@link View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18408 | * View#onInitializeAccessibilityEvent(AccessibilityEvent)} for |
| 18409 | * the case of no accessibility delegate been set. |
| 18410 | * </p> |
| 18411 | * |
| 18412 | * @param host The View hosting the delegate. |
| 18413 | * @param event The event to initialize. |
| 18414 | * |
| 18415 | * @see View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18416 | * View#onInitializeAccessibilityEvent(AccessibilityEvent) |
| 18417 | */ |
| 18418 | public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { |
| 18419 | host.onInitializeAccessibilityEventInternal(event); |
| 18420 | } |
| 18421 | |
| 18422 | /** |
| 18423 | * Initializes an {@link AccessibilityNodeInfo} with information about the host view. |
| 18424 | * <p> |
| 18425 | * The default implementation behaves as |
| 18426 | * {@link View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18427 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)} for |
| 18428 | * the case of no accessibility delegate been set. |
| 18429 | * </p> |
| 18430 | * |
| 18431 | * @param host The View hosting the delegate. |
| 18432 | * @param info The instance to initialize. |
| 18433 | * |
| 18434 | * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18435 | * View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo) |
| 18436 | */ |
| 18437 | public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) { |
| 18438 | host.onInitializeAccessibilityNodeInfoInternal(info); |
| 18439 | } |
| 18440 | |
| 18441 | /** |
| 18442 | * Called when a child of the host View has requested sending an |
| 18443 | * {@link AccessibilityEvent} and gives an opportunity to the parent (the host) |
| 18444 | * to augment the event. |
| 18445 | * <p> |
| 18446 | * The default implementation behaves as |
| 18447 | * {@link ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18448 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent)} for |
| 18449 | * the case of no accessibility delegate been set. |
| 18450 | * </p> |
| 18451 | * |
| 18452 | * @param host The View hosting the delegate. |
| 18453 | * @param child The child which requests sending the event. |
| 18454 | * @param event The event to be sent. |
| 18455 | * @return True if the event should be sent |
| 18456 | * |
| 18457 | * @see ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18458 | * ViewGroup#onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 18459 | */ |
| 18460 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 18461 | AccessibilityEvent event) { |
| 18462 | return host.onRequestSendAccessibilityEventInternal(child, event); |
| 18463 | } |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 18464 | |
| 18465 | /** |
| 18466 | * Gets the provider for managing a virtual view hierarchy rooted at this View |
| 18467 | * and reported to {@link android.accessibilityservice.AccessibilityService}s |
| 18468 | * that explore the window content. |
| 18469 | * <p> |
| 18470 | * The default implementation behaves as |
| 18471 | * {@link View#getAccessibilityNodeProvider() View#getAccessibilityNodeProvider()} for |
| 18472 | * the case of no accessibility delegate been set. |
| 18473 | * </p> |
| 18474 | * |
| 18475 | * @return The provider. |
| 18476 | * |
| 18477 | * @see AccessibilityNodeProvider |
| 18478 | */ |
| 18479 | public AccessibilityNodeProvider getAccessibilityNodeProvider(View host) { |
| 18480 | return null; |
| 18481 | } |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 18482 | } |
Svetoslav Ganov | 33aef98 | 2012-09-13 12:49:03 -0700 | [diff] [blame] | 18483 | |
| 18484 | private class MatchIdPredicate implements Predicate<View> { |
| 18485 | public int mId; |
| 18486 | |
| 18487 | @Override |
| 18488 | public boolean apply(View view) { |
| 18489 | return (view.mID == mId); |
| 18490 | } |
| 18491 | } |
| 18492 | |
| 18493 | private class MatchLabelForPredicate implements Predicate<View> { |
| 18494 | private int mLabeledId; |
| 18495 | |
| 18496 | @Override |
| 18497 | public boolean apply(View view) { |
| 18498 | return (view.mLabelForId == mLabeledId); |
| 18499 | } |
| 18500 | } |
Jeff Sharkey | 36901b6 | 2012-09-19 19:06:22 -0700 | [diff] [blame] | 18501 | |
| 18502 | /** |
| 18503 | * Dump all private flags in readable format, useful for documentation and |
| 18504 | * sanity checking. |
| 18505 | */ |
| 18506 | private static void dumpFlags() { |
| 18507 | final HashMap<String, String> found = Maps.newHashMap(); |
| 18508 | try { |
| 18509 | for (Field field : View.class.getDeclaredFields()) { |
| 18510 | final int modifiers = field.getModifiers(); |
| 18511 | if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) { |
| 18512 | if (field.getType().equals(int.class)) { |
| 18513 | final int value = field.getInt(null); |
| 18514 | dumpFlag(found, field.getName(), value); |
| 18515 | } else if (field.getType().equals(int[].class)) { |
| 18516 | final int[] values = (int[]) field.get(null); |
| 18517 | for (int i = 0; i < values.length; i++) { |
| 18518 | dumpFlag(found, field.getName() + "[" + i + "]", values[i]); |
| 18519 | } |
| 18520 | } |
| 18521 | } |
| 18522 | } |
| 18523 | } catch (IllegalAccessException e) { |
| 18524 | throw new RuntimeException(e); |
| 18525 | } |
| 18526 | |
| 18527 | final ArrayList<String> keys = Lists.newArrayList(); |
| 18528 | keys.addAll(found.keySet()); |
| 18529 | Collections.sort(keys); |
| 18530 | for (String key : keys) { |
| 18531 | Log.d(VIEW_LOG_TAG, found.get(key)); |
| 18532 | } |
| 18533 | } |
| 18534 | |
| 18535 | private static void dumpFlag(HashMap<String, String> found, String name, int value) { |
| 18536 | // Sort flags by prefix, then by bits, always keeping unique keys |
| 18537 | final String bits = String.format("%32s", Integer.toBinaryString(value)).replace('0', ' '); |
| 18538 | final int prefix = name.indexOf('_'); |
| 18539 | final String key = (prefix > 0 ? name.substring(0, prefix) : name) + bits + name; |
| 18540 | final String output = bits + " " + name; |
| 18541 | found.put(key, output); |
| 18542 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18543 | } |