1 /* 2 * Copyright (C) 2012 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 com.android.inputmethod.keyboard.internal; 18 19 import android.graphics.Canvas; 20 import android.view.View; 21 22 import com.android.inputmethod.keyboard.PointerTracker; 23 24 /** 25 * Abstract base class for previews that are drawn on DrawingPreviewPlacerView, e.g., 26 * GestureFloatingTextDrawingPreview, GestureTrailsDrawingPreview, and 27 * SlidingKeyInputDrawingPreview. 28 */ 29 public abstract class AbstractDrawingPreview { 30 private View mDrawingView; 31 private boolean mPreviewEnabled; 32 private boolean mHasValidGeometry; 33 setDrawingView(final DrawingPreviewPlacerView drawingView)34 public void setDrawingView(final DrawingPreviewPlacerView drawingView) { 35 mDrawingView = drawingView; 36 drawingView.addPreview(this); 37 } 38 invalidateDrawingView()39 protected void invalidateDrawingView() { 40 if (mDrawingView != null) { 41 mDrawingView.invalidate(); 42 } 43 } 44 isPreviewEnabled()45 protected final boolean isPreviewEnabled() { 46 return mPreviewEnabled && mHasValidGeometry; 47 } 48 setPreviewEnabled(final boolean enabled)49 public final void setPreviewEnabled(final boolean enabled) { 50 mPreviewEnabled = enabled; 51 } 52 53 /** 54 * Set {@link MainKeyboardView} geometry and position in the {@link SoftInputWindow}. 55 * The class that is overriding this method must call this super implementation. 56 * 57 * @param originCoords the top-left coordinates of the {@link MainKeyboardView} in 58 * {@link SoftInputWindow} coordinate-system. This is unused but has a point in an 59 * extended class, such as {@link GestureTrailsDrawingPreview}. 60 * @param width the width of {@link MainKeyboardView}. 61 * @param height the height of {@link MainKeyboardView}. 62 */ setKeyboardViewGeometry(final int[] originCoords, final int width, final int height)63 public void setKeyboardViewGeometry(final int[] originCoords, final int width, 64 final int height) { 65 mHasValidGeometry = (width > 0 && height > 0); 66 } 67 onDeallocateMemory()68 public abstract void onDeallocateMemory(); 69 70 /** 71 * Draws the preview 72 * @param canvas The canvas where the preview is drawn. 73 */ drawPreview(final Canvas canvas)74 public abstract void drawPreview(final Canvas canvas); 75 76 /** 77 * Set the position of the preview. 78 * @param tracker The new location of the preview is based on the points in PointerTracker. 79 */ setPreviewPosition(final PointerTracker tracker)80 public abstract void setPreviewPosition(final PointerTracker tracker); 81 } 82