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-04-29 01:46:17 +00:00
|
|
|
import android.util.LruCache;
|
2013-12-26 11:28:37 +00:00
|
|
|
|
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2015-02-25 19:27:48 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
2015-02-10 01:09:15 +00:00
|
|
|
import com.android.inputmethod.latin.common.ComposedData;
|
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-03-24 16:59:55 +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,
|
2015-04-09 01:58:13 +00:00
|
|
|
Dictionary.TYPE_CONTACTS,
|
2015-02-05 02:55:39 +00:00
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
2015-04-09 01:58:13 +00:00
|
|
|
Dictionary.TYPE_USER};
|
2015-02-05 02:55:39 +00:00
|
|
|
|
|
|
|
public static final String[] DYNAMIC_DICTIONARY_TYPES = new String[] {
|
2015-04-09 01:58:13 +00:00
|
|
|
Dictionary.TYPE_CONTACTS,
|
2015-02-05 02:55:39 +00:00
|
|
|
Dictionary.TYPE_USER_HISTORY,
|
2015-04-09 01:58:13 +00:00
|
|
|
Dictionary.TYPE_USER};
|
2015-02-05 02:55:39 +00:00
|
|
|
|
2015-04-29 01:46:17 +00:00
|
|
|
/**
|
|
|
|
* The facilitator will put words into the cache whenever it decodes them.
|
|
|
|
* @param cache
|
|
|
|
*/
|
|
|
|
void setValidSpellingWordReadCache(final LruCache<String, Boolean> cache);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The facilitator will get words from the cache whenever it needs to check their spelling.
|
|
|
|
* @param cache
|
|
|
|
*/
|
|
|
|
void setValidSpellingWordWriteCache(final LruCache<String, Boolean> cache);
|
|
|
|
|
2014-10-02 06:08:16 +00:00
|
|
|
/**
|
2015-03-11 23:11:50 +00:00
|
|
|
* Returns whether this facilitator is exactly for this locale.
|
2014-11-24 21:48:16 +00:00
|
|
|
*
|
2015-03-11 23:11:50 +00:00
|
|
|
* @param locale the locale to test against
|
2014-10-02 06:08:16 +00:00
|
|
|
*/
|
2015-03-11 23:11:50 +00:00
|
|
|
boolean isForLocale(final Locale locale);
|
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-03-20 01:54:27 +00:00
|
|
|
/**
|
|
|
|
* Called every time {@link LatinIME} starts on a new text field.
|
|
|
|
* Dot not affect {@link AndroidSpellCheckerService}.
|
|
|
|
*
|
|
|
|
* WARNING: The service methods that call start/finish are very spammy.
|
|
|
|
*/
|
|
|
|
void onStartInput();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called every time the {@link LatinIME} finishes with the current text field.
|
|
|
|
* May be followed by {@link #onStartInput} again in another text field,
|
|
|
|
* or it may be done for a while.
|
|
|
|
* Dot not affect {@link AndroidSpellCheckerService}.
|
|
|
|
*
|
|
|
|
* WARNING: The service methods that call start/finish are very spammy.
|
|
|
|
*/
|
2015-05-04 21:48:28 +00:00
|
|
|
void onFinishInput(Context context);
|
2015-03-20 01:54:27 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
boolean isActive();
|
2014-10-07 05:29:14 +00:00
|
|
|
|
2015-03-11 23:11:50 +00:00
|
|
|
Locale getLocale();
|
2014-10-02 06:08:16 +00:00
|
|
|
|
2015-05-01 19:45:07 +00:00
|
|
|
boolean usesContacts();
|
|
|
|
|
|
|
|
String getAccount();
|
|
|
|
|
2015-02-06 19:18:06 +00:00
|
|
|
void resetDictionaries(
|
|
|
|
final Context context,
|
2015-03-11 23:11:50 +00:00
|
|
|
final Locale newLocale,
|
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,
|
2015-02-06 19:18:06 +00:00
|
|
|
@Nullable final String account,
|
2014-11-24 21:48:16 +00:00
|
|
|
final String dictNamePrefix,
|
2015-02-06 19:18:06 +00:00
|
|
|
@Nullable final DictionaryInitializationListener listener);
|
2014-10-20 05:48:56 +00:00
|
|
|
|
2013-12-26 11:28:37 +00:00
|
|
|
@UsedForTesting
|
2015-02-06 19:18:06 +00:00
|
|
|
void resetDictionariesForTesting(
|
|
|
|
final Context context,
|
2015-03-11 23:11:50 +00:00
|
|
|
final Locale locale,
|
2015-02-06 19:18:06 +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,
|
2015-02-24 00:50:02 +00:00
|
|
|
@Nonnull final NgramContext ngramContext, final long timeStampInSeconds,
|
2015-01-27 01:19:21 +00:00
|
|
|
final boolean blockPotentiallyOffensive);
|
2013-12-26 11:28:37 +00:00
|
|
|
|
2015-02-19 01:50:33 +00:00
|
|
|
void unlearnFromUserHistory(final String word,
|
2015-02-24 00:50:02 +00:00
|
|
|
@Nonnull final NgramContext ngramContext, final long timeStampInSeconds,
|
2015-02-19 01:50:33 +00:00
|
|
|
final int eventType);
|
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-03-05 18:56:14 +00:00
|
|
|
@Nonnull SuggestionResults getSuggestionResults(final ComposedData composedData,
|
2015-02-25 19:27:48 +00:00
|
|
|
final NgramContext ngramContext, @Nonnull final Keyboard keyboard,
|
2015-02-04 20:50:31 +00:00
|
|
|
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId,
|
2015-02-25 19:27:48 +00:00
|
|
|
final int inputStyle);
|
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-05-01 19:45:07 +00:00
|
|
|
boolean clearUserHistoryDictionary(final Context context);
|
2015-03-11 01:43:13 +00:00
|
|
|
|
2015-03-03 20:11:43 +00:00
|
|
|
String dump(final Context context);
|
2015-03-11 01:43:13 +00:00
|
|
|
|
2015-01-27 01:19:21 +00:00
|
|
|
void dumpDictionaryForDebug(final String dictName);
|
2014-08-25 06:19:48 +00:00
|
|
|
|
2015-03-24 16:59:55 +00:00
|
|
|
@Nonnull List<DictionaryStats> getDictionaryStats(final Context context);
|
2013-12-26 11:28:37 +00:00
|
|
|
}
|