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. MSM72xx AOSP port missing hardware audio acceleration

Hi, I've just been having a poke about in the MSM7201 code (for my HTC
Hero). I noticed there's code in the AOSP msm kernel which uses the
audio DSP to accelerate mp3, aac, etc audio decoding. I was trying to
figure out how that was hooked into the audio subsystem.

project's libaudio is here:
http://android.git.kernel.org/?p=platform/hardware/msm7k.git;a=tree

The code in there only uses the /dev/msm_pcm devices. However, running
strings over the libaudio.so from the binaries that came with the
phone shows it refers to /dev/msm_mp3, /dev/msm_aac. This kinda
implies that AOSP builds will be doing audio decoding entirely in
software.

Is there a good reason the audio acceleration code is missing from the
AOSP libaudio? I mean, the hardware support code is all there in the
kernel, and it /appears/ it wouldn't exactly be hard to modify the
libaudio source to add the missing glue in.

Am I missing something, or is this just HTC/Qualcomm trying to annoy
me again? :)

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. findViewbyId returns null --- called in a custom CursorAdapter -- bindView() method. Codes in body.

package edu.ohio.android.bmm.activity;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import edu.ohio.android.bmm.R;
import edu.ohio.android.bmm.db.BMMDBOpenHelper.Diary;

public class DiaryList extends BMMActivity {

        // Cursor for sqlite database
        private Cursor cursor;

        private LayoutInflater mInflater;

        // Icons bound to rows
        private Bitmap mild;
        private Bitmap moderate;
        private Bitmap severe;

        /***
         *
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);
                cursor = fetchAllDiary();
                this.setListAdapter(new DiaryListAdapter(this, cursor, true));
        }

        /**
         *
         * @author vycon
         *
         */
        public class DiaryListAdapter extends CursorAdapter {

                /**
                 *
                 * @param context
                 * @param cursor
                 * @param autoRequery
                 */
                public DiaryListAdapter(Context context, Cursor cursor, boolean
autoRequery) {
                                super(context, cursor, autoRequery);
                                mInflater = LayoutInflater.from(context);

                                // icons bound to the rows
                                mild = 
BitmapFactory.decodeResource(context.getResources(),
R.drawable.mild);
                                moderate = 
BitmapFactory.decodeResource(context.getResources(),
R.drawable.moderate);
                                severe = 
BitmapFactory.decodeResource(context.getResources(),
R.drawable.severe);
                        }

                /**
                 *
                 */
                @Override
                public void bindView(View view, Context context, Cursor cursor) 
{

                        TextView tvStartTime = (TextView)
view.findViewById(R.id.diary_list_row_dateAndTime);
                        TextView tvDuration = (TextView)
view.findViewById(R.id.diary_list_row_duration);
                        TextView tvSymptom = (TextView)
view.findViewById(R.id.diary_list_row_symptom);
                        TextView tvMedication = (TextView)
view.findViewById(R.id.diary_list_row_medication);

                        ImageView ivMaxSeverity = (ImageView)
view.findViewById(R.id.diary_list_row_maxSeverity);
                        ImageView ivInitSeverity = (ImageView)
view.findViewById(R.id.diary_list_row_initSeverity);

                        String maxSeverity =
cursor.getString(cursor.getColumnIndex(Diary.MAX_SEVERITY));
                        String initSeverity =
cursor.getString(cursor.getColumnIndex(Diary.INIT_SEVERITY));

        
tvStartTime.setText(cursor.getString(cursor.getColumnIndex(Diary.START_TIME)));
        
tvDuration.setText(cursor.getString(cursor.getColumnIndex(Diary.DURATION)));
        
tvSymptom.setText(cursor.getString(cursor.getColumnIndex(Diary.SYMPTOM)));
        
tvMedication.setText(cursor.getInt(cursor.getColumnIndex(Diary.MEDICATION_ID)));

                        if (maxSeverity.equalsIgnoreCase("mild")) {
                                ivMaxSeverity.setImageBitmap(mild);
                        }
                        if (maxSeverity.equalsIgnoreCase("moderate")) {
                                ivMaxSeverity.setImageBitmap(moderate);
                        }
                        if (maxSeverity.equalsIgnoreCase("severe")) {
                                ivMaxSeverity.setImageBitmap(severe);
                        }
                        if (initSeverity.equalsIgnoreCase("mild")) {
                                ivInitSeverity.setImageBitmap(mild);
                        }
                        if (initSeverity.equalsIgnoreCase("moderate")) {
                                ivInitSeverity.setImageBitmap(moderate);
                        }
                        if (initSeverity.equalsIgnoreCase("severe")) {
                                ivInitSeverity.setImageBitmap(severe);
                        }
                }

                /**
                 *
                 */
                @Override
                public View newView(Context context, Cursor cursor, ViewGroup
parent) {
                        final View view = 
mInflater.inflate(R.layout.diary_list_view,
parent, false);
                        //bindView(view, context, cursor);
                        return view;
                }

        }

        /**
         *
         */
        @Override
        protected void onListItemClick(ListView l, View v, int position, long
id) {
                // TODO Auto-generated method stub
                super.onListItemClick(l, v, position, id);
        }
}

-- 

3. Rumor: HTC Scorpion and all of its 1.5 Ghz, Android 2.2 goodness headed for Verizon?

4. How does a "held" wakelock impact if the service dies with out releasing it?

5. Acer Ferrari Androi

6. USB On-The-Go on Nexus One!!

7. AT&T menghapus unlimited data plan