42
42
import android .view .inputmethod .BaseInputConnection ;
43
43
import android .view .inputmethod .ExtractedText ;
44
44
import android .view .inputmethod .ExtractedTextRequest ;
45
+ import android .view .inputmethod .CompletionInfo ;
46
+ import android .view .inputmethod .CorrectionInfo ;
45
47
import android .opengl .GLSurfaceView ;
46
48
import android .net .Uri ;
47
49
import android .os .PowerManager ;
55
57
import android .graphics .Bitmap ;
56
58
import android .graphics .BitmapFactory ;
57
59
import android .opengl .GLUtils ;
60
+ import java .lang .Math ;
58
61
import java .nio .FloatBuffer ;
59
62
import java .nio .ByteBuffer ;
60
63
import java .nio .ByteOrder ;
@@ -357,6 +360,16 @@ public interface OnInterceptTouchListener {
357
360
// Access to our meta-data
358
361
private ApplicationInfo ai ;
359
362
363
+ // Text before/after cursor
364
+ static String mTbf = "" ;
365
+ static String mTaf = "" ;
366
+
367
+ public static void updateTextFromCursor (String bef , String aft ){
368
+ mTbf = bef ;
369
+ mTaf = aft ;
370
+ if (DEBUG ) Log .d (TAG , String .format ("mtbf: %s mtaf:%s <<<<<<<<<" , mTbf , mTaf ));
371
+ }
372
+
360
373
// Our own view
361
374
static SDLSurfaceView instance = null ;
362
375
@@ -1159,9 +1172,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
1159
1172
1160
1173
private void deleteLastText (){
1161
1174
// send back space keys
1162
- if (DEBUG ){
1163
- Log .i ("Python:" , String .format ("delete text%s" , mDelLen ));
1164
- }
1175
+ if (DEBUG ) Log .i ("Python:" , String .format ("delete text%s" , mDelLen ));
1165
1176
1166
1177
if (mDelLen == 0 ){
1167
1178
return ;
@@ -1172,16 +1183,27 @@ private void deleteLastText(){
1172
1183
}
1173
1184
1174
1185
@ Override
1175
- public boolean setComposingText (CharSequence text ,
1176
- int newCursorPosition ){
1177
- this .deleteLastText ();
1178
- if (DEBUG ) Log .i ("Python:" , String .format ("set Composing Text %s" , text ));
1179
- // send text
1180
- String message = String .format ("INSERT:%s" , text );
1181
- dispatchCommand (message );
1182
- // store len to be deleted for next time
1183
- mDelLen = text .length ();
1184
- return super .setComposingText (text , newCursorPosition );
1186
+ public boolean endBatchEdit () {
1187
+ if (DEBUG ) Log .i ("Python:" , "endBatchEdit" );
1188
+ return super .endBatchEdit ();
1189
+ }
1190
+
1191
+ @ Override
1192
+ public boolean beginBatchEdit () {
1193
+ if (DEBUG ) Log .i ("Python:" , "beginBatchEdit" );
1194
+ return super .beginBatchEdit ();
1195
+ }
1196
+
1197
+ @ Override
1198
+ public boolean commitCompletion (CompletionInfo text ){
1199
+ if (DEBUG ) Log .i ("Python:" , String .format ("Commit Completion %s" , text ));
1200
+ return super .commitCompletion (text );
1201
+ }
1202
+
1203
+ @ Override
1204
+ public boolean commitCorrection (CorrectionInfo correctionInfo ){
1205
+ if (DEBUG ) Log .i ("Python:" , String .format ("Commit Correction" ));
1206
+ return super .commitCorrection (correctionInfo );
1185
1207
}
1186
1208
1187
1209
@ Override
@@ -1202,12 +1224,36 @@ public boolean sendKeyEvent(KeyEvent event){
1202
1224
@ Override
1203
1225
public boolean setComposingRegion (int start , int end ){
1204
1226
if (DEBUG ) Log .d ("Python:" , String .format ("Set Composing Region %s %s" , start , end ));
1205
- return super .setComposingRegion (start , end );
1227
+ finishComposingText ();
1228
+ if (start < 0 || start > end )
1229
+ return true ;
1230
+ //dispatchCommand(String.format("SEL:%s,%s,%s", mTbf.length(), start, end));
1231
+ return true ;
1232
+ //return super.setComposingRegion(start, end);
1233
+ }
1234
+
1235
+ @ Override
1236
+ public boolean setComposingText (CharSequence text ,
1237
+ int newCursorPosition ){
1238
+ this .deleteLastText ();
1239
+ if (DEBUG ) Log .i ("Python:" , String .format ("set Composing Text %s" , text ));
1240
+ // send text
1241
+ String message = String .format ("INSERT:%s" , text );
1242
+ dispatchCommand (message );
1243
+ // store len to be deleted for next time
1244
+ mDelLen = text .length ();
1245
+ return super .setComposingText (text , newCursorPosition );
1246
+ }
1247
+
1248
+ @ Override
1249
+ public boolean finishComposingText (){
1250
+ if (DEBUG ) Log .i ("Python:" , String .format ("finish Composing Text" ));
1251
+ return super .finishComposingText ();
1206
1252
}
1207
1253
1208
1254
@ Override
1209
1255
public boolean deleteSurroundingText (int beforeLength , int afterLength ){
1210
- if (DEBUG ) Log .d ("Python:" , String .format ("deleteLastText %s %s" , beforeLength , afterLength ));
1256
+ if (DEBUG ) Log .d ("Python:" , String .format ("delete surrounding Text %s %s" , beforeLength , afterLength ));
1211
1257
// move cursor to place from where to start deleting
1212
1258
// send right arrow keys
1213
1259
for (int i = 0 ; i < afterLength ; i ++){
@@ -1237,13 +1283,20 @@ public CharSequence getSelectedText(int flags){
1237
1283
@ Override
1238
1284
public CharSequence getTextBeforeCursor (int n , int flags ){
1239
1285
if (DEBUG ) Log .d ("Python:" , String .format ("getTextBeforeCursor %s %s" , n , flags ));
1240
- return new String (new char [1024 ]).replace ("\0 " , " " );//#super.getTextBeforeCursor(n, flags);
1286
+ /*int len = mTbf.length();
1287
+ int len_n = Math.min(len, n);
1288
+ int start = Math.max(len - n, 0);
1289
+ String tbf = mTbf.substring(start, start + len_n);
1290
+ return tbf;*/
1291
+ return super .getTextBeforeCursor (n , flags );
1241
1292
}
1242
1293
1243
1294
@ Override
1244
1295
public CharSequence getTextAfterCursor (int n , int flags ){
1245
1296
if (DEBUG ) Log .d ("Python:" , String .format ("getTextAfterCursor %s %s" , n , flags ));
1246
- return " " ;//super.getTextAfterCursor(n, flags);
1297
+ Log .d ("Python:" , String .format ("TextAfterCursor %s" , mTaf ));
1298
+ //return mTaf.substring(0, Math.min(mTaf.length(), n));
1299
+ return super .getTextAfterCursor (n , flags );
1247
1300
}
1248
1301
1249
1302
@ Override
0 commit comments