2013-12-26 11:28:37 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-01-27 01:19:21 +00:00
|
|
|
import android.util.Pair;
|
2015-02-03 01:10:38 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
2013-12-26 11:28:37 +00:00
|
|
|
|
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2015-02-04 20:50:31 +00:00
|
|
|
import com.android.inputmethod.keyboard.KeyboardLayout;
|
2014-07-08 07:36:06 +00:00
|
|
|
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
|
2014-03-25 06:35:20 +00:00
|
|
|
import com.android.inputmethod.latin.utils.SuggestionResults;
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2013-12-26 09:26:28 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2015-01-27 01:19:21 +00:00
|
|
|
import java.util.List;
|
2015-02-03 01:10:38 +00:00
|
|
|
import java.util.Locale;
|
2014-02-26 10:14:16 +00:00
|
|
|
import java.util.Map;
|
2013-12-26 11:28:37 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2014-10-22 05:04:07 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2014-11-24 21:48:16 +00:00
|
|
|
/**
|
2015-01-27 01:19:21 +00:00
|
|
|
* Interface that facilitates interaction with different kinds of dictionaries. Provides APIs to
|
|
|
|
* instantiate and select the correct dictionaries (based on language or account), update entries
|
|
|
|
* and fetch suggestions. Currently AndroidSpellCheckerService and LatinIME both use
|
|
|
|
* DictionaryFacilitator as a client for interacting with dictionaries.
|
2014-11-24 21:48:16 +00:00
|
|
|
*/
|
2015-01-27 01:19:21 +00:00
|
|
|
public interface DictionaryFacilitator {
|
2015-02-05 02:55:39 +00:00
|
|
|
|
|
|
|
public static final String[] ALL_DICTIONARY_TYPES = new String[] {
|
|
|
|
Dictionary.TYPE_MAIN,
|
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
|
|
|
Dictionary.TYPE_USER,
|
|
|
|
Dictionary.TYPE_CONTACTS};
|
|
|
|
|
|
|
|
public static final String[] DYNAMIC_DICTIONARY_TYPES = new String[] {
|
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
|
|
|
Dictionary.TYPE_USER,
|
|
|
|
Dictionary.TYPE_CONTACTS};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
|
|
|
|
*/
|
|
|
|
public static final String[] DICTIONARY_TYPES_FOR_SPELLING = new String[] {
|
|
|
|
Dictionary.TYPE_MAIN,
|
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
|
|
|
Dictionary.TYPE_USER,
|
|
|
|
Dictionary.TYPE_CONTACTS};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@link Dictionary#TYPE_USER} is deprecated, except for the spelling service.
|
|
|
|
*/
|
|
|
|
public static final String[] DICTIONARY_TYPES_FOR_SUGGESTIONS = new String[] {
|
|
|
|
Dictionary.TYPE_MAIN,
|
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
|
|
|
Dictionary.TYPE_CONTACTS};
|
|
|
|
|
2014-10-02 06:08:16 +00:00
|
|
|
/**
|
|
|
|
* Returns whether this facilitator is exactly for this list of locales.
|
2014-11-24 21:48:16 +00:00
|
|
|
*
|
2014-10-02 06:08:16 +00:00
|
|
|
* @param locales the list of locales to test against
|
|
|
|
*/
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean isForLocales(final Locale[] locales);
|
2014-10-02 06:08:16 +00:00
|
|
|
|
2014-11-24 21:48:16 +00:00
|
|
|
/**
|
|
|
|
* Returns whether this facilitator is exactly for this account.
|
|
|
|
*
|
|
|
|
* @param account the account to test against.
|
|
|
|
*/
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean isForAccount(@Nullable final String account);
|
2014-11-24 21:48:16 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
interface DictionaryInitializationListener {
|
|
|
|
void onUpdateMainDictionaryAvailability(boolean isMainDictionaryAvailable);
|
2014-03-25 06:35:20 +00:00
|
|
|
}
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void updateEnabledSubtypes(final List<InputMethodSubtype> enabledSubtypes);
|
2014-03-25 06:35:20 +00:00
|
|
|
|
2014-10-07 05:29:14 +00:00
|
|
|
// TODO: remove this, it's confusing with seamless multiple language switching
|
2015-01-27 01:19:21 +00:00
|
|
|
void setIsMonolingualUser(final boolean isMonolingualUser);
|
2014-09-02 09:03:49 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean isActive();
|
2014-10-07 05:29:14 +00:00
|
|
|
|
2014-10-02 06:08:16 +00:00
|
|
|
/**
|
2014-10-07 05:29:14 +00:00
|
|
|
* Returns the most probable locale among all currently active locales. BE CAREFUL using this.
|
2014-10-02 06:08:16 +00:00
|
|
|
*
|
|
|
|
* DO NOT USE THIS just because it's convenient. Use it when it's correct, for example when
|
|
|
|
* choosing what dictionary to put a word in, or when changing the capitalization of a typed
|
|
|
|
* string.
|
2014-10-07 05:29:14 +00:00
|
|
|
* @return the most probable locale
|
2014-10-02 06:08:16 +00:00
|
|
|
*/
|
2015-01-27 01:19:21 +00:00
|
|
|
Locale getMostProbableLocale();
|
2014-10-07 05:29:14 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
Locale[] getLocales();
|
2014-10-07 06:56:45 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void switchMostProbableLanguage(@Nullable final Locale locale);
|
2014-10-07 09:15:14 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean isConfidentAboutCurrentLanguageBeing(final Locale mLocale);
|
2014-10-02 06:08:16 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void resetDictionaries(final Context context, final Locale[] newLocales,
|
2014-03-25 06:35:20 +00:00
|
|
|
final boolean useContactsDict, final boolean usePersonalizedDicts,
|
|
|
|
final boolean forceReloadMainDictionary,
|
2014-11-24 21:48:16 +00:00
|
|
|
@Nullable final String account,
|
2015-01-27 01:19:21 +00:00
|
|
|
final DictionaryInitializationListener listener);
|
2014-06-10 09:05:10 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void resetDictionariesWithDictNamePrefix(final Context context,
|
2014-10-07 06:56:45 +00:00
|
|
|
final Locale[] newLocales,
|
2014-11-24 21:48:16 +00:00
|
|
|
final boolean useContactsDict,
|
|
|
|
final boolean usePersonalizedDicts,
|
2014-06-10 09:05:10 +00:00
|
|
|
final boolean forceReloadMainDictionary,
|
2014-10-22 05:04:07 +00:00
|
|
|
@Nullable final DictionaryInitializationListener listener,
|
2014-11-24 21:48:16 +00:00
|
|
|
final String dictNamePrefix,
|
2015-01-27 01:19:21 +00:00
|
|
|
@Nullable final String account);
|
2014-10-20 05:48:56 +00:00
|
|
|
|
2013-12-26 11:28:37 +00:00
|
|
|
@UsedForTesting
|
2015-01-27 01:19:21 +00:00
|
|
|
void resetDictionariesForTesting(final Context context, final Locale[] locales,
|
2014-02-26 10:14:16 +00:00
|
|
|
final ArrayList<String> dictionaryTypes, final HashMap<String, File> dictionaryFiles,
|
2014-11-24 21:48:16 +00:00
|
|
|
final Map<String, Map<String, String>> additionalDictAttributes,
|
2015-01-27 01:19:21 +00:00
|
|
|
@Nullable final String account);
|
2013-12-27 05:49:32 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void closeDictionaries();
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2014-06-16 07:56:57 +00:00
|
|
|
@UsedForTesting
|
2015-01-27 01:19:21 +00:00
|
|
|
ExpandableBinaryDictionary getSubDictForTesting(final String dictName);
|
2014-06-16 07:56:57 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
// The main dictionaries are loaded asynchronously. Don't cache the return value
|
2014-09-11 09:51:31 +00:00
|
|
|
// of these methods.
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean hasAtLeastOneInitializedMainDictionary();
|
2014-09-11 09:51:31 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean hasAtLeastOneUninitializedMainDictionary();
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void waitForLoadingMainDictionaries(final long timeout, final TimeUnit unit)
|
|
|
|
throws InterruptedException;
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2014-02-20 13:20:43 +00:00
|
|
|
@UsedForTesting
|
2015-01-27 01:19:21 +00:00
|
|
|
void waitForLoadingDictionariesForTesting(final long timeout, final TimeUnit unit)
|
|
|
|
throws InterruptedException;
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void addToUserHistory(final String suggestion, final boolean wasAutoCapitalized,
|
2014-10-22 05:04:07 +00:00
|
|
|
@Nonnull final NgramContext ngramContext, final int timeStampInSeconds,
|
2015-01-27 01:19:21 +00:00
|
|
|
final boolean blockPotentiallyOffensive);
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void removeWordFromPersonalizedDicts(final String word);
|
2014-06-20 05:46:13 +00:00
|
|
|
|
2013-12-26 11:28:37 +00:00
|
|
|
// TODO: Revise the way to fusion suggestion results.
|
2015-01-27 01:19:21 +00:00
|
|
|
SuggestionResults getSuggestionResults(final WordComposer composer,
|
2014-10-24 08:12:30 +00:00
|
|
|
final NgramContext ngramContext, final long proximityInfoHandle,
|
2015-02-04 20:50:31 +00:00
|
|
|
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId,
|
|
|
|
final int inputStyle, final KeyboardLayout keyboardLayout);
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-02-05 01:15:04 +00:00
|
|
|
boolean isValidSpellingWord(final String word);
|
|
|
|
|
|
|
|
boolean isValidSuggestionWord(final String word);
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
int getFrequency(final String word);
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
int getMaxFrequencyOfExactMatches(final String word);
|
2014-06-05 10:05:58 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void clearUserHistoryDictionary();
|
2014-01-29 03:00:33 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void dumpDictionaryForDebug(final String dictName);
|
2014-08-25 06:19:48 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
ArrayList<Pair<String, DictionaryStats>> getStatsOfEnabledSubDicts();
|
2013-12-26 11:28:37 +00:00
|
|
|
}
|