import android.provider.Settings.System;
import android.speech.tts.TtsEngines;
import android.text.TextUtils;
+import android.util.Log;
import android.view.InputDevice;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.textservice.TextServicesManager;
import com.android.internal.app.LocalePicker;
+import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settings.Settings.KeyboardLayoutPickerActivity;
import com.android.settings.SettingsActivity;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
+import com.android.settings.voicewakeup.VoiceWakeupSettings;
+import cyanogenmod.hardware.CMHardwareManager;
+import cyanogenmod.providers.CMSettings;
+
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
implements Preference.OnPreferenceChangeListener, InputManager.InputDeviceListener,
KeyboardLayoutDialogFragment.OnSetupKeyboardLayoutsListener, Indexable,
InputMethodPreference.OnSavePreferenceListener {
+
+ private static final String TAG = "InputMethodAndLanguageSettings";
+
private static final String KEY_SPELL_CHECKERS = "spellcheckers_settings";
private static final String KEY_PHONE_LANGUAGE = "phone_language";
private static final String KEY_CURRENT_INPUT_METHOD = "current_input_method";
private static final String KEY_INPUT_METHOD_SELECTOR = "input_method_selector";
private static final String KEY_USER_DICTIONARY_SETTINGS = "key_user_dictionary_settings";
+ private static final String KEY_POINTER_SETTINGS_CATEGORY = "pointer_settings_category";
private static final String KEY_PREVIOUSLY_ENABLED_SUBTYPES = "previously_enabled_subtypes";
+ private static final String KEY_TOUCHSCREEN_HOVERING = "touchscreen_hovering";
+ private static final String KEY_TRACKPAD_SETTINGS = "gesture_pad_settings";
+ private static final String KEY_STYLUS_GESTURES = "stylus_gestures";
+ private static final String KEY_STYLUS_ICON_ENABLED = "stylus_icon_enabled";
+ private static final String KEY_VOICE_CATEGORY = "voice_category";
+ private static final String KEY_VOICE_WAKEUP = "voice_wakeup";
+
// false: on ICS or later
private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false;
+ private static final String[] sSystemSettingNames = {
+ System.TEXT_AUTO_REPLACE, System.TEXT_AUTO_CAPS, System.TEXT_AUTO_PUNCTUATE,
+ };
+
+ private static final String[] sHardKeyboardKeys = {
+ "auto_replace", "auto_caps", "auto_punctuate",
+ };
+
private int mDefaultInputMethodSelectorVisibility = 0;
private ListPreference mShowInputMethodSelectorPref;
+ private SwitchPreference mStylusIconEnabled;
+ private SwitchPreference mTouchscreenHovering;
private PreferenceCategory mKeyboardSettingsCategory;
private PreferenceCategory mHardKeyboardCategory;
private PreferenceCategory mGameControllerCategory;
private Preference mLanguagePref;
+ private PreferenceScreen mStylusGestures;
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
private final ArrayList<PreferenceScreen> mHardKeyboardPreferenceList = new ArrayList<>();
private InputManager mIm;
private Intent mIntentWaitingForResult;
private InputMethodSettingValuesWrapper mInputMethodSettingValues;
private DevicePolicyManager mDpm;
+ private CMHardwareManager mHardware;
+
+ @Override
+ protected int getMetricsCategory() {
+ return MetricsLogger.INPUTMETHOD_LANGUAGE;
+ }
@Override
public void onCreate(Bundle icicle) {
mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodSettingValues = InputMethodSettingValuesWrapper.getInstance(activity);
+ mHardware = CMHardwareManager.getInstance(activity);
+
try {
mDefaultInputMethodSelectorVisibility = Integer.valueOf(
getString(R.string.input_method_selector_visibility_default_value));
mIm = (InputManager)activity.getSystemService(Context.INPUT_SERVICE);
updateInputDevices();
+ PreferenceCategory pointerSettingsCategory = (PreferenceCategory)
+ findPreference(KEY_POINTER_SETTINGS_CATEGORY);
+
+ mStylusGestures = (PreferenceScreen) findPreference(KEY_STYLUS_GESTURES);
+ mStylusIconEnabled = (SwitchPreference) findPreference(KEY_STYLUS_ICON_ENABLED);
+
+ mTouchscreenHovering = (SwitchPreference) findPreference(KEY_TOUCHSCREEN_HOVERING);
+
+ if (pointerSettingsCategory != null) {
+ if (!getResources().getBoolean(com.android.internal.R.bool.config_stylusGestures)) {
+ pointerSettingsCategory.removePreference(mStylusGestures);
+ pointerSettingsCategory.removePreference(mStylusIconEnabled);
+ }
+
+ if (!mHardware.isSupported(CMHardwareManager.FEATURE_TOUCH_HOVERING)) {
+ pointerSettingsCategory.removePreference(mTouchscreenHovering);
+ mTouchscreenHovering = null;
+ } else {
+ mTouchscreenHovering.setChecked(
+ mHardware.get(CMHardwareManager.FEATURE_TOUCH_HOVERING));
+ }
+
+ Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(getActivity(),
+ pointerSettingsCategory, KEY_TRACKPAD_SETTINGS);
+ if (pointerSettingsCategory.getPreferenceCount() == 0) {
+ getPreferenceScreen().removePreference(pointerSettingsCategory);
+ }
+ }
+
+ // Enable or disable mStatusBarImeSwitcher based on boolean: config_show_cmIMESwitcher
+ boolean showCmImeSwitcher = getResources().getBoolean(
+ com.android.internal.R.bool.config_show_cmIMESwitcher);
+ if (!showCmImeSwitcher) {
+ Preference pref = findPreference(CMSettings.System.STATUS_BAR_IME_SWITCHER);
+ if (pref != null) {
+ getPreferenceScreen().removePreference(pref);
+ }
+ }
+
// Spell Checker
final Preference spellChecker = findPreference(KEY_SPELL_CHECKERS);
if (spellChecker != null) {
if (mShowsOnlyFullImeAndKeyboardList && identifier != null) {
showKeyboardLayoutDialog(identifier);
}
+
+ if (!Utils.isUserOwner() ||
+ !Utils.isPackageInstalled(getActivity(),
+ VoiceWakeupSettings.VOICE_WAKEUP_PACKAGE, false)) {
+ PreferenceCategory voiceCategory = (PreferenceCategory)
+ findPreference(KEY_VOICE_CATEGORY);
+ if (voiceCategory != null) {
+ Preference wakeup = voiceCategory.findPreference(KEY_VOICE_WAKEUP);
+ if (wakeup != null) {
+ voiceCategory.removePreference(wakeup);
+ }
+ }
+ }
+
}
private void updateInputMethodSelectorSummary(int value) {
if (spellChecker != null) {
final TextServicesManager tsm = (TextServicesManager) getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
- if (tsm.isSpellCheckerEnabled()) {
- final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
+ final SpellCheckerInfo sci = tsm.getCurrentSpellChecker();
+ spellChecker.setEnabled(sci != null);
+ if (tsm.isSpellCheckerEnabled() && sci != null) {
spellChecker.setSummary(sci.loadLabel(getPackageManager()));
} else {
spellChecker.setSummary(R.string.switch_off_text);
}
}
+ if (mStylusIconEnabled != null) {
+ mStylusIconEnabled.setChecked(Settings.System.getInt(getActivity().getContentResolver(),
+ Settings.System.STYLUS_ICON_ENABLED, 0) == 1);
+ }
+
if (!mShowsOnlyFullImeAndKeyboardList) {
if (mLanguagePref != null) {
String localeName = getLocaleName(getActivity());
}
}
+ // Hard keyboard
+ if (!mHardKeyboardPreferenceList.isEmpty()) {
+ for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
+ SwitchPreference swPref = (SwitchPreference)
+ mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]);
+ swPref.setChecked(
+ System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0);
+ }
+ }
+
updateInputDevices();
// Refresh internal states in mInputMethodSettingValues to keep the latest
if (Utils.isMonkeyRunning()) {
return false;
}
- if (preference instanceof PreferenceScreen) {
+ if (preference == mStylusIconEnabled) {
+ Settings.System.putInt(getActivity().getContentResolver(),
+ Settings.System.STYLUS_ICON_ENABLED, mStylusIconEnabled.isChecked() ? 1 : 0);
+ } else if (preference == mTouchscreenHovering) {
+ boolean touchHoveringEnable = mTouchscreenHovering.isChecked();
+ CMSettings.Secure.putInt(getActivity().getContentResolver(),
+ CMSettings.Secure.FEATURE_TOUCH_HOVERING,
+ touchHoveringEnable ? 1 : 0);
+ return true;
+ } else if (preference instanceof PreferenceScreen) {
if (preference.getFragment() != null) {
// Fragment will be handled correctly by the super class.
} else if (KEY_CURRENT_INPUT_METHOD.equals(preference.getKey())) {
final InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showInputMethodPicker();
+ imm.showInputMethodPicker(false /* showAuxiliarySubtypes */);
}
} else if (preference instanceof SwitchPreference) {
final SwitchPreference pref = (SwitchPreference) preference;
pref.isChecked() ? 1 : 0);
return true;
}
+ if (!mHardKeyboardPreferenceList.isEmpty()) {
+ for (int i = 0; i < sHardKeyboardKeys.length; ++i) {
+ if (pref == mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i])) {
+ System.putInt(getContentResolver(), sSystemSettingNames[i],
+ pref.isChecked() ? 1 : 0);
+ return true;
+ }
+ }
+ }
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}
}
+ public static void restore(Context context) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ final CMHardwareManager hardware = CMHardwareManager.getInstance(context);
+ if (hardware.isSupported(CMHardwareManager.FEATURE_TOUCH_HOVERING)) {
+ final boolean enabled = prefs.getBoolean(KEY_TOUCHSCREEN_HOVERING,
+ hardware.get(CMHardwareManager.FEATURE_TOUCH_HOVERING));
+ CMSettings.Secure.putInt(context.getContentResolver(),
+ CMSettings.Secure.FEATURE_TOUCH_HOVERING,
+ enabled ? 1 : 0);
+ }
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
R.string.builtin_keyboard_settings_title);
indexable.screenTitle = screenTitle;
indexables.add(indexable);
- }
- // Voice input
- indexable = new SearchIndexableRaw(context);
- indexable.key = "voice_input_settings";
- indexable.title = context.getString(R.string.voice_input_settings);
- indexable.screenTitle = screenTitle;
- indexable.keywords = context.getString(R.string.keywords_voice_input);
- indexables.add(indexable);
+ // Auto replace.
+ indexable = new SearchIndexableRaw(context);
+ indexable.key = "auto_replace";
+ indexable.title = context.getString(R.string.auto_replace);
+ indexable.summaryOn = context.getString(R.string.auto_replace_summary);
+ indexable.summaryOff = context.getString(R.string.auto_replace_summary);
+ indexable.screenTitle = screenTitle;
+ indexables.add(indexable);
+
+ // Auto caps.
+ indexable = new SearchIndexableRaw(context);
+ indexable.key = "auto_caps";
+ indexable.title = context.getString(R.string.auto_caps);
+ indexable.summaryOn = context.getString(R.string.auto_caps_summary);
+ indexable.summaryOff = context.getString(R.string.auto_caps_summary);
+ indexable.screenTitle = screenTitle;
+ indexables.add(indexable);
+
+ // Auto punctuate.
+ indexable = new SearchIndexableRaw(context);
+ indexable.key = "auto_punctuate";
+ indexable.title = context.getString(R.string.auto_punctuate);
+ indexable.summaryOn = context.getString(R.string.auto_punctuate_summary);
+ indexable.summaryOff = context.getString(R.string.auto_punctuate_summary);
+ indexable.screenTitle = screenTitle;
+ indexables.add(indexable);
+ }
// Text-to-speech.
TtsEngines ttsEngines = new TtsEngines(context);