Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b7c1cd5 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android (Google) Code Review
Browse files

Merge "Add PersionalizationDictionaryRegister"

parents 53830bf4 8c4fcb10
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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);
    }

+5 −1
Original line number Diff line number Diff line
@@ -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);
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -59,8 +59,7 @@ public class PersonalizationDictionaryHelper {
        }
    }

    public static void
            registerPersonalizationDictionaryUpdateSession(final Context context,
    public static void registerPersonalizationDictionaryUpdateSession(final Context context,
            final PersonalizationDictionaryUpdateSession session) {
        final PersonalizationPredictionDictionary dictionary =
                getPersonalizationPredictionDictionary(context,
+28 −0
Original line number Diff line number Diff line
/*
 * 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) {
    }
}
+23 −5
Original line number Diff line number Diff line
@@ -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;
        }