4242import android .view .inputmethod .BaseInputConnection ;
4343import android .view .inputmethod .ExtractedText ;
4444import android .view .inputmethod .ExtractedTextRequest ;
45+ import android .view .inputmethod .CompletionInfo ;
46+ import android .view .inputmethod .CorrectionInfo ;
4547import android .opengl .GLSurfaceView ;
4648import android .net .Uri ;
4749import android .os .PowerManager ;
5557import android .graphics .Bitmap ;
5658import android .graphics .BitmapFactory ;
5759import android .opengl .GLUtils ;
60+ import java .lang .Math ;
5861import java .nio .FloatBuffer ;
5962import java .nio .ByteBuffer ;
6063import java .nio .ByteOrder ;
@@ -357,6 +360,16 @@ public interface OnInterceptTouchListener {
357360 // Access to our meta-data
358361 private ApplicationInfo ai ;
359362
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+
360373 // Our own view
361374 static SDLSurfaceView instance = null ;
362375
@@ -1159,9 +1172,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
11591172
11601173 private void deleteLastText (){
11611174 // 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 ));
11651176
11661177 if (mDelLen == 0 ){
11671178 return ;
@@ -1172,16 +1183,27 @@ private void deleteLastText(){
11721183 }
11731184
11741185 @ 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 );
11851207 }
11861208
11871209 @ Override
@@ -1202,12 +1224,36 @@ public boolean sendKeyEvent(KeyEvent event){
12021224 @ Override
12031225 public boolean setComposingRegion (int start , int end ){
12041226 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 ();
12061252 }
12071253
12081254 @ Override
12091255 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 ));
12111257 // move cursor to place from where to start deleting
12121258 // send right arrow keys
12131259 for (int i = 0 ; i < afterLength ; i ++){
@@ -1237,13 +1283,20 @@ public CharSequence getSelectedText(int flags){
12371283 @ Override
12381284 public CharSequence getTextBeforeCursor (int n , int flags ){
12391285 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 );
12411292 }
12421293
12431294 @ Override
12441295 public CharSequence getTextAfterCursor (int n , int flags ){
12451296 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 );
12471300 }
12481301
12491302 @ Override
0 commit comments