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 | |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 19 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 20 | import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY; |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 21 | import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 23 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 24 | import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 25 | |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 26 | import android.Manifest; |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 27 | import android.animation.LayoutTransition; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 28 | import android.app.ActivityManagerNative; |
| 29 | import android.content.ClipDescription; |
| 30 | import android.content.ComponentCallbacks; |
| 31 | import android.content.Context; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.res.CompatibilityInfo; |
| 34 | import android.content.res.Configuration; |
| 35 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.graphics.Canvas; |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 37 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.graphics.PixelFormat; |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 39 | import android.graphics.Point; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import android.graphics.PointF; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 41 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.graphics.Rect; |
| 43 | import android.graphics.Region; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 45 | import android.hardware.display.DisplayManager; |
| 46 | import android.hardware.display.DisplayManager.DisplayListener; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 47 | import android.hardware.input.InputManager; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 48 | import android.media.AudioManager; |
| 49 | import android.os.Binder; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 50 | import android.os.Build; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 51 | import android.os.Bundle; |
| 52 | import android.os.Debug; |
| 53 | import android.os.Handler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 54 | import android.os.Looper; |
| 55 | import android.os.Message; |
| 56 | import android.os.ParcelFileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.os.Process; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 58 | import android.os.RemoteException; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 59 | import android.os.SystemClock; |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 61 | import android.os.Trace; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.util.AndroidRuntimeException; |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 63 | import android.util.DisplayMetrics; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 64 | import android.util.Log; |
Chet Haase | 949dbf7 | 2010-08-11 18:41:06 -0700 | [diff] [blame] | 65 | import android.util.Slog; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 66 | import android.util.TimeUtils; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 67 | import android.util.TypedValue; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 68 | import android.view.Surface.OutOfResourcesException; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 69 | import android.view.View.AttachInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.view.View.MeasureSpec; |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 71 | import android.view.accessibility.AccessibilityEvent; |
| 72 | import android.view.accessibility.AccessibilityManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 73 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 74 | import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 75 | import android.view.accessibility.AccessibilityNodeInfo; |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 76 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 77 | import android.view.accessibility.AccessibilityNodeProvider; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 78 | import android.view.accessibility.IAccessibilityInteractionConnection; |
| 79 | import android.view.accessibility.IAccessibilityInteractionConnectionCallback; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 80 | import android.view.animation.AccelerateDecelerateInterpolator; |
| 81 | import android.view.animation.Interpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.view.inputmethod.InputConnection; |
| 83 | import android.view.inputmethod.InputMethodManager; |
| 84 | import android.widget.Scroller; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 85 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 86 | import com.android.internal.R; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 87 | import com.android.internal.os.IResultReceiver; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 88 | import com.android.internal.os.SomeArgs; |
Adam Powell | 6711f3b | 2015-05-06 15:57:09 -0700 | [diff] [blame] | 89 | import com.android.internal.policy.PhoneFallbackEventHandler; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 90 | import com.android.internal.view.BaseSurfaceHolder; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 91 | import com.android.internal.view.RootViewSurfaceTaker; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 93 | import java.io.FileDescriptor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import java.io.IOException; |
| 95 | import java.io.OutputStream; |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 96 | import java.io.PrintWriter; |
Romain Guy | 6b7bd24 | 2010-10-06 19:49:23 -0700 | [diff] [blame] | 97 | import java.lang.ref.WeakReference; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import java.util.ArrayList; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 99 | import java.util.concurrent.CountDownLatch; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 100 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | /** |
| 103 | * The top of a view hierarchy, implementing the needed protocol between View |
| 104 | * and the WindowManager. This is for the most part an internal implementation |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 105 | * detail of {@link WindowManagerGlobal}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | * |
| 107 | * {@hide} |
| 108 | */ |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 109 | @SuppressWarnings({"EmptyCatchBlock", "PointlessBooleanExpression"}) |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 110 | public final class ViewRootImpl implements ViewParent, |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 111 | View.AttachInfo.Callbacks, ThreadedRenderer.HardwareDrawCallbacks { |
Dianne Hackborn | 70a3f67 | 2011-08-08 14:32:41 -0700 | [diff] [blame] | 112 | private static final String TAG = "ViewRootImpl"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | private static final boolean DBG = false; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 114 | private static final boolean LOCAL_LOGV = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | /** @noinspection PointlessBooleanExpression*/ |
| 116 | private static final boolean DEBUG_DRAW = false || LOCAL_LOGV; |
| 117 | private static final boolean DEBUG_LAYOUT = false || LOCAL_LOGV; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 118 | private static final boolean DEBUG_DIALOG = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | private static final boolean DEBUG_INPUT_RESIZE = false || LOCAL_LOGV; |
| 120 | private static final boolean DEBUG_ORIENTATION = false || LOCAL_LOGV; |
| 121 | private static final boolean DEBUG_TRACKBALL = false || LOCAL_LOGV; |
| 122 | private static final boolean DEBUG_IMF = false || LOCAL_LOGV; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 123 | private static final boolean DEBUG_CONFIGURATION = false || LOCAL_LOGV; |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 124 | private static final boolean DEBUG_FPS = false; |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 125 | private static final boolean DEBUG_INPUT_STAGES = false || LOCAL_LOGV; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 127 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 128 | * Set to false if we do not want to use the multi threaded renderer. Note that by disabling |
| 129 | * this, WindowCallbacks will not fire. |
| 130 | */ |
| 131 | private static final boolean USE_MT_RENDERER = true; |
| 132 | |
| 133 | /** |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 134 | * Set this system property to true to force the view hierarchy to render |
| 135 | * at 60 Hz. This can be used to measure the potential framerate. |
| 136 | */ |
Romain Guy | e9bc11f | 2013-05-23 12:47:26 -0700 | [diff] [blame] | 137 | private static final String PROPERTY_PROFILE_RENDERING = "viewroot.profile_rendering"; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 138 | |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 139 | // properties used by emulator to determine display shape |
Griff Hazen | a093802 | 2015-03-13 10:01:41 -0700 | [diff] [blame] | 140 | public static final String PROPERTY_EMULATOR_WIN_OUTSET_BOTTOM_PX = |
| 141 | "ro.emu.win_outset_bottom_px"; |
Michael Kolb | 437d313 | 2014-06-20 13:28:44 -0700 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
| 144 | * Maximum time we allow the user to roll the trackball enough to generate |
| 145 | * a key event, before resetting the counters. |
| 146 | */ |
| 147 | static final int MAX_TRACKBALL_DELAY = 250; |
| 148 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 149 | private static final int RESIZE_MODE_FREEFORM = 0; |
| 150 | private static final int RESIZE_MODE_DOCKED_DIVIDER = 1; |
| 151 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 152 | static final ThreadLocal<HandlerActionQueue> sRunQueues = new ThreadLocal<HandlerActionQueue>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 154 | static final ArrayList<Runnable> sFirstDrawHandlers = new ArrayList(); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 155 | static boolean sFirstDrawComplete = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 156 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 157 | static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 158 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 159 | final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 160 | final Context mContext; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 161 | final IWindowSession mWindowSession; |
| 162 | final Display mDisplay; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 163 | final DisplayManager mDisplayManager; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 164 | final String mBasePackageName; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | final int[] mTmpLocation = new int[2]; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 167 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 168 | final TypedValue mTmpValue = new TypedValue(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | final Thread mThread; |
| 171 | |
| 172 | final WindowLeaked mLocation; |
| 173 | |
| 174 | final WindowManager.LayoutParams mWindowAttributes = new WindowManager.LayoutParams(); |
| 175 | |
| 176 | final W mWindow; |
| 177 | |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 178 | final int mTargetSdkVersion; |
| 179 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 180 | int mSeq; |
| 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | View mView; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 183 | |
| 184 | View mAccessibilityFocusedHost; |
| 185 | AccessibilityNodeInfo mAccessibilityFocusedVirtualView; |
| 186 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 187 | // The view which captures mouse input, or null when no one is capturing. |
| 188 | View mCapturingView; |
| 189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | int mViewVisibility; |
| 191 | boolean mAppVisible = true; |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 192 | // For recents to freeform transition we need to keep drawing after the app receives information |
| 193 | // that it became invisible. This will ignore that information and depend on the decor view |
| 194 | // visibility to control drawing. The decor view visibility will get adjusted when the app get |
| 195 | // stopped and that's when the app will stop drawing further frames. |
| 196 | private boolean mForceDecorViewVisibility = false; |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 197 | int mOrigWindowType = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 199 | /** Whether the window had focus during the most recent traversal. */ |
| 200 | boolean mHadWindowFocus; |
| 201 | |
| 202 | /** |
| 203 | * Whether the window lost focus during a previous traversal and has not |
| 204 | * yet gained it back. Used to determine whether a WINDOW_STATE_CHANGE |
| 205 | * accessibility events should be sent during traversal. |
| 206 | */ |
| 207 | boolean mLostWindowFocus; |
| 208 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 209 | // Set to true if the owner of this window is in the stopped state, |
| 210 | // so the window should no longer be active. |
| 211 | boolean mStopped = false; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 212 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 213 | // Set to true if the owner of this window is in ambient mode, |
| 214 | // which means it won't receive input events. |
| 215 | boolean mIsAmbientMode = false; |
| 216 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 217 | // Set to true to stop input during an Activity Transition. |
| 218 | boolean mPausedForTransition = false; |
| 219 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 220 | boolean mLastInCompatMode = false; |
| 221 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 222 | SurfaceHolder.Callback2 mSurfaceHolderCallback; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 223 | BaseSurfaceHolder mSurfaceHolder; |
| 224 | boolean mIsCreating; |
| 225 | boolean mDrawingAllowed; |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | final Region mTransparentRegion; |
| 228 | final Region mPreviousTransparentRegion; |
| 229 | |
| 230 | int mWidth; |
| 231 | int mHeight; |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 232 | Rect mDirty; |
Romain Guy | bb93d55 | 2009-03-24 21:04:15 -0700 | [diff] [blame] | 233 | boolean mIsAnimating; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 234 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 235 | private boolean mDragResizing; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 236 | private int mResizeMode; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 237 | private int mCanvasOffsetX; |
| 238 | private int mCanvasOffsetY; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 239 | private boolean mActivityRelaunched; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 240 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 241 | CompatibilityInfo.Translator mTranslator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | |
| 243 | final View.AttachInfo mAttachInfo; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 244 | InputChannel mInputChannel; |
Dianne Hackborn | 1e4b9f3 | 2010-06-23 14:10:57 -0700 | [diff] [blame] | 245 | InputQueue.Callback mInputQueueCallback; |
| 246 | InputQueue mInputQueue; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 247 | FallbackEventHandler mFallbackEventHandler; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 248 | Choreographer mChoreographer; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | final Rect mTempRect; // used in the transaction to not thrash the heap. |
| 251 | 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] | 252 | |
| 253 | boolean mTraversalScheduled; |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 254 | int mTraversalBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | boolean mWillDrawSoon; |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 256 | /** Set to true while in performTraversals for detecting when die(true) is called from internal |
| 257 | * callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */ |
| 258 | boolean mIsInTraversal; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 259 | boolean mApplyInsetsRequested; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | boolean mLayoutRequested; |
| 261 | boolean mFirst; |
| 262 | boolean mReportNextDraw; |
| 263 | boolean mFullRedrawNeeded; |
| 264 | boolean mNewSurfaceNeeded; |
| 265 | boolean mHasHadWindowFocus; |
| 266 | boolean mLastWasImTarget; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 267 | boolean mForceNextWindowRelayout; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 268 | CountDownLatch mWindowDrawCountDown; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 269 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 270 | boolean mIsDrawing; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 271 | int mLastSystemUiVisibility; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 272 | int mClientWindowLayoutFlags; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 273 | boolean mLastOverscanRequested; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 274 | |
| 275 | // Pool of queued input events. |
| 276 | private static final int MAX_QUEUED_INPUT_EVENT_POOL_SIZE = 10; |
| 277 | private QueuedInputEvent mQueuedInputEventPool; |
| 278 | private int mQueuedInputEventPoolSize; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 279 | |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 280 | /* Input event queue. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 281 | * Pending input events are input events waiting to be delivered to the input stages |
| 282 | * and handled by the application. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 283 | */ |
| 284 | QueuedInputEvent mPendingInputEventHead; |
| 285 | QueuedInputEvent mPendingInputEventTail; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 286 | int mPendingInputEventCount; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 287 | boolean mProcessInputEventsScheduled; |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 288 | boolean mUnbufferedInputDispatch; |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 289 | String mPendingInputEventQueueLengthCounterName = "pq"; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 290 | |
| 291 | InputStage mFirstInputStage; |
| 292 | InputStage mFirstPostImeInputStage; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 293 | InputStage mSyntheticInputStage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | |
| 295 | boolean mWindowAttributesChanged = false; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 296 | int mWindowAttributesChangesFlag = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | |
| 298 | // 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] | 299 | // Surface can never be reassigned or cleared (use Surface.clear()). |
John Reck | b13de07 | 2014-11-19 16:33:47 -0800 | [diff] [blame] | 300 | final Surface mSurface = new Surface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
| 302 | boolean mAdded; |
| 303 | boolean mAddedTouchMode; |
| 304 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 305 | final DisplayAdjustments mDisplayAdjustments; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | // These are accessed by multiple threads. |
| 308 | final Rect mWinFrame; // frame given by window manager. |
| 309 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 310 | final Rect mPendingOverscanInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | final Rect mPendingVisibleInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 312 | final Rect mPendingStableInsets = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | final Rect mPendingContentInsets = new Rect(); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 314 | final Rect mPendingOutsets = new Rect(); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 315 | final Rect mPendingBackDropFrame = new Rect(); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 316 | boolean mPendingAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | final ViewTreeObserver.InternalInsetsInfo mLastGivenInsets |
| 318 | = new ViewTreeObserver.InternalInsetsInfo(); |
| 319 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 320 | final Rect mDispatchContentInsets = new Rect(); |
| 321 | final Rect mDispatchStableInsets = new Rect(); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 322 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 323 | private WindowInsets mLastWindowInsets; |
| 324 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 325 | final Configuration mLastConfiguration = new Configuration(); |
| 326 | final Configuration mPendingConfiguration = new Configuration(); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | boolean mScrollMayChange; |
| 329 | int mSoftInputMode; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 330 | WeakReference<View> mLastScrolledFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | int mScrollY; |
| 332 | int mCurScrollY; |
| 333 | Scroller mScroller; |
John Reck | e56e9df | 2014-02-21 15:45:10 -0800 | [diff] [blame] | 334 | static final Interpolator mResizeInterpolator = new AccelerateDecelerateInterpolator(); |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 335 | private ArrayList<LayoutTransition> mPendingTransitions; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 336 | |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 337 | final ViewConfiguration mViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 339 | /* Drag/drop */ |
| 340 | ClipDescription mDragDescription; |
| 341 | View mCurrentDragView; |
Christopher Tate | 7fb8b56 | 2011-01-20 13:46:41 -0800 | [diff] [blame] | 342 | volatile Object mLocalDragState; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 343 | final PointF mDragPoint = new PointF(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 344 | final PointF mLastTouchPoint = new PointF(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 345 | int mLastTouchSource; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 346 | |
| 347 | private boolean mProfileRendering; |
Romain Guy | d075031 | 2012-11-29 11:34:43 -0800 | [diff] [blame] | 348 | private Choreographer.FrameCallback mRenderProfiler; |
| 349 | private boolean mRenderProfilingEnabled; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 350 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 351 | // Variables to track frames per second, enabled via DEBUG_FPS flag |
| 352 | private long mFpsStartTime = -1; |
| 353 | private long mFpsPrevTime = -1; |
| 354 | private int mFpsNumFrames; |
| 355 | |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 356 | private int mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 357 | private PointerIcon mCustomPointerIcon = null; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | /** |
| 360 | * see {@link #playSoundEffect(int)} |
| 361 | */ |
| 362 | AudioManager mAudioManager; |
| 363 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 364 | final AccessibilityManager mAccessibilityManager; |
| 365 | |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 366 | AccessibilityInteractionController mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 367 | |
| 368 | AccessibilityInteractionConnectionManager mAccessibilityInteractionConnectionManager; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 369 | HighContrastTextManager mHighContrastTextManager; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 370 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 371 | SendWindowContentChangedAccessibilityEvent mSendWindowContentChangedAccessibilityEvent; |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 372 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 373 | HashSet<View> mTempHashSet; |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 374 | |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 375 | private final int mDensity; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 376 | private final int mNoncompatDensity; |
Adam Powell | b08013c | 2010-09-16 16:28:11 -0700 | [diff] [blame] | 377 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 378 | private boolean mInLayout = false; |
| 379 | ArrayList<View> mLayoutRequesters = new ArrayList<View>(); |
| 380 | boolean mHandlingLayoutInLayoutRequest = false; |
| 381 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 382 | private int mViewLayoutDirectionInitial; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 383 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 384 | /** Set to true once doDie() has been called. */ |
| 385 | private boolean mRemoved; |
| 386 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 387 | /** |
| 388 | * Consistency verifier for debugging purposes. |
| 389 | */ |
| 390 | protected final InputEventConsistencyVerifier mInputEventConsistencyVerifier = |
| 391 | InputEventConsistencyVerifier.isInstrumentationEnabled() ? |
| 392 | new InputEventConsistencyVerifier(this, 0) : null; |
| 393 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 394 | static final class SystemUiVisibilityInfo { |
| 395 | int seq; |
| 396 | int globalVisibility; |
| 397 | int localValue; |
| 398 | int localChanges; |
| 399 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 400 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 401 | private String mTag = TAG; |
| 402 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 403 | public ViewRootImpl(Context context, Display display) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 404 | mContext = context; |
| 405 | mWindowSession = WindowManagerGlobal.getWindowSession(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 406 | mDisplay = display; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 407 | mBasePackageName = context.getBasePackageName(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 408 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 409 | mDisplayAdjustments = display.getDisplayAdjustments(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | mThread = Thread.currentThread(); |
| 412 | mLocation = new WindowLeaked(null); |
| 413 | mLocation.fillInStackTrace(); |
| 414 | mWidth = -1; |
| 415 | mHeight = -1; |
| 416 | mDirty = new Rect(); |
| 417 | mTempRect = new Rect(); |
| 418 | mVisRect = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | mWinFrame = new Rect(); |
Romain Guy | fb8b763 | 2010-08-23 21:05:08 -0700 | [diff] [blame] | 420 | mWindow = new W(this); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 421 | mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | mViewVisibility = View.GONE; |
| 423 | mTransparentRegion = new Region(); |
| 424 | mPreviousTransparentRegion = new Region(); |
| 425 | 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] | 426 | mAdded = false; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 427 | mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 428 | mAccessibilityManager = AccessibilityManager.getInstance(context); |
| 429 | mAccessibilityInteractionConnectionManager = |
| 430 | new AccessibilityInteractionConnectionManager(); |
Svetoslav Ganov | 00d0c14 | 2012-02-24 11:30:49 -0800 | [diff] [blame] | 431 | mAccessibilityManager.addAccessibilityStateChangeListener( |
| 432 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 433 | mHighContrastTextManager = new HighContrastTextManager(); |
| 434 | mAccessibilityManager.addHighTextContrastStateChangeListener( |
| 435 | mHighContrastTextManager); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | mViewConfiguration = ViewConfiguration.get(context); |
Dianne Hackborn | 11ea334 | 2009-07-22 21:48:55 -0700 | [diff] [blame] | 437 | mDensity = context.getResources().getDisplayMetrics().densityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 438 | mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi; |
Jorim Jaggi | b10e33f | 2015-02-04 21:57:40 +0100 | [diff] [blame] | 439 | mFallbackEventHandler = new PhoneFallbackEventHandler(context); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 440 | mChoreographer = Choreographer.getInstance(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 441 | mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 442 | loadSystemProperties(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 445 | public static void addFirstDrawHandler(Runnable callback) { |
| 446 | synchronized (sFirstDrawHandlers) { |
| 447 | if (!sFirstDrawComplete) { |
| 448 | sFirstDrawHandlers.add(callback); |
| 449 | } |
| 450 | } |
| 451 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 452 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 453 | public static void addConfigCallback(ComponentCallbacks callback) { |
| 454 | synchronized (sConfigCallbacks) { |
| 455 | sConfigCallbacks.add(callback); |
| 456 | } |
| 457 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 458 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 459 | public void addWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 460 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 461 | synchronized (mWindowCallbacks) { |
| 462 | mWindowCallbacks.add(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 467 | public void removeWindowCallbacks(WindowCallbacks callback) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 468 | if (USE_MT_RENDERER) { |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 469 | synchronized (mWindowCallbacks) { |
| 470 | mWindowCallbacks.remove(callback); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 475 | public void reportDrawFinish() { |
| 476 | if (mWindowDrawCountDown != null) { |
| 477 | mWindowDrawCountDown.countDown(); |
| 478 | } |
| 479 | } |
| 480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | // FIXME for perf testing only |
| 482 | private boolean mProfile = false; |
| 483 | |
| 484 | /** |
| 485 | * Call this to profile the next traversal call. |
| 486 | * FIXME for perf testing only. Remove eventually |
| 487 | */ |
| 488 | public void profile() { |
| 489 | mProfile = true; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Indicates whether we are in touch mode. Calling this method triggers an IPC |
| 494 | * call and should be avoided whenever possible. |
| 495 | * |
| 496 | * @return True, if the device is in touch mode, false otherwise. |
| 497 | * |
| 498 | * @hide |
| 499 | */ |
| 500 | static boolean isInTouchMode() { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 501 | IWindowSession windowSession = WindowManagerGlobal.peekWindowSession(); |
| 502 | if (windowSession != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 504 | return windowSession.getInTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | } catch (RemoteException e) { |
| 506 | } |
| 507 | } |
| 508 | return false; |
| 509 | } |
| 510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | /** |
| 512 | * We have one child |
| 513 | */ |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 514 | 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] | 515 | synchronized (this) { |
| 516 | if (mView == null) { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 517 | mView = view; |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 518 | |
| 519 | mAttachInfo.mDisplayState = mDisplay.getState(); |
| 520 | mDisplayManager.registerDisplayListener(mDisplayListener, mHandler); |
| 521 | |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 522 | mViewLayoutDirectionInitial = mView.getRawLayoutDirection(); |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 523 | mFallbackEventHandler.setView(view); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 524 | mWindowAttributes.copyFrom(attrs); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 525 | if (mWindowAttributes.packageName == null) { |
| 526 | mWindowAttributes.packageName = mBasePackageName; |
| 527 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 528 | attrs = mWindowAttributes; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 529 | setTag(); |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 530 | // Keep track of the actual window flags supplied by the client. |
| 531 | mClientWindowLayoutFlags = attrs.flags; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 532 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 533 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 534 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 535 | if (view instanceof RootViewSurfaceTaker) { |
| 536 | mSurfaceHolderCallback = |
| 537 | ((RootViewSurfaceTaker)view).willYouTakeTheSurface(); |
| 538 | if (mSurfaceHolderCallback != null) { |
| 539 | mSurfaceHolder = new TakenSurfaceHolder(); |
Dianne Hackborn | 289b9b6 | 2010-07-09 11:44:11 -0700 | [diff] [blame] | 540 | mSurfaceHolder.setFormat(PixelFormat.UNKNOWN); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 543 | |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 544 | // Compute surface insets required to draw at specified Z value. |
| 545 | // TODO: Use real shadow insets for a constant max Z. |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 546 | if (!attrs.hasManualSurfaceInsets) { |
| 547 | final int surfaceInset = (int) Math.ceil(view.getZ() * 2); |
| 548 | attrs.surfaceInsets.set(surfaceInset, surfaceInset, surfaceInset, surfaceInset); |
| 549 | } |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 550 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 551 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 552 | mTranslator = compatibilityInfo.getTranslator(); |
| 553 | |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 554 | // If the application owns the surface, don't enable hardware acceleration |
| 555 | if (mSurfaceHolder == null) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 556 | enableHardwareAcceleration(attrs); |
Romain Guy | 1aec9a2 | 2011-01-05 09:37:12 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 559 | boolean restore = false; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 560 | if (mTranslator != null) { |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 561 | mSurface.setCompatibilityTranslator(mTranslator); |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 562 | restore = true; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 563 | attrs.backup(); |
| 564 | mTranslator.translateWindowLayout(attrs); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 565 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 566 | if (DEBUG_LAYOUT) Log.d(mTag, "WindowLayout in setView:" + attrs); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 567 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 568 | if (!compatibilityInfo.supportsScreen()) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 569 | attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 570 | mLastInCompatMode = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 571 | } |
| 572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | mSoftInputMode = attrs.softInputMode; |
| 574 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 575 | mWindowAttributesChangesFlag = WindowManager.LayoutParams.EVERYTHING_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | mAttachInfo.mRootView = view; |
Romain Guy | 35b38ce | 2009-10-07 13:38:55 -0700 | [diff] [blame] | 577 | mAttachInfo.mScalingRequired = mTranslator != null; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 578 | mAttachInfo.mApplicationScale = |
| 579 | mTranslator == null ? 1.0f : mTranslator.applicationScale; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 580 | if (panelParentView != null) { |
| 581 | mAttachInfo.mPanelParentWindowToken |
| 582 | = panelParentView.getApplicationWindowToken(); |
| 583 | } |
| 584 | mAdded = true; |
| 585 | int res; /* = WindowManagerImpl.ADD_OKAY; */ |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | // Schedule the first layout -before- adding to the window |
| 588 | // manager, to make sure we do the relayout before receiving |
| 589 | // any other events from the system. |
| 590 | requestLayout(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 591 | if ((mWindowAttributes.inputFeatures |
| 592 | & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) { |
| 593 | mInputChannel = new InputChannel(); |
| 594 | } |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 595 | mForceDecorViewVisibility = (mWindowAttributes.privateFlags |
| 596 | & PRIVATE_FLAG_FORCE_DECOR_VIEW_VISIBILITY) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | try { |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 598 | mOrigWindowType = mWindowAttributes.type; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 599 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 600 | collectViewAttributes(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 601 | res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes, |
| 602 | getHostVisibility(), mDisplay.getDisplayId(), |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 603 | mAttachInfo.mContentInsets, mAttachInfo.mStableInsets, |
| 604 | mAttachInfo.mOutsets, mInputChannel); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | } catch (RemoteException e) { |
| 606 | mAdded = false; |
| 607 | mView = null; |
| 608 | mAttachInfo.mRootView = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 609 | mInputChannel = null; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 610 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 612 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | throw new RuntimeException("Adding window failed", e); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 614 | } finally { |
| 615 | if (restore) { |
| 616 | attrs.restore(); |
| 617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 619 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 620 | if (mTranslator != null) { |
| 621 | mTranslator.translateRectInScreenToAppWindow(mAttachInfo.mContentInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 622 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 623 | mPendingOverscanInsets.set(0, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | mPendingContentInsets.set(mAttachInfo.mContentInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 625 | mPendingStableInsets.set(mAttachInfo.mStableInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | mPendingVisibleInsets.set(0, 0, 0, 0); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 627 | mAttachInfo.mAlwaysConsumeNavBar = |
| 628 | (res & WindowManagerGlobal.ADD_FLAG_ALWAYS_CONSUME_NAV_BAR) != 0; |
| 629 | mPendingAlwaysConsumeNavBar = mAttachInfo.mAlwaysConsumeNavBar; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 630 | if (DEBUG_LAYOUT) Log.v(mTag, "Added window " + mWindow); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 631 | if (res < WindowManagerGlobal.ADD_OKAY) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | mAttachInfo.mRootView = null; |
| 633 | mAdded = false; |
Joe Onorato | 86f6786 | 2010-11-05 18:57:34 -0700 | [diff] [blame] | 634 | mFallbackEventHandler.setView(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | unscheduleTraversals(); |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 636 | setAccessibilityFocus(null, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 637 | switch (res) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 638 | case WindowManagerGlobal.ADD_BAD_APP_TOKEN: |
| 639 | case WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN: |
| 640 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 641 | "Unable to add window -- token " + attrs.token |
| 642 | + " is not valid; is your activity running?"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 643 | case WindowManagerGlobal.ADD_NOT_APP_TOKEN: |
| 644 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 645 | "Unable to add window -- token " + attrs.token |
| 646 | + " is not for an application"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 647 | case WindowManagerGlobal.ADD_APP_EXITING: |
| 648 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 649 | "Unable to add window -- app for token " + attrs.token |
| 650 | + " is exiting"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 651 | case WindowManagerGlobal.ADD_DUPLICATE_ADD: |
| 652 | throw new WindowManager.BadTokenException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 653 | "Unable to add window -- window " + mWindow |
| 654 | + " has already been added"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 655 | case WindowManagerGlobal.ADD_STARTING_NOT_NEEDED: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | // Silently ignore -- we would have just removed it |
| 657 | // right away, anyway. |
| 658 | return; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 659 | case WindowManagerGlobal.ADD_MULTIPLE_SINGLETON: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 660 | throw new WindowManager.BadTokenException("Unable to add window " |
| 661 | + mWindow + " -- another window of type " |
| 662 | + mWindowAttributes.type + " already exists"); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 663 | case WindowManagerGlobal.ADD_PERMISSION_DENIED: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 664 | throw new WindowManager.BadTokenException("Unable to add window " |
| 665 | + mWindow + " -- permission denied for window type " |
| 666 | + mWindowAttributes.type); |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 667 | case WindowManagerGlobal.ADD_INVALID_DISPLAY: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 668 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 669 | + mWindow + " -- the specified display can not be found"); |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 670 | case WindowManagerGlobal.ADD_INVALID_TYPE: |
Alan Viverette | 73f6d60 | 2015-09-14 16:01:19 -0400 | [diff] [blame] | 671 | throw new WindowManager.InvalidDisplayException("Unable to add window " |
| 672 | + mWindow + " -- the specified window type " |
| 673 | + mWindowAttributes.type + " is not valid"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | } |
| 675 | throw new RuntimeException( |
Wale Ogunwale | 74bf065 | 2015-01-12 10:24:36 -0800 | [diff] [blame] | 676 | "Unable to add window -- unknown error code " + res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 678 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 679 | if (view instanceof RootViewSurfaceTaker) { |
| 680 | mInputQueueCallback = |
| 681 | ((RootViewSurfaceTaker)view).willYouTakeTheInputQueue(); |
| 682 | } |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 683 | if (mInputChannel != null) { |
| 684 | if (mInputQueueCallback != null) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 685 | mInputQueue = new InputQueue(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 686 | mInputQueueCallback.onInputQueueCreated(mInputQueue); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 687 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 688 | mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, |
| 689 | Looper.myLooper()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 690 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | view.assignParent(this); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 693 | mAddedTouchMode = (res & WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0; |
| 694 | mAppVisible = (res & WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 695 | |
| 696 | if (mAccessibilityManager.isEnabled()) { |
| 697 | mAccessibilityInteractionConnectionManager.ensureConnection(); |
| 698 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 699 | |
| 700 | if (view.getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 701 | view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 702 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 703 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 704 | // Set up the input pipeline. |
| 705 | CharSequence counterSuffix = attrs.getTitle(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 706 | mSyntheticInputStage = new SyntheticInputStage(); |
| 707 | InputStage viewPostImeStage = new ViewPostImeInputStage(mSyntheticInputStage); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 708 | InputStage nativePostImeStage = new NativePostImeInputStage(viewPostImeStage, |
| 709 | "aq:native-post-ime:" + counterSuffix); |
| 710 | InputStage earlyPostImeStage = new EarlyPostImeInputStage(nativePostImeStage); |
| 711 | InputStage imeStage = new ImeInputStage(earlyPostImeStage, |
| 712 | "aq:ime:" + counterSuffix); |
| 713 | InputStage viewPreImeStage = new ViewPreImeInputStage(imeStage); |
| 714 | InputStage nativePreImeStage = new NativePreImeInputStage(viewPreImeStage, |
| 715 | "aq:native-pre-ime:" + counterSuffix); |
| 716 | |
| 717 | mFirstInputStage = nativePreImeStage; |
| 718 | mFirstPostImeInputStage = earlyPostImeStage; |
| 719 | mPendingInputEventQueueLengthCounterName = "aq:pending:" + counterSuffix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 724 | private void setTag() { |
| 725 | final String[] split = mWindowAttributes.getTitle().toString().split("\\."); |
| 726 | if (split.length > 0) { |
| 727 | mTag = TAG + "[" + split[split.length - 1] + "]"; |
| 728 | } |
| 729 | } |
| 730 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 731 | /** Whether the window is in local focus mode or not */ |
| 732 | private boolean isInLocalFocusMode() { |
| 733 | return (mWindowAttributes.flags & WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE) != 0; |
| 734 | } |
| 735 | |
Dianne Hackborn | 49b043f | 2015-05-07 14:21:38 -0700 | [diff] [blame] | 736 | public int getWindowFlags() { |
| 737 | return mWindowAttributes.flags; |
| 738 | } |
| 739 | |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 740 | public int getDisplayId() { |
| 741 | return mDisplay.getDisplayId(); |
| 742 | } |
| 743 | |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 744 | public CharSequence getTitle() { |
| 745 | return mWindowAttributes.getTitle(); |
| 746 | } |
| 747 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 748 | void destroyHardwareResources() { |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 749 | if (mAttachInfo.mHardwareRenderer != null) { |
| 750 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 751 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 31f2c2e | 2011-11-21 10:55:41 -0800 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | |
Bo Liu | 845535a | 2014-03-21 12:06:23 -0700 | [diff] [blame] | 755 | public void detachFunctor(long functor) { |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 756 | if (mAttachInfo.mHardwareRenderer != null) { |
| 757 | // Fence so that any pending invokeFunctor() messages will be processed |
| 758 | // before we return from detachFunctor. |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 759 | mAttachInfo.mHardwareRenderer.stopDrawing(); |
John Reck | 44ac42a | 2014-05-16 14:46:07 -0700 | [diff] [blame] | 760 | } |
Romain Guy | ba6be8a | 2012-04-23 18:22:09 -0700 | [diff] [blame] | 761 | } |
| 762 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 763 | /** |
| 764 | * Schedules the functor for execution in either kModeProcess or |
| 765 | * kModeProcessNoContext, depending on whether or not there is an EGLContext. |
| 766 | * |
| 767 | * @param functor The native functor to invoke |
| 768 | * @param waitForCompletion If true, this will not return until the functor |
| 769 | * has invoked. If false, the functor may be invoked |
| 770 | * asynchronously. |
| 771 | */ |
Hui Shu | 9970aee | 2014-06-23 17:10:30 -0700 | [diff] [blame] | 772 | public void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 773 | ThreadedRenderer.invokeFunctor(functor, waitForCompletion); |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 774 | } |
| 775 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 776 | public void registerAnimatingRenderNode(RenderNode animator) { |
| 777 | if (mAttachInfo.mHardwareRenderer != null) { |
| 778 | mAttachInfo.mHardwareRenderer.registerAnimatingRenderNode(animator); |
| 779 | } else { |
| 780 | if (mAttachInfo.mPendingAnimatingRenderNodes == null) { |
| 781 | mAttachInfo.mPendingAnimatingRenderNodes = new ArrayList<RenderNode>(); |
| 782 | } |
| 783 | mAttachInfo.mPendingAnimatingRenderNodes.add(animator); |
| 784 | } |
| 785 | } |
| 786 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 787 | private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) { |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 788 | mAttachInfo.mHardwareAccelerated = false; |
| 789 | mAttachInfo.mHardwareAccelerationRequested = false; |
Romain Guy | 4f6aff3 | 2011-01-12 16:21:41 -0800 | [diff] [blame] | 790 | |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 791 | // Don't enable hardware acceleration when the application is in compatibility mode |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 792 | if (mTranslator != null) return; |
Romain Guy | 856d4e1 | 2011-10-14 15:47:55 -0700 | [diff] [blame] | 793 | |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 794 | // Try to enable hardware acceleration if requested |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 795 | final boolean hardwareAccelerated = |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 796 | (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 797 | |
John Reck | dd58e79 | 2014-04-02 16:54:28 +0000 | [diff] [blame] | 798 | if (hardwareAccelerated) { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 799 | if (!ThreadedRenderer.isAvailable()) { |
Romain Guy | 1af23a3 | 2011-03-24 16:03:55 -0700 | [diff] [blame] | 800 | return; |
| 801 | } |
| 802 | |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 803 | // Persistent processes (including the system) should not do |
| 804 | // accelerated rendering on low-end devices. In that case, |
| 805 | // sRendererDisabled will be set. In addition, the system process |
| 806 | // itself should never do accelerated rendering. In that case, both |
| 807 | // sRendererDisabled and sSystemRendererDisabled are set. When |
| 808 | // sSystemRendererDisabled is set, PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED |
| 809 | // can be used by code on the system process to escape that and enable |
| 810 | // HW accelerated drawing. (This is basically for the lock screen.) |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 811 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 812 | final boolean fakeHwAccelerated = (attrs.privateFlags & |
| 813 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED) != 0; |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 814 | final boolean forceHwAccelerated = (attrs.privateFlags & |
| 815 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED) != 0; |
Jim Miller | 1b36592 | 2011-03-09 19:38:07 -0800 | [diff] [blame] | 816 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 817 | if (fakeHwAccelerated) { |
| 818 | // This is exclusively for the preview windows the window manager |
| 819 | // shows for launching applications, so they will look more like |
| 820 | // the app being launched. |
| 821 | mAttachInfo.mHardwareAccelerationRequested = true; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 822 | } else if (!ThreadedRenderer.sRendererDisabled |
| 823 | || (ThreadedRenderer.sSystemRendererDisabled && forceHwAccelerated)) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 824 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 825 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 826 | } |
| 827 | |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 828 | final Rect insets = attrs.surfaceInsets; |
Alan Viverette | 2cd23e6 | 2014-11-04 17:04:02 -0800 | [diff] [blame] | 829 | final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 |
| 830 | || insets.top != 0 || insets.bottom != 0; |
Alan Viverette | 2b12b58 | 2014-10-29 11:11:40 -0700 | [diff] [blame] | 831 | final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 832 | mAttachInfo.mHardwareRenderer = ThreadedRenderer.create(mContext, translucent); |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 833 | if (mAttachInfo.mHardwareRenderer != null) { |
| 834 | mAttachInfo.mHardwareRenderer.setName(attrs.getTitle().toString()); |
| 835 | mAttachInfo.mHardwareAccelerated = |
| 836 | mAttachInfo.mHardwareAccelerationRequested = true; |
| 837 | } |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | public View getView() { |
| 843 | return mView; |
| 844 | } |
| 845 | |
| 846 | final WindowLeaked getLocation() { |
| 847 | return mLocation; |
| 848 | } |
| 849 | |
| 850 | void setLayoutParams(WindowManager.LayoutParams attrs, boolean newView) { |
| 851 | synchronized (this) { |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 852 | final int oldInsetLeft = mWindowAttributes.surfaceInsets.left; |
| 853 | final int oldInsetTop = mWindowAttributes.surfaceInsets.top; |
| 854 | final int oldInsetRight = mWindowAttributes.surfaceInsets.right; |
| 855 | final int oldInsetBottom = mWindowAttributes.surfaceInsets.bottom; |
| 856 | final int oldSoftInputMode = mWindowAttributes.softInputMode; |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 857 | final boolean oldHasManualSurfaceInsets = mWindowAttributes.hasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 858 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 859 | // Keep track of the actual window flags supplied by the client. |
| 860 | mClientWindowLayoutFlags = attrs.flags; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 861 | |
| 862 | // Preserve compatible window flag if exists. |
| 863 | final int compatibleWindowFlag = mWindowAttributes.privateFlags |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 864 | & WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 865 | |
| 866 | // Transfer over system UI visibility values as they carry current state. |
Craig Mautner | 3fe38c0 | 2012-05-03 17:28:09 -0700 | [diff] [blame] | 867 | attrs.systemUiVisibility = mWindowAttributes.systemUiVisibility; |
| 868 | attrs.subtreeSystemUiVisibility = mWindowAttributes.subtreeSystemUiVisibility; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 869 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 870 | mWindowAttributesChangesFlag = mWindowAttributes.copyFrom(attrs); |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 871 | if ((mWindowAttributesChangesFlag |
| 872 | & WindowManager.LayoutParams.TRANSLUCENT_FLAGS_CHANGED) != 0) { |
| 873 | // Recompute system ui visibility. |
| 874 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 875 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 876 | if (mWindowAttributes.packageName == null) { |
| 877 | mWindowAttributes.packageName = mBasePackageName; |
| 878 | } |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 879 | mWindowAttributes.privateFlags |= compatibleWindowFlag; |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 880 | |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 881 | // Restore old surface insets. |
| 882 | mWindowAttributes.surfaceInsets.set( |
| 883 | oldInsetLeft, oldInsetTop, oldInsetRight, oldInsetBottom); |
Alan Viverette | 5435a30 | 2015-01-29 10:25:34 -0800 | [diff] [blame] | 884 | mWindowAttributes.hasManualSurfaceInsets = oldHasManualSurfaceInsets; |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 885 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 886 | applyKeepScreenOnFlag(mWindowAttributes); |
| 887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | if (newView) { |
| 889 | mSoftInputMode = attrs.softInputMode; |
| 890 | requestLayout(); |
| 891 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 892 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 893 | // Don't lose the mode we last auto-computed. |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 894 | if ((attrs.softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 895 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
| 896 | mWindowAttributes.softInputMode = (mWindowAttributes.softInputMode |
| 897 | & ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 898 | | (oldSoftInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 899 | } |
Alan Viverette | dbed893 | 2014-08-06 17:54:52 -0700 | [diff] [blame] | 900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | mWindowAttributesChanged = true; |
| 902 | scheduleTraversals(); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | void handleAppVisibility(boolean visible) { |
| 907 | if (mAppVisible != visible) { |
| 908 | mAppVisible = visible; |
| 909 | scheduleTraversals(); |
John Reck | 73840ea | 2014-09-22 07:39:18 -0700 | [diff] [blame] | 910 | if (!mAppVisible) { |
| 911 | WindowManagerGlobal.trimForeground(); |
| 912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
| 916 | void handleGetNewSurface() { |
| 917 | mNewSurfaceNeeded = true; |
| 918 | mFullRedrawNeeded = true; |
| 919 | scheduleTraversals(); |
| 920 | } |
| 921 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 922 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 923 | @Override |
| 924 | public void onDisplayChanged(int displayId) { |
| 925 | if (mView != null && mDisplay.getDisplayId() == displayId) { |
| 926 | final int oldDisplayState = mAttachInfo.mDisplayState; |
| 927 | final int newDisplayState = mDisplay.getState(); |
| 928 | if (oldDisplayState != newDisplayState) { |
| 929 | mAttachInfo.mDisplayState = newDisplayState; |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 930 | pokeDrawLockIfNeeded(); |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 931 | if (oldDisplayState != Display.STATE_UNKNOWN) { |
| 932 | final int oldScreenState = toViewScreenState(oldDisplayState); |
| 933 | final int newScreenState = toViewScreenState(newDisplayState); |
| 934 | if (oldScreenState != newScreenState) { |
| 935 | mView.dispatchScreenStateChanged(newScreenState); |
| 936 | } |
| 937 | if (oldDisplayState == Display.STATE_OFF) { |
| 938 | // Draw was suppressed so we need to for it to happen here. |
| 939 | mFullRedrawNeeded = true; |
| 940 | scheduleTraversals(); |
| 941 | } |
| 942 | } |
| 943 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 944 | } |
| 945 | } |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 946 | |
| 947 | @Override |
| 948 | public void onDisplayRemoved(int displayId) { |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public void onDisplayAdded(int displayId) { |
| 953 | } |
| 954 | |
| 955 | private int toViewScreenState(int displayState) { |
| 956 | return displayState == Display.STATE_OFF ? |
| 957 | View.SCREEN_STATE_OFF : View.SCREEN_STATE_ON; |
| 958 | } |
| 959 | }; |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 960 | |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 961 | void pokeDrawLockIfNeeded() { |
| 962 | final int displayState = mAttachInfo.mDisplayState; |
| 963 | if (mView != null && mAdded && mTraversalScheduled |
| 964 | && (displayState == Display.STATE_DOZE |
| 965 | || displayState == Display.STATE_DOZE_SUSPEND)) { |
| 966 | try { |
| 967 | mWindowSession.pokeDrawLock(mWindow); |
| 968 | } catch (RemoteException ex) { |
| 969 | // System server died, oh well. |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 974 | @Override |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 975 | public void requestFitSystemWindows() { |
| 976 | checkThread(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 977 | mApplyInsetsRequested = true; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 978 | scheduleTraversals(); |
| 979 | } |
| 980 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 981 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | public void requestLayout() { |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 983 | if (!mHandlingLayoutInLayoutRequest) { |
| 984 | checkThread(); |
| 985 | mLayoutRequested = true; |
| 986 | scheduleTraversals(); |
| 987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | } |
| 989 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 990 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | public boolean isLayoutRequested() { |
| 992 | return mLayoutRequested; |
| 993 | } |
| 994 | |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 995 | void invalidate() { |
| 996 | mDirty.set(0, 0, mWidth, mHeight); |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 997 | if (!mWillDrawSoon) { |
| 998 | scheduleTraversals(); |
| 999 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1002 | void invalidateWorld(View view) { |
| 1003 | view.invalidate(); |
| 1004 | if (view instanceof ViewGroup) { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 1005 | ViewGroup parent = (ViewGroup) view; |
| 1006 | for (int i = 0; i < parent.getChildCount(); i++) { |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 1007 | invalidateWorld(parent.getChildAt(i)); |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |
Craig Mautner | 6018aee | 2012-10-23 14:27:49 -0700 | [diff] [blame] | 1012 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | public void invalidateChild(View child, Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1014 | invalidateChildInParent(null, dirty); |
| 1015 | } |
| 1016 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1017 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1018 | public ViewParent invalidateChildInParent(int[] location, Rect dirty) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1020 | if (DEBUG_DRAW) Log.v(mTag, "Invalidate child: " + dirty); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1021 | |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1022 | if (dirty == null) { |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1023 | invalidate(); |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1024 | return null; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1025 | } else if (dirty.isEmpty() && !mIsAnimating) { |
Chet Haase | 05e91ed | 2012-07-03 14:17:57 -0700 | [diff] [blame] | 1026 | return null; |
Chet Haase | 70d4ba1 | 2010-10-06 09:46:45 -0700 | [diff] [blame] | 1027 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1028 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1029 | if (mCurScrollY != 0 || mTranslator != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | mTempRect.set(dirty); |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1031 | dirty = mTempRect; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1032 | if (mCurScrollY != 0) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1033 | dirty.offset(0, -mCurScrollY); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1034 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1035 | if (mTranslator != null) { |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1036 | mTranslator.translateRectInAppWindowToScreen(dirty); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1037 | } |
Romain Guy | 1e09597 | 2009-07-07 11:22:45 -0700 | [diff] [blame] | 1038 | if (mAttachInfo.mScalingRequired) { |
| 1039 | dirty.inset(-1, -1); |
| 1040 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1042 | |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 1043 | invalidateRectOnScreen(dirty); |
| 1044 | |
| 1045 | return null; |
| 1046 | } |
| 1047 | |
| 1048 | private void invalidateRectOnScreen(Rect dirty) { |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1049 | final Rect localDirty = mDirty; |
| 1050 | if (!localDirty.isEmpty() && !localDirty.contains(dirty)) { |
Romain Guy | 02ccac6 | 2011-06-24 13:20:23 -0700 | [diff] [blame] | 1051 | mAttachInfo.mSetIgnoreDirtyState = true; |
Romain Guy | 7d69594 | 2010-12-01 17:22:29 -0800 | [diff] [blame] | 1052 | mAttachInfo.mIgnoreDirtyState = true; |
| 1053 | } |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1054 | |
| 1055 | // Add the new dirty rect to the current one |
| 1056 | localDirty.union(dirty.left, dirty.top, dirty.right, dirty.bottom); |
| 1057 | // Intersect with the bounds of the window to skip |
| 1058 | // updates that lie outside of the visible region |
Romain Guy | 7b2f8b8 | 2012-03-19 17:18:54 -0700 | [diff] [blame] | 1059 | final float appScale = mAttachInfo.mApplicationScale; |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1060 | final boolean intersected = localDirty.intersect(0, 0, |
| 1061 | (int) (mWidth * appScale + 0.5f), (int) (mHeight * appScale + 0.5f)); |
| 1062 | if (!intersected) { |
Chet Haase | b78ee0e | 2012-10-17 11:32:01 -0700 | [diff] [blame] | 1063 | localDirty.setEmpty(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | } |
Chet Haase | 3561d06 | 2012-10-23 12:54:51 -0700 | [diff] [blame] | 1065 | if (!mWillDrawSoon && (intersected || mIsAnimating)) { |
| 1066 | scheduleTraversals(); |
| 1067 | } |
Romain Guy | 0d9275e | 2010-10-26 14:22:30 -0700 | [diff] [blame] | 1068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 1070 | public void setIsAmbientMode(boolean ambient) { |
| 1071 | mIsAmbientMode = ambient; |
| 1072 | } |
| 1073 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1074 | void setWindowStopped(boolean stopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1075 | if (mStopped != stopped) { |
| 1076 | mStopped = stopped; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1077 | if (!mStopped) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1078 | scheduleTraversals(); |
John Reck | d9b1607 | 2016-02-23 10:35:19 -0800 | [diff] [blame] | 1079 | } else { |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1080 | if (mAttachInfo.mHardwareRenderer != null) { |
Wale Ogunwale | e4f131a | 2016-03-07 07:33:56 -0800 | [diff] [blame] | 1081 | if (DEBUG_DRAW) Log.d(mTag, "WindowStopped on " + getTitle()); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1082 | mAttachInfo.mHardwareRenderer.updateSurface(null); |
John Reck | fc73686 | 2016-02-26 15:01:52 -0800 | [diff] [blame] | 1083 | mAttachInfo.mHardwareRenderer.destroyHardwareResources(mView); |
John Reck | f4db3d2 | 2016-02-26 12:58:17 -0800 | [diff] [blame] | 1084 | } |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 1089 | /** |
| 1090 | * Block the input events during an Activity Transition. The KEYCODE_BACK event is allowed |
| 1091 | * through to allow quick reversal of the Activity Transition. |
| 1092 | * |
| 1093 | * @param paused true to pause, false to resume. |
| 1094 | */ |
| 1095 | public void setPausedForTransition(boolean paused) { |
| 1096 | mPausedForTransition = paused; |
| 1097 | } |
| 1098 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1099 | @Override |
Romain Guy | cfef123 | 2012-02-23 13:50:37 -0800 | [diff] [blame] | 1100 | public ViewParent getParent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | return null; |
| 1102 | } |
| 1103 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 1104 | @Override |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1105 | 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] | 1106 | if (child != mView) { |
| 1107 | throw new RuntimeException("child is not mine, honest!"); |
| 1108 | } |
| 1109 | // Note: don't apply scroll offset, because we want to know its |
| 1110 | // visibility in the virtual canvas being given to the view hierarchy. |
| 1111 | return r.intersect(0, 0, mWidth, mHeight); |
| 1112 | } |
| 1113 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1114 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | public void bringChildToFront(View child) { |
| 1116 | } |
| 1117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | int getHostVisibility() { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1119 | return (mAppVisible || mForceDecorViewVisibility) ? mView.getVisibility() : View.GONE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1121 | |
Chet Haase | cca2c98 | 2011-05-20 14:34:18 -0700 | [diff] [blame] | 1122 | /** |
| 1123 | * Add LayoutTransition to the list of transitions to be started in the next traversal. |
| 1124 | * This list will be cleared after the transitions on the list are start()'ed. These |
| 1125 | * transitionsa re added by LayoutTransition itself when it sets up animations. The setup |
| 1126 | * happens during the layout phase of traversal, which we want to complete before any of the |
| 1127 | * animations are started (because those animations may side-effect properties that layout |
| 1128 | * depends upon, like the bounding rectangles of the affected views). So we add the transition |
| 1129 | * to the list and it is started just prior to starting the drawing phase of traversal. |
| 1130 | * |
| 1131 | * @param transition The LayoutTransition to be started on the next traversal. |
| 1132 | * |
| 1133 | * @hide |
| 1134 | */ |
| 1135 | public void requestTransitionStart(LayoutTransition transition) { |
| 1136 | if (mPendingTransitions == null || !mPendingTransitions.contains(transition)) { |
| 1137 | if (mPendingTransitions == null) { |
| 1138 | mPendingTransitions = new ArrayList<LayoutTransition>(); |
| 1139 | } |
| 1140 | mPendingTransitions.add(transition); |
| 1141 | } |
| 1142 | } |
| 1143 | |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1144 | /** |
| 1145 | * Notifies the HardwareRenderer that a new frame will be coming soon. |
| 1146 | * Currently only {@link ThreadedRenderer} cares about this, and uses |
| 1147 | * this knowledge to adjust the scheduling of off-thread animations |
| 1148 | */ |
| 1149 | void notifyRendererOfFramePending() { |
| 1150 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1151 | mAttachInfo.mHardwareRenderer.notifyFramePending(); |
| 1152 | } |
| 1153 | } |
| 1154 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1155 | void scheduleTraversals() { |
| 1156 | if (!mTraversalScheduled) { |
| 1157 | mTraversalScheduled = true; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1158 | mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1159 | mChoreographer.postCallback( |
| 1160 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 1161 | if (!mUnbufferedInputDispatch) { |
| 1162 | scheduleConsumeBatchedInput(); |
| 1163 | } |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 1164 | notifyRendererOfFramePending(); |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 1165 | pokeDrawLockIfNeeded(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1166 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1167 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1168 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1169 | void unscheduleTraversals() { |
| 1170 | if (mTraversalScheduled) { |
| 1171 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1172 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1173 | mChoreographer.removeCallbacks( |
| 1174 | Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null); |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | void doTraversal() { |
| 1179 | if (mTraversalScheduled) { |
| 1180 | mTraversalScheduled = false; |
Jeff Brown | 3d4e7efe | 2015-02-26 15:34:16 -0800 | [diff] [blame] | 1181 | mHandler.getLooper().getQueue().removeSyncBarrier(mTraversalBarrier); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1182 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1183 | if (mProfile) { |
| 1184 | Debug.startMethodTracing("ViewAncestor"); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1185 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1186 | |
Chris Craik | e22c59b | 2015-05-21 18:33:37 -0700 | [diff] [blame] | 1187 | performTraversals(); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1188 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 1189 | if (mProfile) { |
| 1190 | Debug.stopMethodTracing(); |
| 1191 | mProfile = false; |
| 1192 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1196 | private void applyKeepScreenOnFlag(WindowManager.LayoutParams params) { |
| 1197 | // Update window's global keep screen on flag: if a view has requested |
| 1198 | // that the screen be kept on, then it is always set; otherwise, it is |
| 1199 | // set to whatever the client last requested for the global state. |
| 1200 | if (mAttachInfo.mKeepScreenOn) { |
| 1201 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 1202 | } else { |
| 1203 | params.flags = (params.flags&~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) |
| 1204 | | (mClientWindowLayoutFlags&WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1205 | } |
| 1206 | } |
| 1207 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1208 | private boolean collectViewAttributes() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1209 | if (mAttachInfo.mRecomputeGlobalAttributes) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1210 | //Log.i(mTag, "Computing view hierarchy attributes!"); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1211 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 1212 | boolean oldScreenOn = mAttachInfo.mKeepScreenOn; |
| 1213 | mAttachInfo.mKeepScreenOn = false; |
| 1214 | mAttachInfo.mSystemUiVisibility = 0; |
| 1215 | mAttachInfo.mHasSystemUiListeners = false; |
| 1216 | mView.dispatchCollectViewAttributes(mAttachInfo, 0); |
| 1217 | mAttachInfo.mSystemUiVisibility &= ~mAttachInfo.mDisabledSystemUiVisibility; |
Craig Mautner | 7eac0f5 | 2012-09-13 13:14:14 -0700 | [diff] [blame] | 1218 | WindowManager.LayoutParams params = mWindowAttributes; |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1219 | mAttachInfo.mSystemUiVisibility |= getImpliedSystemUiVisibility(params); |
| 1220 | if (mAttachInfo.mKeepScreenOn != oldScreenOn |
| 1221 | || mAttachInfo.mSystemUiVisibility != params.subtreeSystemUiVisibility |
| 1222 | || mAttachInfo.mHasSystemUiListeners != params.hasSystemUiListeners) { |
Dianne Hackborn | 9d09089 | 2012-06-11 18:35:41 -0700 | [diff] [blame] | 1223 | applyKeepScreenOnFlag(params); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1224 | params.subtreeSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
| 1225 | params.hasSystemUiListeners = mAttachInfo.mHasSystemUiListeners; |
| 1226 | mView.dispatchWindowSystemUiVisiblityChanged(mAttachInfo.mSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1227 | return true; |
| 1228 | } |
| 1229 | } |
| 1230 | return false; |
| 1231 | } |
| 1232 | |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 1233 | private int getImpliedSystemUiVisibility(WindowManager.LayoutParams params) { |
| 1234 | int vis = 0; |
| 1235 | // Translucent decor window flags imply stable system ui visibility. |
| 1236 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) != 0) { |
| 1237 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; |
| 1238 | } |
| 1239 | if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) != 0) { |
| 1240 | vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 1241 | } |
| 1242 | return vis; |
| 1243 | } |
| 1244 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1245 | private boolean measureHierarchy(final View host, final WindowManager.LayoutParams lp, |
| 1246 | final Resources res, final int desiredWindowWidth, final int desiredWindowHeight) { |
| 1247 | int childWidthMeasureSpec; |
| 1248 | int childHeightMeasureSpec; |
| 1249 | boolean windowSizeMayChange = false; |
| 1250 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1251 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1252 | "Measuring " + host + " in display " + desiredWindowWidth |
| 1253 | + "x" + desiredWindowHeight + "..."); |
| 1254 | |
| 1255 | boolean goodMeasure = false; |
| 1256 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { |
| 1257 | // On large screens, we don't want to allow dialogs to just |
| 1258 | // stretch to fill the entire width of the screen to display |
| 1259 | // one line of text. First try doing the layout at a smaller |
| 1260 | // size to see if it will fit. |
| 1261 | final DisplayMetrics packageMetrics = res.getDisplayMetrics(); |
| 1262 | res.getValue(com.android.internal.R.dimen.config_prefDialogWidth, mTmpValue, true); |
| 1263 | int baseSize = 0; |
| 1264 | if (mTmpValue.type == TypedValue.TYPE_DIMENSION) { |
| 1265 | baseSize = (int)mTmpValue.getDimension(packageMetrics); |
| 1266 | } |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1267 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": baseSize=" + baseSize |
| 1268 | + ", desiredWindowWidth=" + desiredWindowWidth); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1269 | if (baseSize != 0 && desiredWindowWidth > baseSize) { |
| 1270 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
| 1271 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1272 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1273 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Filip Gruszczynski | 1937a4c | 2016-01-19 16:17:13 -0800 | [diff] [blame] | 1274 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() |
| 1275 | + ") from width spec: " + MeasureSpec.toString(childWidthMeasureSpec) |
| 1276 | + " and height spec: " + MeasureSpec.toString(childHeightMeasureSpec)); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1277 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
| 1278 | goodMeasure = true; |
| 1279 | } else { |
| 1280 | // Didn't fit in that size... try expanding a bit. |
| 1281 | baseSize = (baseSize+desiredWindowWidth)/2; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1282 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": next baseSize=" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1283 | + baseSize); |
| 1284 | childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1285 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1286 | if (DEBUG_DIALOG) Log.v(mTag, "Window " + mView + ": measured (" |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1287 | + host.getMeasuredWidth() + "," + host.getMeasuredHeight() + ")"); |
| 1288 | if ((host.getMeasuredWidthAndState()&View.MEASURED_STATE_TOO_SMALL) == 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1289 | if (DEBUG_DIALOG) Log.v(mTag, "Good!"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1290 | goodMeasure = true; |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | if (!goodMeasure) { |
| 1297 | childWidthMeasureSpec = getRootMeasureSpec(desiredWindowWidth, lp.width); |
| 1298 | childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1299 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1300 | if (mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) { |
| 1301 | windowSizeMayChange = true; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | if (DBG) { |
| 1306 | System.out.println("======================================"); |
| 1307 | System.out.println("performTraversals -- after measure"); |
| 1308 | host.debug(); |
| 1309 | } |
| 1310 | |
| 1311 | return windowSizeMayChange; |
| 1312 | } |
| 1313 | |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1314 | /** |
| 1315 | * Modifies the input matrix such that it maps view-local coordinates to |
| 1316 | * on-screen coordinates. |
| 1317 | * |
| 1318 | * @param m input matrix to modify |
| 1319 | */ |
| 1320 | void transformMatrixToGlobal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1321 | m.preTranslate(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Modifies the input matrix such that it maps on-screen coordinates to |
| 1326 | * view-local coordinates. |
| 1327 | * |
| 1328 | * @param m input matrix to modify |
| 1329 | */ |
| 1330 | void transformMatrixToLocal(Matrix m) { |
Dake Gu | 7bf379c | 2014-07-15 16:29:38 -0700 | [diff] [blame] | 1331 | m.postTranslate(-mAttachInfo.mWindowLeft, -mAttachInfo.mWindowTop); |
Alan Viverette | fed3f72 | 2013-11-14 14:48:20 -0800 | [diff] [blame] | 1332 | } |
| 1333 | |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1334 | /* package */ WindowInsets getWindowInsets(boolean forceConstruct) { |
| 1335 | if (mLastWindowInsets == null || forceConstruct) { |
| 1336 | mDispatchContentInsets.set(mAttachInfo.mContentInsets); |
| 1337 | mDispatchStableInsets.set(mAttachInfo.mStableInsets); |
| 1338 | Rect contentInsets = mDispatchContentInsets; |
| 1339 | Rect stableInsets = mDispatchStableInsets; |
| 1340 | // For dispatch we preserve old logic, but for direct requests from Views we allow to |
| 1341 | // immediately use pending insets. |
| 1342 | if (!forceConstruct |
| 1343 | && (!mPendingContentInsets.equals(contentInsets) || |
| 1344 | !mPendingStableInsets.equals(stableInsets))) { |
| 1345 | contentInsets = mPendingContentInsets; |
| 1346 | stableInsets = mPendingStableInsets; |
| 1347 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1348 | Rect outsets = mAttachInfo.mOutsets; |
| 1349 | if (outsets.left > 0 || outsets.top > 0 || outsets.right > 0 || outsets.bottom > 0) { |
| 1350 | contentInsets = new Rect(contentInsets.left + outsets.left, |
| 1351 | contentInsets.top + outsets.top, contentInsets.right + outsets.right, |
| 1352 | contentInsets.bottom + outsets.bottom); |
| 1353 | } |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1354 | mLastWindowInsets = new WindowInsets(contentInsets, |
Adam Powell | 01f280d | 2015-05-18 16:07:42 -0700 | [diff] [blame] | 1355 | null /* windowDecorInsets */, stableInsets, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1356 | mContext.getResources().getConfiguration().isScreenRound(), |
| 1357 | mAttachInfo.mAlwaysConsumeNavBar); |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1358 | } |
| 1359 | return mLastWindowInsets; |
| 1360 | } |
| 1361 | |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1362 | void dispatchApplyInsets(View host) { |
Filip Gruszczynski | 954289d | 2015-02-26 15:46:47 -0800 | [diff] [blame] | 1363 | host.dispatchApplyWindowInsets(getWindowInsets(true /* forceConstruct */)); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1366 | private static boolean shouldUseDisplaySize(final WindowManager.LayoutParams lp) { |
| 1367 | return lp.type == TYPE_STATUS_BAR_PANEL |
| 1368 | || lp.type == TYPE_INPUT_METHOD |
| 1369 | || lp.type == TYPE_VOLUME_OVERLAY; |
| 1370 | } |
| 1371 | |
| 1372 | private int dipToPx(int dip) { |
| 1373 | final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); |
| 1374 | return (int) (displayMetrics.density * dip + 0.5f); |
| 1375 | } |
| 1376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | private void performTraversals() { |
| 1378 | // cache mView since it is used so much below... |
| 1379 | final View host = mView; |
| 1380 | |
| 1381 | if (DBG) { |
| 1382 | System.out.println("======================================"); |
| 1383 | System.out.println("performTraversals"); |
| 1384 | host.debug(); |
| 1385 | } |
| 1386 | |
| 1387 | if (host == null || !mAdded) |
| 1388 | return; |
| 1389 | |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 1390 | mIsInTraversal = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | mWillDrawSoon = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1392 | boolean windowSizeMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | boolean newSurface = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1394 | boolean surfaceChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | WindowManager.LayoutParams lp = mWindowAttributes; |
| 1396 | |
| 1397 | int desiredWindowWidth; |
| 1398 | int desiredWindowHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | final int viewVisibility = getHostVisibility(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1401 | final boolean viewVisibilityChanged = !mFirst |
| 1402 | && (mViewVisibility != viewVisibility || mNewSurfaceNeeded); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | |
| 1404 | WindowManager.LayoutParams params = null; |
| 1405 | if (mWindowAttributesChanged) { |
| 1406 | mWindowAttributesChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1407 | surfaceChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | params = lp; |
| 1409 | } |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 1410 | CompatibilityInfo compatibilityInfo = mDisplayAdjustments.getCompatibilityInfo(); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1411 | if (compatibilityInfo.supportsScreen() == mLastInCompatMode) { |
| 1412 | params = lp; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1413 | mFullRedrawNeeded = true; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1414 | mLayoutRequested = true; |
| 1415 | if (mLastInCompatMode) { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1416 | params.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1417 | mLastInCompatMode = false; |
| 1418 | } else { |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1419 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1420 | mLastInCompatMode = true; |
| 1421 | } |
| 1422 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1423 | |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 1424 | mWindowAttributesChangesFlag = 0; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1425 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1426 | Rect frame = mWinFrame; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | if (mFirst) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1428 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | mLayoutRequested = true; |
| 1430 | |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1431 | if (shouldUseDisplaySize(lp)) { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1432 | // NOTE -- system code, won't try to do compat mode. |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1433 | Point size = new Point(); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1434 | mDisplay.getRealSize(size); |
Jeff Brown | bc68a59 | 2011-07-25 12:58:12 -0700 | [diff] [blame] | 1435 | desiredWindowWidth = size.x; |
| 1436 | desiredWindowHeight = size.y; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1437 | } else { |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1438 | Configuration config = mContext.getResources().getConfiguration(); |
| 1439 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1440 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 1441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | |
Romain Guy | c5d5586 | 2011-01-21 19:01:46 -0800 | [diff] [blame] | 1443 | // We used to use the following condition to choose 32 bits drawing caches: |
| 1444 | // PixelFormat.hasAlpha(lp.format) || lp.format == PixelFormat.RGBX_8888 |
| 1445 | // 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] | 1446 | mAttachInfo.mUse32BitDrawingCache = true; |
| 1447 | mAttachInfo.mHasWindowFocus = false; |
| 1448 | mAttachInfo.mWindowVisibility = viewVisibility; |
| 1449 | mAttachInfo.mRecomputeGlobalAttributes = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1450 | mLastConfiguration.setTo(host.getResources().getConfiguration()); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1451 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 1452 | // Set the layout direction if it has not been set before (inherit is the default) |
| 1453 | if (mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
| 1454 | host.setLayoutDirection(mLastConfiguration.getLayoutDirection()); |
| 1455 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1456 | host.dispatchAttachedToWindow(mAttachInfo, 0); |
| 1457 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(true); |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1458 | dispatchApplyInsets(host); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1459 | //Log.i(mTag, "Screen on initialized: " + attachInfo.mKeepScreenOn); |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 1460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | } else { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 1462 | desiredWindowWidth = frame.width(); |
| 1463 | desiredWindowHeight = frame.height(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | if (desiredWindowWidth != mWidth || desiredWindowHeight != mHeight) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1465 | if (DEBUG_ORIENTATION) Log.v(mTag, "View " + host + " resized to: " + frame); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1466 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | mLayoutRequested = true; |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1468 | windowSizeMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | if (viewVisibilityChanged) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1473 | mAttachInfo.mWindowVisibility = viewVisibility; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | host.dispatchWindowVisibilityChanged(viewVisibility); |
| 1475 | if (viewVisibility != View.VISIBLE || mNewSurfaceNeeded) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1476 | endDragResizing(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 1477 | destroyHardwareResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | } |
| 1479 | if (viewVisibility == View.GONE) { |
| 1480 | // After making a window gone, we will count it as being |
| 1481 | // shown for the first time the next time it gets focus. |
| 1482 | mHasHadWindowFocus = false; |
| 1483 | } |
| 1484 | } |
| 1485 | |
Alan Viverette | 7dbc3bf | 2015-01-28 16:14:36 -0800 | [diff] [blame] | 1486 | // Non-visible windows can't hold accessibility focus. |
| 1487 | if (mAttachInfo.mWindowVisibility != View.VISIBLE) { |
| 1488 | host.clearAccessibilityFocus(); |
| 1489 | } |
| 1490 | |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1491 | // 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] | 1492 | getRunQueue().executeActions(mAttachInfo.mHandler); |
Chet Haase | b78c284 | 2012-04-19 13:39:50 -0700 | [diff] [blame] | 1493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | boolean insetsChanged = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1495 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1496 | boolean layoutRequested = mLayoutRequested && (!mStopped || mReportNextDraw); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1497 | if (layoutRequested) { |
Romain Guy | 15df670 | 2009-08-17 20:17:30 -0700 | [diff] [blame] | 1498 | |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1499 | final Resources res = mView.getContext().getResources(); |
| 1500 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1501 | if (mFirst) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | // make sure touch mode code executes by setting cached value |
| 1503 | // to opposite of the added touch mode. |
| 1504 | mAttachInfo.mInTouchMode = !mAddedTouchMode; |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 1505 | ensureTouchModeLocally(mAddedTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1507 | if (!mPendingOverscanInsets.equals(mAttachInfo.mOverscanInsets)) { |
| 1508 | insetsChanged = true; |
| 1509 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1510 | if (!mPendingContentInsets.equals(mAttachInfo.mContentInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | insetsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1513 | if (!mPendingStableInsets.equals(mAttachInfo.mStableInsets)) { |
| 1514 | insetsChanged = true; |
| 1515 | } |
Dianne Hackborn | fa6b35b | 2011-08-24 17:03:54 -0700 | [diff] [blame] | 1516 | if (!mPendingVisibleInsets.equals(mAttachInfo.mVisibleInsets)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1518 | 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] | 1519 | + mAttachInfo.mVisibleInsets); |
| 1520 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1521 | if (!mPendingOutsets.equals(mAttachInfo.mOutsets)) { |
| 1522 | insetsChanged = true; |
| 1523 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1524 | if (mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar) { |
| 1525 | insetsChanged = true; |
| 1526 | } |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1527 | if (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT |
| 1528 | || lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { |
Dianne Hackborn | 711e62a | 2010-11-29 16:38:22 -0800 | [diff] [blame] | 1529 | windowSizeMayChange = true; |
Chong Zhang | f6525ce | 2016-01-14 17:09:56 -0800 | [diff] [blame] | 1530 | |
| 1531 | if (shouldUseDisplaySize(lp)) { |
| 1532 | // NOTE -- system code, won't try to do compat mode. |
| 1533 | Point size = new Point(); |
| 1534 | mDisplay.getRealSize(size); |
| 1535 | desiredWindowWidth = size.x; |
| 1536 | desiredWindowHeight = size.y; |
| 1537 | } else { |
| 1538 | Configuration config = res.getConfiguration(); |
| 1539 | desiredWindowWidth = dipToPx(config.screenWidthDp); |
| 1540 | desiredWindowHeight = dipToPx(config.screenHeightDp); |
| 1541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | // Ask host how big it wants to be |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1546 | windowSizeMayChange |= measureHierarchy(host, lp, res, |
| 1547 | desiredWindowWidth, desiredWindowHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1550 | if (collectViewAttributes()) { |
| 1551 | params = lp; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1553 | if (mAttachInfo.mForceReportNewAttributes) { |
| 1554 | mAttachInfo.mForceReportNewAttributes = false; |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 1555 | params = lp; |
| 1556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1558 | if (mFirst || mAttachInfo.mViewVisibilityChanged) { |
| 1559 | mAttachInfo.mViewVisibilityChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | int resizeMode = mSoftInputMode & |
| 1561 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 1562 | // If we are in auto resize mode, then we need to determine |
| 1563 | // what mode to use now. |
| 1564 | if (resizeMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1565 | final int N = mAttachInfo.mScrollContainers.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | for (int i=0; i<N; i++) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1567 | if (mAttachInfo.mScrollContainers.get(i).isShown()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 1569 | } |
| 1570 | } |
| 1571 | if (resizeMode == 0) { |
| 1572 | resizeMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN; |
| 1573 | } |
| 1574 | if ((lp.softInputMode & |
| 1575 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) != resizeMode) { |
| 1576 | lp.softInputMode = (lp.softInputMode & |
| 1577 | ~WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) | |
| 1578 | resizeMode; |
| 1579 | params = lp; |
| 1580 | } |
| 1581 | } |
| 1582 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1583 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1584 | if (params != null) { |
| 1585 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
| 1586 | if (!PixelFormat.formatHasAlpha(params.format)) { |
| 1587 | params.format = PixelFormat.TRANSLUCENT; |
| 1588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1590 | mAttachInfo.mOverscanRequested = (params.flags |
| 1591 | & WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | } |
| 1593 | |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1594 | if (mApplyInsetsRequested) { |
| 1595 | mApplyInsetsRequested = false; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1596 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1597 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1598 | if (mLayoutRequested) { |
| 1599 | // Short-circuit catching a new layout request here, so |
| 1600 | // we don't need to go through two layout passes when things |
| 1601 | // change due to fitting system windows, which can happen a lot. |
| 1602 | windowSizeMayChange |= measureHierarchy(host, lp, |
| 1603 | mView.getContext().getResources(), |
| 1604 | desiredWindowWidth, desiredWindowHeight); |
| 1605 | } |
| 1606 | } |
| 1607 | |
| 1608 | if (layoutRequested) { |
| 1609 | // Clear this now, so that if anything requests a layout in the |
| 1610 | // rest of this function we will catch it and re-run a full |
| 1611 | // layout pass. |
| 1612 | mLayoutRequested = false; |
| 1613 | } |
| 1614 | |
| 1615 | boolean windowShouldResize = layoutRequested && windowSizeMayChange |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1616 | && ((mWidth != host.getMeasuredWidth() || mHeight != host.getMeasuredHeight()) |
Romain Guy | 2e4f426 | 2010-04-06 11:07:52 -0700 | [diff] [blame] | 1617 | || (lp.width == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1618 | frame.width() < desiredWindowWidth && frame.width() != mWidth) |
| 1619 | || (lp.height == ViewGroup.LayoutParams.WRAP_CONTENT && |
| 1620 | frame.height() < desiredWindowHeight && frame.height() != mHeight)); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1621 | windowShouldResize |= mDragResizing && mResizeMode == RESIZE_MODE_FREEFORM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1623 | // If the activity was just relaunched, it might have unfrozen the task bounds (while |
| 1624 | // relaunching), so we need to force a call into window manager to pick up the latest |
| 1625 | // bounds. |
| 1626 | windowShouldResize |= mActivityRelaunched; |
| 1627 | |
Jeff Brown | 2e05ec3 | 2013-09-30 15:57:43 -0700 | [diff] [blame] | 1628 | // Determine whether to compute insets. |
| 1629 | // If there are no inset listeners remaining then we may still need to compute |
| 1630 | // 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] | 1631 | final boolean computesInternalInsets = |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1632 | mAttachInfo.mTreeObserver.hasComputeInternalInsetsListeners() |
| 1633 | || mAttachInfo.mHasNonEmptyGivenInternalInsets; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | boolean insetsPending = false; |
| 1636 | int relayoutResult = 0; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1637 | |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 1638 | final boolean isViewVisible = viewVisibility == View.VISIBLE; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1639 | if (mFirst || windowShouldResize || insetsChanged || |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 1640 | viewVisibilityChanged || params != null || mForceNextWindowRelayout) { |
| 1641 | mForceNextWindowRelayout = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 1643 | if (isViewVisible) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1644 | // If this window is giving internal insets to the window |
| 1645 | // manager, and it is being added or changing its visibility, |
| 1646 | // then we want to first give the window manager "fake" |
| 1647 | // insets to cause it to effectively ignore the content of |
| 1648 | // the window during layout. This avoids it briefly causing |
| 1649 | // other windows to resize/move based on the raw frame of the |
| 1650 | // window, waiting until we can finish laying out this window |
| 1651 | // and get back to the window manager with the ultimately |
| 1652 | // computed insets. |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1653 | insetsPending = computesInternalInsets && (mFirst || viewVisibilityChanged); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | } |
| 1655 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1656 | if (mSurfaceHolder != null) { |
| 1657 | mSurfaceHolder.mSurfaceLock.lock(); |
| 1658 | mDrawingAllowed = true; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1659 | } |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1660 | |
Romain Guy | c361da8 | 2010-10-25 15:29:10 -0700 | [diff] [blame] | 1661 | boolean hwInitialized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | boolean contentInsetsChanged = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1663 | boolean hadSurface = mSurface.isValid(); |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 1664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | try { |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1666 | if (DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1667 | Log.i(mTag, "host=w:" + host.getMeasuredWidth() + ", h:" + |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 1668 | host.getMeasuredHeight() + ", params=" + params); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1669 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1670 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1671 | if (mAttachInfo.mHardwareRenderer != null) { |
| 1672 | // relayoutWindow may decide to destroy mSurface. As that decision |
| 1673 | // happens in WindowManager service, we need to be defensive here |
| 1674 | // and stop using the surface in case it gets destroyed. |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 1675 | if (mAttachInfo.mHardwareRenderer.pauseSurface(mSurface)) { |
| 1676 | // Animations were running so we need to push a frame |
| 1677 | // to resume them |
| 1678 | mDirty.set(0, 0, mWidth, mHeight); |
| 1679 | } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1680 | mChoreographer.mFrameInfo.addFlags(FrameInfo.FLAG_WINDOW_LAYOUT_CHANGED); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 1681 | } |
Romain Guy | 2a83f00 | 2011-01-18 18:28:21 -0800 | [diff] [blame] | 1682 | final int surfaceGenerationId = mSurface.getGenerationId(); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1683 | relayoutResult = relayoutWindow(params, viewVisibility, insetsPending); |
| 1684 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1685 | if (DEBUG_LAYOUT) Log.v(mTag, "relayout: frame=" + frame.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1686 | + " overscan=" + mPendingOverscanInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | + " content=" + mPendingContentInsets.toShortString() |
| 1688 | + " visible=" + mPendingVisibleInsets.toShortString() |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1689 | + " visible=" + mPendingStableInsets.toShortString() |
Filip Gruszczynski | 0ec1328 | 2015-06-25 11:26:01 -0700 | [diff] [blame] | 1690 | + " outsets=" + mPendingOutsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | + " surface=" + mSurface); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1692 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1693 | if (mPendingConfiguration.seq != 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1694 | if (DEBUG_CONFIGURATION) Log.v(mTag, "Visible with new config: " |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1695 | + mPendingConfiguration); |
riddle_hsu | 164725c | 2015-11-12 14:07:12 +0800 | [diff] [blame] | 1696 | updateConfiguration(new Configuration(mPendingConfiguration), !mFirst); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 1697 | mPendingConfiguration.seq = 0; |
| 1698 | } |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1699 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1700 | final boolean overscanInsetsChanged = !mPendingOverscanInsets.equals( |
| 1701 | mAttachInfo.mOverscanInsets); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1702 | contentInsetsChanged = !mPendingContentInsets.equals( |
| 1703 | mAttachInfo.mContentInsets); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1704 | final boolean visibleInsetsChanged = !mPendingVisibleInsets.equals( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | mAttachInfo.mVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1706 | final boolean stableInsetsChanged = !mPendingStableInsets.equals( |
| 1707 | mAttachInfo.mStableInsets); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1708 | final boolean outsetsChanged = !mPendingOutsets.equals(mAttachInfo.mOutsets); |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1709 | final boolean surfaceSizeChanged = (relayoutResult |
| 1710 | & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1711 | final boolean alwaysConsumeNavBarChanged = |
| 1712 | mPendingAlwaysConsumeNavBar != mAttachInfo.mAlwaysConsumeNavBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | if (contentInsetsChanged) { |
| 1714 | mAttachInfo.mContentInsets.set(mPendingContentInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1715 | 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] | 1716 | + mAttachInfo.mContentInsets); |
| 1717 | } |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1718 | if (overscanInsetsChanged) { |
| 1719 | mAttachInfo.mOverscanInsets.set(mPendingOverscanInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1720 | if (DEBUG_LAYOUT) Log.v(mTag, "Overscan insets changing to: " |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1721 | + mAttachInfo.mOverscanInsets); |
| 1722 | // Need to relayout with content insets. |
| 1723 | contentInsetsChanged = true; |
| 1724 | } |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1725 | if (stableInsetsChanged) { |
| 1726 | mAttachInfo.mStableInsets.set(mPendingStableInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1727 | if (DEBUG_LAYOUT) Log.v(mTag, "Decor insets changing to: " |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1728 | + mAttachInfo.mStableInsets); |
| 1729 | // Need to relayout with content insets. |
| 1730 | contentInsetsChanged = true; |
| 1731 | } |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 1732 | if (alwaysConsumeNavBarChanged) { |
| 1733 | mAttachInfo.mAlwaysConsumeNavBar = mPendingAlwaysConsumeNavBar; |
| 1734 | contentInsetsChanged = true; |
| 1735 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1736 | if (contentInsetsChanged || mLastSystemUiVisibility != |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1737 | mAttachInfo.mSystemUiVisibility || mApplyInsetsRequested |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1738 | || mLastOverscanRequested != mAttachInfo.mOverscanRequested |
| 1739 | || outsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1740 | mLastSystemUiVisibility = mAttachInfo.mSystemUiVisibility; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 1741 | mLastOverscanRequested = mAttachInfo.mOverscanRequested; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 1742 | mAttachInfo.mOutsets.set(mPendingOutsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 1743 | mApplyInsetsRequested = false; |
Adam Powell | 2accbf9 | 2014-04-16 23:14:57 +0000 | [diff] [blame] | 1744 | dispatchApplyInsets(host); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | if (visibleInsetsChanged) { |
| 1747 | mAttachInfo.mVisibleInsets.set(mPendingVisibleInsets); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1748 | 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] | 1749 | + mAttachInfo.mVisibleInsets); |
| 1750 | } |
| 1751 | |
| 1752 | if (!hadSurface) { |
| 1753 | if (mSurface.isValid()) { |
| 1754 | // If we are creating a new surface, then we need to |
| 1755 | // completely redraw it. Also, when we get to the |
| 1756 | // point of drawing it we will hold off and schedule |
| 1757 | // a new traversal instead. This is so we can tell the |
| 1758 | // window manager about all of the windows being displayed |
| 1759 | // before actually drawing them, so it can display then |
| 1760 | // all at once. |
| 1761 | newSurface = true; |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1762 | mFullRedrawNeeded = true; |
Jack Palevich | 61a6e68 | 2009-10-09 17:37:50 -0700 | [diff] [blame] | 1763 | mPreviousTransparentRegion.setEmpty(); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 1764 | |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1765 | // Only initialize up-front if transparent regions are not |
| 1766 | // requested, otherwise defer to see if the entire window |
| 1767 | // will be transparent |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 1768 | if (mAttachInfo.mHardwareRenderer != null) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1769 | try { |
Romain Guy | 786fc93 | 2012-07-24 16:24:56 -0700 | [diff] [blame] | 1770 | hwInitialized = mAttachInfo.mHardwareRenderer.initialize( |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1771 | mSurface); |
John Reck | 63005e6 | 2015-05-19 15:00:13 -0700 | [diff] [blame] | 1772 | if (hwInitialized && (host.mPrivateFlags |
| 1773 | & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) == 0) { |
| 1774 | // Don't pre-allocate if transparent regions |
| 1775 | // are requested as they may not be needed |
| 1776 | mSurface.allocateBuffers(); |
| 1777 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1778 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1779 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1780 | return; |
| 1781 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | } else if (!mSurface.isValid()) { |
| 1785 | // If the surface has been removed, then reset the scroll |
| 1786 | // positions. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 1787 | if (mLastScrolledFocus != null) { |
| 1788 | mLastScrolledFocus.clear(); |
| 1789 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | mScrollY = mCurScrollY = 0; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 1791 | if (mView instanceof RootViewSurfaceTaker) { |
| 1792 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 1793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | if (mScroller != null) { |
| 1795 | mScroller.abortAnimation(); |
| 1796 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1797 | // Our surface is gone |
| 1798 | if (mAttachInfo.mHardwareRenderer != null && |
| 1799 | mAttachInfo.mHardwareRenderer.isEnabled()) { |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 1800 | mAttachInfo.mHardwareRenderer.destroy(); |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1801 | } |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1802 | } else if ((surfaceGenerationId != mSurface.getGenerationId() |
| 1803 | || surfaceSizeChanged) |
| 1804 | && mSurfaceHolder == null |
| 1805 | && mAttachInfo.mHardwareRenderer != null) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 1806 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1807 | try { |
Chong Zhang | f4abc2b | 2015-11-12 23:40:58 -0800 | [diff] [blame] | 1808 | // Need to do updateSurface (which leads to CanvasContext::setSurface and |
| 1809 | // re-create the EGLSurface) if either the Surface changed (as indicated by |
| 1810 | // generation id), or WindowManager changed the surface size. The latter is |
| 1811 | // because on some chips, changing the consumer side's BufferQueue size may |
| 1812 | // not take effect immediately unless we create a new EGLSurface. |
| 1813 | // Note that frame size change doesn't always imply surface size change (eg. |
| 1814 | // drag resizing uses fullscreen surface), need to check surfaceSizeChanged |
| 1815 | // flag from WindowManager. |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 1816 | mAttachInfo.mHardwareRenderer.updateSurface(mSurface); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1817 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 1818 | handleOutOfResourcesException(e); |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 1819 | return; |
| 1820 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1822 | |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1823 | final boolean freeformResizing = (relayoutResult |
| 1824 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_FREEFORM) != 0; |
| 1825 | final boolean dockedResizing = (relayoutResult |
| 1826 | & WindowManagerGlobal.RELAYOUT_RES_DRAG_RESIZING_DOCKED) != 0; |
| 1827 | final boolean dragResizing = freeformResizing || dockedResizing; |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1828 | if (mDragResizing != dragResizing) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1829 | if (dragResizing) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 1830 | startDragResizing(mPendingBackDropFrame, |
| 1831 | mWinFrame.equals(mPendingBackDropFrame), mPendingVisibleInsets, |
| 1832 | mPendingStableInsets); |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 1833 | mResizeMode = freeformResizing |
| 1834 | ? RESIZE_MODE_FREEFORM |
| 1835 | : RESIZE_MODE_DOCKED_DIVIDER; |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1836 | } else { |
| 1837 | // We shouldn't come here, but if we come we should end the resize. |
| 1838 | endDragResizing(); |
| 1839 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1840 | } |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 1841 | if (!USE_MT_RENDERER) { |
| 1842 | if (dragResizing) { |
| 1843 | mCanvasOffsetX = mWinFrame.left; |
| 1844 | mCanvasOffsetY = mWinFrame.top; |
| 1845 | } else { |
| 1846 | mCanvasOffsetX = mCanvasOffsetY = 0; |
| 1847 | } |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 1848 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1849 | } catch (RemoteException e) { |
| 1850 | } |
Romain Guy | 1d0c708 | 2011-08-03 16:22:24 -0700 | [diff] [blame] | 1851 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | if (DEBUG_ORIENTATION) Log.v( |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1853 | TAG, "Relayout returned: frame=" + frame + ", surface=" + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1855 | mAttachInfo.mWindowLeft = frame.left; |
| 1856 | mAttachInfo.mWindowTop = frame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | |
| 1858 | // !!FIXME!! This next section handles the case where we did not get the |
| 1859 | // window size we asked for. We should avoid this by getting a maximum size from |
| 1860 | // the window session beforehand. |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1861 | if (mWidth != frame.width() || mHeight != frame.height()) { |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 1862 | mWidth = frame.width(); |
| 1863 | mHeight = frame.height(); |
| 1864 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1866 | if (mSurfaceHolder != null) { |
| 1867 | // The app owns the surface; tell it about what is going on. |
| 1868 | if (mSurface.isValid()) { |
| 1869 | // XXX .copyFrom() doesn't work! |
| 1870 | //mSurfaceHolder.mSurface.copyFrom(mSurface); |
| 1871 | mSurfaceHolder.mSurface = mSurface; |
| 1872 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 1873 | mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1874 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1875 | if (mSurface.isValid()) { |
| 1876 | if (!hadSurface) { |
| 1877 | mSurfaceHolder.ungetCallbacks(); |
| 1878 | |
| 1879 | mIsCreating = true; |
| 1880 | mSurfaceHolderCallback.surfaceCreated(mSurfaceHolder); |
| 1881 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1882 | if (callbacks != null) { |
| 1883 | for (SurfaceHolder.Callback c : callbacks) { |
| 1884 | c.surfaceCreated(mSurfaceHolder); |
| 1885 | } |
| 1886 | } |
| 1887 | surfaceChanged = true; |
| 1888 | } |
| 1889 | if (surfaceChanged) { |
| 1890 | mSurfaceHolderCallback.surfaceChanged(mSurfaceHolder, |
| 1891 | lp.format, mWidth, mHeight); |
| 1892 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1893 | if (callbacks != null) { |
| 1894 | for (SurfaceHolder.Callback c : callbacks) { |
| 1895 | c.surfaceChanged(mSurfaceHolder, lp.format, |
| 1896 | mWidth, mHeight); |
| 1897 | } |
| 1898 | } |
| 1899 | } |
| 1900 | mIsCreating = false; |
| 1901 | } else if (hadSurface) { |
| 1902 | mSurfaceHolder.ungetCallbacks(); |
| 1903 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1904 | mSurfaceHolderCallback.surfaceDestroyed(mSurfaceHolder); |
| 1905 | if (callbacks != null) { |
| 1906 | for (SurfaceHolder.Callback c : callbacks) { |
| 1907 | c.surfaceDestroyed(mSurfaceHolder); |
| 1908 | } |
| 1909 | } |
| 1910 | mSurfaceHolder.mSurfaceLock.lock(); |
Jozef BABJAK | 93c5b6a | 2011-02-22 09:33:19 +0100 | [diff] [blame] | 1911 | try { |
| 1912 | mSurfaceHolder.mSurface = new Surface(); |
| 1913 | } finally { |
| 1914 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 1915 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
Romain Guy | 53389bd | 2010-09-07 17:16:32 -0700 | [diff] [blame] | 1918 | |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 1919 | final ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 1920 | if (hardwareRenderer != null && hardwareRenderer.isEnabled()) { |
| 1921 | if (hwInitialized |
| 1922 | || mWidth != hardwareRenderer.getWidth() |
| 1923 | || mHeight != hardwareRenderer.getHeight()) { |
| 1924 | hardwareRenderer.setup(mWidth, mHeight, mAttachInfo, |
| 1925 | mWindowAttributes.surfaceInsets); |
Romain Guy | 0398575 | 2011-07-11 15:33:51 -0700 | [diff] [blame] | 1926 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1929 | if (!mStopped || mReportNextDraw) { |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1930 | boolean focusChangedDueToTouchMode = ensureTouchModeLocally( |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1931 | (relayoutResult&WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE) != 0); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1932 | if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth() |
| 1933 | || mHeight != host.getMeasuredHeight() || contentInsetsChanged) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1934 | int childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width); |
| 1935 | int childHeightMeasureSpec = getRootMeasureSpec(mHeight, lp.height); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1936 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1937 | if (DEBUG_LAYOUT) Log.v(mTag, "Ooops, something changed! mWidth=" |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1938 | + mWidth + " measuredWidth=" + host.getMeasuredWidth() |
| 1939 | + " mHeight=" + mHeight |
| 1940 | + " measuredHeight=" + host.getMeasuredHeight() |
| 1941 | + " coveredInsetsChanged=" + contentInsetsChanged); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1942 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1943 | // Ask host how big it wants to be |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1944 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1945 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1946 | // Implementation of weights from WindowManager.LayoutParams |
| 1947 | // We just grow the dimensions as needed and re-measure if |
| 1948 | // needs be |
| 1949 | int width = host.getMeasuredWidth(); |
| 1950 | int height = host.getMeasuredHeight(); |
| 1951 | boolean measureAgain = false; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1952 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1953 | if (lp.horizontalWeight > 0.0f) { |
| 1954 | width += (int) ((mWidth - width) * lp.horizontalWeight); |
| 1955 | childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(width, |
| 1956 | MeasureSpec.EXACTLY); |
| 1957 | measureAgain = true; |
| 1958 | } |
| 1959 | if (lp.verticalWeight > 0.0f) { |
| 1960 | height += (int) ((mHeight - height) * lp.verticalWeight); |
| 1961 | childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, |
| 1962 | MeasureSpec.EXACTLY); |
| 1963 | measureAgain = true; |
| 1964 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1965 | |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1966 | if (measureAgain) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 1967 | if (DEBUG_LAYOUT) Log.v(mTag, |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1968 | "And hey let's measure once more: width=" + width |
| 1969 | + " height=" + height); |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 1970 | performMeasure(childWidthMeasureSpec, childHeightMeasureSpec); |
Dianne Hackborn | ce418e6 | 2011-03-01 14:31:38 -0800 | [diff] [blame] | 1971 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 1972 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 1973 | layoutRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1974 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1975 | } |
Svetoslav Ganov | c9c9a48 | 2012-07-16 08:46:07 -0700 | [diff] [blame] | 1976 | } else { |
| 1977 | // Not the first pass and no window/insets/visibility change but the window |
| 1978 | // may have moved and we need check that and if so to update the left and right |
| 1979 | // in the attach info. We translate only the window frame since on window move |
| 1980 | // the window manager tells us only for the new frame but the insets are the |
| 1981 | // same and we do not want to translate them more than once. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 1982 | maybeHandleWindowMove(frame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
Craig Mautner | 72d6f21 | 2015-02-19 16:33:09 -0800 | [diff] [blame] | 1985 | final boolean didLayout = layoutRequested && (!mStopped || mReportNextDraw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | boolean triggerGlobalLayoutListener = didLayout |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 1987 | || mAttachInfo.mRecomputeGlobalAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | if (didLayout) { |
Jorim Jaggi | 26d02d2 | 2016-02-24 18:37:51 -0500 | [diff] [blame] | 1989 | performLayout(lp, mWidth, mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 1991 | // 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] | 1992 | // We can compute the transparent area |
| 1993 | |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 1994 | if ((host.mPrivateFlags & View.PFLAG_REQUEST_TRANSPARENT_REGIONS) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | // start out transparent |
| 1996 | // TODO: AVOID THAT CALL BY CACHING THE RESULT? |
| 1997 | host.getLocationInWindow(mTmpLocation); |
| 1998 | mTransparentRegion.set(mTmpLocation[0], mTmpLocation[1], |
| 1999 | mTmpLocation[0] + host.mRight - host.mLeft, |
| 2000 | mTmpLocation[1] + host.mBottom - host.mTop); |
| 2001 | |
| 2002 | host.gatherTransparentRegion(mTransparentRegion); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 2003 | if (mTranslator != null) { |
| 2004 | mTranslator.translateRegionInWindowToScreen(mTransparentRegion); |
| 2005 | } |
| 2006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | if (!mTransparentRegion.equals(mPreviousTransparentRegion)) { |
| 2008 | mPreviousTransparentRegion.set(mTransparentRegion); |
Mathias Agopian | 54e3d384 | 2013-04-12 15:13:12 -0700 | [diff] [blame] | 2009 | mFullRedrawNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | // reconfigure window manager |
| 2011 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2012 | mWindowSession.setTransparentRegion(mWindow, mTransparentRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | } catch (RemoteException e) { |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | if (DBG) { |
| 2019 | System.out.println("======================================"); |
Chet Haase | 4610eef | 2015-12-03 07:38:11 -0800 | [diff] [blame] | 2020 | System.out.println("performTraversals -- after setFrame"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | host.debug(); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | if (triggerGlobalLayoutListener) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2026 | mAttachInfo.mRecomputeGlobalAttributes = false; |
| 2027 | mAttachInfo.mTreeObserver.dispatchOnGlobalLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | } |
| 2029 | |
| 2030 | if (computesInternalInsets) { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2031 | // Clear the original insets. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2032 | final ViewTreeObserver.InternalInsetsInfo insets = mAttachInfo.mGivenInternalInsets; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2033 | insets.reset(); |
| 2034 | |
| 2035 | // Compute new insets in place. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2036 | mAttachInfo.mTreeObserver.dispatchOnComputeInternalInsets(insets); |
| 2037 | mAttachInfo.mHasNonEmptyGivenInternalInsets = !insets.isEmpty(); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2038 | |
| 2039 | // Tell the window manager. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | if (insetsPending || !mLastGivenInsets.equals(insets)) { |
| 2041 | mLastGivenInsets.set(insets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2042 | |
| 2043 | // Translate insets to screen coordinates if needed. |
| 2044 | final Rect contentInsets; |
| 2045 | final Rect visibleInsets; |
| 2046 | final Region touchableRegion; |
| 2047 | if (mTranslator != null) { |
| 2048 | contentInsets = mTranslator.getTranslatedContentInsets(insets.contentInsets); |
| 2049 | visibleInsets = mTranslator.getTranslatedVisibleInsets(insets.visibleInsets); |
| 2050 | touchableRegion = mTranslator.getTranslatedTouchableArea(insets.touchableRegion); |
| 2051 | } else { |
| 2052 | contentInsets = insets.contentInsets; |
| 2053 | visibleInsets = insets.visibleInsets; |
| 2054 | touchableRegion = insets.touchableRegion; |
| 2055 | } |
| 2056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2057 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2058 | mWindowSession.setInsets(mWindow, insets.mTouchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2059 | contentInsets, visibleInsets, touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | } catch (RemoteException e) { |
| 2061 | } |
| 2062 | } |
| 2063 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | if (mFirst) { |
| 2066 | // handle first focus request |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2067 | 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] | 2068 | + mView.hasFocus()); |
| 2069 | if (mView != null) { |
| 2070 | if (!mView.hasFocus()) { |
| 2071 | mView.requestFocus(View.FOCUS_FORWARD); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2072 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: requested focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2073 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2075 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: existing focused view=" |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2076 | + mView.findFocus()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | } |
| 2078 | } |
| 2079 | } |
| 2080 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2081 | final boolean changedVisibility = (viewVisibilityChanged || mFirst) && isViewVisible; |
| 2082 | final boolean hasWindowFocus = mAttachInfo.mHasWindowFocus && isViewVisible; |
| 2083 | final boolean regainedFocus = hasWindowFocus && mLostWindowFocus; |
| 2084 | if (regainedFocus) { |
| 2085 | mLostWindowFocus = false; |
| 2086 | } else if (!hasWindowFocus && mHadWindowFocus) { |
| 2087 | mLostWindowFocus = true; |
| 2088 | } |
| 2089 | |
| 2090 | if (changedVisibility || regainedFocus) { |
| 2091 | host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 2092 | } |
| 2093 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2094 | mFirst = false; |
| 2095 | mWillDrawSoon = false; |
| 2096 | mNewSurfaceNeeded = false; |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 2097 | mActivityRelaunched = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | mViewVisibility = viewVisibility; |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2099 | mHadWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2101 | if (hasWindowFocus && !isInLocalFocusMode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | final boolean imTarget = WindowManager.LayoutParams |
| 2103 | .mayUseInputMethod(mWindowAttributes.flags); |
| 2104 | if (imTarget != mLastWasImTarget) { |
| 2105 | mLastWasImTarget = imTarget; |
| 2106 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 2107 | if (imm != null && imTarget) { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2108 | imm.onPreWindowFocus(mView, hasWindowFocus); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2109 | imm.onPostWindowFocus(mView, mView.findFocus(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2110 | mWindowAttributes.softInputMode, |
| 2111 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 2112 | } |
| 2113 | } |
| 2114 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2115 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2116 | // Remember if we must report the next draw. |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2117 | if ((relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2118 | mReportNextDraw = true; |
| 2119 | } |
| 2120 | |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2121 | boolean cancelDraw = mAttachInfo.mTreeObserver.dispatchOnPreDraw() || !isViewVisible; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | |
Jorim Jaggi | 3127c2a4 | 2016-01-26 18:48:44 -0800 | [diff] [blame] | 2123 | if (!cancelDraw) { |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2124 | if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
| 2125 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2126 | mPendingTransitions.get(i).startChangingAnimations(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2127 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2128 | mPendingTransitions.clear(); |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2129 | } |
Chet Haase | 9c45041 | 2015-10-01 13:25:58 -0700 | [diff] [blame] | 2130 | |
| 2131 | performDraw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | } else { |
Alan Viverette | 64bf97a | 2015-09-18 16:42:00 -0400 | [diff] [blame] | 2133 | if (isViewVisible) { |
Chris Wren | 78cb7cf | 2012-05-15 12:36:44 -0400 | [diff] [blame] | 2134 | // Try again |
| 2135 | scheduleTraversals(); |
| 2136 | } else if (mPendingTransitions != null && mPendingTransitions.size() > 0) { |
Chet Haase | d56c695 | 2011-09-07 08:46:23 -0700 | [diff] [blame] | 2137 | for (int i = 0; i < mPendingTransitions.size(); ++i) { |
| 2138 | mPendingTransitions.get(i).endChangingAnimations(); |
| 2139 | } |
| 2140 | mPendingTransitions.clear(); |
| 2141 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | } |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 2143 | |
| 2144 | mIsInTraversal = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | } |
| 2146 | |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 2147 | private void maybeHandleWindowMove(Rect frame) { |
| 2148 | |
| 2149 | // TODO: Well, we are checking whether the frame has changed similarly |
| 2150 | // to how this is done for the insets. This is however incorrect since |
| 2151 | // the insets and the frame are translated. For example, the old frame |
| 2152 | // was (1, 1 - 1, 1) and was translated to say (2, 2 - 2, 2), now the new |
| 2153 | // reported frame is (2, 2 - 2, 2) which implies no change but this is not |
| 2154 | // true since we are comparing a not translated value to a translated one. |
| 2155 | // This scenario is rare but we may want to fix that. |
| 2156 | |
| 2157 | final boolean windowMoved = mAttachInfo.mWindowLeft != frame.left |
| 2158 | || mAttachInfo.mWindowTop != frame.top; |
| 2159 | if (windowMoved) { |
| 2160 | if (mTranslator != null) { |
| 2161 | mTranslator.translateRectInScreenToAppWinFrame(frame); |
| 2162 | } |
| 2163 | mAttachInfo.mWindowLeft = frame.left; |
| 2164 | mAttachInfo.mWindowTop = frame.top; |
| 2165 | |
| 2166 | // Update the light position for the new window offsets. |
| 2167 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2168 | mAttachInfo.mHardwareRenderer.setLightCenter(mAttachInfo); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
Jorim Jaggi | 3127c2a4 | 2016-01-26 18:48:44 -0800 | [diff] [blame] | 2172 | |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2173 | private void handleOutOfResourcesException(Surface.OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2174 | Log.e(mTag, "OutOfResourcesException initializing HW surface", e); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2175 | try { |
| 2176 | if (!mWindowSession.outOfMemory(mWindow) && |
| 2177 | Process.myUid() != Process.SYSTEM_UID) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2178 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2179 | Process.killProcess(Process.myPid()); |
| 2180 | } |
| 2181 | } catch (RemoteException ex) { |
| 2182 | } |
| 2183 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2184 | } |
| 2185 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2186 | private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) { |
| 2187 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure"); |
| 2188 | try { |
| 2189 | mView.measure(childWidthMeasureSpec, childHeightMeasureSpec); |
| 2190 | } finally { |
| 2191 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2192 | } |
| 2193 | } |
| 2194 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2195 | /** |
| 2196 | * Called by {@link android.view.View#isInLayout()} to determine whether the view hierarchy |
| 2197 | * is currently undergoing a layout pass. |
| 2198 | * |
| 2199 | * @return whether the view hierarchy is currently undergoing a layout pass |
| 2200 | */ |
| 2201 | boolean isInLayout() { |
| 2202 | return mInLayout; |
| 2203 | } |
| 2204 | |
| 2205 | /** |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2206 | * Called by {@link android.view.View#requestLayout()} if the view hierarchy is currently |
| 2207 | * undergoing a layout pass. requestLayout() should not generally be called during layout, |
| 2208 | * unless the container hierarchy knows what it is doing (i.e., it is fine as long as |
| 2209 | * all children in that container hierarchy are measured and laid out at the end of the layout |
| 2210 | * pass for that container). If requestLayout() is called anyway, we handle it correctly |
| 2211 | * by registering all requesters during a frame as it proceeds. At the end of the frame, |
| 2212 | * we check all of those views to see if any still have pending layout requests, which |
| 2213 | * indicates that they were not correctly handled by their container hierarchy. If that is |
| 2214 | * the case, we clear all such flags in the tree, to remove the buggy flag state that leads |
| 2215 | * 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] | 2216 | * 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] | 2217 | * requests to the next frame to avoid possible infinite loops. |
| 2218 | * |
| 2219 | * <p>The return value from this method indicates whether the request should proceed |
| 2220 | * (if it is a request during the first layout pass) or should be skipped and posted to the |
| 2221 | * 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] | 2222 | * |
| 2223 | * @param view the view that requested the layout. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2224 | * |
| 2225 | * @return true if request should proceed, false otherwise. |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2226 | */ |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2227 | boolean requestLayoutDuringLayout(final View view) { |
| 2228 | if (view.mParent == null || view.mAttachInfo == null) { |
| 2229 | // Would not normally trigger another layout, so just let it pass through as usual |
| 2230 | return true; |
| 2231 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2232 | if (!mLayoutRequesters.contains(view)) { |
| 2233 | mLayoutRequesters.add(view); |
| 2234 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2235 | if (!mHandlingLayoutInLayoutRequest) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2236 | // Let the request proceed normally; it will be processed in a second layout pass |
| 2237 | // if necessary |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2238 | return true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2239 | } else { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2240 | // Don't let the request proceed during the second layout pass. |
| 2241 | // It will post to the next frame instead. |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2242 | return false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | |
Chet Haase | 3efa7b5 | 2012-12-03 08:33:17 -0800 | [diff] [blame] | 2246 | private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth, |
| 2247 | int desiredWindowHeight) { |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2248 | mLayoutRequested = false; |
| 2249 | mScrollMayChange = true; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2250 | mInLayout = true; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2251 | |
| 2252 | final View host = mView; |
| 2253 | if (DEBUG_ORIENTATION || DEBUG_LAYOUT) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2254 | Log.v(mTag, "Laying out " + host + " to (" + |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2255 | host.getMeasuredWidth() + ", " + host.getMeasuredHeight() + ")"); |
| 2256 | } |
| 2257 | |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2258 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "layout"); |
| 2259 | try { |
| 2260 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2261 | |
Chet Haase | d5a8352 | 2012-11-21 16:24:44 -0800 | [diff] [blame] | 2262 | mInLayout = false; |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2263 | int numViewsRequestingLayout = mLayoutRequesters.size(); |
| 2264 | if (numViewsRequestingLayout > 0) { |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2265 | // requestLayout() was called during layout. |
| 2266 | // If no layout-request flags are set on the requesting views, there is no problem. |
| 2267 | // If some requests are still pending, then we need to clear those flags and do |
| 2268 | // a full request/measure/layout pass to handle this situation. |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2269 | ArrayList<View> validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, |
| 2270 | false); |
| 2271 | if (validLayoutRequesters != null) { |
| 2272 | // Set this flag to indicate that any further requests are happening during |
| 2273 | // the second pass, which may result in posting those requests to the next |
| 2274 | // frame instead |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2275 | mHandlingLayoutInLayoutRequest = true; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2276 | |
| 2277 | // Process fresh layout requests, then measure and layout |
| 2278 | int numValidRequests = validLayoutRequesters.size(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2279 | for (int i = 0; i < numValidRequests; ++i) { |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2280 | final View view = validLayoutRequesters.get(i); |
| 2281 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2282 | " during layout: running second layout pass"); |
| 2283 | view.requestLayout(); |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2284 | } |
| 2285 | measureHierarchy(host, lp, mView.getContext().getResources(), |
| 2286 | desiredWindowWidth, desiredWindowHeight); |
| 2287 | mInLayout = true; |
| 2288 | host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight()); |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2289 | |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2290 | mHandlingLayoutInLayoutRequest = false; |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2291 | |
| 2292 | // Check the valid requests again, this time without checking/clearing the |
| 2293 | // layout flags, since requests happening during the second pass get noop'd |
| 2294 | validLayoutRequesters = getValidLayoutRequesters(mLayoutRequesters, true); |
| 2295 | if (validLayoutRequesters != null) { |
| 2296 | final ArrayList<View> finalRequesters = validLayoutRequesters; |
| 2297 | // Post second-pass requests to the next frame |
| 2298 | getRunQueue().post(new Runnable() { |
| 2299 | @Override |
| 2300 | public void run() { |
| 2301 | int numValidRequests = finalRequesters.size(); |
| 2302 | for (int i = 0; i < numValidRequests; ++i) { |
| 2303 | final View view = finalRequesters.get(i); |
| 2304 | Log.w("View", "requestLayout() improperly called by " + view + |
| 2305 | " during second layout pass: posting in next frame"); |
| 2306 | view.requestLayout(); |
| 2307 | } |
| 2308 | } |
| 2309 | }); |
| 2310 | } |
Chet Haase | cc699b4 | 2012-12-13 09:06:55 -0800 | [diff] [blame] | 2311 | } |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2312 | |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2313 | } |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2314 | } finally { |
| 2315 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2316 | } |
Chet Haase | 9714057 | 2012-09-13 14:56:47 -0700 | [diff] [blame] | 2317 | mInLayout = false; |
Jeff Brown | c8d2668b | 2012-05-16 17:23:59 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Chet Haase | 107a482 | 2013-03-13 06:46:50 -0700 | [diff] [blame] | 2320 | /** |
| 2321 | * This method is called during layout when there have been calls to requestLayout() during |
| 2322 | * layout. It walks through the list of views that requested layout to determine which ones |
| 2323 | * still need it, based on visibility in the hierarchy and whether they have already been |
| 2324 | * handled (as is usually the case with ListView children). |
| 2325 | * |
| 2326 | * @param layoutRequesters The list of views that requested layout during layout |
| 2327 | * @param secondLayoutRequests Whether the requests were issued during the second layout pass. |
| 2328 | * If so, the FORCE_LAYOUT flag was not set on requesters. |
| 2329 | * @return A list of the actual views that still need to be laid out. |
| 2330 | */ |
| 2331 | private ArrayList<View> getValidLayoutRequesters(ArrayList<View> layoutRequesters, |
| 2332 | boolean secondLayoutRequests) { |
| 2333 | |
| 2334 | int numViewsRequestingLayout = layoutRequesters.size(); |
| 2335 | ArrayList<View> validLayoutRequesters = null; |
| 2336 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2337 | View view = layoutRequesters.get(i); |
| 2338 | if (view != null && view.mAttachInfo != null && view.mParent != null && |
| 2339 | (secondLayoutRequests || (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) == |
| 2340 | View.PFLAG_FORCE_LAYOUT)) { |
| 2341 | boolean gone = false; |
| 2342 | View parent = view; |
| 2343 | // Only trigger new requests for views in a non-GONE hierarchy |
| 2344 | while (parent != null) { |
| 2345 | if ((parent.mViewFlags & View.VISIBILITY_MASK) == View.GONE) { |
| 2346 | gone = true; |
| 2347 | break; |
| 2348 | } |
| 2349 | if (parent.mParent instanceof View) { |
| 2350 | parent = (View) parent.mParent; |
| 2351 | } else { |
| 2352 | parent = null; |
| 2353 | } |
| 2354 | } |
| 2355 | if (!gone) { |
| 2356 | if (validLayoutRequesters == null) { |
| 2357 | validLayoutRequesters = new ArrayList<View>(); |
| 2358 | } |
| 2359 | validLayoutRequesters.add(view); |
| 2360 | } |
| 2361 | } |
| 2362 | } |
| 2363 | if (!secondLayoutRequests) { |
| 2364 | // If we're checking the layout flags, then we need to clean them up also |
| 2365 | for (int i = 0; i < numViewsRequestingLayout; ++i) { |
| 2366 | View view = layoutRequesters.get(i); |
| 2367 | while (view != null && |
| 2368 | (view.mPrivateFlags & View.PFLAG_FORCE_LAYOUT) != 0) { |
| 2369 | view.mPrivateFlags &= ~View.PFLAG_FORCE_LAYOUT; |
| 2370 | if (view.mParent instanceof View) { |
| 2371 | view = (View) view.mParent; |
| 2372 | } else { |
| 2373 | view = null; |
| 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | } |
| 2378 | layoutRequesters.clear(); |
| 2379 | return validLayoutRequesters; |
| 2380 | } |
| 2381 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2382 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | public void requestTransparentRegion(View child) { |
| 2384 | // the test below should not fail unless someone is messing with us |
| 2385 | checkThread(); |
| 2386 | if (mView == child) { |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2387 | mView.mPrivateFlags |= View.PFLAG_REQUEST_TRANSPARENT_REGIONS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2388 | // Need to make sure we re-evaluate the window attributes next |
| 2389 | // time around, to ensure the window has the correct format. |
| 2390 | mWindowAttributesChanged = true; |
Romain Guy | f21c9b0 | 2011-09-06 16:56:54 -0700 | [diff] [blame] | 2391 | mWindowAttributesChangesFlag = 0; |
Mathias Agopian | 1bd80ad | 2010-11-04 17:13:39 -0700 | [diff] [blame] | 2392 | requestLayout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | /** |
| 2397 | * Figures out the measure spec for the root view in a window based on it's |
| 2398 | * layout params. |
| 2399 | * |
| 2400 | * @param windowSize |
| 2401 | * The available width or height of the window |
| 2402 | * |
| 2403 | * @param rootDimension |
| 2404 | * The layout params for one dimension (width or height) of the |
| 2405 | * window. |
| 2406 | * |
| 2407 | * @return The measure spec to use to measure the root view. |
| 2408 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 2409 | private static int getRootMeasureSpec(int windowSize, int rootDimension) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | int measureSpec; |
| 2411 | switch (rootDimension) { |
| 2412 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 2413 | case ViewGroup.LayoutParams.MATCH_PARENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | // Window can't resize. Force root view to be windowSize. |
| 2415 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY); |
| 2416 | break; |
| 2417 | case ViewGroup.LayoutParams.WRAP_CONTENT: |
| 2418 | // Window can resize. Set max size for root view. |
| 2419 | measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST); |
| 2420 | break; |
| 2421 | default: |
| 2422 | // Window wants to be an exact size. Force root view to be that size. |
| 2423 | measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY); |
| 2424 | break; |
| 2425 | } |
| 2426 | return measureSpec; |
| 2427 | } |
| 2428 | |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2429 | int mHardwareXOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2430 | int mHardwareYOffset; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2431 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2432 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2433 | public void onHardwarePreDraw(DisplayListCanvas canvas) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2434 | canvas.translate(-mHardwareXOffset, -mHardwareYOffset); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2435 | } |
| 2436 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2437 | @Override |
Chris Craik | f6829a0 | 2015-03-10 10:28:59 -0700 | [diff] [blame] | 2438 | public void onHardwarePostDraw(DisplayListCanvas canvas) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2439 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2442 | /** |
| 2443 | * @hide |
| 2444 | */ |
| 2445 | void outputDisplayList(View view) { |
Chris Craik | 356b5fe | 2015-07-07 10:39:36 -0700 | [diff] [blame] | 2446 | view.mRenderNode.output(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 2447 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2448 | ((ThreadedRenderer)mAttachInfo.mHardwareRenderer).serializeDisplayListTree(); |
| 2449 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | /** |
| 2453 | * @see #PROPERTY_PROFILE_RENDERING |
| 2454 | */ |
| 2455 | private void profileRendering(boolean enabled) { |
| 2456 | if (mProfileRendering) { |
| 2457 | mRenderProfilingEnabled = enabled; |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2458 | |
| 2459 | if (mRenderProfiler != null) { |
| 2460 | mChoreographer.removeFrameCallback(mRenderProfiler); |
| 2461 | } |
| 2462 | if (mRenderProfilingEnabled) { |
| 2463 | if (mRenderProfiler == null) { |
| 2464 | mRenderProfiler = new Choreographer.FrameCallback() { |
| 2465 | @Override |
| 2466 | public void doFrame(long frameTimeNanos) { |
| 2467 | mDirty.set(0, 0, mWidth, mHeight); |
| 2468 | scheduleTraversals(); |
| 2469 | if (mRenderProfilingEnabled) { |
| 2470 | mChoreographer.postFrameCallback(mRenderProfiler); |
| 2471 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2472 | } |
Chris Craik | ae4f3204 | 2013-02-07 12:57:10 -0800 | [diff] [blame] | 2473 | }; |
| 2474 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 2475 | mChoreographer.postFrameCallback(mRenderProfiler); |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2476 | } else { |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2477 | mRenderProfiler = null; |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2482 | /** |
| 2483 | * Called from draw() when DEBUG_FPS is enabled |
| 2484 | */ |
| 2485 | private void trackFPS() { |
| 2486 | // Tracks frames per second drawn. First value in a series of draws may be bogus |
| 2487 | // because it down not account for the intervening idle time |
| 2488 | long nowTime = System.currentTimeMillis(); |
| 2489 | if (mFpsStartTime < 0) { |
| 2490 | mFpsStartTime = mFpsPrevTime = nowTime; |
| 2491 | mFpsNumFrames = 0; |
| 2492 | } else { |
| 2493 | ++mFpsNumFrames; |
| 2494 | String thisHash = Integer.toHexString(System.identityHashCode(this)); |
| 2495 | long frameTime = nowTime - mFpsPrevTime; |
| 2496 | long totalTime = nowTime - mFpsStartTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2497 | Log.v(mTag, "0x" + thisHash + "\tFrame time:\t" + frameTime); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2498 | mFpsPrevTime = nowTime; |
| 2499 | if (totalTime > 1000) { |
| 2500 | float fps = (float) mFpsNumFrames * 1000 / totalTime; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2501 | Log.v(mTag, "0x" + thisHash + "\tFPS:\t" + fps); |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2502 | mFpsStartTime = nowTime; |
| 2503 | mFpsNumFrames = 0; |
| 2504 | } |
| 2505 | } |
| 2506 | } |
| 2507 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2508 | private void performDraw() { |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 2509 | if (mAttachInfo.mDisplayState == Display.STATE_OFF && !mReportNextDraw) { |
Craig Mautner | 006f0e4 | 2012-03-21 11:00:32 -0700 | [diff] [blame] | 2510 | return; |
| 2511 | } |
Romain Guy | 7e4e561 | 2012-03-05 14:37:29 -0800 | [diff] [blame] | 2512 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2513 | final boolean fullRedrawNeeded = mFullRedrawNeeded; |
| 2514 | mFullRedrawNeeded = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2515 | |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2516 | mIsDrawing = true; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2517 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "draw"); |
| 2518 | try { |
| 2519 | draw(fullRedrawNeeded); |
| 2520 | } finally { |
Romain Guy | 1f59e5c | 2012-05-06 14:11:16 -0700 | [diff] [blame] | 2521 | mIsDrawing = false; |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 2522 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 2523 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2524 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 2525 | // For whatever reason we didn't create a HardwareRenderer, end any |
| 2526 | // hardware animations that are now dangling |
| 2527 | if (mAttachInfo.mPendingAnimatingRenderNodes != null) { |
| 2528 | final int count = mAttachInfo.mPendingAnimatingRenderNodes.size(); |
| 2529 | for (int i = 0; i < count; i++) { |
| 2530 | mAttachInfo.mPendingAnimatingRenderNodes.get(i).endAllAnimators(); |
| 2531 | } |
| 2532 | mAttachInfo.mPendingAnimatingRenderNodes.clear(); |
| 2533 | } |
| 2534 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2535 | if (mReportNextDraw) { |
| 2536 | mReportNextDraw = false; |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2537 | |
| 2538 | // if we're using multi-thread renderer, wait for the window frame draws |
| 2539 | if (mWindowDrawCountDown != null) { |
| 2540 | try { |
| 2541 | mWindowDrawCountDown.await(); |
| 2542 | } catch (InterruptedException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2543 | Log.e(mTag, "Window redraw count down interruped!"); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2544 | } |
| 2545 | mWindowDrawCountDown = null; |
| 2546 | } |
| 2547 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 2548 | if (mAttachInfo.mHardwareRenderer != null) { |
| 2549 | mAttachInfo.mHardwareRenderer.fence(); |
| 2550 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2551 | |
| 2552 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2553 | Log.v(mTag, "FINISHED DRAWING: " + mWindowAttributes.getTitle()); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2554 | } |
| 2555 | if (mSurfaceHolder != null && mSurface.isValid()) { |
| 2556 | mSurfaceHolderCallback.surfaceRedrawNeeded(mSurfaceHolder); |
| 2557 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 2558 | if (callbacks != null) { |
| 2559 | for (SurfaceHolder.Callback c : callbacks) { |
| 2560 | if (c instanceof SurfaceHolder.Callback2) { |
Filip Gruszczynski | 1a4dfe5 | 2015-11-15 10:58:57 -0800 | [diff] [blame] | 2561 | ((SurfaceHolder.Callback2)c).surfaceRedrawNeeded(mSurfaceHolder); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | } |
| 2565 | } |
| 2566 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 2567 | mWindowSession.finishDrawing(mWindow); |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2568 | } catch (RemoteException e) { |
| 2569 | } |
| 2570 | } |
| 2571 | } |
| 2572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | private void draw(boolean fullRedrawNeeded) { |
| 2574 | Surface surface = mSurface; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 2575 | if (!surface.isValid()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2576 | return; |
| 2577 | } |
| 2578 | |
Chet Haase | 2f2022a | 2011-10-11 06:41:59 -0700 | [diff] [blame] | 2579 | if (DEBUG_FPS) { |
| 2580 | trackFPS(); |
| 2581 | } |
| 2582 | |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2583 | if (!sFirstDrawComplete) { |
| 2584 | synchronized (sFirstDrawHandlers) { |
| 2585 | sFirstDrawComplete = true; |
Romain Guy | 812ccbe | 2010-06-01 14:07:24 -0700 | [diff] [blame] | 2586 | final int count = sFirstDrawHandlers.size(); |
| 2587 | for (int i = 0; i< count; i++) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 2588 | mHandler.post(sFirstDrawHandlers.get(i)); |
Dianne Hackborn | 2a9094d | 2010-02-03 19:20:09 -0800 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 2592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | scrollToRectOrFocus(null, false); |
| 2594 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2595 | if (mAttachInfo.mViewScrollChanged) { |
| 2596 | mAttachInfo.mViewScrollChanged = false; |
| 2597 | mAttachInfo.mTreeObserver.dispatchOnScrollChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2599 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2600 | boolean animating = mScroller != null && mScroller.computeScrollOffset(); |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2601 | final int curScrollY; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2602 | if (animating) { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2603 | curScrollY = mScroller.getCurrY(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | } else { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2605 | curScrollY = mScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | } |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2607 | if (mCurScrollY != curScrollY) { |
| 2608 | mCurScrollY = curScrollY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | fullRedrawNeeded = true; |
Adrian Roos | 0e7ae4e | 2014-10-01 15:33:22 +0200 | [diff] [blame] | 2610 | if (mView instanceof RootViewSurfaceTaker) { |
| 2611 | ((RootViewSurfaceTaker) mView).onRootViewScrollYChanged(mCurScrollY); |
| 2612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2614 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2615 | final float appScale = mAttachInfo.mApplicationScale; |
| 2616 | final boolean scalingRequired = mAttachInfo.mScalingRequired; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2618 | int resizeAlpha = 0; |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2619 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2620 | final Rect dirty = mDirty; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2621 | if (mSurfaceHolder != null) { |
| 2622 | // The app owns the surface, we won't draw. |
| 2623 | dirty.setEmpty(); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 2624 | if (animating && mScroller != null) { |
| 2625 | mScroller.abortAnimation(); |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2626 | } |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 2627 | return; |
| 2628 | } |
Romain Guy | 58ef7fb | 2010-09-13 12:52:37 -0700 | [diff] [blame] | 2629 | |
| 2630 | if (fullRedrawNeeded) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2631 | mAttachInfo.mIgnoreDirtyState = true; |
Romain Guy | c3166e1 | 2011-08-08 15:00:03 -0700 | [diff] [blame] | 2632 | 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] | 2633 | } |
Chet Haase | ad4f703 | 2011-06-22 09:18:31 -0700 | [diff] [blame] | 2634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2636 | Log.v(mTag, "Draw " + mView + "/" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2637 | + mWindowAttributes.getTitle() |
| 2638 | + ": dirty={" + dirty.left + "," + dirty.top |
| 2639 | + "," + dirty.right + "," + dirty.bottom + "} surface=" |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 2640 | + surface + " surface.isValid()=" + surface.isValid() + ", appScale:" + |
| 2641 | appScale + ", width=" + mWidth + ", height=" + mHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2644 | mAttachInfo.mTreeObserver.dispatchOnDraw(); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2645 | |
Chong Zhang | 0275e39 | 2015-09-17 10:41:44 -0700 | [diff] [blame] | 2646 | int xOffset = -mCanvasOffsetX; |
| 2647 | int yOffset = -mCanvasOffsetY + curScrollY; |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2648 | final WindowManager.LayoutParams params = mWindowAttributes; |
| 2649 | final Rect surfaceInsets = params != null ? params.surfaceInsets : null; |
| 2650 | if (surfaceInsets != null) { |
| 2651 | xOffset -= surfaceInsets.left; |
| 2652 | yOffset -= surfaceInsets.top; |
| 2653 | |
| 2654 | // Offset dirty rect for surface insets. |
| 2655 | dirty.offset(surfaceInsets.left, surfaceInsets.right); |
| 2656 | } |
| 2657 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2658 | boolean accessibilityFocusDirty = false; |
| 2659 | final Drawable drawable = mAttachInfo.mAccessibilityFocusDrawable; |
| 2660 | if (drawable != null) { |
| 2661 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2662 | final boolean hasFocus = getAccessibilityFocusedRect(bounds); |
| 2663 | if (!hasFocus) { |
| 2664 | bounds.setEmpty(); |
| 2665 | } |
| 2666 | if (!bounds.equals(drawable.getBounds())) { |
| 2667 | accessibilityFocusDirty = true; |
| 2668 | } |
| 2669 | } |
| 2670 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 2671 | mAttachInfo.mDrawingTime = |
| 2672 | mChoreographer.getFrameTimeNanos() / TimeUtils.NANOS_PER_MS; |
| 2673 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2674 | if (!dirty.isEmpty() || mIsAnimating || accessibilityFocusDirty) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2675 | if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) { |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2676 | // If accessibility focus moved, always invalidate the root. |
| 2677 | boolean invalidateRoot = accessibilityFocusDirty; |
| 2678 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2679 | // Draw with hardware renderer. |
| 2680 | mIsAnimating = false; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2681 | |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 2682 | if (mHardwareYOffset != yOffset || mHardwareXOffset != xOffset) { |
| 2683 | mHardwareYOffset = yOffset; |
| 2684 | mHardwareXOffset = xOffset; |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2685 | invalidateRoot = true; |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2688 | if (invalidateRoot) { |
| 2689 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 2690 | } |
| 2691 | |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 2692 | dirty.setEmpty(); |
| 2693 | |
Skuhne | 980ee47 | 2015-10-06 11:31:31 -0700 | [diff] [blame] | 2694 | // Stage the content drawn size now. It will be transferred to the renderer |
| 2695 | // shortly before the draw commands get send to the renderer. |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2696 | final boolean updated = updateContentDrawBounds(); |
| 2697 | |
John Reck | 61375a8 | 2014-09-18 19:27:48 +0000 | [diff] [blame] | 2698 | mAttachInfo.mHardwareRenderer.draw(mView, mAttachInfo, this); |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 2699 | |
| 2700 | if (updated) { |
| 2701 | requestDrawWindow(); |
| 2702 | } |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2703 | } else { |
| 2704 | // If we get here with a disabled & requested hardware renderer, something went |
| 2705 | // wrong (an invalidate posted right before we destroyed the hardware surface |
| 2706 | // for instance) so we should just bail out. Locking the surface with software |
| 2707 | // rendering at this point would lock it forever and prevent hardware renderer |
| 2708 | // from doing its job when it comes back. |
| 2709 | // Before we request a new frame we must however attempt to reinitiliaze the |
| 2710 | // hardware renderer if it's in requested state. This would happen after an |
| 2711 | // eglTerminate() for instance. |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2712 | if (mAttachInfo.mHardwareRenderer != null && |
| 2713 | !mAttachInfo.mHardwareRenderer.isEnabled() && |
| 2714 | mAttachInfo.mHardwareRenderer.isRequested()) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2715 | |
| 2716 | try { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2717 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 2718 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 2719 | } catch (OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2720 | handleOutOfResourcesException(e); |
| 2721 | return; |
| 2722 | } |
| 2723 | |
| 2724 | mFullRedrawNeeded = true; |
| 2725 | scheduleTraversals(); |
| 2726 | return; |
| 2727 | } |
| 2728 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2729 | if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset, scalingRequired, dirty)) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2730 | return; |
| 2731 | } |
Jeff Brown | 95db2b2 | 2011-11-30 19:54:41 -0800 | [diff] [blame] | 2732 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2734 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 2735 | if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | mFullRedrawNeeded = true; |
| 2737 | scheduleTraversals(); |
| 2738 | } |
| 2739 | } |
| 2740 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2741 | /** |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2742 | * @return true if drawing was successful, false if an error occurred |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2743 | */ |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2744 | private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff, |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2745 | boolean scalingRequired, Rect dirty) { |
| 2746 | |
| 2747 | // Draw with software renderer. |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2748 | final Canvas canvas; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2749 | try { |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2750 | final int left = dirty.left; |
| 2751 | final int top = dirty.top; |
| 2752 | final int right = dirty.right; |
| 2753 | final int bottom = dirty.bottom; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2754 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2755 | canvas = mSurface.lockCanvas(dirty); |
| 2756 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 2757 | // The dirty rectangle can be modified by Surface.lockCanvas() |
| 2758 | //noinspection ConstantConditions |
Alan Viverette | a51cab9 | 2014-07-16 15:15:49 -0700 | [diff] [blame] | 2759 | if (left != dirty.left || top != dirty.top || right != dirty.right |
| 2760 | || bottom != dirty.bottom) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2761 | attachInfo.mIgnoreDirtyState = true; |
| 2762 | } |
| 2763 | |
| 2764 | // TODO: Do this in native |
| 2765 | canvas.setDensity(mDensity); |
| 2766 | } catch (Surface.OutOfResourcesException e) { |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 2767 | handleOutOfResourcesException(e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2768 | return false; |
| 2769 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2770 | Log.e(mTag, "Could not lock surface", e); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2771 | // Don't assume this is due to out of memory, it could be |
| 2772 | // something else, and if it is something else then we could |
| 2773 | // kill stuff (or ourself) for no reason. |
| 2774 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2775 | return false; |
| 2776 | } |
| 2777 | |
| 2778 | try { |
| 2779 | if (DEBUG_ORIENTATION || DEBUG_DRAW) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2780 | Log.v(mTag, "Surface " + surface + " drawing to bitmap w=" |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2781 | + canvas.getWidth() + ", h=" + canvas.getHeight()); |
| 2782 | //canvas.drawARGB(255, 255, 0, 0); |
| 2783 | } |
| 2784 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2785 | // If this bitmap's format includes an alpha channel, we |
| 2786 | // need to clear it before drawing so that the child will |
| 2787 | // properly re-composite its drawing on a transparent |
| 2788 | // background. This automatically respects the clip/dirty region |
| 2789 | // or |
| 2790 | // If we are applying an offset, we need to clear the area |
| 2791 | // where the offset doesn't appear to avoid having garbage |
| 2792 | // left in the blank areas. |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2793 | if (!canvas.isOpaque() || yoff != 0 || xoff != 0) { |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2794 | canvas.drawColor(0, PorterDuff.Mode.CLEAR); |
| 2795 | } |
| 2796 | |
| 2797 | dirty.setEmpty(); |
| 2798 | mIsAnimating = false; |
Dianne Hackborn | 4702a85 | 2012-08-17 15:18:29 -0700 | [diff] [blame] | 2799 | mView.mPrivateFlags |= View.PFLAG_DRAWN; |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2800 | |
| 2801 | if (DEBUG_DRAW) { |
| 2802 | Context cxt = mView.getContext(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2803 | Log.i(mTag, "Drawing: package:" + cxt.getPackageName() + |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2804 | ", metrics=" + cxt.getResources().getDisplayMetrics() + |
| 2805 | ", compatibilityInfo=" + cxt.getResources().getCompatibilityInfo()); |
| 2806 | } |
| 2807 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 2808 | canvas.translate(-xoff, -yoff); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2809 | if (mTranslator != null) { |
| 2810 | mTranslator.translateCanvas(canvas); |
| 2811 | } |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 2812 | canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2813 | attachInfo.mSetIgnoreDirtyState = false; |
| 2814 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2815 | mView.draw(canvas); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2816 | |
| 2817 | drawAccessibilityFocusedDrawableIfNeeded(canvas); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2818 | } finally { |
| 2819 | if (!attachInfo.mSetIgnoreDirtyState) { |
| 2820 | // Only clear the flag if it was not set during the mView.draw() call |
| 2821 | attachInfo.mIgnoreDirtyState = false; |
| 2822 | } |
| 2823 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2824 | } finally { |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2825 | try { |
| 2826 | surface.unlockCanvasAndPost(canvas); |
| 2827 | } catch (IllegalArgumentException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2828 | Log.e(mTag, "Could not unlock surface", e); |
Romain Guy | dddcd22 | 2012-05-18 15:33:57 -0700 | [diff] [blame] | 2829 | mLayoutRequested = true; // ask wm for a new surface next time. |
| 2830 | //noinspection ReturnInsideFinallyBlock |
| 2831 | return false; |
| 2832 | } |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2833 | |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2834 | if (LOCAL_LOGV) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2835 | Log.v(mTag, "Surface " + surface + " unlockCanvasAndPost"); |
Romain Guy | 25eba5c | 2012-04-04 17:29:03 -0700 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | return true; |
| 2839 | } |
| 2840 | |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2841 | /** |
| 2842 | * We want to draw a highlight around the current accessibility focused. |
| 2843 | * Since adding a style for all possible view is not a viable option we |
| 2844 | * have this specialized drawing method. |
| 2845 | * |
| 2846 | * Note: We are doing this here to be able to draw the highlight for |
| 2847 | * virtual views in addition to real ones. |
| 2848 | * |
| 2849 | * @param canvas The canvas on which to draw. |
| 2850 | */ |
| 2851 | private void drawAccessibilityFocusedDrawableIfNeeded(Canvas canvas) { |
| 2852 | final Rect bounds = mAttachInfo.mTmpInvalRect; |
| 2853 | if (getAccessibilityFocusedRect(bounds)) { |
| 2854 | final Drawable drawable = getAccessibilityFocusedDrawable(); |
| 2855 | if (drawable != null) { |
| 2856 | drawable.setBounds(bounds); |
| 2857 | drawable.draw(canvas); |
| 2858 | } |
| 2859 | } else if (mAttachInfo.mAccessibilityFocusDrawable != null) { |
| 2860 | mAttachInfo.mAccessibilityFocusDrawable.setBounds(0, 0, 0, 0); |
| 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | private boolean getAccessibilityFocusedRect(Rect bounds) { |
| 2865 | final AccessibilityManager manager = AccessibilityManager.getInstance(mView.mContext); |
| 2866 | if (!manager.isEnabled() || !manager.isTouchExplorationEnabled()) { |
| 2867 | return false; |
| 2868 | } |
| 2869 | |
| 2870 | final View host = mAccessibilityFocusedHost; |
| 2871 | if (host == null || host.mAttachInfo == null) { |
| 2872 | return false; |
| 2873 | } |
| 2874 | |
| 2875 | final AccessibilityNodeProvider provider = host.getAccessibilityNodeProvider(); |
| 2876 | if (provider == null) { |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 2877 | host.getBoundsOnScreen(bounds, true); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2878 | } else if (mAccessibilityFocusedVirtualView != null) { |
| 2879 | mAccessibilityFocusedVirtualView.getBoundsInScreen(bounds); |
| 2880 | } else { |
| 2881 | return false; |
| 2882 | } |
| 2883 | |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2884 | // Transform the rect into window-relative coordinates. |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2885 | final AttachInfo attachInfo = mAttachInfo; |
Alan Viverette | 2232add | 2015-05-26 15:24:18 -0700 | [diff] [blame] | 2886 | bounds.offset(0, attachInfo.mViewRootImpl.mScrollY); |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2887 | bounds.offset(-attachInfo.mWindowLeft, -attachInfo.mWindowTop); |
Doris Liu | 9607fbe | 2015-05-28 17:17:28 -0700 | [diff] [blame] | 2888 | if (!bounds.intersect(0, 0, attachInfo.mViewRootImpl.mWidth, |
| 2889 | attachInfo.mViewRootImpl.mHeight)) { |
| 2890 | // If no intersection, set bounds to empty. |
| 2891 | bounds.setEmpty(); |
| 2892 | } |
Alan Viverette | 632af84 | 2014-10-28 13:45:11 -0700 | [diff] [blame] | 2893 | return !bounds.isEmpty(); |
| 2894 | } |
| 2895 | |
| 2896 | private Drawable getAccessibilityFocusedDrawable() { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2897 | // Lazily load the accessibility focus drawable. |
| 2898 | if (mAttachInfo.mAccessibilityFocusDrawable == null) { |
Alan Viverette | f6cf1a0 | 2014-08-11 14:13:02 -0700 | [diff] [blame] | 2899 | final TypedValue value = new TypedValue(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2900 | final boolean resolved = mView.mContext.getTheme().resolveAttribute( |
| 2901 | R.attr.accessibilityFocusedDrawable, value, true); |
| 2902 | if (resolved) { |
| 2903 | mAttachInfo.mAccessibilityFocusDrawable = |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 2904 | mView.mContext.getDrawable(value.resourceId); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2905 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2906 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2907 | return mAttachInfo.mAccessibilityFocusDrawable; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2910 | boolean scrollToRectOrFocus(Rect rectangle, boolean immediate) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 2911 | final Rect ci = mAttachInfo.mContentInsets; |
| 2912 | final Rect vi = mAttachInfo.mVisibleInsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | int scrollY = 0; |
| 2914 | boolean handled = false; |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 2915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | if (vi.left > ci.left || vi.top > ci.top |
| 2917 | || vi.right > ci.right || vi.bottom > ci.bottom) { |
| 2918 | // We'll assume that we aren't going to change the scroll |
| 2919 | // offset, since we want to avoid that unless it is actually |
| 2920 | // going to make the focus visible... otherwise we scroll |
| 2921 | // all over the place. |
| 2922 | scrollY = mScrollY; |
| 2923 | // We can be called for two different situations: during a draw, |
| 2924 | // to update the scroll position if the focus has changed (in which |
| 2925 | // case 'rectangle' is null), or in response to a |
| 2926 | // requestChildRectangleOnScreen() call (in which case 'rectangle' |
| 2927 | // is non-null and we just want to scroll to whatever that |
| 2928 | // rectangle is). |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2929 | final View focus = mView.findFocus(); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2930 | if (focus == null) { |
Romain Guy | e8b1652 | 2009-07-14 13:06:42 -0700 | [diff] [blame] | 2931 | return false; |
| 2932 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2933 | View lastScrolledFocus = (mLastScrolledFocus != null) ? mLastScrolledFocus.get() : null; |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2934 | if (focus != lastScrolledFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | // If the focus has changed, then ignore any requests to scroll |
| 2936 | // to a rectangle; first we want to make sure the entire focus |
| 2937 | // view is visible. |
| 2938 | rectangle = null; |
| 2939 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2940 | 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] | 2941 | + " rectangle=" + rectangle + " ci=" + ci |
| 2942 | + " vi=" + vi); |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2943 | if (focus == lastScrolledFocus && !mScrollMayChange && rectangle == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | // Optimization: if the focus hasn't changed since last |
| 2945 | // time, and no layout has happened, then just leave things |
| 2946 | // as they are. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2947 | 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] | 2948 | + mScrollY + " vi=" + vi.toShortString()); |
Craig Mautner | 26a84df | 2013-04-11 19:09:05 -0700 | [diff] [blame] | 2949 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | // We need to determine if the currently focused view is |
| 2951 | // within the visible part of the window and, if not, apply |
| 2952 | // a pan so it can be seen. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 2953 | mLastScrolledFocus = new WeakReference<View>(focus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2954 | mScrollMayChange = false; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2955 | 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] | 2956 | // Try to find the rectangle from the focus view. |
| 2957 | if (focus.getGlobalVisibleRect(mVisRect, null)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2958 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Root w=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2959 | + mView.getWidth() + " h=" + mView.getHeight() |
| 2960 | + " ci=" + ci.toShortString() |
| 2961 | + " vi=" + vi.toShortString()); |
| 2962 | if (rectangle == null) { |
| 2963 | focus.getFocusedRect(mTempRect); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2964 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, "Focus " + focus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | + ": focusRect=" + mTempRect.toShortString()); |
Dianne Hackborn | 1c6a894 | 2010-03-23 16:34:20 -0700 | [diff] [blame] | 2966 | if (mView instanceof ViewGroup) { |
| 2967 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 2968 | focus, mTempRect); |
| 2969 | } |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2970 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | "Focus in window: focusRect=" |
| 2972 | + mTempRect.toShortString() |
| 2973 | + " visRect=" + mVisRect.toShortString()); |
| 2974 | } else { |
| 2975 | mTempRect.set(rectangle); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2976 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | "Request scroll to rect: " |
| 2978 | + mTempRect.toShortString() |
| 2979 | + " visRect=" + mVisRect.toShortString()); |
| 2980 | } |
| 2981 | if (mTempRect.intersect(mVisRect)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2982 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | "Focus window visible rect: " |
| 2984 | + mTempRect.toShortString()); |
| 2985 | if (mTempRect.height() > |
| 2986 | (mView.getHeight()-vi.top-vi.bottom)) { |
| 2987 | // If the focus simply is not going to fit, then |
| 2988 | // best is probably just to leave things as-is. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2989 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2990 | "Too tall; leaving scrollY=" + scrollY); |
| 2991 | } else if ((mTempRect.top-scrollY) < vi.top) { |
| 2992 | scrollY -= vi.top - (mTempRect.top-scrollY); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2993 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | "Top covered; scrollY=" + scrollY); |
| 2995 | } else if ((mTempRect.bottom-scrollY) |
| 2996 | > (mView.getHeight()-vi.bottom)) { |
| 2997 | scrollY += (mTempRect.bottom-scrollY) |
| 2998 | - (mView.getHeight()-vi.bottom); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 2999 | if (DEBUG_INPUT_RESIZE) Log.v(mTag, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3000 | "Bottom covered; scrollY=" + scrollY); |
| 3001 | } |
| 3002 | handled = true; |
| 3003 | } |
| 3004 | } |
| 3005 | } |
| 3006 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3008 | if (scrollY != mScrollY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3009 | 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] | 3010 | + mScrollY + " , new=" + scrollY); |
Derek Sollenberger | 8d94835 | 2015-07-16 09:27:59 -0400 | [diff] [blame] | 3011 | if (!immediate) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | if (mScroller == null) { |
| 3013 | mScroller = new Scroller(mView.getContext()); |
| 3014 | } |
| 3015 | mScroller.startScroll(0, mScrollY, 0, scrollY-mScrollY); |
| 3016 | } else if (mScroller != null) { |
| 3017 | mScroller.abortAnimation(); |
| 3018 | } |
| 3019 | mScrollY = scrollY; |
| 3020 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | return handled; |
| 3023 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3024 | |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3025 | /** |
| 3026 | * @hide |
| 3027 | */ |
| 3028 | public View getAccessibilityFocusedHost() { |
| 3029 | return mAccessibilityFocusedHost; |
| 3030 | } |
| 3031 | |
| 3032 | /** |
| 3033 | * @hide |
| 3034 | */ |
| 3035 | public AccessibilityNodeInfo getAccessibilityFocusedVirtualView() { |
| 3036 | return mAccessibilityFocusedVirtualView; |
| 3037 | } |
| 3038 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3039 | void setAccessibilityFocus(View view, AccessibilityNodeInfo node) { |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3040 | // If we have a virtual view with accessibility focus we need |
| 3041 | // to clear the focus and invalidate the virtual view bounds. |
| 3042 | if (mAccessibilityFocusedVirtualView != null) { |
| 3043 | |
| 3044 | AccessibilityNodeInfo focusNode = mAccessibilityFocusedVirtualView; |
| 3045 | View focusHost = mAccessibilityFocusedHost; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3046 | |
| 3047 | // Wipe the state of the current accessibility focus since |
| 3048 | // the call into the provider to clear accessibility focus |
| 3049 | // will fire an accessibility event which will end up calling |
| 3050 | // this method and we want to have clean state when this |
| 3051 | // invocation happens. |
| 3052 | mAccessibilityFocusedHost = null; |
| 3053 | mAccessibilityFocusedVirtualView = null; |
| 3054 | |
Alan Viverette | 239a0c0 | 2013-05-07 17:17:35 -0700 | [diff] [blame] | 3055 | // Clear accessibility focus on the host after clearing state since |
| 3056 | // this method may be reentrant. |
| 3057 | focusHost.clearAccessibilityFocusNoCallbacks(); |
| 3058 | |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3059 | AccessibilityNodeProvider provider = focusHost.getAccessibilityNodeProvider(); |
| 3060 | if (provider != null) { |
| 3061 | // Invalidate the area of the cleared accessibility focus. |
| 3062 | focusNode.getBoundsInParent(mTempRect); |
| 3063 | focusHost.invalidate(mTempRect); |
| 3064 | // Clear accessibility focus in the virtual node. |
| 3065 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 3066 | focusNode.getSourceNodeId()); |
| 3067 | provider.performAction(virtualNodeId, |
| 3068 | AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); |
| 3069 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3070 | focusNode.recycle(); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3071 | } |
| 3072 | if (mAccessibilityFocusedHost != null) { |
| 3073 | // Clear accessibility focus in the view. |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3074 | mAccessibilityFocusedHost.clearAccessibilityFocusNoCallbacks(); |
| 3075 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3076 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3077 | // Set the new focus host and node. |
| 3078 | mAccessibilityFocusedHost = view; |
| 3079 | mAccessibilityFocusedVirtualView = node; |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 3080 | |
| 3081 | if (mAttachInfo.mHardwareRenderer != null) { |
| 3082 | mAttachInfo.mHardwareRenderer.invalidateRoot(); |
| 3083 | } |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3086 | void setPointerCapture(View view) { |
| 3087 | if (!mAttachInfo.mHasWindowFocus) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3088 | Log.w(mTag, "Can't set capture if it's not focused."); |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3089 | return; |
| 3090 | } |
| 3091 | if (mCapturingView == view) { |
| 3092 | return; |
| 3093 | } |
| 3094 | mCapturingView = view; |
| 3095 | InputManager.getInstance().setPointerIconDetached(true); |
| 3096 | } |
| 3097 | |
| 3098 | void releasePointerCapture(View view) { |
| 3099 | if (mCapturingView != view || mCapturingView == null) { |
| 3100 | return; |
| 3101 | } |
| 3102 | |
| 3103 | mCapturingView = null; |
| 3104 | InputManager.getInstance().setPointerIconDetached(false); |
| 3105 | } |
| 3106 | |
| 3107 | boolean hasPointerCapture(View view) { |
| 3108 | return view != null && mCapturingView == view; |
| 3109 | } |
| 3110 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3111 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | public void requestChildFocus(View child, View focused) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3113 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3114 | Log.v(mTag, "Request child focus: focus now " + focused); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3115 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3116 | checkThread(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3117 | scheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | } |
| 3119 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3120 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | public void clearChildFocus(View child) { |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3122 | if (DEBUG_INPUT_RESIZE) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3123 | Log.v(mTag, "Clearing child focus"); |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3124 | } |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3125 | checkThread(); |
| 3126 | scheduleTraversals(); |
Svetoslav Ganov | b36a0ac | 2012-02-14 17:46:47 -0800 | [diff] [blame] | 3127 | } |
Amith Yamasani | 73eb97f | 2012-02-14 15:45:15 -0800 | [diff] [blame] | 3128 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3129 | @Override |
| 3130 | public ViewParent getParentForAccessibility() { |
| 3131 | return null; |
| 3132 | } |
| 3133 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3134 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | public void focusableViewAvailable(View v) { |
| 3136 | checkThread(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3137 | if (mView != null) { |
| 3138 | if (!mView.hasFocus()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | v.requestFocus(); |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3140 | } else { |
| 3141 | // the one case where will transfer focus away from the current one |
| 3142 | // is if the current view is a view group that prefers to give focus |
| 3143 | // to its children first AND the view is a descendant of it. |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3144 | View focused = mView.findFocus(); |
| 3145 | if (focused instanceof ViewGroup) { |
| 3146 | ViewGroup group = (ViewGroup) focused; |
| 3147 | if (group.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3148 | && isViewDescendantOf(v, focused)) { |
| 3149 | v.requestFocus(); |
| 3150 | } |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3151 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | } |
| 3153 | } |
| 3154 | } |
| 3155 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3156 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | public void recomputeViewAttributes(View child) { |
| 3158 | checkThread(); |
| 3159 | if (mView == child) { |
| 3160 | mAttachInfo.mRecomputeGlobalAttributes = true; |
| 3161 | if (!mWillDrawSoon) { |
| 3162 | scheduleTraversals(); |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | void dispatchDetachedFromWindow() { |
Romain Guy | 90fc03b | 2011-01-16 13:07:15 -0800 | [diff] [blame] | 3168 | if (mView != null && mView.mAttachInfo != null) { |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3169 | mAttachInfo.mTreeObserver.dispatchOnWindowAttachedChange(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | mView.dispatchDetachedFromWindow(); |
| 3171 | } |
| 3172 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3173 | mAccessibilityInteractionConnectionManager.ensureNoConnection(); |
| 3174 | mAccessibilityManager.removeAccessibilityStateChangeListener( |
| 3175 | mAccessibilityInteractionConnectionManager); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 3176 | mAccessibilityManager.removeHighTextContrastStateChangeListener( |
| 3177 | mHighContrastTextManager); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 3178 | removeSendWindowContentChangedCallback(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3179 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3180 | destroyHardwareRenderer(); |
| 3181 | |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3182 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 3183 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 3184 | mView.assignParent(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | mView = null; |
| 3186 | mAttachInfo.mRootView = null; |
| 3187 | |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3188 | if (mCapturingView != null) { |
| 3189 | releasePointerCapture(mCapturingView); |
| 3190 | } |
| 3191 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 3192 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3194 | if (mInputQueueCallback != null && mInputQueue != null) { |
| 3195 | mInputQueueCallback.onInputQueueDestroyed(mInputQueue); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3196 | mInputQueue.dispose(); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 3197 | mInputQueueCallback = null; |
| 3198 | mInputQueue = null; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 3199 | } |
| 3200 | if (mInputEventReceiver != null) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 3201 | mInputEventReceiver.dispose(); |
| 3202 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3203 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3205 | mWindowSession.remove(mWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | } catch (RemoteException e) { |
| 3207 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3208 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3209 | // Dispose the input channel after removing the window so the Window Manager |
| 3210 | // doesn't interpret the input channel being closed as an abnormal termination. |
| 3211 | if (mInputChannel != null) { |
| 3212 | mInputChannel.dispose(); |
| 3213 | mInputChannel = null; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3214 | } |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 3215 | |
Jeff Brown | d912e1f | 2014-04-11 18:46:22 -0700 | [diff] [blame] | 3216 | mDisplayManager.unregisterDisplayListener(mDisplayListener); |
| 3217 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 3218 | unscheduleTraversals(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3220 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3221 | void updateConfiguration(Configuration config, boolean force) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3222 | if (DEBUG_CONFIGURATION) Log.v(mTag, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3223 | "Applying new config to window " |
| 3224 | + mWindowAttributes.getTitle() |
| 3225 | + ": " + config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3226 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 3227 | CompatibilityInfo ci = mDisplayAdjustments.getCompatibilityInfo(); |
| 3228 | if (!ci.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3229 | config = new Configuration(config); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3230 | ci.applyToConfiguration(mNoncompatDensity, config); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3233 | synchronized (sConfigCallbacks) { |
| 3234 | for (int i=sConfigCallbacks.size()-1; i>=0; i--) { |
| 3235 | sConfigCallbacks.get(i).onConfigurationChanged(config); |
| 3236 | } |
| 3237 | } |
| 3238 | if (mView != null) { |
| 3239 | // At this point the resources have been updated to |
| 3240 | // have the most recent config, whatever that is. Use |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 3241 | // the one in them which may be newer. |
Romain Guy | 1c90f03 | 2011-05-24 14:59:50 -0700 | [diff] [blame] | 3242 | config = mView.getResources().getConfiguration(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3243 | if (force || mLastConfiguration.diff(config) != 0) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3244 | final int lastLayoutDirection = mLastConfiguration.getLayoutDirection(); |
| 3245 | final int currentLayoutDirection = config.getLayoutDirection(); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3246 | mLastConfiguration.setTo(config); |
Fabrice Di Meglio | b003e28 | 2012-10-17 17:20:19 -0700 | [diff] [blame] | 3247 | if (lastLayoutDirection != currentLayoutDirection && |
| 3248 | mViewLayoutDirectionInitial == View.LAYOUT_DIRECTION_INHERIT) { |
Fabrice Di Meglio | cf12897 | 2012-10-16 20:51:12 -0700 | [diff] [blame] | 3249 | mView.setLayoutDirection(currentLayoutDirection); |
| 3250 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 3251 | mView.dispatchConfigurationChanged(config); |
| 3252 | } |
| 3253 | } |
| 3254 | } |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 3255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | /** |
| 3257 | * Return true if child is an ancestor of parent, (or equal to the parent). |
| 3258 | */ |
Svetoslav Ganov | e5dfa47d | 2012-05-08 15:58:32 -0700 | [diff] [blame] | 3259 | public static boolean isViewDescendantOf(View child, View parent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | if (child == parent) { |
| 3261 | return true; |
| 3262 | } |
| 3263 | |
| 3264 | final ViewParent theParent = child.getParent(); |
| 3265 | return (theParent instanceof ViewGroup) && isViewDescendantOf((View) theParent, parent); |
| 3266 | } |
| 3267 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3268 | private static void forceLayout(View view) { |
| 3269 | view.forceLayout(); |
| 3270 | if (view instanceof ViewGroup) { |
| 3271 | ViewGroup group = (ViewGroup) view; |
| 3272 | final int count = group.getChildCount(); |
| 3273 | for (int i = 0; i < count; i++) { |
| 3274 | forceLayout(group.getChildAt(i)); |
| 3275 | } |
| 3276 | } |
| 3277 | } |
| 3278 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3279 | private final static int MSG_INVALIDATE = 1; |
| 3280 | private final static int MSG_INVALIDATE_RECT = 2; |
| 3281 | private final static int MSG_DIE = 3; |
| 3282 | private final static int MSG_RESIZED = 4; |
| 3283 | private final static int MSG_RESIZED_REPORT = 5; |
| 3284 | private final static int MSG_WINDOW_FOCUS_CHANGED = 6; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3285 | private final static int MSG_DISPATCH_INPUT_EVENT = 7; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3286 | private final static int MSG_DISPATCH_APP_VISIBILITY = 8; |
| 3287 | private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3288 | private final static int MSG_DISPATCH_KEY_FROM_IME = 11; |
| 3289 | private final static int MSG_FINISH_INPUT_CONNECTION = 12; |
| 3290 | private final static int MSG_CHECK_FOCUS = 13; |
| 3291 | private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14; |
| 3292 | private final static int MSG_DISPATCH_DRAG_EVENT = 15; |
| 3293 | private final static int MSG_DISPATCH_DRAG_LOCATION_EVENT = 16; |
| 3294 | private final static int MSG_DISPATCH_SYSTEM_UI_VISIBILITY = 17; |
| 3295 | private final static int MSG_UPDATE_CONFIGURATION = 18; |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 3296 | private final static int MSG_PROCESS_INPUT_EVENTS = 19; |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3297 | private final static int MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST = 21; |
Jorim Jaggi | 827e0fa | 2015-05-07 11:41:41 -0700 | [diff] [blame] | 3298 | private final static int MSG_INVALIDATE_WORLD = 22; |
| 3299 | private final static int MSG_WINDOW_MOVED = 23; |
| 3300 | private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; |
| 3301 | private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3302 | private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3303 | private final static int MSG_UPDATE_POINTER_ICON = 27; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3305 | final class ViewRootHandler extends Handler { |
| 3306 | @Override |
| 3307 | public String getMessageName(Message message) { |
| 3308 | switch (message.what) { |
| 3309 | case MSG_INVALIDATE: |
| 3310 | return "MSG_INVALIDATE"; |
| 3311 | case MSG_INVALIDATE_RECT: |
| 3312 | return "MSG_INVALIDATE_RECT"; |
| 3313 | case MSG_DIE: |
| 3314 | return "MSG_DIE"; |
| 3315 | case MSG_RESIZED: |
| 3316 | return "MSG_RESIZED"; |
| 3317 | case MSG_RESIZED_REPORT: |
| 3318 | return "MSG_RESIZED_REPORT"; |
| 3319 | case MSG_WINDOW_FOCUS_CHANGED: |
| 3320 | return "MSG_WINDOW_FOCUS_CHANGED"; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3321 | case MSG_DISPATCH_INPUT_EVENT: |
| 3322 | return "MSG_DISPATCH_INPUT_EVENT"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3323 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3324 | return "MSG_DISPATCH_APP_VISIBILITY"; |
| 3325 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3326 | return "MSG_DISPATCH_GET_NEW_SURFACE"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3327 | case MSG_DISPATCH_KEY_FROM_IME: |
| 3328 | return "MSG_DISPATCH_KEY_FROM_IME"; |
| 3329 | case MSG_FINISH_INPUT_CONNECTION: |
| 3330 | return "MSG_FINISH_INPUT_CONNECTION"; |
| 3331 | case MSG_CHECK_FOCUS: |
| 3332 | return "MSG_CHECK_FOCUS"; |
| 3333 | case MSG_CLOSE_SYSTEM_DIALOGS: |
| 3334 | return "MSG_CLOSE_SYSTEM_DIALOGS"; |
| 3335 | case MSG_DISPATCH_DRAG_EVENT: |
| 3336 | return "MSG_DISPATCH_DRAG_EVENT"; |
| 3337 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: |
| 3338 | return "MSG_DISPATCH_DRAG_LOCATION_EVENT"; |
| 3339 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: |
| 3340 | return "MSG_DISPATCH_SYSTEM_UI_VISIBILITY"; |
| 3341 | case MSG_UPDATE_CONFIGURATION: |
| 3342 | return "MSG_UPDATE_CONFIGURATION"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3343 | case MSG_PROCESS_INPUT_EVENTS: |
| 3344 | return "MSG_PROCESS_INPUT_EVENTS"; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3345 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: |
| 3346 | return "MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST"; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3347 | case MSG_WINDOW_MOVED: |
| 3348 | return "MSG_WINDOW_MOVED"; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3349 | case MSG_SYNTHESIZE_INPUT_EVENT: |
| 3350 | return "MSG_SYNTHESIZE_INPUT_EVENT"; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3351 | case MSG_DISPATCH_WINDOW_SHOWN: |
| 3352 | return "MSG_DISPATCH_WINDOW_SHOWN"; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3353 | case MSG_UPDATE_POINTER_ICON: |
| 3354 | return "MSG_UPDATE_POINTER_ICON"; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3355 | } |
| 3356 | return super.getMessageName(message); |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3357 | } |
Romain Guy | f928469 | 2011-07-13 18:46:21 -0700 | [diff] [blame] | 3358 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3359 | @Override |
| 3360 | public void handleMessage(Message msg) { |
| 3361 | switch (msg.what) { |
| 3362 | case MSG_INVALIDATE: |
| 3363 | ((View) msg.obj).invalidate(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3365 | case MSG_INVALIDATE_RECT: |
| 3366 | final View.AttachInfo.InvalidateInfo info = (View.AttachInfo.InvalidateInfo) msg.obj; |
| 3367 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 3368 | info.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3369 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3370 | case MSG_PROCESS_INPUT_EVENTS: |
| 3371 | mProcessInputEventsScheduled = false; |
| 3372 | doProcessInputEvents(); |
| 3373 | break; |
| 3374 | case MSG_DISPATCH_APP_VISIBILITY: |
| 3375 | handleAppVisibility(msg.arg1 != 0); |
| 3376 | break; |
| 3377 | case MSG_DISPATCH_GET_NEW_SURFACE: |
| 3378 | handleGetNewSurface(); |
| 3379 | break; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3380 | case MSG_RESIZED: { |
| 3381 | // Recycled in the fall through... |
| 3382 | SomeArgs args = (SomeArgs) msg.obj; |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3383 | if (mWinFrame.equals(args.arg1) |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3384 | && mPendingOverscanInsets.equals(args.arg5) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3385 | && mPendingContentInsets.equals(args.arg2) |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3386 | && mPendingStableInsets.equals(args.arg6) |
Romain Guy | dfab363 | 2012-10-03 14:53:25 -0700 | [diff] [blame] | 3387 | && mPendingVisibleInsets.equals(args.arg3) |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3388 | && mPendingOutsets.equals(args.arg7) |
Jorim Jaggi | 0fe356e | 2016-01-05 14:43:25 +0100 | [diff] [blame] | 3389 | && mPendingBackDropFrame.equals(args.arg8) |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3390 | && args.arg4 == null |
| 3391 | && args.argi1 == 0) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3392 | break; |
Romain Guy | cdb8667 | 2010-03-18 18:54:50 -0700 | [diff] [blame] | 3393 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3394 | } // fall through... |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3395 | case MSG_RESIZED_REPORT: |
| 3396 | if (mAdded) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3397 | SomeArgs args = (SomeArgs) msg.obj; |
| 3398 | |
| 3399 | Configuration config = (Configuration) args.arg4; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3400 | if (config != null) { |
| 3401 | updateConfiguration(config, false); |
| 3402 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3403 | |
| 3404 | mWinFrame.set((Rect) args.arg1); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3405 | mPendingOverscanInsets.set((Rect) args.arg5); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3406 | mPendingContentInsets.set((Rect) args.arg2); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 3407 | mPendingStableInsets.set((Rect) args.arg6); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3408 | mPendingVisibleInsets.set((Rect) args.arg3); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 3409 | mPendingOutsets.set((Rect) args.arg7); |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3410 | mPendingBackDropFrame.set((Rect) args.arg8); |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 3411 | mForceNextWindowRelayout = args.argi1 != 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 3412 | mPendingAlwaysConsumeNavBar = args.argi2 != 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3413 | |
| 3414 | args.recycle(); |
| 3415 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3416 | if (msg.what == MSG_RESIZED_REPORT) { |
| 3417 | mReportNextDraw = true; |
| 3418 | } |
Romain Guy | 59a12ca | 2011-06-09 17:48:21 -0700 | [diff] [blame] | 3419 | |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3420 | if (mView != null) { |
| 3421 | forceLayout(mView); |
| 3422 | } |
| 3423 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3424 | requestLayout(); |
| 3425 | } |
| 3426 | break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3427 | case MSG_WINDOW_MOVED: |
| 3428 | if (mAdded) { |
| 3429 | final int w = mWinFrame.width(); |
| 3430 | final int h = mWinFrame.height(); |
| 3431 | final int l = msg.arg1; |
| 3432 | final int t = msg.arg2; |
| 3433 | mWinFrame.left = l; |
| 3434 | mWinFrame.right = l + w; |
| 3435 | mWinFrame.top = t; |
| 3436 | mWinFrame.bottom = t + h; |
| 3437 | |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 3438 | mPendingBackDropFrame.set(mWinFrame); |
| 3439 | |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3440 | // Suppress layouts during resizing - a correct layout will happen when resizing |
| 3441 | // is done, and this just increases system load. |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3442 | boolean isDockedDivider = mWindowAttributes.type == TYPE_DOCK_DIVIDER; |
| 3443 | boolean suppress = (mDragResizing && mResizeMode == RESIZE_MODE_DOCKED_DIVIDER) |
| 3444 | || isDockedDivider; |
Jorim Jaggi | 844e171 | 2016-01-13 17:39:25 -0800 | [diff] [blame] | 3445 | if (!suppress) { |
| 3446 | if (mView != null) { |
| 3447 | forceLayout(mView); |
| 3448 | } |
| 3449 | requestLayout(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 3450 | } else { |
| 3451 | maybeHandleWindowMove(mWinFrame); |
Yohei Yukawa | d2e5647 | 2015-07-28 17:00:33 -0700 | [diff] [blame] | 3452 | } |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 3453 | } |
| 3454 | break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3455 | case MSG_WINDOW_FOCUS_CHANGED: { |
| 3456 | if (mAdded) { |
| 3457 | boolean hasWindowFocus = msg.arg1 != 0; |
| 3458 | mAttachInfo.mHasWindowFocus = hasWindowFocus; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3460 | profileRendering(hasWindowFocus); |
| 3461 | |
| 3462 | if (hasWindowFocus) { |
| 3463 | boolean inTouchMode = msg.arg2 != 0; |
| 3464 | ensureTouchModeLocally(inTouchMode); |
| 3465 | |
Romain Guy | e55945e | 2013-04-04 15:26:04 -0700 | [diff] [blame] | 3466 | if (mAttachInfo.mHardwareRenderer != null && mSurface.isValid()){ |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3467 | mFullRedrawNeeded = true; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3468 | try { |
Alan Viverette | ccb11e1 | 2014-07-08 16:04:02 -0700 | [diff] [blame] | 3469 | final WindowManager.LayoutParams lp = mWindowAttributes; |
Alan Viverette | 49a22e8 | 2014-07-12 20:01:27 -0700 | [diff] [blame] | 3470 | final Rect surfaceInsets = lp != null ? lp.surfaceInsets : null; |
Romain Guy | 3696779b | 2013-01-28 14:04:07 -0800 | [diff] [blame] | 3471 | mAttachInfo.mHardwareRenderer.initializeIfNeeded( |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 3472 | mWidth, mHeight, mAttachInfo, mSurface, surfaceInsets); |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 3473 | } catch (OutOfResourcesException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3474 | Log.e(mTag, "OutOfResourcesException locking surface", e); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3475 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 3476 | if (!mWindowSession.outOfMemory(mWindow)) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3477 | Slog.w(mTag, "No processes killed for memory; killing self"); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3478 | Process.killProcess(Process.myPid()); |
| 3479 | } |
| 3480 | } catch (RemoteException ex) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3481 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3482 | // Retry in a bit. |
| 3483 | sendMessageDelayed(obtainMessage(msg.what, msg.arg1, msg.arg2), 500); |
| 3484 | return; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3485 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 3486 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3488 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3489 | mLastWasImTarget = WindowManager.LayoutParams |
| 3490 | .mayUseInputMethod(mWindowAttributes.flags); |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 3491 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3492 | InputMethodManager imm = InputMethodManager.peekInstance(); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3493 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
| 3494 | imm.onPreWindowFocus(mView, hasWindowFocus); |
| 3495 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3496 | if (mView != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3497 | mAttachInfo.mKeyDispatchState.reset(); |
| 3498 | mView.dispatchWindowFocusChanged(hasWindowFocus); |
Dianne Hackborn | 961cae9 | 2013-03-20 14:59:43 -0700 | [diff] [blame] | 3499 | mAttachInfo.mTreeObserver.dispatchOnWindowFocusChange(hasWindowFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3501 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3502 | // Note: must be done after the focus change callbacks, |
| 3503 | // so all of the view state is set up correctly. |
| 3504 | if (hasWindowFocus) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3505 | if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 3506 | imm.onPostWindowFocus(mView, mView.findFocus(), |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3507 | mWindowAttributes.softInputMode, |
| 3508 | !mHasHadWindowFocus, mWindowAttributes.flags); |
| 3509 | } |
| 3510 | // Clear the forward bit. We can just do this directly, since |
| 3511 | // the window manager doesn't care about it. |
| 3512 | mWindowAttributes.softInputMode &= |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3514 | ((WindowManager.LayoutParams)mView.getLayoutParams()) |
| 3515 | .softInputMode &= |
| 3516 | ~WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION; |
| 3517 | mHasHadWindowFocus = true; |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 3518 | } else if (mCapturingView != null) { |
| 3519 | releasePointerCapture(mCapturingView); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3520 | } |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 3521 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3522 | } break; |
| 3523 | case MSG_DIE: |
| 3524 | doDie(); |
| 3525 | break; |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 3526 | case MSG_DISPATCH_INPUT_EVENT: { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 3527 | SomeArgs args = (SomeArgs)msg.obj; |
| 3528 | InputEvent event = (InputEvent)args.arg1; |
| 3529 | InputEventReceiver receiver = (InputEventReceiver)args.arg2; |
| 3530 | enqueueInputEvent(event, receiver, 0, true); |
| 3531 | args.recycle(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3532 | } break; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3533 | case MSG_SYNTHESIZE_INPUT_EVENT: { |
| 3534 | InputEvent event = (InputEvent)msg.obj; |
| 3535 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_UNHANDLED, true); |
| 3536 | } break; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3537 | case MSG_DISPATCH_KEY_FROM_IME: { |
| 3538 | if (LOCAL_LOGV) Log.v( |
| 3539 | TAG, "Dispatching key " |
| 3540 | + msg.obj + " from IME to " + mView); |
| 3541 | KeyEvent event = (KeyEvent)msg.obj; |
| 3542 | if ((event.getFlags()&KeyEvent.FLAG_FROM_SYSTEM) != 0) { |
| 3543 | // The IME is trying to say this event is from the |
| 3544 | // system! Bad bad bad! |
| 3545 | //noinspection UnusedAssignment |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 3546 | event = KeyEvent.changeFlags(event, event.getFlags() & |
| 3547 | ~KeyEvent.FLAG_FROM_SYSTEM); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3548 | } |
| 3549 | enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true); |
| 3550 | } break; |
| 3551 | case MSG_FINISH_INPUT_CONNECTION: { |
| 3552 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3553 | if (imm != null) { |
| 3554 | imm.reportFinishInputConnection((InputConnection)msg.obj); |
| 3555 | } |
| 3556 | } break; |
| 3557 | case MSG_CHECK_FOCUS: { |
| 3558 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 3559 | if (imm != null) { |
| 3560 | imm.checkFocus(); |
| 3561 | } |
| 3562 | } break; |
| 3563 | case MSG_CLOSE_SYSTEM_DIALOGS: { |
| 3564 | if (mView != null) { |
| 3565 | mView.onCloseSystemDialogs((String)msg.obj); |
| 3566 | } |
| 3567 | } break; |
| 3568 | case MSG_DISPATCH_DRAG_EVENT: |
| 3569 | case MSG_DISPATCH_DRAG_LOCATION_EVENT: { |
| 3570 | DragEvent event = (DragEvent)msg.obj; |
| 3571 | event.mLocalState = mLocalDragState; // only present when this app called startDrag() |
| 3572 | handleDragEvent(event); |
| 3573 | } break; |
| 3574 | case MSG_DISPATCH_SYSTEM_UI_VISIBILITY: { |
Romain Guy | fbb93fa | 2012-12-03 18:50:35 -0800 | [diff] [blame] | 3575 | handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo) msg.obj); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3576 | } break; |
| 3577 | case MSG_UPDATE_CONFIGURATION: { |
| 3578 | Configuration config = (Configuration)msg.obj; |
| 3579 | if (config.isOtherSeqNewer(mLastConfiguration)) { |
| 3580 | config = mLastConfiguration; |
| 3581 | } |
| 3582 | updateConfiguration(config, false); |
| 3583 | } break; |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3584 | case MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 3585 | setAccessibilityFocus(null, null); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 3586 | } break; |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3587 | case MSG_INVALIDATE_WORLD: { |
Romain Guy | f84208f | 2012-09-13 22:50:18 -0700 | [diff] [blame] | 3588 | if (mView != null) { |
| 3589 | invalidateWorld(mView); |
| 3590 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 3591 | } break; |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 3592 | case MSG_DISPATCH_WINDOW_SHOWN: { |
| 3593 | handleDispatchWindowShown(); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 3594 | } break; |
| 3595 | case MSG_REQUEST_KEYBOARD_SHORTCUTS: { |
| 3596 | IResultReceiver receiver = (IResultReceiver) msg.obj; |
| 3597 | handleRequestKeyboardShortcuts(receiver); |
| 3598 | } break; |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 3599 | case MSG_UPDATE_POINTER_ICON: { |
| 3600 | MotionEvent event = (MotionEvent) msg.obj; |
| 3601 | resetPointerIcon(event); |
| 3602 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3604 | } |
| 3605 | } |
Romain Guy | 51e4d4d | 2012-03-15 18:30:47 -0700 | [diff] [blame] | 3606 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 3607 | final ViewRootHandler mHandler = new ViewRootHandler(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 3608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3609 | /** |
| 3610 | * Something in the current window tells us we need to change the touch mode. For |
| 3611 | * example, we are not in touch mode, and the user touches the screen. |
| 3612 | * |
| 3613 | * If the touch mode has changed, tell the window manager, and handle it locally. |
| 3614 | * |
| 3615 | * @param inTouchMode Whether we want to be in touch mode. |
| 3616 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3617 | */ |
| 3618 | boolean ensureTouchMode(boolean inTouchMode) { |
| 3619 | if (DBG) Log.d("touchmode", "ensureTouchMode(" + inTouchMode + "), current " |
| 3620 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3621 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3622 | |
| 3623 | // tell the window manager |
| 3624 | try { |
Matt Wu | d6bc96d | 2016-01-14 12:59:24 -0800 | [diff] [blame] | 3625 | mWindowSession.setInTouchMode(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | } catch (RemoteException e) { |
| 3627 | throw new RuntimeException(e); |
| 3628 | } |
| 3629 | |
| 3630 | // handle the change |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3631 | return ensureTouchModeLocally(inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /** |
| 3635 | * Ensure that the touch mode for this window is set, and if it is changing, |
| 3636 | * take the appropriate action. |
| 3637 | * @param inTouchMode Whether we want to be in touch mode. |
| 3638 | * @return True if the touch mode changed and focus changed was changed as a result |
| 3639 | */ |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3640 | private boolean ensureTouchModeLocally(boolean inTouchMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current " |
| 3642 | + "touch mode is " + mAttachInfo.mInTouchMode); |
| 3643 | |
| 3644 | if (mAttachInfo.mInTouchMode == inTouchMode) return false; |
| 3645 | |
| 3646 | mAttachInfo.mInTouchMode = inTouchMode; |
| 3647 | mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode); |
| 3648 | |
Romain Guy | 2d4cff6 | 2010-04-09 15:39:00 -0700 | [diff] [blame] | 3649 | return (inTouchMode) ? enterTouchMode() : leaveTouchMode(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | private boolean enterTouchMode() { |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3653 | if (mView != null && mView.hasFocus()) { |
| 3654 | // note: not relying on mFocusedView here because this could |
| 3655 | // be when the window is first being added, and mFocused isn't |
| 3656 | // set yet. |
| 3657 | final View focused = mView.findFocus(); |
| 3658 | if (focused != null && !focused.isFocusableInTouchMode()) { |
| 3659 | final ViewGroup ancestorToTakeFocus = findAncestorToTakeFocusInTouchMode(focused); |
| 3660 | if (ancestorToTakeFocus != null) { |
| 3661 | // there is an ancestor that wants focus after its |
| 3662 | // descendants that is focusable in touch mode.. give it |
| 3663 | // focus |
| 3664 | return ancestorToTakeFocus.requestFocus(); |
| 3665 | } else { |
Alan Viverette | 973f3b4 | 2013-08-13 16:57:28 -0700 | [diff] [blame] | 3666 | // There's nothing to focus. Clear and propagate through the |
| 3667 | // hierarchy, but don't attempt to place new focus. |
Alan Viverette | 223622a | 2013-12-17 13:29:02 -0800 | [diff] [blame] | 3668 | focused.clearFocusInternal(null, true, false); |
Alan Viverette | ed7821a | 2013-07-24 15:49:23 -0700 | [diff] [blame] | 3669 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | return false; |
| 3674 | } |
| 3675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | /** |
| 3677 | * Find an ancestor of focused that wants focus after its descendants and is |
| 3678 | * focusable in touch mode. |
| 3679 | * @param focused The currently focused view. |
| 3680 | * @return An appropriate view, or null if no such view exists. |
| 3681 | */ |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 3682 | private static ViewGroup findAncestorToTakeFocusInTouchMode(View focused) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | ViewParent parent = focused.getParent(); |
| 3684 | while (parent instanceof ViewGroup) { |
| 3685 | final ViewGroup vgParent = (ViewGroup) parent; |
| 3686 | if (vgParent.getDescendantFocusability() == ViewGroup.FOCUS_AFTER_DESCENDANTS |
| 3687 | && vgParent.isFocusableInTouchMode()) { |
| 3688 | return vgParent; |
| 3689 | } |
| 3690 | if (vgParent.isRootNamespace()) { |
| 3691 | return null; |
| 3692 | } else { |
| 3693 | parent = vgParent.getParent(); |
| 3694 | } |
| 3695 | } |
| 3696 | return null; |
| 3697 | } |
| 3698 | |
| 3699 | private boolean leaveTouchMode() { |
| 3700 | if (mView != null) { |
| 3701 | if (mView.hasFocus()) { |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3702 | View focusedView = mView.findFocus(); |
| 3703 | if (!(focusedView instanceof ViewGroup)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | // some view has focus, let it keep it |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3705 | return false; |
Svetoslav Ganov | 149567f | 2013-01-08 15:23:34 -0800 | [diff] [blame] | 3706 | } else if (((ViewGroup) focusedView).getDescendantFocusability() != |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | ViewGroup.FOCUS_AFTER_DESCENDANTS) { |
| 3708 | // some view group has focus, and doesn't prefer its children |
| 3709 | // over itself for focus, so let them keep it. |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3710 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | } |
| 3712 | } |
Svetoslav Ganov | cf8a3b8 | 2012-04-30 16:49:59 -0700 | [diff] [blame] | 3713 | |
| 3714 | // find the best view to give focus to in this brave new non-touch-mode |
| 3715 | // world |
| 3716 | final View focused = focusSearch(null, View.FOCUS_DOWN); |
| 3717 | if (focused != null) { |
| 3718 | return focused.requestFocus(View.FOCUS_DOWN); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | return false; |
| 3722 | } |
| 3723 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3724 | /** |
| 3725 | * Base class for implementing a stage in the chain of responsibility |
| 3726 | * for processing input events. |
| 3727 | * <p> |
| 3728 | * Events are delivered to the stage by the {@link #deliver} method. The stage |
| 3729 | * then has the choice of finishing the event or forwarding it to the next stage. |
| 3730 | * </p> |
| 3731 | */ |
| 3732 | abstract class InputStage { |
| 3733 | private final InputStage mNext; |
| 3734 | |
| 3735 | protected static final int FORWARD = 0; |
| 3736 | protected static final int FINISH_HANDLED = 1; |
| 3737 | protected static final int FINISH_NOT_HANDLED = 2; |
| 3738 | |
| 3739 | /** |
| 3740 | * Creates an input stage. |
| 3741 | * @param next The next stage to which events should be forwarded. |
| 3742 | */ |
| 3743 | public InputStage(InputStage next) { |
| 3744 | mNext = next; |
| 3745 | } |
| 3746 | |
| 3747 | /** |
| 3748 | * Delivers an event to be processed. |
| 3749 | */ |
| 3750 | public final void deliver(QueuedInputEvent q) { |
| 3751 | if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { |
| 3752 | forward(q); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3753 | } else if (shouldDropInputEvent(q)) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3754 | finish(q, false); |
| 3755 | } else { |
| 3756 | apply(q, onProcess(q)); |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | /** |
| 3761 | * Marks the the input event as finished then forwards it to the next stage. |
| 3762 | */ |
| 3763 | protected void finish(QueuedInputEvent q, boolean handled) { |
| 3764 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED; |
| 3765 | if (handled) { |
| 3766 | q.mFlags |= QueuedInputEvent.FLAG_FINISHED_HANDLED; |
| 3767 | } |
| 3768 | forward(q); |
| 3769 | } |
| 3770 | |
| 3771 | /** |
| 3772 | * Forwards the event to the next stage. |
| 3773 | */ |
| 3774 | protected void forward(QueuedInputEvent q) { |
| 3775 | onDeliverToNext(q); |
| 3776 | } |
| 3777 | |
| 3778 | /** |
| 3779 | * Applies a result code from {@link #onProcess} to the specified event. |
| 3780 | */ |
| 3781 | protected void apply(QueuedInputEvent q, int result) { |
| 3782 | if (result == FORWARD) { |
| 3783 | forward(q); |
| 3784 | } else if (result == FINISH_HANDLED) { |
| 3785 | finish(q, true); |
| 3786 | } else if (result == FINISH_NOT_HANDLED) { |
| 3787 | finish(q, false); |
| 3788 | } else { |
| 3789 | throw new IllegalArgumentException("Invalid result: " + result); |
| 3790 | } |
| 3791 | } |
| 3792 | |
| 3793 | /** |
| 3794 | * Called when an event is ready to be processed. |
| 3795 | * @return A result code indicating how the event was handled. |
| 3796 | */ |
| 3797 | protected int onProcess(QueuedInputEvent q) { |
| 3798 | return FORWARD; |
| 3799 | } |
| 3800 | |
| 3801 | /** |
| 3802 | * Called when an event is being delivered to the next stage. |
| 3803 | */ |
| 3804 | protected void onDeliverToNext(QueuedInputEvent q) { |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3805 | if (DEBUG_INPUT_STAGES) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3806 | Log.v(mTag, "Done with " + getClass().getSimpleName() + ". " + q); |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 3807 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3808 | if (mNext != null) { |
| 3809 | mNext.deliver(q); |
| 3810 | } else { |
| 3811 | finishInputEvent(q); |
| 3812 | } |
| 3813 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3814 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3815 | protected boolean shouldDropInputEvent(QueuedInputEvent q) { |
| 3816 | if (mView == null || !mAdded) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3817 | 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] | 3818 | return true; |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3819 | } else if ((!mAttachInfo.mHasWindowFocus |
| 3820 | && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) || mStopped |
Joe LaPenna | 90776de | 2016-01-22 07:11:49 -0800 | [diff] [blame] | 3821 | || (mIsAmbientMode && !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_BUTTON)) |
| 3822 | || (mPausedForTransition && !isBack(q.mEvent))) { |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3823 | // This is a focus event and the window doesn't currently have input focus or |
| 3824 | // has stopped. This could be an event that came back from the previous stage |
| 3825 | // but the window has lost focus or stopped in the meantime. |
| 3826 | if (isTerminalInputEvent(q.mEvent)) { |
| 3827 | // Don't drop terminal input events, however mark them as canceled. |
| 3828 | q.mEvent.cancel(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3829 | Slog.w(mTag, "Cancelling event due to no window focus: " + q.mEvent); |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3830 | return false; |
| 3831 | } |
| 3832 | |
| 3833 | // Drop non-terminal input events. |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 3834 | Slog.w(mTag, "Dropping event due to no window focus: " + q.mEvent); |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 3835 | return true; |
| 3836 | } |
| 3837 | return false; |
| 3838 | } |
| 3839 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3840 | void dump(String prefix, PrintWriter writer) { |
| 3841 | if (mNext != null) { |
| 3842 | mNext.dump(prefix, writer); |
| 3843 | } |
| 3844 | } |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 3845 | |
| 3846 | private boolean isBack(InputEvent event) { |
| 3847 | if (event instanceof KeyEvent) { |
| 3848 | return ((KeyEvent) event).getKeyCode() == KeyEvent.KEYCODE_BACK; |
| 3849 | } else { |
| 3850 | return false; |
| 3851 | } |
| 3852 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * Base class for implementing an input pipeline stage that supports |
| 3857 | * asynchronous and out-of-order processing of input events. |
| 3858 | * <p> |
| 3859 | * In addition to what a normal input stage can do, an asynchronous |
| 3860 | * input stage may also defer an input event that has been delivered to it |
| 3861 | * and finish or forward it later. |
| 3862 | * </p> |
| 3863 | */ |
| 3864 | abstract class AsyncInputStage extends InputStage { |
| 3865 | private final String mTraceCounter; |
| 3866 | |
| 3867 | private QueuedInputEvent mQueueHead; |
| 3868 | private QueuedInputEvent mQueueTail; |
| 3869 | private int mQueueLength; |
| 3870 | |
| 3871 | protected static final int DEFER = 3; |
| 3872 | |
| 3873 | /** |
| 3874 | * Creates an asynchronous input stage. |
| 3875 | * @param next The next stage to which events should be forwarded. |
| 3876 | * @param traceCounter The name of a counter to record the size of |
| 3877 | * the queue of pending events. |
| 3878 | */ |
| 3879 | public AsyncInputStage(InputStage next, String traceCounter) { |
| 3880 | super(next); |
| 3881 | mTraceCounter = traceCounter; |
| 3882 | } |
| 3883 | |
| 3884 | /** |
| 3885 | * Marks the event as deferred, which is to say that it will be handled |
| 3886 | * asynchronously. The caller is responsible for calling {@link #forward} |
| 3887 | * or {@link #finish} later when it is done handling the event. |
| 3888 | */ |
| 3889 | protected void defer(QueuedInputEvent q) { |
| 3890 | q.mFlags |= QueuedInputEvent.FLAG_DEFERRED; |
| 3891 | enqueue(q); |
| 3892 | } |
| 3893 | |
| 3894 | @Override |
| 3895 | protected void forward(QueuedInputEvent q) { |
| 3896 | // Clear the deferred flag. |
| 3897 | q.mFlags &= ~QueuedInputEvent.FLAG_DEFERRED; |
| 3898 | |
| 3899 | // Fast path if the queue is empty. |
| 3900 | QueuedInputEvent curr = mQueueHead; |
| 3901 | if (curr == null) { |
| 3902 | super.forward(q); |
| 3903 | return; |
| 3904 | } |
| 3905 | |
| 3906 | // Determine whether the event must be serialized behind any others |
| 3907 | // before it can be delivered to the next stage. This is done because |
| 3908 | // deferred events might be handled out of order by the stage. |
| 3909 | final int deviceId = q.mEvent.getDeviceId(); |
| 3910 | QueuedInputEvent prev = null; |
| 3911 | boolean blocked = false; |
| 3912 | while (curr != null && curr != q) { |
| 3913 | if (!blocked && deviceId == curr.mEvent.getDeviceId()) { |
| 3914 | blocked = true; |
| 3915 | } |
| 3916 | prev = curr; |
| 3917 | curr = curr.mNext; |
| 3918 | } |
| 3919 | |
| 3920 | // If the event is blocked, then leave it in the queue to be delivered later. |
| 3921 | // Note that the event might not yet be in the queue if it was not previously |
| 3922 | // deferred so we will enqueue it if needed. |
| 3923 | if (blocked) { |
| 3924 | if (curr == null) { |
| 3925 | enqueue(q); |
| 3926 | } |
| 3927 | return; |
| 3928 | } |
| 3929 | |
| 3930 | // The event is not blocked. Deliver it immediately. |
| 3931 | if (curr != null) { |
| 3932 | curr = curr.mNext; |
| 3933 | dequeue(q, prev); |
| 3934 | } |
| 3935 | super.forward(q); |
| 3936 | |
| 3937 | // Dequeuing this event may have unblocked successors. Deliver them. |
| 3938 | while (curr != null) { |
| 3939 | if (deviceId == curr.mEvent.getDeviceId()) { |
| 3940 | if ((curr.mFlags & QueuedInputEvent.FLAG_DEFERRED) != 0) { |
| 3941 | break; |
| 3942 | } |
| 3943 | QueuedInputEvent next = curr.mNext; |
| 3944 | dequeue(curr, prev); |
| 3945 | super.forward(curr); |
| 3946 | curr = next; |
| 3947 | } else { |
| 3948 | prev = curr; |
| 3949 | curr = curr.mNext; |
| 3950 | } |
| 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | @Override |
| 3955 | protected void apply(QueuedInputEvent q, int result) { |
| 3956 | if (result == DEFER) { |
| 3957 | defer(q); |
| 3958 | } else { |
| 3959 | super.apply(q, result); |
| 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | private void enqueue(QueuedInputEvent q) { |
| 3964 | if (mQueueTail == null) { |
| 3965 | mQueueHead = q; |
| 3966 | mQueueTail = q; |
| 3967 | } else { |
| 3968 | mQueueTail.mNext = q; |
| 3969 | mQueueTail = q; |
| 3970 | } |
| 3971 | |
| 3972 | mQueueLength += 1; |
| 3973 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3974 | } |
| 3975 | |
| 3976 | private void dequeue(QueuedInputEvent q, QueuedInputEvent prev) { |
| 3977 | if (prev == null) { |
| 3978 | mQueueHead = q.mNext; |
| 3979 | } else { |
| 3980 | prev.mNext = q.mNext; |
| 3981 | } |
| 3982 | if (mQueueTail == q) { |
| 3983 | mQueueTail = prev; |
| 3984 | } |
| 3985 | q.mNext = null; |
| 3986 | |
| 3987 | mQueueLength -= 1; |
| 3988 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mTraceCounter, mQueueLength); |
| 3989 | } |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 3990 | |
| 3991 | @Override |
| 3992 | void dump(String prefix, PrintWriter writer) { |
| 3993 | writer.print(prefix); |
| 3994 | writer.print(getClass().getName()); |
| 3995 | writer.print(": mQueueLength="); |
| 3996 | writer.println(mQueueLength); |
| 3997 | |
| 3998 | super.dump(prefix, writer); |
| 3999 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | /** |
| 4003 | * Delivers pre-ime input events to a native activity. |
| 4004 | * Does not support pointer events. |
| 4005 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4006 | final class NativePreImeInputStage extends AsyncInputStage |
| 4007 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4008 | public NativePreImeInputStage(InputStage next, String traceCounter) { |
| 4009 | super(next, traceCounter); |
| 4010 | } |
| 4011 | |
| 4012 | @Override |
| 4013 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4014 | if (mInputQueue != null && q.mEvent instanceof KeyEvent) { |
| 4015 | mInputQueue.sendInputEvent(q.mEvent, q, true, this); |
| 4016 | return DEFER; |
| 4017 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4018 | return FORWARD; |
| 4019 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4020 | |
| 4021 | @Override |
| 4022 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4023 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4024 | if (handled) { |
| 4025 | finish(q, true); |
| 4026 | return; |
| 4027 | } |
| 4028 | forward(q); |
| 4029 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | /** |
| 4033 | * Delivers pre-ime input events to the view hierarchy. |
| 4034 | * Does not support pointer events. |
| 4035 | */ |
| 4036 | final class ViewPreImeInputStage extends InputStage { |
| 4037 | public ViewPreImeInputStage(InputStage next) { |
| 4038 | super(next); |
| 4039 | } |
| 4040 | |
| 4041 | @Override |
| 4042 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4043 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4044 | return processKeyEvent(q); |
| 4045 | } |
| 4046 | return FORWARD; |
| 4047 | } |
| 4048 | |
| 4049 | private int processKeyEvent(QueuedInputEvent q) { |
| 4050 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4051 | if (mView.dispatchKeyEventPreIme(event)) { |
| 4052 | return FINISH_HANDLED; |
| 4053 | } |
| 4054 | return FORWARD; |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | /** |
| 4059 | * Delivers input events to the ime. |
| 4060 | * Does not support pointer events. |
| 4061 | */ |
| 4062 | final class ImeInputStage extends AsyncInputStage |
| 4063 | implements InputMethodManager.FinishedInputEventCallback { |
| 4064 | public ImeInputStage(InputStage next, String traceCounter) { |
| 4065 | super(next, traceCounter); |
| 4066 | } |
| 4067 | |
| 4068 | @Override |
| 4069 | protected int onProcess(QueuedInputEvent q) { |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 4070 | if (mLastWasImTarget && !isInLocalFocusMode()) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4071 | InputMethodManager imm = InputMethodManager.peekInstance(); |
| 4072 | if (imm != null) { |
| 4073 | final InputEvent event = q.mEvent; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4074 | if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4075 | int result = imm.dispatchInputEvent(event, q, this, mHandler); |
| 4076 | if (result == InputMethodManager.DISPATCH_HANDLED) { |
| 4077 | return FINISH_HANDLED; |
| 4078 | } else if (result == InputMethodManager.DISPATCH_NOT_HANDLED) { |
Adam Lesinski | c0f6eed | 2013-10-28 16:03:19 -0700 | [diff] [blame] | 4079 | // The IME could not handle it, so skip along to the next InputStage |
| 4080 | return FORWARD; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4081 | } else { |
| 4082 | return DEFER; // callback will be invoked later |
| 4083 | } |
| 4084 | } |
| 4085 | } |
| 4086 | return FORWARD; |
| 4087 | } |
| 4088 | |
| 4089 | @Override |
| 4090 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4091 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4092 | if (handled) { |
| 4093 | finish(q, true); |
| 4094 | return; |
| 4095 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4096 | forward(q); |
| 4097 | } |
| 4098 | } |
| 4099 | |
| 4100 | /** |
| 4101 | * Performs early processing of post-ime input events. |
| 4102 | */ |
| 4103 | final class EarlyPostImeInputStage extends InputStage { |
| 4104 | public EarlyPostImeInputStage(InputStage next) { |
| 4105 | super(next); |
| 4106 | } |
| 4107 | |
| 4108 | @Override |
| 4109 | protected int onProcess(QueuedInputEvent q) { |
| 4110 | if (q.mEvent instanceof KeyEvent) { |
| 4111 | return processKeyEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4112 | } else { |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4113 | final int source = q.mEvent.getSource(); |
| 4114 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4115 | return processPointerEvent(q); |
Jeff Brown | 481c157 | 2012-03-09 14:41:15 -0800 | [diff] [blame] | 4116 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4117 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4118 | return FORWARD; |
| 4119 | } |
| 4120 | |
| 4121 | private int processKeyEvent(QueuedInputEvent q) { |
| 4122 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4123 | |
| 4124 | // If the key's purpose is to exit touch mode then we consume it |
| 4125 | // and consider it handled. |
| 4126 | if (checkForLeavingTouchModeAndConsume(event)) { |
| 4127 | return FINISH_HANDLED; |
| 4128 | } |
| 4129 | |
| 4130 | // Make sure the fallback event policy sees all keys that will be |
| 4131 | // delivered to the view hierarchy. |
| 4132 | mFallbackEventHandler.preDispatchKeyEvent(event); |
| 4133 | return FORWARD; |
| 4134 | } |
| 4135 | |
| 4136 | private int processPointerEvent(QueuedInputEvent q) { |
| 4137 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4138 | |
| 4139 | // Translate the pointer event for compatibility, if needed. |
| 4140 | if (mTranslator != null) { |
| 4141 | mTranslator.translateEventInScreenToAppWindow(event); |
| 4142 | } |
| 4143 | |
| 4144 | // Enter touch mode on down or scroll. |
| 4145 | final int action = event.getAction(); |
| 4146 | if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_SCROLL) { |
| 4147 | ensureTouchMode(true); |
| 4148 | } |
| 4149 | |
| 4150 | // Offset the scroll position. |
| 4151 | if (mCurScrollY != 0) { |
| 4152 | event.offsetLocation(0, mCurScrollY); |
| 4153 | } |
| 4154 | |
| 4155 | // Remember the touch position for possible drag-initiation. |
| 4156 | if (event.isTouchEvent()) { |
| 4157 | mLastTouchPoint.x = event.getRawX(); |
| 4158 | mLastTouchPoint.y = event.getRawY(); |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 4159 | mLastTouchSource = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4160 | } |
| 4161 | return FORWARD; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4165 | /** |
| 4166 | * Delivers post-ime input events to a native activity. |
| 4167 | */ |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4168 | final class NativePostImeInputStage extends AsyncInputStage |
| 4169 | implements InputQueue.FinishedInputEventCallback { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4170 | public NativePostImeInputStage(InputStage next, String traceCounter) { |
| 4171 | super(next, traceCounter); |
| 4172 | } |
| 4173 | |
| 4174 | @Override |
| 4175 | protected int onProcess(QueuedInputEvent q) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4176 | if (mInputQueue != null) { |
| 4177 | mInputQueue.sendInputEvent(q.mEvent, q, false, this); |
| 4178 | return DEFER; |
| 4179 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4180 | return FORWARD; |
| 4181 | } |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 4182 | |
| 4183 | @Override |
| 4184 | public void onFinishedInputEvent(Object token, boolean handled) { |
| 4185 | QueuedInputEvent q = (QueuedInputEvent)token; |
| 4186 | if (handled) { |
| 4187 | finish(q, true); |
| 4188 | return; |
| 4189 | } |
| 4190 | forward(q); |
| 4191 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | /** |
| 4195 | * Delivers post-ime input events to the view hierarchy. |
| 4196 | */ |
| 4197 | final class ViewPostImeInputStage extends InputStage { |
| 4198 | public ViewPostImeInputStage(InputStage next) { |
| 4199 | super(next); |
| 4200 | } |
| 4201 | |
| 4202 | @Override |
| 4203 | protected int onProcess(QueuedInputEvent q) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4204 | if (q.mEvent instanceof KeyEvent) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4205 | return processKeyEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4206 | } else { |
| 4207 | final int source = q.mEvent.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4208 | if ((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 4209 | return processPointerEvent(q); |
| 4210 | } else if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
| 4211 | return processTrackballEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4212 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4213 | return processGenericMotionEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4214 | } |
| 4215 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4216 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 4217 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 4218 | @Override |
| 4219 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4220 | if (mUnbufferedInputDispatch |
| 4221 | && q.mEvent instanceof MotionEvent |
| 4222 | && ((MotionEvent)q.mEvent).isTouchEvent() |
| 4223 | && isTerminalInputEvent(q.mEvent)) { |
| 4224 | mUnbufferedInputDispatch = false; |
| 4225 | scheduleConsumeBatchedInput(); |
| 4226 | } |
| 4227 | super.onDeliverToNext(q); |
| 4228 | } |
| 4229 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4230 | private int processKeyEvent(QueuedInputEvent q) { |
| 4231 | final KeyEvent event = (KeyEvent)q.mEvent; |
| 4232 | |
| 4233 | // Deliver the key to the view hierarchy. |
| 4234 | if (mView.dispatchKeyEvent(event)) { |
| 4235 | return FINISH_HANDLED; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4236 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4237 | |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4238 | if (shouldDropInputEvent(q)) { |
| 4239 | return FINISH_NOT_HANDLED; |
| 4240 | } |
| 4241 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4242 | // If the Control modifier is held, try to interpret the key as a shortcut. |
| 4243 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4244 | && event.isCtrlPressed() |
| 4245 | && event.getRepeatCount() == 0 |
| 4246 | && !KeyEvent.isModifierKey(event.getKeyCode())) { |
| 4247 | if (mView.dispatchKeyShortcutEvent(event)) { |
| 4248 | return FINISH_HANDLED; |
| 4249 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4250 | if (shouldDropInputEvent(q)) { |
| 4251 | return FINISH_NOT_HANDLED; |
| 4252 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | // Apply the fallback event policy. |
| 4256 | if (mFallbackEventHandler.dispatchKeyEvent(event)) { |
| 4257 | return FINISH_HANDLED; |
| 4258 | } |
Michael Wright | 17d28ca | 2013-10-31 17:47:45 -0700 | [diff] [blame] | 4259 | if (shouldDropInputEvent(q)) { |
| 4260 | return FINISH_NOT_HANDLED; |
| 4261 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4262 | |
| 4263 | // Handle automatic focus changes. |
| 4264 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 4265 | int direction = 0; |
| 4266 | switch (event.getKeyCode()) { |
| 4267 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 4268 | if (event.hasNoModifiers()) { |
| 4269 | direction = View.FOCUS_LEFT; |
| 4270 | } |
| 4271 | break; |
| 4272 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 4273 | if (event.hasNoModifiers()) { |
| 4274 | direction = View.FOCUS_RIGHT; |
| 4275 | } |
| 4276 | break; |
| 4277 | case KeyEvent.KEYCODE_DPAD_UP: |
| 4278 | if (event.hasNoModifiers()) { |
| 4279 | direction = View.FOCUS_UP; |
| 4280 | } |
| 4281 | break; |
| 4282 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 4283 | if (event.hasNoModifiers()) { |
| 4284 | direction = View.FOCUS_DOWN; |
| 4285 | } |
| 4286 | break; |
| 4287 | case KeyEvent.KEYCODE_TAB: |
| 4288 | if (event.hasNoModifiers()) { |
| 4289 | direction = View.FOCUS_FORWARD; |
| 4290 | } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { |
| 4291 | direction = View.FOCUS_BACKWARD; |
| 4292 | } |
| 4293 | break; |
| 4294 | } |
| 4295 | if (direction != 0) { |
| 4296 | View focused = mView.findFocus(); |
| 4297 | if (focused != null) { |
| 4298 | View v = focused.focusSearch(direction); |
| 4299 | if (v != null && v != focused) { |
| 4300 | // do the math the get the interesting rect |
| 4301 | // of previous focused into the coord system of |
| 4302 | // newly focused view |
| 4303 | focused.getFocusedRect(mTempRect); |
| 4304 | if (mView instanceof ViewGroup) { |
| 4305 | ((ViewGroup) mView).offsetDescendantRectToMyCoords( |
| 4306 | focused, mTempRect); |
| 4307 | ((ViewGroup) mView).offsetRectIntoDescendantCoords( |
| 4308 | v, mTempRect); |
| 4309 | } |
| 4310 | if (v.requestFocus(direction, mTempRect)) { |
| 4311 | playSoundEffect(SoundEffectConstants |
| 4312 | .getContantForFocusDirection(direction)); |
| 4313 | return FINISH_HANDLED; |
| 4314 | } |
| 4315 | } |
| 4316 | |
| 4317 | // Give the focused view a last chance to handle the dpad key. |
| 4318 | if (mView.dispatchUnhandledMove(focused, direction)) { |
| 4319 | return FINISH_HANDLED; |
| 4320 | } |
| 4321 | } else { |
| 4322 | // find the best view to give focus to in this non-touch-mode with no-focus |
| 4323 | View v = focusSearch(null, direction); |
| 4324 | if (v != null && v.requestFocus(direction)) { |
| 4325 | return FINISH_HANDLED; |
| 4326 | } |
| 4327 | } |
| 4328 | } |
| 4329 | } |
| 4330 | return FORWARD; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4331 | } |
| 4332 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4333 | private int processPointerEvent(QueuedInputEvent q) { |
| 4334 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4335 | |
Vladislav Kaznacheev | 527905e | 2016-02-16 16:20:56 -0800 | [diff] [blame] | 4336 | mAttachInfo.mUnbufferedDispatchRequested = false; |
| 4337 | final View eventTarget = |
| 4338 | (event.isFromSource(InputDevice.SOURCE_MOUSE) && mCapturingView != null) ? |
| 4339 | mCapturingView : mView; |
| 4340 | mAttachInfo.mHandlingPointerEvent = true; |
| 4341 | boolean handled = eventTarget.dispatchPointerEvent(event); |
| 4342 | maybeUpdatePointerIcon(event); |
| 4343 | mAttachInfo.mHandlingPointerEvent = false; |
| 4344 | if (mAttachInfo.mUnbufferedDispatchRequested && !mUnbufferedInputDispatch) { |
| 4345 | mUnbufferedInputDispatch = true; |
| 4346 | if (mConsumeBatchedInputScheduled) { |
| 4347 | scheduleConsumeBatchedInputImmediately(); |
| 4348 | } |
| 4349 | } |
| 4350 | return handled ? FINISH_HANDLED : FORWARD; |
| 4351 | } |
| 4352 | |
| 4353 | private void maybeUpdatePointerIcon(MotionEvent event) { |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4354 | if (event.getPointerCount() == 1 |
| 4355 | && event.isFromSource(InputDevice.SOURCE_MOUSE)) { |
| 4356 | if (event.getActionMasked() == MotionEvent.ACTION_HOVER_ENTER |
| 4357 | || event.getActionMasked() == MotionEvent.ACTION_HOVER_EXIT) { |
| 4358 | // Other apps or the window manager may change the icon shape outside of |
| 4359 | // this app, therefore the icon shape has to be reset on enter/exit event. |
| 4360 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4361 | } |
| 4362 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4363 | if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { |
| 4364 | if (!updatePointerIcon(event) && |
| 4365 | event.getActionMasked() == MotionEvent.ACTION_HOVER_MOVE) { |
| 4366 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
Jun Mukai | 1db5397 | 2015-09-11 18:08:31 -0700 | [diff] [blame] | 4367 | } |
| 4368 | } |
| 4369 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4372 | private int processTrackballEvent(QueuedInputEvent q) { |
| 4373 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4374 | |
| 4375 | if (mView.dispatchTrackballEvent(event)) { |
| 4376 | return FINISH_HANDLED; |
| 4377 | } |
| 4378 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4379 | } |
| 4380 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4381 | private int processGenericMotionEvent(QueuedInputEvent q) { |
| 4382 | final MotionEvent event = (MotionEvent)q.mEvent; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4383 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4384 | // Deliver the event to the view. |
| 4385 | if (mView.dispatchGenericMotionEvent(event)) { |
| 4386 | return FINISH_HANDLED; |
| 4387 | } |
| 4388 | return FORWARD; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4389 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4390 | } |
| 4391 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4392 | private void resetPointerIcon(MotionEvent event) { |
| 4393 | mPointerIconShape = PointerIcon.STYLE_NOT_SPECIFIED; |
| 4394 | updatePointerIcon(event); |
| 4395 | } |
| 4396 | |
| 4397 | private boolean updatePointerIcon(MotionEvent event) { |
| 4398 | final float x = event.getX(); |
| 4399 | final float y = event.getY(); |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4400 | if (mView == null) { |
| 4401 | // E.g. click outside a popup to dismiss it |
| 4402 | Slog.d(mTag, "updatePointerIcon called after view was removed"); |
| 4403 | return false; |
| 4404 | } |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4405 | if (x < 0 || x >= mView.getWidth() || y < 0 || y >= mView.getHeight()) { |
Andrii Kulian | 33c1bc5 | 2016-02-29 10:38:59 -0800 | [diff] [blame] | 4406 | // E.g. when moving window divider with mouse |
| 4407 | Slog.d(mTag, "updatePointerIcon called with position out of bounds"); |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 4408 | return false; |
| 4409 | } |
| 4410 | final PointerIcon pointerIcon = mView.getPointerIcon(event, x, y); |
| 4411 | final int pointerShape = (pointerIcon != null) ? |
| 4412 | pointerIcon.getStyle() : PointerIcon.STYLE_DEFAULT; |
| 4413 | |
| 4414 | if (mPointerIconShape != pointerShape) { |
| 4415 | mPointerIconShape = pointerShape; |
| 4416 | if (mPointerIconShape != PointerIcon.STYLE_CUSTOM) { |
| 4417 | mCustomPointerIcon = null; |
| 4418 | InputManager.getInstance().setPointerIconShape(pointerShape); |
| 4419 | return true; |
| 4420 | } |
| 4421 | } |
| 4422 | if (mPointerIconShape == PointerIcon.STYLE_CUSTOM && |
| 4423 | !pointerIcon.equals(mCustomPointerIcon)) { |
| 4424 | mCustomPointerIcon = pointerIcon; |
| 4425 | InputManager.getInstance().setCustomPointerIcon(mCustomPointerIcon); |
| 4426 | } |
| 4427 | return true; |
| 4428 | } |
| 4429 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4430 | /** |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4431 | * Performs synthesis of new input events from unhandled input events. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4432 | */ |
| 4433 | final class SyntheticInputStage extends InputStage { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4434 | private final SyntheticTrackballHandler mTrackball = new SyntheticTrackballHandler(); |
| 4435 | private final SyntheticJoystickHandler mJoystick = new SyntheticJoystickHandler(); |
| 4436 | private final SyntheticTouchNavigationHandler mTouchNavigation = |
| 4437 | new SyntheticTouchNavigationHandler(); |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4438 | private final SyntheticKeyboardHandler mKeyboard = new SyntheticKeyboardHandler(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4439 | |
| 4440 | public SyntheticInputStage() { |
| 4441 | super(null); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 4442 | } |
| 4443 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4444 | @Override |
| 4445 | protected int onProcess(QueuedInputEvent q) { |
| 4446 | q.mFlags |= QueuedInputEvent.FLAG_RESYNTHESIZED; |
| 4447 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4448 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4449 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4450 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4451 | mTrackball.process(event); |
| 4452 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4453 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4454 | mJoystick.process(event); |
| 4455 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4456 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4457 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4458 | mTouchNavigation.process(event); |
| 4459 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4460 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4461 | } else if ((q.mFlags & QueuedInputEvent.FLAG_UNHANDLED) != 0) { |
| 4462 | mKeyboard.process((KeyEvent)q.mEvent); |
| 4463 | return FINISH_HANDLED; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4464 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 4465 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4466 | return FORWARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | } |
| 4468 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4469 | @Override |
| 4470 | protected void onDeliverToNext(QueuedInputEvent q) { |
| 4471 | if ((q.mFlags & QueuedInputEvent.FLAG_RESYNTHESIZED) == 0) { |
| 4472 | // Cancel related synthetic events if any prior stage has handled the event. |
| 4473 | if (q.mEvent instanceof MotionEvent) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4474 | final MotionEvent event = (MotionEvent)q.mEvent; |
| 4475 | final int source = event.getSource(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4476 | if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4477 | mTrackball.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4478 | } else if ((source & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4479 | mJoystick.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4480 | } else if ((source & InputDevice.SOURCE_TOUCH_NAVIGATION) |
| 4481 | == InputDevice.SOURCE_TOUCH_NAVIGATION) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4482 | mTouchNavigation.cancel(event); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4483 | } |
| 4484 | } |
| 4485 | } |
| 4486 | super.onDeliverToNext(q); |
| 4487 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4488 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4489 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4490 | /** |
| 4491 | * Creates dpad events from unhandled trackball movements. |
| 4492 | */ |
| 4493 | final class SyntheticTrackballHandler { |
| 4494 | private final TrackballAxis mX = new TrackballAxis(); |
| 4495 | private final TrackballAxis mY = new TrackballAxis(); |
| 4496 | private long mLastTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4497 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4498 | public void process(MotionEvent event) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4499 | // Translate the trackball event into DPAD keys and try to deliver those. |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4500 | long curTime = SystemClock.uptimeMillis(); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4501 | if ((mLastTime + MAX_TRACKBALL_DELAY) < curTime) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4502 | // It has been too long since the last movement, |
| 4503 | // so restart at the beginning. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4504 | mX.reset(0); |
| 4505 | mY.reset(0); |
| 4506 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | final int action = event.getAction(); |
| 4510 | final int metaState = event.getMetaState(); |
| 4511 | switch (action) { |
| 4512 | case MotionEvent.ACTION_DOWN: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4513 | mX.reset(2); |
| 4514 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4515 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4516 | KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4517 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4518 | InputDevice.SOURCE_KEYBOARD)); |
| 4519 | break; |
| 4520 | case MotionEvent.ACTION_UP: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4521 | mX.reset(2); |
| 4522 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4523 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4524 | KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER, 0, metaState, |
| 4525 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4526 | InputDevice.SOURCE_KEYBOARD)); |
| 4527 | break; |
| 4528 | } |
| 4529 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4530 | if (DEBUG_TRACKBALL) Log.v(mTag, "TB X=" + mX.position + " step=" |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4531 | + mX.step + " dir=" + mX.dir + " acc=" + mX.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4532 | + " move=" + event.getX() |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4533 | + " / Y=" + mY.position + " step=" |
| 4534 | + mY.step + " dir=" + mY.dir + " acc=" + mY.acceleration |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4535 | + " move=" + event.getY()); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4536 | final float xOff = mX.collect(event.getX(), event.getEventTime(), "X"); |
| 4537 | final float yOff = mY.collect(event.getY(), event.getEventTime(), "Y"); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4538 | |
| 4539 | // Generate DPAD events based on the trackball movement. |
| 4540 | // We pick the axis that has moved the most as the direction of |
| 4541 | // the DPAD. When we generate DPAD events for one axis, then the |
| 4542 | // other axis is reset -- we don't want to perform DPAD jumps due |
| 4543 | // to slight movements in the trackball when making major movements |
| 4544 | // along the other axis. |
| 4545 | int keycode = 0; |
| 4546 | int movement = 0; |
| 4547 | float accel = 1; |
| 4548 | if (xOff > yOff) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4549 | movement = mX.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4550 | if (movement != 0) { |
| 4551 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_RIGHT |
| 4552 | : KeyEvent.KEYCODE_DPAD_LEFT; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4553 | accel = mX.acceleration; |
| 4554 | mY.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4555 | } |
| 4556 | } else if (yOff > 0) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4557 | movement = mY.generate(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4558 | if (movement != 0) { |
| 4559 | keycode = movement > 0 ? KeyEvent.KEYCODE_DPAD_DOWN |
| 4560 | : KeyEvent.KEYCODE_DPAD_UP; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4561 | accel = mY.acceleration; |
| 4562 | mX.reset(2); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | if (keycode != 0) { |
| 4567 | if (movement < 0) movement = -movement; |
| 4568 | int accelMovement = (int)(movement * accel); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4569 | if (DEBUG_TRACKBALL) Log.v(mTag, "Move: movement=" + movement |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4570 | + " accelMovement=" + accelMovement |
| 4571 | + " accel=" + accel); |
| 4572 | if (accelMovement > movement) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4573 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4574 | + keycode); |
| 4575 | movement--; |
| 4576 | int repeatCount = accelMovement - movement; |
| 4577 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4578 | KeyEvent.ACTION_MULTIPLE, keycode, repeatCount, metaState, |
| 4579 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4580 | InputDevice.SOURCE_KEYBOARD)); |
| 4581 | } |
| 4582 | while (movement > 0) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4583 | if (DEBUG_TRACKBALL) Log.v(mTag, "Delivering fake DPAD: " |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4584 | + keycode); |
| 4585 | movement--; |
| 4586 | curTime = SystemClock.uptimeMillis(); |
| 4587 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4588 | KeyEvent.ACTION_DOWN, keycode, 0, metaState, |
| 4589 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4590 | InputDevice.SOURCE_KEYBOARD)); |
| 4591 | enqueueInputEvent(new KeyEvent(curTime, curTime, |
| 4592 | KeyEvent.ACTION_UP, keycode, 0, metaState, |
| 4593 | KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_FALLBACK, |
| 4594 | InputDevice.SOURCE_KEYBOARD)); |
| 4595 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4596 | mLastTime = curTime; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4597 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4600 | public void cancel(MotionEvent event) { |
| 4601 | mLastTime = Integer.MIN_VALUE; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 4602 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4603 | // If we reach this, we consumed a trackball event. |
| 4604 | // Because we will not translate the trackball event into a key event, |
| 4605 | // touch mode will not exit, so we exit touch mode here. |
| 4606 | if (mView != null && mAdded) { |
| 4607 | ensureTouchMode(false); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4608 | } |
| 4609 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4610 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4612 | /** |
| 4613 | * Maintains state information for a single trackball axis, generating |
| 4614 | * discrete (DPAD) movements based on raw trackball motion. |
| 4615 | */ |
| 4616 | static final class TrackballAxis { |
| 4617 | /** |
| 4618 | * The maximum amount of acceleration we will apply. |
| 4619 | */ |
| 4620 | static final float MAX_ACCELERATION = 20; |
| 4621 | |
| 4622 | /** |
| 4623 | * The maximum amount of time (in milliseconds) between events in order |
| 4624 | * for us to consider the user to be doing fast trackball movements, |
| 4625 | * and thus apply an acceleration. |
| 4626 | */ |
| 4627 | static final long FAST_MOVE_TIME = 150; |
| 4628 | |
| 4629 | /** |
| 4630 | * Scaling factor to the time (in milliseconds) between events to how |
| 4631 | * much to multiple/divide the current acceleration. When movement |
| 4632 | * is < FAST_MOVE_TIME this multiplies the acceleration; when > |
| 4633 | * FAST_MOVE_TIME it divides it. |
| 4634 | */ |
| 4635 | static final float ACCEL_MOVE_SCALING_FACTOR = (1.0f/40); |
| 4636 | |
| 4637 | static final float FIRST_MOVEMENT_THRESHOLD = 0.5f; |
| 4638 | static final float SECOND_CUMULATIVE_MOVEMENT_THRESHOLD = 2.0f; |
| 4639 | static final float SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD = 1.0f; |
| 4640 | |
| 4641 | float position; |
| 4642 | float acceleration = 1; |
| 4643 | long lastMoveTime = 0; |
| 4644 | int step; |
| 4645 | int dir; |
| 4646 | int nonAccelMovement; |
| 4647 | |
| 4648 | void reset(int _step) { |
| 4649 | position = 0; |
| 4650 | acceleration = 1; |
| 4651 | lastMoveTime = 0; |
| 4652 | step = _step; |
| 4653 | dir = 0; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4654 | } |
| 4655 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4656 | /** |
| 4657 | * Add trackball movement into the state. If the direction of movement |
| 4658 | * has been reversed, the state is reset before adding the |
| 4659 | * movement (so that you don't have to compensate for any previously |
| 4660 | * collected movement before see the result of the movement in the |
| 4661 | * new direction). |
| 4662 | * |
| 4663 | * @return Returns the absolute value of the amount of movement |
| 4664 | * collected so far. |
| 4665 | */ |
| 4666 | float collect(float off, long time, String axis) { |
| 4667 | long normTime; |
| 4668 | if (off > 0) { |
| 4669 | normTime = (long)(off * FAST_MOVE_TIME); |
| 4670 | if (dir < 0) { |
| 4671 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to positive!"); |
| 4672 | position = 0; |
| 4673 | step = 0; |
| 4674 | acceleration = 1; |
| 4675 | lastMoveTime = 0; |
| 4676 | } |
| 4677 | dir = 1; |
| 4678 | } else if (off < 0) { |
| 4679 | normTime = (long)((-off) * FAST_MOVE_TIME); |
| 4680 | if (dir > 0) { |
| 4681 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " reversed to negative!"); |
| 4682 | position = 0; |
| 4683 | step = 0; |
| 4684 | acceleration = 1; |
| 4685 | lastMoveTime = 0; |
| 4686 | } |
| 4687 | dir = -1; |
| 4688 | } else { |
| 4689 | normTime = 0; |
| 4690 | } |
| 4691 | |
| 4692 | // The number of milliseconds between each movement that is |
| 4693 | // considered "normal" and will not result in any acceleration |
| 4694 | // or deceleration, scaled by the offset we have here. |
| 4695 | if (normTime > 0) { |
| 4696 | long delta = time - lastMoveTime; |
| 4697 | lastMoveTime = time; |
| 4698 | float acc = acceleration; |
| 4699 | if (delta < normTime) { |
| 4700 | // The user is scrolling rapidly, so increase acceleration. |
| 4701 | float scale = (normTime-delta) * ACCEL_MOVE_SCALING_FACTOR; |
| 4702 | if (scale > 1) acc *= scale; |
| 4703 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " accelerate: off=" |
| 4704 | + off + " normTime=" + normTime + " delta=" + delta |
| 4705 | + " scale=" + scale + " acc=" + acc); |
| 4706 | acceleration = acc < MAX_ACCELERATION ? acc : MAX_ACCELERATION; |
| 4707 | } else { |
| 4708 | // The user is scrolling slowly, so decrease acceleration. |
| 4709 | float scale = (delta-normTime) * ACCEL_MOVE_SCALING_FACTOR; |
| 4710 | if (scale > 1) acc /= scale; |
| 4711 | if (DEBUG_TRACKBALL) Log.v(TAG, axis + " deccelerate: off=" |
| 4712 | + off + " normTime=" + normTime + " delta=" + delta |
| 4713 | + " scale=" + scale + " acc=" + acc); |
| 4714 | acceleration = acc > 1 ? acc : 1; |
| 4715 | } |
| 4716 | } |
| 4717 | position += off; |
| 4718 | return Math.abs(position); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 4719 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4720 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4721 | /** |
| 4722 | * Generate the number of discrete movement events appropriate for |
| 4723 | * the currently collected trackball movement. |
| 4724 | * |
| 4725 | * @return Returns the number of discrete movements, either positive |
| 4726 | * or negative, or 0 if there is not enough trackball movement yet |
| 4727 | * for a discrete movement. |
| 4728 | */ |
| 4729 | int generate() { |
| 4730 | int movement = 0; |
| 4731 | nonAccelMovement = 0; |
| 4732 | do { |
| 4733 | final int dir = position >= 0 ? 1 : -1; |
| 4734 | switch (step) { |
| 4735 | // If we are going to execute the first step, then we want |
| 4736 | // to do this as soon as possible instead of waiting for |
| 4737 | // a full movement, in order to make things look responsive. |
| 4738 | case 0: |
| 4739 | if (Math.abs(position) < FIRST_MOVEMENT_THRESHOLD) { |
| 4740 | return movement; |
| 4741 | } |
| 4742 | movement += dir; |
| 4743 | nonAccelMovement += dir; |
| 4744 | step = 1; |
| 4745 | break; |
| 4746 | // If we have generated the first movement, then we need |
| 4747 | // to wait for the second complete trackball motion before |
| 4748 | // generating the second discrete movement. |
| 4749 | case 1: |
| 4750 | if (Math.abs(position) < SECOND_CUMULATIVE_MOVEMENT_THRESHOLD) { |
| 4751 | return movement; |
| 4752 | } |
| 4753 | movement += dir; |
| 4754 | nonAccelMovement += dir; |
| 4755 | position -= SECOND_CUMULATIVE_MOVEMENT_THRESHOLD * dir; |
| 4756 | step = 2; |
| 4757 | break; |
| 4758 | // After the first two, we generate discrete movements |
| 4759 | // consistently with the trackball, applying an acceleration |
| 4760 | // if the trackball is moving quickly. This is a simple |
| 4761 | // acceleration on top of what we already compute based |
| 4762 | // on how quickly the wheel is being turned, to apply |
| 4763 | // a longer increasing acceleration to continuous movement |
| 4764 | // in one direction. |
| 4765 | default: |
| 4766 | if (Math.abs(position) < SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD) { |
| 4767 | return movement; |
| 4768 | } |
| 4769 | movement += dir; |
| 4770 | position -= dir * SUBSEQUENT_INCREMENTAL_MOVEMENT_THRESHOLD; |
| 4771 | float acc = acceleration; |
| 4772 | acc *= 1.1f; |
| 4773 | acceleration = acc < MAX_ACCELERATION ? acc : acceleration; |
| 4774 | break; |
| 4775 | } |
| 4776 | } while (true); |
| 4777 | } |
| 4778 | } |
| 4779 | |
| 4780 | /** |
| 4781 | * Creates dpad events from unhandled joystick movements. |
| 4782 | */ |
| 4783 | final class SyntheticJoystickHandler extends Handler { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4784 | private final static String TAG = "SyntheticJoystickHandler"; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4785 | private final static int MSG_ENQUEUE_X_AXIS_KEY_REPEAT = 1; |
| 4786 | private final static int MSG_ENQUEUE_Y_AXIS_KEY_REPEAT = 2; |
| 4787 | |
| 4788 | private int mLastXDirection; |
| 4789 | private int mLastYDirection; |
| 4790 | private int mLastXKeyCode; |
| 4791 | private int mLastYKeyCode; |
| 4792 | |
| 4793 | public SyntheticJoystickHandler() { |
| 4794 | super(true); |
| 4795 | } |
| 4796 | |
| 4797 | @Override |
| 4798 | public void handleMessage(Message msg) { |
| 4799 | switch (msg.what) { |
| 4800 | case MSG_ENQUEUE_X_AXIS_KEY_REPEAT: |
| 4801 | case MSG_ENQUEUE_Y_AXIS_KEY_REPEAT: { |
| 4802 | KeyEvent oldEvent = (KeyEvent)msg.obj; |
| 4803 | KeyEvent e = KeyEvent.changeTimeRepeat(oldEvent, |
| 4804 | SystemClock.uptimeMillis(), |
| 4805 | oldEvent.getRepeatCount() + 1); |
| 4806 | if (mAttachInfo.mHasWindowFocus) { |
| 4807 | enqueueInputEvent(e); |
| 4808 | Message m = obtainMessage(msg.what, e); |
| 4809 | m.setAsynchronous(true); |
| 4810 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatDelay()); |
| 4811 | } |
| 4812 | } break; |
| 4813 | } |
| 4814 | } |
| 4815 | |
| 4816 | public void process(MotionEvent event) { |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4817 | switch(event.getActionMasked()) { |
| 4818 | case MotionEvent.ACTION_CANCEL: |
| 4819 | cancel(event); |
| 4820 | break; |
| 4821 | case MotionEvent.ACTION_MOVE: |
| 4822 | update(event, true); |
| 4823 | break; |
| 4824 | default: |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 4825 | Log.w(mTag, "Unexpected action: " + event.getActionMasked()); |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4826 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4827 | } |
| 4828 | |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 4829 | private void cancel(MotionEvent event) { |
| 4830 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
| 4831 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4832 | update(event, false); |
| 4833 | } |
| 4834 | |
| 4835 | private void update(MotionEvent event, boolean synthesizeNewKeys) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4836 | final long time = event.getEventTime(); |
| 4837 | final int metaState = event.getMetaState(); |
| 4838 | final int deviceId = event.getDeviceId(); |
| 4839 | final int source = event.getSource(); |
| 4840 | |
| 4841 | int xDirection = joystickAxisValueToDirection( |
| 4842 | event.getAxisValue(MotionEvent.AXIS_HAT_X)); |
| 4843 | if (xDirection == 0) { |
| 4844 | xDirection = joystickAxisValueToDirection(event.getX()); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4847 | int yDirection = joystickAxisValueToDirection( |
| 4848 | event.getAxisValue(MotionEvent.AXIS_HAT_Y)); |
| 4849 | if (yDirection == 0) { |
| 4850 | yDirection = joystickAxisValueToDirection(event.getY()); |
| 4851 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4852 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4853 | if (xDirection != mLastXDirection) { |
| 4854 | if (mLastXKeyCode != 0) { |
| 4855 | removeMessages(MSG_ENQUEUE_X_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4856 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4857 | KeyEvent.ACTION_UP, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4858 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4859 | mLastXKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4860 | } |
| 4861 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4862 | mLastXDirection = xDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4863 | |
| 4864 | if (xDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4865 | mLastXKeyCode = xDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4866 | ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT; |
| 4867 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4868 | KeyEvent.ACTION_DOWN, mLastXKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4869 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4870 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4871 | Message m = obtainMessage(MSG_ENQUEUE_X_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4872 | m.setAsynchronous(true); |
Michael Wright | b961852 | 2013-04-10 15:20:56 -0700 | [diff] [blame] | 4873 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4874 | } |
| 4875 | } |
| 4876 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4877 | if (yDirection != mLastYDirection) { |
| 4878 | if (mLastYKeyCode != 0) { |
| 4879 | removeMessages(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4880 | enqueueInputEvent(new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4881 | KeyEvent.ACTION_UP, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4882 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source)); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4883 | mLastYKeyCode = 0; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4884 | } |
| 4885 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4886 | mLastYDirection = yDirection; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4887 | |
| 4888 | if (yDirection != 0 && synthesizeNewKeys) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4889 | mLastYKeyCode = yDirection > 0 |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4890 | ? KeyEvent.KEYCODE_DPAD_DOWN : KeyEvent.KEYCODE_DPAD_UP; |
| 4891 | final KeyEvent e = new KeyEvent(time, time, |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4892 | KeyEvent.ACTION_DOWN, mLastYKeyCode, 0, metaState, |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4893 | deviceId, 0, KeyEvent.FLAG_FALLBACK, source); |
| 4894 | enqueueInputEvent(e); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4895 | Message m = obtainMessage(MSG_ENQUEUE_Y_AXIS_KEY_REPEAT, e); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4896 | m.setAsynchronous(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4897 | sendMessageDelayed(m, ViewConfiguration.getKeyRepeatTimeout()); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4898 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4899 | } |
| 4900 | } |
| 4901 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 4902 | private int joystickAxisValueToDirection(float value) { |
| 4903 | if (value >= 0.5f) { |
| 4904 | return 1; |
| 4905 | } else if (value <= -0.5f) { |
| 4906 | return -1; |
| 4907 | } else { |
| 4908 | return 0; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4909 | } |
| 4910 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4911 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 4912 | |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4913 | /** |
| 4914 | * Creates dpad events from unhandled touch navigation movements. |
| 4915 | */ |
| 4916 | final class SyntheticTouchNavigationHandler extends Handler { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4917 | private static final String LOCAL_TAG = "SyntheticTouchNavigationHandler"; |
| 4918 | private static final boolean LOCAL_DEBUG = false; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4919 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4920 | // Assumed nominal width and height in millimeters of a touch navigation pad, |
| 4921 | // if no resolution information is available from the input system. |
| 4922 | private static final float DEFAULT_WIDTH_MILLIMETERS = 48; |
| 4923 | private static final float DEFAULT_HEIGHT_MILLIMETERS = 48; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4924 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4925 | /* TODO: These constants should eventually be moved to ViewConfiguration. */ |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4926 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4927 | // The nominal distance traveled to move by one unit. |
| 4928 | private static final int TICK_DISTANCE_MILLIMETERS = 12; |
| 4929 | |
| 4930 | // Minimum and maximum fling velocity in ticks per second. |
| 4931 | // The minimum velocity should be set such that we perform enough ticks per |
| 4932 | // second that the fling appears to be fluid. For example, if we set the minimum |
| 4933 | // to 2 ticks per second, then there may be up to half a second delay between the next |
| 4934 | // to last and last ticks which is noticeably discrete and jerky. This value should |
| 4935 | // probably not be set to anything less than about 4. |
| 4936 | // If fling accuracy is a problem then consider tuning the tick distance instead. |
| 4937 | private static final float MIN_FLING_VELOCITY_TICKS_PER_SECOND = 6f; |
| 4938 | private static final float MAX_FLING_VELOCITY_TICKS_PER_SECOND = 20f; |
| 4939 | |
| 4940 | // Fling velocity decay factor applied after each new key is emitted. |
| 4941 | // This parameter controls the deceleration and overall duration of the fling. |
| 4942 | // The fling stops automatically when its velocity drops below the minimum |
| 4943 | // fling velocity defined above. |
| 4944 | private static final float FLING_TICK_DECAY = 0.8f; |
| 4945 | |
| 4946 | /* The input device that we are tracking. */ |
| 4947 | |
| 4948 | private int mCurrentDeviceId = -1; |
| 4949 | private int mCurrentSource; |
| 4950 | private boolean mCurrentDeviceSupported; |
| 4951 | |
| 4952 | /* Configuration for the current input device. */ |
| 4953 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4954 | // The scaled tick distance. A movement of this amount should generally translate |
| 4955 | // into a single dpad event in a given direction. |
| 4956 | private float mConfigTickDistance; |
| 4957 | |
| 4958 | // The minimum and maximum scaled fling velocity. |
| 4959 | private float mConfigMinFlingVelocity; |
| 4960 | private float mConfigMaxFlingVelocity; |
| 4961 | |
| 4962 | /* Tracking state. */ |
| 4963 | |
| 4964 | // The velocity tracker for detecting flings. |
| 4965 | private VelocityTracker mVelocityTracker; |
| 4966 | |
| 4967 | // The active pointer id, or -1 if none. |
| 4968 | private int mActivePointerId = -1; |
| 4969 | |
John Reck | 79d81e6 | 2013-11-05 13:26:57 -0800 | [diff] [blame] | 4970 | // Location where tracking started. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4971 | private float mStartX; |
| 4972 | private float mStartY; |
| 4973 | |
| 4974 | // Most recently observed position. |
| 4975 | private float mLastX; |
| 4976 | private float mLastY; |
| 4977 | |
| 4978 | // Accumulated movement delta since the last direction key was sent. |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4979 | private float mAccumulatedX; |
| 4980 | private float mAccumulatedY; |
| 4981 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4982 | // Set to true if any movement was delivered to the app. |
| 4983 | // Implies that tap slop was exceeded. |
| 4984 | private boolean mConsumedMovement; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4985 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4986 | // The most recently sent key down event. |
| 4987 | // The keycode remains set until the direction changes or a fling ends |
| 4988 | // so that repeated key events may be generated as required. |
| 4989 | private long mPendingKeyDownTime; |
| 4990 | private int mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 4991 | private int mPendingKeyRepeatCount; |
| 4992 | private int mPendingKeyMetaState; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4993 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 4994 | // The current fling velocity while a fling is in progress. |
| 4995 | private boolean mFlinging; |
| 4996 | private float mFlingVelocity; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 4997 | |
| 4998 | public SyntheticTouchNavigationHandler() { |
| 4999 | super(true); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | public void process(MotionEvent event) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5003 | // Update the current device information. |
| 5004 | final long time = event.getEventTime(); |
| 5005 | final int deviceId = event.getDeviceId(); |
| 5006 | final int source = event.getSource(); |
| 5007 | if (mCurrentDeviceId != deviceId || mCurrentSource != source) { |
| 5008 | finishKeys(time); |
| 5009 | finishTracking(time); |
| 5010 | mCurrentDeviceId = deviceId; |
| 5011 | mCurrentSource = source; |
| 5012 | mCurrentDeviceSupported = false; |
| 5013 | InputDevice device = event.getDevice(); |
| 5014 | if (device != null) { |
| 5015 | // In order to support an input device, we must know certain |
| 5016 | // characteristics about it, such as its size and resolution. |
| 5017 | InputDevice.MotionRange xRange = device.getMotionRange(MotionEvent.AXIS_X); |
| 5018 | InputDevice.MotionRange yRange = device.getMotionRange(MotionEvent.AXIS_Y); |
| 5019 | if (xRange != null && yRange != null) { |
| 5020 | mCurrentDeviceSupported = true; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5021 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5022 | // Infer the resolution if it not actually known. |
| 5023 | float xRes = xRange.getResolution(); |
| 5024 | if (xRes <= 0) { |
| 5025 | xRes = xRange.getRange() / DEFAULT_WIDTH_MILLIMETERS; |
| 5026 | } |
| 5027 | float yRes = yRange.getResolution(); |
| 5028 | if (yRes <= 0) { |
| 5029 | yRes = yRange.getRange() / DEFAULT_HEIGHT_MILLIMETERS; |
| 5030 | } |
| 5031 | float nominalRes = (xRes + yRes) * 0.5f; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5032 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5033 | // Precompute all of the configuration thresholds we will need. |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5034 | mConfigTickDistance = TICK_DISTANCE_MILLIMETERS * nominalRes; |
| 5035 | mConfigMinFlingVelocity = |
| 5036 | MIN_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5037 | mConfigMaxFlingVelocity = |
| 5038 | MAX_FLING_VELOCITY_TICKS_PER_SECOND * mConfigTickDistance; |
| 5039 | |
| 5040 | if (LOCAL_DEBUG) { |
| 5041 | Log.d(LOCAL_TAG, "Configured device " + mCurrentDeviceId |
| 5042 | + " (" + Integer.toHexString(mCurrentSource) + "): " |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5043 | + ", mConfigTickDistance=" + mConfigTickDistance |
| 5044 | + ", mConfigMinFlingVelocity=" + mConfigMinFlingVelocity |
| 5045 | + ", mConfigMaxFlingVelocity=" + mConfigMaxFlingVelocity); |
| 5046 | } |
| 5047 | } |
| 5048 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5049 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5050 | if (!mCurrentDeviceSupported) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5051 | return; |
| 5052 | } |
| 5053 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5054 | // Handle the event. |
| 5055 | final int action = event.getActionMasked(); |
| 5056 | switch (action) { |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5057 | case MotionEvent.ACTION_DOWN: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5058 | boolean caughtFling = mFlinging; |
| 5059 | finishKeys(time); |
| 5060 | finishTracking(time); |
| 5061 | mActivePointerId = event.getPointerId(0); |
| 5062 | mVelocityTracker = VelocityTracker.obtain(); |
| 5063 | mVelocityTracker.addMovement(event); |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5064 | mStartX = event.getX(); |
| 5065 | mStartY = event.getY(); |
| 5066 | mLastX = mStartX; |
| 5067 | mLastY = mStartY; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5068 | mAccumulatedX = 0; |
| 5069 | mAccumulatedY = 0; |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5070 | |
| 5071 | // If we caught a fling, then pretend that the tap slop has already |
| 5072 | // been exceeded to suppress taps whose only purpose is to stop the fling. |
| 5073 | mConsumedMovement = caughtFling; |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5074 | break; |
| 5075 | } |
| 5076 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5077 | case MotionEvent.ACTION_MOVE: |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5078 | case MotionEvent.ACTION_UP: { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5079 | if (mActivePointerId < 0) { |
| 5080 | break; |
| 5081 | } |
| 5082 | final int index = event.findPointerIndex(mActivePointerId); |
| 5083 | if (index < 0) { |
| 5084 | finishKeys(time); |
| 5085 | finishTracking(time); |
| 5086 | break; |
| 5087 | } |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5088 | |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5089 | mVelocityTracker.addMovement(event); |
| 5090 | final float x = event.getX(index); |
| 5091 | final float y = event.getY(index); |
| 5092 | mAccumulatedX += x - mLastX; |
| 5093 | mAccumulatedY += y - mLastY; |
| 5094 | mLastX = x; |
| 5095 | mLastY = y; |
| 5096 | |
| 5097 | // Consume any accumulated movement so far. |
| 5098 | final int metaState = event.getMetaState(); |
| 5099 | consumeAccumulatedMovement(time, metaState); |
| 5100 | |
| 5101 | // Detect taps and flings. |
| 5102 | if (action == MotionEvent.ACTION_UP) { |
Michael Wright | 88d7f79 | 2013-08-27 15:45:42 -0700 | [diff] [blame] | 5103 | if (mConsumedMovement && mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5104 | // It might be a fling. |
| 5105 | mVelocityTracker.computeCurrentVelocity(1000, mConfigMaxFlingVelocity); |
| 5106 | final float vx = mVelocityTracker.getXVelocity(mActivePointerId); |
| 5107 | final float vy = mVelocityTracker.getYVelocity(mActivePointerId); |
| 5108 | if (!startFling(time, vx, vy)) { |
| 5109 | finishKeys(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5110 | } |
| 5111 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5112 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5113 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5114 | break; |
| 5115 | } |
| 5116 | |
| 5117 | case MotionEvent.ACTION_CANCEL: { |
| 5118 | finishKeys(time); |
| 5119 | finishTracking(time); |
Jeff Brown | 678a125 | 2013-04-09 17:46:25 -0700 | [diff] [blame] | 5120 | break; |
| 5121 | } |
| 5122 | } |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5123 | } |
Jeff Brown | 4dac901 | 2013-04-10 01:03:19 -0700 | [diff] [blame] | 5124 | |
| 5125 | public void cancel(MotionEvent event) { |
| 5126 | if (mCurrentDeviceId == event.getDeviceId() |
| 5127 | && mCurrentSource == event.getSource()) { |
| 5128 | final long time = event.getEventTime(); |
| 5129 | finishKeys(time); |
| 5130 | finishTracking(time); |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | private void finishKeys(long time) { |
| 5135 | cancelFling(); |
| 5136 | sendKeyUp(time); |
| 5137 | } |
| 5138 | |
| 5139 | private void finishTracking(long time) { |
| 5140 | if (mActivePointerId >= 0) { |
| 5141 | mActivePointerId = -1; |
| 5142 | mVelocityTracker.recycle(); |
| 5143 | mVelocityTracker = null; |
| 5144 | } |
| 5145 | } |
| 5146 | |
| 5147 | private void consumeAccumulatedMovement(long time, int metaState) { |
| 5148 | final float absX = Math.abs(mAccumulatedX); |
| 5149 | final float absY = Math.abs(mAccumulatedY); |
| 5150 | if (absX >= absY) { |
| 5151 | if (absX >= mConfigTickDistance) { |
| 5152 | mAccumulatedX = consumeAccumulatedMovement(time, metaState, mAccumulatedX, |
| 5153 | KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT); |
| 5154 | mAccumulatedY = 0; |
| 5155 | mConsumedMovement = true; |
| 5156 | } |
| 5157 | } else { |
| 5158 | if (absY >= mConfigTickDistance) { |
| 5159 | mAccumulatedY = consumeAccumulatedMovement(time, metaState, mAccumulatedY, |
| 5160 | KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN); |
| 5161 | mAccumulatedX = 0; |
| 5162 | mConsumedMovement = true; |
| 5163 | } |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | private float consumeAccumulatedMovement(long time, int metaState, |
| 5168 | float accumulator, int negativeKeyCode, int positiveKeyCode) { |
| 5169 | while (accumulator <= -mConfigTickDistance) { |
| 5170 | sendKeyDownOrRepeat(time, negativeKeyCode, metaState); |
| 5171 | accumulator += mConfigTickDistance; |
| 5172 | } |
| 5173 | while (accumulator >= mConfigTickDistance) { |
| 5174 | sendKeyDownOrRepeat(time, positiveKeyCode, metaState); |
| 5175 | accumulator -= mConfigTickDistance; |
| 5176 | } |
| 5177 | return accumulator; |
| 5178 | } |
| 5179 | |
| 5180 | private void sendKeyDownOrRepeat(long time, int keyCode, int metaState) { |
| 5181 | if (mPendingKeyCode != keyCode) { |
| 5182 | sendKeyUp(time); |
| 5183 | mPendingKeyDownTime = time; |
| 5184 | mPendingKeyCode = keyCode; |
| 5185 | mPendingKeyRepeatCount = 0; |
| 5186 | } else { |
| 5187 | mPendingKeyRepeatCount += 1; |
| 5188 | } |
| 5189 | mPendingKeyMetaState = metaState; |
| 5190 | |
| 5191 | // Note: Normally we would pass FLAG_LONG_PRESS when the repeat count is 1 |
| 5192 | // but it doesn't quite make sense when simulating the events in this way. |
| 5193 | if (LOCAL_DEBUG) { |
| 5194 | Log.d(LOCAL_TAG, "Sending key down: keyCode=" + mPendingKeyCode |
| 5195 | + ", repeatCount=" + mPendingKeyRepeatCount |
| 5196 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5197 | } |
| 5198 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5199 | KeyEvent.ACTION_DOWN, mPendingKeyCode, mPendingKeyRepeatCount, |
| 5200 | mPendingKeyMetaState, mCurrentDeviceId, |
| 5201 | KeyEvent.FLAG_FALLBACK, mCurrentSource)); |
| 5202 | } |
| 5203 | |
| 5204 | private void sendKeyUp(long time) { |
| 5205 | if (mPendingKeyCode != KeyEvent.KEYCODE_UNKNOWN) { |
| 5206 | if (LOCAL_DEBUG) { |
| 5207 | Log.d(LOCAL_TAG, "Sending key up: keyCode=" + mPendingKeyCode |
| 5208 | + ", metaState=" + Integer.toHexString(mPendingKeyMetaState)); |
| 5209 | } |
| 5210 | enqueueInputEvent(new KeyEvent(mPendingKeyDownTime, time, |
| 5211 | KeyEvent.ACTION_UP, mPendingKeyCode, 0, mPendingKeyMetaState, |
| 5212 | mCurrentDeviceId, 0, KeyEvent.FLAG_FALLBACK, |
| 5213 | mCurrentSource)); |
| 5214 | mPendingKeyCode = KeyEvent.KEYCODE_UNKNOWN; |
| 5215 | } |
| 5216 | } |
| 5217 | |
| 5218 | private boolean startFling(long time, float vx, float vy) { |
| 5219 | if (LOCAL_DEBUG) { |
| 5220 | Log.d(LOCAL_TAG, "Considering fling: vx=" + vx + ", vy=" + vy |
| 5221 | + ", min=" + mConfigMinFlingVelocity); |
| 5222 | } |
| 5223 | |
| 5224 | // Flings must be oriented in the same direction as the preceding movements. |
| 5225 | switch (mPendingKeyCode) { |
| 5226 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5227 | if (-vx >= mConfigMinFlingVelocity |
| 5228 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5229 | mFlingVelocity = -vx; |
| 5230 | break; |
| 5231 | } |
| 5232 | return false; |
| 5233 | |
| 5234 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5235 | if (vx >= mConfigMinFlingVelocity |
| 5236 | && Math.abs(vy) < mConfigMinFlingVelocity) { |
| 5237 | mFlingVelocity = vx; |
| 5238 | break; |
| 5239 | } |
| 5240 | return false; |
| 5241 | |
| 5242 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5243 | if (-vy >= mConfigMinFlingVelocity |
| 5244 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5245 | mFlingVelocity = -vy; |
| 5246 | break; |
| 5247 | } |
| 5248 | return false; |
| 5249 | |
| 5250 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 5251 | if (vy >= mConfigMinFlingVelocity |
| 5252 | && Math.abs(vx) < mConfigMinFlingVelocity) { |
| 5253 | mFlingVelocity = vy; |
| 5254 | break; |
| 5255 | } |
| 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | // Post the first fling event. |
| 5260 | mFlinging = postFling(time); |
| 5261 | return mFlinging; |
| 5262 | } |
| 5263 | |
| 5264 | private boolean postFling(long time) { |
| 5265 | // The idea here is to estimate the time when the pointer would have |
| 5266 | // traveled one tick distance unit given the current fling velocity. |
| 5267 | // This effect creates continuity of motion. |
| 5268 | if (mFlingVelocity >= mConfigMinFlingVelocity) { |
| 5269 | long delay = (long)(mConfigTickDistance / mFlingVelocity * 1000); |
| 5270 | postAtTime(mFlingRunnable, time + delay); |
| 5271 | if (LOCAL_DEBUG) { |
| 5272 | Log.d(LOCAL_TAG, "Posted fling: velocity=" |
| 5273 | + mFlingVelocity + ", delay=" + delay |
| 5274 | + ", keyCode=" + mPendingKeyCode); |
| 5275 | } |
| 5276 | return true; |
| 5277 | } |
| 5278 | return false; |
| 5279 | } |
| 5280 | |
| 5281 | private void cancelFling() { |
| 5282 | if (mFlinging) { |
| 5283 | removeCallbacks(mFlingRunnable); |
| 5284 | mFlinging = false; |
| 5285 | } |
| 5286 | } |
| 5287 | |
| 5288 | private final Runnable mFlingRunnable = new Runnable() { |
| 5289 | @Override |
| 5290 | public void run() { |
| 5291 | final long time = SystemClock.uptimeMillis(); |
| 5292 | sendKeyDownOrRepeat(time, mPendingKeyCode, mPendingKeyMetaState); |
| 5293 | mFlingVelocity *= FLING_TICK_DECAY; |
| 5294 | if (!postFling(time)) { |
| 5295 | mFlinging = false; |
| 5296 | finishKeys(time); |
| 5297 | } |
| 5298 | } |
| 5299 | }; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5302 | final class SyntheticKeyboardHandler { |
| 5303 | public void process(KeyEvent event) { |
| 5304 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) != 0) { |
| 5305 | return; |
| 5306 | } |
| 5307 | |
| 5308 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 5309 | final int keyCode = event.getKeyCode(); |
| 5310 | final int metaState = event.getMetaState(); |
| 5311 | |
| 5312 | // Check for fallback actions specified by the key character map. |
| 5313 | KeyCharacterMap.FallbackAction fallbackAction = |
| 5314 | kcm.getFallbackAction(keyCode, metaState); |
| 5315 | if (fallbackAction != null) { |
| 5316 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 5317 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 5318 | event.getDownTime(), event.getEventTime(), |
| 5319 | event.getAction(), fallbackAction.keyCode, |
| 5320 | event.getRepeatCount(), fallbackAction.metaState, |
| 5321 | event.getDeviceId(), event.getScanCode(), |
| 5322 | flags, event.getSource(), null); |
| 5323 | fallbackAction.recycle(); |
| 5324 | enqueueInputEvent(fallbackEvent); |
| 5325 | } |
| 5326 | } |
| 5327 | } |
| 5328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5329 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5330 | * Returns true if the key is used for keyboard navigation. |
| 5331 | * @param keyEvent The key event. |
| 5332 | * @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] | 5333 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5334 | private static boolean isNavigationKey(KeyEvent keyEvent) { |
| 5335 | switch (keyEvent.getKeyCode()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 5337 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 5338 | case KeyEvent.KEYCODE_DPAD_UP: |
| 5339 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5340 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 5341 | case KeyEvent.KEYCODE_PAGE_UP: |
| 5342 | case KeyEvent.KEYCODE_PAGE_DOWN: |
| 5343 | case KeyEvent.KEYCODE_MOVE_HOME: |
| 5344 | case KeyEvent.KEYCODE_MOVE_END: |
| 5345 | case KeyEvent.KEYCODE_TAB: |
| 5346 | case KeyEvent.KEYCODE_SPACE: |
| 5347 | case KeyEvent.KEYCODE_ENTER: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5348 | return true; |
| 5349 | } |
| 5350 | return false; |
| 5351 | } |
| 5352 | |
| 5353 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5354 | * Returns true if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | * @param keyEvent The key event. |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5356 | * @return True if the key is used for typing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5357 | */ |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5358 | private static boolean isTypingKey(KeyEvent keyEvent) { |
| 5359 | return keyEvent.getUnicodeChar() > 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5362 | /** |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5363 | * 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] | 5364 | * @param event The key event. |
| 5365 | * @return Whether this key event should be consumed (meaning the act of |
| 5366 | * leaving touch mode alone is considered the event). |
| 5367 | */ |
| 5368 | private boolean checkForLeavingTouchModeAndConsume(KeyEvent event) { |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5369 | // Only relevant in touch mode. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5370 | if (!mAttachInfo.mInTouchMode) { |
| 5371 | return false; |
| 5372 | } |
| 5373 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5374 | // Only consider leaving touch mode on DOWN or MULTIPLE actions, never on UP. |
| 5375 | final int action = event.getAction(); |
| 5376 | if (action != KeyEvent.ACTION_DOWN && action != KeyEvent.ACTION_MULTIPLE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5377 | return false; |
| 5378 | } |
| 5379 | |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5380 | // Don't leave touch mode if the IME told us not to. |
| 5381 | if ((event.getFlags() & KeyEvent.FLAG_KEEP_TOUCH_MODE) != 0) { |
| 5382 | return false; |
| 5383 | } |
| 5384 | |
| 5385 | // If the key can be used for keyboard navigation then leave touch mode |
| 5386 | // and select a focused view if needed (in ensureTouchMode). |
| 5387 | // When a new focused view is selected, we consume the navigation key because |
| 5388 | // navigation doesn't make much sense unless a view already has focus so |
| 5389 | // the key's purpose is to set focus. |
| 5390 | if (isNavigationKey(event)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | return ensureTouchMode(false); |
| 5392 | } |
Jeff Brown | 4e6319b | 2010-12-13 10:36:51 -0800 | [diff] [blame] | 5393 | |
| 5394 | // If the key can be used for typing then leave touch mode |
| 5395 | // and select a focused view if needed (in ensureTouchMode). |
| 5396 | // Always allow the view to process the typing key. |
| 5397 | if (isTypingKey(event)) { |
| 5398 | ensureTouchMode(false); |
| 5399 | return false; |
| 5400 | } |
| 5401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | return false; |
| 5403 | } |
| 5404 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5405 | /* drag/drop */ |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5406 | void setLocalDragState(Object obj) { |
| 5407 | mLocalDragState = obj; |
| 5408 | } |
| 5409 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5410 | private void handleDragEvent(DragEvent event) { |
| 5411 | // From the root, only drag start/end/location are dispatched. entered/exited |
| 5412 | // are determined and dispatched by the viewgroup hierarchy, who then report |
| 5413 | // that back here for ultimate reporting back to the framework. |
| 5414 | if (mView != null && mAdded) { |
| 5415 | final int what = event.mAction; |
| 5416 | |
| 5417 | if (what == DragEvent.ACTION_DRAG_EXITED) { |
| 5418 | // A direct EXITED event means that the window manager knows we've just crossed |
| 5419 | // a window boundary, so the current drag target within this one must have |
| 5420 | // just been exited. Send it the usual notifications and then we're done |
| 5421 | // for now. |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5422 | mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5423 | } else { |
| 5424 | // Cache the drag description when the operation starts, then fill it in |
| 5425 | // on subsequent calls as a convenience |
| 5426 | if (what == DragEvent.ACTION_DRAG_STARTED) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5427 | mCurrentDragView = null; // Start the current-recipient tracking |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5428 | mDragDescription = event.mClipDescription; |
| 5429 | } else { |
| 5430 | event.mClipDescription = mDragDescription; |
| 5431 | } |
| 5432 | |
| 5433 | // For events with a [screen] location, translate into window coordinates |
| 5434 | if ((what == DragEvent.ACTION_DRAG_LOCATION) || (what == DragEvent.ACTION_DROP)) { |
| 5435 | mDragPoint.set(event.mX, event.mY); |
| 5436 | if (mTranslator != null) { |
| 5437 | mTranslator.translatePointInScreenToAppWindow(mDragPoint); |
| 5438 | } |
| 5439 | |
| 5440 | if (mCurScrollY != 0) { |
| 5441 | mDragPoint.offset(0, mCurScrollY); |
| 5442 | } |
| 5443 | |
| 5444 | event.mX = mDragPoint.x; |
| 5445 | event.mY = mDragPoint.y; |
| 5446 | } |
| 5447 | |
| 5448 | // Remember who the current drag target is pre-dispatch |
| 5449 | final View prevDragView = mCurrentDragView; |
| 5450 | |
| 5451 | // Now dispatch the drag/drop event |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5452 | boolean result = mView.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5453 | |
| 5454 | // If we changed apparent drag target, tell the OS about it |
| 5455 | if (prevDragView != mCurrentDragView) { |
| 5456 | try { |
| 5457 | if (prevDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5458 | mWindowSession.dragRecipientExited(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5459 | } |
| 5460 | if (mCurrentDragView != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5461 | mWindowSession.dragRecipientEntered(mWindow); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5462 | } |
| 5463 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5464 | Slog.e(mTag, "Unable to note drag target change"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5465 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5466 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5467 | |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5468 | // Report the drop result when we're done |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5469 | if (what == DragEvent.ACTION_DROP) { |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 5470 | mDragDescription = null; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5471 | try { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5472 | Log.i(mTag, "Reporting drop result: " + result); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5473 | mWindowSession.reportDropResult(mWindow, result); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5474 | } catch (RemoteException e) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5475 | Log.e(mTag, "Unable to report drop result"); |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5476 | } |
| 5477 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5478 | |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5479 | // When the drag operation ends, reset drag-related state |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5480 | if (what == DragEvent.ACTION_DRAG_ENDED) { |
| 5481 | setLocalDragState(null); |
Vladislav Kaznacheev | 8206391 | 2015-11-20 14:20:13 -0800 | [diff] [blame] | 5482 | mAttachInfo.mDragToken = null; |
Vladislav Kaznacheev | 4f63974 | 2015-11-18 13:21:35 -0800 | [diff] [blame] | 5483 | if (mAttachInfo.mDragSurface != null) { |
| 5484 | mAttachInfo.mDragSurface.release(); |
| 5485 | mAttachInfo.mDragSurface = null; |
| 5486 | } |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 5487 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5488 | } |
| 5489 | } |
| 5490 | event.recycle(); |
| 5491 | } |
| 5492 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5493 | public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { |
| 5494 | if (mSeq != args.seq) { |
| 5495 | // The sequence has changed, so we need to update our value and make |
| 5496 | // sure to do a traversal afterward so the window manager is given our |
| 5497 | // most recent data. |
| 5498 | mSeq = args.seq; |
| 5499 | mAttachInfo.mForceReportNewAttributes = true; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5500 | scheduleTraversals(); |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 5501 | } |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5502 | if (mView == null) return; |
| 5503 | if (args.localChanges != 0) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5504 | mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5505 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5506 | |
| 5507 | int visibility = args.globalVisibility&View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5508 | if (visibility != mAttachInfo.mGlobalSystemUiVisibility) { |
| 5509 | mAttachInfo.mGlobalSystemUiVisibility = visibility; |
| 5510 | mView.dispatchSystemUiVisibilityChanged(visibility); |
Dianne Hackborn | cf67578 | 2012-05-10 15:07:24 -0700 | [diff] [blame] | 5511 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 5514 | public void handleDispatchWindowShown() { |
| 5515 | mAttachInfo.mTreeObserver.dispatchOnWindowShown(); |
| 5516 | } |
| 5517 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 5518 | public void handleRequestKeyboardShortcuts(IResultReceiver receiver) { |
| 5519 | Bundle data = new Bundle(); |
| 5520 | ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); |
| 5521 | if (mView != null) { |
| 5522 | mView.requestKeyboardShortcuts(list); |
| 5523 | } |
| 5524 | data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); |
| 5525 | try { |
| 5526 | receiver.send(0, data); |
| 5527 | } catch (RemoteException e) { |
| 5528 | } |
| 5529 | } |
| 5530 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5531 | public void getLastTouchPoint(Point outLocation) { |
| 5532 | outLocation.x = (int) mLastTouchPoint.x; |
| 5533 | outLocation.y = (int) mLastTouchPoint.y; |
| 5534 | } |
| 5535 | |
Vladislav Kaznacheev | ba76112 | 2016-01-22 12:09:45 -0800 | [diff] [blame] | 5536 | public int getLastTouchSource() { |
| 5537 | return mLastTouchSource; |
| 5538 | } |
| 5539 | |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 5540 | public void setDragFocus(View newDragTarget) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5541 | if (mCurrentDragView != newDragTarget) { |
Chris Tate | 048691c | 2010-10-12 17:39:18 -0700 | [diff] [blame] | 5542 | mCurrentDragView = newDragTarget; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5543 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5546 | private AudioManager getAudioManager() { |
| 5547 | if (mView == null) { |
| 5548 | throw new IllegalStateException("getAudioManager called when there is no mView"); |
| 5549 | } |
| 5550 | if (mAudioManager == null) { |
| 5551 | mAudioManager = (AudioManager) mView.getContext().getSystemService(Context.AUDIO_SERVICE); |
| 5552 | } |
| 5553 | return mAudioManager; |
| 5554 | } |
| 5555 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5556 | public AccessibilityInteractionController getAccessibilityInteractionController() { |
| 5557 | if (mView == null) { |
| 5558 | throw new IllegalStateException("getAccessibilityInteractionController" |
| 5559 | + " called when there is no mView"); |
| 5560 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5561 | if (mAccessibilityInteractionController == null) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 5562 | mAccessibilityInteractionController = new AccessibilityInteractionController(this); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5563 | } |
Gilles Debunne | 5ac8442 | 2011-10-19 09:35:58 -0700 | [diff] [blame] | 5564 | return mAccessibilityInteractionController; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5567 | private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility, |
| 5568 | boolean insetsPending) throws RemoteException { |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5569 | |
| 5570 | float appScale = mAttachInfo.mApplicationScale; |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5571 | boolean restore = false; |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5572 | if (params != null && mTranslator != null) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5573 | restore = true; |
| 5574 | params.backup(); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5575 | mTranslator.translateWindowLayout(params); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5576 | } |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5577 | if (params != null) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5578 | if (DBG) Log.d(mTag, "WindowLayout in layoutWindow:" + params); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5579 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5580 | mPendingConfiguration.seq = 0; |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5581 | //Log.d(mTag, ">>>>>> CALLING relayout"); |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5582 | if (params != null && mOrigWindowType != params.type) { |
| 5583 | // For compatibility with old apps, don't crash here. |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 5584 | if (mTargetSdkVersion < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5585 | Slog.w(mTag, "Window type can not be changed after " |
Dianne Hackborn | 180c484 | 2011-09-13 12:39:25 -0700 | [diff] [blame] | 5586 | + "the window is added; ignoring change of " + mView); |
| 5587 | params.type = mOrigWindowType; |
| 5588 | } |
| 5589 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5590 | int relayoutResult = mWindowSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 5591 | mWindow, mSeq, params, |
Dianne Hackborn | 189ee18 | 2010-12-02 21:48:53 -0800 | [diff] [blame] | 5592 | (int) (mView.getMeasuredWidth() * appScale + 0.5f), |
| 5593 | (int) (mView.getMeasuredHeight() * appScale + 0.5f), |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5594 | viewVisibility, insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5595 | mWinFrame, mPendingOverscanInsets, mPendingContentInsets, mPendingVisibleInsets, |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 5596 | mPendingStableInsets, mPendingOutsets, mPendingBackDropFrame, mPendingConfiguration, |
| 5597 | mSurface); |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5598 | |
| 5599 | mPendingAlwaysConsumeNavBar = |
| 5600 | (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_CONSUME_ALWAYS_NAV_BAR) != 0; |
| 5601 | |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5602 | //Log.d(mTag, "<<<<<< BACK FROM relayout"); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5603 | if (restore) { |
Mitsuru Oshima | e5fb328 | 2009-06-09 21:16:08 -0700 | [diff] [blame] | 5604 | params.restore(); |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5605 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5606 | |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5607 | if (mTranslator != null) { |
| 5608 | mTranslator.translateRectInScreenToAppWinFrame(mWinFrame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5609 | mTranslator.translateRectInScreenToAppWindow(mPendingOverscanInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5610 | mTranslator.translateRectInScreenToAppWindow(mPendingContentInsets); |
| 5611 | mTranslator.translateRectInScreenToAppWindow(mPendingVisibleInsets); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5612 | mTranslator.translateRectInScreenToAppWindow(mPendingStableInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5613 | } |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 5614 | return relayoutResult; |
| 5615 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 5616 | |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5617 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5618 | * {@inheritDoc} |
| 5619 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5620 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5621 | public void playSoundEffect(int effectId) { |
| 5622 | checkThread(); |
| 5623 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5624 | try { |
| 5625 | final AudioManager audioManager = getAudioManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | |
Jean-Michel Trivi | 13b18fd | 2010-05-05 09:18:15 -0700 | [diff] [blame] | 5627 | switch (effectId) { |
| 5628 | case SoundEffectConstants.CLICK: |
| 5629 | audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); |
| 5630 | return; |
| 5631 | case SoundEffectConstants.NAVIGATION_DOWN: |
| 5632 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_DOWN); |
| 5633 | return; |
| 5634 | case SoundEffectConstants.NAVIGATION_LEFT: |
| 5635 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_LEFT); |
| 5636 | return; |
| 5637 | case SoundEffectConstants.NAVIGATION_RIGHT: |
| 5638 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_RIGHT); |
| 5639 | return; |
| 5640 | case SoundEffectConstants.NAVIGATION_UP: |
| 5641 | audioManager.playSoundEffect(AudioManager.FX_FOCUS_NAVIGATION_UP); |
| 5642 | return; |
| 5643 | default: |
| 5644 | throw new IllegalArgumentException("unknown effect id " + effectId + |
| 5645 | " not defined in " + SoundEffectConstants.class.getCanonicalName()); |
| 5646 | } |
| 5647 | } catch (IllegalStateException e) { |
| 5648 | // Exception thrown by getAudioManager() when mView is null |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5649 | 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] | 5650 | e.printStackTrace(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | } |
| 5652 | } |
| 5653 | |
| 5654 | /** |
| 5655 | * {@inheritDoc} |
| 5656 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5657 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | public boolean performHapticFeedback(int effectId, boolean always) { |
| 5659 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5660 | return mWindowSession.performHapticFeedback(mWindow, effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | } catch (RemoteException e) { |
| 5662 | return false; |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * {@inheritDoc} |
| 5668 | */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5669 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | public View focusSearch(View focused, int direction) { |
| 5671 | checkThread(); |
| 5672 | if (!(mView instanceof ViewGroup)) { |
| 5673 | return null; |
| 5674 | } |
| 5675 | return FocusFinder.getInstance().findNextFocus((ViewGroup) mView, focused, direction); |
| 5676 | } |
| 5677 | |
| 5678 | public void debug() { |
| 5679 | mView.debug(); |
| 5680 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 5681 | |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5682 | public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { |
| 5683 | String innerPrefix = prefix + " "; |
| 5684 | writer.print(prefix); writer.println("ViewRoot:"); |
| 5685 | writer.print(innerPrefix); writer.print("mAdded="); writer.print(mAdded); |
| 5686 | writer.print(" mRemoved="); writer.println(mRemoved); |
| 5687 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputScheduled="); |
| 5688 | writer.println(mConsumeBatchedInputScheduled); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 5689 | writer.print(innerPrefix); writer.print("mConsumeBatchedInputImmediatelyScheduled="); |
| 5690 | writer.println(mConsumeBatchedInputImmediatelyScheduled); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5691 | writer.print(innerPrefix); writer.print("mPendingInputEventCount="); |
| 5692 | writer.println(mPendingInputEventCount); |
| 5693 | writer.print(innerPrefix); writer.print("mProcessInputEventsScheduled="); |
| 5694 | writer.println(mProcessInputEventsScheduled); |
| 5695 | writer.print(innerPrefix); writer.print("mTraversalScheduled="); |
| 5696 | writer.print(mTraversalScheduled); |
Daniel Koulomzin | 087ae47 | 2015-12-16 17:52:25 -0500 | [diff] [blame] | 5697 | writer.print(innerPrefix); writer.print("mIsAmbientMode="); |
| 5698 | writer.print(mIsAmbientMode); |
Jeff Brown | 5182c78 | 2013-10-15 20:31:52 -0700 | [diff] [blame] | 5699 | if (mTraversalScheduled) { |
| 5700 | writer.print(" (barrier="); writer.print(mTraversalBarrier); writer.println(")"); |
| 5701 | } else { |
| 5702 | writer.println(); |
| 5703 | } |
| 5704 | mFirstInputStage.dump(innerPrefix, writer); |
| 5705 | |
| 5706 | mChoreographer.dump(prefix, writer); |
| 5707 | |
| 5708 | writer.print(prefix); writer.println("View Hierarchy:"); |
| 5709 | dumpViewHierarchy(innerPrefix, writer, mView); |
| 5710 | } |
| 5711 | |
| 5712 | private void dumpViewHierarchy(String prefix, PrintWriter writer, View view) { |
| 5713 | writer.print(prefix); |
| 5714 | if (view == null) { |
| 5715 | writer.println("null"); |
| 5716 | return; |
| 5717 | } |
| 5718 | writer.println(view.toString()); |
| 5719 | if (!(view instanceof ViewGroup)) { |
| 5720 | return; |
| 5721 | } |
| 5722 | ViewGroup grp = (ViewGroup)view; |
| 5723 | final int N = grp.getChildCount(); |
| 5724 | if (N <= 0) { |
| 5725 | return; |
| 5726 | } |
| 5727 | prefix = prefix + " "; |
| 5728 | for (int i=0; i<N; i++) { |
| 5729 | dumpViewHierarchy(prefix, writer, grp.getChildAt(i)); |
| 5730 | } |
| 5731 | } |
| 5732 | |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5733 | public void dumpGfxInfo(int[] info) { |
Romain Guy | 54ab347 | 2012-06-14 12:52:53 -0700 | [diff] [blame] | 5734 | info[0] = info[1] = 0; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5735 | if (mView != null) { |
| 5736 | getGfxInfo(mView, info); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5737 | } |
| 5738 | } |
| 5739 | |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5740 | private static void getGfxInfo(View view, int[] info) { |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5741 | RenderNode renderNode = view.mRenderNode; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5742 | info[0]++; |
Chris Craik | 64a12e1 | 2014-03-28 18:12:12 -0700 | [diff] [blame] | 5743 | if (renderNode != null) { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 5744 | info[1] += renderNode.getDebugSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | if (view instanceof ViewGroup) { |
| 5748 | ViewGroup group = (ViewGroup) view; |
| 5749 | |
| 5750 | int count = group.getChildCount(); |
| 5751 | for (int i = 0; i < count; i++) { |
| 5752 | getGfxInfo(group.getChildAt(i), info); |
| 5753 | } |
| 5754 | } |
| 5755 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5756 | |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5757 | /** |
| 5758 | * @param immediate True, do now if not in traversal. False, put on queue and do later. |
| 5759 | * @return True, request has been queued. False, request has been completed. |
| 5760 | */ |
| 5761 | boolean die(boolean immediate) { |
Craig Mautner | df2390a | 2012-08-29 20:59:22 -0700 | [diff] [blame] | 5762 | // Make sure we do execute immediately if we are in the middle of a traversal or the damage |
| 5763 | // done by dispatchDetachedFromWindow will cause havoc on return. |
| 5764 | if (immediate && !mIsInTraversal) { |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5765 | doDie(); |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5766 | return false; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5767 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5768 | |
| 5769 | if (!mIsDrawing) { |
| 5770 | destroyHardwareRenderer(); |
| 5771 | } else { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5772 | Log.e(mTag, "Attempting to destroy the window while drawing!\n" + |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5773 | " window=" + this + ", title=" + mWindowAttributes.getTitle()); |
| 5774 | } |
| 5775 | mHandler.sendEmptyMessage(MSG_DIE); |
| 5776 | return true; |
Dianne Hackborn | 94d6914 | 2009-09-28 22:14:42 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
| 5779 | void doDie() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5780 | checkThread(); |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5781 | 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] | 5782 | synchronized (this) { |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5783 | if (mRemoved) { |
| 5784 | return; |
| 5785 | } |
| 5786 | mRemoved = true; |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5787 | if (mAdded) { |
Romain Guy | 16260e7 | 2011-09-01 14:26:11 -0700 | [diff] [blame] | 5788 | dispatchDetachedFromWindow(); |
| 5789 | } |
| 5790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | if (mAdded && !mFirst) { |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5792 | destroyHardwareRenderer(); |
| 5793 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5794 | if (mView != null) { |
| 5795 | int viewVisibility = mView.getVisibility(); |
| 5796 | boolean viewVisibilityChanged = mViewVisibility != viewVisibility; |
| 5797 | if (mWindowAttributesChanged || viewVisibilityChanged) { |
| 5798 | // If layout params have been changed, first give them |
| 5799 | // to the window manager to make sure it has the correct |
| 5800 | // animation info. |
| 5801 | try { |
| 5802 | if ((relayoutWindow(mWindowAttributes, viewVisibility, false) |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 5803 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) { |
| 5804 | mWindowSession.finishDrawing(mWindow); |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5805 | } |
| 5806 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | } |
Craig Mautner | 8f303ad | 2013-06-14 11:32:22 -0700 | [diff] [blame] | 5809 | |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5810 | mSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5812 | } |
Romain Guy | edbca12 | 2012-04-04 18:25:53 -0700 | [diff] [blame] | 5813 | |
| 5814 | mAdded = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5815 | } |
Craig Mautner | 05eb730 | 2013-06-03 17:24:21 -0700 | [diff] [blame] | 5816 | WindowManagerGlobal.getInstance().doRemoveView(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
| 5818 | |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5819 | public void requestUpdateConfiguration(Configuration config) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5820 | Message msg = mHandler.obtainMessage(MSG_UPDATE_CONFIGURATION, config); |
| 5821 | mHandler.sendMessage(msg); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5824 | public void loadSystemProperties() { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5825 | mHandler.post(new Runnable() { |
| 5826 | @Override |
| 5827 | public void run() { |
| 5828 | // Profiling |
| 5829 | mProfileRendering = SystemProperties.getBoolean(PROPERTY_PROFILE_RENDERING, false); |
| 5830 | profileRendering(mAttachInfo.mHasWindowFocus); |
| 5831 | |
| 5832 | // Hardware rendering |
| 5833 | if (mAttachInfo.mHardwareRenderer != null) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 5834 | if (mAttachInfo.mHardwareRenderer.loadSystemProperties()) { |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5835 | invalidate(); |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | // Layout debugging |
| 5840 | boolean layout = SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false); |
| 5841 | if (layout != mAttachInfo.mDebugLayout) { |
| 5842 | mAttachInfo.mDebugLayout = layout; |
| 5843 | if (!mHandler.hasMessages(MSG_INVALIDATE_WORLD)) { |
| 5844 | mHandler.sendEmptyMessageDelayed(MSG_INVALIDATE_WORLD, 200); |
| 5845 | } |
| 5846 | } |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5847 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 5848 | }); |
Dianne Hackborn | a53de06 | 2012-05-08 18:53:51 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5851 | private void destroyHardwareRenderer() { |
John Reck | 51aaf90 | 2015-12-02 15:08:07 -0800 | [diff] [blame] | 5852 | ThreadedRenderer hardwareRenderer = mAttachInfo.mHardwareRenderer; |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5853 | |
| 5854 | if (hardwareRenderer != null) { |
| 5855 | if (mView != null) { |
| 5856 | hardwareRenderer.destroyHardwareResources(mView); |
| 5857 | } |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 5858 | hardwareRenderer.destroy(); |
Romain Guy | a998dff | 2012-03-23 18:58:36 -0700 | [diff] [blame] | 5859 | hardwareRenderer.setRequested(false); |
| 5860 | |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 5861 | mAttachInfo.mHardwareRenderer = null; |
| 5862 | mAttachInfo.mHardwareAccelerated = false; |
Romain Guy | 29d8997 | 2010-09-22 16:10:57 -0700 | [diff] [blame] | 5863 | } |
| 5864 | } |
| 5865 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5866 | public void dispatchFinishInputConnection(InputConnection connection) { |
| 5867 | Message msg = mHandler.obtainMessage(MSG_FINISH_INPUT_CONNECTION, connection); |
| 5868 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5869 | } |
Mitsuru Oshima | 3d91492 | 2009-05-13 22:29:15 -0700 | [diff] [blame] | 5870 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5871 | public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5872 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5873 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 5874 | boolean alwaysConsumeNavBar) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5875 | if (DEBUG_LAYOUT) Log.v(mTag, "Resizing " + this + ": frame=" + frame.toShortString() |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5876 | + " contentInsets=" + contentInsets.toShortString() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | + " visibleInsets=" + visibleInsets.toShortString() |
Chong Zhang | d153c4f | 2015-11-06 20:26:40 -0800 | [diff] [blame] | 5878 | + " reportDraw=" + reportDraw |
| 5879 | + " backDropFrame=" + backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5880 | |
| 5881 | // Tell all listeners that we are resizing the window so that the chrome can get |
| 5882 | // updated as fast as possible on a separate thread, |
| 5883 | if (mDragResizing) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5884 | boolean fullscreen = frame.equals(backDropFrame); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5885 | synchronized (mWindowCallbacks) { |
| 5886 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 5887 | mWindowCallbacks.get(i).onWindowSizeIsChanging(backDropFrame, fullscreen, |
| 5888 | visibleInsets, stableInsets); |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 5889 | } |
| 5890 | } |
| 5891 | } |
| 5892 | |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5893 | Message msg = mHandler.obtainMessage(reportDraw ? MSG_RESIZED_REPORT : MSG_RESIZED); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5894 | if (mTranslator != null) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5895 | mTranslator.translateRectInScreenToAppWindow(frame); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5896 | mTranslator.translateRectInScreenToAppWindow(overscanInsets); |
Dianne Hackborn | 3556c9a | 2012-05-04 16:31:25 -0700 | [diff] [blame] | 5897 | mTranslator.translateRectInScreenToAppWindow(contentInsets); |
Mitsuru Oshima | 64f5934 | 2009-06-21 00:03:11 -0700 | [diff] [blame] | 5898 | mTranslator.translateRectInScreenToAppWindow(visibleInsets); |
Mitsuru Oshima | 9189cab | 2009-06-03 11:19:12 -0700 | [diff] [blame] | 5899 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5900 | SomeArgs args = SomeArgs.obtain(); |
| 5901 | final boolean sameProcessCall = (Binder.getCallingPid() == android.os.Process.myPid()); |
| 5902 | args.arg1 = sameProcessCall ? new Rect(frame) : frame; |
| 5903 | args.arg2 = sameProcessCall ? new Rect(contentInsets) : contentInsets; |
| 5904 | args.arg3 = sameProcessCall ? new Rect(visibleInsets) : visibleInsets; |
| 5905 | args.arg4 = sameProcessCall && newConfig != null ? new Configuration(newConfig) : newConfig; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 5906 | args.arg5 = sameProcessCall ? new Rect(overscanInsets) : overscanInsets; |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 5907 | args.arg6 = sameProcessCall ? new Rect(stableInsets) : stableInsets; |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 5908 | args.arg7 = sameProcessCall ? new Rect(outsets) : outsets; |
Jorim Jaggi | a7262a8 | 2015-11-03 15:15:40 +0100 | [diff] [blame] | 5909 | args.arg8 = sameProcessCall ? new Rect(backDropFrame) : backDropFrame; |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 5910 | args.argi1 = forceLayout ? 1 : 0; |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 5911 | args.argi2 = alwaysConsumeNavBar ? 1 : 0; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 5912 | msg.obj = args; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 5913 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5914 | } |
Chet Haase | 1f4786b | 2011-11-02 10:51:52 -0700 | [diff] [blame] | 5915 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 5916 | public void dispatchMoved(int newX, int newY) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 5917 | 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] | 5918 | if (mTranslator != null) { |
| 5919 | PointF point = new PointF(newX, newY); |
| 5920 | mTranslator.translatePointInScreenToAppWindow(point); |
| 5921 | newX = (int) (point.x + 0.5); |
| 5922 | newY = (int) (point.y + 0.5); |
| 5923 | } |
| 5924 | Message msg = mHandler.obtainMessage(MSG_WINDOW_MOVED, newX, newY); |
| 5925 | mHandler.sendMessage(msg); |
| 5926 | } |
| 5927 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5928 | /** |
| 5929 | * Represents a pending input event that is waiting in a queue. |
| 5930 | * |
| 5931 | * Input events are processed in serial order by the timestamp specified by |
Romain Guy | 211370f | 2012-02-01 16:10:55 -0800 | [diff] [blame] | 5932 | * {@link InputEvent#getEventTimeNano()}. In general, the input dispatcher delivers |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5933 | * one input event to the application at a time and waits for the application |
| 5934 | * to finish handling it before delivering the next one. |
| 5935 | * |
| 5936 | * However, because the application or IME can synthesize and inject multiple |
| 5937 | * key events at a time without going through the input dispatcher, we end up |
| 5938 | * needing a queue on the application's side. |
| 5939 | */ |
| 5940 | private static final class QueuedInputEvent { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5941 | public static final int FLAG_DELIVER_POST_IME = 1 << 0; |
| 5942 | public static final int FLAG_DEFERRED = 1 << 1; |
| 5943 | public static final int FLAG_FINISHED = 1 << 2; |
| 5944 | public static final int FLAG_FINISHED_HANDLED = 1 << 3; |
| 5945 | public static final int FLAG_RESYNTHESIZED = 1 << 4; |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5946 | public static final int FLAG_UNHANDLED = 1 << 5; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5947 | |
| 5948 | public QueuedInputEvent mNext; |
| 5949 | |
| 5950 | public InputEvent mEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 5951 | public InputEventReceiver mReceiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 5952 | public int mFlags; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 5953 | |
| 5954 | public boolean shouldSkipIme() { |
| 5955 | if ((mFlags & FLAG_DELIVER_POST_IME) != 0) { |
| 5956 | return true; |
| 5957 | } |
| 5958 | return mEvent instanceof MotionEvent |
| 5959 | && mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER); |
| 5960 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 5961 | |
| 5962 | public boolean shouldSendToSynthesizer() { |
| 5963 | if ((mFlags & FLAG_UNHANDLED) != 0) { |
| 5964 | return true; |
| 5965 | } |
| 5966 | |
| 5967 | return false; |
| 5968 | } |
Michael Wright | 06a7925 | 2014-05-05 17:45:29 -0700 | [diff] [blame] | 5969 | |
| 5970 | @Override |
| 5971 | public String toString() { |
| 5972 | StringBuilder sb = new StringBuilder("QueuedInputEvent{flags="); |
| 5973 | boolean hasPrevious = false; |
| 5974 | hasPrevious = flagToString("DELIVER_POST_IME", FLAG_DELIVER_POST_IME, hasPrevious, sb); |
| 5975 | hasPrevious = flagToString("DEFERRED", FLAG_DEFERRED, hasPrevious, sb); |
| 5976 | hasPrevious = flagToString("FINISHED", FLAG_FINISHED, hasPrevious, sb); |
| 5977 | hasPrevious = flagToString("FINISHED_HANDLED", FLAG_FINISHED_HANDLED, hasPrevious, sb); |
| 5978 | hasPrevious = flagToString("RESYNTHESIZED", FLAG_RESYNTHESIZED, hasPrevious, sb); |
| 5979 | hasPrevious = flagToString("UNHANDLED", FLAG_UNHANDLED, hasPrevious, sb); |
| 5980 | if (!hasPrevious) { |
| 5981 | sb.append("0"); |
| 5982 | } |
| 5983 | sb.append(", hasNextQueuedEvent=" + (mEvent != null ? "true" : "false")); |
| 5984 | sb.append(", hasInputEventReceiver=" + (mReceiver != null ? "true" : "false")); |
| 5985 | sb.append(", mEvent=" + mEvent + "}"); |
| 5986 | return sb.toString(); |
| 5987 | } |
| 5988 | |
| 5989 | private boolean flagToString(String name, int flag, |
| 5990 | boolean hasPrevious, StringBuilder sb) { |
| 5991 | if ((mFlags & flag) != 0) { |
| 5992 | if (hasPrevious) { |
| 5993 | sb.append("|"); |
| 5994 | } |
| 5995 | sb.append(name); |
| 5996 | return true; |
| 5997 | } |
| 5998 | return hasPrevious; |
| 5999 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6000 | } |
| 6001 | |
| 6002 | private QueuedInputEvent obtainQueuedInputEvent(InputEvent event, |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6003 | InputEventReceiver receiver, int flags) { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6004 | QueuedInputEvent q = mQueuedInputEventPool; |
| 6005 | if (q != null) { |
| 6006 | mQueuedInputEventPoolSize -= 1; |
| 6007 | mQueuedInputEventPool = q.mNext; |
| 6008 | q.mNext = null; |
| 6009 | } else { |
| 6010 | q = new QueuedInputEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6013 | q.mEvent = event; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6014 | q.mReceiver = receiver; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6015 | q.mFlags = flags; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6016 | return q; |
| 6017 | } |
| 6018 | |
| 6019 | private void recycleQueuedInputEvent(QueuedInputEvent q) { |
| 6020 | q.mEvent = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6021 | q.mReceiver = null; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6022 | |
| 6023 | if (mQueuedInputEventPoolSize < MAX_QUEUED_INPUT_EVENT_POOL_SIZE) { |
| 6024 | mQueuedInputEventPoolSize += 1; |
| 6025 | q.mNext = mQueuedInputEventPool; |
| 6026 | mQueuedInputEventPool = q; |
| 6027 | } |
| 6028 | } |
| 6029 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6030 | void enqueueInputEvent(InputEvent event) { |
| 6031 | enqueueInputEvent(event, null, 0, false); |
| 6032 | } |
| 6033 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6034 | void enqueueInputEvent(InputEvent event, |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6035 | InputEventReceiver receiver, int flags, boolean processImmediately) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6036 | adjustInputEventForCompatibility(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6037 | QueuedInputEvent q = obtainQueuedInputEvent(event, receiver, flags); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6038 | |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6039 | // Always enqueue the input event in order, regardless of its time stamp. |
| 6040 | // We do this because the application or the IME may inject key events |
| 6041 | // in response to touch events and we want to ensure that the injected keys |
| 6042 | // are processed in the order they were received and we cannot trust that |
| 6043 | // the time stamp of injected events are monotonic. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6044 | QueuedInputEvent last = mPendingInputEventTail; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6045 | if (last == null) { |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6046 | mPendingInputEventHead = q; |
| 6047 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6048 | } else { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6049 | last.mNext = q; |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6050 | mPendingInputEventTail = q; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6051 | } |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6052 | mPendingInputEventCount += 1; |
| 6053 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6054 | mPendingInputEventCount); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6055 | |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6056 | if (processImmediately) { |
| 6057 | doProcessInputEvents(); |
| 6058 | } else { |
| 6059 | scheduleProcessInputEvents(); |
| 6060 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | private void scheduleProcessInputEvents() { |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6064 | if (!mProcessInputEventsScheduled) { |
| 6065 | mProcessInputEventsScheduled = true; |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6066 | Message msg = mHandler.obtainMessage(MSG_PROCESS_INPUT_EVENTS); |
| 6067 | msg.setAsynchronous(true); |
| 6068 | mHandler.sendMessage(msg); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6069 | } |
| 6070 | } |
| 6071 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6072 | void doProcessInputEvents() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6073 | // Deliver all pending input events in the queue. |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6074 | while (mPendingInputEventHead != null) { |
| 6075 | QueuedInputEvent q = mPendingInputEventHead; |
| 6076 | mPendingInputEventHead = q.mNext; |
| 6077 | if (mPendingInputEventHead == null) { |
| 6078 | mPendingInputEventTail = null; |
| 6079 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6080 | q.mNext = null; |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6081 | |
Michael Wright | 95ae942 | 2013-03-14 10:58:50 -0700 | [diff] [blame] | 6082 | mPendingInputEventCount -= 1; |
| 6083 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, mPendingInputEventQueueLengthCounterName, |
| 6084 | mPendingInputEventCount); |
| 6085 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 6086 | long eventTime = q.mEvent.getEventTimeNano(); |
| 6087 | long oldestEventTime = eventTime; |
| 6088 | if (q.mEvent instanceof MotionEvent) { |
| 6089 | MotionEvent me = (MotionEvent)q.mEvent; |
| 6090 | if (me.getHistorySize() > 0) { |
| 6091 | oldestEventTime = me.getHistoricalEventTimeNano(0); |
| 6092 | } |
| 6093 | } |
| 6094 | mChoreographer.mFrameInfo.updateInputEventTime(eventTime, oldestEventTime); |
| 6095 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6096 | deliverInputEvent(q); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | // We are done processing all input events that we can process right now |
| 6100 | // so we can clear the pending flag immediately. |
Jeff Brown | 96e942d | 2011-11-30 19:55:01 -0800 | [diff] [blame] | 6101 | if (mProcessInputEventsScheduled) { |
| 6102 | mProcessInputEventsScheduled = false; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6103 | mHandler.removeMessages(MSG_PROCESS_INPUT_EVENTS); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6104 | } |
| 6105 | } |
| 6106 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6107 | private void deliverInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6108 | Trace.asyncTraceBegin(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6109 | q.mEvent.getSequenceNumber()); |
| 6110 | if (mInputEventConsistencyVerifier != null) { |
| 6111 | mInputEventConsistencyVerifier.onInputEvent(q.mEvent, 0); |
| 6112 | } |
Michael Wright | c8a7e54 | 2013-03-20 17:58:33 -0700 | [diff] [blame] | 6113 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6114 | InputStage stage; |
| 6115 | if (q.shouldSendToSynthesizer()) { |
| 6116 | stage = mSyntheticInputStage; |
| 6117 | } else { |
| 6118 | stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; |
| 6119 | } |
| 6120 | |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6121 | if (stage != null) { |
| 6122 | stage.deliver(q); |
| 6123 | } else { |
| 6124 | finishInputEvent(q); |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6125 | } |
Michael Wright | bf02096 | 2013-03-28 17:27:50 -0700 | [diff] [blame] | 6126 | } |
| 6127 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6128 | private void finishInputEvent(QueuedInputEvent q) { |
Michael Wright | d2c3adc | 2014-02-18 22:50:50 -0800 | [diff] [blame] | 6129 | Trace.asyncTraceEnd(Trace.TRACE_TAG_VIEW, "deliverInputEvent", |
| 6130 | q.mEvent.getSequenceNumber()); |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6131 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6132 | if (q.mReceiver != null) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6133 | boolean handled = (q.mFlags & QueuedInputEvent.FLAG_FINISHED_HANDLED) != 0; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6134 | q.mReceiver.finishInputEvent(q.mEvent, handled); |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 6135 | } else { |
| 6136 | q.mEvent.recycleIfNeededAfterDispatch(); |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | recycleQueuedInputEvent(q); |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6140 | } |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6141 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6142 | private void adjustInputEventForCompatibility(InputEvent e) { |
Dianne Hackborn | 0e3de6c | 2015-07-29 15:20:21 -0700 | [diff] [blame] | 6143 | if (mTargetSdkVersion < Build.VERSION_CODES.M && e instanceof MotionEvent) { |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 6144 | MotionEvent motion = (MotionEvent) e; |
| 6145 | final int mask = |
| 6146 | MotionEvent.BUTTON_STYLUS_PRIMARY | MotionEvent.BUTTON_STYLUS_SECONDARY; |
| 6147 | final int buttonState = motion.getButtonState(); |
| 6148 | final int compatButtonState = (buttonState & mask) >> 4; |
| 6149 | if (compatButtonState != 0) { |
| 6150 | motion.setButtonState(buttonState | compatButtonState); |
| 6151 | } |
| 6152 | } |
| 6153 | } |
| 6154 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 6155 | static boolean isTerminalInputEvent(InputEvent event) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 6156 | if (event instanceof KeyEvent) { |
| 6157 | final KeyEvent keyEvent = (KeyEvent)event; |
| 6158 | return keyEvent.getAction() == KeyEvent.ACTION_UP; |
| 6159 | } else { |
| 6160 | final MotionEvent motionEvent = (MotionEvent)event; |
| 6161 | final int action = motionEvent.getAction(); |
| 6162 | return action == MotionEvent.ACTION_UP |
| 6163 | || action == MotionEvent.ACTION_CANCEL |
| 6164 | || action == MotionEvent.ACTION_HOVER_EXIT; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 6165 | } |
| 6166 | } |
| 6167 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6168 | void scheduleConsumeBatchedInput() { |
| 6169 | if (!mConsumeBatchedInputScheduled) { |
| 6170 | mConsumeBatchedInputScheduled = true; |
| 6171 | mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, |
| 6172 | mConsumedBatchedInputRunnable, null); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6173 | } |
| 6174 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6175 | |
| 6176 | void unscheduleConsumeBatchedInput() { |
| 6177 | if (mConsumeBatchedInputScheduled) { |
| 6178 | mConsumeBatchedInputScheduled = false; |
| 6179 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_INPUT, |
| 6180 | mConsumedBatchedInputRunnable, null); |
| 6181 | } |
| 6182 | } |
| 6183 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6184 | void scheduleConsumeBatchedInputImmediately() { |
| 6185 | if (!mConsumeBatchedInputImmediatelyScheduled) { |
| 6186 | unscheduleConsumeBatchedInput(); |
| 6187 | mConsumeBatchedInputImmediatelyScheduled = true; |
| 6188 | mHandler.post(mConsumeBatchedInputImmediatelyRunnable); |
| 6189 | } |
| 6190 | } |
| 6191 | |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6192 | void doConsumeBatchedInput(long frameTimeNanos) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6193 | if (mConsumeBatchedInputScheduled) { |
| 6194 | mConsumeBatchedInputScheduled = false; |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6195 | if (mInputEventReceiver != null) { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6196 | if (mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos) |
| 6197 | && frameTimeNanos != -1) { |
Michael Wright | 62ce65d | 2013-10-25 14:50:36 -0700 | [diff] [blame] | 6198 | // If we consumed a batch here, we want to go ahead and schedule the |
| 6199 | // consumption of batched input events on the next frame. Otherwise, we would |
| 6200 | // 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] | 6201 | // things occurring in the process. If the frame time is -1, however, then |
| 6202 | // 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] | 6203 | scheduleConsumeBatchedInput(); |
| 6204 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6205 | } |
Jeff Brown | 330314c | 2012-04-27 02:20:22 -0700 | [diff] [blame] | 6206 | doProcessInputEvents(); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | final class TraversalRunnable implements Runnable { |
| 6211 | @Override |
| 6212 | public void run() { |
| 6213 | doTraversal(); |
| 6214 | } |
| 6215 | } |
| 6216 | final TraversalRunnable mTraversalRunnable = new TraversalRunnable(); |
Jeff Brown | 4a06c80 | 2012-02-15 15:06:01 -0800 | [diff] [blame] | 6217 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6218 | final class WindowInputEventReceiver extends InputEventReceiver { |
| 6219 | public WindowInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 6220 | super(inputChannel, looper); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6221 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6222 | |
| 6223 | @Override |
| 6224 | public void onInputEvent(InputEvent event) { |
Jeff Brown | f9261d2 | 2012-02-03 13:49:15 -0800 | [diff] [blame] | 6225 | enqueueInputEvent(event, this, 0, true); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6226 | } |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6227 | |
| 6228 | @Override |
| 6229 | public void onBatchedInputEventPending() { |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6230 | if (mUnbufferedInputDispatch) { |
| 6231 | super.onBatchedInputEventPending(); |
| 6232 | } else { |
| 6233 | scheduleConsumeBatchedInput(); |
| 6234 | } |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6235 | } |
| 6236 | |
| 6237 | @Override |
| 6238 | public void dispose() { |
| 6239 | unscheduleConsumeBatchedInput(); |
| 6240 | super.dispose(); |
Jeff Brown | 072ec96 | 2012-02-07 14:46:57 -0800 | [diff] [blame] | 6241 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 6242 | } |
| 6243 | WindowInputEventReceiver mInputEventReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6244 | |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6245 | final class ConsumeBatchedInputRunnable implements Runnable { |
| 6246 | @Override |
| 6247 | public void run() { |
Jeff Brown | 771526c | 2012-04-27 15:13:25 -0700 | [diff] [blame] | 6248 | doConsumeBatchedInput(mChoreographer.getFrameTimeNanos()); |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6249 | } |
| 6250 | } |
| 6251 | final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable = |
| 6252 | new ConsumeBatchedInputRunnable(); |
| 6253 | boolean mConsumeBatchedInputScheduled; |
| 6254 | |
Michael Wright | 9d744c7 | 2014-02-18 21:27:42 -0800 | [diff] [blame] | 6255 | final class ConsumeBatchedInputImmediatelyRunnable implements Runnable { |
| 6256 | @Override |
| 6257 | public void run() { |
| 6258 | doConsumeBatchedInput(-1); |
| 6259 | } |
| 6260 | } |
| 6261 | final ConsumeBatchedInputImmediatelyRunnable mConsumeBatchedInputImmediatelyRunnable = |
| 6262 | new ConsumeBatchedInputImmediatelyRunnable(); |
| 6263 | boolean mConsumeBatchedInputImmediatelyScheduled; |
| 6264 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6265 | final class InvalidateOnAnimationRunnable implements Runnable { |
| 6266 | private boolean mPosted; |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6267 | private final ArrayList<View> mViews = new ArrayList<View>(); |
| 6268 | private final ArrayList<AttachInfo.InvalidateInfo> mViewRects = |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6269 | new ArrayList<AttachInfo.InvalidateInfo>(); |
| 6270 | private View[] mTempViews; |
| 6271 | private AttachInfo.InvalidateInfo[] mTempViewRects; |
| 6272 | |
| 6273 | public void addView(View view) { |
| 6274 | synchronized (this) { |
| 6275 | mViews.add(view); |
| 6276 | postIfNeededLocked(); |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | public void addViewRect(AttachInfo.InvalidateInfo info) { |
| 6281 | synchronized (this) { |
| 6282 | mViewRects.add(info); |
| 6283 | postIfNeededLocked(); |
| 6284 | } |
| 6285 | } |
| 6286 | |
| 6287 | public void removeView(View view) { |
| 6288 | synchronized (this) { |
| 6289 | mViews.remove(view); |
| 6290 | |
| 6291 | for (int i = mViewRects.size(); i-- > 0; ) { |
| 6292 | AttachInfo.InvalidateInfo info = mViewRects.get(i); |
| 6293 | if (info.target == view) { |
| 6294 | mViewRects.remove(i); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6295 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | |
| 6299 | if (mPosted && mViews.isEmpty() && mViewRects.isEmpty()) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6300 | mChoreographer.removeCallbacks(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6301 | mPosted = false; |
| 6302 | } |
| 6303 | } |
| 6304 | } |
| 6305 | |
| 6306 | @Override |
| 6307 | public void run() { |
| 6308 | final int viewCount; |
| 6309 | final int viewRectCount; |
| 6310 | synchronized (this) { |
| 6311 | mPosted = false; |
| 6312 | |
| 6313 | viewCount = mViews.size(); |
| 6314 | if (viewCount != 0) { |
| 6315 | mTempViews = mViews.toArray(mTempViews != null |
| 6316 | ? mTempViews : new View[viewCount]); |
| 6317 | mViews.clear(); |
| 6318 | } |
| 6319 | |
| 6320 | viewRectCount = mViewRects.size(); |
| 6321 | if (viewRectCount != 0) { |
| 6322 | mTempViewRects = mViewRects.toArray(mTempViewRects != null |
| 6323 | ? mTempViewRects : new AttachInfo.InvalidateInfo[viewRectCount]); |
| 6324 | mViewRects.clear(); |
| 6325 | } |
| 6326 | } |
| 6327 | |
| 6328 | for (int i = 0; i < viewCount; i++) { |
| 6329 | mTempViews[i].invalidate(); |
Adam Powell | 3e3c4ee | 2012-05-16 17:34:21 -0700 | [diff] [blame] | 6330 | mTempViews[i] = null; |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | for (int i = 0; i < viewRectCount; i++) { |
| 6334 | final View.AttachInfo.InvalidateInfo info = mTempViewRects[i]; |
| 6335 | info.target.invalidate(info.left, info.top, info.right, info.bottom); |
Svetoslav Ganov | abae2a1 | 2012-11-27 16:59:37 -0800 | [diff] [blame] | 6336 | info.recycle(); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | private void postIfNeededLocked() { |
| 6341 | if (!mPosted) { |
Jeff Brown | ebb2d8d | 2012-03-23 17:14:34 -0700 | [diff] [blame] | 6342 | mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, this, null); |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6343 | mPosted = true; |
| 6344 | } |
| 6345 | } |
| 6346 | } |
| 6347 | final InvalidateOnAnimationRunnable mInvalidateOnAnimationRunnable = |
| 6348 | new InvalidateOnAnimationRunnable(); |
| 6349 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6350 | public void dispatchInvalidateDelayed(View view, long delayMilliseconds) { |
| 6351 | Message msg = mHandler.obtainMessage(MSG_INVALIDATE, view); |
| 6352 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6353 | } |
| 6354 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6355 | public void dispatchInvalidateRectDelayed(AttachInfo.InvalidateInfo info, |
| 6356 | long delayMilliseconds) { |
| 6357 | final Message msg = mHandler.obtainMessage(MSG_INVALIDATE_RECT, info); |
| 6358 | mHandler.sendMessageDelayed(msg, delayMilliseconds); |
| 6359 | } |
| 6360 | |
Jeff Brown | 6cb7b46 | 2012-03-05 13:21:17 -0800 | [diff] [blame] | 6361 | public void dispatchInvalidateOnAnimation(View view) { |
| 6362 | mInvalidateOnAnimationRunnable.addView(view); |
| 6363 | } |
| 6364 | |
| 6365 | public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) { |
| 6366 | mInvalidateOnAnimationRunnable.addViewRect(info); |
| 6367 | } |
| 6368 | |
| 6369 | public void cancelInvalidate(View view) { |
| 6370 | mHandler.removeMessages(MSG_INVALIDATE, view); |
| 6371 | // fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning |
| 6372 | // them to the pool |
| 6373 | mHandler.removeMessages(MSG_INVALIDATE_RECT, view); |
| 6374 | mInvalidateOnAnimationRunnable.removeView(view); |
| 6375 | } |
| 6376 | |
keunyoung | 30f420f | 2013-08-02 14:23:10 -0700 | [diff] [blame] | 6377 | public void dispatchInputEvent(InputEvent event) { |
Jae Seo | 6a6059a | 2014-04-17 21:35:29 -0700 | [diff] [blame] | 6378 | dispatchInputEvent(event, null); |
| 6379 | } |
| 6380 | |
| 6381 | public void dispatchInputEvent(InputEvent event, InputEventReceiver receiver) { |
| 6382 | SomeArgs args = SomeArgs.obtain(); |
| 6383 | args.arg1 = event; |
| 6384 | args.arg2 = receiver; |
| 6385 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_INPUT_EVENT, args); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6386 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6387 | mHandler.sendMessage(msg); |
| 6388 | } |
| 6389 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6390 | public void synthesizeInputEvent(InputEvent event) { |
| 6391 | Message msg = mHandler.obtainMessage(MSG_SYNTHESIZE_INPUT_EVENT, event); |
| 6392 | msg.setAsynchronous(true); |
| 6393 | mHandler.sendMessage(msg); |
| 6394 | } |
| 6395 | |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6396 | public void dispatchKeyFromIme(KeyEvent event) { |
| 6397 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_KEY_FROM_IME, event); |
Jeff Brown | e0dbd00 | 2012-02-15 19:34:58 -0800 | [diff] [blame] | 6398 | msg.setAsynchronous(true); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6399 | mHandler.sendMessage(msg); |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 6400 | } |
| 6401 | |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6402 | /** |
| 6403 | * Reinject unhandled {@link InputEvent}s in order to synthesize fallbacks events. |
| 6404 | * |
| 6405 | * Note that it is the responsibility of the caller of this API to recycle the InputEvent it |
| 6406 | * passes in. |
| 6407 | */ |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6408 | public void dispatchUnhandledInputEvent(InputEvent event) { |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6409 | if (event instanceof MotionEvent) { |
| 6410 | event = MotionEvent.obtain((MotionEvent) event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6411 | } |
Michael Wright | 899d705 | 2014-04-23 17:23:39 -0700 | [diff] [blame] | 6412 | synthesizeInputEvent(event); |
Michael Wright | 3da2834 | 2014-04-22 17:00:11 -0700 | [diff] [blame] | 6413 | } |
| 6414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | public void dispatchAppVisibility(boolean visible) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6416 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_APP_VISIBILITY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6417 | msg.arg1 = visible ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6418 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | public void dispatchGetNewSurface() { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6422 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_GET_NEW_SURFACE); |
| 6423 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
| 6427 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6428 | msg.what = MSG_WINDOW_FOCUS_CHANGED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6429 | msg.arg1 = hasFocus ? 1 : 0; |
| 6430 | msg.arg2 = inTouchMode ? 1 : 0; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6431 | mHandler.sendMessage(msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6432 | } |
| 6433 | |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 6434 | public void dispatchWindowShown() { |
| 6435 | mHandler.sendEmptyMessage(MSG_DISPATCH_WINDOW_SHOWN); |
| 6436 | } |
| 6437 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6438 | public void dispatchCloseSystemDialogs(String reason) { |
| 6439 | Message msg = Message.obtain(); |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6440 | msg.what = MSG_CLOSE_SYSTEM_DIALOGS; |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6441 | msg.obj = reason; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6442 | mHandler.sendMessage(msg); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6443 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6444 | |
| 6445 | public void dispatchDragEvent(DragEvent event) { |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6446 | final int what; |
| 6447 | if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6448 | what = MSG_DISPATCH_DRAG_LOCATION_EVENT; |
| 6449 | mHandler.removeMessages(what); |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6450 | } else { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6451 | what = MSG_DISPATCH_DRAG_EVENT; |
Chris Tate | 91e9bb3 | 2010-10-12 12:58:43 -0700 | [diff] [blame] | 6452 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6453 | Message msg = mHandler.obtainMessage(what, event); |
| 6454 | mHandler.sendMessage(msg); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6455 | } |
| 6456 | |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 6457 | public void updatePointerIcon(float x, float y) { |
| 6458 | final int what = MSG_UPDATE_POINTER_ICON; |
| 6459 | mHandler.removeMessages(what); |
| 6460 | final long now = SystemClock.uptimeMillis(); |
| 6461 | final MotionEvent event = MotionEvent.obtain( |
| 6462 | 0, now, MotionEvent.ACTION_HOVER_MOVE, x, y, 0); |
| 6463 | Message msg = mHandler.obtainMessage(what, event); |
| 6464 | mHandler.sendMessage(msg); |
| 6465 | } |
| 6466 | |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 6467 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 6468 | int localValue, int localChanges) { |
| 6469 | SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); |
| 6470 | args.seq = seq; |
| 6471 | args.globalVisibility = globalVisibility; |
| 6472 | args.localValue = localValue; |
| 6473 | args.localChanges = localChanges; |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6474 | mHandler.sendMessage(mHandler.obtainMessage(MSG_DISPATCH_SYSTEM_UI_VISIBILITY, args)); |
| 6475 | } |
| 6476 | |
| 6477 | public void dispatchCheckFocus() { |
| 6478 | if (!mHandler.hasMessages(MSG_CHECK_FOCUS)) { |
| 6479 | // This will result in a call to checkFocus() below. |
| 6480 | mHandler.sendEmptyMessage(MSG_CHECK_FOCUS); |
| 6481 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 6482 | } |
| 6483 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 6484 | public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver) { |
| 6485 | mHandler.obtainMessage(MSG_REQUEST_KEYBOARD_SHORTCUTS, receiver).sendToTarget(); |
| 6486 | } |
| 6487 | |
svetoslavganov | 75986cf | 2009-05-14 22:28:01 -0700 | [diff] [blame] | 6488 | /** |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6489 | * Post a callback to send a |
| 6490 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6491 | * This event is send at most once every |
| 6492 | * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()}. |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6493 | */ |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6494 | private void postSendWindowContentChangedCallback(View source, int changeType) { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6495 | if (mSendWindowContentChangedAccessibilityEvent == null) { |
| 6496 | mSendWindowContentChangedAccessibilityEvent = |
| 6497 | new SendWindowContentChangedAccessibilityEvent(); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6498 | } |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6499 | mSendWindowContentChangedAccessibilityEvent.runOrPost(source, changeType); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | /** |
| 6503 | * Remove a posted callback to send a |
| 6504 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. |
| 6505 | */ |
| 6506 | private void removeSendWindowContentChangedCallback() { |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 6507 | if (mSendWindowContentChangedAccessibilityEvent != null) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 6508 | mHandler.removeCallbacks(mSendWindowContentChangedAccessibilityEvent); |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 6509 | } |
| 6510 | } |
| 6511 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6512 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6513 | public boolean showContextMenuForChild(View originalView) { |
| 6514 | return false; |
| 6515 | } |
| 6516 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6517 | @Override |
Oren Blasberg | ed39126 | 2015-09-01 12:12:51 -0700 | [diff] [blame] | 6518 | public boolean showContextMenuForChild(View originalView, float x, float y) { |
| 6519 | return false; |
| 6520 | } |
| 6521 | |
| 6522 | @Override |
Adam Powell | 6e34636 | 2010-07-23 10:18:23 -0700 | [diff] [blame] | 6523 | public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) { |
| 6524 | return null; |
| 6525 | } |
| 6526 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6527 | @Override |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 6528 | public ActionMode startActionModeForChild( |
| 6529 | View originalView, ActionMode.Callback callback, int type) { |
| 6530 | return null; |
| 6531 | } |
| 6532 | |
| 6533 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6534 | public void createContextMenu(ContextMenu menu) { |
| 6535 | } |
| 6536 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6537 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6538 | public void childDrawableStateChanged(View child) { |
| 6539 | } |
| 6540 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6541 | @Override |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6542 | public boolean requestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
George Mount | 41725de | 2015-04-09 08:23:05 -0700 | [diff] [blame] | 6543 | if (mView == null || mStopped || mPausedForTransition) { |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6544 | return false; |
| 6545 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6546 | // Intercept accessibility focus events fired by virtual nodes to keep |
| 6547 | // track of accessibility focus position in such nodes. |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6548 | final int eventType = event.getEventType(); |
| 6549 | switch (eventType) { |
| 6550 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6551 | final long sourceNodeId = event.getSourceNodeId(); |
| 6552 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6553 | sourceNodeId); |
| 6554 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6555 | if (source != null) { |
| 6556 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6557 | if (provider != null) { |
Svetoslav | b3ba1d4 | 2014-09-26 15:20:40 -0700 | [diff] [blame] | 6558 | final int virtualNodeId = AccessibilityNodeInfo.getVirtualDescendantId( |
| 6559 | sourceNodeId); |
| 6560 | final AccessibilityNodeInfo node; |
| 6561 | if (virtualNodeId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6562 | node = provider.createAccessibilityNodeInfo( |
| 6563 | AccessibilityNodeProvider.HOST_VIEW_ID); |
| 6564 | } else { |
| 6565 | node = provider.createAccessibilityNodeInfo(virtualNodeId); |
| 6566 | } |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6567 | setAccessibilityFocus(source, node); |
| 6568 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6569 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6570 | } break; |
| 6571 | case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED: { |
Svetoslav Ganov | 45a02e0 | 2012-06-17 15:07:29 -0700 | [diff] [blame] | 6572 | final long sourceNodeId = event.getSourceNodeId(); |
| 6573 | final int accessibilityViewId = AccessibilityNodeInfo.getAccessibilityViewId( |
| 6574 | sourceNodeId); |
| 6575 | View source = mView.findViewByAccessibilityId(accessibilityViewId); |
| 6576 | if (source != null) { |
| 6577 | AccessibilityNodeProvider provider = source.getAccessibilityNodeProvider(); |
| 6578 | if (provider != null) { |
| 6579 | setAccessibilityFocus(null, null); |
| 6580 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6581 | } |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6582 | } break; |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6583 | |
| 6584 | |
| 6585 | case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6586 | handleWindowContentChangedEvent(event); |
Svetoslav | f0c758b | 2014-09-03 17:47:37 -0700 | [diff] [blame] | 6587 | } break; |
Svetoslav Ganov | 791fd31 | 2012-05-14 15:12:30 -0700 | [diff] [blame] | 6588 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6589 | mAccessibilityManager.sendAccessibilityEvent(event); |
Svetoslav Ganov | 736c275 | 2011-04-22 18:30:36 -0700 | [diff] [blame] | 6590 | return true; |
| 6591 | } |
| 6592 | |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6593 | /** |
| 6594 | * Updates the focused virtual view, when necessary, in response to a |
| 6595 | * content changed event. |
| 6596 | * <p> |
| 6597 | * This is necessary to get updated bounds after a position change. |
| 6598 | * |
| 6599 | * @param event an accessibility event of type |
| 6600 | * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} |
| 6601 | */ |
| 6602 | private void handleWindowContentChangedEvent(AccessibilityEvent event) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6603 | final View focusedHost = mAccessibilityFocusedHost; |
| 6604 | if (focusedHost == null || mAccessibilityFocusedVirtualView == null) { |
| 6605 | // No virtual view focused, nothing to do here. |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6606 | return; |
| 6607 | } |
| 6608 | |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6609 | final AccessibilityNodeProvider provider = focusedHost.getAccessibilityNodeProvider(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6610 | if (provider == null) { |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6611 | // Error state: virtual view with no provider. Clear focus. |
| 6612 | mAccessibilityFocusedHost = null; |
| 6613 | mAccessibilityFocusedVirtualView = null; |
| 6614 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6615 | return; |
| 6616 | } |
| 6617 | |
| 6618 | // We only care about change types that may affect the bounds of the |
| 6619 | // focused virtual view. |
| 6620 | final int changes = event.getContentChangeTypes(); |
| 6621 | if ((changes & AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE) == 0 |
| 6622 | && changes != AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED) { |
| 6623 | return; |
| 6624 | } |
| 6625 | |
| 6626 | final long eventSourceNodeId = event.getSourceNodeId(); |
| 6627 | final int changedViewId = AccessibilityNodeInfo.getAccessibilityViewId(eventSourceNodeId); |
| 6628 | |
| 6629 | // Search up the tree for subtree containment. |
| 6630 | boolean hostInSubtree = false; |
| 6631 | View root = mAccessibilityFocusedHost; |
| 6632 | while (root != null && !hostInSubtree) { |
| 6633 | if (changedViewId == root.getAccessibilityViewId()) { |
| 6634 | hostInSubtree = true; |
| 6635 | } else { |
| 6636 | final ViewParent parent = root.getParent(); |
| 6637 | if (parent instanceof View) { |
| 6638 | root = (View) parent; |
| 6639 | } else { |
| 6640 | root = null; |
| 6641 | } |
| 6642 | } |
| 6643 | } |
| 6644 | |
| 6645 | // We care only about changes in subtrees containing the host view. |
| 6646 | if (!hostInSubtree) { |
| 6647 | return; |
| 6648 | } |
| 6649 | |
| 6650 | final long focusedSourceNodeId = mAccessibilityFocusedVirtualView.getSourceNodeId(); |
| 6651 | int focusedChildId = AccessibilityNodeInfo.getVirtualDescendantId(focusedSourceNodeId); |
| 6652 | if (focusedChildId == AccessibilityNodeInfo.UNDEFINED_ITEM_ID) { |
| 6653 | // TODO: Should we clear the focused virtual view? |
| 6654 | focusedChildId = AccessibilityNodeProvider.HOST_VIEW_ID; |
| 6655 | } |
| 6656 | |
| 6657 | // Refresh the node for the focused virtual view. |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6658 | final Rect oldBounds = mTempRect; |
| 6659 | mAccessibilityFocusedVirtualView.getBoundsInScreen(oldBounds); |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6660 | mAccessibilityFocusedVirtualView = provider.createAccessibilityNodeInfo(focusedChildId); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6661 | if (mAccessibilityFocusedVirtualView == null) { |
| 6662 | // Error state: The node no longer exists. Clear focus. |
| 6663 | mAccessibilityFocusedHost = null; |
| 6664 | focusedHost.clearAccessibilityFocusNoCallbacks(); |
| 6665 | |
| 6666 | // This will probably fail, but try to keep the provider's internal |
| 6667 | // state consistent by clearing focus. |
| 6668 | provider.performAction(focusedChildId, |
| 6669 | AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS.getId(), null); |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6670 | invalidateRectOnScreen(oldBounds); |
Alan Viverette | 25acc7e | 2015-05-19 11:32:08 -0700 | [diff] [blame] | 6671 | } else { |
| 6672 | // The node was refreshed, invalidate bounds if necessary. |
| 6673 | final Rect newBounds = mAccessibilityFocusedVirtualView.getBoundsInScreen(); |
| 6674 | if (!oldBounds.equals(newBounds)) { |
| 6675 | oldBounds.union(newBounds); |
| 6676 | invalidateRectOnScreen(oldBounds); |
| 6677 | } |
Alan Viverette | a7ea65e | 2015-05-15 11:30:21 -0700 | [diff] [blame] | 6678 | } |
Alan Viverette | 34457f5 | 2015-03-25 13:09:20 -0700 | [diff] [blame] | 6679 | } |
| 6680 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6681 | @Override |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 6682 | public void notifySubtreeAccessibilityStateChanged(View child, View source, int changeType) { |
| 6683 | postSendWindowContentChangedCallback(source, changeType); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6684 | } |
| 6685 | |
Fabrice Di Meglio | 9dd4c5c | 2013-02-08 18:15:07 -0800 | [diff] [blame] | 6686 | @Override |
| 6687 | public boolean canResolveLayoutDirection() { |
| 6688 | return true; |
| 6689 | } |
| 6690 | |
| 6691 | @Override |
| 6692 | public boolean isLayoutDirectionResolved() { |
| 6693 | return true; |
| 6694 | } |
| 6695 | |
| 6696 | @Override |
| 6697 | public int getLayoutDirection() { |
| 6698 | return View.LAYOUT_DIRECTION_RESOLVED_DEFAULT; |
| 6699 | } |
| 6700 | |
| 6701 | @Override |
| 6702 | public boolean canResolveTextDirection() { |
| 6703 | return true; |
| 6704 | } |
| 6705 | |
| 6706 | @Override |
| 6707 | public boolean isTextDirectionResolved() { |
| 6708 | return true; |
| 6709 | } |
| 6710 | |
| 6711 | @Override |
| 6712 | public int getTextDirection() { |
| 6713 | return View.TEXT_DIRECTION_RESOLVED_DEFAULT; |
| 6714 | } |
| 6715 | |
| 6716 | @Override |
| 6717 | public boolean canResolveTextAlignment() { |
| 6718 | return true; |
| 6719 | } |
| 6720 | |
| 6721 | @Override |
| 6722 | public boolean isTextAlignmentResolved() { |
| 6723 | return true; |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
| 6727 | public int getTextAlignment() { |
| 6728 | return View.TEXT_ALIGNMENT_RESOLVED_DEFAULT; |
| 6729 | } |
| 6730 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6731 | private View getCommonPredecessor(View first, View second) { |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6732 | if (mTempHashSet == null) { |
| 6733 | mTempHashSet = new HashSet<View>(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6734 | } |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 6735 | HashSet<View> seen = mTempHashSet; |
| 6736 | seen.clear(); |
| 6737 | View firstCurrent = first; |
| 6738 | while (firstCurrent != null) { |
| 6739 | seen.add(firstCurrent); |
| 6740 | ViewParent firstCurrentParent = firstCurrent.mParent; |
| 6741 | if (firstCurrentParent instanceof View) { |
| 6742 | firstCurrent = (View) firstCurrentParent; |
| 6743 | } else { |
| 6744 | firstCurrent = null; |
| 6745 | } |
| 6746 | } |
| 6747 | View secondCurrent = second; |
| 6748 | while (secondCurrent != null) { |
| 6749 | if (seen.contains(secondCurrent)) { |
| 6750 | seen.clear(); |
| 6751 | return secondCurrent; |
| 6752 | } |
| 6753 | ViewParent secondCurrentParent = secondCurrent.mParent; |
| 6754 | if (secondCurrentParent instanceof View) { |
| 6755 | secondCurrent = (View) secondCurrentParent; |
| 6756 | } else { |
| 6757 | secondCurrent = null; |
| 6758 | } |
| 6759 | } |
| 6760 | seen.clear(); |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 6761 | return null; |
| 6762 | } |
| 6763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | void checkThread() { |
| 6765 | if (mThread != Thread.currentThread()) { |
| 6766 | throw new CalledFromWrongThreadException( |
| 6767 | "Only the original thread that created a view hierarchy can touch its views."); |
| 6768 | } |
| 6769 | } |
| 6770 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6771 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 6773 | // 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] | 6774 | } |
| 6775 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6776 | @Override |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6777 | public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) { |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6778 | if (rectangle == null) { |
| 6779 | return scrollToRectOrFocus(null, immediate); |
| 6780 | } |
| 6781 | rectangle.offset(child.getLeft() - child.getScrollX(), |
| 6782 | child.getTop() - child.getScrollY()); |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6783 | final boolean scrolled = scrollToRectOrFocus(rectangle, immediate); |
Yigit Boyar | d62d5e9 | 2016-01-19 18:56:20 -0800 | [diff] [blame] | 6784 | mTempRect.set(rectangle); |
| 6785 | mTempRect.offset(0, -mCurScrollY); |
| 6786 | mTempRect.offset(mAttachInfo.mWindowLeft, mAttachInfo.mWindowTop); |
| 6787 | try { |
| 6788 | mWindowSession.onRectangleOnScreenRequested(mWindow, mTempRect); |
| 6789 | } catch (RemoteException re) { |
| 6790 | /* ignore */ |
Svetoslav Ganov | 1cf70bb | 2012-08-06 10:53:34 -0700 | [diff] [blame] | 6791 | } |
| 6792 | return scrolled; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6793 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6794 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6795 | @Override |
Adam Powell | 539ee87 | 2012-02-03 19:00:49 -0800 | [diff] [blame] | 6796 | public void childHasTransientStateChanged(View child, boolean hasTransientState) { |
| 6797 | // Do nothing. |
| 6798 | } |
| 6799 | |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6800 | @Override |
| 6801 | public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { |
| 6802 | return false; |
| 6803 | } |
| 6804 | |
| 6805 | @Override |
| 6806 | public void onStopNestedScroll(View target) { |
| 6807 | } |
| 6808 | |
| 6809 | @Override |
| 6810 | public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) { |
| 6811 | } |
| 6812 | |
| 6813 | @Override |
| 6814 | public void onNestedScroll(View target, int dxConsumed, int dyConsumed, |
| 6815 | int dxUnconsumed, int dyUnconsumed) { |
| 6816 | } |
| 6817 | |
| 6818 | @Override |
| 6819 | public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) { |
| 6820 | } |
| 6821 | |
| 6822 | @Override |
Adam Powell | b36e4f9 | 2014-05-01 10:23:33 -0700 | [diff] [blame] | 6823 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { |
Adam Powell | 10ba277 | 2014-04-15 09:46:51 -0700 | [diff] [blame] | 6824 | return false; |
| 6825 | } |
| 6826 | |
Adam Powell | b72be59 | 2014-07-16 21:41:31 -0700 | [diff] [blame] | 6827 | @Override |
| 6828 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { |
| 6829 | return false; |
| 6830 | } |
| 6831 | |
Adam Powell | b6ab098 | 2015-01-07 17:00:12 -0800 | [diff] [blame] | 6832 | @Override |
| 6833 | public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle args) { |
| 6834 | return false; |
| 6835 | } |
| 6836 | |
Jorim Jaggi | b774e55 | 2015-08-24 14:52:45 -0700 | [diff] [blame] | 6837 | /** |
| 6838 | * Force the window to report its next draw. |
| 6839 | * <p> |
| 6840 | * This method is only supposed to be used to speed up the interaction from SystemUI and window |
| 6841 | * manager when waiting for the first frame to be drawn when turning on the screen. DO NOT USE |
| 6842 | * unless you fully understand this interaction. |
| 6843 | * @hide |
| 6844 | */ |
| 6845 | public void setReportNextDraw() { |
| 6846 | mReportNextDraw = true; |
| 6847 | invalidate(); |
| 6848 | } |
| 6849 | |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6850 | void changeCanvasOpacity(boolean opaque) { |
Filip Gruszczynski | 34dab0b | 2015-12-22 08:29:07 -0800 | [diff] [blame] | 6851 | Log.d(mTag, "changeCanvasOpacity: opaque=" + opaque); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 6852 | if (mAttachInfo.mHardwareRenderer != null) { |
| 6853 | mAttachInfo.mHardwareRenderer.setOpaque(opaque); |
| 6854 | } |
Craig Mautner | bc57cd1 | 2013-08-19 15:47:42 -0700 | [diff] [blame] | 6855 | } |
| 6856 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6857 | class TakenSurfaceHolder extends BaseSurfaceHolder { |
| 6858 | @Override |
| 6859 | public boolean onAllowLockCanvas() { |
| 6860 | return mDrawingAllowed; |
| 6861 | } |
| 6862 | |
| 6863 | @Override |
| 6864 | public void onRelayoutContainer() { |
| 6865 | // Not currently interesting -- from changing between fixed and layout size. |
| 6866 | } |
| 6867 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6868 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6869 | public void setFormat(int format) { |
| 6870 | ((RootViewSurfaceTaker)mView).setSurfaceFormat(format); |
| 6871 | } |
| 6872 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6873 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6874 | public void setType(int type) { |
| 6875 | ((RootViewSurfaceTaker)mView).setSurfaceType(type); |
| 6876 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6877 | |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6878 | @Override |
| 6879 | public void onUpdateSurface() { |
| 6880 | // We take care of format and type changes on our own. |
| 6881 | throw new IllegalStateException("Shouldn't be here"); |
| 6882 | } |
| 6883 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6884 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6885 | public boolean isCreating() { |
| 6886 | return mIsCreating; |
| 6887 | } |
| 6888 | |
| 6889 | @Override |
| 6890 | public void setFixedSize(int width, int height) { |
| 6891 | throw new UnsupportedOperationException( |
| 6892 | "Currently only support sizing from layout"); |
| 6893 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6894 | |
| 6895 | @Override |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 6896 | public void setKeepScreenOn(boolean screenOn) { |
| 6897 | ((RootViewSurfaceTaker)mView).setSurfaceKeepScreenOn(screenOn); |
| 6898 | } |
| 6899 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 6900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | static class W extends IWindow.Stub { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6902 | private final WeakReference<ViewRootImpl> mViewAncestor; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6903 | private final IWindowSession mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6905 | W(ViewRootImpl viewAncestor) { |
| 6906 | mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor); |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 6907 | mWindowSession = viewAncestor.mWindowSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | } |
| 6909 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6910 | @Override |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6911 | public void resized(Rect frame, Rect overscanInsets, Rect contentInsets, |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 6912 | Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6913 | Configuration newConfig, Rect backDropFrame, boolean forceLayout, |
| 6914 | boolean alwaysConsumeNavBar) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6915 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6916 | if (viewAncestor != null) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 6917 | viewAncestor.dispatchResized(frame, overscanInsets, contentInsets, |
Jorim Jaggi | a4a58ef | 2016-01-27 02:10:08 -0800 | [diff] [blame] | 6918 | visibleInsets, stableInsets, outsets, reportDraw, newConfig, backDropFrame, |
Jorim Jaggi | 0ffd49c | 2016-02-12 15:04:21 -0800 | [diff] [blame] | 6919 | forceLayout, alwaysConsumeNavBar); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6920 | } |
| 6921 | } |
| 6922 | |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 6923 | @Override |
| 6924 | public void moved(int newX, int newY) { |
| 6925 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 6926 | if (viewAncestor != null) { |
| 6927 | viewAncestor.dispatchMoved(newX, newY); |
| 6928 | } |
| 6929 | } |
| 6930 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6931 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6932 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6933 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6934 | if (viewAncestor != null) { |
| 6935 | viewAncestor.dispatchAppVisibility(visible); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | } |
| 6937 | } |
| 6938 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6939 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6940 | public void dispatchGetNewSurface() { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6941 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6942 | if (viewAncestor != null) { |
| 6943 | viewAncestor.dispatchGetNewSurface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6944 | } |
| 6945 | } |
| 6946 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6947 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | public void windowFocusChanged(boolean hasFocus, boolean inTouchMode) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6949 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6950 | if (viewAncestor != null) { |
| 6951 | viewAncestor.windowFocusChanged(hasFocus, inTouchMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | } |
| 6953 | } |
| 6954 | |
| 6955 | private static int checkCallingPermission(String permission) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | try { |
| 6957 | return ActivityManagerNative.getDefault().checkPermission( |
| 6958 | permission, Binder.getCallingPid(), Binder.getCallingUid()); |
| 6959 | } catch (RemoteException e) { |
| 6960 | return PackageManager.PERMISSION_DENIED; |
| 6961 | } |
| 6962 | } |
| 6963 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6964 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6965 | public void executeCommand(String command, String parameters, ParcelFileDescriptor out) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6966 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6967 | if (viewAncestor != null) { |
| 6968 | final View view = viewAncestor.mView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | if (view != null) { |
| 6970 | if (checkCallingPermission(Manifest.permission.DUMP) != |
| 6971 | PackageManager.PERMISSION_GRANTED) { |
| 6972 | throw new SecurityException("Insufficient permissions to invoke" |
| 6973 | + " executeCommand() from pid=" + Binder.getCallingPid() |
| 6974 | + ", uid=" + Binder.getCallingUid()); |
| 6975 | } |
| 6976 | |
| 6977 | OutputStream clientStream = null; |
| 6978 | try { |
| 6979 | clientStream = new ParcelFileDescriptor.AutoCloseOutputStream(out); |
| 6980 | ViewDebug.dispatchCommand(view, command, parameters, clientStream); |
| 6981 | } catch (IOException e) { |
| 6982 | e.printStackTrace(); |
| 6983 | } finally { |
| 6984 | if (clientStream != null) { |
| 6985 | try { |
| 6986 | clientStream.close(); |
| 6987 | } catch (IOException e) { |
| 6988 | e.printStackTrace(); |
| 6989 | } |
| 6990 | } |
| 6991 | } |
| 6992 | } |
| 6993 | } |
| 6994 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 6995 | |
| 6996 | @Override |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 6997 | public void closeSystemDialogs(String reason) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 6998 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 6999 | if (viewAncestor != null) { |
| 7000 | viewAncestor.dispatchCloseSystemDialogs(reason); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 7001 | } |
| 7002 | } |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7003 | |
| 7004 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7005 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 7006 | boolean sync) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7007 | if (sync) { |
| 7008 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7009 | mWindowSession.wallpaperOffsetsComplete(asBinder()); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7010 | } catch (RemoteException e) { |
| 7011 | } |
| 7012 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7013 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7014 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7015 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7016 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 7017 | int z, Bundle extras, boolean sync) { |
| 7018 | if (sync) { |
| 7019 | try { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 7020 | mWindowSession.wallpaperCommandComplete(asBinder(), null); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 7021 | } catch (RemoteException e) { |
| 7022 | } |
| 7023 | } |
| 7024 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7025 | |
| 7026 | /* Drag/drop */ |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7027 | @Override |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7028 | public void dispatchDragEvent(DragEvent event) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7029 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7030 | if (viewAncestor != null) { |
| 7031 | viewAncestor.dispatchDragEvent(event); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7032 | } |
| 7033 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7034 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7035 | @Override |
Vladislav Kaznacheev | ec6a447 | 2016-01-22 12:21:52 -0800 | [diff] [blame] | 7036 | public void updatePointerIcon(float x, float y) { |
| 7037 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7038 | if (viewAncestor != null) { |
| 7039 | viewAncestor.updatePointerIcon(x, y); |
| 7040 | } |
| 7041 | } |
| 7042 | |
| 7043 | @Override |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7044 | public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, |
| 7045 | int localValue, int localChanges) { |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 7046 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7047 | if (viewAncestor != null) { |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 7048 | viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, |
| 7049 | localValue, localChanges); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 7050 | } |
| 7051 | } |
Dianne Hackborn | 12d3a94 | 2012-04-27 14:16:30 -0700 | [diff] [blame] | 7052 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7053 | @Override |
Craig Mautner | 9c79504 | 2014-10-28 19:59:59 -0700 | [diff] [blame] | 7054 | public void dispatchWindowShown() { |
| 7055 | final ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7056 | if (viewAncestor != null) { |
| 7057 | viewAncestor.dispatchWindowShown(); |
| 7058 | } |
| 7059 | } |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 7060 | |
| 7061 | @Override |
| 7062 | public void requestAppKeyboardShortcuts(IResultReceiver receiver) { |
| 7063 | ViewRootImpl viewAncestor = mViewAncestor.get(); |
| 7064 | if (viewAncestor != null) { |
| 7065 | viewAncestor.dispatchRequestKeyboardShortcuts(receiver); |
| 7066 | } |
| 7067 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7068 | } |
| 7069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | public static final class CalledFromWrongThreadException extends AndroidRuntimeException { |
| 7071 | public CalledFromWrongThreadException(String msg) { |
| 7072 | super(msg); |
| 7073 | } |
| 7074 | } |
| 7075 | |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7076 | static HandlerActionQueue getRunQueue() { |
| 7077 | HandlerActionQueue rq = sRunQueues.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | if (rq != null) { |
| 7079 | return rq; |
| 7080 | } |
Alan Viverette | bea0c7da | 2015-09-01 16:00:20 -0400 | [diff] [blame] | 7081 | rq = new HandlerActionQueue(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7082 | sRunQueues.set(rq); |
| 7083 | return rq; |
| 7084 | } |
Romain Guy | 8506ab4 | 2009-06-11 17:35:47 -0700 | [diff] [blame] | 7085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | /** |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7087 | * Start a drag resizing which will inform all listeners that a window resize is taking place. |
| 7088 | */ |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7089 | private void startDragResizing(Rect initialBounds, boolean fullscreen, Rect systemInsets, |
| 7090 | Rect stableInsets) { |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7091 | if (!mDragResizing) { |
| 7092 | mDragResizing = true; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7093 | synchronized (mWindowCallbacks) { |
| 7094 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
Jorim Jaggi | 9511b0f | 2016-01-29 19:12:44 -0800 | [diff] [blame] | 7095 | mWindowCallbacks.get(i).onWindowDragResizeStart(initialBounds, fullscreen, |
| 7096 | systemInsets, stableInsets); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7097 | } |
| 7098 | } |
| 7099 | mFullRedrawNeeded = true; |
| 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | /** |
| 7104 | * End a drag resize which will inform all listeners that a window resize has ended. |
| 7105 | */ |
| 7106 | private void endDragResizing() { |
| 7107 | if (mDragResizing) { |
| 7108 | mDragResizing = false; |
Chong Zhang | dcee1de | 2015-10-06 10:26:00 -0700 | [diff] [blame] | 7109 | synchronized (mWindowCallbacks) { |
| 7110 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7111 | mWindowCallbacks.get(i).onWindowDragResizeEnd(); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7112 | } |
| 7113 | } |
| 7114 | mFullRedrawNeeded = true; |
| 7115 | } |
| 7116 | } |
| 7117 | |
Chong Zhang | 8dbd9ad | 2015-10-09 10:06:11 -0700 | [diff] [blame] | 7118 | private boolean updateContentDrawBounds() { |
| 7119 | boolean updated = false; |
| 7120 | synchronized (mWindowCallbacks) { |
| 7121 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7122 | updated |= mWindowCallbacks.get(i).onContentDrawn( |
| 7123 | mWindowAttributes.surfaceInsets.left, |
| 7124 | mWindowAttributes.surfaceInsets.top, |
| 7125 | mWidth, mHeight); |
| 7126 | } |
| 7127 | } |
| 7128 | return updated | (mDragResizing && mReportNextDraw); |
| 7129 | } |
| 7130 | |
| 7131 | private void requestDrawWindow() { |
| 7132 | if (mReportNextDraw) { |
| 7133 | mWindowDrawCountDown = new CountDownLatch(mWindowCallbacks.size()); |
| 7134 | } |
| 7135 | synchronized (mWindowCallbacks) { |
| 7136 | for (int i = mWindowCallbacks.size() - 1; i >= 0; i--) { |
| 7137 | mWindowCallbacks.get(i).onRequestDraw(mReportNextDraw); |
| 7138 | } |
| 7139 | } |
| 7140 | } |
| 7141 | |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 7142 | /** |
Jorim Jaggi | 4846ee3 | 2016-01-07 17:39:12 +0100 | [diff] [blame] | 7143 | * Tells this instance that its corresponding activity has just relaunched. In this case, we |
| 7144 | * need to force a relayout of the window to make sure we get the correct bounds from window |
| 7145 | * manager. |
| 7146 | */ |
| 7147 | public void reportActivityRelaunched() { |
| 7148 | mActivityRelaunched = true; |
| 7149 | } |
| 7150 | |
| 7151 | /** |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7152 | * Class for managing the accessibility interaction connection |
| 7153 | * based on the global accessibility state. |
| 7154 | */ |
| 7155 | final class AccessibilityInteractionConnectionManager |
| 7156 | implements AccessibilityStateChangeListener { |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7157 | @Override |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7158 | public void onAccessibilityStateChanged(boolean enabled) { |
| 7159 | if (enabled) { |
| 7160 | ensureConnection(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7161 | if (mAttachInfo.mHasWindowFocus) { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7162 | mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 7163 | View focusedView = mView.findFocus(); |
| 7164 | if (focusedView != null && focusedView != mView) { |
| 7165 | focusedView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); |
| 7166 | } |
| 7167 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7168 | } else { |
| 7169 | ensureNoConnection(); |
Svetoslav Ganov | 005b83b | 2012-04-16 18:17:17 -0700 | [diff] [blame] | 7170 | mHandler.obtainMessage(MSG_CLEAR_ACCESSIBILITY_FOCUS_HOST).sendToTarget(); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | public void ensureConnection() { |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7175 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7176 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7177 | if (!registered) { |
| 7178 | mAttachInfo.mAccessibilityWindowId = |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7179 | mAccessibilityManager.addAccessibilityInteractionConnection(mWindow, |
| 7180 | new AccessibilityInteractionConnection(ViewRootImpl.this)); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7181 | } |
| 7182 | } |
| 7183 | |
| 7184 | public void ensureNoConnection() { |
Svetoslav Ganov | 0d04e24 | 2012-02-21 13:46:36 -0800 | [diff] [blame] | 7185 | final boolean registered = |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7186 | mAttachInfo.mAccessibilityWindowId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7187 | if (registered) { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 7188 | mAttachInfo.mAccessibilityWindowId = AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7189 | mAccessibilityManager.removeAccessibilityInteractionConnection(mWindow); |
| 7190 | } |
| 7191 | } |
| 7192 | } |
| 7193 | |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7194 | final class HighContrastTextManager implements HighTextContrastChangeListener { |
| 7195 | HighContrastTextManager() { |
| 7196 | mAttachInfo.mHighContrastText = mAccessibilityManager.isHighTextContrastEnabled(); |
| 7197 | } |
| 7198 | @Override |
| 7199 | public void onHighTextContrastStateChanged(boolean enabled) { |
| 7200 | mAttachInfo.mHighContrastText = enabled; |
| 7201 | |
| 7202 | // Destroy Displaylists so they can be recreated with high contrast recordings |
| 7203 | destroyHardwareResources(); |
Chris Craik | d36a81f | 2014-07-17 10:16:51 -0700 | [diff] [blame] | 7204 | |
| 7205 | // Schedule redraw, which will rerecord + redraw all text |
| 7206 | invalidate(); |
Chris Craik | cce47eb | 2014-07-16 15:12:15 -0700 | [diff] [blame] | 7207 | } |
| 7208 | } |
| 7209 | |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7210 | /** |
| 7211 | * This class is an interface this ViewAncestor provides to the |
| 7212 | * AccessibilityManagerService to the latter can interact with |
| 7213 | * the view hierarchy in this ViewAncestor. |
| 7214 | */ |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7215 | static final class AccessibilityInteractionConnection |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7216 | extends IAccessibilityInteractionConnection.Stub { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7217 | private final WeakReference<ViewRootImpl> mViewRootImpl; |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7218 | |
Svetoslav Ganov | f79f476 | 2011-10-28 15:40:32 -0700 | [diff] [blame] | 7219 | AccessibilityInteractionConnection(ViewRootImpl viewRootImpl) { |
| 7220 | mViewRootImpl = new WeakReference<ViewRootImpl>(viewRootImpl); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7221 | } |
| 7222 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7223 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7224 | public void findAccessibilityNodeInfoByAccessibilityId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7225 | Region interactiveRegion, int interactionId, |
| 7226 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7227 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7228 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7229 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7230 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7231 | .findAccessibilityNodeInfoByAccessibilityIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7232 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7233 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7234 | } else { |
| 7235 | // We cannot make the call and notify the caller so it does not wait. |
| 7236 | try { |
| 7237 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7238 | } catch (RemoteException re) { |
| 7239 | /* best effort - ignore */ |
| 7240 | } |
Svetoslav Ganov | 601ad80 | 2011-06-09 14:47:38 -0700 | [diff] [blame] | 7241 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7242 | } |
| 7243 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7244 | @Override |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7245 | public void performAccessibilityAction(long accessibilityNodeId, int action, |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7246 | Bundle arguments, int interactionId, |
| 7247 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7248 | int interrogatingPid, long interrogatingTid) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7249 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7250 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7251 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | aa780c1 | 2012-04-19 23:01:39 -0700 | [diff] [blame] | 7252 | .performAccessibilityActionClientThread(accessibilityNodeId, action, arguments, |
Svet Ganov | 7498efd | 2014-09-03 21:33:00 -0700 | [diff] [blame] | 7253 | interactionId, callback, flags, interrogatingPid, interrogatingTid); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7254 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7255 | // 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] | 7256 | try { |
| 7257 | callback.setPerformAccessibilityActionResult(false, interactionId); |
| 7258 | } catch (RemoteException re) { |
| 7259 | /* best effort - ignore */ |
| 7260 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7261 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7262 | } |
| 7263 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7264 | @Override |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7265 | public void findAccessibilityNodeInfosByViewId(long accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7266 | String viewId, Region interactiveRegion, int interactionId, |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7267 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7268 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 0210785 | 2011-10-03 17:06:56 -0700 | [diff] [blame] | 7269 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7270 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
Svetoslav Ganov | af5b4f4 | 2011-10-28 12:41:38 -0700 | [diff] [blame] | 7271 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 7272 | .findAccessibilityNodeInfosByViewIdClientThread(accessibilityNodeId, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7273 | viewId, interactiveRegion, interactionId, callback, flags, |
| 7274 | interrogatingPid, interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7275 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7276 | // 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] | 7277 | try { |
| 7278 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
| 7279 | } catch (RemoteException re) { |
| 7280 | /* best effort - ignore */ |
| 7281 | } |
| 7282 | } |
| 7283 | } |
| 7284 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7285 | @Override |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7286 | public void findAccessibilityNodeInfosByText(long accessibilityNodeId, String text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7287 | Region interactiveRegion, int interactionId, |
| 7288 | IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7289 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7290 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7291 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7292 | viewRootImpl.getAccessibilityInteractionController() |
| 7293 | .findAccessibilityNodeInfosByTextClientThread(accessibilityNodeId, text, |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7294 | interactiveRegion, interactionId, callback, flags, interrogatingPid, |
| 7295 | interrogatingTid, spec); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7296 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7297 | // 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] | 7298 | try { |
| 7299 | callback.setFindAccessibilityNodeInfosResult(null, interactionId); |
| 7300 | } catch (RemoteException re) { |
| 7301 | /* best effort - ignore */ |
| 7302 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7303 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7304 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7305 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7306 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7307 | public void findFocus(long accessibilityNodeId, int focusType, Region interactiveRegion, |
| 7308 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7309 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7310 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7311 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7312 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7313 | .findFocusClientThread(accessibilityNodeId, focusType, interactiveRegion, |
| 7314 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7315 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7316 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7317 | // 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] | 7318 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7319 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7320 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7321 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7322 | } |
| 7323 | } |
| 7324 | } |
| 7325 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7326 | @Override |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7327 | public void focusSearch(long accessibilityNodeId, int direction, Region interactiveRegion, |
| 7328 | int interactionId, IAccessibilityInteractionConnectionCallback callback, int flags, |
Svetoslav Ganov | 152e9bb | 2012-10-12 20:15:29 -0700 | [diff] [blame] | 7329 | int interrogatingPid, long interrogatingTid, MagnificationSpec spec) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7330 | ViewRootImpl viewRootImpl = mViewRootImpl.get(); |
| 7331 | if (viewRootImpl != null && viewRootImpl.mView != null) { |
| 7332 | viewRootImpl.getAccessibilityInteractionController() |
Svetoslav | 9ae9ed2 | 2014-09-02 16:36:35 -0700 | [diff] [blame] | 7333 | .focusSearchClientThread(accessibilityNodeId, direction, interactiveRegion, |
| 7334 | interactionId, callback, flags, interrogatingPid, interrogatingTid, |
| 7335 | spec); |
Svetoslav Ganov | 8bd6961 | 2011-08-23 13:40:30 -0700 | [diff] [blame] | 7336 | } else { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7337 | // 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] | 7338 | try { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7339 | callback.setFindAccessibilityNodeInfoResult(null, interactionId); |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7340 | } catch (RemoteException re) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7341 | /* best effort - ignore */ |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7342 | } |
| 7343 | } |
| 7344 | } |
Svetoslav Ganov | 8643aa0 | 2011-04-20 12:12:33 -0700 | [diff] [blame] | 7345 | } |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7346 | |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7347 | private class SendWindowContentChangedAccessibilityEvent implements Runnable { |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7348 | private int mChangeTypes = 0; |
| 7349 | |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7350 | public View mSource; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7351 | public long mLastEventTimeMillis; |
Svetoslav Ganov | a015617 | 2011-06-26 17:55:44 -0700 | [diff] [blame] | 7352 | |
Igor Murashkin | a86ab640 | 2013-08-30 12:58:36 -0700 | [diff] [blame] | 7353 | @Override |
Svetoslav Ganov | eeee4d2 | 2011-06-10 20:51:30 -0700 | [diff] [blame] | 7354 | public void run() { |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7355 | // The accessibility may be turned off while we were waiting so check again. |
| 7356 | if (AccessibilityManager.getInstance(mContext).isEnabled()) { |
| 7357 | mLastEventTimeMillis = SystemClock.uptimeMillis(); |
| 7358 | AccessibilityEvent event = AccessibilityEvent.obtain(); |
| 7359 | event.setEventType(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7360 | event.setContentChangeTypes(mChangeTypes); |
Svetoslav | 8d820ecf | 2013-07-15 17:12:41 -0700 | [diff] [blame] | 7361 | mSource.sendAccessibilityEventUnchecked(event); |
| 7362 | } else { |
| 7363 | mLastEventTimeMillis = 0; |
| 7364 | } |
| 7365 | // In any case reset to initial state. |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7366 | mSource.resetSubtreeAccessibilityStateChanged(); |
| 7367 | mSource = null; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7368 | mChangeTypes = 0; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7369 | } |
| 7370 | |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7371 | public void runOrPost(View source, int changeType) { |
Svetoslav Ganov | 4213804 | 2012-03-20 11:51:39 -0700 | [diff] [blame] | 7372 | if (mSource != null) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7373 | // If there is no common predecessor, then mSource points to |
| 7374 | // a removed view, hence in this case always prefer the source. |
| 7375 | View predecessor = getCommonPredecessor(mSource, source); |
| 7376 | mSource = (predecessor != null) ? predecessor : source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7377 | mChangeTypes |= changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7378 | return; |
| 7379 | } |
| 7380 | mSource = source; |
Alan Viverette | 77e9a28 | 2013-09-12 17:16:09 -0700 | [diff] [blame] | 7381 | mChangeTypes = changeType; |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7382 | final long timeSinceLastMillis = SystemClock.uptimeMillis() - mLastEventTimeMillis; |
| 7383 | final long minEventIntevalMillis = |
| 7384 | ViewConfiguration.getSendRecurringAccessibilityEventsInterval(); |
| 7385 | if (timeSinceLastMillis >= minEventIntevalMillis) { |
Svetoslav | 9dafebb | 2013-06-18 16:29:25 -0700 | [diff] [blame] | 7386 | mSource.removeCallbacks(this); |
Svetoslav | 6254f48 | 2013-06-04 17:22:14 -0700 | [diff] [blame] | 7387 | run(); |
| 7388 | } else { |
| 7389 | mSource.postDelayed(this, minEventIntevalMillis - timeSinceLastMillis); |
Svetoslav Ganov | 79311c4 | 2012-01-17 20:24:26 -0800 | [diff] [blame] | 7390 | } |
| 7391 | } |
| 7392 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | } |