remove references to Gservices from LatinIME
Open-sourced platform code shouldn't refer to Gservices. Use the platform-standard Secure settings table instead (which we can still push values into from the servers on google-experience devices, like gservices), but can be populated by other mechanisms for non-ged phones. Change-Id: Id0b5830bfc78c1d10dc732dce46546cd09cd1422main
parent
b1cd701602
commit
a16ff1b19e
|
@ -5,7 +5,6 @@
|
||||||
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
|
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />
|
||||||
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY" />
|
||||||
<uses-permission android:name="android.permission.BACKUP_DATA" />
|
<uses-permission android:name="android.permission.BACKUP_DATA" />
|
||||||
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
|
|
||||||
|
|
||||||
<application android:label="@string/english_ime_name"
|
<application android:label="@string/english_ime_name"
|
||||||
android:backupAgent="LatinIMEBackupAgent"
|
android:backupAgent="LatinIMEBackupAgent"
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2009 Google Inc.
|
* Copyright (C) 2009 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -66,15 +66,15 @@ public class Hints {
|
||||||
public Hints(Context context, Display display) {
|
public Hints(Context context, Display display) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mDisplay = display;
|
mDisplay = display;
|
||||||
|
|
||||||
ContentResolver cr = mContext.getContentResolver();
|
ContentResolver cr = mContext.getContentResolver();
|
||||||
mSwipeHintMaxDaysToShow = GoogleSettingsUtil.getGservicesInt(
|
mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt(
|
||||||
cr,
|
cr,
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS,
|
||||||
DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW);
|
DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW);
|
||||||
mPunctuationHintMaxDisplays = GoogleSettingsUtil.getGservicesInt(
|
mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt(
|
||||||
cr,
|
cr,
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS,
|
||||||
DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS);
|
DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public class Hints {
|
||||||
PreferenceManager.getDefaultSharedPreferences(mContext).edit();
|
PreferenceManager.getDefaultSharedPreferences(mContext).edit();
|
||||||
editor.putLong(PREF_VOICE_INPUT_LAST_TIME_USED, System.currentTimeMillis());
|
editor.putLong(PREF_VOICE_INPUT_LAST_TIME_USED, System.currentTimeMillis());
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
|
||||||
mVoiceResultContainedPunctuation = false;
|
mVoiceResultContainedPunctuation = false;
|
||||||
for (CharSequence s : SPEAKABLE_PUNCTUATION.keySet()) {
|
for (CharSequence s : SPEAKABLE_PUNCTUATION.keySet()) {
|
||||||
if (text.indexOf(s.toString()) >= 0) {
|
if (text.indexOf(s.toString()) >= 0) {
|
||||||
|
@ -117,40 +117,40 @@ public class Hints {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldShowSwipeHint() {
|
private boolean shouldShowSwipeHint() {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
|
||||||
int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0);
|
int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0);
|
||||||
|
|
||||||
// If we've already shown the hint for enough days, we'll return false.
|
// If we've already shown the hint for enough days, we'll return false.
|
||||||
if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) {
|
if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) {
|
||||||
|
|
||||||
long lastTimeVoiceWasUsed = sp.getLong(PREF_VOICE_INPUT_LAST_TIME_USED, 0);
|
long lastTimeVoiceWasUsed = sp.getLong(PREF_VOICE_INPUT_LAST_TIME_USED, 0);
|
||||||
|
|
||||||
// If the user has used voice today, we'll return false. (We don't show the hint on
|
// If the user has used voice today, we'll return false. (We don't show the hint on
|
||||||
// any day that the user has already used voice.)
|
// any day that the user has already used voice.)
|
||||||
if (!isFromToday(lastTimeVoiceWasUsed)) {
|
if (!isFromToday(lastTimeVoiceWasUsed)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the provided time is from some time today (i.e., this day, month,
|
* Determines whether the provided time is from some time today (i.e., this day, month,
|
||||||
* and year).
|
* and year).
|
||||||
*/
|
*/
|
||||||
private boolean isFromToday(long timeInMillis) {
|
private boolean isFromToday(long timeInMillis) {
|
||||||
if (timeInMillis == 0) return false;
|
if (timeInMillis == 0) return false;
|
||||||
|
|
||||||
Calendar today = Calendar.getInstance();
|
Calendar today = Calendar.getInstance();
|
||||||
today.setTimeInMillis(System.currentTimeMillis());
|
today.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
|
||||||
Calendar timestamp = Calendar.getInstance();
|
Calendar timestamp = Calendar.getInstance();
|
||||||
timestamp.setTimeInMillis(timeInMillis);
|
timestamp.setTimeInMillis(timeInMillis);
|
||||||
|
|
||||||
return (today.get(Calendar.YEAR) == timestamp.get(Calendar.YEAR) &&
|
return (today.get(Calendar.YEAR) == timestamp.get(Calendar.YEAR) &&
|
||||||
today.get(Calendar.DAY_OF_MONTH) == timestamp.get(Calendar.DAY_OF_MONTH) &&
|
today.get(Calendar.DAY_OF_MONTH) == timestamp.get(Calendar.DAY_OF_MONTH) &&
|
||||||
today.get(Calendar.MONTH) == timestamp.get(Calendar.MONTH));
|
today.get(Calendar.MONTH) == timestamp.get(Calendar.MONTH));
|
||||||
|
@ -158,7 +158,7 @@ public class Hints {
|
||||||
|
|
||||||
private void showHint(int hintViewResource) {
|
private void showHint(int hintViewResource) {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
|
||||||
int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0);
|
int numUniqueDaysShown = sp.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0);
|
||||||
long lastTimeHintWasShown = sp.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0);
|
long lastTimeHintWasShown = sp.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0);
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public class Hints {
|
||||||
mDisplay.showHint(hintViewResource);
|
mDisplay.showHint(hintViewResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAndIncrementPref(String pref) {
|
private int getAndIncrementPref(String pref) {
|
||||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
int value = sp.getInt(pref, 0);
|
int value = sp.getInt(pref, 0);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2009 Google Inc.
|
* Copyright (C) 2008-2009 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
@ -60,7 +60,7 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.EditingUtil;
|
import com.android.inputmethod.voice.EditingUtil;
|
||||||
import com.android.inputmethod.voice.FieldContext;
|
import com.android.inputmethod.voice.FieldContext;
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
import com.android.inputmethod.voice.VoiceInput;
|
import com.android.inputmethod.voice.VoiceInput;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
@ -83,7 +83,7 @@ public class LatinIME extends InputMethodService
|
||||||
static final boolean TRACE = false;
|
static final boolean TRACE = false;
|
||||||
static final boolean VOICE_INSTALLED = true;
|
static final boolean VOICE_INSTALLED = true;
|
||||||
static final boolean ENABLE_VOICE_BUTTON = true;
|
static final boolean ENABLE_VOICE_BUTTON = true;
|
||||||
|
|
||||||
private static final String PREF_VIBRATE_ON = "vibrate_on";
|
private static final String PREF_VIBRATE_ON = "vibrate_on";
|
||||||
private static final String PREF_SOUND_ON = "sound_on";
|
private static final String PREF_SOUND_ON = "sound_on";
|
||||||
private static final String PREF_AUTO_CAP = "auto_cap";
|
private static final String PREF_AUTO_CAP = "auto_cap";
|
||||||
|
@ -95,9 +95,9 @@ public class LatinIME extends InputMethodService
|
||||||
private static final String PREF_VOICE_MAIN = "voice_on_main";
|
private static final String PREF_VOICE_MAIN = "voice_on_main";
|
||||||
|
|
||||||
// Whether or not the user has used voice input before (and thus, whether to show the
|
// Whether or not the user has used voice input before (and thus, whether to show the
|
||||||
// first-run warning dialog or not).
|
// first-run warning dialog or not).
|
||||||
private static final String PREF_HAS_USED_VOICE_INPUT = "has_used_voice_input";
|
private static final String PREF_HAS_USED_VOICE_INPUT = "has_used_voice_input";
|
||||||
|
|
||||||
// Whether or not the user has used voice input from an unsupported locale UI before.
|
// Whether or not the user has used voice input from an unsupported locale UI before.
|
||||||
// For example, the user has a Chinese UI but activates voice input.
|
// For example, the user has a Chinese UI but activates voice input.
|
||||||
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
|
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
|
||||||
|
@ -116,12 +116,12 @@ public class LatinIME extends InputMethodService
|
||||||
"en_NZ " +
|
"en_NZ " +
|
||||||
"en_SG " +
|
"en_SG " +
|
||||||
"en_ZA ";
|
"en_ZA ";
|
||||||
|
|
||||||
// The private IME option used to indicate that no microphone should be shown for a
|
// The private IME option used to indicate that no microphone should be shown for a
|
||||||
// given text field. For instance this is specified by the search dialog when the
|
// given text field. For instance this is specified by the search dialog when the
|
||||||
// dialog is already showing a voice search button.
|
// dialog is already showing a voice search button.
|
||||||
private static final String IME_OPTION_NO_MICROPHONE = "nm";
|
private static final String IME_OPTION_NO_MICROPHONE = "nm";
|
||||||
|
|
||||||
public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
|
public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
|
||||||
public static final String PREF_INPUT_LANGUAGE = "input_language";
|
public static final String PREF_INPUT_LANGUAGE = "input_language";
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public class LatinIME extends InputMethodService
|
||||||
// If we detect a swipe gesture, and the user types N ms later, cancel the
|
// If we detect a swipe gesture, and the user types N ms later, cancel the
|
||||||
// swipe since it was probably a false trigger.
|
// swipe since it was probably a false trigger.
|
||||||
private static final long MIN_MILLIS_AFTER_SWIPE_TO_WAIT_FOR_TYPING = 500;
|
private static final long MIN_MILLIS_AFTER_SWIPE_TO_WAIT_FOR_TYPING = 500;
|
||||||
|
|
||||||
// How many continuous deletes at which to start deleting at a higher speed.
|
// How many continuous deletes at which to start deleting at a higher speed.
|
||||||
private static final int DELETE_ACCELERATE_AT = 20;
|
private static final int DELETE_ACCELERATE_AT = 20;
|
||||||
// Key events coming any faster than this are long-presses.
|
// Key events coming any faster than this are long-presses.
|
||||||
|
@ -150,7 +150,7 @@ public class LatinIME extends InputMethodService
|
||||||
// A word that is frequently typed and get's promoted to the user dictionary, uses this
|
// A word that is frequently typed and get's promoted to the user dictionary, uses this
|
||||||
// frequency.
|
// frequency.
|
||||||
static final int FREQUENCY_FOR_AUTO_ADD = 250;
|
static final int FREQUENCY_FOR_AUTO_ADD = 250;
|
||||||
|
|
||||||
static final int KEYCODE_ENTER = '\n';
|
static final int KEYCODE_ENTER = '\n';
|
||||||
static final int KEYCODE_SPACE = ' ';
|
static final int KEYCODE_SPACE = ' ';
|
||||||
|
|
||||||
|
@ -163,18 +163,18 @@ public class LatinIME extends InputMethodService
|
||||||
private CandidateView mCandidateView;
|
private CandidateView mCandidateView;
|
||||||
private Suggest mSuggest;
|
private Suggest mSuggest;
|
||||||
private CompletionInfo[] mCompletions;
|
private CompletionInfo[] mCompletions;
|
||||||
|
|
||||||
private AlertDialog mOptionsDialog;
|
private AlertDialog mOptionsDialog;
|
||||||
private AlertDialog mVoiceWarningDialog;
|
private AlertDialog mVoiceWarningDialog;
|
||||||
|
|
||||||
KeyboardSwitcher mKeyboardSwitcher;
|
KeyboardSwitcher mKeyboardSwitcher;
|
||||||
|
|
||||||
private UserDictionary mUserDictionary;
|
private UserDictionary mUserDictionary;
|
||||||
private ContactsDictionary mContactsDictionary;
|
private ContactsDictionary mContactsDictionary;
|
||||||
private ExpandableDictionary mAutoDictionary;
|
private ExpandableDictionary mAutoDictionary;
|
||||||
|
|
||||||
private Hints mHints;
|
private Hints mHints;
|
||||||
|
|
||||||
Resources mResources;
|
Resources mResources;
|
||||||
|
|
||||||
private String mLocale;
|
private String mLocale;
|
||||||
|
@ -214,13 +214,13 @@ public class LatinIME extends InputMethodService
|
||||||
private boolean mEnableVoice = true;
|
private boolean mEnableVoice = true;
|
||||||
private boolean mVoiceOnPrimary;
|
private boolean mVoiceOnPrimary;
|
||||||
private int mOrientation;
|
private int mOrientation;
|
||||||
|
|
||||||
// Indicates whether the suggestion strip is to be on in landscape
|
// Indicates whether the suggestion strip is to be on in landscape
|
||||||
private boolean mJustAccepted;
|
private boolean mJustAccepted;
|
||||||
private CharSequence mJustRevertedSeparator;
|
private CharSequence mJustRevertedSeparator;
|
||||||
private int mDeleteCount;
|
private int mDeleteCount;
|
||||||
private long mLastKeyTime;
|
private long mLastKeyTime;
|
||||||
|
|
||||||
private Tutorial mTutorial;
|
private Tutorial mTutorial;
|
||||||
|
|
||||||
private Vibrator mVibrator;
|
private Vibrator mVibrator;
|
||||||
|
@ -420,7 +420,7 @@ public class LatinIME extends InputMethodService
|
||||||
return mCandidateViewContainer;
|
return mCandidateViewContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartInputView(EditorInfo attribute, boolean restarting) {
|
public void onStartInputView(EditorInfo attribute, boolean restarting) {
|
||||||
// In landscape mode, this method gets called without the input view being created.
|
// In landscape mode, this method gets called without the input view being created.
|
||||||
if (mInputView == null) {
|
if (mInputView == null) {
|
||||||
|
@ -445,7 +445,7 @@ public class LatinIME extends InputMethodService
|
||||||
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
variation == EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
|
||||||
mPasswordText = true;
|
mPasswordText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
mEnableVoiceButton = shouldShowVoiceButton(makeFieldContext(), attribute);
|
mEnableVoiceButton = shouldShowVoiceButton(makeFieldContext(), attribute);
|
||||||
final boolean enableVoiceButton = mEnableVoiceButton && mEnableVoice;
|
final boolean enableVoiceButton = mEnableVoiceButton && mEnableVoice;
|
||||||
|
|
||||||
|
@ -565,11 +565,11 @@ public class LatinIME extends InputMethodService
|
||||||
@Override
|
@Override
|
||||||
public void onFinishInput() {
|
public void onFinishInput() {
|
||||||
super.onFinishInput();
|
super.onFinishInput();
|
||||||
|
|
||||||
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
|
if (mAfterVoiceInput) mVoiceInput.logInputEnded();
|
||||||
|
|
||||||
mVoiceInput.flushLogs();
|
mVoiceInput.flushLogs();
|
||||||
|
|
||||||
if (mInputView != null) {
|
if (mInputView != null) {
|
||||||
mInputView.closing();
|
mInputView.closing();
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ public class LatinIME extends InputMethodService
|
||||||
setSuggestions(null, false, false, false);
|
setSuggestions(null, false, false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CharSequence> stringList = new ArrayList<CharSequence>();
|
List<CharSequence> stringList = new ArrayList<CharSequence>();
|
||||||
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
|
for (int i=0; i<(completions != null ? completions.length : 0); i++) {
|
||||||
CompletionInfo ci = completions[i];
|
CompletionInfo ci = completions[i];
|
||||||
|
@ -712,7 +712,7 @@ public class LatinIME extends InputMethodService
|
||||||
super.setCandidatesViewShown(shown);
|
super.setCandidatesViewShown(shown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComputeInsets(InputMethodService.Insets outInsets) {
|
public void onComputeInsets(InputMethodService.Insets outInsets) {
|
||||||
super.onComputeInsets(outInsets);
|
super.onComputeInsets(outInsets);
|
||||||
|
@ -720,7 +720,7 @@ public class LatinIME extends InputMethodService
|
||||||
outInsets.contentTopInsets = outInsets.visibleTopInsets;
|
outInsets.contentTopInsets = outInsets.visibleTopInsets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
|
@ -760,7 +760,7 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
// Enable shift key and DPAD to do selections
|
// Enable shift key and DPAD to do selections
|
||||||
if (mInputView != null && mInputView.isShown() && mInputView.isShifted()) {
|
if (mInputView != null && mInputView.isShown() && mInputView.isShifted()) {
|
||||||
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
|
event = new KeyEvent(event.getDownTime(), event.getEventTime(),
|
||||||
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
|
event.getAction(), event.getKeyCode(), event.getRepeatCount(),
|
||||||
event.getDeviceId(), event.getScanCode(),
|
event.getDeviceId(), event.getScanCode(),
|
||||||
KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
|
KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
|
||||||
|
@ -864,7 +864,7 @@ public class LatinIME extends InputMethodService
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
updateShiftKeyState(getCurrentInputEditorInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addWordToDictionary(String word) {
|
public boolean addWordToDictionary(String word) {
|
||||||
mUserDictionary.addWord(word, 128);
|
mUserDictionary.addWord(word, 128);
|
||||||
return true;
|
return true;
|
||||||
|
@ -877,12 +877,12 @@ public class LatinIME extends InputMethodService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of KeyboardViewListener
|
// Implementation of KeyboardViewListener
|
||||||
|
|
||||||
public void onKey(int primaryCode, int[] keyCodes) {
|
public void onKey(int primaryCode, int[] keyCodes) {
|
||||||
long when = SystemClock.uptimeMillis();
|
long when = SystemClock.uptimeMillis();
|
||||||
if (primaryCode != Keyboard.KEYCODE_DELETE ||
|
if (primaryCode != Keyboard.KEYCODE_DELETE ||
|
||||||
when > mLastKeyTime + QUICK_PRESS) {
|
when > mLastKeyTime + QUICK_PRESS) {
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -937,7 +937,7 @@ public class LatinIME extends InputMethodService
|
||||||
changeKeyboardMode();
|
changeKeyboardMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onText(CharSequence text) {
|
public void onText(CharSequence text) {
|
||||||
InputConnection ic = getCurrentInputConnection();
|
InputConnection ic = getCurrentInputConnection();
|
||||||
if (ic == null) return;
|
if (ic == null) return;
|
||||||
|
@ -999,7 +999,7 @@ public class LatinIME extends InputMethodService
|
||||||
mKeyboardSwitcher.toggleShift();
|
mKeyboardSwitcher.toggleShift();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCharacter(int primaryCode, int[] keyCodes) {
|
private void handleCharacter(int primaryCode, int[] keyCodes) {
|
||||||
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
if (VOICE_INSTALLED && mVoiceInputHighlighted) {
|
||||||
commitVoiceInput();
|
commitVoiceInput();
|
||||||
|
@ -1055,12 +1055,12 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
if (mPredicting) {
|
if (mPredicting) {
|
||||||
// In certain languages where single quote is a separator, it's better
|
// In certain languages where single quote is a separator, it's better
|
||||||
// not to auto correct, but accept the typed word. For instance,
|
// not to auto correct, but accept the typed word. For instance,
|
||||||
// in Italian dov' should not be expanded to dove' because the elision
|
// in Italian dov' should not be expanded to dove' because the elision
|
||||||
// requires the last vowel to be removed.
|
// requires the last vowel to be removed.
|
||||||
if (mAutoCorrectOn && primaryCode != '\'' &&
|
if (mAutoCorrectOn && primaryCode != '\'' &&
|
||||||
(mJustRevertedSeparator == null
|
(mJustRevertedSeparator == null
|
||||||
|| mJustRevertedSeparator.length() == 0
|
|| mJustRevertedSeparator.length() == 0
|
||||||
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
|
|| mJustRevertedSeparator.charAt(0) != primaryCode)) {
|
||||||
pickDefaultSuggestion();
|
pickDefaultSuggestion();
|
||||||
pickedDefault = true;
|
pickedDefault = true;
|
||||||
|
@ -1070,10 +1070,10 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
TextEntryState.typedCharacter((char) primaryCode, true);
|
TextEntryState.typedCharacter((char) primaryCode, true);
|
||||||
if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED
|
if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED
|
||||||
&& primaryCode != KEYCODE_ENTER) {
|
&& primaryCode != KEYCODE_ENTER) {
|
||||||
swapPunctuationAndSpace();
|
swapPunctuationAndSpace();
|
||||||
} else if (isPredictionOn() && primaryCode == ' ') {
|
} else if (isPredictionOn() && primaryCode == ' ') {
|
||||||
//else if (TextEntryState.STATE_SPACE_AFTER_ACCEPTED) {
|
//else if (TextEntryState.STATE_SPACE_AFTER_ACCEPTED) {
|
||||||
doubleSpace();
|
doubleSpace();
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1101,7 @@ public class LatinIME extends InputMethodService
|
||||||
toggleCapsLock();
|
toggleCapsLock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleCapsLock() {
|
private void toggleCapsLock() {
|
||||||
mCapsLock = !mCapsLock;
|
mCapsLock = !mCapsLock;
|
||||||
if (mKeyboardSwitcher.isAlphabetMode()) {
|
if (mKeyboardSwitcher.isAlphabetMode()) {
|
||||||
|
@ -1113,13 +1113,13 @@ public class LatinIME extends InputMethodService
|
||||||
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
|
||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPredictionOn() {
|
private boolean isPredictionOn() {
|
||||||
boolean predictionOn = mPredictionOn;
|
boolean predictionOn = mPredictionOn;
|
||||||
//if (isFullscreenMode()) predictionOn &= mPredictionLandscape;
|
//if (isFullscreenMode()) predictionOn &= mPredictionLandscape;
|
||||||
return predictionOn;
|
return predictionOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCandidateStripVisible() {
|
private boolean isCandidateStripVisible() {
|
||||||
return isPredictionOn() && mShowSuggestions;
|
return isPredictionOn() && mShowSuggestions;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1159,7 @@ public class LatinIME extends InputMethodService
|
||||||
reallyStartListening(swipe);
|
reallyStartListening(swipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reallyStartListening(boolean swipe) {
|
private void reallyStartListening(boolean swipe) {
|
||||||
if (!mHasUsedVoiceInput) {
|
if (!mHasUsedVoiceInput) {
|
||||||
// The user has started a voice input, so remember that in the
|
// The user has started a voice input, so remember that in the
|
||||||
|
@ -1170,7 +1170,7 @@ public class LatinIME extends InputMethodService
|
||||||
editor.commit();
|
editor.commit();
|
||||||
mHasUsedVoiceInput = true;
|
mHasUsedVoiceInput = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale) {
|
if (!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale) {
|
||||||
// The user has started a voice input from an unsupported locale, so remember that
|
// The user has started a voice input from an unsupported locale, so remember that
|
||||||
// in the future (so we don't show the warning dialog the next time they do this).
|
// in the future (so we don't show the warning dialog the next time they do this).
|
||||||
|
@ -1180,7 +1180,7 @@ public class LatinIME extends InputMethodService
|
||||||
editor.commit();
|
editor.commit();
|
||||||
mHasUsedVoiceInputUnsupportedLocale = true;
|
mHasUsedVoiceInputUnsupportedLocale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear N-best suggestions
|
// Clear N-best suggestions
|
||||||
setSuggestions(null, false, false, true);
|
setSuggestions(null, false, false, true);
|
||||||
|
|
||||||
|
@ -1189,7 +1189,7 @@ public class LatinIME extends InputMethodService
|
||||||
mVoiceInput.startListening(context, swipe);
|
mVoiceInput.startListening(context, swipe);
|
||||||
switchToRecognitionStatusView();
|
switchToRecognitionStatusView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showVoiceWarningDialog(final boolean swipe) {
|
private void showVoiceWarningDialog(final boolean swipe) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setCancelable(true);
|
builder.setCancelable(true);
|
||||||
|
@ -1205,7 +1205,7 @@ public class LatinIME extends InputMethodService
|
||||||
mVoiceInput.logKeyboardWarningDialogCancel();
|
mVoiceInput.logKeyboardWarningDialogCancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (mLocaleSupportedForVoiceInput) {
|
if (mLocaleSupportedForVoiceInput) {
|
||||||
String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
String message = getString(R.string.voice_warning_may_not_understand) + "\n\n" +
|
||||||
getString(R.string.voice_warning_how_to_turn_off);
|
getString(R.string.voice_warning_how_to_turn_off);
|
||||||
|
@ -1216,10 +1216,10 @@ public class LatinIME extends InputMethodService
|
||||||
getString(R.string.voice_warning_how_to_turn_off);
|
getString(R.string.voice_warning_how_to_turn_off);
|
||||||
builder.setMessage(message);
|
builder.setMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setTitle(R.string.voice_warning_title);
|
builder.setTitle(R.string.voice_warning_title);
|
||||||
mVoiceWarningDialog = builder.create();
|
mVoiceWarningDialog = builder.create();
|
||||||
|
|
||||||
Window window = mVoiceWarningDialog.getWindow();
|
Window window = mVoiceWarningDialog.getWindow();
|
||||||
WindowManager.LayoutParams lp = window.getAttributes();
|
WindowManager.LayoutParams lp = window.getAttributes();
|
||||||
lp.token = mInputView.getWindowToken();
|
lp.token = mInputView.getWindowToken();
|
||||||
|
@ -1391,11 +1391,11 @@ public class LatinIME extends InputMethodService
|
||||||
// Fool the state watcher so that a subsequent backspace will not do a revert
|
// Fool the state watcher so that a subsequent backspace will not do a revert
|
||||||
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
TextEntryState.typedCharacter((char) KEYCODE_SPACE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pickSuggestion(CharSequence suggestion) {
|
private void pickSuggestion(CharSequence suggestion) {
|
||||||
if (mCapsLock) {
|
if (mCapsLock) {
|
||||||
suggestion = suggestion.toString().toUpperCase();
|
suggestion = suggestion.toString().toUpperCase();
|
||||||
} else if (preferCapitalization()
|
} else if (preferCapitalization()
|
||||||
|| (mKeyboardSwitcher.isAlphabetMode() && mInputView.isShifted())) {
|
|| (mKeyboardSwitcher.isAlphabetMode() && mInputView.isShifted())) {
|
||||||
suggestion = suggestion.toString().toUpperCase().charAt(0)
|
suggestion = suggestion.toString().toUpperCase().charAt(0)
|
||||||
+ suggestion.subSequence(1, suggestion.length()).toString();
|
+ suggestion.subSequence(1, suggestion.length()).toString();
|
||||||
|
@ -1428,13 +1428,13 @@ public class LatinIME extends InputMethodService
|
||||||
&& !isWordSeparator(toLeft.charAt(0))) {
|
&& !isWordSeparator(toLeft.charAt(0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(toRight)
|
if (!TextUtils.isEmpty(toRight)
|
||||||
&& !isWordSeparator(toRight.charAt(0))) {
|
&& !isWordSeparator(toRight.charAt(0))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revertLastWord(boolean deleteChar) {
|
public void revertLastWord(boolean deleteChar) {
|
||||||
final int length = mComposing.length();
|
final int length = mComposing.length();
|
||||||
if (!mPredicting && length > 0) {
|
if (!mPredicting && length > 0) {
|
||||||
|
@ -1445,7 +1445,7 @@ public class LatinIME extends InputMethodService
|
||||||
if (deleteChar) ic.deleteSurroundingText(1, 0);
|
if (deleteChar) ic.deleteSurroundingText(1, 0);
|
||||||
int toDelete = mCommittedLength;
|
int toDelete = mCommittedLength;
|
||||||
CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
|
CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
|
||||||
if (toTheLeft != null && toTheLeft.length() > 0
|
if (toTheLeft != null && toTheLeft.length() > 0
|
||||||
&& isWordSeparator(toTheLeft.charAt(0))) {
|
&& isWordSeparator(toTheLeft.charAt(0))) {
|
||||||
toDelete--;
|
toDelete--;
|
||||||
}
|
}
|
||||||
|
@ -1463,7 +1463,7 @@ public class LatinIME extends InputMethodService
|
||||||
protected String getWordSeparators() {
|
protected String getWordSeparators() {
|
||||||
return mWordSeparators;
|
return mWordSeparators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWordSeparator(int code) {
|
public boolean isWordSeparator(int code) {
|
||||||
String separators = getWordSeparators();
|
String separators = getWordSeparators();
|
||||||
return separators.contains(String.valueOf((char)code));
|
return separators.contains(String.valueOf((char)code));
|
||||||
|
@ -1542,11 +1542,11 @@ public class LatinIME extends InputMethodService
|
||||||
public void onRelease(int primaryCode) {
|
public void onRelease(int primaryCode) {
|
||||||
//vibrate();
|
//vibrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldContext makeFieldContext() {
|
private FieldContext makeFieldContext() {
|
||||||
return new FieldContext(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
return new FieldContext(getCurrentInputConnection(), getCurrentInputEditorInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
private boolean fieldCanDoVoice(FieldContext fieldContext) {
|
||||||
return !mPasswordText
|
return !mPasswordText
|
||||||
&& mVoiceInput != null
|
&& mVoiceInput != null
|
||||||
|
@ -1564,7 +1564,7 @@ public class LatinIME extends InputMethodService
|
||||||
&& !(attribute != null && attribute.privateImeOptions != null
|
&& !(attribute != null && attribute.privateImeOptions != null
|
||||||
&& attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE));
|
&& attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive ringer mode changes to detect silent mode
|
// receive ringer mode changes to detect silent mode
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1652,7 +1652,7 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTutorial() {
|
private void startTutorial() {
|
||||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_TUTORIAL), 500);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_TUTORIAL), 500);
|
||||||
}
|
}
|
||||||
|
@ -1700,21 +1700,21 @@ public class LatinIME extends InputMethodService
|
||||||
mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false);
|
mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false);
|
||||||
mHasUsedVoiceInputUnsupportedLocale =
|
mHasUsedVoiceInputUnsupportedLocale =
|
||||||
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
||||||
|
|
||||||
// Get the current list of supported locales and check the current locale against that
|
// Get the current list of supported locales and check the current locale against that
|
||||||
// list. We cache this value so as not to check it every time the user starts a voice
|
// list. We cache this value so as not to check it every time the user starts a voice
|
||||||
// input. Because this method is called by onStartInputView, this should mean that as
|
// input. Because this method is called by onStartInputView, this should mean that as
|
||||||
// long as the locale doesn't change while the user is keeping the IME open, the
|
// long as the locale doesn't change while the user is keeping the IME open, the
|
||||||
// value should never be stale.
|
// value should never be stale.
|
||||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||||
getContentResolver(),
|
getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
ArrayList<String> voiceInputSupportedLocales =
|
||||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||||
|
|
||||||
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mLocale);
|
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mLocale);
|
||||||
|
|
||||||
// If there is no auto text data, then quickfix is forced to "on", so that the other options
|
// If there is no auto text data, then quickfix is forced to "on", so that the other options
|
||||||
// will continue to work
|
// will continue to work
|
||||||
|
|
||||||
|
@ -1809,7 +1809,7 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
@Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
@Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
|
||||||
super.dump(fd, fout, args);
|
super.dump(fd, fout, args);
|
||||||
|
|
||||||
final Printer p = new PrintWriterPrinter(fout);
|
final Printer p = new PrintWriterPrinter(fout);
|
||||||
p.println("LatinIME state :");
|
p.println("LatinIME state :");
|
||||||
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
|
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
|
||||||
|
@ -1827,14 +1827,14 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Characters per second measurement
|
// Characters per second measurement
|
||||||
|
|
||||||
private static final boolean PERF_DEBUG = false;
|
private static final boolean PERF_DEBUG = false;
|
||||||
private long mLastCpsTime;
|
private long mLastCpsTime;
|
||||||
private static final int CPS_BUFFER_SIZE = 16;
|
private static final int CPS_BUFFER_SIZE = 16;
|
||||||
private long[] mCpsIntervals = new long[CPS_BUFFER_SIZE];
|
private long[] mCpsIntervals = new long[CPS_BUFFER_SIZE];
|
||||||
private int mCpsIndex;
|
private int mCpsIndex;
|
||||||
private boolean mInputTypeNoAutoCorrect;
|
private boolean mInputTypeNoAutoCorrect;
|
||||||
|
|
||||||
private void measureCps() {
|
private void measureCps() {
|
||||||
if (!LatinIME.PERF_DEBUG) return;
|
if (!LatinIME.PERF_DEBUG) return;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2009 Google Inc.
|
* Copyright (C) 2008-2009 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
@ -33,7 +33,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
import com.android.inputmethod.voice.VoiceInputLogger;
|
import com.android.inputmethod.voice.VoiceInputLogger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -49,20 +49,20 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
|
private static final String PREDICTION_SETTINGS_KEY = "prediction_settings";
|
||||||
private static final String VOICE_SETTINGS_KEY = "enable_voice_input";
|
private static final String VOICE_SETTINGS_KEY = "enable_voice_input";
|
||||||
private static final String VOICE_SERVER_KEY = "voice_server_url";
|
private static final String VOICE_SERVER_KEY = "voice_server_url";
|
||||||
|
|
||||||
private static final String TAG = "LatinIMESettings";
|
private static final String TAG = "LatinIMESettings";
|
||||||
|
|
||||||
// Dialog ids
|
// Dialog ids
|
||||||
private static final int VOICE_INPUT_CONFIRM_DIALOG = 0;
|
private static final int VOICE_INPUT_CONFIRM_DIALOG = 0;
|
||||||
|
|
||||||
private CheckBoxPreference mQuickFixes;
|
private CheckBoxPreference mQuickFixes;
|
||||||
private CheckBoxPreference mShowSuggestions;
|
private CheckBoxPreference mShowSuggestions;
|
||||||
private CheckBoxPreference mVoicePreference;
|
private CheckBoxPreference mVoicePreference;
|
||||||
|
|
||||||
private VoiceInputLogger mLogger;
|
private VoiceInputLogger mLogger;
|
||||||
|
|
||||||
private boolean mOkClicked = false;
|
private boolean mOkClicked = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
@ -70,14 +70,14 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY);
|
mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY);
|
||||||
mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY);
|
mShowSuggestions = (CheckBoxPreference) findPreference(SHOW_SUGGESTIONS_KEY);
|
||||||
mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY);
|
mVoicePreference = (CheckBoxPreference) findPreference(VOICE_SETTINGS_KEY);
|
||||||
|
|
||||||
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
mVoicePreference.setOnPreferenceClickListener(this);
|
mVoicePreference.setOnPreferenceClickListener(this);
|
||||||
mVoicePreference.setChecked(prefs.getBoolean(
|
mVoicePreference.setChecked(prefs.getBoolean(
|
||||||
VOICE_SETTINGS_KEY, getResources().getBoolean(R.bool.voice_input_default)));
|
VOICE_SETTINGS_KEY, getResources().getBoolean(R.bool.voice_input_default)));
|
||||||
|
|
||||||
mLogger = VoiceInputLogger.getLogger(this);
|
mLogger = VoiceInputLogger.getLogger(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
|| !RecognitionManager.isRecognitionAvailable(this)) {
|
|| !RecognitionManager.isRecognitionAvailable(this)) {
|
||||||
getPreferenceScreen().removePreference(mVoicePreference);
|
getPreferenceScreen().removePreference(mVoicePreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
mVoicePreference.setChecked(
|
mVoicePreference.setChecked(
|
||||||
getPreferenceManager().getSharedPreferences().getBoolean(VOICE_SETTINGS_KEY, true));
|
getPreferenceManager().getSharedPreferences().getBoolean(VOICE_SETTINGS_KEY, true));
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
@ -144,13 +144,13 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
.setTitle(R.string.voice_warning_title)
|
.setTitle(R.string.voice_warning_title)
|
||||||
.setPositiveButton(android.R.string.ok, listener)
|
.setPositiveButton(android.R.string.ok, listener)
|
||||||
.setNegativeButton(android.R.string.cancel, listener);
|
.setNegativeButton(android.R.string.cancel, listener);
|
||||||
|
|
||||||
// Get the current list of supported locales and check the current locale against
|
// 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
|
// 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.
|
// the current language as part of the pop-up confirmation dialog.
|
||||||
String supportedLocalesString = GoogleSettingsUtil.getGservicesString(
|
String supportedLocalesString = SettingsUtil.getSettingsString(
|
||||||
getContentResolver(),
|
getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES,
|
||||||
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
LatinIME.DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES);
|
||||||
ArrayList<String> voiceInputSupportedLocales =
|
ArrayList<String> voiceInputSupportedLocales =
|
||||||
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
Lists.newArrayList(supportedLocalesString.split("\\s+"));
|
||||||
|
@ -167,7 +167,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
getString(R.string.voice_hint_dialog_message);
|
getString(R.string.voice_hint_dialog_message);
|
||||||
builder.setMessage(message);
|
builder.setMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
dialog.setOnDismissListener(this);
|
dialog.setOnDismissListener(this);
|
||||||
mLogger.settingsWarningDialogShown();
|
mLogger.settingsWarningDialogShown();
|
||||||
|
@ -177,7 +177,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
public void onDismiss(DialogInterface dialog) {
|
||||||
mLogger.settingsWarningDialogDismissed();
|
mLogger.settingsWarningDialogDismissed();
|
||||||
if (!mOkClicked) {
|
if (!mOkClicked) {
|
||||||
|
@ -186,7 +186,7 @@ public class LatinIMESettings extends PreferenceActivity
|
||||||
mVoicePreference.setChecked(false);
|
mVoicePreference.setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateVoicePreference() {
|
private void updateVoicePreference() {
|
||||||
SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
|
SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit();
|
||||||
boolean isChecked = mVoicePreference.isChecked();
|
boolean isChecked = mVoicePreference.isChecked();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2009 Google Inc.
|
* Copyright (C) 2009 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
@ -36,7 +36,7 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.voice.GoogleSettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -112,10 +112,10 @@ public class RecognitionView {
|
||||||
mView = inflater.inflate(R.layout.recognition_status, null);
|
mView = inflater.inflate(R.layout.recognition_status, null);
|
||||||
|
|
||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
mMinMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
mMinMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||||
cr, GoogleSettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f);
|
||||||
mMaxMicrophoneLevel = GoogleSettingsUtil.getGservicesFloat(
|
mMaxMicrophoneLevel = SettingsUtil.getSettingsFloat(
|
||||||
cr, GoogleSettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
cr, SettingsUtil.LATIN_IME_MAX_MICROPHONE_LEVEL, 30.f);
|
||||||
|
|
||||||
// Pre-load volume level images
|
// Pre-load volume level images
|
||||||
Resources r = context.getResources();
|
Resources r = context.getResources();
|
||||||
|
@ -131,7 +131,7 @@ public class RecognitionView {
|
||||||
|
|
||||||
mInitializing = r.getDrawable(R.drawable.mic_slash);
|
mInitializing = r.getDrawable(R.drawable.mic_slash);
|
||||||
mError = r.getDrawable(R.drawable.caution);
|
mError = r.getDrawable(R.drawable.caution);
|
||||||
|
|
||||||
mImage = (ImageView) mView.findViewById(R.id.image);
|
mImage = (ImageView) mView.findViewById(R.id.image);
|
||||||
mButton = mView.findViewById(R.id.button);
|
mButton = mView.findViewById(R.id.button);
|
||||||
mButton.setOnClickListener(clickListener);
|
mButton.setOnClickListener(clickListener);
|
||||||
|
@ -207,12 +207,12 @@ public class RecognitionView {
|
||||||
final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray())
|
final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray())
|
||||||
.order(ByteOrder.nativeOrder()).asShortBuffer();
|
.order(ByteOrder.nativeOrder()).asShortBuffer();
|
||||||
buf.position(0);
|
buf.position(0);
|
||||||
waveBuffer.reset();
|
waveBuffer.reset();
|
||||||
showWave(buf, speechStartPosition / 2, speechEndPosition / 2);
|
showWave(buf, speechStartPosition / 2, speechEndPosition / 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an average abs of the specified buffer.
|
* @return an average abs of the specified buffer.
|
||||||
*/
|
*/
|
||||||
|
@ -295,15 +295,15 @@ public class RecognitionView {
|
||||||
MarginLayoutParams mProgressParams = (MarginLayoutParams)mProgress.getLayoutParams();
|
MarginLayoutParams mProgressParams = (MarginLayoutParams)mProgress.getLayoutParams();
|
||||||
mProgressParams.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
mProgressParams.topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||||
-h / 2 - 18, mContext.getResources().getDisplayMetrics());
|
-h / 2 - 18, mContext.getResources().getDisplayMetrics());
|
||||||
|
|
||||||
// Tweak the padding manually to fill out the whole view horizontally.
|
// Tweak the padding manually to fill out the whole view horizontally.
|
||||||
// TODO: Do this in the xml layout instead.
|
// TODO: Do this in the xml layout instead.
|
||||||
((View) mImage.getParent()).setPadding(4, ((View) mImage.getParent()).getPaddingTop(), 3,
|
((View) mImage.getParent()).setPadding(4, ((View) mImage.getParent()).getPaddingTop(), 3,
|
||||||
((View) mImage.getParent()).getPaddingBottom());
|
((View) mImage.getParent()).getPaddingBottom());
|
||||||
mProgress.setLayoutParams(mProgressParams);
|
mProgress.setLayoutParams(mProgressParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void finish() {
|
public void finish() {
|
||||||
mState = State.READY;
|
mState = State.READY;
|
||||||
mUiHandler.post(new Runnable() {
|
mUiHandler.post(new Runnable() {
|
||||||
|
|
|
@ -19,20 +19,19 @@ package com.android.inputmethod.voice;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for getting Google-specific settings from GoogleSettings.Partner or
|
* Utility for retrieving settings from Settings.Secure.
|
||||||
* Gservices. Retrieving such settings may fail on a non-Google Experience
|
|
||||||
* Device (GED)
|
|
||||||
*/
|
*/
|
||||||
public class GoogleSettingsUtil {
|
public class SettingsUtil {
|
||||||
/**
|
/**
|
||||||
* A whitespace-separated list of supported locales for voice input from the keyboard.
|
* A whitespace-separated list of supported locales for voice input from the keyboard.
|
||||||
*/
|
*/
|
||||||
public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES =
|
public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES =
|
||||||
"latin_ime_voice_input_supported_locales";
|
"latin_ime_voice_input_supported_locales";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A whitespace-separated list of recommended app packages for voice input from the
|
* A whitespace-separated list of recommended app packages for voice input from the
|
||||||
* keyboard.
|
* keyboard.
|
||||||
|
@ -45,7 +44,7 @@ public class GoogleSettingsUtil {
|
||||||
*/
|
*/
|
||||||
public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS =
|
public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS =
|
||||||
"latin_ime_voice_input_swipe_hint_max_days";
|
"latin_ime_voice_input_swipe_hint_max_days";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of times to show the punctuation hint for voice input.
|
* The maximum number of times to show the punctuation hint for voice input.
|
||||||
*/
|
*/
|
||||||
|
@ -60,7 +59,7 @@ public class GoogleSettingsUtil {
|
||||||
public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
|
public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
|
||||||
"latin_ime_speech_input_complete_silence_length_millis";
|
"latin_ime_speech_input_complete_silence_length_millis";
|
||||||
public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
|
public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
|
||||||
"latin_ime_speech_input_possibly_complete_silence_length_millis";
|
"latin_ime_speech_input_possibly_complete_silence_length_millis";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Min and max volume levels that can be displayed on the "speak now" screen.
|
* Min and max volume levels that can be displayed on the "speak now" screen.
|
||||||
|
@ -76,100 +75,39 @@ public class GoogleSettingsUtil {
|
||||||
public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
|
public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uri to use to access gservices settings
|
* Get a string-valued setting.
|
||||||
*/
|
*
|
||||||
private static final Uri GSERVICES_URI = Uri.parse("content://settings/gservices");
|
|
||||||
|
|
||||||
private static final String TAG = GoogleSettingsUtil.class.getSimpleName();
|
|
||||||
|
|
||||||
private static final boolean DBG = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safely query for a Gservices string setting, which may not be available if this
|
|
||||||
* is not a Google Experience Device.
|
|
||||||
*
|
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if none can be found
|
* @param defaultValue The default value to use if none can be found
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found
|
* @return The value of the setting, or defaultValue if it couldn't be found
|
||||||
*/
|
*/
|
||||||
public static String getGservicesString(ContentResolver cr, String key, String defaultValue) {
|
public static String getSettingsString(ContentResolver cr, String key, String defaultValue) {
|
||||||
return getSettingString(GSERVICES_URI, cr, key, defaultValue);
|
String result = Settings.Secure.getString(cr, key);
|
||||||
|
return (result == null) ? defaultValue : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safely query for a Gservices int setting, which may not be available if this
|
* Get an int-valued setting.
|
||||||
* is not a Google Experience Device.
|
*
|
||||||
*
|
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
||||||
*/
|
*/
|
||||||
public static int getGservicesInt(ContentResolver cr, String key, int defaultValue) {
|
public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) {
|
||||||
try {
|
return Settings.Secure.getInt(cr, key, defaultValue);
|
||||||
return Integer.parseInt(getGservicesString(cr, key, String.valueOf(defaultValue)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Safely query for a Gservices float setting, which may not be available if this
|
* Get a float-valued setting.
|
||||||
* is not a Google Experience Device.
|
*
|
||||||
*
|
|
||||||
* @param cr The content resolver to use
|
* @param cr The content resolver to use
|
||||||
* @param key The setting to look up
|
* @param key The setting to look up
|
||||||
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
* @param defaultValue The default value to use if the setting couldn't be found or parsed
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
* @return The value of the setting, or defaultValue if it couldn't be found or parsed
|
||||||
*/
|
*/
|
||||||
public static float getGservicesFloat(ContentResolver cr, String key, float defaultValue) {
|
public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) {
|
||||||
try {
|
return Settings.Secure.getFloat(cr, key, defaultValue);
|
||||||
return Float.parseFloat(getGservicesString(cr, key, String.valueOf(defaultValue)));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A safe way to query for a setting on both Google Experience and
|
|
||||||
* non-Google Experience devices, (code adapted from maps application
|
|
||||||
* examples)
|
|
||||||
*
|
|
||||||
* @param uri The uri to provide to the content resolver
|
|
||||||
* @param cr The content resolver to use
|
|
||||||
* @param key The setting to look up
|
|
||||||
* @param defaultValue The default value to use if none can be found
|
|
||||||
* @return The value of the setting, or defaultValue if it couldn't be found
|
|
||||||
*/
|
|
||||||
private static String getSettingString(Uri uri, ContentResolver cr, String key,
|
|
||||||
String defaultValue) {
|
|
||||||
String value = null;
|
|
||||||
|
|
||||||
Cursor cursor = null;
|
|
||||||
try {
|
|
||||||
cursor = cr.query(uri, new String[] {
|
|
||||||
"value"
|
|
||||||
}, "name='" + key + "'", null, null);
|
|
||||||
if ((cursor != null) && cursor.moveToFirst()) {
|
|
||||||
value = cursor.getString(cursor.getColumnIndexOrThrow("value"));
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// This happens because we're probably running a non Type 1 aka
|
|
||||||
// Google Experience device which doesn't have the Google libraries.
|
|
||||||
if (DBG) {
|
|
||||||
Log.d(TAG, "Error getting setting from " + uri + " for key " + key + ": " + t);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DBG && value == null) {
|
|
||||||
Log.i(TAG, "no setting found from " + uri + " for key " + key + ", returning default");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (value != null) ? value : defaultValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2009 Google Inc.
|
* Copyright (C) 2009 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* 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
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
@ -81,13 +81,13 @@ public class VoiceInput implements OnClickListener {
|
||||||
"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS";
|
"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS";
|
||||||
private static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
|
private static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS =
|
||||||
"android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS";
|
"android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS";
|
||||||
|
|
||||||
// The usual endpointer default value for input complete silence length is 0.5 seconds,
|
// The usual endpointer default value for input complete silence length is 0.5 seconds,
|
||||||
// but that's used for things like voice search. For dictation-like voice input like this,
|
// but that's used for things like voice search. For dictation-like voice input like this,
|
||||||
// we go with a more liberal value of 1 second. This value will only be used if a value
|
// we go with a more liberal value of 1 second. This value will only be used if a value
|
||||||
// is not provided from Gservices.
|
// is not provided from Gservices.
|
||||||
private static final String INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS = "1000";
|
private static final String INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS = "1000";
|
||||||
|
|
||||||
// Used to record part of that state for logging purposes.
|
// Used to record part of that state for logging purposes.
|
||||||
public static final int DEFAULT = 0;
|
public static final int DEFAULT = 0;
|
||||||
public static final int LISTENING = 1;
|
public static final int LISTENING = 1;
|
||||||
|
@ -145,11 +145,11 @@ public class VoiceInput implements OnClickListener {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
newView();
|
newView();
|
||||||
|
|
||||||
String recommendedPackages = GoogleSettingsUtil.getGservicesString(
|
String recommendedPackages = SettingsUtil.getSettingsString(
|
||||||
context.getContentResolver(),
|
context.getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,
|
||||||
DEFAULT_RECOMMENDED_PACKAGES);
|
DEFAULT_RECOMMENDED_PACKAGES);
|
||||||
|
|
||||||
mRecommendedList = new Whitelist();
|
mRecommendedList = new Whitelist();
|
||||||
for (String recommendedPackage : recommendedPackages.split("\\s+")) {
|
for (String recommendedPackage : recommendedPackages.split("\\s+")) {
|
||||||
mRecommendedList.addApp(recommendedPackage);
|
mRecommendedList.addApp(recommendedPackage);
|
||||||
|
@ -167,10 +167,10 @@ public class VoiceInput implements OnClickListener {
|
||||||
public boolean isBlacklistedField(FieldContext context) {
|
public boolean isBlacklistedField(FieldContext context) {
|
||||||
return mBlacklist.matches(context);
|
return mBlacklist.matches(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to decide whether to show voice input hints for this field, etc.
|
* Used to decide whether to show voice input hints for this field, etc.
|
||||||
*
|
*
|
||||||
* @return true if field is recommended for voice
|
* @return true if field is recommended for voice
|
||||||
*/
|
*/
|
||||||
public boolean isRecommendedField(FieldContext context) {
|
public boolean isRecommendedField(FieldContext context) {
|
||||||
|
@ -190,7 +190,7 @@ public class VoiceInput implements OnClickListener {
|
||||||
|
|
||||||
Locale locale = Locale.getDefault();
|
Locale locale = Locale.getDefault();
|
||||||
String localeString = locale.getLanguage() + "-" + locale.getCountry();
|
String localeString = locale.getLanguage() + "-" + locale.getCountry();
|
||||||
|
|
||||||
mLogger.start(localeString, swipe);
|
mLogger.start(localeString, swipe);
|
||||||
|
|
||||||
mState = LISTENING;
|
mState = LISTENING;
|
||||||
|
@ -215,9 +215,9 @@ public class VoiceInput implements OnClickListener {
|
||||||
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
|
intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle());
|
||||||
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
|
intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME");
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
|
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
|
||||||
GoogleSettingsUtil.getGservicesInt(
|
SettingsUtil.getSettingsInt(
|
||||||
mContext.getContentResolver(),
|
mContext.getContentResolver(),
|
||||||
GoogleSettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,
|
||||||
1));
|
1));
|
||||||
|
|
||||||
// Get endpointer params from Gservices.
|
// Get endpointer params from Gservices.
|
||||||
|
@ -226,27 +226,27 @@ public class VoiceInput implements OnClickListener {
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
|
EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,
|
||||||
null /* rely on endpointer default */);
|
null /* rely on endpointer default */);
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
|
INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS
|
||||||
/* our default value is different from the endpointer's */);
|
/* our default value is different from the endpointer's */);
|
||||||
putEndpointerExtra(
|
putEndpointerExtra(
|
||||||
cr,
|
cr,
|
||||||
intent,
|
intent,
|
||||||
GoogleSettingsUtil.
|
SettingsUtil.
|
||||||
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
|
||||||
null /* rely on endpointer default */);
|
null /* rely on endpointer default */);
|
||||||
|
|
||||||
mRecognitionManager.startListening(intent);
|
mRecognitionManager.startListening(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the provided Gservices key, attempts to parse it into a long,
|
* Gets the value of the provided Gservices key, attempts to parse it into a long,
|
||||||
* and if successful, puts the long value as an extra in the provided intent.
|
* and if successful, puts the long value as an extra in the provided intent.
|
||||||
|
@ -254,15 +254,15 @@ public class VoiceInput implements OnClickListener {
|
||||||
private void putEndpointerExtra(ContentResolver cr, Intent i,
|
private void putEndpointerExtra(ContentResolver cr, Intent i,
|
||||||
String gservicesKey, String intentExtraKey, String defaultValue) {
|
String gservicesKey, String intentExtraKey, String defaultValue) {
|
||||||
long l = -1;
|
long l = -1;
|
||||||
String s = GoogleSettingsUtil.getGservicesString(cr, gservicesKey, defaultValue);
|
String s = SettingsUtil.getSettingsString(cr, gservicesKey, defaultValue);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
try {
|
try {
|
||||||
l = Long.valueOf(s);
|
l = Long.valueOf(s);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "could not parse value for " + gservicesKey + ": " + s);
|
Log.e(TAG, "could not parse value for " + gservicesKey + ": " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l != -1) i.putExtra(intentExtraKey, l);
|
if (l != -1) i.putExtra(intentExtraKey, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,35 +302,35 @@ public class VoiceInput implements OnClickListener {
|
||||||
public void logTextModified() {
|
public void logTextModified() {
|
||||||
mLogger.textModified();
|
mLogger.textModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logKeyboardWarningDialogShown() {
|
public void logKeyboardWarningDialogShown() {
|
||||||
mLogger.keyboardWarningDialogShown();
|
mLogger.keyboardWarningDialogShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logKeyboardWarningDialogDismissed() {
|
public void logKeyboardWarningDialogDismissed() {
|
||||||
mLogger.keyboardWarningDialogDismissed();
|
mLogger.keyboardWarningDialogDismissed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logKeyboardWarningDialogOk() {
|
public void logKeyboardWarningDialogOk() {
|
||||||
mLogger.keyboardWarningDialogOk();
|
mLogger.keyboardWarningDialogOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logKeyboardWarningDialogCancel() {
|
public void logKeyboardWarningDialogCancel() {
|
||||||
mLogger.keyboardWarningDialogCancel();
|
mLogger.keyboardWarningDialogCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logSwipeHintDisplayed() {
|
public void logSwipeHintDisplayed() {
|
||||||
mLogger.swipeHintDisplayed();
|
mLogger.swipeHintDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logPunctuationHintDisplayed() {
|
public void logPunctuationHintDisplayed() {
|
||||||
mLogger.punctuationHintDisplayed();
|
mLogger.punctuationHintDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logVoiceInputDelivered() {
|
public void logVoiceInputDelivered() {
|
||||||
mLogger.voiceInputDelivered();
|
mLogger.voiceInputDelivered();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logNBestChoose(int index) {
|
public void logNBestChoose(int index) {
|
||||||
mLogger.nBestChoose(index);
|
mLogger.nBestChoose(index);
|
||||||
}
|
}
|
||||||
|
@ -338,11 +338,11 @@ public class VoiceInput implements OnClickListener {
|
||||||
public void logInputEnded() {
|
public void logInputEnded() {
|
||||||
mLogger.inputEnded();
|
mLogger.inputEnded();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flushLogs() {
|
public void flushLogs() {
|
||||||
mLogger.flush();
|
mLogger.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent makeIntent() {
|
private static Intent makeIntent() {
|
||||||
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue