Add PersionalizationDictionaryRegister

Bug: 9429906
Change-Id: Ibd4d5cedb371c0b4ee1342a3e6d221c9e34c2402
main
Satoshi Kataoka 2013-08-12 12:20:18 +09:00
parent 4a2f6a2216
commit 8c4fcb108f
5 changed files with 61 additions and 9 deletions

View File

@ -74,6 +74,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.personalization.PersonalizationDictionaryHelper;
import com.android.inputmethod.latin.personalization.PersonalizationDictionarySessionRegister;
import com.android.inputmethod.latin.personalization.PersonalizationPredictionDictionary;
import com.android.inputmethod.latin.personalization.UserHistoryPredictionDictionary;
import com.android.inputmethod.latin.settings.Settings;
@ -470,6 +471,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
KeyboardSwitcher.init(this);
AudioAndHapticFeedbackManager.init(this);
AccessibilityUtils.init(this);
PersonalizationDictionarySessionRegister.init(this);
super.onCreate();
@ -650,6 +652,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mOptionsDialog.dismiss();
}
}
PersonalizationDictionarySessionRegister.onConfigurationChanged(this, conf);
super.onConfigurationChanged(conf);
}

View File

@ -402,7 +402,11 @@ public abstract class DynamicPredictionDictionaryBase extends ExpandableDictiona
}
public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) {
session.setDictionary(this);
session.setPredictionDictionary(mLocale, this);
mSessions.add(session);
}
public void unRegisterUpdateSession(PersonalizationDictionaryUpdateSession session) {
mSessions.remove(session);
}
}

View File

@ -59,9 +59,8 @@ public class PersonalizationDictionaryHelper {
}
}
public static void
registerPersonalizationDictionaryUpdateSession(final Context context,
final PersonalizationDictionaryUpdateSession session) {
public static void registerPersonalizationDictionaryUpdateSession(final Context context,
final PersonalizationDictionaryUpdateSession session) {
final PersonalizationPredictionDictionary dictionary =
getPersonalizationPredictionDictionary(context,
context.getResources().getConfiguration().locale.toString(),

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.personalization;
import android.content.Context;
import android.content.res.Configuration;
public class PersonalizationDictionarySessionRegister {
public static void init(Context context) {
}
public static void onConfigurationChanged(final Context context, final Configuration conf) {
}
}

View File

@ -43,18 +43,36 @@ public abstract class PersonalizationDictionaryUpdateSession {
}
// TODO: Use a dynamic binary dictionary instead
public WeakReference<DynamicPredictionDictionaryBase> mDictionary;
public WeakReference<DynamicPredictionDictionaryBase> mPredictionDictionary;
public String mLocale;
public abstract void onDictionaryReady();
public void setDictionary(DynamicPredictionDictionaryBase dictionary) {
mDictionary = new WeakReference<DynamicPredictionDictionaryBase>(dictionary);
public void setPredictionDictionary(String locale, DynamicPredictionDictionaryBase dictionary) {
mPredictionDictionary = new WeakReference<DynamicPredictionDictionaryBase>(dictionary);
mLocale = locale;
}
protected DynamicPredictionDictionaryBase getPredictionDictionary() {
return mPredictionDictionary == null ? null : mPredictionDictionary.get();
}
private void unsetPredictionDictionary() {
final DynamicPredictionDictionaryBase dictionary = getPredictionDictionary();
if (dictionary == null) {
return;
}
dictionary.unRegisterUpdateSession(this);
}
public void closeSession() {
unsetPredictionDictionary();
}
public void addToPersonalizationDictionary(
final ArrayList<PersonalizationLanguageModelParam> lmParams) {
final DynamicPredictionDictionaryBase dictionary = mDictionary == null
? null : mDictionary.get();
final DynamicPredictionDictionaryBase dictionary = getPredictionDictionary();
if (dictionary == null) {
return;
}