Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2014 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.utils;
     18 
     19 import java.util.List;
     20 import java.util.Locale;
     21 
     22 import android.view.inputmethod.InputMethodSubtype;
     23 
     24 import com.android.inputmethod.latin.Dictionary;
     25 import com.android.inputmethod.latin.PrevWordsInfo;
     26 
     27 public class DistracterFilterCheckingIsInDictionary implements DistracterFilter {
     28     private final DistracterFilter mDistracterFilter;
     29     private final Dictionary mDictionary;
     30 
     31     public DistracterFilterCheckingIsInDictionary(final DistracterFilter distracterFilter,
     32             final Dictionary dictionary) {
     33         mDistracterFilter = distracterFilter;
     34         mDictionary = dictionary;
     35     }
     36 
     37     @Override
     38     public boolean isDistracterToWordsInDictionaries(PrevWordsInfo prevWordsInfo,
     39             String testedWord, Locale locale) {
     40         if (mDictionary.isInDictionary(testedWord)) {
     41             // This filter treats entries that are already in the dictionary as non-distracters
     42             // because they have passed the filtering in the past.
     43             return false;
     44         } else {
     45             return mDistracterFilter.isDistracterToWordsInDictionaries(
     46                     prevWordsInfo, testedWord, locale);
     47         }
     48     }
     49 
     50     @Override
     51     public void updateEnabledSubtypes(List<InputMethodSubtype> enabledSubtypes) {
     52         // Do nothing.
     53     }
     54 
     55     @Override
     56     public void close() {
     57         // Do nothing.
     58     }
     59 }
     60