Skip to content

fixes to support swiftkey #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 70 additions & 17 deletions src/src/org/renpy/android/SDLSurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.opengl.GLSurfaceView;
import android.net.Uri;
import android.os.PowerManager;
Expand All @@ -55,6 +57,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;
import java.lang.Math;
import java.nio.FloatBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand Down Expand Up @@ -357,6 +360,16 @@ public interface OnInterceptTouchListener {
// Access to our meta-data
private ApplicationInfo ai;

// Text before/after cursor
static String mTbf = "";
static String mTaf = "";

public static void updateTextFromCursor(String bef, String aft){
mTbf = bef;
mTaf = aft;
if (DEBUG) Log.d(TAG, String.format("mtbf: %s mtaf:%s <<<<<<<<<", mTbf, mTaf));
}

// Our own view
static SDLSurfaceView instance = null;

Expand Down Expand Up @@ -1159,9 +1172,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {

private void deleteLastText(){
// send back space keys
if (DEBUG){
Log.i("Python:", String.format("delete text%s", mDelLen));
}
if (DEBUG) Log.i("Python:", String.format("delete text%s", mDelLen));

if (mDelLen == 0){
return;
Expand All @@ -1172,16 +1183,27 @@ private void deleteLastText(){
}

@Override
public boolean setComposingText(CharSequence text,
int newCursorPosition){
this.deleteLastText();
if (DEBUG) Log.i("Python:", String.format("set Composing Text %s", text));
// send text
String message = String.format("INSERT:%s", text);
dispatchCommand(message);
// store len to be deleted for next time
mDelLen = text.length();
return super.setComposingText(text, newCursorPosition);
public boolean endBatchEdit() {
if (DEBUG) Log.i("Python:", "endBatchEdit");
return super.endBatchEdit();
}

@Override
public boolean beginBatchEdit() {
if (DEBUG) Log.i("Python:", "beginBatchEdit");
return super.beginBatchEdit();
}

@Override
public boolean commitCompletion(CompletionInfo text){
if (DEBUG) Log.i("Python:", String.format("Commit Completion %s", text));
return super.commitCompletion(text);
}

@Override
public boolean commitCorrection(CorrectionInfo correctionInfo){
if (DEBUG) Log.i("Python:", String.format("Commit Correction"));
return super.commitCorrection(correctionInfo);
}

@Override
Expand All @@ -1202,12 +1224,36 @@ public boolean sendKeyEvent(KeyEvent event){
@Override
public boolean setComposingRegion(int start, int end){
if (DEBUG) Log.d("Python:", String.format("Set Composing Region %s %s", start, end));
return super.setComposingRegion(start, end);
finishComposingText();
if (start < 0 || start > end)
return true;
//dispatchCommand(String.format("SEL:%s,%s,%s", mTbf.length(), start, end));
return true;
//return super.setComposingRegion(start, end);
}

@Override
public boolean setComposingText(CharSequence text,
int newCursorPosition){
this.deleteLastText();
if (DEBUG) Log.i("Python:", String.format("set Composing Text %s", text));
// send text
String message = String.format("INSERT:%s", text);
dispatchCommand(message);
// store len to be deleted for next time
mDelLen = text.length();
return super.setComposingText(text, newCursorPosition);
}

@Override
public boolean finishComposingText(){
if (DEBUG) Log.i("Python:", String.format("finish Composing Text"));
return super.finishComposingText();
}

@Override
public boolean deleteSurroundingText (int beforeLength, int afterLength){
if (DEBUG) Log.d("Python:", String.format("deleteLastText %s %s", beforeLength, afterLength));
if (DEBUG) Log.d("Python:", String.format("delete surrounding Text %s %s", beforeLength, afterLength));
// move cursor to place from where to start deleting
// send right arrow keys
for (int i = 0; i < afterLength; i++){
Expand Down Expand Up @@ -1237,13 +1283,20 @@ public CharSequence getSelectedText(int flags){
@Override
public CharSequence getTextBeforeCursor(int n, int flags){
if (DEBUG) Log.d("Python:", String.format("getTextBeforeCursor %s %s", n, flags));
return new String(new char[1024]).replace("\0", " ");//#super.getTextBeforeCursor(n, flags);
/*int len = mTbf.length();
int len_n = Math.min(len, n);
int start = Math.max(len - n, 0);
String tbf = mTbf.substring(start, start + len_n);
return tbf;*/
return super.getTextBeforeCursor(n, flags);
}

@Override
public CharSequence getTextAfterCursor(int n, int flags){
if (DEBUG) Log.d("Python:", String.format("getTextAfterCursor %s %s", n, flags));
return " ";//super.getTextAfterCursor(n, flags);
Log.d("Python:", String.format("TextAfterCursor %s", mTaf));
//return mTaf.substring(0, Math.min(mTaf.length(), n));
return super.getTextAfterCursor(n, flags);
}

@Override
Expand Down