Merge "Remove workaround code of placing DrawingPreviewPlacerView"

This commit is contained in:
Tadashi G. Takaoka 2014-04-07 08:58:19 +00:00 committed by Android (Google) Code Review
commit a857235d0c
4 changed files with 30 additions and 27 deletions

View file

@ -30,7 +30,6 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -428,21 +427,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
private void locatePreviewPlacerView() { 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); getLocationInWindow(mOriginCoords);
final DisplayMetrics dm = getResources().getDisplayMetrics(); mDrawingPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, getWidth(), getHeight());
if (CoordinateUtils.y(mOriginCoords) < dm.heightPixels / 4) { }
// In transient state.
return; private void installPreviewPlacerView() {
}
final View rootView = getRootView(); final View rootView = getRootView();
if (rootView == null) { if (rootView == null) {
Log.w(TAG, "Cannot find root view"); 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. // Note: It'd be very weird if we get null by android.R.id.content.
if (windowContentView == null) { if (windowContentView == null) {
Log.w(TAG, "Cannot find android.R.id.content view to add DrawingPreviewPlacerView"); Log.w(TAG, "Cannot find android.R.id.content view to add DrawingPreviewPlacerView");
} else { return;
windowContentView.addView(mDrawingPreviewPlacerView);
mDrawingPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, width, height);
} }
windowContentView.addView(mDrawingPreviewPlacerView);
} }
/** /**
@ -576,6 +564,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
installPreviewPlacerView();
// Notify the ResearchLogger (development only diagnostics) that the keyboard view has // 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 // been attached. This is needed to properly show the splash screen, which requires that
// the window token of the KeyboardView be non-null. // the window token of the KeyboardView be non-null.

View file

@ -29,25 +29,37 @@ import com.android.inputmethod.keyboard.PointerTracker;
public abstract class AbstractDrawingPreview { public abstract class AbstractDrawingPreview {
private final View mDrawingView; private final View mDrawingView;
private boolean mPreviewEnabled; private boolean mPreviewEnabled;
private boolean mHasValidGeometry;
protected AbstractDrawingPreview(final View drawingView) { protected AbstractDrawingPreview(final View drawingView) {
mDrawingView = drawingView; mDrawingView = drawingView;
} }
public final View getDrawingView() { protected final View getDrawingView() {
return mDrawingView; return mDrawingView;
} }
protected final boolean isPreviewEnabled() {
return mPreviewEnabled && mHasValidGeometry;
}
public final void setPreviewEnabled(final boolean enabled) { public final void setPreviewEnabled(final boolean enabled) {
mPreviewEnabled = enabled; mPreviewEnabled = enabled;
} }
public boolean isPreviewEnabled() { /**
return mPreviewEnabled; * Set {@link MainKeyboardView} geometry and position in the {@link SoftInputWindow}.
} * The class that is overriding this method must call this super implementation.
*
public void setKeyboardGeometry(final int[] originCoords, final int width, final int height) { * @param originCoords the top-left coordinates of the {@link MainKeyboardView} in
// Default implementation is empty. * {@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(); public abstract void onDeallocateMemory();

View file

@ -55,7 +55,7 @@ public final class DrawingPreviewPlacerView extends RelativeLayout {
CoordinateUtils.copy(mKeyboardViewOrigin, originCoords); CoordinateUtils.copy(mKeyboardViewOrigin, originCoords);
final int count = mPreviews.size(); final int count = mPreviews.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
mPreviews.get(i).setKeyboardGeometry(originCoords, width, height); mPreviews.get(i).setKeyboardViewGeometry(originCoords, width, height);
} }
} }

View file

@ -95,7 +95,9 @@ public final class GestureTrailsDrawingPreview extends AbstractDrawingPreview {
} }
@Override @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 mOffscreenOffsetY = (int)(height
* GestureStrokeRecognitionPoints.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO); * GestureStrokeRecognitionPoints.EXTRA_GESTURE_TRAIL_AREA_ABOVE_KEYBOARD_RATIO);
mOffscreenWidth = width; mOffscreenWidth = width;