FileDocCategorySizeDatePackage
PinyinDecoderService.javaAPI DocAndroid 1.5 API9641Wed May 06 22:42:48 BST 2009com.android.inputmethod.pinyin

PinyinDecoderService

public class PinyinDecoderService extends android.app.Service
This class is used to separate the input method kernel in an individual service so that both IME and IME-syncer can use it.

Fields Summary
private static final int
MAX_PATH_FILE_LENGTH
private static boolean
inited
private String
mUsr_dict_file
private final IPinyinDecoderService.Stub
mBinder
Constructors Summary
Methods Summary
private booleangetUsrDictFileName(byte[] usr_dict)


     
        try {
            System.loadLibrary("jni_pinyinime");
        } catch (UnsatisfiedLinkError ule) {
            Log.e("PinyinDecoderService",
                    "WARNING: Could not load jni_pinyinime natives");
        }
    
        if (null == usr_dict) {
            return false;
        }

        for (int i = 0; i < mUsr_dict_file.length(); i++)
            usr_dict[i] = (byte) mUsr_dict_file.charAt(i);
        usr_dict[mUsr_dict_file.length()] = 0;

        return true;
    
private voidinitPinyinEngine()

        byte usr_dict[];
        usr_dict = new byte[MAX_PATH_FILE_LENGTH];

        // Here is how we open a built-in dictionary for access through
        // a file descriptor...
        AssetFileDescriptor afd = getResources().openRawResourceFd(
                R.raw.dict_pinyin);
        if (Environment.getInstance().needDebug()) {
            Log
                    .i("foo", "Dict: start=" + afd.getStartOffset()
                            + ", length=" + afd.getLength() + ", fd="
                            + afd.getParcelFileDescriptor());
        }
        if (getUsrDictFileName(usr_dict)) {
            inited = nativeImOpenDecoderFd(afd.getFileDescriptor(), afd
                    .getStartOffset(), afd.getLength(), usr_dict);
        }
        try {
            afd.close();
        } catch (IOException e) {
        }
    
static native intnativeImAddLetter(byte ch)

static native booleannativeImCancelInput()

static native intnativeImCancelLastChoice()

static native intnativeImChoose(int choiceId)

static native booleannativeImCloseDecoder()

static native intnativeImDelSearch(int pos, boolean is_pos_in_splid, boolean clear_fixed_this_step)

static native booleannativeImFlushCache()

static native java.lang.StringnativeImGetChoice(int choiceId)

static native intnativeImGetFixedLen()

static native java.lang.StringnativeImGetPredictItem(int predictNo)

static native intnativeImGetPredictsNum(java.lang.String fixedStr)

static native java.lang.StringnativeImGetPyStr(boolean decoded)

static native intnativeImGetPyStrLen(boolean decoded)

static native int[]nativeImGetSplStart()

static native booleannativeImOpenDecoder(byte[] fn_sys_dict, byte[] fn_usr_dict)

static native booleannativeImOpenDecoderFd(java.io.FileDescriptor fd, long startOffset, long length, byte[] fn_usr_dict)

static native voidnativeImResetSearch()

static native intnativeImSearch(byte[] pyBuf, int pyLen)

static native voidnativeImSetMaxLens(int maxSpsLen, int maxHzsLen)

static native booleannativeSyncBegin(byte[] user_dict)

static native booleannativeSyncClearLastGot()

static native booleannativeSyncFinish()

static native intnativeSyncGetCapacity()

static native intnativeSyncGetLastCount()

static native java.lang.StringnativeSyncGetLemmas()

static native intnativeSyncGetTotalCount()

static native intnativeSyncPutLemmas(java.lang.String tomerge)

static native java.lang.StringnativeSyncUserDict(byte[] user_dict, java.lang.String tomerge)

public android.os.IBinderonBind(android.content.Intent intent)


    
        
        return mBinder;
    
public voidonCreate()

        super.onCreate();
        mUsr_dict_file = getFileStreamPath("usr_dict.dat").getPath();
        // This is a hack to make sure our "files" directory has been
        // created.
        try {
            openFileOutput("dummy", 0).close();
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        }

        initPinyinEngine();
    
public voidonDestroy()

        nativeImCloseDecoder();
        inited = false;
        super.onDestroy();