| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.inputmethod; |
| 18 |
|
| 19 |
import android.annotation.AnyThread; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.graphics.Rect; |
| 23 |
import android.os.Bundle; |
| 24 |
import android.os.RemoteException; |
| 25 |
import android.util.Log; |
| 26 |
|
| 27 |
import com.android.internal.view.IInputContext; |
| 28 |
import com.android.internal.view.IInputMethodSession; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
final class InputMethodSessionWrapper { |
| 36 |
|
| 37 |
private static final String TAG = "InputMethodSessionWrapper"; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
@NonNull |
| 43 |
private final IInputMethodSession mSession; |
| 44 |
|
| 45 |
private InputMethodSessionWrapper(@NonNull IInputMethodSession inputMethodSession) { |
| 46 |
mSession = inputMethodSession; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@Nullable |
| 57 |
public static InputMethodSessionWrapper createOrNull( |
| 58 |
@NonNull IInputMethodSession inputMethodSession) { |
| 59 |
return inputMethodSession != null ? new InputMethodSessionWrapper(inputMethodSession) |
| 60 |
: null; |
| 61 |
} |
| 62 |
|
| 63 |
@AnyThread |
| 64 |
void finishInput() { |
| 65 |
try { |
| 66 |
mSession.finishInput(); |
| 67 |
} catch (RemoteException e) { |
| 68 |
Log.w(TAG, "IME died", e); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
@AnyThread |
| 73 |
void updateCursorAnchorInfo(CursorAnchorInfo cursorAnchorInfo) { |
| 74 |
try { |
| 75 |
mSession.updateCursorAnchorInfo(cursorAnchorInfo); |
| 76 |
} catch (RemoteException e) { |
| 77 |
Log.w(TAG, "IME died", e); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
@AnyThread |
| 82 |
void displayCompletions(CompletionInfo[] completions) { |
| 83 |
try { |
| 84 |
mSession.displayCompletions(completions); |
| 85 |
} catch (RemoteException e) { |
| 86 |
Log.w(TAG, "IME died", e); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
@AnyThread |
| 91 |
void updateExtractedText(int token, ExtractedText text) { |
| 92 |
try { |
| 93 |
mSession.updateExtractedText(token, text); |
| 94 |
} catch (RemoteException e) { |
| 95 |
Log.w(TAG, "IME died", e); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
@AnyThread |
| 100 |
void appPrivateCommand(String action, Bundle data) { |
| 101 |
try { |
| 102 |
mSession.appPrivateCommand(action, data); |
| 103 |
} catch (RemoteException e) { |
| 104 |
Log.w(TAG, "IME died", e); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
@AnyThread |
| 109 |
void viewClicked(boolean focusChanged) { |
| 110 |
try { |
| 111 |
mSession.viewClicked(focusChanged); |
| 112 |
} catch (RemoteException e) { |
| 113 |
Log.w(TAG, "IME died", e); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
@AnyThread |
| 118 |
void updateCursor(Rect newCursor) { |
| 119 |
try { |
| 120 |
mSession.updateCursor(newCursor); |
| 121 |
} catch (RemoteException e) { |
| 122 |
Log.w(TAG, "IME died", e); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
@AnyThread |
| 127 |
void updateSelection(int oldSelStart, int oldSelEnd, int selStart, int selEnd, |
| 128 |
int candidatesStart, int candidatesEnd) { |
| 129 |
try { |
| 130 |
mSession.updateSelection( |
| 131 |
oldSelStart, oldSelEnd, selStart, selEnd, candidatesStart, candidatesEnd); |
| 132 |
} catch (RemoteException e) { |
| 133 |
Log.w(TAG, "IME died", e); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
@AnyThread |
| 138 |
void invalidateInput(EditorInfo editorInfo, IInputContext inputContext, int sessionId) { |
| 139 |
try { |
| 140 |
mSession.invalidateInput(editorInfo, inputContext, sessionId); |
| 141 |
} catch (RemoteException e) { |
| 142 |
Log.w(TAG, "IME died", e); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
@AnyThread |
| 150 |
@NonNull |
| 151 |
@Override |
| 152 |
public String toString() { |
| 153 |
return mSession.toString(); |
| 154 |
} |
| 155 |
} |