am a8765dae: am b1067103: am 633f1a5e: Merge "Use fragment for text correction preference screen" into lmp-dev

* commit 'a8765daeec64991afab0bccab5dea82c6296425d':
  Use fragment for text correction preference screen
main
Tadashi G. Takaoka 2014-07-28 12:18:12 +00:00 committed by Android Git Automerger
commit 12769faeed
5 changed files with 203 additions and 126 deletions

View File

@ -37,63 +37,9 @@
android:title="@string/settings_screen_gesture"
android:key="screen_gesture" />
<PreferenceScreen
android:fragment="com.android.inputmethod.latin.settings.CorrectionSettingsFragment"
android:title="@string/settings_screen_correction"
android:key="screen_correction">
<PreferenceScreen
android:key="edit_personal_dictionary"
android:title="@string/edit_personal_dictionary">
<intent android:action="android.settings.USER_DICTIONARY_SETTINGS" />
</PreferenceScreen>
<PreferenceScreen
android:key="configure_dictionaries_key"
android:title="@string/configure_dictionaries_title">
<intent
android:action="android.intent.action.MAIN"
android:targetClass="@string/dictionary_pack_settings_activity">
<extra
android:name="clientId"
android:value="@string/dictionary_pack_client_id" />
</intent>
</PreferenceScreen>
<CheckBoxPreference
android:key="pref_key_block_potentially_offensive"
android:title="@string/prefs_block_potentially_offensive_title"
android:summary="@string/prefs_block_potentially_offensive_summary"
android:defaultValue="@bool/config_block_potentially_offensive"
android:persistent="true" />
<ListPreference
android:key="auto_correction_threshold"
android:title="@string/auto_correction"
android:summary="@string/auto_correction_summary"
android:entryValues="@array/auto_correction_threshold_mode_indexes"
android:entries="@array/auto_correction_threshold_modes"
android:defaultValue="@string/auto_correction_threshold_mode_index_modest"
android:persistent="true" />
<CheckBoxPreference
android:key="show_suggestions"
android:summary="@string/prefs_show_suggestions_summary"
android:title="@string/prefs_show_suggestions"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_personalized_dicts"
android:title="@string/use_personalized_dicts"
android:summary="@string/use_personalized_dicts_summary"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_contacts_dict"
android:title="@string/use_contacts_dict"
android:summary="@string/use_contacts_dict_summary"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="next_word_prediction"
android:title="@string/bigram_prediction"
android:summary="@string/bigram_prediction_summary"
android:defaultValue="true"
android:persistent="true" />
</PreferenceScreen>
android:key="screen_correction" />
<PreferenceScreen
android:title="@string/settings_screen_advanced"
android:key="screen_advanced">

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
android:title="@string/settings_screen_correction"
android:key="screen_correction">
<PreferenceScreen
android:key="edit_personal_dictionary"
android:title="@string/edit_personal_dictionary">
<intent android:action="android.settings.USER_DICTIONARY_SETTINGS" />
</PreferenceScreen>
<PreferenceScreen
android:key="configure_dictionaries_key"
android:title="@string/configure_dictionaries_title">
<intent
android:action="android.intent.action.MAIN"
android:targetClass="@string/dictionary_pack_settings_activity">
<extra
android:name="clientId"
android:value="@string/dictionary_pack_client_id" />
</intent>
</PreferenceScreen>
<CheckBoxPreference
android:key="pref_key_block_potentially_offensive"
android:title="@string/prefs_block_potentially_offensive_title"
android:summary="@string/prefs_block_potentially_offensive_summary"
android:defaultValue="@bool/config_block_potentially_offensive"
android:persistent="true" />
<ListPreference
android:key="auto_correction_threshold"
android:title="@string/auto_correction"
android:summary="@string/auto_correction_summary"
android:entryValues="@array/auto_correction_threshold_mode_indexes"
android:entries="@array/auto_correction_threshold_modes"
android:defaultValue="@string/auto_correction_threshold_mode_index_modest"
android:persistent="true" />
<CheckBoxPreference
android:key="show_suggestions"
android:summary="@string/prefs_show_suggestions_summary"
android:title="@string/prefs_show_suggestions"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_personalized_dicts"
android:title="@string/use_personalized_dicts"
android:summary="@string/use_personalized_dicts_summary"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_contacts_dict"
android:title="@string/use_contacts_dict"
android:summary="@string/use_contacts_dict_summary"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="next_word_prediction"
android:title="@string/bigram_prediction"
android:summary="@string/bigram_prediction_summary"
android:defaultValue="true"
android:persistent="true" />
</PreferenceScreen>

View File

@ -0,0 +1,123 @@
/*
* Copyright (C) 2014 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.settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.userdictionary.UserDictionaryList;
import com.android.inputmethod.latin.userdictionary.UserDictionarySettings;
import java.util.TreeSet;
/**
* "Text correction" settings sub screen.
*
* This settings sub screen handles the following text correction preferences.
* - Personal dictionary
* - Add-on dictionaries
* - Block offensive words
* - Auto-correction
* - Show correction suggestions
* - Personalized suggestions
* - Suggest Contact names
* - Next-word suggestions
*/
public final class CorrectionSettingsFragment extends SubScreenFragment {
private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false;
private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS =
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|| Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2;
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_correction);
final Context context = getActivity();
final PackageManager pm = context.getPackageManager();
ensureConsistencyOfAutoCorrectionSettings();
final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent();
intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
final int number = pm.queryIntentActivities(intent, 0).size();
if (0 >= number) {
removePreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
}
final Preference editPersonalDictionary =
findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null
: pm.resolveActivity(
editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary);
}
}
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
ensureConsistencyOfAutoCorrectionSettings();
}
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getString(
R.string.auto_correction_threshold_mode_index_off);
final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
Settings.PREF_AUTO_CORRECTION_THRESHOLD);
final String currentSetting = autoCorrectionThresholdPref.getValue();
setPreferenceEnabled(
Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
}
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
final Activity activity = getActivity();
final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
if (null == localeList) {
// The locale list is null if and only if the user dictionary service is
// not present or disabled. In this case we need to remove the preference.
getPreferenceScreen().removePreference(userDictionaryPreference);
} else if (localeList.size() <= 1) {
userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
// If the size of localeList is 0, we don't set the locale parameter in the
// extras. This will be interpreted by the UserDictionarySettings class as
// meaning "the current locale".
// Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
// the locale list always has at least one element, since it always includes the current
// locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
if (localeList.size() == 1) {
final String locale = (String)localeList.toArray()[0];
userDictionaryPreference.getExtras().putString("locale", locale);
}
} else {
userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
}
}
}

View File

@ -21,11 +21,8 @@ import android.app.backup.BackupManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
@ -37,27 +34,18 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
import com.android.inputmethod.keyboard.KeyboardTheme;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.setup.LauncherIconVisibilityManager;
import com.android.inputmethod.latin.userdictionary.UserDictionaryList;
import com.android.inputmethod.latin.userdictionary.UserDictionarySettings;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.FeedbackUtils;
import com.android.inputmethodcommon.InputMethodSettingsFragment;
import java.util.TreeSet;
public final class SettingsFragment extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = SettingsFragment.class.getSimpleName();
private static final boolean DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS = false;
private static final boolean USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS =
DBG_USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS
|| Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2;
private static final int NO_MENU_GROUP = Menu.NONE; // We don't care about menu grouping.
private static final int MENU_FEEDBACK = Menu.FIRST; // The first menu item id and order.
@ -115,10 +103,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this);
ensureConsistencyOfAutoCorrectionSettings();
final PreferenceScreen correctionScreen =
(PreferenceScreen) findPreference(Settings.SCREEN_CORRECTION);
final PreferenceScreen advancedScreen =
(PreferenceScreen) findPreference(Settings.SCREEN_ADVANCED);
final PreferenceScreen debugScreen =
@ -160,15 +144,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
removePreference(Settings.PREF_SHOW_SETUP_WIZARD_ICON, advancedScreen);
}
final PreferenceScreen dictionaryLink =
(PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent();
intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
final int number = context.getPackageManager().queryIntentActivities(intent, 0).size();
if (0 >= number) {
correctionScreen.removePreference(dictionaryLink);
}
if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
final Preference enableMetricsLogging =
findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
@ -183,16 +158,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING, advancedScreen);
}
final Preference editPersonalDictionary =
findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTIGS ? null
: context.getPackageManager().resolveActivity(
editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary);
}
if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) {
getPreferenceScreen().removePreference(findPreference(Settings.SCREEN_GESTURE));
}
@ -261,22 +226,11 @@ public final class SettingsFragment extends InputMethodSettingsFragment
} else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
}
ensureConsistencyOfAutoCorrectionSettings();
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
updateListPreferenceSummaryToCurrentValue(Settings.PREF_KEYBOARD_THEME);
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString(
R.string.auto_correction_threshold_mode_index_off);
final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
Settings.PREF_AUTO_CORRECTION_THRESHOLD);
final String currentSetting = autoCorrectionThresholdPref.getValue();
setPreferenceEnabled(
Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
}
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
final SharedPreferences sp, final Resources res) {
setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS,
@ -382,30 +336,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
});
}
private void overwriteUserDictionaryPreference(Preference userDictionaryPreference) {
final Activity activity = getActivity();
final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
if (null == localeList) {
// The locale list is null if and only if the user dictionary service is
// not present or disabled. In this case we need to remove the preference.
getPreferenceScreen().removePreference(userDictionaryPreference);
} else if (localeList.size() <= 1) {
userDictionaryPreference.setFragment(UserDictionarySettings.class.getName());
// If the size of localeList is 0, we don't set the locale parameter in the
// extras. This will be interpreted by the UserDictionarySettings class as
// meaning "the current locale".
// Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
// the locale list always has at least one element, since it always includes the current
// locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
if (localeList.size() == 1) {
final String locale = (String)localeList.toArray()[0];
userDictionaryPreference.getExtras().putString("locale", locale);
}
} else {
userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
}
}
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
if (FeedbackUtils.isFeedbackFormSupported()) {

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils;
import com.android.inputmethod.dictionarypack.DictionarySettingsFragment;
import com.android.inputmethod.latin.about.AboutPreferences;
import com.android.inputmethod.latin.settings.CorrectionSettingsFragment;
import com.android.inputmethod.latin.settings.CustomInputStyleSettingsFragment;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.settings.GestureSettingsFragment;
@ -41,6 +42,7 @@ public class FragmentUtils {
sLatinImeFragments.add(MultiLingualSettingsFragment.class.getName());
sLatinImeFragments.add(CustomInputStyleSettingsFragment.class.getName());
sLatinImeFragments.add(GestureSettingsFragment.class.getName());
sLatinImeFragments.add(CorrectionSettingsFragment.class.getName());
sLatinImeFragments.add(DebugSettings.class.getName());
sLatinImeFragments.add(SettingsFragment.class.getName());
sLatinImeFragments.add(SpellCheckerSettingsFragment.class.getName());