mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1153904 - Add item in Settings for Voice input. r=liuche
--HG-- extra : commitid : 7bSNSn6infw extra : rebase_source : a2981d2d2f408ff834dbed37451e0721db39e574 extra : histedit_source : 335d1dba180cc0dc56cd47435d6829f823471891
This commit is contained in:
parent
50c78b8ae7
commit
664bab157c
@ -250,6 +250,8 @@ size. -->
|
||||
<!ENTITY pref_media_autoplay_enabled_summary "Control if websites can autoplay videos and other media content">
|
||||
<!ENTITY pref_zoom_force_enabled "Always enable zoom">
|
||||
<!ENTITY pref_zoom_force_enabled_summary "Force override so you can zoom any page">
|
||||
<!ENTITY pref_voice_input "Voice input">
|
||||
<!ENTITY pref_voice_input_summary "Allow voice dictation in the title bar">
|
||||
|
||||
<!ENTITY pref_use_master_password "Use master password">
|
||||
<!ENTITY pref_sync "Sync">
|
||||
|
@ -99,6 +99,7 @@ gujar.sources += [
|
||||
'util/StringUtils.java',
|
||||
'util/ThreadUtils.java',
|
||||
'util/UIAsyncTask.java',
|
||||
'util/VoiceRecognizerUtils.java',
|
||||
'util/WeakReferenceHandler.java',
|
||||
'util/WebActivityMapper.java',
|
||||
'util/WindowUtils.java',
|
||||
|
@ -43,6 +43,7 @@ import org.mozilla.gecko.updater.UpdateServiceHelper;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
import org.mozilla.gecko.util.VoiceRecognizerUtils;
|
||||
import org.mozilla.gecko.widget.FloatingHintEditText;
|
||||
|
||||
import android.app.ActionBar;
|
||||
@ -128,6 +129,7 @@ OnSharedPreferenceChangeListener
|
||||
private static final String PREFS_TRACKING_PROTECTION = "privacy.trackingprotection.enabled";
|
||||
private static final String PREFS_TRACKING_PROTECTION_LEARN_MORE = NON_PREF_PREFIX + "trackingprotection.learn_more";
|
||||
public static final String PREFS_OPEN_URLS_IN_PRIVATE = NON_PREF_PREFIX + "openExternalURLsPrivately";
|
||||
public static final String PREFS_VOICE_INPUT_ENABLED = NON_PREF_PREFIX + "voice_input_enabled";
|
||||
|
||||
private static final String ACTION_STUMBLER_UPLOAD_PREF = AppConstants.ANDROID_PACKAGE_NAME + ".STUMBLER_PREF";
|
||||
|
||||
@ -787,6 +789,12 @@ OnSharedPreferenceChangeListener
|
||||
preferences.removePreference(pref);
|
||||
i--;
|
||||
continue;
|
||||
} else if (PREFS_VOICE_INPUT_ENABLED.equals(key) &&
|
||||
(!AppConstants.NIGHTLY_BUILD || !VoiceRecognizerUtils.supportsVoiceRecognizer(getApplicationContext(), getResources().getString(R.string.voicesearch_prompt)))) {
|
||||
// Remove UI for voice input on non nightly builds.
|
||||
preferences.removePreference(pref);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Some Preference UI elements are not actually preferences,
|
||||
|
@ -33,6 +33,11 @@
|
||||
android:title="@string/pref_zoom_force_enabled"
|
||||
android:summary="@string/pref_zoom_force_enabled_summary" />
|
||||
|
||||
<CheckBoxPreference android:key="android.not_a_preference.voice_search_enabled"
|
||||
android:title="@string/pref_voice_input"
|
||||
android:summary="@string/pref_voice_input_summary"
|
||||
android:defaultValue="true"/>
|
||||
|
||||
<PreferenceCategory android:title="@string/pref_category_advanced">
|
||||
|
||||
<CheckBoxPreference
|
||||
|
@ -218,6 +218,8 @@
|
||||
<string name="pref_media_autoplay_enabled_summary">&pref_media_autoplay_enabled_summary;</string>
|
||||
<string name="pref_zoom_force_enabled">&pref_zoom_force_enabled;</string>
|
||||
<string name="pref_zoom_force_enabled_summary">&pref_zoom_force_enabled_summary;</string>
|
||||
<string name="pref_voice_input">&pref_voice_input;</string>
|
||||
<string name="pref_voice_input_summary">&pref_voice_input_summary;</string>
|
||||
<string name="pref_reflow_on_zoom">&pref_reflow_on_zoom4;</string>
|
||||
<string name="pref_restore">&pref_restore;</string>
|
||||
<string name="pref_restore_always">&pref_restore_always;</string>
|
||||
|
@ -12,11 +12,14 @@ import org.mozilla.gecko.CustomEditText;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.InputMethods;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.toolbar.BrowserToolbar.OnCommitListener;
|
||||
import org.mozilla.gecko.toolbar.BrowserToolbar.OnDismissListener;
|
||||
import org.mozilla.gecko.toolbar.BrowserToolbar.OnFilterListener;
|
||||
import org.mozilla.gecko.util.ActivityResultHandler;
|
||||
import org.mozilla.gecko.util.GamepadUtils;
|
||||
import org.mozilla.gecko.util.VoiceRecognizerUtils;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
@ -44,7 +47,6 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputConnectionWrapper;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.ViewParent;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -66,6 +68,7 @@ public class ToolbarEditText extends CustomEditText
|
||||
private OnCommitListener mCommitListener;
|
||||
private OnDismissListener mDismissListener;
|
||||
private OnFilterListener mFilterListener;
|
||||
private VoiceSearchOnTouchListener mVoiceOnTouchListener;
|
||||
|
||||
private ToolbarPrefs mPrefs;
|
||||
|
||||
@ -103,7 +106,6 @@ public class ToolbarEditText extends CustomEditText
|
||||
setOnKeyPreImeListener(new KeyPreImeListener());
|
||||
setOnSelectionChangedListener(new SelectionChangeListener());
|
||||
addTextChangedListener(new TextChangeListener());
|
||||
configureCompoundDrawables();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,6 +114,7 @@ public class ToolbarEditText extends CustomEditText
|
||||
|
||||
if (gainFocus) {
|
||||
resetAutocompleteState();
|
||||
configureCompoundDrawables();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -476,29 +479,32 @@ public class ToolbarEditText extends CustomEditText
|
||||
* Currently, only voice input.
|
||||
*/
|
||||
private void configureCompoundDrawables() {
|
||||
if (!AppConstants.NIGHTLY_BUILD || !supportsVoiceRecognizer()) {
|
||||
// Remove the mic button if we can't support the voice recognizer.
|
||||
if (AppConstants.NIGHTLY_BUILD && voiceIsEnabled()) {
|
||||
final Drawable micImg = getContext().getResources().getDrawable(R.drawable.ab_mic);
|
||||
setCompoundDrawablesWithIntrinsicBounds(null, null, micImg, null);
|
||||
|
||||
if (mVoiceOnTouchListener == null) {
|
||||
mVoiceOnTouchListener = new VoiceSearchOnTouchListener();
|
||||
}
|
||||
setOnTouchListener(mVoiceOnTouchListener);
|
||||
} else {
|
||||
// Remove the mic button
|
||||
setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||
return;
|
||||
setOnTouchListener(null);
|
||||
}
|
||||
setOnTouchListener(new VoiceSearchOnTouchListener());
|
||||
}
|
||||
|
||||
private boolean supportsVoiceRecognizer() {
|
||||
final Intent intent = createVoiceRecognizerIntent();
|
||||
return intent.resolveActivity(getContext().getPackageManager()) != null;
|
||||
}
|
||||
|
||||
private Intent createVoiceRecognizerIntent() {
|
||||
final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.voicesearch_prompt));
|
||||
return intent;
|
||||
private boolean voiceIsEnabled() {
|
||||
final boolean voiceIsSupported = VoiceRecognizerUtils.supportsVoiceRecognizer(getContext(), getResources().getString(R.string.voicesearch_prompt));
|
||||
if (!voiceIsSupported) {
|
||||
return false;
|
||||
}
|
||||
return GeckoSharedPrefs.forApp(getContext())
|
||||
.getBoolean(GeckoPreferences.PREFS_VOICE_INPUT_ENABLED, true);
|
||||
}
|
||||
|
||||
private void launchVoiceRecognizer() {
|
||||
final Intent intent = createVoiceRecognizerIntent();
|
||||
final Intent intent = VoiceRecognizerUtils.createVoiceRecognizerIntent(getResources().getString(R.string.voicesearch_prompt));
|
||||
|
||||
Activity activity = GeckoAppShell.getGeckoInterface().getActivity();
|
||||
ActivityHandlerHelper.startIntentForActivity(activity, intent, new ActivityResultHandler() {
|
||||
|
25
mobile/android/base/util/VoiceRecognizerUtils.java
Normal file
25
mobile/android/base/util/VoiceRecognizerUtils.java
Normal file
@ -0,0 +1,25 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.speech.RecognizerIntent;
|
||||
|
||||
public class VoiceRecognizerUtils {
|
||||
public static boolean supportsVoiceRecognizer(Context context, String prompt) {
|
||||
final Intent intent = createVoiceRecognizerIntent(prompt);
|
||||
return intent.resolveActivity(context.getPackageManager()) != null;
|
||||
}
|
||||
|
||||
public static Intent createVoiceRecognizerIntent(String prompt) {
|
||||
final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
|
||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
|
||||
return intent;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user