Make dump dictionary settings easily extensible.

This adds "Dump contextual dictionary".

Bug: 14161647
Change-Id: I41a6d6e131d9d8c300ac0120d903d46d88bb3346
main
Keisuke Kuroyanagi 2014-06-10 19:59:19 +09:00
parent 1ffb7cd448
commit a20432479d
4 changed files with 23 additions and 45 deletions

View File

@ -349,14 +349,8 @@ mobile devices. [CHAR LIMIT=25] -->
<string name="read_external_dictionary_confirm_install_message">Really install this file for <xliff:g id="LANGUAGE_NAME" example="English">%s</xliff:g>?</string> <string name="read_external_dictionary_confirm_install_message">Really install this file for <xliff:g id="LANGUAGE_NAME" example="English">%s</xliff:g>?</string>
<!-- Title for an error dialog that contains the details of the error in the body [CHAR LIMIT=80] --> <!-- Title for an error dialog that contains the details of the error in the body [CHAR LIMIT=80] -->
<string name="error">There was an error</string> <string name="error">There was an error</string>
<!-- Title of the settings for dumpping contacts dictionary file [CHAR LIMIT=35] --> <!-- Title of the settings group for dumpping dictionary files that have been created on the device [CHAR LIMIT=35] -->
<string name="prefs_dump_contacts_dict">Dump contacts dictionary</string> <string name="prefs_dump_dynamic_dicts" translatable="false">Dump dictionary</string>
<!-- Title of the settings for dumpping personal dictionary file [CHAR LIMIT=35] -->
<string name="prefs_dump_user_dict">Dump personal dictionary</string>
<!-- Title of the settings for dumpping user history dictionary file [CHAR LIMIT=35] -->
<string name="prefs_dump_user_history_dict">Dump user history dictionary</string>
<!-- Title of the settings for dumpping personalization dictionary file [CHAR LIMIT=35] -->
<string name="prefs_dump_personalization_dict">Dump personalization dictionary</string>
<!-- Title of the button to revert to the default value of the device in the settings dialog [CHAR LIMIT=15] --> <!-- Title of the button to revert to the default value of the device in the settings dialog [CHAR LIMIT=15] -->
<string name="button_default">Default</string> <string name="button_default">Default</string>

View File

@ -61,16 +61,8 @@
<PreferenceScreen <PreferenceScreen
android:key="read_external_dictionary" android:key="read_external_dictionary"
android:title="@string/prefs_read_external_dictionary" /> android:title="@string/prefs_read_external_dictionary" />
<PreferenceScreen <PreferenceCategory
android:key="dump_contacts_dict" android:key="pref_key_dump_dictionaries"
android:title="@string/prefs_dump_contacts_dict" /> android:title="@string/prefs_dump_dynamic_dicts">
<PreferenceScreen </PreferenceCategory>
android:key="dump_user_dict"
android:title="@string/prefs_dump_user_dict" />
<PreferenceScreen
android:key="dump_user_history_dict"
android:title="@string/prefs_dump_user_history_dict" />
<PreferenceScreen
android:key="dump_personalization_dict"
android:title="@string/prefs_dump_personalization_dict" />
</PreferenceScreen> </PreferenceScreen>

View File

