DicTraverseSession.java revision f6c2200890012708709964fb1a8933ed1c3e7dd8
1/* 2 * Copyright (C) 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.inputmethod.latin; 18 19import java.util.Locale; 20 21public class DicTraverseSession { 22 static { 23 JniUtils.loadNativeLibrary(); 24 } 25 private native long setDicTraverseSessionNative(String locale); 26 //private native void initDicTraverseSessionNative(long nativeDicTraverseSession, 27 //long dictionary, int[] previousWord, int previousWordLength); 28 private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession); 29 30 private long mNativeDicTraverseSession; 31 32 public DicTraverseSession(Locale locale) { 33 mNativeDicTraverseSession = createNativeDicTraverseSession( 34 locale != null ? locale.toString() : ""); 35 } 36 37 public long getSession() { 38 return mNativeDicTraverseSession; 39 } 40 41 public void initSession(long dictionary) { 42 initSession(dictionary, null, 0); 43 } 44 45 public void initSession(long dictionary, int[] previousWord, int previousWordLength) { 46 //initDicTraverseSessionNative( 47 //mNativeDicTraverseSession, dictionary, previousWord, previousWordLength); 48 } 49 50 private final long createNativeDicTraverseSession(String locale) { 51 return setDicTraverseSessionNative(locale); 52 } 53 54 private void closeInternal() { 55 if (mNativeDicTraverseSession != 0) { 56 releaseDicTraverseSessionNative(mNativeDicTraverseSession); 57 mNativeDicTraverseSession = 0; 58 } 59 } 60 61 public void close() { 62 closeInternal(); 63 } 64 65 @Override 66 protected void finalize() throws Throwable { 67 try { 68 closeInternal(); 69 } finally { 70 super.finalize(); 71 } 72 } 73} 74