mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Move MoreKeysPanel.Controller implementation to MainKeyboardView
Change-Id: Iffa298d51ca21a7dcd1e77c633217532d96d2cf5
This commit is contained in:
parent
00f8474c73
commit
d9449ccf3c
@ -67,9 +67,6 @@
|
||||
<!-- Amount to offset the touch Y coordinate by, for bias correction. -->
|
||||
<attr name="verticalCorrection" format="dimension" />
|
||||
|
||||
<!-- Layout resource for more keys panel -->
|
||||
<attr name="moreKeysLayout" format="reference" />
|
||||
|
||||
<attr name="backgroundDimAlpha" format="integer" />
|
||||
|
||||
<!-- Attributes for PreviewPlacerView -->
|
||||
@ -126,6 +123,8 @@
|
||||
<attr name="longPressShiftKeyTimeout" format="integer" />
|
||||
<!-- Ignore special key timeout while typing in millisecond. -->
|
||||
<attr name="ignoreAltCodeKeyTimeout" format="integer" />
|
||||
<!-- Layout resource for more keys keyboard -->
|
||||
<attr name="moreKeysKeyboardLayout" format="reference" />
|
||||
<!-- More keys keyboard will shown at touched point. -->
|
||||
<attr name="showMoreKeysKeyboardAtTouchedPoint" format="boolean" />
|
||||
<!-- Static threshold for gesture after fast typing (msec) -->
|
||||
|
@ -59,7 +59,6 @@
|
||||
<item name="keyPreviewHeight">@dimen/key_preview_height</item>
|
||||
<item name="keyPreviewTextRatio">@fraction/key_preview_text_ratio</item>
|
||||
<item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
|
||||
<item name="moreKeysLayout">@layout/more_keys_keyboard</item>
|
||||
<item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
|
||||
<item name="keyTextShadowColor">@color/key_text_shadow_color_default</item>
|
||||
<item name="keyTextShadowRadius">2.75</item>
|
||||
@ -89,6 +88,7 @@
|
||||
<item name="longPressKeyTimeout">@integer/config_long_press_key_timeout</item>
|
||||
<item name="longPressShiftKeyTimeout">@integer/config_long_press_shift_key_timeout</item>
|
||||
<item name="ignoreAltCodeKeyTimeout">@integer/config_ignore_alt_code_key_timeout</item>
|
||||
<item name="moreKeysKeyboardLayout">@layout/more_keys_keyboard</item>
|
||||
<item name="showMoreKeysKeyboardAtTouchedPoint">@bool/config_show_more_keys_keyboard_at_touched_point</item>
|
||||
<item name="languageOnSpacebarFinalAlpha">@integer/config_language_on_spacebar_final_alpha</item>
|
||||
<item name="languageOnSpacebarFadeoutAnimator">@anim/language_on_spacebar_fadeout</item>
|
||||
|
@ -60,7 +60,6 @@ import java.util.HashSet;
|
||||
* A view that renders a virtual {@link Keyboard}.
|
||||
*
|
||||
* @attr ref R.styleable#KeyboardView_keyBackground
|
||||
* @attr ref R.styleable#KeyboardView_moreKeysLayout
|
||||
* @attr ref R.styleable#KeyboardView_keyPreviewLayout
|
||||
* @attr ref R.styleable#KeyboardView_keyPreviewOffset
|
||||
* @attr ref R.styleable#KeyboardView_keyPreviewHeight
|
||||
@ -103,8 +102,8 @@ import java.util.HashSet;
|
||||
* @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintActivatedColor
|
||||
* @attr ref R.styleable#Keyboard_Key_keyPreviewTextColor
|
||||
*/
|
||||
public class KeyboardView extends View implements PointerTracker.DrawingProxy,
|
||||
MoreKeysPanel.Controller {
|
||||
// TODO: Move PointerTracker.DrawingProxy to MainKeyboardView
|
||||
public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||
private static final String TAG = KeyboardView.class.getSimpleName();
|
||||
|
||||
// XML attributes
|
||||
@ -115,7 +114,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
|
||||
private final float mKeyShiftedLetterHintPadding;
|
||||
private final float mKeyTextShadowRadius;
|
||||
protected final float mVerticalCorrection;
|
||||
protected final int mMoreKeysLayout;
|
||||
protected final Drawable mKeyBackground;
|
||||
protected final Rect mKeyBackgroundPadding = new Rect();
|
||||
private final int mBackgroundDimAlpha;
|
||||
@ -136,13 +134,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
|
||||
protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams();
|
||||
|
||||
// Preview placer view
|
||||
private final PreviewPlacerView mPreviewPlacerView;
|
||||
// TODO: Move PreviewPlacerView to MainKeyboardView
|
||||
protected final PreviewPlacerView mPreviewPlacerView;
|
||||
private final int[] mOriginCoords = CoordinateUtils.newInstance();
|
||||
|
||||
// More keys panel (used by both more keys keyboard and more suggestions view)
|
||||
// TODO: Consider extending to support multiple more keys panels
|
||||
protected MoreKeysPanel mMoreKeysPanel;
|
||||
|
||||
// Key preview
|
||||
private static final int PREVIEW_ALPHA = 240;
|
||||
private final int mKeyPreviewLayoutId;
|
||||
@ -287,8 +282,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
|
||||
}
|
||||
mVerticalCorrection = keyboardViewAttr.getDimension(
|
||||
R.styleable.KeyboardView_verticalCorrection, 0);
|
||||
mMoreKeysLayout = keyboardViewAttr.getResourceId(
|
||||
R.styleable.KeyboardView_moreKeysLayout, 0);
|
||||
mBackgroundDimAlpha = keyboardViewAttr.getInt(
|
||||
R.styleable.KeyboardView_backgroundDimAlpha, 0);
|
||||
mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt(
|
||||
@ -1027,42 +1020,11 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy,
|
||||
public void closing() {
|
||||
dismissAllKeyPreviews();
|
||||
cancelAllMessages();
|
||||
onCancelMoreKeysPanel();
|
||||
mInvalidateAllKeys = true;
|
||||
mKeyboard = null;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
onDismissMoreKeysPanel();
|
||||
}
|
||||
mMoreKeysPanel = panel;
|
||||
mPreviewPlacerView.addView(mMoreKeysPanel.getContainerView());
|
||||
}
|
||||
|
||||
public boolean isShowingMoreKeysPanel() {
|
||||
return (mMoreKeysPanel != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelMoreKeysPanel() {
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
mMoreKeysPanel.dismissMoreKeysPanel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDismissMoreKeysPanel() {
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView());
|
||||
mMoreKeysPanel = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
|
@ -85,6 +85,7 @@ import java.util.WeakHashMap;
|
||||
* @attr ref R.styleable#MainKeyboardView_longPressKeyTimeout
|
||||
* @attr ref R.styleable#MainKeyboardView_longPressShiftKeyTimeout
|
||||
* @attr ref R.styleable#MainKeyboardView_ignoreAltCodeKeyTimeout
|
||||
* @attr ref R.styleable#MainKeyboardView_moreKeysKeyboardLayout
|
||||
* @attr ref R.styleable#MainKeyboardView_showMoreKeysKeyboardAtTouchPoint
|
||||
* @attr ref R.styleable#MainKeyboardView_gestureStaticTimeThresholdAfterFastTyping
|
||||
* @attr ref R.styleable#MainKeyboardView_gestureDetectFastMoveSpeedThreshold
|
||||
@ -99,7 +100,7 @@ import java.util.WeakHashMap;
|
||||
* @attr ref R.styleable#MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration
|
||||
*/
|
||||
public final class MainKeyboardView extends KeyboardView implements PointerTracker.KeyEventHandler,
|
||||
TouchScreenRegulator.ProcessMotionEvent {
|
||||
MoreKeysPanel.Controller, TouchScreenRegulator.ProcessMotionEvent {
|
||||
private static final String TAG = MainKeyboardView.class.getSimpleName();
|
||||
|
||||
// TODO: Kill process when the usability study mode was changed.
|
||||
@ -137,11 +138,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
// More keys keyboard
|
||||
private final WeakHashMap<Key, MoreKeysPanel> mMoreKeysPanelCache =
|
||||
new WeakHashMap<Key, MoreKeysPanel>();
|
||||
private final int mMoreKeysLayout;
|
||||
private final boolean mConfigShowMoreKeysKeyboardAtTouchedPoint;
|
||||
// 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;
|
||||
|
||||
private final TouchScreenRegulator mTouchScreenRegulator;
|
||||
|
||||
protected KeyDetector mKeyDetector;
|
||||
private KeyDetector mKeyDetector;
|
||||
private final boolean mHasDistinctMultitouch;
|
||||
private int mOldPointerCount = 1;
|
||||
private Key mOldKey;
|
||||
@ -402,38 +407,41 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
res, R.array.phantom_sudden_move_event_device_list));
|
||||
PointerTracker.init(needsPhantomSuddenMoveEventHack);
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(
|
||||
final TypedArray mainKeyboardViewAttr = context.obtainStyledAttributes(
|
||||
attrs, R.styleable.MainKeyboardView, defStyle, R.style.MainKeyboardView);
|
||||
mAutoCorrectionSpacebarLedEnabled = a.getBoolean(
|
||||
mAutoCorrectionSpacebarLedEnabled = mainKeyboardViewAttr.getBoolean(
|
||||
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
|
||||
mAutoCorrectionSpacebarLedIcon = a.getDrawable(
|
||||
mAutoCorrectionSpacebarLedIcon = mainKeyboardViewAttr.getDrawable(
|
||||
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon);
|
||||
mSpacebarTextRatio = a.getFraction(
|
||||
mSpacebarTextRatio = mainKeyboardViewAttr.getFraction(
|
||||
R.styleable.MainKeyboardView_spacebarTextRatio, 1, 1, 1.0f);
|
||||
mSpacebarTextColor = a.getColor(R.styleable.MainKeyboardView_spacebarTextColor, 0);
|
||||
mSpacebarTextShadowColor = a.getColor(
|
||||
mSpacebarTextColor = mainKeyboardViewAttr.getColor(
|
||||
R.styleable.MainKeyboardView_spacebarTextColor, 0);
|
||||
mSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
|
||||
R.styleable.MainKeyboardView_spacebarTextShadowColor, 0);
|
||||
mLanguageOnSpacebarFinalAlpha = a.getInt(
|
||||
mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarFinalAlpha,
|
||||
Constants.Color.ALPHA_OPAQUE);
|
||||
final int languageOnSpacebarFadeoutAnimatorResId = a.getResourceId(
|
||||
final int languageOnSpacebarFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_languageOnSpacebarFadeoutAnimator, 0);
|
||||
final int altCodeKeyWhileTypingFadeoutAnimatorResId = a.getResourceId(
|
||||
final int altCodeKeyWhileTypingFadeoutAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeoutAnimator, 0);
|
||||
final int altCodeKeyWhileTypingFadeinAnimatorResId = a.getResourceId(
|
||||
final int altCodeKeyWhileTypingFadeinAnimatorResId = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_altCodeKeyWhileTypingFadeinAnimator, 0);
|
||||
|
||||
final float keyHysteresisDistance = a.getDimension(
|
||||
final float keyHysteresisDistance = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistance, 0);
|
||||
final float keyHysteresisDistanceForSlidingModifier = a.getDimension(
|
||||
final float keyHysteresisDistanceForSlidingModifier = mainKeyboardViewAttr.getDimension(
|
||||
R.styleable.MainKeyboardView_keyHysteresisDistanceForSlidingModifier, 0);
|
||||
mKeyDetector = new KeyDetector(
|
||||
keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier);
|
||||
mKeyTimerHandler = new KeyTimerHandler(this, a);
|
||||
mConfigShowMoreKeysKeyboardAtTouchedPoint = a.getBoolean(
|
||||
mKeyTimerHandler = new KeyTimerHandler(this, mainKeyboardViewAttr);
|
||||
mMoreKeysLayout = mainKeyboardViewAttr.getResourceId(
|
||||
R.styleable.MainKeyboardView_moreKeysKeyboardLayout, 0);
|
||||
mConfigShowMoreKeysKeyboardAtTouchedPoint = mainKeyboardViewAttr.getBoolean(
|
||||
R.styleable.MainKeyboardView_showMoreKeysKeyboardAtTouchedPoint, false);
|
||||
PointerTracker.setParameters(a);
|
||||
a.recycle();
|
||||
PointerTracker.setParameters(mainKeyboardViewAttr);
|
||||
mainKeyboardViewAttr.recycle();
|
||||
|
||||
mLanguageOnSpacebarFadeoutAnimator = loadObjectAnimator(
|
||||
languageOnSpacebarFadeoutAnimatorResId, this);
|
||||
@ -591,8 +599,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
return onLongPress(parentKey, tracker);
|
||||
}
|
||||
|
||||
// This default implementation returns a more keys panel.
|
||||
protected MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) {
|
||||
private MoreKeysPanel onCreateMoreKeysPanel(final Key parentKey) {
|
||||
if (parentKey.mMoreKeys == null) {
|
||||
return null;
|
||||
}
|
||||
@ -613,14 +620,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a key is long pressed. By default this will open more keys keyboard associated
|
||||
* with this key.
|
||||
* Called when a key is long pressed.
|
||||
* @param parentKey the key that was long pressed
|
||||
* @param tracker the pointer tracker which pressed the parent key
|
||||
* @return true if the long press is handled, false otherwise. Subclasses should call the
|
||||
* method on the base class if the subclass doesn't wish to handle the call.
|
||||
*/
|
||||
protected boolean onLongPress(final Key parentKey, final PointerTracker tracker) {
|
||||
private boolean onLongPress(final Key parentKey, final PointerTracker tracker) {
|
||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||
ResearchLogger.mainKeyboardView_onLongPress();
|
||||
}
|
||||
@ -697,6 +703,38 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
return PointerTracker.isAnyInSlidingKeyInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
onDismissMoreKeysPanel();
|
||||
}
|
||||
mMoreKeysPanel = panel;
|
||||
mPreviewPlacerView.addView(mMoreKeysPanel.getContainerView());
|
||||
}
|
||||
|
||||
public boolean isShowingMoreKeysPanel() {
|
||||
return (mMoreKeysPanel != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelMoreKeysPanel() {
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
mMoreKeysPanel.dismissMoreKeysPanel();
|
||||
}
|
||||
PointerTracker.dismissAllMoreKeysPanels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDismissMoreKeysPanel() {
|
||||
dimEntireKeyboard(false /* dimmed */);
|
||||
if (isShowingMoreKeysPanel()) {
|
||||
mPreviewPlacerView.removeView(mMoreKeysPanel.getContainerView());
|
||||
mMoreKeysPanel = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getPointerCount() {
|
||||
return mOldPointerCount;
|
||||
}
|
||||
@ -853,18 +891,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||
mMoreKeysPanelCache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelMoreKeysPanel() {
|
||||
super.onCancelMoreKeysPanel();
|
||||
PointerTracker.dismissAllMoreKeysPanels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDismissMoreKeysPanel() {
|
||||
dimEntireKeyboard(false /* dimmed */);
|
||||
return super.onDismissMoreKeysPanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives hover events from the input framework.
|
||||
*
|
||||
|
@ -52,7 +52,7 @@ import android.widget.TextView;
|
||||
import com.android.inputmethod.keyboard.Keyboard;
|
||||
import com.android.inputmethod.keyboard.KeyboardActionListener;
|
||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||
import com.android.inputmethod.keyboard.KeyboardView;
|
||||
import com.android.inputmethod.keyboard.MainKeyboardView;
|
||||
import com.android.inputmethod.keyboard.MoreKeysPanel;
|
||||
import com.android.inputmethod.keyboard.ViewLayoutUtils;
|
||||
import com.android.inputmethod.latin.AutoCorrection;
|
||||
@ -81,7 +81,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||
static final boolean DBG = LatinImeLogger.sDBG;
|
||||
|
||||
private final ViewGroup mSuggestionsStrip;
|
||||
KeyboardView mKeyboardView;
|
||||
MainKeyboardView mMainKeyboardView;
|
||||
|
||||
private final View mMoreSuggestionsContainer;
|
||||
private final MoreSuggestionsView mMoreSuggestionsView;
|
||||
@ -610,7 +610,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||
*/
|
||||
public void setListener(final Listener listener, final View inputView) {
|
||||
mListener = listener;
|
||||
mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view);
|
||||
mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view);
|
||||
}
|
||||
|
||||
public void setSuggestions(final SuggestedWords suggestedWords) {
|
||||
@ -676,13 +676,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||
new MoreKeysPanel.Controller() {
|
||||
@Override
|
||||
public boolean onDismissMoreKeysPanel() {
|
||||
mKeyboardView.dimEntireKeyboard(false /* dimmed */);
|
||||
return mKeyboardView.onDismissMoreKeysPanel();
|
||||
mMainKeyboardView.dimEntireKeyboard(false /* dimmed */);
|
||||
return mMainKeyboardView.onDismissMoreKeysPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowMoreKeysPanel(MoreKeysPanel panel) {
|
||||
mKeyboardView.onShowMoreKeysPanel(panel);
|
||||
mMainKeyboardView.onShowMoreKeysPanel(panel);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -728,7 +728,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||
mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
|
||||
mOriginX = mLastX;
|
||||
mOriginY = mLastY;
|
||||
mKeyboardView.dimEntireKeyboard(true /* dimmed */);
|
||||
mMainKeyboardView.dimEntireKeyboard(true /* dimmed */);
|
||||
for (int i = 0; i < params.mSuggestionsCountInStrip; i++) {
|
||||
mWords.get(i).setPressed(false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user