From 0c01fc6f1c01a2009546a2982818e68c08012ab3 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 7 Apr 2014 16:10:48 +0900 Subject: [PATCH] Remove workaround code of placing DrawingPreviewPlacerView This CL divides MainKeyboardView.locatePreviewPlacerView method into two methods. One is installing DrawingPreviewPlacerView to the window as Frontmost view. Another is telling the location of MainKeyboardView to DrawingPreviewPlacerView. Thus we can eliminate workaround code to deal with transient states in orientation change. Change-Id: Ia5d8f28dfb5213d27aa218c72d838a3c3be5a527 --- .../keyboard/MainKeyboardView.java | 25 +++++------------- .../internal/AbstractDrawingPreview.java | 26 ++++++++++++++----- .../internal/DrawingPreviewPlacerView.java | 2 +- .../internal/GestureTrailsDrawingPreview.java | 4 ++- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 0f9c39a80..d8dd93a35 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -30,7 +30,6 @@ import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; import android.util.AttributeSet; -import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -428,21 +427,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack } private void locatePreviewPlacerView() { - if (mDrawingPreviewPlacerView.getParent() != null) { - return; - } - final int width = getWidth(); - final int height = getHeight(); - if (width == 0 || height == 0) { - // In transient state. - return; - } getLocationInWindow(mOriginCoords); - final DisplayMetrics dm = getResources().getDisplayMetrics(); - if (CoordinateUtils.y(mOriginCoords) < dm.heightPixels / 4) { - // In transient state. - return; - } + mDrawingPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, getWidth(), getHeight()); + } + + private void installPreviewPlacerView() { final View rootView = getRootView(); if (rootView == null) { Log.w(TAG, "Cannot find root view"); @@ -452,10 +441,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack // Note: It'd be very weird if we get null by android.R.id.content. if (windowContentView == null) { Log.w(TAG, "Cannot find android.R.id.content view to add DrawingPreviewPlacerView"); - } else { - windowContentView.addView(mDrawingPreviewPlacerView); - mDrawingPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, width, height); + return; } + windowContentView.addView(mDrawingPreviewPlacerView); } /** @@ -576,6 +564,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); + installPreviewPlacerView(); // Notify the ResearchLogger (development only diagnostics) that the keyboard view has // been attached. This is needed to properly show the splash screen, which requires that // the window token of the KeyboardView be non-null. diff --git a/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java index cd7dd6f18..3a72aed0d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java @@ -29,25 +29,37 @@ import com.android.inputmethod.keyboard.PointerTracker; public abstract class AbstractDrawingPreview { private final View mDrawingView; private boolean mPreviewEnabled; + private boolean mHasValidGeometry; protected AbstractDrawingPreview(final View drawingView) { mDrawingView = drawingView; } - public final View getDrawingView() { + protected final View getDrawingView() { return mDrawingView; } + protected final boolean isPreviewEnabled() { + return mPreviewEnabled && mHasValidGeometry; + } + public final void setPreviewEnabled(final boolean enabled) { mPreviewEnabled = enabled; } - public boolean isPreviewEnabled() { - return mPreviewEnabled; - } - - public void setKeyboardGeometry(final int[] originCoords, final int width, final int height) { - // Default implementation is empty. + /** + * Set {@link MainKeyboardView} geometry and position in the {@link SoftInputWindow}. + * The class that is overriding this method must call this super implementation. + * + * @param originCoords the top-left coordinates of the {@link MainKeyboardView} in + * {@link SoftInputWindow} coordinate-system. This is unused but has a point in an + * extended class, such as {@link GestureTrailsDrawingPreview}. + * @param width the width of {@link MainKeyboardView}. + * @param height the height of {@link MainKeyboardView}. + */ + public void setKeyboardViewGeometry(final int[] originCoords, final int width, + final int height) { + mHasValidGeometry = (width > 0 && height > 0); } public abstract void onDeallocateMemory(); diff --git a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java index 606addcc4..fdc2458d4 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java @@ -55,7 +55,7 @@ public final class DrawingPreviewPlacerView extends RelativeLayout { CoordinateUtils.copy(mKeyboardViewOrigin, originCoords); final int count = mPreviews.size(); for (int i = 0; i < count; i++) { - mPreviews.get(i).setKeyboardGeometry(originCoords, width, height); + mPreviews.get(i).setKeyboardViewGeometry(originCoords, width, height); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java index eef4b36ed..d8b00c707 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java @@ -95,7 +95,9 @@ public final class GestureTrailsDrawingPreview extends AbstractDrawingPreview { } @Override - public void setKeyboardGeometry(final int[] originCoords, final int width, final int height) { + public void setKeyboardViewGeometry(final int[] originCoords, final int width, + final int height) { + super.setKeyboardViewGeometry(originCoords, width, height); mOffscreenOffsetY = (int)(height * GestureStrokeRecognitionPoints.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO); mOffscreenWidth = width;