M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@ -0,0 +1,664 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
import android.text.NoCopySpan;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.MetaKeyKeyListener;
import android.util.Log;
import android.util.LogPrinter;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewRoot;
class ComposingText implements NoCopySpan {
}
/**
* Base class for implementors of the InputConnection interface, taking care
* of most of the common behavior for providing a connection to an Editable.
* Implementors of this class will want to be sure to implement
* {@link #getEditable} to provide access to their own editable object.
*/
public class BaseInputConnection implements InputConnection {
private static final boolean DEBUG = false;
private static final String TAG = "BaseInputConnection";
static final Object COMPOSING = new ComposingText();
final InputMethodManager mIMM;
final View mTargetView;
final boolean mDummyMode;
private Object[] mDefaultComposingSpans;
Editable mEditable;
KeyCharacterMap mKeyCharacterMap;
BaseInputConnection(InputMethodManager mgr, boolean fullEditor) {
mIMM = mgr;
mTargetView = null;
mDummyMode = !fullEditor;
}
public BaseInputConnection(View targetView, boolean fullEditor) {
mIMM = (InputMethodManager)targetView.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
mTargetView = targetView;
mDummyMode = !fullEditor;
}
public static final void removeComposingSpans(Spannable text) {
text.removeSpan(COMPOSING);
Object[] sps = text.getSpans(0, text.length(), Object.class);
if (sps != null) {
for (int i=sps.length-1; i>=0; i--) {
Object o = sps[i];
if ((text.getSpanFlags(o)&Spanned.SPAN_COMPOSING) != 0) {
text.removeSpan(o);
}
}
}
}
public static void setComposingSpans(Spannable text) {
setComposingSpans(text, 0, text.length());
}
/** @hide */
public static void setComposingSpans(Spannable text, int start, int end) {
final Object[] sps = text.getSpans(start, end, Object.class);
if (sps != null) {
for (int i=sps.length-1; i>=0; i--) {
final Object o = sps[i];
if (o == COMPOSING) {
text.removeSpan(o);
continue;
}
final int fl = text.getSpanFlags(o);
if ((fl&(Spanned.SPAN_COMPOSING|Spanned.SPAN_POINT_MARK_MASK))
!= (Spanned.SPAN_COMPOSING|Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)) {
text.setSpan(o, text.getSpanStart(o), text.getSpanEnd(o),
(fl & ~Spanned.SPAN_POINT_MARK_MASK)
| Spanned.SPAN_COMPOSING
| Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
text.setSpan(COMPOSING, start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
}
public static int getComposingSpanStart(Spannable text) {
return text.getSpanStart(COMPOSING);
}
public static int getComposingSpanEnd(Spannable text) {
return text.getSpanEnd(COMPOSING);
}
/**
* Return the target of edit operations. The default implementation
* returns its own fake editable that is just used for composing text;
* subclasses that are real text editors should override this and
* supply their own.
*/
public Editable getEditable() {
if (mEditable == null) {
mEditable = Editable.Factory.getInstance().newEditable("");
Selection.setSelection(mEditable, 0);
}
return mEditable;
}
/**
* Default implementation does nothing.
*/
public boolean beginBatchEdit() {
return false;
}
/**
* Default implementation does nothing.
*/
public boolean endBatchEdit() {
return false;
}
/**
* Default implementation uses
* {@link MetaKeyKeyListener#clearMetaKeyState(long, int)
* MetaKeyKeyListener.clearMetaKeyState(long, int)} to clear the state.
*/
public boolean clearMetaKeyStates(int states) {
final Editable content = getEditable();
if (content == null) return false;
MetaKeyKeyListener.clearMetaKeyState(content, states);
return true;
}
/**
* Default implementation does nothing.
*/
public boolean commitCompletion(CompletionInfo text) {
return false;
}
/**
* Default implementation replaces any existing composing text with
* the given text. In addition, only if dummy mode, a key event is
* sent for the new text and the current editable buffer cleared.
*/
public boolean commitText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.v(TAG, "commitText " + text);
replaceText(text, newCursorPosition, false);
sendCurrentText();
return true;
}
/**
* The default implementation performs the deletion around the current
* selection position of the editable text.
*/
public boolean deleteSurroundingText(int leftLength, int rightLength) {
if (DEBUG) Log.v(TAG, "deleteSurroundingText " + leftLength
+ " / " + rightLength);
final Editable content = getEditable();
if (content == null) return false;
beginBatchEdit();
int a = Selection.getSelectionStart(content);
int b = Selection.getSelectionEnd(content);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
// ignore the composing text.
int ca = getComposingSpanStart(content);
int cb = getComposingSpanEnd(content);
if (cb < ca) {
int tmp = ca;
ca = cb;
cb = tmp;
}
if (ca != -1 && cb != -1) {
if (ca < a) a = ca;
if (cb > b) b = cb;
}
int deleted = 0;
if (leftLength > 0) {
int start = a - leftLength;
if (start < 0) start = 0;
content.delete(start, a);
deleted = a - start;
}
if (rightLength > 0) {
b = b - deleted;
int end = b + rightLength;
if (end > content.length()) end = content.length();
content.delete(b, end);
}
endBatchEdit();
return true;
}
/**
* The default implementation removes the composing state from the
* current editable text. In addition, only if dummy mode, a key event is
* sent for the new text and the current editable buffer cleared.
*/
public boolean finishComposingText() {
if (DEBUG) Log.v(TAG, "finishComposingText");
final Editable content = getEditable();
if (content != null) {
beginBatchEdit();
removeComposingSpans(content);
endBatchEdit();
sendCurrentText();
}
return true;
}
/**
* The default implementation uses TextUtils.getCapsMode to get the
* cursor caps mode for the current selection position in the editable
* text, unless in dummy mode in which case 0 is always returned.
*/
public int getCursorCapsMode(int reqModes) {
if (mDummyMode) return 0;
final Editable content = getEditable();
if (content == null) return 0;
int a = Selection.getSelectionStart(content);
int b = Selection.getSelectionEnd(content);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
return TextUtils.getCapsMode(content, a, reqModes);
}
/**
* The default implementation always returns null.
*/
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
return null;
}
/**
* The default implementation returns the given amount of text from the
* current cursor position in the buffer.
*/
public CharSequence getTextBeforeCursor(int length, int flags) {
final Editable content = getEditable();
if (content == null) return null;
int a = Selection.getSelectionStart(content);
int b = Selection.getSelectionEnd(content);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
if (a <= 0) {
return "";
}
if (length > a) {
length = a;
}
if ((flags&GET_TEXT_WITH_STYLES) != 0) {
return content.subSequence(a - length, a);
}
return TextUtils.substring(content, a - length, a);
}
/**
* The default implementation returns the text currently selected, or null if none is
* selected.
*/
public CharSequence getSelectedText(int flags) {
final Editable content = getEditable();
if (content == null) return null;
int a = Selection.getSelectionStart(content);
int b = Selection.getSelectionEnd(content);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
if (a == b) return null;
if ((flags&GET_TEXT_WITH_STYLES) != 0) {
return content.subSequence(a, b);
}
return TextUtils.substring(content, a, b);
}
/**
* The default implementation returns the given amount of text from the
* current cursor position in the buffer.
*/
public CharSequence getTextAfterCursor(int length, int flags) {
final Editable content = getEditable();
if (content == null) return null;
int a = Selection.getSelectionStart(content);
int b = Selection.getSelectionEnd(content);
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
// Guard against the case where the cursor has not been positioned yet.
if (b < 0) {
b = 0;
}
if (b + length > content.length()) {
length = content.length() - b;
}
if ((flags&GET_TEXT_WITH_STYLES) != 0) {
return content.subSequence(b, b + length);
}
return TextUtils.substring(content, b, b + length);
}
/**
* The default implementation turns this into the enter key.
*/
public boolean performEditorAction(int actionCode) {
long eventTime = SystemClock.uptimeMillis();
sendKeyEvent(new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE
| KeyEvent.FLAG_EDITOR_ACTION));
sendKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), eventTime,
KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE
| KeyEvent.FLAG_EDITOR_ACTION));
return true;
}
/**
* The default implementation does nothing.
*/
public boolean performContextMenuAction(int id) {
return false;
}
/**
* The default implementation does nothing.
*/
public boolean performPrivateCommand(String action, Bundle data) {
return false;
}
/**
* The default implementation places the given text into the editable,
* replacing any existing composing text. The new text is marked as
* in a composing state with the composing style.
*/
public boolean setComposingText(CharSequence text, int newCursorPosition) {
if (DEBUG) Log.v(TAG, "setComposingText " + text);
replaceText(text, newCursorPosition, true);
return true;
}
public boolean setComposingRegion(int start, int end) {
final Editable content = getEditable();
if (content != null) {
beginBatchEdit();
removeComposingSpans(content);
int a = start;
int b = end;
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
// Clip the end points to be within the content bounds.
final int length = content.length();
if (a < 0) a = 0;
if (b < 0) b = 0;
if (a > length) a = length;
if (b > length) b = length;
ensureDefaultComposingSpans();
if (mDefaultComposingSpans != null) {
for (int i = 0; i < mDefaultComposingSpans.length; ++i) {
content.setSpan(mDefaultComposingSpans[i], a, b,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
}
}
content.setSpan(COMPOSING, a, b,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
endBatchEdit();
sendCurrentText();
}
return true;
}
/**
* The default implementation changes the selection position in the
* current editable text.
*/
public boolean setSelection(int start, int end) {
if (DEBUG) Log.v(TAG, "setSelection " + start + ", " + end);
final Editable content = getEditable();
if (content == null) return false;
int len = content.length();
if (start > len || end > len) {
// If the given selection is out of bounds, just ignore it.
// Most likely the text was changed out from under the IME,
// the the IME is going to have to update all of its state
// anyway.
return true;
}
if (start == end && MetaKeyKeyListener.getMetaState(content,
MetaKeyKeyListener.META_SELECTING) != 0) {
// If we are in selection mode, then we want to extend the
// selection instead of replacing it.
Selection.extendSelection(content, start);
} else {
Selection.setSelection(content, start, end);
}
return true;
}
/**
* Provides standard implementation for sending a key event to the window
* attached to the input connection's view.
*/
public boolean sendKeyEvent(KeyEvent event) {
synchronized (mIMM.mH) {
Handler h = mTargetView != null ? mTargetView.getHandler() : null;
if (h == null) {
if (mIMM.mServedView != null) {
h = mIMM.mServedView.getHandler();
}
}
if (h != null) {
h.sendMessage(h.obtainMessage(ViewRoot.DISPATCH_KEY_FROM_IME,
event));
}
}
return false;
}
/**
* Updates InputMethodManager with the current fullscreen mode.
*/
public boolean reportFullscreenMode(boolean enabled) {
mIMM.setFullscreenMode(enabled);
return true;
}
private void sendCurrentText() {
if (!mDummyMode) {
return;
}
Editable content = getEditable();
if (content != null) {
final int N = content.length();
if (N == 0) {
return;
}
if (N == 1) {
// If it's 1 character, we have a chance of being
// able to generate normal key events...
if (mKeyCharacterMap == null) {
mKeyCharacterMap = KeyCharacterMap.load(
KeyCharacterMap.BUILT_IN_KEYBOARD);
}
char[] chars = new char[1];
content.getChars(0, 1, chars, 0);
KeyEvent[] events = mKeyCharacterMap.getEvents(chars);
if (events != null) {
for (int i=0; i<events.length; i++) {
if (DEBUG) Log.v(TAG, "Sending: " + events[i]);
sendKeyEvent(events[i]);
}
content.clear();
return;
}
}
// Otherwise, revert to the special key event containing
// the actual characters.
KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
content.toString(), KeyCharacterMap.BUILT_IN_KEYBOARD, 0);
sendKeyEvent(event);
content.clear();
}
}
private void ensureDefaultComposingSpans() {
if (mDefaultComposingSpans == null) {
Context context;
if (mTargetView != null) {
context = mTargetView.getContext();
} else if (mIMM.mServedView != null) {
context = mIMM.mServedView.getContext();
} else {
context = null;
}
if (context != null) {
TypedArray ta = context.getTheme()
.obtainStyledAttributes(new int[] {
com.android.internal.R.attr.candidatesTextStyleSpans
});
CharSequence style = ta.getText(0);
ta.recycle();
if (style != null && style instanceof Spanned) {
mDefaultComposingSpans = ((Spanned)style).getSpans(
0, style.length(), Object.class);
}
}
}
}
private void replaceText(CharSequence text, int newCursorPosition,
boolean composing) {
final Editable content = getEditable();
if (content == null) {
return;
}
beginBatchEdit();
// delete composing text set previously.
int a = getComposingSpanStart(content);
int b = getComposingSpanEnd(content);
if (DEBUG) Log.v(TAG, "Composing span: " + a + " to " + b);
if (b < a) {
int tmp = a;
a = b;
b = tmp;
}
if (a != -1 && b != -1) {
removeComposingSpans(content);
} else {
a = Selection.getSelectionStart(content);
b = Selection.getSelectionEnd(content);
if (a < 0) a = 0;
if (b < 0) b = 0;
if (b < a) {
int tmp = a;
a = b;
b = tmp;
}
}
if (composing) {
Spannable sp = null;
if (!(text instanceof Spannable)) {
sp = new SpannableStringBuilder(text);
text = sp;
ensureDefaultComposingSpans();
if (mDefaultComposingSpans != null) {
for (int i = 0; i < mDefaultComposingSpans.length; ++i) {
sp.setSpan(mDefaultComposingSpans[i], 0, sp.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
}
}
} else {
sp = (Spannable)text;
}
setComposingSpans(sp);
}
if (DEBUG) Log.v(TAG, "Replacing from " + a + " to " + b + " with \""
+ text + "\", composing=" + composing
+ ", type=" + text.getClass().getCanonicalName());
if (DEBUG) {
LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
lp.println("Current text:");
TextUtils.dumpSpans(content, lp, " ");
lp.println("Composing text:");
TextUtils.dumpSpans(text, lp, " ");
}
// 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;
} else {
newCursorPosition += a;
}
if (newCursorPosition < 0) newCursorPosition = 0;
if (newCursorPosition > content.length())
newCursorPosition = content.length();
Selection.setSelection(content, newCursorPosition);
content.replace(a, b, text);
if (DEBUG) {
LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
lp.println("Final text:");
TextUtils.dumpSpans(content, lp, " ");
}
endBatchEdit();
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable CompletionInfo;

View File

@ -0,0 +1,131 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Information about a single text completion that an editor has reported to
* an input method.
*/
public final class CompletionInfo implements Parcelable {
static final String TAG = "CompletionInfo";
final long mId;
final int mPosition;
final CharSequence mText;
final CharSequence mLabel;
/**
* Create a simple completion with just text, no label.
*/
public CompletionInfo(long id, int index, CharSequence text) {
mId = id;
mPosition = index;
mText = text;
mLabel = null;
}
/**
* Create a full completion with both text and label.
*/
public CompletionInfo(long id, int index, CharSequence text, CharSequence label) {
mId = id;
mPosition = index;
mText = text;
mLabel = label;
}
CompletionInfo(Parcel source) {
mId = source.readLong();
mPosition = source.readInt();
mText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
}
/**
* Return the abstract identifier for this completion, typically
* corresponding to the id associated with it in the original adapter.
*/
public long getId() {
return mId;
}
/**
* Return the original position of this completion, typically
* corresponding to its position in the original adapter.
*/
public int getPosition() {
return mPosition;
}
/**
* Return the actual text associated with this completion. This is the
* real text that will be inserted into the editor if the user selects it.
*/
public CharSequence getText() {
return mText;
}
/**
* Return the user-visible label for the completion, or null if the plain
* text should be shown. If non-null, this will be what the user sees as
* the completion option instead of the actual text.
*/
public CharSequence getLabel() {
return mLabel;
}
@Override
public String toString() {
return "CompletionInfo{#" + mPosition + " \"" + mText
+ "\" id=" + mId + " label=" + mLabel + "}";
}
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(mId);
dest.writeInt(mPosition);
TextUtils.writeToParcel(mText, dest, flags);
TextUtils.writeToParcel(mLabel, dest, flags);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<CompletionInfo> CREATOR
= new Parcelable.Creator<CompletionInfo>() {
public CompletionInfo createFromParcel(Parcel source) {
return new CompletionInfo(source);
}
public CompletionInfo[] newArray(int size) {
return new CompletionInfo[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable EditorInfo;

View File

@ -0,0 +1,318 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Printer;
/**
* An EditorInfo describes several attributes of a text editing object
* that an input method is communicating with (typically an EditText), most
* importantly the type of text content it contains.
*/
public class EditorInfo implements InputType, Parcelable {
/**
* The content type of the text box, whose bits are defined by
* {@link InputType}.
*
* @see InputType
* @see #TYPE_MASK_CLASS
* @see #TYPE_MASK_VARIATION
* @see #TYPE_MASK_FLAGS
*/
public int inputType = TYPE_NULL;
/**
* Set of bits in {@link #imeOptions} that provide alternative actions
* associated with the "enter" key. This both helps the IME provide
* better feedback about what the enter key will do, and also allows it
* to provide alternative mechanisms for providing that command.
*/
public static final int IME_MASK_ACTION = 0x000000ff;
/**
* Bits of {@link #IME_MASK_ACTION}: no specific action has been
* associated with this editor, let the editor come up with its own if
* it can.
*/
public static final int IME_ACTION_UNSPECIFIED = 0x00000000;
/**
* Bits of {@link #IME_MASK_ACTION}: there is no available action.
*/
public static final int IME_ACTION_NONE = 0x00000001;
/**
* Bits of {@link #IME_MASK_ACTION}: the action key performs a "go"
* operation to take the user to the target of the text they typed.
* Typically used, for example, when entering a URL.
*/
public static final int IME_ACTION_GO = 0x00000002;
/**
* Bits of {@link #IME_MASK_ACTION}: the action key performs a "search"
* operation, taking the user to the results of searching for the text
* the have typed (in whatever context is appropriate).
*/
public static final int IME_ACTION_SEARCH = 0x00000003;
/**
* Bits of {@link #IME_MASK_ACTION}: the action key performs a "send"
* operation, delivering the text to its target. This is typically used
* when composing a message.
*/
public static final int IME_ACTION_SEND = 0x00000004;
/**
* Bits of {@link #IME_MASK_ACTION}: the action key performs a "next"
* operation, taking the user to the next field that will accept text.
*/
public static final int IME_ACTION_NEXT = 0x00000005;
/**
* Bits of {@link #IME_MASK_ACTION}: the action key performs a "done"
* operation, typically meaning the IME will be closed.
*/
public static final int IME_ACTION_DONE = 0x00000006;
/**
* Flag of {@link #imeOptions}: used to specify that the IME does not need
* to show its extracted text UI. For input methods that may be fullscreen,
* often when in landscape mode, this allows them to be smaller and let part
* of the application be shown behind. Though there will likely be limited
* access to the application available from the user, it can make the
* experience of a (mostly) fullscreen IME less jarring. Note that when
* this flag is specified the IME may <em>not</em> be set up to be able
* to display text, so it should only be used in situations where this is
* not needed.
*/
public static final int IME_FLAG_NO_EXTRACT_UI = 0x10000000;
/**
* Flag of {@link #imeOptions}: used in conjunction with
* {@link #IME_MASK_ACTION}, this indicates that the action should not
* be available as an accessory button when the input method is full-screen.
* Note that by setting this flag, there can be cases where the action
* is simply never available to the user. Setting this generally means
* that you think showing text being edited is more important than the
* action you have supplied.
*/
public static final int IME_FLAG_NO_ACCESSORY_ACTION = 0x20000000;
/**
* Flag of {@link #imeOptions}: used in conjunction with
* {@link #IME_MASK_ACTION}, this indicates that the action should not
* be available in-line as a replacement for "enter" key. Typically this is
* because the action has such a significant impact or is not recoverable
* enough that accidentally hitting it should be avoided, such as sending
* a message. Note that {@link android.widget.TextView} will automatically set this
* flag for you on multi-line text views.
*/
public static final int IME_FLAG_NO_ENTER_ACTION = 0x40000000;
/**
* Flag of {@link #imeOptions}: used to request that the IME never go
* into fullscreen mode. Applications need to be aware that the flag is not
* a guarantee, and not all IMEs will respect it.
* @hide
*/
public static final int IME_FLAG_NO_FULLSCREEN = 0x80000000;
/**
* Generic unspecified type for {@link #imeOptions}.
*/
public static final int IME_NULL = 0x00000000;
/**
* Extended type information for the editor, to help the IME better
* integrate with it.
*/
public int imeOptions = IME_NULL;
/**
* A string supplying additional information options that are
* private to a particular IME implementation. The string must be
* scoped to a package owned by the implementation, to ensure there are
* no conflicts between implementations, but other than that you can put
* whatever you want in it to communicate with the IME. For example,
* you could have a string that supplies an argument like
* <code>"com.example.myapp.SpecialMode=3"</code>. This field is can be
* filled in from the {@link android.R.attr#privateImeOptions}
* attribute of a TextView.
*/
public String privateImeOptions = null;
/**
* In some cases an IME may be able to display an arbitrary label for
* a command the user can perform, which you can specify here. You can
* not count on this being used.
*/
public CharSequence actionLabel = null;
/**
* If {@link #actionLabel} has been given, this is the id for that command
* when the user presses its button that is delivered back with
* {@link InputConnection#performEditorAction(int)
* InputConnection.performEditorAction()}.
*/
public int actionId = 0;
/**
* The text offset of the start of the selection at the time editing
* began; -1 if not known.
*/
public int initialSelStart = -1;
/**
* The text offset of the end of the selection at the time editing
* began; -1 if not known.
*/
public int initialSelEnd = -1;
/**
* The capitalization mode of the first character being edited in the
* text. Values may be any combination of
* {@link TextUtils#CAP_MODE_CHARACTERS TextUtils.CAP_MODE_CHARACTERS},
* {@link TextUtils#CAP_MODE_WORDS TextUtils.CAP_MODE_WORDS}, and
* {@link TextUtils#CAP_MODE_SENTENCES TextUtils.CAP_MODE_SENTENCES}, though
* you should generally just take a non-zero value to mean start out in
* caps mode.
*/
public int initialCapsMode = 0;
/**
* The "hint" text of the text view, typically shown in-line when the
* text is empty to tell the user what to enter.
*/
public CharSequence hintText;
/**
* A label to show to the user describing the text they are writing.
*/
public CharSequence label;
/**
* Name of the package that owns this editor.
*/
public String packageName;
/**
* Identifier for the editor's field. This is optional, and may be
* 0. By default it is filled in with the result of
* {@link android.view.View#getId() View.getId()} on the View that
* is being edited.
*/
public int fieldId;
/**
* Additional name for the editor's field. This can supply additional
* name information for the field. By default it is null. The actual
* contents have no meaning.
*/
public String fieldName;
/**
* Any extra data to supply to the input method. This is for extended
* communication with specific input methods; the name fields in the
* bundle should be scoped (such as "com.mydomain.im.SOME_FIELD") so
* that they don't conflict with others. This field is can be
* filled in from the {@link android.R.attr#editorExtras}
* attribute of a TextView.
*/
public Bundle extras;
/**
* Write debug output of this object.
*/
public void dump(Printer pw, String prefix) {
pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType)
+ " imeOptions=0x" + Integer.toHexString(imeOptions)
+ " privateImeOptions=" + privateImeOptions);
pw.println(prefix + "actionLabel=" + actionLabel
+ " actionId=" + actionId);
pw.println(prefix + "initialSelStart=" + initialSelStart
+ " initialSelEnd=" + initialSelEnd
+ " initialCapsMode=0x"
+ Integer.toHexString(initialCapsMode));
pw.println(prefix + "hintText=" + hintText
+ " label=" + label);
pw.println(prefix + "packageName=" + packageName
+ " fieldId=" + fieldId
+ " fieldName=" + fieldName);
pw.println(prefix + "extras=" + extras);
}
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(inputType);
dest.writeInt(imeOptions);
dest.writeString(privateImeOptions);
TextUtils.writeToParcel(actionLabel, dest, flags);
dest.writeInt(actionId);
dest.writeInt(initialSelStart);
dest.writeInt(initialSelEnd);
dest.writeInt(initialCapsMode);
TextUtils.writeToParcel(hintText, dest, flags);
TextUtils.writeToParcel(label, dest, flags);
dest.writeString(packageName);
dest.writeInt(fieldId);
dest.writeString(fieldName);
dest.writeBundle(extras);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<EditorInfo> CREATOR = new Parcelable.Creator<EditorInfo>() {
public EditorInfo createFromParcel(Parcel source) {
EditorInfo res = new EditorInfo();
res.inputType = source.readInt();
res.imeOptions = source.readInt();
res.privateImeOptions = source.readString();
res.actionLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
res.actionId = source.readInt();
res.initialSelStart = source.readInt();
res.initialSelEnd = source.readInt();
res.initialCapsMode = source.readInt();
res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
res.packageName = source.readString();
res.fieldId = source.readInt();
res.fieldName = source.readString();
res.extras = source.readBundle();
return res;
}
public EditorInfo[] newArray(int size) {
return new EditorInfo[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable ExtractedText;

View File

@ -0,0 +1,123 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Information about text that has been extracted for use by an input method.
*/
public class ExtractedText implements Parcelable {
/**
* The text that has been extracted.
*/
public CharSequence text;
/**
* The offset in the overall text at which the extracted text starts.
*/
public int startOffset;
/**
* If the content is a report of a partial text change, this is the
* offset where the change starts and it runs until
* {@link #partialEndOffset}. If the content is the full text, this
* field is -1.
*/
public int partialStartOffset;
/**
* If the content is a report of a partial text change, this is the offset
* where the change ends. Note that the actual text may be larger or
* smaller than the difference between this and {@link #partialEndOffset},
* meaning a reduction or increase, respectively, in the total text.
*/
public int partialEndOffset;
/**
* The offset where the selection currently starts within the extracted
* text. The real selection start position is at
* <var>startOffset</var>+<var>selectionStart</var>.
*/
public int selectionStart;
/**
* The offset where the selection currently ends within the extracted
* text. The real selection end position is at
* <var>startOffset</var>+<var>selectionEnd</var>.
*/
public int selectionEnd;
/**
* Bit for {@link #flags}: set if the text being edited can only be on
* a single line.
*/
public static final int FLAG_SINGLE_LINE = 0x0001;
/**
* Bit for {@link #flags}: set if the editor is currently in selection mode.
*/
public static final int FLAG_SELECTING = 0x0002;
/**
* Additional bit flags of information about the edited text.
*/
public int flags;
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
TextUtils.writeToParcel(text, dest, flags);
dest.writeInt(startOffset);
dest.writeInt(partialStartOffset);
dest.writeInt(partialEndOffset);
dest.writeInt(selectionStart);
dest.writeInt(selectionEnd);
dest.writeInt(this.flags);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<ExtractedText> CREATOR = new Parcelable.Creator<ExtractedText>() {
public ExtractedText createFromParcel(Parcel source) {
ExtractedText res = new ExtractedText();
res.text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
res.startOffset = source.readInt();
res.partialStartOffset = source.readInt();
res.partialEndOffset = source.readInt();
res.selectionStart = source.readInt();
res.selectionEnd = source.readInt();
res.flags = source.readInt();
return res;
}
public ExtractedText[] newArray(int size) {
return new ExtractedText[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable ExtractedTextRequest;

View File

@ -0,0 +1,86 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Description of what an input method would like from an application when
* extract text from its input editor.
*/
public class ExtractedTextRequest implements Parcelable {
/**
* Arbitrary integer that can be supplied in the request, which will be
* delivered back when reporting updates.
*/
public int token;
/**
* Additional request flags, having the same possible values as the
* flags parameter of {@link InputConnection#getTextBeforeCursor
* InputConnection.getTextBeforeCursor()}.
*/
public int flags;
/**
* Hint for the maximum number of lines to return.
*/
public int hintMaxLines;
/**
* Hint for the maximum number of characters to return.
*/
public int hintMaxChars;
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(token);
dest.writeInt(this.flags);
dest.writeInt(hintMaxLines);
dest.writeInt(hintMaxChars);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<ExtractedTextRequest> CREATOR
= new Parcelable.Creator<ExtractedTextRequest>() {
public ExtractedTextRequest createFromParcel(Parcel source) {
ExtractedTextRequest res = new ExtractedTextRequest();
res.token = source.readInt();
res.flags = source.readInt();
res.hintMaxLines = source.readInt();
res.hintMaxChars = source.readInt();
return res;
}
public ExtractedTextRequest[] newArray(int size) {
return new ExtractedTextRequest[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable InputBinding;

View File

@ -0,0 +1,152 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Information given to an {@link InputMethod} about a client connecting
* to it.
*/
public final class InputBinding implements Parcelable {
static final String TAG = "InputBinding";
/**
* The connection back to the client.
*/
final InputConnection mConnection;
/**
* A remotable token for the connection back to the client.
*/
final IBinder mConnectionToken;
/**
* The UID where this binding came from.
*/
final int mUid;
/**
* The PID where this binding came from.
*/
final int mPid;
/**
* Constructor.
*
* @param conn The interface for communicating back with the application.
* @param connToken A remoteable token for communicating across processes.
* @param uid The user id of the client of this binding.
* @param pid The process id of where the binding came from.
*/
public InputBinding(InputConnection conn, IBinder connToken,
int uid, int pid) {
mConnection = conn;
mConnectionToken = connToken;
mUid = uid;
mPid = pid;
}
/**
* Constructor from an existing InputBinding taking a new local input
* connection interface.
*
* @param conn The new connection interface.
* @param binding Existing binding to copy.
*/
public InputBinding(InputConnection conn, InputBinding binding) {
mConnection = conn;
mConnectionToken = binding.getConnectionToken();
mUid = binding.getUid();
mPid = binding.getPid();
}
InputBinding(Parcel source) {
mConnection = null;
mConnectionToken = source.readStrongBinder();
mUid = source.readInt();
mPid = source.readInt();
}
/**
* Return the connection for interacting back with the application.
*/
public InputConnection getConnection() {
return mConnection;
}
/**
* Return the token for the connection back to the application. You can
* not use this directly, it must be converted to a {@link InputConnection}
* for you.
*/
public IBinder getConnectionToken() {
return mConnectionToken;
}
/**
* Return the user id of the client associated with this binding.
*/
public int getUid() {
return mUid;
}
/**
* Return the process id where this binding came from.
*/
public int getPid() {
return mPid;
}
@Override
public String toString() {
return "InputBinding{" + mConnectionToken
+ " / uid " + mUid + " / pid " + mPid + "}";
}
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeStrongBinder(mConnectionToken);
dest.writeInt(mUid);
dest.writeInt(mPid);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<InputBinding> CREATOR = new Parcelable.Creator<InputBinding>() {
public InputBinding createFromParcel(Parcel source) {
return new InputBinding(source);
}
public InputBinding[] newArray(int size) {
return new InputBinding[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@ -0,0 +1,346 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.os.Bundle;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
/**
* The InputConnection interface is the communication channel from an
* {@link InputMethod} back to the application that is receiving its input. It
* is used to perform such things as reading text around the cursor,
* committing text to the text box, and sending raw key events to the application.
*
* <p>Implementations of this interface should generally be done by
* subclassing {@link BaseInputConnection}.
*/
public interface InputConnection {
/**
* Flag for use with {@link #getTextAfterCursor} and
* {@link #getTextBeforeCursor} to have style information returned along
* with the text. If not set, you will receive only the raw text. If
* set, you may receive a complex CharSequence of both text and style
* spans.
*/
static final int GET_TEXT_WITH_STYLES = 0x0001;
/**
* Flag for use with {@link #getExtractedText} to indicate you would
* like to receive updates when the extracted text changes.
*/
public static final int GET_EXTRACTED_TEXT_MONITOR = 0x0001;
/**
* Get <var>n</var> characters of text before the current cursor position.
*
* <p>This method may fail either if the input connection has become invalid
* (such as its process crashing) or the client is taking too long to
* respond with the text (it is given a couple seconds to return).
* In either case, a null is returned.
*
* @param n The expected length of the text.
* @param flags Supplies additional options controlling how the text is
* returned. May be either 0 or {@link #GET_TEXT_WITH_STYLES}.
*
* @return Returns the text before the cursor position; the length of the
* returned text might be less than <var>n</var>.
*/
public CharSequence getTextBeforeCursor(int n, int flags);
/**
* Get <var>n</var> characters of text after the current cursor position.
*
* <p>This method may fail either if the input connection has become invalid
* (such as its process crashing) or the client is taking too long to
* respond with the text (it is given a couple seconds to return).
* In either case, a null is returned.
*
* @param n The expected length of the text.
* @param flags Supplies additional options controlling how the text is
* returned. May be either 0 or {@link #GET_TEXT_WITH_STYLES}.
*
* @return Returns the text after the cursor position; the length of the
* returned text might be less than <var>n</var>.
*/
public CharSequence getTextAfterCursor(int n, int flags);
/**
* Gets the selected text, if any.
*
* <p>This method may fail if either the input connection has become
* invalid (such as its process crashing) or the client is taking too
* long to respond with the text (it is given a couple of seconds to return).
* In either case, a null is returned.
*
* @param flags Supplies additional options controlling how the text is
* returned. May be either 0 or {@link #GET_TEXT_WITH_STYLES}.
* @return Returns the text that is currently selected, if any, or null if
* no text is selected.
*/
public CharSequence getSelectedText(int flags);
/**
* Retrieve the current capitalization mode in effect at the current
* cursor position in the text. See
* {@link android.text.TextUtils#getCapsMode TextUtils.getCapsMode} for
* more information.
*
* <p>This method may fail either if the input connection has become invalid
* (such as its process crashing) or the client is taking too long to
* respond with the text (it is given a couple seconds to return).
* In either case, a 0 is returned.
*
* @param reqModes The desired modes to retrieve, as defined by
* {@link android.text.TextUtils#getCapsMode TextUtils.getCapsMode}. These
* constants are defined so that you can simply pass the current
* {@link EditorInfo#inputType TextBoxAttribute.contentType} value
* directly in to here.
*
* @return Returns the caps mode flags that are in effect.
*/
public int getCursorCapsMode(int reqModes);
/**
* Retrieve the current text in the input connection's editor, and monitor
* for any changes to it. This function returns with the current text,
* and optionally the input connection can send updates to the
* input method when its text changes.
*
* <p>This method may fail either if the input connection has become invalid
* (such as its process crashing) or the client is taking too long to
* respond with the text (it is given a couple seconds to return).
* In either case, a null is returned.
*
* @param request Description of how the text should be returned.
* @param flags Additional options to control the client, either 0 or
* {@link #GET_EXTRACTED_TEXT_MONITOR}.
*
* @return Returns an ExtractedText object describing the state of the
* text view and containing the extracted text itself.
*/
public ExtractedText getExtractedText(ExtractedTextRequest request,
int flags);
/**
* Delete <var>leftLength</var> characters of text before the current cursor
* position, and delete <var>rightLength</var> characters of text after the
* current cursor position, excluding composing text.
*
* @param leftLength The number of characters to be deleted before the
* current cursor position.
* @param rightLength The number of characters to be deleted after the
* current cursor position.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean deleteSurroundingText(int leftLength, int rightLength);
/**
* Set composing text around the current cursor position with the given text,
* and set the new cursor position. Any composing text set previously will
* be removed automatically.
*
* @param text The composing text with styles if necessary. If no style
* object attached to the text, the default style for composing text
* is used. See {#link android.text.Spanned} for how to attach style
* object to the text. {#link android.text.SpannableString} and
* {#link android.text.SpannableStringBuilder} are two
* implementations of the interface {#link android.text.Spanned}.
* @param newCursorPosition The new cursor position around the text. If
* > 0, this is relative to the end of the text - 1; if <= 0, this
* is relative to the start of the text. So a value of 1 will
* always advance you to the position after the full text being
* inserted. Note that this means you can't position the cursor
* within the text, because the editor can make modifications to
* the text you are providing so it is not possible to correctly
* specify locations there.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean setComposingText(CharSequence text, int newCursorPosition);
/**
* Mark a certain region of text as composing text. Any composing text set
* previously will be removed automatically. The default style for composing
* text is used.
*
* @param start the position in the text at which the composing region begins
* @param end the position in the text at which the composing region ends
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean setComposingRegion(int start, int end);
/**
* Have the text editor finish whatever composing text is currently
* active. This simply leaves the text as-is, removing any special
* composing styling or other state that was around it. The cursor
* position remains unchanged.
*/
public boolean finishComposingText();
/**
* Commit text to the text box and set the new cursor position.
* Any composing text set previously will be removed
* automatically.
*
* @param text The committed text.
* @param newCursorPosition The new cursor position around the text. If
* > 0, this is relative to the end of the text - 1; if <= 0, this
* is relative to the start of the text. So a value of 1 will
* always advance you to the position after the full text being
* inserted. Note that this means you can't position the cursor
* within the text, because the editor can make modifications to
* the text you are providing so it is not possible to correctly
* specify locations there.
*
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean commitText(CharSequence text, int newCursorPosition);
/**
* Commit a completion the user has selected from the possible ones
* previously reported to {@link InputMethodSession#displayCompletions
* InputMethodSession.displayCompletions()}. This will result in the
* same behavior as if the user had selected the completion from the
* actual UI.
*
* @param text The committed completion.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean commitCompletion(CompletionInfo text);
/**
* Set the selection of the text editor. To set the cursor position,
* start and end should have the same value.
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean setSelection(int start, int end);
/**
* Have the editor perform an action it has said it can do.
*
* @param editorAction This must be one of the action constants for
* {@link EditorInfo#imeOptions EditorInfo.editorType}, such as
* {@link EditorInfo#IME_ACTION_GO EditorInfo.EDITOR_ACTION_GO}.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean performEditorAction(int editorAction);
/**
* Perform a context menu action on the field. The given id may be one of:
* {@link android.R.id#selectAll},
* {@link android.R.id#startSelectingText}, {@link android.R.id#stopSelectingText},
* {@link android.R.id#cut}, {@link android.R.id#copy},
* {@link android.R.id#paste}, {@link android.R.id#copyUrl},
* or {@link android.R.id#switchInputMethod}
*/
public boolean performContextMenuAction(int id);
/**
* Tell the editor that you are starting a batch of editor operations.
* The editor will try to avoid sending you updates about its state
* until {@link #endBatchEdit} is called.
*/
public boolean beginBatchEdit();
/**
* Tell the editor that you are done with a batch edit previously
* initiated with {@link #endBatchEdit}.
*/
public boolean endBatchEdit();
/**
* Send a key event to the process that is currently attached through
* this input connection. The event will be dispatched like a normal
* key event, to the currently focused; this generally is the view that
* is providing this InputConnection, but due to the asynchronous nature
* of this protocol that can not be guaranteed and the focus may have
* changed by the time the event is received.
*
* <p>
* This method can be used to send key events to the application. For
* example, an on-screen keyboard may use this method to simulate a hardware
* keyboard. There are three types of standard keyboards, numeric (12-key),
* predictive (20-key) and ALPHA (QWERTY). You can specify the keyboard type
* by specify the device id of the key event.
*
* <p>
* You will usually want to set the flag
* {@link KeyEvent#FLAG_SOFT_KEYBOARD KeyEvent.FLAG_SOFT_KEYBOARD} on all
* key event objects you give to this API; the flag will not be set
* for you.
*
* @param event The key event.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*
* @see KeyEvent
* @see KeyCharacterMap#NUMERIC
* @see KeyCharacterMap#PREDICTIVE
* @see KeyCharacterMap#ALPHA
*/
public boolean sendKeyEvent(KeyEvent event);
/**
* Clear the given meta key pressed states in the given input connection.
*
* @param states The states to be cleared, may be one or more bits as
* per {@link KeyEvent#getMetaState() KeyEvent.getMetaState()}.
*
* @return Returns true on success, false if the input connection is no longer
* valid.
*/
public boolean clearMetaKeyStates(int states);
/**
* Called by the IME to tell the client when it switches between fullscreen
* and normal modes. This will normally be called for you by the standard
* implementation of {@link android.inputmethodservice.InputMethodService}.
*/
public boolean reportFullscreenMode(boolean enabled);
/**
* API to send private commands from an input method to its connected
* editor. This can be used to provide domain-specific features that are
* only known between certain input methods and their clients. Note that
* because the InputConnection protocol is asynchronous, you have no way
* to get a result back or know if the client understood the command; you
* can use the information in {@link EditorInfo} to determine if
* a client supports a particular command.
*
* @param action Name of the command to be performed. This <em>must</em>
* be a scoped name, i.e. prefixed with a package name you own, so that
* different developers will not create conflicting commands.
* @param data Any data to include with the command.
* @return Returns true if the command was sent (whether or not the
* associated editor understood it), false if the input connection is no longer
* valid.
*/
public boolean performPrivateCommand(String action, Bundle data);
}

View File

@ -0,0 +1,125 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.os.Bundle;
import android.view.KeyEvent;
/**
* <p>Wrapper class for proxying calls to another InputConnection. Subclass
* and have fun!
*/
public class InputConnectionWrapper implements InputConnection {
private InputConnection mTarget;
final boolean mMutable;
public InputConnectionWrapper(InputConnection target, boolean mutable) {
mMutable = mutable;
mTarget = target;
}
/**
* Change the target of the input connection.
*/
public void setTarget(InputConnection target) {
if (mTarget != null && !mMutable) {
throw new SecurityException("not mutable");
}
mTarget = target;
}
public CharSequence getTextBeforeCursor(int n, int flags) {
return mTarget.getTextBeforeCursor(n, flags);
}
public CharSequence getTextAfterCursor(int n, int flags) {
return mTarget.getTextAfterCursor(n, flags);
}
public CharSequence getSelectedText(int flags) {
return mTarget.getSelectedText(flags);
}
public int getCursorCapsMode(int reqModes) {
return mTarget.getCursorCapsMode(reqModes);
}
public ExtractedText getExtractedText(ExtractedTextRequest request,
int flags) {
return mTarget.getExtractedText(request, flags);
}
public boolean deleteSurroundingText(int leftLength, int rightLength) {
return mTarget.deleteSurroundingText(leftLength, rightLength);
}
public boolean setComposingText(CharSequence text, int newCursorPosition) {
return mTarget.setComposingText(text, newCursorPosition);
}
public boolean setComposingRegion(int start, int end) {
return mTarget.setComposingRegion(start, end);
}
public boolean finishComposingText() {
return mTarget.finishComposingText();
}
public boolean commitText(CharSequence text, int newCursorPosition) {
return mTarget.commitText(text, newCursorPosition);
}
public boolean commitCompletion(CompletionInfo text) {
return mTarget.commitCompletion(text);
}
public boolean setSelection(int start, int end) {
return mTarget.setSelection(start, end);
}
public boolean performEditorAction(int editorAction) {
return mTarget.performEditorAction(editorAction);
}
public boolean performContextMenuAction(int id) {
return mTarget.performContextMenuAction(id);
}
public boolean beginBatchEdit() {
return mTarget.beginBatchEdit();
}
public boolean endBatchEdit() {
return mTarget.endBatchEdit();
}
public boolean sendKeyEvent(KeyEvent event) {
return mTarget.sendKeyEvent(event);
}
public boolean clearMetaKeyStates(int states) {
return mTarget.clearMetaKeyStates(states);
}
public boolean reportFullscreenMode(boolean enabled) {
return mTarget.reportFullscreenMode(enabled);
}
public boolean performPrivateCommand(String action, Bundle data) {
return mTarget.performPrivateCommand(action, data);
}
}

View File

@ -0,0 +1,222 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.inputmethodservice.InputMethodService;
import android.os.IBinder;
import android.os.ResultReceiver;
/**
* The InputMethod interface represents an input method which can generate key
* events and text, such as digital, email addresses, CJK characters, other
* language characters, and etc., while handling various input events, and send
* the text back to the application that requests text input. See
* {@link InputMethodManager} for more general information about the
* architecture.
*
* <p>Applications will not normally use this interface themselves, instead
* relying on the standard interaction provided by
* {@link android.widget.TextView} and {@link android.widget.EditText}.
*
* <p>Those implementing input methods should normally do so by deriving from
* {@link InputMethodService} or one of its subclasses. When implementing
* an input method, the service component containing it must also supply
* a {@link #SERVICE_META_DATA} meta-data field, referencing an XML resource
* providing details about the input method. All input methods also must
* require that clients hold the
* {@link android.Manifest.permission#BIND_INPUT_METHOD} in order to interact
* with the service; if this is not required, the system will not use that
* input method, because it can not trust that it is not compromised.
*
* <p>The InputMethod interface is actually split into two parts: the interface
* here is the top-level interface to the input method, providing all
* access to it, which only the system can access (due to the BIND_INPUT_METHOD
* permission requirement). In addition its method
* {@link #createSession(android.view.inputmethod.InputMethod.SessionCallback)}
* can be called to instantate a secondary {@link InputMethodSession} interface
* which is what clients use to communicate with the input method.
*/
public interface InputMethod {
/**
* This is the interface name that a service implementing an input
* method should say that it supports -- that is, this is the action it
* uses for its intent filter.
* To be supported, the service must also require the
* {@link android.Manifest.permission#BIND_INPUT_METHOD} permission so
* that other applications can not abuse it.
*/
@SdkConstant(SdkConstantType.SERVICE_ACTION)
public static final String SERVICE_INTERFACE = "android.view.InputMethod";
/**
* Name under which an InputMethod service component publishes information
* about itself. This meta-data must reference an XML resource containing
* an
* <code>&lt;{@link android.R.styleable#InputMethod input-method}&gt;</code>
* tag.
*/
public static final String SERVICE_META_DATA = "android.view.im";
public interface SessionCallback {
public void sessionCreated(InputMethodSession session);
}
/**
* Called first thing after an input method is created, this supplies a
* unique token for the session it has with the system service. It is
* needed to identify itself with the service to validate its operations.
* This token <strong>must not</strong> be passed to applications, since
* it grants special priviledges that should not be given to applications.
*
* <p>Note: to protect yourself from malicious clients, you should only
* accept the first token given to you. Any after that may come from the
* client.
*/
public void attachToken(IBinder token);
/**
* Bind a new application environment in to the input method, so that it
* can later start and stop input processing.
* Typically this method is called when this input method is enabled in an
* application for the first time.
*
* @param binding Information about the application window that is binding
* to the input method.
*
* @see InputBinding
* @see #unbindInput()
*/
public void bindInput(InputBinding binding);
/**
* Unbind an application environment, called when the information previously
* set by {@link #bindInput} is no longer valid for this input method.
*
* <p>
* Typically this method is called when the application changes to be
* non-foreground.
*/
public void unbindInput();
/**
* This method is called when the application starts to receive text and it
* is ready for this input method to process received events and send result
* text back to the application.
*
* @param inputConnection Optional specific input connection for
* communicating with the text box; if null, you should use the generic
* bound input connection.
* @param info Information about the text box (typically, an EditText)
* that requests input.
*
* @see EditorInfo
*/
public void startInput(InputConnection inputConnection, EditorInfo info);
/**
* This method is called when the state of this input method needs to be
* reset.
*
* <p>
* Typically, this method is called when the input focus is moved from one
* text box to another.
*
* @param inputConnection Optional specific input connection for
* communicating with the text box; if null, you should use the generic
* bound input connection.
* @param attribute The attribute of the text box (typically, a EditText)
* that requests input.
*
* @see EditorInfo
*/
public void restartInput(InputConnection inputConnection, EditorInfo attribute);
/**
* Create a new {@link InputMethodSession} that can be handed to client
* applications for interacting with the input method. You can later
* use {@link #revokeSession(InputMethodSession)} to destroy the session
* so that it can no longer be used by any clients.
*
* @param callback Interface that is called with the newly created session.
*/
public void createSession(SessionCallback callback);
/**
* Control whether a particular input method session is active.
*
* @param session The {@link InputMethodSession} previously provided through
* SessionCallback.sessionCreated() that is to be changed.
*/
public void setSessionEnabled(InputMethodSession session, boolean enabled);
/**
* Disable and destroy a session that was previously created with
* {@link #createSession(android.view.inputmethod.InputMethod.SessionCallback)}.
* After this call, the given session interface is no longer active and
* calls on it will fail.
*
* @param session The {@link InputMethodSession} previously provided through
* SessionCallback.sessionCreated() that is to be revoked.
*/
public void revokeSession(InputMethodSession session);
/**
* Flag for {@link #showSoftInput}: this show has been explicitly
* requested by the user. If not set, the system has decided it may be
* a good idea to show the input method based on a navigation operation
* in the UI.
*/
public static final int SHOW_EXPLICIT = 0x00001;
/**
* Flag for {@link #showSoftInput}: this show has been forced to
* happen by the user. If set, the input method should remain visible
* until deliberated dismissed by the user in its UI.
*/
public static final int SHOW_FORCED = 0x00002;
/**
* Request that any soft input part of the input method be shown to the user.
*
* @param flags Provides additional information about the show request.
* Currently may be 0 or have the bit {@link #SHOW_EXPLICIT} set.
* @param resultReceiver The client requesting the show may wish to
* be told the impact of their request, which should be supplied here.
* The result code should be
* {@link InputMethodManager#RESULT_UNCHANGED_SHOWN InputMethodManager.RESULT_UNCHANGED_SHOWN},
* {@link InputMethodManager#RESULT_UNCHANGED_HIDDEN InputMethodManager.RESULT_UNCHANGED_HIDDEN},
* {@link InputMethodManager#RESULT_SHOWN InputMethodManager.RESULT_SHOWN}, or
* {@link InputMethodManager#RESULT_HIDDEN InputMethodManager.RESULT_HIDDEN}.
*/
public void showSoftInput(int flags, ResultReceiver resultReceiver);
/**
* Request that any soft input part of the input method be hidden from the user.
* @param flags Provides additional information about the show request.
* Currently always 0.
* @param resultReceiver The client requesting the show may wish to
* be told the impact of their request, which should be supplied here.
* The result code should be
* {@link InputMethodManager#RESULT_UNCHANGED_SHOWN InputMethodManager.RESULT_UNCHANGED_SHOWN},
* {@link InputMethodManager#RESULT_UNCHANGED_HIDDEN InputMethodManager.RESULT_UNCHANGED_HIDDEN},
* {@link InputMethodManager#RESULT_SHOWN InputMethodManager.RESULT_SHOWN}, or
* {@link InputMethodManager#RESULT_HIDDEN InputMethodManager.RESULT_HIDDEN}.
*/
public void hideSoftInput(int flags, ResultReceiver resultReceiver);
}

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2008 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 android.view.inputmethod;
parcelable InputMethodInfo;

View File

@ -0,0 +1,306 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Printer;
import android.util.Xml;
import java.io.IOException;
/**
* This class is used to specify meta information of an input method.
*/
public final class InputMethodInfo implements Parcelable {
static final String TAG = "InputMethodInfo";
/**
* The Service that implements this input method component.
*/
final ResolveInfo mService;
/**
* The unique string Id to identify the input method. This is generated
* from the input method component.
*/
final String mId;
/**
* The input method setting activity's name, used by the system settings to
* launch the setting activity of this input method.
*/
final String mSettingsActivityName;
/**
* The resource in the input method's .apk that holds a boolean indicating
* whether it should be considered the default input method for this
* system. This is a resource ID instead of the final value so that it
* can change based on the configuration (in particular locale).
*/
final int mIsDefaultResId;
/**
* Constructor.
*
* @param context The Context in which we are parsing the input method.
* @param service The ResolveInfo returned from the package manager about
* this input method's component.
*/
public InputMethodInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
mService = service;
ServiceInfo si = service.serviceInfo;
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
PackageManager pm = context.getPackageManager();
String settingsActivityComponent = null;
int isDefaultResId = 0;
XmlResourceParser parser = null;
try {
parser = si.loadXmlMetaData(pm, InputMethod.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException("No "
+ InputMethod.SERVICE_META_DATA + " meta-data");
}
Resources res = pm.getResourcesForApplication(si.applicationInfo);
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
}
String nodeName = parser.getName();
if (!"input-method".equals(nodeName)) {
throw new XmlPullParserException(
"Meta-data does not start with input-method tag");
}
TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.InputMethod);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.InputMethod_settingsActivity);
isDefaultResId = sa.getResourceId(
com.android.internal.R.styleable.InputMethod_isDefault, 0);
sa.recycle();
} catch (NameNotFoundException e) {
throw new XmlPullParserException(
"Unable to create context for: " + si.packageName);
} finally {
if (parser != null) parser.close();
}
mSettingsActivityName = settingsActivityComponent;
mIsDefaultResId = isDefaultResId;
}
InputMethodInfo(Parcel source) {
mId = source.readString();
mSettingsActivityName = source.readString();
mIsDefaultResId = source.readInt();
mService = ResolveInfo.CREATOR.createFromParcel(source);
}
/**
* Temporary API for creating a built-in input method.
*/
public InputMethodInfo(String packageName, String className,
CharSequence label, String settingsActivity) {
ResolveInfo ri = new ResolveInfo();
ServiceInfo si = new ServiceInfo();
ApplicationInfo ai = new ApplicationInfo();
ai.packageName = packageName;
ai.enabled = true;
si.applicationInfo = ai;
si.enabled = true;
si.packageName = packageName;
si.name = className;
si.exported = true;
si.nonLocalizedLabel = label;
ri.serviceInfo = si;
mService = ri;
mId = new ComponentName(si.packageName, si.name).flattenToShortString();
mSettingsActivityName = settingsActivity;
mIsDefaultResId = 0;
}
/**
* Return a unique ID for this input method. The ID is generated from
* the package and class name implementing the method.
*/
public String getId() {
return mId;
}
/**
* Return the .apk package that implements this input method.
*/
public String getPackageName() {
return mService.serviceInfo.packageName;
}
/**
* Return the class name of the service component that implements
* this input method.
*/
public String getServiceName() {
return mService.serviceInfo.name;
}
/**
* Return the raw information about the Service implementing this
* input method. Do not modify the returned object.
*/
public ServiceInfo getServiceInfo() {
return mService.serviceInfo;
}
/**
* Return the component of the service that implements this input
* method.
*/
public ComponentName getComponent() {
return new ComponentName(mService.serviceInfo.packageName,
mService.serviceInfo.name);
}
/**
* Load the user-displayed label for this input method.
*
* @param pm Supply a PackageManager used to load the input method's
* resources.
*/
public CharSequence loadLabel(PackageManager pm) {
return mService.loadLabel(pm);
}
/**
* Load the user-displayed icon for this input method.
*
* @param pm Supply a PackageManager used to load the input method's
* resources.
*/
public Drawable loadIcon(PackageManager pm) {
return mService.loadIcon(pm);
}
/**
* Return the class name of an activity that provides a settings UI for
* the input method. You can launch this activity be starting it with
* an {@link android.content.Intent} whose action is MAIN and with an
* explicit {@link android.content.ComponentName}
* composed of {@link #getPackageName} and the class name returned here.
*
* <p>A null will be returned if there is no settings activity associated
* with the input method.
*/
public String getSettingsActivity() {
return mSettingsActivityName;
}
/**
* Return the resource identifier of a resource inside of this input
* method's .apk that determines whether it should be considered a
* default input method for the system.
*/
public int getIsDefaultResourceId() {
return mIsDefaultResId;
}
public void dump(Printer pw, String prefix) {
pw.println(prefix + "mId=" + mId
+ " mSettingsActivityName=" + mSettingsActivityName);
pw.println(prefix + "mIsDefaultResId=0x"
+ Integer.toHexString(mIsDefaultResId));
pw.println(prefix + "Service:");
mService.dump(pw, prefix + " ");
}
@Override
public String toString() {
return "InputMethodInfo{" + mId
+ ", settings: "
+ mSettingsActivityName + "}";
}
/**
* Used to test whether the given parameter object is an
* {@link InputMethodInfo} and its Id is the same to this one.
*
* @return true if the given parameter object is an
* {@link InputMethodInfo} and its Id is the same to this one.
*/
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof InputMethodInfo)) return false;
InputMethodInfo obj = (InputMethodInfo) o;
return mId.equals(obj.mId);
}
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mId);
dest.writeString(mSettingsActivityName);
dest.writeInt(mIsDefaultResId);
mService.writeToParcel(dest, flags);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<InputMethodInfo> CREATOR = new Parcelable.Creator<InputMethodInfo>() {
public InputMethodInfo createFromParcel(Parcel source) {
return new InputMethodInfo(source);
}
public InputMethodInfo[] newArray(int size) {
return new InputMethodInfo[size];
}
};
public int describeContents() {
return 0;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,154 @@
/*
* Copyright (C) 2007-2008 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 android.view.inputmethod;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
/**
* The InputMethodSession interface provides the per-client functionality
* of {@link InputMethod} that is safe to expose to applications.
*
* <p>Applications will not normally use this interface themselves, instead
* relying on the standard interaction provided by
* {@link android.widget.TextView} and {@link android.widget.EditText}.
*/
public interface InputMethodSession {
public interface EventCallback {
void finishedEvent(int seq, boolean handled);
}
/**
* This method is called when the application would like to stop
* receiving text input.
*/
public void finishInput();
/**
* This method is called when the selection or cursor in the current
* target input field has changed.
*
* @param oldSelStart The previous text offset of the cursor selection
* start position.
* @param oldSelEnd The previous text offset of the cursor selection
* end position.
* @param newSelStart The new text offset of the cursor selection
* start position.
* @param newSelEnd The new text offset of the cursor selection
* end position.
* @param candidatesStart The text offset of the current candidate
* text start position.
* @param candidatesEnd The text offset of the current candidate
* text end position.
*/
public void updateSelection(int oldSelStart, int oldSelEnd,
int newSelStart, int newSelEnd,
int candidatesStart, int candidatesEnd);
/**
* This method is called when cursor location of the target input field
* has changed within its window. This is not normally called, but will
* only be reported if requested by the input method.
*
* @param newCursor The rectangle of the cursor currently being shown in
* the input field's window coordinates.
*/
public void updateCursor(Rect newCursor);
/**
* Called by a text editor that performs auto completion, to tell the
* input method about the completions it has available. This can be used
* by the input method to display them to the user to select the text to
* be inserted.
*
* @param completions Array of text completions that are available, starting with
* the best. If this array is null, any existing completions will be
* removed.
*/
public void displayCompletions(CompletionInfo[] completions);
/**
* Called by a text editor to report its new extracted text when its
* contents change. This will only be called if the input method
* calls {@link InputConnection#getExtractedText(ExtractedTextRequest, int)
* InputConnection.getExtractedText()} with the option to report updates.
*
* @param token The input method supplied token for identifying its request.
* @param text The new extracted text.
*/
public void updateExtractedText(int token, ExtractedText text);
/**
* This method is called when a key is pressed. When done with the event,
* the implementation must call back on <var>callback</var> with its
* result.
*
* <p>
* If the input method wants to handle this event, return true, otherwise
* return false and the caller (i.e. the application) will handle the event.
*
* @param event The key event.
*
* @return Whether the input method wants to handle this event.
*
* @see #dispatchKeyUp
* @see android.view.KeyEvent
*/
public void dispatchKeyEvent(int seq, KeyEvent event, EventCallback callback);
/**
* This method is called when there is a track ball event.
*
* <p>
* If the input method wants to handle this event, return true, otherwise
* return false and the caller (i.e. the application) will handle the event.
*
* @param event The motion event.
*
* @return Whether the input method wants to handle this event.
*
* @see android.view.MotionEvent
*/
public void dispatchTrackballEvent(int seq, MotionEvent event, EventCallback callback);
/**
* Process a private command sent from the application to the input method.
* This can be used to provide domain-specific features that are
* only known between certain input methods and their clients.
*
* @param action Name of the command to be performed. This <em>must</em>
* be a scoped name, i.e. prefixed with a package name you own, so that
* different developers will not create conflicting commands.
* @param data Any data to include with the command.
*/
public void appPrivateCommand(String action, Bundle data);
/**
* Toggle the soft input window.
* Applications can toggle the state of the soft input window.
* @param showFlags Provides additional operating flags. May be
* 0 or have the {@link InputMethodManager#SHOW_IMPLICIT},
* {@link InputMethodManager#SHOW_FORCED} bit set.
* @param hideFlags Provides additional operating flags. May be
* 0 or have the {@link InputMethodManager#HIDE_IMPLICIT_ONLY},
* {@link InputMethodManager#HIDE_NOT_ALWAYS} bit set.
*/
public void toggleSoftInput(int showFlags, int hideFlags);
}

View File

@ -0,0 +1,12 @@
<html>
<body>
Framework classes for interaction between views and input methods (such
as soft keyboards). See {@link android.view.inputmethod.InputMethodManager} for
an overview. In most cases the main classes here are not needed for
most applications, since they are dealt with for you by
{@link android.widget.TextView}. When implementing a custom text editor,
however, you will need to implement the
{@link android.view.inputmethod.InputConnection} class to allow the current
input method to interact with your view.
</body>
</html>