Removed APIs for setCorrectionSpan from InputConnection
("setCorrectionSpan" was added in Id3abc9ea4d11753cd )
Also..
- Added a class java doc for CorrectionSpan
- Removed FLAG_DEFAULT
- Changed the return type of getSuggestions from Array<CharSequence> to String[]
Change-Id: If5eb091e307a7a40c5b4a70ec1fe6059ecd9fb2d
This commit is contained in:
@@ -22,23 +22,21 @@ import android.os.Parcelable;
|
||||
import android.text.ParcelableSpan;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Sets correction candidates of words under this span.
|
||||
*/
|
||||
public class CorrectionSpan implements ParcelableSpan {
|
||||
|
||||
/**
|
||||
* Flag for the default value.
|
||||
*/
|
||||
public static final int FLAG_DEFAULT = 0x0000;
|
||||
/**
|
||||
* Flag for indicating that the input is verbatim. TextView refers to this flag to determine
|
||||
* how it displays a word with CorrectionSpan.
|
||||
*/
|
||||
public static final int FLAG_VERBATIM = 0x0001;
|
||||
|
||||
private static final int SUGGESTS_MAX_SIZE = 5;
|
||||
private static final int SUGGESTIONS_MAX_SIZE = 5;
|
||||
|
||||
/*
|
||||
* TODO: Needs to check the validity and add a feature that TextView will change
|
||||
@@ -48,7 +46,7 @@ public class CorrectionSpan implements ParcelableSpan {
|
||||
*/
|
||||
|
||||
private final int mFlags;
|
||||
private final List<CharSequence> mSuggests = new ArrayList<CharSequence>();
|
||||
private final String[] mSuggestions;
|
||||
private final String mLocaleString;
|
||||
private final String mOriginalString;
|
||||
/*
|
||||
@@ -58,35 +56,33 @@ public class CorrectionSpan implements ParcelableSpan {
|
||||
|
||||
/**
|
||||
* @param context Context for the application
|
||||
* @param suggests Suggests for the string under the span
|
||||
* @param suggestions Suggestions for the string under the span
|
||||
* @param flags Additional flags indicating how this span is handled in TextView
|
||||
*/
|
||||
public CorrectionSpan(Context context, List<CharSequence> suggests, int flags) {
|
||||
this(context, null, suggests, flags, null);
|
||||
public CorrectionSpan(Context context, String[] suggestions, int flags) {
|
||||
this(context, null, suggestions, flags, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param locale Locale of the suggestions
|
||||
* @param suggests Suggests for the string under the span
|
||||
* @param suggestions Suggestions for the string under the span
|
||||
* @param flags Additional flags indicating how this span is handled in TextView
|
||||
*/
|
||||
public CorrectionSpan(Locale locale, List<CharSequence> suggests, int flags) {
|
||||
this(null, locale, suggests, flags, null);
|
||||
public CorrectionSpan(Locale locale, String[] suggestions, int flags) {
|
||||
this(null, locale, suggestions, flags, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context Context for the application
|
||||
* @param locale locale Locale of the suggestions
|
||||
* @param suggests suggests Suggests for the string under the span
|
||||
* @param suggestions Suggestions for the string under the span
|
||||
* @param flags Additional flags indicating how this span is handled in TextView
|
||||
* @param originalString originalString for suggests
|
||||
* @param originalString originalString for suggestions
|
||||
*/
|
||||
public CorrectionSpan(Context context, Locale locale, List<CharSequence> suggests, int flags,
|
||||
public CorrectionSpan(Context context, Locale locale, String[] suggestions, int flags,
|
||||
String originalString) {
|
||||
final int N = Math.min(SUGGESTS_MAX_SIZE, suggests.size());
|
||||
for (int i = 0; i < N; ++i) {
|
||||
mSuggests.add(suggests.get(i));
|
||||
}
|
||||
final int N = Math.min(SUGGESTIONS_MAX_SIZE, suggestions.length);
|
||||
mSuggestions = Arrays.copyOf(suggestions, N);
|
||||
mFlags = flags;
|
||||
if (context != null && locale == null) {
|
||||
mLocaleString = context.getResources().getConfiguration().locale.toString();
|
||||
@@ -97,7 +93,7 @@ public class CorrectionSpan implements ParcelableSpan {
|
||||
}
|
||||
|
||||
public CorrectionSpan(Parcel src) {
|
||||
src.readList(mSuggests, null);
|
||||
mSuggestions = src.readStringArray();
|
||||
mFlags = src.readInt();
|
||||
mLocaleString = src.readString();
|
||||
mOriginalString = src.readString();
|
||||
@@ -106,8 +102,8 @@ public class CorrectionSpan implements ParcelableSpan {
|
||||
/**
|
||||
* @return suggestions
|
||||
*/
|
||||
public List<CharSequence> getSuggests() {
|
||||
return new ArrayList<CharSequence>(mSuggests);
|
||||
public String[] getSuggestions() {
|
||||
return Arrays.copyOf(mSuggestions, mSuggestions.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +131,7 @@ public class CorrectionSpan implements ParcelableSpan {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeList(mSuggests);
|
||||
dest.writeStringArray(mSuggestions);
|
||||
dest.writeInt(mFlags);
|
||||
dest.writeString(mLocaleString);
|
||||
dest.writeString(mOriginalString);
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.text.Editable;
|
||||
import android.text.NoCopySpan;
|
||||
@@ -30,7 +29,6 @@ import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.MetaKeyKeyListener;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.util.Log;
|
||||
import android.util.LogPrinter;
|
||||
import android.view.KeyCharacterMap;
|
||||
@@ -191,15 +189,6 @@ public class BaseInputConnection implements InputConnection {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation does nothing and returns false.
|
||||
*/
|
||||
@Override
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default implementation performs the deletion around the current
|
||||
* selection position of the editable text.
|
||||
@@ -655,7 +644,7 @@ public class BaseInputConnection implements InputConnection {
|
||||
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
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package android.view.inputmethod;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
@@ -355,10 +353,4 @@ public interface InputConnection {
|
||||
* valid.
|
||||
*/
|
||||
public boolean performPrivateCommand(String action, Bundle data);
|
||||
|
||||
/**
|
||||
* Add a correction span.
|
||||
*/
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package android.view.inputmethod;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
/**
|
||||
@@ -60,8 +58,7 @@ public class InputConnectionWrapper implements InputConnection {
|
||||
return mTarget.getCursorCapsMode(reqModes);
|
||||
}
|
||||
|
||||
public ExtractedText getExtractedText(ExtractedTextRequest request,
|
||||
int flags) {
|
||||
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
|
||||
return mTarget.getExtractedText(request, flags);
|
||||
}
|
||||
|
||||
@@ -128,9 +125,4 @@ public class InputConnectionWrapper implements InputConnection {
|
||||
public boolean performPrivateCommand(String action, Bundle data) {
|
||||
return mTarget.performPrivateCommand(action, data);
|
||||
}
|
||||
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags) {
|
||||
return mTarget.setCorrectionSpan(token, correctionSpan, start, end, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8331,19 +8331,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
||||
sLastCutOrCopyTime = SystemClock.uptimeMillis();
|
||||
}
|
||||
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan span, int start, int end,
|
||||
int flags) {
|
||||
if (getWindowToken() != token || !(mText instanceof Spannable)) return false;
|
||||
Spannable spannable = (Spannable)mText;
|
||||
CorrectionSpan[] spans = spannable.getSpans(start, end, CorrectionSpan.class);
|
||||
final int N = spans.length;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
spannable.removeSpan(spans[i]);
|
||||
}
|
||||
spannable.setSpan(span, start, end, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* An ActionMode Callback class that is used to provide actions while in text selection mode.
|
||||
*
|
||||
|
||||
@@ -18,11 +18,9 @@ package com.android.internal.view;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
@@ -47,7 +45,6 @@ public class IInputConnectionWrapper extends IInputContext.Stub {
|
||||
private static final int DO_PERFORM_EDITOR_ACTION = 58;
|
||||
private static final int DO_PERFORM_CONTEXT_MENU_ACTION = 59;
|
||||
private static final int DO_SET_COMPOSING_TEXT = 60;
|
||||
private static final int DO_SET_SECURE_CORRECTION_SPAN = 61;
|
||||
private static final int DO_SET_COMPOSING_REGION = 63;
|
||||
private static final int DO_FINISH_COMPOSING_TEXT = 65;
|
||||
private static final int DO_SEND_KEY_EVENT = 70;
|
||||
@@ -178,13 +175,6 @@ public class IInputConnectionWrapper extends IInputContext.Stub {
|
||||
dispatchMessage(obtainMessageOO(DO_PERFORM_PRIVATE_COMMAND, action, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags) {
|
||||
dispatchMessage(obtainMessageOOIII(DO_SET_SECURE_CORRECTION_SPAN, token, correctionSpan,
|
||||
start, end, flags));
|
||||
}
|
||||
|
||||
void dispatchMessage(Message msg) {
|
||||
// If we are calling this from the main thread, then we can call
|
||||
// right through. Otherwise, we need to send the message to the
|
||||
@@ -430,17 +420,6 @@ public class IInputConnectionWrapper extends IInputContext.Stub {
|
||||
(Bundle)args.arg2);
|
||||
return;
|
||||
}
|
||||
case DO_SET_SECURE_CORRECTION_SPAN: {
|
||||
InputConnection ic = mInputConnection.get();
|
||||
if (ic == null || !isActive()) {
|
||||
Log.w(TAG, "setCorrectionSpan on inactive InputConnection");
|
||||
return;
|
||||
}
|
||||
SomeArgs args = (SomeArgs)msg.obj;
|
||||
ic.setCorrectionSpan((IBinder)args.arg1, (CorrectionSpan)args.arg2, msg.arg1,
|
||||
msg.arg2, args.seq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log.w(TAG, "Unhandled message code: " + msg.what);
|
||||
}
|
||||
@@ -490,12 +469,4 @@ public class IInputConnectionWrapper extends IInputContext.Stub {
|
||||
args.arg2 = arg2;
|
||||
return mH.obtainMessage(what, 0, 0, args);
|
||||
}
|
||||
|
||||
Message obtainMessageOOIII(int what, Object arg1, Object arg2, int arg3, int arg4, int arg5) {
|
||||
SomeArgs args = new SomeArgs();
|
||||
args.arg1 = arg1;
|
||||
args.arg2 = arg2;
|
||||
args.seq = arg5;
|
||||
return mH.obtainMessage(what, arg3, arg4, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.internal.view;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
import android.view.inputmethod.CorrectionInfo;
|
||||
@@ -74,6 +73,4 @@ import com.android.internal.view.IInputContextCallback;
|
||||
|
||||
void getSelectedText(int flags, int seq, IInputContextCallback callback);
|
||||
|
||||
void setCorrectionSpan(in IBinder token, in CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
package com.android.internal.view;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SystemClock;
|
||||
import android.text.style.CorrectionSpan;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
@@ -253,7 +251,7 @@ public class InputConnectionWrapper implements InputConnection {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
|
||||
ExtractedText value = null;
|
||||
try {
|
||||
@@ -415,14 +413,4 @@ public class InputConnectionWrapper implements InputConnection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags) {
|
||||
try {
|
||||
mIInputContext.setCorrectionSpan(token, correctionSpan, start, end, flags);
|
||||
return true;
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,13 +146,4 @@ public class EditableInputConnection extends BaseInputConnection {
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setCorrectionSpan(IBinder token, CorrectionSpan correctionSpan, int start,
|
||||
int end, int flags) {
|
||||
mTextView.beginBatchEdit();
|
||||
boolean retval = mTextView.setCorrectionSpan(token, correctionSpan, start, end, flags);
|
||||
mTextView.endBatchEdit();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user