2011-07-01 04:07:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard;
|
|
|
|
|
2012-03-14 03:33:03 +00:00
|
|
|
import android.animation.AnimatorInflater;
|
2012-03-16 05:05:20 +00:00
|
|
|
import android.animation.ObjectAnimator;
|
2011-07-01 04:07:59 +00:00
|
|
|
import android.content.Context;
|
2012-11-01 04:04:49 +00:00
|
|
|
import android.content.SharedPreferences;
|
2011-07-01 04:07:59 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2011-12-17 23:13:36 +00:00
|
|
|
import android.content.res.TypedArray;
|
2011-08-23 03:22:24 +00:00
|
|
|
import android.graphics.Canvas;
|
2013-01-21 07:36:25 +00:00
|
|
|
import android.graphics.Color;
|
2011-12-17 18:06:20 +00:00
|
|
|
import android.graphics.Paint;
|
2011-12-17 23:13:36 +00:00
|
|
|
import android.graphics.Paint.Align;
|
2012-01-25 03:57:28 +00:00
|
|
|
import android.graphics.Typeface;
|
2012-11-01 04:04:49 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2011-07-01 04:07:59 +00:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.View;
|
2011-08-31 04:00:32 +00:00
|
|
|
import android.view.ViewGroup;
|
2012-04-11 09:21:10 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2011-07-01 04:07:59 +00:00
|
|
|
|
|
|
|
import com.android.inputmethod.accessibility.AccessibilityUtils;
|
2014-05-20 06:19:45 +00:00
|
|
|
import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate;
|
2012-10-03 08:36:45 +00:00
|
|
|
import com.android.inputmethod.annotations.ExternallyReferenced;
|
2013-12-13 08:09:16 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.DrawingHandler;
|
2013-12-24 09:03:17 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.DrawingPreviewPlacerView;
|
|
|
|
import com.android.inputmethod.keyboard.internal.GestureFloatingTextDrawingPreview;
|
|
|
|
import com.android.inputmethod.keyboard.internal.GestureTrailsDrawingPreview;
|
2012-08-30 07:18:53 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
|
2014-02-04 07:08:10 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyPreviewChoreographer;
|
2013-01-21 06:23:32 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
|
2014-08-11 10:13:07 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.KeyPreviewView;
|
2014-03-28 07:03:00 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.LanguageOnSpacebarHelper;
|
2014-06-19 01:06:17 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
|
2013-07-31 09:13:42 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper;
|
2013-12-24 09:03:17 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.SlidingKeyInputDrawingPreview;
|
2013-12-13 08:09:16 +00:00
|
|
|
import com.android.inputmethod.keyboard.internal.TimerHandler;
|
2012-07-19 08:20:54 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2011-07-01 04:07:59 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
2013-01-21 06:57:32 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords;
|
2013-07-22 03:43:37 +00:00
|
|
|
import com.android.inputmethod.latin.settings.DebugSettings;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CoordinateUtils;
|
2014-03-28 03:25:41 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SpacebarLanguageUtils;
|
2013-07-05 09:57:07 +00:00
|
|
|
import com.android.inputmethod.latin.utils.TypefaceUtils;
|
2011-07-01 04:07:59 +00:00
|
|
|
|
|
|
|
import java.util.WeakHashMap;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A view that is responsible for detecting key presses and touch movements.
|
|
|
|
*
|
2013-12-13 08:09:16 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
|
2014-05-13 02:19:43 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius
|
2013-12-13 08:09:16 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
|
2012-08-30 08:42:49 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFadeoutAnimator
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyHysteresisDistance
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdTime
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_touchNoiseThresholdDistance
|
2013-12-13 08:09:16 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_keySelectionByDraggingFinger
|
2012-08-30 08:42:49 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyRepeatStartTimeout
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyRepeatInterval
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout
|
2013-01-21 06:57:32 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewLayout
|
2013-01-21 06:23:32 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewOffset
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewHeight
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewLingerTimeout
|
2014-09-01 09:26:34 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewShowUpAnimator
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_keyPreviewDismissAnimator
|
2013-01-21 05:41:33 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardLayout
|
2014-08-22 09:36:09 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardForActionLayout
|
2013-01-21 07:36:25 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_backgroundDimAlpha
|
2012-08-30 08:42:49 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint
|
2013-01-21 06:57:32 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureFloatingPreviewTextLingerTimeout
|
2012-10-05 05:37:22 +00:00
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureStaticTimeThresholdAfterFastTyping
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDetectFastMoveSpeedThreshold
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDynamicThresholdDecayDuration
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDynamicTimeThresholdFrom
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDynamicTimeThresholdTo
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDynamicDistanceThresholdFrom
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureDynamicDistanceThresholdTo
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureSamplingMinimumDistance
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureRecognitionMinimumTime
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_gestureRecognitionSpeedThreshold
|
|
|
|
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
|
2011-07-01 04:07:59 +00:00
|
|
|
*/
|
2013-12-13 08:09:16 +00:00
|
|
|
public final class MainKeyboardView extends KeyboardView implements PointerTracker.DrawingProxy,
|
|
|
|
MoreKeysPanel.Controller, DrawingHandler.Callbacks, TimerHandler.Callbacks {
|
2012-07-23 01:27:14 +00:00
|
|
|
private static final String TAG = MainKeyboardView.class.getSimpleName();
|
2011-07-01 04:07:59 +00:00
|
|
|
|
2012-01-25 03:57:28 +00:00
|
|
|
/** Listener for {@link KeyboardActionListener}. */
|
|
|
|
private KeyboardActionListener mKeyboardActionListener;
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
/* Space key and its icon and background. */
|
2011-12-17 23:13:36 +00:00
|
|
|
private Key mSpaceKey;
|
2012-01-25 03:57:28 +00:00
|
|
|
// Stuff to draw language name on spacebar.
|
2012-03-16 05:05:20 +00:00
|
|
|
private final int mLanguageOnSpacebarFinalAlpha;
|
|
|
|
private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator;
|
2014-03-28 07:03:00 +00:00
|
|
|
private int mLanguageOnSpacebarFormatType;
|
2012-05-24 09:20:26 +00:00
|
|
|
private boolean mHasMultipleEnabledIMEsOrSubtypes;
|
2012-07-19 08:20:54 +00:00
|
|
|
private int mLanguageOnSpacebarAnimAlpha = Constants.Color.ALPHA_OPAQUE;
|
2013-12-13 08:09:16 +00:00
|
|
|
private final float mLanguageOnSpacebarTextRatio;
|
|
|
|
private float mLanguageOnSpacebarTextSize;
|
|
|
|
private final int mLanguageOnSpacebarTextColor;
|
2014-05-13 02:19:43 +00:00
|
|
|
private final float mLanguageOnSpacebarTextShadowRadius;
|
2013-12-13 08:09:16 +00:00
|
|
|
private final int mLanguageOnSpacebarTextShadowColor;
|
2014-05-13 02:19:43 +00:00
|
|
|
private static final float LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED = -1.0f;
|
2012-04-26 05:40:47 +00:00
|
|
|
// The minimum x-scale to fit the language name on spacebar.
|
|
|
|
private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f;
|
2011-12-15 14:26:18 +00:00
|
|
|
|
2012-03-14 05:46:22 +00:00
|
|
|
// Stuff to draw altCodeWhileTyping keys.
|
2013-12-13 08:09:16 +00:00
|
|
|
private final ObjectAnimator mAltCodeKeyWhileTypingFadeoutAnimator;
|
|
|
|
private final ObjectAnimator mAltCodeKeyWhileTypingFadeinAnimator;
|
2012-07-19 08:20:54 +00:00
|
|
|
private int mAltCodeKeyWhileTypingAnimAlpha = Constants.Color.ALPHA_OPAQUE;
|
2012-03-14 05:46:22 +00:00
|
|
|
|
2013-12-24 09:03:17 +00:00
|
|
|
// Drawing preview placer view
|
|
|
|
private final DrawingPreviewPlacerView mDrawingPreviewPlacerView;
|
2013-01-21 06:57:32 +00:00
|
|
|
private final int[] mOriginCoords = CoordinateUtils.newInstance();
|
2013-12-24 09:03:17 +00:00
|
|
|
private final GestureFloatingTextDrawingPreview mGestureFloatingTextDrawingPreview;
|
|
|
|
private final GestureTrailsDrawingPreview mGestureTrailsDrawingPreview;
|
|
|
|
private final SlidingKeyInputDrawingPreview mSlidingKeyInputDrawingPreview;
|
2013-01-21 06:57:32 +00:00
|
|
|
|
2013-01-21 06:23:32 +00:00
|
|
|
// Key preview
|
2014-02-04 03:37:17 +00:00
|
|
|
private final KeyPreviewDrawParams mKeyPreviewDrawParams;
|
2014-02-04 07:08:10 +00:00
|
|
|
private final KeyPreviewChoreographer mKeyPreviewChoreographer;
|
2013-01-21 06:23:32 +00:00
|
|
|
|
2012-02-08 07:12:11 +00:00
|
|
|
// More keys keyboard
|
2013-01-21 07:36:25 +00:00
|
|
|
private final Paint mBackgroundDimAlphaPaint = new Paint();
|
|
|
|
private boolean mNeedsToDimEntireKeyboard;
|
2013-01-22 05:32:47 +00:00
|
|
|
private final View mMoreKeysKeyboardContainer;
|
2014-08-22 09:36:09 +00:00
|
|
|
private final View mMoreKeysKeyboardForActionContainer;
|
2014-05-23 11:18:17 +00:00
|
|
|
private final WeakHashMap<Key, Keyboard> mMoreKeysKeyboardCache = new WeakHashMap<>();
|
2012-02-08 07:12:11 +00:00
|
|
|
private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint;
|
2013-01-21 05:41:33 +00:00
|
|
|
// More keys panel (used by both more keys keyboard and more suggestions view)
|
|
|
|
// TODO: Consider extending to support multiple more keys panels
|
|
|
|
private MoreKeysPanel mMoreKeysPanel;
|
2011-07-01 04:07:59 +00:00
|
|
|
|
2013-01-21 06:57:32 +00:00
|
|
|
// Gesture floating preview text
|
|
|
|
// TODO: Make this parameter customizable by user via settings.
|
|
|
|
private int mGestureFloatingPreviewTextLingerTimeout;
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private final KeyDetector mKeyDetector;
|
2013-07-31 09:13:42 +00:00
|
|
|
private final NonDistinctMultitouchHelper mNonDistinctMultitouchHelper;
|
2011-07-01 04:07:59 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private final TimerHandler mKeyTimerHandler;
|
2013-09-06 08:08:34 +00:00
|
|
|
private final int mLanguageOnSpacebarHorizontalMargin;
|
2011-07-01 04:07:59 +00:00
|
|
|
|
2014-06-02 09:43:07 +00:00
|
|
|
private final DrawingHandler mDrawingHandler = new DrawingHandler(this);
|
2013-01-21 06:57:32 +00:00
|
|
|
|
2014-06-02 09:43:07 +00:00
|
|
|
private MainKeyboardAccessibilityDelegate mAccessibilityDelegate;
|
2014-04-30 09:40:12 +00:00
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public MainKeyboardView(final Context context, final AttributeSet attrs) {
|
2012-07-23 01:27:14 +00:00
|
|
|
this(context, attrs, R.attr.mainKeyboardViewStyle);
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public MainKeyboardView(final Context context, final AttributeSet attrs, final int defStyle) {
|
2011-07-01 04:07:59 +00:00
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
2013-12-24 09:03:17 +00:00
|
|
|
mDrawingPreviewPlacerView = new DrawingPreviewPlacerView(context, attrs);
|
2013-12-13 08:09:16 +00:00
|
|
|
|
|
|
|
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
|
|
|
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
|
|
|
final int ignoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
|
|
|
|
final int gestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
|
|
|
|
mKeyTimerHandler = new TimerHandler(
|
|
|
|
this, ignoreAltCodeKeyTimeout, gestureRecognitionUpdateTime);
|
|
|
|
|
|
|
|
final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
|
|
|
|
R.styleable.MainKeyboardView_keyHysteresisDistance, 0.0f);
|
|
|
|
final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
|
|
|
|
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0.0f);
|
|
|
|
mKeyDetector = new KeyDetector(
|
|
|
|
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
|
|
|
|
|
2013-12-20 02:56:09 +00:00
|
|
|
PointerTracker.init(mainKeyboardViewAttr, mKeyTimerHandler, this /* DrawingProxy */);
|
2013-12-13 08:09:16 +00:00
|
|
|
|
2012-11-01 04:04:49 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
final boolean forceNonDistinctMultitouch = prefs.getBoolean(
|
2013-01-08 09:26:47 +00:00
|
|
|
DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, false);
|
2012-11-01 04:04:49 +00:00
|
|
|
final boolean hasDistinctMultitouch = context.getPackageManager()
|
2013-07-31 09:13:42 +00:00
|
|
|
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)
|
|
|
|
&& !forceNonDistinctMultitouch;
|
|
|
|
mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null
|
2013-12-20 02:56:09 +00:00
|
|
|
: new NonDistinctMultitouchHelper();
|
2011-12-17 18:06:20 +00:00
|
|
|
|
2013-01-21 07:36:25 +00:00
|
|
|
final int backgroundDimAlpha = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_backgroundDimAlpha, 0);
|
|
|
|
mBackgroundDimAlphaPaint.setColor(Color.BLACK);
|
|
|
|
mBackgroundDimAlphaPaint.setAlpha(backgroundDimAlpha);
|
2013-12-13 08:09:16 +00:00
|
|
|
mLanguageOnSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
|
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
|
|
|
|
mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
|
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
|
2014-05-13 02:19:43 +00:00
|
|
|
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
|
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
|
|
|
|
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);
|
2013-12-13 08:09:16 +00:00
|
|
|
mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
|
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0);
|
2013-01-21 05:41:33 +00:00
|
|
|
mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
|
2012-07-23 01:27:14 +00:00
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
|
2012-07-19 08:20:54 +00:00
|
|
|
Constants.Color.ALPHA_OPAQUE);
|
2013-01-21 05:41:33 +00:00
|
|
|
final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
2012-07-23 01:27:14 +00:00
|
|
|
R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
2013-01-21 05:41:33 +00:00
|
|
|
final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
2012-07-23 01:27:14 +00:00
|
|
|
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
|
2013-01-21 05:41:33 +00:00
|
|
|
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
2012-07-23 01:27:14 +00:00
|
|
|
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
2012-01-25 11:14:39 +00:00
|
|
|
|
2014-02-04 03:37:17 +00:00
|
|
|
mKeyPreviewDrawParams = new KeyPreviewDrawParams(mainKeyboardViewAttr);
|
2014-02-04 07:08:10 +00:00
|
|
|
mKeyPreviewChoreographer = new KeyPreviewChoreographer(mKeyPreviewDrawParams);
|
|
|
|
|
2013-01-22 05:32:47 +00:00
|
|
|
final int moreKeysKeyboardLayoutId = mainKeyboardViewAttr.getResourceId(
|
2013-01-21 05:41:33 +00:00
|
|
|
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
|
2014-08-22 09:36:09 +00:00
|
|
|
final int moreKeysKeyboardForActionLayoutId = mainKeyboardViewAttr.getResourceId(
|
|
|
|
R.styleable.MainKeyboardView_moreKeysKeyboardForActionLayout,
|
|
|
|
moreKeysKeyboardLayoutId);
|
2013-01-21 05:41:33 +00:00
|
|
|
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
|
2012-07-23 01:27:14 +00:00
|
|
|
R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);
|
2013-01-21 06:57:32 +00:00
|
|
|
|
|
|
|
mGestureFloatingPreviewTextLingerTimeout = mainKeyboardViewAttr.getInt(
|
|
|
|
R.styleable.MainKeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
|
2013-01-21 10:17:17 +00:00
|
|
|
|
2013-12-24 09:03:17 +00:00
|
|
|
mGestureFloatingTextDrawingPreview = new GestureFloatingTextDrawingPreview(
|
2014-06-16 22:15:47 +00:00
|
|
|
mainKeyboardViewAttr);
|
|
|
|
mGestureFloatingTextDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
|
2013-01-21 10:17:17 +00:00
|
|
|
|
2014-06-16 22:15:47 +00:00
|
|
|
mGestureTrailsDrawingPreview = new GestureTrailsDrawingPreview(mainKeyboardViewAttr);
|
|
|
|
mGestureTrailsDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
|
2013-01-21 10:17:17 +00:00
|
|
|
|
2014-06-16 22:15:47 +00:00
|
|
|
mSlidingKeyInputDrawingPreview = new SlidingKeyInputDrawingPreview(mainKeyboardViewAttr);
|
|
|
|
mSlidingKeyInputDrawingPreview.setDrawingView(mDrawingPreviewPlacerView);
|
2013-01-21 05:41:33 +00:00
|
|
|
mainKeyboardViewAttr.recycle();
|
2012-01-25 11:14:39 +00:00
|
|
|
|
2014-08-22 09:36:09 +00:00
|
|
|
final LayoutInflater inflater = LayoutInflater.from(getContext());
|
|
|
|
mMoreKeysKeyboardContainer = inflater.inflate(moreKeysKeyboardLayoutId, null);
|
|
|
|
mMoreKeysKeyboardForActionContainer = inflater.inflate(
|
|
|
|
moreKeysKeyboardForActionLayoutId, null);
|
2012-03-16 05:05:20 +00:00
|
|
|
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
|
|
|
|
languageOnSpacebarFadeoutAnimatorResId, this);
|
|
|
|
mAltCodeKeyWhileTypingFadeoutAnimator = loadObjectAnimator(
|
|
|
|
altCodeKeyWhileTypingFadeoutAnimatorResId, this);
|
|
|
|
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
|
|
|
|
altCodeKeyWhileTypingFadeinAnimatorResId, this);
|
2013-07-02 09:07:35 +00:00
|
|
|
|
|
|
|
mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
|
2013-09-06 08:08:34 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
|
|
|
|
R.dimen.config_language_on_spacebar_horizontal_margin);
|
2012-03-16 05:05:20 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 15:25:05 +00:00
|
|
|
@Override
|
|
|
|
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
|
|
|
|
super.setHardwareAcceleratedDrawingEnabled(enabled);
|
2013-12-24 09:03:17 +00:00
|
|
|
mDrawingPreviewPlacerView.setHardwareAcceleratedDrawingEnabled(enabled);
|
2013-08-01 15:25:05 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
|
2012-10-29 06:14:20 +00:00
|
|
|
if (resId == 0) {
|
2013-04-26 05:36:43 +00:00
|
|
|
// TODO: Stop returning null.
|
2012-10-29 06:14:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-03-16 05:05:20 +00:00
|
|
|
final ObjectAnimator animator = (ObjectAnimator)AnimatorInflater.loadAnimator(
|
|
|
|
getContext(), resId);
|
2012-03-14 03:33:03 +00:00
|
|
|
if (animator != null) {
|
2012-03-16 05:05:20 +00:00
|
|
|
animator.setTarget(target);
|
2012-03-14 05:46:22 +00:00
|
|
|
}
|
2012-03-16 05:05:20 +00:00
|
|
|
return animator;
|
|
|
|
}
|
2012-03-14 05:46:22 +00:00
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
private static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel,
|
|
|
|
final ObjectAnimator animatorToStart) {
|
|
|
|
if (animatorToCancel == null || animatorToStart == null) {
|
|
|
|
// TODO: Stop using null as a no-operation animator.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
float startFraction = 0.0f;
|
|
|
|
if (animatorToCancel.isStarted()) {
|
|
|
|
animatorToCancel.cancel();
|
|
|
|
startFraction = 1.0f - animatorToCancel.getAnimatedFraction();
|
|
|
|
}
|
|
|
|
final long startTime = (long)(animatorToStart.getDuration() * startFraction);
|
|
|
|
animatorToStart.start();
|
|
|
|
animatorToStart.setCurrentPlayTime(startTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements {@link TimerHander.Callbacks} method.
|
|
|
|
@Override
|
|
|
|
public void startWhileTypingFadeinAnimation() {
|
|
|
|
cancelAndStartAnimators(
|
|
|
|
mAltCodeKeyWhileTypingFadeoutAnimator, mAltCodeKeyWhileTypingFadeinAnimator);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startWhileTypingFadeoutAnimation() {
|
|
|
|
cancelAndStartAnimators(
|
|
|
|
mAltCodeKeyWhileTypingFadeinAnimator, mAltCodeKeyWhileTypingFadeoutAnimator);
|
|
|
|
}
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
@ExternallyReferenced
|
2012-03-16 05:05:20 +00:00
|
|
|
public int getLanguageOnSpacebarAnimAlpha() {
|
|
|
|
return mLanguageOnSpacebarAnimAlpha;
|
2012-03-14 03:33:03 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
@ExternallyReferenced
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setLanguageOnSpacebarAnimAlpha(final int alpha) {
|
2012-03-16 05:05:20 +00:00
|
|
|
mLanguageOnSpacebarAnimAlpha = alpha;
|
|
|
|
invalidateKey(mSpaceKey);
|
|
|
|
}
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
@ExternallyReferenced
|
2012-03-16 05:05:20 +00:00
|
|
|
public int getAltCodeKeyWhileTypingAnimAlpha() {
|
|
|
|
return mAltCodeKeyWhileTypingAnimAlpha;
|
|
|
|
}
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
@ExternallyReferenced
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setAltCodeKeyWhileTypingAnimAlpha(final int alpha) {
|
2013-04-26 06:50:12 +00:00
|
|
|
if (mAltCodeKeyWhileTypingAnimAlpha == alpha) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Update the visual of alt-code-key-while-typing.
|
2012-03-16 05:05:20 +00:00
|
|
|
mAltCodeKeyWhileTypingAnimAlpha = alpha;
|
2013-04-26 06:50:12 +00:00
|
|
|
final Keyboard keyboard = getKeyboard();
|
|
|
|
if (keyboard == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (final Key key : keyboard.mAltCodeKeysWhileTyping) {
|
|
|
|
invalidateKey(key);
|
|
|
|
}
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setKeyboardActionListener(final KeyboardActionListener listener) {
|
2011-07-01 04:07:59 +00:00
|
|
|
mKeyboardActionListener = listener;
|
2011-07-11 22:24:01 +00:00
|
|
|
PointerTracker.setKeyboardActionListener(listener);
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// TODO: We should reconsider which coordinate system should be used to represent keyboard
|
|
|
|
// event.
|
|
|
|
public int getKeyX(final int x) {
|
|
|
|
return Constants.isValidCoordinate(x) ? mKeyDetector.getTouchX(x) : x;
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// TODO: We should reconsider which coordinate system should be used to represent keyboard
|
|
|
|
// event.
|
|
|
|
public int getKeyY(final int y) {
|
|
|
|
return Constants.isValidCoordinate(y) ? mKeyDetector.getTouchY(y) : y;
|
2011-07-09 04:26:29 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 04:07:59 +00:00
|
|
|
/**
|
|
|
|
* Attaches a keyboard to this view. The keyboard can be switched at any time and the
|
|
|
|
* view will re-layout itself to accommodate the keyboard.
|
|
|
|
* @see Keyboard
|
|
|
|
* @see #getKeyboard()
|
|
|
|
* @param keyboard the keyboard to display in this view
|
|
|
|
*/
|
|
|
|
@Override
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setKeyboard(final Keyboard keyboard) {
|
2014-01-09 03:53:35 +00:00
|
|
|
// Remove any pending messages, except dismissing preview and key repeat.
|
|
|
|
mKeyTimerHandler.cancelLongPressTimers();
|
2011-07-01 04:07:59 +00:00
|
|
|
super.setKeyboard(keyboard);
|
2011-07-08 05:31:29 +00:00
|
|
|
mKeyDetector.setKeyboard(
|
2013-04-11 03:08:36 +00:00
|
|
|
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
|
2012-08-08 02:41:58 +00:00
|
|
|
PointerTracker.setKeyDetector(mKeyDetector);
|
2013-01-22 05:32:47 +00:00
|
|
|
mMoreKeysKeyboardCache.clear();
|
2011-12-17 23:13:36 +00:00
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
mSpaceKey = keyboard.getKey(Constants.CODE_SPACE);
|
2011-12-17 23:13:36 +00:00
|
|
|
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
|
2013-12-13 08:09:16 +00:00
|
|
|
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
|
2012-06-05 18:02:54 +00:00
|
|
|
|
2014-06-02 09:43:07 +00:00
|
|
|
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
|
2014-06-07 14:28:13 +00:00
|
|
|
if (mAccessibilityDelegate == null) {
|
|
|
|
mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector);
|
|
|
|
}
|
2014-06-03 09:04:08 +00:00
|
|
|
mAccessibilityDelegate.setKeyboard(keyboard);
|
2014-06-02 09:43:07 +00:00
|
|
|
} else {
|
2014-06-03 09:04:08 +00:00
|
|
|
mAccessibilityDelegate = null;
|
2014-06-02 09:43:07 +00:00
|
|
|
}
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 06:23:32 +00:00
|
|
|
/**
|
2014-09-01 09:26:34 +00:00
|
|
|
* Enables or disables the key preview popup. This is a popup that shows a magnified
|
2013-01-21 06:23:32 +00:00
|
|
|
* version of the depressed key. By default the preview is enabled.
|
|
|
|
* @param previewEnabled whether or not to enable the key feedback preview
|
|
|
|
* @param delay the delay after which the preview is dismissed
|
|
|
|
*/
|
|
|
|
public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
|
2014-02-04 06:06:47 +00:00
|
|
|
mKeyPreviewDrawParams.setPopupEnabled(previewEnabled, delay);
|
2013-01-21 06:23:32 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 09:26:34 +00:00
|
|
|
/**
|
|
|
|
* Enables or disables the key preview popup animations and set animations' parameters.
|
|
|
|
*
|
|
|
|
* @param hasCustomAnimationParams false to use the default key preview popup animations
|
|
|
|
* specified by keyPreviewShowUpAnimator and keyPreviewDismissAnimator attributes.
|
|
|
|
* true to override the default animations with the specified parameters.
|
|
|
|
* @param showUpStartXScale from this x-scale the show up animation will start.
|
|
|
|
* @param showUpStartYScale from this y-scale the show up animation will start.
|
|
|
|
* @param showUpDuration the duration of the show up animation in milliseconds.
|
|
|
|
* @param dismissEndXScale to this x-scale the dismiss animation will end.
|
|
|
|
* @param dismissEndYScale to this y-scale the dismiss animation will end.
|
|
|
|
* @param dismissDuration the duration of the dismiss animation in milliseconds.
|
|
|
|
*/
|
|
|
|
public void setKeyPreviewAnimationParams(final boolean hasCustomAnimationParams,
|
|
|
|
final float showUpStartXScale, final float showUpStartYScale, final int showUpDuration,
|
|
|
|
final float dismissEndXScale, final float dismissEndYScale, final int dismissDuration) {
|
|
|
|
mKeyPreviewDrawParams.setAnimationParams(hasCustomAnimationParams,
|
|
|
|
showUpStartXScale, showUpStartYScale, showUpDuration,
|
|
|
|
dismissEndXScale, dismissEndYScale, dismissDuration);
|
2014-02-07 06:25:50 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 06:57:32 +00:00
|
|
|
private void locatePreviewPlacerView() {
|
|
|
|
getLocationInWindow(mOriginCoords);
|
2014-04-07 07:10:48 +00:00
|
|
|
mDrawingPreviewPlacerView.setKeyboardViewGeometry(mOriginCoords, getWidth(), getHeight());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void installPreviewPlacerView() {
|
2013-01-21 06:57:32 +00:00
|
|
|
final View rootView = getRootView();
|
|
|
|
if (rootView == null) {
|
|
|
|
Log.w(TAG, "Cannot find root view");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final ViewGroup windowContentView = (ViewGroup)rootView.findViewById(android.R.id.content);
|
|
|
|
// Note: It'd be very weird if we get null by android.R.id.content.
|
|
|
|
if (windowContentView == null) {
|
2013-12-24 09:03:17 +00:00
|
|
|
Log.w(TAG, "Cannot find android.R.id.content view to add DrawingPreviewPlacerView");
|
2014-04-07 07:10:48 +00:00
|
|
|
return;
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
2014-04-07 07:10:48 +00:00
|
|
|
windowContentView.addView(mDrawingPreviewPlacerView);
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// Implements {@link DrawingHandler.Callbacks} method.
|
|
|
|
@Override
|
|
|
|
public void dismissAllKeyPreviews() {
|
2014-02-04 07:08:10 +00:00
|
|
|
mKeyPreviewChoreographer.dismissAllKeyPreviews();
|
2013-01-21 06:57:32 +00:00
|
|
|
PointerTracker.setReleasedKeyGraphicsToAllKeys();
|
|
|
|
}
|
|
|
|
|
2013-01-21 06:23:32 +00:00
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
public void showKeyPreview(final Key key) {
|
2014-06-13 02:01:36 +00:00
|
|
|
// If the key is invalid or has no key preview, we must not show key preview.
|
|
|
|
if (key == null || key.noKeyPreview()) {
|
2013-01-21 06:23:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
final Keyboard keyboard = getKeyboard();
|
2014-06-13 02:01:36 +00:00
|
|
|
if (keyboard == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final KeyPreviewDrawParams previewParams = mKeyPreviewDrawParams;
|
2014-02-04 06:06:47 +00:00
|
|
|
if (!previewParams.isPopupEnabled()) {
|
2014-02-04 03:37:17 +00:00
|
|
|
previewParams.setVisibleOffset(-keyboard.mVerticalGap);
|
2013-12-13 08:09:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-04 07:08:10 +00:00
|
|
|
locatePreviewPlacerView();
|
2013-01-21 06:23:32 +00:00
|
|
|
getLocationInWindow(mOriginCoords);
|
2014-06-23 20:54:25 +00:00
|
|
|
mKeyPreviewChoreographer.placeAndShowKeyPreview(key, keyboard.mIconsSet, mKeyDrawParams,
|
2014-06-18 00:05:11 +00:00
|
|
|
getWidth(), mOriginCoords, mDrawingPreviewPlacerView, isHardwareAccelerated());
|
2013-12-13 08:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implements {@link TimerHandler.Callbacks} method.
|
2013-01-21 06:23:32 +00:00
|
|
|
@Override
|
2013-12-13 08:09:16 +00:00
|
|
|
public void dismissKeyPreviewWithoutDelay(final Key key) {
|
2014-02-04 07:08:10 +00:00
|
|
|
mKeyPreviewChoreographer.dismissKeyPreview(key, false /* withAnimation */);
|
2013-12-13 08:09:16 +00:00
|
|
|
// To redraw key top letter.
|
|
|
|
invalidateKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismissKeyPreview(final Key key) {
|
|
|
|
if (!isHardwareAccelerated()) {
|
|
|
|
// TODO: Implement preference option to control key preview method and duration.
|
2014-02-04 06:06:47 +00:00
|
|
|
mDrawingHandler.dismissKeyPreview(mKeyPreviewDrawParams.getLingerTimeout(), key);
|
2013-12-13 08:09:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-04 07:08:10 +00:00
|
|
|
mKeyPreviewChoreographer.dismissKeyPreview(key, true /* withAnimation */);
|
2013-01-21 06:23:32 +00:00
|
|
|
}
|
|
|
|
|
2013-01-24 07:08:33 +00:00
|
|
|
public void setSlidingKeyInputPreviewEnabled(final boolean enabled) {
|
2013-12-24 09:03:17 +00:00
|
|
|
mSlidingKeyInputDrawingPreview.setPreviewEnabled(enabled);
|
2013-01-24 07:08:33 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 06:23:32 +00:00
|
|
|
@Override
|
|
|
|
public void showSlidingKeyInputPreview(final PointerTracker tracker) {
|
|
|
|
locatePreviewPlacerView();
|
2013-12-24 09:03:17 +00:00
|
|
|
mSlidingKeyInputDrawingPreview.setPreviewPosition(tracker);
|
2013-01-21 06:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismissSlidingKeyInputPreview() {
|
2013-12-24 09:03:17 +00:00
|
|
|
mSlidingKeyInputDrawingPreview.dismissSlidingKeyInputPreview();
|
2013-01-21 06:23:32 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 12:07:40 +00:00
|
|
|
private void setGesturePreviewMode(final boolean isGestureTrailEnabled,
|
|
|
|
final boolean isGestureFloatingPreviewTextEnabled) {
|
2013-12-24 09:03:17 +00:00
|
|
|
mGestureFloatingTextDrawingPreview.setPreviewEnabled(isGestureFloatingPreviewTextEnabled);
|
|
|
|
mGestureTrailsDrawingPreview.setPreviewEnabled(isGestureTrailEnabled);
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// Implements {@link DrawingHandler.Callbacks} method.
|
|
|
|
@Override
|
2013-01-21 06:57:32 +00:00
|
|
|
public void showGestureFloatingPreviewText(final SuggestedWords suggestedWords) {
|
|
|
|
locatePreviewPlacerView();
|
2013-12-24 09:03:17 +00:00
|
|
|
mGestureFloatingTextDrawingPreview.setSuggetedWords(suggestedWords);
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void dismissGestureFloatingPreviewText() {
|
|
|
|
locatePreviewPlacerView();
|
|
|
|
mDrawingHandler.dismissGestureFloatingPreviewText(mGestureFloatingPreviewTextLingerTimeout);
|
|
|
|
}
|
|
|
|
|
2013-01-21 10:17:17 +00:00
|
|
|
@Override
|
2013-07-30 09:42:48 +00:00
|
|
|
public void showGestureTrail(final PointerTracker tracker,
|
|
|
|
final boolean showsFloatingPreviewText) {
|
2013-01-21 06:57:32 +00:00
|
|
|
locatePreviewPlacerView();
|
2013-07-30 09:42:48 +00:00
|
|
|
if (showsFloatingPreviewText) {
|
2013-12-24 09:03:17 +00:00
|
|
|
mGestureFloatingTextDrawingPreview.setPreviewPosition(tracker);
|
2013-07-30 09:42:48 +00:00
|
|
|
}
|
2013-12-24 09:03:17 +00:00
|
|
|
mGestureTrailsDrawingPreview.setPreviewPosition(tracker);
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 02:41:58 +00:00
|
|
|
// Note that this method is called from a non-UI thread.
|
2014-05-14 06:30:37 +00:00
|
|
|
@SuppressWarnings("static-method")
|
2012-08-30 08:42:49 +00:00
|
|
|
public void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
|
2012-08-08 02:41:58 +00:00
|
|
|
PointerTracker.setMainDictionaryAvailability(mainDictionaryAvailable);
|
|
|
|
}
|
|
|
|
|
2013-08-09 12:07:40 +00:00
|
|
|
public void setGestureHandlingEnabledByUser(final boolean isGestureHandlingEnabledByUser,
|
|
|
|
final boolean isGestureTrailEnabled,
|
|
|
|
final boolean isGestureFloatingPreviewTextEnabled) {
|
|
|
|
PointerTracker.setGestureHandlingEnabledByUser(isGestureHandlingEnabledByUser);
|
|
|
|
setGesturePreviewMode(isGestureHandlingEnabledByUser && isGestureTrailEnabled,
|
|
|
|
isGestureHandlingEnabledByUser && isGestureFloatingPreviewTextEnabled);
|
2012-07-23 05:59:19 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 01:41:15 +00:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
2014-04-07 07:10:48 +00:00
|
|
|
installPreviewPlacerView();
|
2012-08-21 06:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
2013-12-24 09:03:17 +00:00
|
|
|
mDrawingPreviewPlacerView.removeAllViews();
|
2012-07-19 01:41:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 05:32:47 +00:00
|
|
|
private MoreKeysPanel onCreateMoreKeysPanel(final Key key, final Context context) {
|
2014-06-19 01:06:17 +00:00
|
|
|
final MoreKeySpec[] moreKeys = key.getMoreKeys();
|
|
|
|
if (moreKeys == null) {
|
2011-07-01 04:07:59 +00:00
|
|
|
return null;
|
2012-10-29 06:14:20 +00:00
|
|
|
}
|
2013-01-22 05:32:47 +00:00
|
|
|
Keyboard moreKeysKeyboard = mMoreKeysKeyboardCache.get(key);
|
|
|
|
if (moreKeysKeyboard == null) {
|
2014-06-19 01:06:17 +00:00
|
|
|
// {@link KeyPreviewDrawParams#mPreviewVisibleWidth} should have been set at
|
|
|
|
// {@link KeyPreviewChoreographer#placeKeyPreview(Key,TextView,KeyboardIconsSet,KeyDrawParams,int,int[]},
|
|
|
|
// though there may be some chances that the value is zero. <code>width == 0</code>
|
|
|
|
// will cause zero-division error at
|
|
|
|
// {@link MoreKeysKeyboardParams#setParameters(int,int,int,int,int,int,boolean,int)}.
|
2014-06-23 20:54:25 +00:00
|
|
|
final boolean isSingleMoreKeyWithPreview = mKeyPreviewDrawParams.isPopupEnabled()
|
2014-06-19 01:06:17 +00:00
|
|
|
&& !key.noKeyPreview() && moreKeys.length == 1
|
|
|
|
&& mKeyPreviewDrawParams.getVisibleWidth() > 0;
|
|
|
|
final MoreKeysKeyboard.Builder builder = new MoreKeysKeyboard.Builder(
|
2014-06-23 20:54:25 +00:00
|
|
|
context, key, getKeyboard(), isSingleMoreKeyWithPreview,
|
2014-06-19 01:06:17 +00:00
|
|
|
mKeyPreviewDrawParams.getVisibleWidth(),
|
|
|
|
mKeyPreviewDrawParams.getVisibleHeight(), newLabelPaint(key));
|
|
|
|
moreKeysKeyboard = builder.build();
|
2013-01-22 05:32:47 +00:00
|
|
|
mMoreKeysKeyboardCache.put(key, moreKeysKeyboard);
|
2012-10-29 06:14:20 +00:00
|
|
|
}
|
2011-07-01 04:07:59 +00:00
|
|
|
|
2014-08-22 09:36:09 +00:00
|
|
|
final View container = key.isActionKey() ? mMoreKeysKeyboardForActionContainer
|
|
|
|
: mMoreKeysKeyboardContainer;
|
2012-02-08 07:12:11 +00:00
|
|
|
final MoreKeysKeyboardView moreKeysKeyboardView =
|
|
|
|
(MoreKeysKeyboardView)container.findViewById(R.id.more_keys_keyboard_view);
|
|
|
|
moreKeysKeyboardView.setKeyboard(moreKeysKeyboard);
|
2011-08-31 04:00:32 +00:00
|
|
|
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
2012-02-08 07:12:11 +00:00
|
|
|
return moreKeysKeyboardView;
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
// Implements {@link TimerHandler.Callbacks} method.
|
2011-07-01 04:07:59 +00:00
|
|
|
/**
|
2013-01-21 05:41:33 +00:00
|
|
|
* Called when a key is long pressed.
|
2011-07-01 04:07:59 +00:00
|
|
|
* @param tracker the pointer tracker which pressed the parent key
|
|
|
|
*/
|
2013-12-13 08:09:16 +00:00
|
|
|
@Override
|
|
|
|
public void onLongPress(final PointerTracker tracker) {
|
2013-01-22 05:32:47 +00:00
|
|
|
if (isShowingMoreKeysPanel()) {
|
2013-05-21 23:42:07 +00:00
|
|
|
return;
|
2013-01-22 05:32:47 +00:00
|
|
|
}
|
|
|
|
final Key key = tracker.getKey();
|
|
|
|
if (key == null) {
|
2013-05-21 23:42:07 +00:00
|
|
|
return;
|
2013-01-22 05:32:47 +00:00
|
|
|
}
|
2013-07-02 09:07:35 +00:00
|
|
|
final KeyboardActionListener listener = mKeyboardActionListener;
|
2013-05-22 00:14:31 +00:00
|
|
|
if (key.hasNoPanelAutoMoreKey()) {
|
2013-08-12 09:05:11 +00:00
|
|
|
final int moreKeyCode = key.getMoreKeys()[0].mCode;
|
2011-12-17 23:36:16 +00:00
|
|
|
tracker.onLongPressed();
|
2013-08-13 03:10:26 +00:00
|
|
|
listener.onPressKey(moreKeyCode, 0 /* repeatCount */, true /* isSinglePointer */);
|
2014-03-31 10:43:12 +00:00
|
|
|
listener.onCodeInput(moreKeyCode, Constants.NOT_A_COORDINATE,
|
|
|
|
Constants.NOT_A_COORDINATE, false /* isKeyRepeat */);
|
2013-07-02 09:07:35 +00:00
|
|
|
listener.onReleaseKey(moreKeyCode, false /* withSliding */);
|
2013-05-21 23:42:07 +00:00
|
|
|
return;
|
2011-12-17 23:36:16 +00:00
|
|
|
}
|
2013-08-12 09:05:11 +00:00
|
|
|
final int code = key.getCode();
|
2013-01-22 05:32:47 +00:00
|
|
|
if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) {
|
2011-12-17 23:36:16 +00:00
|
|
|
// Long pressing the space key invokes IME switcher dialog.
|
2013-07-02 09:07:35 +00:00
|
|
|
if (listener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
|
2011-08-23 03:22:24 +00:00
|
|
|
tracker.onLongPressed();
|
2013-07-02 09:07:35 +00:00
|
|
|
listener.onReleaseKey(code, false /* withSliding */);
|
2013-05-21 23:42:07 +00:00
|
|
|
return;
|
2011-08-23 03:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 23:42:07 +00:00
|
|
|
openMoreKeysPanel(key, tracker);
|
2011-08-23 03:22:24 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 23:42:07 +00:00
|
|
|
private void openMoreKeysPanel(final Key key, final PointerTracker tracker) {
|
2013-01-22 05:32:47 +00:00
|
|
|
final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext());
|
2011-08-31 06:26:32 +00:00
|
|
|
if (moreKeysPanel == null) {
|
2013-05-21 23:42:07 +00:00
|
|
|
return;
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
2011-07-11 01:09:15 +00:00
|
|
|
|
2012-11-28 06:24:13 +00:00
|
|
|
final int[] lastCoords = CoordinateUtils.newInstance();
|
|
|
|
tracker.getLastCoordinates(lastCoords);
|
2014-06-19 01:06:17 +00:00
|
|
|
final boolean keyPreviewEnabled = mKeyPreviewDrawParams.isPopupEnabled()
|
|
|
|
&& !key.noKeyPreview();
|
2012-04-27 14:44:28 +00:00
|
|
|
// The more keys keyboard is usually horizontally aligned with the center of the parent key.
|
|
|
|
// If showMoreKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more
|
|
|
|
// keys keyboard is placed at the touch point of the parent key.
|
|
|
|
final int pointX = (mConfigShowMoreKeysKeyboardAtTouchedPoint && !keyPreviewEnabled)
|
2012-11-28 06:24:13 +00:00
|
|
|
? CoordinateUtils.x(lastCoords)
|
2013-08-12 09:05:11 +00:00
|
|
|
: key.getX() + key.getWidth() / 2;
|
2012-04-27 14:44:28 +00:00
|
|
|
// The more keys keyboard is usually vertically aligned with the top edge of the parent key
|
|
|
|
// (plus vertical gap). If the key preview is enabled, the more keys keyboard is vertically
|
|
|
|
// aligned with the bottom edge of the visible part of the key preview.
|
2012-08-28 08:19:49 +00:00
|
|
|
// {@code mPreviewVisibleOffset} has been set appropriately in
|
|
|
|
// {@link KeyboardView#showKeyPreview(PointerTracker)}.
|
2014-02-04 03:37:17 +00:00
|
|
|
final int pointY = key.getY() + mKeyPreviewDrawParams.getVisibleOffset();
|
2012-12-03 06:49:10 +00:00
|
|
|
moreKeysPanel.showMoreKeysPanel(this, this, pointX, pointY, mKeyboardActionListener);
|
2013-08-01 07:55:55 +00:00
|
|
|
tracker.onShowMoreKeysPanel(moreKeysPanel);
|
2013-12-13 08:09:16 +00:00
|
|
|
// TODO: Implement zoom in animation of more keys panel.
|
|
|
|
dismissKeyPreviewWithoutDelay(key);
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 08:09:16 +00:00
|
|
|
public boolean isInDraggingFinger() {
|
2013-01-22 05:32:47 +00:00
|
|
|
if (isShowingMoreKeysPanel()) {
|
2011-07-11 01:09:15 +00:00
|
|
|
return true;
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
2013-12-13 08:09:16 +00:00
|
|
|
return PointerTracker.isAnyInDraggingFinger();
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 05:41:33 +00:00
|
|
|
@Override
|
|
|
|
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
2013-04-25 09:26:24 +00:00
|
|
|
locatePreviewPlacerView();
|
2013-12-24 09:03:17 +00:00
|
|
|
panel.showInParent(mDrawingPreviewPlacerView);
|
2013-01-21 05:41:33 +00:00
|
|
|
mMoreKeysPanel = panel;
|
2013-01-22 05:32:47 +00:00
|
|
|
dimEntireKeyboard(true /* dimmed */);
|
2013-01-21 05:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingMoreKeysPanel() {
|
2013-01-22 05:32:47 +00:00
|
|
|
return mMoreKeysPanel != null && mMoreKeysPanel.isShowingInParent();
|
2013-01-21 05:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-03 12:02:35 +00:00
|
|
|
public void onCancelMoreKeysPanel() {
|
2013-01-21 05:41:33 +00:00
|
|
|
PointerTracker.dismissAllMoreKeysPanels();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-03 12:02:35 +00:00
|
|
|
public void onDismissMoreKeysPanel() {
|
2013-01-21 05:41:33 +00:00
|
|
|
dimEntireKeyboard(false /* dimmed */);
|
|
|
|
if (isShowingMoreKeysPanel()) {
|
2013-12-16 07:13:12 +00:00
|
|
|
mMoreKeysPanel.removeFromParent();
|
2013-01-21 05:41:33 +00:00
|
|
|
mMoreKeysPanel = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 07:22:53 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer() {
|
|
|
|
mKeyTimerHandler.startDoubleTapShiftKeyTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelDoubleTapShiftKeyTimer() {
|
|
|
|
mKeyTimerHandler.cancelDoubleTapShiftKeyTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInDoubleTapShiftKeyTimeout() {
|
|
|
|
return mKeyTimerHandler.isInDoubleTapShiftKeyTimeout();
|
|
|
|
}
|
|
|
|
|
2011-07-01 04:07:59 +00:00
|
|
|
@Override
|
2012-08-30 08:42:49 +00:00
|
|
|
public boolean onTouchEvent(final MotionEvent me) {
|
2011-08-29 09:36:26 +00:00
|
|
|
if (getKeyboard() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-31 09:13:42 +00:00
|
|
|
if (mNonDistinctMultitouchHelper != null) {
|
|
|
|
if (me.getPointerCount() > 1 && mKeyTimerHandler.isInKeyRepeat()) {
|
|
|
|
// Key repeating timer will be canceled if 2 or more keys are in action.
|
2013-12-13 08:09:16 +00:00
|
|
|
mKeyTimerHandler.cancelKeyRepeatTimers();
|
2013-07-31 09:13:42 +00:00
|
|
|
}
|
|
|
|
// Non distinct multitouch screen support
|
2013-12-13 08:09:16 +00:00
|
|
|
mNonDistinctMultitouchHelper.processMotionEvent(me, mKeyDetector);
|
2013-07-31 09:13:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-07-31 08:32:41 +00:00
|
|
|
return processMotionEvent(me);
|
2011-08-23 06:57:51 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public boolean processMotionEvent(final MotionEvent me) {
|
2013-08-01 08:48:04 +00:00
|
|
|
final int index = me.getActionIndex();
|
|
|
|
final int id = me.getPointerId(index);
|
2013-12-13 08:09:16 +00:00
|
|
|
final PointerTracker tracker = PointerTracker.getPointerTracker(id);
|
|
|
|
// When a more keys panel is showing, we should ignore other fingers' single touch events
|
|
|
|
// other than the finger that is showing the more keys panel.
|
|
|
|
if (isShowingMoreKeysPanel() && !tracker.isShowingMoreKeysPanel()
|
|
|
|
&& PointerTracker.getActivePointerTrackerCount() == 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
tracker.processMotionEvent(me, mKeyDetector);
|
2011-07-01 04:07:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:00:45 +00:00
|
|
|
public void cancelAllOngoingEvents() {
|
2013-01-21 06:57:32 +00:00
|
|
|
mKeyTimerHandler.cancelAllMessages();
|
|
|
|
mDrawingHandler.cancelAllMessages();
|
2013-07-25 10:00:45 +00:00
|
|
|
dismissAllKeyPreviews();
|
|
|
|
dismissGestureFloatingPreviewText();
|
|
|
|
dismissSlidingKeyInputPreview();
|
|
|
|
PointerTracker.dismissAllMoreKeysPanels();
|
|
|
|
PointerTracker.cancelAllPointerTrackers();
|
2013-01-21 06:57:32 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 04:07:59 +00:00
|
|
|
public void closing() {
|
2013-07-25 10:00:45 +00:00
|
|
|
cancelAllOngoingEvents();
|
2013-01-22 05:32:47 +00:00
|
|
|
mMoreKeysKeyboardCache.clear();
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-30 09:40:12 +00:00
|
|
|
public void onHideWindow() {
|
2014-06-23 05:20:21 +00:00
|
|
|
onDismissMoreKeysPanel();
|
2014-06-02 09:43:07 +00:00
|
|
|
final MainKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
|
|
|
|
if (accessibilityDelegate != null) {
|
|
|
|
accessibilityDelegate.onHideWindow();
|
2014-05-01 08:06:40 +00:00
|
|
|
}
|
2014-04-30 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 21:06:26 +00:00
|
|
|
/**
|
2014-05-26 03:51:37 +00:00
|
|
|
* {@inheritDoc}
|
2011-07-26 21:06:26 +00:00
|
|
|
*/
|
2012-04-02 14:13:09 +00:00
|
|
|
@Override
|
2014-05-26 03:51:37 +00:00
|
|
|
public boolean onHoverEvent(final MotionEvent event) {
|
2014-06-02 09:43:07 +00:00
|
|
|
final MainKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
|
|
|
|
if (accessibilityDelegate != null) {
|
|
|
|
return accessibilityDelegate.onHoverEvent(event);
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
2014-05-26 03:51:37 +00:00
|
|
|
return super.onHoverEvent(event);
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|
2011-12-17 18:06:20 +00:00
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public void updateShortcutKey(final boolean available) {
|
2011-12-17 23:00:07 +00:00
|
|
|
final Keyboard keyboard = getKeyboard();
|
2012-10-29 06:14:20 +00:00
|
|
|
if (keyboard == null) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-29 05:46:34 +00:00
|
|
|
final Key shortcutKey = keyboard.getKey(Constants.CODE_SHORTCUT);
|
2012-10-29 06:14:20 +00:00
|
|
|
if (shortcutKey == null) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-17 23:00:07 +00:00
|
|
|
shortcutKey.setEnabled(available);
|
|
|
|
invalidateKey(shortcutKey);
|
2011-12-17 19:55:17 +00:00
|
|
|
}
|
|
|
|
|
2012-08-30 08:42:49 +00:00
|
|
|
public void startDisplayLanguageOnSpacebar(final boolean subtypeChanged,
|
2014-03-28 07:03:00 +00:00
|
|
|
final int languageOnSpacebarFormatType,
|
|
|
|
final boolean hasMultipleEnabledIMEsOrSubtypes) {
|
2014-08-11 10:13:07 +00:00
|
|
|
if (subtypeChanged) {
|
|
|
|
KeyPreviewView.clearTextCache();
|
|
|
|
}
|
2014-03-28 07:03:00 +00:00
|
|
|
mLanguageOnSpacebarFormatType = languageOnSpacebarFormatType;
|
2012-05-24 09:20:26 +00:00
|
|
|
mHasMultipleEnabledIMEsOrSubtypes = hasMultipleEnabledIMEsOrSubtypes;
|
|
|
|
final ObjectAnimator animator = mLanguageOnSpacebarFadeoutAnimator;
|
2012-03-14 03:33:03 +00:00
|
|
|
if (animator == null) {
|
2014-03-28 07:03:00 +00:00
|
|
|
mLanguageOnSpacebarFormatType = LanguageOnSpacebarHelper.FORMAT_TYPE_NONE;
|
2012-03-13 03:44:03 +00:00
|
|
|
} else {
|
2014-03-28 07:03:00 +00:00
|
|
|
if (subtypeChanged
|
|
|
|
&& languageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) {
|
2012-07-19 08:20:54 +00:00
|
|
|
setLanguageOnSpacebarAnimAlpha(Constants.Color.ALPHA_OPAQUE);
|
2012-03-16 05:05:20 +00:00
|
|
|
if (animator.isStarted()) {
|
|
|
|
animator.cancel();
|
|
|
|
}
|
2012-03-14 03:33:03 +00:00
|
|
|
animator.start();
|
2012-03-13 05:15:39 +00:00
|
|
|
} else {
|
2012-03-16 05:05:20 +00:00
|
|
|
if (!animator.isStarted()) {
|
|
|
|
mLanguageOnSpacebarAnimAlpha = mLanguageOnSpacebarFinalAlpha;
|
|
|
|
}
|
2012-03-13 05:15:39 +00:00
|
|
|
}
|
2012-03-13 03:44:03 +00:00
|
|
|
}
|
2011-12-17 23:13:36 +00:00
|
|
|
invalidateKey(mSpaceKey);
|
|
|
|
}
|
|
|
|
|
2013-01-22 05:32:47 +00:00
|
|
|
private void dimEntireKeyboard(final boolean dimmed) {
|
2013-01-21 07:36:25 +00:00
|
|
|
final boolean needsRedrawing = mNeedsToDimEntireKeyboard != dimmed;
|
|
|
|
mNeedsToDimEntireKeyboard = dimmed;
|
|
|
|
if (needsRedrawing) {
|
|
|
|
invalidateAllKeys();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(final Canvas canvas) {
|
|
|
|
super.onDraw(canvas);
|
|
|
|
|
|
|
|
// Overlay a dark rectangle to dim.
|
|
|
|
if (mNeedsToDimEntireKeyboard) {
|
2013-04-11 03:08:36 +00:00
|
|
|
canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mBackgroundDimAlphaPaint);
|
2013-01-21 07:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-17 18:06:20 +00:00
|
|
|
@Override
|
2012-08-30 08:42:49 +00:00
|
|
|
protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint,
|
|
|
|
final KeyDrawParams params) {
|
2012-03-14 10:49:13 +00:00
|
|
|
if (key.altCodeWhileTyping() && key.isEnabled()) {
|
2012-03-14 05:46:22 +00:00
|
|
|
params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha;
|
|
|
|
}
|
2014-05-15 08:28:54 +00:00
|
|
|
super.onDrawKeyTopVisuals(key, canvas, paint, params);
|
2013-08-12 09:05:11 +00:00
|
|
|
final int code = key.getCode();
|
|
|
|
if (code == Constants.CODE_SPACE) {
|
2014-05-15 08:28:54 +00:00
|
|
|
// If input language are explicitly selected.
|
|
|
|
if (mLanguageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) {
|
|
|
|
drawLanguageOnSpacebar(key, canvas, paint);
|
|
|
|
}
|
2011-12-17 23:13:36 +00:00
|
|
|
// Whether space key needs to show the "..." popup hint for special purposes
|
2012-05-24 09:20:26 +00:00
|
|
|
if (key.isLongPressEnabled() && mHasMultipleEnabledIMEsOrSubtypes) {
|
2012-01-25 03:57:28 +00:00
|
|
|
drawKeyPopupHint(key, canvas, paint, params);
|
2011-12-17 23:13:36 +00:00
|
|
|
}
|
2013-08-12 09:05:11 +00:00
|
|
|
} else if (code == Constants.CODE_LANGUAGE_SWITCH) {
|
2012-05-24 09:20:26 +00:00
|
|
|
drawKeyPopupHint(key, canvas, paint, params);
|
2011-12-17 18:06:20 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-17 23:13:36 +00:00
|
|
|
|
2013-09-06 08:08:34 +00:00
|
|
|
private boolean fitsTextIntoWidth(final int width, final String text, final Paint paint) {
|
|
|
|
final int maxTextWidth = width - mLanguageOnSpacebarHorizontalMargin * 2;
|
2012-04-26 05:40:47 +00:00
|
|
|
paint.setTextScaleX(1.0f);
|
2013-12-13 08:09:16 +00:00
|
|
|
final float textWidth = TypefaceUtils.getStringWidth(text, paint);
|
2012-10-29 06:14:20 +00:00
|
|
|
if (textWidth < width) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-26 05:40:47 +00:00
|
|
|
|
2013-09-06 08:08:34 +00:00
|
|
|
final float scaleX = maxTextWidth / textWidth;
|
2012-10-29 06:14:20 +00:00
|
|
|
if (scaleX < MINIMUM_XSCALE_OF_LANGUAGE_NAME) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-26 05:40:47 +00:00
|
|
|
|
|
|
|
paint.setTextScaleX(scaleX);
|
2013-12-13 08:09:16 +00:00
|
|
|
return TypefaceUtils.getStringWidth(text, paint) < maxTextWidth;
|
2012-04-26 05:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Layout language name on spacebar.
|
2013-09-06 08:08:34 +00:00
|
|
|
private String layoutLanguageOnSpacebar(final Paint paint,
|
2013-04-11 03:08:36 +00:00
|
|
|
final InputMethodSubtype subtype, final int width) {
|
2012-04-26 05:40:47 +00:00
|
|
|
// Choose appropriate language name to fit into the width.
|
2014-03-28 07:03:00 +00:00
|
|
|
if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarHelper.FORMAT_TYPE_FULL_LOCALE) {
|
|
|
|
final String fullText = SpacebarLanguageUtils.getFullDisplayName(subtype);
|
|
|
|
if (fitsTextIntoWidth(width, fullText, paint)) {
|
|
|
|
return fullText;
|
|
|
|
}
|
2012-04-26 05:40:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 03:25:41 +00:00
|
|
|
final String middleText = SpacebarLanguageUtils.getMiddleDisplayName(subtype);
|
2012-10-29 06:14:20 +00:00
|
|
|
if (fitsTextIntoWidth(width, middleText, paint)) {
|
|
|
|
return middleText;
|
2011-12-17 23:13:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-26 05:40:47 +00:00
|
|
|
return "";
|
2011-12-17 23:13:36 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 08:28:54 +00:00
|
|
|
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
|
2013-08-12 09:05:11 +00:00
|
|
|
final int width = key.getWidth();
|
|
|
|
final int height = key.getHeight();
|
2014-05-15 08:28:54 +00:00
|
|
|
paint.setTextAlign(Align.CENTER);
|
|
|
|
paint.setTypeface(Typeface.DEFAULT);
|
|
|
|
paint.setTextSize(mLanguageOnSpacebarTextSize);
|
|
|
|
final InputMethodSubtype subtype = getKeyboard().mId.mSubtype;
|
|
|
|
final String language = layoutLanguageOnSpacebar(paint, subtype, width);
|
|
|
|
// Draw language text with shadow
|
|
|
|
final float descent = paint.descent();
|
|
|
|
final float textHeight = -paint.ascent() + descent;
|
|
|
|
final float baseline = height / 2 + textHeight / 2;
|
|
|
|
if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
|
|
|
|
paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
|
|
|
|
mLanguageOnSpacebarTextShadowColor);
|
|
|
|
} else {
|
2014-05-13 02:19:43 +00:00
|
|
|
paint.clearShadowLayer();
|
2011-12-17 23:13:36 +00:00
|
|
|
}
|
2014-05-15 08:28:54 +00:00
|
|
|
paint.setColor(mLanguageOnSpacebarTextColor);
|
|
|
|
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
|
|
|
canvas.drawText(language, width / 2, baseline - descent, paint);
|
|
|
|
paint.clearShadowLayer();
|
|
|
|
paint.setTextScaleX(1.0f);
|
2011-12-17 23:13:36 +00:00
|
|
|
}
|
2013-07-30 11:29:19 +00:00
|
|
|
|
2013-08-01 09:01:48 +00:00
|
|
|
@Override
|
2013-07-30 11:29:19 +00:00
|
|
|
public void deallocateMemory() {
|
2013-08-01 09:01:48 +00:00
|
|
|
super.deallocateMemory();
|
2013-12-24 09:26:55 +00:00
|
|
|
mDrawingPreviewPlacerView.deallocateMemory();
|
2013-07-30 11:29:19 +00:00
|
|
|
}
|
2011-07-01 04:07:59 +00:00
|
|
|
}
|