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 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 20 | import static android.view.View.PFLAG_DRAW_ANIMATION; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 21 | import static android.view.WindowCallbacks.RESIZE_MODE_DOCKED_DIVIDER; |
| 22 | import static android.view.WindowCallbacks.RESIZE_MODE_FREEFORM; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 24 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 25 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 26 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 27 | |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 28 | import android.Manifest; |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 29 | import android.animation.LayoutTransition; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 30 | import android.annotation.NonNull; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 31 | import android.app.ActivityManager; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 32 | import android.app.ActivityThread; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 33 | import android.app.ResourcesManager; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 34 | import android.content.ClipData; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 35 | import android.content.ClipDescription; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.pm.PackageManager; |
| 38 | import android.content.res.CompatibilityInfo; |
| 39 | import android.content.res.Configuration; |
| 40 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.graphics.Canvas; |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 42 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.graphics.PixelFormat; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 44 | import android.graphics.Point; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 45 | import android.graphics.PointF; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 46 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.graphics.Rect; |
| 48 | import android.graphics.Region; |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 49 | import android.graphics.drawable.AnimatedVectorDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 50 | import android.graphics.drawable.Drawable; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 51 | import android.hardware.display.DisplayManager; |
| 52 | import android.hardware.display.DisplayManager.DisplayListener; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 53 | import android.hardware.input.InputManager; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 54 | import android.media.AudioManager; |
| 55 | import android.os.Binder; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 56 | import android.os.Build; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 57 | import android.os.Bundle; |
| 58 | import android.os.Debug; |
| 59 | import android.os.Handler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 60 | import android.os.Looper; |
| 61 | import android.os.Message; |
| 62 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.os.Process; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 64 | import android.os.RemoteException; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 65 | import android.os.SystemClock; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 66 | import android.os.SystemProperties; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 67 | import android.os.Trace; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.util.AndroidRuntimeException; |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 69 | import android.util.DisplayMetrics; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 70 | import android.util.Log; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 71 | import android.util.MergedConfiguration; |
Chet Haase | 949dbf7 | 2010-08-11 18:41:06 -0700 | [diff] [blame] | 72 | import android.util.Slog; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 73 | import android.util.TimeUtils; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 74 | import android.util.TypedValue; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 75 | import android.view.Surface.OutOfResourcesException; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 76 | import android.view.View.AttachInfo; |
Evan Rosky | 5722331 | 2017-02-08 14:42:45 -0800 | [diff] [blame] | 77 | import android.view.View.FocusDirection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.view.View.MeasureSpec; |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 79 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 80 | import android.view.accessibility.AccessibilityEvent; |
| 81 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 82 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 83 | import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 84 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 85 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 86 | import android.view.accessibility.AccessibilityNodeProvider; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 87 | import android.view.accessibility.AccessibilityWindowInfo; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 88 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 89 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 90 | import android.view.animation.AccelerateDecelerateInterpolator; |
| 91 | import android.view.animation.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.view.inputmethod.InputMethodManager; |
| 93 | import android.widget.Scroller; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 94 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 95 | import com.android.internal.R; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 96 | import com.android.internal.annotations.GuardedBy; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 97 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 98 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 99 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 100 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 101 | import com.android.internal.view.RootViewSurfaceTaker; |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 102 | import com.android.internal.view.SurfaceCallbackHelper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 104 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import java.io.IOException; |
| 106 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 107 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 108 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | import java.util.ArrayList; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 110 | import java.util.HashSet; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 111 | import java.util.concurrent.CountDownLatch; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | /** |
| 114 | * The top of a view hierarchy, implementing the needed protocol between View |
| 115 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 116 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | * |
| 118 | * {@hide} |
| 119 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 120 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 121 | public final class ViewRootImpl implements ViewParent, |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 122 | View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 123 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 125 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | /** @noinspection PointlessBooleanExpression*/ |
| 127 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 128 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 129 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 131 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 132 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 133 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 134 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 135 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 136 | private static final boolean DEBUG_INPUT_STAGES = false || LOCAL_LOGV; |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 137 | private static final boolean DEBUG_KEEP_SCREEN_ON = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 139 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 140 | * Set to false if we do not want to use the multi threaded renderer. Note that by disabling |
| 141 | * this, WindowCallbacks will not fire. |
| 142 | */ |
| 143 | private static final boolean USE_MT_RENDERER = true; |
| 144 | |
| 145 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 146 | * Set this system property to true to force the view hierarchy to render |
| 147 | * at 60 Hz. This can be used to measure the potential framerate. |
| 148 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 149 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 150 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 151 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 152 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 153 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Maximum time we allow the user to roll the trackball enough to generate |
| 157 | * a key event, before resetting the counters. |
| 158 | */ |
| 159 | static final int MAX_TRACKBALL_DELAY = 250; |
| 160 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 161 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 163 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 164 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 165 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Callback for notifying about global configuration changes. |
| 168 | */ |
| 169 | public interface ConfigChangedCallback { |
| 170 | |
| 171 | /** Notifies about global config change. */ |
| 172 | void onConfigurationChanged(Configuration globalConfig); |
| 173 | } |
| 174 | |
| 175 | private static final ArrayList<ConfigChangedCallback> sConfigCallbacks = new ArrayList<>(); |
| 176 | |
| 177 | /** |
| 178 | * Callback for notifying activities about override configuration changes. |
| 179 | */ |
| 180 | public interface ActivityConfigCallback { |
| 181 | |
| 182 | /** |
| 183 | * Notifies about override config change and/or move to different display. |
| 184 | * @param overrideConfig New override config to apply to activity. |
| 185 | * @param newDisplayId New display id, {@link Display#INVALID_DISPLAY} if not changed. |
| 186 | */ |
| 187 | void onConfigurationChanged(Configuration overrideConfig, int newDisplayId); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Callback used to notify corresponding activity about override configuration change and make |
| 192 | * sure that all resources are set correctly before updating the ViewRootImpl's internal state. |
| 193 | */ |
| 194 | private ActivityConfigCallback mActivityConfigCallback; |
| 195 | |
| 196 | /** |
| 197 | * Used when configuration change first updates the config of corresponding activity. |
| 198 | * In that case we receive a call back from {@link ActivityThread} and this flag is used to |
| 199 | * preserve the initial value. |
| 200 | * |
| 201 | * @see #performConfigurationChange(Configuration, Configuration, boolean, int) |
| 202 | */ |
| 203 | private boolean mForceNextConfigUpdate; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 204 | |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 205 | /** |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 206 | * Signals that compatibility booleans have been initialized according to |
| 207 | * target SDK versions. |
| 208 | */ |
| 209 | private static boolean sCompatibilityDone = false; |
| 210 | |
| 211 | /** |
| 212 | * Always assign focus if a focusable View is available. |
| 213 | */ |
| 214 | private static boolean sAlwaysAssignFocus; |
| 215 | |
| 216 | /** |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 217 | * This list must only be modified by the main thread, so a lock is only needed when changing |
| 218 | * the list or when accessing the list from a non-main thread. |
| 219 | */ |
| 220 | @GuardedBy("mWindowCallbacks") |
| 221 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 222 | final Context mContext; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 223 | final IWindowSession mWindowSession; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 224 | @NonNull Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 225 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 226 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 229 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 230 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | final Thread mThread; |
| 233 | |
| 234 | final WindowLeaked mLocation; |
| 235 | |
| 236 | final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
| 237 | |
| 238 | final W mWindow; |
| 239 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 240 | final int mTargetSdkVersion; |
| 241 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 242 | int mSeq; |
| 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 245 | |
| 246 | View mAccessibilityFocusedHost; |
| 247 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 248 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 249 | // True if the window currently has pointer capture enabled. |
| 250 | boolean mPointerCapture; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | int mViewVisibility; |
| 253 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 254 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 255 | // that it became invisible. This will ignore that information and depend on the decor view |
| 256 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 257 | // stopped and that's when the app will stop drawing further frames. |
| 258 | private boolean mForceDecorViewVisibility = false; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 259 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 261 | /** Whether the window had focus during the most recent traversal. */ |
| 262 | boolean mHadWindowFocus; |
| 263 | |
| 264 | /** |
| 265 | * Whether the window lost focus during a previous traversal and has not |
| 266 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 267 | * accessibility events should be sent during traversal. |
| 268 | */ |
| 269 | boolean mLostWindowFocus; |
| 270 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 271 | // Set to true if the owner of this window is in the stopped state, |
| 272 | // so the window should no longer be active. |
| 273 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 274 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 275 | // Set to true if the owner of this window is in ambient mode, |
| 276 | // which means it won't receive input events. |
| 277 | boolean mIsAmbientMode = false; |
| 278 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 279 | // Set to true to stop input during an Activity Transition. |
| 280 | boolean mPausedForTransition = false; |
| 281 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 282 | boolean mLastInCompatMode = false; |
| 283 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 284 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 285 | BaseSurfaceHolder mSurfaceHolder; |
| 286 | boolean mIsCreating; |
| 287 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | final Region mTransparentRegion; |
| 290 | final Region mPreviousTransparentRegion; |
| 291 | |
| 292 | int mWidth; |
| 293 | int mHeight; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 294 | Rect mDirty; |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 295 | public boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 296 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 297 | private boolean mDragResizing; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 298 | private boolean mInvalidateRootRequested; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 299 | private int mResizeMode; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 300 | private int mCanvasOffsetX; |
| 301 | private int mCanvasOffsetY; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 302 | private boolean mActivityRelaunched; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 303 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 304 | CompatibilityInfo.Translator mTranslator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | |
| 306 | final View.AttachInfo mAttachInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 307 | InputChannel mInputChannel; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 308 | InputQueue.Callback mInputQueueCallback; |
| 309 | InputQueue mInputQueue; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 310 | FallbackEventHandler mFallbackEventHandler; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 311 | Choreographer mChoreographer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | final Rect mTempRect; // used in the transaction to not thrash the heap. |
| 314 | final Rect mVisRect; // used to retrieve visible rect of focused view. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | |
Chris Craik | 3f06c6d | 2017-01-09 18:19:48 +0000 | [diff] [blame] | 316 | public boolean mTraversalScheduled; |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 317 | int mTraversalBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | boolean mWillDrawSoon; |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 319 | /** Set to true while in performTraversals for detecting when die(true) is called from internal |
| 320 | * callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */ |
| 321 | boolean mIsInTraversal; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 322 | boolean mApplyInsetsRequested; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | boolean mLayoutRequested; |
| 324 | boolean mFirst; |
| 325 | boolean mReportNextDraw; |
| 326 | boolean mFullRedrawNeeded; |
| 327 | boolean mNewSurfaceNeeded; |
| 328 | boolean mHasHadWindowFocus; |
| 329 | boolean mLastWasImTarget; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 330 | boolean mForceNextWindowRelayout; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 331 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 332 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 333 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 334 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 335 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 336 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 337 | |
| 338 | // Pool of queued input events. |
| 339 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 340 | private QueuedInputEvent mQueuedInputEventPool; |
| 341 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 342 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 343 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 344 | * Pending input events are input events waiting to be delivered to the input stages |
| 345 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 346 | */ |
| 347 | QueuedInputEvent mPendingInputEventHead; |
| 348 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 349 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 350 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 351 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 352 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 353 | |
| 354 | InputStage mFirstInputStage; |
| 355 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 356 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | |
| 358 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 359 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | |
| 361 | // These can be accessed by any thread, must be protected with a lock. |
Mathias Agopian | 5583dc6 | 2009-07-09 16:28:11 -0700 | [diff] [blame] | 362 | // Surface can never be reassigned or cleared (use Surface.clear()). |
John Reck | b13de07 | 2014-11-19 16:33:47 -0800 | [diff] [blame] | 363 | final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | |
| 365 | boolean mAdded; |
| 366 | boolean mAddedTouchMode; |
| 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | // These are accessed by multiple threads. |
| 369 | final Rect mWinFrame; // frame given by window manager. |
| 370 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 371 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 373 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 375 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 376 | final Rect mPendingBackDropFrame = new Rect(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 377 | boolean mPendingAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 379 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 380 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 381 | final Rect mDispatchContentInsets = new Rect(); |
| 382 | final Rect mDispatchStableInsets = new Rect(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 383 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 384 | private WindowInsets mLastWindowInsets; |
| 385 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 386 | /** Last applied configuration obtained from resources. */ |
| 387 | private final Configuration mLastConfigurationFromResources = new Configuration(); |
| 388 | /** Last configuration reported from WM or via {@link #MSG_UPDATE_CONFIGURATION}. */ |
| 389 | private final MergedConfiguration mLastReportedMergedConfiguration = new MergedConfiguration(); |
| 390 | /** Configurations waiting to be applied. */ |
| 391 | private final MergedConfiguration mPendingMergedConfiguration = new MergedConfiguration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | boolean mScrollMayChange; |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 394 | @SoftInputModeFlags |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | int mSoftInputMode; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 396 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | int mScrollY; |
| 398 | int mCurScrollY; |
| 399 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 400 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 401 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 402 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 403 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 405 | /* Drag/drop */ |
| 406 | ClipDescription mDragDescription; |
| 407 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 408 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 409 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 410 | final PointF mLastTouchPoint = new PointF(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 411 | int mLastTouchSource; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 412 | |
| 413 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 414 | private Choreographer.FrameCallback mRenderProfiler; |
| 415 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 416 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 417 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 418 | private long mFpsStartTime = -1; |
| 419 | private long mFpsPrevTime = -1; |
| 420 | private int mFpsNumFrames; |
| 421 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 422 | private int mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 423 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | /** |
| 426 | * see {@link #playSoundEffect(int)} |
| 427 | */ |
| 428 | AudioManager mAudioManager; |
| 429 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 430 | final AccessibilityManager mAccessibilityManager; |
| 431 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 432 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 433 | |
| 434 | AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 435 | HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 436 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 437 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 438 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 439 | HashSet<View> mTempHashSet; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 440 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 441 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 442 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 443 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 444 | private boolean mInLayout = false; |
| 445 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 446 | boolean mHandlingLayoutInLayoutRequest = false; |
| 447 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 448 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 449 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 450 | /** Set to true once doDie() has been called. */ |
| 451 | private boolean mRemoved; |
| 452 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 453 | private boolean mNeedsRendererSetup; |
Robert Carr | 1bccabf | 2016-04-28 13:27:08 -0700 | [diff] [blame] | 454 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 455 | /** |
| 456 | * Consistency verifier for debugging purposes. |
| 457 | */ |
| 458 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 459 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 460 | new InputEventConsistencyVerifier(this, 0) : null; |
| 461 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 462 | static final class SystemUiVisibilityInfo { |
| 463 | int seq; |
| 464 | int globalVisibility; |
| 465 | int localValue; |
| 466 | int localChanges; |
| 467 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 468 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 469 | private String mTag = TAG; |
| 470 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 471 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 472 | mContext = context; |
| 473 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 474 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 475 | mBasePackageName = context.getBasePackageName(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | mThread = Thread.currentThread(); |
| 477 | mLocation = new WindowLeaked(null); |
| 478 | mLocation.fillInStackTrace(); |
| 479 | mWidth = -1; |
| 480 | mHeight = -1; |
| 481 | mDirty = new Rect(); |
| 482 | mTempRect = new Rect(); |
| 483 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 485 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 486 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | mViewVisibility = View.GONE; |
| 488 | mTransparentRegion = new Region(); |
| 489 | mPreviousTransparentRegion = new Region(); |
| 490 | mFirst = true; // true for the first time the view is added |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | mAdded = false; |
John Reck | d94094e | 2016-09-08 14:12:26 -0700 | [diff] [blame] | 492 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this, |
| 493 | context); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 494 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
| 495 | mAccessibilityInteractionConnectionManager = |
| 496 | new AccessibilityInteractionConnectionManager(); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 497 | mAccessibilityManager.addAccessibilityStateChangeListener( |
| 498 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 499 | mHighContrastTextManager = new HighContrastTextManager(); |
| 500 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
| 501 | mHighContrastTextManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 503 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 504 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 505 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 506 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 507 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 508 | |
| 509 | if (!sCompatibilityDone) { |
Evan Rosky | cfd6c85 | 2017-03-17 12:39:15 -0700 | [diff] [blame] | 510 | sAlwaysAssignFocus = true; |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 511 | |
| 512 | sCompatibilityDone = true; |
| 513 | } |
| 514 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 515 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 518 | public static void addFirstDrawHandler(Runnable callback) { |
| 519 | synchronized (sFirstDrawHandlers) { |
| 520 | if (!sFirstDrawComplete) { |
| 521 | sFirstDrawHandlers.add(callback); |
| 522 | } |
| 523 | } |
| 524 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 525 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 526 | /** Add static config callback to be notified about global config changes. */ |
| 527 | public static void addConfigCallback(ConfigChangedCallback callback) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 528 | synchronized (sConfigCallbacks) { |
| 529 | sConfigCallbacks.add(callback); |
| 530 | } |
| 531 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 532 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 533 | /** Add activity config callback to be notified about override config changes. */ |
| 534 | public void setActivityConfigCallback(ActivityConfigCallback callback) { |
| 535 | mActivityConfigCallback = callback; |
| 536 | } |
| 537 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 538 | public void addWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 539 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 540 | synchronized (mWindowCallbacks) { |
| 541 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 546 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 547 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 548 | synchronized (mWindowCallbacks) { |
| 549 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 554 | public void reportDrawFinish() { |
| 555 | if (mWindowDrawCountDown != null) { |
| 556 | mWindowDrawCountDown.countDown(); |
| 557 | } |
| 558 | } |
| 559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | // FIXME for perf testing only |
| 561 | private boolean mProfile = false; |
| 562 | |
| 563 | /** |
| 564 | * Call this to profile the next traversal call. |
| 565 | * FIXME for perf testing only. Remove eventually |
| 566 | */ |
| 567 | public void profile() { |
| 568 | mProfile = true; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 573 | * call and should be avoided whenever possible. |
| 574 | * |
| 575 | * @return True, if the device is in touch mode, false otherwise. |
| 576 | * |
| 577 | * @hide |
| 578 | */ |
| 579 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 580 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 581 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 583 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } catch (RemoteException e) { |
| 585 | } |
| 586 | } |
| 587 | return false; |
| 588 | } |
| 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | /** |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 591 | * Notifies us that our child has been rebuilt, following |
| 592 | * a window preservation operation. In these cases we |
| 593 | * keep the same DecorView, but the activity controlling it |
| 594 | * is a different instance, and we need to update our |
| 595 | * callbacks. |
| 596 | * |
| 597 | * @hide |
| 598 | */ |
| 599 | public void notifyChildRebuilt() { |
| 600 | if (mView instanceof RootViewSurfaceTaker) { |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 601 | if (mSurfaceHolderCallback != null) { |
| 602 | mSurfaceHolder.removeCallback(mSurfaceHolderCallback); |
| 603 | } |
| 604 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 605 | mSurfaceHolderCallback = |
| 606 | ((RootViewSurfaceTaker)mView).willYouTakeTheSurface(); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 607 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 608 | if (mSurfaceHolderCallback != null) { |
| 609 | mSurfaceHolder = new TakenSurfaceHolder(); |
| 610 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 611 | mSurfaceHolder.addCallback(mSurfaceHolderCallback); |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 612 | } else { |
| 613 | mSurfaceHolder = null; |
| 614 | } |
| 615 | |
| 616 | mInputQueueCallback = |
| 617 | ((RootViewSurfaceTaker)mView).willYouTakeTheInputQueue(); |
| 618 | if (mInputQueueCallback != null) { |
| 619 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | * We have one child |
| 626 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 627 | public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | synchronized (this) { |
| 629 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 630 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 631 | |
| 632 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 633 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 634 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 635 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 636 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 637 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 638 | if (mWindowAttributes.packageName == null) { |
| 639 | mWindowAttributes.packageName = mBasePackageName; |
| 640 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 641 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 642 | setTag(); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 643 | |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 644 | if (DEBUG_KEEP_SCREEN_ON && (mClientWindowLayoutFlags |
| 645 | & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0 |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 646 | && (attrs.flags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 647 | Slog.d(mTag, "setView: FLAG_KEEP_SCREEN_ON changed from true to false!"); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 648 | } |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 649 | // Keep track of the actual window flags supplied by the client. |
| 650 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 651 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 652 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 653 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 654 | if (view instanceof RootViewSurfaceTaker) { |
| 655 | mSurfaceHolderCallback = |
| 656 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 657 | if (mSurfaceHolderCallback != null) { |
| 658 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 659 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 660 | mSurfaceHolder.addCallback(mSurfaceHolderCallback); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 663 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 664 | // Compute surface insets required to draw at specified Z value. |
| 665 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 666 | if (!attrs.hasManualSurfaceInsets) { |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 667 | attrs.setSurfaceInsets(view, false /*manual*/, true /*preservePrevious*/); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 668 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 669 | |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 670 | CompatibilityInfo compatibilityInfo = |
| 671 | mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 672 | mTranslator = compatibilityInfo.getTranslator(); |
| 673 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 674 | // If the application owns the surface, don't enable hardware acceleration |
| 675 | if (mSurfaceHolder == null) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 676 | enableHardwareAcceleration(attrs); |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 679 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 680 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 681 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 682 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 683 | attrs.backup(); |
| 684 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 685 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 686 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 687 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 688 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 689 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 690 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 691 | } |
| 692 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | mSoftInputMode = attrs.softInputMode; |
| 694 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 695 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 697 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 698 | mAttachInfo.mApplicationScale = |
| 699 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | if (panelParentView != null) { |
| 701 | mAttachInfo.mPanelParentWindowToken |
| 702 | = panelParentView.getApplicationWindowToken(); |
| 703 | } |
| 704 | mAdded = true; |
| 705 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | // Schedule the first layout -before- adding to the window |
| 708 | // manager, to make sure we do the relayout before receiving |
| 709 | // any other events from the system. |
| 710 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 711 | if ((mWindowAttributes.inputFeatures |
| 712 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 713 | mInputChannel = new InputChannel(); |
| 714 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 715 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 716 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 718 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 719 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 720 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 721 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
| 722 | getHostVisibility(), mDisplay.getDisplayId(), |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 723 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
| 724 | mAttachInfo.mOutsets, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | } catch (RemoteException e) { |
| 726 | mAdded = false; |
| 727 | mView = null; |
| 728 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 729 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 730 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 732 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 734 | } finally { |
| 735 | if (restore) { |
| 736 | attrs.restore(); |
| 737 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 739 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 740 | if (mTranslator != null) { |
| 741 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 742 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 743 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 745 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 747 | mAttachInfo.mAlwaysConsumeNavBar = |
| 748 | (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR) != 0; |
| 749 | mPendingAlwaysConsumeNavBar = mAttachInfo.mAlwaysConsumeNavBar; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 750 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 751 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | mAttachInfo.mRootView = null; |
| 753 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 754 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 756 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 758 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 759 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 760 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 761 | "Unable to add window -- token " + attrs.token |
| 762 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 763 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 764 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 765 | "Unable to add window -- token " + attrs.token |
| 766 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 767 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 768 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 769 | "Unable to add window -- app for token " + attrs.token |
| 770 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 771 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 772 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 773 | "Unable to add window -- window " + mWindow |
| 774 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 775 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 776 | // Silently ignore -- we would have just removed it |
| 777 | // right away, anyway. |
| 778 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 779 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 780 | throw new WindowManager.BadTokenException("Unable to add window " |
| 781 | + mWindow + " -- another window of type " |
| 782 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 783 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 784 | throw new WindowManager.BadTokenException("Unable to add window " |
| 785 | + mWindow + " -- permission denied for window type " |
| 786 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 787 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 788 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 789 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 790 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 791 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 792 | + mWindow + " -- the specified window type " |
| 793 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | } |
| 795 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 796 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 798 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 799 | if (view instanceof RootViewSurfaceTaker) { |
| 800 | mInputQueueCallback = |
| 801 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 802 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 803 | if (mInputChannel != null) { |
| 804 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 805 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 806 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 807 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 808 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 809 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 810 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 813 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 814 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 815 | |
| 816 | if (mAccessibilityManager.isEnabled()) { |
| 817 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 818 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 819 | |
| 820 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 821 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 822 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 823 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 824 | // Set up the input pipeline. |
| 825 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 826 | mSyntheticInputStage = new SyntheticInputStage(); |
| 827 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 828 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 829 | "aq:native-post-ime:" + counterSuffix); |
| 830 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 831 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 832 | "aq:ime:" + counterSuffix); |
| 833 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 834 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 835 | "aq:native-pre-ime:" + counterSuffix); |
| 836 | |
| 837 | mFirstInputStage = nativePreImeStage; |
| 838 | mFirstPostImeInputStage = earlyPostImeStage; |
| 839 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 844 | private void setTag() { |
| 845 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 846 | if (split.length > 0) { |
| 847 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 848 | } |
| 849 | } |
| 850 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 851 | /** Whether the window is in local focus mode or not */ |
| 852 | private boolean isInLocalFocusMode() { |
| 853 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 854 | } |
| 855 | |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 856 | public int getWindowFlags() { |
| 857 | return mWindowAttributes.flags; |
| 858 | } |
| 859 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 860 | public int getDisplayId() { |
| 861 | return mDisplay.getDisplayId(); |
| 862 | } |
| 863 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 864 | public CharSequence getTitle() { |
| 865 | return mWindowAttributes.getTitle(); |
| 866 | } |
| 867 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 868 | void destroyHardwareResources() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 869 | if (mAttachInfo.mThreadedRenderer != null) { |
| 870 | mAttachInfo.mThreadedRenderer.destroyHardwareResources(mView); |
| 871 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 875 | public void detachFunctor(long functor) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 876 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 877 | // Fence so that any pending invokeFunctor() messages will be processed |
| 878 | // before we return from detachFunctor. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 879 | mAttachInfo.mThreadedRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 880 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 881 | } |
| 882 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 883 | /** |
| 884 | * Schedules the functor for execution in either kModeProcess or |
| 885 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 886 | * |
| 887 | * @param functor The native functor to invoke |
| 888 | * @param waitForCompletion If true, this will not return until the functor |
| 889 | * has invoked. If false, the functor may be invoked |
| 890 | * asynchronously. |
| 891 | */ |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 892 | public static void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 893 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 894 | } |
| 895 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 896 | public void registerAnimatingRenderNode(RenderNode animator) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 897 | if (mAttachInfo.mThreadedRenderer != null) { |
| 898 | mAttachInfo.mThreadedRenderer.registerAnimatingRenderNode(animator); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 899 | } else { |
| 900 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 901 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 902 | } |
| 903 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 904 | } |
| 905 | } |
| 906 | |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 907 | public void registerVectorDrawableAnimator( |
| 908 | AnimatedVectorDrawable.VectorDrawableAnimatorRT animator) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 909 | if (mAttachInfo.mThreadedRenderer != null) { |
| 910 | mAttachInfo.mThreadedRenderer.registerVectorDrawableAnimator(animator); |
Doris Liu | 718cd3e | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 914 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 915 | mAttachInfo.mHardwareAccelerated = false; |
| 916 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 917 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 918 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 919 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 920 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 921 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 922 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 923 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 924 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 925 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 926 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 927 | return; |
| 928 | } |
| 929 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 930 | // Persistent processes (including the system) should not do |
| 931 | // accelerated rendering on low-end devices. In that case, |
| 932 | // sRendererDisabled will be set. In addition, the system process |
| 933 | // itself should never do accelerated rendering. In that case, both |
| 934 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 935 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 936 | // can be used by code on the system process to escape that and enable |
| 937 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 938 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 939 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 940 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 941 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 942 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 943 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 944 | if (fakeHwAccelerated) { |
| 945 | // This is exclusively for the preview windows the window manager |
| 946 | // shows for launching applications, so they will look more like |
| 947 | // the app being launched. |
| 948 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 949 | } else if (!ThreadedRenderer.sRendererDisabled |
| 950 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 951 | if (mAttachInfo.mThreadedRenderer != null) { |
| 952 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 953 | } |
| 954 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 955 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 956 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 957 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 958 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 959 | mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent, |
| 960 | attrs.getTitle().toString()); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 961 | if (mAttachInfo.mThreadedRenderer != null) { |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 962 | mAttachInfo.mHardwareAccelerated = |
| 963 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 964 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | } |
| 968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | public View getView() { |
| 970 | return mView; |
| 971 | } |
| 972 | |
| 973 | final WindowLeaked getLocation() { |
| 974 | return mLocation; |
| 975 | } |
| 976 | |
| 977 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 978 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 979 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 980 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 981 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 982 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 983 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 984 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 985 | |
| 986 | if (DEBUG_KEEP_SCREEN_ON && (mClientWindowLayoutFlags |
| 987 | & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0 |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 988 | && (attrs.flags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { |
Chong Zhang | 44aabe4 | 2016-05-10 11:20:14 -0700 | [diff] [blame] | 989 | Slog.d(mTag, "setLayoutParams: FLAG_KEEP_SCREEN_ON from true to false!"); |
Chong Zhang | 4ffc318 | 2016-05-04 15:06:02 -0700 | [diff] [blame] | 990 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 991 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 992 | // Keep track of the actual window flags supplied by the client. |
| 993 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 994 | |
| 995 | // Preserve compatible window flag if exists. |
| 996 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 997 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 998 | |
| 999 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 1000 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 1001 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1002 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1003 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1004 | if ((mWindowAttributesChangesFlag |
| 1005 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 1006 | // Recompute system ui visibility. |
| 1007 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 1008 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 1009 | if ((mWindowAttributesChangesFlag |
| 1010 | & WindowManager.LayoutParams.LAYOUT_CHANGED) != 0) { |
| 1011 | // Request to update light center. |
| 1012 | mAttachInfo.mNeedsUpdateLightCenter = true; |
| 1013 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1014 | if (mWindowAttributes.packageName == null) { |
| 1015 | mWindowAttributes.packageName = mBasePackageName; |
| 1016 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1017 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1018 | |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1019 | if (mWindowAttributes.preservePreviousSurfaceInsets) { |
| 1020 | // Restore old surface insets. |
| 1021 | mWindowAttributes.surfaceInsets.set( |
| 1022 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
| 1023 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Robert Carr | 1bccabf | 2016-04-28 13:27:08 -0700 | [diff] [blame] | 1024 | } else if (mWindowAttributes.surfaceInsets.left != oldInsetLeft |
| 1025 | || mWindowAttributes.surfaceInsets.top != oldInsetTop |
| 1026 | || mWindowAttributes.surfaceInsets.right != oldInsetRight |
| 1027 | || mWindowAttributes.surfaceInsets.bottom != oldInsetBottom) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1028 | mNeedsRendererSetup = true; |
Wale Ogunwale | 246c209 | 2016-04-07 14:12:44 -0700 | [diff] [blame] | 1029 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1030 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1031 | applyKeepScreenOnFlag(mWindowAttributes); |
| 1032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | if (newView) { |
| 1034 | mSoftInputMode = attrs.softInputMode; |
| 1035 | requestLayout(); |
| 1036 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1037 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1038 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1039 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1040 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 1041 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 1042 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1043 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1044 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | mWindowAttributesChanged = true; |
| 1047 | scheduleTraversals(); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | void handleAppVisibility(boolean visible) { |
| 1052 | if (mAppVisible != visible) { |
| 1053 | mAppVisible = visible; |
| 1054 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 1055 | if (!mAppVisible) { |
| 1056 | WindowManagerGlobal.trimForeground(); |
| 1057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | void handleGetNewSurface() { |
| 1062 | mNewSurfaceNeeded = true; |
| 1063 | mFullRedrawNeeded = true; |
| 1064 | scheduleTraversals(); |
| 1065 | } |
| 1066 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1067 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 1068 | @Override |
| 1069 | public void onDisplayChanged(int displayId) { |
| 1070 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 1071 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 1072 | final int newDisplayState = mDisplay.getState(); |
| 1073 | if (oldDisplayState != newDisplayState) { |
| 1074 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1075 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1076 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 1077 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 1078 | final int newScreenState = toViewScreenState(newDisplayState); |
| 1079 | if (oldScreenState != newScreenState) { |
| 1080 | mView.dispatchScreenStateChanged(newScreenState); |
| 1081 | } |
| 1082 | if (oldDisplayState == Display.STATE_OFF) { |
| 1083 | // Draw was suppressed so we need to for it to happen here. |
| 1084 | mFullRedrawNeeded = true; |
| 1085 | scheduleTraversals(); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 1089 | } |
| 1090 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 1091 | |
| 1092 | @Override |
| 1093 | public void onDisplayRemoved(int displayId) { |
| 1094 | } |
| 1095 | |
| 1096 | @Override |
| 1097 | public void onDisplayAdded(int displayId) { |
| 1098 | } |
| 1099 | |
| 1100 | private int toViewScreenState(int displayState) { |
| 1101 | return displayState == Display.STATE_OFF ? |
| 1102 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 1103 | } |
| 1104 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 1105 | |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1106 | /** |
| 1107 | * Notify about move to a different display. |
| 1108 | * @param displayId The id of the display where this view root is moved to. |
| 1109 | * |
| 1110 | * @hide |
| 1111 | */ |
| 1112 | public void onMovedToDisplay(int displayId) { |
| 1113 | if (mDisplay.getDisplayId() == displayId) { |
| 1114 | return; |
| 1115 | } |
| 1116 | |
| 1117 | // Get new instance of display based on current display adjustments. It may be updated later |
| 1118 | // if moving between the displays also involved a configuration change. |
Bryce Lee | 609bf65 | 2017-02-09 16:50:13 -0800 | [diff] [blame] | 1119 | mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(displayId, |
| 1120 | mView.getResources()); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 1121 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 1122 | // Internal state updated, now notify the view hierarchy. |
| 1123 | mView.dispatchMovedToDisplay(mDisplay); |
| 1124 | } |
| 1125 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1126 | void pokeDrawLockIfNeeded() { |
| 1127 | final int displayState = mAttachInfo.mDisplayState; |
| 1128 | if (mView != null && mAdded && mTraversalScheduled |
| 1129 | && (displayState == Display.STATE_DOZE |
| 1130 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 1131 | try { |
| 1132 | mWindowSession.pokeDrawLock(mWindow); |
| 1133 | } catch (RemoteException ex) { |
| 1134 | // System server died, oh well. |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1139 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1140 | public void requestFitSystemWindows() { |
| 1141 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1142 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1143 | scheduleTraversals(); |
| 1144 | } |
| 1145 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1146 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 1148 | if (!mHandlingLayoutInLayoutRequest) { |
| 1149 | checkThread(); |
| 1150 | mLayoutRequested = true; |
| 1151 | scheduleTraversals(); |
| 1152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | } |
| 1154 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1155 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1156 | public boolean isLayoutRequested() { |
| 1157 | return mLayoutRequested; |
| 1158 | } |
| 1159 | |
Chris Craik | 9de95db | 2017-01-18 17:59:23 -0800 | [diff] [blame] | 1160 | @Override |
| 1161 | public void onDescendantInvalidated(@NonNull View child, @NonNull View descendant) { |
| 1162 | if ((descendant.mPrivateFlags & PFLAG_DRAW_ANIMATION) != 0) { |
| 1163 | mIsAnimating = true; |
| 1164 | } |
| 1165 | invalidate(); |
| 1166 | } |
| 1167 | |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1168 | void invalidate() { |
| 1169 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 1170 | if (!mWillDrawSoon) { |
| 1171 | scheduleTraversals(); |
| 1172 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1175 | void invalidateWorld(View view) { |
| 1176 | view.invalidate(); |
| 1177 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 1178 | ViewGroup parent = (ViewGroup) view; |
| 1179 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1180 | invalidateWorld(parent.getChildAt(i)); |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1185 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1187 | invalidateChildInParent(null, dirty); |
| 1188 | } |
| 1189 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1190 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1191 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1193 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1194 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1195 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1196 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1197 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1198 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1199 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1200 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1201 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1202 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1204 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1205 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1206 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1207 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1208 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1209 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1210 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1211 | if (mAttachInfo.mScalingRequired) { |
| 1212 | dirty.inset(-1, -1); |
| 1213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1215 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1216 | invalidateRectOnScreen(dirty); |
| 1217 | |
| 1218 | return null; |
| 1219 | } |
| 1220 | |
| 1221 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1222 | final Rect localDirty = mDirty; |
| 1223 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1224 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1225 | mAttachInfo.mIgnoreDirtyState = true; |
| 1226 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1227 | |
| 1228 | // Add the new dirty rect to the current one |
| 1229 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1230 | // Intersect with the bounds of the window to skip |
| 1231 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1232 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1233 | final boolean intersected = localDirty.intersect(0, 0, |
| 1234 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1235 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1236 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1238 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1239 | scheduleTraversals(); |
| 1240 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1243 | public void setIsAmbientMode(boolean ambient) { |
| 1244 | mIsAmbientMode = ambient; |
| 1245 | } |
| 1246 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1247 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1248 | if (mStopped != stopped) { |
| 1249 | mStopped = stopped; |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1250 | final ThreadedRenderer renderer = mAttachInfo.mThreadedRenderer; |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 1251 | if (renderer != null) { |
| 1252 | if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle() + " set to " + mStopped); |
| 1253 | renderer.setStopped(mStopped); |
| 1254 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1255 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1256 | scheduleTraversals(); |
John Reck | d9b1607 | 2016-02-23 10:35:19 -0800 | [diff] [blame] | 1257 | } else { |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 1258 | if (renderer != null) { |
| 1259 | renderer.destroyHardwareResources(mView); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1260 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1265 | /** |
| 1266 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1267 | * through to allow quick reversal of the Activity Transition. |
| 1268 | * |
| 1269 | * @param paused true to pause, false to resume. |
| 1270 | */ |
| 1271 | public void setPausedForTransition(boolean paused) { |
| 1272 | mPausedForTransition = paused; |
| 1273 | } |
| 1274 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1275 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1276 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | return null; |
| 1278 | } |
| 1279 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1280 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1281 | public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | if (child != mView) { |
| 1283 | throw new RuntimeException("child is not mine, honest!"); |
| 1284 | } |
| 1285 | // Note: don't apply scroll offset, because we want to know its |
| 1286 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1287 | return r.intersect(0, 0, mWidth, mHeight); |
| 1288 | } |
| 1289 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1290 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | public void bringChildToFront(View child) { |
| 1292 | } |
| 1293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | int getHostVisibility() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1295 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1297 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1298 | /** |
| 1299 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1300 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1301 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1302 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1303 | * animations are started (because those animations may side-effect properties that layout |
| 1304 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1305 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1306 | * |
| 1307 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1308 | * |
| 1309 | * @hide |
| 1310 | */ |
| 1311 | public void requestTransitionStart(LayoutTransition transition) { |
| 1312 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1313 | if (mPendingTransitions == null) { |
| 1314 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1315 | } |
| 1316 | mPendingTransitions.add(transition); |
| 1317 | } |
| 1318 | } |
| 1319 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1320 | /** |
| 1321 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1322 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1323 | * this knowledge to adjust the scheduling of off-thread animations |
| 1324 | */ |
| 1325 | void notifyRendererOfFramePending() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1326 | if (mAttachInfo.mThreadedRenderer != null) { |
| 1327 | mAttachInfo.mThreadedRenderer.notifyFramePending(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1331 | void scheduleTraversals() { |
| 1332 | if (!mTraversalScheduled) { |
| 1333 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1334 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1335 | mChoreographer.postCallback( |
| 1336 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1337 | if (!mUnbufferedInputDispatch) { |
| 1338 | scheduleConsumeBatchedInput(); |
| 1339 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1340 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1341 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1342 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1343 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1344 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1345 | void unscheduleTraversals() { |
| 1346 | if (mTraversalScheduled) { |
| 1347 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1348 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1349 | mChoreographer.removeCallbacks( |
| 1350 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | void doTraversal() { |
| 1355 | if (mTraversalScheduled) { |
| 1356 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1357 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1358 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1359 | if (mProfile) { |
| 1360 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1361 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1362 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1363 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1364 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1365 | if (mProfile) { |
| 1366 | Debug.stopMethodTracing(); |
| 1367 | mProfile = false; |
| 1368 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1372 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1373 | // Update window's global keep screen on flag: if a view has requested |
| 1374 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1375 | // set to whatever the client last requested for the global state. |
| 1376 | if (mAttachInfo.mKeepScreenOn) { |
| 1377 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1378 | } else { |
| 1379 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1380 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1381 | } |
| 1382 | } |
| 1383 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1384 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1385 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1386 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1387 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1388 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1389 | mAttachInfo.mKeepScreenOn = false; |
| 1390 | mAttachInfo.mSystemUiVisibility = 0; |
| 1391 | mAttachInfo.mHasSystemUiListeners = false; |
| 1392 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1393 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1394 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1395 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1396 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1397 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1398 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1399 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1400 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1401 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1402 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1403 | return true; |
| 1404 | } |
| 1405 | } |
| 1406 | return false; |
| 1407 | } |
| 1408 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1409 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1410 | int vis = 0; |
| 1411 | // Translucent decor window flags imply stable system ui visibility. |
| 1412 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1413 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1414 | } |
| 1415 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1416 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1417 | } |
| 1418 | return vis; |
| 1419 | } |
| 1420 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1421 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1422 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1423 | int childWidthMeasureSpec; |
| 1424 | int childHeightMeasureSpec; |
| 1425 | boolean windowSizeMayChange = false; |
| 1426 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1427 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1428 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1429 | + "x" + desiredWindowHeight + "..."); |
| 1430 | |
| 1431 | boolean goodMeasure = false; |
| 1432 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1433 | // On large screens, we don't want to allow dialogs to just |
| 1434 | // stretch to fill the entire width of the screen to display |
| 1435 | // one line of text. First try doing the layout at a smaller |
| 1436 | // size to see if it will fit. |
| 1437 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1438 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1439 | int baseSize = 0; |
| 1440 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1441 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1442 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1443 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1444 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1445 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1446 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1447 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1448 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1449 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1450 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1451 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1452 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1453 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1454 | goodMeasure = true; |
| 1455 | } else { |
| 1456 | // Didn't fit in that size... try expanding a bit. |
| 1457 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1458 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1459 | + baseSize); |
| 1460 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1461 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1462 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1463 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1464 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1465 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1466 | goodMeasure = true; |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | if (!goodMeasure) { |
| 1473 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1474 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1475 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1476 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1477 | windowSizeMayChange = true; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | if (DBG) { |
| 1482 | System.out.println("======================================"); |
| 1483 | System.out.println("performTraversals -- after measure"); |
| 1484 | host.debug(); |
| 1485 | } |
| 1486 | |
| 1487 | return windowSizeMayChange; |
| 1488 | } |
| 1489 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1490 | /** |
| 1491 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1492 | * on-screen coordinates. |
| 1493 | * |
| 1494 | * @param m input matrix to modify |
| 1495 | */ |
| 1496 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1497 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | /** |
| 1501 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1502 | * view-local coordinates. |
| 1503 | * |
| 1504 | * @param m input matrix to modify |
| 1505 | */ |
| 1506 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1507 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1508 | } |
| 1509 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1510 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1511 | if (mLastWindowInsets == null || forceConstruct) { |
| 1512 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1513 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
| 1514 | Rect contentInsets = mDispatchContentInsets; |
| 1515 | Rect stableInsets = mDispatchStableInsets; |
| 1516 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1517 | // immediately use pending insets. |
| 1518 | if (!forceConstruct |
| 1519 | && (!mPendingContentInsets.equals(contentInsets) || |
| 1520 | !mPendingStableInsets.equals(stableInsets))) { |
| 1521 | contentInsets = mPendingContentInsets; |
| 1522 | stableInsets = mPendingStableInsets; |
| 1523 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1524 | Rect outsets = mAttachInfo.mOutsets; |
| 1525 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1526 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1527 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1528 | contentInsets.bottom + outsets.bottom); |
| 1529 | } |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1530 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1531 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1532 | mContext.getResources().getConfiguration().isScreenRound(), |
| 1533 | mAttachInfo.mAlwaysConsumeNavBar); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1534 | } |
| 1535 | return mLastWindowInsets; |
| 1536 | } |
| 1537 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1538 | void dispatchApplyInsets(View host) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1539 | host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1542 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1543 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1544 | || lp.type == TYPE_INPUT_METHOD |
| 1545 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1546 | } |
| 1547 | |
| 1548 | private int dipToPx(int dip) { |
| 1549 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1550 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1551 | } |
| 1552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | private void performTraversals() { |
| 1554 | // cache mView since it is used so much below... |
| 1555 | final View host = mView; |
| 1556 | |
| 1557 | if (DBG) { |
| 1558 | System.out.println("======================================"); |
| 1559 | System.out.println("performTraversals"); |
| 1560 | host.debug(); |
| 1561 | } |
| 1562 | |
| 1563 | if (host == null || !mAdded) |
| 1564 | return; |
| 1565 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1566 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1568 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1570 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1572 | |
| 1573 | int desiredWindowWidth; |
| 1574 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1576 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1577 | final boolean viewVisibilityChanged = !mFirst |
| 1578 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded); |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1579 | final boolean viewUserVisibilityChanged = !mFirst && |
| 1580 | ((mViewVisibility == View.VISIBLE) != (viewVisibility == View.VISIBLE)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | |
| 1582 | WindowManager.LayoutParams params = null; |
| 1583 | if (mWindowAttributesChanged) { |
| 1584 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1585 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | params = lp; |
| 1587 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 1588 | CompatibilityInfo compatibilityInfo = |
| 1589 | mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1590 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1591 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1592 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1593 | mLayoutRequested = true; |
| 1594 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1595 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1596 | mLastInCompatMode = false; |
| 1597 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1598 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1599 | mLastInCompatMode = true; |
| 1600 | } |
| 1601 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1602 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1603 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1604 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1605 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1607 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | mLayoutRequested = true; |
| 1609 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1610 | final Configuration config = mContext.getResources().getConfiguration(); |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1611 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1612 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1613 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1614 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1615 | desiredWindowWidth = size.x; |
| 1616 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1617 | } else { |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1618 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1619 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1622 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1623 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1624 | // However, windows are now always 32 bits by default, so choose 32 bits |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1625 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1626 | mAttachInfo.mHasWindowFocus = false; |
| 1627 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1628 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1629 | mLastConfigurationFromResources.setTo(config); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1630 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1631 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1632 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1633 | host.setLayoutDirection(config.getLayoutDirection()); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1634 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1635 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1636 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1637 | dispatchApplyInsets(host); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1638 | //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1641 | desiredWindowWidth = frame.width(); |
| 1642 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1644 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1645 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1647 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | if (viewVisibilityChanged) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1652 | mAttachInfo.mWindowVisibility = viewVisibility; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | host.dispatchWindowVisibilityChanged(viewVisibility); |
Adam Powell | 06f9eb8 | 2016-08-24 17:09:01 -0700 | [diff] [blame] | 1654 | if (viewUserVisibilityChanged) { |
Adam Powell | 64e1ba4 | 2016-08-22 09:09:44 -0700 | [diff] [blame] | 1655 | host.dispatchVisibilityAggregated(viewVisibility == View.VISIBLE); |
| 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1658 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1659 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | } |
| 1661 | if (viewVisibility == View.GONE) { |
| 1662 | // After making a window gone, we will count it as being |
| 1663 | // shown for the first time the next time it gets focus. |
| 1664 | mHasHadWindowFocus = false; |
| 1665 | } |
| 1666 | } |
| 1667 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1668 | // Non-visible windows can't hold accessibility focus. |
| 1669 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1670 | host.clearAccessibilityFocus(); |
| 1671 | } |
| 1672 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1673 | // Execute enqueued actions on every traversal in case a detached view enqueued an action |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1674 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1677 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1678 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1679 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1680 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1681 | final Resources res = mView.getContext().getResources(); |
| 1682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | // make sure touch mode code executes by setting cached value |
| 1685 | // to opposite of the added touch mode. |
| 1686 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1687 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1689 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1690 | insetsChanged = true; |
| 1691 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1692 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1695 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1696 | insetsChanged = true; |
| 1697 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1698 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1700 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | + mAttachInfo.mVisibleInsets); |
| 1702 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1703 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1704 | insetsChanged = true; |
| 1705 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1706 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1707 | insetsChanged = true; |
| 1708 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1709 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1710 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1711 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1712 | |
| 1713 | if (shouldUseDisplaySize(lp)) { |
| 1714 | // NOTE -- system code, won't try to do compat mode. |
| 1715 | Point size = new Point(); |
| 1716 | mDisplay.getRealSize(size); |
| 1717 | desiredWindowWidth = size.x; |
| 1718 | desiredWindowHeight = size.y; |
| 1719 | } else { |
| 1720 | Configuration config = res.getConfiguration(); |
| 1721 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1722 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1723 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1728 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1729 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1732 | if (collectViewAttributes()) { |
| 1733 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1734 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1735 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1736 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1737 | params = lp; |
| 1738 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1740 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1741 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | int resizeMode = mSoftInputMode & |
| 1743 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1744 | // If we are in auto resize mode, then we need to determine |
| 1745 | // what mode to use now. |
| 1746 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1747 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1748 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1749 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1751 | } |
| 1752 | } |
| 1753 | if (resizeMode == 0) { |
| 1754 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1755 | } |
| 1756 | if ((lp.softInputMode & |
| 1757 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1758 | lp.softInputMode = (lp.softInputMode & |
| 1759 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1760 | resizeMode; |
| 1761 | params = lp; |
| 1762 | } |
| 1763 | } |
| 1764 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1765 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1766 | if (params != null) { |
| 1767 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1768 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1769 | params.format = PixelFormat.TRANSLUCENT; |
| 1770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1772 | mAttachInfo.mOverscanRequested = (params.flags |
| 1773 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1774 | } |
| 1775 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1776 | if (mApplyInsetsRequested) { |
| 1777 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1778 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1779 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1780 | if (mLayoutRequested) { |
| 1781 | // Short-circuit catching a new layout request here, so |
| 1782 | // we don't need to go through two layout passes when things |
| 1783 | // change due to fitting system windows, which can happen a lot. |
| 1784 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1785 | mView.getContext().getResources(), |
| 1786 | desiredWindowWidth, desiredWindowHeight); |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | if (layoutRequested) { |
| 1791 | // Clear this now, so that if anything requests a layout in the |
| 1792 | // rest of this function we will catch it and re-run a full |
| 1793 | // layout pass. |
| 1794 | mLayoutRequested = false; |
| 1795 | } |
| 1796 | |
| 1797 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1798 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1799 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1800 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1801 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1802 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1803 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1804 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1805 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1806 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1807 | // bounds. |
| 1808 | windowShouldResize |= mActivityRelaunched; |
| 1809 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1810 | // Determine whether to compute insets. |
| 1811 | // If there are no inset listeners remaining then we may still need to compute |
| 1812 | // insets in case the old insets were non-empty and must be reset. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1814 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1815 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1816 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | boolean insetsPending = false; |
| 1818 | int relayoutResult = 0; |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 1819 | boolean updatedConfiguration = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1820 | |
Robert Carr | b259485 | 2016-04-25 16:21:13 -0700 | [diff] [blame] | 1821 | final int surfaceGenerationId = mSurface.getGenerationId(); |
| 1822 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1823 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1824 | final boolean windowRelayoutWasForced = mForceNextWindowRelayout; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1825 | if (mFirst || windowShouldResize || insetsChanged || |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1826 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
| 1827 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1829 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1830 | // If this window is giving internal insets to the window |
| 1831 | // manager, and it is being added or changing its visibility, |
| 1832 | // then we want to first give the window manager "fake" |
| 1833 | // insets to cause it to effectively ignore the content of |
| 1834 | // the window during layout. This avoids it briefly causing |
| 1835 | // other windows to resize/move based on the raw frame of the |
| 1836 | // window, waiting until we can finish laying out this window |
| 1837 | // and get back to the window manager with the ultimately |
| 1838 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1839 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | } |
| 1841 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1842 | if (mSurfaceHolder != null) { |
| 1843 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1844 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1845 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1846 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1847 | boolean hwInitialized = false; |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 1848 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1849 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1852 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1853 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1854 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1855 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1856 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1857 | if (mAttachInfo.mThreadedRenderer != null) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1858 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 1859 | // happens in WindowManager service, we need to be defensive here |
| 1860 | // and stop using the surface in case it gets destroyed. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1861 | if (mAttachInfo.mThreadedRenderer.pauseSurface(mSurface)) { |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 1862 | // Animations were running so we need to push a frame |
| 1863 | // to resume them |
| 1864 | mDirty.set(0, 0, mWidth, mHeight); |
| 1865 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1866 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1867 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1868 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 1869 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1870 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1871 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | + " content=" + mPendingContentInsets.toShortString() |
| 1873 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1874 | + " visible=" + mPendingStableInsets.toShortString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 1875 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1877 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1878 | final Configuration pendingMergedConfig = |
| 1879 | mPendingMergedConfiguration.getMergedConfiguration(); |
| 1880 | if (pendingMergedConfig.seq != 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1881 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 1882 | + pendingMergedConfig); |
| 1883 | performConfigurationChange(mPendingMergedConfiguration, !mFirst, |
| 1884 | INVALID_DISPLAY /* same display */); |
| 1885 | pendingMergedConfig.seq = 0; |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 1886 | updatedConfiguration = true; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1887 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1888 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1889 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 1890 | mAttachInfo.mOverscanInsets); |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 1891 | contentInsetsChanged = !mPendingContentInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1893 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1895 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 1896 | mAttachInfo.mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1897 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1898 | final boolean surfaceSizeChanged = (relayoutResult |
| 1899 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1900 | final boolean alwaysConsumeNavBarChanged = |
| 1901 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1902 | if (contentInsetsChanged) { |
| 1903 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1904 | if (DEBUG_LAYOUT) Log.v(mTag, "Content insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | + mAttachInfo.mContentInsets); |
| 1906 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1907 | if (overscanInsetsChanged) { |
| 1908 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1909 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1910 | + mAttachInfo.mOverscanInsets); |
| 1911 | // Need to relayout with content insets. |
| 1912 | contentInsetsChanged = true; |
| 1913 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1914 | if (stableInsetsChanged) { |
| 1915 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1916 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1917 | + mAttachInfo.mStableInsets); |
| 1918 | // Need to relayout with content insets. |
| 1919 | contentInsetsChanged = true; |
| 1920 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1921 | if (alwaysConsumeNavBarChanged) { |
| 1922 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 1923 | contentInsetsChanged = true; |
| 1924 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1925 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1926 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1927 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 1928 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1929 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1930 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1931 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1932 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1933 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1934 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1935 | if (visibleInsetsChanged) { |
| 1936 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1937 | if (DEBUG_LAYOUT) Log.v(mTag, "Visible insets changing to: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | + mAttachInfo.mVisibleInsets); |
| 1939 | } |
| 1940 | |
| 1941 | if (!hadSurface) { |
| 1942 | if (mSurface.isValid()) { |
| 1943 | // If we are creating a new surface, then we need to |
| 1944 | // completely redraw it. Also, when we get to the |
| 1945 | // point of drawing it we will hold off and schedule |
| 1946 | // a new traversal instead. This is so we can tell the |
| 1947 | // window manager about all of the windows being displayed |
| 1948 | // before actually drawing them, so it can display then |
| 1949 | // all at once. |
| 1950 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1951 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 1952 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1953 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1954 | // Only initialize up-front if transparent regions are not |
| 1955 | // requested, otherwise defer to see if the entire window |
| 1956 | // will be transparent |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1957 | if (mAttachInfo.mThreadedRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1958 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1959 | hwInitialized = mAttachInfo.mThreadedRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1960 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1961 | if (hwInitialized && (host.mPrivateFlags |
| 1962 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 1963 | // Don't pre-allocate if transparent regions |
| 1964 | // are requested as they may not be needed |
| 1965 | mSurface.allocateBuffers(); |
| 1966 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1967 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1968 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1969 | return; |
| 1970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | } else if (!mSurface.isValid()) { |
| 1974 | // If the surface has been removed, then reset the scroll |
| 1975 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 1976 | if (mLastScrolledFocus != null) { |
| 1977 | mLastScrolledFocus.clear(); |
| 1978 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1979 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 1980 | if (mView instanceof RootViewSurfaceTaker) { |
| 1981 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 1982 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | if (mScroller != null) { |
| 1984 | mScroller.abortAnimation(); |
| 1985 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1986 | // Our surface is gone |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1987 | if (mAttachInfo.mThreadedRenderer != null && |
| 1988 | mAttachInfo.mThreadedRenderer.isEnabled()) { |
| 1989 | mAttachInfo.mThreadedRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1990 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1991 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
Andrii Kulian | b2e3780 | 2017-01-11 00:36:44 -0800 | [diff] [blame] | 1992 | || surfaceSizeChanged || windowRelayoutWasForced) |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1993 | && mSurfaceHolder == null |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 1994 | && mAttachInfo.mThreadedRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1995 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1996 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1997 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 1998 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 1999 | // generation id), or WindowManager changed the surface size. The latter is |
| 2000 | // because on some chips, changing the consumer side's BufferQueue size may |
| 2001 | // not take effect immediately unless we create a new EGLSurface. |
| 2002 | // Note that frame size change doesn't always imply surface size change (eg. |
| 2003 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 2004 | // flag from WindowManager. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2005 | mAttachInfo.mThreadedRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2006 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2007 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2008 | return; |
| 2009 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2011 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2012 | final boolean freeformResizing = (relayoutResult |
| 2013 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 2014 | final boolean dockedResizing = (relayoutResult |
| 2015 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 2016 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2017 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2018 | if (dragResizing) { |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2019 | mResizeMode = freeformResizing |
| 2020 | ? RESIZE_MODE_FREEFORM |
| 2021 | : RESIZE_MODE_DOCKED_DIVIDER; |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2022 | startDragResizing(mPendingBackDropFrame, |
| 2023 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 2024 | mPendingStableInsets, mResizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2025 | } else { |
| 2026 | // We shouldn't come here, but if we come we should end the resize. |
| 2027 | endDragResizing(); |
| 2028 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2029 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 2030 | if (!USE_MT_RENDERER) { |
| 2031 | if (dragResizing) { |
| 2032 | mCanvasOffsetX = mWinFrame.left; |
| 2033 | mCanvasOffsetY = mWinFrame.top; |
| 2034 | } else { |
| 2035 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 2036 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2037 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2038 | } catch (RemoteException e) { |
| 2039 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 2040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2042 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2044 | mAttachInfo.mWindowLeft = frame.left; |
| 2045 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | |
| 2047 | // !!FIXME!! This next section handles the case where we did not get the |
| 2048 | // window size we asked for. We should avoid this by getting a maximum size from |
| 2049 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2050 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 2051 | mWidth = frame.width(); |
| 2052 | mHeight = frame.height(); |
| 2053 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2055 | if (mSurfaceHolder != null) { |
| 2056 | // The app owns the surface; tell it about what is going on. |
| 2057 | if (mSurface.isValid()) { |
| 2058 | // XXX .copyFrom() doesn't work! |
| 2059 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 2060 | mSurfaceHolder.mSurface = mSurface; |
| 2061 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 2062 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2063 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2064 | if (mSurface.isValid()) { |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2065 | if (!hadSurface) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2066 | mSurfaceHolder.ungetCallbacks(); |
| 2067 | |
| 2068 | mIsCreating = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2069 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2070 | if (callbacks != null) { |
| 2071 | for (SurfaceHolder.Callback c : callbacks) { |
| 2072 | c.surfaceCreated(mSurfaceHolder); |
| 2073 | } |
| 2074 | } |
| 2075 | surfaceChanged = true; |
| 2076 | } |
John Reck | 208c47c | 2016-06-09 16:26:21 -0700 | [diff] [blame] | 2077 | if (surfaceChanged || surfaceGenerationId != mSurface.getGenerationId()) { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2078 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2079 | if (callbacks != null) { |
| 2080 | for (SurfaceHolder.Callback c : callbacks) { |
| 2081 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 2082 | mWidth, mHeight); |
| 2083 | } |
| 2084 | } |
| 2085 | } |
| 2086 | mIsCreating = false; |
| 2087 | } else if (hadSurface) { |
| 2088 | mSurfaceHolder.ungetCallbacks(); |
| 2089 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2090 | if (callbacks != null) { |
| 2091 | for (SurfaceHolder.Callback c : callbacks) { |
| 2092 | c.surfaceDestroyed(mSurfaceHolder); |
| 2093 | } |
| 2094 | } |
| 2095 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 2096 | try { |
| 2097 | mSurfaceHolder.mSurface = new Surface(); |
| 2098 | } finally { |
| 2099 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 2100 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2101 | } |
| 2102 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 2103 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2104 | final ThreadedRenderer threadedRenderer = mAttachInfo.mThreadedRenderer; |
| 2105 | if (threadedRenderer != null && threadedRenderer.isEnabled()) { |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2106 | if (hwInitialized |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2107 | || mWidth != threadedRenderer.getWidth() |
| 2108 | || mHeight != threadedRenderer.getHeight() |
| 2109 | || mNeedsRendererSetup) { |
| 2110 | threadedRenderer.setup(mWidth, mHeight, mAttachInfo, |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2111 | mWindowAttributes.surfaceInsets); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2112 | mNeedsRendererSetup = false; |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 2113 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2114 | } |
| 2115 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2116 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2117 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2118 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2119 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2120 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged || |
Chet Haase | d86fb2c | 2016-05-04 07:26:02 -0700 | [diff] [blame] | 2121 | updatedConfiguration) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2122 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 2123 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2124 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2125 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2126 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 2127 | + " mHeight=" + mHeight |
| 2128 | + " measuredHeight=" + host.getMeasuredHeight() |
Chong Zhang | 75eccbd | 2016-07-12 19:25:08 -0700 | [diff] [blame] | 2129 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2130 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2131 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2132 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2133 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2134 | // Implementation of weights from WindowManager.LayoutParams |
| 2135 | // We just grow the dimensions as needed and re-measure if |
| 2136 | // needs be |
| 2137 | int width = host.getMeasuredWidth(); |
| 2138 | int height = host.getMeasuredHeight(); |
| 2139 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2140 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2141 | if (lp.horizontalWeight > 0.0f) { |
| 2142 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 2143 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 2144 | MeasureSpec.EXACTLY); |
| 2145 | measureAgain = true; |
| 2146 | } |
| 2147 | if (lp.verticalWeight > 0.0f) { |
| 2148 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 2149 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 2150 | MeasureSpec.EXACTLY); |
| 2151 | measureAgain = true; |
| 2152 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2153 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2154 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2155 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2156 | "And hey let's measure once more: width=" + width |
| 2157 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2158 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 2159 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2160 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2161 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 2164 | } else { |
| 2165 | // Not the first pass and no window/insets/visibility change but the window |
| 2166 | // may have moved and we need check that and if so to update the left and right |
| 2167 | // in the attach info. We translate only the window frame since on window move |
| 2168 | // the window manager tells us only for the new frame but the insets are the |
| 2169 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2170 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | } |
| 2172 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 2173 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2175 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 2177 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2179 | // By this point all views have been sized and positioned |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2180 | // We can compute the transparent area |
| 2181 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2182 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | // start out transparent |
| 2184 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 2185 | host.getLocationInWindow(mTmpLocation); |
| 2186 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 2187 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2188 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2189 | |
| 2190 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2191 | if (mTranslator != null) { |
| 2192 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2193 | } |
| 2194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2196 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2197 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | // reconfigure window manager |
| 2199 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2200 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | } catch (RemoteException e) { |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | if (DBG) { |
| 2207 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2208 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | host.debug(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
| 2213 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2214 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2215 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2219 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2220 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2221 | insets.reset(); |
| 2222 | |
| 2223 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2224 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2225 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2226 | |
| 2227 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2229 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2230 | |
| 2231 | // Translate insets to screen coordinates if needed. |
| 2232 | final Rect contentInsets; |
| 2233 | final Rect visibleInsets; |
| 2234 | final Region touchableRegion; |
| 2235 | if (mTranslator != null) { |
| 2236 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2237 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2238 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2239 | } else { |
| 2240 | contentInsets = insets.contentInsets; |
| 2241 | visibleInsets = insets.visibleInsets; |
| 2242 | touchableRegion = insets.touchableRegion; |
| 2243 | } |
| 2244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2245 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2246 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2247 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2248 | } catch (RemoteException e) { |
| 2249 | } |
| 2250 | } |
| 2251 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2252 | |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 2253 | if (mFirst && sAlwaysAssignFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | // handle first focus request |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2255 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: mView.hasFocus()=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | + mView.hasFocus()); |
| 2257 | if (mView != null) { |
| 2258 | if (!mView.hasFocus()) { |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 2259 | mView.restoreDefaultFocus(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2260 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2261 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2263 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2264 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2269 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2270 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2271 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2272 | if (regainedFocus) { |
| 2273 | mLostWindowFocus = false; |
| 2274 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2275 | mLostWindowFocus = true; |
| 2276 | } |
| 2277 | |
| 2278 | if (changedVisibility || regainedFocus) { |
Phil Weaver | 532c799 | 2016-08-29 15:59:03 -0700 | [diff] [blame] | 2279 | // Toasts are presented as notifications - don't present them as windows as well |
| 2280 | boolean isToast = (mWindowAttributes == null) ? false |
| 2281 | : (mWindowAttributes.type == WindowManager.LayoutParams.TYPE_TOAST); |
| 2282 | if (!isToast) { |
| 2283 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2284 | } |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2285 | } |
| 2286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2287 | mFirst = false; |
| 2288 | mWillDrawSoon = false; |
| 2289 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2290 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2292 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2294 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | final boolean imTarget = WindowManager.LayoutParams |
| 2296 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2297 | if (imTarget != mLastWasImTarget) { |
| 2298 | mLastWasImTarget = imTarget; |
| 2299 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2300 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2301 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2302 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | mWindowAttributes.softInputMode, |
| 2304 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2305 | } |
| 2306 | } |
| 2307 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2308 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2309 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2310 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2311 | mReportNextDraw = true; |
| 2312 | } |
| 2313 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2314 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | |
Jorim Jaggi | 75c21ca | 2016-03-28 19:26:09 -0400 | [diff] [blame] | 2316 | if (!cancelDraw && !newSurface) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2317 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2318 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2319 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2320 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2321 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2322 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2323 | |
| 2324 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2326 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2327 | // Try again |
| 2328 | scheduleTraversals(); |
| 2329 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2330 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2331 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2332 | } |
| 2333 | mPendingTransitions.clear(); |
| 2334 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2336 | |
| 2337 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2340 | private void maybeHandleWindowMove(Rect frame) { |
| 2341 | |
| 2342 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2343 | // to how this is done for the insets. This is however incorrect since |
| 2344 | // the insets and the frame are translated. For example, the old frame |
| 2345 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2346 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2347 | // true since we are comparing a not translated value to a translated one. |
| 2348 | // This scenario is rare but we may want to fix that. |
| 2349 | |
| 2350 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2351 | || mAttachInfo.mWindowTop != frame.top; |
| 2352 | if (windowMoved) { |
| 2353 | if (mTranslator != null) { |
| 2354 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2355 | } |
| 2356 | mAttachInfo.mWindowLeft = frame.left; |
| 2357 | mAttachInfo.mWindowTop = frame.top; |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2358 | } |
| 2359 | if (windowMoved || mAttachInfo.mNeedsUpdateLightCenter) { |
| 2360 | // Update the light position for the new offsets. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2361 | if (mAttachInfo.mThreadedRenderer != null) { |
| 2362 | mAttachInfo.mThreadedRenderer.setLightCenter(mAttachInfo); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2363 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2364 | mAttachInfo.mNeedsUpdateLightCenter = false; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2365 | } |
| 2366 | } |
Teng-Hui Zhu | 2757128 | 2016-05-12 15:53:53 -0700 | [diff] [blame] | 2367 | |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2368 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2369 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2370 | try { |
| 2371 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2372 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2373 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2374 | Process.killProcess(Process.myPid()); |
| 2375 | } |
| 2376 | } catch (RemoteException ex) { |
| 2377 | } |
| 2378 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2379 | } |
| 2380 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2381 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
| 2382 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2383 | try { |
| 2384 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2385 | } finally { |
| 2386 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2387 | } |
| 2388 | } |
| 2389 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2390 | /** |
| 2391 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2392 | * is currently undergoing a layout pass. |
| 2393 | * |
| 2394 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2395 | */ |
| 2396 | boolean isInLayout() { |
| 2397 | return mInLayout; |
| 2398 | } |
| 2399 | |
| 2400 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2401 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2402 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2403 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2404 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2405 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2406 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2407 | * we check all of those views to see if any still have pending layout requests, which |
| 2408 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2409 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2410 | * to blank containers, and force a second request/measure/layout pass in this frame. If |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2411 | * more requestLayout() calls are received during that second layout pass, we post those |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2412 | * requests to the next frame to avoid possible infinite loops. |
| 2413 | * |
| 2414 | * <p>The return value from this method indicates whether the request should proceed |
| 2415 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2416 | * next frame (if it is a request during the second layout pass).</p> |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2417 | * |
| 2418 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2419 | * |
| 2420 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2421 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2422 | boolean requestLayoutDuringLayout(final View view) { |
| 2423 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2424 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2425 | return true; |
| 2426 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2427 | if (!mLayoutRequesters.contains(view)) { |
| 2428 | mLayoutRequesters.add(view); |
| 2429 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2430 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2431 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2432 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2433 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2434 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2435 | // Don't let the request proceed during the second layout pass. |
| 2436 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2437 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2441 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2442 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2443 | mLayoutRequested = false; |
| 2444 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2445 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2446 | |
| 2447 | final View host = mView; |
| 2448 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2449 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2450 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2451 | } |
| 2452 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2453 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2454 | try { |
| 2455 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2456 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2457 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2458 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2459 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2460 | // requestLayout() was called during layout. |
| 2461 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2462 | // If some requests are still pending, then we need to clear those flags and do |
| 2463 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2464 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2465 | false); |
| 2466 | if (validLayoutRequesters != null) { |
| 2467 | // Set this flag to indicate that any further requests are happening during |
| 2468 | // the second pass, which may result in posting those requests to the next |
| 2469 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2470 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2471 | |
| 2472 | // Process fresh layout requests, then measure and layout |
| 2473 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2474 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2475 | final View view = validLayoutRequesters.get(i); |
| 2476 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2477 | " during layout: running second layout pass"); |
| 2478 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2479 | } |
| 2480 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2481 | desiredWindowWidth, desiredWindowHeight); |
| 2482 | mInLayout = true; |
| 2483 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2484 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2485 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2486 | |
| 2487 | // Check the valid requests again, this time without checking/clearing the |
| 2488 | // layout flags, since requests happening during the second pass get noop'd |
| 2489 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2490 | if (validLayoutRequesters != null) { |
| 2491 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2492 | // Post second-pass requests to the next frame |
| 2493 | getRunQueue().post(new Runnable() { |
| 2494 | @Override |
| 2495 | public void run() { |
| 2496 | int numValidRequests = finalRequesters.size(); |
| 2497 | for (int i = 0; i < numValidRequests; ++i) { |
| 2498 | final View view = finalRequesters.get(i); |
| 2499 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2500 | " during second layout pass: posting in next frame"); |
| 2501 | view.requestLayout(); |
| 2502 | } |
| 2503 | } |
| 2504 | }); |
| 2505 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2506 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2507 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2508 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2509 | } finally { |
| 2510 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2511 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2512 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2515 | /** |
| 2516 | * This method is called during layout when there have been calls to requestLayout() during |
| 2517 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2518 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2519 | * handled (as is usually the case with ListView children). |
| 2520 | * |
| 2521 | * @param layoutRequesters The list of views that requested layout during layout |
| 2522 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2523 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2524 | * @return A list of the actual views that still need to be laid out. |
| 2525 | */ |
| 2526 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2527 | boolean secondLayoutRequests) { |
| 2528 | |
| 2529 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2530 | ArrayList<View> validLayoutRequesters = null; |
| 2531 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2532 | View view = layoutRequesters.get(i); |
| 2533 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2534 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2535 | View.PFLAG_FORCE_LAYOUT)) { |
| 2536 | boolean gone = false; |
| 2537 | View parent = view; |
| 2538 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2539 | while (parent != null) { |
| 2540 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2541 | gone = true; |
| 2542 | break; |
| 2543 | } |
| 2544 | if (parent.mParent instanceof View) { |
| 2545 | parent = (View) parent.mParent; |
| 2546 | } else { |
| 2547 | parent = null; |
| 2548 | } |
| 2549 | } |
| 2550 | if (!gone) { |
| 2551 | if (validLayoutRequesters == null) { |
| 2552 | validLayoutRequesters = new ArrayList<View>(); |
| 2553 | } |
| 2554 | validLayoutRequesters.add(view); |
| 2555 | } |
| 2556 | } |
| 2557 | } |
| 2558 | if (!secondLayoutRequests) { |
| 2559 | // If we're checking the layout flags, then we need to clean them up also |
| 2560 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2561 | View view = layoutRequesters.get(i); |
| 2562 | while (view != null && |
| 2563 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2564 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2565 | if (view.mParent instanceof View) { |
| 2566 | view = (View) view.mParent; |
| 2567 | } else { |
| 2568 | view = null; |
| 2569 | } |
| 2570 | } |
| 2571 | } |
| 2572 | } |
| 2573 | layoutRequesters.clear(); |
| 2574 | return validLayoutRequesters; |
| 2575 | } |
| 2576 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2577 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | public void requestTransparentRegion(View child) { |
| 2579 | // the test below should not fail unless someone is messing with us |
| 2580 | checkThread(); |
| 2581 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2582 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2583 | // Need to make sure we re-evaluate the window attributes next |
| 2584 | // time around, to ensure the window has the correct format. |
| 2585 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2586 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2587 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | } |
| 2589 | } |
| 2590 | |
| 2591 | /** |
| 2592 | * Figures out the measure spec for the root view in a window based on it's |
| 2593 | * layout params. |
| 2594 | * |
| 2595 | * @param windowSize |
| 2596 | * The available width or height of the window |
| 2597 | * |
| 2598 | * @param rootDimension |
| 2599 | * The layout params for one dimension (width or height) of the |
| 2600 | * window. |
| 2601 | * |
| 2602 | * @return The measure spec to use to measure the root view. |
| 2603 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2604 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | int measureSpec; |
| 2606 | switch (rootDimension) { |
| 2607 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2608 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | // Window can't resize. Force root view to be windowSize. |
| 2610 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2611 | break; |
| 2612 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2613 | // Window can resize. Set max size for root view. |
| 2614 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2615 | break; |
| 2616 | default: |
| 2617 | // Window wants to be an exact size. Force root view to be that size. |
| 2618 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2619 | break; |
| 2620 | } |
| 2621 | return measureSpec; |
| 2622 | } |
| 2623 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2624 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2625 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2626 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2627 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2628 | public void onPreDraw(DisplayListCanvas canvas) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2629 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2630 | } |
| 2631 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2632 | @Override |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2633 | public void onPostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2634 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 2635 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 2636 | mWindowCallbacks.get(i).onPostDraw(canvas); |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2637 | } |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2638 | } |
| 2639 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2640 | /** |
| 2641 | * @hide |
| 2642 | */ |
| 2643 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 2644 | view.mRenderNode.output(); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2645 | if (mAttachInfo.mThreadedRenderer != null) { |
| 2646 | ((ThreadedRenderer)mAttachInfo.mThreadedRenderer).serializeDisplayListTree(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 2647 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | /** |
| 2651 | * @see #PROPERTY_PROFILE_RENDERING |
| 2652 | */ |
| 2653 | private void profileRendering(boolean enabled) { |
| 2654 | if (mProfileRendering) { |
| 2655 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2656 | |
| 2657 | if (mRenderProfiler != null) { |
| 2658 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 2659 | } |
| 2660 | if (mRenderProfilingEnabled) { |
| 2661 | if (mRenderProfiler == null) { |
| 2662 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 2663 | @Override |
| 2664 | public void doFrame(long frameTimeNanos) { |
| 2665 | mDirty.set(0, 0, mWidth, mHeight); |
| 2666 | scheduleTraversals(); |
| 2667 | if (mRenderProfilingEnabled) { |
| 2668 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 2669 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2670 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2671 | }; |
| 2672 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2673 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2674 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2675 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | } |
| 2679 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2680 | /** |
| 2681 | * Called from draw() when DEBUG_FPS is enabled |
| 2682 | */ |
| 2683 | private void trackFPS() { |
| 2684 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 2685 | // because it down not account for the intervening idle time |
| 2686 | long nowTime = System.currentTimeMillis(); |
| 2687 | if (mFpsStartTime < 0) { |
| 2688 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 2689 | mFpsNumFrames = 0; |
| 2690 | } else { |
| 2691 | ++mFpsNumFrames; |
| 2692 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 2693 | long frameTime = nowTime - mFpsPrevTime; |
| 2694 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2695 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2696 | mFpsPrevTime = nowTime; |
| 2697 | if (totalTime > 1000) { |
| 2698 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2699 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2700 | mFpsStartTime = nowTime; |
| 2701 | mFpsNumFrames = 0; |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 2706 | /** |
| 2707 | * A count of the number of calls to pendingDrawFinished we |
| 2708 | * require to notify the WM drawing is complete. |
| 2709 | * |
| 2710 | * This starts at 1, for the ViewRootImpl surface itself. |
| 2711 | * Subsurfaces may debt the value with drawPending. |
| 2712 | */ |
| 2713 | int mDrawsNeededToReport = 1; |
| 2714 | |
| 2715 | /** |
| 2716 | * Delay notifying WM of draw finished until |
| 2717 | * a balanced call to pendingDrawFinished. |
| 2718 | */ |
| 2719 | void drawPending() { |
| 2720 | mDrawsNeededToReport++; |
| 2721 | } |
| 2722 | |
| 2723 | void pendingDrawFinished() { |
| 2724 | if (mDrawsNeededToReport == 0) { |
| 2725 | throw new RuntimeException("Unbalanced drawPending/pendingDrawFinished calls"); |
| 2726 | } |
| 2727 | mDrawsNeededToReport--; |
| 2728 | if (mDrawsNeededToReport == 0) { |
| 2729 | reportDrawFinished(); |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | private void postDrawFinished() { |
| 2734 | mHandler.sendEmptyMessage(MSG_DRAW_FINISHED); |
| 2735 | } |
| 2736 | |
| 2737 | private void reportDrawFinished() { |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 2738 | try { |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 2739 | mDrawsNeededToReport = 1; |
Robert Carr | d5c7dd6 | 2017-03-08 10:39:30 -0800 | [diff] [blame] | 2740 | mWindowSession.finishDrawing(mWindow); |
| 2741 | } catch (RemoteException e) { |
| 2742 | // Have fun! |
| 2743 | } |
| 2744 | } |
| 2745 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2746 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 2747 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 2748 | return; |
| 2749 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 2750 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2751 | final boolean fullRedrawNeeded = mFullRedrawNeeded; |
| 2752 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2753 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2754 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2755 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
| 2756 | try { |
| 2757 | draw(fullRedrawNeeded); |
| 2758 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2759 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2760 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2761 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2762 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 2763 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 2764 | // hardware animations that are now dangling |
| 2765 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 2766 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 2767 | for (int i = 0; i < count; i++) { |
| 2768 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 2769 | } |
| 2770 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 2771 | } |
| 2772 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2773 | if (mReportNextDraw) { |
| 2774 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2775 | |
| 2776 | // if we're using multi-thread renderer, wait for the window frame draws |
| 2777 | if (mWindowDrawCountDown != null) { |
| 2778 | try { |
| 2779 | mWindowDrawCountDown.await(); |
| 2780 | } catch (InterruptedException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2781 | Log.e(mTag, "Window redraw count down interruped!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2782 | } |
| 2783 | mWindowDrawCountDown = null; |
| 2784 | } |
| 2785 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2786 | if (mAttachInfo.mThreadedRenderer != null) { |
| 2787 | mAttachInfo.mThreadedRenderer.fence(); |
| 2788 | mAttachInfo.mThreadedRenderer.setStopped(mStopped); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 2789 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2790 | |
| 2791 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2792 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2793 | } |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 2794 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2795 | if (mSurfaceHolder != null && mSurface.isValid()) { |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 2796 | SurfaceCallbackHelper sch = new SurfaceCallbackHelper(this::postDrawFinished); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2797 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Robert Carr | 25cfa13 | 2016-11-16 13:24:09 -0800 | [diff] [blame] | 2798 | |
| 2799 | sch.dispatchSurfaceRedrawNeededAsync(mSurfaceHolder, callbacks); |
| 2800 | } else { |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 2801 | pendingDrawFinished(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2802 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | private void draw(boolean fullRedrawNeeded) { |
| 2807 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 2808 | if (!surface.isValid()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | return; |
| 2810 | } |
| 2811 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2812 | if (DEBUG_FPS) { |
| 2813 | trackFPS(); |
| 2814 | } |
| 2815 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2816 | if (!sFirstDrawComplete) { |
| 2817 | synchronized (sFirstDrawHandlers) { |
| 2818 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2819 | final int count = sFirstDrawHandlers.size(); |
| 2820 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 2821 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2826 | scrollToRectOrFocus(null, false); |
| 2827 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2828 | if (mAttachInfo.mViewScrollChanged) { |
| 2829 | mAttachInfo.mViewScrollChanged = false; |
| 2830 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2832 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2833 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2834 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2835 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2836 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2837 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2838 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2840 | if (mCurScrollY != curScrollY) { |
| 2841 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2843 | if (mView instanceof RootViewSurfaceTaker) { |
| 2844 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2847 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2848 | final float appScale = mAttachInfo.mApplicationScale; |
| 2849 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2851 | int resizeAlpha = 0; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2852 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2853 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2854 | if (mSurfaceHolder != null) { |
| 2855 | // The app owns the surface, we won't draw. |
| 2856 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2857 | if (animating && mScroller != null) { |
| 2858 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2859 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2860 | return; |
| 2861 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2862 | |
| 2863 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2864 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 2865 | dirty.set(0, 0, (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2866 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 2867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2868 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2869 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | + mWindowAttributes.getTitle() |
| 2871 | + ": dirty={" + dirty.left + "," + dirty.top |
| 2872 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2873 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 2874 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | } |
| 2876 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2877 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2878 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2879 | int xOffset = -mCanvasOffsetX; |
| 2880 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2881 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 2882 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 2883 | if (surfaceInsets != null) { |
| 2884 | xOffset -= surfaceInsets.left; |
| 2885 | yOffset -= surfaceInsets.top; |
| 2886 | |
| 2887 | // Offset dirty rect for surface insets. |
| 2888 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 2889 | } |
| 2890 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2891 | boolean accessibilityFocusDirty = false; |
| 2892 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 2893 | if (drawable != null) { |
| 2894 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2895 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 2896 | if (!hasFocus) { |
| 2897 | bounds.setEmpty(); |
| 2898 | } |
| 2899 | if (!bounds.equals(drawable.getBounds())) { |
| 2900 | accessibilityFocusDirty = true; |
| 2901 | } |
| 2902 | } |
| 2903 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2904 | mAttachInfo.mDrawingTime = |
| 2905 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 2906 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2907 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2908 | if (mAttachInfo.mThreadedRenderer != null && mAttachInfo.mThreadedRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2909 | // If accessibility focus moved, always invalidate the root. |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 2910 | boolean invalidateRoot = accessibilityFocusDirty || mInvalidateRootRequested; |
| 2911 | mInvalidateRootRequested = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2912 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2913 | // Draw with hardware renderer. |
| 2914 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2915 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 2916 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 2917 | mHardwareYOffset = yOffset; |
| 2918 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2919 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2922 | if (invalidateRoot) { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2923 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2926 | dirty.setEmpty(); |
| 2927 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 2928 | // Stage the content drawn size now. It will be transferred to the renderer |
| 2929 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2930 | final boolean updated = updateContentDrawBounds(); |
| 2931 | |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 2932 | if (mReportNextDraw) { |
| 2933 | // report next draw overrides setStopped() |
| 2934 | // This value is re-sync'd to the value of mStopped |
| 2935 | // in the handling of mReportNextDraw post-draw. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2936 | mAttachInfo.mThreadedRenderer.setStopped(false); |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 2937 | } |
| 2938 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2939 | if (updated) { |
| 2940 | requestDrawWindow(); |
| 2941 | } |
Jorim Jaggi | 0d6222d | 2016-04-18 20:42:10 -0700 | [diff] [blame] | 2942 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2943 | mAttachInfo.mThreadedRenderer.draw(mView, mAttachInfo, this); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2944 | } else { |
| 2945 | // If we get here with a disabled & requested hardware renderer, something went |
| 2946 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 2947 | // for instance) so we should just bail out. Locking the surface with software |
| 2948 | // rendering at this point would lock it forever and prevent hardware renderer |
| 2949 | // from doing its job when it comes back. |
| 2950 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 2951 | // hardware renderer if it's in requested state. This would happen after an |
| 2952 | // eglTerminate() for instance. |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2953 | if (mAttachInfo.mThreadedRenderer != null && |
| 2954 | !mAttachInfo.mThreadedRenderer.isEnabled() && |
| 2955 | mAttachInfo.mThreadedRenderer.isRequested()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2956 | |
| 2957 | try { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 2958 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2959 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2960 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2961 | handleOutOfResourcesException(e); |
| 2962 | return; |
| 2963 | } |
| 2964 | |
| 2965 | mFullRedrawNeeded = true; |
| 2966 | scheduleTraversals(); |
| 2967 | return; |
| 2968 | } |
| 2969 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2970 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2971 | return; |
| 2972 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 2973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2975 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2976 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | mFullRedrawNeeded = true; |
| 2978 | scheduleTraversals(); |
| 2979 | } |
| 2980 | } |
| 2981 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2982 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2983 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2984 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2985 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2986 | boolean scalingRequired, Rect dirty) { |
| 2987 | |
| 2988 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2989 | final Canvas canvas; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2990 | try { |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2991 | final int left = dirty.left; |
| 2992 | final int top = dirty.top; |
| 2993 | final int right = dirty.right; |
| 2994 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2995 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2996 | canvas = mSurface.lockCanvas(dirty); |
| 2997 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 2998 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 2999 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 3000 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 3001 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3002 | attachInfo.mIgnoreDirtyState = true; |
| 3003 | } |
| 3004 | |
| 3005 | // TODO: Do this in native |
| 3006 | canvas.setDensity(mDensity); |
| 3007 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3008 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3009 | return false; |
| 3010 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3011 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3012 | // Don't assume this is due to out of memory, it could be |
| 3013 | // something else, and if it is something else then we could |
| 3014 | // kill stuff (or ourself) for no reason. |
| 3015 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3016 | return false; |
| 3017 | } |
| 3018 | |
| 3019 | try { |
| 3020 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3021 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3022 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 3023 | //canvas.drawARGB(255, 255, 0, 0); |
| 3024 | } |
| 3025 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3026 | // If this bitmap's format includes an alpha channel, we |
| 3027 | // need to clear it before drawing so that the child will |
| 3028 | // properly re-composite its drawing on a transparent |
| 3029 | // background. This automatically respects the clip/dirty region |
| 3030 | // or |
| 3031 | // If we are applying an offset, we need to clear the area |
| 3032 | // where the offset doesn't appear to avoid having garbage |
| 3033 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3034 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3035 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 3036 | } |
| 3037 | |
| 3038 | dirty.setEmpty(); |
| 3039 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 3040 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3041 | |
| 3042 | if (DEBUG_DRAW) { |
| 3043 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3044 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3045 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 3046 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 3047 | } |
| 3048 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3049 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3050 | if (mTranslator != null) { |
| 3051 | mTranslator.translateCanvas(canvas); |
| 3052 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3053 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3054 | attachInfo.mSetIgnoreDirtyState = false; |
| 3055 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3056 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3057 | |
| 3058 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3059 | } finally { |
| 3060 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 3061 | // Only clear the flag if it was not set during the mView.draw() call |
| 3062 | attachInfo.mIgnoreDirtyState = false; |
| 3063 | } |
| 3064 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3065 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3066 | try { |
| 3067 | surface.unlockCanvasAndPost(canvas); |
| 3068 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3069 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 3070 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 3071 | //noinspection ReturnInsideFinallyBlock |
| 3072 | return false; |
| 3073 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3074 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3075 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3076 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 3077 | } |
| 3078 | } |
| 3079 | return true; |
| 3080 | } |
| 3081 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3082 | /** |
| 3083 | * We want to draw a highlight around the current accessibility focused. |
| 3084 | * Since adding a style for all possible view is not a viable option we |
| 3085 | * have this specialized drawing method. |
| 3086 | * |
| 3087 | * Note: We are doing this here to be able to draw the highlight for |
| 3088 | * virtual views in addition to real ones. |
| 3089 | * |
| 3090 | * @param canvas The canvas on which to draw. |
| 3091 | */ |
| 3092 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 3093 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 3094 | if (getAccessibilityFocusedRect(bounds)) { |
| 3095 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 3096 | if (drawable != null) { |
| 3097 | drawable.setBounds(bounds); |
| 3098 | drawable.draw(canvas); |
| 3099 | } |
| 3100 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 3101 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 3106 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 3107 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 3108 | return false; |
| 3109 | } |
| 3110 | |
| 3111 | final View host = mAccessibilityFocusedHost; |
| 3112 | if (host == null || host.mAttachInfo == null) { |
| 3113 | return false; |
| 3114 | } |
| 3115 | |
| 3116 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 3117 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 3118 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3119 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 3120 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 3121 | } else { |
| 3122 | return false; |
| 3123 | } |
| 3124 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3125 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3126 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 3127 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3128 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 3129 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 3130 | attachInfo.mViewRootImpl.mHeight)) { |
| 3131 | // If no intersection, set bounds to empty. |
| 3132 | bounds.setEmpty(); |
| 3133 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 3134 | return !bounds.isEmpty(); |
| 3135 | } |
| 3136 | |
| 3137 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3138 | // Lazily load the accessibility focus drawable. |
| 3139 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 3140 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3141 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 3142 | R.attr.accessibilityFocusedDrawable, value, true); |
| 3143 | if (resolved) { |
| 3144 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 3145 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3146 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3147 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3148 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3149 | } |
| 3150 | |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 3151 | /** |
| 3152 | * Requests that the root render node is invalidated next time we perform a draw, such that |
| 3153 | * {@link WindowCallbacks#onPostDraw} gets called. |
| 3154 | */ |
| 3155 | public void requestInvalidateRootRenderNode() { |
| 3156 | mInvalidateRootRequested = true; |
| 3157 | } |
| 3158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 3160 | final Rect ci = mAttachInfo.mContentInsets; |
| 3161 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | int scrollY = 0; |
| 3163 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3165 | if (vi.left > ci.left || vi.top > ci.top |
| 3166 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 3167 | // We'll assume that we aren't going to change the scroll |
| 3168 | // offset, since we want to avoid that unless it is actually |
| 3169 | // going to make the focus visible... otherwise we scroll |
| 3170 | // all over the place. |
| 3171 | scrollY = mScrollY; |
| 3172 | // We can be called for two different situations: during a draw, |
| 3173 | // to update the scroll position if the focus has changed (in which |
| 3174 | // case 'rectangle' is null), or in response to a |
| 3175 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 3176 | // is non-null and we just want to scroll to whatever that |
| 3177 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3178 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3179 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 3180 | return false; |
| 3181 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3182 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3183 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | // If the focus has changed, then ignore any requests to scroll |
| 3185 | // to a rectangle; first we want to make sure the entire focus |
| 3186 | // view is visible. |
| 3187 | rectangle = null; |
| 3188 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3189 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Eval scroll: focus=" + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3190 | + " rectangle=" + rectangle + " ci=" + ci |
| 3191 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3192 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | // Optimization: if the focus hasn't changed since last |
| 3194 | // time, and no layout has happened, then just leave things |
| 3195 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3196 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Keeping scroll y=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 3198 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | // We need to determine if the currently focused view is |
| 3200 | // within the visible part of the window and, if not, apply |
| 3201 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3202 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3203 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3204 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Need to scroll?"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3205 | // Try to find the rectangle from the focus view. |
| 3206 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3207 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | + mView.getWidth() + " h=" + mView.getHeight() |
| 3209 | + " ci=" + ci.toShortString() |
| 3210 | + " vi=" + vi.toShortString()); |
| 3211 | if (rectangle == null) { |
| 3212 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3213 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 3215 | if (mView instanceof ViewGroup) { |
| 3216 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 3217 | focus, mTempRect); |
| 3218 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3219 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3220 | "Focus in window: focusRect=" |
| 3221 | + mTempRect.toShortString() |
| 3222 | + " visRect=" + mVisRect.toShortString()); |
| 3223 | } else { |
| 3224 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3225 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | "Request scroll to rect: " |
| 3227 | + mTempRect.toShortString() |
| 3228 | + " visRect=" + mVisRect.toShortString()); |
| 3229 | } |
| 3230 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3231 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | "Focus window visible rect: " |
| 3233 | + mTempRect.toShortString()); |
| 3234 | if (mTempRect.height() > |
| 3235 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 3236 | // If the focus simply is not going to fit, then |
| 3237 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3238 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | "Too tall; leaving scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3240 | } |
| 3241 | // Next, check whether top or bottom is covered based on the non-scrolled |
| 3242 | // position, and calculate new scrollY (or set it to 0). |
| 3243 | // We can't keep using mScrollY here. For example mScrollY is non-zero |
| 3244 | // due to IME, then IME goes away. The current value of mScrollY leaves top |
| 3245 | // and bottom both visible, but we still need to scroll it back to 0. |
| 3246 | else if (mTempRect.top < vi.top) { |
| 3247 | scrollY = mTempRect.top - vi.top; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3248 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | "Top covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3250 | } else if (mTempRect.bottom > (mView.getHeight()-vi.bottom)) { |
| 3251 | scrollY = mTempRect.bottom - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3252 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | "Bottom covered; scrollY=" + scrollY); |
Chong Zhang | 6725472 | 2016-06-02 12:56:54 -0700 | [diff] [blame] | 3254 | } else { |
| 3255 | scrollY = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | } |
| 3257 | handled = true; |
| 3258 | } |
| 3259 | } |
| 3260 | } |
| 3261 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3264 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Pan scroll changed: old=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3265 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3266 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | if (mScroller == null) { |
| 3268 | mScroller = new Scroller(mView.getContext()); |
| 3269 | } |
| 3270 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3271 | } else if (mScroller != null) { |
| 3272 | mScroller.abortAnimation(); |
| 3273 | } |
| 3274 | mScrollY = scrollY; |
| 3275 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | return handled; |
| 3278 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3279 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3280 | /** |
| 3281 | * @hide |
| 3282 | */ |
| 3283 | public View getAccessibilityFocusedHost() { |
| 3284 | return mAccessibilityFocusedHost; |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * @hide |
| 3289 | */ |
| 3290 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3291 | return mAccessibilityFocusedVirtualView; |
| 3292 | } |
| 3293 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3294 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3295 | // If we have a virtual view with accessibility focus we need |
| 3296 | // to clear the focus and invalidate the virtual view bounds. |
| 3297 | if (mAccessibilityFocusedVirtualView != null) { |
| 3298 | |
| 3299 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3300 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3301 | |
| 3302 | // Wipe the state of the current accessibility focus since |
| 3303 | // the call into the provider to clear accessibility focus |
| 3304 | // will fire an accessibility event which will end up calling |
| 3305 | // this method and we want to have clean state when this |
| 3306 | // invocation happens. |
| 3307 | mAccessibilityFocusedHost = null; |
| 3308 | mAccessibilityFocusedVirtualView = null; |
| 3309 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3310 | // Clear accessibility focus on the host after clearing state since |
| 3311 | // this method may be reentrant. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3312 | focusHost.clearAccessibilityFocusNoCallbacks( |
| 3313 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3314 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3315 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3316 | if (provider != null) { |
| 3317 | // Invalidate the area of the cleared accessibility focus. |
| 3318 | focusNode.getBoundsInParent(mTempRect); |
| 3319 | focusHost.invalidate(mTempRect); |
| 3320 | // Clear accessibility focus in the virtual node. |
| 3321 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3322 | focusNode.getSourceNodeId()); |
| 3323 | provider.performAction(virtualNodeId, |
| 3324 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3325 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3326 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3327 | } |
Phil Weaver | da46927 | 2016-06-24 18:17:21 -0700 | [diff] [blame] | 3328 | if ((mAccessibilityFocusedHost != null) && (mAccessibilityFocusedHost != view)) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3329 | // Clear accessibility focus in the view. |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 3330 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks( |
| 3331 | AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3332 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3333 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3334 | // Set the new focus host and node. |
| 3335 | mAccessibilityFocusedHost = view; |
| 3336 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3337 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3338 | if (mAttachInfo.mThreadedRenderer != null) { |
| 3339 | mAttachInfo.mThreadedRenderer.invalidateRoot(); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3340 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3343 | boolean hasPointerCapture() { |
| 3344 | return mPointerCapture; |
| 3345 | } |
| 3346 | |
| 3347 | void requestPointerCapture(boolean enabled) { |
| 3348 | if (mPointerCapture == enabled) { |
| 3349 | return; |
| 3350 | } |
| 3351 | InputManager.getInstance().requestPointerCapture(mAttachInfo.mWindowToken, enabled); |
| 3352 | } |
| 3353 | |
| 3354 | private void handlePointerCaptureChanged(boolean hasCapture) { |
| 3355 | if (mPointerCapture == hasCapture) { |
| 3356 | return; |
| 3357 | } |
| 3358 | mPointerCapture = hasCapture; |
| 3359 | if (mView != null) { |
| 3360 | mView.dispatchPointerCaptureChanged(hasCapture); |
| 3361 | } |
| 3362 | } |
| 3363 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3364 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3366 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3367 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3369 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3370 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | } |
| 3372 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3373 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3375 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3376 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3377 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3378 | checkThread(); |
| 3379 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3380 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3381 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3382 | @Override |
| 3383 | public ViewParent getParentForAccessibility() { |
| 3384 | return null; |
| 3385 | } |
| 3386 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3387 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3388 | public void focusableViewAvailable(View v) { |
| 3389 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3390 | if (mView != null) { |
| 3391 | if (!mView.hasFocus()) { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 3392 | if (sAlwaysAssignFocus) { |
| 3393 | v.requestFocus(); |
| 3394 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3395 | } else { |
| 3396 | // the one case where will transfer focus away from the current one |
| 3397 | // is if the current view is a view group that prefers to give focus |
| 3398 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3399 | View focused = mView.findFocus(); |
| 3400 | if (focused instanceof ViewGroup) { |
| 3401 | ViewGroup group = (ViewGroup) focused; |
| 3402 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3403 | && isViewDescendantOf(v, focused)) { |
| 3404 | v.requestFocus(); |
| 3405 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3406 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3411 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | public void recomputeViewAttributes(View child) { |
| 3413 | checkThread(); |
| 3414 | if (mView == child) { |
| 3415 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3416 | if (!mWillDrawSoon) { |
| 3417 | scheduleTraversals(); |
| 3418 | } |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | void dispatchDetachedFromWindow() { |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3423 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3424 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | mView.dispatchDetachedFromWindow(); |
| 3426 | } |
| 3427 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3428 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3429 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3430 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3431 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3432 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3433 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3434 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3435 | destroyHardwareRenderer(); |
| 3436 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3437 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3438 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3439 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | mView = null; |
| 3441 | mAttachInfo.mRootView = null; |
| 3442 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3443 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3445 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3446 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3447 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3448 | mInputQueueCallback = null; |
| 3449 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3450 | } |
| 3451 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3452 | mInputEventReceiver.dispose(); |
| 3453 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3456 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | } catch (RemoteException e) { |
| 3458 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3459 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3460 | // Dispose the input channel after removing the window so the Window Manager |
| 3461 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3462 | if (mInputChannel != null) { |
| 3463 | mInputChannel.dispose(); |
| 3464 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3465 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3466 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3467 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3468 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3469 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3471 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3472 | /** |
| 3473 | * Notifies all callbacks that configuration and/or display has changed and updates internal |
| 3474 | * state. |
| 3475 | * @param mergedConfiguration New global and override config in {@link MergedConfiguration} |
| 3476 | * container. |
| 3477 | * @param force Flag indicating if we should force apply the config. |
| 3478 | * @param newDisplayId Id of new display if moved, {@link Display#INVALID_DISPLAY} if not |
| 3479 | * changed. |
| 3480 | */ |
| 3481 | private void performConfigurationChange(MergedConfiguration mergedConfiguration, boolean force, |
| 3482 | int newDisplayId) { |
| 3483 | if (mergedConfiguration == null) { |
| 3484 | throw new IllegalArgumentException("No merged config provided."); |
| 3485 | } |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3486 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3487 | Configuration globalConfig = mergedConfiguration.getGlobalConfiguration(); |
| 3488 | final Configuration overrideConfig = mergedConfiguration.getOverrideConfiguration(); |
| 3489 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
| 3490 | "Applying new config to window " + mWindowAttributes.getTitle() |
| 3491 | + ", globalConfig: " + globalConfig |
| 3492 | + ", overrideConfig: " + overrideConfig); |
| 3493 | |
| 3494 | final CompatibilityInfo ci = mDisplay.getDisplayAdjustments().getCompatibilityInfo(); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3495 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3496 | globalConfig = new Configuration(globalConfig); |
| 3497 | ci.applyToConfiguration(mNoncompatDensity, globalConfig); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3500 | synchronized (sConfigCallbacks) { |
| 3501 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3502 | sConfigCallbacks.get(i).onConfigurationChanged(globalConfig); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3503 | } |
| 3504 | } |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 3505 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3506 | mLastReportedMergedConfiguration.setConfiguration(globalConfig, overrideConfig); |
| 3507 | |
| 3508 | mForceNextConfigUpdate = force; |
| 3509 | if (mActivityConfigCallback != null) { |
| 3510 | // An activity callback is set - notify it about override configuration update. |
| 3511 | // This basically initiates a round trip to ActivityThread and back, which will ensure |
| 3512 | // that corresponding activity and resources are updated before updating inner state of |
| 3513 | // ViewRootImpl. Eventually it will call #updateConfiguration(). |
| 3514 | mActivityConfigCallback.onConfigurationChanged(overrideConfig, newDisplayId); |
| 3515 | } else { |
| 3516 | // There is no activity callback - update the configuration right away. |
| 3517 | updateConfiguration(); |
| 3518 | } |
| 3519 | mForceNextConfigUpdate = false; |
| 3520 | } |
| 3521 | |
| 3522 | /** |
| 3523 | * Update display and views if last applied merged configuration changed. |
| 3524 | */ |
| 3525 | public void updateConfiguration() { |
| 3526 | if (mView == null) { |
| 3527 | return; |
| 3528 | } |
| 3529 | |
| 3530 | // At this point the resources have been updated to |
| 3531 | // have the most recent config, whatever that is. Use |
| 3532 | // the one in them which may be newer. |
| 3533 | final Resources localResources = mView.getResources(); |
| 3534 | final Configuration config = localResources.getConfiguration(); |
| 3535 | if (mForceNextConfigUpdate || mLastConfigurationFromResources.diff(config) != 0) { |
| 3536 | // Update the display with new DisplayAdjustments. |
| 3537 | mDisplay = ResourcesManager.getInstance().getAdjustedDisplay( |
| 3538 | mDisplay.getDisplayId(), localResources); |
| 3539 | |
| 3540 | final int lastLayoutDirection = mLastConfigurationFromResources.getLayoutDirection(); |
| 3541 | final int currentLayoutDirection = config.getLayoutDirection(); |
| 3542 | mLastConfigurationFromResources.setTo(config); |
| 3543 | if (lastLayoutDirection != currentLayoutDirection |
| 3544 | && mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 3545 | mView.setLayoutDirection(currentLayoutDirection); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3546 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3547 | mView.dispatchConfigurationChanged(config); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3548 | } |
| 3549 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3551 | /** |
| 3552 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3553 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3554 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | if (child == parent) { |
| 3556 | return true; |
| 3557 | } |
| 3558 | |
| 3559 | final ViewParent theParent = child.getParent(); |
| 3560 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3561 | } |
| 3562 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3563 | private static void forceLayout(View view) { |
| 3564 | view.forceLayout(); |
| 3565 | if (view instanceof ViewGroup) { |
| 3566 | ViewGroup group = (ViewGroup) view; |
| 3567 | final int count = group.getChildCount(); |
| 3568 | for (int i = 0; i < count; i++) { |
| 3569 | forceLayout(group.getChildAt(i)); |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3574 | private final static int MSG_INVALIDATE = 1; |
| 3575 | private final static int MSG_INVALIDATE_RECT = 2; |
| 3576 | private final static int MSG_DIE = 3; |
| 3577 | private final static int MSG_RESIZED = 4; |
| 3578 | private final static int MSG_RESIZED_REPORT = 5; |
| 3579 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3580 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3581 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 3582 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3583 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3584 | private final static int MSG_CHECK_FOCUS = 13; |
| 3585 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 3586 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 3587 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 3588 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 3589 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3590 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3591 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 3592 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 3593 | private final static int MSG_WINDOW_MOVED = 23; |
| 3594 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 3595 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3596 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3597 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3598 | private final static int MSG_POINTER_CAPTURE_CHANGED = 28; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 3599 | private final static int MSG_DRAW_FINISHED = 29; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3601 | final class ViewRootHandler extends Handler { |
| 3602 | @Override |
| 3603 | public String getMessageName(Message message) { |
| 3604 | switch (message.what) { |
| 3605 | case MSG_INVALIDATE: |
| 3606 | return "MSG_INVALIDATE"; |
| 3607 | case MSG_INVALIDATE_RECT: |
| 3608 | return "MSG_INVALIDATE_RECT"; |
| 3609 | case MSG_DIE: |
| 3610 | return "MSG_DIE"; |
| 3611 | case MSG_RESIZED: |
| 3612 | return "MSG_RESIZED"; |
| 3613 | case MSG_RESIZED_REPORT: |
| 3614 | return "MSG_RESIZED_REPORT"; |
| 3615 | case MSG_WINDOW_FOCUS_CHANGED: |
| 3616 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3617 | case MSG_DISPATCH_INPUT_EVENT: |
| 3618 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3619 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3620 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 3621 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3622 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3623 | case MSG_DISPATCH_KEY_FROM_IME: |
| 3624 | return "MSG_DISPATCH_KEY_FROM_IME"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3625 | case MSG_CHECK_FOCUS: |
| 3626 | return "MSG_CHECK_FOCUS"; |
| 3627 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 3628 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 3629 | case MSG_DISPATCH_DRAG_EVENT: |
| 3630 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 3631 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 3632 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 3633 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 3634 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 3635 | case MSG_UPDATE_CONFIGURATION: |
| 3636 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3637 | case MSG_PROCESS_INPUT_EVENTS: |
| 3638 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3639 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 3640 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3641 | case MSG_WINDOW_MOVED: |
| 3642 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3643 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 3644 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3645 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 3646 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3647 | case MSG_UPDATE_POINTER_ICON: |
| 3648 | return "MSG_UPDATE_POINTER_ICON"; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3649 | case MSG_POINTER_CAPTURE_CHANGED: |
| 3650 | return "MSG_POINTER_CAPTURE_CHANGED"; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 3651 | case MSG_DRAW_FINISHED: |
| 3652 | return "MSG_DRAW_FINISHED"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3653 | } |
| 3654 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3655 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3656 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3657 | @Override |
Michael Wright | 53b854a | 2016-04-12 19:22:41 -0400 | [diff] [blame] | 3658 | public boolean sendMessageAtTime(Message msg, long uptimeMillis) { |
| 3659 | if (msg.what == MSG_REQUEST_KEYBOARD_SHORTCUTS && msg.obj == null) { |
| 3660 | // Debugging for b/27963013 |
| 3661 | throw new NullPointerException( |
| 3662 | "Attempted to call MSG_REQUEST_KEYBOARD_SHORTCUTS with null receiver:"); |
| 3663 | } |
| 3664 | return super.sendMessageAtTime(msg, uptimeMillis); |
| 3665 | } |
| 3666 | |
| 3667 | @Override |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3668 | public void handleMessage(Message msg) { |
| 3669 | switch (msg.what) { |
| 3670 | case MSG_INVALIDATE: |
| 3671 | ((View) msg.obj).invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3673 | case MSG_INVALIDATE_RECT: |
| 3674 | final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj; |
| 3675 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 3676 | info.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3677 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3678 | case MSG_PROCESS_INPUT_EVENTS: |
| 3679 | mProcessInputEventsScheduled = false; |
| 3680 | doProcessInputEvents(); |
| 3681 | break; |
| 3682 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3683 | handleAppVisibility(msg.arg1 != 0); |
| 3684 | break; |
| 3685 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3686 | handleGetNewSurface(); |
| 3687 | break; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3688 | case MSG_RESIZED: { |
| 3689 | // Recycled in the fall through... |
| 3690 | SomeArgs args = (SomeArgs) msg.obj; |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3691 | if (mWinFrame.equals(args.arg1) |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3692 | && mPendingOverscanInsets.equals(args.arg5) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3693 | && mPendingContentInsets.equals(args.arg2) |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3694 | && mPendingStableInsets.equals(args.arg6) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3695 | && mPendingVisibleInsets.equals(args.arg3) |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3696 | && mPendingOutsets.equals(args.arg7) |
Jorim Jaggi | 0fe356e | 2016-01-05 14:43:25 +0100 | [diff] [blame] | 3697 | && mPendingBackDropFrame.equals(args.arg8) |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3698 | && args.arg4 == null |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3699 | && args.argi1 == 0 |
| 3700 | && mDisplay.getDisplayId() == args.argi3) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3701 | break; |
Romain Guy | cdb8667 | 2010-03-18 18:54:50 -0700 | [diff] [blame] | 3702 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3703 | } // fall through... |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3704 | case MSG_RESIZED_REPORT: |
| 3705 | if (mAdded) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3706 | SomeArgs args = (SomeArgs) msg.obj; |
| 3707 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3708 | final int displayId = args.argi3; |
| 3709 | final boolean displayChanged = mDisplay.getDisplayId() != displayId; |
| 3710 | if (displayChanged) { |
| 3711 | onMovedToDisplay(displayId); |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 3712 | } |
| 3713 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3714 | final MergedConfiguration mergedConfiguration = (MergedConfiguration) args.arg4; |
| 3715 | if (mergedConfiguration != null) { |
| 3716 | performConfigurationChange(mergedConfiguration, false /* force */, |
| 3717 | displayChanged ? displayId : INVALID_DISPLAY /* same display */); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3718 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3719 | |
Jorim Jaggi | 26952d7 | 2016-04-01 17:43:14 -0700 | [diff] [blame] | 3720 | final boolean framesChanged = !mWinFrame.equals(args.arg1) |
| 3721 | || !mPendingOverscanInsets.equals(args.arg5) |
| 3722 | || !mPendingContentInsets.equals(args.arg2) |
| 3723 | || !mPendingStableInsets.equals(args.arg6) |
| 3724 | || !mPendingVisibleInsets.equals(args.arg3) |
| 3725 | || !mPendingOutsets.equals(args.arg7); |
| 3726 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3727 | mWinFrame.set((Rect) args.arg1); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3728 | mPendingOverscanInsets.set((Rect) args.arg5); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3729 | mPendingContentInsets.set((Rect) args.arg2); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3730 | mPendingStableInsets.set((Rect) args.arg6); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3731 | mPendingVisibleInsets.set((Rect) args.arg3); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3732 | mPendingOutsets.set((Rect) args.arg7); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3733 | mPendingBackDropFrame.set((Rect) args.arg8); |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3734 | mForceNextWindowRelayout = args.argi1 != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3735 | mPendingAlwaysConsumeNavBar = args.argi2 != 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3736 | |
| 3737 | args.recycle(); |
| 3738 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3739 | if (msg.what == MSG_RESIZED_REPORT) { |
| 3740 | mReportNextDraw = true; |
| 3741 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3742 | |
Jorim Jaggi | 26952d7 | 2016-04-01 17:43:14 -0700 | [diff] [blame] | 3743 | if (mView != null && framesChanged) { |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3744 | forceLayout(mView); |
| 3745 | } |
| 3746 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3747 | requestLayout(); |
| 3748 | } |
| 3749 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3750 | case MSG_WINDOW_MOVED: |
| 3751 | if (mAdded) { |
| 3752 | final int w = mWinFrame.width(); |
| 3753 | final int h = mWinFrame.height(); |
| 3754 | final int l = msg.arg1; |
| 3755 | final int t = msg.arg2; |
| 3756 | mWinFrame.left = l; |
| 3757 | mWinFrame.right = l + w; |
| 3758 | mWinFrame.top = t; |
| 3759 | mWinFrame.bottom = t + h; |
| 3760 | |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3761 | mPendingBackDropFrame.set(mWinFrame); |
Winson Chung | c7c4dbb | 2016-10-28 14:33:32 -0700 | [diff] [blame] | 3762 | maybeHandleWindowMove(mWinFrame); |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3763 | } |
| 3764 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3765 | case MSG_WINDOW_FOCUS_CHANGED: { |
| 3766 | if (mAdded) { |
| 3767 | boolean hasWindowFocus = msg.arg1 != 0; |
| 3768 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3770 | profileRendering(hasWindowFocus); |
| 3771 | |
| 3772 | if (hasWindowFocus) { |
| 3773 | boolean inTouchMode = msg.arg2 != 0; |
| 3774 | ensureTouchModeLocally(inTouchMode); |
| 3775 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3776 | if (mAttachInfo.mThreadedRenderer != null && mSurface.isValid()){ |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3777 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3778 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3779 | final WindowManager.LayoutParams lp = mWindowAttributes; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 3780 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 3781 | mAttachInfo.mThreadedRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3782 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3783 | } catch (OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3784 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3785 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3786 | if (!mWindowSession.outOfMemory(mWindow)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3787 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3788 | Process.killProcess(Process.myPid()); |
| 3789 | } |
| 3790 | } catch (RemoteException ex) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3791 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3792 | // Retry in a bit. |
| 3793 | sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500); |
| 3794 | return; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3795 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3796 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3798 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3799 | mLastWasImTarget = WindowManager.LayoutParams |
| 3800 | .mayUseInputMethod(mWindowAttributes.flags); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3801 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3802 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3803 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 3804 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 3805 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3806 | if (mView != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3807 | mAttachInfo.mKeyDispatchState.reset(); |
| 3808 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3809 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 3810 | |
| 3811 | if (mAttachInfo.mTooltipHost != null) { |
| 3812 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 3813 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3815 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3816 | // Note: must be done after the focus change callbacks, |
| 3817 | // so all of the view state is set up correctly. |
| 3818 | if (hasWindowFocus) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3819 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3820 | imm.onPostWindowFocus(mView, mView.findFocus(), |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3821 | mWindowAttributes.softInputMode, |
| 3822 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 3823 | } |
| 3824 | // Clear the forward bit. We can just do this directly, since |
| 3825 | // the window manager doesn't care about it. |
| 3826 | mWindowAttributes.softInputMode &= |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3827 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3828 | ((WindowManager.LayoutParams)mView.getLayoutParams()) |
| 3829 | .softInputMode &= |
| 3830 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 3831 | mHasHadWindowFocus = true; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3832 | } else { |
| 3833 | if (mPointerCapture) { |
| 3834 | handlePointerCaptureChanged(false); |
| 3835 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3836 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3837 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3838 | } break; |
| 3839 | case MSG_DIE: |
| 3840 | doDie(); |
| 3841 | break; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3842 | case MSG_DISPATCH_INPUT_EVENT: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 3843 | SomeArgs args = (SomeArgs)msg.obj; |
| 3844 | InputEvent event = (InputEvent)args.arg1; |
| 3845 | InputEventReceiver receiver = (InputEventReceiver)args.arg2; |
| 3846 | enqueueInputEvent(event, receiver, 0, true); |
| 3847 | args.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3848 | } break; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3849 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 3850 | InputEvent event = (InputEvent)msg.obj; |
| 3851 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 3852 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3853 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 3854 | if (LOCAL_LOGV) Log.v( |
| 3855 | TAG, "Dispatching key " |
| 3856 | + msg.obj + " from IME to " + mView); |
| 3857 | KeyEvent event = (KeyEvent)msg.obj; |
| 3858 | if ((event.getFlags()&KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 3859 | // The IME is trying to say this event is from the |
| 3860 | // system! Bad bad bad! |
| 3861 | //noinspection UnusedAssignment |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3862 | event = KeyEvent.changeFlags(event, event.getFlags() & |
| 3863 | ~KeyEvent.FLAG_FROM_SYSTEM); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3864 | } |
| 3865 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 3866 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3867 | case MSG_CHECK_FOCUS: { |
| 3868 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3869 | if (imm != null) { |
| 3870 | imm.checkFocus(); |
| 3871 | } |
| 3872 | } break; |
| 3873 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
| 3874 | if (mView != null) { |
| 3875 | mView.onCloseSystemDialogs((String)msg.obj); |
| 3876 | } |
| 3877 | } break; |
| 3878 | case MSG_DISPATCH_DRAG_EVENT: |
| 3879 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 3880 | DragEvent event = (DragEvent)msg.obj; |
| 3881 | event.mLocalState = mLocalDragState; // only present when this app called startDrag() |
| 3882 | handleDragEvent(event); |
| 3883 | } break; |
| 3884 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3885 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3886 | } break; |
| 3887 | case MSG_UPDATE_CONFIGURATION: { |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3888 | Configuration config = (Configuration) msg.obj; |
| 3889 | if (config.isOtherSeqNewer( |
| 3890 | mLastReportedMergedConfiguration.getMergedConfiguration())) { |
| 3891 | // If we already have a newer merged config applied - use its global part. |
| 3892 | config = mLastReportedMergedConfiguration.getGlobalConfiguration(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3893 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 3894 | |
| 3895 | // Use the newer global config and last reported override config. |
| 3896 | mPendingMergedConfiguration.setConfiguration(config, |
| 3897 | mLastReportedMergedConfiguration.getOverrideConfiguration()); |
| 3898 | |
| 3899 | performConfigurationChange(mPendingMergedConfiguration, false /* force */, |
| 3900 | INVALID_DISPLAY /* same display */); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3901 | } break; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3902 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3903 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3904 | } break; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3905 | case MSG_INVALIDATE_WORLD: { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 3906 | if (mView != null) { |
| 3907 | invalidateWorld(mView); |
| 3908 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3909 | } break; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3910 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 3911 | handleDispatchWindowShown(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3912 | } break; |
| 3913 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 3914 | final IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 3915 | final int deviceId = msg.arg1; |
| 3916 | handleRequestKeyboardShortcuts(receiver, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3917 | } break; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3918 | case MSG_UPDATE_POINTER_ICON: { |
| 3919 | MotionEvent event = (MotionEvent) msg.obj; |
| 3920 | resetPointerIcon(event); |
| 3921 | } break; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 3922 | case MSG_POINTER_CAPTURE_CHANGED: { |
| 3923 | final boolean hasCapture = msg.arg1 != 0; |
| 3924 | handlePointerCaptureChanged(hasCapture); |
| 3925 | } break; |
Robert Carr | 8508bb2 | 2017-03-27 15:46:27 -0700 | [diff] [blame^] | 3926 | case MSG_DRAW_FINISHED: { |
| 3927 | pendingDrawFinished(); |
| 3928 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | } |
| 3931 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 3932 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3933 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3935 | /** |
| 3936 | * Something in the current window tells us we need to change the touch mode. For |
| 3937 | * example, we are not in touch mode, and the user touches the screen. |
| 3938 | * |
| 3939 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 3940 | * |
| 3941 | * @param inTouchMode Whether we want to be in touch mode. |
| 3942 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3943 | */ |
| 3944 | boolean ensureTouchMode(boolean inTouchMode) { |
| 3945 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 3946 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3947 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3948 | |
| 3949 | // tell the window manager |
| 3950 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 3951 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | } catch (RemoteException e) { |
| 3953 | throw new RuntimeException(e); |
| 3954 | } |
| 3955 | |
| 3956 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3957 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3958 | } |
| 3959 | |
| 3960 | /** |
| 3961 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 3962 | * take the appropriate action. |
| 3963 | * @param inTouchMode Whether we want to be in touch mode. |
| 3964 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3965 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3966 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 3968 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3969 | |
| 3970 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3971 | |
| 3972 | mAttachInfo.mInTouchMode = inTouchMode; |
| 3973 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 3974 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3975 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3979 | if (mView != null && mView.hasFocus()) { |
| 3980 | // note: not relying on mFocusedView here because this could |
| 3981 | // be when the window is first being added, and mFocused isn't |
| 3982 | // set yet. |
| 3983 | final View focused = mView.findFocus(); |
| 3984 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 3985 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 3986 | if (ancestorToTakeFocus != null) { |
| 3987 | // there is an ancestor that wants focus after its |
| 3988 | // descendants that is focusable in touch mode.. give it |
| 3989 | // focus |
| 3990 | return ancestorToTakeFocus.requestFocus(); |
| 3991 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 3992 | // There's nothing to focus. Clear and propagate through the |
| 3993 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 3994 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3995 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | } |
| 3997 | } |
| 3998 | } |
| 3999 | return false; |
| 4000 | } |
| 4001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | /** |
| 4003 | * Find an ancestor of focused that wants focus after its descendants and is |
| 4004 | * focusable in touch mode. |
| 4005 | * @param focused The currently focused view. |
| 4006 | * @return An appropriate view, or null if no such view exists. |
| 4007 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 4008 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4009 | ViewParent parent = focused.getParent(); |
| 4010 | while (parent instanceof ViewGroup) { |
| 4011 | final ViewGroup vgParent = (ViewGroup) parent; |
| 4012 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 4013 | && vgParent.isFocusableInTouchMode()) { |
| 4014 | return vgParent; |
| 4015 | } |
| 4016 | if (vgParent.isRootNamespace()) { |
| 4017 | return null; |
| 4018 | } else { |
| 4019 | parent = vgParent.getParent(); |
| 4020 | } |
| 4021 | } |
| 4022 | return null; |
| 4023 | } |
| 4024 | |
| 4025 | private boolean leaveTouchMode() { |
| 4026 | if (mView != null) { |
| 4027 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4028 | View focusedView = mView.findFocus(); |
| 4029 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4031 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 4032 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 4034 | // some view group has focus, and doesn't prefer its children |
| 4035 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4036 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | } |
| 4038 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 4039 | |
| 4040 | // find the best view to give focus to in this brave new non-touch-mode |
| 4041 | // world |
| 4042 | final View focused = focusSearch(null, View.FOCUS_DOWN); |
| 4043 | if (focused != null) { |
| 4044 | return focused.requestFocus(View.FOCUS_DOWN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | return false; |
| 4048 | } |
| 4049 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4050 | /** |
| 4051 | * Base class for implementing a stage in the chain of responsibility |
| 4052 | * for processing input events. |
| 4053 | * <p> |
| 4054 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 4055 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 4056 | * </p> |
| 4057 | */ |
| 4058 | abstract class InputStage { |
| 4059 | private final InputStage mNext; |
| 4060 | |
| 4061 | protected static final int FORWARD = 0; |
| 4062 | protected static final int FINISH_HANDLED = 1; |
| 4063 | protected static final int FINISH_NOT_HANDLED = 2; |
| 4064 | |
| 4065 | /** |
| 4066 | * Creates an input stage. |
| 4067 | * @param next The next stage to which events should be forwarded. |
| 4068 | */ |
| 4069 | public InputStage(InputStage next) { |
| 4070 | mNext = next; |
| 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * Delivers an event to be processed. |
| 4075 | */ |
| 4076 | public final void deliver(QueuedInputEvent q) { |
| 4077 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 4078 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4079 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4080 | finish(q, false); |
| 4081 | } else { |
| 4082 | apply(q, onProcess(q)); |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | /** |
| 4087 | * Marks the the input event as finished then forwards it to the next stage. |
| 4088 | */ |
| 4089 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 4090 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 4091 | if (handled) { |
| 4092 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 4093 | } |
| 4094 | forward(q); |
| 4095 | } |
| 4096 | |
| 4097 | /** |
| 4098 | * Forwards the event to the next stage. |
| 4099 | */ |
| 4100 | protected void forward(QueuedInputEvent q) { |
| 4101 | onDeliverToNext(q); |
| 4102 | } |
| 4103 | |
| 4104 | /** |
| 4105 | * Applies a result code from {@link #onProcess} to the specified event. |
| 4106 | */ |
| 4107 | protected void apply(QueuedInputEvent q, int result) { |
| 4108 | if (result == FORWARD) { |
| 4109 | forward(q); |
| 4110 | } else if (result == FINISH_HANDLED) { |
| 4111 | finish(q, true); |
| 4112 | } else if (result == FINISH_NOT_HANDLED) { |
| 4113 | finish(q, false); |
| 4114 | } else { |
| 4115 | throw new IllegalArgumentException("Invalid result: " + result); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Called when an event is ready to be processed. |
| 4121 | * @return A result code indicating how the event was handled. |
| 4122 | */ |
| 4123 | protected int onProcess(QueuedInputEvent q) { |
| 4124 | return FORWARD; |
| 4125 | } |
| 4126 | |
| 4127 | /** |
| 4128 | * Called when an event is being delivered to the next stage. |
| 4129 | */ |
| 4130 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4131 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4132 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 4133 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4134 | if (mNext != null) { |
| 4135 | mNext.deliver(q); |
| 4136 | } else { |
| 4137 | finishInputEvent(q); |
| 4138 | } |
| 4139 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4140 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4141 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 4142 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4143 | Slog.w(mTag, "Dropping event due to root view being removed: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4144 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4145 | } else if ((!mAttachInfo.mHasWindowFocus |
| 4146 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 4147 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 4148 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4149 | // This is a focus event and the window doesn't currently have input focus or |
| 4150 | // has stopped. This could be an event that came back from the previous stage |
| 4151 | // but the window has lost focus or stopped in the meantime. |
| 4152 | if (isTerminalInputEvent(q.mEvent)) { |
| 4153 | // Don't drop terminal input events, however mark them as canceled. |
| 4154 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4155 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 4156 | return false; |
| 4157 | } |
| 4158 | |
| 4159 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4160 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4161 | return true; |
| 4162 | } |
| 4163 | return false; |
| 4164 | } |
| 4165 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4166 | void dump(String prefix, PrintWriter writer) { |
| 4167 | if (mNext != null) { |
| 4168 | mNext.dump(prefix, writer); |
| 4169 | } |
| 4170 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 4171 | |
| 4172 | private boolean isBack(InputEvent event) { |
| 4173 | if (event instanceof KeyEvent) { |
| 4174 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 4175 | } else { |
| 4176 | return false; |
| 4177 | } |
| 4178 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * Base class for implementing an input pipeline stage that supports |
| 4183 | * asynchronous and out-of-order processing of input events. |
| 4184 | * <p> |
| 4185 | * In addition to what a normal input stage can do, an asynchronous |
| 4186 | * input stage may also defer an input event that has been delivered to it |
| 4187 | * and finish or forward it later. |
| 4188 | * </p> |
| 4189 | */ |
| 4190 | abstract class AsyncInputStage extends InputStage { |
| 4191 | private final String mTraceCounter; |
| 4192 | |
| 4193 | private QueuedInputEvent mQueueHead; |
| 4194 | private QueuedInputEvent mQueueTail; |
| 4195 | private int mQueueLength; |
| 4196 | |
| 4197 | protected static final int DEFER = 3; |
| 4198 | |
| 4199 | /** |
| 4200 | * Creates an asynchronous input stage. |
| 4201 | * @param next The next stage to which events should be forwarded. |
| 4202 | * @param traceCounter The name of a counter to record the size of |
| 4203 | * the queue of pending events. |
| 4204 | */ |
| 4205 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 4206 | super(next); |
| 4207 | mTraceCounter = traceCounter; |
| 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * Marks the event as deferred, which is to say that it will be handled |
| 4212 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 4213 | * or {@link #finish} later when it is done handling the event. |
| 4214 | */ |
| 4215 | protected void defer(QueuedInputEvent q) { |
| 4216 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 4217 | enqueue(q); |
| 4218 | } |
| 4219 | |
| 4220 | @Override |
| 4221 | protected void forward(QueuedInputEvent q) { |
| 4222 | // Clear the deferred flag. |
| 4223 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 4224 | |
| 4225 | // Fast path if the queue is empty. |
| 4226 | QueuedInputEvent curr = mQueueHead; |
| 4227 | if (curr == null) { |
| 4228 | super.forward(q); |
| 4229 | return; |
| 4230 | } |
| 4231 | |
| 4232 | // Determine whether the event must be serialized behind any others |
| 4233 | // before it can be delivered to the next stage. This is done because |
| 4234 | // deferred events might be handled out of order by the stage. |
| 4235 | final int deviceId = q.mEvent.getDeviceId(); |
| 4236 | QueuedInputEvent prev = null; |
| 4237 | boolean blocked = false; |
| 4238 | while (curr != null && curr != q) { |
| 4239 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 4240 | blocked = true; |
| 4241 | } |
| 4242 | prev = curr; |
| 4243 | curr = curr.mNext; |
| 4244 | } |
| 4245 | |
| 4246 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 4247 | // Note that the event might not yet be in the queue if it was not previously |
| 4248 | // deferred so we will enqueue it if needed. |
| 4249 | if (blocked) { |
| 4250 | if (curr == null) { |
| 4251 | enqueue(q); |
| 4252 | } |
| 4253 | return; |
| 4254 | } |
| 4255 | |
| 4256 | // The event is not blocked. Deliver it immediately. |
| 4257 | if (curr != null) { |
| 4258 | curr = curr.mNext; |
| 4259 | dequeue(q, prev); |
| 4260 | } |
| 4261 | super.forward(q); |
| 4262 | |
| 4263 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 4264 | while (curr != null) { |
| 4265 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 4266 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 4267 | break; |
| 4268 | } |
| 4269 | QueuedInputEvent next = curr.mNext; |
| 4270 | dequeue(curr, prev); |
| 4271 | super.forward(curr); |
| 4272 | curr = next; |
| 4273 | } else { |
| 4274 | prev = curr; |
| 4275 | curr = curr.mNext; |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | |
| 4280 | @Override |
| 4281 | protected void apply(QueuedInputEvent q, int result) { |
| 4282 | if (result == DEFER) { |
| 4283 | defer(q); |
| 4284 | } else { |
| 4285 | super.apply(q, result); |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | private void enqueue(QueuedInputEvent q) { |
| 4290 | if (mQueueTail == null) { |
| 4291 | mQueueHead = q; |
| 4292 | mQueueTail = q; |
| 4293 | } else { |
| 4294 | mQueueTail.mNext = q; |
| 4295 | mQueueTail = q; |
| 4296 | } |
| 4297 | |
| 4298 | mQueueLength += 1; |
| 4299 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4300 | } |
| 4301 | |
| 4302 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 4303 | if (prev == null) { |
| 4304 | mQueueHead = q.mNext; |
| 4305 | } else { |
| 4306 | prev.mNext = q.mNext; |
| 4307 | } |
| 4308 | if (mQueueTail == q) { |
| 4309 | mQueueTail = prev; |
| 4310 | } |
| 4311 | q.mNext = null; |
| 4312 | |
| 4313 | mQueueLength -= 1; |
| 4314 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 4315 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 4316 | |
| 4317 | @Override |
| 4318 | void dump(String prefix, PrintWriter writer) { |
| 4319 | writer.print(prefix); |
| 4320 | writer.print(getClass().getName()); |
| 4321 | writer.print(": mQueueLength="); |
| 4322 | writer.println(mQueueLength); |
| 4323 | |
| 4324 | super.dump(prefix, writer); |
| 4325 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /** |
| 4329 | * Delivers pre-ime input events to a native activity. |
| 4330 | * Does not support pointer events. |
| 4331 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4332 | final class NativePreImeInputStage extends AsyncInputStage |
| 4333 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4334 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4335 | super(next, traceCounter); |
| 4336 | } |
| 4337 | |
| 4338 | @Override |
| 4339 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4340 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4341 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4342 | return DEFER; |
| 4343 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4344 | return FORWARD; |
| 4345 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4346 | |
| 4347 | @Override |
| 4348 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4349 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4350 | if (handled) { |
| 4351 | finish(q, true); |
| 4352 | return; |
| 4353 | } |
| 4354 | forward(q); |
| 4355 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * Delivers pre-ime input events to the view hierarchy. |
| 4360 | * Does not support pointer events. |
| 4361 | */ |
| 4362 | final class ViewPreImeInputStage extends InputStage { |
| 4363 | public ViewPreImeInputStage(InputStage next) { |
| 4364 | super(next); |
| 4365 | } |
| 4366 | |
| 4367 | @Override |
| 4368 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4369 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4370 | return processKeyEvent(q); |
| 4371 | } |
| 4372 | return FORWARD; |
| 4373 | } |
| 4374 | |
| 4375 | private int processKeyEvent(QueuedInputEvent q) { |
| 4376 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4377 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4378 | return FINISH_HANDLED; |
| 4379 | } |
| 4380 | return FORWARD; |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * Delivers input events to the ime. |
| 4386 | * Does not support pointer events. |
| 4387 | */ |
| 4388 | final class ImeInputStage extends AsyncInputStage |
| 4389 | implements InputMethodManager.FinishedInputEventCallback { |
| 4390 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4391 | super(next, traceCounter); |
| 4392 | } |
| 4393 | |
| 4394 | @Override |
| 4395 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4396 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4397 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4398 | if (imm != null) { |
| 4399 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4400 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4401 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4402 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4403 | return FINISH_HANDLED; |
| 4404 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4405 | // The IME could not handle it, so skip along to the next InputStage |
| 4406 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4407 | } else { |
| 4408 | return DEFER; // callback will be invoked later |
| 4409 | } |
| 4410 | } |
| 4411 | } |
| 4412 | return FORWARD; |
| 4413 | } |
| 4414 | |
| 4415 | @Override |
| 4416 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4417 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4418 | if (handled) { |
| 4419 | finish(q, true); |
| 4420 | return; |
| 4421 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4422 | forward(q); |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * Performs early processing of post-ime input events. |
| 4428 | */ |
| 4429 | final class EarlyPostImeInputStage extends InputStage { |
| 4430 | public EarlyPostImeInputStage(InputStage next) { |
| 4431 | super(next); |
| 4432 | } |
| 4433 | |
| 4434 | @Override |
| 4435 | protected int onProcess(QueuedInputEvent q) { |
| 4436 | if (q.mEvent instanceof KeyEvent) { |
| 4437 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4438 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4439 | final int source = q.mEvent.getSource(); |
| 4440 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4441 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4442 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4443 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4444 | return FORWARD; |
| 4445 | } |
| 4446 | |
| 4447 | private int processKeyEvent(QueuedInputEvent q) { |
| 4448 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4449 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4450 | if (mAttachInfo.mTooltipHost != null) { |
| 4451 | mAttachInfo.mTooltipHost.handleTooltipKey(event); |
| 4452 | } |
| 4453 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4454 | // If the key's purpose is to exit touch mode then we consume it |
| 4455 | // and consider it handled. |
| 4456 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4457 | return FINISH_HANDLED; |
| 4458 | } |
| 4459 | |
| 4460 | // Make sure the fallback event policy sees all keys that will be |
| 4461 | // delivered to the view hierarchy. |
| 4462 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4463 | return FORWARD; |
| 4464 | } |
| 4465 | |
| 4466 | private int processPointerEvent(QueuedInputEvent q) { |
| 4467 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4468 | |
| 4469 | // Translate the pointer event for compatibility, if needed. |
| 4470 | if (mTranslator != null) { |
| 4471 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4472 | } |
| 4473 | |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4474 | // Enter touch mode on down or scroll, if it is coming from a touch screen device, |
| 4475 | // exit otherwise. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4476 | final int action = event.getAction(); |
Vladislav Kaznacheev | 7614cdf | 2017-02-21 11:57:59 -0800 | [diff] [blame] | 4477 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4478 | ensureTouchMode(event.isFromSource(InputDevice.SOURCE_TOUCHSCREEN)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4479 | } |
| 4480 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4481 | if (action == MotionEvent.ACTION_DOWN && mAttachInfo.mTooltipHost != null) { |
| 4482 | mAttachInfo.mTooltipHost.hideTooltip(); |
| 4483 | } |
| 4484 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4485 | // Offset the scroll position. |
| 4486 | if (mCurScrollY != 0) { |
| 4487 | event.offsetLocation(0, mCurScrollY); |
| 4488 | } |
| 4489 | |
| 4490 | // Remember the touch position for possible drag-initiation. |
| 4491 | if (event.isTouchEvent()) { |
| 4492 | mLastTouchPoint.x = event.getRawX(); |
| 4493 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4494 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4495 | } |
| 4496 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4497 | } |
| 4498 | } |
| 4499 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4500 | /** |
| 4501 | * Delivers post-ime input events to a native activity. |
| 4502 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4503 | final class NativePostImeInputStage extends AsyncInputStage |
| 4504 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4505 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4506 | super(next, traceCounter); |
| 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4511 | if (mInputQueue != null) { |
| 4512 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4513 | return DEFER; |
| 4514 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4515 | return FORWARD; |
| 4516 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4517 | |
| 4518 | @Override |
| 4519 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4520 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4521 | if (handled) { |
| 4522 | finish(q, true); |
| 4523 | return; |
| 4524 | } |
| 4525 | forward(q); |
| 4526 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /** |
| 4530 | * Delivers post-ime input events to the view hierarchy. |
| 4531 | */ |
| 4532 | final class ViewPostImeInputStage extends InputStage { |
| 4533 | public ViewPostImeInputStage(InputStage next) { |
| 4534 | super(next); |
| 4535 | } |
| 4536 | |
| 4537 | @Override |
| 4538 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4539 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4540 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4541 | } else { |
| 4542 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4543 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4544 | return processPointerEvent(q); |
| 4545 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4546 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4547 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4548 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4549 | } |
| 4550 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4551 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4552 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4553 | @Override |
| 4554 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4555 | if (mUnbufferedInputDispatch |
| 4556 | && q.mEvent instanceof MotionEvent |
| 4557 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4558 | && isTerminalInputEvent(q.mEvent)) { |
| 4559 | mUnbufferedInputDispatch = false; |
| 4560 | scheduleConsumeBatchedInput(); |
| 4561 | } |
| 4562 | super.onDeliverToNext(q); |
| 4563 | } |
| 4564 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4565 | private boolean performFocusNavigation(KeyEvent event) { |
| 4566 | int direction = 0; |
| 4567 | switch (event.getKeyCode()) { |
| 4568 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4569 | if (event.hasNoModifiers()) { |
| 4570 | direction = View.FOCUS_LEFT; |
| 4571 | } |
| 4572 | break; |
| 4573 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4574 | if (event.hasNoModifiers()) { |
| 4575 | direction = View.FOCUS_RIGHT; |
| 4576 | } |
| 4577 | break; |
| 4578 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4579 | if (event.hasNoModifiers()) { |
| 4580 | direction = View.FOCUS_UP; |
| 4581 | } |
| 4582 | break; |
| 4583 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4584 | if (event.hasNoModifiers()) { |
| 4585 | direction = View.FOCUS_DOWN; |
| 4586 | } |
| 4587 | break; |
| 4588 | case KeyEvent.KEYCODE_TAB: |
| 4589 | if (event.hasNoModifiers()) { |
| 4590 | direction = View.FOCUS_FORWARD; |
| 4591 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4592 | direction = View.FOCUS_BACKWARD; |
| 4593 | } |
| 4594 | break; |
| 4595 | } |
| 4596 | if (direction != 0) { |
| 4597 | View focused = mView.findFocus(); |
| 4598 | if (focused != null) { |
| 4599 | View v = focused.focusSearch(direction); |
| 4600 | if (v != null && v != focused) { |
| 4601 | // do the math the get the interesting rect |
| 4602 | // of previous focused into the coord system of |
| 4603 | // newly focused view |
| 4604 | focused.getFocusedRect(mTempRect); |
| 4605 | if (mView instanceof ViewGroup) { |
| 4606 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4607 | focused, mTempRect); |
| 4608 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 4609 | v, mTempRect); |
| 4610 | } |
| 4611 | if (v.requestFocus(direction, mTempRect)) { |
| 4612 | playSoundEffect(SoundEffectConstants |
| 4613 | .getContantForFocusDirection(direction)); |
| 4614 | return true; |
| 4615 | } |
| 4616 | } |
| 4617 | |
| 4618 | // Give the focused view a last chance to handle the dpad key. |
| 4619 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 4620 | return true; |
| 4621 | } |
| 4622 | } else { |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 4623 | if (mView.restoreDefaultFocus()) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4624 | return true; |
| 4625 | } |
| 4626 | } |
| 4627 | } |
| 4628 | return false; |
| 4629 | } |
| 4630 | |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 4631 | private boolean performKeyboardGroupNavigation(int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4632 | final View focused = mView.findFocus(); |
Evan Rosky | 37df2db | 2017-01-24 16:35:52 -0800 | [diff] [blame] | 4633 | if (focused == null && mView.restoreDefaultFocus()) { |
| 4634 | return true; |
| 4635 | } |
| 4636 | View cluster = focused.keyboardNavigationClusterSearch(null, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4637 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 4638 | // Since requestFocus only takes "real" focus directions (and therefore also |
| 4639 | // restoreFocusInCluster), convert forward/backward focus into FOCUS_DOWN. |
| 4640 | int realDirection = direction; |
| 4641 | if (direction == View.FOCUS_FORWARD || direction == View.FOCUS_BACKWARD) { |
| 4642 | realDirection = View.FOCUS_DOWN; |
| 4643 | } |
| 4644 | |
Evan Rosky | 3ac6463 | 2017-02-13 18:04:43 -0800 | [diff] [blame] | 4645 | if (cluster != null && cluster.isRootNamespace()) { |
| 4646 | // the default cluster. Try to find a non-clustered view to focus. |
| 4647 | if (cluster.restoreFocusNotInCluster()) { |
| 4648 | return true; |
| 4649 | } |
| 4650 | // otherwise skip to next actual cluster |
| 4651 | cluster = keyboardNavigationClusterSearch(null, direction); |
| 4652 | } |
| 4653 | |
Evan Rosky | 53fcf11 | 2017-01-26 14:37:55 -0800 | [diff] [blame] | 4654 | if (cluster != null && cluster.restoreFocusInCluster(realDirection)) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4655 | return true; |
| 4656 | } |
| 4657 | |
| 4658 | return false; |
| 4659 | } |
| 4660 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4661 | private int processKeyEvent(QueuedInputEvent q) { |
| 4662 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4663 | |
| 4664 | // Deliver the key to the view hierarchy. |
| 4665 | if (mView.dispatchKeyEvent(event)) { |
| 4666 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4667 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4668 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4669 | if (shouldDropInputEvent(q)) { |
| 4670 | return FINISH_NOT_HANDLED; |
| 4671 | } |
| 4672 | |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 4673 | int groupNavigationDirection = 0; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4674 | |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 4675 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4676 | && event.getKeyCode() == KeyEvent.KEYCODE_TAB) { |
| 4677 | if (KeyEvent.metaStateHasModifiers(event.getMetaState(), KeyEvent.META_META_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 4678 | groupNavigationDirection = View.FOCUS_FORWARD; |
Evan Rosky | 516f9e6 | 2017-01-23 16:43:52 -0800 | [diff] [blame] | 4679 | } else if (KeyEvent.metaStateHasModifiers(event.getMetaState(), |
| 4680 | KeyEvent.META_META_ON | KeyEvent.META_SHIFT_ON)) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 4681 | groupNavigationDirection = View.FOCUS_BACKWARD; |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 4685 | // If a modifier is held, try to interpret the key as a shortcut. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4686 | if (event.getAction() == KeyEvent.ACTION_DOWN |
Peeyush Agarwal | e631e32 | 2016-10-19 11:41:42 +0100 | [diff] [blame] | 4687 | && !KeyEvent.metaStateHasNoModifiers(event.getMetaState()) |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4688 | && event.getRepeatCount() == 0 |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4689 | && !KeyEvent.isModifierKey(event.getKeyCode()) |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 4690 | && groupNavigationDirection == 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4691 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 4692 | return FINISH_HANDLED; |
| 4693 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4694 | if (shouldDropInputEvent(q)) { |
| 4695 | return FINISH_NOT_HANDLED; |
| 4696 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | // Apply the fallback event policy. |
| 4700 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 4701 | return FINISH_HANDLED; |
| 4702 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4703 | if (shouldDropInputEvent(q)) { |
| 4704 | return FINISH_NOT_HANDLED; |
| 4705 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4706 | |
| 4707 | // Handle automatic focus changes. |
| 4708 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
Vadim Tryshev | 311a5b5 | 2017-01-05 18:54:11 -0800 | [diff] [blame] | 4709 | if (groupNavigationDirection != 0) { |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 4710 | if (performKeyboardGroupNavigation(groupNavigationDirection)) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 4711 | return FINISH_HANDLED; |
| 4712 | } |
| 4713 | } else { |
| 4714 | if (performFocusNavigation(event)) { |
| 4715 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | } |
| 4719 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4720 | } |
| 4721 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4722 | private int processPointerEvent(QueuedInputEvent q) { |
| 4723 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4724 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4725 | mAttachInfo.mUnbufferedDispatchRequested = false; |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4726 | mAttachInfo.mHandlingPointerEvent = true; |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4727 | boolean handled = mView.dispatchPointerEvent(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4728 | maybeUpdatePointerIcon(event); |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4729 | maybeUpdateTooltip(event); |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4730 | mAttachInfo.mHandlingPointerEvent = false; |
| 4731 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 4732 | mUnbufferedInputDispatch = true; |
| 4733 | if (mConsumeBatchedInputScheduled) { |
| 4734 | scheduleConsumeBatchedInputImmediately(); |
| 4735 | } |
| 4736 | } |
| 4737 | return handled ? FINISH_HANDLED : FORWARD; |
| 4738 | } |
| 4739 | |
| 4740 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4741 | if (event.getPointerCount() == 1 && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4742 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 4743 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4744 | // Other apps or the window manager may change the icon type outside of |
| 4745 | // this app, therefore the icon type has to be reset on enter/exit event. |
| 4746 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4749 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 4750 | if (!updatePointerIcon(event) && |
| 4751 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4752 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4753 | } |
| 4754 | } |
| 4755 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4756 | } |
| 4757 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4758 | private int processTrackballEvent(QueuedInputEvent q) { |
| 4759 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4760 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 4761 | if (event.isFromSource(InputDevice.SOURCE_MOUSE_RELATIVE)) { |
| 4762 | if (!hasPointerCapture() || mView.dispatchCapturedPointerEvent(event)) { |
| 4763 | return FINISH_HANDLED; |
| 4764 | } |
| 4765 | } |
| 4766 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4767 | if (mView.dispatchTrackballEvent(event)) { |
| 4768 | return FINISH_HANDLED; |
| 4769 | } |
| 4770 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4773 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 4774 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4775 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4776 | // Deliver the event to the view. |
| 4777 | if (mView.dispatchGenericMotionEvent(event)) { |
| 4778 | return FINISH_HANDLED; |
| 4779 | } |
| 4780 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4781 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4784 | private void resetPointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4785 | mPointerIconType = PointerIcon.TYPE_NOT_SPECIFIED; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4786 | updatePointerIcon(event); |
| 4787 | } |
| 4788 | |
| 4789 | private boolean updatePointerIcon(MotionEvent event) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4790 | final int pointerIndex = 0; |
| 4791 | final float x = event.getX(pointerIndex); |
| 4792 | final float y = event.getY(pointerIndex); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4793 | if (mView == null) { |
| 4794 | // E.g. click outside a popup to dismiss it |
| 4795 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 4796 | return false; |
| 4797 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4798 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4799 | // E.g. when moving window divider with mouse |
| 4800 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4801 | return false; |
| 4802 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4803 | final PointerIcon pointerIcon = mView.onResolvePointerIcon(event, pointerIndex); |
| 4804 | final int pointerType = (pointerIcon != null) ? |
| 4805 | pointerIcon.getType() : PointerIcon.TYPE_DEFAULT; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4806 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4807 | if (mPointerIconType != pointerType) { |
| 4808 | mPointerIconType = pointerType; |
Vladislav Kaznacheev | e40fb27 | 2017-01-03 16:45:42 -0800 | [diff] [blame] | 4809 | mCustomPointerIcon = null; |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4810 | if (mPointerIconType != PointerIcon.TYPE_CUSTOM) { |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4811 | InputManager.getInstance().setPointerIconType(pointerType); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4812 | return true; |
| 4813 | } |
| 4814 | } |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 4815 | if (mPointerIconType == PointerIcon.TYPE_CUSTOM && |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4816 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 4817 | mCustomPointerIcon = pointerIcon; |
| 4818 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 4819 | } |
| 4820 | return true; |
| 4821 | } |
| 4822 | |
Vladislav Kaznacheev | f847ee3 | 2016-11-21 14:11:00 -0800 | [diff] [blame] | 4823 | private void maybeUpdateTooltip(MotionEvent event) { |
| 4824 | if (event.getPointerCount() != 1) { |
| 4825 | return; |
| 4826 | } |
| 4827 | final int action = event.getActionMasked(); |
| 4828 | if (action != MotionEvent.ACTION_HOVER_ENTER |
| 4829 | && action != MotionEvent.ACTION_HOVER_MOVE |
| 4830 | && action != MotionEvent.ACTION_HOVER_EXIT) { |
| 4831 | return; |
| 4832 | } |
| 4833 | AccessibilityManager manager = AccessibilityManager.getInstance(mContext); |
| 4834 | if (manager.isEnabled() && manager.isTouchExplorationEnabled()) { |
| 4835 | return; |
| 4836 | } |
| 4837 | if (mView == null) { |
| 4838 | Slog.d(mTag, "maybeUpdateTooltip called after view was removed"); |
| 4839 | return; |
| 4840 | } |
| 4841 | mView.dispatchTooltipHoverEvent(event); |
| 4842 | } |
| 4843 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4844 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4845 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4846 | */ |
| 4847 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4848 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 4849 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 4850 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 4851 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4852 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4853 | |
| 4854 | public SyntheticInputStage() { |
| 4855 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4856 | } |
| 4857 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4858 | @Override |
| 4859 | protected int onProcess(QueuedInputEvent q) { |
| 4860 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 4861 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4862 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4863 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4864 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4865 | mTrackball.process(event); |
| 4866 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4867 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4868 | mJoystick.process(event); |
| 4869 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4870 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4871 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4872 | mTouchNavigation.process(event); |
| 4873 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4874 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4875 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 4876 | mKeyboard.process((KeyEvent)q.mEvent); |
| 4877 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4878 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4879 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4880 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4881 | } |
| 4882 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4883 | @Override |
| 4884 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4885 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 4886 | // Cancel related synthetic events if any prior stage has handled the event. |
| 4887 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4888 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4889 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4890 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4891 | mTrackball.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4892 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4893 | mJoystick.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4894 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4895 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4896 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4897 | } |
| 4898 | } |
| 4899 | } |
| 4900 | super.onDeliverToNext(q); |
| 4901 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4902 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4903 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4904 | /** |
| 4905 | * Creates dpad events from unhandled trackball movements. |
| 4906 | */ |
| 4907 | final class SyntheticTrackballHandler { |
| 4908 | private final TrackballAxis mX = new TrackballAxis(); |
| 4909 | private final TrackballAxis mY = new TrackballAxis(); |
| 4910 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4911 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4912 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4913 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4914 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4915 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4916 | // It has been too long since the last movement, |
| 4917 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4918 | mX.reset(0); |
| 4919 | mY.reset(0); |
| 4920 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | final int action = event.getAction(); |
| 4924 | final int metaState = event.getMetaState(); |
| 4925 | switch (action) { |
| 4926 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4927 | mX.reset(2); |
| 4928 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4929 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4930 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4931 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4932 | InputDevice.SOURCE_KEYBOARD)); |
| 4933 | break; |
| 4934 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4935 | mX.reset(2); |
| 4936 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4937 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4938 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4939 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4940 | InputDevice.SOURCE_KEYBOARD)); |
| 4941 | break; |
| 4942 | } |
| 4943 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4944 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4945 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4946 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4947 | + " / Y=" + mY.position + " step=" |
| 4948 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4949 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4950 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 4951 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4952 | |
| 4953 | // Generate DPAD events based on the trackball movement. |
| 4954 | // We pick the axis that has moved the most as the direction of |
| 4955 | // the DPAD. When we generate DPAD events for one axis, then the |
| 4956 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 4957 | // to slight movements in the trackball when making major movements |
| 4958 | // along the other axis. |
| 4959 | int keycode = 0; |
| 4960 | int movement = 0; |
| 4961 | float accel = 1; |
| 4962 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4963 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4964 | if (movement != 0) { |
| 4965 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 4966 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4967 | accel = mX.acceleration; |
| 4968 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4969 | } |
| 4970 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4971 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4972 | if (movement != 0) { |
| 4973 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 4974 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4975 | accel = mY.acceleration; |
| 4976 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | if (keycode != 0) { |
| 4981 | if (movement < 0) movement = -movement; |
| 4982 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4983 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4984 | + " accelMovement=" + accelMovement |
| 4985 | + " accel=" + accel); |
| 4986 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4987 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4988 | + keycode); |
| 4989 | movement--; |
| 4990 | int repeatCount = accelMovement - movement; |
| 4991 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4992 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 4993 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4994 | InputDevice.SOURCE_KEYBOARD)); |
| 4995 | } |
| 4996 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4997 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4998 | + keycode); |
| 4999 | movement--; |
| 5000 | curTime = SystemClock.uptimeMillis(); |
| 5001 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5002 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 5003 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5004 | InputDevice.SOURCE_KEYBOARD)); |
| 5005 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 5006 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 5007 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 5008 | InputDevice.SOURCE_KEYBOARD)); |
| 5009 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5010 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5011 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5014 | public void cancel(MotionEvent event) { |
| 5015 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 5016 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5017 | // If we reach this, we consumed a trackball event. |
| 5018 | // Because we will not translate the trackball event into a key event, |
| 5019 | // touch mode will not exit, so we exit touch mode here. |
| 5020 | if (mView != null && mAdded) { |
| 5021 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5022 | } |
| 5023 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5024 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5025 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5026 | /** |
| 5027 | * Maintains state information for a single trackball axis, generating |
| 5028 | * discrete (DPAD) movements based on raw trackball motion. |
| 5029 | */ |
| 5030 | static final class TrackballAxis { |
| 5031 | /** |
| 5032 | * The maximum amount of acceleration we will apply. |
| 5033 | */ |
| 5034 | static final float MAX_ACCELERATION = 20; |
| 5035 | |
| 5036 | /** |
| 5037 | * The maximum amount of time (in milliseconds) between events in order |
| 5038 | * for us to consider the user to be doing fast trackball movements, |
| 5039 | * and thus apply an acceleration. |
| 5040 | */ |
| 5041 | static final long FAST_MOVE_TIME = 150; |
| 5042 | |
| 5043 | /** |
| 5044 | * Scaling factor to the time (in milliseconds) between events to how |
| 5045 | * much to multiple/divide the current acceleration. When movement |
| 5046 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 5047 | * FAST_MOVE_TIME it divides it. |
| 5048 | */ |
| 5049 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 5050 | |
| 5051 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 5052 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 5053 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 5054 | |
| 5055 | float position; |
| 5056 | float acceleration = 1; |
| 5057 | long lastMoveTime = 0; |
| 5058 | int step; |
| 5059 | int dir; |
| 5060 | int nonAccelMovement; |
| 5061 | |
| 5062 | void reset(int _step) { |
| 5063 | position = 0; |
| 5064 | acceleration = 1; |
| 5065 | lastMoveTime = 0; |
| 5066 | step = _step; |
| 5067 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5068 | } |
| 5069 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5070 | /** |
| 5071 | * Add trackball movement into the state. If the direction of movement |
| 5072 | * has been reversed, the state is reset before adding the |
| 5073 | * movement (so that you don't have to compensate for any previously |
| 5074 | * collected movement before see the result of the movement in the |
| 5075 | * new direction). |
| 5076 | * |
| 5077 | * @return Returns the absolute value of the amount of movement |
| 5078 | * collected so far. |
| 5079 | */ |
| 5080 | float collect(float off, long time, String axis) { |
| 5081 | long normTime; |
| 5082 | if (off > 0) { |
| 5083 | normTime = (long)(off * FAST_MOVE_TIME); |
| 5084 | if (dir < 0) { |
| 5085 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 5086 | position = 0; |
| 5087 | step = 0; |
| 5088 | acceleration = 1; |
| 5089 | lastMoveTime = 0; |
| 5090 | } |
| 5091 | dir = 1; |
| 5092 | } else if (off < 0) { |
| 5093 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 5094 | if (dir > 0) { |
| 5095 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 5096 | position = 0; |
| 5097 | step = 0; |
| 5098 | acceleration = 1; |
| 5099 | lastMoveTime = 0; |
| 5100 | } |
| 5101 | dir = -1; |
| 5102 | } else { |
| 5103 | normTime = 0; |
| 5104 | } |
| 5105 | |
| 5106 | // The number of milliseconds between each movement that is |
| 5107 | // considered "normal" and will not result in any acceleration |
| 5108 | // or deceleration, scaled by the offset we have here. |
| 5109 | if (normTime > 0) { |
| 5110 | long delta = time - lastMoveTime; |
| 5111 | lastMoveTime = time; |
| 5112 | float acc = acceleration; |
| 5113 | if (delta < normTime) { |
| 5114 | // The user is scrolling rapidly, so increase acceleration. |
| 5115 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 5116 | if (scale > 1) acc *= scale; |
| 5117 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 5118 | + off + " normTime=" + normTime + " delta=" + delta |
| 5119 | + " scale=" + scale + " acc=" + acc); |
| 5120 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 5121 | } else { |
| 5122 | // The user is scrolling slowly, so decrease acceleration. |
| 5123 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 5124 | if (scale > 1) acc /= scale; |
| 5125 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 5126 | + off + " normTime=" + normTime + " delta=" + delta |
| 5127 | + " scale=" + scale + " acc=" + acc); |
| 5128 | acceleration = acc > 1 ? acc : 1; |
| 5129 | } |
| 5130 | } |
| 5131 | position += off; |
| 5132 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 5133 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5134 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5135 | /** |
| 5136 | * Generate the number of discrete movement events appropriate for |
| 5137 | * the currently collected trackball movement. |
| 5138 | * |
| 5139 | * @return Returns the number of discrete movements, either positive |
| 5140 | * or negative, or 0 if there is not enough trackball movement yet |
| 5141 | * for a discrete movement. |
| 5142 | */ |
| 5143 | int generate() { |
| 5144 | int movement = 0; |
| 5145 | nonAccelMovement = 0; |
| 5146 | do { |
| 5147 | final int dir = position >= 0 ? 1 : -1; |
| 5148 | switch (step) { |
| 5149 | // If we are going to execute the first step, then we want |
| 5150 | // to do this as soon as possible instead of waiting for |
| 5151 | // a full movement, in order to make things look responsive. |
| 5152 | case 0: |
| 5153 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 5154 | return movement; |
| 5155 | } |
| 5156 | movement += dir; |
| 5157 | nonAccelMovement += dir; |
| 5158 | step = 1; |
| 5159 | break; |
| 5160 | // If we have generated the first movement, then we need |
| 5161 | // to wait for the second complete trackball motion before |
| 5162 | // generating the second discrete movement. |
| 5163 | case 1: |
| 5164 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 5165 | return movement; |
| 5166 | } |
| 5167 | movement += dir; |
| 5168 | nonAccelMovement += dir; |
| 5169 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 5170 | step = 2; |
| 5171 | break; |
| 5172 | // After the first two, we generate discrete movements |
| 5173 | // consistently with the trackball, applying an acceleration |
| 5174 | // if the trackball is moving quickly. This is a simple |
| 5175 | // acceleration on top of what we already compute based |
| 5176 | // on how quickly the wheel is being turned, to apply |
| 5177 | // a longer increasing acceleration to continuous movement |
| 5178 | // in one direction. |
| 5179 | default: |
| 5180 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 5181 | return movement; |
| 5182 | } |
| 5183 | movement += dir; |
| 5184 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 5185 | float acc = acceleration; |
| 5186 | acc *= 1.1f; |
| 5187 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 5188 | break; |
| 5189 | } |
| 5190 | } while (true); |
| 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | /** |
| 5195 | * Creates dpad events from unhandled joystick movements. |
| 5196 | */ |
| 5197 | final class SyntheticJoystickHandler extends Handler { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5198 | private final static String TAG = "SyntheticJoystickHandler"; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5199 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 5200 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 5201 | |
| 5202 | private int mLastXDirection; |
| 5203 | private int mLastYDirection; |
| 5204 | private int mLastXKeyCode; |
| 5205 | private int mLastYKeyCode; |
| 5206 | |
| 5207 | public SyntheticJoystickHandler() { |
| 5208 | super(true); |
| 5209 | } |
| 5210 | |
| 5211 | @Override |
| 5212 | public void handleMessage(Message msg) { |
| 5213 | switch (msg.what) { |
| 5214 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 5215 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
| 5216 | KeyEvent oldEvent = (KeyEvent)msg.obj; |
| 5217 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 5218 | SystemClock.uptimeMillis(), |
| 5219 | oldEvent.getRepeatCount() + 1); |
| 5220 | if (mAttachInfo.mHasWindowFocus) { |
| 5221 | enqueueInputEvent(e); |
| 5222 | Message m = obtainMessage(msg.what, e); |
| 5223 | m.setAsynchronous(true); |
| 5224 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 5225 | } |
| 5226 | } break; |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5231 | switch(event.getActionMasked()) { |
| 5232 | case MotionEvent.ACTION_CANCEL: |
| 5233 | cancel(event); |
| 5234 | break; |
| 5235 | case MotionEvent.ACTION_MOVE: |
| 5236 | update(event, true); |
| 5237 | break; |
| 5238 | default: |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5239 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5240 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 5243 | private void cancel(MotionEvent event) { |
| 5244 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 5245 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5246 | update(event, false); |
| 5247 | } |
| 5248 | |
| 5249 | private void update(MotionEvent event, boolean synthesizeNewKeys) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5250 | final long time = event.getEventTime(); |
| 5251 | final int metaState = event.getMetaState(); |
| 5252 | final int deviceId = event.getDeviceId(); |
| 5253 | final int source = event.getSource(); |
| 5254 | |
| 5255 | int xDirection = joystickAxisValueToDirection( |
| 5256 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
| 5257 | if (xDirection == 0) { |
| 5258 | xDirection = joystickAxisValueToDirection(event.getX()); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5259 | } |
| 5260 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5261 | int yDirection = joystickAxisValueToDirection( |
| 5262 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
| 5263 | if (yDirection == 0) { |
| 5264 | yDirection = joystickAxisValueToDirection(event.getY()); |
| 5265 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5266 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5267 | if (xDirection != mLastXDirection) { |
| 5268 | if (mLastXKeyCode != 0) { |
| 5269 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5270 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5271 | KeyEvent.ACTION_UP, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5272 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5273 | mLastXKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5276 | mLastXDirection = xDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5277 | |
| 5278 | if (xDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5279 | mLastXKeyCode = xDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5280 | ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT; |
| 5281 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5282 | KeyEvent.ACTION_DOWN, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5283 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 5284 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5285 | Message m = obtainMessage(MSG_ENQUEUE_X_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5286 | m.setAsynchronous(true); |
Michael Wright | b961852 | 2013-04-10 15:20:56 -0700 | [diff] [blame] | 5287 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5288 | } |
| 5289 | } |
| 5290 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5291 | if (yDirection != mLastYDirection) { |
| 5292 | if (mLastYKeyCode != 0) { |
| 5293 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5294 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5295 | KeyEvent.ACTION_UP, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5296 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5297 | mLastYKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5300 | mLastYDirection = yDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5301 | |
| 5302 | if (yDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5303 | mLastYKeyCode = yDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5304 | ? KeyEvent.KEYCODE_DPAD_DOWN : KeyEvent.KEYCODE_DPAD_UP; |
| 5305 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5306 | KeyEvent.ACTION_DOWN, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5307 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 5308 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5309 | Message m = obtainMessage(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5310 | m.setAsynchronous(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5311 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5312 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5313 | } |
| 5314 | } |
| 5315 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5316 | private int joystickAxisValueToDirection(float value) { |
| 5317 | if (value >= 0.5f) { |
| 5318 | return 1; |
| 5319 | } else if (value <= -0.5f) { |
| 5320 | return -1; |
| 5321 | } else { |
| 5322 | return 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5323 | } |
| 5324 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5325 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5326 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5327 | /** |
| 5328 | * Creates dpad events from unhandled touch navigation movements. |
| 5329 | */ |
| 5330 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5331 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 5332 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5333 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5334 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 5335 | // if no resolution information is available from the input system. |
| 5336 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 5337 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5338 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5339 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5340 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5341 | // The nominal distance traveled to move by one unit. |
| 5342 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 5343 | |
| 5344 | // Minimum and maximum fling velocity in ticks per second. |
| 5345 | // The minimum velocity should be set such that we perform enough ticks per |
| 5346 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 5347 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 5348 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 5349 | // probably not be set to anything less than about 4. |
| 5350 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 5351 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 5352 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 5353 | |
| 5354 | // Fling velocity decay factor applied after each new key is emitted. |
| 5355 | // This parameter controls the deceleration and overall duration of the fling. |
| 5356 | // The fling stops automatically when its velocity drops below the minimum |
| 5357 | // fling velocity defined above. |
| 5358 | private static final float FLING_TICK_DECAY = 0.8f; |
| 5359 | |
| 5360 | /* The input device that we are tracking. */ |
| 5361 | |
| 5362 | private int mCurrentDeviceId = -1; |
| 5363 | private int mCurrentSource; |
| 5364 | private boolean mCurrentDeviceSupported; |
| 5365 | |
| 5366 | /* Configuration for the current input device. */ |
| 5367 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5368 | // The scaled tick distance. A movement of this amount should generally translate |
| 5369 | // into a single dpad event in a given direction. |
| 5370 | private float mConfigTickDistance; |
| 5371 | |
| 5372 | // The minimum and maximum scaled fling velocity. |
| 5373 | private float mConfigMinFlingVelocity; |
| 5374 | private float mConfigMaxFlingVelocity; |
| 5375 | |
| 5376 | /* Tracking state. */ |
| 5377 | |
| 5378 | // The velocity tracker for detecting flings. |
| 5379 | private VelocityTracker mVelocityTracker; |
| 5380 | |
| 5381 | // The active pointer id, or -1 if none. |
| 5382 | private int mActivePointerId = -1; |
| 5383 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 5384 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5385 | private float mStartX; |
| 5386 | private float mStartY; |
| 5387 | |
| 5388 | // Most recently observed position. |
| 5389 | private float mLastX; |
| 5390 | private float mLastY; |
| 5391 | |
| 5392 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5393 | private float mAccumulatedX; |
| 5394 | private float mAccumulatedY; |
| 5395 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5396 | // Set to true if any movement was delivered to the app. |
| 5397 | // Implies that tap slop was exceeded. |
| 5398 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5399 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5400 | // The most recently sent key down event. |
| 5401 | // The keycode remains set until the direction changes or a fling ends |
| 5402 | // so that repeated key events may be generated as required. |
| 5403 | private long mPendingKeyDownTime; |
| 5404 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5405 | private int mPendingKeyRepeatCount; |
| 5406 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5407 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5408 | // The current fling velocity while a fling is in progress. |
| 5409 | private boolean mFlinging; |
| 5410 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5411 | |
| 5412 | public SyntheticTouchNavigationHandler() { |
| 5413 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5417 | // Update the current device information. |
| 5418 | final long time = event.getEventTime(); |
| 5419 | final int deviceId = event.getDeviceId(); |
| 5420 | final int source = event.getSource(); |
| 5421 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5422 | finishKeys(time); |
| 5423 | finishTracking(time); |
| 5424 | mCurrentDeviceId = deviceId; |
| 5425 | mCurrentSource = source; |
| 5426 | mCurrentDeviceSupported = false; |
| 5427 | InputDevice device = event.getDevice(); |
| 5428 | if (device != null) { |
| 5429 | // In order to support an input device, we must know certain |
| 5430 | // characteristics about it, such as its size and resolution. |
| 5431 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5432 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5433 | if (xRange != null && yRange != null) { |
| 5434 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5435 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5436 | // Infer the resolution if it not actually known. |
| 5437 | float xRes = xRange.getResolution(); |
| 5438 | if (xRes <= 0) { |
| 5439 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5440 | } |
| 5441 | float yRes = yRange.getResolution(); |
| 5442 | if (yRes <= 0) { |
| 5443 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5444 | } |
| 5445 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5446 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5447 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5448 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5449 | mConfigMinFlingVelocity = |
| 5450 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5451 | mConfigMaxFlingVelocity = |
| 5452 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5453 | |
| 5454 | if (LOCAL_DEBUG) { |
| 5455 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5456 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5457 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5458 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5459 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5460 | } |
| 5461 | } |
| 5462 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5463 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5464 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5465 | return; |
| 5466 | } |
| 5467 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5468 | // Handle the event. |
| 5469 | final int action = event.getActionMasked(); |
| 5470 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5471 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5472 | boolean caughtFling = mFlinging; |
| 5473 | finishKeys(time); |
| 5474 | finishTracking(time); |
| 5475 | mActivePointerId = event.getPointerId(0); |
| 5476 | mVelocityTracker = VelocityTracker.obtain(); |
| 5477 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5478 | mStartX = event.getX(); |
| 5479 | mStartY = event.getY(); |
| 5480 | mLastX = mStartX; |
| 5481 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5482 | mAccumulatedX = 0; |
| 5483 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5484 | |
| 5485 | // If we caught a fling, then pretend that the tap slop has already |
| 5486 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5487 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5488 | break; |
| 5489 | } |
| 5490 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5491 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5492 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5493 | if (mActivePointerId < 0) { |
| 5494 | break; |
| 5495 | } |
| 5496 | final int index = event.findPointerIndex(mActivePointerId); |
| 5497 | if (index < 0) { |
| 5498 | finishKeys(time); |
| 5499 | finishTracking(time); |
| 5500 | break; |
| 5501 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5502 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5503 | mVelocityTracker.addMovement(event); |
| 5504 | final float x = event.getX(index); |
| 5505 | final float y = event.getY(index); |
| 5506 | mAccumulatedX += x - mLastX; |
| 5507 | mAccumulatedY += y - mLastY; |
| 5508 | mLastX = x; |
| 5509 | mLastY = y; |
| 5510 | |
| 5511 | // Consume any accumulated movement so far. |
| 5512 | final int metaState = event.getMetaState(); |
| 5513 | consumeAccumulatedMovement(time, metaState); |
| 5514 | |
| 5515 | // Detect taps and flings. |
| 5516 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 5517 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5518 | // It might be a fling. |
| 5519 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 5520 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 5521 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 5522 | if (!startFling(time, vx, vy)) { |
| 5523 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5524 | } |
| 5525 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5526 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5527 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5528 | break; |
| 5529 | } |
| 5530 | |
| 5531 | case MotionEvent.ACTION_CANCEL: { |
| 5532 | finishKeys(time); |
| 5533 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5534 | break; |
| 5535 | } |
| 5536 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5537 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5538 | |
| 5539 | public void cancel(MotionEvent event) { |
| 5540 | if (mCurrentDeviceId == event.getDeviceId() |
| 5541 | && mCurrentSource == event.getSource()) { |
| 5542 | final long time = event.getEventTime(); |
| 5543 | finishKeys(time); |
| 5544 | finishTracking(time); |
| 5545 | } |
| 5546 | } |
| 5547 | |
| 5548 | private void finishKeys(long time) { |
| 5549 | cancelFling(); |
| 5550 | sendKeyUp(time); |
| 5551 | } |
| 5552 | |
| 5553 | private void finishTracking(long time) { |
| 5554 | if (mActivePointerId >= 0) { |
| 5555 | mActivePointerId = -1; |
| 5556 | mVelocityTracker.recycle(); |
| 5557 | mVelocityTracker = null; |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 5562 | final float absX = Math.abs(mAccumulatedX); |
| 5563 | final float absY = Math.abs(mAccumulatedY); |
| 5564 | if (absX >= absY) { |
| 5565 | if (absX >= mConfigTickDistance) { |
| 5566 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 5567 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 5568 | mAccumulatedY = 0; |
| 5569 | mConsumedMovement = true; |
| 5570 | } |
| 5571 | } else { |
| 5572 | if (absY >= mConfigTickDistance) { |
| 5573 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 5574 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 5575 | mAccumulatedX = 0; |
| 5576 | mConsumedMovement = true; |
| 5577 | } |
| 5578 | } |
| 5579 | } |
| 5580 | |
| 5581 | private float consumeAccumulatedMovement(long time, int metaState, |
| 5582 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 5583 | while (accumulator <= -mConfigTickDistance) { |
| 5584 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 5585 | accumulator += mConfigTickDistance; |
| 5586 | } |
| 5587 | while (accumulator >= mConfigTickDistance) { |
| 5588 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 5589 | accumulator -= mConfigTickDistance; |
| 5590 | } |
| 5591 | return accumulator; |
| 5592 | } |
| 5593 | |
| 5594 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 5595 | if (mPendingKeyCode != keyCode) { |
| 5596 | sendKeyUp(time); |
| 5597 | mPendingKeyDownTime = time; |
| 5598 | mPendingKeyCode = keyCode; |
| 5599 | mPendingKeyRepeatCount = 0; |
| 5600 | } else { |
| 5601 | mPendingKeyRepeatCount += 1; |
| 5602 | } |
| 5603 | mPendingKeyMetaState = metaState; |
| 5604 | |
| 5605 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 5606 | // but it doesn't quite make sense when simulating the events in this way. |
| 5607 | if (LOCAL_DEBUG) { |
| 5608 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 5609 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 5610 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5611 | } |
| 5612 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5613 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 5614 | mPendingKeyMetaState, mCurrentDeviceId, |
| 5615 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 5616 | } |
| 5617 | |
| 5618 | private void sendKeyUp(long time) { |
| 5619 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5620 | if (LOCAL_DEBUG) { |
| 5621 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 5622 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5623 | } |
| 5624 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5625 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 5626 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 5627 | mCurrentSource)); |
| 5628 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | private boolean startFling(long time, float vx, float vy) { |
| 5633 | if (LOCAL_DEBUG) { |
| 5634 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 5635 | + ", min=" + mConfigMinFlingVelocity); |
| 5636 | } |
| 5637 | |
| 5638 | // Flings must be oriented in the same direction as the preceding movements. |
| 5639 | switch (mPendingKeyCode) { |
| 5640 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5641 | if (-vx >= mConfigMinFlingVelocity |
| 5642 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5643 | mFlingVelocity = -vx; |
| 5644 | break; |
| 5645 | } |
| 5646 | return false; |
| 5647 | |
| 5648 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5649 | if (vx >= mConfigMinFlingVelocity |
| 5650 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5651 | mFlingVelocity = vx; |
| 5652 | break; |
| 5653 | } |
| 5654 | return false; |
| 5655 | |
| 5656 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5657 | if (-vy >= mConfigMinFlingVelocity |
| 5658 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5659 | mFlingVelocity = -vy; |
| 5660 | break; |
| 5661 | } |
| 5662 | return false; |
| 5663 | |
| 5664 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 5665 | if (vy >= mConfigMinFlingVelocity |
| 5666 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5667 | mFlingVelocity = vy; |
| 5668 | break; |
| 5669 | } |
| 5670 | return false; |
| 5671 | } |
| 5672 | |
| 5673 | // Post the first fling event. |
| 5674 | mFlinging = postFling(time); |
| 5675 | return mFlinging; |
| 5676 | } |
| 5677 | |
| 5678 | private boolean postFling(long time) { |
| 5679 | // The idea here is to estimate the time when the pointer would have |
| 5680 | // traveled one tick distance unit given the current fling velocity. |
| 5681 | // This effect creates continuity of motion. |
| 5682 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 5683 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 5684 | postAtTime(mFlingRunnable, time + delay); |
| 5685 | if (LOCAL_DEBUG) { |
| 5686 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 5687 | + mFlingVelocity + ", delay=" + delay |
| 5688 | + ", keyCode=" + mPendingKeyCode); |
| 5689 | } |
| 5690 | return true; |
| 5691 | } |
| 5692 | return false; |
| 5693 | } |
| 5694 | |
| 5695 | private void cancelFling() { |
| 5696 | if (mFlinging) { |
| 5697 | removeCallbacks(mFlingRunnable); |
| 5698 | mFlinging = false; |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | private final Runnable mFlingRunnable = new Runnable() { |
| 5703 | @Override |
| 5704 | public void run() { |
| 5705 | final long time = SystemClock.uptimeMillis(); |
| 5706 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 5707 | mFlingVelocity *= FLING_TICK_DECAY; |
| 5708 | if (!postFling(time)) { |
| 5709 | mFlinging = false; |
| 5710 | finishKeys(time); |
| 5711 | } |
| 5712 | } |
| 5713 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5714 | } |
| 5715 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5716 | final class SyntheticKeyboardHandler { |
| 5717 | public void process(KeyEvent event) { |
| 5718 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 5719 | return; |
| 5720 | } |
| 5721 | |
| 5722 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 5723 | final int keyCode = event.getKeyCode(); |
| 5724 | final int metaState = event.getMetaState(); |
| 5725 | |
| 5726 | // Check for fallback actions specified by the key character map. |
| 5727 | KeyCharacterMap.FallbackAction fallbackAction = |
| 5728 | kcm.getFallbackAction(keyCode, metaState); |
| 5729 | if (fallbackAction != null) { |
| 5730 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 5731 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 5732 | event.getDownTime(), event.getEventTime(), |
| 5733 | event.getAction(), fallbackAction.keyCode, |
| 5734 | event.getRepeatCount(), fallbackAction.metaState, |
| 5735 | event.getDeviceId(), event.getScanCode(), |
| 5736 | flags, event.getSource(), null); |
| 5737 | fallbackAction.recycle(); |
| 5738 | enqueueInputEvent(fallbackEvent); |
| 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5743 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5744 | * Returns true if the key is used for keyboard navigation. |
| 5745 | * @param keyEvent The key event. |
| 5746 | * @return True if the key is used for keyboard navigation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5747 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5748 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 5749 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5750 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5751 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5752 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5753 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5754 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5755 | case KeyEvent.KEYCODE_PAGE_UP: |
| 5756 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 5757 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 5758 | case KeyEvent.KEYCODE_MOVE_END: |
| 5759 | case KeyEvent.KEYCODE_TAB: |
| 5760 | case KeyEvent.KEYCODE_SPACE: |
| 5761 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5762 | return true; |
| 5763 | } |
| 5764 | return false; |
| 5765 | } |
| 5766 | |
| 5767 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5768 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5769 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5770 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5771 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5772 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 5773 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5774 | } |
| 5775 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5776 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5777 | * See if the key event means we should leave touch mode (and leave touch mode if so). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5778 | * @param event The key event. |
| 5779 | * @return Whether this key event should be consumed (meaning the act of |
| 5780 | * leaving touch mode alone is considered the event). |
| 5781 | */ |
| 5782 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5783 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5784 | if (!mAttachInfo.mInTouchMode) { |
| 5785 | return false; |
| 5786 | } |
| 5787 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5788 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 5789 | final int action = event.getAction(); |
| 5790 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | return false; |
| 5792 | } |
| 5793 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5794 | // Don't leave touch mode if the IME told us not to. |
| 5795 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 5796 | return false; |
| 5797 | } |
| 5798 | |
| 5799 | // If the key can be used for keyboard navigation then leave touch mode |
| 5800 | // and select a focused view if needed (in ensureTouchMode). |
| 5801 | // When a new focused view is selected, we consume the navigation key because |
| 5802 | // navigation doesn't make much sense unless a view already has focus so |
| 5803 | // the key's purpose is to set focus. |
| 5804 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5805 | return ensureTouchMode(false); |
| 5806 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5807 | |
| 5808 | // If the key can be used for typing then leave touch mode |
| 5809 | // and select a focused view if needed (in ensureTouchMode). |
| 5810 | // Always allow the view to process the typing key. |
| 5811 | if (isTypingKey(event)) { |
| 5812 | ensureTouchMode(false); |
| 5813 | return false; |
| 5814 | } |
| 5815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | return false; |
| 5817 | } |
| 5818 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5819 | /* drag/drop */ |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5820 | void setLocalDragState(Object obj) { |
| 5821 | mLocalDragState = obj; |
| 5822 | } |
| 5823 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5824 | private void handleDragEvent(DragEvent event) { |
| 5825 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 5826 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 5827 | // that back here for ultimate reporting back to the framework. |
| 5828 | if (mView != null && mAdded) { |
| 5829 | final int what = event.mAction; |
| 5830 | |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 5831 | // Cache the drag description when the operation starts, then fill it in |
| 5832 | // on subsequent calls as a convenience |
| 5833 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
| 5834 | mCurrentDragView = null; // Start the current-recipient tracking |
| 5835 | mDragDescription = event.mClipDescription; |
| 5836 | } else { |
Vladislav Kaznacheev | cd84cfa | 2016-07-26 15:17:49 -0700 | [diff] [blame] | 5837 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 5838 | mDragDescription = null; |
| 5839 | } |
Vladislav Kaznacheev | 7fe1f79 | 2016-07-14 17:15:02 -0700 | [diff] [blame] | 5840 | event.mClipDescription = mDragDescription; |
| 5841 | } |
| 5842 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5843 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 5844 | // A direct EXITED event means that the window manager knows we've just crossed |
| 5845 | // a window boundary, so the current drag target within this one must have |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5846 | // just been exited. Send the EXITED notification to the current drag view, if any. |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 5847 | if (View.sCascadedDragDrop) { |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 5848 | mView.dispatchDragEnterExitInPreN(event); |
| 5849 | } |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5850 | setDragFocus(null, event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5851 | } else { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5852 | // For events with a [screen] location, translate into window coordinates |
| 5853 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 5854 | mDragPoint.set(event.mX, event.mY); |
| 5855 | if (mTranslator != null) { |
| 5856 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 5857 | } |
| 5858 | |
| 5859 | if (mCurScrollY != 0) { |
| 5860 | mDragPoint.offset(0, mCurScrollY); |
| 5861 | } |
| 5862 | |
| 5863 | event.mX = mDragPoint.x; |
| 5864 | event.mY = mDragPoint.y; |
| 5865 | } |
| 5866 | |
| 5867 | // Remember who the current drag target is pre-dispatch |
| 5868 | final View prevDragView = mCurrentDragView; |
| 5869 | |
Vadim Tryshev | 6973317 | 2016-09-30 17:25:30 -0700 | [diff] [blame] | 5870 | if (what == DragEvent.ACTION_DROP && event.mClipData != null) { |
| 5871 | event.mClipData.prepareToEnterProcess(); |
Vladislav Kaznacheev | 854d3f2 | 2016-08-11 10:19:36 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5874 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5875 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5876 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5877 | if (what == DragEvent.ACTION_DRAG_LOCATION && !event.mEventHandlerWasCalled) { |
| 5878 | // If the LOCATION event wasn't delivered to any handler, no view now has a drag |
| 5879 | // focus. |
| 5880 | setDragFocus(null, event); |
| 5881 | } |
| 5882 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5883 | // If we changed apparent drag target, tell the OS about it |
| 5884 | if (prevDragView != mCurrentDragView) { |
| 5885 | try { |
| 5886 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5887 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5888 | } |
| 5889 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5890 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5891 | } |
| 5892 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5893 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5894 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5895 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5896 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5897 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5898 | if (what == DragEvent.ACTION_DROP) { |
| 5899 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5900 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5901 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5902 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5903 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5904 | } |
| 5905 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5906 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5907 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5908 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5909 | mCurrentDragView = null; |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5910 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5911 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 5912 | if (mAttachInfo.mDragSurface != null) { |
| 5913 | mAttachInfo.mDragSurface.release(); |
| 5914 | mAttachInfo.mDragSurface = null; |
| 5915 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5916 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5917 | } |
| 5918 | } |
| 5919 | event.recycle(); |
| 5920 | } |
| 5921 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5922 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 5923 | if (mSeq != args.seq) { |
| 5924 | // The sequence has changed, so we need to update our value and make |
| 5925 | // sure to do a traversal afterward so the window manager is given our |
| 5926 | // most recent data. |
| 5927 | mSeq = args.seq; |
| 5928 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5929 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 5930 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5931 | if (mView == null) return; |
| 5932 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5933 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5934 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5935 | |
| 5936 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5937 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 5938 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 5939 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5940 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5941 | } |
| 5942 | |
Phil Weaver | 964c68e | 2016-10-27 16:22:05 -0700 | [diff] [blame] | 5943 | /** |
| 5944 | * Notify that the window title changed |
| 5945 | */ |
| 5946 | public void onWindowTitleChanged() { |
| 5947 | mAttachInfo.mForceReportNewAttributes = true; |
| 5948 | } |
| 5949 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 5950 | public void handleDispatchWindowShown() { |
| 5951 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 5952 | } |
| 5953 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5954 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5955 | Bundle data = new Bundle(); |
| 5956 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 5957 | if (mView != null) { |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 5958 | mView.requestKeyboardShortcuts(list, deviceId); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5959 | } |
| 5960 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 5961 | try { |
| 5962 | receiver.send(0, data); |
| 5963 | } catch (RemoteException e) { |
| 5964 | } |
| 5965 | } |
| 5966 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5967 | public void getLastTouchPoint(Point outLocation) { |
| 5968 | outLocation.x = (int) mLastTouchPoint.x; |
| 5969 | outLocation.y = (int) mLastTouchPoint.y; |
| 5970 | } |
| 5971 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 5972 | public int getLastTouchSource() { |
| 5973 | return mLastTouchSource; |
| 5974 | } |
| 5975 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5976 | public void setDragFocus(View newDragTarget, DragEvent event) { |
Vadim Tryshev | 45bee6b | 2016-09-19 11:00:37 -0700 | [diff] [blame] | 5977 | if (mCurrentDragView != newDragTarget && !View.sCascadedDragDrop) { |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5978 | // Send EXITED and ENTERED notifications to the old and new drag focus views. |
| 5979 | |
| 5980 | final float tx = event.mX; |
| 5981 | final float ty = event.mY; |
| 5982 | final int action = event.mAction; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 5983 | final ClipData td = event.mClipData; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5984 | // Position should not be available for ACTION_DRAG_ENTERED and ACTION_DRAG_EXITED. |
| 5985 | event.mX = 0; |
| 5986 | event.mY = 0; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 5987 | event.mClipData = null; |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5988 | |
| 5989 | if (mCurrentDragView != null) { |
| 5990 | event.mAction = DragEvent.ACTION_DRAG_EXITED; |
| 5991 | mCurrentDragView.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5992 | } |
| 5993 | |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5994 | if (newDragTarget != null) { |
| 5995 | event.mAction = DragEvent.ACTION_DRAG_ENTERED; |
| 5996 | newDragTarget.callDragEventHandler(event); |
Vadim Tryshev | 1edc6daf | 2016-09-15 16:19:15 -0700 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | event.mAction = action; |
| 6000 | event.mX = tx; |
| 6001 | event.mY = ty; |
Vadim Tryshev | a61efa4 | 2016-09-28 15:15:52 -0700 | [diff] [blame] | 6002 | event.mClipData = td; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6003 | } |
Vadim Tryshev | ef12811 | 2016-09-16 14:05:53 -0700 | [diff] [blame] | 6004 | |
| 6005 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6006 | } |
| 6007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6008 | private AudioManager getAudioManager() { |
| 6009 | if (mView == null) { |
| 6010 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 6011 | } |
| 6012 | if (mAudioManager == null) { |
| 6013 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 6014 | } |
| 6015 | return mAudioManager; |
| 6016 | } |
| 6017 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6018 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 6019 | if (mView == null) { |
| 6020 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 6021 | + " called when there is no mView"); |
| 6022 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6023 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6024 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6025 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 6026 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6027 | } |
| 6028 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6029 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 6030 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6031 | |
| 6032 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6033 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6034 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6035 | restore = true; |
| 6036 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6037 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6038 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6039 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6040 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6041 | } |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6042 | mPendingMergedConfiguration.getMergedConfiguration().seq = 0; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6043 | //Log.d(mTag, ">>>>>> CALLING relayout"); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 6044 | if (params != null && mOrigWindowType != params.type) { |
| 6045 | // For compatibility with old apps, don't crash here. |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6046 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6047 | Slog.w(mTag, "Window type can not be changed after " |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 6048 | + "the window is added; ignoring change of " + mView); |
| 6049 | params.type = mOrigWindowType; |
| 6050 | } |
| 6051 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6052 | int relayoutResult = mWindowSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6053 | mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 6054 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
| 6055 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6056 | viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6057 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6058 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, |
| 6059 | mPendingMergedConfiguration, mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6060 | |
| 6061 | mPendingAlwaysConsumeNavBar = |
| 6062 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 6063 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6064 | //Log.d(mTag, "<<<<<< BACK FROM relayout"); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6065 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 6066 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 6067 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6068 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6069 | if (mTranslator != null) { |
| 6070 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6071 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6072 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 6073 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6074 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6075 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 6076 | return relayoutResult; |
| 6077 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6078 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6079 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6080 | * {@inheritDoc} |
| 6081 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6082 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6083 | public void playSoundEffect(int effectId) { |
| 6084 | checkThread(); |
| 6085 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6086 | try { |
| 6087 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6088 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6089 | switch (effectId) { |
| 6090 | case SoundEffectConstants.CLICK: |
| 6091 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 6092 | return; |
| 6093 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 6094 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 6095 | return; |
| 6096 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 6097 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 6098 | return; |
| 6099 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 6100 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 6101 | return; |
| 6102 | case SoundEffectConstants.NAVIGATION_UP: |
| 6103 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 6104 | return; |
| 6105 | default: |
| 6106 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 6107 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 6108 | } |
| 6109 | } catch (IllegalStateException e) { |
| 6110 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6111 | Log.e(mTag, "FATAL EXCEPTION when attempting to play sound effect: " + e); |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 6112 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | } |
| 6114 | } |
| 6115 | |
| 6116 | /** |
| 6117 | * {@inheritDoc} |
| 6118 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6119 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 6121 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6122 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | } catch (RemoteException e) { |
| 6124 | return false; |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | /** |
| 6129 | * {@inheritDoc} |
| 6130 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6131 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | public View focusSearch(View focused, int direction) { |
| 6133 | checkThread(); |
| 6134 | if (!(mView instanceof ViewGroup)) { |
| 6135 | return null; |
| 6136 | } |
| 6137 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 6138 | } |
| 6139 | |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6140 | /** |
| 6141 | * {@inheritDoc} |
| 6142 | */ |
| 6143 | @Override |
Evan Rosky | 5722331 | 2017-02-08 14:42:45 -0800 | [diff] [blame] | 6144 | public View keyboardNavigationClusterSearch(View currentCluster, |
| 6145 | @FocusDirection int direction) { |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6146 | checkThread(); |
Vadim Tryshev | b5ced22 | 2017-01-17 19:31:35 -0800 | [diff] [blame] | 6147 | return FocusFinder.getInstance().findNextKeyboardNavigationCluster( |
| 6148 | mView, currentCluster, direction); |
Vadim Tryshev | 01b0c9e | 2016-11-21 15:25:01 -0800 | [diff] [blame] | 6149 | } |
| 6150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6151 | public void debug() { |
| 6152 | mView.debug(); |
| 6153 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6154 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6155 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 6156 | String innerPrefix = prefix + " "; |
| 6157 | writer.print(prefix); writer.println("ViewRoot:"); |
| 6158 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 6159 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 6160 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 6161 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6162 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 6163 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6164 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 6165 | writer.println(mPendingInputEventCount); |
| 6166 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 6167 | writer.println(mProcessInputEventsScheduled); |
| 6168 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 6169 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 6170 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 6171 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 6172 | if (mTraversalScheduled) { |
| 6173 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 6174 | } else { |
| 6175 | writer.println(); |
| 6176 | } |
| 6177 | mFirstInputStage.dump(innerPrefix, writer); |
| 6178 | |
| 6179 | mChoreographer.dump(prefix, writer); |
| 6180 | |
| 6181 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 6182 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 6183 | } |
| 6184 | |
| 6185 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 6186 | writer.print(prefix); |
| 6187 | if (view == null) { |
| 6188 | writer.println("null"); |
| 6189 | return; |
| 6190 | } |
| 6191 | writer.println(view.toString()); |
| 6192 | if (!(view instanceof ViewGroup)) { |
| 6193 | return; |
| 6194 | } |
| 6195 | ViewGroup grp = (ViewGroup)view; |
| 6196 | final int N = grp.getChildCount(); |
| 6197 | if (N <= 0) { |
| 6198 | return; |
| 6199 | } |
| 6200 | prefix = prefix + " "; |
| 6201 | for (int i=0; i<N; i++) { |
| 6202 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 6203 | } |
| 6204 | } |
| 6205 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6206 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 6207 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6208 | if (mView != null) { |
| 6209 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6213 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6214 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6215 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 6216 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 6217 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
| 6220 | if (view instanceof ViewGroup) { |
| 6221 | ViewGroup group = (ViewGroup) view; |
| 6222 | |
| 6223 | int count = group.getChildCount(); |
| 6224 | for (int i = 0; i < count; i++) { |
| 6225 | getGfxInfo(group.getChildAt(i), info); |
| 6226 | } |
| 6227 | } |
| 6228 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6230 | /** |
| 6231 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 6232 | * @return True, request has been queued. False, request has been completed. |
| 6233 | */ |
| 6234 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 6235 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 6236 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 6237 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6238 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6239 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6240 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6241 | |
| 6242 | if (!mIsDrawing) { |
| 6243 | destroyHardwareRenderer(); |
| 6244 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6245 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6246 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 6247 | } |
| 6248 | mHandler.sendEmptyMessage(MSG_DIE); |
| 6249 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6253 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6254 | if (LOCAL_LOGV) Log.v(mTag, "DIE in " + this + " of " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6255 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6256 | if (mRemoved) { |
| 6257 | return; |
| 6258 | } |
| 6259 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6260 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 6261 | dispatchDetachedFromWindow(); |
| 6262 | } |
| 6263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6265 | destroyHardwareRenderer(); |
| 6266 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6267 | if (mView != null) { |
| 6268 | int viewVisibility = mView.getVisibility(); |
| 6269 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 6270 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 6271 | // If layout params have been changed, first give them |
| 6272 | // to the window manager to make sure it has the correct |
| 6273 | // animation info. |
| 6274 | try { |
| 6275 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6276 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 6277 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6278 | } |
| 6279 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6281 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 6282 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6283 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6284 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 6286 | |
| 6287 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6288 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 6289 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | } |
| 6291 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6292 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6293 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 6294 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 6295 | } |
| 6296 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6297 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6298 | mHandler.post(new Runnable() { |
| 6299 | @Override |
| 6300 | public void run() { |
| 6301 | // Profiling |
| 6302 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 6303 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 6304 | |
| 6305 | // Hardware rendering |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6306 | if (mAttachInfo.mThreadedRenderer != null) { |
| 6307 | if (mAttachInfo.mThreadedRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6308 | invalidate(); |
| 6309 | } |
| 6310 | } |
| 6311 | |
| 6312 | // Layout debugging |
| 6313 | boolean layout = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); |
| 6314 | if (layout != mAttachInfo.mDebugLayout) { |
| 6315 | mAttachInfo.mDebugLayout = layout; |
| 6316 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 6317 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 6318 | } |
| 6319 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6320 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 6321 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 6322 | } |
| 6323 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6324 | private void destroyHardwareRenderer() { |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6325 | ThreadedRenderer hardwareRenderer = mAttachInfo.mThreadedRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6326 | |
| 6327 | if (hardwareRenderer != null) { |
| 6328 | if (mView != null) { |
| 6329 | hardwareRenderer.destroyHardwareResources(mView); |
| 6330 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 6331 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 6332 | hardwareRenderer.setRequested(false); |
| 6333 | |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 6334 | mAttachInfo.mThreadedRenderer = null; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6335 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6339 | private void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6340 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6341 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6342 | boolean alwaysConsumeNavBar, int displayId) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6343 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6344 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6345 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 6346 | + " reportDraw=" + reportDraw |
| 6347 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6348 | |
| 6349 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 6350 | // updated as fast as possible on a separate thread, |
| 6351 | if (mDragResizing) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6352 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6353 | synchronized (mWindowCallbacks) { |
| 6354 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 6355 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 6356 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6361 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6362 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6363 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6364 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 6365 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 6366 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 6367 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6368 | SomeArgs args = SomeArgs.obtain(); |
| 6369 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 6370 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 6371 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 6372 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 6373 | args.arg4 = sameProcessCall && mergedConfiguration != null |
| 6374 | ? new MergedConfiguration(mergedConfiguration) : null; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6375 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 6376 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6377 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 6378 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6379 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6380 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 6381 | args.argi3 = displayId; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 6382 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6383 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6384 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 6385 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6386 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6387 | if (DEBUG_LAYOUT) Log.v(mTag, "Window moved " + this + ": newX=" + newX + " newY=" + newY); |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6388 | if (mTranslator != null) { |
| 6389 | PointF point = new PointF(newX, newY); |
| 6390 | mTranslator.translatePointInScreenToAppWindow(point); |
| 6391 | newX = (int) (point.x + 0.5); |
| 6392 | newY = (int) (point.y + 0.5); |
| 6393 | } |
| 6394 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 6395 | mHandler.sendMessage(msg); |
| 6396 | } |
| 6397 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6398 | /** |
| 6399 | * Represents a pending input event that is waiting in a queue. |
| 6400 | * |
| 6401 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 6402 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6403 | * one input event to the application at a time and waits for the application |
| 6404 | * to finish handling it before delivering the next one. |
| 6405 | * |
| 6406 | * However, because the application or IME can synthesize and inject multiple |
| 6407 | * key events at a time without going through the input dispatcher, we end up |
| 6408 | * needing a queue on the application's side. |
| 6409 | */ |
| 6410 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6411 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 6412 | public static final int FLAG_DEFERRED = 1 << 1; |
| 6413 | public static final int FLAG_FINISHED = 1 << 2; |
| 6414 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 6415 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6416 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6417 | |
| 6418 | public QueuedInputEvent mNext; |
| 6419 | |
| 6420 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6421 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6422 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6423 | |
| 6424 | public boolean shouldSkipIme() { |
| 6425 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 6426 | return true; |
| 6427 | } |
| 6428 | return mEvent instanceof MotionEvent |
Prashant Malani | fecbc67 | 2016-07-22 15:38:05 -0700 | [diff] [blame] | 6429 | && (mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) |
| 6430 | || mEvent.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6431 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6432 | |
| 6433 | public boolean shouldSendToSynthesizer() { |
| 6434 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 6435 | return true; |
| 6436 | } |
| 6437 | |
| 6438 | return false; |
| 6439 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 6440 | |
| 6441 | @Override |
| 6442 | public String toString() { |
| 6443 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 6444 | boolean hasPrevious = false; |
| 6445 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 6446 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 6447 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 6448 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 6449 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 6450 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 6451 | if (!hasPrevious) { |
| 6452 | sb.append("0"); |
| 6453 | } |
| 6454 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 6455 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 6456 | sb.append(", mEvent=" + mEvent + "}"); |
| 6457 | return sb.toString(); |
| 6458 | } |
| 6459 | |
| 6460 | private boolean flagToString(String name, int flag, |
| 6461 | boolean hasPrevious, StringBuilder sb) { |
| 6462 | if ((mFlags & flag) != 0) { |
| 6463 | if (hasPrevious) { |
| 6464 | sb.append("|"); |
| 6465 | } |
| 6466 | sb.append(name); |
| 6467 | return true; |
| 6468 | } |
| 6469 | return hasPrevious; |
| 6470 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6474 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6475 | QueuedInputEvent q = mQueuedInputEventPool; |
| 6476 | if (q != null) { |
| 6477 | mQueuedInputEventPoolSize -= 1; |
| 6478 | mQueuedInputEventPool = q.mNext; |
| 6479 | q.mNext = null; |
| 6480 | } else { |
| 6481 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6482 | } |
| 6483 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6484 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6485 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6486 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6487 | return q; |
| 6488 | } |
| 6489 | |
| 6490 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 6491 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6492 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6493 | |
| 6494 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 6495 | mQueuedInputEventPoolSize += 1; |
| 6496 | q.mNext = mQueuedInputEventPool; |
| 6497 | mQueuedInputEventPool = q; |
| 6498 | } |
| 6499 | } |
| 6500 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6501 | void enqueueInputEvent(InputEvent event) { |
| 6502 | enqueueInputEvent(event, null, 0, false); |
| 6503 | } |
| 6504 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6505 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6506 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6507 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6508 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6509 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6510 | // Always enqueue the input event in order, regardless of its time stamp. |
| 6511 | // We do this because the application or the IME may inject key events |
| 6512 | // in response to touch events and we want to ensure that the injected keys |
| 6513 | // are processed in the order they were received and we cannot trust that |
| 6514 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6515 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6516 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6517 | mPendingInputEventHead = q; |
| 6518 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6519 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6520 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6521 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6522 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6523 | mPendingInputEventCount += 1; |
| 6524 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6525 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6526 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6527 | if (processImmediately) { |
| 6528 | doProcessInputEvents(); |
| 6529 | } else { |
| 6530 | scheduleProcessInputEvents(); |
| 6531 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6535 | if (!mProcessInputEventsScheduled) { |
| 6536 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6537 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 6538 | msg.setAsynchronous(true); |
| 6539 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6540 | } |
| 6541 | } |
| 6542 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6543 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6544 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6545 | while (mPendingInputEventHead != null) { |
| 6546 | QueuedInputEvent q = mPendingInputEventHead; |
| 6547 | mPendingInputEventHead = q.mNext; |
| 6548 | if (mPendingInputEventHead == null) { |
| 6549 | mPendingInputEventTail = null; |
| 6550 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6551 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6552 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6553 | mPendingInputEventCount -= 1; |
| 6554 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6555 | mPendingInputEventCount); |
| 6556 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 6557 | long eventTime = q.mEvent.getEventTimeNano(); |
| 6558 | long oldestEventTime = eventTime; |
| 6559 | if (q.mEvent instanceof MotionEvent) { |
| 6560 | MotionEvent me = (MotionEvent)q.mEvent; |
| 6561 | if (me.getHistorySize() > 0) { |
| 6562 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 6563 | } |
| 6564 | } |
| 6565 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 6566 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6567 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | // We are done processing all input events that we can process right now |
| 6571 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6572 | if (mProcessInputEventsScheduled) { |
| 6573 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6574 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6575 | } |
| 6576 | } |
| 6577 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6578 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6579 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6580 | q.mEvent.getSequenceNumber()); |
| 6581 | if (mInputEventConsistencyVerifier != null) { |
| 6582 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 6583 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6584 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6585 | InputStage stage; |
| 6586 | if (q.shouldSendToSynthesizer()) { |
| 6587 | stage = mSyntheticInputStage; |
| 6588 | } else { |
| 6589 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 6590 | } |
| 6591 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6592 | if (stage != null) { |
| 6593 | stage.deliver(q); |
| 6594 | } else { |
| 6595 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6596 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6597 | } |
| 6598 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6599 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6600 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6601 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6602 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6603 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6604 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6605 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 6606 | } else { |
| 6607 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6608 | } |
| 6609 | |
| 6610 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6611 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6612 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6613 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6614 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6615 | MotionEvent motion = (MotionEvent) e; |
| 6616 | final int mask = |
| 6617 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 6618 | final int buttonState = motion.getButtonState(); |
| 6619 | final int compatButtonState = (buttonState & mask) >> 4; |
| 6620 | if (compatButtonState != 0) { |
| 6621 | motion.setButtonState(buttonState | compatButtonState); |
| 6622 | } |
| 6623 | } |
| 6624 | } |
| 6625 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6626 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6627 | if (event instanceof KeyEvent) { |
| 6628 | final KeyEvent keyEvent = (KeyEvent)event; |
| 6629 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 6630 | } else { |
| 6631 | final MotionEvent motionEvent = (MotionEvent)event; |
| 6632 | final int action = motionEvent.getAction(); |
| 6633 | return action == MotionEvent.ACTION_UP |
| 6634 | || action == MotionEvent.ACTION_CANCEL |
| 6635 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6636 | } |
| 6637 | } |
| 6638 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6639 | void scheduleConsumeBatchedInput() { |
| 6640 | if (!mConsumeBatchedInputScheduled) { |
| 6641 | mConsumeBatchedInputScheduled = true; |
| 6642 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 6643 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6644 | } |
| 6645 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6646 | |
| 6647 | void unscheduleConsumeBatchedInput() { |
| 6648 | if (mConsumeBatchedInputScheduled) { |
| 6649 | mConsumeBatchedInputScheduled = false; |
| 6650 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 6651 | mConsumedBatchedInputRunnable, null); |
| 6652 | } |
| 6653 | } |
| 6654 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6655 | void scheduleConsumeBatchedInputImmediately() { |
| 6656 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 6657 | unscheduleConsumeBatchedInput(); |
| 6658 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 6659 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 6660 | } |
| 6661 | } |
| 6662 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6663 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6664 | if (mConsumeBatchedInputScheduled) { |
| 6665 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6666 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6667 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 6668 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6669 | // If we consumed a batch here, we want to go ahead and schedule the |
| 6670 | // consumption of batched input events on the next frame. Otherwise, we would |
| 6671 | // wait until we have more input events pending and might get starved by other |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6672 | // things occurring in the process. If the frame time is -1, however, then |
| 6673 | // we're in a non-batching mode, so there's no need to schedule this. |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6674 | scheduleConsumeBatchedInput(); |
| 6675 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6676 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6677 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | final class TraversalRunnable implements Runnable { |
| 6682 | @Override |
| 6683 | public void run() { |
| 6684 | doTraversal(); |
| 6685 | } |
| 6686 | } |
| 6687 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6688 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6689 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 6690 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 6691 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6692 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6693 | |
| 6694 | @Override |
| 6695 | public void onInputEvent(InputEvent event) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6696 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6697 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6698 | |
| 6699 | @Override |
| 6700 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6701 | if (mUnbufferedInputDispatch) { |
| 6702 | super.onBatchedInputEventPending(); |
| 6703 | } else { |
| 6704 | scheduleConsumeBatchedInput(); |
| 6705 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
| 6708 | @Override |
| 6709 | public void dispose() { |
| 6710 | unscheduleConsumeBatchedInput(); |
| 6711 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6712 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6713 | } |
| 6714 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6716 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 6717 | @Override |
| 6718 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6719 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6720 | } |
| 6721 | } |
| 6722 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 6723 | new ConsumeBatchedInputRunnable(); |
| 6724 | boolean mConsumeBatchedInputScheduled; |
| 6725 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6726 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 6727 | @Override |
| 6728 | public void run() { |
| 6729 | doConsumeBatchedInput(-1); |
| 6730 | } |
| 6731 | } |
| 6732 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 6733 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 6734 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 6735 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6736 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 6737 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6738 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 6739 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6740 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 6741 | private View[] mTempViews; |
| 6742 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 6743 | |
| 6744 | public void addView(View view) { |
| 6745 | synchronized (this) { |
| 6746 | mViews.add(view); |
| 6747 | postIfNeededLocked(); |
| 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 6752 | synchronized (this) { |
| 6753 | mViewRects.add(info); |
| 6754 | postIfNeededLocked(); |
| 6755 | } |
| 6756 | } |
| 6757 | |
| 6758 | public void removeView(View view) { |
| 6759 | synchronized (this) { |
| 6760 | mViews.remove(view); |
| 6761 | |
| 6762 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 6763 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 6764 | if (info.target == view) { |
| 6765 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6766 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6771 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6772 | mPosted = false; |
| 6773 | } |
| 6774 | } |
| 6775 | } |
| 6776 | |
| 6777 | @Override |
| 6778 | public void run() { |
| 6779 | final int viewCount; |
| 6780 | final int viewRectCount; |
| 6781 | synchronized (this) { |
| 6782 | mPosted = false; |
| 6783 | |
| 6784 | viewCount = mViews.size(); |
| 6785 | if (viewCount != 0) { |
| 6786 | mTempViews = mViews.toArray(mTempViews != null |
| 6787 | ? mTempViews : new View[viewCount]); |
| 6788 | mViews.clear(); |
| 6789 | } |
| 6790 | |
| 6791 | viewRectCount = mViewRects.size(); |
| 6792 | if (viewRectCount != 0) { |
| 6793 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 6794 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 6795 | mViewRects.clear(); |
| 6796 | } |
| 6797 | } |
| 6798 | |
| 6799 | for (int i = 0; i < viewCount; i++) { |
| 6800 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 6801 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6802 | } |
| 6803 | |
| 6804 | for (int i = 0; i < viewRectCount; i++) { |
| 6805 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 6806 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6807 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6808 | } |
| 6809 | } |
| 6810 | |
| 6811 | private void postIfNeededLocked() { |
| 6812 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6813 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6814 | mPosted = true; |
| 6815 | } |
| 6816 | } |
| 6817 | } |
| 6818 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 6819 | new InvalidateOnAnimationRunnable(); |
| 6820 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6821 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 6822 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 6823 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6824 | } |
| 6825 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6826 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 6827 | long delayMilliseconds) { |
| 6828 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 6829 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6830 | } |
| 6831 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6832 | public void dispatchInvalidateOnAnimation(View view) { |
| 6833 | mInvalidateOnAnimationRunnable.addView(view); |
| 6834 | } |
| 6835 | |
| 6836 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 6837 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 6838 | } |
| 6839 | |
| 6840 | public void cancelInvalidate(View view) { |
| 6841 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 6842 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 6843 | // them to the pool |
| 6844 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 6845 | mInvalidateOnAnimationRunnable.removeView(view); |
| 6846 | } |
| 6847 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 6848 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 6849 | dispatchInputEvent(event, null); |
| 6850 | } |
| 6851 | |
| 6852 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 6853 | SomeArgs args = SomeArgs.obtain(); |
| 6854 | args.arg1 = event; |
| 6855 | args.arg2 = receiver; |
| 6856 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6857 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6858 | mHandler.sendMessage(msg); |
| 6859 | } |
| 6860 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6861 | public void synthesizeInputEvent(InputEvent event) { |
| 6862 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 6863 | msg.setAsynchronous(true); |
| 6864 | mHandler.sendMessage(msg); |
| 6865 | } |
| 6866 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6867 | public void dispatchKeyFromIme(KeyEvent event) { |
| 6868 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6869 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6870 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6871 | } |
| 6872 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6873 | /** |
| 6874 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 6875 | * |
| 6876 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 6877 | * passes in. |
| 6878 | */ |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6879 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6880 | if (event instanceof MotionEvent) { |
| 6881 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6882 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6883 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6884 | } |
| 6885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6886 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6887 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6889 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6893 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 6894 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
| 6898 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6899 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6900 | msg.arg1 = hasFocus ? 1 : 0; |
| 6901 | msg.arg2 = inTouchMode ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6902 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | } |
| 6904 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6905 | public void dispatchWindowShown() { |
| 6906 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 6907 | } |
| 6908 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6909 | public void dispatchCloseSystemDialogs(String reason) { |
| 6910 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6911 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6912 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6913 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6914 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6915 | |
| 6916 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6917 | final int what; |
| 6918 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6919 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 6920 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6921 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6922 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6923 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6924 | Message msg = mHandler.obtainMessage(what, event); |
| 6925 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6926 | } |
| 6927 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 6928 | public void updatePointerIcon(float x, float y) { |
| 6929 | final int what = MSG_UPDATE_POINTER_ICON; |
| 6930 | mHandler.removeMessages(what); |
| 6931 | final long now = SystemClock.uptimeMillis(); |
| 6932 | final MotionEvent event = MotionEvent.obtain( |
| 6933 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 6934 | Message msg = mHandler.obtainMessage(what, event); |
| 6935 | mHandler.sendMessage(msg); |
| 6936 | } |
| 6937 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6938 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6939 | int localValue, int localChanges) { |
| 6940 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 6941 | args.seq = seq; |
| 6942 | args.globalVisibility = globalVisibility; |
| 6943 | args.localValue = localValue; |
| 6944 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6945 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 6946 | } |
| 6947 | |
| 6948 | public void dispatchCheckFocus() { |
| 6949 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 6950 | // This will result in a call to checkFocus() below. |
| 6951 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 6952 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6953 | } |
| 6954 | |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 6955 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 6956 | mHandler.obtainMessage( |
| 6957 | MSG_REQUEST_KEYBOARD_SHORTCUTS, deviceId, 0, receiver).sendToTarget(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6958 | } |
| 6959 | |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 6960 | public void dispatchPointerCaptureChanged(boolean on) { |
| 6961 | final int what = MSG_POINTER_CAPTURE_CHANGED; |
| 6962 | mHandler.removeMessages(what); |
| 6963 | Message msg = mHandler.obtainMessage(what); |
| 6964 | msg.arg1 = on ? 1 : 0; |
| 6965 | mHandler.sendMessage(msg); |
| 6966 | } |
| 6967 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6968 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6969 | * Post a callback to send a |
| 6970 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6971 | * This event is send at most once every |
| 6972 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6973 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6974 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6975 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 6976 | mSendWindowContentChangedAccessibilityEvent = |
| 6977 | new SendWindowContentChangedAccessibilityEvent(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6978 | } |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6979 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
| 6982 | /** |
| 6983 | * Remove a posted callback to send a |
| 6984 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 6985 | */ |
| 6986 | private void removeSendWindowContentChangedCallback() { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6987 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6988 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6989 | } |
| 6990 | } |
| 6991 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6992 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | public boolean showContextMenuForChild(View originalView) { |
| 6994 | return false; |
| 6995 | } |
| 6996 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6997 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 6998 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 6999 | return false; |
| 7000 | } |
| 7001 | |
| 7002 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 7003 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 7004 | return null; |
| 7005 | } |
| 7006 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7007 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 7008 | public ActionMode startActionModeForChild( |
| 7009 | View originalView, ActionMode.Callback callback, int type) { |
| 7010 | return null; |
| 7011 | } |
| 7012 | |
| 7013 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | public void createContextMenu(ContextMenu menu) { |
| 7015 | } |
| 7016 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7017 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | public void childDrawableStateChanged(View child) { |
| 7019 | } |
| 7020 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7021 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7022 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 7023 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7024 | return false; |
| 7025 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7026 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 7027 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7028 | final int eventType = event.getEventType(); |
| 7029 | switch (eventType) { |
| 7030 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7031 | final long sourceNodeId = event.getSourceNodeId(); |
| 7032 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7033 | sourceNodeId); |
| 7034 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7035 | if (source != null) { |
| 7036 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7037 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 7038 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 7039 | sourceNodeId); |
| 7040 | final AccessibilityNodeInfo node; |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7041 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7042 | setAccessibilityFocus(source, node); |
| 7043 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7044 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7045 | } break; |
| 7046 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 7047 | final long sourceNodeId = event.getSourceNodeId(); |
| 7048 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 7049 | sourceNodeId); |
| 7050 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 7051 | if (source != null) { |
| 7052 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 7053 | if (provider != null) { |
| 7054 | setAccessibilityFocus(null, null); |
| 7055 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7056 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7057 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7058 | |
| 7059 | |
| 7060 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7061 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 7062 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 7063 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7064 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 7065 | return true; |
| 7066 | } |
| 7067 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7068 | /** |
| 7069 | * Updates the focused virtual view, when necessary, in response to a |
| 7070 | * content changed event. |
| 7071 | * <p> |
| 7072 | * This is necessary to get updated bounds after a position change. |
| 7073 | * |
| 7074 | * @param event an accessibility event of type |
| 7075 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 7076 | */ |
| 7077 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7078 | final View focusedHost = mAccessibilityFocusedHost; |
| 7079 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 7080 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7081 | return; |
| 7082 | } |
| 7083 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7084 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7085 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7086 | // Error state: virtual view with no provider. Clear focus. |
| 7087 | mAccessibilityFocusedHost = null; |
| 7088 | mAccessibilityFocusedVirtualView = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7089 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7090 | return; |
| 7091 | } |
| 7092 | |
| 7093 | // We only care about change types that may affect the bounds of the |
| 7094 | // focused virtual view. |
| 7095 | final int changes = event.getContentChangeTypes(); |
| 7096 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 7097 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 7098 | return; |
| 7099 | } |
| 7100 | |
| 7101 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 7102 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 7103 | |
| 7104 | // Search up the tree for subtree containment. |
| 7105 | boolean hostInSubtree = false; |
| 7106 | View root = mAccessibilityFocusedHost; |
| 7107 | while (root != null && !hostInSubtree) { |
| 7108 | if (changedViewId == root.getAccessibilityViewId()) { |
| 7109 | hostInSubtree = true; |
| 7110 | } else { |
| 7111 | final ViewParent parent = root.getParent(); |
| 7112 | if (parent instanceof View) { |
| 7113 | root = (View) parent; |
| 7114 | } else { |
| 7115 | root = null; |
| 7116 | } |
| 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | // We care only about changes in subtrees containing the host view. |
| 7121 | if (!hostInSubtree) { |
| 7122 | return; |
| 7123 | } |
| 7124 | |
| 7125 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 7126 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7127 | |
| 7128 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7129 | final Rect oldBounds = mTempRect; |
| 7130 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7131 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7132 | if (mAccessibilityFocusedVirtualView == null) { |
| 7133 | // Error state: The node no longer exists. Clear focus. |
| 7134 | mAccessibilityFocusedHost = null; |
Phil Weaver | e37cfab | 2016-04-07 21:01:57 -0700 | [diff] [blame] | 7135 | focusedHost.clearAccessibilityFocusNoCallbacks(0); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7136 | |
| 7137 | // This will probably fail, but try to keep the provider's internal |
| 7138 | // state consistent by clearing focus. |
| 7139 | provider.performAction(focusedChildId, |
| 7140 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7141 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 7142 | } else { |
| 7143 | // The node was refreshed, invalidate bounds if necessary. |
| 7144 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 7145 | if (!oldBounds.equals(newBounds)) { |
| 7146 | oldBounds.union(newBounds); |
| 7147 | invalidateRectOnScreen(oldBounds); |
| 7148 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 7149 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7152 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7153 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 7154 | postSendWindowContentChangedCallback(source, changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7155 | } |
| 7156 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 7157 | @Override |
| 7158 | public boolean canResolveLayoutDirection() { |
| 7159 | return true; |
| 7160 | } |
| 7161 | |
| 7162 | @Override |
| 7163 | public boolean isLayoutDirectionResolved() { |
| 7164 | return true; |
| 7165 | } |
| 7166 | |
| 7167 | @Override |
| 7168 | public int getLayoutDirection() { |
| 7169 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 7170 | } |
| 7171 | |
| 7172 | @Override |
| 7173 | public boolean canResolveTextDirection() { |
| 7174 | return true; |
| 7175 | } |
| 7176 | |
| 7177 | @Override |
| 7178 | public boolean isTextDirectionResolved() { |
| 7179 | return true; |
| 7180 | } |
| 7181 | |
| 7182 | @Override |
| 7183 | public int getTextDirection() { |
| 7184 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 7185 | } |
| 7186 | |
| 7187 | @Override |
| 7188 | public boolean canResolveTextAlignment() { |
| 7189 | return true; |
| 7190 | } |
| 7191 | |
| 7192 | @Override |
| 7193 | public boolean isTextAlignmentResolved() { |
| 7194 | return true; |
| 7195 | } |
| 7196 | |
| 7197 | @Override |
| 7198 | public int getTextAlignment() { |
| 7199 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 7200 | } |
| 7201 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7202 | private View getCommonPredecessor(View first, View second) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7203 | if (mTempHashSet == null) { |
| 7204 | mTempHashSet = new HashSet<View>(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7205 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7206 | HashSet<View> seen = mTempHashSet; |
| 7207 | seen.clear(); |
| 7208 | View firstCurrent = first; |
| 7209 | while (firstCurrent != null) { |
| 7210 | seen.add(firstCurrent); |
| 7211 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 7212 | if (firstCurrentParent instanceof View) { |
| 7213 | firstCurrent = (View) firstCurrentParent; |
| 7214 | } else { |
| 7215 | firstCurrent = null; |
| 7216 | } |
| 7217 | } |
| 7218 | View secondCurrent = second; |
| 7219 | while (secondCurrent != null) { |
| 7220 | if (seen.contains(secondCurrent)) { |
| 7221 | seen.clear(); |
| 7222 | return secondCurrent; |
| 7223 | } |
| 7224 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 7225 | if (secondCurrentParent instanceof View) { |
| 7226 | secondCurrent = (View) secondCurrentParent; |
| 7227 | } else { |
| 7228 | secondCurrent = null; |
| 7229 | } |
| 7230 | } |
| 7231 | seen.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7232 | return null; |
| 7233 | } |
| 7234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | void checkThread() { |
| 7236 | if (mThread != Thread.currentThread()) { |
| 7237 | throw new CalledFromWrongThreadException( |
| 7238 | "Only the original thread that created a view hierarchy can touch its views."); |
| 7239 | } |
| 7240 | } |
| 7241 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7242 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 7244 | // ViewAncestor never intercepts touch event, so this can be a no-op |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | } |
| 7246 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7247 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7248 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7249 | if (rectangle == null) { |
| 7250 | return scrollToRectOrFocus(null, immediate); |
| 7251 | } |
| 7252 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 7253 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7254 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 7255 | mTempRect.set(rectangle); |
| 7256 | mTempRect.offset(0, -mCurScrollY); |
| 7257 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 7258 | try { |
| 7259 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 7260 | } catch (RemoteException re) { |
| 7261 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 7262 | } |
| 7263 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7265 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7266 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 7267 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 7268 | // Do nothing. |
| 7269 | } |
| 7270 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7271 | @Override |
| 7272 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 7273 | return false; |
| 7274 | } |
| 7275 | |
| 7276 | @Override |
| 7277 | public void onStopNestedScroll(View target) { |
| 7278 | } |
| 7279 | |
| 7280 | @Override |
| 7281 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 7282 | } |
| 7283 | |
| 7284 | @Override |
| 7285 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 7286 | int dxUnconsumed, int dyUnconsumed) { |
| 7287 | } |
| 7288 | |
| 7289 | @Override |
| 7290 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 7291 | } |
| 7292 | |
| 7293 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 7294 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 7295 | return false; |
| 7296 | } |
| 7297 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 7298 | @Override |
| 7299 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 7300 | return false; |
| 7301 | } |
| 7302 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 7303 | @Override |
| 7304 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 7305 | return false; |
| 7306 | } |
| 7307 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 7308 | /** |
| 7309 | * Force the window to report its next draw. |
| 7310 | * <p> |
| 7311 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 7312 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 7313 | * unless you fully understand this interaction. |
| 7314 | * @hide |
| 7315 | */ |
| 7316 | public void setReportNextDraw() { |
| 7317 | mReportNextDraw = true; |
| 7318 | invalidate(); |
| 7319 | } |
| 7320 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7321 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 7322 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
Stan Iliev | 45faba5 | 2016-06-28 13:33:15 -0400 | [diff] [blame] | 7323 | if (mAttachInfo.mThreadedRenderer != null) { |
| 7324 | mAttachInfo.mThreadedRenderer.setOpaque(opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 7325 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 7326 | } |
| 7327 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7328 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 7329 | @Override |
| 7330 | public boolean onAllowLockCanvas() { |
| 7331 | return mDrawingAllowed; |
| 7332 | } |
| 7333 | |
| 7334 | @Override |
| 7335 | public void onRelayoutContainer() { |
| 7336 | // Not currently interesting -- from changing between fixed and layout size. |
| 7337 | } |
| 7338 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7339 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7340 | public void setFormat(int format) { |
| 7341 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 7342 | } |
| 7343 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7344 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7345 | public void setType(int type) { |
| 7346 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 7347 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7348 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7349 | @Override |
| 7350 | public void onUpdateSurface() { |
| 7351 | // We take care of format and type changes on our own. |
| 7352 | throw new IllegalStateException("Shouldn't be here"); |
| 7353 | } |
| 7354 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7355 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7356 | public boolean isCreating() { |
| 7357 | return mIsCreating; |
| 7358 | } |
| 7359 | |
| 7360 | @Override |
| 7361 | public void setFixedSize(int width, int height) { |
| 7362 | throw new UnsupportedOperationException( |
| 7363 | "Currently only support sizing from layout"); |
| 7364 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7365 | |
| 7366 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 7367 | public void setKeepScreenOn(boolean screenOn) { |
| 7368 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 7369 | } |
| 7370 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7373 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7374 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7376 | W(ViewRootImpl viewAncestor) { |
| 7377 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7378 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | } |
| 7380 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7381 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7382 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 7383 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7384 | MergedConfiguration mergedConfiguration, Rect backDropFrame, boolean forceLayout, |
Andrii Kulian | b047b8b | 2017-02-08 18:38:26 -0800 | [diff] [blame] | 7385 | boolean alwaysConsumeNavBar, int displayId) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7386 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7387 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 7388 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 7389 | visibleInsets, stableInsets, outsets, reportDraw, mergedConfiguration, |
| 7390 | backDropFrame, forceLayout, alwaysConsumeNavBar, displayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | } |
| 7392 | } |
| 7393 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 7394 | @Override |
| 7395 | public void moved(int newX, int newY) { |
| 7396 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7397 | if (viewAncestor != null) { |
| 7398 | viewAncestor.dispatchMoved(newX, newY); |
| 7399 | } |
| 7400 | } |
| 7401 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7402 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7403 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7404 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7405 | if (viewAncestor != null) { |
| 7406 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | } |
| 7408 | } |
| 7409 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7410 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7412 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7413 | if (viewAncestor != null) { |
| 7414 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7415 | } |
| 7416 | } |
| 7417 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7418 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7420 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7421 | if (viewAncestor != null) { |
| 7422 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7423 | } |
| 7424 | } |
| 7425 | |
| 7426 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 7428 | return ActivityManager.getService().checkPermission( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 7430 | } catch (RemoteException e) { |
| 7431 | return PackageManager.PERMISSION_DENIED; |
| 7432 | } |
| 7433 | } |
| 7434 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7435 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7437 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7438 | if (viewAncestor != null) { |
| 7439 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7440 | if (view != null) { |
| 7441 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 7442 | PackageManager.PERMISSION_GRANTED) { |
| 7443 | throw new SecurityException("Insufficient permissions to invoke" |
| 7444 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 7445 | + ", uid=" + Binder.getCallingUid()); |
| 7446 | } |
| 7447 | |
| 7448 | OutputStream clientStream = null; |
| 7449 | try { |
| 7450 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 7451 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 7452 | } catch (IOException e) { |
| 7453 | e.printStackTrace(); |
| 7454 | } finally { |
| 7455 | if (clientStream != null) { |
| 7456 | try { |
| 7457 | clientStream.close(); |
| 7458 | } catch (IOException e) { |
| 7459 | e.printStackTrace(); |
| 7460 | } |
| 7461 | } |
| 7462 | } |
| 7463 | } |
| 7464 | } |
| 7465 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7466 | |
| 7467 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7468 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7469 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7470 | if (viewAncestor != null) { |
| 7471 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7472 | } |
| 7473 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7474 | |
| 7475 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7476 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 7477 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7478 | if (sync) { |
| 7479 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7480 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7481 | } catch (RemoteException e) { |
| 7482 | } |
| 7483 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7484 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7485 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7486 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7487 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 7488 | int z, Bundle extras, boolean sync) { |
| 7489 | if (sync) { |
| 7490 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7491 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7492 | } catch (RemoteException e) { |
| 7493 | } |
| 7494 | } |
| 7495 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7496 | |
| 7497 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7498 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7499 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7500 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7501 | if (viewAncestor != null) { |
| 7502 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7503 | } |
| 7504 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7505 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7506 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7507 | public void updatePointerIcon(float x, float y) { |
| 7508 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7509 | if (viewAncestor != null) { |
| 7510 | viewAncestor.updatePointerIcon(x, y); |
| 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7515 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7516 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7517 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7518 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7519 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 7520 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7521 | } |
| 7522 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 7523 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7524 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7525 | public void dispatchWindowShown() { |
| 7526 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7527 | if (viewAncestor != null) { |
| 7528 | viewAncestor.dispatchWindowShown(); |
| 7529 | } |
| 7530 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7531 | |
| 7532 | @Override |
Clara Bayarri | fcd7e80 | 2016-03-10 12:58:18 +0000 | [diff] [blame] | 7533 | public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) { |
| 7534 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7535 | if (viewAncestor != null) { |
| 7536 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver, deviceId); |
| 7537 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7538 | } |
Vladislav Kaznacheev | 3787de1 | 2016-12-21 10:36:35 -0800 | [diff] [blame] | 7539 | |
| 7540 | @Override |
| 7541 | public void dispatchPointerCaptureChanged(boolean hasCapture) { |
| 7542 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7543 | if (viewAncestor != null) { |
| 7544 | viewAncestor.dispatchPointerCaptureChanged(hasCapture); |
| 7545 | } |
| 7546 | } |
| 7547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7548 | } |
| 7549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7550 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
| 7551 | public CalledFromWrongThreadException(String msg) { |
| 7552 | super(msg); |
| 7553 | } |
| 7554 | } |
| 7555 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7556 | static HandlerActionQueue getRunQueue() { |
| 7557 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | if (rq != null) { |
| 7559 | return rq; |
| 7560 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7561 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | sRunQueues.set(rq); |
| 7563 | return rq; |
| 7564 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7567 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 7568 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7569 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
Jorim Jaggi | c39c7b0 | 2016-03-24 10:47:07 -0700 | [diff] [blame] | 7570 | Rect stableInsets, int resizeMode) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7571 | if (!mDragResizing) { |
| 7572 | mDragResizing = true; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7573 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7574 | mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds, fullscreen, |
| 7575 | systemInsets, stableInsets, resizeMode); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7576 | } |
| 7577 | mFullRedrawNeeded = true; |
| 7578 | } |
| 7579 | } |
| 7580 | |
| 7581 | /** |
| 7582 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 7583 | */ |
| 7584 | private void endDragResizing() { |
| 7585 | if (mDragResizing) { |
| 7586 | mDragResizing = false; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7587 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7588 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7589 | } |
| 7590 | mFullRedrawNeeded = true; |
| 7591 | } |
| 7592 | } |
| 7593 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7594 | private boolean updateContentDrawBounds() { |
| 7595 | boolean updated = false; |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7596 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7597 | updated |= mWindowCallbacks.get(i).onContentDrawn( |
| 7598 | mWindowAttributes.surfaceInsets.left, |
| 7599 | mWindowAttributes.surfaceInsets.top, |
| 7600 | mWidth, mHeight); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7601 | } |
| 7602 | return updated | (mDragResizing && mReportNextDraw); |
| 7603 | } |
| 7604 | |
| 7605 | private void requestDrawWindow() { |
| 7606 | if (mReportNextDraw) { |
| 7607 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
| 7608 | } |
Jorim Jaggi | 16b6319 | 2016-03-25 18:32:19 -0700 | [diff] [blame] | 7609 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7610 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7611 | } |
| 7612 | } |
| 7613 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7614 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 7615 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 7616 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 7617 | * manager. |
| 7618 | */ |
| 7619 | public void reportActivityRelaunched() { |
| 7620 | mActivityRelaunched = true; |
| 7621 | } |
| 7622 | |
| 7623 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7624 | * Class for managing the accessibility interaction connection |
| 7625 | * based on the global accessibility state. |
| 7626 | */ |
| 7627 | final class AccessibilityInteractionConnectionManager |
| 7628 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7629 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7630 | public void onAccessibilityStateChanged(boolean enabled) { |
| 7631 | if (enabled) { |
| 7632 | ensureConnection(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7633 | if (mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7634 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 7635 | View focusedView = mView.findFocus(); |
| 7636 | if (focusedView != null && focusedView != mView) { |
| 7637 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 7638 | } |
| 7639 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7640 | } else { |
| 7641 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 7642 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7643 | } |
| 7644 | } |
| 7645 | |
| 7646 | public void ensureConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7647 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 7648 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7649 | if (!registered) { |
| 7650 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7651 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
| 7652 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | public void ensureNoConnection() { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7657 | final boolean registered = mAttachInfo.mAccessibilityWindowId |
| 7658 | != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7659 | if (registered) { |
Phil Weaver | f00cd14 | 2017-03-03 13:44:00 -0800 | [diff] [blame] | 7660 | mAttachInfo.mAccessibilityWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7661 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 7662 | } |
| 7663 | } |
| 7664 | } |
| 7665 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7666 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 7667 | HighContrastTextManager() { |
| 7668 | mAttachInfo.mHighContrastText = mAccessibilityManager.isHighTextContrastEnabled(); |
| 7669 | } |
| 7670 | @Override |
| 7671 | public void onHighTextContrastStateChanged(boolean enabled) { |
| 7672 | mAttachInfo.mHighContrastText = enabled; |
| 7673 | |
| 7674 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 7675 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7676 | |
| 7677 | // Schedule redraw, which will rerecord + redraw all text |
| 7678 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7679 | } |
| 7680 | } |
| 7681 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7682 | /** |
| 7683 | * This class is an interface this ViewAncestor provides to the |
| 7684 | * AccessibilityManagerService to the latter can interact with |
| 7685 | * the view hierarchy in this ViewAncestor. |
| 7686 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7687 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7688 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7689 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7690 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 7691 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 7692 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7693 | } |
| 7694 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7695 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7696 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7697 | Region interactiveRegion, int interactionId, |
| 7698 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 7699 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec, Bundle args) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7700 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7701 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7702 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7703 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7704 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
Phil Weaver | c2e2893 | 2016-12-08 12:29:25 -0800 | [diff] [blame] | 7705 | interrogatingTid, spec, args); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7706 | } else { |
| 7707 | // We cannot make the call and notify the caller so it does not wait. |
| 7708 | try { |
| 7709 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7710 | } catch (RemoteException re) { |
| 7711 | /* best effort - ignore */ |
| 7712 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 7713 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7716 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7717 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7718 | Bundle arguments, int interactionId, |
| 7719 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7720 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7721 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7722 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7723 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7724 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7725 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7726 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7727 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7728 | try { |
| 7729 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 7730 | } catch (RemoteException re) { |
| 7731 | /* best effort - ignore */ |
| 7732 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7733 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7734 | } |
| 7735 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7736 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7737 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7738 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7739 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7740 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7741 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7742 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7743 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7744 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7745 | viewId, interactiveRegion, interactionId, callback, flags, |
| 7746 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7747 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7748 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7749 | try { |
| 7750 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 7751 | } catch (RemoteException re) { |
| 7752 | /* best effort - ignore */ |
| 7753 | } |
| 7754 | } |
| 7755 | } |
| 7756 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7757 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7758 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7759 | Region interactiveRegion, int interactionId, |
| 7760 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7761 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7762 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7763 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7764 | viewRootImpl.getAccessibilityInteractionController() |
| 7765 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7766 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7767 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7768 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7769 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7770 | try { |
| 7771 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7772 | } catch (RemoteException re) { |
| 7773 | /* best effort - ignore */ |
| 7774 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7775 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7776 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7777 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7778 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7779 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 7780 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7781 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7782 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7783 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7784 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7785 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 7786 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7787 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7788 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7789 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7790 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7791 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7792 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7793 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7794 | } |
| 7795 | } |
| 7796 | } |
| 7797 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7798 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7799 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 7800 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7801 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7802 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7803 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7804 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7805 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 7806 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7807 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7808 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7809 | // We cannot make the call and notify the caller so it does not wait. |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7810 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7811 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7812 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7813 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7814 | } |
| 7815 | } |
| 7816 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7817 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7818 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7819 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7820 | private int mChangeTypes = 0; |
| 7821 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7822 | public View mSource; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7823 | public long mLastEventTimeMillis; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7824 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7825 | @Override |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7826 | public void run() { |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7827 | // The accessibility may be turned off while we were waiting so check again. |
| 7828 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7829 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 7830 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 7831 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7832 | event.setContentChangeTypes(mChangeTypes); |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7833 | mSource.sendAccessibilityEventUnchecked(event); |
| 7834 | } else { |
| 7835 | mLastEventTimeMillis = 0; |
| 7836 | } |
| 7837 | // In any case reset to initial state. |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7838 | mSource.resetSubtreeAccessibilityStateChanged(); |
| 7839 | mSource = null; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7840 | mChangeTypes = 0; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7841 | } |
| 7842 | |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7843 | public void runOrPost(View source, int changeType) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7844 | if (mSource != null) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7845 | // If there is no common predecessor, then mSource points to |
| 7846 | // a removed view, hence in this case always prefer the source. |
| 7847 | View predecessor = getCommonPredecessor(mSource, source); |
| 7848 | mSource = (predecessor != null) ? predecessor : source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7849 | mChangeTypes |= changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7850 | return; |
| 7851 | } |
| 7852 | mSource = source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7853 | mChangeTypes = changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7854 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 7855 | final long minEventIntevalMillis = |
| 7856 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 7857 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7858 | mSource.removeCallbacks(this); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7859 | run(); |
| 7860 | } else { |
| 7861 | mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7862 | } |
| 7863 | } |
| 7864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | } |