2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-02-27 16:29:35 -08:00
|
|
|
import android.R;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.Selection;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.method.KeyListener;
|
|
|
|
import android.text.method.TextKeyListener;
|
|
|
|
import android.text.style.BackgroundColorSpan;
|
|
|
|
import android.text.style.CharacterStyle;
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
import android.text.style.UnderlineSpan;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.LogPrinter;
|
2012-04-18 14:57:55 -07:00
|
|
|
import android.view.KeyCharacterMap;
|
2012-02-27 16:29:35 -08:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.inputmethod.BaseInputConnection;
|
|
|
|
import android.view.inputmethod.CompletionInfo;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.view.inputmethod.ExtractedText;
|
|
|
|
import android.view.inputmethod.ExtractedTextRequest;
|
|
|
|
import android.view.inputmethod.InputConnection;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
import org.mozilla.gecko.gfx.InputConnectionHandler;
|
|
|
|
|
2012-02-27 16:29:35 -08:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public class GeckoInputConnection
|
|
|
|
extends BaseInputConnection
|
2012-02-27 16:29:22 -08:00
|
|
|
implements TextWatcher, InputConnectionHandler {
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
private static final boolean DEBUG = false;
|
|
|
|
protected static final String LOGTAG = "GeckoInputConnection";
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-27 16:29:44 -08:00
|
|
|
// IME stuff
|
|
|
|
public static final int IME_STATE_DISABLED = 0;
|
|
|
|
public static final int IME_STATE_ENABLED = 1;
|
|
|
|
public static final int IME_STATE_PASSWORD = 2;
|
|
|
|
public static final int IME_STATE_PLUGIN = 3;
|
|
|
|
|
|
|
|
private static final int NOTIFY_IME_RESETINPUTSTATE = 0;
|
|
|
|
private static final int NOTIFY_IME_SETOPENSTATE = 1;
|
|
|
|
private static final int NOTIFY_IME_CANCELCOMPOSITION = 2;
|
|
|
|
private static final int NOTIFY_IME_FOCUSCHANGE = 3;
|
|
|
|
|
2012-03-23 10:32:42 -07:00
|
|
|
private static final int NO_COMPOSITION_STRING = -1;
|
|
|
|
|
2012-02-27 16:29:44 -08:00
|
|
|
private static final Timer mIMETimer = new Timer("GeckoInputConnection Timer");
|
|
|
|
private static int mIMEState;
|
|
|
|
private static String mIMETypeHint;
|
|
|
|
private static String mIMEActionHint;
|
|
|
|
|
|
|
|
// Is a composition active?
|
2012-03-23 10:32:42 -07:00
|
|
|
private int mCompositionStart = NO_COMPOSITION_STRING;
|
2012-04-18 14:57:55 -07:00
|
|
|
private boolean mCommittingText;
|
|
|
|
private KeyCharacterMap mKeyCharacterMap;
|
2012-02-27 16:29:44 -08:00
|
|
|
private Editable mEditable;
|
|
|
|
private Editable.Factory mEditableFactory;
|
|
|
|
private boolean mBatchMode;
|
|
|
|
private ExtractedTextRequest mUpdateRequest;
|
|
|
|
private final ExtractedText mUpdateExtract = new ExtractedText();
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
public static GeckoInputConnection create(View targetView) {
|
|
|
|
if (DEBUG)
|
|
|
|
return new DebugGeckoInputConnection(targetView);
|
|
|
|
else
|
|
|
|
return new GeckoInputConnection(targetView);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
protected GeckoInputConnection(View targetView) {
|
2011-11-18 10:28:17 -08:00
|
|
|
super(targetView, true);
|
|
|
|
|
|
|
|
mEditableFactory = Editable.Factory.getInstance();
|
|
|
|
initEditable("");
|
|
|
|
mIMEState = IME_STATE_DISABLED;
|
|
|
|
mIMETypeHint = "";
|
|
|
|
mIMEActionHint = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean beginBatchEdit() {
|
|
|
|
mBatchMode = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-15 13:35:45 -08:00
|
|
|
public boolean endBatchEdit() {
|
|
|
|
mBatchMode = false;
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-15 13:35:45 -08:00
|
|
|
public boolean commitCompletion(CompletionInfo text) {
|
|
|
|
return commitText(text.getText(), 1);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-15 13:35:45 -08:00
|
|
|
public boolean commitText(CharSequence text, int newCursorPosition) {
|
2012-05-16 22:29:23 -07:00
|
|
|
if (mCommittingText)
|
|
|
|
Log.e(LOGTAG, "Please report this bug:", new IllegalStateException("commitText, but already committing text?!"));
|
|
|
|
|
2012-04-18 14:57:55 -07:00
|
|
|
mCommittingText = true;
|
2011-12-15 13:35:45 -08:00
|
|
|
replaceText(text, newCursorPosition, false);
|
2012-04-18 14:57:55 -07:00
|
|
|
mCommittingText = false;
|
2012-01-17 23:17:51 -08:00
|
|
|
|
2012-03-23 10:32:42 -07:00
|
|
|
if (hasCompositionString()) {
|
2012-01-17 23:17:51 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . commitText: endComposition");
|
|
|
|
endComposition();
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean finishComposingText() {
|
2012-05-16 22:29:23 -07:00
|
|
|
// finishComposingText() is sometimes called even when we are not composing text.
|
2012-03-23 10:32:42 -07:00
|
|
|
if (hasCompositionString()) {
|
2012-01-17 23:17:51 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . finishComposingText: endComposition");
|
|
|
|
endComposition();
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
final Editable content = getEditable();
|
|
|
|
if (content != null) {
|
|
|
|
beginBatchEdit();
|
|
|
|
removeComposingSpans(content);
|
|
|
|
endBatchEdit();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Editable getEditable() {
|
2011-12-15 13:35:45 -08:00
|
|
|
return mEditable;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean performContextMenuAction(int id) {
|
2011-12-15 13:35:45 -08:00
|
|
|
final Editable content = getEditable();
|
|
|
|
if (content == null)
|
2011-11-18 10:28:17 -08:00
|
|
|
return false;
|
2011-12-15 13:35:45 -08:00
|
|
|
|
|
|
|
String text = content.toString();
|
|
|
|
|
2012-03-08 17:21:18 -08:00
|
|
|
clampSelection();
|
2011-12-15 13:35:45 -08:00
|
|
|
int a = Selection.getSelectionStart(content);
|
|
|
|
int b = Selection.getSelectionEnd(content);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case R.id.selectAll:
|
|
|
|
setSelection(0, text.length());
|
|
|
|
break;
|
|
|
|
case R.id.cut:
|
|
|
|
// Fill the clipboard
|
|
|
|
GeckoAppShell.setClipboardText(text);
|
2011-12-15 13:35:45 -08:00
|
|
|
// If selection is empty, we'll select everything
|
|
|
|
if (a >= b)
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, 0, text.length()));
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_DELETE_TEXT, 0, 0));
|
2011-11-18 10:28:17 -08:00
|
|
|
break;
|
|
|
|
case R.id.paste:
|
|
|
|
commitText(GeckoAppShell.getClipboardText(), 1);
|
|
|
|
break;
|
|
|
|
case R.id.copy:
|
|
|
|
// If there is no selection set, we must be doing "Copy All",
|
2011-12-15 13:35:45 -08:00
|
|
|
// otherwise get the selection
|
|
|
|
if (a < b)
|
|
|
|
text = text.substring(a, b);
|
|
|
|
GeckoAppShell.setClipboardText(text.substring(a, b));
|
2011-11-18 10:28:17 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
|
|
|
|
if (req == null)
|
|
|
|
return null;
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
final Editable content = getEditable();
|
|
|
|
if (content == null)
|
2011-11-18 10:28:17 -08:00
|
|
|
return null;
|
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0)
|
|
|
|
mUpdateRequest = req;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
ExtractedText extract = new ExtractedText();
|
|
|
|
extract.flags = 0;
|
|
|
|
extract.partialStartOffset = -1;
|
|
|
|
extract.partialEndOffset = -1;
|
|
|
|
|
2012-03-08 17:21:18 -08:00
|
|
|
clampSelection();
|
|
|
|
extract.selectionStart = Selection.getSelectionStart(content);
|
|
|
|
extract.selectionEnd = Selection.getSelectionEnd(content);
|
2011-12-15 13:35:45 -08:00
|
|
|
extract.startOffset = 0;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-31 09:24:31 -08:00
|
|
|
try {
|
|
|
|
extract.text = content.toString();
|
|
|
|
} catch (IndexOutOfBoundsException iob) {
|
|
|
|
Log.d(LOGTAG,
|
2012-02-27 16:29:22 -08:00
|
|
|
"IndexOutOfBoundsException thrown from getExtractedText(). start: "
|
|
|
|
+ Selection.getSelectionStart(content)
|
|
|
|
+ " end: " + Selection.getSelectionEnd(content));
|
2012-01-31 09:24:31 -08:00
|
|
|
return null;
|
|
|
|
}
|
2011-12-15 13:35:45 -08:00
|
|
|
return extract;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
@Override
|
|
|
|
public boolean setSelection(int start, int end) {
|
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, start, end - start));
|
2012-01-06 18:27:09 -08:00
|
|
|
|
|
|
|
return super.setSelection(start, end);
|
|
|
|
}
|
|
|
|
|
2012-03-08 17:21:18 -08:00
|
|
|
@Override
|
|
|
|
public boolean deleteSurroundingText(int leftLength, int rightLength) {
|
|
|
|
clampSelection();
|
|
|
|
return super.deleteSurroundingText(leftLength, rightLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCursorCapsMode(int reqModes) {
|
|
|
|
clampSelection();
|
|
|
|
return super.getCursorCapsMode(reqModes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getTextBeforeCursor(int length, int flags) {
|
|
|
|
clampSelection();
|
|
|
|
return super.getTextBeforeCursor(length, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getSelectedText(int flags) {
|
|
|
|
clampSelection();
|
|
|
|
return super.getSelectedText(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getTextAfterCursor(int length, int flags) {
|
|
|
|
clampSelection();
|
|
|
|
return super.getTextAfterCursor(length, flags);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
2012-05-16 22:29:23 -07:00
|
|
|
// setComposingText will likely be called multiple times while we are composing text.
|
2012-03-08 17:21:18 -08:00
|
|
|
clampSelection();
|
|
|
|
return super.setComposingText(text, newCursorPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Android's BaseInputConnection.java is vulnerable to IndexOutOfBoundsExceptions because it
|
|
|
|
// does not adequately protect against stale indexes for selections exceeding the content length
|
|
|
|
// when the Editable content changes. We must clamp the indexes to be safe.
|
|
|
|
private void clampSelection() {
|
|
|
|
Editable content = getEditable();
|
|
|
|
if (content == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int selectionStart = Selection.getSelectionStart(content);
|
|
|
|
final int selectionEnd = Selection.getSelectionEnd(content);
|
|
|
|
|
|
|
|
int a = clampContentIndex(content, selectionStart);
|
|
|
|
int b = clampContentIndex(content, selectionEnd);
|
|
|
|
|
|
|
|
if (a > b) {
|
|
|
|
int tmp = a;
|
|
|
|
a = b;
|
|
|
|
b = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a != selectionStart || b != selectionEnd) {
|
|
|
|
Log.e(LOGTAG, "CLAMPING BOGUS SELECTION (" + selectionStart + ", " + selectionEnd
|
|
|
|
+ "] -> (" + a + ", " + b + "]", new AssertionError());
|
|
|
|
setSelection(a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int clampContentIndex(Editable content, int index) {
|
|
|
|
if (index < 0) {
|
|
|
|
index = 0;
|
|
|
|
} else {
|
|
|
|
final int contentLength = content.length();
|
|
|
|
if (index > contentLength) {
|
|
|
|
index = contentLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
2011-12-15 13:35:45 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
private void replaceText(CharSequence text, int newCursorPosition, boolean composing) {
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, String.format("IME: replaceText(\"%s\", %d, %b)",
|
|
|
|
text, newCursorPosition, composing));
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (text == null)
|
|
|
|
text = "";
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
final Editable content = getEditable();
|
|
|
|
if (content == null) {
|
|
|
|
return;
|
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
beginBatchEdit();
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
// delete composing text set previously.
|
|
|
|
int a = getComposingSpanStart(content);
|
|
|
|
int b = getComposingSpanEnd(content);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, "Composing span: " + a + " to " + b);
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (b < a) {
|
|
|
|
int tmp = a;
|
|
|
|
a = b;
|
|
|
|
b = tmp;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (a != -1 && b != -1) {
|
|
|
|
removeComposingSpans(content);
|
|
|
|
} else {
|
2012-03-08 17:21:18 -08:00
|
|
|
clampSelection();
|
2011-12-15 13:35:45 -08:00
|
|
|
a = Selection.getSelectionStart(content);
|
|
|
|
b = Selection.getSelectionEnd(content);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (composing) {
|
|
|
|
Spannable sp = null;
|
|
|
|
if (!(text instanceof Spannable)) {
|
|
|
|
sp = new SpannableStringBuilder(text);
|
|
|
|
text = sp;
|
2012-03-23 10:32:42 -07:00
|
|
|
// Underline the active composition string.
|
|
|
|
sp.setSpan(new UnderlineSpan(), 0, sp.length(),
|
2012-01-17 23:17:51 -08:00
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
|
2011-12-15 13:35:45 -08:00
|
|
|
} else {
|
2012-02-27 16:29:22 -08:00
|
|
|
sp = (Spannable) text;
|
2011-12-15 13:35:45 -08:00
|
|
|
}
|
|
|
|
setComposingSpans(sp);
|
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, "Replacing from " + a + " to " + b + " with \""
|
|
|
|
+ text + "\", composing=" + composing
|
|
|
|
+ ", type=" + text.getClass().getCanonicalName());
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
LogPrinter lp = new LogPrinter(Log.VERBOSE, LOGTAG);
|
|
|
|
lp.println("Current text:");
|
|
|
|
TextUtils.dumpSpans(content, lp, " ");
|
|
|
|
lp.println("Composing text:");
|
|
|
|
TextUtils.dumpSpans(text, lp, " ");
|
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
// Position the cursor appropriately, so that after replacing the
|
|
|
|
// desired range of text it will be located in the correct spot.
|
|
|
|
// This allows us to deal with filters performing edits on the text
|
|
|
|
// we are providing here.
|
|
|
|
if (newCursorPosition > 0) {
|
|
|
|
newCursorPosition += b - 1;
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2011-12-15 13:35:45 -08:00
|
|
|
newCursorPosition += a;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-12-15 13:35:45 -08:00
|
|
|
if (newCursorPosition < 0) newCursorPosition = 0;
|
|
|
|
if (newCursorPosition > content.length())
|
|
|
|
newCursorPosition = content.length();
|
|
|
|
Selection.setSelection(content, newCursorPosition);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
content.replace(a, b, text);
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
LogPrinter lp = new LogPrinter(Log.VERBOSE, LOGTAG);
|
|
|
|
lp.println("Final text:");
|
|
|
|
TextUtils.dumpSpans(content, lp, " ");
|
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
endBatchEdit();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
@Override
|
|
|
|
public boolean setComposingRegion(int start, int end) {
|
2012-03-23 10:32:42 -07:00
|
|
|
if (hasCompositionString()) {
|
2012-01-17 23:17:51 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . setComposingRegion: endComposition");
|
|
|
|
endComposition();
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.setComposingRegion(start, end);
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
public String getComposingText() {
|
|
|
|
final Editable content = getEditable();
|
|
|
|
if (content == null) {
|
|
|
|
return null;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-12-15 13:35:45 -08:00
|
|
|
int a = getComposingSpanStart(content);
|
|
|
|
int b = getComposingSpanEnd(content);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (a < 0 || b < 0)
|
|
|
|
return null;
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
if (b < a) {
|
|
|
|
int tmp = a;
|
|
|
|
a = b;
|
|
|
|
b = tmp;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
return TextUtils.substring(content, a, b);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public boolean onKeyDel() {
|
|
|
|
// Some IMEs don't update us on deletions
|
|
|
|
// In that case we are not updated when a composition
|
|
|
|
// is destroyed, and Bad Things happen
|
|
|
|
|
2012-03-23 10:32:42 -07:00
|
|
|
if (!hasCompositionString())
|
2011-11-18 10:28:17 -08:00
|
|
|
return false;
|
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
String text = getComposingText();
|
|
|
|
|
|
|
|
if (text != null && text.length() > 1) {
|
|
|
|
text = text.substring(0, text.length() - 1);
|
|
|
|
replaceText(text, 1, false);
|
|
|
|
return false;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
commitText(null, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:55 -08:00
|
|
|
private static InputMethodManager getInputMethodManager() {
|
|
|
|
Context context = GeckoApp.mAppContext.getLayerController().getView().getContext();
|
|
|
|
return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void notifyTextChange(InputMethodManager imm, String text,
|
|
|
|
int start, int oldEnd, int newEnd) {
|
2012-01-06 18:27:09 -08:00
|
|
|
if (!mBatchMode) {
|
|
|
|
if (!text.contentEquals(mEditable)) {
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, String.format(
|
|
|
|
". . . notifyTextChange: current mEditable=\"%s\"",
|
|
|
|
mEditable.toString()));
|
2012-01-06 18:27:09 -08:00
|
|
|
setEditable(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUpdateRequest == null)
|
2011-11-18 10:28:17 -08:00
|
|
|
return;
|
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
View v = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
|
|
|
|
if (imm == null) {
|
2012-02-27 16:29:55 -08:00
|
|
|
imm = getInputMethodManager();
|
2012-01-06 18:27:09 -08:00
|
|
|
if (imm == null)
|
|
|
|
return;
|
2011-12-15 13:35:45 -08:00
|
|
|
}
|
2012-01-06 18:27:09 -08:00
|
|
|
|
|
|
|
mUpdateExtract.flags = 0;
|
|
|
|
|
|
|
|
// We update from (0, oldEnd) to (0, newEnd) because some Android IMEs
|
|
|
|
// assume that updates start at zero, according to jchen.
|
|
|
|
mUpdateExtract.partialStartOffset = 0;
|
|
|
|
mUpdateExtract.partialEndOffset = oldEnd;
|
|
|
|
|
|
|
|
// Faster to not query for selection
|
|
|
|
mUpdateExtract.selectionStart = newEnd;
|
|
|
|
mUpdateExtract.selectionEnd = newEnd;
|
|
|
|
|
|
|
|
mUpdateExtract.text = text.substring(0, newEnd);
|
|
|
|
mUpdateExtract.startOffset = 0;
|
|
|
|
|
|
|
|
imm.updateExtractedText(v, mUpdateRequest.token, mUpdateExtract);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void notifySelectionChange(InputMethodManager imm,
|
|
|
|
int start, int end) {
|
2012-01-06 18:27:09 -08:00
|
|
|
if (!mBatchMode) {
|
|
|
|
final Editable content = getEditable();
|
2012-03-08 17:21:18 -08:00
|
|
|
|
|
|
|
start = clampContentIndex(content, start);
|
|
|
|
end = clampContentIndex(content, end);
|
|
|
|
|
|
|
|
clampSelection();
|
2012-01-06 18:27:09 -08:00
|
|
|
int a = Selection.getSelectionStart(content);
|
|
|
|
int b = Selection.getSelectionEnd(content);
|
2012-03-08 17:21:18 -08:00
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
if (start != a || end != b) {
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, String.format(
|
|
|
|
". . . notifySelectionChange: current editable selection: [%d, %d]",
|
|
|
|
a, b));
|
|
|
|
}
|
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
super.setSelection(start, end);
|
2012-01-17 23:17:51 -08:00
|
|
|
|
|
|
|
// Check if the selection is inside composing span
|
|
|
|
int ca = getComposingSpanStart(content);
|
|
|
|
int cb = getComposingSpanEnd(content);
|
|
|
|
if (cb < ca) {
|
|
|
|
int tmp = ca;
|
|
|
|
ca = cb;
|
|
|
|
cb = tmp;
|
|
|
|
}
|
|
|
|
if (start < ca || start > cb || end < ca || end > cb) {
|
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . notifySelectionChange: removeComposingSpans");
|
|
|
|
removeComposingSpans(content);
|
|
|
|
}
|
2012-01-06 18:27:09 -08:00
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-06 18:27:09 -08:00
|
|
|
if (imm != null && imm.isFullscreenMode()) {
|
|
|
|
View v = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
imm.updateSelection(v, start, end, -1, -1);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reset() {
|
2012-03-23 10:32:42 -07:00
|
|
|
mCompositionStart = NO_COMPOSITION_STRING;
|
2011-11-18 10:28:17 -08:00
|
|
|
mBatchMode = false;
|
2012-01-06 18:27:09 -08:00
|
|
|
mUpdateRequest = null;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TextWatcher
|
2012-02-27 16:29:22 -08:00
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2012-03-23 10:32:42 -07:00
|
|
|
if (hasCompositionString() && mCompositionStart != start) {
|
2012-01-25 17:34:12 -08:00
|
|
|
// Changed range is different from the composition, need to reset the composition
|
|
|
|
endComposition();
|
|
|
|
}
|
|
|
|
|
2012-04-18 14:57:55 -07:00
|
|
|
CharSequence changedText = s.subSequence(start, start + count);
|
|
|
|
if (changedText.length() == 1) {
|
|
|
|
char changedChar = changedText.charAt(0);
|
|
|
|
|
2012-02-14 17:08:47 -08:00
|
|
|
// Some IMEs (e.g. SwiftKey X) send a string with '\n' when Enter is pressed
|
|
|
|
// Such string cannot be handled by Gecko, so we convert it to a key press instead
|
2012-04-18 14:57:55 -07:00
|
|
|
if (changedChar == '\n') {
|
|
|
|
processKeyDown(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_DOWN,
|
|
|
|
KeyEvent.KEYCODE_ENTER), false);
|
|
|
|
processKeyUp(KeyEvent.KEYCODE_ENTER, new KeyEvent(KeyEvent.ACTION_UP,
|
|
|
|
KeyEvent.KEYCODE_ENTER), false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are committing a single character and didn't have an active composition string,
|
|
|
|
// we can send Gecko keydown/keyup events instead of composition events.
|
|
|
|
if (mCommittingText && !hasCompositionString() && synthesizeKeyEvents(changedChar)) {
|
|
|
|
// Block this thread until all pending events are processed
|
|
|
|
GeckoAppShell.geckoEventSync();
|
|
|
|
return;
|
|
|
|
}
|
2012-02-14 17:08:47 -08:00
|
|
|
}
|
|
|
|
|
2012-05-16 22:29:23 -07:00
|
|
|
boolean startCompositionString = !hasCompositionString();
|
|
|
|
if (startCompositionString) {
|
2012-01-17 23:17:51 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . onTextChanged: IME_COMPOSITION_BEGIN");
|
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_COMPOSITION_BEGIN, 0, 0));
|
2012-01-25 17:34:12 -08:00
|
|
|
mCompositionStart = start;
|
2012-01-17 23:17:51 -08:00
|
|
|
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, ". . . onTextChanged: IME_SET_SELECTION, start=" + start + ", len="
|
|
|
|
+ before);
|
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, start, before));
|
2012-01-17 23:17:51 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-04-18 14:57:55 -07:00
|
|
|
sendTextToGecko(changedText, start + count);
|
2011-12-20 17:03:54 -08:00
|
|
|
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, ". . . onTextChanged: IME_SET_SELECTION, start=" + (start + count)
|
|
|
|
+ ", 0");
|
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, start + count, 0));
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-21 10:26:53 -07:00
|
|
|
// End composition if all characters in the word have been deleted.
|
|
|
|
// This fixes autocomplete results not appearing.
|
2012-05-16 22:29:23 -07:00
|
|
|
if (count == 0 || (startCompositionString && mCommittingText))
|
2012-03-21 10:26:53 -07:00
|
|
|
endComposition();
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
// Block this thread until all pending events are processed
|
|
|
|
GeckoAppShell.geckoEventSync();
|
|
|
|
}
|
|
|
|
|
2012-04-18 14:57:55 -07:00
|
|
|
private boolean synthesizeKeyEvents(char inputChar) {
|
|
|
|
if (mKeyCharacterMap == null) {
|
|
|
|
mKeyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Synthesize VKB key events that could plausibly generate the input character.
|
|
|
|
char[] inputChars = { inputChar };
|
|
|
|
KeyEvent[] events = mKeyCharacterMap.getEvents(inputChars);
|
|
|
|
if (events == null) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, "synthesizeKeyEvents: char '" + inputChar
|
|
|
|
+ "' has no virtual key mapping");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean sentKeyEvents = false;
|
|
|
|
|
|
|
|
for (KeyEvent event : events) {
|
|
|
|
if (!KeyEvent.isModifierKey(event.getKeyCode())) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, "synthesizeKeyEvents: char '" + inputChar
|
|
|
|
+ "' -> action=" + event.getAction()
|
|
|
|
+ ", keyCode=" + event.getKeyCode()
|
|
|
|
+ ", UnicodeChar='" + (char) event.getUnicodeChar() + "'");
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
|
|
|
|
sentKeyEvents = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sentKeyEvents;
|
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
private void endComposition() {
|
|
|
|
if (DEBUG) Log.d(LOGTAG, "IME: endComposition: IME_COMPOSITION_END");
|
2012-05-16 22:29:23 -07:00
|
|
|
|
|
|
|
if (!hasCompositionString())
|
|
|
|
Log.e(LOGTAG, "Please report this bug:", new IllegalStateException("endComposition, but not composing text?!"));
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_COMPOSITION_END, 0, 0));
|
2012-05-16 22:29:23 -07:00
|
|
|
|
2012-03-23 10:32:42 -07:00
|
|
|
mCompositionStart = NO_COMPOSITION_STRING;
|
2012-01-17 23:17:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sendTextToGecko(CharSequence text, int caretPos) {
|
|
|
|
if (DEBUG) Log.d(LOGTAG, "IME: sendTextToGecko(\"" + text + "\")");
|
|
|
|
|
|
|
|
// Handle composition text styles
|
|
|
|
if (text != null && text instanceof Spanned) {
|
|
|
|
Spanned span = (Spanned) text;
|
|
|
|
int spanStart = 0, spanEnd = 0;
|
|
|
|
boolean pastSelStart = false, pastSelEnd = false;
|
|
|
|
|
|
|
|
do {
|
|
|
|
int rangeType = GeckoEvent.IME_RANGE_CONVERTEDTEXT;
|
|
|
|
int rangeStyles = 0, rangeForeColor = 0, rangeBackColor = 0;
|
|
|
|
|
|
|
|
// Find next offset where there is a style transition
|
|
|
|
spanEnd = span.nextSpanTransition(spanStart + 1, text.length(),
|
|
|
|
CharacterStyle.class);
|
|
|
|
|
|
|
|
// Empty range, continue
|
|
|
|
if (spanEnd <= spanStart)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Get and iterate through list of span objects within range
|
2012-02-27 16:29:22 -08:00
|
|
|
CharacterStyle[] styles = span.getSpans(spanStart, spanEnd, CharacterStyle.class);
|
2012-01-17 23:17:51 -08:00
|
|
|
|
|
|
|
for (CharacterStyle style : styles) {
|
|
|
|
if (style instanceof UnderlineSpan) {
|
|
|
|
// Text should be underlined
|
|
|
|
rangeStyles |= GeckoEvent.IME_RANGE_UNDERLINE;
|
|
|
|
} else if (style instanceof ForegroundColorSpan) {
|
|
|
|
// Text should be of a different foreground color
|
|
|
|
rangeStyles |= GeckoEvent.IME_RANGE_FORECOLOR;
|
2012-02-27 16:29:22 -08:00
|
|
|
rangeForeColor = ((ForegroundColorSpan) style).getForegroundColor();
|
2012-01-17 23:17:51 -08:00
|
|
|
} else if (style instanceof BackgroundColorSpan) {
|
|
|
|
// Text should be of a different background color
|
|
|
|
rangeStyles |= GeckoEvent.IME_RANGE_BACKCOLOR;
|
2012-02-27 16:29:22 -08:00
|
|
|
rangeBackColor = ((BackgroundColorSpan) style).getBackgroundColor();
|
2012-01-17 23:17:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add range to array, the actual styles are
|
|
|
|
// applied when IME_SET_TEXT is sent
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, String.format(
|
|
|
|
". . . sendTextToGecko: IME_ADD_RANGE, %d, %d, %d, %d, %d, %d",
|
|
|
|
spanStart, spanEnd - spanStart, rangeType, rangeStyles, rangeForeColor,
|
|
|
|
rangeBackColor));
|
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMERangeEvent(spanStart, spanEnd - spanStart,
|
|
|
|
rangeType, rangeStyles,
|
|
|
|
rangeForeColor, rangeBackColor));
|
2011-12-20 17:03:54 -08:00
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
spanStart = spanEnd;
|
|
|
|
} while (spanStart < text.length());
|
|
|
|
} else {
|
2012-02-27 16:29:22 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . sendTextToGecko: IME_ADD_RANGE, 0, " + text.length()
|
|
|
|
+ ", IME_RANGE_RAWINPUT, IME_RANGE_UNDERLINE)");
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMERangeEvent(0, text == null ? 0 : text.length(),
|
|
|
|
GeckoEvent.IME_RANGE_RAWINPUT,
|
|
|
|
GeckoEvent.IME_RANGE_UNDERLINE, 0, 0));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
// Change composition (treating selection end as where the caret is)
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, ". . . sendTextToGecko: IME_SET_TEXT, IME_RANGE_CARETPOSITION, \""
|
|
|
|
+ text + "\")");
|
|
|
|
}
|
|
|
|
|
2012-01-17 23:17:51 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMERangeEvent(caretPos, 0,
|
|
|
|
GeckoEvent.IME_RANGE_CARETPOSITION, 0, 0, 0,
|
|
|
|
text.toString()));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
public void afterTextChanged(Editable s) {
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
2011-11-18 10:28:17 -08:00
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_TEXT;
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE;
|
|
|
|
outAttrs.actionLabel = null;
|
|
|
|
|
|
|
|
if (mIMEState == IME_STATE_PASSWORD)
|
|
|
|
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("url"))
|
|
|
|
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_URI;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("email"))
|
|
|
|
outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("search"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_SEARCH;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("tel"))
|
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_PHONE;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("number") ||
|
|
|
|
mIMETypeHint.equalsIgnoreCase("range"))
|
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_NUMBER;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("datetime") ||
|
|
|
|
mIMETypeHint.equalsIgnoreCase("datetime-local"))
|
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
|
|
|
|
InputType.TYPE_DATETIME_VARIATION_NORMAL;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("date"))
|
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
|
|
|
|
InputType.TYPE_DATETIME_VARIATION_DATE;
|
|
|
|
else if (mIMETypeHint.equalsIgnoreCase("time"))
|
|
|
|
outAttrs.inputType = InputType.TYPE_CLASS_DATETIME |
|
|
|
|
InputType.TYPE_DATETIME_VARIATION_TIME;
|
|
|
|
|
|
|
|
if (mIMEActionHint.equalsIgnoreCase("go"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_GO;
|
|
|
|
else if (mIMEActionHint.equalsIgnoreCase("done"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE;
|
|
|
|
else if (mIMEActionHint.equalsIgnoreCase("next"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_NEXT;
|
|
|
|
else if (mIMEActionHint.equalsIgnoreCase("search"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_SEARCH;
|
|
|
|
else if (mIMEActionHint.equalsIgnoreCase("send"))
|
|
|
|
outAttrs.imeOptions = EditorInfo.IME_ACTION_SEND;
|
|
|
|
else if (mIMEActionHint != null && mIMEActionHint.length() != 0)
|
|
|
|
outAttrs.actionLabel = mIMEActionHint;
|
|
|
|
|
2012-03-13 14:22:54 -07:00
|
|
|
outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI
|
|
|
|
| EditorInfo.IME_FLAG_NO_FULLSCREEN;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
reset();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
|
|
|
switch (event.getAction()) {
|
|
|
|
case KeyEvent.ACTION_DOWN:
|
|
|
|
return processKeyDown(keyCode, event, true);
|
|
|
|
case KeyEvent.ACTION_UP:
|
|
|
|
return processKeyUp(keyCode, event, true);
|
|
|
|
case KeyEvent.ACTION_MULTIPLE:
|
|
|
|
return onKeyMultiple(keyCode, event.getRepeatCount(), event);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
return processKeyDown(keyCode, event, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean processKeyDown(int keyCode, KeyEvent event, boolean isPreIme) {
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, "IME: processKeyDown(keyCode=" + keyCode + ", event=" + event + ", "
|
|
|
|
+ isPreIme + ")");
|
|
|
|
}
|
2011-12-15 13:35:45 -08:00
|
|
|
|
2012-03-12 17:08:04 -07:00
|
|
|
clampSelection();
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_MENU:
|
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
|
|
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
|
|
|
case KeyEvent.KEYCODE_SEARCH:
|
|
|
|
return false;
|
|
|
|
case KeyEvent.KEYCODE_DEL:
|
|
|
|
// See comments in GeckoInputConnection.onKeyDel
|
|
|
|
if (onKeyDel()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KeyEvent.KEYCODE_ENTER:
|
|
|
|
if ((event.getFlags() & KeyEvent.FLAG_EDITOR_ACTION) != 0 &&
|
|
|
|
mIMEActionHint.equalsIgnoreCase("next"))
|
|
|
|
event = new KeyEvent(event.getAction(), KeyEvent.KEYCODE_TAB);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPreIme && mIMEState != IME_STATE_DISABLED &&
|
|
|
|
(event.getMetaState() & KeyEvent.META_ALT_ON) != 0)
|
|
|
|
// Let active IME process pre-IME key events
|
|
|
|
return false;
|
|
|
|
|
2012-03-12 16:02:06 -07:00
|
|
|
View view = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
KeyListener keyListener = TextKeyListener.getInstance();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
// KeyListener returns true if it handled the event for us.
|
|
|
|
if (mIMEState == IME_STATE_DISABLED ||
|
2012-01-06 18:27:09 -08:00
|
|
|
keyCode == KeyEvent.KEYCODE_ENTER ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DEL ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_TAB ||
|
|
|
|
(event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
|
2012-03-12 16:02:06 -07:00
|
|
|
!keyListener.onKeyDown(view, mEditable, keyCode, event)) {
|
2012-01-06 18:27:09 -08:00
|
|
|
// Make sure selection in Gecko is up-to-date
|
|
|
|
final Editable content = getEditable();
|
|
|
|
int a = Selection.getSelectionStart(content);
|
|
|
|
int b = Selection.getSelectionEnd(content);
|
|
|
|
GeckoAppShell.sendEventToGecko(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createIMEEvent(GeckoEvent.IME_SET_SELECTION, a, b - a));
|
2012-01-06 18:27:09 -08:00
|
|
|
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
|
2012-01-06 18:27:09 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
return processKeyUp(keyCode, event, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean processKeyUp(int keyCode, KeyEvent event, boolean isPreIme) {
|
2012-02-27 16:29:55 -08:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(LOGTAG, "IME: processKeyUp(keyCode=" + keyCode + ", event=" + event + ", "
|
|
|
|
+ isPreIme + ")");
|
|
|
|
}
|
2011-12-15 13:35:45 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_BACK:
|
|
|
|
case KeyEvent.KEYCODE_SEARCH:
|
|
|
|
case KeyEvent.KEYCODE_MENU:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPreIme && mIMEState != IME_STATE_DISABLED &&
|
|
|
|
(event.getMetaState() & KeyEvent.META_ALT_ON) != 0)
|
|
|
|
// Let active IME process pre-IME key events
|
|
|
|
return false;
|
|
|
|
|
2012-03-12 16:02:06 -07:00
|
|
|
View view = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
KeyListener keyListener = TextKeyListener.getInstance();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
if (mIMEState == IME_STATE_DISABLED ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_ENTER ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DEL ||
|
|
|
|
(event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) != 0 ||
|
2012-03-12 16:02:06 -07:00
|
|
|
!keyListener.onKeyUp(view, mEditable, keyCode, event)) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
|
2012-03-12 16:02:06 -07:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createKeyEvent(event));
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
|
|
|
View v = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
switch (keyCode) {
|
|
|
|
case KeyEvent.KEYCODE_MENU:
|
2012-02-27 16:29:55 -08:00
|
|
|
InputMethodManager imm = getInputMethodManager();
|
2011-11-18 10:28:17 -08:00
|
|
|
imm.toggleSoftInputFromWindow(v.getWindowToken(),
|
2012-02-14 12:28:27 -08:00
|
|
|
InputMethodManager.SHOW_FORCED, 0);
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-03 19:59:27 -08:00
|
|
|
public boolean isIMEEnabled() {
|
|
|
|
// make sure this picks up PASSWORD and PLUGIN states as well
|
|
|
|
return mIMEState != IME_STATE_DISABLED;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public void notifyIME(int type, int state) {
|
|
|
|
View v = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
|
|
|
|
if (v == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NOTIFY_IME_RESETINPUTSTATE:
|
2012-01-06 18:27:09 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . notifyIME: reset");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
// Composition event is already fired from widget.
|
|
|
|
// So reset IME flags.
|
|
|
|
reset();
|
|
|
|
|
|
|
|
// Don't use IMEStateUpdater for reset.
|
|
|
|
// Because IME may not work showSoftInput()
|
|
|
|
// after calling restartInput() immediately.
|
|
|
|
// So we have to call showSoftInput() delay.
|
2012-02-27 16:29:55 -08:00
|
|
|
InputMethodManager imm = getInputMethodManager();
|
2012-01-02 21:54:29 -08:00
|
|
|
if (imm == null) {
|
2011-11-18 10:28:17 -08:00
|
|
|
// no way to reset IME status directly
|
|
|
|
IMEStateUpdater.resetIME();
|
|
|
|
} else {
|
|
|
|
imm.restartInput(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep current enabled state
|
|
|
|
IMEStateUpdater.enableIME();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOTIFY_IME_CANCELCOMPOSITION:
|
2012-01-06 18:27:09 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . notifyIME: cancel");
|
2011-11-18 10:28:17 -08:00
|
|
|
IMEStateUpdater.resetIME();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOTIFY_IME_FOCUSCHANGE:
|
2012-01-06 18:27:09 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, ". . . notifyIME: focus");
|
2011-11-18 10:28:17 -08:00
|
|
|
IMEStateUpdater.resetIME();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:22:54 -07:00
|
|
|
public void notifyIMEEnabled(int state, String typeHint, String actionHint) {
|
2011-11-18 10:28:17 -08:00
|
|
|
View v = GeckoApp.mAppContext.getLayerController().getView();
|
|
|
|
|
|
|
|
if (v == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* When IME is 'disabled', IME processing is disabled.
|
|
|
|
In addition, the IME UI is hidden */
|
|
|
|
mIMEState = state;
|
|
|
|
mIMETypeHint = typeHint;
|
|
|
|
mIMEActionHint = actionHint;
|
|
|
|
IMEStateUpdater.enableIME();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void notifyIMEChange(String text, int start, int end, int newEnd) {
|
2012-02-27 16:29:55 -08:00
|
|
|
InputMethodManager imm = getInputMethodManager();
|
2011-11-18 10:28:17 -08:00
|
|
|
if (imm == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newEnd < 0)
|
|
|
|
notifySelectionChange(imm, start, end);
|
|
|
|
else
|
|
|
|
notifyTextChange(imm, text, start, end, newEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delay updating IME states (see bug 573800) */
|
2012-02-27 16:29:22 -08:00
|
|
|
private static final class IMEStateUpdater extends TimerTask {
|
2012-02-27 16:29:44 -08:00
|
|
|
private static IMEStateUpdater instance;
|
|
|
|
private boolean mEnable;
|
|
|
|
private boolean mReset;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-27 16:29:44 -08:00
|
|
|
private static IMEStateUpdater getInstance() {
|
2011-11-18 10:28:17 -08:00
|
|
|
if (instance == null) {
|
|
|
|
instance = new IMEStateUpdater();
|
|
|
|
mIMETimer.schedule(instance, 200);
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:44 -08:00
|
|
|
public static synchronized void enableIME() {
|
2011-11-18 10:28:17 -08:00
|
|
|
getInstance().mEnable = true;
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:44 -08:00
|
|
|
public static synchronized void resetIME() {
|
2011-11-18 10:28:17 -08:00
|
|
|
getInstance().mReset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
2011-12-15 13:35:45 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, "IME: run()");
|
2012-02-27 16:29:22 -08:00
|
|
|
synchronized (IMEStateUpdater.class) {
|
2011-11-18 10:28:17 -08:00
|
|
|
instance = null;
|
|
|
|
}
|
|
|
|
|
2012-05-01 18:15:42 -07:00
|
|
|
final View v = GeckoApp.mAppContext.getLayerController().getView();
|
2012-02-27 16:29:22 -08:00
|
|
|
if (DEBUG) Log.d(LOGTAG, "IME: v=" + v);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-05-01 18:15:42 -07:00
|
|
|
final InputMethodManager imm = getInputMethodManager();
|
2011-11-18 10:28:17 -08:00
|
|
|
if (imm == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mReset)
|
|
|
|
imm.restartInput(v);
|
|
|
|
|
|
|
|
if (!mEnable)
|
|
|
|
return;
|
|
|
|
|
2012-05-01 18:15:42 -07:00
|
|
|
if (mIMEState != IME_STATE_DISABLED) {
|
|
|
|
if (!v.isFocused()) {
|
|
|
|
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
v.requestFocus();
|
|
|
|
imm.showSoftInput(v, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
imm.showSoftInput(v, 0);
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-18 10:28:17 -08:00
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
2012-05-01 18:15:42 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
public void setEditable(String contents) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mEditable.removeSpan(this);
|
|
|
|
mEditable.replace(0, mEditable.length(), contents);
|
|
|
|
mEditable.setSpan(this, 0, contents.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
Selection.setSelection(mEditable, contents.length());
|
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
public void initEditable(String contents) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mEditable = mEditableFactory.newEditable(contents);
|
|
|
|
mEditable.setSpan(this, 0, contents.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
Selection.setSelection(mEditable, contents.length());
|
|
|
|
}
|
2012-03-23 10:32:42 -07:00
|
|
|
|
|
|
|
private boolean hasCompositionString() {
|
|
|
|
return mCompositionStart != NO_COMPOSITION_STRING;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 16:29:22 -08:00
|
|
|
class DebugGeckoInputConnection extends GeckoInputConnection {
|
2011-12-15 13:35:45 -08:00
|
|
|
public DebugGeckoInputConnection(View targetView) {
|
|
|
|
super(targetView);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean beginBatchEdit() {
|
|
|
|
Log.d(LOGTAG, "IME: beginBatchEdit");
|
|
|
|
return super.beginBatchEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean endBatchEdit() {
|
|
|
|
Log.d(LOGTAG, "IME: endBatchEdit");
|
|
|
|
return super.endBatchEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean commitCompletion(CompletionInfo text) {
|
|
|
|
Log.d(LOGTAG, "IME: commitCompletion");
|
|
|
|
return super.commitCompletion(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean commitText(CharSequence text, int newCursorPosition) {
|
|
|
|
Log.d(LOGTAG, String.format("IME: commitText(\"%s\", %d)", text, newCursorPosition));
|
|
|
|
return super.commitText(text, newCursorPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean deleteSurroundingText(int leftLength, int rightLength) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, "IME: deleteSurroundingText(leftLen=" + leftLength + ", rightLen="
|
|
|
|
+ rightLength + ")");
|
2011-12-15 13:35:45 -08:00
|
|
|
return super.deleteSurroundingText(leftLength, rightLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean finishComposingText() {
|
|
|
|
Log.d(LOGTAG, "IME: finishComposingText");
|
|
|
|
return super.finishComposingText();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Editable getEditable() {
|
2012-02-27 16:29:55 -08:00
|
|
|
Editable editable = super.getEditable();
|
|
|
|
Log.d(LOGTAG, "IME: getEditable -> " + editable);
|
|
|
|
return editable;
|
2011-12-15 13:35:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean performContextMenuAction(int id) {
|
|
|
|
Log.d(LOGTAG, "IME: performContextMenuAction");
|
|
|
|
return super.performContextMenuAction(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
|
|
|
|
Log.d(LOGTAG, "IME: getExtractedText");
|
|
|
|
ExtractedText extract = super.getExtractedText(req, flags);
|
|
|
|
if (extract != null)
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, String.format(
|
|
|
|
". . . getExtractedText: extract.text=\"%s\", selStart=%d, selEnd=%d",
|
|
|
|
extract.text, extract.selectionStart, extract.selectionEnd));
|
2011-12-15 13:35:45 -08:00
|
|
|
return extract;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getTextAfterCursor(int length, int flags) {
|
|
|
|
Log.d(LOGTAG, "IME: getTextAfterCursor(length=" + length + ", flags=" + flags + ")");
|
|
|
|
CharSequence s = super.getTextAfterCursor(length, flags);
|
|
|
|
Log.d(LOGTAG, ". . . getTextAfterCursor returns \"" + s + "\"");
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getTextBeforeCursor(int length, int flags) {
|
|
|
|
Log.d(LOGTAG, "IME: getTextBeforeCursor");
|
|
|
|
CharSequence s = super.getTextBeforeCursor(length, flags);
|
|
|
|
Log.d(LOGTAG, ". . . getTextBeforeCursor returns \"" + s + "\"");
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setComposingText(CharSequence text, int newCursorPosition) {
|
|
|
|
Log.d(LOGTAG, String.format("IME: setComposingText(\"%s\", %d)", text, newCursorPosition));
|
|
|
|
return super.setComposingText(text, newCursorPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setComposingRegion(int start, int end) {
|
|
|
|
Log.d(LOGTAG, "IME: setComposingRegion(start=" + start + ", end=" + end + ")");
|
|
|
|
return super.setComposingRegion(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean setSelection(int start, int end) {
|
|
|
|
Log.d(LOGTAG, "IME: setSelection(start=" + start + ", end=" + end + ")");
|
|
|
|
return super.setSelection(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getComposingText() {
|
|
|
|
Log.d(LOGTAG, "IME: getComposingText");
|
|
|
|
String s = super.getComposingText();
|
|
|
|
Log.d(LOGTAG, ". . . getComposingText: Composing text = \"" + s + "\"");
|
|
|
|
return s;
|
|
|
|
}
|
2012-02-27 16:29:22 -08:00
|
|
|
|
2011-12-15 13:35:45 -08:00
|
|
|
@Override
|
|
|
|
public boolean onKeyDel() {
|
|
|
|
Log.d(LOGTAG, "IME: onKeyDel");
|
|
|
|
return super.onKeyDel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyTextChange(InputMethodManager imm, String text,
|
|
|
|
int start, int oldEnd, int newEnd) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, String.format(
|
|
|
|
"IME: >notifyTextChange(\"%s\", start=%d, oldEnd=%d, newEnd=%d)",
|
|
|
|
text, start, oldEnd, newEnd));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.notifyTextChange(imm, text, start, oldEnd, newEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifySelectionChange(InputMethodManager imm,
|
|
|
|
int start, int end) {
|
2012-01-06 18:27:09 -08:00
|
|
|
Log.d(LOGTAG, String.format("IME: >notifySelectionChange(start=%d, end=%d)", start, end));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.notifySelectionChange(imm, start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void reset() {
|
|
|
|
Log.d(LOGTAG, "IME: reset");
|
|
|
|
super.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-02-27 16:29:22 -08:00
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, String.format("IME: onTextChanged(\"%s\" start=%d, before=%d, count=%d)",
|
|
|
|
s, start, before, count));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.onTextChanged(s, start, before, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-02-27 16:29:22 -08:00
|
|
|
public void afterTextChanged(Editable s) {
|
2011-12-15 13:35:45 -08:00
|
|
|
Log.d(LOGTAG, "IME: afterTextChanged(\"" + s + "\")");
|
|
|
|
super.afterTextChanged(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-02-27 16:29:22 -08:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, String.format("IME: beforeTextChanged(\"%s\", start=%d, count=%d, after=%d)",
|
|
|
|
s, start, count, after));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.beforeTextChanged(s, start, count, after);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-02-27 16:29:22 -08:00
|
|
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, "IME: onCreateInputConnection called");
|
2011-12-15 13:35:45 -08:00
|
|
|
return super.onCreateInputConnection(outAttrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
|
|
|
Log.d(LOGTAG, "IME: onKeyPreIme(keyCode=" + keyCode + ", event=" + event + ")");
|
|
|
|
return super.onKeyPreIme(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
Log.d(LOGTAG, "IME: onKeyDown(keyCode=" + keyCode + ", event=" + event + ")");
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
Log.d(LOGTAG, "IME: onKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
|
2012-02-27 16:29:55 -08:00
|
|
|
Log.d(LOGTAG, "IME: onKeyMultiple(keyCode=" + keyCode + ", repeatCount=" + repeatCount
|
|
|
|
+ ", event=" + event + ")");
|
2011-12-15 13:35:45 -08:00
|
|
|
return super.onKeyMultiple(keyCode, repeatCount, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
|
|
|
Log.d(LOGTAG, "IME: onKeyLongPress(keyCode=" + keyCode + ", event=" + event + ")");
|
|
|
|
return super.onKeyLongPress(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyIME(int type, int state) {
|
2012-01-06 18:27:09 -08:00
|
|
|
Log.d(LOGTAG, String.format("IME: >notifyIME(type=%d, state=%d)", type, state));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.notifyIME(type, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyIMEChange(String text, int start, int end, int newEnd) {
|
2012-01-06 18:27:09 -08:00
|
|
|
Log.d(LOGTAG, String.format("IME: >notifyIMEChange(\"%s\", start=%d, end=%d, newEnd=%d)",
|
|
|
|
text, start, end, newEnd));
|
2011-12-15 13:35:45 -08:00
|
|
|
super.notifyIMEChange(text, start, end, newEnd);
|
|
|
|
}
|
|
|
|
}
|