2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* 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
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-01-28 18:09:44 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* 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;
|
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.app.Dialog;
|
2010-03-05 23:49:16 +00:00
|
|
|
import android.app.backup.BackupManager;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.content.DialogInterface;
|
2009-07-05 20:17:13 +00:00
|
|
|
import android.content.SharedPreferences;
|
2010-08-20 05:35:02 +00:00
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.os.Bundle;
|
2009-03-26 00:39:38 +00:00
|
|
|
import android.preference.CheckBoxPreference;
|
2010-02-09 22:17:30 +00:00
|
|
|
import android.preference.ListPreference;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.preference.PreferenceActivity;
|
|
|
|
import android.preference.PreferenceGroup;
|
2010-03-30 17:05:53 +00:00
|
|
|
import android.speech.SpeechRecognizer;
|
2009-03-26 00:39:38 +00:00
|
|
|
import android.text.AutoText;
|
2010-01-16 20:21:23 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2010-01-28 18:09:44 +00:00
|
|
|
import com.android.inputmethod.voice.SettingsUtil;
|
2010-01-16 20:21:23 +00:00
|
|
|
import com.android.inputmethod.voice.VoiceInputLogger;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2009-07-05 20:17:13 +00:00
|
|
|
public class LatinIMESettings extends PreferenceActivity
|
2010-01-16 20:21:23 +00:00
|
|
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
|
|
|
DialogInterface.OnDismissListener {
|
2009-07-05 20:17:13 +00:00
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
private static final String QUICK_FIXES_KEY = "quick_fixes";
|
2009-03-13 22:11:42 +00:00
|
|
|
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
|
2010-02-09 22:17:30 +00:00
|
|
|
private static final String VOICE_SETTINGS_KEY = "voice_mode";
|
2010-08-20 05:35:02 +00:00
|
|
|
private static final String DEBUG_MODE_KEY = "debug_mode";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private static final String TAG = "LatinIMESettings";
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Dialog ids
|
|
|
|
private static final int VOICE_INPUT_CONFIRM_DIALOG = 0;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
private CheckBoxPreference mQuickFixes;
|
2010-08-20 05:35:02 +00:00
|
|
|
private CheckBoxPreference mDebugMode;
|
2010-02-09 22:17:30 +00:00
|
|
|
private ListPreference mVoicePreference;
|
|
|
|
private boolean mVoiceOn;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private VoiceInputLogger mLogger;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private boolean mOkClicked = false;
|
2010-02-09 22:17:30 +00:00
|
|
|
private String mVoiceModeOff;
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
addPreferencesFromResource(R.xml.prefs);
|
2009-03-26 00:39:38 +00:00
|
|
|
mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY);
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoicePreference = (ListPreference) findPreference(VOICE_SETTINGS_KEY);
|
2010-01-16 20:21:23 +00:00
|
|
|
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
|
|
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoiceModeOff = getString(R.string.voice_mode_off);
|
|
|
|
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
|
2010-01-16 20:21:23 +00:00
|
|
|
mLogger = VoiceInputLogger.getLogger(this);
|
2010-08-20 05:35:02 +00:00
|
|
|
|
|
|
|
mDebugMode = (CheckBoxPreference) findPreference(DEBUG_MODE_KEY);
|
2010-08-30 05:53:01 +00:00
|
|
|
updateDebugMode();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 00:39:38 +00:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
int autoTextSize = AutoText.getSize(getListView());
|
|
|
|
if (autoTextSize < 1) {
|
|
|
|
((PreferenceGroup) findPreference(PREDICTION_SETTINGS_KEY))
|
2010-01-16 20:21:23 +00:00
|
|
|
.removePreference(mQuickFixes);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
if (!LatinIME.VOICE_INSTALLED
|
2010-03-30 17:05:53 +00:00
|
|
|
|| !SpeechRecognizer.isRecognitionAvailable(this)) {
|
2010-01-16 20:21:23 +00:00
|
|
|
getPreferenceScreen().removePreference(mVoicePreference);
|
2010-02-09 22:17:30 +00:00
|
|
|
} else {
|
|
|
|
updateVoiceModeSummary();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2009-07-05 20:17:13 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
|
|
|
|
this);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2009-07-05 20:17:13 +00:00
|
|
|
(new BackupManager(this)).dataChanged();
|
2010-02-09 22:17:30 +00:00
|
|
|
// If turning on voice input, show dialog
|
|
|
|
if (key.equals(VOICE_SETTINGS_KEY) && !mVoiceOn) {
|
|
|
|
if (! prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff)
|
|
|
|
.equals(mVoiceModeOff)) {
|
|
|
|
showVoiceConfirmation();
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-08-20 05:35:02 +00:00
|
|
|
} else if (key.equals(DEBUG_MODE_KEY)) {
|
2010-08-30 05:53:01 +00:00
|
|
|
if (mDebugMode != null) {
|
|
|
|
mDebugMode.setChecked(prefs.getBoolean(DEBUG_MODE_KEY, false));
|
|
|
|
updateDebugMode();
|
|
|
|
}
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff));
|
|
|
|
updateVoiceModeSummary();
|
|
|
|
}
|
|
|
|
|
2010-08-30 05:53:01 +00:00
|
|
|
private void updateDebugMode() {
|
2010-08-20 05:35:02 +00:00
|
|
|
if (mDebugMode == null) {
|
|
|
|
return;
|
|
|
|
}
|
2010-08-30 05:53:01 +00:00
|
|
|
boolean isDebugMode = mDebugMode.isChecked();
|
2010-08-20 05:35:02 +00:00
|
|
|
String version = "";
|
|
|
|
try {
|
|
|
|
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
|
|
|
|
version = "Version " + info.versionName;
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.e(TAG, "Could not find version info.");
|
|
|
|
}
|
|
|
|
if (!isDebugMode) {
|
|
|
|
mDebugMode.setEnabled(false);
|
|
|
|
mDebugMode.setTitle(version);
|
|
|
|
mDebugMode.setSummary("");
|
|
|
|
} else {
|
|
|
|
mDebugMode.setEnabled(true);
|
|
|
|
mDebugMode.setSummary(version);
|
2010-08-30 05:53:01 +00:00
|
|
|
mDebugMode.setSummary("");
|
2010-08-20 05:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-09 22:17:30 +00:00
|
|
|
private void showVoiceConfirmation() {
|
|
|
|
mOkClicked = false;
|
|
|
|
showDialog(VOICE_INPUT_CONFIRM_DIALOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVoiceModeSummary() {
|
|
|
|
mVoicePreference.setSummary(
|
|
|
|
getResources().getStringArray(R.array.voice_input_modes_summary)
|
|
|
|
[mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
@Override
|
|
|
|
protected Dialog onCreateDialog(int id) {
|
|
|
|
switch (id) {
|
|
|
|
case VOICE_INPUT_CONFIRM_DIALOG:
|
|
|
|
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
|
|
|
if (whichButton == DialogInterface.BUTTON_NEGATIVE) {
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoicePreference.setValue(mVoiceModeOff);
|
2010-01-16 20:21:23 +00:00
|
|
|
mLogger.settingsWarningDialogCancel();
|
|
|
|
} else if (whichButton == DialogInterface.BUTTON_POSITIVE) {
|
|
|
|
mOkClicked = true;
|
|
|
|
mLogger.settingsWarningDialogOk();
|
|
|
|
}
|
|
|
|
updateVoicePreference();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
|
.setTitle(R.string.voice_warning_title)
|
|
|
|
.setPositiveButton(android.R.string.ok, listener)
|
|
|
|
.setNegativeButton(android.R.string.cancel, listener);
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
// Get the current list of supported locales and check the current locale against
|
|
|
|
// that list, to decide whether to put a warning that voice input will not work in
|
|
|
|
// the current language as part of the pop-up confirmation dialog.
|
2010-01-28 18:09:44 +00:00
|
|
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
2010-01-16 20:21:23 +00:00
|
|
|
getContentResolver(),
|
2010-01-28 18:09:44 +00:00
|
|
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
2010-01-16 20:21:23 +00:00
|
|
|
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
|
|
|
ArrayList<String> voiceInputSupportedLocales =
|
2010-02-17 22:42:51 +00:00
|
|
|
LatinIME.newArrayList(supportedLocalesString.split("\\s+"));
|
2010-01-16 20:21:23 +00:00
|
|
|
boolean localeSupported = voiceInputSupportedLocales.contains(
|
|
|
|
Locale.getDefault().toString());
|
|
|
|
|
|
|
|
if (localeSupported) {
|
|
|
|
String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
|
|
|
getString(R.string.voice_hint_dialog_message);
|
|
|
|
builder.setMessage(message);
|
|
|
|
} else {
|
|
|
|
String message = getString(R.string.voice_warning_locale_not_supported) +
|
|
|
|
"\n\n" + getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
|
|
|
getString(R.string.voice_hint_dialog_message);
|
|
|
|
builder.setMessage(message);
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
dialog.setOnDismissListener(this);
|
|
|
|
mLogger.settingsWarningDialogShown();
|
|
|
|
return dialog;
|
|
|
|
default:
|
|
|
|
Log.e(TAG, "unknown dialog " + id);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
mLogger.settingsWarningDialogDismissed();
|
|
|
|
if (!mOkClicked) {
|
|
|
|
// This assumes that onPreferenceClick gets called first, and this if the user
|
|
|
|
// agreed after the warning, we set the mOkClicked value to true.
|
2010-02-09 22:17:30 +00:00
|
|
|
mVoicePreference.setValue(mVoiceModeOff);
|
2010-01-16 20:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-28 18:09:44 +00:00
|
|
|
|
2010-01-16 20:21:23 +00:00
|
|
|
private void updateVoicePreference() {
|
2010-02-09 22:17:30 +00:00
|
|
|
boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff);
|
2010-01-16 20:21:23 +00:00
|
|
|
if (isChecked) {
|
|
|
|
mLogger.voiceInputSettingEnabled();
|
|
|
|
} else {
|
|
|
|
mLogger.voiceInputSettingDisabled();
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|