@ -74,7 +74,7 @@ public class DictionaryFacilitator {
Dictionary.TYPE_CONTEXTUAL Dictionary.TYPE_CONTEXTUAL
}; };
private static final Map<String, Class<? extends ExpandableBinaryDictionary>> public static final Map<String, Class<? extends ExpandableBinaryDictionary>>
DICT_TYPE_TO_CLASS = new HashMap<>(); DICT_TYPE_TO_CLASS = new HashMap<>();
static { static {

View File

@ -25,10 +25,12 @@ import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryDumpBroadcastReceiver; import com.android.inputmethod.latin.DictionaryDumpBroadcastReceiver;
import com.android.inputmethod.latin.DictionaryFacilitator;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug; import com.android.inputmethod.latin.debug.ExternalDictionaryGetterForDebug;
import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.ApplicationUtils;
@ -48,10 +50,9 @@ public final class DebugSettings extends PreferenceFragment
public static final String PREF_KEY_PREVIEW_DISMISS_DURATION = public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
"pref_key_preview_dismiss_duration"; "pref_key_preview_dismiss_duration";
private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary"; private static final String PREF_READ_EXTERNAL_DICTIONARY = "read_external_dictionary";
private static final String PREF_DUMP_CONTACTS_DICT = "dump_contacts_dict"; private static final String PREF_KEY_DUMP_DICTS = "pref_key_dump_dictionaries";
private static final String PREF_DUMP_USER_DICT = "dump_user_dict"; private static final String PREF_KEY_DUMP_DICT_PREFIX = "pref_key_dump_dictionaries";
private static final String PREF_DUMP_USER_HISTORY_DICT = "dump_user_history_dict"; private static final String DICT_NAME_KEY_FOR_EXTRAS = "dict_name";
private static final String PREF_DUMP_PERSONALIZATION_DICT = "dump_personalization_dict";
public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview"; public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview";
public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout"; public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
@ -80,16 +81,18 @@ public final class DebugSettings extends PreferenceFragment
}); });
} }
final PreferenceGroup dictDumpPreferenceGroup =
(PreferenceGroup)findPreference(PREF_KEY_DUMP_DICTS);
final OnPreferenceClickListener dictDumpPrefClickListener = final OnPreferenceClickListener dictDumpPrefClickListener =
new DictDumpPrefClickListener(this); new DictDumpPrefClickListener(this);
findPreference(PREF_DUMP_CONTACTS_DICT).setOnPreferenceClickListener( for (final String dictName : DictionaryFacilitator.DICT_TYPE_TO_CLASS.keySet()) {
dictDumpPrefClickListener); final Preference preference = new Preference(getActivity());
findPreference(PREF_DUMP_USER_DICT).setOnPreferenceClickListener( preference.setKey(PREF_KEY_DUMP_DICT_PREFIX + dictName);
dictDumpPrefClickListener); preference.setTitle("Dump " + dictName + " dictionary");
findPreference(PREF_DUMP_USER_HISTORY_DICT).setOnPreferenceClickListener( preference.setOnPreferenceClickListener(dictDumpPrefClickListener);
dictDumpPrefClickListener); preference.getExtras().putString(DICT_NAME_KEY_FOR_EXTRAS, dictName);
findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener( dictDumpPreferenceGroup.addPreference(preference);
dictDumpPrefClickListener); }
final Resources res = getResources(); final Resources res = getResources();
setupKeyLongpressTimeoutSettings(prefs, res); setupKeyLongpressTimeoutSettings(prefs, res);
setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION, setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION,
@ -117,18 +120,7 @@ public final class DebugSettings extends PreferenceFragment
@Override @Override
public boolean onPreferenceClick(final Preference arg0) { public boolean onPreferenceClick(final Preference arg0) {
final String dictName; final String dictName = arg0.getExtras().getString(DICT_NAME_KEY_FOR_EXTRAS);
if (arg0.getKey().equals(PREF_DUMP_CONTACTS_DICT)) {
dictName = Dictionary.TYPE_CONTACTS;
} else if (arg0.getKey().equals(PREF_DUMP_USER_DICT)) {
dictName = Dictionary.TYPE_USER;
} else if (arg0.getKey().equals(PREF_DUMP_USER_HISTORY_DICT)) {
dictName = Dictionary.TYPE_USER_HISTORY;
} else if (arg0.getKey().equals(PREF_DUMP_PERSONALIZATION_DICT)) {
dictName = Dictionary.TYPE_PERSONALIZATION;
} else {
dictName = null;
}
if (dictName != null) { if (dictName != null) {
final Intent intent = final Intent intent =
new Intent(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION); new Intent(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION);