Can't get cursor position from InputConnection

by nattster » Fri, 20 May 2011 09:30:36 GMT


Sponsored Links
 I'm developing an Input Method. 
I'd like to change cursor position with 
*InputConnection.setSelection< http://developer.android.com/reference/android/view/inputmethod/InputConnection.html #setSelection(int,
 
int)>*.

This method allows me to set absolute position of cursor.
But what I want is to move cursor relatively from current position.
(e.g. Move left 3 characters from current position)

I can't find method to get current cursor position.
Currently, I got this hack:

    InputConnection conn;
    CharSequence seq = conn.getTextBeforeCursor(1000, 0); 
    // will get as much characters as possible on the left of cursor

    int cursor_pos = seq.length();

Is there any better way to do this?
Should we introduce new method to InputConnection, i.e. getSelectionStart?

-- 



Other Threads

1. Bug in Bitmap.compress when used on JPEGs?

Hi there,

I experience strange things when using the compress method from
Bitmap. I'm useing the code at the bottom to download JPEGs from a
server. Out of all images downloaded, ~10% fail to be written with a
NullpointerException and a preceding message from something called
'skia'. Each image is different and it doesn't always happen for the
same ones:

09-01 13:19:04.126: DEBUG/skia(1124): xxxxxxxxxxxxxx failure to skip
request 9936 actual 6906
09-01 13:19:04.132: DEBUG/skia(1124): xxxxxxxxxxxxxxxxxxxxx jpeg
setjump exit
09-01 13:19:04.132: ERROR/ImageUtil(1124):
java.lang.NullPointerException

If I use the same code on PNGs, all works like a charm.

The code used is:

public static String saveImageFromURI(URI uri, String name,
                        final Activity ctx, Handler handler) {
                boolean success = false;
                String qualifiedName = name + ".jpg";
                FileOutputStream fos = null;
                try {
                        URL url = uri.toURL();
                        Bitmap bmp = 
BitmapFactory.decodeStream(url.openStream());
                        fos = ctx.openFileOutput(qualifiedName, 
Context.MODE_PRIVATE);
                        success = bmp.compress(Bitmap.CompressFormat.JPEG, 75, 
fos);
                } catch (MalformedURLException e) {
                        Log.e(TAG, e.toString(), e);
                } catch (IOException e) {
                        Log.e(TAG, e.toString(), e);
                } catch (IllegalArgumentException e) {
                        Log.e(TAG, e.toString());
                } catch (NullPointerException e) {
                        Log.e(TAG, e.toString(), e);
                } finally {
                        try {
                                if (fos != null)
                                        fos.close();
                        } catch (IOException e) {
                                Log.e(TAG, e.toString(), e);
                        }
                }
                if (success) {
                        return qualifiedName;
                } else {
                        return null;
                }
        }

Any ideas what could cause this behaviour?

snowcrash

--~--~---------~--~----~------------~-------~--~----~

2. How to use the mic for audio-input in android

If you connect mic to your PC, the emulator should be able to detect it
without any additional launch flags.

2008/9/3 HTP <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~

3. REST + JSON Web Service Client

4. allocation in loop each 1s

5. Setting highlight text color (textColorHighlight doesn't do it)

6. Creating pop-up menu

7. Will android provide Mail API??