Skip to content

Instantly share code, notes, and snippets.

@barend
Created September 2, 2014 11:21
Show Gist options
  • Save barend/7dcda2694187de0740f6 to your computer and use it in GitHub Desktop.
Save barend/7dcda2694187de0740f6 to your computer and use it in GitHub Desktop.
Android InputConnectionWrapper, as-is delegate with logging.
package com.example;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
public class LoggingInputConnectionWrapper extends InputConnectionWrapper {
public LoggingInputConnectionWrapper(InputConnection target, boolean mutable) {
super(target, mutable);
}
@Override
public CharSequence getTextBeforeCursor(int n, int flags) {
android.util.Log.i("LICW", String.format("getTextBeforeCursor(%d, %d)", n, flags));
return super.getTextBeforeCursor(n, flags);
}
@Override
public CharSequence getTextAfterCursor(int n, int flags) {
android.util.Log.i("LICW", String.format("getTextAfterCursor(%d, %d)", n, flags));
return super.getTextAfterCursor(n, flags);
}
@Override
public CharSequence getSelectedText(int flags) {
android.util.Log.i("LICW", String.format("getSelectedText(%d)", flags));
return super.getSelectedText(flags);
}
@Override
public int getCursorCapsMode(int reqModes) {
android.util.Log.i("LICW", String.format("getCursorCapsMode(%d)", reqModes));
return super.getCursorCapsMode(reqModes);
}
@Override
public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
android.util.Log.i("LICW", String.format("getExtractedText(%s, %d)", request, flags));
return super.getExtractedText(request, flags);
}
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
android.util.Log.i("LICW", String.format("deleteSurroundingText(%d, %d)", beforeLength, afterLength));
return super.deleteSurroundingText(beforeLength, afterLength);
}
@Override
public boolean setComposingText(CharSequence text, int newCursorPosition) {
android.util.Log.i("LICW", String.format("setComposingText(%s, %d)", text, newCursorPosition));
return super.setComposingText(text, newCursorPosition);
}
@Override
public boolean setComposingRegion(int start, int end) {
android.util.Log.i("LICW", String.format("setComposingRegion(%d, %d)", start, end));
return super.setComposingRegion(start, end);
}
@Override
public boolean finishComposingText() {
android.util.Log.i("LICW", "finishComposingText()");
return super.finishComposingText();
}
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
android.util.Log.i("LICW", String.format("commitText(%s, %d)", text, newCursorPosition));
return super.commitText(text, newCursorPosition);
}
@Override
public boolean commitCompletion(CompletionInfo text) {
android.util.Log.i("LICW", String.format("commitCompletion(%s)", text));
return super.commitCompletion(text);
}
@Override
public boolean commitCorrection(CorrectionInfo correctionInfo) {
android.util.Log.i("LICW", String.format("commitCorrection(%s)", correctionInfo));
return super.commitCorrection(correctionInfo);
}
@Override
public boolean setSelection(int start, int end) {
android.util.Log.i("LICW", String.format("setSelection(%d, %d)", start, end));
return super.setSelection(start, end);
}
@Override
public boolean performEditorAction(int editorAction) {
android.util.Log.i("LICW", String.format("performEditorAction(%d)", editorAction));
return super.performEditorAction(editorAction);
}
@Override
public boolean performContextMenuAction(int id) {
android.util.Log.i("LICW", String.format("performContextMenuAction(%d)", id));
return super.performContextMenuAction(id);
}
@Override
public boolean beginBatchEdit() {
android.util.Log.i("LICW", "beginBatchEdit()");
return super.beginBatchEdit();
}
@Override
public boolean endBatchEdit() {
android.util.Log.i("LICW", "endBatchEdit()");
return super.endBatchEdit();
}
@Override
public boolean sendKeyEvent(KeyEvent event) {
android.util.Log.i("LICW", String.format("sendKeyEvent(%s)", event));
return super.sendKeyEvent(event);
}
@Override
public boolean clearMetaKeyStates(int states) {
android.util.Log.i("LICW", String.format("clearMetaKeyStates(%d)", states));
return super.clearMetaKeyStates(states);
}
@Override
public boolean reportFullscreenMode(boolean enabled) {
android.util.Log.i("LICW", String.format("reportFullscreenMode(%s)", enabled));
return super.reportFullscreenMode(enabled);
}
@Override
public boolean performPrivateCommand(String action, Bundle data) {
android.util.Log.i("LICW", String.format("performPrivateCommand(%s, %s)", action, data));
return super.performPrivateCommand(action, data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment