2828import android .view .MotionEvent ;
2929import android .view .View ;
3030import android .view .ViewGroup ;
31+ import android .view .ViewParent ;
3132import android .view .accessibility .AccessibilityEvent ;
3233
3334import android .widget .FrameLayout ;
5758final class EmojiPageKeyboardView extends KeyboardView implements
5859 MoreKeysPanel .Controller {
5960 private static final String TAG = "EmojiPageKeyboardView" ;
60- private static final boolean LOG = true ;
61+ private static final boolean LOG = false ;
6162 private static final long KEY_PRESS_DELAY_TIME = 250 ; // msec
6263 private static final long KEY_RELEASE_DELAY_TIME = 30 ; // msec
6364
@@ -121,13 +122,7 @@ public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
121122 mMoreKeysPlacerView .setLayerType (LAYER_TYPE_HARDWARE , layerPaint );
122123 }
123124
124- @ Override
125- protected void onAttachedToWindow () {
126- super .onAttachedToWindow ();
127- installMoreKeysPlacerView ();
128- }
129-
130- private void installMoreKeysPlacerView () {
125+ private void installMoreKeysPlacerView (final boolean uninstall ) {
131126 final View rootView = getRootView ();
132127 if (rootView == null ) {
133128 Log .w (TAG , "Cannot find root view" );
@@ -140,30 +135,11 @@ private void installMoreKeysPlacerView() {
140135 return ;
141136 }
142137
143- windowContentView .addView (mMoreKeysPlacerView );
144- }
145-
146- @ Override
147- protected void onDetachedFromWindow () {
148- super .onDetachedFromWindow ();
149- mMoreKeysPlacerView .removeAllViews ();
150- uninstallMoreKeysPlacerView ();
151- }
152-
153- private void uninstallMoreKeysPlacerView () {
154- final View rootView = getRootView ();
155- if (rootView == null ) {
156- Log .w (TAG , "Cannot find root view" );
157- return ;
158- }
159- final ViewGroup windowContentView = rootView .findViewById (android .R .id .content );
160- // Note: It'd be very weird if we get null by android.R.id.content.
161- if (windowContentView == null ) {
162- Log .w (TAG , "Cannot find android.R.id.content view to add DrawingPreviewPlacerView" );
163- return ;
138+ if (uninstall ) {
139+ windowContentView .removeView (mMoreKeysPlacerView );
140+ } else {
141+ windowContentView .addView (mMoreKeysPlacerView );
164142 }
165-
166- windowContentView .removeView (mMoreKeysPlacerView );
167143 }
168144
169145 public void setOnKeyEventListener (final OnKeyEventListener listener ) {
@@ -223,34 +199,38 @@ public MoreKeysPanel showMoreKeysKeyboard(@Nonnull final Key key, final int last
223199 return moreKeysKeyboardView ;
224200 }
225201
226- @ Override
227- public void onShowMoreKeysPanel (final MoreKeysPanel panel ) {
228- // Dismiss another {@link MoreKeysPanel} that may be being showed.
229- onDismissMoreKeysPanel ();
230- panel .showInParent (mMoreKeysPlacerView );
231- mMoreKeysPanel = panel ;
202+ private void dismissMoreKeysPanel () {
203+ if (isShowingMoreKeysPanel ()) {
204+ mMoreKeysPanel .dismissMoreKeysPanel ();
205+ }
232206 }
233207
234208 public boolean isShowingMoreKeysPanel () {
235209 return mMoreKeysPanel != null ;
236210 }
237211
238212 @ Override
239- public void onCancelMoreKeysPanel () {
240- // Nothing to do
213+ public void onShowMoreKeysPanel (final MoreKeysPanel panel ) {
214+ // install placer view only when needed instead of when this
215+ // view is attached to window
216+ installMoreKeysPlacerView (false /* uninstall */ );
217+ panel .showInParent (mMoreKeysPlacerView );
218+ mMoreKeysPanel = panel ;
241219 }
242220
243221 @ Override
244222 public void onDismissMoreKeysPanel () {
245223 if (isShowingMoreKeysPanel ()) {
246224 mMoreKeysPanel .removeFromParent ();
247225 mMoreKeysPanel = null ;
226+ installMoreKeysPlacerView (true /* uninstall */ );
248227 }
249228 }
250229
251- private void dismissMoreKeysPanel () {
230+ @ Override
231+ public void onCancelMoreKeysPanel () {
252232 if (isShowingMoreKeysPanel ()) {
253- mMoreKeysPanel . dismissMoreKeysPanel ();
233+ dismissMoreKeysPanel ();
254234 }
255235 }
256236
@@ -319,6 +299,9 @@ private void onLongPressed(final Key key) {
319299 final int translatedX = moreKeysPanel .translateX (x );
320300 final int translatedY = moreKeysPanel .translateY (y );
321301 moreKeysPanel .onDownEvent (translatedX , translatedY , mPointerId , 0 /* nor used for now */ );
302+ // No need of re-allowing parent later as we don't
303+ // want any scroll to append during this entire input.
304+ disallowParentInterceptTouchEvent (true );
322305 }
323306 }
324307
@@ -465,4 +448,13 @@ public boolean onMove(final MotionEvent e) {
465448 mLastY = y ;
466449 return true ;
467450 }
451+
452+ private void disallowParentInterceptTouchEvent (final boolean disallow ) {
453+ final ViewParent parent = getParent ();
454+ if (parent == null ) {
455+ Log .w (TAG , "Cannot disallow touch event interception, no parent found." );
456+ return ;
457+ }
458+ parent .requestDisallowInterceptTouchEvent (disallow );
459+ }
468460}
0 commit comments