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 | |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 19 | import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; |
| 20 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 21 | import android.animation.LayoutTransition; |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 22 | import android.annotation.CallSuper; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 23 | import android.annotation.IdRes; |
Alan Viverette | 922e1c6 | 2015-05-05 17:18:27 -0700 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 26 | import android.annotation.UiThread; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 27 | import android.annotation.UnsupportedAppUsage; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 28 | import android.content.ClipData; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 30 | import android.content.Intent; |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
| 34 | import android.graphics.Bitmap; |
| 35 | import android.graphics.Canvas; |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 36 | import android.graphics.Color; |
| 37 | import android.graphics.Insets; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 38 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.graphics.Paint; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import android.graphics.PointF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.graphics.RectF; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 43 | import android.graphics.Region; |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 44 | import android.os.Build; |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [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.Parcelable; |
| 47 | import android.os.SystemClock; |
| 48 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.util.Log; |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 50 | import android.util.Pools; |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 51 | import android.util.Pools.SynchronizedPool; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.util.SparseArray; |
Dianne Hackborn | 6ff55fc | 2015-08-05 18:07:31 -0700 | [diff] [blame] | 53 | import android.util.SparseBooleanArray; |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 54 | import android.view.WindowInsetsAnimationListener.InsetsAnimation; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 55 | import android.view.accessibility.AccessibilityEvent; |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 56 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 57 | import android.view.accessibility.AccessibilityNodeInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.view.animation.Animation; |
| 59 | import android.view.animation.AnimationUtils; |
| 60 | import android.view.animation.LayoutAnimationController; |
| 61 | import android.view.animation.Transformation; |
Felipe Leme | fe05a52 | 2018-01-23 15:57:49 -0800 | [diff] [blame] | 62 | import android.view.autofill.Helper; |
Chet Haase | cb3d023 | 2017-05-24 18:27:14 -0700 | [diff] [blame] | 63 | |
Romain Guy | 0211a0a | 2011-02-14 16:34:59 -0800 | [diff] [blame] | 64 | import com.android.internal.R; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | |
| 66 | import java.util.ArrayList; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 67 | import java.util.Collection; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 68 | import java.util.Collections; |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 69 | import java.util.HashSet; |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 70 | import java.util.List; |
| 71 | import java.util.Map; |
Paul Duffin | ca4964c | 2017-02-07 15:04:10 +0000 | [diff] [blame] | 72 | import java.util.function.Predicate; |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
| 75 | * <p> |
| 76 | * A <code>ViewGroup</code> is a special view that can contain other views |
| 77 | * (called children.) The view group is the base class for layouts and views |
| 78 | * containers. This class also defines the |
| 79 | * {@link android.view.ViewGroup.LayoutParams} class which serves as the base |
| 80 | * class for layouts parameters. |
| 81 | * </p> |
| 82 | * |
| 83 | * <p> |
| 84 | * Also see {@link LayoutParams} for layout attributes. |
| 85 | * </p> |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 86 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 87 | * <div class="special reference"> |
| 88 | * <h3>Developer Guides</h3> |
| 89 | * <p>For more information about creating user interface layouts, read the |
| 90 | * <a href="{@docRoot}guide/topics/ui/declaring-layout.html">XML Layouts</a> developer |
| 91 | * guide.</p></div> |
| 92 | * |
Dianne Hackborn | 7caab0f | 2013-03-06 13:47:04 -0800 | [diff] [blame] | 93 | * <p>Here is a complete implementation of a custom ViewGroup that implements |
| 94 | * a simple {@link android.widget.FrameLayout} along with the ability to stack |
| 95 | * children in left and right gutters.</p> |
| 96 | * |
| 97 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/view/CustomLayout.java |
| 98 | * Complete} |
| 99 | * |
| 100 | * <p>If you are implementing XML layout attributes as shown in the example, this is the |
| 101 | * corresponding definition for them that would go in <code>res/values/attrs.xml</code>:</p> |
| 102 | * |
| 103 | * {@sample development/samples/ApiDemos/res/values/attrs.xml CustomLayout} |
| 104 | * |
| 105 | * <p>Finally the layout manager can be used in an XML layout like so:</p> |
| 106 | * |
| 107 | * {@sample development/samples/ApiDemos/res/layout/custom_layout.xml Complete} |
| 108 | * |
Romain Guy | d6a463a | 2009-05-21 23:10:10 -0700 | [diff] [blame] | 109 | * @attr ref android.R.styleable#ViewGroup_clipChildren |
| 110 | * @attr ref android.R.styleable#ViewGroup_clipToPadding |
| 111 | * @attr ref android.R.styleable#ViewGroup_layoutAnimation |
| 112 | * @attr ref android.R.styleable#ViewGroup_animationCache |
| 113 | * @attr ref android.R.styleable#ViewGroup_persistentDrawingCache |
| 114 | * @attr ref android.R.styleable#ViewGroup_alwaysDrawnWithCache |
| 115 | * @attr ref android.R.styleable#ViewGroup_addStatesFromChildren |
| 116 | * @attr ref android.R.styleable#ViewGroup_descendantFocusability |
Chet Haase | 13cc120 | 2010-09-03 15:39:20 -0700 | [diff] [blame] | 117 | * @attr ref android.R.styleable#ViewGroup_animateLayoutChanges |
Scott Main | 27a8508 | 2013-06-10 10:39:48 -0700 | [diff] [blame] | 118 | * @attr ref android.R.styleable#ViewGroup_splitMotionEvents |
| 119 | * @attr ref android.R.styleable#ViewGroup_layoutMode |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | */ |
Tor Norbye | 83c6896 | 2015-03-10 20:55:31 -0700 | [diff] [blame] | 121 | @UiThread |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | public abstract class ViewGroup extends View implements ViewParent, ViewManager { |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 123 | private static final String TAG = "ViewGroup"; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 124 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 125 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | private static final boolean DBG = false; |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Views which have been hidden or removed which need to be animated on |
| 130 | * their way out. |
| 131 | * This field should be made private, so it is hidden from the SDK. |
| 132 | * {@hide} |
| 133 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 134 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | protected ArrayList<View> mDisappearingChildren; |
| 136 | |
| 137 | /** |
| 138 | * Listener used to propagate events indicating when children are added |
| 139 | * and/or removed from a view group. |
| 140 | * This field should be made private, so it is hidden from the SDK. |
| 141 | * {@hide} |
| 142 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 143 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | protected OnHierarchyChangeListener mOnHierarchyChangeListener; |
| 145 | |
| 146 | // The view contained within this ViewGroup that has or contains focus. |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 147 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | private View mFocused; |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 149 | // The view contained within this ViewGroup (excluding nested keyboard navigation clusters) |
| 150 | // that is or contains a default-focus view. |
| 151 | private View mDefaultFocus; |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 152 | // The last child of this ViewGroup which held focus within the current cluster |
Evan Rosky | 6c286be | 2017-04-19 17:23:32 -0700 | [diff] [blame] | 153 | View mFocusedInCluster; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | |
Chet Haase | 4846032 | 2010-06-11 14:22:25 -0700 | [diff] [blame] | 155 | /** |
| 156 | * A Transformation used when drawing children, to |
| 157 | * apply on the child being drawn. |
| 158 | */ |
Romain Guy | f699130 | 2013-06-05 17:19:01 -0700 | [diff] [blame] | 159 | private Transformation mChildTransformation; |
Chet Haase | 4846032 | 2010-06-11 14:22:25 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Used to track the current invalidation region. |
| 163 | */ |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 164 | RectF mInvalidateRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | |
Chet Haase | 4846032 | 2010-06-11 14:22:25 -0700 | [diff] [blame] | 166 | /** |
| 167 | * A Transformation used to calculate a correct |
| 168 | * invalidation area when the application is autoscaled. |
| 169 | */ |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 170 | Transformation mInvalidationTransformation; |
Chet Haase | 4846032 | 2010-06-11 14:22:25 -0700 | [diff] [blame] | 171 | |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 172 | // Current frontmost child that can accept drag and lies under the drag location. |
| 173 | // Used only to generate ENTER/EXIT events for pre-Nougat aps. |
| 174 | private View mCurrentDragChild; |
| 175 | |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 176 | // Metadata about the ongoing drag |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 177 | private DragEvent mCurrentDragStartEvent; |
| 178 | private boolean mIsInterestedInDrag; |
| 179 | private HashSet<View> mChildrenInterestedInDrag; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 180 | |
| 181 | // Used during drag dispatch |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 182 | private PointF mLocalPoint; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 183 | |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 184 | // Lazily-created holder for point computations. |
| 185 | private float[] mTempPoint; |
| 186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | // Layout animation |
| 188 | private LayoutAnimationController mLayoutAnimationController; |
| 189 | private Animation.AnimationListener mAnimationListener; |
| 190 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 191 | // First touch target in the linked list of touch targets. |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 192 | @UnsupportedAppUsage |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 193 | private TouchTarget mFirstTouchTarget; |
| 194 | |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 195 | // For debugging only. You can see these in hierarchyviewer. |
Romain Guy | e95003e | 2011-01-09 13:53:06 -0800 | [diff] [blame] | 196 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 197 | @ViewDebug.ExportedProperty(category = "events") |
| 198 | private long mLastTouchDownTime; |
| 199 | @ViewDebug.ExportedProperty(category = "events") |
| 200 | private int mLastTouchDownIndex = -1; |
Romain Guy | e95003e | 2011-01-09 13:53:06 -0800 | [diff] [blame] | 201 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 202 | @ViewDebug.ExportedProperty(category = "events") |
| 203 | private float mLastTouchDownX; |
Romain Guy | e95003e | 2011-01-09 13:53:06 -0800 | [diff] [blame] | 204 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 205 | @ViewDebug.ExportedProperty(category = "events") |
| 206 | private float mLastTouchDownY; |
| 207 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 208 | // First hover target in the linked list of hover targets. |
| 209 | // The hover targets are children which have received ACTION_HOVER_ENTER. |
| 210 | // They might not have actually handled the hover event, but we will |
| 211 | // continue sending hover events to them as long as the pointer remains over |
| 212 | // their bounds and the view group does not intercept hover. |
| 213 | private HoverTarget mFirstHoverTarget; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 214 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 215 | // True if the view group itself received a hover event. |
| 216 | // It might not have actually handled the hover event. |
| 217 | private boolean mHoveredSelf; |
| 218 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 219 | // The child capable of showing a tooltip and currently under the pointer. |
| 220 | private View mTooltipHoverTarget; |
| 221 | |
| 222 | // True if the view group is capable of showing a tooltip and the pointer is directly |
| 223 | // over the view group but not one of its child views. |
| 224 | private boolean mTooltipHoveredSelf; |
| 225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | /** |
| 227 | * Internal flags. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 228 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | * This field should be made private, so it is hidden from the SDK. |
| 230 | * {@hide} |
| 231 | */ |
Romain Guy | 2440e67 | 2012-08-07 14:43:43 -0700 | [diff] [blame] | 232 | @ViewDebug.ExportedProperty(flagMapping = { |
| 233 | @ViewDebug.FlagToString(mask = FLAG_CLIP_CHILDREN, equals = FLAG_CLIP_CHILDREN, |
| 234 | name = "CLIP_CHILDREN"), |
| 235 | @ViewDebug.FlagToString(mask = FLAG_CLIP_TO_PADDING, equals = FLAG_CLIP_TO_PADDING, |
| 236 | name = "CLIP_TO_PADDING"), |
| 237 | @ViewDebug.FlagToString(mask = FLAG_PADDING_NOT_NULL, equals = FLAG_PADDING_NOT_NULL, |
| 238 | name = "PADDING_NOT_NULL") |
Jon Miranda | 4597e98 | 2014-07-29 07:25:49 -0700 | [diff] [blame] | 239 | }, formatToHexString = true) |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 240 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | protected int mGroupFlags; |
| 242 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 243 | /** |
| 244 | * Either {@link #LAYOUT_MODE_CLIP_BOUNDS} or {@link #LAYOUT_MODE_OPTICAL_BOUNDS}. |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 245 | */ |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 246 | private int mLayoutMode = LAYOUT_MODE_UNDEFINED; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 247 | |
Romain Guy | 33f6beb | 2012-02-16 19:24:51 -0800 | [diff] [blame] | 248 | /** |
| 249 | * NOTE: If you change the flags below make sure to reflect the changes |
| 250 | * the DisplayList class |
| 251 | */ |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | // When set, ViewGroup invalidates only the child's rectangle |
| 254 | // Set by default |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 255 | static final int FLAG_CLIP_CHILDREN = 0x1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | |
| 257 | // When set, ViewGroup excludes the padding area from the invalidate rectangle |
| 258 | // Set by default |
| 259 | private static final int FLAG_CLIP_TO_PADDING = 0x2; |
| 260 | |
| 261 | // When set, dispatchDraw() will invoke invalidate(); this is set by drawChild() when |
| 262 | // a child needs to be invalidated and FLAG_OPTIMIZE_INVALIDATE is set |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 263 | static final int FLAG_INVALIDATE_REQUIRED = 0x4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | |
| 265 | // When set, dispatchDraw() will run the layout animation and unset the flag |
| 266 | private static final int FLAG_RUN_ANIMATION = 0x8; |
| 267 | |
| 268 | // When set, there is either no layout animation on the ViewGroup or the layout |
| 269 | // animation is over |
| 270 | // Set by default |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 271 | static final int FLAG_ANIMATION_DONE = 0x10; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | |
| 273 | // If set, this ViewGroup has padding; if unset there is no padding and we don't need |
| 274 | // to clip it, even if FLAG_CLIP_TO_PADDING is set |
| 275 | private static final int FLAG_PADDING_NOT_NULL = 0x20; |
| 276 | |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 277 | /** @deprecated - functionality removed */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 278 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | private static final int FLAG_ANIMATION_CACHE = 0x40; |
| 280 | |
| 281 | // When set, this ViewGroup converts calls to invalidate(Rect) to invalidate() during a |
| 282 | // layout animation; this avoid clobbering the hierarchy |
| 283 | // Automatically set when the layout animation starts, depending on the animation's |
| 284 | // characteristics |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 285 | static final int FLAG_OPTIMIZE_INVALIDATE = 0x80; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
| 287 | // When set, the next call to drawChild() will clear mChildTransformation's matrix |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 288 | static final int FLAG_CLEAR_TRANSFORMATION = 0x100; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | |
| 290 | // When set, this ViewGroup invokes mAnimationListener.onAnimationEnd() and removes |
| 291 | // the children's Bitmap caches if necessary |
| 292 | // This flag is set when the layout animation is over (after FLAG_ANIMATION_DONE is set) |
| 293 | private static final int FLAG_NOTIFY_ANIMATION_LISTENER = 0x200; |
| 294 | |
| 295 | /** |
| 296 | * When set, the drawing method will call {@link #getChildDrawingOrder(int, int)} |
| 297 | * to get the index of the child to draw for that iteration. |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 298 | * |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 299 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 301 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | protected static final int FLAG_USE_CHILD_DRAWING_ORDER = 0x400; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | /** |
| 305 | * When set, this ViewGroup supports static transformations on children; this causes |
| 306 | * {@link #getChildStaticTransformation(View, android.view.animation.Transformation)} to be |
| 307 | * invoked when a child is drawn. |
| 308 | * |
| 309 | * Any subclass overriding |
| 310 | * {@link #getChildStaticTransformation(View, android.view.animation.Transformation)} should |
| 311 | * set this flags in {@link #mGroupFlags}. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 312 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | * {@hide} |
| 314 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 315 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | protected static final int FLAG_SUPPORT_STATIC_TRANSFORMATIONS = 0x800; |
| 317 | |
John Reck | fb5899d | 2014-08-15 18:51:27 -0700 | [diff] [blame] | 318 | // UNUSED FLAG VALUE: 0x1000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * When set, this ViewGroup's drawable states also include those |
| 322 | * of its children. |
| 323 | */ |
| 324 | private static final int FLAG_ADD_STATES_FROM_CHILDREN = 0x2000; |
| 325 | |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 326 | /** @deprecated functionality removed */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 327 | @Deprecated |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 328 | private static final int FLAG_ALWAYS_DRAWN_WITH_CACHE = 0x4000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 330 | /** @deprecated functionality removed */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 331 | @Deprecated |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 332 | private static final int FLAG_CHILDREN_DRAWN_WITH_CACHE = 0x8000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * When set, this group will go through its list of children to notify them of |
| 336 | * any drawable state change. |
| 337 | */ |
| 338 | private static final int FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE = 0x10000; |
| 339 | |
| 340 | private static final int FLAG_MASK_FOCUSABILITY = 0x60000; |
| 341 | |
| 342 | /** |
| 343 | * This view will get focus before any of its descendants. |
| 344 | */ |
| 345 | public static final int FOCUS_BEFORE_DESCENDANTS = 0x20000; |
| 346 | |
| 347 | /** |
| 348 | * This view will get focus only if none of its descendants want it. |
| 349 | */ |
| 350 | public static final int FOCUS_AFTER_DESCENDANTS = 0x40000; |
| 351 | |
| 352 | /** |
| 353 | * This view will block any of its descendants from getting focus, even |
| 354 | * if they are focusable. |
| 355 | */ |
| 356 | public static final int FOCUS_BLOCK_DESCENDANTS = 0x60000; |
| 357 | |
| 358 | /** |
| 359 | * Used to map between enum in attrubutes and flag values. |
| 360 | */ |
| 361 | private static final int[] DESCENDANT_FOCUSABILITY_FLAGS = |
| 362 | {FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, |
| 363 | FOCUS_BLOCK_DESCENDANTS}; |
| 364 | |
| 365 | /** |
| 366 | * When set, this ViewGroup should not intercept touch events. |
Adam Powell | 110486f | 2010-06-22 17:14:44 -0700 | [diff] [blame] | 367 | * {@hide} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 369 | @UnsupportedAppUsage |
Adam Powell | 110486f | 2010-06-22 17:14:44 -0700 | [diff] [blame] | 370 | protected static final int FLAG_DISALLOW_INTERCEPT = 0x80000; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | /** |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 373 | * When set, this ViewGroup will split MotionEvents to multiple child Views when appropriate. |
| 374 | */ |
Adam Powell | f37df07 | 2010-09-17 16:22:49 -0700 | [diff] [blame] | 375 | private static final int FLAG_SPLIT_MOTION_EVENTS = 0x200000; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 376 | |
| 377 | /** |
Adam Powell | 4b86788 | 2011-09-16 12:59:46 -0700 | [diff] [blame] | 378 | * When set, this ViewGroup will not dispatch onAttachedToWindow calls |
| 379 | * to children when adding new views. This is used to prevent multiple |
| 380 | * onAttached calls when a ViewGroup adds children in its own onAttached method. |
| 381 | */ |
| 382 | private static final int FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW = 0x400000; |
| 383 | |
| 384 | /** |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 385 | * When true, indicates that a layoutMode has been explicitly set, either with |
| 386 | * an explicit call to {@link #setLayoutMode(int)} in code or from an XML resource. |
| 387 | * This distinguishes the situation in which a layout mode was inherited from |
| 388 | * one of the ViewGroup's ancestors and cached locally. |
| 389 | */ |
| 390 | private static final int FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET = 0x800000; |
| 391 | |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 392 | static final int FLAG_IS_TRANSITION_GROUP = 0x1000000; |
Chris Craik | d863a10 | 2013-12-19 13:31:15 -0800 | [diff] [blame] | 393 | |
Chris Craik | b49f446 | 2014-03-20 12:44:20 -0700 | [diff] [blame] | 394 | static final int FLAG_IS_TRANSITION_GROUP_SET = 0x2000000; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 395 | |
Chris Craik | d863a10 | 2013-12-19 13:31:15 -0800 | [diff] [blame] | 396 | /** |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 397 | * When set, focus will not be permitted to enter this group if a touchscreen is present. |
| 398 | */ |
| 399 | static final int FLAG_TOUCHSCREEN_BLOCKS_FOCUS = 0x4000000; |
| 400 | |
| 401 | /** |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 402 | * When true, indicates that a call to startActionModeForChild was made with the type parameter |
| 403 | * and should not be ignored. This helps in backwards compatibility with the existing method |
| 404 | * without a type. |
| 405 | * |
| 406 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback) |
| 407 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback, int) |
| 408 | */ |
| 409 | private static final int FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED = 0x8000000; |
| 410 | |
| 411 | /** |
| 412 | * When true, indicates that a call to startActionModeForChild was made without the type |
| 413 | * parameter. This helps in backwards compatibility with the existing method |
| 414 | * without a type. |
| 415 | * |
| 416 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback) |
| 417 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback, int) |
| 418 | */ |
| 419 | private static final int FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED = 0x10000000; |
| 420 | |
| 421 | /** |
Adam Powell | 2af189a | 2016-02-05 15:52:02 -0800 | [diff] [blame] | 422 | * When set, indicates that a call to showContextMenuForChild was made with explicit |
| 423 | * coordinates within the initiating child view. |
| 424 | */ |
| 425 | private static final int FLAG_SHOW_CONTEXT_MENU_WITH_COORDS = 0x20000000; |
| 426 | |
| 427 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | * Indicates which types of drawing caches are to be kept in memory. |
| 429 | * This field should be made private, so it is hidden from the SDK. |
| 430 | * {@hide} |
| 431 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 432 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | protected int mPersistentDrawingCache; |
| 434 | |
| 435 | /** |
| 436 | * Used to indicate that no drawing cache should be kept in memory. |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 437 | * |
| 438 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 439 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 440 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 441 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 442 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 443 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 444 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 445 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 446 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 447 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 448 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 449 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 451 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | public static final int PERSISTENT_NO_CACHE = 0x0; |
| 453 | |
| 454 | /** |
| 455 | * Used to indicate that the animation drawing cache should be kept in memory. |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 456 | * |
| 457 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 458 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 459 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 460 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 461 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 462 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 463 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 464 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 465 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 466 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 467 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 468 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 470 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | public static final int PERSISTENT_ANIMATION_CACHE = 0x1; |
| 472 | |
| 473 | /** |
| 474 | * Used to indicate that the scrolling drawing cache should be kept in memory. |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 475 | * |
| 476 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 477 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 478 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 479 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 480 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 481 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 482 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 483 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 484 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 485 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 486 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 487 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 489 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | public static final int PERSISTENT_SCROLLING_CACHE = 0x2; |
| 491 | |
| 492 | /** |
| 493 | * Used to indicate that all drawing caches should be kept in memory. |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 494 | * |
| 495 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 496 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 497 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 498 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 499 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 500 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 501 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 502 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 503 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 504 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 505 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 506 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 508 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | public static final int PERSISTENT_ALL_CACHES = 0x3; |
| 510 | |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 511 | // Layout Modes |
| 512 | |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 513 | private static final int LAYOUT_MODE_UNDEFINED = -1; |
| 514 | |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 515 | /** |
| 516 | * This constant is a {@link #setLayoutMode(int) layoutMode}. |
Philip Milne | 7a23b49 | 2012-04-24 22:12:36 -0700 | [diff] [blame] | 517 | * Clip bounds are the raw values of {@link #getLeft() left}, {@link #getTop() top}, |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 518 | * {@link #getRight() right} and {@link #getBottom() bottom}. |
| 519 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 520 | public static final int LAYOUT_MODE_CLIP_BOUNDS = 0; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 521 | |
| 522 | /** |
| 523 | * This constant is a {@link #setLayoutMode(int) layoutMode}. |
Philip Milne | 7a23b49 | 2012-04-24 22:12:36 -0700 | [diff] [blame] | 524 | * Optical bounds describe where a widget appears to be. They sit inside the clip |
| 525 | * bounds which need to cover a larger area to allow other effects, |
| 526 | * such as shadows and glows, to be drawn. |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 527 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 528 | public static final int LAYOUT_MODE_OPTICAL_BOUNDS = 1; |
| 529 | |
| 530 | /** @hide */ |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 531 | public static int LAYOUT_MODE_DEFAULT = LAYOUT_MODE_CLIP_BOUNDS; |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | /** |
| 534 | * We clip to padding when FLAG_CLIP_TO_PADDING and FLAG_PADDING_NOT_NULL |
| 535 | * are set at the same time. |
| 536 | */ |
| 537 | protected static final int CLIP_TO_PADDING_MASK = FLAG_CLIP_TO_PADDING | FLAG_PADDING_NOT_NULL; |
| 538 | |
| 539 | // Index of the child's left position in the mLocation array |
| 540 | private static final int CHILD_LEFT_INDEX = 0; |
| 541 | // Index of the child's top position in the mLocation array |
| 542 | private static final int CHILD_TOP_INDEX = 1; |
| 543 | |
| 544 | // Child views of this ViewGroup |
Mihai Popa | 831c1a9 | 2018-10-15 15:40:23 +0100 | [diff] [blame] | 545 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | private View[] mChildren; |
| 547 | // Number of valid children in the mChildren array, the rest should be null or not |
| 548 | // considered as children |
Mihai Popa | 831c1a9 | 2018-10-15 15:40:23 +0100 | [diff] [blame] | 549 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | private int mChildrenCount; |
| 551 | |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 552 | // Whether layout calls are currently being suppressed, controlled by calls to |
| 553 | // suppressLayout() |
| 554 | boolean mSuppressLayout = false; |
| 555 | |
| 556 | // Whether any layout calls have actually been suppressed while mSuppressLayout |
| 557 | // has been true. This tracks whether we need to issue a requestLayout() when |
| 558 | // layout is later re-enabled. |
| 559 | private boolean mLayoutCalledWhileSuppressed = false; |
| 560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | private static final int ARRAY_INITIAL_CAPACITY = 12; |
| 562 | private static final int ARRAY_CAPACITY_INCREMENT = 12; |
| 563 | |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 564 | private static float[] sDebugLines; |
Philip Milne | 604f440 | 2012-04-24 19:27:11 -0700 | [diff] [blame] | 565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | // Used to draw cached views |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 567 | Paint mCachePaint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 569 | // Used to animate add/remove changes in layout |
| 570 | private LayoutTransition mTransition; |
| 571 | |
| 572 | // The set of views that are currently being transitioned. This list is used to track views |
| 573 | // being removed that should not actually be removed from the parent yet because they are |
| 574 | // being animated. |
| 575 | private ArrayList<View> mTransitioningViews; |
| 576 | |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 577 | // List of children changing visibility. This is used to potentially keep rendering |
| 578 | // views during a transition when they otherwise would have become gone/invisible |
| 579 | private ArrayList<View> mVisibilityChangingChildren; |
| 580 | |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 581 | // Temporary holder of presorted children, only used for |
| 582 | // input/software draw dispatch for correctly Z ordering. |
| 583 | private ArrayList<View> mPreSortedChildren; |
| 584 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 585 | // Indicates how many of this container's child subtrees contain transient state |
| 586 | @ViewDebug.ExportedProperty(category = "layout") |
| 587 | private int mChildCountWithTransientState = 0; |
| 588 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 589 | /** |
| 590 | * Currently registered axes for nested scrolling. Flag set consisting of |
| 591 | * {@link #SCROLL_AXIS_HORIZONTAL} {@link #SCROLL_AXIS_VERTICAL} or {@link #SCROLL_AXIS_NONE} |
| 592 | * for null. |
| 593 | */ |
| 594 | private int mNestedScrollAxes; |
| 595 | |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 596 | // Used to manage the list of transient views, added by addTransientView() |
| 597 | private List<Integer> mTransientIndices = null; |
| 598 | private List<View> mTransientViews = null; |
| 599 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 600 | /** |
| 601 | * Keeps track of how many child views have UnhandledKeyEventListeners. This should only be |
| 602 | * updated on the UI thread so shouldn't require explicit synchronization. |
| 603 | */ |
| 604 | int mChildUnhandledKeyListeners = 0; |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 605 | |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 606 | /** |
| 607 | * Empty ActionMode used as a sentinel in recursive entries to startActionModeForChild. |
| 608 | * |
| 609 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback) |
| 610 | * @see #startActionModeForChild(View, android.view.ActionMode.Callback, int) |
| 611 | */ |
| 612 | private static final ActionMode SENTINEL_ACTION_MODE = new ActionMode() { |
| 613 | @Override |
| 614 | public void setTitle(CharSequence title) {} |
| 615 | |
| 616 | @Override |
| 617 | public void setTitle(int resId) {} |
| 618 | |
| 619 | @Override |
| 620 | public void setSubtitle(CharSequence subtitle) {} |
| 621 | |
| 622 | @Override |
| 623 | public void setSubtitle(int resId) {} |
| 624 | |
| 625 | @Override |
| 626 | public void setCustomView(View view) {} |
| 627 | |
| 628 | @Override |
| 629 | public void invalidate() {} |
| 630 | |
| 631 | @Override |
| 632 | public void finish() {} |
| 633 | |
| 634 | @Override |
| 635 | public Menu getMenu() { |
| 636 | return null; |
| 637 | } |
| 638 | |
| 639 | @Override |
| 640 | public CharSequence getTitle() { |
| 641 | return null; |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | public CharSequence getSubtitle() { |
| 646 | return null; |
| 647 | } |
| 648 | |
| 649 | @Override |
| 650 | public View getCustomView() { |
| 651 | return null; |
| 652 | } |
| 653 | |
| 654 | @Override |
| 655 | public MenuInflater getMenuInflater() { |
| 656 | return null; |
| 657 | } |
| 658 | }; |
| 659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | public ViewGroup(Context context) { |
Alan Viverette | d6479ec | 2013-09-10 17:03:02 -0700 | [diff] [blame] | 661 | this(context, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | public ViewGroup(Context context, AttributeSet attrs) { |
Alan Viverette | d6479ec | 2013-09-10 17:03:02 -0700 | [diff] [blame] | 665 | this(context, attrs, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 668 | public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr) { |
Alan Viverette | d6479ec | 2013-09-10 17:03:02 -0700 | [diff] [blame] | 669 | this(context, attrs, defStyleAttr, 0); |
Alan Viverette | 617feb9 | 2013-09-09 18:09:13 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 673 | super(context, attrs, defStyleAttr, defStyleRes); |
Felipe Leme | d04a697 | 2017-03-02 12:56:18 -0800 | [diff] [blame] | 674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | initViewGroup(); |
Alan Viverette | d6479ec | 2013-09-10 17:03:02 -0700 | [diff] [blame] | 676 | initFromAttributes(context, attrs, defStyleAttr, defStyleRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | private void initViewGroup() { |
| 680 | // ViewGroup doesn't draw by default |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 681 | if (!debugDraw()) { |
| 682 | setFlags(WILL_NOT_DRAW, DRAW_MASK); |
| 683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | mGroupFlags |= FLAG_CLIP_CHILDREN; |
| 685 | mGroupFlags |= FLAG_CLIP_TO_PADDING; |
| 686 | mGroupFlags |= FLAG_ANIMATION_DONE; |
Chris Craik | f6ce8fd | 2015-05-11 15:33:11 -0700 | [diff] [blame] | 687 | mGroupFlags |= FLAG_ANIMATION_CACHE; |
| 688 | mGroupFlags |= FLAG_ALWAYS_DRAWN_WITH_CACHE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 690 | if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB) { |
| 691 | mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS; |
| 692 | } |
| 693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS); |
| 695 | |
| 696 | mChildren = new View[ARRAY_INITIAL_CAPACITY]; |
| 697 | mChildrenCount = 0; |
| 698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | mPersistentDrawingCache = PERSISTENT_SCROLLING_CACHE; |
| 700 | } |
| 701 | |
Alan Viverette | d6479ec | 2013-09-10 17:03:02 -0700 | [diff] [blame] | 702 | private void initFromAttributes( |
| 703 | Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
Filip Gruszczyński | b50cea0 | 2014-03-05 17:54:58 -0800 | [diff] [blame] | 704 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup, defStyleAttr, |
| 705 | defStyleRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | |
| 707 | final int N = a.getIndexCount(); |
| 708 | for (int i = 0; i < N; i++) { |
| 709 | int attr = a.getIndex(i); |
| 710 | switch (attr) { |
| 711 | case R.styleable.ViewGroup_clipChildren: |
| 712 | setClipChildren(a.getBoolean(attr, true)); |
| 713 | break; |
| 714 | case R.styleable.ViewGroup_clipToPadding: |
| 715 | setClipToPadding(a.getBoolean(attr, true)); |
| 716 | break; |
| 717 | case R.styleable.ViewGroup_animationCache: |
| 718 | setAnimationCacheEnabled(a.getBoolean(attr, true)); |
| 719 | break; |
| 720 | case R.styleable.ViewGroup_persistentDrawingCache: |
| 721 | setPersistentDrawingCache(a.getInt(attr, PERSISTENT_SCROLLING_CACHE)); |
| 722 | break; |
| 723 | case R.styleable.ViewGroup_addStatesFromChildren: |
| 724 | setAddStatesFromChildren(a.getBoolean(attr, false)); |
| 725 | break; |
| 726 | case R.styleable.ViewGroup_alwaysDrawnWithCache: |
| 727 | setAlwaysDrawnWithCacheEnabled(a.getBoolean(attr, true)); |
| 728 | break; |
| 729 | case R.styleable.ViewGroup_layoutAnimation: |
| 730 | int id = a.getResourceId(attr, -1); |
| 731 | if (id > 0) { |
| 732 | setLayoutAnimation(AnimationUtils.loadLayoutAnimation(mContext, id)); |
| 733 | } |
| 734 | break; |
| 735 | case R.styleable.ViewGroup_descendantFocusability: |
| 736 | setDescendantFocusability(DESCENDANT_FOCUSABILITY_FLAGS[a.getInt(attr, 0)]); |
| 737 | break; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 738 | case R.styleable.ViewGroup_splitMotionEvents: |
| 739 | setMotionEventSplittingEnabled(a.getBoolean(attr, false)); |
| 740 | break; |
Chet Haase | 13cc120 | 2010-09-03 15:39:20 -0700 | [diff] [blame] | 741 | case R.styleable.ViewGroup_animateLayoutChanges: |
| 742 | boolean animateLayoutChanges = a.getBoolean(attr, false); |
| 743 | if (animateLayoutChanges) { |
| 744 | setLayoutTransition(new LayoutTransition()); |
| 745 | } |
| 746 | break; |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 747 | case R.styleable.ViewGroup_layoutMode: |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 748 | setLayoutMode(a.getInt(attr, LAYOUT_MODE_UNDEFINED)); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 749 | break; |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 750 | case R.styleable.ViewGroup_transitionGroup: |
| 751 | setTransitionGroup(a.getBoolean(attr, false)); |
| 752 | break; |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 753 | case R.styleable.ViewGroup_touchscreenBlocksFocus: |
| 754 | setTouchscreenBlocksFocus(a.getBoolean(attr, false)); |
| 755 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | a.recycle(); |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Gets the descendant focusability of this view group. The descendant |
| 764 | * focusability defines the relationship between this view group and its |
| 765 | * descendants when looking for a view to take focus in |
| 766 | * {@link #requestFocus(int, android.graphics.Rect)}. |
| 767 | * |
| 768 | * @return one of {@link #FOCUS_BEFORE_DESCENDANTS}, {@link #FOCUS_AFTER_DESCENDANTS}, |
| 769 | * {@link #FOCUS_BLOCK_DESCENDANTS}. |
| 770 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 771 | @ViewDebug.ExportedProperty(category = "focus", mapping = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | @ViewDebug.IntToString(from = FOCUS_BEFORE_DESCENDANTS, to = "FOCUS_BEFORE_DESCENDANTS"), |
| 773 | @ViewDebug.IntToString(from = FOCUS_AFTER_DESCENDANTS, to = "FOCUS_AFTER_DESCENDANTS"), |
| 774 | @ViewDebug.IntToString(from = FOCUS_BLOCK_DESCENDANTS, to = "FOCUS_BLOCK_DESCENDANTS") |
| 775 | }) |
| 776 | public int getDescendantFocusability() { |
| 777 | return mGroupFlags & FLAG_MASK_FOCUSABILITY; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Set the descendant focusability of this view group. This defines the relationship |
| 782 | * between this view group and its descendants when looking for a view to |
| 783 | * take focus in {@link #requestFocus(int, android.graphics.Rect)}. |
| 784 | * |
| 785 | * @param focusability one of {@link #FOCUS_BEFORE_DESCENDANTS}, {@link #FOCUS_AFTER_DESCENDANTS}, |
| 786 | * {@link #FOCUS_BLOCK_DESCENDANTS}. |
| 787 | */ |
| 788 | public void setDescendantFocusability(int focusability) { |
| 789 | switch (focusability) { |
| 790 | case FOCUS_BEFORE_DESCENDANTS: |
| 791 | case FOCUS_AFTER_DESCENDANTS: |
| 792 | case FOCUS_BLOCK_DESCENDANTS: |
| 793 | break; |
| 794 | default: |
| 795 | throw new IllegalArgumentException("must be one of FOCUS_BEFORE_DESCENDANTS, " |
| 796 | + "FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS"); |
| 797 | } |
| 798 | mGroupFlags &= ~FLAG_MASK_FOCUSABILITY; |
| 799 | mGroupFlags |= (focusability & FLAG_MASK_FOCUSABILITY); |
| 800 | } |
| 801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | @Override |
| 803 | void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { |
| 804 | if (mFocused != null) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 805 | mFocused.unFocus(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | mFocused = null; |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 807 | mFocusedInCluster = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | } |
| 809 | super.handleFocusGainInternal(direction, previouslyFocusedRect); |
| 810 | } |
| 811 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 812 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | public void requestChildFocus(View child, View focused) { |
| 814 | if (DBG) { |
| 815 | System.out.println(this + " requestChildFocus()"); |
| 816 | } |
| 817 | if (getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS) { |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | // Unfocus us, if necessary |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 822 | super.unFocus(focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | |
| 824 | // We had a previous notion of who had focus. Clear it. |
| 825 | if (mFocused != child) { |
| 826 | if (mFocused != null) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 827 | mFocused.unFocus(focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | mFocused = child; |
| 831 | } |
| 832 | if (mParent != null) { |
| 833 | mParent.requestChildFocus(this, focused); |
| 834 | } |
| 835 | } |
| 836 | |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 837 | void setDefaultFocus(View child) { |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 838 | // Stop at any higher view which is explicitly focused-by-default |
| 839 | if (mDefaultFocus != null && mDefaultFocus.isFocusedByDefault()) { |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 840 | return; |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 841 | } |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 842 | |
| 843 | mDefaultFocus = child; |
| 844 | |
| 845 | if (mParent instanceof ViewGroup) { |
| 846 | ((ViewGroup) mParent).setDefaultFocus(this); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | /** |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 851 | * Clears the default-focus chain from {@param child} up to the first parent which has another |
| 852 | * default-focusable branch below it or until there is no default-focus chain. |
| 853 | * |
| 854 | * @param child |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 855 | */ |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 856 | void clearDefaultFocus(View child) { |
| 857 | // Stop at any higher view which is explicitly focused-by-default |
| 858 | if (mDefaultFocus != child && mDefaultFocus != null |
| 859 | && mDefaultFocus.isFocusedByDefault()) { |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | mDefaultFocus = null; |
| 864 | |
| 865 | // Search child siblings for default focusables. |
| 866 | for (int i = 0; i < mChildrenCount; ++i) { |
| 867 | View sibling = mChildren[i]; |
| 868 | if (sibling.isFocusedByDefault()) { |
| 869 | mDefaultFocus = sibling; |
| 870 | return; |
| 871 | } else if (mDefaultFocus == null && sibling.hasDefaultFocus()) { |
| 872 | mDefaultFocus = sibling; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | if (mParent instanceof ViewGroup) { |
| 877 | ((ViewGroup) mParent).clearDefaultFocus(this); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | @Override |
| 882 | boolean hasDefaultFocus() { |
| 883 | return mDefaultFocus != null || super.hasDefaultFocus(); |
| 884 | } |
| 885 | |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 886 | /** |
| 887 | * Removes {@code child} (and associated focusedInCluster chain) from the cluster containing |
| 888 | * it. |
| 889 | * <br> |
| 890 | * This is intended to be run on {@code child}'s immediate parent. This is necessary because |
| 891 | * the chain is sometimes cleared after {@code child} has been detached. |
| 892 | */ |
| 893 | void clearFocusedInCluster(View child) { |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 894 | if (mFocusedInCluster != child) { |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 895 | return; |
| 896 | } |
Evan Rosky | 5b20e09 | 2017-07-13 18:04:39 -0700 | [diff] [blame] | 897 | clearFocusedInCluster(); |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Removes the focusedInCluster chain from this up to the cluster containing it. |
| 902 | */ |
| 903 | void clearFocusedInCluster() { |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 904 | View top = findKeyboardNavigationCluster(); |
| 905 | ViewParent parent = this; |
| 906 | do { |
| 907 | ((ViewGroup) parent).mFocusedInCluster = null; |
Evan Rosky | 6c286be | 2017-04-19 17:23:32 -0700 | [diff] [blame] | 908 | if (parent == top) { |
| 909 | break; |
| 910 | } |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 911 | parent = parent.getParent(); |
Evan Rosky | 6c286be | 2017-04-19 17:23:32 -0700 | [diff] [blame] | 912 | } while (parent instanceof ViewGroup); |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | public void focusableViewAvailable(View v) { |
| 917 | if (mParent != null |
| 918 | // shortcut: don't report a new focusable view if we block our descendants from |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 919 | // getting focus or if we're not visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | && (getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS) |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 921 | && ((mViewFlags & VISIBILITY_MASK) == VISIBLE) |
Adam Powell | 88c1175 | 2014-07-21 17:19:16 -0700 | [diff] [blame] | 922 | && (isFocusableInTouchMode() || !shouldBlockFocusForTouchscreen()) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | // shortcut: don't report a new focusable view if we already are focused |
| 924 | // (and we don't prefer our descendants) |
| 925 | // |
| 926 | // note: knowing that mFocused is non-null is not a good enough reason |
| 927 | // to break the traversal since in that case we'd actually have to find |
| 928 | // the focused view and make sure it wasn't FOCUS_AFTER_DESCENDANTS and |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 929 | // an ancestor of v; this will get checked for at ViewAncestor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | && !(isFocused() && getDescendantFocusability() != FOCUS_AFTER_DESCENDANTS)) { |
| 931 | mParent.focusableViewAvailable(v); |
| 932 | } |
| 933 | } |
| 934 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 935 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | public boolean showContextMenuForChild(View originalView) { |
Adam Powell | 2af189a | 2016-02-05 15:52:02 -0800 | [diff] [blame] | 937 | if (isShowingContextMenuWithCoords()) { |
| 938 | // We're being called for compatibility. Return false and let the version |
| 939 | // with coordinates recurse up. |
| 940 | return false; |
| 941 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | return mParent != null && mParent.showContextMenuForChild(originalView); |
| 943 | } |
| 944 | |
Adam Powell | 2af189a | 2016-02-05 15:52:02 -0800 | [diff] [blame] | 945 | /** |
| 946 | * @hide used internally for compatibility with existing app code only |
| 947 | */ |
| 948 | public final boolean isShowingContextMenuWithCoords() { |
| 949 | return (mGroupFlags & FLAG_SHOW_CONTEXT_MENU_WITH_COORDS) != 0; |
| 950 | } |
| 951 | |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 952 | @Override |
| 953 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
Adam Powell | 2af189a | 2016-02-05 15:52:02 -0800 | [diff] [blame] | 954 | try { |
| 955 | mGroupFlags |= FLAG_SHOW_CONTEXT_MENU_WITH_COORDS; |
| 956 | if (showContextMenuForChild(originalView)) { |
| 957 | return true; |
| 958 | } |
| 959 | } finally { |
| 960 | mGroupFlags &= ~FLAG_SHOW_CONTEXT_MENU_WITH_COORDS; |
| 961 | } |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 962 | return mParent != null && mParent.showContextMenuForChild(originalView, x, y); |
| 963 | } |
| 964 | |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 965 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 966 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 967 | if ((mGroupFlags & FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED) == 0) { |
| 968 | // This is the original call. |
| 969 | try { |
| 970 | mGroupFlags |= FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED; |
| 971 | return startActionModeForChild(originalView, callback, ActionMode.TYPE_PRIMARY); |
| 972 | } finally { |
| 973 | mGroupFlags &= ~FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED; |
| 974 | } |
| 975 | } else { |
| 976 | // We are being called from the new method with type. |
| 977 | return SENTINEL_ACTION_MODE; |
| 978 | } |
| 979 | } |
| 980 | |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 981 | @Override |
| 982 | public ActionMode startActionModeForChild( |
| 983 | View originalView, ActionMode.Callback callback, int type) { |
Adam Powell | e9fd6d2 | 2015-06-01 11:26:32 -0700 | [diff] [blame] | 984 | if ((mGroupFlags & FLAG_START_ACTION_MODE_FOR_CHILD_IS_NOT_TYPED) == 0 |
| 985 | && type == ActionMode.TYPE_PRIMARY) { |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 986 | ActionMode mode; |
| 987 | try { |
| 988 | mGroupFlags |= FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED; |
| 989 | mode = startActionModeForChild(originalView, callback); |
| 990 | } finally { |
| 991 | mGroupFlags &= ~FLAG_START_ACTION_MODE_FOR_CHILD_IS_TYPED; |
| 992 | } |
| 993 | if (mode != SENTINEL_ACTION_MODE) { |
| 994 | return mode; |
| 995 | } |
| 996 | } |
| 997 | if (mParent != null) { |
| 998 | try { |
| 999 | return mParent.startActionModeForChild(originalView, callback, type); |
| 1000 | } catch (AbstractMethodError ame) { |
| 1001 | // Custom view parents might not implement this method. |
| 1002 | return mParent.startActionModeForChild(originalView, callback); |
| 1003 | } |
| 1004 | } |
| 1005 | return null; |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /** |
Clara Bayarri | d5bf3ed | 2015-03-27 17:32:45 +0000 | [diff] [blame] | 1009 | * @hide |
| 1010 | */ |
| 1011 | @Override |
| 1012 | public boolean dispatchActivityResult( |
| 1013 | String who, int requestCode, int resultCode, Intent data) { |
| 1014 | if (super.dispatchActivityResult(who, requestCode, resultCode, data)) { |
| 1015 | return true; |
| 1016 | } |
| 1017 | int childCount = getChildCount(); |
| 1018 | for (int i = 0; i < childCount; i++) { |
| 1019 | View child = getChildAt(i); |
| 1020 | if (child.dispatchActivityResult(who, requestCode, resultCode, data)) { |
| 1021 | return true; |
| 1022 | } |
| 1023 | } |
| 1024 | return false; |
| 1025 | } |
| 1026 | |
| 1027 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1028 | * Find the nearest view in the specified direction that wants to take |
| 1029 | * focus. |
| 1030 | * |
| 1031 | * @param focused The view that currently has focus |
| 1032 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and |
| 1033 | * FOCUS_RIGHT, or 0 for not applicable. |
| 1034 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1035 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | public View focusSearch(View focused, int direction) { |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 1037 | if (isRootNamespace()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | // root namespace means we should consider ourselves the top of the |
| 1039 | // tree for focus searching; otherwise we could be focus searching |
Vadim Tryshev | 418b1fc | 2016-11-28 18:26:24 -0800 | [diff] [blame] | 1040 | // into other tabs. see LocalActivityManager and TabHost for more info. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | return FocusFinder.getInstance().findNextFocus(this, focused, direction); |
| 1042 | } else if (mParent != null) { |
| 1043 | return mParent.focusSearch(focused, direction); |
| 1044 | } |
| 1045 | return null; |
| 1046 | } |
| 1047 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1048 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1053 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 1054 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 1055 | ViewParent parent = mParent; |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 1056 | if (parent == null) { |
| 1057 | return false; |
| 1058 | } |
| 1059 | final boolean propagate = onRequestSendAccessibilityEvent(child, event); |
| 1060 | if (!propagate) { |
| 1061 | return false; |
| 1062 | } |
| 1063 | return parent.requestSendAccessibilityEvent(this, event); |
| 1064 | } |
| 1065 | |
| 1066 | /** |
| 1067 | * Called when a child has requested sending an {@link AccessibilityEvent} and |
| 1068 | * gives an opportunity to its parent to augment the event. |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 1069 | * <p> |
Adam Powell | 2fcbbd0 | 2011-09-28 18:56:43 -0700 | [diff] [blame] | 1070 | * If an {@link android.view.View.AccessibilityDelegate} has been specified via calling |
| 1071 | * {@link android.view.View#setAccessibilityDelegate(android.view.View.AccessibilityDelegate)} its |
| 1072 | * {@link android.view.View.AccessibilityDelegate#onRequestSendAccessibilityEvent(ViewGroup, View, AccessibilityEvent)} |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 1073 | * is responsible for handling this call. |
| 1074 | * </p> |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 1075 | * |
| 1076 | * @param child The child which requests sending the event. |
| 1077 | * @param event The event to be sent. |
| 1078 | * @return True if the event should be sent. |
| 1079 | * |
| 1080 | * @see #requestSendAccessibilityEvent(View, AccessibilityEvent) |
| 1081 | */ |
| 1082 | public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 1083 | if (mAccessibilityDelegate != null) { |
| 1084 | return mAccessibilityDelegate.onRequestSendAccessibilityEvent(this, child, event); |
| 1085 | } else { |
| 1086 | return onRequestSendAccessibilityEventInternal(child, event); |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * @see #onRequestSendAccessibilityEvent(View, AccessibilityEvent) |
| 1092 | * |
| 1093 | * Note: Called from the default {@link View.AccessibilityDelegate}. |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 1094 | * |
| 1095 | * @hide |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 1096 | */ |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 1097 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 1098 | return true; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1102 | * Called when a child view has changed whether or not it is tracking transient state. |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1103 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1104 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1105 | public void childHasTransientStateChanged(View child, boolean childHasTransientState) { |
| 1106 | final boolean oldHasTransientState = hasTransientState(); |
| 1107 | if (childHasTransientState) { |
| 1108 | mChildCountWithTransientState++; |
| 1109 | } else { |
| 1110 | mChildCountWithTransientState--; |
| 1111 | } |
| 1112 | |
| 1113 | final boolean newHasTransientState = hasTransientState(); |
| 1114 | if (mParent != null && oldHasTransientState != newHasTransientState) { |
| 1115 | try { |
| 1116 | mParent.childHasTransientStateChanged(this, newHasTransientState); |
| 1117 | } catch (AbstractMethodError e) { |
| 1118 | Log.e(TAG, mParent.getClass().getSimpleName() + |
| 1119 | " does not fully implement ViewParent", e); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 1124 | @Override |
| 1125 | public boolean hasTransientState() { |
| 1126 | return mChildCountWithTransientState > 0 || super.hasTransientState(); |
| 1127 | } |
| 1128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | @Override |
| 1130 | public boolean dispatchUnhandledMove(View focused, int direction) { |
| 1131 | return mFocused != null && |
| 1132 | mFocused.dispatchUnhandledMove(focused, direction); |
| 1133 | } |
| 1134 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1135 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | public void clearChildFocus(View child) { |
| 1137 | if (DBG) { |
| 1138 | System.out.println(this + " clearChildFocus()"); |
| 1139 | } |
| 1140 | |
| 1141 | mFocused = null; |
| 1142 | if (mParent != null) { |
| 1143 | mParent.clearChildFocus(this); |
| 1144 | } |
| 1145 | } |
| 1146 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | @Override |
| 1148 | public void clearFocus() { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 1149 | if (DBG) { |
| 1150 | System.out.println(this + " clearFocus()"); |
| 1151 | } |
| 1152 | if (mFocused == null) { |
| 1153 | super.clearFocus(); |
| 1154 | } else { |
Svetoslav Ganov | b552d89 | 2012-06-02 14:35:02 -0700 | [diff] [blame] | 1155 | View focused = mFocused; |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 1156 | mFocused = null; |
Svetoslav Ganov | b552d89 | 2012-06-02 14:35:02 -0700 | [diff] [blame] | 1157 | focused.clearFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | @Override |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 1162 | void unFocus(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | if (DBG) { |
| 1164 | System.out.println(this + " unFocus()"); |
| 1165 | } |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 1166 | if (mFocused == null) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 1167 | super.unFocus(focused); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 1168 | } else { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 1169 | mFocused.unFocus(focused); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 1170 | mFocused = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /** |
| 1175 | * Returns the focused child of this view, if any. The child may have focus |
| 1176 | * or contain focus. |
| 1177 | * |
| 1178 | * @return the focused child or null. |
| 1179 | */ |
| 1180 | public View getFocusedChild() { |
| 1181 | return mFocused; |
| 1182 | } |
| 1183 | |
Adam Powell | 88c1175 | 2014-07-21 17:19:16 -0700 | [diff] [blame] | 1184 | View getDeepestFocusedChild() { |
| 1185 | View v = this; |
| 1186 | while (v != null) { |
| 1187 | if (v.isFocused()) { |
| 1188 | return v; |
| 1189 | } |
| 1190 | v = v instanceof ViewGroup ? ((ViewGroup) v).getFocusedChild() : null; |
| 1191 | } |
| 1192 | return null; |
| 1193 | } |
| 1194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | /** |
| 1196 | * Returns true if this view has or contains focus |
| 1197 | * |
| 1198 | * @return true if this view has or contains focus |
| 1199 | */ |
| 1200 | @Override |
| 1201 | public boolean hasFocus() { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1202 | return (mPrivateFlags & PFLAG_FOCUSED) != 0 || mFocused != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * (non-Javadoc) |
| 1207 | * |
| 1208 | * @see android.view.View#findFocus() |
| 1209 | */ |
| 1210 | @Override |
| 1211 | public View findFocus() { |
| 1212 | if (DBG) { |
| 1213 | System.out.println("Find focus in " + this + ": flags=" |
| 1214 | + isFocused() + ", child=" + mFocused); |
| 1215 | } |
| 1216 | |
| 1217 | if (isFocused()) { |
| 1218 | return this; |
| 1219 | } |
| 1220 | |
| 1221 | if (mFocused != null) { |
| 1222 | return mFocused.findFocus(); |
| 1223 | } |
| 1224 | return null; |
| 1225 | } |
| 1226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | @Override |
Adam Powell | 0f552f4 | 2017-02-03 11:50:42 -0800 | [diff] [blame] | 1228 | boolean hasFocusable(boolean allowAutoFocus, boolean dispatchExplicit) { |
Alan Viverette | 7485a9b | 2017-02-27 11:55:53 -0500 | [diff] [blame] | 1229 | // This should probably be super.hasFocusable, but that would change |
| 1230 | // behavior. Historically, we have not checked the ancestor views for |
| 1231 | // shouldBlockFocusForTouchscreen() in ViewGroup.hasFocusable. |
| 1232 | |
| 1233 | // Invisible and gone views are never focusable. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | if ((mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
Alan Viverette | 7485a9b | 2017-02-27 11:55:53 -0500 | [diff] [blame] | 1238 | // Only use effective focusable value when allowed. |
| 1239 | if ((allowAutoFocus || getFocusable() != FOCUSABLE_AUTO) && isFocusable()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | return true; |
| 1241 | } |
| 1242 | |
Alan Viverette | 7485a9b | 2017-02-27 11:55:53 -0500 | [diff] [blame] | 1243 | // Determine whether we have a focused descendant. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | final int descendantFocusability = getDescendantFocusability(); |
Adam Powell | 88c1175 | 2014-07-21 17:19:16 -0700 | [diff] [blame] | 1245 | if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) { |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 1246 | return hasFocusableChild(dispatchExplicit); |
| 1247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 1249 | return false; |
| 1250 | } |
Adam Powell | 0f552f4 | 2017-02-03 11:50:42 -0800 | [diff] [blame] | 1251 | |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 1252 | boolean hasFocusableChild(boolean dispatchExplicit) { |
| 1253 | // Determine whether we have a focusable descendant. |
| 1254 | final int count = mChildrenCount; |
| 1255 | final View[] children = mChildren; |
| 1256 | |
| 1257 | for (int i = 0; i < count; i++) { |
| 1258 | final View child = children[i]; |
| 1259 | |
| 1260 | // In case the subclass has overridden has[Explicit]Focusable, dispatch |
| 1261 | // to the expected one for each child even though we share logic here. |
| 1262 | if ((dispatchExplicit && child.hasExplicitFocusable()) |
| 1263 | || (!dispatchExplicit && child.hasFocusable())) { |
| 1264 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | return false; |
| 1269 | } |
| 1270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | @Override |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1272 | public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | final int focusableCount = views.size(); |
| 1274 | |
| 1275 | final int descendantFocusability = getDescendantFocusability(); |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1276 | final boolean blockFocusForTouchscreen = shouldBlockFocusForTouchscreen(); |
| 1277 | final boolean focusSelf = (isFocusableInTouchMode() || !blockFocusForTouchscreen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | |
Evan Rosky | 3b94bf5 | 2017-01-10 17:05:28 -0800 | [diff] [blame] | 1279 | if (descendantFocusability == FOCUS_BLOCK_DESCENDANTS) { |
| 1280 | if (focusSelf) { |
| 1281 | super.addFocusables(views, direction, focusableMode); |
Adam Powell | 88c1175 | 2014-07-21 17:19:16 -0700 | [diff] [blame] | 1282 | } |
Evan Rosky | 3b94bf5 | 2017-01-10 17:05:28 -0800 | [diff] [blame] | 1283 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1286 | if (blockFocusForTouchscreen) { |
Evan Rosky | 3b94bf5 | 2017-01-10 17:05:28 -0800 | [diff] [blame] | 1287 | focusableMode |= FOCUSABLES_TOUCH_MODE; |
| 1288 | } |
| 1289 | |
| 1290 | if ((descendantFocusability == FOCUS_BEFORE_DESCENDANTS) && focusSelf) { |
| 1291 | super.addFocusables(views, direction, focusableMode); |
| 1292 | } |
| 1293 | |
| 1294 | int count = 0; |
| 1295 | final View[] children = new View[mChildrenCount]; |
| 1296 | for (int i = 0; i < mChildrenCount; ++i) { |
| 1297 | View child = mChildren[i]; |
| 1298 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 1299 | children[count++] = child; |
| 1300 | } |
| 1301 | } |
Evan Rosky | d114e0f | 2017-03-23 11:20:04 -0700 | [diff] [blame] | 1302 | FocusFinder.sort(children, 0, count, this, isLayoutRtl()); |
Evan Rosky | 3b94bf5 | 2017-01-10 17:05:28 -0800 | [diff] [blame] | 1303 | for (int i = 0; i < count; ++i) { |
| 1304 | children[i].addFocusables(views, direction, focusableMode); |
| 1305 | } |
| 1306 | |
| 1307 | // When set to FOCUS_AFTER_DESCENDANTS, we only add ourselves if |
| 1308 | // there aren't any focusable descendants. this is |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | // to avoid the focus search finding layouts when a more precise search |
| 1310 | // among the focusable children would be more interesting. |
Evan Rosky | 3b94bf5 | 2017-01-10 17:05:28 -0800 | [diff] [blame] | 1311 | if ((descendantFocusability == FOCUS_AFTER_DESCENDANTS) && focusSelf |
| 1312 | && focusableCount == views.size()) { |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1313 | super.addFocusables(views, direction, focusableMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1317 | @Override |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 1318 | public void addKeyboardNavigationClusters(Collection<View> views, int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1319 | final int focusableCount = views.size(); |
| 1320 | |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1321 | if (isKeyboardNavigationCluster()) { |
| 1322 | // Cluster-navigation can enter a touchscreenBlocksFocus cluster, so temporarily |
| 1323 | // disable touchscreenBlocksFocus to evaluate whether it contains focusables. |
| 1324 | final boolean blockedFocus = getTouchscreenBlocksFocus(); |
| 1325 | try { |
| 1326 | setTouchscreenBlocksFocusNoRefocus(false); |
| 1327 | super.addKeyboardNavigationClusters(views, direction); |
| 1328 | } finally { |
| 1329 | setTouchscreenBlocksFocusNoRefocus(blockedFocus); |
| 1330 | } |
| 1331 | } else { |
| 1332 | super.addKeyboardNavigationClusters(views, direction); |
| 1333 | } |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1334 | |
| 1335 | if (focusableCount != views.size()) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 1336 | // No need to look for groups inside a group. |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | if (getDescendantFocusability() == FOCUS_BLOCK_DESCENDANTS) { |
| 1341 | return; |
| 1342 | } |
| 1343 | |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 1344 | int count = 0; |
| 1345 | final View[] visibleChildren = new View[mChildrenCount]; |
| 1346 | for (int i = 0; i < mChildrenCount; ++i) { |
| 1347 | final View child = mChildren[i]; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1348 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 1349 | visibleChildren[count++] = child; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1350 | } |
| 1351 | } |
Evan Rosky | d114e0f | 2017-03-23 11:20:04 -0700 | [diff] [blame] | 1352 | FocusFinder.sort(visibleChildren, 0, count, this, isLayoutRtl()); |
Evan Rosky | bd10c52 | 2017-03-27 15:50:38 -0700 | [diff] [blame] | 1353 | for (int i = 0; i < count; ++i) { |
| 1354 | visibleChildren[i].addKeyboardNavigationClusters(views, direction); |
| 1355 | } |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1358 | /** |
| 1359 | * Set whether this ViewGroup should ignore focus requests for itself and its children. |
| 1360 | * If this option is enabled and the ViewGroup or a descendant currently has focus, focus |
| 1361 | * will proceed forward. |
| 1362 | * |
| 1363 | * @param touchscreenBlocksFocus true to enable blocking focus in the presence of a touchscreen |
| 1364 | */ |
| 1365 | public void setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus) { |
| 1366 | if (touchscreenBlocksFocus) { |
| 1367 | mGroupFlags |= FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 1368 | if (hasFocus() && !isKeyboardNavigationCluster()) { |
Adam Powell | 88c1175 | 2014-07-21 17:19:16 -0700 | [diff] [blame] | 1369 | final View focusedChild = getDeepestFocusedChild(); |
| 1370 | if (!focusedChild.isFocusableInTouchMode()) { |
| 1371 | final View newFocus = focusSearch(FOCUS_FORWARD); |
| 1372 | if (newFocus != null) { |
| 1373 | newFocus.requestFocus(); |
| 1374 | } |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | } else { |
| 1378 | mGroupFlags &= ~FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1379 | } |
| 1380 | } |
| 1381 | |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1382 | private void setTouchscreenBlocksFocusNoRefocus(boolean touchscreenBlocksFocus) { |
| 1383 | if (touchscreenBlocksFocus) { |
| 1384 | mGroupFlags |= FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1385 | } else { |
| 1386 | mGroupFlags &= ~FLAG_TOUCHSCREEN_BLOCKS_FOCUS; |
| 1387 | } |
| 1388 | } |
| 1389 | |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1390 | /** |
| 1391 | * Check whether this ViewGroup should ignore focus requests for itself and its children. |
| 1392 | */ |
Evan Rosky | ecb63fc | 2017-04-13 16:57:18 -0700 | [diff] [blame] | 1393 | @ViewDebug.ExportedProperty(category = "focus") |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1394 | public boolean getTouchscreenBlocksFocus() { |
| 1395 | return (mGroupFlags & FLAG_TOUCHSCREEN_BLOCKS_FOCUS) != 0; |
| 1396 | } |
| 1397 | |
| 1398 | boolean shouldBlockFocusForTouchscreen() { |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1399 | // There is a special case for keyboard-navigation clusters. We allow cluster navigation |
| 1400 | // to jump into blockFocusForTouchscreen ViewGroups which are clusters. Once in the |
| 1401 | // cluster, focus is free to move around within it. |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1402 | return getTouchscreenBlocksFocus() && |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 1403 | mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN) |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 1404 | && !(isKeyboardNavigationCluster() |
| 1405 | && (hasFocus() || (findKeyboardNavigationCluster() != this))); |
Adam Powell | ff0d298 | 2014-07-10 20:34:14 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1408 | @Override |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 1409 | public void findViewsWithText(ArrayList<View> outViews, CharSequence text, int flags) { |
| 1410 | super.findViewsWithText(outViews, text, flags); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1411 | final int childrenCount = mChildrenCount; |
| 1412 | final View[] children = mChildren; |
| 1413 | for (int i = 0; i < childrenCount; i++) { |
| 1414 | View child = children[i]; |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 1415 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1416 | && (child.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
Svetoslav Ganov | ea515ae | 2011-09-14 18:15:32 -0700 | [diff] [blame] | 1417 | child.findViewsWithText(outViews, text, flags); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
Svetoslav | 5b578da | 2013-05-08 14:23:32 -0700 | [diff] [blame] | 1422 | /** @hide */ |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 1423 | @Override |
Svetoslav | 5b578da | 2013-05-08 14:23:32 -0700 | [diff] [blame] | 1424 | public View findViewByAccessibilityIdTraversal(int accessibilityId) { |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 1425 | View foundView = super.findViewByAccessibilityIdTraversal(accessibilityId); |
| 1426 | if (foundView != null) { |
| 1427 | return foundView; |
| 1428 | } |
Svetoslav | 6cc4627 | 2015-06-03 11:38:30 -0700 | [diff] [blame] | 1429 | |
| 1430 | if (getAccessibilityNodeProvider() != null) { |
| 1431 | return null; |
| 1432 | } |
| 1433 | |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 1434 | final int childrenCount = mChildrenCount; |
| 1435 | final View[] children = mChildren; |
| 1436 | for (int i = 0; i < childrenCount; i++) { |
| 1437 | View child = children[i]; |
| 1438 | foundView = child.findViewByAccessibilityIdTraversal(accessibilityId); |
| 1439 | if (foundView != null) { |
| 1440 | return foundView; |
| 1441 | } |
| 1442 | } |
Svetoslav | 6cc4627 | 2015-06-03 11:38:30 -0700 | [diff] [blame] | 1443 | |
Svetoslav Ganov | 2cdedff | 2011-10-03 14:18:42 -0700 | [diff] [blame] | 1444 | return null; |
| 1445 | } |
| 1446 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1447 | /** @hide */ |
| 1448 | @Override |
| 1449 | public View findViewByAutofillIdTraversal(int autofillId) { |
| 1450 | View foundView = super.findViewByAutofillIdTraversal(autofillId); |
| 1451 | if (foundView != null) { |
| 1452 | return foundView; |
| 1453 | } |
| 1454 | |
| 1455 | final int childrenCount = mChildrenCount; |
| 1456 | final View[] children = mChildren; |
| 1457 | for (int i = 0; i < childrenCount; i++) { |
| 1458 | View child = children[i]; |
| 1459 | foundView = child.findViewByAutofillIdTraversal(autofillId); |
| 1460 | if (foundView != null) { |
| 1461 | return foundView; |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | return null; |
| 1466 | } |
| 1467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | @Override |
| 1469 | public void dispatchWindowFocusChanged(boolean hasFocus) { |
| 1470 | super.dispatchWindowFocusChanged(hasFocus); |
| 1471 | final int count = mChildrenCount; |
| 1472 | final View[] children = mChildren; |
| 1473 | for (int i = 0; i < count; i++) { |
| 1474 | children[i].dispatchWindowFocusChanged(hasFocus); |
| 1475 | } |
| 1476 | } |
| 1477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | @Override |
| 1479 | public void addTouchables(ArrayList<View> views) { |
| 1480 | super.addTouchables(views); |
| 1481 | |
| 1482 | final int count = mChildrenCount; |
| 1483 | final View[] children = mChildren; |
| 1484 | |
| 1485 | for (int i = 0; i < count; i++) { |
| 1486 | final View child = children[i]; |
| 1487 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 1488 | child.addTouchables(views); |
| 1489 | } |
| 1490 | } |
| 1491 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1492 | |
| 1493 | /** |
| 1494 | * @hide |
| 1495 | */ |
| 1496 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1497 | @UnsupportedAppUsage |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1498 | public void makeOptionalFitsSystemWindows() { |
| 1499 | super.makeOptionalFitsSystemWindows(); |
| 1500 | final int count = mChildrenCount; |
| 1501 | final View[] children = mChildren; |
| 1502 | for (int i = 0; i < count; i++) { |
| 1503 | children[i].makeOptionalFitsSystemWindows(); |
| 1504 | } |
| 1505 | } |
| 1506 | |
Romain Guy | 43c9cdf | 2010-01-27 13:53:55 -0800 | [diff] [blame] | 1507 | @Override |
| 1508 | public void dispatchDisplayHint(int hint) { |
| 1509 | super.dispatchDisplayHint(hint); |
| 1510 | final int count = mChildrenCount; |
| 1511 | final View[] children = mChildren; |
| 1512 | for (int i = 0; i < count; i++) { |
| 1513 | children[i].dispatchDisplayHint(hint); |
| 1514 | } |
| 1515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | |
| 1517 | /** |
Chet Haase | 0d29936 | 2012-01-26 10:51:48 -0800 | [diff] [blame] | 1518 | * Called when a view's visibility has changed. Notify the parent to take any appropriate |
| 1519 | * action. |
| 1520 | * |
| 1521 | * @param child The view whose visibility has changed |
| 1522 | * @param oldVisibility The previous visibility value (GONE, INVISIBLE, or VISIBLE). |
| 1523 | * @param newVisibility The new visibility value (GONE, INVISIBLE, or VISIBLE). |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1524 | * @hide |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1525 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1526 | @UnsupportedAppUsage |
Chet Haase | 0d29936 | 2012-01-26 10:51:48 -0800 | [diff] [blame] | 1527 | protected void onChildVisibilityChanged(View child, int oldVisibility, int newVisibility) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1528 | if (mTransition != null) { |
Chet Haase | 0d29936 | 2012-01-26 10:51:48 -0800 | [diff] [blame] | 1529 | if (newVisibility == VISIBLE) { |
| 1530 | mTransition.showChild(this, child, oldVisibility); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1531 | } else { |
Chet Haase | 0d29936 | 2012-01-26 10:51:48 -0800 | [diff] [blame] | 1532 | mTransition.hideChild(this, child, newVisibility); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1533 | if (mTransitioningViews != null && mTransitioningViews.contains(child)) { |
Chet Haase | ddbb346 | 2012-06-19 13:54:29 -0700 | [diff] [blame] | 1534 | // Only track this on disappearing views - appearing views are already visible |
| 1535 | // and don't need special handling during drawChild() |
| 1536 | if (mVisibilityChangingChildren == null) { |
| 1537 | mVisibilityChangingChildren = new ArrayList<View>(); |
| 1538 | } |
| 1539 | mVisibilityChangingChildren.add(child); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1540 | addDisappearingView(child); |
| 1541 | } |
| 1542 | } |
| 1543 | } |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1544 | |
| 1545 | // in all cases, for drags |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1546 | if (newVisibility == VISIBLE && mCurrentDragStartEvent != null) { |
| 1547 | if (!mChildrenInterestedInDrag.contains(child)) { |
| 1548 | notifyChildOfDragStart(child); |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1549 | } |
| 1550 | } |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 1551 | } |
| 1552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | @Override |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 1554 | protected void dispatchVisibilityChanged(View changedView, int visibility) { |
| 1555 | super.dispatchVisibilityChanged(changedView, visibility); |
| 1556 | final int count = mChildrenCount; |
| 1557 | final View[] children = mChildren; |
| 1558 | for (int i = 0; i < count; i++) { |
| 1559 | children[i].dispatchVisibilityChanged(changedView, visibility); |
| 1560 | } |
| 1561 | } |
| 1562 | |
Adam Powell | 326d808 | 2009-12-09 15:10:07 -0800 | [diff] [blame] | 1563 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | public void dispatchWindowVisibilityChanged(int visibility) { |
| 1565 | super.dispatchWindowVisibilityChanged(visibility); |
| 1566 | final int count = mChildrenCount; |
| 1567 | final View[] children = mChildren; |
| 1568 | for (int i = 0; i < count; i++) { |
| 1569 | children[i].dispatchWindowVisibilityChanged(visibility); |
| 1570 | } |
| 1571 | } |
| 1572 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1573 | @Override |
Adam Powell | 9c146bf | 2016-03-15 17:35:00 -0700 | [diff] [blame] | 1574 | boolean dispatchVisibilityAggregated(boolean isVisible) { |
| 1575 | isVisible = super.dispatchVisibilityAggregated(isVisible); |
Adam Powell | 41d9690 | 2016-03-15 14:43:19 -0700 | [diff] [blame] | 1576 | final int count = mChildrenCount; |
| 1577 | final View[] children = mChildren; |
| 1578 | for (int i = 0; i < count; i++) { |
Adam Powell | 9c146bf | 2016-03-15 17:35:00 -0700 | [diff] [blame] | 1579 | // Only dispatch to visible children. Not visible children and their subtrees already |
| 1580 | // know that they aren't visible and that's not going to change as a result of |
| 1581 | // whatever triggered this dispatch. |
| 1582 | if (children[i].getVisibility() == VISIBLE) { |
| 1583 | children[i].dispatchVisibilityAggregated(isVisible); |
Adam Powell | 41d9690 | 2016-03-15 14:43:19 -0700 | [diff] [blame] | 1584 | } |
| 1585 | } |
Adam Powell | 9c146bf | 2016-03-15 17:35:00 -0700 | [diff] [blame] | 1586 | return isVisible; |
Adam Powell | 41d9690 | 2016-03-15 14:43:19 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | @Override |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1590 | public void dispatchConfigurationChanged(Configuration newConfig) { |
| 1591 | super.dispatchConfigurationChanged(newConfig); |
| 1592 | final int count = mChildrenCount; |
| 1593 | final View[] children = mChildren; |
| 1594 | for (int i = 0; i < count; i++) { |
| 1595 | children[i].dispatchConfigurationChanged(newConfig); |
| 1596 | } |
| 1597 | } |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 1598 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1599 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | public void recomputeViewAttributes(View child) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1601 | if (mAttachInfo != null && !mAttachInfo.mRecomputeGlobalAttributes) { |
| 1602 | ViewParent parent = mParent; |
| 1603 | if (parent != null) parent.recomputeViewAttributes(this); |
| 1604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1608 | void dispatchCollectViewAttributes(AttachInfo attachInfo, int visibility) { |
| 1609 | if ((visibility & VISIBILITY_MASK) == VISIBLE) { |
| 1610 | super.dispatchCollectViewAttributes(attachInfo, visibility); |
| 1611 | final int count = mChildrenCount; |
| 1612 | final View[] children = mChildren; |
| 1613 | for (int i = 0; i < count; i++) { |
| 1614 | final View child = children[i]; |
| 1615 | child.dispatchCollectViewAttributes(attachInfo, |
| 1616 | visibility | (child.mViewFlags&VISIBILITY_MASK)); |
| 1617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 1621 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | public void bringChildToFront(View child) { |
Alan Viverette | 77bb6f1 | 2015-02-11 17:24:33 -0800 | [diff] [blame] | 1623 | final int index = indexOfChild(child); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | if (index >= 0) { |
| 1625 | removeFromArray(index); |
| 1626 | addInArray(child, mChildrenCount); |
| 1627 | child.mParent = this; |
Chet Haase | cb96db8 | 2013-09-04 10:21:46 -0700 | [diff] [blame] | 1628 | requestLayout(); |
| 1629 | invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 1633 | private PointF getLocalPoint() { |
| 1634 | if (mLocalPoint == null) mLocalPoint = new PointF(); |
| 1635 | return mLocalPoint; |
| 1636 | } |
| 1637 | |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1638 | @Override |
| 1639 | boolean dispatchDragEnterExitInPreN(DragEvent event) { |
| 1640 | if (event.mAction == DragEvent.ACTION_DRAG_EXITED && mCurrentDragChild != null) { |
| 1641 | // The drag exited a sub-tree of views; notify of the exit all descendants that are in |
| 1642 | // entered state. |
| 1643 | // We don't need this recursive delivery for ENTERED events because they get generated |
| 1644 | // from the recursive delivery of LOCATION/DROP events, and hence, don't need their own |
| 1645 | // recursion. |
| 1646 | mCurrentDragChild.dispatchDragEnterExitInPreN(event); |
| 1647 | mCurrentDragChild = null; |
| 1648 | } |
| 1649 | return mIsInterestedInDrag && super.dispatchDragEnterExitInPreN(event); |
| 1650 | } |
| 1651 | |
Steve Block | 8a7259b | 2012-03-01 11:24:41 +0000 | [diff] [blame] | 1652 | // TODO: Write real docs |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1653 | @Override |
| 1654 | public boolean dispatchDragEvent(DragEvent event) { |
| 1655 | boolean retval = false; |
| 1656 | final float tx = event.mX; |
| 1657 | final float ty = event.mY; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 1658 | final ClipData td = event.mClipData; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1659 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1660 | // Dispatch down the view hierarchy |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 1661 | final PointF localPoint = getLocalPoint(); |
| 1662 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1663 | switch (event.mAction) { |
| 1664 | case DragEvent.ACTION_DRAG_STARTED: { |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1665 | // Clear the state to recalculate which views we drag over. |
| 1666 | mCurrentDragChild = null; |
| 1667 | |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1668 | // Set up our tracking of drag-started notifications |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1669 | mCurrentDragStartEvent = DragEvent.obtain(event); |
| 1670 | if (mChildrenInterestedInDrag == null) { |
| 1671 | mChildrenInterestedInDrag = new HashSet<View>(); |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1672 | } else { |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1673 | mChildrenInterestedInDrag.clear(); |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1674 | } |
| 1675 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1676 | // Now dispatch down to our children, caching the responses |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1677 | final int count = mChildrenCount; |
| 1678 | final View[] children = mChildren; |
| 1679 | for (int i = 0; i < count; i++) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 1680 | final View child = children[i]; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1681 | child.mPrivateFlags2 &= ~View.DRAG_MASK; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 1682 | if (child.getVisibility() == VISIBLE) { |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1683 | if (notifyChildOfDragStart(children[i])) { |
| 1684 | retval = true; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 1685 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1689 | // Notify itself of the drag start. |
| 1690 | mIsInterestedInDrag = super.dispatchDragEvent(event); |
| 1691 | if (mIsInterestedInDrag) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1692 | retval = true; |
| 1693 | } |
Yorke Lee | 0394b21 | 2016-03-10 18:20:04 -0800 | [diff] [blame] | 1694 | |
| 1695 | if (!retval) { |
| 1696 | // Neither us nor any of our children are interested in this drag, so stop tracking |
| 1697 | // the current drag event. |
| 1698 | mCurrentDragStartEvent.recycle(); |
| 1699 | mCurrentDragStartEvent = null; |
| 1700 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1701 | } break; |
| 1702 | |
| 1703 | case DragEvent.ACTION_DRAG_ENDED: { |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1704 | // Release the bookkeeping now that the drag lifecycle has ended |
Vadim Tryshev | 1517789 | 2015-12-18 08:01:00 -0800 | [diff] [blame] | 1705 | final HashSet<View> childrenInterestedInDrag = mChildrenInterestedInDrag; |
| 1706 | if (childrenInterestedInDrag != null) { |
| 1707 | for (View child : childrenInterestedInDrag) { |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1708 | // If a child was interested in the ongoing drag, it's told that it's over |
| 1709 | if (child.dispatchDragEvent(event)) { |
| 1710 | retval = true; |
| 1711 | } |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 1712 | } |
Vadim Tryshev | 1517789 | 2015-12-18 08:01:00 -0800 | [diff] [blame] | 1713 | childrenInterestedInDrag.clear(); |
| 1714 | } |
| 1715 | if (mCurrentDragStartEvent != null) { |
| 1716 | mCurrentDragStartEvent.recycle(); |
| 1717 | mCurrentDragStartEvent = null; |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 1718 | } |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1719 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1720 | if (mIsInterestedInDrag) { |
| 1721 | if (super.dispatchDragEvent(event)) { |
| 1722 | retval = true; |
| 1723 | } |
| 1724 | mIsInterestedInDrag = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1725 | } |
| 1726 | } break; |
| 1727 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 1728 | case DragEvent.ACTION_DRAG_LOCATION: |
| 1729 | case DragEvent.ACTION_DROP: { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1730 | // Find the [possibly new] drag target |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1731 | View target = findFrontmostDroppableChildAt(event.mX, event.mY, localPoint); |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1732 | |
| 1733 | if (target != mCurrentDragChild) { |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 1734 | if (sCascadedDragDrop) { |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1735 | // For pre-Nougat apps, make sure that the whole hierarchy of views that contain |
| 1736 | // the drag location is kept in the state between ENTERED and EXITED events. |
| 1737 | // (Starting with N, only the innermost view will be in that state). |
| 1738 | |
| 1739 | final int action = event.mAction; |
| 1740 | // Position should not be available for ACTION_DRAG_ENTERED and |
| 1741 | // ACTION_DRAG_EXITED. |
| 1742 | event.mX = 0; |
| 1743 | event.mY = 0; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 1744 | event.mClipData = null; |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1745 | |
| 1746 | if (mCurrentDragChild != null) { |
| 1747 | event.mAction = DragEvent.ACTION_DRAG_EXITED; |
| 1748 | mCurrentDragChild.dispatchDragEnterExitInPreN(event); |
| 1749 | } |
| 1750 | |
| 1751 | if (target != null) { |
| 1752 | event.mAction = DragEvent.ACTION_DRAG_ENTERED; |
| 1753 | target.dispatchDragEnterExitInPreN(event); |
| 1754 | } |
| 1755 | |
| 1756 | event.mAction = action; |
| 1757 | event.mX = tx; |
| 1758 | event.mY = ty; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 1759 | event.mClipData = td; |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 1760 | } |
| 1761 | mCurrentDragChild = target; |
| 1762 | } |
| 1763 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1764 | if (target == null && mIsInterestedInDrag) { |
| 1765 | target = this; |
| 1766 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1767 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 1768 | // Dispatch the actual drag notice, localized into the target coordinates. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1769 | if (target != null) { |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1770 | if (target != this) { |
| 1771 | event.mX = localPoint.x; |
| 1772 | event.mY = localPoint.y; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1773 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1774 | retval = target.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1775 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1776 | event.mX = tx; |
| 1777 | event.mY = ty; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 1778 | |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 1779 | if (mIsInterestedInDrag) { |
| 1780 | final boolean eventWasConsumed; |
| 1781 | if (sCascadedDragDrop) { |
| 1782 | eventWasConsumed = retval; |
| 1783 | } else { |
| 1784 | eventWasConsumed = event.mEventHandlerWasCalled; |
| 1785 | } |
| 1786 | |
| 1787 | if (!eventWasConsumed) { |
| 1788 | retval = super.dispatchDragEvent(event); |
| 1789 | } |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 1790 | } |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1791 | } else { |
| 1792 | retval = super.dispatchDragEvent(event); |
| 1793 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1794 | } |
| 1795 | } break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1798 | return retval; |
| 1799 | } |
| 1800 | |
| 1801 | // Find the frontmost child view that lies under the given point, and calculate |
| 1802 | // the position within its own local coordinate system. |
| 1803 | View findFrontmostDroppableChildAt(float x, float y, PointF outLocalPoint) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1804 | final int count = mChildrenCount; |
| 1805 | final View[] children = mChildren; |
| 1806 | for (int i = count - 1; i >= 0; i--) { |
| 1807 | final View child = children[i]; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1808 | if (!child.canAcceptDrag()) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1809 | continue; |
| 1810 | } |
| 1811 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 1812 | if (isTransformedTouchPointInView(x, y, child, outLocalPoint)) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1813 | return child; |
| 1814 | } |
| 1815 | } |
| 1816 | return null; |
| 1817 | } |
| 1818 | |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1819 | boolean notifyChildOfDragStart(View child) { |
| 1820 | // The caller guarantees that the child is not in mChildrenInterestedInDrag yet. |
| 1821 | |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1822 | if (ViewDebug.DEBUG_DRAG) { |
| 1823 | Log.d(View.VIEW_LOG_TAG, "Sending drag-started to view: " + child); |
| 1824 | } |
| 1825 | |
Vladislav Kaznacheev | c244970 | 2016-05-16 12:57:15 -0700 | [diff] [blame] | 1826 | final float tx = mCurrentDragStartEvent.mX; |
| 1827 | final float ty = mCurrentDragStartEvent.mY; |
| 1828 | |
| 1829 | final float[] point = getTempPoint(); |
| 1830 | point[0] = tx; |
| 1831 | point[1] = ty; |
| 1832 | transformPointToViewLocal(point, child); |
| 1833 | |
| 1834 | mCurrentDragStartEvent.mX = point[0]; |
| 1835 | mCurrentDragStartEvent.mY = point[1]; |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1836 | final boolean canAccept = child.dispatchDragEvent(mCurrentDragStartEvent); |
Vladislav Kaznacheev | c244970 | 2016-05-16 12:57:15 -0700 | [diff] [blame] | 1837 | mCurrentDragStartEvent.mX = tx; |
| 1838 | mCurrentDragStartEvent.mY = ty; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 1839 | mCurrentDragStartEvent.mEventHandlerWasCalled = false; |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 1840 | if (canAccept) { |
| 1841 | mChildrenInterestedInDrag.add(child); |
| 1842 | if (!child.canAcceptDrag()) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1843 | child.mPrivateFlags2 |= View.PFLAG2_DRAG_CAN_ACCEPT; |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1844 | child.refreshDrawableState(); |
| 1845 | } |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1846 | } |
Christopher Tate | 3d4bf17 | 2011-03-28 16:16:46 -0700 | [diff] [blame] | 1847 | return canAccept; |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1850 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1851 | public void dispatchWindowSystemUiVisiblityChanged(int visible) { |
| 1852 | super.dispatchWindowSystemUiVisiblityChanged(visible); |
| 1853 | |
| 1854 | final int count = mChildrenCount; |
| 1855 | final View[] children = mChildren; |
| 1856 | for (int i=0; i <count; i++) { |
| 1857 | final View child = children[i]; |
| 1858 | child.dispatchWindowSystemUiVisiblityChanged(visible); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 1863 | public void dispatchSystemUiVisibilityChanged(int visible) { |
| 1864 | super.dispatchSystemUiVisibilityChanged(visible); |
| 1865 | |
| 1866 | final int count = mChildrenCount; |
| 1867 | final View[] children = mChildren; |
| 1868 | for (int i=0; i <count; i++) { |
| 1869 | final View child = children[i]; |
| 1870 | child.dispatchSystemUiVisibilityChanged(visible); |
| 1871 | } |
| 1872 | } |
| 1873 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1874 | @Override |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 1875 | boolean updateLocalSystemUiVisibility(int localValue, int localChanges) { |
| 1876 | boolean changed = super.updateLocalSystemUiVisibility(localValue, localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1877 | |
| 1878 | final int count = mChildrenCount; |
| 1879 | final View[] children = mChildren; |
| 1880 | for (int i=0; i <count; i++) { |
| 1881 | final View child = children[i]; |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 1882 | changed |= child.updateLocalSystemUiVisibility(localValue, localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1883 | } |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 1884 | return changed; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1887 | @Override |
| 1888 | public boolean dispatchKeyEventPreIme(KeyEvent event) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1889 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1890 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | return super.dispatchKeyEventPreIme(event); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1892 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1893 | == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | return mFocused.dispatchKeyEventPreIme(event); |
| 1895 | } |
| 1896 | return false; |
| 1897 | } |
| 1898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | @Override |
| 1900 | public boolean dispatchKeyEvent(KeyEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1901 | if (mInputEventConsistencyVerifier != null) { |
| 1902 | mInputEventConsistencyVerifier.onKeyEvent(event, 1); |
| 1903 | } |
| 1904 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1905 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1906 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 1907 | if (super.dispatchKeyEvent(event)) { |
| 1908 | return true; |
| 1909 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1910 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1911 | == PFLAG_HAS_BOUNDS) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 1912 | if (mFocused.dispatchKeyEvent(event)) { |
| 1913 | return true; |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | if (mInputEventConsistencyVerifier != null) { |
| 1918 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | } |
| 1920 | return false; |
| 1921 | } |
| 1922 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | @Override |
| 1924 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1925 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1926 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | return super.dispatchKeyShortcutEvent(event); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1928 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1929 | == PFLAG_HAS_BOUNDS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | return mFocused.dispatchKeyShortcutEvent(event); |
| 1931 | } |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | @Override |
| 1936 | public boolean dispatchTrackballEvent(MotionEvent event) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1937 | if (mInputEventConsistencyVerifier != null) { |
| 1938 | mInputEventConsistencyVerifier.onTrackballEvent(event, 1); |
| 1939 | } |
| 1940 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1941 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1942 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 1943 | if (super.dispatchTrackballEvent(event)) { |
| 1944 | return true; |
| 1945 | } |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1946 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1947 | == PFLAG_HAS_BOUNDS) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 1948 | if (mFocused.dispatchTrackballEvent(event)) { |
| 1949 | return true; |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | if (mInputEventConsistencyVerifier != null) { |
| 1954 | mInputEventConsistencyVerifier.onUnhandledEvent(event, 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | } |
| 1956 | return false; |
| 1957 | } |
| 1958 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1959 | @Override |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 1960 | public boolean dispatchCapturedPointerEvent(MotionEvent event) { |
| 1961 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 1962 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
| 1963 | if (super.dispatchCapturedPointerEvent(event)) { |
| 1964 | return true; |
| 1965 | } |
| 1966 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 1967 | == PFLAG_HAS_BOUNDS) { |
| 1968 | if (mFocused.dispatchCapturedPointerEvent(event)) { |
| 1969 | return true; |
| 1970 | } |
| 1971 | } |
| 1972 | return false; |
| 1973 | } |
| 1974 | |
| 1975 | @Override |
| 1976 | public void dispatchPointerCaptureChanged(boolean hasCapture) { |
| 1977 | exitHoverTargets(); |
| 1978 | |
| 1979 | super.dispatchPointerCaptureChanged(hasCapture); |
| 1980 | final int count = mChildrenCount; |
| 1981 | final View[] children = mChildren; |
| 1982 | for (int i = 0; i < count; i++) { |
| 1983 | children[i].dispatchPointerCaptureChanged(hasCapture); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | @Override |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 1988 | public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) { |
| 1989 | final float x = event.getX(pointerIndex); |
| 1990 | final float y = event.getY(pointerIndex); |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 1991 | if (isOnScrollbarThumb(x, y) || isDraggingScrollBar()) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 1992 | return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_ARROW); |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 1993 | } |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 1994 | // Check what the child under the pointer says about the pointer. |
| 1995 | final int childrenCount = mChildrenCount; |
| 1996 | if (childrenCount != 0) { |
| 1997 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 1998 | final boolean customOrder = preorderedList == null |
| 1999 | && isChildrenDrawingOrderEnabled(); |
| 2000 | final View[] children = mChildren; |
| 2001 | for (int i = childrenCount - 1; i >= 0; i--) { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2002 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2003 | final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
Vladislav Kaznacheev | 3d5cfc0 | 2017-01-05 17:50:38 -0800 | [diff] [blame] | 2004 | if (!canViewReceivePointerEvents(child) |
| 2005 | || !isTransformedTouchPointInView(x, y, child, null)) { |
| 2006 | continue; |
| 2007 | } |
| 2008 | final PointerIcon pointerIcon = |
| 2009 | dispatchResolvePointerIcon(event, pointerIndex, child); |
| 2010 | if (pointerIcon != null) { |
| 2011 | if (preorderedList != null) preorderedList.clear(); |
| 2012 | return pointerIcon; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 2013 | } |
| 2014 | } |
Chris Craik | fc56377 | 2016-05-04 13:34:30 -0700 | [diff] [blame] | 2015 | if (preorderedList != null) preorderedList.clear(); |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | // The pointer is not a child or the child has no preferences, returning the default |
| 2019 | // implementation. |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 2020 | return super.onResolvePointerIcon(event, pointerIndex); |
| 2021 | } |
| 2022 | |
| 2023 | private PointerIcon dispatchResolvePointerIcon(MotionEvent event, int pointerIndex, |
| 2024 | View child) { |
| 2025 | final PointerIcon pointerIcon; |
| 2026 | if (!child.hasIdentityMatrix()) { |
| 2027 | MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
| 2028 | pointerIcon = child.onResolvePointerIcon(transformedEvent, pointerIndex); |
| 2029 | transformedEvent.recycle(); |
| 2030 | } else { |
| 2031 | final float offsetX = mScrollX - child.mLeft; |
| 2032 | final float offsetY = mScrollY - child.mTop; |
| 2033 | event.offsetLocation(offsetX, offsetY); |
| 2034 | pointerIcon = child.onResolvePointerIcon(event, pointerIndex); |
| 2035 | event.offsetLocation(-offsetX, -offsetY); |
| 2036 | } |
| 2037 | return pointerIcon; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2040 | private int getAndVerifyPreorderedIndex(int childrenCount, int i, boolean customOrder) { |
| 2041 | final int childIndex; |
| 2042 | if (customOrder) { |
| 2043 | final int childIndex1 = getChildDrawingOrder(childrenCount, i); |
| 2044 | if (childIndex1 >= childrenCount) { |
| 2045 | throw new IndexOutOfBoundsException("getChildDrawingOrder() " |
| 2046 | + "returned invalid index " + childIndex1 |
| 2047 | + " (child count is " + childrenCount + ")"); |
| 2048 | } |
| 2049 | childIndex = childIndex1; |
| 2050 | } else { |
| 2051 | childIndex = i; |
| 2052 | } |
| 2053 | return childIndex; |
| 2054 | } |
| 2055 | |
Romain Guy | a948927 | 2011-06-22 20:58:11 -0700 | [diff] [blame] | 2056 | @SuppressWarnings({"ConstantConditions"}) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | @Override |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2058 | protected boolean dispatchHoverEvent(MotionEvent event) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2059 | final int action = event.getAction(); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2060 | |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2061 | // First check whether the view group wants to intercept the hover event. |
| 2062 | final boolean interceptHover = onInterceptHoverEvent(event); |
| 2063 | event.setAction(action); // restore action in case it was changed |
| 2064 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2065 | MotionEvent eventNoHistory = event; |
| 2066 | boolean handled = false; |
| 2067 | |
| 2068 | // Send events to the hovered children and build a new list of hover targets until |
| 2069 | // one is found that handles the event. |
| 2070 | HoverTarget firstOldHoverTarget = mFirstHoverTarget; |
| 2071 | mFirstHoverTarget = null; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2072 | if (!interceptHover && action != MotionEvent.ACTION_HOVER_EXIT) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2073 | final float x = event.getX(); |
| 2074 | final float y = event.getY(); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2075 | final int childrenCount = mChildrenCount; |
| 2076 | if (childrenCount != 0) { |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2077 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2078 | final boolean customOrder = preorderedList == null |
| 2079 | && isChildrenDrawingOrderEnabled(); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2080 | final View[] children = mChildren; |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2081 | HoverTarget lastHoverTarget = null; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2082 | for (int i = childrenCount - 1; i >= 0; i--) { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2083 | final int childIndex = getAndVerifyPreorderedIndex( |
| 2084 | childrenCount, i, customOrder); |
| 2085 | final View child = getAndVerifyPreorderedView( |
| 2086 | preorderedList, children, childIndex); |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2087 | if (!canViewReceivePointerEvents(child) |
| 2088 | || !isTransformedTouchPointInView(x, y, child, null)) { |
| 2089 | continue; |
| 2090 | } |
| 2091 | |
| 2092 | // Obtain a hover target for this child. Dequeue it from the |
| 2093 | // old hover target list if the child was previously hovered. |
| 2094 | HoverTarget hoverTarget = firstOldHoverTarget; |
| 2095 | final boolean wasHovered; |
| 2096 | for (HoverTarget predecessor = null; ;) { |
| 2097 | if (hoverTarget == null) { |
| 2098 | hoverTarget = HoverTarget.obtain(child); |
| 2099 | wasHovered = false; |
| 2100 | break; |
| 2101 | } |
| 2102 | |
| 2103 | if (hoverTarget.child == child) { |
| 2104 | if (predecessor != null) { |
| 2105 | predecessor.next = hoverTarget.next; |
| 2106 | } else { |
| 2107 | firstOldHoverTarget = hoverTarget.next; |
| 2108 | } |
| 2109 | hoverTarget.next = null; |
| 2110 | wasHovered = true; |
| 2111 | break; |
| 2112 | } |
| 2113 | |
| 2114 | predecessor = hoverTarget; |
| 2115 | hoverTarget = hoverTarget.next; |
| 2116 | } |
| 2117 | |
| 2118 | // Enqueue the hover target onto the new hover target list. |
| 2119 | if (lastHoverTarget != null) { |
| 2120 | lastHoverTarget.next = hoverTarget; |
| 2121 | } else { |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2122 | mFirstHoverTarget = hoverTarget; |
| 2123 | } |
Sangkyu Lee | 8725f36 | 2013-03-13 09:38:45 +0900 | [diff] [blame] | 2124 | lastHoverTarget = hoverTarget; |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2125 | |
| 2126 | // Dispatch the event to the child. |
| 2127 | if (action == MotionEvent.ACTION_HOVER_ENTER) { |
| 2128 | if (!wasHovered) { |
| 2129 | // Send the enter as is. |
| 2130 | handled |= dispatchTransformedGenericPointerEvent( |
| 2131 | event, child); // enter |
| 2132 | } |
| 2133 | } else if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2134 | if (!wasHovered) { |
| 2135 | // Synthesize an enter from a move. |
| 2136 | eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2137 | eventNoHistory.setAction(MotionEvent.ACTION_HOVER_ENTER); |
| 2138 | handled |= dispatchTransformedGenericPointerEvent( |
| 2139 | eventNoHistory, child); // enter |
| 2140 | eventNoHistory.setAction(action); |
| 2141 | |
| 2142 | handled |= dispatchTransformedGenericPointerEvent( |
| 2143 | eventNoHistory, child); // move |
| 2144 | } else { |
| 2145 | // Send the move as is. |
| 2146 | handled |= dispatchTransformedGenericPointerEvent(event, child); |
| 2147 | } |
| 2148 | } |
| 2149 | if (handled) { |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2150 | break; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2151 | } |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2152 | } |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2153 | if (preorderedList != null) preorderedList.clear(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2154 | } |
| 2155 | } |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2156 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2157 | // Send exit events to all previously hovered children that are no longer hovered. |
| 2158 | while (firstOldHoverTarget != null) { |
| 2159 | final View child = firstOldHoverTarget.child; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2160 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2161 | // Exit the old hovered child. |
| 2162 | if (action == MotionEvent.ACTION_HOVER_EXIT) { |
| 2163 | // Send the exit as is. |
| 2164 | handled |= dispatchTransformedGenericPointerEvent( |
| 2165 | event, child); // exit |
| 2166 | } else { |
| 2167 | // Synthesize an exit from a move or enter. |
| 2168 | // Ignore the result because hover focus has moved to a different view. |
| 2169 | if (action == MotionEvent.ACTION_HOVER_MOVE) { |
Vladislav Kaznacheev | 5a77c37 | 2016-10-10 16:11:15 -0700 | [diff] [blame] | 2170 | final boolean hoverExitPending = event.isHoverExitPending(); |
| 2171 | event.setHoverExitPending(true); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2172 | dispatchTransformedGenericPointerEvent( |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2173 | event, child); // move |
Vladislav Kaznacheev | 5a77c37 | 2016-10-10 16:11:15 -0700 | [diff] [blame] | 2174 | event.setHoverExitPending(hoverExitPending); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2175 | } |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2176 | eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2177 | eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2178 | dispatchTransformedGenericPointerEvent( |
| 2179 | eventNoHistory, child); // exit |
| 2180 | eventNoHistory.setAction(action); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2183 | final HoverTarget nextOldHoverTarget = firstOldHoverTarget.next; |
| 2184 | firstOldHoverTarget.recycle(); |
| 2185 | firstOldHoverTarget = nextOldHoverTarget; |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Vladislav Kaznacheev | 5a77c37 | 2016-10-10 16:11:15 -0700 | [diff] [blame] | 2188 | // Send events to the view group itself if no children have handled it and the view group |
| 2189 | // itself is not currently being hover-exited. |
| 2190 | boolean newHoveredSelf = !handled && |
| 2191 | (action != MotionEvent.ACTION_HOVER_EXIT) && !event.isHoverExitPending(); |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2192 | if (newHoveredSelf == mHoveredSelf) { |
| 2193 | if (newHoveredSelf) { |
| 2194 | // Send event to the view group as before. |
| 2195 | handled |= super.dispatchHoverEvent(event); |
| 2196 | } |
| 2197 | } else { |
| 2198 | if (mHoveredSelf) { |
| 2199 | // Exit the view group. |
| 2200 | if (action == MotionEvent.ACTION_HOVER_EXIT) { |
| 2201 | // Send the exit as is. |
| 2202 | handled |= super.dispatchHoverEvent(event); // exit |
| 2203 | } else { |
| 2204 | // Synthesize an exit from a move or enter. |
| 2205 | // Ignore the result because hover focus is moving to a different view. |
| 2206 | if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2207 | super.dispatchHoverEvent(event); // move |
| 2208 | } |
| 2209 | eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2210 | eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2211 | super.dispatchHoverEvent(eventNoHistory); // exit |
| 2212 | eventNoHistory.setAction(action); |
| 2213 | } |
| 2214 | mHoveredSelf = false; |
| 2215 | } |
| 2216 | |
| 2217 | if (newHoveredSelf) { |
| 2218 | // Enter the view group. |
| 2219 | if (action == MotionEvent.ACTION_HOVER_ENTER) { |
| 2220 | // Send the enter as is. |
| 2221 | handled |= super.dispatchHoverEvent(event); // enter |
| 2222 | mHoveredSelf = true; |
| 2223 | } else if (action == MotionEvent.ACTION_HOVER_MOVE) { |
| 2224 | // Synthesize an enter from a move. |
| 2225 | eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory); |
| 2226 | eventNoHistory.setAction(MotionEvent.ACTION_HOVER_ENTER); |
| 2227 | handled |= super.dispatchHoverEvent(eventNoHistory); // enter |
| 2228 | eventNoHistory.setAction(action); |
| 2229 | |
| 2230 | handled |= super.dispatchHoverEvent(eventNoHistory); // move |
| 2231 | mHoveredSelf = true; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2232 | } |
| 2233 | } |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2234 | } |
| 2235 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2236 | // Recycle the copy of the event that we made. |
| 2237 | if (eventNoHistory != event) { |
| 2238 | eventNoHistory.recycle(); |
| 2239 | } |
| 2240 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2241 | // Done. |
| 2242 | return handled; |
| 2243 | } |
| 2244 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 2245 | private void exitHoverTargets() { |
| 2246 | if (mHoveredSelf || mFirstHoverTarget != null) { |
| 2247 | final long now = SystemClock.uptimeMillis(); |
| 2248 | MotionEvent event = MotionEvent.obtain(now, now, |
| 2249 | MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2250 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2251 | dispatchHoverEvent(event); |
| 2252 | event.recycle(); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | private void cancelHoverTarget(View view) { |
| 2257 | HoverTarget predecessor = null; |
| 2258 | HoverTarget target = mFirstHoverTarget; |
| 2259 | while (target != null) { |
| 2260 | final HoverTarget next = target.next; |
| 2261 | if (target.child == view) { |
| 2262 | if (predecessor == null) { |
| 2263 | mFirstHoverTarget = next; |
| 2264 | } else { |
| 2265 | predecessor.next = next; |
| 2266 | } |
| 2267 | target.recycle(); |
| 2268 | |
| 2269 | final long now = SystemClock.uptimeMillis(); |
| 2270 | MotionEvent event = MotionEvent.obtain(now, now, |
| 2271 | MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2272 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2273 | view.dispatchHoverEvent(event); |
| 2274 | event.recycle(); |
| 2275 | return; |
| 2276 | } |
| 2277 | predecessor = target; |
| 2278 | target = next; |
| 2279 | } |
| 2280 | } |
| 2281 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 2282 | @Override |
| 2283 | boolean dispatchTooltipHoverEvent(MotionEvent event) { |
| 2284 | final int action = event.getAction(); |
| 2285 | switch (action) { |
| 2286 | case MotionEvent.ACTION_HOVER_ENTER: |
| 2287 | break; |
| 2288 | |
| 2289 | case MotionEvent.ACTION_HOVER_MOVE: |
| 2290 | View newTarget = null; |
| 2291 | |
| 2292 | // Check what the child under the pointer says about the tooltip. |
| 2293 | final int childrenCount = mChildrenCount; |
| 2294 | if (childrenCount != 0) { |
| 2295 | final float x = event.getX(); |
| 2296 | final float y = event.getY(); |
| 2297 | |
| 2298 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2299 | final boolean customOrder = preorderedList == null |
| 2300 | && isChildrenDrawingOrderEnabled(); |
| 2301 | final View[] children = mChildren; |
| 2302 | for (int i = childrenCount - 1; i >= 0; i--) { |
| 2303 | final int childIndex = |
| 2304 | getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2305 | final View child = |
| 2306 | getAndVerifyPreorderedView(preorderedList, children, childIndex); |
Vladislav Kaznacheev | 943cf0e | 2017-01-06 09:52:51 -0800 | [diff] [blame] | 2307 | if (!canViewReceivePointerEvents(child) |
| 2308 | || !isTransformedTouchPointInView(x, y, child, null)) { |
| 2309 | continue; |
| 2310 | } |
| 2311 | if (dispatchTooltipHoverEvent(event, child)) { |
| 2312 | newTarget = child; |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 2313 | break; |
| 2314 | } |
| 2315 | } |
| 2316 | if (preorderedList != null) preorderedList.clear(); |
| 2317 | } |
| 2318 | |
| 2319 | if (mTooltipHoverTarget != newTarget) { |
| 2320 | if (mTooltipHoverTarget != null) { |
| 2321 | event.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2322 | mTooltipHoverTarget.dispatchTooltipHoverEvent(event); |
| 2323 | event.setAction(action); |
| 2324 | } |
| 2325 | mTooltipHoverTarget = newTarget; |
| 2326 | } |
| 2327 | |
| 2328 | if (mTooltipHoverTarget != null) { |
| 2329 | if (mTooltipHoveredSelf) { |
| 2330 | mTooltipHoveredSelf = false; |
| 2331 | event.setAction(MotionEvent.ACTION_HOVER_EXIT); |
| 2332 | super.dispatchTooltipHoverEvent(event); |
| 2333 | event.setAction(action); |
| 2334 | } |
| 2335 | return true; |
| 2336 | } |
| 2337 | |
| 2338 | mTooltipHoveredSelf = super.dispatchTooltipHoverEvent(event); |
| 2339 | return mTooltipHoveredSelf; |
| 2340 | |
| 2341 | case MotionEvent.ACTION_HOVER_EXIT: |
| 2342 | if (mTooltipHoverTarget != null) { |
| 2343 | mTooltipHoverTarget.dispatchTooltipHoverEvent(event); |
| 2344 | mTooltipHoverTarget = null; |
| 2345 | } else if (mTooltipHoveredSelf) { |
| 2346 | super.dispatchTooltipHoverEvent(event); |
| 2347 | mTooltipHoveredSelf = false; |
| 2348 | } |
| 2349 | break; |
| 2350 | } |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | private boolean dispatchTooltipHoverEvent(MotionEvent event, View child) { |
| 2355 | final boolean result; |
| 2356 | if (!child.hasIdentityMatrix()) { |
| 2357 | MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
| 2358 | result = child.dispatchTooltipHoverEvent(transformedEvent); |
| 2359 | transformedEvent.recycle(); |
| 2360 | } else { |
| 2361 | final float offsetX = mScrollX - child.mLeft; |
| 2362 | final float offsetY = mScrollY - child.mTop; |
| 2363 | event.offsetLocation(offsetX, offsetY); |
| 2364 | result = child.dispatchTooltipHoverEvent(event); |
| 2365 | event.offsetLocation(-offsetX, -offsetY); |
| 2366 | } |
| 2367 | return result; |
| 2368 | } |
| 2369 | |
| 2370 | private void exitTooltipHoverTargets() { |
| 2371 | if (mTooltipHoveredSelf || mTooltipHoverTarget != null) { |
| 2372 | final long now = SystemClock.uptimeMillis(); |
| 2373 | MotionEvent event = MotionEvent.obtain(now, now, |
| 2374 | MotionEvent.ACTION_HOVER_EXIT, 0.0f, 0.0f, 0); |
| 2375 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2376 | dispatchTooltipHoverEvent(event); |
| 2377 | event.recycle(); |
| 2378 | } |
| 2379 | } |
| 2380 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 2381 | /** @hide */ |
| 2382 | @Override |
| 2383 | protected boolean hasHoveredChild() { |
| 2384 | return mFirstHoverTarget != null; |
| 2385 | } |
| 2386 | |
Dieter Hsu | fa1b8de | 2018-08-22 10:35:58 +0800 | [diff] [blame] | 2387 | /** @hide */ |
| 2388 | @Override |
| 2389 | protected boolean pointInHoveredChild(MotionEvent event) { |
| 2390 | if (mFirstHoverTarget != null) { |
| 2391 | return isTransformedTouchPointInView(event.getX(), event.getY(), |
| 2392 | mFirstHoverTarget.child, null); |
| 2393 | } |
| 2394 | return false; |
| 2395 | } |
| 2396 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2397 | @Override |
Adam Powell | cf392d1 | 2015-06-25 14:48:45 -0700 | [diff] [blame] | 2398 | public void addChildrenForAccessibility(ArrayList<View> outChildren) { |
Svetoslav | 762621c | 2015-06-01 17:21:59 -0700 | [diff] [blame] | 2399 | if (getAccessibilityNodeProvider() != null) { |
| 2400 | return; |
| 2401 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2402 | ChildListForAccessibility children = ChildListForAccessibility.obtain(this, true); |
| 2403 | try { |
| 2404 | final int childrenCount = children.getChildCount(); |
| 2405 | for (int i = 0; i < childrenCount; i++) { |
| 2406 | View child = children.getChildAt(i); |
Svetoslav Ganov | c406be9 | 2012-05-11 16:12:32 -0700 | [diff] [blame] | 2407 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2408 | if (child.includeForAccessibility()) { |
Adam Powell | cf392d1 | 2015-06-25 14:48:45 -0700 | [diff] [blame] | 2409 | outChildren.add(child); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2410 | } else { |
Adam Powell | cf392d1 | 2015-06-25 14:48:45 -0700 | [diff] [blame] | 2411 | child.addChildrenForAccessibility(outChildren); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2412 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2413 | } |
| 2414 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 2415 | } finally { |
| 2416 | children.recycle(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | /** |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2421 | * Implement this method to intercept hover events before they are handled |
| 2422 | * by child views. |
| 2423 | * <p> |
| 2424 | * This method is called before dispatching a hover event to a child of |
| 2425 | * the view group or to the view group's own {@link #onHoverEvent} to allow |
| 2426 | * the view group a chance to intercept the hover event. |
| 2427 | * This method can also be used to watch all pointer motions that occur within |
| 2428 | * the bounds of the view group even when the pointer is hovering over |
| 2429 | * a child of the view group rather than over the view group itself. |
| 2430 | * </p><p> |
| 2431 | * The view group can prevent its children from receiving hover events by |
| 2432 | * implementing this method and returning <code>true</code> to indicate |
| 2433 | * that it would like to intercept hover events. The view group must |
| 2434 | * continuously return <code>true</code> from {@link #onInterceptHoverEvent} |
| 2435 | * for as long as it wishes to continue intercepting hover events from |
| 2436 | * its children. |
| 2437 | * </p><p> |
| 2438 | * Interception preserves the invariant that at most one view can be |
| 2439 | * hovered at a time by transferring hover focus from the currently hovered |
| 2440 | * child to the view group or vice-versa as needed. |
| 2441 | * </p><p> |
| 2442 | * If this method returns <code>true</code> and a child is already hovered, then the |
| 2443 | * child view will first receive a hover exit event and then the view group |
| 2444 | * itself will receive a hover enter event in {@link #onHoverEvent}. |
| 2445 | * Likewise, if this method had previously returned <code>true</code> to intercept hover |
| 2446 | * events and instead returns <code>false</code> while the pointer is hovering |
| 2447 | * within the bounds of one of a child, then the view group will first receive a |
| 2448 | * hover exit event in {@link #onHoverEvent} and then the hovered child will |
| 2449 | * receive a hover enter event. |
| 2450 | * </p><p> |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 2451 | * The default implementation handles mouse hover on the scroll bars. |
Jeff Brown | 10b6290 | 2011-06-20 16:40:37 -0700 | [diff] [blame] | 2452 | * </p> |
| 2453 | * |
| 2454 | * @param event The motion event that describes the hover. |
| 2455 | * @return True if the view group would like to intercept the hover event |
| 2456 | * and prevent its children from receiving it. |
| 2457 | */ |
| 2458 | public boolean onInterceptHoverEvent(MotionEvent event) { |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 2459 | if (event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 2460 | final int action = event.getAction(); |
| 2461 | final float x = event.getX(); |
| 2462 | final float y = event.getY(); |
| 2463 | if ((action == MotionEvent.ACTION_HOVER_MOVE |
| 2464 | || action == MotionEvent.ACTION_HOVER_ENTER) && isOnScrollbar(x, y)) { |
| 2465 | return true; |
| 2466 | } |
| 2467 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 2468 | return false; |
| 2469 | } |
| 2470 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2471 | private static MotionEvent obtainMotionEventNoHistoryOrSelf(MotionEvent event) { |
| 2472 | if (event.getHistorySize() == 0) { |
| 2473 | return event; |
| 2474 | } |
| 2475 | return MotionEvent.obtainNoHistory(event); |
| 2476 | } |
| 2477 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2478 | @Override |
| 2479 | protected boolean dispatchGenericPointerEvent(MotionEvent event) { |
| 2480 | // Send the event to the child under the pointer. |
| 2481 | final int childrenCount = mChildrenCount; |
| 2482 | if (childrenCount != 0) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2483 | final float x = event.getX(); |
| 2484 | final float y = event.getY(); |
| 2485 | |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2486 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 2487 | final boolean customOrder = preorderedList == null |
| 2488 | && isChildrenDrawingOrderEnabled(); |
| 2489 | final View[] children = mChildren; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2490 | for (int i = childrenCount - 1; i >= 0; i--) { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2491 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 2492 | final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2493 | if (!canViewReceivePointerEvents(child) |
| 2494 | || !isTransformedTouchPointInView(x, y, child, null)) { |
| 2495 | continue; |
| 2496 | } |
| 2497 | |
| 2498 | if (dispatchTransformedGenericPointerEvent(event, child)) { |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2499 | if (preorderedList != null) preorderedList.clear(); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2500 | return true; |
| 2501 | } |
| 2502 | } |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2503 | if (preorderedList != null) preorderedList.clear(); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | // No child handled the event. Send it to this view group. |
| 2507 | return super.dispatchGenericPointerEvent(event); |
| 2508 | } |
| 2509 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2510 | @Override |
| 2511 | protected boolean dispatchGenericFocusedEvent(MotionEvent event) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2512 | // Send the event to the focused child or to this view group if it has focus. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2513 | if ((mPrivateFlags & (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) |
| 2514 | == (PFLAG_FOCUSED | PFLAG_HAS_BOUNDS)) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2515 | return super.dispatchGenericFocusedEvent(event); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2516 | } else if (mFocused != null && (mFocused.mPrivateFlags & PFLAG_HAS_BOUNDS) |
| 2517 | == PFLAG_HAS_BOUNDS) { |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2518 | return mFocused.dispatchGenericMotionEvent(event); |
| 2519 | } |
| 2520 | return false; |
| 2521 | } |
| 2522 | |
| 2523 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2524 | * Dispatches a generic pointer event to a child, taking into account |
| 2525 | * transformations that apply to the child. |
| 2526 | * |
| 2527 | * @param event The event to send. |
| 2528 | * @param child The view to send the event to. |
| 2529 | * @return {@code true} if the child handled the event. |
| 2530 | */ |
| 2531 | private boolean dispatchTransformedGenericPointerEvent(MotionEvent event, View child) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2532 | boolean handled; |
| 2533 | if (!child.hasIdentityMatrix()) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 2534 | MotionEvent transformedEvent = getTransformedMotionEvent(event, child); |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2535 | handled = child.dispatchGenericMotionEvent(transformedEvent); |
| 2536 | transformedEvent.recycle(); |
| 2537 | } else { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 2538 | final float offsetX = mScrollX - child.mLeft; |
| 2539 | final float offsetY = mScrollY - child.mTop; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2540 | event.offsetLocation(offsetX, offsetY); |
| 2541 | handled = child.dispatchGenericMotionEvent(event); |
| 2542 | event.offsetLocation(-offsetX, -offsetY); |
| 2543 | } |
| 2544 | return handled; |
| 2545 | } |
| 2546 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 2547 | /** |
| 2548 | * Returns a MotionEvent that's been transformed into the child's local coordinates. |
| 2549 | * |
| 2550 | * It's the responsibility of the caller to recycle it once they're finished with it. |
| 2551 | * @param event The event to transform. |
| 2552 | * @param child The view whose coordinate space is to be used. |
| 2553 | * @return A copy of the the given MotionEvent, transformed into the given View's coordinate |
| 2554 | * space. |
| 2555 | */ |
| 2556 | private MotionEvent getTransformedMotionEvent(MotionEvent event, View child) { |
| 2557 | final float offsetX = mScrollX - child.mLeft; |
| 2558 | final float offsetY = mScrollY - child.mTop; |
| 2559 | final MotionEvent transformedEvent = MotionEvent.obtain(event); |
| 2560 | transformedEvent.offsetLocation(offsetX, offsetY); |
| 2561 | if (!child.hasIdentityMatrix()) { |
| 2562 | transformedEvent.transform(child.getInverseMatrix()); |
| 2563 | } |
| 2564 | return transformedEvent; |
| 2565 | } |
| 2566 | |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 2567 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 2569 | if (mInputEventConsistencyVerifier != null) { |
| 2570 | mInputEventConsistencyVerifier.onTouchEvent(ev, 1); |
| 2571 | } |
| 2572 | |
Svet Ganov | 0a2ccee | 2015-02-06 10:12:32 -0800 | [diff] [blame] | 2573 | // If the event targets the accessibility focused view and this is it, start |
| 2574 | // normal event dispatch. Maybe a descendant is what will handle the click. |
Svet Ganov | f33fe1f | 2015-02-06 19:23:31 -0800 | [diff] [blame] | 2575 | if (ev.isTargetAccessibilityFocus() && isAccessibilityFocusedViewOrHost()) { |
Svet Ganov | 0a2ccee | 2015-02-06 10:12:32 -0800 | [diff] [blame] | 2576 | ev.setTargetAccessibilityFocus(false); |
| 2577 | } |
| 2578 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2579 | boolean handled = false; |
| 2580 | if (onFilterTouchEventForSecurity(ev)) { |
| 2581 | final int action = ev.getAction(); |
| 2582 | final int actionMasked = action & MotionEvent.ACTION_MASK; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2583 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2584 | // Handle an initial down. |
| 2585 | if (actionMasked == MotionEvent.ACTION_DOWN) { |
| 2586 | // Throw away all previous state when starting a new touch gesture. |
| 2587 | // The framework may have dropped the up or cancel event for the previous gesture |
| 2588 | // due to an app switch, ANR, or some other state change. |
| 2589 | cancelAndClearTouchTargets(ev); |
| 2590 | resetTouchState(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2591 | } |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 2592 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2593 | // Check for interception. |
| 2594 | final boolean intercepted; |
Svet Ganov | f33fe1f | 2015-02-06 19:23:31 -0800 | [diff] [blame] | 2595 | if (actionMasked == MotionEvent.ACTION_DOWN |
| 2596 | || mFirstTouchTarget != null) { |
| 2597 | final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0; |
| 2598 | if (!disallowIntercept) { |
| 2599 | intercepted = onInterceptTouchEvent(ev); |
| 2600 | ev.setAction(action); // restore action in case it was changed |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2601 | } else { |
Svet Ganov | f33fe1f | 2015-02-06 19:23:31 -0800 | [diff] [blame] | 2602 | intercepted = false; |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2603 | } |
| 2604 | } else { |
Svet Ganov | f33fe1f | 2015-02-06 19:23:31 -0800 | [diff] [blame] | 2605 | // There are no touch targets and this action is not an initial down |
| 2606 | // so this view group continues to intercept touches. |
| 2607 | intercepted = true; |
| 2608 | } |
| 2609 | |
| 2610 | // If intercepted, start normal event dispatch. Also if there is already |
| 2611 | // a view that is handling the gesture, do normal event dispatch. |
| 2612 | if (intercepted || mFirstTouchTarget != null) { |
| 2613 | ev.setTargetAccessibilityFocus(false); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2614 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2615 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2616 | // Check for cancelation. |
| 2617 | final boolean canceled = resetCancelNextUpFlag(this) |
| 2618 | || actionMasked == MotionEvent.ACTION_CANCEL; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2619 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2620 | // Update list of touch targets for pointer down, if needed. |
| 2621 | final boolean split = (mGroupFlags & FLAG_SPLIT_MOTION_EVENTS) != 0; |
| 2622 | TouchTarget newTouchTarget = null; |
| 2623 | boolean alreadyDispatchedToNewTouchTarget = false; |
| 2624 | if (!canceled && !intercepted) { |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2625 | |
Phil Weaver | 1e6ecc6 | 2017-11-07 15:28:21 -0800 | [diff] [blame] | 2626 | // If the event is targeting accessibility focus we give it to the |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2627 | // view that has accessibility focus and if it does not handle it |
| 2628 | // we clear the flag and dispatch the event to all children as usual. |
| 2629 | // We are looking up the accessibility focused host to avoid keeping |
| 2630 | // state since these events are very rare. |
| 2631 | View childWithAccessibilityFocus = ev.isTargetAccessibilityFocus() |
| 2632 | ? findChildWithAccessibilityFocus() : null; |
| 2633 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2634 | if (actionMasked == MotionEvent.ACTION_DOWN |
| 2635 | || (split && actionMasked == MotionEvent.ACTION_POINTER_DOWN) |
Svet Ganov | f33fe1f | 2015-02-06 19:23:31 -0800 | [diff] [blame] | 2636 | || actionMasked == MotionEvent.ACTION_HOVER_MOVE) { |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2637 | final int actionIndex = ev.getActionIndex(); // always 0 for down |
| 2638 | final int idBitsToAssign = split ? 1 << ev.getPointerId(actionIndex) |
| 2639 | : TouchTarget.ALL_POINTER_IDS; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2640 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2641 | // Clean up earlier touch targets for this pointer id in case they |
| 2642 | // have become out of sync. |
| 2643 | removePointersFromTouchTargets(idBitsToAssign); |
| 2644 | |
| 2645 | final int childrenCount = mChildrenCount; |
Chet Haase | 9c17fe6 | 2013-03-22 17:05:55 -0700 | [diff] [blame] | 2646 | if (newTouchTarget == null && childrenCount != 0) { |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 2647 | final float x = ev.getX(actionIndex); |
| 2648 | final float y = ev.getY(actionIndex); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2649 | // Find a child that can receive the event. |
| 2650 | // Scan children from front to back. |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 2651 | final ArrayList<View> preorderedList = buildTouchDispatchChildList(); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2652 | final boolean customOrder = preorderedList == null |
| 2653 | && isChildrenDrawingOrderEnabled(); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2654 | final View[] children = mChildren; |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2655 | for (int i = childrenCount - 1; i >= 0; i--) { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2656 | final int childIndex = getAndVerifyPreorderedIndex( |
| 2657 | childrenCount, i, customOrder); |
| 2658 | final View child = getAndVerifyPreorderedView( |
| 2659 | preorderedList, children, childIndex); |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2660 | |
| 2661 | // If there is a view that has accessibility focus we want it |
| 2662 | // to get the event first and if not handled we will perform a |
| 2663 | // normal dispatch. We may do a double iteration but this is |
| 2664 | // safer given the timeframe. |
| 2665 | if (childWithAccessibilityFocus != null) { |
| 2666 | if (childWithAccessibilityFocus != child) { |
| 2667 | continue; |
| 2668 | } |
| 2669 | childWithAccessibilityFocus = null; |
| 2670 | i = childrenCount - 1; |
| 2671 | } |
| 2672 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2673 | if (!canViewReceivePointerEvents(child) |
| 2674 | || !isTransformedTouchPointInView(x, y, child, null)) { |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2675 | ev.setTargetAccessibilityFocus(false); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2676 | continue; |
| 2677 | } |
| 2678 | |
| 2679 | newTouchTarget = getTouchTarget(child); |
| 2680 | if (newTouchTarget != null) { |
| 2681 | // Child is already receiving touch within its bounds. |
| 2682 | // Give it the new pointer in addition to the ones it is handling. |
| 2683 | newTouchTarget.pointerIdBits |= idBitsToAssign; |
| 2684 | break; |
| 2685 | } |
| 2686 | |
| 2687 | resetCancelNextUpFlag(child); |
| 2688 | if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) { |
| 2689 | // Child wants to receive touch within its bounds. |
| 2690 | mLastTouchDownTime = ev.getDownTime(); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2691 | if (preorderedList != null) { |
| 2692 | // childIndex points into presorted list, find original index |
| 2693 | for (int j = 0; j < childrenCount; j++) { |
| 2694 | if (children[childIndex] == mChildren[j]) { |
| 2695 | mLastTouchDownIndex = j; |
| 2696 | break; |
| 2697 | } |
| 2698 | } |
| 2699 | } else { |
| 2700 | mLastTouchDownIndex = childIndex; |
| 2701 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2702 | mLastTouchDownX = ev.getX(); |
| 2703 | mLastTouchDownY = ev.getY(); |
| 2704 | newTouchTarget = addTouchTarget(child, idBitsToAssign); |
| 2705 | alreadyDispatchedToNewTouchTarget = true; |
| 2706 | break; |
| 2707 | } |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2708 | |
| 2709 | // The accessibility focus didn't handle the event, so clear |
| 2710 | // the flag and do a normal dispatch to all children. |
| 2711 | ev.setTargetAccessibilityFocus(false); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2712 | } |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 2713 | if (preorderedList != null) preorderedList.clear(); |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | if (newTouchTarget == null && mFirstTouchTarget != null) { |
| 2717 | // Did not find a child to receive the event. |
| 2718 | // Assign the pointer to the least recently added target. |
| 2719 | newTouchTarget = mFirstTouchTarget; |
| 2720 | while (newTouchTarget.next != null) { |
| 2721 | newTouchTarget = newTouchTarget.next; |
| 2722 | } |
| 2723 | newTouchTarget.pointerIdBits |= idBitsToAssign; |
| 2724 | } |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | // Dispatch to touch targets. |
| 2729 | if (mFirstTouchTarget == null) { |
| 2730 | // No touch targets so treat this as an ordinary view. |
| 2731 | handled = dispatchTransformedTouchEvent(ev, canceled, null, |
| 2732 | TouchTarget.ALL_POINTER_IDS); |
| 2733 | } else { |
| 2734 | // Dispatch to touch targets, excluding the new touch target if we already |
| 2735 | // dispatched to it. Cancel touch targets if necessary. |
| 2736 | TouchTarget predecessor = null; |
| 2737 | TouchTarget target = mFirstTouchTarget; |
| 2738 | while (target != null) { |
| 2739 | final TouchTarget next = target.next; |
| 2740 | if (alreadyDispatchedToNewTouchTarget && target == newTouchTarget) { |
| 2741 | handled = true; |
| 2742 | } else { |
| 2743 | final boolean cancelChild = resetCancelNextUpFlag(target.child) |
Chet Haase | 9c17fe6 | 2013-03-22 17:05:55 -0700 | [diff] [blame] | 2744 | || intercepted; |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2745 | if (dispatchTransformedTouchEvent(ev, cancelChild, |
| 2746 | target.child, target.pointerIdBits)) { |
| 2747 | handled = true; |
| 2748 | } |
| 2749 | if (cancelChild) { |
| 2750 | if (predecessor == null) { |
| 2751 | mFirstTouchTarget = next; |
| 2752 | } else { |
| 2753 | predecessor.next = next; |
| 2754 | } |
| 2755 | target.recycle(); |
| 2756 | target = next; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2757 | continue; |
| 2758 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2759 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2760 | predecessor = target; |
| 2761 | target = next; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | } |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2763 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2764 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2765 | // Update list of touch targets for pointer up or cancel, if needed. |
| 2766 | if (canceled |
| 2767 | || actionMasked == MotionEvent.ACTION_UP |
| 2768 | || actionMasked == MotionEvent.ACTION_HOVER_MOVE) { |
| 2769 | resetTouchState(); |
| 2770 | } else if (split && actionMasked == MotionEvent.ACTION_POINTER_UP) { |
| 2771 | final int actionIndex = ev.getActionIndex(); |
| 2772 | final int idBitsToRemove = 1 << ev.getPointerId(actionIndex); |
| 2773 | removePointersFromTouchTargets(idBitsToRemove); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | } |
| 2775 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2776 | |
Jeff Brown | bbdc50b | 2011-04-19 23:46:52 -0700 | [diff] [blame] | 2777 | if (!handled && mInputEventConsistencyVerifier != null) { |
| 2778 | mInputEventConsistencyVerifier.onUnhandledEvent(ev, 1); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2779 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2780 | return handled; |
| 2781 | } |
| 2782 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2783 | /** |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 2784 | * Provide custom ordering of views in which the touch will be dispatched. |
| 2785 | * |
| 2786 | * This is called within a tight loop, so you are not allowed to allocate objects, including |
| 2787 | * the return array. Instead, you should return a pre-allocated list that will be cleared |
| 2788 | * after the dispatch is finished. |
| 2789 | * @hide |
| 2790 | */ |
| 2791 | public ArrayList<View> buildTouchDispatchChildList() { |
| 2792 | return buildOrderedChildList(); |
| 2793 | } |
| 2794 | |
| 2795 | /** |
Svetoslav | c73cfa0 | 2015-02-09 17:14:28 -0800 | [diff] [blame] | 2796 | * Finds the child which has accessibility focus. |
| 2797 | * |
| 2798 | * @return The child that has focus. |
| 2799 | */ |
| 2800 | private View findChildWithAccessibilityFocus() { |
| 2801 | ViewRootImpl viewRoot = getViewRootImpl(); |
| 2802 | if (viewRoot == null) { |
| 2803 | return null; |
| 2804 | } |
| 2805 | |
| 2806 | View current = viewRoot.getAccessibilityFocusedHost(); |
| 2807 | if (current == null) { |
| 2808 | return null; |
| 2809 | } |
| 2810 | |
| 2811 | ViewParent parent = current.getParent(); |
| 2812 | while (parent instanceof View) { |
| 2813 | if (parent == this) { |
| 2814 | return current; |
| 2815 | } |
| 2816 | current = (View) parent; |
| 2817 | parent = current.getParent(); |
| 2818 | } |
| 2819 | |
| 2820 | return null; |
| 2821 | } |
| 2822 | |
| 2823 | /** |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2824 | * Resets all touch state in preparation for a new cycle. |
| 2825 | */ |
| 2826 | private void resetTouchState() { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2827 | clearTouchTargets(); |
| 2828 | resetCancelNextUpFlag(this); |
| 2829 | mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT; |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 2830 | mNestedScrollAxes = SCROLL_AXIS_NONE; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2833 | /** |
| 2834 | * Resets the cancel next up flag. |
| 2835 | * Returns true if the flag was previously set. |
| 2836 | */ |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2837 | private static boolean resetCancelNextUpFlag(@NonNull View view) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2838 | if ((view.mPrivateFlags & PFLAG_CANCEL_NEXT_UP_EVENT) != 0) { |
| 2839 | view.mPrivateFlags &= ~PFLAG_CANCEL_NEXT_UP_EVENT; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2840 | return true; |
Adam Cohen | 9b07394 | 2010-08-19 16:49:52 -0700 | [diff] [blame] | 2841 | } |
| 2842 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2845 | /** |
| 2846 | * Clears all touch targets. |
| 2847 | */ |
| 2848 | private void clearTouchTargets() { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2849 | TouchTarget target = mFirstTouchTarget; |
| 2850 | if (target != null) { |
| 2851 | do { |
| 2852 | TouchTarget next = target.next; |
| 2853 | target.recycle(); |
| 2854 | target = next; |
| 2855 | } while (target != null); |
| 2856 | mFirstTouchTarget = null; |
| 2857 | } |
| 2858 | } |
| 2859 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2860 | /** |
| 2861 | * Cancels and clears all touch targets. |
| 2862 | */ |
| 2863 | private void cancelAndClearTouchTargets(MotionEvent event) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2864 | if (mFirstTouchTarget != null) { |
| 2865 | boolean syntheticEvent = false; |
| 2866 | if (event == null) { |
| 2867 | final long now = SystemClock.uptimeMillis(); |
| 2868 | event = MotionEvent.obtain(now, now, |
| 2869 | MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
Jeff Brown | 2fdbc5a | 2011-06-30 12:25:54 -0700 | [diff] [blame] | 2870 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2871 | syntheticEvent = true; |
| 2872 | } |
| 2873 | |
| 2874 | for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) { |
| 2875 | resetCancelNextUpFlag(target.child); |
| 2876 | dispatchTransformedTouchEvent(event, true, target.child, target.pointerIdBits); |
| 2877 | } |
| 2878 | clearTouchTargets(); |
| 2879 | |
| 2880 | if (syntheticEvent) { |
| 2881 | event.recycle(); |
| 2882 | } |
| 2883 | } |
| 2884 | } |
| 2885 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2886 | /** |
| 2887 | * Gets the touch target for specified child view. |
| 2888 | * Returns null if not found. |
| 2889 | */ |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2890 | private TouchTarget getTouchTarget(@NonNull View child) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2891 | for (TouchTarget target = mFirstTouchTarget; target != null; target = target.next) { |
| 2892 | if (target.child == child) { |
| 2893 | return target; |
| 2894 | } |
| 2895 | } |
| 2896 | return null; |
| 2897 | } |
| 2898 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2899 | /** |
| 2900 | * Adds a touch target for specified child to the beginning of the list. |
| 2901 | * Assumes the target child is not already present. |
| 2902 | */ |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2903 | private TouchTarget addTouchTarget(@NonNull View child, int pointerIdBits) { |
| 2904 | final TouchTarget target = TouchTarget.obtain(child, pointerIdBits); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2905 | target.next = mFirstTouchTarget; |
| 2906 | mFirstTouchTarget = target; |
| 2907 | return target; |
| 2908 | } |
| 2909 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2910 | /** |
| 2911 | * Removes the pointer ids from consideration. |
| 2912 | */ |
| 2913 | private void removePointersFromTouchTargets(int pointerIdBits) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2914 | TouchTarget predecessor = null; |
| 2915 | TouchTarget target = mFirstTouchTarget; |
| 2916 | while (target != null) { |
| 2917 | final TouchTarget next = target.next; |
| 2918 | if ((target.pointerIdBits & pointerIdBits) != 0) { |
| 2919 | target.pointerIdBits &= ~pointerIdBits; |
| 2920 | if (target.pointerIdBits == 0) { |
| 2921 | if (predecessor == null) { |
| 2922 | mFirstTouchTarget = next; |
| 2923 | } else { |
| 2924 | predecessor.next = next; |
| 2925 | } |
| 2926 | target.recycle(); |
| 2927 | target = next; |
| 2928 | continue; |
| 2929 | } |
| 2930 | } |
| 2931 | predecessor = target; |
| 2932 | target = next; |
| 2933 | } |
| 2934 | } |
| 2935 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2936 | @UnsupportedAppUsage |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 2937 | private void cancelTouchTarget(View view) { |
| 2938 | TouchTarget predecessor = null; |
| 2939 | TouchTarget target = mFirstTouchTarget; |
| 2940 | while (target != null) { |
| 2941 | final TouchTarget next = target.next; |
| 2942 | if (target.child == view) { |
| 2943 | if (predecessor == null) { |
| 2944 | mFirstTouchTarget = next; |
| 2945 | } else { |
| 2946 | predecessor.next = next; |
| 2947 | } |
| 2948 | target.recycle(); |
| 2949 | |
| 2950 | final long now = SystemClock.uptimeMillis(); |
| 2951 | MotionEvent event = MotionEvent.obtain(now, now, |
| 2952 | MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); |
| 2953 | event.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 2954 | view.dispatchTouchEvent(event); |
| 2955 | event.recycle(); |
| 2956 | return; |
| 2957 | } |
| 2958 | predecessor = target; |
| 2959 | target = next; |
| 2960 | } |
| 2961 | } |
| 2962 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2963 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2964 | * Returns true if a child view can receive pointer events. |
| 2965 | * @hide |
| 2966 | */ |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 2967 | private static boolean canViewReceivePointerEvents(@NonNull View child) { |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2968 | return (child.mViewFlags & VISIBILITY_MASK) == VISIBLE |
| 2969 | || child.getAnimation() != null; |
| 2970 | } |
| 2971 | |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 2972 | private float[] getTempPoint() { |
| 2973 | if (mTempPoint == null) { |
| 2974 | mTempPoint = new float[2]; |
| 2975 | } |
| 2976 | return mTempPoint; |
| 2977 | } |
| 2978 | |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2979 | /** |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2980 | * Returns true if a child view contains the specified point when transformed |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2981 | * into its coordinate space. |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2982 | * Child must not be null. |
Adam Cohen | a32edd4 | 2010-10-26 10:35:01 -0700 | [diff] [blame] | 2983 | * @hide |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2984 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2985 | @UnsupportedAppUsage |
Adam Cohen | a32edd4 | 2010-10-26 10:35:01 -0700 | [diff] [blame] | 2986 | protected boolean isTransformedTouchPointInView(float x, float y, View child, |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 2987 | PointF outLocalPoint) { |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 2988 | final float[] point = getTempPoint(); |
| 2989 | point[0] = x; |
| 2990 | point[1] = y; |
| 2991 | transformPointToViewLocal(point, child); |
| 2992 | final boolean isInView = child.pointInView(point[0], point[1]); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 2993 | if (isInView && outLocalPoint != null) { |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 2994 | outLocalPoint.set(point[0], point[1]); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 2995 | } |
| 2996 | return isInView; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 2999 | /** |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 3000 | * @hide |
| 3001 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 3002 | @UnsupportedAppUsage |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 3003 | public void transformPointToViewLocal(float[] point, View child) { |
| 3004 | point[0] += mScrollX - child.mLeft; |
| 3005 | point[1] += mScrollY - child.mTop; |
| 3006 | |
| 3007 | if (!child.hasIdentityMatrix()) { |
| 3008 | child.getInverseMatrix().mapPoints(point); |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | /** |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 3013 | * Transforms a motion event into the coordinate space of a particular child view, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3014 | * filters out irrelevant pointer ids, and overrides its action if necessary. |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 3015 | * If child is null, assumes the MotionEvent will be sent to this ViewGroup instead. |
| 3016 | */ |
| 3017 | private boolean dispatchTransformedTouchEvent(MotionEvent event, boolean cancel, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3018 | View child, int desiredPointerIdBits) { |
| 3019 | final boolean handled; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3020 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3021 | // Canceling motions is a special case. We don't need to perform any transformations |
| 3022 | // or filtering. The important part is the action, not the contents. |
| 3023 | final int oldAction = event.getAction(); |
| 3024 | if (cancel || oldAction == MotionEvent.ACTION_CANCEL) { |
| 3025 | event.setAction(MotionEvent.ACTION_CANCEL); |
| 3026 | if (child == null) { |
| 3027 | handled = super.dispatchTouchEvent(event); |
| 3028 | } else { |
| 3029 | handled = child.dispatchTouchEvent(event); |
| 3030 | } |
| 3031 | event.setAction(oldAction); |
| 3032 | return handled; |
| 3033 | } |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3034 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3035 | // Calculate the number of pointers to deliver. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3036 | final int oldPointerIdBits = event.getPointerIdBits(); |
| 3037 | final int newPointerIdBits = oldPointerIdBits & desiredPointerIdBits; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3038 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3039 | // If for some reason we ended up in an inconsistent state where it looks like we |
| 3040 | // might produce a motion event with no pointers in it, then drop the event. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3041 | if (newPointerIdBits == 0) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3042 | return false; |
| 3043 | } |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3044 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3045 | // If the number of pointers is the same and we don't need to perform any fancy |
| 3046 | // irreversible transformations, then we can reuse the motion event for this |
| 3047 | // dispatch as long as we are careful to revert any changes we make. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3048 | // Otherwise we need to make a copy. |
| 3049 | final MotionEvent transformedEvent; |
| 3050 | if (newPointerIdBits == oldPointerIdBits) { |
| 3051 | if (child == null || child.hasIdentityMatrix()) { |
| 3052 | if (child == null) { |
| 3053 | handled = super.dispatchTouchEvent(event); |
| 3054 | } else { |
| 3055 | final float offsetX = mScrollX - child.mLeft; |
| 3056 | final float offsetY = mScrollY - child.mTop; |
| 3057 | event.offsetLocation(offsetX, offsetY); |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3058 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3059 | handled = child.dispatchTouchEvent(event); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3060 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3061 | event.offsetLocation(-offsetX, -offsetY); |
| 3062 | } |
| 3063 | return handled; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3064 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3065 | transformedEvent = MotionEvent.obtain(event); |
| 3066 | } else { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3067 | transformedEvent = event.split(newPointerIdBits); |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3070 | // Perform any necessary transformations and dispatch. |
| 3071 | if (child == null) { |
| 3072 | handled = super.dispatchTouchEvent(transformedEvent); |
| 3073 | } else { |
| 3074 | final float offsetX = mScrollX - child.mLeft; |
| 3075 | final float offsetY = mScrollY - child.mTop; |
| 3076 | transformedEvent.offsetLocation(offsetX, offsetY); |
| 3077 | if (! child.hasIdentityMatrix()) { |
| 3078 | transformedEvent.transform(child.getInverseMatrix()); |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3081 | handled = child.dispatchTouchEvent(transformedEvent); |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3084 | // Done. |
| 3085 | transformedEvent.recycle(); |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3086 | return handled; |
| 3087 | } |
| 3088 | |
Romain Guy | 469b1db | 2010-10-05 11:49:57 -0700 | [diff] [blame] | 3089 | /** |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3090 | * Enable or disable the splitting of MotionEvents to multiple children during touch event |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 3091 | * dispatch. This behavior is enabled by default for applications that target an |
| 3092 | * SDK version of {@link Build.VERSION_CODES#HONEYCOMB} or newer. |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3093 | * |
| 3094 | * <p>When this option is enabled MotionEvents may be split and dispatched to different child |
| 3095 | * views depending on where each pointer initially went down. This allows for user interactions |
| 3096 | * such as scrolling two panes of content independently, chording of buttons, and performing |
| 3097 | * independent gestures on different pieces of content. |
| 3098 | * |
| 3099 | * @param split <code>true</code> to allow MotionEvents to be split and dispatched to multiple |
| 3100 | * child views. <code>false</code> to only allow one child view to be the target of |
| 3101 | * any MotionEvent received by this ViewGroup. |
Scott Main | 27a8508 | 2013-06-10 10:39:48 -0700 | [diff] [blame] | 3102 | * @attr ref android.R.styleable#ViewGroup_splitMotionEvents |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3103 | */ |
| 3104 | public void setMotionEventSplittingEnabled(boolean split) { |
| 3105 | // TODO Applications really shouldn't change this setting mid-touch event, |
| 3106 | // but perhaps this should handle that case and send ACTION_CANCELs to any child views |
| 3107 | // with gestures in progress when this is changed. |
| 3108 | if (split) { |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3109 | mGroupFlags |= FLAG_SPLIT_MOTION_EVENTS; |
| 3110 | } else { |
| 3111 | mGroupFlags &= ~FLAG_SPLIT_MOTION_EVENTS; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /** |
Jeff Brown | 995e774 | 2010-12-22 16:59:36 -0800 | [diff] [blame] | 3116 | * Returns true if MotionEvents dispatched to this ViewGroup can be split to multiple children. |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 3117 | * @return true if MotionEvents dispatched to this ViewGroup can be split to multiple children. |
| 3118 | */ |
| 3119 | public boolean isMotionEventSplittingEnabled() { |
| 3120 | return (mGroupFlags & FLAG_SPLIT_MOTION_EVENTS) == FLAG_SPLIT_MOTION_EVENTS; |
| 3121 | } |
| 3122 | |
| 3123 | /** |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3124 | * Returns true if this ViewGroup should be considered as a single entity for removal |
| 3125 | * when executing an Activity transition. If this is false, child elements will move |
| 3126 | * individually during the transition. |
George Mount | 427c641 | 2014-11-05 16:45:36 -0800 | [diff] [blame] | 3127 | * |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3128 | * @return True if the ViewGroup should be acted on together during an Activity transition. |
George Mount | 427c641 | 2014-11-05 16:45:36 -0800 | [diff] [blame] | 3129 | * The default value is true when there is a non-null background or if |
| 3130 | * {@link #getTransitionName()} is not null or if a |
| 3131 | * non-null {@link android.view.ViewOutlineProvider} other than |
| 3132 | * {@link android.view.ViewOutlineProvider#BACKGROUND} was given to |
| 3133 | * {@link #setOutlineProvider(ViewOutlineProvider)} and false otherwise. |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3134 | */ |
| 3135 | public boolean isTransitionGroup() { |
| 3136 | if ((mGroupFlags & FLAG_IS_TRANSITION_GROUP_SET) != 0) { |
| 3137 | return ((mGroupFlags & FLAG_IS_TRANSITION_GROUP) != 0); |
| 3138 | } else { |
George Mount | 427c641 | 2014-11-05 16:45:36 -0800 | [diff] [blame] | 3139 | final ViewOutlineProvider outlineProvider = getOutlineProvider(); |
| 3140 | return getBackground() != null || getTransitionName() != null || |
| 3141 | (outlineProvider != null && outlineProvider != ViewOutlineProvider.BACKGROUND); |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | /** |
| 3146 | * Changes whether or not this ViewGroup should be treated as a single entity during |
George Mount | 31a2172 | 2014-03-24 17:44:36 -0700 | [diff] [blame] | 3147 | * Activity Transitions. |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3148 | * @param isTransitionGroup Whether or not the ViewGroup should be treated as a unit |
| 3149 | * in Activity transitions. If false, the ViewGroup won't transition, |
| 3150 | * only its children. If true, the entire ViewGroup will transition |
| 3151 | * together. |
George Mount | 62ab9b7 | 2014-05-02 13:51:17 -0700 | [diff] [blame] | 3152 | * @see android.app.ActivityOptions#makeSceneTransitionAnimation(android.app.Activity, |
| 3153 | * android.util.Pair[]) |
George Mount | 0a778ed | 2013-12-13 13:35:36 -0800 | [diff] [blame] | 3154 | */ |
| 3155 | public void setTransitionGroup(boolean isTransitionGroup) { |
| 3156 | mGroupFlags |= FLAG_IS_TRANSITION_GROUP_SET; |
| 3157 | if (isTransitionGroup) { |
| 3158 | mGroupFlags |= FLAG_IS_TRANSITION_GROUP; |
| 3159 | } else { |
| 3160 | mGroupFlags &= ~FLAG_IS_TRANSITION_GROUP; |
| 3161 | } |
| 3162 | } |
| 3163 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 3164 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | if (disallowIntercept == ((mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0)) { |
| 3168 | // We're already in this state, assume our ancestors are too |
| 3169 | return; |
| 3170 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | if (disallowIntercept) { |
| 3173 | mGroupFlags |= FLAG_DISALLOW_INTERCEPT; |
| 3174 | } else { |
| 3175 | mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT; |
| 3176 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | // Pass it up to our parent |
| 3179 | if (mParent != null) { |
| 3180 | mParent.requestDisallowInterceptTouchEvent(disallowIntercept); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | /** |
| 3185 | * Implement this method to intercept all touch screen motion events. This |
| 3186 | * allows you to watch events as they are dispatched to your children, and |
| 3187 | * take ownership of the current gesture at any point. |
| 3188 | * |
| 3189 | * <p>Using this function takes some care, as it has a fairly complicated |
| 3190 | * interaction with {@link View#onTouchEvent(MotionEvent) |
| 3191 | * View.onTouchEvent(MotionEvent)}, and using it requires implementing |
| 3192 | * that method as well as this one in the correct way. Events will be |
| 3193 | * received in the following order: |
| 3194 | * |
| 3195 | * <ol> |
| 3196 | * <li> You will receive the down event here. |
| 3197 | * <li> The down event will be handled either by a child of this view |
| 3198 | * group, or given to your own onTouchEvent() method to handle; this means |
| 3199 | * you should implement onTouchEvent() to return true, so you will |
| 3200 | * continue to see the rest of the gesture (instead of looking for |
| 3201 | * a parent view to handle it). Also, by returning true from |
| 3202 | * onTouchEvent(), you will not receive any following |
| 3203 | * events in onInterceptTouchEvent() and all touch processing must |
| 3204 | * happen in onTouchEvent() like normal. |
| 3205 | * <li> For as long as you return false from this function, each following |
| 3206 | * event (up to and including the final up) will be delivered first here |
| 3207 | * and then to the target's onTouchEvent(). |
| 3208 | * <li> If you return true from here, you will not receive any |
| 3209 | * following events: the target view will receive the same event but |
| 3210 | * with the action {@link MotionEvent#ACTION_CANCEL}, and all further |
| 3211 | * events will be delivered to your onTouchEvent() method and no longer |
| 3212 | * appear here. |
| 3213 | * </ol> |
| 3214 | * |
| 3215 | * @param ev The motion event being dispatched down the hierarchy. |
| 3216 | * @return Return true to steal motion events from the children and have |
| 3217 | * them dispatched to this ViewGroup through onTouchEvent(). |
| 3218 | * The current target will receive an ACTION_CANCEL event, and no further |
| 3219 | * messages will be delivered here. |
| 3220 | */ |
| 3221 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Keisuke Kuroyanagi | d85bc50 | 2016-01-21 14:50:38 +0900 | [diff] [blame] | 3222 | if (ev.isFromSource(InputDevice.SOURCE_MOUSE) |
| 3223 | && ev.getAction() == MotionEvent.ACTION_DOWN |
| 3224 | && ev.isButtonPressed(MotionEvent.BUTTON_PRIMARY) |
| 3225 | && isOnScrollbarThumb(ev.getX(), ev.getY())) { |
| 3226 | return true; |
| 3227 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | return false; |
| 3229 | } |
| 3230 | |
| 3231 | /** |
| 3232 | * {@inheritDoc} |
| 3233 | * |
| 3234 | * Looks for a view to give focus to respecting the setting specified by |
| 3235 | * {@link #getDescendantFocusability()}. |
| 3236 | * |
| 3237 | * Uses {@link #onRequestFocusInDescendants(int, android.graphics.Rect)} to |
| 3238 | * find focus within the children of this group when appropriate. |
| 3239 | * |
| 3240 | * @see #FOCUS_BEFORE_DESCENDANTS |
| 3241 | * @see #FOCUS_AFTER_DESCENDANTS |
| 3242 | * @see #FOCUS_BLOCK_DESCENDANTS |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 3243 | * @see #onRequestFocusInDescendants(int, android.graphics.Rect) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | */ |
| 3245 | @Override |
| 3246 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 3247 | if (DBG) { |
| 3248 | System.out.println(this + " ViewGroup.requestFocus direction=" |
| 3249 | + direction); |
| 3250 | } |
| 3251 | int descendantFocusability = getDescendantFocusability(); |
| 3252 | |
Evan Rosky | 5db64eb | 2017-11-20 23:04:46 +0000 | [diff] [blame] | 3253 | boolean result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | switch (descendantFocusability) { |
| 3255 | case FOCUS_BLOCK_DESCENDANTS: |
Evan Rosky | 5db64eb | 2017-11-20 23:04:46 +0000 | [diff] [blame] | 3256 | result = super.requestFocus(direction, previouslyFocusedRect); |
| 3257 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | case FOCUS_BEFORE_DESCENDANTS: { |
| 3259 | final boolean took = super.requestFocus(direction, previouslyFocusedRect); |
Evan Rosky | 5db64eb | 2017-11-20 23:04:46 +0000 | [diff] [blame] | 3260 | result = took ? took : onRequestFocusInDescendants(direction, |
| 3261 | previouslyFocusedRect); |
| 3262 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | } |
| 3264 | case FOCUS_AFTER_DESCENDANTS: { |
| 3265 | final boolean took = onRequestFocusInDescendants(direction, previouslyFocusedRect); |
Evan Rosky | 5db64eb | 2017-11-20 23:04:46 +0000 | [diff] [blame] | 3266 | result = took ? took : super.requestFocus(direction, previouslyFocusedRect); |
| 3267 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | } |
| 3269 | default: |
| 3270 | throw new IllegalStateException("descendant focusability must be " |
| 3271 | + "one of FOCUS_BEFORE_DESCENDANTS, FOCUS_AFTER_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS " |
| 3272 | + "but is " + descendantFocusability); |
| 3273 | } |
Evan Rosky | 5db64eb | 2017-11-20 23:04:46 +0000 | [diff] [blame] | 3274 | if (result && !isLayoutValid() && ((mPrivateFlags & PFLAG_WANTS_FOCUS) == 0)) { |
| 3275 | mPrivateFlags |= PFLAG_WANTS_FOCUS; |
| 3276 | } |
| 3277 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | /** |
| 3281 | * Look for a descendant to call {@link View#requestFocus} on. |
| 3282 | * Called by {@link ViewGroup#requestFocus(int, android.graphics.Rect)} |
| 3283 | * when it wants to request focus within its children. Override this to |
| 3284 | * customize how your {@link ViewGroup} requests focus within its children. |
| 3285 | * @param direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
| 3286 | * @param previouslyFocusedRect The rectangle (in this View's coordinate system) |
| 3287 | * to give a finer grained hint about where focus is coming from. May be null |
| 3288 | * if there is no hint. |
| 3289 | * @return Whether focus was taken. |
| 3290 | */ |
| 3291 | @SuppressWarnings({"ConstantConditions"}) |
| 3292 | protected boolean onRequestFocusInDescendants(int direction, |
| 3293 | Rect previouslyFocusedRect) { |
| 3294 | int index; |
| 3295 | int increment; |
| 3296 | int end; |
| 3297 | int count = mChildrenCount; |
| 3298 | if ((direction & FOCUS_FORWARD) != 0) { |
| 3299 | index = 0; |
| 3300 | increment = 1; |
| 3301 | end = count; |
| 3302 | } else { |
| 3303 | index = count - 1; |
| 3304 | increment = -1; |
| 3305 | end = -1; |
| 3306 | } |
| 3307 | final View[] children = mChildren; |
| 3308 | for (int i = index; i != end; i += increment) { |
| 3309 | View child = children[i]; |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 3310 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3311 | if (child.requestFocus(direction, previouslyFocusedRect)) { |
| 3312 | return true; |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | return false; |
| 3317 | } |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3318 | |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 3319 | @Override |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 3320 | public boolean restoreDefaultFocus() { |
| 3321 | if (mDefaultFocus != null |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 3322 | && getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 3323 | && (mDefaultFocus.mViewFlags & VISIBILITY_MASK) == VISIBLE |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 3324 | && mDefaultFocus.restoreDefaultFocus()) { |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 3325 | return true; |
| 3326 | } |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 3327 | return super.restoreDefaultFocus(); |
| 3328 | } |
| 3329 | |
| 3330 | /** |
| 3331 | * @hide |
| 3332 | */ |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 3333 | @TestApi |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 3334 | @Override |
| 3335 | public boolean restoreFocusInCluster(@FocusRealDirection int direction) { |
Evan Rosky | 18b886e | 2017-02-15 13:26:51 -0800 | [diff] [blame] | 3336 | // Allow cluster-navigation to enter touchscreenBlocksFocus ViewGroups. |
| 3337 | if (isKeyboardNavigationCluster()) { |
| 3338 | final boolean blockedFocus = getTouchscreenBlocksFocus(); |
| 3339 | try { |
| 3340 | setTouchscreenBlocksFocusNoRefocus(false); |
| 3341 | return restoreFocusInClusterInternal(direction); |
| 3342 | } finally { |
| 3343 | setTouchscreenBlocksFocusNoRefocus(blockedFocus); |
| 3344 | } |
| 3345 | } else { |
| 3346 | return restoreFocusInClusterInternal(direction); |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | private boolean restoreFocusInClusterInternal(@FocusRealDirection int direction) { |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 3351 | if (mFocusedInCluster != null && getDescendantFocusability() != FOCUS_BLOCK_DESCENDANTS |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 3352 | && (mFocusedInCluster.mViewFlags & VISIBILITY_MASK) == VISIBLE |
| 3353 | && mFocusedInCluster.restoreFocusInCluster(direction)) { |
| 3354 | return true; |
| 3355 | } |
| 3356 | return super.restoreFocusInCluster(direction); |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 3357 | } |
| 3358 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 3359 | /** |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 3360 | * @hide |
| 3361 | */ |
| 3362 | @Override |
| 3363 | public boolean restoreFocusNotInCluster() { |
| 3364 | if (mFocusedInCluster != null) { |
| 3365 | // since clusters don't nest; we can assume that a non-null mFocusedInCluster |
| 3366 | // will refer to a view not-in a cluster. |
| 3367 | return restoreFocusInCluster(View.FOCUS_DOWN); |
| 3368 | } |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 3369 | if (isKeyboardNavigationCluster() || (mViewFlags & VISIBILITY_MASK) != VISIBLE) { |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 3370 | return false; |
| 3371 | } |
| 3372 | int descendentFocusability = getDescendantFocusability(); |
| 3373 | if (descendentFocusability == FOCUS_BLOCK_DESCENDANTS) { |
| 3374 | return super.requestFocus(FOCUS_DOWN, null); |
| 3375 | } |
| 3376 | if (descendentFocusability == FOCUS_BEFORE_DESCENDANTS |
| 3377 | && super.requestFocus(FOCUS_DOWN, null)) { |
| 3378 | return true; |
| 3379 | } |
| 3380 | for (int i = 0; i < mChildrenCount; ++i) { |
| 3381 | View child = mChildren[i]; |
| 3382 | if (!child.isKeyboardNavigationCluster() |
| 3383 | && child.restoreFocusNotInCluster()) { |
| 3384 | return true; |
| 3385 | } |
| 3386 | } |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 3387 | if (descendentFocusability == FOCUS_AFTER_DESCENDANTS && !hasFocusableChild(false)) { |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 3388 | return super.requestFocus(FOCUS_DOWN, null); |
| 3389 | } |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
| 3393 | /** |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 3394 | * {@inheritDoc} |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3395 | * |
Romain Guy | dcc490f | 2010-02-24 17:59:35 -0800 | [diff] [blame] | 3396 | * @hide |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 3397 | */ |
| 3398 | @Override |
| 3399 | public void dispatchStartTemporaryDetach() { |
| 3400 | super.dispatchStartTemporaryDetach(); |
| 3401 | final int count = mChildrenCount; |
| 3402 | final View[] children = mChildren; |
| 3403 | for (int i = 0; i < count; i++) { |
| 3404 | children[i].dispatchStartTemporaryDetach(); |
| 3405 | } |
| 3406 | } |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3407 | |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 3408 | /** |
| 3409 | * {@inheritDoc} |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3410 | * |
Romain Guy | dcc490f | 2010-02-24 17:59:35 -0800 | [diff] [blame] | 3411 | * @hide |
Romain Guy | a440b00 | 2010-02-24 15:57:54 -0800 | [diff] [blame] | 3412 | */ |
| 3413 | @Override |
| 3414 | public void dispatchFinishTemporaryDetach() { |
| 3415 | super.dispatchFinishTemporaryDetach(); |
| 3416 | final int count = mChildrenCount; |
| 3417 | final View[] children = mChildren; |
| 3418 | for (int i = 0; i < count; i++) { |
| 3419 | children[i].dispatchFinishTemporaryDetach(); |
| 3420 | } |
| 3421 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 3424 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | void dispatchAttachedToWindow(AttachInfo info, int visibility) { |
Adam Powell | 4b86788 | 2011-09-16 12:59:46 -0700 | [diff] [blame] | 3426 | mGroupFlags |= FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3427 | super.dispatchAttachedToWindow(info, visibility); |
Adam Powell | 4b86788 | 2011-09-16 12:59:46 -0700 | [diff] [blame] | 3428 | mGroupFlags &= ~FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW; |
| 3429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | final int count = mChildrenCount; |
| 3431 | final View[] children = mChildren; |
| 3432 | for (int i = 0; i < count; i++) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3433 | final View child = children[i]; |
| 3434 | child.dispatchAttachedToWindow(info, |
Adam Powell | eb2b0af | 2015-05-20 18:26:35 -0700 | [diff] [blame] | 3435 | combineVisibility(visibility, child.getVisibility())); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3436 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 3437 | final int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 3438 | for (int i = 0; i < transientCount; ++i) { |
| 3439 | View view = mTransientViews.get(i); |
Adam Powell | eb2b0af | 2015-05-20 18:26:35 -0700 | [diff] [blame] | 3440 | view.dispatchAttachedToWindow(info, |
| 3441 | combineVisibility(visibility, view.getVisibility())); |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 3442 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3443 | } |
| 3444 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3445 | @Override |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 3446 | void dispatchScreenStateChanged(int screenState) { |
| 3447 | super.dispatchScreenStateChanged(screenState); |
| 3448 | |
| 3449 | final int count = mChildrenCount; |
| 3450 | final View[] children = mChildren; |
| 3451 | for (int i = 0; i < count; i++) { |
| 3452 | children[i].dispatchScreenStateChanged(screenState); |
| 3453 | } |
| 3454 | } |
| 3455 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3456 | @Override |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3457 | void dispatchMovedToDisplay(Display display, Configuration config) { |
| 3458 | super.dispatchMovedToDisplay(display, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3459 | |
| 3460 | final int count = mChildrenCount; |
| 3461 | final View[] children = mChildren; |
| 3462 | for (int i = 0; i < count; i++) { |
Andrii Kulian | e5c58ee | 2017-03-27 19:25:24 -0700 | [diff] [blame] | 3463 | children[i].dispatchMovedToDisplay(display, config); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 3467 | /** @hide */ |
Romain Guy | bb9908b | 2012-03-08 11:14:07 -0800 | [diff] [blame] | 3468 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 3469 | public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3470 | boolean handled = false; |
| 3471 | if (includeForAccessibility()) { |
| 3472 | handled = super.dispatchPopulateAccessibilityEventInternal(event); |
| 3473 | if (handled) { |
| 3474 | return handled; |
| 3475 | } |
Svetoslav Ganov | b84b94e | 2011-09-22 19:26:56 -0700 | [diff] [blame] | 3476 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3477 | // Let our children have a shot in populating the event. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3478 | ChildListForAccessibility children = ChildListForAccessibility.obtain(this, true); |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 3479 | try { |
| 3480 | final int childCount = children.getChildCount(); |
| 3481 | for (int i = 0; i < childCount; i++) { |
| 3482 | View child = children.getChildAt(i); |
| 3483 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 3484 | handled = child.dispatchPopulateAccessibilityEvent(event); |
| 3485 | if (handled) { |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 3486 | return handled; |
| 3487 | } |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 3488 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3489 | } |
Svetoslav Ganov | 76f287e | 2012-04-23 11:02:36 -0700 | [diff] [blame] | 3490 | } finally { |
| 3491 | children.recycle(); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3492 | } |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 3493 | return false; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
Dianne Hackborn | 6251f0d | 2015-04-01 16:45:03 -0700 | [diff] [blame] | 3496 | /** |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3497 | * Dispatch creation of {@link ViewStructure} down the hierarchy. This implementation |
| 3498 | * adds in all child views of the view group, in addition to calling the default View |
| 3499 | * implementation. |
| 3500 | */ |
| 3501 | @Override |
| 3502 | public void dispatchProvideStructure(ViewStructure structure) { |
| 3503 | super.dispatchProvideStructure(structure); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3504 | if (isAssistBlocked() || structure.getChildCount() != 0) { |
| 3505 | return; |
| 3506 | } |
| 3507 | final int childrenCount = mChildrenCount; |
| 3508 | if (childrenCount <= 0) { |
| 3509 | return; |
| 3510 | } |
Philip P. Moltmann | 083d8aa | 2017-08-15 15:22:37 -0700 | [diff] [blame] | 3511 | |
| 3512 | if (!isLaidOut()) { |
Felipe Leme | fe05a52 | 2018-01-23 15:57:49 -0800 | [diff] [blame] | 3513 | if (Helper.sVerbose) { |
| 3514 | Log.v(VIEW_LOG_TAG, "dispatchProvideStructure(): not laid out, ignoring " |
| 3515 | + childrenCount + " children of " + getAccessibilityViewId()); |
| 3516 | } |
Philip P. Moltmann | 083d8aa | 2017-08-15 15:22:37 -0700 | [diff] [blame] | 3517 | return; |
| 3518 | } |
| 3519 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3520 | structure.setChildCount(childrenCount); |
| 3521 | ArrayList<View> preorderedList = buildOrderedChildList(); |
| 3522 | boolean customOrder = preorderedList == null |
| 3523 | && isChildrenDrawingOrderEnabled(); |
| 3524 | for (int i = 0; i < childrenCount; i++) { |
| 3525 | int childIndex; |
| 3526 | try { |
| 3527 | childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 3528 | } catch (IndexOutOfBoundsException e) { |
| 3529 | childIndex = i; |
| 3530 | if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.M) { |
| 3531 | Log.w(TAG, "Bad getChildDrawingOrder while collecting assist @ " |
| 3532 | + i + " of " + childrenCount, e); |
| 3533 | // At least one app is failing when we call getChildDrawingOrder |
| 3534 | // at this point, so deal semi-gracefully with it by falling back |
| 3535 | // on the basic order. |
| 3536 | customOrder = false; |
| 3537 | if (i > 0) { |
| 3538 | // If we failed at the first index, there really isn't |
| 3539 | // anything to do -- we will just proceed with the simple |
| 3540 | // sequence order. |
| 3541 | // Otherwise, we failed in the middle, so need to come up |
| 3542 | // with an order for the remaining indices and use that. |
| 3543 | // Failed at the first one, easy peasy. |
| 3544 | int[] permutation = new int[childrenCount]; |
| 3545 | SparseBooleanArray usedIndices = new SparseBooleanArray(); |
| 3546 | // Go back and collected the indices we have done so far. |
| 3547 | for (int j = 0; j < i; j++) { |
| 3548 | permutation[j] = getChildDrawingOrder(childrenCount, j); |
| 3549 | usedIndices.put(permutation[j], true); |
| 3550 | } |
| 3551 | // Fill in the remaining indices with indices that have not |
| 3552 | // yet been used. |
| 3553 | int nextIndex = 0; |
| 3554 | for (int j = i; j < childrenCount; j++) { |
| 3555 | while (usedIndices.get(nextIndex, false)) { |
| 3556 | nextIndex++; |
| 3557 | } |
| 3558 | permutation[j] = nextIndex; |
| 3559 | nextIndex++; |
| 3560 | } |
| 3561 | // Build the final view list. |
| 3562 | preorderedList = new ArrayList<>(childrenCount); |
| 3563 | for (int j = 0; j < childrenCount; j++) { |
| 3564 | final int index = permutation[j]; |
| 3565 | final View child = mChildren[index]; |
| 3566 | preorderedList.add(child); |
| 3567 | } |
| 3568 | } |
| 3569 | } else { |
| 3570 | throw e; |
| 3571 | } |
| 3572 | } |
| 3573 | final View child = getAndVerifyPreorderedView(preorderedList, mChildren, |
| 3574 | childIndex); |
| 3575 | final ViewStructure cstructure = structure.newChild(i); |
| 3576 | child.dispatchProvideStructure(cstructure); |
| 3577 | } |
| 3578 | if (preorderedList != null) { |
| 3579 | preorderedList.clear(); |
| 3580 | } |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | /** |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3584 | * {@inheritDoc} |
| 3585 | * |
| 3586 | * <p>This implementation adds in all child views of the view group, in addition to calling the |
| 3587 | * default {@link View} implementation. |
Dianne Hackborn | 6251f0d | 2015-04-01 16:45:03 -0700 | [diff] [blame] | 3588 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 3589 | @Override |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3590 | public void dispatchProvideAutofillStructure(ViewStructure structure, |
| 3591 | @AutofillFlags int flags) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 3592 | super.dispatchProvideAutofillStructure(structure, flags); |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 3593 | |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3594 | if (structure.getChildCount() != 0) { |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3595 | return; |
| 3596 | } |
Philip P. Moltmann | 083d8aa | 2017-08-15 15:22:37 -0700 | [diff] [blame] | 3597 | |
| 3598 | if (!isLaidOut()) { |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 3599 | if (Helper.sVerbose) { |
| 3600 | Log.v(VIEW_LOG_TAG, "dispatchProvideAutofillStructure(): not laid out, ignoring " |
| 3601 | + mChildrenCount + " children of " + getAutofillId()); |
| 3602 | } |
Philip P. Moltmann | 083d8aa | 2017-08-15 15:22:37 -0700 | [diff] [blame] | 3603 | return; |
| 3604 | } |
| 3605 | |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3606 | final ChildListForAutoFill children = getChildrenForAutofill(flags); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3607 | final int childrenCount = children.size(); |
| 3608 | structure.setChildCount(childrenCount); |
| 3609 | for (int i = 0; i < childrenCount; i++) { |
| 3610 | final View child = children.get(i); |
| 3611 | final ViewStructure cstructure = structure.newChild(i); |
| 3612 | child.dispatchProvideAutofillStructure(cstructure, flags); |
| 3613 | } |
| 3614 | children.recycle(); |
Felipe Leme | 6d55387 | 2016-12-08 17:13:25 -0800 | [diff] [blame] | 3615 | } |
Felipe Leme | 1ca634a | 2016-11-28 17:21:21 -0800 | [diff] [blame] | 3616 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3617 | /** |
| 3618 | * Gets the children for autofill. Children for autofill are the first |
| 3619 | * level descendants that are important for autofill. The returned |
| 3620 | * child list object is pooled and the caller must recycle it once done. |
| 3621 | * @hide */ |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3622 | private @NonNull ChildListForAutoFill getChildrenForAutofill(@AutofillFlags int flags) { |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3623 | final ChildListForAutoFill children = ChildListForAutoFill.obtain(); |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3624 | populateChildrenForAutofill(children, flags); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3625 | return children; |
Felipe Leme | d04a697 | 2017-03-02 12:56:18 -0800 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | /** @hide */ |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3629 | private void populateChildrenForAutofill(ArrayList<View> list, @AutofillFlags int flags) { |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 3630 | final int childrenCount = mChildrenCount; |
| 3631 | if (childrenCount <= 0) { |
| 3632 | return; |
| 3633 | } |
| 3634 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 3635 | final boolean customOrder = preorderedList == null |
| 3636 | && isChildrenDrawingOrderEnabled(); |
| 3637 | for (int i = 0; i < childrenCount; i++) { |
| 3638 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 3639 | final View child = (preorderedList == null) |
| 3640 | ? mChildren[childIndex] : preorderedList.get(childIndex); |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3641 | if ((flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0 |
| 3642 | || child.isImportantForAutofill()) { |
Felipe Leme | d04a697 | 2017-03-02 12:56:18 -0800 | [diff] [blame] | 3643 | list.add(child); |
| 3644 | } else if (child instanceof ViewGroup) { |
Svet Ganov | fd31f85 | 2017-04-26 15:54:27 -0700 | [diff] [blame] | 3645 | ((ViewGroup) child).populateChildrenForAutofill(list, flags); |
Felipe Leme | d04a697 | 2017-03-02 12:56:18 -0800 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | } |
| 3649 | |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 3650 | private static View getAndVerifyPreorderedView(ArrayList<View> preorderedList, View[] children, |
| 3651 | int childIndex) { |
| 3652 | final View child; |
| 3653 | if (preorderedList != null) { |
| 3654 | child = preorderedList.get(childIndex); |
| 3655 | if (child == null) { |
| 3656 | throw new RuntimeException("Invalid preorderedList contained null child at index " |
| 3657 | + childIndex); |
| 3658 | } |
| 3659 | } else { |
| 3660 | child = children[childIndex]; |
| 3661 | } |
| 3662 | return child; |
| 3663 | } |
| 3664 | |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 3665 | /** @hide */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3666 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 3667 | @UnsupportedAppUsage |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 3668 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
Svetoslav Ganov | 031d9c1 | 2011-09-09 16:41:13 -0700 | [diff] [blame] | 3669 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Svet Ganov | 55bdb10 | 2015-02-06 12:41:17 -0800 | [diff] [blame] | 3670 | if (getAccessibilityNodeProvider() != null) { |
| 3671 | return; |
| 3672 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3673 | if (mAttachInfo != null) { |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 3674 | final ArrayList<View> childrenForAccessibility = mAttachInfo.mTempArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3675 | childrenForAccessibility.clear(); |
| 3676 | addChildrenForAccessibility(childrenForAccessibility); |
| 3677 | final int childrenForAccessibilityCount = childrenForAccessibility.size(); |
| 3678 | for (int i = 0; i < childrenForAccessibilityCount; i++) { |
Alan Viverette | f0aed09 | 2013-11-06 15:33:03 -0800 | [diff] [blame] | 3679 | final View child = childrenForAccessibility.get(i); |
| 3680 | info.addChildUnchecked(child); |
Svetoslav Ganov | ea1da3d | 2011-06-15 17:16:02 -0700 | [diff] [blame] | 3681 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3682 | childrenForAccessibility.clear(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 3686 | @Override |
Maxim Bogatov | f399af3 | 2015-06-16 15:15:49 -0700 | [diff] [blame] | 3687 | public CharSequence getAccessibilityClassName() { |
| 3688 | return ViewGroup.class.getName(); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3691 | @Override |
| 3692 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 3693 | // If this is a live region, we should send a subtree change event |
| 3694 | // from this view. Otherwise, we can let it propagate up. |
| 3695 | if (getAccessibilityLiveRegion() != ACCESSIBILITY_LIVE_REGION_NONE) { |
| 3696 | notifyViewAccessibilityStateChangedIfNeeded( |
| 3697 | AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE); |
| 3698 | } else if (mParent != null) { |
| 3699 | try { |
| 3700 | mParent.notifySubtreeAccessibilityStateChanged(this, source, changeType); |
| 3701 | } catch (AbstractMethodError e) { |
| 3702 | Log.e(VIEW_LOG_TAG, mParent.getClass().getSimpleName() + |
| 3703 | " does not fully implement ViewParent", e); |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 3708 | /** @hide */ |
| 3709 | @Override |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3710 | public void notifySubtreeAccessibilityStateChangedIfNeeded() { |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 3711 | if (!AccessibilityManager.getInstance(mContext).isEnabled() || mAttachInfo == null) { |
| 3712 | return; |
| 3713 | } |
| 3714 | // If something important for a11y is happening in this subtree, make sure it's dispatched |
| 3715 | // from a view that is important for a11y so it doesn't get lost. |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3716 | if ((getImportantForAccessibility() != IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) |
| 3717 | && !isImportantForAccessibility() && (getChildCount() > 0)) { |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 3718 | ViewParent a11yParent = getParentForAccessibility(); |
| 3719 | if (a11yParent instanceof View) { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3720 | ((View) a11yParent).notifySubtreeAccessibilityStateChangedIfNeeded(); |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 3721 | return; |
| 3722 | } |
| 3723 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3724 | super.notifySubtreeAccessibilityStateChangedIfNeeded(); |
Phil Weaver | 4d3eec41 | 2016-09-01 16:28:34 -0700 | [diff] [blame] | 3725 | } |
| 3726 | |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 3727 | @Override |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 3728 | void resetSubtreeAccessibilityStateChanged() { |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 3729 | super.resetSubtreeAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3730 | View[] children = mChildren; |
| 3731 | final int childCount = mChildrenCount; |
| 3732 | for (int i = 0; i < childCount; i++) { |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 3733 | children[i].resetSubtreeAccessibilityStateChanged(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | /** |
Phil Weaver | 1f22254 | 2016-01-08 11:49:32 -0800 | [diff] [blame] | 3738 | * Counts the number of children of this View that will be sent to an accessibility service. |
| 3739 | * |
| 3740 | * @return The number of children an {@code AccessibilityNodeInfo} rooted at this View |
| 3741 | * would have. |
| 3742 | */ |
| 3743 | int getNumChildrenForAccessibility() { |
| 3744 | int numChildrenForAccessibility = 0; |
| 3745 | for (int i = 0; i < getChildCount(); i++) { |
| 3746 | View child = getChildAt(i); |
| 3747 | if (child.includeForAccessibility()) { |
| 3748 | numChildrenForAccessibility++; |
| 3749 | } else if (child instanceof ViewGroup) { |
| 3750 | numChildrenForAccessibility += ((ViewGroup) child) |
| 3751 | .getNumChildrenForAccessibility(); |
| 3752 | } |
| 3753 | } |
| 3754 | return numChildrenForAccessibility; |
| 3755 | } |
| 3756 | |
| 3757 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | * {@inheritDoc} |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 3759 | * |
| 3760 | * <p>Subclasses should always call <code>super.onNestedPrePerformAccessibilityAction</code></p> |
| 3761 | * |
| 3762 | * @param target The target view dispatching this action |
| 3763 | * @param action Action being performed; see |
| 3764 | * {@link android.view.accessibility.AccessibilityNodeInfo} |
| 3765 | * @param args Optional action arguments |
| 3766 | * @return false by default. Subclasses should return true if they handle the event. |
| 3767 | */ |
| 3768 | @Override |
| 3769 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 3770 | return false; |
| 3771 | } |
| 3772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 3774 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | void dispatchDetachedFromWindow() { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3776 | // If we still have a touch target, we are still in the process of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | // dispatching motion events to a child; we need to get rid of that |
| 3778 | // child to avoid dispatching events to it after the window is torn |
| 3779 | // down. To make sure we keep the child in a consistent state, we |
| 3780 | // first send it an ACTION_CANCEL motion event. |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 3781 | cancelAndClearTouchTargets(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 3783 | // Similarly, set ACTION_EXIT to all hover targets and clear them. |
| 3784 | exitHoverTargets(); |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 3785 | exitTooltipHoverTargets(); |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 3786 | |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 3787 | // In case view is detached while transition is running |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 3788 | mLayoutCalledWhileSuppressed = false; |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 3789 | |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 3790 | // Tear down our drag tracking |
Vadim Tryshev | 1a68dc9 | 2015-07-20 17:01:50 -0700 | [diff] [blame] | 3791 | mChildrenInterestedInDrag = null; |
| 3792 | mIsInterestedInDrag = false; |
| 3793 | if (mCurrentDragStartEvent != null) { |
| 3794 | mCurrentDragStartEvent.recycle(); |
| 3795 | mCurrentDragStartEvent = null; |
Christopher Tate | 86cab1b | 2011-01-13 20:28:55 -0800 | [diff] [blame] | 3796 | } |
| 3797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3798 | final int count = mChildrenCount; |
| 3799 | final View[] children = mChildren; |
| 3800 | for (int i = 0; i < count; i++) { |
| 3801 | children[i].dispatchDetachedFromWindow(); |
| 3802 | } |
John Reck | ca7a9da | 2014-03-05 16:29:07 -0800 | [diff] [blame] | 3803 | clearDisappearingChildren(); |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 3804 | final int transientCount = mTransientViews == null ? 0 : mTransientIndices.size(); |
| 3805 | for (int i = 0; i < transientCount; ++i) { |
| 3806 | View view = mTransientViews.get(i); |
| 3807 | view.dispatchDetachedFromWindow(); |
| 3808 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | super.dispatchDetachedFromWindow(); |
| 3810 | } |
| 3811 | |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3812 | /** |
| 3813 | * @hide |
| 3814 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3815 | @Override |
Fabrice Di Meglio | 23c89fd | 2012-08-13 12:17:42 -0700 | [diff] [blame] | 3816 | protected void internalSetPadding(int left, int top, int right, int bottom) { |
Romain Guy | 2440e67 | 2012-08-07 14:43:43 -0700 | [diff] [blame] | 3817 | super.internalSetPadding(left, top, right, bottom); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | |
Romain Guy | 13f35f3 | 2011-03-24 12:03:17 -0700 | [diff] [blame] | 3819 | if ((mPaddingLeft | mPaddingTop | mPaddingRight | mPaddingBottom) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | mGroupFlags |= FLAG_PADDING_NOT_NULL; |
| 3821 | } else { |
| 3822 | mGroupFlags &= ~FLAG_PADDING_NOT_NULL; |
| 3823 | } |
| 3824 | } |
| 3825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | @Override |
| 3827 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 3828 | super.dispatchSaveInstanceState(container); |
| 3829 | final int count = mChildrenCount; |
| 3830 | final View[] children = mChildren; |
| 3831 | for (int i = 0; i < count; i++) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3832 | View c = children[i]; |
| 3833 | if ((c.mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED) { |
| 3834 | c.dispatchSaveInstanceState(container); |
| 3835 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | } |
| 3837 | } |
| 3838 | |
| 3839 | /** |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 3840 | * Perform dispatching of a {@link #saveHierarchyState(android.util.SparseArray)} freeze()} |
| 3841 | * to only this view, not to its children. For use when overriding |
| 3842 | * {@link #dispatchSaveInstanceState(android.util.SparseArray)} dispatchFreeze()} to allow |
| 3843 | * subclasses to freeze their own state but not the state of their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | * |
| 3845 | * @param container the container |
| 3846 | */ |
| 3847 | protected void dispatchFreezeSelfOnly(SparseArray<Parcelable> container) { |
| 3848 | super.dispatchSaveInstanceState(container); |
| 3849 | } |
| 3850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | @Override |
| 3852 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 3853 | super.dispatchRestoreInstanceState(container); |
| 3854 | final int count = mChildrenCount; |
| 3855 | final View[] children = mChildren; |
| 3856 | for (int i = 0; i < count; i++) { |
Dianne Hackborn | b4bc78b | 2010-05-12 18:59:50 -0700 | [diff] [blame] | 3857 | View c = children[i]; |
| 3858 | if ((c.mViewFlags & PARENT_SAVE_DISABLED_MASK) != PARENT_SAVE_DISABLED) { |
| 3859 | c.dispatchRestoreInstanceState(container); |
| 3860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | /** |
Romain Guy | 02739a8 | 2011-05-16 11:43:18 -0700 | [diff] [blame] | 3865 | * Perform dispatching of a {@link #restoreHierarchyState(android.util.SparseArray)} |
| 3866 | * to only this view, not to its children. For use when overriding |
| 3867 | * {@link #dispatchRestoreInstanceState(android.util.SparseArray)} to allow |
| 3868 | * subclasses to thaw their own state but not the state of their children. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3869 | * |
| 3870 | * @param container the container |
| 3871 | */ |
| 3872 | protected void dispatchThawSelfOnly(SparseArray<Parcelable> container) { |
| 3873 | super.dispatchRestoreInstanceState(container); |
| 3874 | } |
| 3875 | |
| 3876 | /** |
| 3877 | * Enables or disables the drawing cache for each child of this view group. |
| 3878 | * |
| 3879 | * @param enabled true to enable the cache, false to dispose of it |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 3880 | * |
| 3881 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 3882 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 3883 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 3884 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 3885 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 3886 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 3887 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 3888 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 3889 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 3890 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 3891 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 3892 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3893 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 3894 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | protected void setChildrenDrawingCacheEnabled(boolean enabled) { |
| 3896 | if (enabled || (mPersistentDrawingCache & PERSISTENT_ALL_CACHES) != PERSISTENT_ALL_CACHES) { |
| 3897 | final View[] children = mChildren; |
| 3898 | final int count = mChildrenCount; |
| 3899 | for (int i = 0; i < count; i++) { |
| 3900 | children[i].setDrawingCacheEnabled(enabled); |
| 3901 | } |
| 3902 | } |
| 3903 | } |
| 3904 | |
sergeyv | b37d44e | 2016-03-29 20:27:44 -0700 | [diff] [blame] | 3905 | /** |
| 3906 | * @hide |
| 3907 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | @Override |
Sunny Goyal | d1b287e | 2018-01-04 09:37:22 -0800 | [diff] [blame] | 3909 | public Bitmap createSnapshot(ViewDebug.CanvasProvider canvasProvider, boolean skipChildren) { |
Romain Guy | 65554f2 | 2010-03-22 18:58:21 -0700 | [diff] [blame] | 3910 | int count = mChildrenCount; |
| 3911 | int[] visibilities = null; |
| 3912 | |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 3913 | if (skipChildren) { |
Romain Guy | 65554f2 | 2010-03-22 18:58:21 -0700 | [diff] [blame] | 3914 | visibilities = new int[count]; |
| 3915 | for (int i = 0; i < count; i++) { |
| 3916 | View child = getChildAt(i); |
| 3917 | visibilities[i] = child.getVisibility(); |
| 3918 | if (visibilities[i] == View.VISIBLE) { |
sergeyv | b37d44e | 2016-03-29 20:27:44 -0700 | [diff] [blame] | 3919 | child.mViewFlags = (child.mViewFlags & ~View.VISIBILITY_MASK) |
| 3920 | | (View.INVISIBLE & View.VISIBILITY_MASK); |
Romain Guy | 65554f2 | 2010-03-22 18:58:21 -0700 | [diff] [blame] | 3921 | } |
| 3922 | } |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 3923 | } |
| 3924 | |
Sunny Goyal | d1b287e | 2018-01-04 09:37:22 -0800 | [diff] [blame] | 3925 | try { |
| 3926 | return super.createSnapshot(canvasProvider, skipChildren); |
| 3927 | } finally { |
| 3928 | if (skipChildren) { |
| 3929 | for (int i = 0; i < count; i++) { |
| 3930 | View child = getChildAt(i); |
| 3931 | child.mViewFlags = (child.mViewFlags & ~View.VISIBILITY_MASK) |
| 3932 | | (visibilities[i] & View.VISIBILITY_MASK); |
| 3933 | } |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 3934 | } |
Romain Guy | 65554f2 | 2010-03-22 18:58:21 -0700 | [diff] [blame] | 3935 | } |
Romain Guy | 223ff5c | 2010-03-02 17:07:47 -0800 | [diff] [blame] | 3936 | } |
| 3937 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 3938 | /** Return true if this ViewGroup is laying out using optical bounds. */ |
| 3939 | boolean isLayoutModeOptical() { |
| 3940 | return mLayoutMode == LAYOUT_MODE_OPTICAL_BOUNDS; |
| 3941 | } |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 3942 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 3943 | @Override |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 3944 | Insets computeOpticalInsets() { |
| 3945 | if (isLayoutModeOptical()) { |
| 3946 | int left = 0; |
| 3947 | int top = 0; |
| 3948 | int right = 0; |
| 3949 | int bottom = 0; |
| 3950 | for (int i = 0; i < mChildrenCount; i++) { |
| 3951 | View child = getChildAt(i); |
| 3952 | if (child.getVisibility() == VISIBLE) { |
| 3953 | Insets insets = child.getOpticalInsets(); |
| 3954 | left = Math.max(left, insets.left); |
| 3955 | top = Math.max(top, insets.top); |
| 3956 | right = Math.max(right, insets.right); |
| 3957 | bottom = Math.max(bottom, insets.bottom); |
| 3958 | } |
| 3959 | } |
| 3960 | return Insets.of(left, top, right, bottom); |
| 3961 | } else { |
| 3962 | return Insets.NONE; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | private static void fillRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { |
| 3967 | if (x1 != x2 && y1 != y2) { |
| 3968 | if (x1 > x2) { |
| 3969 | int tmp = x1; x1 = x2; x2 = tmp; |
| 3970 | } |
| 3971 | if (y1 > y2) { |
| 3972 | int tmp = y1; y1 = y2; y2 = tmp; |
| 3973 | } |
| 3974 | canvas.drawRect(x1, y1, x2, y2, paint); |
| 3975 | } |
| 3976 | } |
| 3977 | |
| 3978 | private static int sign(int x) { |
| 3979 | return (x >= 0) ? 1 : -1; |
| 3980 | } |
| 3981 | |
| 3982 | private static void drawCorner(Canvas c, Paint paint, int x1, int y1, int dx, int dy, int lw) { |
| 3983 | fillRect(c, paint, x1, y1, x1 + dx, y1 + lw * sign(dy)); |
| 3984 | fillRect(c, paint, x1, y1, x1 + lw * sign(dx), y1 + dy); |
| 3985 | } |
| 3986 | |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 3987 | private static void drawRectCorners(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint, |
| 3988 | int lineLength, int lineWidth) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 3989 | drawCorner(canvas, paint, x1, y1, lineLength, lineLength, lineWidth); |
| 3990 | drawCorner(canvas, paint, x1, y2, lineLength, -lineLength, lineWidth); |
| 3991 | drawCorner(canvas, paint, x2, y1, -lineLength, lineLength, lineWidth); |
| 3992 | drawCorner(canvas, paint, x2, y2, -lineLength, -lineLength, lineWidth); |
| 3993 | } |
| 3994 | |
| 3995 | private static void fillDifference(Canvas canvas, |
| 3996 | int x2, int y2, int x3, int y3, |
| 3997 | int dx1, int dy1, int dx2, int dy2, Paint paint) { |
| 3998 | int x1 = x2 - dx1; |
| 3999 | int y1 = y2 - dy1; |
| 4000 | |
| 4001 | int x4 = x3 + dx2; |
| 4002 | int y4 = y3 + dy2; |
| 4003 | |
| 4004 | fillRect(canvas, paint, x1, y1, x4, y2); |
| 4005 | fillRect(canvas, paint, x1, y2, x2, y3); |
| 4006 | fillRect(canvas, paint, x3, y2, x4, y3); |
| 4007 | fillRect(canvas, paint, x1, y3, x4, y4); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | /** |
Alan Viverette | 2d7771c | 2018-01-31 17:04:31 -0500 | [diff] [blame] | 4011 | * @hide |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4012 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4013 | protected void onDebugDrawMargins(Canvas canvas, Paint paint) { |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4014 | for (int i = 0; i < getChildCount(); i++) { |
| 4015 | View c = getChildAt(i); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4016 | c.getLayoutParams().onDebugDraw(c, canvas, paint); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | /** |
Alan Viverette | 2d7771c | 2018-01-31 17:04:31 -0500 | [diff] [blame] | 4021 | * @hide |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4022 | */ |
| 4023 | protected void onDebugDraw(Canvas canvas) { |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4024 | Paint paint = getDebugPaint(); |
| 4025 | |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4026 | // Draw optical bounds |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4027 | { |
| 4028 | paint.setColor(Color.RED); |
| 4029 | paint.setStyle(Paint.Style.STROKE); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4030 | |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4031 | for (int i = 0; i < getChildCount(); i++) { |
| 4032 | View c = getChildAt(i); |
Chris Craik | a1dab8b | 2015-06-30 13:51:25 -0700 | [diff] [blame] | 4033 | if (c.getVisibility() != View.GONE) { |
| 4034 | Insets insets = c.getOpticalInsets(); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4035 | |
Chris Craik | a1dab8b | 2015-06-30 13:51:25 -0700 | [diff] [blame] | 4036 | drawRect(canvas, paint, |
| 4037 | c.getLeft() + insets.left, |
| 4038 | c.getTop() + insets.top, |
| 4039 | c.getRight() - insets.right - 1, |
| 4040 | c.getBottom() - insets.bottom - 1); |
| 4041 | } |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4042 | } |
| 4043 | } |
| 4044 | |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4045 | // Draw margins |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4046 | { |
| 4047 | paint.setColor(Color.argb(63, 255, 0, 255)); |
| 4048 | paint.setStyle(Paint.Style.FILL); |
Philip Milne | 604f440 | 2012-04-24 19:27:11 -0700 | [diff] [blame] | 4049 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4050 | onDebugDrawMargins(canvas, paint); |
| 4051 | } |
| 4052 | |
| 4053 | // Draw clip bounds |
| 4054 | { |
Vadim Tryshev | cdf38ba | 2016-10-11 18:33:10 -0700 | [diff] [blame] | 4055 | paint.setColor(DEBUG_CORNERS_COLOR); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4056 | paint.setStyle(Paint.Style.FILL); |
| 4057 | |
Vadim Tryshev | cdf38ba | 2016-10-11 18:33:10 -0700 | [diff] [blame] | 4058 | int lineLength = dipsToPixels(DEBUG_CORNERS_SIZE_DIP); |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4059 | int lineWidth = dipsToPixels(1); |
| 4060 | for (int i = 0; i < getChildCount(); i++) { |
| 4061 | View c = getChildAt(i); |
Chris Craik | a1dab8b | 2015-06-30 13:51:25 -0700 | [diff] [blame] | 4062 | if (c.getVisibility() != View.GONE) { |
| 4063 | drawRectCorners(canvas, c.getLeft(), c.getTop(), c.getRight(), c.getBottom(), |
| 4064 | paint, lineLength, lineWidth); |
| 4065 | } |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 4066 | } |
Philip Milne | 604f440 | 2012-04-24 19:27:11 -0700 | [diff] [blame] | 4067 | } |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | @Override |
| 4071 | protected void dispatchDraw(Canvas canvas) { |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 4072 | boolean usingRenderNodeProperties = canvas.isRecordingFor(mRenderNode); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4073 | final int childrenCount = mChildrenCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | final View[] children = mChildren; |
| 4075 | int flags = mGroupFlags; |
| 4076 | |
| 4077 | if ((flags & FLAG_RUN_ANIMATION) != 0 && canAnimate()) { |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 4078 | final boolean buildCache = !isHardwareAccelerated(); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4079 | for (int i = 0; i < childrenCount; i++) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | final View child = children[i]; |
| 4081 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { |
| 4082 | final LayoutParams params = child.getLayoutParams(); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4083 | attachLayoutAnimationParameters(child, params, i, childrenCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | bindLayoutAnimation(child); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | final LayoutAnimationController controller = mLayoutAnimationController; |
| 4089 | if (controller.willOverlap()) { |
| 4090 | mGroupFlags |= FLAG_OPTIMIZE_INVALIDATE; |
| 4091 | } |
| 4092 | |
| 4093 | controller.start(); |
| 4094 | |
| 4095 | mGroupFlags &= ~FLAG_RUN_ANIMATION; |
| 4096 | mGroupFlags &= ~FLAG_ANIMATION_DONE; |
| 4097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | if (mAnimationListener != null) { |
| 4099 | mAnimationListener.onAnimationStart(controller.getAnimation()); |
| 4100 | } |
| 4101 | } |
| 4102 | |
Selim Cinek | 19cadc2 | 2014-04-16 17:27:19 +0200 | [diff] [blame] | 4103 | int clipSaveCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4104 | final boolean clipToPadding = (flags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK; |
| 4105 | if (clipToPadding) { |
John Reck | 41f864e | 2016-05-12 15:07:49 -0700 | [diff] [blame] | 4106 | clipSaveCount = canvas.save(Canvas.CLIP_SAVE_FLAG); |
Romain Guy | 8f2d94f | 2009-03-25 18:04:42 -0700 | [diff] [blame] | 4107 | canvas.clipRect(mScrollX + mPaddingLeft, mScrollY + mPaddingTop, |
| 4108 | mScrollX + mRight - mLeft - mPaddingRight, |
| 4109 | mScrollY + mBottom - mTop - mPaddingBottom); |
Selim Cinek | 19cadc2 | 2014-04-16 17:27:19 +0200 | [diff] [blame] | 4110 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | // We will draw our child's animation, let's reset the flag |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4113 | mPrivateFlags &= ~PFLAG_DRAW_ANIMATION; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | mGroupFlags &= ~FLAG_INVALIDATE_REQUIRED; |
| 4115 | |
| 4116 | boolean more = false; |
| 4117 | final long drawingTime = getDrawingTime(); |
| 4118 | |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 4119 | if (usingRenderNodeProperties) canvas.insertReorderBarrier(); |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4120 | final int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 4121 | int transientIndex = transientCount != 0 ? 0 : -1; |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4122 | // Only use the preordered list if not HW accelerated, since the HW pipeline will do the |
| 4123 | // draw reordering internally |
Chris Craik | a753f4c | 2014-07-24 12:39:17 -0700 | [diff] [blame] | 4124 | final ArrayList<View> preorderedList = usingRenderNodeProperties |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4125 | ? null : buildOrderedChildList(); |
| 4126 | final boolean customOrder = preorderedList == null |
| 4127 | && isChildrenDrawingOrderEnabled(); |
| 4128 | for (int i = 0; i < childrenCount; i++) { |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4129 | while (transientIndex >= 0 && mTransientIndices.get(transientIndex) == i) { |
| 4130 | final View transientChild = mTransientViews.get(transientIndex); |
| 4131 | if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE || |
| 4132 | transientChild.getAnimation() != null) { |
| 4133 | more |= drawChild(canvas, transientChild, drawingTime); |
| 4134 | } |
| 4135 | transientIndex++; |
| 4136 | if (transientIndex >= transientCount) { |
| 4137 | transientIndex = -1; |
| 4138 | } |
| 4139 | } |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4140 | |
| 4141 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 4142 | final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4143 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) { |
| 4144 | more |= drawChild(canvas, child, drawingTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | } |
| 4146 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4147 | while (transientIndex >= 0) { |
| 4148 | // there may be additional transient views after the normal views |
| 4149 | final View transientChild = mTransientViews.get(transientIndex); |
| 4150 | if ((transientChild.mViewFlags & VISIBILITY_MASK) == VISIBLE || |
| 4151 | transientChild.getAnimation() != null) { |
| 4152 | more |= drawChild(canvas, transientChild, drawingTime); |
| 4153 | } |
| 4154 | transientIndex++; |
| 4155 | if (transientIndex >= transientCount) { |
| 4156 | break; |
| 4157 | } |
| 4158 | } |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4159 | if (preorderedList != null) preorderedList.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | |
| 4161 | // Draw any disappearing views that have animations |
| 4162 | if (mDisappearingChildren != null) { |
| 4163 | final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 4164 | final int disappearingCount = disappearingChildren.size() - 1; |
| 4165 | // Go backwards -- we may delete as animations finish |
| 4166 | for (int i = disappearingCount; i >= 0; i--) { |
| 4167 | final View child = disappearingChildren.get(i); |
| 4168 | more |= drawChild(canvas, child, drawingTime); |
| 4169 | } |
| 4170 | } |
Chris Craik | 8afd0f2 | 2014-08-21 17:41:57 -0700 | [diff] [blame] | 4171 | if (usingRenderNodeProperties) canvas.insertInorderBarrier(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 4173 | if (debugDraw()) { |
| 4174 | onDebugDraw(canvas); |
| 4175 | } |
| 4176 | |
Chris Craik | e4cf152 | 2014-08-04 17:55:22 -0700 | [diff] [blame] | 4177 | if (clipToPadding) { |
Selim Cinek | 19cadc2 | 2014-04-16 17:27:19 +0200 | [diff] [blame] | 4178 | canvas.restoreToCount(clipSaveCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | // mGroupFlags might have been updated by drawChild() |
| 4182 | flags = mGroupFlags; |
| 4183 | |
| 4184 | if ((flags & FLAG_INVALIDATE_REQUIRED) == FLAG_INVALIDATE_REQUIRED) { |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 4185 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | if ((flags & FLAG_ANIMATION_DONE) == 0 && (flags & FLAG_NOTIFY_ANIMATION_LISTENER) == 0 && |
| 4189 | mLayoutAnimationController.isDone() && !more) { |
| 4190 | // We want to erase the drawing cache and notify the listener after the |
| 4191 | // next frame is drawn because one extra invalidate() is caused by |
| 4192 | // drawChild() after the animation is over |
| 4193 | mGroupFlags |= FLAG_NOTIFY_ANIMATION_LISTENER; |
| 4194 | final Runnable end = new Runnable() { |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 4195 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | public void run() { |
| 4197 | notifyAnimationListener(); |
| 4198 | } |
| 4199 | }; |
| 4200 | post(end); |
| 4201 | } |
| 4202 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4204 | /** |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 4205 | * Returns the ViewGroupOverlay for this view group, creating it if it does |
| 4206 | * not yet exist. In addition to {@link ViewOverlay}'s support for drawables, |
| 4207 | * {@link ViewGroupOverlay} allows views to be added to the overlay. These |
| 4208 | * views, like overlay drawables, are visual-only; they do not receive input |
| 4209 | * events and should not be used as anything other than a temporary |
| 4210 | * representation of a view in a parent container, such as might be used |
| 4211 | * by an animation effect. |
| 4212 | * |
Chet Haase | 9539949 | 2013-04-08 14:30:31 -0700 | [diff] [blame] | 4213 | * <p>Note: Overlays do not currently work correctly with {@link |
| 4214 | * SurfaceView} or {@link TextureView}; contents in overlays for these |
| 4215 | * types of views may not display correctly.</p> |
| 4216 | * |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 4217 | * @return The ViewGroupOverlay object for this view. |
| 4218 | * @see ViewGroupOverlay |
| 4219 | */ |
| 4220 | @Override |
| 4221 | public ViewGroupOverlay getOverlay() { |
| 4222 | if (mOverlay == null) { |
| 4223 | mOverlay = new ViewGroupOverlay(mContext, this); |
| 4224 | } |
| 4225 | return (ViewGroupOverlay) mOverlay; |
| 4226 | } |
| 4227 | |
| 4228 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | * Returns the index of the child to draw for this iteration. Override this |
| 4230 | * if you want to change the drawing order of children. By default, it |
| 4231 | * returns i. |
| 4232 | * <p> |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 4233 | * NOTE: In order for this method to be called, you must enable child ordering |
| 4234 | * first by calling {@link #setChildrenDrawingOrderEnabled(boolean)}. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4235 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4236 | * @param i The current iteration. |
| 4237 | * @return The index of the child to draw this iteration. |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 4238 | * |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 4239 | * @see #setChildrenDrawingOrderEnabled(boolean) |
| 4240 | * @see #isChildrenDrawingOrderEnabled() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | */ |
| 4242 | protected int getChildDrawingOrder(int childCount, int i) { |
| 4243 | return i; |
| 4244 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4245 | |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4246 | private boolean hasChildWithZ() { |
| 4247 | for (int i = 0; i < mChildrenCount; i++) { |
| 4248 | if (mChildren[i].getZ() != 0) return true; |
| 4249 | } |
| 4250 | return false; |
| 4251 | } |
| 4252 | |
| 4253 | /** |
| 4254 | * Populates (and returns) mPreSortedChildren with a pre-ordered list of the View's children, |
Chris Craik | 57c79c8 | 2014-09-30 12:54:31 -0700 | [diff] [blame] | 4255 | * sorted first by Z, then by child drawing order (if applicable). This list must be cleared |
| 4256 | * after use to avoid leaking child Views. |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4257 | * |
| 4258 | * Uses a stable, insertion sort which is commonly O(n) for ViewGroups with very few elevated |
| 4259 | * children. |
| 4260 | */ |
George Mount | 8120652 | 2014-09-26 21:53:39 -0700 | [diff] [blame] | 4261 | ArrayList<View> buildOrderedChildList() { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4262 | final int childrenCount = mChildrenCount; |
| 4263 | if (childrenCount <= 1 || !hasChildWithZ()) return null; |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4264 | |
| 4265 | if (mPreSortedChildren == null) { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4266 | mPreSortedChildren = new ArrayList<>(childrenCount); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4267 | } else { |
Chris Craik | fc56377 | 2016-05-04 13:34:30 -0700 | [diff] [blame] | 4268 | // callers should clear, so clear shouldn't be necessary, but for safety... |
| 4269 | mPreSortedChildren.clear(); |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4270 | mPreSortedChildren.ensureCapacity(childrenCount); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4273 | final boolean customOrder = isChildrenDrawingOrderEnabled(); |
| 4274 | for (int i = 0; i < childrenCount; i++) { |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4275 | // add next child (in child order) to end of list |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 4276 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 4277 | final View nextChild = mChildren[childIndex]; |
| 4278 | final float currentZ = nextChild.getZ(); |
Chris Craik | ab008f0 | 2014-05-23 17:55:03 -0700 | [diff] [blame] | 4279 | |
| 4280 | // insert ahead of any Views with greater Z |
| 4281 | int insertIndex = i; |
| 4282 | while (insertIndex > 0 && mPreSortedChildren.get(insertIndex - 1).getZ() > currentZ) { |
| 4283 | insertIndex--; |
| 4284 | } |
| 4285 | mPreSortedChildren.add(insertIndex, nextChild); |
| 4286 | } |
| 4287 | return mPreSortedChildren; |
| 4288 | } |
| 4289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | private void notifyAnimationListener() { |
| 4291 | mGroupFlags &= ~FLAG_NOTIFY_ANIMATION_LISTENER; |
| 4292 | mGroupFlags |= FLAG_ANIMATION_DONE; |
| 4293 | |
| 4294 | if (mAnimationListener != null) { |
| 4295 | final Runnable end = new Runnable() { |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 4296 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | public void run() { |
| 4298 | mAnimationListener.onAnimationEnd(mLayoutAnimationController.getAnimation()); |
| 4299 | } |
| 4300 | }; |
| 4301 | post(end); |
| 4302 | } |
| 4303 | |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 4304 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /** |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 4308 | * This method is used to cause children of this ViewGroup to restore or recreate their |
| 4309 | * display lists. It is called by getDisplayList() when the parent ViewGroup does not need |
| 4310 | * to recreate its own display list, which would happen if it went through the normal |
| 4311 | * draw/dispatchDraw mechanisms. |
| 4312 | * |
| 4313 | * @hide |
| 4314 | */ |
| 4315 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4316 | @UnsupportedAppUsage |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 4317 | protected void dispatchGetDisplayList() { |
| 4318 | final int count = mChildrenCount; |
| 4319 | final View[] children = mChildren; |
| 4320 | for (int i = 0; i < count; i++) { |
| 4321 | final View child = children[i]; |
John Reck | c2330f5 | 2015-04-28 13:18:52 -0700 | [diff] [blame] | 4322 | if (((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null)) { |
Chet Haase | 6c0665f | 2014-08-01 13:32:27 -0700 | [diff] [blame] | 4323 | recreateChildDisplayList(child); |
Romain Guy | 2f57ba5 | 2011-02-03 18:03:29 -0800 | [diff] [blame] | 4324 | } |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 4325 | } |
Selim Cinek | d6a51b1 | 2018-03-15 17:10:20 -0700 | [diff] [blame] | 4326 | final int transientCount = mTransientViews == null ? 0 : mTransientIndices.size(); |
| 4327 | for (int i = 0; i < transientCount; ++i) { |
| 4328 | View child = mTransientViews.get(i); |
| 4329 | if (((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null)) { |
| 4330 | recreateChildDisplayList(child); |
| 4331 | } |
| 4332 | } |
Chet Haase | 91cedf1 | 2013-03-11 07:56:30 -0700 | [diff] [blame] | 4333 | if (mOverlay != null) { |
Chet Haase | edf6f4b | 2013-03-26 07:55:30 -0700 | [diff] [blame] | 4334 | View overlayView = mOverlay.getOverlayView(); |
Chet Haase | 6c0665f | 2014-08-01 13:32:27 -0700 | [diff] [blame] | 4335 | recreateChildDisplayList(overlayView); |
Chet Haase | 91cedf1 | 2013-03-11 07:56:30 -0700 | [diff] [blame] | 4336 | } |
Chet Haase | 6c0665f | 2014-08-01 13:32:27 -0700 | [diff] [blame] | 4337 | if (mDisappearingChildren != null) { |
| 4338 | final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 4339 | final int disappearingCount = disappearingChildren.size(); |
| 4340 | for (int i = 0; i < disappearingCount; ++i) { |
| 4341 | final View child = disappearingChildren.get(i); |
| 4342 | recreateChildDisplayList(child); |
| 4343 | } |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | private void recreateChildDisplayList(View child) { |
Chris Craik | 31a2d06 | 2015-05-01 14:22:47 -0700 | [diff] [blame] | 4348 | child.mRecreateDisplayList = (child.mPrivateFlags & PFLAG_INVALIDATED) != 0; |
Chet Haase | 6c0665f | 2014-08-01 13:32:27 -0700 | [diff] [blame] | 4349 | child.mPrivateFlags &= ~PFLAG_INVALIDATED; |
Chris Craik | 31a2d06 | 2015-05-01 14:22:47 -0700 | [diff] [blame] | 4350 | child.updateDisplayListIfDirty(); |
Chet Haase | 6c0665f | 2014-08-01 13:32:27 -0700 | [diff] [blame] | 4351 | child.mRecreateDisplayList = false; |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | * Draw one child of this View Group. This method is responsible for getting |
| 4356 | * the canvas in the right state. This includes clipping, translating so |
| 4357 | * that the child's scrolled origin is at 0, 0, and applying any animation |
| 4358 | * transformations. |
| 4359 | * |
| 4360 | * @param canvas The canvas on which to draw the child |
| 4361 | * @param child Who to draw |
Chet Haase | bcca79a | 2012-02-14 08:45:14 -0800 | [diff] [blame] | 4362 | * @param drawingTime The time at which draw is occurring |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | * @return True if an invalidate() was issued |
| 4364 | */ |
| 4365 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 4366 | return child.draw(canvas, this, drawingTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | } |
| 4368 | |
Alan Viverette | 922e1c6 | 2015-05-05 17:18:27 -0700 | [diff] [blame] | 4369 | @Override |
| 4370 | void getScrollIndicatorBounds(@NonNull Rect out) { |
| 4371 | super.getScrollIndicatorBounds(out); |
| 4372 | |
| 4373 | // If we have padding and we're supposed to clip children to that |
| 4374 | // padding, offset the scroll indicators to match our clip bounds. |
| 4375 | final boolean clipToPadding = (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK; |
| 4376 | if (clipToPadding) { |
| 4377 | out.left += mPaddingLeft; |
| 4378 | out.right -= mPaddingRight; |
| 4379 | out.top += mPaddingTop; |
| 4380 | out.bottom -= mPaddingBottom; |
| 4381 | } |
| 4382 | } |
| 4383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | /** |
Chris Craik | d863a10 | 2013-12-19 13:31:15 -0800 | [diff] [blame] | 4385 | * Returns whether this group's children are clipped to their bounds before drawing. |
Chet Haase | 430742f | 2013-04-12 11:18:36 -0700 | [diff] [blame] | 4386 | * The default value is true. |
| 4387 | * @see #setClipChildren(boolean) |
| 4388 | * |
| 4389 | * @return True if the group's children will be clipped to their bounds, |
| 4390 | * false otherwise. |
| 4391 | */ |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 4392 | @ViewDebug.ExportedProperty(category = "drawing") |
Chet Haase | 430742f | 2013-04-12 11:18:36 -0700 | [diff] [blame] | 4393 | public boolean getClipChildren() { |
| 4394 | return ((mGroupFlags & FLAG_CLIP_CHILDREN) != 0); |
| 4395 | } |
| 4396 | |
| 4397 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | * By default, children are clipped to their bounds before drawing. This |
| 4399 | * allows view groups to override this behavior for animations, etc. |
| 4400 | * |
| 4401 | * @param clipChildren true to clip children to their bounds, |
| 4402 | * false otherwise |
| 4403 | * @attr ref android.R.styleable#ViewGroup_clipChildren |
| 4404 | */ |
| 4405 | public void setClipChildren(boolean clipChildren) { |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 4406 | boolean previousValue = (mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN; |
| 4407 | if (clipChildren != previousValue) { |
| 4408 | setBooleanFlag(FLAG_CLIP_CHILDREN, clipChildren); |
Chet Haase | 1271e2c | 2012-04-20 09:54:27 -0700 | [diff] [blame] | 4409 | for (int i = 0; i < mChildrenCount; ++i) { |
| 4410 | View child = getChildAt(i); |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 4411 | if (child.mRenderNode != null) { |
| 4412 | child.mRenderNode.setClipToBounds(clipChildren); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 4413 | } |
| 4414 | } |
John Reck | aae9f3b | 2014-07-28 09:30:36 -0700 | [diff] [blame] | 4415 | invalidate(true); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 4416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | /** |
Doris Liu | b134b5e | 2015-05-28 17:26:46 -0700 | [diff] [blame] | 4420 | * Sets whether this ViewGroup will clip its children to its padding and resize (but not |
| 4421 | * clip) any EdgeEffect to the padded region, if padding is present. |
Chris Craik | b165296 | 2014-11-14 17:05:06 -0800 | [diff] [blame] | 4422 | * <p> |
| 4423 | * By default, children are clipped to the padding of their parent |
Doris Liu | b134b5e | 2015-05-28 17:26:46 -0700 | [diff] [blame] | 4424 | * ViewGroup. This clipping behavior is only enabled if padding is non-zero. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | * |
Doris Liu | b134b5e | 2015-05-28 17:26:46 -0700 | [diff] [blame] | 4426 | * @param clipToPadding true to clip children to the padding of the group, and resize (but |
| 4427 | * not clip) any EdgeEffect to the padded region. False otherwise. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | * @attr ref android.R.styleable#ViewGroup_clipToPadding |
| 4429 | */ |
| 4430 | public void setClipToPadding(boolean clipToPadding) { |
John Reck | 9fa3a24 | 2014-06-27 15:57:19 -0700 | [diff] [blame] | 4431 | if (hasBooleanFlag(FLAG_CLIP_TO_PADDING) != clipToPadding) { |
| 4432 | setBooleanFlag(FLAG_CLIP_TO_PADDING, clipToPadding); |
John Reck | aae9f3b | 2014-07-28 09:30:36 -0700 | [diff] [blame] | 4433 | invalidate(true); |
John Reck | 9fa3a24 | 2014-06-27 15:57:19 -0700 | [diff] [blame] | 4434 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | /** |
Doris Liu | b134b5e | 2015-05-28 17:26:46 -0700 | [diff] [blame] | 4438 | * Returns whether this ViewGroup will clip its children to its padding, and resize (but |
| 4439 | * not clip) any EdgeEffect to the padded region, if padding is present. |
Chris Craik | b165296 | 2014-11-14 17:05:06 -0800 | [diff] [blame] | 4440 | * <p> |
| 4441 | * By default, children are clipped to the padding of their parent |
| 4442 | * Viewgroup. This clipping behavior is only enabled if padding is non-zero. |
Adam Powell | 1c35b08 | 2014-07-11 15:37:15 -0700 | [diff] [blame] | 4443 | * |
Doris Liu | b134b5e | 2015-05-28 17:26:46 -0700 | [diff] [blame] | 4444 | * @return true if this ViewGroup clips children to its padding and resizes (but doesn't |
| 4445 | * clip) any EdgeEffect to the padded region, false otherwise. |
Adam Powell | 1c35b08 | 2014-07-11 15:37:15 -0700 | [diff] [blame] | 4446 | * |
| 4447 | * @attr ref android.R.styleable#ViewGroup_clipToPadding |
| 4448 | */ |
Chris Craik | 5c75c52 | 2014-09-05 14:08:08 -0700 | [diff] [blame] | 4449 | @ViewDebug.ExportedProperty(category = "drawing") |
Adam Powell | 1c35b08 | 2014-07-11 15:37:15 -0700 | [diff] [blame] | 4450 | public boolean getClipToPadding() { |
| 4451 | return hasBooleanFlag(FLAG_CLIP_TO_PADDING); |
| 4452 | } |
| 4453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | @Override |
| 4455 | public void dispatchSetSelected(boolean selected) { |
| 4456 | final View[] children = mChildren; |
| 4457 | final int count = mChildrenCount; |
| 4458 | for (int i = 0; i < count; i++) { |
| 4459 | children[i].setSelected(selected); |
| 4460 | } |
| 4461 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4462 | |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 4463 | @Override |
| 4464 | public void dispatchSetActivated(boolean activated) { |
| 4465 | final View[] children = mChildren; |
| 4466 | final int count = mChildrenCount; |
| 4467 | for (int i = 0; i < count; i++) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 4468 | children[i].setActivated(activated); |
| 4469 | } |
| 4470 | } |
| 4471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | @Override |
| 4473 | protected void dispatchSetPressed(boolean pressed) { |
| 4474 | final View[] children = mChildren; |
| 4475 | final int count = mChildrenCount; |
| 4476 | for (int i = 0; i < count; i++) { |
Adam Powell | 035a1fc | 2012-02-27 15:23:50 -0800 | [diff] [blame] | 4477 | final View child = children[i]; |
| 4478 | // Children that are clickable on their own should not |
| 4479 | // show a pressed state when their parent view does. |
| 4480 | // Clearing a pressed state always propagates. |
| 4481 | if (!pressed || (!child.isClickable() && !child.isLongClickable())) { |
| 4482 | child.setPressed(pressed); |
| 4483 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
Alan Viverette | b942b6f | 2014-12-08 10:37:39 -0800 | [diff] [blame] | 4487 | /** |
| 4488 | * Dispatches drawable hotspot changes to child views that meet at least |
| 4489 | * one of the following criteria: |
| 4490 | * <ul> |
| 4491 | * <li>Returns {@code false} from both {@link View#isClickable()} and |
| 4492 | * {@link View#isLongClickable()}</li> |
| 4493 | * <li>Requests duplication of parent state via |
| 4494 | * {@link View#setDuplicateParentStateEnabled(boolean)}</li> |
| 4495 | * </ul> |
| 4496 | * |
| 4497 | * @param x hotspot x coordinate |
| 4498 | * @param y hotspot y coordinate |
| 4499 | * @see #drawableHotspotChanged(float, float) |
| 4500 | */ |
| 4501 | @Override |
| 4502 | public void dispatchDrawableHotspotChanged(float x, float y) { |
| 4503 | final int count = mChildrenCount; |
| 4504 | if (count == 0) { |
| 4505 | return; |
| 4506 | } |
| 4507 | |
| 4508 | final View[] children = mChildren; |
| 4509 | for (int i = 0; i < count; i++) { |
| 4510 | final View child = children[i]; |
| 4511 | // Children that are clickable on their own should not |
| 4512 | // receive hotspots when their parent view does. |
| 4513 | final boolean nonActionable = !child.isClickable() && !child.isLongClickable(); |
| 4514 | final boolean duplicatesState = (child.mViewFlags & DUPLICATE_PARENT_STATE) != 0; |
| 4515 | if (nonActionable || duplicatesState) { |
| 4516 | final float[] point = getTempPoint(); |
| 4517 | point[0] = x; |
| 4518 | point[1] = y; |
| 4519 | transformPointToViewLocal(point, child); |
| 4520 | child.drawableHotspotChanged(point[0], point[1]); |
| 4521 | } |
| 4522 | } |
| 4523 | } |
| 4524 | |
Adam Powell | 1487466 | 2013-07-18 19:42:41 -0700 | [diff] [blame] | 4525 | @Override |
| 4526 | void dispatchCancelPendingInputEvents() { |
| 4527 | super.dispatchCancelPendingInputEvents(); |
| 4528 | |
| 4529 | final View[] children = mChildren; |
| 4530 | final int count = mChildrenCount; |
| 4531 | for (int i = 0; i < count; i++) { |
| 4532 | children[i].dispatchCancelPendingInputEvents(); |
| 4533 | } |
| 4534 | } |
| 4535 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | /** |
| 4537 | * When this property is set to true, this ViewGroup supports static transformations on |
| 4538 | * children; this causes |
| 4539 | * {@link #getChildStaticTransformation(View, android.view.animation.Transformation)} to be |
| 4540 | * invoked when a child is drawn. |
| 4541 | * |
| 4542 | * Any subclass overriding |
| 4543 | * {@link #getChildStaticTransformation(View, android.view.animation.Transformation)} should |
| 4544 | * set this property to true. |
| 4545 | * |
| 4546 | * @param enabled True to enable static transformations on children, false otherwise. |
| 4547 | * |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 4548 | * @see #getChildStaticTransformation(View, android.view.animation.Transformation) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4549 | */ |
| 4550 | protected void setStaticTransformationsEnabled(boolean enabled) { |
| 4551 | setBooleanFlag(FLAG_SUPPORT_STATIC_TRANSFORMATIONS, enabled); |
| 4552 | } |
| 4553 | |
| 4554 | /** |
Chet Haase | 2d46fcc | 2011-12-19 18:01:05 -0800 | [diff] [blame] | 4555 | * Sets <code>t</code> to be the static transformation of the child, if set, returning a |
| 4556 | * boolean to indicate whether a static transform was set. The default implementation |
| 4557 | * simply returns <code>false</code>; subclasses may override this method for different |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 4558 | * behavior. {@link #setStaticTransformationsEnabled(boolean)} must be set to true |
| 4559 | * for this method to be called. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | * |
Chet Haase | 2d46fcc | 2011-12-19 18:01:05 -0800 | [diff] [blame] | 4561 | * @param child The child view whose static transform is being requested |
| 4562 | * @param t The Transformation which will hold the result |
| 4563 | * @return true if the transformation was set, false otherwise |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 4564 | * @see #setStaticTransformationsEnabled(boolean) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4565 | */ |
| 4566 | protected boolean getChildStaticTransformation(View child, Transformation t) { |
| 4567 | return false; |
| 4568 | } |
| 4569 | |
Romain Guy | f699130 | 2013-06-05 17:19:01 -0700 | [diff] [blame] | 4570 | Transformation getChildTransformation() { |
| 4571 | if (mChildTransformation == null) { |
| 4572 | mChildTransformation = new Transformation(); |
| 4573 | } |
| 4574 | return mChildTransformation; |
| 4575 | } |
| 4576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | /** |
| 4578 | * {@hide} |
| 4579 | */ |
| 4580 | @Override |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4581 | protected <T extends View> T findViewTraversal(@IdRes int id) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | if (id == mID) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4583 | return (T) this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | final View[] where = mChildren; |
| 4587 | final int len = mChildrenCount; |
| 4588 | |
| 4589 | for (int i = 0; i < len; i++) { |
| 4590 | View v = where[i]; |
| 4591 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4592 | if ((v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4593 | v = v.findViewById(id); |
| 4594 | |
| 4595 | if (v != null) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4596 | return (T) v; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | } |
| 4598 | } |
| 4599 | } |
| 4600 | |
| 4601 | return null; |
| 4602 | } |
| 4603 | |
| 4604 | /** |
| 4605 | * {@hide} |
| 4606 | */ |
| 4607 | @Override |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4608 | protected <T extends View> T findViewWithTagTraversal(Object tag) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | if (tag != null && tag.equals(mTag)) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4610 | return (T) this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | final View[] where = mChildren; |
| 4614 | final int len = mChildrenCount; |
| 4615 | |
| 4616 | for (int i = 0; i < len; i++) { |
| 4617 | View v = where[i]; |
| 4618 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4619 | if ((v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | v = v.findViewWithTag(tag); |
| 4621 | |
| 4622 | if (v != null) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4623 | return (T) v; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4624 | } |
| 4625 | } |
| 4626 | } |
| 4627 | |
| 4628 | return null; |
| 4629 | } |
| 4630 | |
| 4631 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4632 | * {@hide} |
| 4633 | */ |
| 4634 | @Override |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4635 | protected <T extends View> T findViewByPredicateTraversal(Predicate<View> predicate, |
| 4636 | View childToSkip) { |
Paul Duffin | ca4964c | 2017-02-07 15:04:10 +0000 | [diff] [blame] | 4637 | if (predicate.test(this)) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4638 | return (T) this; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | final View[] where = mChildren; |
| 4642 | final int len = mChildrenCount; |
| 4643 | |
| 4644 | for (int i = 0; i < len; i++) { |
| 4645 | View v = where[i]; |
| 4646 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 4647 | if (v != childToSkip && (v.mPrivateFlags & PFLAG_IS_ROOT_NAMESPACE) == 0) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4648 | v = v.findViewByPredicate(predicate); |
| 4649 | |
| 4650 | if (v != null) { |
Alan Viverette | 8e1a729 | 2017-02-27 10:57:58 -0500 | [diff] [blame] | 4651 | return (T) v; |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | return null; |
| 4657 | } |
| 4658 | |
| 4659 | /** |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4660 | * This method adds a view to this container at the specified index purely for the |
| 4661 | * purposes of allowing that view to draw even though it is not a normal child of |
| 4662 | * the container. That is, the view does not participate in layout, focus, accessibility, |
| 4663 | * input, or other normal view operations; it is purely an item to be drawn during the normal |
| 4664 | * rendering operation of this container. The index that it is added at is the order |
| 4665 | * in which it will be drawn, with respect to the other views in the container. |
| 4666 | * For example, a transient view added at index 0 will be drawn before all other views |
| 4667 | * in the container because it will be drawn first (including before any real view |
| 4668 | * at index 0). There can be more than one transient view at any particular index; |
| 4669 | * these views will be drawn in the order in which they were added to the list of |
| 4670 | * transient views. The index of transient views can also be greater than the number |
| 4671 | * of normal views in the container; that just means that they will be drawn after all |
| 4672 | * other views are drawn. |
| 4673 | * |
| 4674 | * <p>Note that since transient views do not participate in layout, they must be sized |
| 4675 | * manually or, more typically, they should just use the size that they had before they |
| 4676 | * were removed from their container.</p> |
| 4677 | * |
| 4678 | * <p>Transient views are useful for handling animations of views that have been removed |
| 4679 | * from the container, but which should be animated out after the removal. Adding these |
| 4680 | * views as transient views allows them to participate in drawing without side-effecting |
| 4681 | * the layout of the container.</p> |
| 4682 | * |
| 4683 | * <p>Transient views must always be explicitly {@link #removeTransientView(View) removed} |
| 4684 | * from the container when they are no longer needed. For example, a transient view |
| 4685 | * which is added in order to fade it out in its old location should be removed |
| 4686 | * once the animation is complete.</p> |
| 4687 | * |
Riddle Hsu | 95459d3 | 2018-06-08 15:54:08 +0800 | [diff] [blame] | 4688 | * @param view The view to be added. The view must not have a parent. |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4689 | * @param index The index at which this view should be drawn, must be >= 0. |
| 4690 | * This value is relative to the {@link #getChildAt(int) index} values in the normal |
| 4691 | * child list of this container, where any transient view at a particular index will |
| 4692 | * be drawn before any normal child at that same index. |
Chris Craik | 66b4139 | 2015-04-17 10:08:10 -0700 | [diff] [blame] | 4693 | * |
| 4694 | * @hide |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4695 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4696 | @UnsupportedAppUsage |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4697 | public void addTransientView(View view, int index) { |
Riddle Hsu | 95459d3 | 2018-06-08 15:54:08 +0800 | [diff] [blame] | 4698 | if (index < 0 || view == null) { |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4699 | return; |
| 4700 | } |
Riddle Hsu | 95459d3 | 2018-06-08 15:54:08 +0800 | [diff] [blame] | 4701 | if (view.mParent != null) { |
| 4702 | throw new IllegalStateException("The specified view already has a parent " |
| 4703 | + view.mParent); |
| 4704 | } |
| 4705 | |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4706 | if (mTransientIndices == null) { |
| 4707 | mTransientIndices = new ArrayList<Integer>(); |
| 4708 | mTransientViews = new ArrayList<View>(); |
| 4709 | } |
| 4710 | final int oldSize = mTransientIndices.size(); |
| 4711 | if (oldSize > 0) { |
| 4712 | int insertionIndex; |
| 4713 | for (insertionIndex = 0; insertionIndex < oldSize; ++insertionIndex) { |
| 4714 | if (index < mTransientIndices.get(insertionIndex)) { |
| 4715 | break; |
| 4716 | } |
| 4717 | } |
| 4718 | mTransientIndices.add(insertionIndex, index); |
| 4719 | mTransientViews.add(insertionIndex, view); |
| 4720 | } else { |
| 4721 | mTransientIndices.add(index); |
| 4722 | mTransientViews.add(view); |
| 4723 | } |
| 4724 | view.mParent = this; |
Riddle Hsu | 95459d3 | 2018-06-08 15:54:08 +0800 | [diff] [blame] | 4725 | if (mAttachInfo != null) { |
| 4726 | view.dispatchAttachedToWindow(mAttachInfo, (mViewFlags & VISIBILITY_MASK)); |
| 4727 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4728 | invalidate(true); |
| 4729 | } |
| 4730 | |
| 4731 | /** |
| 4732 | * Removes a view from the list of transient views in this container. If there is no |
| 4733 | * such transient view, this method does nothing. |
| 4734 | * |
| 4735 | * @param view The transient view to be removed |
Chris Craik | 66b4139 | 2015-04-17 10:08:10 -0700 | [diff] [blame] | 4736 | * |
| 4737 | * @hide |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4738 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4739 | @UnsupportedAppUsage |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4740 | public void removeTransientView(View view) { |
| 4741 | if (mTransientViews == null) { |
| 4742 | return; |
| 4743 | } |
| 4744 | final int size = mTransientViews.size(); |
| 4745 | for (int i = 0; i < size; ++i) { |
| 4746 | if (view == mTransientViews.get(i)) { |
| 4747 | mTransientViews.remove(i); |
| 4748 | mTransientIndices.remove(i); |
| 4749 | view.mParent = null; |
Riddle Hsu | 95459d3 | 2018-06-08 15:54:08 +0800 | [diff] [blame] | 4750 | if (view.mAttachInfo != null) { |
| 4751 | view.dispatchDetachedFromWindow(); |
| 4752 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4753 | invalidate(true); |
| 4754 | return; |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | /** |
| 4760 | * Returns the number of transient views in this container. Specific transient |
| 4761 | * views and the index at which they were added can be retrieved via |
| 4762 | * {@link #getTransientView(int)} and {@link #getTransientViewIndex(int)}. |
| 4763 | * |
| 4764 | * @see #addTransientView(View, int) |
| 4765 | * @return The number of transient views in this container |
Chris Craik | 66b4139 | 2015-04-17 10:08:10 -0700 | [diff] [blame] | 4766 | * |
| 4767 | * @hide |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4768 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4769 | @UnsupportedAppUsage |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4770 | public int getTransientViewCount() { |
| 4771 | return mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 4772 | } |
| 4773 | |
| 4774 | /** |
| 4775 | * Given a valid position within the list of transient views, returns the index of |
| 4776 | * the transient view at that position. |
| 4777 | * |
| 4778 | * @param position The position of the index being queried. Must be at least 0 |
| 4779 | * and less than the value returned by {@link #getTransientViewCount()}. |
| 4780 | * @return The index of the transient view stored in the given position if the |
| 4781 | * position is valid, otherwise -1 |
Chris Craik | 66b4139 | 2015-04-17 10:08:10 -0700 | [diff] [blame] | 4782 | * |
| 4783 | * @hide |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4784 | */ |
| 4785 | public int getTransientViewIndex(int position) { |
| 4786 | if (position < 0 || mTransientIndices == null || position >= mTransientIndices.size()) { |
| 4787 | return -1; |
| 4788 | } |
| 4789 | return mTransientIndices.get(position); |
| 4790 | } |
| 4791 | |
| 4792 | /** |
| 4793 | * Given a valid position within the list of transient views, returns the |
| 4794 | * transient view at that position. |
| 4795 | * |
| 4796 | * @param position The position of the view being queried. Must be at least 0 |
| 4797 | * and less than the value returned by {@link #getTransientViewCount()}. |
| 4798 | * @return The transient view stored in the given position if the |
| 4799 | * position is valid, otherwise null |
Chris Craik | 66b4139 | 2015-04-17 10:08:10 -0700 | [diff] [blame] | 4800 | * |
| 4801 | * @hide |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4802 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4803 | @UnsupportedAppUsage |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 4804 | public View getTransientView(int position) { |
| 4805 | if (mTransientViews == null || position >= mTransientViews.size()) { |
| 4806 | return null; |
| 4807 | } |
| 4808 | return mTransientViews.get(position); |
| 4809 | } |
| 4810 | |
| 4811 | /** |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4812 | * <p>Adds a child view. If no layout parameters are already set on the child, the |
| 4813 | * default parameters for this ViewGroup are set on the child.</p> |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 4814 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4815 | * <p><strong>Note:</strong> do not invoke this method from |
| 4816 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 4817 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | * |
| 4819 | * @param child the child view to add |
| 4820 | * |
| 4821 | * @see #generateDefaultLayoutParams() |
| 4822 | */ |
| 4823 | public void addView(View child) { |
| 4824 | addView(child, -1); |
| 4825 | } |
| 4826 | |
| 4827 | /** |
| 4828 | * Adds a child view. If no layout parameters are already set on the child, the |
| 4829 | * default parameters for this ViewGroup are set on the child. |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 4830 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4831 | * <p><strong>Note:</strong> do not invoke this method from |
| 4832 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 4833 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | * |
| 4835 | * @param child the child view to add |
| 4836 | * @param index the position at which to add the child |
| 4837 | * |
| 4838 | * @see #generateDefaultLayoutParams() |
| 4839 | */ |
| 4840 | public void addView(View child, int index) { |
Adam Powell | 45a9da5 | 2014-10-09 09:44:18 -0700 | [diff] [blame] | 4841 | if (child == null) { |
| 4842 | throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 4843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4844 | LayoutParams params = child.getLayoutParams(); |
| 4845 | if (params == null) { |
| 4846 | params = generateDefaultLayoutParams(); |
| 4847 | if (params == null) { |
| 4848 | throw new IllegalArgumentException("generateDefaultLayoutParams() cannot return null"); |
| 4849 | } |
| 4850 | } |
| 4851 | addView(child, index, params); |
| 4852 | } |
| 4853 | |
| 4854 | /** |
| 4855 | * Adds a child view with this ViewGroup's default layout parameters and the |
| 4856 | * specified width and height. |
| 4857 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4858 | * <p><strong>Note:</strong> do not invoke this method from |
| 4859 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 4860 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
| 4861 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | * @param child the child view to add |
| 4863 | */ |
| 4864 | public void addView(View child, int width, int height) { |
| 4865 | final LayoutParams params = generateDefaultLayoutParams(); |
| 4866 | params.width = width; |
| 4867 | params.height = height; |
| 4868 | addView(child, -1, params); |
| 4869 | } |
| 4870 | |
| 4871 | /** |
| 4872 | * Adds a child view with the specified layout parameters. |
| 4873 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4874 | * <p><strong>Note:</strong> do not invoke this method from |
| 4875 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 4876 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
| 4877 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4878 | * @param child the child view to add |
| 4879 | * @param params the layout parameters to set on the child |
| 4880 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 4881 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4882 | public void addView(View child, LayoutParams params) { |
| 4883 | addView(child, -1, params); |
| 4884 | } |
| 4885 | |
| 4886 | /** |
| 4887 | * Adds a child view with the specified layout parameters. |
| 4888 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 4889 | * <p><strong>Note:</strong> do not invoke this method from |
| 4890 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 4891 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
| 4892 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | * @param child the child view to add |
Alan Viverette | 77bb6f1 | 2015-02-11 17:24:33 -0800 | [diff] [blame] | 4894 | * @param index the position at which to add the child or -1 to add last |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4895 | * @param params the layout parameters to set on the child |
| 4896 | */ |
| 4897 | public void addView(View child, int index, LayoutParams params) { |
| 4898 | if (DBG) { |
| 4899 | System.out.println(this + " addView"); |
| 4900 | } |
| 4901 | |
Adam Powell | 45a9da5 | 2014-10-09 09:44:18 -0700 | [diff] [blame] | 4902 | if (child == null) { |
| 4903 | throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 4904 | } |
| 4905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4906 | // addViewInner() will call child.requestLayout() when setting the new LayoutParams |
| 4907 | // therefore, we call requestLayout() on ourselves before, so that the child's request |
| 4908 | // will be blocked at our level |
| 4909 | requestLayout(); |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 4910 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4911 | addViewInner(child, index, params, false); |
| 4912 | } |
| 4913 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 4914 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | public void updateViewLayout(View view, ViewGroup.LayoutParams params) { |
| 4916 | if (!checkLayoutParams(params)) { |
| 4917 | throw new IllegalArgumentException("Invalid LayoutParams supplied to " + this); |
| 4918 | } |
| 4919 | if (view.mParent != this) { |
| 4920 | throw new IllegalArgumentException("Given view not a child of " + this); |
| 4921 | } |
| 4922 | view.setLayoutParams(params); |
| 4923 | } |
| 4924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { |
| 4926 | return p != null; |
| 4927 | } |
| 4928 | |
| 4929 | /** |
| 4930 | * Interface definition for a callback to be invoked when the hierarchy |
| 4931 | * within this view changed. The hierarchy changes whenever a child is added |
| 4932 | * to or removed from this view. |
| 4933 | */ |
| 4934 | public interface OnHierarchyChangeListener { |
| 4935 | /** |
| 4936 | * Called when a new child is added to a parent view. |
| 4937 | * |
| 4938 | * @param parent the view in which a child was added |
| 4939 | * @param child the new child view added in the hierarchy |
| 4940 | */ |
| 4941 | void onChildViewAdded(View parent, View child); |
| 4942 | |
| 4943 | /** |
| 4944 | * Called when a child is removed from a parent view. |
| 4945 | * |
| 4946 | * @param parent the view from which the child was removed |
| 4947 | * @param child the child removed from the hierarchy |
| 4948 | */ |
| 4949 | void onChildViewRemoved(View parent, View child); |
| 4950 | } |
| 4951 | |
| 4952 | /** |
| 4953 | * Register a callback to be invoked when a child is added to or removed |
| 4954 | * from this view. |
| 4955 | * |
| 4956 | * @param listener the callback to invoke on hierarchy change |
| 4957 | */ |
| 4958 | public void setOnHierarchyChangeListener(OnHierarchyChangeListener listener) { |
| 4959 | mOnHierarchyChangeListener = listener; |
| 4960 | } |
| 4961 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4962 | @UnsupportedAppUsage |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 4963 | void dispatchViewAdded(View child) { |
| 4964 | onViewAdded(child); |
Philip Milne | f51d91c | 2011-07-18 16:12:19 -0700 | [diff] [blame] | 4965 | if (mOnHierarchyChangeListener != null) { |
| 4966 | mOnHierarchyChangeListener.onChildViewAdded(this, child); |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | /** |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 4971 | * Called when a new child is added to this ViewGroup. Overrides should always |
| 4972 | * call super.onViewAdded. |
| 4973 | * |
| 4974 | * @param child the added child view |
Philip Milne | f51d91c | 2011-07-18 16:12:19 -0700 | [diff] [blame] | 4975 | */ |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 4976 | public void onViewAdded(View child) { |
| 4977 | } |
| 4978 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 4979 | @UnsupportedAppUsage |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 4980 | void dispatchViewRemoved(View child) { |
| 4981 | onViewRemoved(child); |
Philip Milne | f51d91c | 2011-07-18 16:12:19 -0700 | [diff] [blame] | 4982 | if (mOnHierarchyChangeListener != null) { |
| 4983 | mOnHierarchyChangeListener.onChildViewRemoved(this, child); |
| 4984 | } |
| 4985 | } |
| 4986 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 4987 | /** |
| 4988 | * Called when a child view is removed from this ViewGroup. Overrides should always |
| 4989 | * call super.onViewRemoved. |
| 4990 | * |
| 4991 | * @param child the removed child view |
| 4992 | */ |
| 4993 | public void onViewRemoved(View child) { |
| 4994 | } |
| 4995 | |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 4996 | private void clearCachedLayoutMode() { |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 4997 | if (!hasBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET)) { |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 4998 | mLayoutMode = LAYOUT_MODE_UNDEFINED; |
| 4999 | } |
| 5000 | } |
| 5001 | |
| 5002 | @Override |
| 5003 | protected void onAttachedToWindow() { |
| 5004 | super.onAttachedToWindow(); |
| 5005 | clearCachedLayoutMode(); |
| 5006 | } |
| 5007 | |
| 5008 | @Override |
| 5009 | protected void onDetachedFromWindow() { |
| 5010 | super.onDetachedFromWindow(); |
| 5011 | clearCachedLayoutMode(); |
| 5012 | } |
| 5013 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 5014 | /** @hide */ |
| 5015 | @Override |
| 5016 | protected void destroyHardwareResources() { |
| 5017 | super.destroyHardwareResources(); |
| 5018 | int count = getChildCount(); |
| 5019 | for (int i = 0; i < count; i++) { |
| 5020 | getChildAt(i).destroyHardwareResources(); |
| 5021 | } |
| 5022 | } |
| 5023 | |
Philip Milne | f51d91c | 2011-07-18 16:12:19 -0700 | [diff] [blame] | 5024 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5025 | * Adds a view during layout. This is useful if in your onLayout() method, |
| 5026 | * you need to add more views (as does the list view for example). |
| 5027 | * |
| 5028 | * If index is negative, it means put it at the end of the list. |
| 5029 | * |
| 5030 | * @param child the view to add to the group |
Alan Viverette | 77bb6f1 | 2015-02-11 17:24:33 -0800 | [diff] [blame] | 5031 | * @param index the index at which the child must be added or -1 to add last |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5032 | * @param params the layout parameters to associate with the child |
| 5033 | * @return true if the child was added, false otherwise |
| 5034 | */ |
| 5035 | protected boolean addViewInLayout(View child, int index, LayoutParams params) { |
| 5036 | return addViewInLayout(child, index, params, false); |
| 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * Adds a view during layout. This is useful if in your onLayout() method, |
| 5041 | * you need to add more views (as does the list view for example). |
| 5042 | * |
| 5043 | * If index is negative, it means put it at the end of the list. |
| 5044 | * |
| 5045 | * @param child the view to add to the group |
Alan Viverette | 77bb6f1 | 2015-02-11 17:24:33 -0800 | [diff] [blame] | 5046 | * @param index the index at which the child must be added or -1 to add last |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | * @param params the layout parameters to associate with the child |
| 5048 | * @param preventRequestLayout if true, calling this method will not trigger a |
| 5049 | * layout request on child |
| 5050 | * @return true if the child was added, false otherwise |
| 5051 | */ |
| 5052 | protected boolean addViewInLayout(View child, int index, LayoutParams params, |
| 5053 | boolean preventRequestLayout) { |
Adam Powell | 45a9da5 | 2014-10-09 09:44:18 -0700 | [diff] [blame] | 5054 | if (child == null) { |
| 5055 | throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup"); |
| 5056 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | child.mParent = null; |
| 5058 | addViewInner(child, index, params, preventRequestLayout); |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5059 | child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DRAWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | return true; |
| 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * Prevents the specified child to be laid out during the next layout pass. |
| 5065 | * |
| 5066 | * @param child the child on which to perform the cleanup |
| 5067 | */ |
| 5068 | protected void cleanupLayoutState(View child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5069 | child.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | private void addViewInner(View child, int index, LayoutParams params, |
| 5073 | boolean preventRequestLayout) { |
| 5074 | |
Chet Haase | e8e45d3 | 2011-03-02 17:07:35 -0800 | [diff] [blame] | 5075 | if (mTransition != null) { |
| 5076 | // Don't prevent other add transitions from completing, but cancel remove |
| 5077 | // transitions to let them complete the process before we add to the container |
| 5078 | mTransition.cancel(LayoutTransition.DISAPPEARING); |
Chet Haase | add6577 | 2011-02-09 16:47:29 -0800 | [diff] [blame] | 5079 | } |
| 5080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | if (child.getParent() != null) { |
| 5082 | throw new IllegalStateException("The specified child already has a parent. " + |
| 5083 | "You must call removeView() on the child's parent first."); |
| 5084 | } |
| 5085 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5086 | if (mTransition != null) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 5087 | mTransition.addChild(this, child); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5090 | if (!checkLayoutParams(params)) { |
| 5091 | params = generateLayoutParams(params); |
| 5092 | } |
| 5093 | |
| 5094 | if (preventRequestLayout) { |
| 5095 | child.mLayoutParams = params; |
| 5096 | } else { |
| 5097 | child.setLayoutParams(params); |
| 5098 | } |
| 5099 | |
| 5100 | if (index < 0) { |
| 5101 | index = mChildrenCount; |
| 5102 | } |
| 5103 | |
| 5104 | addInArray(child, index); |
| 5105 | |
| 5106 | // tell our children |
| 5107 | if (preventRequestLayout) { |
| 5108 | child.assignParent(this); |
| 5109 | } else { |
| 5110 | child.mParent = this; |
Evan Rosky | cd80e61 | 2018-05-17 17:46:09 -0700 | [diff] [blame] | 5111 | } |
| 5112 | if (child.hasUnhandledKeyListener()) { |
| 5113 | incrementChildUnhandledKeyListeners(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | } |
| 5115 | |
Evan Rosky | 2ae1bf5 | 2017-05-11 11:18:45 -0700 | [diff] [blame] | 5116 | final boolean childHasFocus = child.hasFocus(); |
| 5117 | if (childHasFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | requestChildFocus(child, child.findFocus()); |
| 5119 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | AttachInfo ai = mAttachInfo; |
Adam Powell | 4b86788 | 2011-09-16 12:59:46 -0700 | [diff] [blame] | 5122 | if (ai != null && (mGroupFlags & FLAG_PREVENT_DISPATCH_ATTACHED_TO_WINDOW) == 0) { |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5123 | boolean lastKeepOn = ai.mKeepScreenOn; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | ai.mKeepScreenOn = false; |
| 5125 | child.dispatchAttachedToWindow(mAttachInfo, (mViewFlags&VISIBILITY_MASK)); |
| 5126 | if (ai.mKeepScreenOn) { |
| 5127 | needGlobalAttributesUpdate(true); |
| 5128 | } |
| 5129 | ai.mKeepScreenOn = lastKeepOn; |
| 5130 | } |
| 5131 | |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 5132 | if (child.isLayoutDirectionInherited()) { |
Fabrice Di Meglio | a7e0bcd | 2012-10-16 19:55:01 -0700 | [diff] [blame] | 5133 | child.resetRtlProperties(); |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 5134 | } |
| 5135 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 5136 | dispatchViewAdded(child); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | |
| 5138 | if ((child.mViewFlags & DUPLICATE_PARENT_STATE) == DUPLICATE_PARENT_STATE) { |
| 5139 | mGroupFlags |= FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE; |
| 5140 | } |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5141 | |
| 5142 | if (child.hasTransientState()) { |
| 5143 | childHasTransientStateChanged(child, true); |
| 5144 | } |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 5145 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5146 | if (child.getVisibility() != View.GONE) { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 5147 | notifySubtreeAccessibilityStateChangedIfNeeded(); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 5148 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 5149 | |
| 5150 | if (mTransientIndices != null) { |
| 5151 | final int transientCount = mTransientIndices.size(); |
| 5152 | for (int i = 0; i < transientCount; ++i) { |
| 5153 | final int oldIndex = mTransientIndices.get(i); |
| 5154 | if (index <= oldIndex) { |
| 5155 | mTransientIndices.set(i, oldIndex + 1); |
| 5156 | } |
| 5157 | } |
| 5158 | } |
Vadim Tryshev | 02ed4a0 | 2015-10-23 17:39:33 -0700 | [diff] [blame] | 5159 | |
| 5160 | if (mCurrentDragStartEvent != null && child.getVisibility() == VISIBLE) { |
| 5161 | notifyChildOfDragStart(child); |
| 5162 | } |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 5163 | |
| 5164 | if (child.hasDefaultFocus()) { |
| 5165 | // When adding a child that contains default focus, either during inflation or while |
| 5166 | // manually assembling the hierarchy, update the ancestor default-focus chain. |
| 5167 | setDefaultFocus(child); |
| 5168 | } |
Svetoslav Ganov | 24c9045 | 2017-12-27 15:17:14 -0800 | [diff] [blame] | 5169 | |
| 5170 | touchAccessibilityNodeProviderIfNeeded(child); |
| 5171 | } |
| 5172 | |
| 5173 | /** |
| 5174 | * We may need to touch the provider to bring up the a11y layer. In a11y mode |
| 5175 | * clients inspect the screen or the user touches it which triggers bringing up |
| 5176 | * of the a11y infrastructure while in autofill mode we want the infra up and |
| 5177 | * running from the beginning since we watch for a11y events to drive autofill. |
| 5178 | */ |
| 5179 | private void touchAccessibilityNodeProviderIfNeeded(View child) { |
| 5180 | if (mContext.isAutofillCompatibilityEnabled()) { |
| 5181 | child.getAccessibilityNodeProvider(); |
| 5182 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | private void addInArray(View child, int index) { |
| 5186 | View[] children = mChildren; |
| 5187 | final int count = mChildrenCount; |
| 5188 | final int size = children.length; |
| 5189 | if (index == count) { |
| 5190 | if (size == count) { |
| 5191 | mChildren = new View[size + ARRAY_CAPACITY_INCREMENT]; |
| 5192 | System.arraycopy(children, 0, mChildren, 0, size); |
| 5193 | children = mChildren; |
| 5194 | } |
| 5195 | children[mChildrenCount++] = child; |
| 5196 | } else if (index < count) { |
| 5197 | if (size == count) { |
| 5198 | mChildren = new View[size + ARRAY_CAPACITY_INCREMENT]; |
| 5199 | System.arraycopy(children, 0, mChildren, 0, index); |
| 5200 | System.arraycopy(children, index, mChildren, index + 1, count - index); |
| 5201 | children = mChildren; |
| 5202 | } else { |
| 5203 | System.arraycopy(children, index, children, index + 1, count - index); |
| 5204 | } |
| 5205 | children[index] = child; |
| 5206 | mChildrenCount++; |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 5207 | if (mLastTouchDownIndex >= index) { |
| 5208 | mLastTouchDownIndex++; |
| 5209 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5210 | } else { |
| 5211 | throw new IndexOutOfBoundsException("index=" + index + " count=" + count); |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | // This method also sets the child's mParent to null |
| 5216 | private void removeFromArray(int index) { |
| 5217 | final View[] children = mChildren; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5218 | if (!(mTransitioningViews != null && mTransitioningViews.contains(children[index]))) { |
| 5219 | children[index].mParent = null; |
| 5220 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5221 | final int count = mChildrenCount; |
| 5222 | if (index == count - 1) { |
| 5223 | children[--mChildrenCount] = null; |
| 5224 | } else if (index >= 0 && index < count) { |
| 5225 | System.arraycopy(children, index + 1, children, index, count - index - 1); |
| 5226 | children[--mChildrenCount] = null; |
| 5227 | } else { |
| 5228 | throw new IndexOutOfBoundsException(); |
| 5229 | } |
Joe Onorato | 03ab0c7 | 2011-01-06 15:46:27 -0800 | [diff] [blame] | 5230 | if (mLastTouchDownIndex == index) { |
| 5231 | mLastTouchDownTime = 0; |
| 5232 | mLastTouchDownIndex = -1; |
| 5233 | } else if (mLastTouchDownIndex > index) { |
| 5234 | mLastTouchDownIndex--; |
| 5235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | // This method also sets the children's mParent to null |
| 5239 | private void removeFromArray(int start, int count) { |
| 5240 | final View[] children = mChildren; |
| 5241 | final int childrenCount = mChildrenCount; |
| 5242 | |
| 5243 | start = Math.max(0, start); |
| 5244 | final int end = Math.min(childrenCount, start + count); |
| 5245 | |
| 5246 | if (start == end) { |
| 5247 | return; |
| 5248 | } |
| 5249 | |
| 5250 | if (end == childrenCount) { |
| 5251 | for (int i = start; i < end; i++) { |
| 5252 | children[i].mParent = null; |
| 5253 | children[i] = null; |
| 5254 | } |
| 5255 | } else { |
| 5256 | for (int i = start; i < end; i++) { |
| 5257 | children[i].mParent = null; |
| 5258 | } |
| 5259 | |
| 5260 | // Since we're looping above, we might as well do the copy, but is arraycopy() |
| 5261 | // faster than the extra 2 bounds checks we would do in the loop? |
| 5262 | System.arraycopy(children, end, children, start, childrenCount - end); |
| 5263 | |
| 5264 | for (int i = childrenCount - (end - start); i < childrenCount; i++) { |
| 5265 | children[i] = null; |
| 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | mChildrenCount -= (end - start); |
| 5270 | } |
| 5271 | |
| 5272 | private void bindLayoutAnimation(View child) { |
| 5273 | Animation a = mLayoutAnimationController.getAnimationForView(child); |
| 5274 | child.setAnimation(a); |
| 5275 | } |
| 5276 | |
| 5277 | /** |
| 5278 | * Subclasses should override this method to set layout animation |
| 5279 | * parameters on the supplied child. |
| 5280 | * |
| 5281 | * @param child the child to associate with animation parameters |
| 5282 | * @param params the child's layout parameters which hold the animation |
| 5283 | * parameters |
| 5284 | * @param index the index of the child in the view group |
| 5285 | * @param count the number of children in the view group |
| 5286 | */ |
| 5287 | protected void attachLayoutAnimationParameters(View child, |
| 5288 | LayoutParams params, int index, int count) { |
| 5289 | LayoutAnimationController.AnimationParameters animationParams = |
| 5290 | params.layoutAnimationParameters; |
| 5291 | if (animationParams == null) { |
| 5292 | animationParams = new LayoutAnimationController.AnimationParameters(); |
| 5293 | params.layoutAnimationParameters = animationParams; |
| 5294 | } |
| 5295 | |
| 5296 | animationParams.count = count; |
| 5297 | animationParams.index = index; |
| 5298 | } |
| 5299 | |
| 5300 | /** |
| 5301 | * {@inheritDoc} |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 5302 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5303 | * <p><strong>Note:</strong> do not invoke this method from |
| 5304 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5305 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5306 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 5307 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5308 | public void removeView(View view) { |
Alan Viverette | 177ec460 | 2014-10-17 13:34:50 -0700 | [diff] [blame] | 5309 | if (removeViewInternal(view)) { |
| 5310 | requestLayout(); |
| 5311 | invalidate(true); |
| 5312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * Removes a view during layout. This is useful if in your onLayout() method, |
| 5317 | * you need to remove more views. |
| 5318 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5319 | * <p><strong>Note:</strong> do not invoke this method from |
| 5320 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5321 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 5322 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | * @param view the view to remove from the group |
| 5324 | */ |
| 5325 | public void removeViewInLayout(View view) { |
| 5326 | removeViewInternal(view); |
| 5327 | } |
| 5328 | |
| 5329 | /** |
| 5330 | * Removes a range of views during layout. This is useful if in your onLayout() method, |
| 5331 | * you need to remove more views. |
| 5332 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5333 | * <p><strong>Note:</strong> do not invoke this method from |
| 5334 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5335 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
| 5336 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5337 | * @param start the index of the first view to remove from the group |
| 5338 | * @param count the number of views to remove from the group |
| 5339 | */ |
| 5340 | public void removeViewsInLayout(int start, int count) { |
| 5341 | removeViewsInternal(start, count); |
| 5342 | } |
| 5343 | |
| 5344 | /** |
| 5345 | * Removes the view at the specified position in the group. |
| 5346 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5347 | * <p><strong>Note:</strong> do not invoke this method from |
| 5348 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5349 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 5350 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | * @param index the position in the group of the view to remove |
| 5352 | */ |
| 5353 | public void removeViewAt(int index) { |
| 5354 | removeViewInternal(index, getChildAt(index)); |
| 5355 | requestLayout(); |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 5356 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | /** |
| 5360 | * Removes the specified range of views from the group. |
| 5361 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5362 | * <p><strong>Note:</strong> do not invoke this method from |
| 5363 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5364 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
| 5365 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5366 | * @param start the first position in the group of the range of views to remove |
| 5367 | * @param count the number of views to remove |
| 5368 | */ |
| 5369 | public void removeViews(int start, int count) { |
| 5370 | removeViewsInternal(start, count); |
| 5371 | requestLayout(); |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 5372 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5373 | } |
| 5374 | |
Alan Viverette | 177ec460 | 2014-10-17 13:34:50 -0700 | [diff] [blame] | 5375 | private boolean removeViewInternal(View view) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | final int index = indexOfChild(view); |
| 5377 | if (index >= 0) { |
| 5378 | removeViewInternal(index, view); |
Alan Viverette | 177ec460 | 2014-10-17 13:34:50 -0700 | [diff] [blame] | 5379 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | } |
Alan Viverette | 177ec460 | 2014-10-17 13:34:50 -0700 | [diff] [blame] | 5381 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | private void removeViewInternal(int index, View view) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5385 | if (mTransition != null) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 5386 | mTransition.removeChild(this, view); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5389 | boolean clearChildFocus = false; |
| 5390 | if (view == mFocused) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 5391 | view.unFocus(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5392 | clearChildFocus = true; |
| 5393 | } |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5394 | if (view == mFocusedInCluster) { |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 5395 | clearFocusedInCluster(view); |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 5396 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 5398 | view.clearAccessibilityFocus(); |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 5399 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 5400 | cancelTouchTarget(view); |
| 5401 | cancelHoverTarget(view); |
| 5402 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5403 | if (view.getAnimation() != null || |
| 5404 | (mTransitioningViews != null && mTransitioningViews.contains(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5405 | addDisappearingView(view); |
| 5406 | } else if (view.mAttachInfo != null) { |
| 5407 | view.dispatchDetachedFromWindow(); |
| 5408 | } |
| 5409 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5410 | if (view.hasTransientState()) { |
| 5411 | childHasTransientStateChanged(view, false); |
| 5412 | } |
| 5413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | needGlobalAttributesUpdate(false); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5416 | removeFromArray(index); |
| 5417 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 5418 | if (view.hasUnhandledKeyListener()) { |
| 5419 | decrementChildUnhandledKeyListeners(); |
| 5420 | } |
| 5421 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5422 | if (view == mDefaultFocus) { |
| 5423 | clearDefaultFocus(view); |
| 5424 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5425 | if (clearChildFocus) { |
| 5426 | clearChildFocus(view); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5427 | if (!rootViewRequestFocus()) { |
| 5428 | notifyGlobalFocusCleared(this); |
| 5429 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5430 | } |
Romain Guy | 6fb0563 | 2012-11-29 10:50:33 -0800 | [diff] [blame] | 5431 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 5432 | dispatchViewRemoved(view); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 5433 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5434 | if (view.getVisibility() != View.GONE) { |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 5435 | notifySubtreeAccessibilityStateChangedIfNeeded(); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 5436 | } |
Chet Haase | c633d2f | 2015-04-07 10:29:39 -0700 | [diff] [blame] | 5437 | |
| 5438 | int transientCount = mTransientIndices == null ? 0 : mTransientIndices.size(); |
| 5439 | for (int i = 0; i < transientCount; ++i) { |
| 5440 | final int oldIndex = mTransientIndices.get(i); |
| 5441 | if (index < oldIndex) { |
| 5442 | mTransientIndices.set(i, oldIndex - 1); |
| 5443 | } |
| 5444 | } |
Vadim Tryshev | 02ed4a0 | 2015-10-23 17:39:33 -0700 | [diff] [blame] | 5445 | |
| 5446 | if (mCurrentDragStartEvent != null) { |
| 5447 | mChildrenInterestedInDrag.remove(view); |
| 5448 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5449 | } |
| 5450 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5451 | /** |
| 5452 | * Sets the LayoutTransition object for this ViewGroup. If the LayoutTransition object is |
| 5453 | * not null, changes in layout which occur because of children being added to or removed from |
| 5454 | * the ViewGroup will be animated according to the animations defined in that LayoutTransition |
| 5455 | * object. By default, the transition object is null (so layout changes are not animated). |
| 5456 | * |
Chet Haase | ef3cbfd | 2013-08-21 14:01:02 -0700 | [diff] [blame] | 5457 | * <p>Replacing a non-null transition will cause that previous transition to be |
| 5458 | * canceled, if it is currently running, to restore this container to |
| 5459 | * its correct post-transition state.</p> |
| 5460 | * |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5461 | * @param transition The LayoutTransition object that will animated changes in layout. A value |
| 5462 | * of <code>null</code> means no transition will run on layout changes. |
Chet Haase | 13cc120 | 2010-09-03 15:39:20 -0700 | [diff] [blame] | 5463 | * @attr ref android.R.styleable#ViewGroup_animateLayoutChanges |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5464 | */ |
| 5465 | public void setLayoutTransition(LayoutTransition transition) { |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 5466 | if (mTransition != null) { |
Chet Haase | fee6f2b | 2013-08-27 12:22:29 -0700 | [diff] [blame] | 5467 | LayoutTransition previousTransition = mTransition; |
| 5468 | previousTransition.cancel(); |
| 5469 | previousTransition.removeTransitionListener(mLayoutTransitionListener); |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 5470 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5471 | mTransition = transition; |
Chet Haase | 13cc120 | 2010-09-03 15:39:20 -0700 | [diff] [blame] | 5472 | if (mTransition != null) { |
| 5473 | mTransition.addTransitionListener(mLayoutTransitionListener); |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | /** |
| 5478 | * Gets the LayoutTransition object for this ViewGroup. If the LayoutTransition object is |
| 5479 | * not null, changes in layout which occur because of children being added to or removed from |
| 5480 | * the ViewGroup will be animated according to the animations defined in that LayoutTransition |
| 5481 | * object. By default, the transition object is null (so layout changes are not animated). |
| 5482 | * |
| 5483 | * @return LayoutTranstion The LayoutTransition object that will animated changes in layout. |
| 5484 | * A value of <code>null</code> means no transition will run on layout changes. |
| 5485 | */ |
| 5486 | public LayoutTransition getLayoutTransition() { |
| 5487 | return mTransition; |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5490 | private void removeViewsInternal(int start, int count) { |
Chris Craik | 18a759d | 2015-10-14 14:16:33 -0700 | [diff] [blame] | 5491 | final int end = start + count; |
| 5492 | |
| 5493 | if (start < 0 || count < 0 || end > mChildrenCount) { |
| 5494 | throw new IndexOutOfBoundsException(); |
| 5495 | } |
| 5496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5497 | final View focused = mFocused; |
| 5498 | final boolean detach = mAttachInfo != null; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5499 | boolean clearChildFocus = false; |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5500 | View clearDefaultFocus = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5501 | |
| 5502 | final View[] children = mChildren; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5503 | |
| 5504 | for (int i = start; i < end; i++) { |
| 5505 | final View view = children[i]; |
| 5506 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5507 | if (mTransition != null) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 5508 | mTransition.removeChild(this, view); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5511 | if (view == focused) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 5512 | view.unFocus(null); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5513 | clearChildFocus = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | } |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 5515 | if (view == mDefaultFocus) { |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5516 | clearDefaultFocus = view; |
| 5517 | } |
| 5518 | if (view == mFocusedInCluster) { |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 5519 | clearFocusedInCluster(view); |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 5520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5521 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 5522 | view.clearAccessibilityFocus(); |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 5523 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 5524 | cancelTouchTarget(view); |
| 5525 | cancelHoverTarget(view); |
| 5526 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5527 | if (view.getAnimation() != null || |
| 5528 | (mTransitioningViews != null && mTransitioningViews.contains(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5529 | addDisappearingView(view); |
| 5530 | } else if (detach) { |
| 5531 | view.dispatchDetachedFromWindow(); |
| 5532 | } |
| 5533 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5534 | if (view.hasTransientState()) { |
| 5535 | childHasTransientStateChanged(view, false); |
| 5536 | } |
| 5537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5538 | needGlobalAttributesUpdate(false); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5539 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 5540 | dispatchViewRemoved(view); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | removeFromArray(start, count); |
| 5544 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5545 | if (clearDefaultFocus != null) { |
| 5546 | clearDefaultFocus(clearDefaultFocus); |
| 5547 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5548 | if (clearChildFocus) { |
| 5549 | clearChildFocus(focused); |
| 5550 | if (!rootViewRequestFocus()) { |
| 5551 | notifyGlobalFocusCleared(focused); |
| 5552 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5553 | } |
| 5554 | } |
| 5555 | |
| 5556 | /** |
| 5557 | * Call this method to remove all child views from the |
| 5558 | * ViewGroup. |
Filip Gruszczynski | a33bdf3 | 2015-11-19 18:22:16 -0800 | [diff] [blame] | 5559 | * |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5560 | * <p><strong>Note:</strong> do not invoke this method from |
| 5561 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5562 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5563 | */ |
| 5564 | public void removeAllViews() { |
| 5565 | removeAllViewsInLayout(); |
| 5566 | requestLayout(); |
Romain Guy | 849d0a3 | 2011-02-01 17:20:48 -0800 | [diff] [blame] | 5567 | invalidate(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | /** |
| 5571 | * Called by a ViewGroup subclass to remove child views from itself, |
| 5572 | * when it must first know its size on screen before it can calculate how many |
| 5573 | * child views it will render. An example is a Gallery or a ListView, which |
| 5574 | * may "have" 50 children, but actually only render the number of children |
| 5575 | * that can currently fit inside the object on screen. Do not call |
| 5576 | * this method unless you are extending ViewGroup and understand the |
| 5577 | * view measuring and layout pipeline. |
Romain Guy | 393a52c | 2012-05-22 20:21:08 -0700 | [diff] [blame] | 5578 | * |
| 5579 | * <p><strong>Note:</strong> do not invoke this method from |
| 5580 | * {@link #draw(android.graphics.Canvas)}, {@link #onDraw(android.graphics.Canvas)}, |
| 5581 | * {@link #dispatchDraw(android.graphics.Canvas)} or any related method.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5582 | */ |
| 5583 | public void removeAllViewsInLayout() { |
| 5584 | final int count = mChildrenCount; |
| 5585 | if (count <= 0) { |
| 5586 | return; |
| 5587 | } |
| 5588 | |
| 5589 | final View[] children = mChildren; |
| 5590 | mChildrenCount = 0; |
| 5591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5592 | final View focused = mFocused; |
| 5593 | final boolean detach = mAttachInfo != null; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5594 | boolean clearChildFocus = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5595 | |
| 5596 | needGlobalAttributesUpdate(false); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | for (int i = count - 1; i >= 0; i--) { |
| 5599 | final View view = children[i]; |
| 5600 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5601 | if (mTransition != null) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 5602 | mTransition.removeChild(this, view); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5605 | if (view == focused) { |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 5606 | view.unFocus(null); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5607 | clearChildFocus = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5608 | } |
| 5609 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 5610 | view.clearAccessibilityFocus(); |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 5611 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 5612 | cancelTouchTarget(view); |
| 5613 | cancelHoverTarget(view); |
| 5614 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5615 | if (view.getAnimation() != null || |
| 5616 | (mTransitioningViews != null && mTransitioningViews.contains(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5617 | addDisappearingView(view); |
| 5618 | } else if (detach) { |
| 5619 | view.dispatchDetachedFromWindow(); |
| 5620 | } |
| 5621 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5622 | if (view.hasTransientState()) { |
| 5623 | childHasTransientStateChanged(view, false); |
| 5624 | } |
| 5625 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 5626 | dispatchViewRemoved(view); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5627 | |
| 5628 | view.mParent = null; |
| 5629 | children[i] = null; |
| 5630 | } |
| 5631 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5632 | if (mDefaultFocus != null) { |
| 5633 | clearDefaultFocus(mDefaultFocus); |
| 5634 | } |
Evan Rosky | 776fa5f | 2017-04-26 16:47:54 -0700 | [diff] [blame] | 5635 | if (mFocusedInCluster != null) { |
| 5636 | clearFocusedInCluster(mFocusedInCluster); |
| 5637 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 5638 | if (clearChildFocus) { |
| 5639 | clearChildFocus(focused); |
| 5640 | if (!rootViewRequestFocus()) { |
| 5641 | notifyGlobalFocusCleared(focused); |
| 5642 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | /** |
| 5647 | * Finishes the removal of a detached view. This method will dispatch the detached from |
| 5648 | * window event and notify the hierarchy change listener. |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5649 | * <p> |
| 5650 | * This method is intended to be lightweight and makes no assumptions about whether the |
| 5651 | * parent or child should be redrawn. Proper use of this method will include also making |
| 5652 | * any appropriate {@link #requestLayout()} or {@link #invalidate()} calls. |
| 5653 | * For example, callers can {@link #post(Runnable) post} a {@link Runnable} |
| 5654 | * which performs a {@link #requestLayout()} on the next frame, after all detach/remove |
| 5655 | * calls are finished, causing layout to be run prior to redrawing the view hierarchy. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5656 | * |
| 5657 | * @param child the child to be definitely removed from the view hierarchy |
| 5658 | * @param animate if true and the view has an animation, the view is placed in the |
| 5659 | * disappearing views list, otherwise, it is detached from the window |
| 5660 | * |
| 5661 | * @see #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams) |
| 5662 | * @see #detachAllViewsFromParent() |
| 5663 | * @see #detachViewFromParent(View) |
| 5664 | * @see #detachViewFromParent(int) |
| 5665 | */ |
| 5666 | protected void removeDetachedView(View child, boolean animate) { |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5667 | if (mTransition != null) { |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 5668 | mTransition.removeChild(this, child); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | if (child == mFocused) { |
| 5672 | child.clearFocus(); |
| 5673 | } |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 5674 | if (child == mDefaultFocus) { |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 5675 | clearDefaultFocus(child); |
| 5676 | } |
| 5677 | if (child == mFocusedInCluster) { |
Evan Rosky | 0e8a683 | 2017-04-10 12:35:15 -0700 | [diff] [blame] | 5678 | clearFocusedInCluster(child); |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 5679 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5680 | |
Svetoslav Ganov | 961bf0e | 2012-05-08 09:40:03 -0700 | [diff] [blame] | 5681 | child.clearAccessibilityFocus(); |
| 5682 | |
Jeff Brown | 59a422e | 2012-04-19 15:19:19 -0700 | [diff] [blame] | 5683 | cancelTouchTarget(child); |
| 5684 | cancelHoverTarget(child); |
| 5685 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 5686 | if ((animate && child.getAnimation() != null) || |
| 5687 | (mTransitioningViews != null && mTransitioningViews.contains(child))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | addDisappearingView(child); |
| 5689 | } else if (child.mAttachInfo != null) { |
| 5690 | child.dispatchDetachedFromWindow(); |
| 5691 | } |
| 5692 | |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 5693 | if (child.hasTransientState()) { |
| 5694 | childHasTransientStateChanged(child, false); |
| 5695 | } |
| 5696 | |
Adam Powell | 6690d01 | 2015-06-17 16:41:56 -0700 | [diff] [blame] | 5697 | dispatchViewRemoved(child); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /** |
| 5701 | * Attaches a view to this view group. Attaching a view assigns this group as the parent, |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5702 | * sets the layout parameters and puts the view in the list of children so that |
| 5703 | * it can be retrieved by calling {@link #getChildAt(int)}. |
| 5704 | * <p> |
| 5705 | * This method is intended to be lightweight and makes no assumptions about whether the |
| 5706 | * parent or child should be redrawn. Proper use of this method will include also making |
| 5707 | * any appropriate {@link #requestLayout()} or {@link #invalidate()} calls. |
| 5708 | * For example, callers can {@link #post(Runnable) post} a {@link Runnable} |
| 5709 | * which performs a {@link #requestLayout()} on the next frame, after all detach/attach |
| 5710 | * calls are finished, causing layout to be run prior to redrawing the view hierarchy. |
| 5711 | * <p> |
| 5712 | * This method should be called only for views which were detached from their parent. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5713 | * |
| 5714 | * @param child the child to attach |
| 5715 | * @param index the index at which the child should be attached |
| 5716 | * @param params the layout parameters of the child |
| 5717 | * |
| 5718 | * @see #removeDetachedView(View, boolean) |
| 5719 | * @see #detachAllViewsFromParent() |
| 5720 | * @see #detachViewFromParent(View) |
| 5721 | * @see #detachViewFromParent(int) |
| 5722 | */ |
| 5723 | protected void attachViewToParent(View child, int index, LayoutParams params) { |
| 5724 | child.mLayoutParams = params; |
| 5725 | |
| 5726 | if (index < 0) { |
| 5727 | index = mChildrenCount; |
| 5728 | } |
| 5729 | |
| 5730 | addInArray(child, index); |
| 5731 | |
| 5732 | child.mParent = this; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5733 | child.mPrivateFlags = (child.mPrivateFlags & ~PFLAG_DIRTY_MASK |
| 5734 | & ~PFLAG_DRAWING_CACHE_VALID) |
| 5735 | | PFLAG_DRAWN | PFLAG_INVALIDATED; |
| 5736 | this.mPrivateFlags |= PFLAG_INVALIDATED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | |
| 5738 | if (child.hasFocus()) { |
| 5739 | requestChildFocus(child, child.findFocus()); |
| 5740 | } |
Adam Powell | c587409 | 2016-03-17 16:27:24 -0700 | [diff] [blame] | 5741 | dispatchVisibilityAggregated(isAttachedToWindow() && getWindowVisibility() == VISIBLE |
| 5742 | && isShown()); |
Phil Weaver | 1317162 | 2018-04-03 11:39:20 -0700 | [diff] [blame] | 5743 | notifySubtreeAccessibilityStateChangedIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /** |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5747 | * Detaches a view from its parent. Detaching a view should be followed |
| 5748 | * either by a call to |
| 5749 | * {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)} |
| 5750 | * or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be |
| 5751 | * temporary; reattachment or removal should happen within the same drawing cycle as |
| 5752 | * detachment. When a view is detached, its parent is null and cannot be retrieved by a |
| 5753 | * call to {@link #getChildAt(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5754 | * |
| 5755 | * @param child the child to detach |
| 5756 | * |
| 5757 | * @see #detachViewFromParent(int) |
| 5758 | * @see #detachViewsFromParent(int, int) |
| 5759 | * @see #detachAllViewsFromParent() |
| 5760 | * @see #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams) |
| 5761 | * @see #removeDetachedView(View, boolean) |
| 5762 | */ |
| 5763 | protected void detachViewFromParent(View child) { |
| 5764 | removeFromArray(indexOfChild(child)); |
| 5765 | } |
| 5766 | |
| 5767 | /** |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5768 | * Detaches a view from its parent. Detaching a view should be followed |
| 5769 | * either by a call to |
| 5770 | * {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)} |
| 5771 | * or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be |
| 5772 | * temporary; reattachment or removal should happen within the same drawing cycle as |
| 5773 | * detachment. When a view is detached, its parent is null and cannot be retrieved by a |
| 5774 | * call to {@link #getChildAt(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5775 | * |
| 5776 | * @param index the index of the child to detach |
| 5777 | * |
| 5778 | * @see #detachViewFromParent(View) |
| 5779 | * @see #detachAllViewsFromParent() |
| 5780 | * @see #detachViewsFromParent(int, int) |
| 5781 | * @see #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams) |
| 5782 | * @see #removeDetachedView(View, boolean) |
| 5783 | */ |
| 5784 | protected void detachViewFromParent(int index) { |
| 5785 | removeFromArray(index); |
| 5786 | } |
| 5787 | |
| 5788 | /** |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5789 | * Detaches a range of views from their parents. Detaching a view should be followed |
| 5790 | * either by a call to |
| 5791 | * {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)} |
| 5792 | * or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be |
| 5793 | * temporary; reattachment or removal should happen within the same drawing cycle as |
| 5794 | * detachment. When a view is detached, its parent is null and cannot be retrieved by a |
| 5795 | * call to {@link #getChildAt(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5796 | * |
| 5797 | * @param start the first index of the childrend range to detach |
| 5798 | * @param count the number of children to detach |
| 5799 | * |
| 5800 | * @see #detachViewFromParent(View) |
| 5801 | * @see #detachViewFromParent(int) |
| 5802 | * @see #detachAllViewsFromParent() |
| 5803 | * @see #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams) |
| 5804 | * @see #removeDetachedView(View, boolean) |
| 5805 | */ |
| 5806 | protected void detachViewsFromParent(int start, int count) { |
| 5807 | removeFromArray(start, count); |
| 5808 | } |
| 5809 | |
| 5810 | /** |
Chet Haase | ca479d4 | 2012-08-30 17:20:08 -0700 | [diff] [blame] | 5811 | * Detaches all views from the parent. Detaching a view should be followed |
| 5812 | * either by a call to |
| 5813 | * {@link #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)} |
| 5814 | * or a call to {@link #removeDetachedView(View, boolean)}. Detachment should only be |
| 5815 | * temporary; reattachment or removal should happen within the same drawing cycle as |
| 5816 | * detachment. When a view is detached, its parent is null and cannot be retrieved by a |
| 5817 | * call to {@link #getChildAt(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | * |
| 5819 | * @see #detachViewFromParent(View) |
| 5820 | * @see #detachViewFromParent(int) |
| 5821 | * @see #detachViewsFromParent(int, int) |
| 5822 | * @see #attachViewToParent(View, int, android.view.ViewGroup.LayoutParams) |
| 5823 | * @see #removeDetachedView(View, boolean) |
| 5824 | */ |
| 5825 | protected void detachAllViewsFromParent() { |
| 5826 | final int count = mChildrenCount; |
| 5827 | if (count <= 0) { |
| 5828 | return; |
| 5829 | } |
| 5830 | |
| 5831 | final View[] children = mChildren; |
| 5832 | mChildrenCount = 0; |
| 5833 | |
| 5834 | for (int i = count - 1; i >= 0; i--) { |
| 5835 | children[i].mParent = null; |
| 5836 | children[i] = null; |
| 5837 | } |
| 5838 | } |
| 5839 | |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5840 | @Override |
| 5841 | @CallSuper |
| 5842 | public void onDescendantInvalidated(@NonNull View child, @NonNull View target) { |
| 5843 | /* |
| 5844 | * HW-only, Rect-ignoring damage codepath |
| 5845 | * |
| 5846 | * We don't deal with rectangles here, since RenderThread native code computes damage for |
| 5847 | * everything drawn by HWUI (and SW layer / drawing cache doesn't keep track of damage area) |
| 5848 | */ |
| 5849 | |
| 5850 | // if set, combine the animation flag into the parent |
| 5851 | mPrivateFlags |= (target.mPrivateFlags & PFLAG_DRAW_ANIMATION); |
| 5852 | |
| 5853 | if ((target.mPrivateFlags & ~PFLAG_DIRTY_MASK) != 0) { |
| 5854 | // We lazily use PFLAG_DIRTY, since computing opaque isn't worth the potential |
| 5855 | // optimization in provides in a DisplayList world. |
| 5856 | mPrivateFlags = (mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DIRTY; |
| 5857 | |
| 5858 | // simplified invalidateChildInParent behavior: clear cache validity to be safe... |
| 5859 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5860 | } |
| 5861 | |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5862 | // ... and mark inval if in software layer that needs to repaint (hw handled in native) |
| 5863 | if (mLayerType == LAYER_TYPE_SOFTWARE) { |
| 5864 | // Layered parents should be invalidated. Escalate to a full invalidate (and note that |
| 5865 | // we do this after consuming any relevant flags from the originating descendant) |
| 5866 | mPrivateFlags |= PFLAG_INVALIDATED | PFLAG_DIRTY; |
| 5867 | target = this; |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5868 | } |
| 5869 | |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5870 | if (mParent != null) { |
| 5871 | mParent.onDescendantInvalidated(this, target); |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5872 | } |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | |
| 5876 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | * Don't call or override this method. It is used for the implementation of |
| 5878 | * the view hierarchy. |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5879 | * |
| 5880 | * @deprecated Use {@link #onDescendantInvalidated(View, View)} instead to observe updates to |
| 5881 | * draw state in descendants. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5882 | */ |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5883 | @Deprecated |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 5884 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5885 | public final void invalidateChild(View child, final Rect dirty) { |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5886 | final AttachInfo attachInfo = mAttachInfo; |
| 5887 | if (attachInfo != null && attachInfo.mHardwareAccelerated) { |
| 5888 | // HW accelerated fast path |
| 5889 | onDescendantInvalidated(child, child); |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5890 | return; |
| 5891 | } |
| 5892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | ViewParent parent = this; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5894 | if (attachInfo != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5895 | // If the child is drawing an animation, we want to copy this flag onto |
| 5896 | // ourselves and the parent to make sure the invalidate request goes |
| 5897 | // through |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5898 | final boolean drawAnimation = (child.mPrivateFlags & PFLAG_DRAW_ANIMATION) != 0; |
Romain Guy | 24443ea | 2009-05-11 11:56:30 -0700 | [diff] [blame] | 5899 | |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5900 | // Check whether the child that requests the invalidate is fully opaque |
| 5901 | // Views being animated or transformed are not considered opaque because we may |
| 5902 | // be invalidating their old position and need the parent to paint behind them. |
| 5903 | Matrix childMatrix = child.getMatrix(); |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5904 | // Mark the child as dirty, using the appropriate flag |
| 5905 | // Make sure we do not set both flags at the same time |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5906 | |
John Reck | 96bb8ad | 2014-06-19 10:53:03 -0700 | [diff] [blame] | 5907 | if (child.mLayerType != LAYER_TYPE_NONE) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5908 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 5909 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | final int[] location = attachInfo.mInvalidateChildLocation; |
| 5913 | location[CHILD_LEFT_INDEX] = child.mLeft; |
| 5914 | location[CHILD_TOP_INDEX] = child.mTop; |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 5915 | if (!childMatrix.isIdentity() || |
| 5916 | (mGroupFlags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5917 | RectF boundingRect = attachInfo.mTmpTransformRect; |
| 5918 | boundingRect.set(dirty); |
Chet Haase | 599913d | 2012-07-23 16:22:05 -0700 | [diff] [blame] | 5919 | Matrix transformMatrix; |
| 5920 | if ((mGroupFlags & ViewGroup.FLAG_SUPPORT_STATIC_TRANSFORMATIONS) != 0) { |
| 5921 | Transformation t = attachInfo.mTmpTransformation; |
| 5922 | boolean transformed = getChildStaticTransformation(child, t); |
| 5923 | if (transformed) { |
| 5924 | transformMatrix = attachInfo.mTmpMatrix; |
| 5925 | transformMatrix.set(t.getMatrix()); |
| 5926 | if (!childMatrix.isIdentity()) { |
| 5927 | transformMatrix.preConcat(childMatrix); |
| 5928 | } |
| 5929 | } else { |
| 5930 | transformMatrix = childMatrix; |
| 5931 | } |
| 5932 | } else { |
| 5933 | transformMatrix = childMatrix; |
| 5934 | } |
| 5935 | transformMatrix.mapRect(boundingRect); |
Alan Viverette | c45b1d4 | 2015-11-16 15:38:59 -0500 | [diff] [blame] | 5936 | dirty.set((int) Math.floor(boundingRect.left), |
| 5937 | (int) Math.floor(boundingRect.top), |
| 5938 | (int) Math.ceil(boundingRect.right), |
| 5939 | (int) Math.ceil(boundingRect.bottom)); |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | do { |
| 5943 | View view = null; |
| 5944 | if (parent instanceof View) { |
| 5945 | view = (View) parent; |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | if (drawAnimation) { |
| 5949 | if (view != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5950 | view.mPrivateFlags |= PFLAG_DRAW_ANIMATION; |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5951 | } else if (parent instanceof ViewRootImpl) { |
| 5952 | ((ViewRootImpl) parent).mIsAnimating = true; |
| 5953 | } |
| 5954 | } |
| 5955 | |
| 5956 | // If the parent is dirty opaque or not dirty, mark it dirty with the opaque |
| 5957 | // flag coming from the child that initiated the invalidate |
| 5958 | if (view != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 5959 | if ((view.mPrivateFlags & PFLAG_DIRTY_MASK) != PFLAG_DIRTY) { |
Nader Jawad | 70e7299 | 2018-05-08 10:54:33 -0700 | [diff] [blame] | 5960 | view.mPrivateFlags = (view.mPrivateFlags & ~PFLAG_DIRTY_MASK) | PFLAG_DIRTY; |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | parent = parent.invalidateChildInParent(location, dirty); |
| 5965 | if (view != null) { |
| 5966 | // Account for transform on current parent |
| 5967 | Matrix m = view.getMatrix(); |
| 5968 | if (!m.isIdentity()) { |
| 5969 | RectF boundingRect = attachInfo.mTmpTransformRect; |
| 5970 | boundingRect.set(dirty); |
| 5971 | m.mapRect(boundingRect); |
Alan Viverette | c45b1d4 | 2015-11-16 15:38:59 -0500 | [diff] [blame] | 5972 | dirty.set((int) Math.floor(boundingRect.left), |
| 5973 | (int) Math.floor(boundingRect.top), |
| 5974 | (int) Math.ceil(boundingRect.right), |
| 5975 | (int) Math.ceil(boundingRect.bottom)); |
Romain Guy | fe455af | 2012-02-15 16:40:20 -0800 | [diff] [blame] | 5976 | } |
| 5977 | } |
| 5978 | } while (parent != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5979 | } |
| 5980 | } |
| 5981 | |
| 5982 | /** |
| 5983 | * Don't call or override this method. It is used for the implementation of |
| 5984 | * the view hierarchy. |
| 5985 | * |
| 5986 | * This implementation returns null if this ViewGroup does not have a parent, |
| 5987 | * if this ViewGroup is already fully invalidated or if the dirty rectangle |
| 5988 | * does not intersect with this ViewGroup's bounds. |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5989 | * |
| 5990 | * @deprecated Use {@link #onDescendantInvalidated(View, View)} instead to observe updates to |
| 5991 | * draw state in descendants. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | */ |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 5993 | @Deprecated |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 5994 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5995 | public ViewParent invalidateChildInParent(final int[] location, final Rect dirty) { |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 5996 | if ((mPrivateFlags & (PFLAG_DRAWN | PFLAG_DRAWING_CACHE_VALID)) != 0) { |
| 5997 | // either DRAWN, or DRAWING_CACHE_VALID |
| 5998 | if ((mGroupFlags & (FLAG_OPTIMIZE_INVALIDATE | FLAG_ANIMATION_DONE)) |
| 5999 | != FLAG_OPTIMIZE_INVALIDATE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | dirty.offset(location[CHILD_LEFT_INDEX] - mScrollX, |
| 6001 | location[CHILD_TOP_INDEX] - mScrollY); |
Chet Haase | a4f14eb | 2013-04-22 11:11:39 -0700 | [diff] [blame] | 6002 | if ((mGroupFlags & FLAG_CLIP_CHILDREN) == 0) { |
| 6003 | dirty.union(0, 0, mRight - mLeft, mBottom - mTop); |
| 6004 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6005 | |
| 6006 | final int left = mLeft; |
| 6007 | final int top = mTop; |
| 6008 | |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 6009 | if ((mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN) { |
| 6010 | if (!dirty.intersect(0, 0, mRight - left, mBottom - top)) { |
| 6011 | dirty.setEmpty(); |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 6012 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6013 | } |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 6014 | |
| 6015 | location[CHILD_LEFT_INDEX] = left; |
| 6016 | location[CHILD_TOP_INDEX] = top; |
Selim Cinek | 1cb8b08 | 2016-12-21 15:34:30 +0000 | [diff] [blame] | 6017 | } else { |
Selim Cinek | 1cb8b08 | 2016-12-21 15:34:30 +0000 | [diff] [blame] | 6018 | |
Chet Haase | a3db866 | 2011-07-19 10:36:05 -0700 | [diff] [blame] | 6019 | if ((mGroupFlags & FLAG_CLIP_CHILDREN) == FLAG_CLIP_CHILDREN) { |
| 6020 | dirty.set(0, 0, mRight - mLeft, mBottom - mTop); |
| 6021 | } else { |
| 6022 | // in case the dirty rect extends outside the bounds of this container |
| 6023 | dirty.union(0, 0, mRight - mLeft, mBottom - mTop); |
| 6024 | } |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 6025 | location[CHILD_LEFT_INDEX] = mLeft; |
| 6026 | location[CHILD_TOP_INDEX] = mTop; |
Romain Guy | 3a3133d | 2011-02-01 22:59:58 -0800 | [diff] [blame] | 6027 | |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 6028 | mPrivateFlags &= ~PFLAG_DRAWN; |
Selim Cinek | 1cb8b08 | 2016-12-21 15:34:30 +0000 | [diff] [blame] | 6029 | } |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 6030 | mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; |
| 6031 | if (mLayerType != LAYER_TYPE_NONE) { |
| 6032 | mPrivateFlags |= PFLAG_INVALIDATED; |
| 6033 | } |
| 6034 | |
| 6035 | return mParent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | return null; |
| 6039 | } |
| 6040 | |
| 6041 | /** |
| 6042 | * Offset a rectangle that is in a descendant's coordinate |
| 6043 | * space into our coordinate space. |
| 6044 | * @param descendant A descendant of this view |
| 6045 | * @param rect A rectangle defined in descendant's coordinate space. |
| 6046 | */ |
| 6047 | public final void offsetDescendantRectToMyCoords(View descendant, Rect rect) { |
| 6048 | offsetRectBetweenParentAndChild(descendant, rect, true, false); |
| 6049 | } |
| 6050 | |
| 6051 | /** |
| 6052 | * Offset a rectangle that is in our coordinate space into an ancestor's |
| 6053 | * coordinate space. |
| 6054 | * @param descendant A descendant of this view |
| 6055 | * @param rect A rectangle defined in descendant's coordinate space. |
| 6056 | */ |
| 6057 | public final void offsetRectIntoDescendantCoords(View descendant, Rect rect) { |
| 6058 | offsetRectBetweenParentAndChild(descendant, rect, false, false); |
| 6059 | } |
| 6060 | |
| 6061 | /** |
| 6062 | * Helper method that offsets a rect either from parent to descendant or |
| 6063 | * descendant to parent. |
| 6064 | */ |
| 6065 | void offsetRectBetweenParentAndChild(View descendant, Rect rect, |
| 6066 | boolean offsetFromChildToParent, boolean clipToBounds) { |
| 6067 | |
| 6068 | // already in the same coord system :) |
| 6069 | if (descendant == this) { |
| 6070 | return; |
| 6071 | } |
| 6072 | |
| 6073 | ViewParent theParent = descendant.mParent; |
| 6074 | |
| 6075 | // search and offset up to the parent |
| 6076 | while ((theParent != null) |
| 6077 | && (theParent instanceof View) |
| 6078 | && (theParent != this)) { |
| 6079 | |
| 6080 | if (offsetFromChildToParent) { |
Hyunyoung Song | 4eb1a4e | 2016-03-09 22:51:02 +0000 | [diff] [blame] | 6081 | rect.offset(descendant.mLeft - descendant.mScrollX, |
| 6082 | descendant.mTop - descendant.mScrollY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | if (clipToBounds) { |
| 6084 | View p = (View) theParent; |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 6085 | boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft, |
| 6086 | p.mBottom - p.mTop); |
| 6087 | if (!intersected) { |
| 6088 | rect.setEmpty(); |
| 6089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6090 | } |
| 6091 | } else { |
| 6092 | if (clipToBounds) { |
| 6093 | View p = (View) theParent; |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 6094 | boolean intersected = rect.intersect(0, 0, p.mRight - p.mLeft, |
| 6095 | p.mBottom - p.mTop); |
| 6096 | if (!intersected) { |
| 6097 | rect.setEmpty(); |
| 6098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | } |
Hyunyoung Song | 4eb1a4e | 2016-03-09 22:51:02 +0000 | [diff] [blame] | 6100 | rect.offset(descendant.mScrollX - descendant.mLeft, |
| 6101 | descendant.mScrollY - descendant.mTop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | descendant = (View) theParent; |
| 6105 | theParent = descendant.mParent; |
| 6106 | } |
| 6107 | |
| 6108 | // now that we are up to this view, need to offset one more time |
| 6109 | // to get into our coordinate space |
| 6110 | if (theParent == this) { |
| 6111 | if (offsetFromChildToParent) { |
Hyunyoung Song | 4eb1a4e | 2016-03-09 22:51:02 +0000 | [diff] [blame] | 6112 | rect.offset(descendant.mLeft - descendant.mScrollX, |
| 6113 | descendant.mTop - descendant.mScrollY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6114 | } else { |
Hyunyoung Song | 4eb1a4e | 2016-03-09 22:51:02 +0000 | [diff] [blame] | 6115 | rect.offset(descendant.mScrollX - descendant.mLeft, |
| 6116 | descendant.mScrollY - descendant.mTop); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6117 | } |
| 6118 | } else { |
| 6119 | throw new IllegalArgumentException("parameter must be a descendant of this view"); |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | /** |
| 6124 | * Offset the vertical location of all children of this view by the specified number of pixels. |
| 6125 | * |
| 6126 | * @param offset the number of pixels to offset |
| 6127 | * |
| 6128 | * @hide |
| 6129 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 6130 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6131 | public void offsetChildrenTopAndBottom(int offset) { |
| 6132 | final int count = mChildrenCount; |
| 6133 | final View[] children = mChildren; |
Romain Guy | 5549cb5 | 2013-05-06 18:42:08 -0700 | [diff] [blame] | 6134 | boolean invalidate = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6135 | |
| 6136 | for (int i = 0; i < count; i++) { |
| 6137 | final View v = children[i]; |
| 6138 | v.mTop += offset; |
| 6139 | v.mBottom += offset; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6140 | if (v.mRenderNode != null) { |
Romain Guy | 5549cb5 | 2013-05-06 18:42:08 -0700 | [diff] [blame] | 6141 | invalidate = true; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6142 | v.mRenderNode.offsetTopAndBottom(offset); |
Chet Haase | a1cff50 | 2012-02-21 13:43:44 -0800 | [diff] [blame] | 6143 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | } |
Romain Guy | 5549cb5 | 2013-05-06 18:42:08 -0700 | [diff] [blame] | 6145 | |
| 6146 | if (invalidate) { |
| 6147 | invalidateViewProperty(false, false); |
| 6148 | } |
Eugene Susla | 72c510f | 2018-01-23 21:12:11 +0000 | [diff] [blame] | 6149 | notifySubtreeAccessibilityStateChangedIfNeeded(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6150 | } |
| 6151 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 6152 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { |
Abodunrinwa Toki | 4e7a120 | 2016-05-03 18:23:12 +0100 | [diff] [blame] | 6154 | return getChildVisibleRect(child, r, offset, false); |
| 6155 | } |
| 6156 | |
| 6157 | /** |
Abodunrinwa Toki | cb66406 | 2016-05-13 19:26:03 +0100 | [diff] [blame] | 6158 | * @param forceParentCheck true to guarantee that this call will propagate to all ancestors, |
| 6159 | * false otherwise |
| 6160 | * |
Abodunrinwa Toki | 4e7a120 | 2016-05-03 18:23:12 +0100 | [diff] [blame] | 6161 | * @hide |
| 6162 | */ |
| 6163 | public boolean getChildVisibleRect( |
| 6164 | View child, Rect r, android.graphics.Point offset, boolean forceParentCheck) { |
Adam Powell | f93bb6d | 2011-12-12 15:21:57 -0800 | [diff] [blame] | 6165 | // It doesn't make a whole lot of sense to call this on a view that isn't attached, |
| 6166 | // but for some simple tests it can be useful. If we don't have attach info this |
| 6167 | // will allocate memory. |
| 6168 | final RectF rect = mAttachInfo != null ? mAttachInfo.mTmpTransformRect : new RectF(); |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6169 | rect.set(r); |
| 6170 | |
| 6171 | if (!child.hasIdentityMatrix()) { |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6172 | child.getMatrix().mapRect(rect); |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6173 | } |
| 6174 | |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6175 | final int dx = child.mLeft - mScrollX; |
| 6176 | final int dy = child.mTop - mScrollY; |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6177 | |
| 6178 | rect.offset(dx, dy); |
| 6179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | if (offset != null) { |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6181 | if (!child.hasIdentityMatrix()) { |
Adam Powell | f93bb6d | 2011-12-12 15:21:57 -0800 | [diff] [blame] | 6182 | float[] position = mAttachInfo != null ? mAttachInfo.mTmpTransformLocation |
| 6183 | : new float[2]; |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6184 | position[0] = offset.x; |
| 6185 | position[1] = offset.y; |
| 6186 | child.getMatrix().mapPoints(position); |
Alan Viverette | c45b1d4 | 2015-11-16 15:38:59 -0500 | [diff] [blame] | 6187 | offset.x = Math.round(position[0]); |
| 6188 | offset.y = Math.round(position[1]); |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6189 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6190 | offset.x += dx; |
| 6191 | offset.y += dy; |
| 6192 | } |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6193 | |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6194 | final int width = mRight - mLeft; |
| 6195 | final int height = mBottom - mTop; |
| 6196 | |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6197 | boolean rectIsVisible = true; |
Adam Powell | 35da41e | 2014-12-10 18:59:34 -0800 | [diff] [blame] | 6198 | if (mParent == null || |
| 6199 | (mParent instanceof ViewGroup && ((ViewGroup) mParent).getClipChildren())) { |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6200 | // Clip to bounds. |
| 6201 | rectIsVisible = rect.intersect(0, 0, width, height); |
Gilles Debunne | cea4513 | 2011-11-24 02:19:27 +0100 | [diff] [blame] | 6202 | } |
| 6203 | |
Abodunrinwa Toki | 4e7a120 | 2016-05-03 18:23:12 +0100 | [diff] [blame] | 6204 | if ((forceParentCheck || rectIsVisible) |
| 6205 | && (mGroupFlags & CLIP_TO_PADDING_MASK) == CLIP_TO_PADDING_MASK) { |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6206 | // Clip to padding. |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6207 | rectIsVisible = rect.intersect(mPaddingLeft, mPaddingTop, |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6208 | width - mPaddingRight, height - mPaddingBottom); |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6209 | } |
| 6210 | |
Abodunrinwa Toki | 4e7a120 | 2016-05-03 18:23:12 +0100 | [diff] [blame] | 6211 | if ((forceParentCheck || rectIsVisible) && mClipBounds != null) { |
Alan Viverette | ab2cf6d | 2014-11-26 14:34:36 -0800 | [diff] [blame] | 6212 | // Clip to clipBounds. |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6213 | rectIsVisible = rect.intersect(mClipBounds.left, mClipBounds.top, mClipBounds.right, |
| 6214 | mClipBounds.bottom); |
| 6215 | } |
Alan Viverette | c45b1d4 | 2015-11-16 15:38:59 -0500 | [diff] [blame] | 6216 | r.set((int) Math.floor(rect.left), (int) Math.floor(rect.top), |
| 6217 | (int) Math.ceil(rect.right), (int) Math.ceil(rect.bottom)); |
Abodunrinwa Toki | 4e7a120 | 2016-05-03 18:23:12 +0100 | [diff] [blame] | 6218 | |
| 6219 | if ((forceParentCheck || rectIsVisible) && mParent != null) { |
Abodunrinwa Toki | cb66406 | 2016-05-13 19:26:03 +0100 | [diff] [blame] | 6220 | if (mParent instanceof ViewGroup) { |
| 6221 | rectIsVisible = ((ViewGroup) mParent) |
| 6222 | .getChildVisibleRect(this, r, offset, forceParentCheck); |
| 6223 | } else { |
| 6224 | rectIsVisible = mParent.getChildVisibleRect(this, r, offset); |
| 6225 | } |
George Mount | 002d43d | 2014-11-11 12:54:43 -0800 | [diff] [blame] | 6226 | } |
| 6227 | return rectIsVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6228 | } |
| 6229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6230 | @Override |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 6231 | public final void layout(int l, int t, int r, int b) { |
Chet Haase | 430742f | 2013-04-12 11:18:36 -0700 | [diff] [blame] | 6232 | if (!mSuppressLayout && (mTransition == null || !mTransition.isChangingLayout())) { |
Chet Haase | 7dd4a53 | 2012-04-16 13:35:09 -0700 | [diff] [blame] | 6233 | if (mTransition != null) { |
| 6234 | mTransition.layoutChange(this); |
| 6235 | } |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 6236 | super.layout(l, t, r, b); |
| 6237 | } else { |
| 6238 | // record the fact that we noop'd it; request layout when transition finishes |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 6239 | mLayoutCalledWhileSuppressed = true; |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 6240 | } |
| 6241 | } |
| 6242 | |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 6243 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6244 | protected abstract void onLayout(boolean changed, |
| 6245 | int l, int t, int r, int b); |
| 6246 | |
| 6247 | /** |
| 6248 | * Indicates whether the view group has the ability to animate its children |
| 6249 | * after the first layout. |
| 6250 | * |
| 6251 | * @return true if the children can be animated, false otherwise |
| 6252 | */ |
| 6253 | protected boolean canAnimate() { |
| 6254 | return mLayoutAnimationController != null; |
| 6255 | } |
| 6256 | |
| 6257 | /** |
| 6258 | * Runs the layout animation. Calling this method triggers a relayout of |
| 6259 | * this view group. |
| 6260 | */ |
| 6261 | public void startLayoutAnimation() { |
| 6262 | if (mLayoutAnimationController != null) { |
| 6263 | mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6264 | requestLayout(); |
| 6265 | } |
| 6266 | } |
| 6267 | |
| 6268 | /** |
| 6269 | * Schedules the layout animation to be played after the next layout pass |
| 6270 | * of this view group. This can be used to restart the layout animation |
| 6271 | * when the content of the view group changes or when the activity is |
| 6272 | * paused and resumed. |
| 6273 | */ |
| 6274 | public void scheduleLayoutAnimation() { |
| 6275 | mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6276 | } |
| 6277 | |
| 6278 | /** |
| 6279 | * Sets the layout animation controller used to animate the group's |
| 6280 | * children after the first layout. |
| 6281 | * |
| 6282 | * @param controller the animation controller |
| 6283 | */ |
| 6284 | public void setLayoutAnimation(LayoutAnimationController controller) { |
| 6285 | mLayoutAnimationController = controller; |
| 6286 | if (mLayoutAnimationController != null) { |
| 6287 | mGroupFlags |= FLAG_RUN_ANIMATION; |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | /** |
| 6292 | * Returns the layout animation controller used to animate the group's |
| 6293 | * children. |
| 6294 | * |
| 6295 | * @return the current animation controller |
| 6296 | */ |
| 6297 | public LayoutAnimationController getLayoutAnimation() { |
| 6298 | return mLayoutAnimationController; |
| 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * Indicates whether the children's drawing cache is used during a layout |
| 6303 | * animation. By default, the drawing cache is enabled but this will prevent |
| 6304 | * nested layout animations from working. To nest animations, you must disable |
| 6305 | * the cache. |
| 6306 | * |
| 6307 | * @return true if the animation cache is enabled, false otherwise |
| 6308 | * |
| 6309 | * @see #setAnimationCacheEnabled(boolean) |
| 6310 | * @see View#setDrawingCacheEnabled(boolean) |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6311 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6312 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6313 | * Caching behavior of children may be controlled through {@link View#setLayerType(int, Paint)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6315 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | public boolean isAnimationCacheEnabled() { |
| 6317 | return (mGroupFlags & FLAG_ANIMATION_CACHE) == FLAG_ANIMATION_CACHE; |
| 6318 | } |
| 6319 | |
| 6320 | /** |
| 6321 | * Enables or disables the children's drawing cache during a layout animation. |
| 6322 | * By default, the drawing cache is enabled but this will prevent nested |
| 6323 | * layout animations from working. To nest animations, you must disable the |
| 6324 | * cache. |
| 6325 | * |
| 6326 | * @param enabled true to enable the animation cache, false otherwise |
| 6327 | * |
| 6328 | * @see #isAnimationCacheEnabled() |
| 6329 | * @see View#setDrawingCacheEnabled(boolean) |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6330 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6331 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6332 | * Caching behavior of children may be controlled through {@link View#setLayerType(int, Paint)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6334 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6335 | public void setAnimationCacheEnabled(boolean enabled) { |
| 6336 | setBooleanFlag(FLAG_ANIMATION_CACHE, enabled); |
| 6337 | } |
| 6338 | |
| 6339 | /** |
| 6340 | * Indicates whether this ViewGroup will always try to draw its children using their |
| 6341 | * drawing cache. By default this property is enabled. |
| 6342 | * |
| 6343 | * @return true if the animation cache is enabled, false otherwise |
| 6344 | * |
| 6345 | * @see #setAlwaysDrawnWithCacheEnabled(boolean) |
| 6346 | * @see #setChildrenDrawnWithCacheEnabled(boolean) |
| 6347 | * @see View#setDrawingCacheEnabled(boolean) |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6348 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6349 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6350 | * Child views may no longer have their caching behavior disabled by parents. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6352 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6353 | public boolean isAlwaysDrawnWithCacheEnabled() { |
| 6354 | return (mGroupFlags & FLAG_ALWAYS_DRAWN_WITH_CACHE) == FLAG_ALWAYS_DRAWN_WITH_CACHE; |
| 6355 | } |
| 6356 | |
| 6357 | /** |
| 6358 | * Indicates whether this ViewGroup will always try to draw its children using their |
| 6359 | * drawing cache. This property can be set to true when the cache rendering is |
| 6360 | * slightly different from the children's normal rendering. Renderings can be different, |
| 6361 | * for instance, when the cache's quality is set to low. |
| 6362 | * |
| 6363 | * When this property is disabled, the ViewGroup will use the drawing cache of its |
| 6364 | * children only when asked to. It's usually the task of subclasses to tell ViewGroup |
| 6365 | * when to start using the drawing cache and when to stop using it. |
| 6366 | * |
| 6367 | * @param always true to always draw with the drawing cache, false otherwise |
| 6368 | * |
| 6369 | * @see #isAlwaysDrawnWithCacheEnabled() |
| 6370 | * @see #setChildrenDrawnWithCacheEnabled(boolean) |
| 6371 | * @see View#setDrawingCacheEnabled(boolean) |
| 6372 | * @see View#setDrawingCacheQuality(int) |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6373 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6374 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6375 | * Child views may no longer have their caching behavior disabled by parents. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6377 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | public void setAlwaysDrawnWithCacheEnabled(boolean always) { |
| 6379 | setBooleanFlag(FLAG_ALWAYS_DRAWN_WITH_CACHE, always); |
| 6380 | } |
| 6381 | |
| 6382 | /** |
| 6383 | * Indicates whether the ViewGroup is currently drawing its children using |
| 6384 | * their drawing cache. |
| 6385 | * |
| 6386 | * @return true if children should be drawn with their cache, false otherwise |
| 6387 | * |
| 6388 | * @see #setAlwaysDrawnWithCacheEnabled(boolean) |
| 6389 | * @see #setChildrenDrawnWithCacheEnabled(boolean) |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6390 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6391 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6392 | * Child views may no longer be forced to cache their rendering state by their parents. |
| 6393 | * Use {@link View#setLayerType(int, Paint)} on individual Views instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6395 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | protected boolean isChildrenDrawnWithCacheEnabled() { |
| 6397 | return (mGroupFlags & FLAG_CHILDREN_DRAWN_WITH_CACHE) == FLAG_CHILDREN_DRAWN_WITH_CACHE; |
| 6398 | } |
| 6399 | |
| 6400 | /** |
| 6401 | * Tells the ViewGroup to draw its children using their drawing cache. This property |
| 6402 | * is ignored when {@link #isAlwaysDrawnWithCacheEnabled()} is true. A child's drawing cache |
| 6403 | * will be used only if it has been enabled. |
| 6404 | * |
| 6405 | * Subclasses should call this method to start and stop using the drawing cache when |
| 6406 | * they perform performance sensitive operations, like scrolling or animating. |
| 6407 | * |
| 6408 | * @param enabled true if children should be drawn with their cache, false otherwise |
| 6409 | * |
| 6410 | * @see #setAlwaysDrawnWithCacheEnabled(boolean) |
| 6411 | * @see #isChildrenDrawnWithCacheEnabled() |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6412 | * |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6413 | * @deprecated As of {@link android.os.Build.VERSION_CODES#M}, this property is ignored. |
Chris Craik | 5a6bbae | 2015-04-10 17:41:34 -0700 | [diff] [blame] | 6414 | * Child views may no longer be forced to cache their rendering state by their parents. |
| 6415 | * Use {@link View#setLayerType(int, Paint)} on individual Views instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6416 | */ |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 6417 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6418 | protected void setChildrenDrawnWithCacheEnabled(boolean enabled) { |
| 6419 | setBooleanFlag(FLAG_CHILDREN_DRAWN_WITH_CACHE, enabled); |
| 6420 | } |
| 6421 | |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 6422 | /** |
| 6423 | * Indicates whether the ViewGroup is drawing its children in the order defined by |
| 6424 | * {@link #getChildDrawingOrder(int, int)}. |
| 6425 | * |
| 6426 | * @return true if children drawing order is defined by {@link #getChildDrawingOrder(int, int)}, |
| 6427 | * false otherwise |
| 6428 | * |
| 6429 | * @see #setChildrenDrawingOrderEnabled(boolean) |
| 6430 | * @see #getChildDrawingOrder(int, int) |
| 6431 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6432 | @ViewDebug.ExportedProperty(category = "drawing") |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 6433 | protected boolean isChildrenDrawingOrderEnabled() { |
| 6434 | return (mGroupFlags & FLAG_USE_CHILD_DRAWING_ORDER) == FLAG_USE_CHILD_DRAWING_ORDER; |
| 6435 | } |
| 6436 | |
| 6437 | /** |
| 6438 | * Tells the ViewGroup whether to draw its children in the order defined by the method |
| 6439 | * {@link #getChildDrawingOrder(int, int)}. |
Chris Craik | e83cbd4 | 2014-09-03 17:52:24 -0700 | [diff] [blame] | 6440 | * <p> |
| 6441 | * Note that {@link View#getZ() Z} reordering, done by {@link #dispatchDraw(Canvas)}, |
| 6442 | * will override custom child ordering done via this method. |
Romain Guy | 293451e | 2009-11-04 13:59:48 -0800 | [diff] [blame] | 6443 | * |
| 6444 | * @param enabled true if the order of the children when drawing is determined by |
| 6445 | * {@link #getChildDrawingOrder(int, int)}, false otherwise |
| 6446 | * |
| 6447 | * @see #isChildrenDrawingOrderEnabled() |
| 6448 | * @see #getChildDrawingOrder(int, int) |
| 6449 | */ |
| 6450 | protected void setChildrenDrawingOrderEnabled(boolean enabled) { |
| 6451 | setBooleanFlag(FLAG_USE_CHILD_DRAWING_ORDER, enabled); |
| 6452 | } |
| 6453 | |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 6454 | private boolean hasBooleanFlag(int flag) { |
Philip Milne | f091b66 | 2013-02-27 11:15:21 -0800 | [diff] [blame] | 6455 | return (mGroupFlags & flag) == flag; |
| 6456 | } |
| 6457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6458 | private void setBooleanFlag(int flag, boolean value) { |
| 6459 | if (value) { |
| 6460 | mGroupFlags |= flag; |
| 6461 | } else { |
| 6462 | mGroupFlags &= ~flag; |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /** |
| 6467 | * Returns an integer indicating what types of drawing caches are kept in memory. |
| 6468 | * |
| 6469 | * @see #setPersistentDrawingCache(int) |
| 6470 | * @see #setAnimationCacheEnabled(boolean) |
| 6471 | * |
| 6472 | * @return one or a combination of {@link #PERSISTENT_NO_CACHE}, |
| 6473 | * {@link #PERSISTENT_ANIMATION_CACHE}, {@link #PERSISTENT_SCROLLING_CACHE} |
| 6474 | * and {@link #PERSISTENT_ALL_CACHES} |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 6475 | * |
| 6476 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 6477 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 6478 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 6479 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 6480 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 6481 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 6482 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 6483 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 6484 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 6485 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 6486 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 6487 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 6489 | @Deprecated |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 6490 | @ViewDebug.ExportedProperty(category = "drawing", mapping = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6491 | @ViewDebug.IntToString(from = PERSISTENT_NO_CACHE, to = "NONE"), |
Romain Guy | 203688c | 2010-05-12 15:41:32 -0700 | [diff] [blame] | 6492 | @ViewDebug.IntToString(from = PERSISTENT_ANIMATION_CACHE, to = "ANIMATION"), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | @ViewDebug.IntToString(from = PERSISTENT_SCROLLING_CACHE, to = "SCROLLING"), |
| 6494 | @ViewDebug.IntToString(from = PERSISTENT_ALL_CACHES, to = "ALL") |
| 6495 | }) |
| 6496 | public int getPersistentDrawingCache() { |
| 6497 | return mPersistentDrawingCache; |
| 6498 | } |
| 6499 | |
| 6500 | /** |
| 6501 | * Indicates what types of drawing caches should be kept in memory after |
| 6502 | * they have been created. |
| 6503 | * |
| 6504 | * @see #getPersistentDrawingCache() |
| 6505 | * @see #setAnimationCacheEnabled(boolean) |
| 6506 | * |
| 6507 | * @param drawingCacheToKeep one or a combination of {@link #PERSISTENT_NO_CACHE}, |
| 6508 | * {@link #PERSISTENT_ANIMATION_CACHE}, {@link #PERSISTENT_SCROLLING_CACHE} |
| 6509 | * and {@link #PERSISTENT_ALL_CACHES} |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 6510 | * |
| 6511 | * @deprecated The view drawing cache was largely made obsolete with the introduction of |
| 6512 | * hardware-accelerated rendering in API 11. With hardware-acceleration, intermediate cache |
| 6513 | * layers are largely unnecessary and can easily result in a net loss in performance due to the |
| 6514 | * cost of creating and updating the layer. In the rare cases where caching layers are useful, |
| 6515 | * such as for alpha animations, {@link #setLayerType(int, Paint)} handles this with hardware |
| 6516 | * rendering. For software-rendered snapshots of a small part of the View hierarchy or |
| 6517 | * individual Views it is recommended to create a {@link Canvas} from either a {@link Bitmap} or |
| 6518 | * {@link android.graphics.Picture} and call {@link #draw(Canvas)} on the View. However these |
| 6519 | * software-rendered usages are discouraged and have compatibility issues with hardware-only |
| 6520 | * rendering features such as {@link android.graphics.Bitmap.Config#HARDWARE Config.HARDWARE} |
| 6521 | * bitmaps, real-time shadows, and outline clipping. For screenshots of the UI for feedback |
| 6522 | * reports or unit testing the {@link PixelCopy} API is recommended. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | */ |
John Reck | 949cfe1 | 2017-10-09 13:27:03 -0700 | [diff] [blame] | 6524 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | public void setPersistentDrawingCache(int drawingCacheToKeep) { |
| 6526 | mPersistentDrawingCache = drawingCacheToKeep & PERSISTENT_ALL_CACHES; |
| 6527 | } |
| 6528 | |
Philip Milne | f091b66 | 2013-02-27 11:15:21 -0800 | [diff] [blame] | 6529 | private void setLayoutMode(int layoutMode, boolean explicitly) { |
| 6530 | mLayoutMode = layoutMode; |
| 6531 | setBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET, explicitly); |
| 6532 | } |
| 6533 | |
| 6534 | /** |
| 6535 | * Recursively traverse the view hierarchy, resetting the layoutMode of any |
| 6536 | * descendants that had inherited a different layoutMode from a previous parent. |
| 6537 | * Recursion terminates when a descendant's mode is: |
| 6538 | * <ul> |
| 6539 | * <li>Undefined</li> |
| 6540 | * <li>The same as the root node's</li> |
| 6541 | * <li>A mode that had been explicitly set</li> |
| 6542 | * <ul/> |
| 6543 | * The first two clauses are optimizations. |
| 6544 | * @param layoutModeOfRoot |
| 6545 | */ |
| 6546 | @Override |
| 6547 | void invalidateInheritedLayoutMode(int layoutModeOfRoot) { |
| 6548 | if (mLayoutMode == LAYOUT_MODE_UNDEFINED || |
| 6549 | mLayoutMode == layoutModeOfRoot || |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 6550 | hasBooleanFlag(FLAG_LAYOUT_MODE_WAS_EXPLICITLY_SET)) { |
Philip Milne | f091b66 | 2013-02-27 11:15:21 -0800 | [diff] [blame] | 6551 | return; |
| 6552 | } |
| 6553 | setLayoutMode(LAYOUT_MODE_UNDEFINED, false); |
| 6554 | |
| 6555 | // apply recursively |
| 6556 | for (int i = 0, N = getChildCount(); i < N; i++) { |
| 6557 | getChildAt(i).invalidateInheritedLayoutMode(layoutModeOfRoot); |
| 6558 | } |
| 6559 | } |
| 6560 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6561 | /** |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 6562 | * Returns the basis of alignment during layout operations on this ViewGroup: |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 6563 | * either {@link #LAYOUT_MODE_CLIP_BOUNDS} or {@link #LAYOUT_MODE_OPTICAL_BOUNDS}. |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 6564 | * <p> |
| 6565 | * If no layoutMode was explicitly set, either programmatically or in an XML resource, |
| 6566 | * the method returns the layoutMode of the view's parent ViewGroup if such a parent exists, |
| 6567 | * otherwise the method returns a default value of {@link #LAYOUT_MODE_CLIP_BOUNDS}. |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6568 | * |
Philip Milne | fcc6a0f | 2012-04-16 16:12:19 -0700 | [diff] [blame] | 6569 | * @return the layout mode to use during layout operations |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6570 | * |
| 6571 | * @see #setLayoutMode(int) |
| 6572 | */ |
| 6573 | public int getLayoutMode() { |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 6574 | if (mLayoutMode == LAYOUT_MODE_UNDEFINED) { |
Philip Milne | f091b66 | 2013-02-27 11:15:21 -0800 | [diff] [blame] | 6575 | int inheritedLayoutMode = (mParent instanceof ViewGroup) ? |
| 6576 | ((ViewGroup) mParent).getLayoutMode() : LAYOUT_MODE_DEFAULT; |
| 6577 | setLayoutMode(inheritedLayoutMode, false); |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 6578 | } |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6579 | return mLayoutMode; |
| 6580 | } |
| 6581 | |
| 6582 | /** |
Philip Milne | cfb631b | 2012-10-26 10:51:46 -0700 | [diff] [blame] | 6583 | * Sets the basis of alignment during the layout of this ViewGroup. |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 6584 | * Valid values are either {@link #LAYOUT_MODE_CLIP_BOUNDS} or |
| 6585 | * {@link #LAYOUT_MODE_OPTICAL_BOUNDS}. |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6586 | * |
Philip Milne | fcc6a0f | 2012-04-16 16:12:19 -0700 | [diff] [blame] | 6587 | * @param layoutMode the layout mode to use during layout operations |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6588 | * |
| 6589 | * @see #getLayoutMode() |
Scott Main | 27a8508 | 2013-06-10 10:39:48 -0700 | [diff] [blame] | 6590 | * @attr ref android.R.styleable#ViewGroup_layoutMode |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6591 | */ |
| 6592 | public void setLayoutMode(int layoutMode) { |
| 6593 | if (mLayoutMode != layoutMode) { |
Philip Milne | f091b66 | 2013-02-27 11:15:21 -0800 | [diff] [blame] | 6594 | invalidateInheritedLayoutMode(layoutMode); |
| 6595 | setLayoutMode(layoutMode, layoutMode != LAYOUT_MODE_UNDEFINED); |
Philip Milne | 1557fd7 | 2012-04-04 23:41:34 -0700 | [diff] [blame] | 6596 | requestLayout(); |
| 6597 | } |
| 6598 | } |
| 6599 | |
| 6600 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6601 | * Returns a new set of layout parameters based on the supplied attributes set. |
| 6602 | * |
| 6603 | * @param attrs the attributes to build the layout parameters from |
| 6604 | * |
| 6605 | * @return an instance of {@link android.view.ViewGroup.LayoutParams} or one |
| 6606 | * of its descendants |
| 6607 | */ |
| 6608 | public LayoutParams generateLayoutParams(AttributeSet attrs) { |
| 6609 | return new LayoutParams(getContext(), attrs); |
| 6610 | } |
| 6611 | |
| 6612 | /** |
| 6613 | * Returns a safe set of layout parameters based on the supplied layout params. |
| 6614 | * When a ViewGroup is passed a View whose layout params do not pass the test of |
| 6615 | * {@link #checkLayoutParams(android.view.ViewGroup.LayoutParams)}, this method |
| 6616 | * is invoked. This method should return a new set of layout params suitable for |
| 6617 | * this ViewGroup, possibly by copying the appropriate attributes from the |
| 6618 | * specified set of layout params. |
| 6619 | * |
| 6620 | * @param p The layout parameters to convert into a suitable set of layout parameters |
| 6621 | * for this ViewGroup. |
| 6622 | * |
| 6623 | * @return an instance of {@link android.view.ViewGroup.LayoutParams} or one |
| 6624 | * of its descendants |
| 6625 | */ |
| 6626 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 6627 | return p; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | } |
| 6629 | |
| 6630 | /** |
| 6631 | * Returns a set of default layout parameters. These parameters are requested |
| 6632 | * when the View passed to {@link #addView(View)} has no layout parameters |
| 6633 | * already set. If null is returned, an exception is thrown from addView. |
| 6634 | * |
| 6635 | * @return a set of default layout parameters or null |
| 6636 | */ |
| 6637 | protected LayoutParams generateDefaultLayoutParams() { |
| 6638 | return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
| 6639 | } |
| 6640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6641 | @Override |
| 6642 | protected void debug(int depth) { |
| 6643 | super.debug(depth); |
| 6644 | String output; |
| 6645 | |
| 6646 | if (mFocused != null) { |
| 6647 | output = debugIndent(depth); |
| 6648 | output += "mFocused"; |
| 6649 | Log.d(VIEW_LOG_TAG, output); |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 6650 | mFocused.debug(depth + 1); |
| 6651 | } |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 6652 | if (mDefaultFocus != null) { |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 6653 | output = debugIndent(depth); |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 6654 | output += "mDefaultFocus"; |
Vadim Tryshev | 01d8c49 | 2016-12-15 11:33:15 -0800 | [diff] [blame] | 6655 | Log.d(VIEW_LOG_TAG, output); |
Vadim Tryshev | 5ca7398 | 2017-01-04 17:24:43 -0800 | [diff] [blame] | 6656 | mDefaultFocus.debug(depth + 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | } |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 6658 | if (mFocusedInCluster != null) { |
| 6659 | output = debugIndent(depth); |
| 6660 | output += "mFocusedInCluster"; |
| 6661 | Log.d(VIEW_LOG_TAG, output); |
| 6662 | mFocusedInCluster.debug(depth + 1); |
| 6663 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6664 | if (mChildrenCount != 0) { |
| 6665 | output = debugIndent(depth); |
| 6666 | output += "{"; |
| 6667 | Log.d(VIEW_LOG_TAG, output); |
| 6668 | } |
| 6669 | int count = mChildrenCount; |
| 6670 | for (int i = 0; i < count; i++) { |
| 6671 | View child = mChildren[i]; |
| 6672 | child.debug(depth + 1); |
| 6673 | } |
| 6674 | |
| 6675 | if (mChildrenCount != 0) { |
| 6676 | output = debugIndent(depth); |
| 6677 | output += "}"; |
| 6678 | Log.d(VIEW_LOG_TAG, output); |
| 6679 | } |
| 6680 | } |
| 6681 | |
| 6682 | /** |
| 6683 | * Returns the position in the group of the specified child view. |
| 6684 | * |
| 6685 | * @param child the view for which to get the position |
| 6686 | * @return a positive integer representing the position of the view in the |
| 6687 | * group, or -1 if the view does not exist in the group |
| 6688 | */ |
| 6689 | public int indexOfChild(View child) { |
| 6690 | final int count = mChildrenCount; |
| 6691 | final View[] children = mChildren; |
| 6692 | for (int i = 0; i < count; i++) { |
| 6693 | if (children[i] == child) { |
| 6694 | return i; |
| 6695 | } |
| 6696 | } |
| 6697 | return -1; |
| 6698 | } |
| 6699 | |
| 6700 | /** |
| 6701 | * Returns the number of children in the group. |
| 6702 | * |
| 6703 | * @return a positive integer representing the number of children in |
| 6704 | * the group |
| 6705 | */ |
| 6706 | public int getChildCount() { |
| 6707 | return mChildrenCount; |
| 6708 | } |
| 6709 | |
| 6710 | /** |
| 6711 | * Returns the view at the specified position in the group. |
| 6712 | * |
| 6713 | * @param index the position at which to get the view from |
| 6714 | * @return the view at the specified position or null if the position |
| 6715 | * does not exist within the group |
| 6716 | */ |
| 6717 | public View getChildAt(int index) { |
Adam Powell | 3ba8f5d6 | 2011-03-07 15:36:33 -0800 | [diff] [blame] | 6718 | if (index < 0 || index >= mChildrenCount) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6719 | return null; |
| 6720 | } |
Adam Powell | 3ba8f5d6 | 2011-03-07 15:36:33 -0800 | [diff] [blame] | 6721 | return mChildren[index]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6722 | } |
| 6723 | |
| 6724 | /** |
| 6725 | * Ask all of the children of this view to measure themselves, taking into |
| 6726 | * account both the MeasureSpec requirements for this view and its padding. |
| 6727 | * We skip children that are in the GONE state The heavy lifting is done in |
| 6728 | * getChildMeasureSpec. |
| 6729 | * |
| 6730 | * @param widthMeasureSpec The width requirements for this view |
| 6731 | * @param heightMeasureSpec The height requirements for this view |
| 6732 | */ |
| 6733 | protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec) { |
| 6734 | final int size = mChildrenCount; |
| 6735 | final View[] children = mChildren; |
| 6736 | for (int i = 0; i < size; ++i) { |
| 6737 | final View child = children[i]; |
| 6738 | if ((child.mViewFlags & VISIBILITY_MASK) != GONE) { |
| 6739 | measureChild(child, widthMeasureSpec, heightMeasureSpec); |
| 6740 | } |
| 6741 | } |
| 6742 | } |
| 6743 | |
| 6744 | /** |
| 6745 | * Ask one of the children of this view to measure itself, taking into |
| 6746 | * account both the MeasureSpec requirements for this view and its padding. |
| 6747 | * The heavy lifting is done in getChildMeasureSpec. |
| 6748 | * |
| 6749 | * @param child The child to measure |
| 6750 | * @param parentWidthMeasureSpec The width requirements for this view |
| 6751 | * @param parentHeightMeasureSpec The height requirements for this view |
| 6752 | */ |
| 6753 | protected void measureChild(View child, int parentWidthMeasureSpec, |
| 6754 | int parentHeightMeasureSpec) { |
| 6755 | final LayoutParams lp = child.getLayoutParams(); |
| 6756 | |
| 6757 | final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, |
| 6758 | mPaddingLeft + mPaddingRight, lp.width); |
| 6759 | final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, |
| 6760 | mPaddingTop + mPaddingBottom, lp.height); |
| 6761 | |
| 6762 | child.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * Ask one of the children of this view to measure itself, taking into |
| 6767 | * account both the MeasureSpec requirements for this view and its padding |
| 6768 | * and margins. The child must have MarginLayoutParams The heavy lifting is |
| 6769 | * done in getChildMeasureSpec. |
| 6770 | * |
| 6771 | * @param child The child to measure |
| 6772 | * @param parentWidthMeasureSpec The width requirements for this view |
| 6773 | * @param widthUsed Extra space that has been used up by the parent |
| 6774 | * horizontally (possibly by other children of the parent) |
| 6775 | * @param parentHeightMeasureSpec The height requirements for this view |
| 6776 | * @param heightUsed Extra space that has been used up by the parent |
| 6777 | * vertically (possibly by other children of the parent) |
| 6778 | */ |
| 6779 | protected void measureChildWithMargins(View child, |
| 6780 | int parentWidthMeasureSpec, int widthUsed, |
| 6781 | int parentHeightMeasureSpec, int heightUsed) { |
| 6782 | final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); |
| 6783 | |
| 6784 | final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec, |
| 6785 | mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin |
| 6786 | + widthUsed, lp.width); |
| 6787 | final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec, |
| 6788 | mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin |
| 6789 | + heightUsed, lp.height); |
| 6790 | |
| 6791 | child.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 6792 | } |
| 6793 | |
| 6794 | /** |
| 6795 | * Does the hard part of measureChildren: figuring out the MeasureSpec to |
| 6796 | * pass to a particular child. This method figures out the right MeasureSpec |
| 6797 | * for one dimension (height or width) of one child view. |
| 6798 | * |
| 6799 | * The goal is to combine information from our MeasureSpec with the |
| 6800 | * LayoutParams of the child to get the best possible results. For example, |
| 6801 | * if the this view knows its size (because its MeasureSpec has a mode of |
| 6802 | * EXACTLY), and the child has indicated in its LayoutParams that it wants |
| 6803 | * to be the same size as the parent, the parent should ask the child to |
| 6804 | * layout given an exact size. |
| 6805 | * |
| 6806 | * @param spec The requirements for this view |
| 6807 | * @param padding The padding of this view for the current dimension and |
| 6808 | * margins, if applicable |
| 6809 | * @param childDimension How big the child wants to be in the current |
| 6810 | * dimension |
| 6811 | * @return a MeasureSpec integer for the child |
| 6812 | */ |
| 6813 | public static int getChildMeasureSpec(int spec, int padding, int childDimension) { |
| 6814 | int specMode = MeasureSpec.getMode(spec); |
| 6815 | int specSize = MeasureSpec.getSize(spec); |
| 6816 | |
| 6817 | int size = Math.max(0, specSize - padding); |
| 6818 | |
| 6819 | int resultSize = 0; |
| 6820 | int resultMode = 0; |
| 6821 | |
| 6822 | switch (specMode) { |
| 6823 | // Parent has imposed an exact size on us |
| 6824 | case MeasureSpec.EXACTLY: |
| 6825 | if (childDimension >= 0) { |
| 6826 | resultSize = childDimension; |
| 6827 | resultMode = MeasureSpec.EXACTLY; |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6828 | } else if (childDimension == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6829 | // Child wants to be our size. So be it. |
| 6830 | resultSize = size; |
| 6831 | resultMode = MeasureSpec.EXACTLY; |
| 6832 | } else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 6833 | // Child wants to determine its own size. It can't be |
| 6834 | // bigger than us. |
| 6835 | resultSize = size; |
| 6836 | resultMode = MeasureSpec.AT_MOST; |
| 6837 | } |
| 6838 | break; |
| 6839 | |
| 6840 | // Parent has imposed a maximum size on us |
| 6841 | case MeasureSpec.AT_MOST: |
| 6842 | if (childDimension >= 0) { |
| 6843 | // Child wants a specific size... so be it |
| 6844 | resultSize = childDimension; |
| 6845 | resultMode = MeasureSpec.EXACTLY; |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6846 | } else if (childDimension == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | // Child wants to be our size, but our size is not fixed. |
| 6848 | // Constrain child to not be bigger than us. |
| 6849 | resultSize = size; |
| 6850 | resultMode = MeasureSpec.AT_MOST; |
| 6851 | } else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 6852 | // Child wants to determine its own size. It can't be |
| 6853 | // bigger than us. |
| 6854 | resultSize = size; |
| 6855 | resultMode = MeasureSpec.AT_MOST; |
| 6856 | } |
| 6857 | break; |
| 6858 | |
| 6859 | // Parent asked to see how big we want to be |
| 6860 | case MeasureSpec.UNSPECIFIED: |
| 6861 | if (childDimension >= 0) { |
| 6862 | // Child wants a specific size... let him have it |
| 6863 | resultSize = childDimension; |
| 6864 | resultMode = MeasureSpec.EXACTLY; |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6865 | } else if (childDimension == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | // Child wants to be our size... find out how big it should |
| 6867 | // be |
Adam Powell | d5dbf4b | 2015-06-11 13:19:24 -0700 | [diff] [blame] | 6868 | resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6869 | resultMode = MeasureSpec.UNSPECIFIED; |
| 6870 | } else if (childDimension == LayoutParams.WRAP_CONTENT) { |
| 6871 | // Child wants to determine its own size.... find out how |
| 6872 | // big it should be |
Adam Powell | d5dbf4b | 2015-06-11 13:19:24 -0700 | [diff] [blame] | 6873 | resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6874 | resultMode = MeasureSpec.UNSPECIFIED; |
| 6875 | } |
| 6876 | break; |
| 6877 | } |
Tor Norbye | 6756864 | 2015-03-31 07:47:23 -0700 | [diff] [blame] | 6878 | //noinspection ResourceType |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6879 | return MeasureSpec.makeMeasureSpec(resultSize, resultMode); |
| 6880 | } |
| 6881 | |
| 6882 | |
| 6883 | /** |
| 6884 | * Removes any pending animations for views that have been removed. Call |
| 6885 | * this if you don't want animations for exiting views to stack up. |
| 6886 | */ |
| 6887 | public void clearDisappearingChildren() { |
John Reck | ca7a9da | 2014-03-05 16:29:07 -0800 | [diff] [blame] | 6888 | final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 6889 | if (disappearingChildren != null) { |
| 6890 | final int count = disappearingChildren.size(); |
| 6891 | for (int i = 0; i < count; i++) { |
| 6892 | final View view = disappearingChildren.get(i); |
| 6893 | if (view.mAttachInfo != null) { |
| 6894 | view.dispatchDetachedFromWindow(); |
| 6895 | } |
| 6896 | view.clearAnimation(); |
| 6897 | } |
| 6898 | disappearingChildren.clear(); |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 6899 | invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6900 | } |
| 6901 | } |
| 6902 | |
| 6903 | /** |
| 6904 | * Add a view which is removed from mChildren but still needs animation |
| 6905 | * |
| 6906 | * @param v View to add |
| 6907 | */ |
| 6908 | private void addDisappearingView(View v) { |
| 6909 | ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 6910 | |
| 6911 | if (disappearingChildren == null) { |
| 6912 | disappearingChildren = mDisappearingChildren = new ArrayList<View>(); |
| 6913 | } |
| 6914 | |
| 6915 | disappearingChildren.add(v); |
| 6916 | } |
| 6917 | |
| 6918 | /** |
| 6919 | * Cleanup a view when its animation is done. This may mean removing it from |
| 6920 | * the list of disappearing views. |
| 6921 | * |
| 6922 | * @param view The view whose animation has finished |
| 6923 | * @param animation The animation, cannot be null |
| 6924 | */ |
Chet Haase | 64a48c1 | 2012-02-13 16:33:29 -0800 | [diff] [blame] | 6925 | void finishAnimatingView(final View view, Animation animation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6926 | final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 6927 | if (disappearingChildren != null) { |
| 6928 | if (disappearingChildren.contains(view)) { |
| 6929 | disappearingChildren.remove(view); |
| 6930 | |
| 6931 | if (view.mAttachInfo != null) { |
| 6932 | view.dispatchDetachedFromWindow(); |
| 6933 | } |
| 6934 | |
| 6935 | view.clearAnimation(); |
| 6936 | mGroupFlags |= FLAG_INVALIDATE_REQUIRED; |
| 6937 | } |
| 6938 | } |
| 6939 | |
| 6940 | if (animation != null && !animation.getFillAfter()) { |
| 6941 | view.clearAnimation(); |
| 6942 | } |
| 6943 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6944 | if ((view.mPrivateFlags & PFLAG_ANIMATION_STARTED) == PFLAG_ANIMATION_STARTED) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | view.onAnimationEnd(); |
| 6946 | // Should be performed by onAnimationEnd() but this avoid an infinite loop, |
| 6947 | // so we'd rather be safe than sorry |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 6948 | view.mPrivateFlags &= ~PFLAG_ANIMATION_STARTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | // Draw one more frame after the animation is done |
| 6950 | mGroupFlags |= FLAG_INVALIDATE_REQUIRED; |
| 6951 | } |
| 6952 | } |
| 6953 | |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 6954 | /** |
Chet Haase | aceafe6 | 2011-08-26 15:44:33 -0700 | [diff] [blame] | 6955 | * Utility function called by View during invalidation to determine whether a view that |
| 6956 | * is invisible or gone should still be invalidated because it is being transitioned (and |
| 6957 | * therefore still needs to be drawn). |
| 6958 | */ |
| 6959 | boolean isViewTransitioning(View view) { |
| 6960 | return (mTransitioningViews != null && mTransitioningViews.contains(view)); |
| 6961 | } |
| 6962 | |
| 6963 | /** |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 6964 | * This method tells the ViewGroup that the given View object, which should have this |
| 6965 | * ViewGroup as its parent, |
| 6966 | * should be kept around (re-displayed when the ViewGroup draws its children) even if it |
| 6967 | * is removed from its parent. This allows animations, such as those used by |
| 6968 | * {@link android.app.Fragment} and {@link android.animation.LayoutTransition} to animate |
| 6969 | * the removal of views. A call to this method should always be accompanied by a later call |
| 6970 | * to {@link #endViewTransition(View)}, such as after an animation on the View has finished, |
| 6971 | * so that the View finally gets removed. |
| 6972 | * |
| 6973 | * @param view The View object to be kept visible even if it gets removed from its parent. |
| 6974 | */ |
| 6975 | public void startViewTransition(View view) { |
| 6976 | if (view.mParent == this) { |
| 6977 | if (mTransitioningViews == null) { |
| 6978 | mTransitioningViews = new ArrayList<View>(); |
| 6979 | } |
| 6980 | mTransitioningViews.add(view); |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | /** |
| 6985 | * This method should always be called following an earlier call to |
| 6986 | * {@link #startViewTransition(View)}. The given View is finally removed from its parent |
| 6987 | * and will no longer be displayed. Note that this method does not perform the functionality |
| 6988 | * of removing a view from its parent; it just discontinues the display of a View that |
| 6989 | * has previously been removed. |
| 6990 | * |
| 6991 | * @return view The View object that has been removed but is being kept around in the visible |
| 6992 | * hierarchy by an earlier call to {@link #startViewTransition(View)}. |
| 6993 | */ |
| 6994 | public void endViewTransition(View view) { |
| 6995 | if (mTransitioningViews != null) { |
| 6996 | mTransitioningViews.remove(view); |
| 6997 | final ArrayList<View> disappearingChildren = mDisappearingChildren; |
| 6998 | if (disappearingChildren != null && disappearingChildren.contains(view)) { |
| 6999 | disappearingChildren.remove(view); |
Chet Haase | 5e25c2c | 2010-09-16 11:15:56 -0700 | [diff] [blame] | 7000 | if (mVisibilityChangingChildren != null && |
| 7001 | mVisibilityChangingChildren.contains(view)) { |
| 7002 | mVisibilityChangingChildren.remove(view); |
| 7003 | } else { |
| 7004 | if (view.mAttachInfo != null) { |
| 7005 | view.dispatchDetachedFromWindow(); |
| 7006 | } |
| 7007 | if (view.mParent != null) { |
| 7008 | view.mParent = null; |
| 7009 | } |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 7010 | } |
Chet Haase | b85967b | 2012-03-26 14:37:51 -0700 | [diff] [blame] | 7011 | invalidate(); |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 7012 | } |
| 7013 | } |
| 7014 | } |
| 7015 | |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7016 | private LayoutTransition.TransitionListener mLayoutTransitionListener = |
| 7017 | new LayoutTransition.TransitionListener() { |
| 7018 | @Override |
| 7019 | public void startTransition(LayoutTransition transition, ViewGroup container, |
| 7020 | View view, int transitionType) { |
| 7021 | // We only care about disappearing items, since we need special logic to keep |
| 7022 | // those items visible after they've been 'removed' |
| 7023 | if (transitionType == LayoutTransition.DISAPPEARING) { |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 7024 | startViewTransition(view); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | @Override |
| 7029 | public void endTransition(LayoutTransition transition, ViewGroup container, |
| 7030 | View view, int transitionType) { |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 7031 | if (mLayoutCalledWhileSuppressed && !transition.isChangingLayout()) { |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 7032 | requestLayout(); |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 7033 | mLayoutCalledWhileSuppressed = false; |
Chet Haase | 9c08744 | 2011-01-12 16:20:16 -0800 | [diff] [blame] | 7034 | } |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7035 | if (transitionType == LayoutTransition.DISAPPEARING && mTransitioningViews != null) { |
Chet Haase | b20db3e | 2010-09-10 13:07:30 -0700 | [diff] [blame] | 7036 | endViewTransition(view); |
Chet Haase | 21cd138 | 2010-09-01 17:42:29 -0700 | [diff] [blame] | 7037 | } |
| 7038 | } |
| 7039 | }; |
| 7040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | /** |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 7042 | * Tells this ViewGroup to suppress all layout() calls until layout |
| 7043 | * suppression is disabled with a later call to suppressLayout(false). |
| 7044 | * When layout suppression is disabled, a requestLayout() call is sent |
| 7045 | * if layout() was attempted while layout was being suppressed. |
Chet Haase | b989502 | 2013-04-02 15:10:58 -0700 | [diff] [blame] | 7046 | */ |
| 7047 | public void suppressLayout(boolean suppress) { |
| 7048 | mSuppressLayout = suppress; |
| 7049 | if (!suppress) { |
| 7050 | if (mLayoutCalledWhileSuppressed) { |
| 7051 | requestLayout(); |
| 7052 | mLayoutCalledWhileSuppressed = false; |
| 7053 | } |
| 7054 | } |
| 7055 | } |
| 7056 | |
| 7057 | /** |
Chet Haase | 199acdf | 2013-07-24 18:40:55 -0700 | [diff] [blame] | 7058 | * Returns whether layout calls on this container are currently being |
| 7059 | * suppressed, due to an earlier call to {@link #suppressLayout(boolean)}. |
| 7060 | * |
| 7061 | * @return true if layout calls are currently suppressed, false otherwise. |
Chet Haase | 199acdf | 2013-07-24 18:40:55 -0700 | [diff] [blame] | 7062 | */ |
| 7063 | public boolean isLayoutSuppressed() { |
| 7064 | return mSuppressLayout; |
| 7065 | } |
| 7066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | @Override |
| 7068 | public boolean gatherTransparentRegion(Region region) { |
| 7069 | // If no transparent regions requested, we are always opaque. |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7070 | final boolean meOpaque = (mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7071 | if (meOpaque && region == null) { |
| 7072 | // The caller doesn't care about the region, so stop now. |
| 7073 | return true; |
| 7074 | } |
| 7075 | super.gatherTransparentRegion(region); |
Teng-Hui Zhu | f8da30d | 2016-08-15 10:28:20 -0700 | [diff] [blame] | 7076 | // Instead of naively traversing the view tree, we have to traverse according to the Z |
| 7077 | // order here. We need to go with the same order as dispatchDraw(). |
| 7078 | // One example is that after surfaceView punch a hole, we will still allow other views drawn |
| 7079 | // on top of that hole. In this case, those other views should be able to cut the |
| 7080 | // transparent region into smaller area. |
| 7081 | final int childrenCount = mChildrenCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | boolean noneOfTheChildrenAreTransparent = true; |
Teng-Hui Zhu | f8da30d | 2016-08-15 10:28:20 -0700 | [diff] [blame] | 7083 | if (childrenCount > 0) { |
| 7084 | final ArrayList<View> preorderedList = buildOrderedChildList(); |
| 7085 | final boolean customOrder = preorderedList == null |
| 7086 | && isChildrenDrawingOrderEnabled(); |
| 7087 | final View[] children = mChildren; |
| 7088 | for (int i = 0; i < childrenCount; i++) { |
| 7089 | final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); |
| 7090 | final View child = getAndVerifyPreorderedView(preorderedList, children, childIndex); |
| 7091 | if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE || child.getAnimation() != null) { |
| 7092 | if (!child.gatherTransparentRegion(region)) { |
| 7093 | noneOfTheChildrenAreTransparent = false; |
| 7094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7095 | } |
| 7096 | } |
Teng-Hui Zhu | f8da30d | 2016-08-15 10:28:20 -0700 | [diff] [blame] | 7097 | if (preorderedList != null) preorderedList.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | } |
| 7099 | return meOpaque || noneOfTheChildrenAreTransparent; |
| 7100 | } |
| 7101 | |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 7102 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | public void requestTransparentRegion(View child) { |
| 7104 | if (child != null) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 7105 | child.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7106 | if (mParent != null) { |
| 7107 | mParent.requestTransparentRegion(this); |
| 7108 | } |
| 7109 | } |
| 7110 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7112 | @Override |
Adam Powell | 46e38fd | 2014-02-03 10:16:49 -0800 | [diff] [blame] | 7113 | public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { |
| 7114 | insets = super.dispatchApplyWindowInsets(insets); |
Jorim Jaggi | 15637fd | 2018-12-04 13:38:03 +0100 | [diff] [blame] | 7115 | if (View.sBrokenInsetsDispatch) { |
| 7116 | return brokenDispatchApplyWindowInsets(insets); |
| 7117 | } else { |
| 7118 | return newDispatchApplyWindowInsets(insets); |
| 7119 | } |
| 7120 | } |
| 7121 | |
| 7122 | private WindowInsets brokenDispatchApplyWindowInsets(WindowInsets insets) { |
Adam Powell | 0d9fdba | 2014-06-11 15:33:08 -0700 | [diff] [blame] | 7123 | if (!insets.isConsumed()) { |
Adam Powell | 46e38fd | 2014-02-03 10:16:49 -0800 | [diff] [blame] | 7124 | final int count = getChildCount(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | for (int i = 0; i < count; i++) { |
Adam Powell | 46e38fd | 2014-02-03 10:16:49 -0800 | [diff] [blame] | 7126 | insets = getChildAt(i).dispatchApplyWindowInsets(insets); |
Adam Powell | 0d9fdba | 2014-06-11 15:33:08 -0700 | [diff] [blame] | 7127 | if (insets.isConsumed()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7128 | break; |
| 7129 | } |
| 7130 | } |
| 7131 | } |
Adam Powell | 46e38fd | 2014-02-03 10:16:49 -0800 | [diff] [blame] | 7132 | return insets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | } |
| 7134 | |
Jorim Jaggi | 15637fd | 2018-12-04 13:38:03 +0100 | [diff] [blame] | 7135 | private WindowInsets newDispatchApplyWindowInsets(WindowInsets insets) { |
| 7136 | final int count = getChildCount(); |
| 7137 | for (int i = 0; i < count; i++) { |
| 7138 | getChildAt(i).dispatchApplyWindowInsets(insets); |
| 7139 | } |
| 7140 | return insets; |
| 7141 | } |
| 7142 | |
Jorim Jaggi | 02a741f | 2018-12-12 17:40:19 -0800 | [diff] [blame] | 7143 | @Override |
| 7144 | void dispatchWindowInsetsAnimationStarted(InsetsAnimation animation) { |
| 7145 | super.dispatchWindowInsetsAnimationStarted(animation); |
| 7146 | final int count = getChildCount(); |
| 7147 | for (int i = 0; i < count; i++) { |
| 7148 | getChildAt(i).dispatchWindowInsetsAnimationStarted(animation); |
| 7149 | } |
| 7150 | } |
| 7151 | |
| 7152 | @Override |
| 7153 | WindowInsets dispatchWindowInsetsAnimationProgress(WindowInsets insets) { |
| 7154 | insets = super.dispatchWindowInsetsAnimationProgress(insets); |
| 7155 | final int count = getChildCount(); |
| 7156 | for (int i = 0; i < count; i++) { |
| 7157 | getChildAt(i).dispatchWindowInsetsAnimationProgress(insets); |
| 7158 | } |
| 7159 | return insets; |
| 7160 | } |
| 7161 | |
| 7162 | @Override |
| 7163 | void dispatchWindowInsetsAnimationFinished(InsetsAnimation animation) { |
| 7164 | super.dispatchWindowInsetsAnimationFinished(animation); |
| 7165 | final int count = getChildCount(); |
| 7166 | for (int i = 0; i < count; i++) { |
| 7167 | getChildAt(i).dispatchWindowInsetsAnimationFinished(animation); |
| 7168 | } |
| 7169 | } |
| 7170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7171 | /** |
| 7172 | * Returns the animation listener to which layout animation events are |
| 7173 | * sent. |
| 7174 | * |
| 7175 | * @return an {@link android.view.animation.Animation.AnimationListener} |
| 7176 | */ |
| 7177 | public Animation.AnimationListener getLayoutAnimationListener() { |
| 7178 | return mAnimationListener; |
| 7179 | } |
| 7180 | |
| 7181 | @Override |
| 7182 | protected void drawableStateChanged() { |
| 7183 | super.drawableStateChanged(); |
| 7184 | |
| 7185 | if ((mGroupFlags & FLAG_NOTIFY_CHILDREN_ON_DRAWABLE_STATE_CHANGE) != 0) { |
| 7186 | if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0) { |
| 7187 | throw new IllegalStateException("addStateFromChildren cannot be enabled if a" |
| 7188 | + " child has duplicateParentState set to true"); |
| 7189 | } |
| 7190 | |
| 7191 | final View[] children = mChildren; |
| 7192 | final int count = mChildrenCount; |
| 7193 | |
| 7194 | for (int i = 0; i < count; i++) { |
| 7195 | final View child = children[i]; |
| 7196 | if ((child.mViewFlags & DUPLICATE_PARENT_STATE) != 0) { |
| 7197 | child.refreshDrawableState(); |
| 7198 | } |
| 7199 | } |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | @Override |
Dianne Hackborn | e213677 | 2010-11-04 15:08:59 -0700 | [diff] [blame] | 7204 | public void jumpDrawablesToCurrentState() { |
| 7205 | super.jumpDrawablesToCurrentState(); |
| 7206 | final View[] children = mChildren; |
| 7207 | final int count = mChildrenCount; |
| 7208 | for (int i = 0; i < count; i++) { |
| 7209 | children[i].jumpDrawablesToCurrentState(); |
| 7210 | } |
| 7211 | } |
| 7212 | |
| 7213 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7214 | protected int[] onCreateDrawableState(int extraSpace) { |
| 7215 | if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) == 0) { |
| 7216 | return super.onCreateDrawableState(extraSpace); |
| 7217 | } |
| 7218 | |
| 7219 | int need = 0; |
| 7220 | int n = getChildCount(); |
| 7221 | for (int i = 0; i < n; i++) { |
| 7222 | int[] childState = getChildAt(i).getDrawableState(); |
| 7223 | |
| 7224 | if (childState != null) { |
| 7225 | need += childState.length; |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | int[] state = super.onCreateDrawableState(extraSpace + need); |
| 7230 | |
| 7231 | for (int i = 0; i < n; i++) { |
| 7232 | int[] childState = getChildAt(i).getDrawableState(); |
| 7233 | |
| 7234 | if (childState != null) { |
| 7235 | state = mergeDrawableStates(state, childState); |
| 7236 | } |
| 7237 | } |
| 7238 | |
| 7239 | return state; |
| 7240 | } |
| 7241 | |
| 7242 | /** |
| 7243 | * Sets whether this ViewGroup's drawable states also include |
| 7244 | * its children's drawable states. This is used, for example, to |
| 7245 | * make a group appear to be focused when its child EditText or button |
| 7246 | * is focused. |
| 7247 | */ |
| 7248 | public void setAddStatesFromChildren(boolean addsStates) { |
| 7249 | if (addsStates) { |
| 7250 | mGroupFlags |= FLAG_ADD_STATES_FROM_CHILDREN; |
| 7251 | } else { |
| 7252 | mGroupFlags &= ~FLAG_ADD_STATES_FROM_CHILDREN; |
| 7253 | } |
| 7254 | |
| 7255 | refreshDrawableState(); |
| 7256 | } |
| 7257 | |
| 7258 | /** |
| 7259 | * Returns whether this ViewGroup's drawable states also include |
| 7260 | * its children's drawable states. This is used, for example, to |
| 7261 | * make a group appear to be focused when its child EditText or button |
| 7262 | * is focused. |
| 7263 | */ |
| 7264 | public boolean addStatesFromChildren() { |
| 7265 | return (mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0; |
| 7266 | } |
| 7267 | |
| 7268 | /** |
Jeff Smith | a45746e | 2012-07-19 14:19:24 -0500 | [diff] [blame] | 7269 | * If {@link #addStatesFromChildren} is true, refreshes this group's |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7270 | * drawable state (to include the states from its children). |
| 7271 | */ |
Alan Viverette | be463f2 | 2016-01-21 10:50:10 -0500 | [diff] [blame] | 7272 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7273 | public void childDrawableStateChanged(View child) { |
| 7274 | if ((mGroupFlags & FLAG_ADD_STATES_FROM_CHILDREN) != 0) { |
| 7275 | refreshDrawableState(); |
| 7276 | } |
| 7277 | } |
| 7278 | |
| 7279 | /** |
| 7280 | * Specifies the animation listener to which layout animation events must |
| 7281 | * be sent. Only |
| 7282 | * {@link android.view.animation.Animation.AnimationListener#onAnimationStart(Animation)} |
| 7283 | * and |
| 7284 | * {@link android.view.animation.Animation.AnimationListener#onAnimationEnd(Animation)} |
| 7285 | * are invoked. |
| 7286 | * |
| 7287 | * @param animationListener the layout animation listener |
| 7288 | */ |
| 7289 | public void setLayoutAnimationListener(Animation.AnimationListener animationListener) { |
| 7290 | mAnimationListener = animationListener; |
| 7291 | } |
| 7292 | |
| 7293 | /** |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7294 | * This method is called by LayoutTransition when there are 'changing' animations that need |
| 7295 | * to start after the layout/setup phase. The request is forwarded to the ViewAncestor, who |
| 7296 | * starts all pending transitions prior to the drawing phase in the current traversal. |
| 7297 | * |
| 7298 | * @param transition The LayoutTransition to be started on the next traversal. |
| 7299 | * |
| 7300 | * @hide |
| 7301 | */ |
| 7302 | public void requestTransitionStart(LayoutTransition transition) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7303 | ViewRootImpl viewAncestor = getViewRootImpl(); |
Chet Haase | 1abf7fa | 2011-08-17 18:31:56 -0700 | [diff] [blame] | 7304 | if (viewAncestor != null) { |
| 7305 | viewAncestor.requestTransitionStart(transition); |
| 7306 | } |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 7307 | } |
| 7308 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 7309 | /** |
| 7310 | * @hide |
| 7311 | */ |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 7312 | @Override |
Fabrice Di Meglio | 09ecb25 | 2013-05-03 16:51:55 -0700 | [diff] [blame] | 7313 | public boolean resolveRtlPropertiesIfNeeded() { |
| 7314 | final boolean result = super.resolveRtlPropertiesIfNeeded(); |
| 7315 | // We dont need to resolve the children RTL properties if nothing has changed for the parent |
| 7316 | if (result) { |
| 7317 | int count = getChildCount(); |
| 7318 | for (int i = 0; i < count; i++) { |
| 7319 | final View child = getChildAt(i); |
| 7320 | if (child.isLayoutDirectionInherited()) { |
| 7321 | child.resolveRtlPropertiesIfNeeded(); |
| 7322 | } |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7323 | } |
| 7324 | } |
Fabrice Di Meglio | 09ecb25 | 2013-05-03 16:51:55 -0700 | [diff] [blame] | 7325 | return result; |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
| 7328 | /** |
| 7329 | * @hide |
| 7330 | */ |
| 7331 | @Override |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7332 | public boolean resolveLayoutDirection() { |
| 7333 | final boolean result = super.resolveLayoutDirection(); |
| 7334 | if (result) { |
| 7335 | int count = getChildCount(); |
| 7336 | for (int i = 0; i < count; i++) { |
| 7337 | final View child = getChildAt(i); |
| 7338 | if (child.isLayoutDirectionInherited()) { |
| 7339 | child.resolveLayoutDirection(); |
| 7340 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7341 | } |
| 7342 | } |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7343 | return result; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | /** |
| 7347 | * @hide |
| 7348 | */ |
| 7349 | @Override |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7350 | public boolean resolveTextDirection() { |
| 7351 | final boolean result = super.resolveTextDirection(); |
| 7352 | if (result) { |
| 7353 | int count = getChildCount(); |
| 7354 | for (int i = 0; i < count; i++) { |
| 7355 | final View child = getChildAt(i); |
| 7356 | if (child.isTextDirectionInherited()) { |
| 7357 | child.resolveTextDirection(); |
| 7358 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7359 | } |
| 7360 | } |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7361 | return result; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | /** |
| 7365 | * @hide |
| 7366 | */ |
| 7367 | @Override |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7368 | public boolean resolveTextAlignment() { |
| 7369 | final boolean result = super.resolveTextAlignment(); |
| 7370 | if (result) { |
| 7371 | int count = getChildCount(); |
| 7372 | for (int i = 0; i < count; i++) { |
| 7373 | final View child = getChildAt(i); |
| 7374 | if (child.isTextAlignmentInherited()) { |
| 7375 | child.resolveTextAlignment(); |
| 7376 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7377 | } |
| 7378 | } |
Fabrice Di Meglio | 9a04856 | 2012-09-26 14:55:56 -0700 | [diff] [blame] | 7379 | return result; |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | /** |
| 7383 | * @hide |
| 7384 | */ |
| 7385 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 7386 | @UnsupportedAppUsage |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7387 | public void resolvePadding() { |
| 7388 | super.resolvePadding(); |
| 7389 | int count = getChildCount(); |
| 7390 | for (int i = 0; i < count; i++) { |
| 7391 | final View child = getChildAt(i); |
Adam Powell | 05f3512 | 2014-11-10 17:47:37 -0800 | [diff] [blame] | 7392 | if (child.isLayoutDirectionInherited() && !child.isPaddingResolved()) { |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7393 | child.resolvePadding(); |
| 7394 | } |
| 7395 | } |
| 7396 | } |
| 7397 | |
| 7398 | /** |
| 7399 | * @hide |
| 7400 | */ |
| 7401 | @Override |
| 7402 | protected void resolveDrawables() { |
| 7403 | super.resolveDrawables(); |
| 7404 | int count = getChildCount(); |
| 7405 | for (int i = 0; i < count; i++) { |
| 7406 | final View child = getChildAt(i); |
Adam Powell | 05f3512 | 2014-11-10 17:47:37 -0800 | [diff] [blame] | 7407 | if (child.isLayoutDirectionInherited() && !child.areDrawablesResolved()) { |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7408 | child.resolveDrawables(); |
| 7409 | } |
| 7410 | } |
| 7411 | } |
| 7412 | |
Fabrice Di Meglio | 1e0ed6b | 2012-10-18 16:06:52 -0700 | [diff] [blame] | 7413 | /** |
| 7414 | * @hide |
| 7415 | */ |
Fabrice Di Meglio | fcc3348 | 2012-10-18 11:11:51 -0700 | [diff] [blame] | 7416 | @Override |
| 7417 | public void resolveLayoutParams() { |
| 7418 | super.resolveLayoutParams(); |
| 7419 | int count = getChildCount(); |
| 7420 | for (int i = 0; i < count; i++) { |
| 7421 | final View child = getChildAt(i); |
| 7422 | child.resolveLayoutParams(); |
| 7423 | } |
| 7424 | } |
| 7425 | |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7426 | /** |
| 7427 | * @hide |
| 7428 | */ |
Aurimas Liutikas | 80e4e18 | 2018-08-13 16:13:37 -0700 | [diff] [blame] | 7429 | @TestApi |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7430 | @Override |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 7431 | public void resetResolvedLayoutDirection() { |
| 7432 | super.resetResolvedLayoutDirection(); |
| 7433 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 7434 | int count = getChildCount(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 7435 | for (int i = 0; i < count; i++) { |
| 7436 | final View child = getChildAt(i); |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 7437 | if (child.isLayoutDirectionInherited()) { |
Fabrice Di Meglio | 7f86c80 | 2011-07-01 15:09:24 -0700 | [diff] [blame] | 7438 | child.resetResolvedLayoutDirection(); |
Fabrice Di Meglio | 80dc53d | 2011-06-21 18:36:33 -0700 | [diff] [blame] | 7439 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7440 | } |
| 7441 | } |
| 7442 | |
| 7443 | /** |
| 7444 | * @hide |
| 7445 | */ |
Aurimas Liutikas | 80e4e18 | 2018-08-13 16:13:37 -0700 | [diff] [blame] | 7446 | @TestApi |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7447 | @Override |
| 7448 | public void resetResolvedTextDirection() { |
| 7449 | super.resetResolvedTextDirection(); |
| 7450 | |
| 7451 | int count = getChildCount(); |
| 7452 | for (int i = 0; i < count; i++) { |
| 7453 | final View child = getChildAt(i); |
Fabrice Di Meglio | 97e146c | 2012-09-23 15:45:16 -0700 | [diff] [blame] | 7454 | if (child.isTextDirectionInherited()) { |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 7455 | child.resetResolvedTextDirection(); |
| 7456 | } |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7457 | } |
| 7458 | } |
| 7459 | |
| 7460 | /** |
| 7461 | * @hide |
| 7462 | */ |
Aurimas Liutikas | 80e4e18 | 2018-08-13 16:13:37 -0700 | [diff] [blame] | 7463 | @TestApi |
Fabrice Di Meglio | 1f88ba8 | 2012-09-24 14:56:49 -0700 | [diff] [blame] | 7464 | @Override |
| 7465 | public void resetResolvedTextAlignment() { |
| 7466 | super.resetResolvedTextAlignment(); |
| 7467 | |
| 7468 | int count = getChildCount(); |
| 7469 | for (int i = 0; i < count; i++) { |
| 7470 | final View child = getChildAt(i); |
Fabrice Di Meglio | 1a7d487 | 2012-09-23 16:19:58 -0700 | [diff] [blame] | 7471 | if (child.isTextAlignmentInherited()) { |
Fabrice Di Meglio | 9da0f8a | 2012-03-13 19:37:57 -0700 | [diff] [blame] | 7472 | child.resetResolvedTextAlignment(); |
| 7473 | } |
| 7474 | } |
| 7475 | } |
| 7476 | |
Fabrice Di Meglio | 2226886 | 2011-06-27 18:13:18 -0700 | [diff] [blame] | 7477 | /** |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7478 | * @hide |
| 7479 | */ |
Aurimas Liutikas | 80e4e18 | 2018-08-13 16:13:37 -0700 | [diff] [blame] | 7480 | @TestApi |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7481 | @Override |
| 7482 | public void resetResolvedPadding() { |
| 7483 | super.resetResolvedPadding(); |
| 7484 | |
| 7485 | int count = getChildCount(); |
| 7486 | for (int i = 0; i < count; i++) { |
| 7487 | final View child = getChildAt(i); |
| 7488 | if (child.isLayoutDirectionInherited()) { |
| 7489 | child.resetResolvedPadding(); |
| 7490 | } |
| 7491 | } |
| 7492 | } |
| 7493 | |
| 7494 | /** |
| 7495 | * @hide |
| 7496 | */ |
Aurimas Liutikas | 80e4e18 | 2018-08-13 16:13:37 -0700 | [diff] [blame] | 7497 | @TestApi |
Fabrice Di Meglio | 84ebb35 | 2012-10-11 16:27:37 -0700 | [diff] [blame] | 7498 | @Override |
| 7499 | protected void resetResolvedDrawables() { |
| 7500 | super.resetResolvedDrawables(); |
| 7501 | |
| 7502 | int count = getChildCount(); |
| 7503 | for (int i = 0; i < count; i++) { |
| 7504 | final View child = getChildAt(i); |
| 7505 | if (child.isLayoutDirectionInherited()) { |
| 7506 | child.resetResolvedDrawables(); |
| 7507 | } |
| 7508 | } |
| 7509 | } |
| 7510 | |
| 7511 | /** |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7512 | * Return true if the pressed state should be delayed for children or descendants of this |
| 7513 | * ViewGroup. Generally, this should be done for containers that can scroll, such as a List. |
| 7514 | * This prevents the pressed state from appearing when the user is actually trying to scroll |
| 7515 | * the content. |
| 7516 | * |
| 7517 | * The default implementation returns true for compatibility reasons. Subclasses that do |
| 7518 | * not scroll should generally override this method and return false. |
| 7519 | */ |
| 7520 | public boolean shouldDelayChildPressedState() { |
| 7521 | return true; |
| 7522 | } |
| 7523 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7524 | /** |
| 7525 | * @inheritDoc |
| 7526 | */ |
| 7527 | @Override |
| 7528 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 7529 | return false; |
| 7530 | } |
| 7531 | |
| 7532 | /** |
| 7533 | * @inheritDoc |
| 7534 | */ |
| 7535 | @Override |
| 7536 | public void onNestedScrollAccepted(View child, View target, int axes) { |
| 7537 | mNestedScrollAxes = axes; |
| 7538 | } |
| 7539 | |
| 7540 | /** |
| 7541 | * @inheritDoc |
| 7542 | * |
| 7543 | * <p>The default implementation of onStopNestedScroll calls |
| 7544 | * {@link #stopNestedScroll()} to halt any recursive nested scrolling in progress.</p> |
| 7545 | */ |
| 7546 | @Override |
| 7547 | public void onStopNestedScroll(View child) { |
| 7548 | // Stop any recursive nested scrolling. |
| 7549 | stopNestedScroll(); |
Adam Powell | d4a22d4 | 2015-04-16 15:44:10 -0700 | [diff] [blame] | 7550 | mNestedScrollAxes = 0; |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7551 | } |
| 7552 | |
| 7553 | /** |
| 7554 | * @inheritDoc |
| 7555 | */ |
| 7556 | @Override |
| 7557 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 7558 | int dxUnconsumed, int dyUnconsumed) { |
Chris Banes | 61d5070 | 2016-03-23 13:11:45 +0000 | [diff] [blame] | 7559 | // Re-dispatch up the tree by default |
| 7560 | dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, null); |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | /** |
| 7564 | * @inheritDoc |
| 7565 | */ |
| 7566 | @Override |
| 7567 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
Chris Banes | 61d5070 | 2016-03-23 13:11:45 +0000 | [diff] [blame] | 7568 | // Re-dispatch up the tree by default |
| 7569 | dispatchNestedPreScroll(dx, dy, consumed, null); |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7570 | } |
| 7571 | |
| 7572 | /** |
| 7573 | * @inheritDoc |
| 7574 | */ |
| 7575 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 7576 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Chris Banes | 61d5070 | 2016-03-23 13:11:45 +0000 | [diff] [blame] | 7577 | // Re-dispatch up the tree by default |
| 7578 | return dispatchNestedFling(velocityX, velocityY, consumed); |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | /** |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 7582 | * @inheritDoc |
| 7583 | */ |
| 7584 | @Override |
| 7585 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
Chris Banes | 61d5070 | 2016-03-23 13:11:45 +0000 | [diff] [blame] | 7586 | // Re-dispatch up the tree by default |
| 7587 | return dispatchNestedPreFling(velocityX, velocityY); |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | /** |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7591 | * Return the current axes of nested scrolling for this ViewGroup. |
| 7592 | * |
| 7593 | * <p>A ViewGroup returning something other than {@link #SCROLL_AXIS_NONE} is currently |
| 7594 | * acting as a nested scrolling parent for one or more descendant views in the hierarchy.</p> |
| 7595 | * |
| 7596 | * @return Flags indicating the current axes of nested scrolling |
| 7597 | * @see #SCROLL_AXIS_HORIZONTAL |
| 7598 | * @see #SCROLL_AXIS_VERTICAL |
| 7599 | * @see #SCROLL_AXIS_NONE |
| 7600 | */ |
| 7601 | public int getNestedScrollAxes() { |
| 7602 | return mNestedScrollAxes; |
| 7603 | } |
| 7604 | |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7605 | /** @hide */ |
| 7606 | protected void onSetLayoutParams(View child, LayoutParams layoutParams) { |
Robert Carr | 5429daa | 2017-04-03 19:00:26 -0700 | [diff] [blame] | 7607 | requestLayout(); |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7608 | } |
| 7609 | |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 7610 | /** @hide */ |
| 7611 | @Override |
| 7612 | public void captureTransitioningViews(List<View> transitioningViews) { |
| 7613 | if (getVisibility() != View.VISIBLE) { |
| 7614 | return; |
| 7615 | } |
| 7616 | if (isTransitionGroup()) { |
| 7617 | transitioningViews.add(this); |
| 7618 | } else { |
| 7619 | int count = getChildCount(); |
| 7620 | for (int i = 0; i < count; i++) { |
| 7621 | View child = getChildAt(i); |
| 7622 | child.captureTransitioningViews(transitioningViews); |
| 7623 | } |
| 7624 | } |
| 7625 | } |
| 7626 | |
| 7627 | /** @hide */ |
| 7628 | @Override |
George Mount | abb352a | 2014-05-09 10:27:20 -0700 | [diff] [blame] | 7629 | public void findNamedViews(Map<String, View> namedElements) { |
George Mount | fe361d2 | 2014-07-08 17:25:25 -0700 | [diff] [blame] | 7630 | if (getVisibility() != VISIBLE && mGhostView == null) { |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 7631 | return; |
| 7632 | } |
George Mount | abb352a | 2014-05-09 10:27:20 -0700 | [diff] [blame] | 7633 | super.findNamedViews(namedElements); |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 7634 | int count = getChildCount(); |
| 7635 | for (int i = 0; i < count; i++) { |
| 7636 | View child = getChildAt(i); |
George Mount | abb352a | 2014-05-09 10:27:20 -0700 | [diff] [blame] | 7637 | child.findNamedViews(namedElements); |
George Mount | e180337 | 2014-02-26 19:00:52 +0000 | [diff] [blame] | 7638 | } |
| 7639 | } |
| 7640 | |
Evan Rosky | 4807ae2 | 2018-03-22 16:04:15 -0700 | [diff] [blame] | 7641 | @Override |
| 7642 | boolean hasUnhandledKeyListener() { |
| 7643 | return (mChildUnhandledKeyListeners > 0) || super.hasUnhandledKeyListener(); |
| 7644 | } |
| 7645 | |
| 7646 | void incrementChildUnhandledKeyListeners() { |
| 7647 | mChildUnhandledKeyListeners += 1; |
| 7648 | if (mChildUnhandledKeyListeners == 1) { |
| 7649 | if (mParent instanceof ViewGroup) { |
| 7650 | ((ViewGroup) mParent).incrementChildUnhandledKeyListeners(); |
| 7651 | } |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | void decrementChildUnhandledKeyListeners() { |
| 7656 | mChildUnhandledKeyListeners -= 1; |
| 7657 | if (mChildUnhandledKeyListeners == 0) { |
| 7658 | if (mParent instanceof ViewGroup) { |
| 7659 | ((ViewGroup) mParent).decrementChildUnhandledKeyListeners(); |
| 7660 | } |
| 7661 | } |
| 7662 | } |
| 7663 | |
| 7664 | @Override |
| 7665 | View dispatchUnhandledKeyEvent(KeyEvent evt) { |
| 7666 | if (!hasUnhandledKeyListener()) { |
| 7667 | return null; |
| 7668 | } |
| 7669 | ArrayList<View> orderedViews = buildOrderedChildList(); |
| 7670 | if (orderedViews != null) { |
| 7671 | try { |
| 7672 | for (int i = orderedViews.size() - 1; i >= 0; --i) { |
| 7673 | View v = orderedViews.get(i); |
| 7674 | View consumer = v.dispatchUnhandledKeyEvent(evt); |
| 7675 | if (consumer != null) { |
| 7676 | return consumer; |
| 7677 | } |
| 7678 | } |
| 7679 | } finally { |
| 7680 | orderedViews.clear(); |
| 7681 | } |
| 7682 | } else { |
| 7683 | for (int i = getChildCount() - 1; i >= 0; --i) { |
| 7684 | View v = getChildAt(i); |
| 7685 | View consumer = v.dispatchUnhandledKeyEvent(evt); |
| 7686 | if (consumer != null) { |
| 7687 | return consumer; |
| 7688 | } |
| 7689 | } |
| 7690 | } |
| 7691 | if (onUnhandledKeyEvent(evt)) { |
| 7692 | return this; |
| 7693 | } |
| 7694 | return null; |
| 7695 | } |
| 7696 | |
Patrick Dubroy | e0a799a | 2011-05-04 16:19:22 -0700 | [diff] [blame] | 7697 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7698 | * LayoutParams are used by views to tell their parents how they want to be |
| 7699 | * laid out. See |
| 7700 | * {@link android.R.styleable#ViewGroup_Layout ViewGroup Layout Attributes} |
| 7701 | * for a list of all child view attributes that this class supports. |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7702 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7703 | * <p> |
| 7704 | * The base LayoutParams class just describes how big the view wants to be |
| 7705 | * for both width and height. For each dimension, it can specify one of: |
| 7706 | * <ul> |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7707 | * <li>FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which |
| 7708 | * means that the view wants to be as big as its parent (minus padding) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7709 | * <li> WRAP_CONTENT, which means that the view wants to be just big enough |
| 7710 | * to enclose its content (plus padding) |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7711 | * <li> an exact number |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | * </ul> |
| 7713 | * There are subclasses of LayoutParams for different subclasses of |
| 7714 | * ViewGroup. For example, AbsoluteLayout has its own subclass of |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 7715 | * LayoutParams which adds an X and Y value.</p> |
| 7716 | * |
| 7717 | * <div class="special reference"> |
| 7718 | * <h3>Developer Guides</h3> |
| 7719 | * <p>For more information about creating user interface layouts, read the |
| 7720 | * <a href="{@docRoot}guide/topics/ui/declaring-layout.html">XML Layouts</a> developer |
| 7721 | * guide.</p></div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7722 | * |
| 7723 | * @attr ref android.R.styleable#ViewGroup_Layout_layout_height |
| 7724 | * @attr ref android.R.styleable#ViewGroup_Layout_layout_width |
| 7725 | */ |
| 7726 | public static class LayoutParams { |
| 7727 | /** |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7728 | * Special value for the height or width requested by a View. |
| 7729 | * FILL_PARENT means that the view wants to be as big as its parent, |
| 7730 | * minus the parent's padding, if any. This value is deprecated |
| 7731 | * starting in API Level 8 and replaced by {@link #MATCH_PARENT}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | */ |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7733 | @SuppressWarnings({"UnusedDeclaration"}) |
| 7734 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | public static final int FILL_PARENT = -1; |
| 7736 | |
| 7737 | /** |
| 7738 | * Special value for the height or width requested by a View. |
Gilles Debunne | f5c6eff | 2010-02-09 19:08:36 -0800 | [diff] [blame] | 7739 | * MATCH_PARENT means that the view wants to be as big as its parent, |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7740 | * minus the parent's padding, if any. Introduced in API Level 8. |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7741 | */ |
| 7742 | public static final int MATCH_PARENT = -1; |
| 7743 | |
| 7744 | /** |
| 7745 | * Special value for the height or width requested by a View. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7746 | * WRAP_CONTENT means that the view wants to be just large enough to fit |
| 7747 | * its own internal content, taking its own padding into account. |
| 7748 | */ |
| 7749 | public static final int WRAP_CONTENT = -2; |
| 7750 | |
| 7751 | /** |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7752 | * Information about how wide the view wants to be. Can be one of the |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 7753 | * constants FILL_PARENT (replaced by MATCH_PARENT |
| 7754 | * in API Level 8) or WRAP_CONTENT, or an exact size. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7755 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7756 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7757 | @ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | @ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT") |
| 7759 | }) |
| 7760 | public int width; |
| 7761 | |
| 7762 | /** |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7763 | * Information about how tall the view wants to be. Can be one of the |
Mark Doliner | d0646dc | 2014-08-27 16:04:02 -0700 | [diff] [blame] | 7764 | * constants FILL_PARENT (replaced by MATCH_PARENT |
| 7765 | * in API Level 8) or WRAP_CONTENT, or an exact size. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7766 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7767 | @ViewDebug.ExportedProperty(category = "layout", mapping = { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7768 | @ViewDebug.IntToString(from = MATCH_PARENT, to = "MATCH_PARENT"), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7769 | @ViewDebug.IntToString(from = WRAP_CONTENT, to = "WRAP_CONTENT") |
| 7770 | }) |
| 7771 | public int height; |
| 7772 | |
| 7773 | /** |
| 7774 | * Used to animate layouts. |
| 7775 | */ |
| 7776 | public LayoutAnimationController.AnimationParameters layoutAnimationParameters; |
| 7777 | |
| 7778 | /** |
| 7779 | * Creates a new set of layout parameters. The values are extracted from |
| 7780 | * the supplied attributes set and context. The XML attributes mapped |
| 7781 | * to this set of layout parameters are: |
| 7782 | * |
| 7783 | * <ul> |
| 7784 | * <li><code>layout_width</code>: the width, either an exact value, |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7785 | * {@link #WRAP_CONTENT}, or {@link #FILL_PARENT} (replaced by |
| 7786 | * {@link #MATCH_PARENT} in API Level 8)</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7787 | * <li><code>layout_height</code>: the height, either an exact value, |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7788 | * {@link #WRAP_CONTENT}, or {@link #FILL_PARENT} (replaced by |
| 7789 | * {@link #MATCH_PARENT} in API Level 8)</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7790 | * </ul> |
| 7791 | * |
| 7792 | * @param c the application environment |
| 7793 | * @param attrs the set of attributes from which to extract the layout |
| 7794 | * parameters' values |
| 7795 | */ |
| 7796 | public LayoutParams(Context c, AttributeSet attrs) { |
| 7797 | TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_Layout); |
| 7798 | setBaseAttributes(a, |
| 7799 | R.styleable.ViewGroup_Layout_layout_width, |
| 7800 | R.styleable.ViewGroup_Layout_layout_height); |
| 7801 | a.recycle(); |
| 7802 | } |
| 7803 | |
| 7804 | /** |
| 7805 | * Creates a new set of layout parameters with the specified width |
| 7806 | * and height. |
| 7807 | * |
Dirk Dougherty | 75c66da | 2010-03-25 16:33:33 -0700 | [diff] [blame] | 7808 | * @param width the width, either {@link #WRAP_CONTENT}, |
| 7809 | * {@link #FILL_PARENT} (replaced by {@link #MATCH_PARENT} in |
| 7810 | * API Level 8), or a fixed size in pixels |
| 7811 | * @param height the height, either {@link #WRAP_CONTENT}, |
| 7812 | * {@link #FILL_PARENT} (replaced by {@link #MATCH_PARENT} in |
| 7813 | * API Level 8), or a fixed size in pixels |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7814 | */ |
| 7815 | public LayoutParams(int width, int height) { |
| 7816 | this.width = width; |
| 7817 | this.height = height; |
| 7818 | } |
| 7819 | |
| 7820 | /** |
| 7821 | * Copy constructor. Clones the width and height values of the source. |
| 7822 | * |
| 7823 | * @param source The layout params to copy from. |
| 7824 | */ |
| 7825 | public LayoutParams(LayoutParams source) { |
| 7826 | this.width = source.width; |
| 7827 | this.height = source.height; |
| 7828 | } |
| 7829 | |
| 7830 | /** |
| 7831 | * Used internally by MarginLayoutParams. |
| 7832 | * @hide |
| 7833 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 7834 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7835 | LayoutParams() { |
| 7836 | } |
| 7837 | |
| 7838 | /** |
Dave Burke | 579e140 | 2012-10-18 20:41:55 -0700 | [diff] [blame] | 7839 | * Extracts the layout parameters from the supplied attributes. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | * |
| 7841 | * @param a the style attributes to extract the parameters from |
| 7842 | * @param widthAttr the identifier of the width attribute |
| 7843 | * @param heightAttr the identifier of the height attribute |
| 7844 | */ |
| 7845 | protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) { |
Dave Burke | 579e140 | 2012-10-18 20:41:55 -0700 | [diff] [blame] | 7846 | width = a.getLayoutDimension(widthAttr, "layout_width"); |
| 7847 | height = a.getLayoutDimension(heightAttr, "layout_height"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | } |
| 7849 | |
| 7850 | /** |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7851 | * Resolve layout parameters depending on the layout direction. Subclasses that care about |
| 7852 | * layoutDirection changes should override this method. The default implementation does |
| 7853 | * nothing. |
| 7854 | * |
| 7855 | * @param layoutDirection the direction of the layout |
| 7856 | * |
| 7857 | * {@link View#LAYOUT_DIRECTION_LTR} |
| 7858 | * {@link View#LAYOUT_DIRECTION_RTL} |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7859 | */ |
Fabrice Di Meglio | 2918ab6 | 2012-10-10 16:39:25 -0700 | [diff] [blame] | 7860 | public void resolveLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7861 | } |
| 7862 | |
| 7863 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7864 | * Returns a String representation of this set of layout parameters. |
| 7865 | * |
| 7866 | * @param output the String to prepend to the internal representation |
| 7867 | * @return a String with the following format: output + |
| 7868 | * "ViewGroup.LayoutParams={ width=WIDTH, height=HEIGHT }" |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7869 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | * @hide |
| 7871 | */ |
| 7872 | public String debug(String output) { |
| 7873 | return output + "ViewGroup.LayoutParams={ width=" |
| 7874 | + sizeToString(width) + ", height=" + sizeToString(height) + " }"; |
| 7875 | } |
| 7876 | |
| 7877 | /** |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 7878 | * Use {@code canvas} to draw suitable debugging annotations for these LayoutParameters. |
| 7879 | * |
| 7880 | * @param view the view that contains these layout parameters |
| 7881 | * @param canvas the canvas on which to draw |
Alan Viverette | 2d7771c | 2018-01-31 17:04:31 -0500 | [diff] [blame] | 7882 | * |
| 7883 | * @hide |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 7884 | */ |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 7885 | public void onDebugDraw(View view, Canvas canvas, Paint paint) { |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 7886 | } |
| 7887 | |
| 7888 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7889 | * Converts the specified size to a readable String. |
| 7890 | * |
| 7891 | * @param size the size to convert |
| 7892 | * @return a String instance representing the supplied size |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7893 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | * @hide |
| 7895 | */ |
| 7896 | protected static String sizeToString(int size) { |
| 7897 | if (size == WRAP_CONTENT) { |
| 7898 | return "wrap-content"; |
| 7899 | } |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7900 | if (size == MATCH_PARENT) { |
| 7901 | return "match-parent"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7902 | } |
| 7903 | return String.valueOf(size); |
| 7904 | } |
Siva Velusamy | 0d857b9 | 2015-04-22 10:23:56 -0700 | [diff] [blame] | 7905 | |
| 7906 | /** @hide */ |
| 7907 | void encode(@NonNull ViewHierarchyEncoder encoder) { |
| 7908 | encoder.beginObject(this); |
| 7909 | encodeProperties(encoder); |
| 7910 | encoder.endObject(); |
| 7911 | } |
| 7912 | |
| 7913 | /** @hide */ |
| 7914 | protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 7915 | encoder.addProperty("width", width); |
| 7916 | encoder.addProperty("height", height); |
| 7917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | /** |
| 7921 | * Per-child layout information for layouts that support margins. |
| 7922 | * See |
| 7923 | * {@link android.R.styleable#ViewGroup_MarginLayout ViewGroup Margin Layout Attributes} |
| 7924 | * for a list of all child view attributes that this class supports. |
Chet Haase | 353d397 | 2017-06-29 07:54:19 -0700 | [diff] [blame] | 7925 | * |
| 7926 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_margin |
| 7927 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginHorizontal |
| 7928 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginVertical |
| 7929 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginLeft |
| 7930 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginTop |
| 7931 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginRight |
| 7932 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginBottom |
| 7933 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart |
| 7934 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7935 | */ |
| 7936 | public static class MarginLayoutParams extends ViewGroup.LayoutParams { |
| 7937 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7938 | * The left margin in pixels of the child. Margin values should be positive. |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7939 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7940 | * to this field. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7941 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7942 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7943 | public int leftMargin; |
| 7944 | |
| 7945 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7946 | * The top margin in pixels of the child. Margin values should be positive. |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7947 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7948 | * to this field. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7949 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7950 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7951 | public int topMargin; |
| 7952 | |
| 7953 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7954 | * The right margin in pixels of the child. Margin values should be positive. |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7955 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7956 | * to this field. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7957 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7958 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | public int rightMargin; |
| 7960 | |
| 7961 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7962 | * The bottom margin in pixels of the child. Margin values should be positive. |
Philip Milne | d7dd890 | 2012-01-26 16:55:30 -0800 | [diff] [blame] | 7963 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7964 | * to this field. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | */ |
Konstantin Lopyrev | bea9516 | 2010-08-10 17:02:18 -0700 | [diff] [blame] | 7966 | @ViewDebug.ExportedProperty(category = "layout") |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7967 | public int bottomMargin; |
| 7968 | |
| 7969 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7970 | * The start margin in pixels of the child. Margin values should be positive. |
Fabrice Di Meglio | 54546f2 | 2012-02-14 16:26:16 -0800 | [diff] [blame] | 7971 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7972 | * to this field. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7973 | */ |
| 7974 | @ViewDebug.ExportedProperty(category = "layout") |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 7975 | @UnsupportedAppUsage |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 7976 | private int startMargin = DEFAULT_MARGIN_RELATIVE; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7977 | |
| 7978 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 7979 | * The end margin in pixels of the child. Margin values should be positive. |
Fabrice Di Meglio | 54546f2 | 2012-02-14 16:26:16 -0800 | [diff] [blame] | 7980 | * Call {@link ViewGroup#setLayoutParams(LayoutParams)} after reassigning a new value |
| 7981 | * to this field. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7982 | */ |
| 7983 | @ViewDebug.ExportedProperty(category = "layout") |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 7984 | @UnsupportedAppUsage |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 7985 | private int endMargin = DEFAULT_MARGIN_RELATIVE; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7986 | |
| 7987 | /** |
| 7988 | * The default start and end margin. |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 7989 | * @hide |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7990 | */ |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 7991 | public static final int DEFAULT_MARGIN_RELATIVE = Integer.MIN_VALUE; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 7992 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 7993 | /** |
| 7994 | * Bit 0: layout direction |
| 7995 | * Bit 1: layout direction |
| 7996 | * Bit 2: left margin undefined |
| 7997 | * Bit 3: right margin undefined |
| 7998 | * Bit 4: is RTL compatibility mode |
| 7999 | * Bit 5: need resolution |
| 8000 | * |
| 8001 | * Bit 6 to 7 not used |
| 8002 | * |
| 8003 | * @hide |
| 8004 | */ |
| 8005 | @ViewDebug.ExportedProperty(category = "layout", flagMapping = { |
| 8006 | @ViewDebug.FlagToString(mask = LAYOUT_DIRECTION_MASK, |
| 8007 | equals = LAYOUT_DIRECTION_MASK, name = "LAYOUT_DIRECTION"), |
| 8008 | @ViewDebug.FlagToString(mask = LEFT_MARGIN_UNDEFINED_MASK, |
| 8009 | equals = LEFT_MARGIN_UNDEFINED_MASK, name = "LEFT_MARGIN_UNDEFINED_MASK"), |
| 8010 | @ViewDebug.FlagToString(mask = RIGHT_MARGIN_UNDEFINED_MASK, |
| 8011 | equals = RIGHT_MARGIN_UNDEFINED_MASK, name = "RIGHT_MARGIN_UNDEFINED_MASK"), |
| 8012 | @ViewDebug.FlagToString(mask = RTL_COMPATIBILITY_MODE_MASK, |
| 8013 | equals = RTL_COMPATIBILITY_MODE_MASK, name = "RTL_COMPATIBILITY_MODE_MASK"), |
| 8014 | @ViewDebug.FlagToString(mask = NEED_RESOLUTION_MASK, |
| 8015 | equals = NEED_RESOLUTION_MASK, name = "NEED_RESOLUTION_MASK") |
Jon Miranda | 4597e98 | 2014-07-29 07:25:49 -0700 | [diff] [blame] | 8016 | }, formatToHexString = true) |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8017 | byte mMarginFlags; |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8018 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8019 | private static final int LAYOUT_DIRECTION_MASK = 0x00000003; |
| 8020 | private static final int LEFT_MARGIN_UNDEFINED_MASK = 0x00000004; |
| 8021 | private static final int RIGHT_MARGIN_UNDEFINED_MASK = 0x00000008; |
| 8022 | private static final int RTL_COMPATIBILITY_MODE_MASK = 0x00000010; |
| 8023 | private static final int NEED_RESOLUTION_MASK = 0x00000020; |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8024 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8025 | private static final int DEFAULT_MARGIN_RESOLVED = 0; |
| 8026 | private static final int UNDEFINED_MARGIN = DEFAULT_MARGIN_RELATIVE; |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8027 | |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8028 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | * Creates a new set of layout parameters. The values are extracted from |
| 8030 | * the supplied attributes set and context. |
| 8031 | * |
| 8032 | * @param c the application environment |
| 8033 | * @param attrs the set of attributes from which to extract the layout |
| 8034 | * parameters' values |
| 8035 | */ |
| 8036 | public MarginLayoutParams(Context c, AttributeSet attrs) { |
| 8037 | super(); |
| 8038 | |
| 8039 | TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ViewGroup_MarginLayout); |
| 8040 | setBaseAttributes(a, |
| 8041 | R.styleable.ViewGroup_MarginLayout_layout_width, |
| 8042 | R.styleable.ViewGroup_MarginLayout_layout_height); |
| 8043 | |
| 8044 | int margin = a.getDimensionPixelSize( |
| 8045 | com.android.internal.R.styleable.ViewGroup_MarginLayout_layout_margin, -1); |
| 8046 | if (margin >= 0) { |
| 8047 | leftMargin = margin; |
| 8048 | topMargin = margin; |
| 8049 | rightMargin= margin; |
| 8050 | bottomMargin = margin; |
| 8051 | } else { |
Chet Haase | 40b2de5 | 2016-11-28 16:11:42 -0800 | [diff] [blame] | 8052 | int horizontalMargin = a.getDimensionPixelSize( |
| 8053 | R.styleable.ViewGroup_MarginLayout_layout_marginHorizontal, -1); |
| 8054 | int verticalMargin = a.getDimensionPixelSize( |
| 8055 | R.styleable.ViewGroup_MarginLayout_layout_marginVertical, -1); |
| 8056 | |
| 8057 | if (horizontalMargin >= 0) { |
| 8058 | leftMargin = horizontalMargin; |
| 8059 | rightMargin = horizontalMargin; |
| 8060 | } else { |
| 8061 | leftMargin = a.getDimensionPixelSize( |
| 8062 | R.styleable.ViewGroup_MarginLayout_layout_marginLeft, |
| 8063 | UNDEFINED_MARGIN); |
| 8064 | if (leftMargin == UNDEFINED_MARGIN) { |
| 8065 | mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8066 | leftMargin = DEFAULT_MARGIN_RESOLVED; |
| 8067 | } |
| 8068 | rightMargin = a.getDimensionPixelSize( |
| 8069 | R.styleable.ViewGroup_MarginLayout_layout_marginRight, |
| 8070 | UNDEFINED_MARGIN); |
| 8071 | if (rightMargin == UNDEFINED_MARGIN) { |
| 8072 | mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
| 8073 | rightMargin = DEFAULT_MARGIN_RESOLVED; |
| 8074 | } |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8075 | } |
| 8076 | |
Chet Haase | cb3d023 | 2017-05-24 18:27:14 -0700 | [diff] [blame] | 8077 | startMargin = a.getDimensionPixelSize( |
| 8078 | R.styleable.ViewGroup_MarginLayout_layout_marginStart, |
| 8079 | DEFAULT_MARGIN_RELATIVE); |
| 8080 | endMargin = a.getDimensionPixelSize( |
| 8081 | R.styleable.ViewGroup_MarginLayout_layout_marginEnd, |
| 8082 | DEFAULT_MARGIN_RELATIVE); |
| 8083 | |
Chet Haase | 40b2de5 | 2016-11-28 16:11:42 -0800 | [diff] [blame] | 8084 | if (verticalMargin >= 0) { |
| 8085 | topMargin = verticalMargin; |
| 8086 | bottomMargin = verticalMargin; |
| 8087 | } else { |
| 8088 | topMargin = a.getDimensionPixelSize( |
| 8089 | R.styleable.ViewGroup_MarginLayout_layout_marginTop, |
| 8090 | DEFAULT_MARGIN_RESOLVED); |
| 8091 | bottomMargin = a.getDimensionPixelSize( |
| 8092 | R.styleable.ViewGroup_MarginLayout_layout_marginBottom, |
| 8093 | DEFAULT_MARGIN_RESOLVED); |
| 8094 | } |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8095 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8096 | if (isMarginRelative()) { |
| 8097 | mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | } |
| 8100 | |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8101 | final boolean hasRtlSupport = c.getApplicationInfo().hasRtlSupport(); |
| 8102 | final int targetSdkVersion = c.getApplicationInfo().targetSdkVersion; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8103 | if (targetSdkVersion < JELLY_BEAN_MR1 || !hasRtlSupport) { |
| 8104 | mMarginFlags |= RTL_COMPATIBILITY_MODE_MASK; |
| 8105 | } |
| 8106 | |
| 8107 | // Layout direction is LTR by default |
| 8108 | mMarginFlags |= LAYOUT_DIRECTION_LTR; |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | a.recycle(); |
| 8111 | } |
| 8112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | public MarginLayoutParams(int width, int height) { |
| 8114 | super(width, height); |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8115 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8116 | mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8117 | mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8118 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8119 | mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8120 | mMarginFlags &= ~RTL_COMPATIBILITY_MODE_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | } |
| 8122 | |
| 8123 | /** |
| 8124 | * Copy constructor. Clones the width, height and margin values of the source. |
| 8125 | * |
| 8126 | * @param source The layout params to copy from. |
| 8127 | */ |
| 8128 | public MarginLayoutParams(MarginLayoutParams source) { |
| 8129 | this.width = source.width; |
| 8130 | this.height = source.height; |
| 8131 | |
| 8132 | this.leftMargin = source.leftMargin; |
| 8133 | this.topMargin = source.topMargin; |
| 8134 | this.rightMargin = source.rightMargin; |
| 8135 | this.bottomMargin = source.bottomMargin; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8136 | this.startMargin = source.startMargin; |
| 8137 | this.endMargin = source.endMargin; |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8138 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8139 | this.mMarginFlags = source.mMarginFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | } |
| 8141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8142 | public MarginLayoutParams(LayoutParams source) { |
| 8143 | super(source); |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8144 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8145 | mMarginFlags |= LEFT_MARGIN_UNDEFINED_MASK; |
| 8146 | mMarginFlags |= RIGHT_MARGIN_UNDEFINED_MASK; |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8147 | |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8148 | mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8149 | mMarginFlags &= ~RTL_COMPATIBILITY_MODE_MASK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8150 | } |
| 8151 | |
| 8152 | /** |
Adam Powell | d760083 | 2014-07-01 15:22:50 -0700 | [diff] [blame] | 8153 | * @hide Used internally. |
| 8154 | */ |
| 8155 | public final void copyMarginsFrom(MarginLayoutParams source) { |
| 8156 | this.leftMargin = source.leftMargin; |
| 8157 | this.topMargin = source.topMargin; |
| 8158 | this.rightMargin = source.rightMargin; |
| 8159 | this.bottomMargin = source.bottomMargin; |
| 8160 | this.startMargin = source.startMargin; |
| 8161 | this.endMargin = source.endMargin; |
| 8162 | |
| 8163 | this.mMarginFlags = source.mMarginFlags; |
| 8164 | } |
| 8165 | |
| 8166 | /** |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8167 | * Sets the margins, in pixels. A call to {@link android.view.View#requestLayout()} needs |
| 8168 | * to be done so that the new margins are taken into account. Left and right margins may be |
kopriva | debd4ee | 2018-09-13 10:59:46 -0700 | [diff] [blame] | 8169 | * overridden by {@link android.view.View#requestLayout()} depending on layout direction. |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 8170 | * Margin values should be positive. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | * |
| 8172 | * @param left the left margin size |
| 8173 | * @param top the top margin size |
| 8174 | * @param right the right margin size |
| 8175 | * @param bottom the bottom margin size |
| 8176 | * |
| 8177 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginLeft |
| 8178 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginTop |
| 8179 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginRight |
| 8180 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginBottom |
| 8181 | */ |
| 8182 | public void setMargins(int left, int top, int right, int bottom) { |
| 8183 | leftMargin = left; |
| 8184 | topMargin = top; |
| 8185 | rightMargin = right; |
| 8186 | bottomMargin = bottom; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8187 | mMarginFlags &= ~LEFT_MARGIN_UNDEFINED_MASK; |
| 8188 | mMarginFlags &= ~RIGHT_MARGIN_UNDEFINED_MASK; |
| 8189 | if (isMarginRelative()) { |
| 8190 | mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8191 | } else { |
| 8192 | mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8193 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8194 | } |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8195 | |
| 8196 | /** |
| 8197 | * Sets the relative margins, in pixels. A call to {@link android.view.View#requestLayout()} |
| 8198 | * needs to be done so that the new relative margins are taken into account. Left and right |
kopriva | debd4ee | 2018-09-13 10:59:46 -0700 | [diff] [blame] | 8199 | * margins may be overridden by {@link android.view.View#requestLayout()} depending on |
| 8200 | * layout direction. Margin values should be positive. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8201 | * |
| 8202 | * @param start the start margin size |
| 8203 | * @param top the top margin size |
| 8204 | * @param end the right margin size |
| 8205 | * @param bottom the bottom margin size |
| 8206 | * |
| 8207 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart |
| 8208 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginTop |
| 8209 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd |
| 8210 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginBottom |
| 8211 | * |
| 8212 | * @hide |
| 8213 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 8214 | @UnsupportedAppUsage |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8215 | public void setMarginsRelative(int start, int top, int end, int bottom) { |
| 8216 | startMargin = start; |
| 8217 | topMargin = top; |
| 8218 | endMargin = end; |
| 8219 | bottomMargin = bottom; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8220 | mMarginFlags |= NEED_RESOLUTION_MASK; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8221 | } |
| 8222 | |
| 8223 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 8224 | * Sets the relative start margin. Margin values should be positive. |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8225 | * |
Fabrice Di Meglio | 61a2177 | 2012-09-12 16:33:13 -0700 | [diff] [blame] | 8226 | * @param start the start margin size |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8227 | * |
| 8228 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart |
| 8229 | */ |
| 8230 | public void setMarginStart(int start) { |
| 8231 | startMargin = start; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8232 | mMarginFlags |= NEED_RESOLUTION_MASK; |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8233 | } |
| 8234 | |
| 8235 | /** |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8236 | * Returns the start margin in pixels. |
| 8237 | * |
| 8238 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart |
| 8239 | * |
| 8240 | * @return the start margin in pixels. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8241 | */ |
| 8242 | public int getMarginStart() { |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8243 | if (startMargin != DEFAULT_MARGIN_RELATIVE) return startMargin; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8244 | if ((mMarginFlags & NEED_RESOLUTION_MASK) == NEED_RESOLUTION_MASK) { |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8245 | doResolveMargins(); |
| 8246 | } |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8247 | switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8248 | case View.LAYOUT_DIRECTION_RTL: |
| 8249 | return rightMargin; |
| 8250 | case View.LAYOUT_DIRECTION_LTR: |
| 8251 | default: |
| 8252 | return leftMargin; |
| 8253 | } |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8254 | } |
| 8255 | |
| 8256 | /** |
Adam Powell | a7a735f | 2014-10-09 12:54:52 -0700 | [diff] [blame] | 8257 | * Sets the relative end margin. Margin values should be positive. |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8258 | * |
Fabrice Di Meglio | 61a2177 | 2012-09-12 16:33:13 -0700 | [diff] [blame] | 8259 | * @param end the end margin size |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8260 | * |
| 8261 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd |
| 8262 | */ |
| 8263 | public void setMarginEnd(int end) { |
| 8264 | endMargin = end; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8265 | mMarginFlags |= NEED_RESOLUTION_MASK; |
Fabrice Di Meglio | a40627d | 2012-09-11 16:47:21 -0700 | [diff] [blame] | 8266 | } |
| 8267 | |
| 8268 | /** |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8269 | * Returns the end margin in pixels. |
| 8270 | * |
| 8271 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd |
| 8272 | * |
| 8273 | * @return the end margin in pixels. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8274 | */ |
| 8275 | public int getMarginEnd() { |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8276 | if (endMargin != DEFAULT_MARGIN_RELATIVE) return endMargin; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8277 | if ((mMarginFlags & NEED_RESOLUTION_MASK) == NEED_RESOLUTION_MASK) { |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8278 | doResolveMargins(); |
| 8279 | } |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8280 | switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8281 | case View.LAYOUT_DIRECTION_RTL: |
| 8282 | return leftMargin; |
| 8283 | case View.LAYOUT_DIRECTION_LTR: |
| 8284 | default: |
| 8285 | return rightMargin; |
| 8286 | } |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8287 | } |
| 8288 | |
| 8289 | /** |
| 8290 | * Check if margins are relative. |
| 8291 | * |
| 8292 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginStart |
| 8293 | * @attr ref android.R.styleable#ViewGroup_MarginLayout_layout_marginEnd |
| 8294 | * |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8295 | * @return true if either marginStart or marginEnd has been set. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8296 | */ |
| 8297 | public boolean isMarginRelative() { |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8298 | return (startMargin != DEFAULT_MARGIN_RELATIVE || endMargin != DEFAULT_MARGIN_RELATIVE); |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8299 | } |
| 8300 | |
| 8301 | /** |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8302 | * Set the layout direction |
| 8303 | * @param layoutDirection the layout direction. |
| 8304 | * Should be either {@link View#LAYOUT_DIRECTION_LTR} |
| 8305 | * or {@link View#LAYOUT_DIRECTION_RTL}. |
| 8306 | */ |
| 8307 | public void setLayoutDirection(int layoutDirection) { |
| 8308 | if (layoutDirection != View.LAYOUT_DIRECTION_LTR && |
| 8309 | layoutDirection != View.LAYOUT_DIRECTION_RTL) return; |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8310 | if (layoutDirection != (mMarginFlags & LAYOUT_DIRECTION_MASK)) { |
| 8311 | mMarginFlags &= ~LAYOUT_DIRECTION_MASK; |
| 8312 | mMarginFlags |= (layoutDirection & LAYOUT_DIRECTION_MASK); |
| 8313 | if (isMarginRelative()) { |
| 8314 | mMarginFlags |= NEED_RESOLUTION_MASK; |
| 8315 | } else { |
| 8316 | mMarginFlags &= ~NEED_RESOLUTION_MASK; |
| 8317 | } |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8318 | } |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8319 | } |
| 8320 | |
| 8321 | /** |
| 8322 | * Retuns the layout direction. Can be either {@link View#LAYOUT_DIRECTION_LTR} or |
| 8323 | * {@link View#LAYOUT_DIRECTION_RTL}. |
| 8324 | * |
| 8325 | * @return the layout direction. |
| 8326 | */ |
| 8327 | public int getLayoutDirection() { |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8328 | return (mMarginFlags & LAYOUT_DIRECTION_MASK); |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8329 | } |
| 8330 | |
| 8331 | /** |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8332 | * This will be called by {@link android.view.View#requestLayout()}. Left and Right margins |
Fabrice Di Meglio | 98aec1c | 2012-02-13 16:54:05 -0800 | [diff] [blame] | 8333 | * may be overridden depending on layout direction. |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8334 | */ |
| 8335 | @Override |
Fabrice Di Meglio | 2918ab6 | 2012-10-10 16:39:25 -0700 | [diff] [blame] | 8336 | public void resolveLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8337 | setLayoutDirection(layoutDirection); |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8338 | |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8339 | // No relative margin or pre JB-MR1 case or no need to resolve, just dont do anything |
| 8340 | // Will use the left and right margins if no relative margin is defined. |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8341 | if (!isMarginRelative() || |
| 8342 | (mMarginFlags & NEED_RESOLUTION_MASK) != NEED_RESOLUTION_MASK) return; |
Fabrice Di Meglio | 69bd558 | 2012-07-02 13:17:24 -0700 | [diff] [blame] | 8343 | |
Fabrice Di Meglio | 0072f64 | 2013-03-26 15:50:24 -0700 | [diff] [blame] | 8344 | // Proceed with resolution |
| 8345 | doResolveMargins(); |
| 8346 | } |
| 8347 | |
| 8348 | private void doResolveMargins() { |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8349 | if ((mMarginFlags & RTL_COMPATIBILITY_MODE_MASK) == RTL_COMPATIBILITY_MODE_MASK) { |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8350 | // if left or right margins are not defined and if we have some start or end margin |
| 8351 | // defined then use those start and end margins. |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8352 | if ((mMarginFlags & LEFT_MARGIN_UNDEFINED_MASK) == LEFT_MARGIN_UNDEFINED_MASK |
| 8353 | && startMargin > DEFAULT_MARGIN_RELATIVE) { |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8354 | leftMargin = startMargin; |
| 8355 | } |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8356 | if ((mMarginFlags & RIGHT_MARGIN_UNDEFINED_MASK) == RIGHT_MARGIN_UNDEFINED_MASK |
| 8357 | && endMargin > DEFAULT_MARGIN_RELATIVE) { |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8358 | rightMargin = endMargin; |
| 8359 | } |
| 8360 | } else { |
| 8361 | // We have some relative margins (either the start one or the end one or both). So use |
| 8362 | // them and override what has been defined for left and right margins. If either start |
| 8363 | // or end margin is not defined, just set it to default "0". |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8364 | switch(mMarginFlags & LAYOUT_DIRECTION_MASK) { |
Fabrice Di Meglio | 02a7d56 | 2013-03-27 12:41:22 -0700 | [diff] [blame] | 8365 | case View.LAYOUT_DIRECTION_RTL: |
| 8366 | leftMargin = (endMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8367 | endMargin : DEFAULT_MARGIN_RESOLVED; |
| 8368 | rightMargin = (startMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8369 | startMargin : DEFAULT_MARGIN_RESOLVED; |
| 8370 | break; |
| 8371 | case View.LAYOUT_DIRECTION_LTR: |
| 8372 | default: |
| 8373 | leftMargin = (startMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8374 | startMargin : DEFAULT_MARGIN_RESOLVED; |
| 8375 | rightMargin = (endMargin > DEFAULT_MARGIN_RELATIVE) ? |
| 8376 | endMargin : DEFAULT_MARGIN_RESOLVED; |
| 8377 | break; |
| 8378 | } |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8379 | } |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8380 | mMarginFlags &= ~NEED_RESOLUTION_MASK; |
Fabrice Di Meglio | b76023a | 2011-06-20 17:41:21 -0700 | [diff] [blame] | 8381 | } |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 8382 | |
Fabrice Di Meglio | 03b8d3a | 2012-09-27 17:05:27 -0700 | [diff] [blame] | 8383 | /** |
| 8384 | * @hide |
| 8385 | */ |
| 8386 | public boolean isLayoutRtl() { |
Fabrice Di Meglio | b365f91 | 2013-03-27 16:36:21 -0700 | [diff] [blame] | 8387 | return ((mMarginFlags & LAYOUT_DIRECTION_MASK) == View.LAYOUT_DIRECTION_RTL); |
Fabrice Di Meglio | f443f98 | 2012-07-13 20:24:03 -0700 | [diff] [blame] | 8388 | } |
| 8389 | |
Alan Viverette | 2d7771c | 2018-01-31 17:04:31 -0500 | [diff] [blame] | 8390 | /** |
| 8391 | * @hide |
| 8392 | */ |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 8393 | @Override |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 8394 | public void onDebugDraw(View view, Canvas canvas, Paint paint) { |
| 8395 | Insets oi = isLayoutModeOptical(view.mParent) ? view.getOpticalInsets() : Insets.NONE; |
| 8396 | |
| 8397 | fillDifference(canvas, |
| 8398 | view.getLeft() + oi.left, |
| 8399 | view.getTop() + oi.top, |
| 8400 | view.getRight() - oi.right, |
| 8401 | view.getBottom() - oi.bottom, |
| 8402 | leftMargin, |
| 8403 | topMargin, |
| 8404 | rightMargin, |
| 8405 | bottomMargin, |
| 8406 | paint); |
Philip Milne | 10ca24a | 2012-04-23 15:38:27 -0700 | [diff] [blame] | 8407 | } |
Siva Velusamy | 0d857b9 | 2015-04-22 10:23:56 -0700 | [diff] [blame] | 8408 | |
| 8409 | /** @hide */ |
| 8410 | @Override |
| 8411 | protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 8412 | super.encodeProperties(encoder); |
| 8413 | encoder.addProperty("leftMargin", leftMargin); |
| 8414 | encoder.addProperty("topMargin", topMargin); |
| 8415 | encoder.addProperty("rightMargin", rightMargin); |
| 8416 | encoder.addProperty("bottomMargin", bottomMargin); |
| 8417 | encoder.addProperty("startMargin", startMargin); |
| 8418 | encoder.addProperty("endMargin", endMargin); |
| 8419 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | } |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 8421 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8422 | /* Describes a touched view and the ids of the pointers that it has captured. |
| 8423 | * |
| 8424 | * This code assumes that pointer ids are always in the range 0..31 such that |
| 8425 | * it can use a bitfield to track which pointer ids are present. |
| 8426 | * As it happens, the lower layers of the input dispatch pipeline also use the |
| 8427 | * same trick so the assumption should be safe here... |
| 8428 | */ |
| 8429 | private static final class TouchTarget { |
| 8430 | private static final int MAX_RECYCLED = 32; |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 8431 | private static final Object sRecycleLock = new Object[0]; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8432 | private static TouchTarget sRecycleBin; |
| 8433 | private static int sRecycledCount; |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 8434 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8435 | public static final int ALL_POINTER_IDS = -1; // all ones |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 8436 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8437 | // The touched child view. |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 8438 | @UnsupportedAppUsage |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8439 | public View child; |
| 8440 | |
| 8441 | // The combined bit mask of pointer ids for all pointers captured by the target. |
| 8442 | public int pointerIdBits; |
| 8443 | |
| 8444 | // The next target in the target list. |
| 8445 | public TouchTarget next; |
| 8446 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 8447 | @UnsupportedAppUsage |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8448 | private TouchTarget() { |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 8449 | } |
| 8450 | |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 8451 | public static TouchTarget obtain(@NonNull View child, int pointerIdBits) { |
| 8452 | if (child == null) { |
| 8453 | throw new IllegalArgumentException("child must be non-null"); |
| 8454 | } |
| 8455 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8456 | final TouchTarget target; |
| 8457 | synchronized (sRecycleLock) { |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8458 | if (sRecycleBin == null) { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8459 | target = new TouchTarget(); |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8460 | } else { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8461 | target = sRecycleBin; |
| 8462 | sRecycleBin = target.next; |
| 8463 | sRecycledCount--; |
| 8464 | target.next = null; |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8465 | } |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8466 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8467 | target.child = child; |
| 8468 | target.pointerIdBits = pointerIdBits; |
| 8469 | return target; |
| 8470 | } |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8471 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8472 | public void recycle() { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 8473 | if (child == null) { |
| 8474 | throw new IllegalStateException("already recycled once"); |
| 8475 | } |
| 8476 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 8477 | synchronized (sRecycleLock) { |
| 8478 | if (sRecycledCount < MAX_RECYCLED) { |
| 8479 | next = sRecycleBin; |
| 8480 | sRecycleBin = this; |
| 8481 | sRecycledCount += 1; |
Patrick Dubroy | fb0547d2 | 2010-10-19 17:36:18 -0700 | [diff] [blame] | 8482 | } else { |
| 8483 | next = null; |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8484 | } |
Patrick Dubroy | fb0547d2 | 2010-10-19 17:36:18 -0700 | [diff] [blame] | 8485 | child = null; |
Adam Powell | 816c3be | 2010-08-23 18:00:05 -0700 | [diff] [blame] | 8486 | } |
| 8487 | } |
Adam Powell | 2b342f0 | 2010-08-18 18:14:13 -0700 | [diff] [blame] | 8488 | } |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8489 | |
| 8490 | /* Describes a hovered view. */ |
| 8491 | private static final class HoverTarget { |
| 8492 | private static final int MAX_RECYCLED = 32; |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 8493 | private static final Object sRecycleLock = new Object[0]; |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8494 | private static HoverTarget sRecycleBin; |
| 8495 | private static int sRecycledCount; |
| 8496 | |
| 8497 | // The hovered child view. |
| 8498 | public View child; |
| 8499 | |
| 8500 | // The next target in the target list. |
| 8501 | public HoverTarget next; |
| 8502 | |
| 8503 | private HoverTarget() { |
| 8504 | } |
| 8505 | |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 8506 | public static HoverTarget obtain(@NonNull View child) { |
| 8507 | if (child == null) { |
| 8508 | throw new IllegalArgumentException("child must be non-null"); |
| 8509 | } |
| 8510 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8511 | final HoverTarget target; |
| 8512 | synchronized (sRecycleLock) { |
| 8513 | if (sRecycleBin == null) { |
| 8514 | target = new HoverTarget(); |
| 8515 | } else { |
| 8516 | target = sRecycleBin; |
| 8517 | sRecycleBin = target.next; |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 8518 | sRecycledCount--; |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8519 | target.next = null; |
| 8520 | } |
| 8521 | } |
| 8522 | target.child = child; |
| 8523 | return target; |
| 8524 | } |
| 8525 | |
| 8526 | public void recycle() { |
Alan Viverette | a7b85e6 | 2016-01-22 10:14:02 -0500 | [diff] [blame] | 8527 | if (child == null) { |
| 8528 | throw new IllegalStateException("already recycled once"); |
| 8529 | } |
| 8530 | |
Jeff Brown | 87b7f80 | 2011-06-21 18:35:45 -0700 | [diff] [blame] | 8531 | synchronized (sRecycleLock) { |
| 8532 | if (sRecycledCount < MAX_RECYCLED) { |
| 8533 | next = sRecycleBin; |
| 8534 | sRecycleBin = this; |
| 8535 | sRecycledCount += 1; |
| 8536 | } else { |
| 8537 | next = null; |
| 8538 | } |
| 8539 | child = null; |
| 8540 | } |
| 8541 | } |
| 8542 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8543 | |
| 8544 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 8545 | * Pooled class that to hold the children for autifill. |
| 8546 | */ |
| 8547 | static class ChildListForAutoFill extends ArrayList<View> { |
| 8548 | private static final int MAX_POOL_SIZE = 32; |
| 8549 | |
| 8550 | private static final Pools.SimplePool<ChildListForAutoFill> sPool = |
| 8551 | new Pools.SimplePool<>(MAX_POOL_SIZE); |
| 8552 | |
| 8553 | public static ChildListForAutoFill obtain() { |
| 8554 | ChildListForAutoFill list = sPool.acquire(); |
| 8555 | if (list == null) { |
| 8556 | list = new ChildListForAutoFill(); |
| 8557 | } |
| 8558 | return list; |
| 8559 | } |
| 8560 | |
| 8561 | public void recycle() { |
| 8562 | clear(); |
| 8563 | sPool.release(this); |
| 8564 | } |
| 8565 | } |
| 8566 | |
| 8567 | /** |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8568 | * Pooled class that orderes the children of a ViewGroup from start |
| 8569 | * to end based on how they are laid out and the layout direction. |
| 8570 | */ |
| 8571 | static class ChildListForAccessibility { |
| 8572 | |
| 8573 | private static final int MAX_POOL_SIZE = 32; |
| 8574 | |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8575 | private static final SynchronizedPool<ChildListForAccessibility> sPool = |
| 8576 | new SynchronizedPool<ChildListForAccessibility>(MAX_POOL_SIZE); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8577 | |
| 8578 | private final ArrayList<View> mChildren = new ArrayList<View>(); |
| 8579 | |
| 8580 | private final ArrayList<ViewLocationHolder> mHolders = new ArrayList<ViewLocationHolder>(); |
| 8581 | |
| 8582 | public static ChildListForAccessibility obtain(ViewGroup parent, boolean sort) { |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8583 | ChildListForAccessibility list = sPool.acquire(); |
| 8584 | if (list == null) { |
| 8585 | list = new ChildListForAccessibility(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8586 | } |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8587 | list.init(parent, sort); |
| 8588 | return list; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8589 | } |
| 8590 | |
| 8591 | public void recycle() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8592 | clear(); |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8593 | sPool.release(this); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8594 | } |
| 8595 | |
| 8596 | public int getChildCount() { |
| 8597 | return mChildren.size(); |
| 8598 | } |
| 8599 | |
| 8600 | public View getChildAt(int index) { |
| 8601 | return mChildren.get(index); |
| 8602 | } |
| 8603 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8604 | private void init(ViewGroup parent, boolean sort) { |
| 8605 | ArrayList<View> children = mChildren; |
| 8606 | final int childCount = parent.getChildCount(); |
| 8607 | for (int i = 0; i < childCount; i++) { |
| 8608 | View child = parent.getChildAt(i); |
| 8609 | children.add(child); |
| 8610 | } |
| 8611 | if (sort) { |
| 8612 | ArrayList<ViewLocationHolder> holders = mHolders; |
| 8613 | for (int i = 0; i < childCount; i++) { |
| 8614 | View child = children.get(i); |
| 8615 | ViewLocationHolder holder = ViewLocationHolder.obtain(parent, child); |
| 8616 | holders.add(holder); |
| 8617 | } |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8618 | sort(holders); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8619 | for (int i = 0; i < childCount; i++) { |
| 8620 | ViewLocationHolder holder = holders.get(i); |
| 8621 | children.set(i, holder.mView); |
| 8622 | holder.recycle(); |
| 8623 | } |
| 8624 | holders.clear(); |
| 8625 | } |
| 8626 | } |
| 8627 | |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8628 | private void sort(ArrayList<ViewLocationHolder> holders) { |
| 8629 | // This is gross but the least risky solution. The current comparison |
| 8630 | // strategy breaks transitivity but produces very good results. Coming |
| 8631 | // up with a new strategy requires time which we do not have, so ... |
| 8632 | try { |
| 8633 | ViewLocationHolder.setComparisonStrategy( |
| 8634 | ViewLocationHolder.COMPARISON_STRATEGY_STRIPE); |
| 8635 | Collections.sort(holders); |
| 8636 | } catch (IllegalArgumentException iae) { |
| 8637 | // Note that in practice this occurs extremely rarely in a couple |
| 8638 | // of pathological cases. |
| 8639 | ViewLocationHolder.setComparisonStrategy( |
| 8640 | ViewLocationHolder.COMPARISON_STRATEGY_LOCATION); |
| 8641 | Collections.sort(holders); |
| 8642 | } |
| 8643 | } |
| 8644 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8645 | private void clear() { |
| 8646 | mChildren.clear(); |
| 8647 | } |
| 8648 | } |
| 8649 | |
| 8650 | /** |
| 8651 | * Pooled class that holds a View and its location with respect to |
| 8652 | * a specified root. This enables sorting of views based on their |
| 8653 | * coordinates without recomputing the position relative to the root |
| 8654 | * on every comparison. |
| 8655 | */ |
| 8656 | static class ViewLocationHolder implements Comparable<ViewLocationHolder> { |
| 8657 | |
| 8658 | private static final int MAX_POOL_SIZE = 32; |
| 8659 | |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8660 | private static final SynchronizedPool<ViewLocationHolder> sPool = |
| 8661 | new SynchronizedPool<ViewLocationHolder>(MAX_POOL_SIZE); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8662 | |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8663 | public static final int COMPARISON_STRATEGY_STRIPE = 1; |
| 8664 | |
| 8665 | public static final int COMPARISON_STRATEGY_LOCATION = 2; |
| 8666 | |
| 8667 | private static int sComparisonStrategy = COMPARISON_STRATEGY_STRIPE; |
| 8668 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8669 | private final Rect mLocation = new Rect(); |
| 8670 | |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8671 | private ViewGroup mRoot; |
| 8672 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8673 | public View mView; |
| 8674 | |
| 8675 | private int mLayoutDirection; |
| 8676 | |
| 8677 | public static ViewLocationHolder obtain(ViewGroup root, View view) { |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8678 | ViewLocationHolder holder = sPool.acquire(); |
| 8679 | if (holder == null) { |
| 8680 | holder = new ViewLocationHolder(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8681 | } |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8682 | holder.init(root, view); |
| 8683 | return holder; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8684 | } |
| 8685 | |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8686 | public static void setComparisonStrategy(int strategy) { |
| 8687 | sComparisonStrategy = strategy; |
| 8688 | } |
| 8689 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8690 | public void recycle() { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8691 | clear(); |
Svetoslav Ganov | be922dc | 2012-11-30 16:46:26 -0800 | [diff] [blame] | 8692 | sPool.release(this); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8693 | } |
| 8694 | |
| 8695 | @Override |
| 8696 | public int compareTo(ViewLocationHolder another) { |
| 8697 | // This instance is greater than an invalid argument. |
| 8698 | if (another == null) { |
| 8699 | return 1; |
| 8700 | } |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8701 | |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8702 | int boundsResult = compareBoundsOfTree(this, another); |
| 8703 | if (boundsResult != 0) { |
| 8704 | return boundsResult; |
| 8705 | } |
| 8706 | |
| 8707 | // Just break the tie somehow. The accessibility ids are unique |
| 8708 | // and stable, hence this is deterministic tie breaking. |
| 8709 | return mView.getAccessibilityViewId() - another.mView.getAccessibilityViewId(); |
| 8710 | } |
| 8711 | |
| 8712 | /** |
| 8713 | * Compare two views based on their bounds. Use the bounds of their children to break ties. |
| 8714 | * |
| 8715 | * @param holder1 Holder of first view to compare |
Phil Weaver | 6adf3a1 | 2018-08-21 16:08:42 -0700 | [diff] [blame] | 8716 | * @param holder2 Holder of second view to compare. Must have the same root as holder1. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8717 | * @return The compare result, with equality if no good comparison was found. |
| 8718 | */ |
| 8719 | private static int compareBoundsOfTree( |
| 8720 | ViewLocationHolder holder1, ViewLocationHolder holder2) { |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8721 | if (sComparisonStrategy == COMPARISON_STRATEGY_STRIPE) { |
| 8722 | // First is above second. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8723 | if (holder1.mLocation.bottom - holder2.mLocation.top <= 0) { |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8724 | return -1; |
| 8725 | } |
| 8726 | // First is below second. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8727 | if (holder1.mLocation.top - holder2.mLocation.bottom >= 0) { |
Svetoslav | 88e447b | 2014-10-09 15:49:02 -0700 | [diff] [blame] | 8728 | return 1; |
| 8729 | } |
| 8730 | } |
| 8731 | |
Svetoslav | 04cab1b | 2014-08-25 18:35:57 -0700 | [diff] [blame] | 8732 | // We are ordering left-to-right, top-to-bottom. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8733 | if (holder1.mLayoutDirection == LAYOUT_DIRECTION_LTR) { |
| 8734 | final int leftDifference = holder1.mLocation.left - holder2.mLocation.left; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8735 | if (leftDifference != 0) { |
| 8736 | return leftDifference; |
| 8737 | } |
| 8738 | } else { // RTL |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8739 | final int rightDifference = holder1.mLocation.right - holder2.mLocation.right; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8740 | if (rightDifference != 0) { |
| 8741 | return -rightDifference; |
| 8742 | } |
| 8743 | } |
Svetoslav | 04cab1b | 2014-08-25 18:35:57 -0700 | [diff] [blame] | 8744 | // We are ordering left-to-right, top-to-bottom. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8745 | final int topDifference = holder1.mLocation.top - holder2.mLocation.top; |
Svetoslav | 04cab1b | 2014-08-25 18:35:57 -0700 | [diff] [blame] | 8746 | if (topDifference != 0) { |
| 8747 | return topDifference; |
| 8748 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8749 | // Break tie by height. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8750 | final int heightDiference = holder1.mLocation.height() - holder2.mLocation.height(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8751 | if (heightDiference != 0) { |
| 8752 | return -heightDiference; |
| 8753 | } |
| 8754 | // Break tie by width. |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8755 | final int widthDifference = holder1.mLocation.width() - holder2.mLocation.width(); |
| 8756 | if (widthDifference != 0) { |
| 8757 | return -widthDifference; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8758 | } |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8759 | |
| 8760 | // Find a child of each view with different screen bounds. |
| 8761 | final Rect view1Bounds = new Rect(); |
| 8762 | final Rect view2Bounds = new Rect(); |
| 8763 | final Rect tempRect = new Rect(); |
| 8764 | holder1.mView.getBoundsOnScreen(view1Bounds, true); |
| 8765 | holder2.mView.getBoundsOnScreen(view2Bounds, true); |
| 8766 | final View child1 = holder1.mView.findViewByPredicateTraversal((view) -> { |
| 8767 | view.getBoundsOnScreen(tempRect, true); |
| 8768 | return !tempRect.equals(view1Bounds); |
| 8769 | }, null); |
| 8770 | final View child2 = holder2.mView.findViewByPredicateTraversal((view) -> { |
| 8771 | view.getBoundsOnScreen(tempRect, true); |
| 8772 | return !tempRect.equals(view2Bounds); |
| 8773 | }, null); |
| 8774 | |
| 8775 | |
| 8776 | // Compare the children recursively |
| 8777 | if ((child1 != null) && (child2 != null)) { |
| 8778 | final ViewLocationHolder childHolder1 = |
| 8779 | ViewLocationHolder.obtain(holder1.mRoot, child1); |
| 8780 | final ViewLocationHolder childHolder2 = |
| 8781 | ViewLocationHolder.obtain(holder1.mRoot, child2); |
| 8782 | return compareBoundsOfTree(childHolder1, childHolder2); |
| 8783 | } |
| 8784 | |
| 8785 | // If only one has a child, use that one |
| 8786 | if (child1 != null) { |
| 8787 | return 1; |
| 8788 | } |
| 8789 | |
| 8790 | if (child2 != null) { |
| 8791 | return -1; |
| 8792 | } |
| 8793 | |
| 8794 | // Give up |
| 8795 | return 0; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8796 | } |
| 8797 | |
| 8798 | private void init(ViewGroup root, View view) { |
| 8799 | Rect viewLocation = mLocation; |
| 8800 | view.getDrawingRect(viewLocation); |
| 8801 | root.offsetDescendantRectToMyCoords(view, viewLocation); |
| 8802 | mView = view; |
Phil Weaver | 86b3260 | 2018-05-10 18:00:18 -0700 | [diff] [blame] | 8803 | mRoot = root; |
Fabrice Di Meglio | e56ffdc | 2012-09-23 14:51:16 -0700 | [diff] [blame] | 8804 | mLayoutDirection = root.getLayoutDirection(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | private void clear() { |
| 8808 | mView = null; |
Phil Weaver | 6adf3a1 | 2018-08-21 16:08:42 -0700 | [diff] [blame] | 8809 | mRoot = null; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 8810 | mLocation.set(0, 0, 0, 0); |
| 8811 | } |
| 8812 | } |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8813 | |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 8814 | private static void drawRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) { |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8815 | if (sDebugLines== null) { |
Romain Guy | 6410c0a | 2013-06-17 11:21:58 -0700 | [diff] [blame] | 8816 | // TODO: This won't work with multiple UI threads in a single process |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8817 | sDebugLines = new float[16]; |
| 8818 | } |
| 8819 | |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8820 | sDebugLines[0] = x1; |
| 8821 | sDebugLines[1] = y1; |
| 8822 | sDebugLines[2] = x2; |
| 8823 | sDebugLines[3] = y1; |
| 8824 | |
| 8825 | sDebugLines[4] = x2; |
| 8826 | sDebugLines[5] = y1; |
| 8827 | sDebugLines[6] = x2; |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 8828 | sDebugLines[7] = y2; |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8829 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 8830 | sDebugLines[8] = x2; |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8831 | sDebugLines[9] = y2; |
| 8832 | sDebugLines[10] = x1; |
| 8833 | sDebugLines[11] = y2; |
| 8834 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 8835 | sDebugLines[12] = x1; |
| 8836 | sDebugLines[13] = y2; |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8837 | sDebugLines[14] = x1; |
| 8838 | sDebugLines[15] = y1; |
| 8839 | |
Philip Milne | 7b75781 | 2012-09-19 18:13:44 -0700 | [diff] [blame] | 8840 | canvas.drawLines(sDebugLines, paint); |
Romain Guy | cbc6774 | 2012-04-27 16:12:57 -0700 | [diff] [blame] | 8841 | } |
Siva Velusamy | 0d857b9 | 2015-04-22 10:23:56 -0700 | [diff] [blame] | 8842 | |
| 8843 | /** @hide */ |
| 8844 | @Override |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 8845 | @UnsupportedAppUsage |
Siva Velusamy | 0d857b9 | 2015-04-22 10:23:56 -0700 | [diff] [blame] | 8846 | protected void encodeProperties(@NonNull ViewHierarchyEncoder encoder) { |
| 8847 | super.encodeProperties(encoder); |
| 8848 | |
| 8849 | encoder.addProperty("focus:descendantFocusability", getDescendantFocusability()); |
| 8850 | encoder.addProperty("drawing:clipChildren", getClipChildren()); |
| 8851 | encoder.addProperty("drawing:clipToPadding", getClipToPadding()); |
| 8852 | encoder.addProperty("drawing:childrenDrawingOrderEnabled", isChildrenDrawingOrderEnabled()); |
| 8853 | encoder.addProperty("drawing:persistentDrawingCache", getPersistentDrawingCache()); |
| 8854 | |
| 8855 | int n = getChildCount(); |
| 8856 | encoder.addProperty("meta:__childCount__", (short)n); |
| 8857 | for (int i = 0; i < n; i++) { |
| 8858 | encoder.addPropertyKey("meta:__child__" + i); |
| 8859 | getChildAt(i).encode(encoder); |
| 8860 | } |
| 8861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8862 | } |