mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Support multiple key preview
Bug: 4298393 Change-Id: Ibd3681f7255c85e3602e1af4ace8f8e7fce3fb06
This commit is contained in:
parent
ff6ad279e6
commit
4692af50da
@ -87,8 +87,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
private final KeyDrawParams mKeyDrawParams;
|
private final KeyDrawParams mKeyDrawParams;
|
||||||
|
|
||||||
// Key preview
|
// Key preview
|
||||||
|
private final int mKeyPreviewLayoutId;
|
||||||
private final KeyPreviewDrawParams mKeyPreviewDrawParams;
|
private final KeyPreviewDrawParams mKeyPreviewDrawParams;
|
||||||
private final TextView mPreviewText;
|
|
||||||
private boolean mShowKeyPreviewPopup = true;
|
private boolean mShowKeyPreviewPopup = true;
|
||||||
private final int mDelayBeforePreview;
|
private final int mDelayBeforePreview;
|
||||||
private int mDelayAfterPreview;
|
private int mDelayAfterPreview;
|
||||||
@ -139,9 +139,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
keyboardView.showKey(msg.arg1, tracker);
|
keyboardView.showKey(msg.arg1, tracker);
|
||||||
break;
|
break;
|
||||||
case MSG_DISMISS_KEY_PREVIEW:
|
case MSG_DISMISS_KEY_PREVIEW:
|
||||||
if (keyboardView.mPreviewText != null) {
|
tracker.getKeyPreviewText().setVisibility(View.INVISIBLE);
|
||||||
keyboardView.mPreviewText.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +148,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
removeMessages(MSG_SHOW_KEY_PREVIEW);
|
removeMessages(MSG_SHOW_KEY_PREVIEW);
|
||||||
final KeyboardView keyboardView = getOuterInstance();
|
final KeyboardView keyboardView = getOuterInstance();
|
||||||
if (keyboardView == null) return;
|
if (keyboardView == null) return;
|
||||||
if (keyboardView.mPreviewText.getVisibility() == VISIBLE || delay == 0) {
|
if (tracker.getKeyPreviewText().getVisibility() == VISIBLE || delay == 0) {
|
||||||
// Show right away, if it's already visible and finger is moving around
|
// Show right away, if it's already visible and finger is moving around
|
||||||
keyboardView.showKey(keyIndex, tracker);
|
keyboardView.showKey(keyIndex, tracker);
|
||||||
} else {
|
} else {
|
||||||
@ -171,6 +169,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
|
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelDismissKeyPreview(PointerTracker tracker) {
|
||||||
|
removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
|
||||||
|
}
|
||||||
|
|
||||||
public void cancelAllDismissKeyPreviews() {
|
public void cancelAllDismissKeyPreviews() {
|
||||||
removeMessages(MSG_DISMISS_KEY_PREVIEW);
|
removeMessages(MSG_DISMISS_KEY_PREVIEW);
|
||||||
}
|
}
|
||||||
@ -317,11 +319,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
|
|
||||||
mKeyDrawParams = new KeyDrawParams(a);
|
mKeyDrawParams = new KeyDrawParams(a);
|
||||||
mKeyPreviewDrawParams = new KeyPreviewDrawParams(a, mKeyDrawParams);
|
mKeyPreviewDrawParams = new KeyPreviewDrawParams(a, mKeyDrawParams);
|
||||||
final int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
|
mKeyPreviewLayoutId = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
|
||||||
if (previewLayout != 0) {
|
if (mKeyPreviewLayoutId == 0) {
|
||||||
mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null);
|
|
||||||
} else {
|
|
||||||
mPreviewText = null;
|
|
||||||
mShowKeyPreviewPopup = false;
|
mShowKeyPreviewPopup = false;
|
||||||
}
|
}
|
||||||
mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f);
|
mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f);
|
||||||
@ -730,6 +729,17 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
mDrawingHandler.cancelAllMessages();
|
mDrawingHandler.cancelAllMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by {@link PointerTracker} constructor to create a TextView.
|
||||||
|
@Override
|
||||||
|
public TextView inflateKeyPreviewText() {
|
||||||
|
final Context context = getContext();
|
||||||
|
if (mKeyPreviewLayoutId != 0) {
|
||||||
|
return (TextView)LayoutInflater.from(context).inflate(mKeyPreviewLayoutId, null);
|
||||||
|
} else {
|
||||||
|
return new TextView(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showKeyPreview(int keyIndex, PointerTracker tracker) {
|
public void showKeyPreview(int keyIndex, PointerTracker tracker) {
|
||||||
if (mShowKeyPreviewPopup) {
|
if (mShowKeyPreviewPopup) {
|
||||||
@ -760,15 +770,15 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Introduce minimum duration for displaying key previews
|
// TODO: Introduce minimum duration for displaying key previews
|
||||||
// TODO: Display up to two key previews when the user presses two keys at the same time
|
|
||||||
private void showKey(final int keyIndex, PointerTracker tracker) {
|
private void showKey(final int keyIndex, PointerTracker tracker) {
|
||||||
final TextView previewText = mPreviewText;
|
final TextView previewText = tracker.getKeyPreviewText();
|
||||||
// If the key preview has no parent view yet, add it to the ViewGroup which can place
|
// If the key preview has no parent view yet, add it to the ViewGroup which can place
|
||||||
// key preview absolutely in SoftInputWindow.
|
// key preview absolutely in SoftInputWindow.
|
||||||
if (previewText.getParent() == null) {
|
if (previewText.getParent() == null) {
|
||||||
addKeyPreview(previewText);
|
addKeyPreview(previewText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mDrawingHandler.cancelDismissKeyPreview(tracker);
|
||||||
final Key key = tracker.getKey(keyIndex);
|
final Key key = tracker.getKey(keyIndex);
|
||||||
// If keyIndex is invalid or IME is already closed, we must not show key preview.
|
// If keyIndex is invalid or IME is already closed, we must not show key preview.
|
||||||
// Trying to show key preview while root window is closed causes
|
// Trying to show key preview while root window is closed causes
|
||||||
@ -776,7 +786,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
if (key == null)
|
if (key == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mDrawingHandler.cancelAllDismissKeyPreviews();
|
|
||||||
final KeyPreviewDrawParams params = mKeyPreviewDrawParams;
|
final KeyPreviewDrawParams params = mKeyPreviewDrawParams;
|
||||||
final int keyDrawX = key.mX + key.mVisualInsetsLeft;
|
final int keyDrawX = key.mX + key.mVisualInsetsLeft;
|
||||||
final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
|
final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
|
||||||
@ -858,7 +867,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void closing() {
|
public void closing() {
|
||||||
mPreviewText.setVisibility(View.GONE);
|
PointerTracker.dismissAllKeyPreviews();
|
||||||
cancelAllMessages();
|
cancelAllMessages();
|
||||||
|
|
||||||
mDirtyRect.union(0, 0, getWidth(), getHeight());
|
mDirtyRect.union(0, 0, getWidth(), getHeight());
|
||||||
|
@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
|
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
@ -64,6 +65,7 @@ public class PointerTracker {
|
|||||||
|
|
||||||
public interface DrawingProxy {
|
public interface DrawingProxy {
|
||||||
public void invalidateKey(Key key);
|
public void invalidateKey(Key key);
|
||||||
|
public TextView inflateKeyPreviewText();
|
||||||
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
public void showKeyPreview(int keyIndex, PointerTracker tracker);
|
||||||
public void cancelShowKeyPreview(PointerTracker tracker);
|
public void cancelShowKeyPreview(PointerTracker tracker);
|
||||||
public void dismissKeyPreview(PointerTracker tracker);
|
public void dismissKeyPreview(PointerTracker tracker);
|
||||||
@ -100,6 +102,7 @@ public class PointerTracker {
|
|||||||
private Keyboard mKeyboard;
|
private Keyboard mKeyboard;
|
||||||
private List<Key> mKeys;
|
private List<Key> mKeys;
|
||||||
private int mKeyQuarterWidthSquared;
|
private int mKeyQuarterWidthSquared;
|
||||||
|
private final TextView mKeyPreviewText;
|
||||||
|
|
||||||
// The position and time at which first down event occurred.
|
// The position and time at which first down event occurred.
|
||||||
private long mDownTime;
|
private long mDownTime;
|
||||||
@ -215,6 +218,11 @@ public class PointerTracker {
|
|||||||
mListener = handler.getKeyboardActionListener();
|
mListener = handler.getKeyboardActionListener();
|
||||||
mDrawingProxy = handler.getDrawingProxy();
|
mDrawingProxy = handler.getDrawingProxy();
|
||||||
mTimerProxy = handler.getTimerProxy();
|
mTimerProxy = handler.getTimerProxy();
|
||||||
|
mKeyPreviewText = mDrawingProxy.inflateKeyPreviewText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getKeyPreviewText() {
|
||||||
|
return mKeyPreviewText;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if keyboard has been changed by this callback.
|
// Returns true if keyboard has been changed by this callback.
|
||||||
|
Loading…
Reference in New Issue
Block a user