Home | History | Annotate | Download | only in personalization
      1 /*
      2  * Copyright (C) 2013 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 
     17 package com.android.inputmethod.latin.personalization;
     18 
     19 import com.android.inputmethod.latin.Dictionary;
     20 import com.android.inputmethod.latin.ExpandableBinaryDictionary;
     21 import com.android.inputmethod.latin.utils.CollectionUtils;
     22 
     23 import android.content.Context;
     24 import android.content.SharedPreferences;
     25 
     26 import java.util.ArrayList;
     27 
     28 /**
     29  * This class is a dictionary for the personalized language model that uses binary dictionary.
     30  */
     31 public class PersonalizationDictionary extends ExpandableBinaryDictionary {
     32     private static final String NAME = "personalization";
     33     private final ArrayList<PersonalizationDictionaryUpdateSession> mSessions =
     34             CollectionUtils.newArrayList();
     35 
     36     /** Locale for which this user history dictionary is storing words */
     37     private final String mLocale;
     38 
     39     public PersonalizationDictionary(final Context context, final String locale,
     40             final SharedPreferences prefs) {
     41         // TODO: Make isUpdatable true.
     42         super(context, getFilenameWithLocale(NAME, locale), Dictionary.TYPE_PERSONALIZATION,
     43                 false /* isUpdatable */);
     44         mLocale = locale;
     45         // TODO: Restore last updated time
     46         loadDictionary();
     47     }
     48 
     49     @Override
     50     protected void loadDictionaryAsync() {
     51         // TODO: Implement
     52     }
     53 
     54     @Override
     55     protected boolean hasContentChanged() {
     56         return false;
     57     }
     58 
     59     @Override
     60     protected boolean needsToReloadBeforeWriting() {
     61         return false;
     62     }
     63 
     64     public void registerUpdateSession(PersonalizationDictionaryUpdateSession session) {
     65         session.setDictionary(this);
     66         mSessions.add(session);
     67         session.onDictionaryReady();
     68     }
     69 
     70     public void unRegisterUpdateSession(PersonalizationDictionaryUpdateSession session) {
     71         mSessions.remove(session);
     72     }
     73 }
     74