Example usage for android.speech RecognizerIntent LANGUAGE_MODEL_WEB_SEARCH

List of usage examples for android.speech RecognizerIntent LANGUAGE_MODEL_WEB_SEARCH

Introduction

In this page you can find the example usage for android.speech RecognizerIntent LANGUAGE_MODEL_WEB_SEARCH.

Prototype

String LANGUAGE_MODEL_WEB_SEARCH

To view the source code for android.speech RecognizerIntent LANGUAGE_MODEL_WEB_SEARCH.

Click Source Link

Document

Use a language model based on web search terms.

Usage

From source file:onion.chat.MainActivity.java

private void listen() {
    //inform();/*from w  ww  . j  a  va2  s .co  m*/
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0) {
        Toast.makeText(this, "Voice recognizer not present", Toast.LENGTH_SHORT).show();
    } else {
        try {
            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

            intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());

            intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Its Ur's");

            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
        } catch (Exception e) {
            String toSpeak = "Oops your device doesn't support Voice recognition";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        }
    }
}

From source file:android.support.v7ox.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mDrawableManager = AppCompatDrawableManager.get();

    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView,
            defStyleAttr, 0);//from ww w  . ja  v a2s  . c o m

    final LayoutInflater inflater = LayoutInflater.from(context);
    final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view);
    inflater.inflate(layoutResId, this, true);

    mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
    mSearchSrcTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.search_edit_frame);
    mSearchPlate = findViewById(R.id.search_plate);
    mSubmitArea = findViewById(R.id.submit_area);
    mSearchButton = (ImageView) findViewById(R.id.search_button);
    mGoButton = (ImageView) findViewById(R.id.search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
    mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn);
    mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon);

    // Set up icons and backgrounds.
    mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground));
    mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground));
    mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));
    mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon));
    mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon));
    mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon));
    mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));

    mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon);

    // Extract dropdown layout resource IDs for later use.
    mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout,
            R.layout.abc_search_dropdown_item_icons_2line);
    mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0);

    mSearchButton.setOnClickListener(mOnClickListener);
    mCloseButton.setOnClickListener(mOnClickListener);
    mGoButton.setOnClickListener(mOnClickListener);
    mVoiceButton.setOnClickListener(mOnClickListener);
    mSearchSrcTextView.setOnClickListener(mOnClickListener);

    mSearchSrcTextView.addTextChangedListener(mTextWatcher);
    mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener);
    mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener);
    mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener);
    mSearchSrcTextView.setOnKeyListener(mTextKeyListener);

    // Inform any listener of focus changes
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus);
            }
        }
    });
    setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));

    final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }

    mDefaultQueryHint = a.getText(R.styleable.SearchView_defaultQueryHint);
    mQueryHint = a.getText(R.styleable.SearchView_queryHint);

    final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }

    final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    boolean focusable = true;
    focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable);
    setFocusable(focusable);

    a.recycle();

    // Save voice intent for later queries/launching
    mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
    mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            addOnLayoutChangeListenerToDropDownAnchorSDK11();
        } else {
            addOnLayoutChangeListenerToDropDownAnchorBase();
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:android.support.v7.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView,
            defStyleAttr, 0);//from ww w. ja v a 2s  . c  o  m
    // Keep the TintManager in case we need it later
    mTintManager = a.getTintManager();

    final LayoutInflater inflater = LayoutInflater.from(context);
    final int layoutResId = a.getResourceId(R.styleable.SearchView_layout, R.layout.abc_search_view);
    inflater.inflate(layoutResId, this, true);

    mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
    mSearchSrcTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.search_edit_frame);
    mSearchPlate = findViewById(R.id.search_plate);
    mSubmitArea = findViewById(R.id.submit_area);
    mSearchButton = (ImageView) findViewById(R.id.search_button);
    mGoButton = (ImageView) findViewById(R.id.search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
    mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn);
    mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon);

    // Set up icons and backgrounds.
    mSearchPlate.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_queryBackground));
    mSubmitArea.setBackgroundDrawable(a.getDrawable(R.styleable.SearchView_submitBackground));
    mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));
    mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon));
    mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon));
    mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon));
    mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));

    mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon);

    // Extract dropdown layout resource IDs for later use.
    mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout,
            R.layout.abc_search_dropdown_item_icons_2line);
    mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0);

    mSearchButton.setOnClickListener(mOnClickListener);
    mCloseButton.setOnClickListener(mOnClickListener);
    mGoButton.setOnClickListener(mOnClickListener);
    mVoiceButton.setOnClickListener(mOnClickListener);
    mSearchSrcTextView.setOnClickListener(mOnClickListener);

    mSearchSrcTextView.addTextChangedListener(mTextWatcher);
    mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener);
    mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener);
    mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener);
    mSearchSrcTextView.setOnKeyListener(mTextKeyListener);

    // Inform any listener of focus changes
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus);
            }
        }
    });
    setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));

    final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }

    final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }

    final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }

    final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    boolean focusable = true;
    focusable = a.getBoolean(R.styleable.SearchView_android_focusable, focusable);
    setFocusable(focusable);

    a.recycle();

    // Save voice intent for later queries/launching
    mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
    mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            addOnLayoutChangeListenerToDropDownAnchorSDK11();
        } else {
            addOnLayoutChangeListenerToDropDownAnchorBase();
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:com.example.navigationsearchview.NavigationSearchView.java

public NavigationSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SearchView,
            defStyleAttr, 0);/* w ww  .  j  a  v a2 s. c o m*/
    // Keep the TintManager in case we need it later
    mTintManager = a.getTintManager();

    final LayoutInflater inflater = LayoutInflater.from(context);
    final int layoutResId = com.example.navigationsearchview.R.layout.abc_search_view;
    inflater.inflate(layoutResId, this, true);// original true

    mSearchSrcTextView = (SearchAutoComplete) findViewById(R.id.search_src_text);
    mSearchSrcTextView.setSearchView(this);

    mSearchEditFrame = findViewById(R.id.search_edit_frame);
    mSearchPlate = findViewById(R.id.search_plate);
    mSubmitArea = findViewById(R.id.submit_area);
    mSearchButton = (ImageView) findViewById(R.id.search_button);
    mGoButton = (ImageView) findViewById(R.id.search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
    mVoiceButton = (ImageView) findViewById(R.id.search_voice_btn);
    mCollapsedIcon = (ImageView) findViewById(R.id.search_mag_icon);
    // next and previous
    mNextButton = (ImageView) findViewById(R.id.search_next_btn);
    mPrevButton = (ImageView) findViewById(R.id.search_previous_btn);

    // Set up icons and backgrounds.
    mSearchPlate.setBackground(a.getDrawable((R.styleable.SearchView_queryBackground)));
    mSubmitArea.setBackground(a.getDrawable((R.styleable.SearchView_submitBackground)));
    mSearchButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));
    mGoButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_goIcon));
    mCloseButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_closeIcon));
    mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.SearchView_voiceIcon));
    mCollapsedIcon.setImageDrawable(a.getDrawable(R.styleable.SearchView_searchIcon));

    // next and previous
    mNextButton.setImageResource(R.drawable.arrow_right);
    mPrevButton.setImageResource(R.drawable.arrow_left);
    mSearchHintIcon = a.getDrawable(R.styleable.SearchView_iconifiedByDefault);

    // Extract dropdown layout resource IDs for later use.
    mSuggestionRowLayout = a.getResourceId(R.styleable.SearchView_suggestionRowLayout,
            R.layout.abc_search_dropdown_item_icons_2line);
    mSuggestionCommitIconResId = a.getResourceId(R.styleable.SearchView_commitIcon, 0);

    mSearchButton.setOnClickListener(mOnClickListener);
    mCloseButton.setOnClickListener(mOnClickListener);
    mGoButton.setOnClickListener(mOnClickListener);
    mVoiceButton.setOnClickListener(mOnClickListener);
    mSearchSrcTextView.setOnClickListener(mOnClickListener);
    // next and previous button
    mNextButton.setOnClickListener(mOnClickListener);
    mPrevButton.setOnClickListener(mOnClickListener);

    mSearchSrcTextView.addTextChangedListener(mTextWatcher);
    mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener);
    mSearchSrcTextView.setOnItemClickListener(mOnItemClickListener);
    mSearchSrcTextView.setOnItemSelectedListener(mOnItemSelectedListener);
    mSearchSrcTextView.setOnKeyListener(mTextKeyListener);

    // Inform any listener of focus changes
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(NavigationSearchView.this, hasFocus);
            }
        }
    });
    setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));

    final int maxWidth = a.getDimensionPixelSize(R.styleable.SearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }

    final CharSequence queryHint = a.getText(R.styleable.SearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }

    final int imeOptions = a.getInt(R.styleable.SearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }

    final int inputType = a.getInt(R.styleable.SearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    boolean focusable = true;
    focusable = a.getBoolean(0, focusable);
    setFocusable(focusable);

    a.recycle();

    // Save voice intent for later queries/launching
    mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
    mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    mDropDownAnchor = findViewById(mSearchSrcTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            addOnLayoutChangeListenerToDropDownAnchorSDK11();
        } else {
            addOnLayoutChangeListenerToDropDownAnchorBase();
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}

From source file:conversandroid.RichASR.java

/**
 * Reads the values for the language model and the maximum number of recognition results
 * from the GUI//from   w  w w  .  j a v  a  2s .  c om
 */
private void setRecognitionParams() {
    String numResults = ((EditText) findViewById(R.id.numResults_editText)).getText().toString();

    //Converts String into int, if it is not possible, it uses the default value
    try {
        numberRecoResults = Integer.parseInt(numResults);
    } catch (Exception e) {
        numberRecoResults = DEFAULT_NUMBER_RESULTS;
    }
    //If the number is <= 0, it uses the default value
    if (numberRecoResults <= 0)
        numberRecoResults = DEFAULT_NUMBER_RESULTS;

    RadioGroup radioG = (RadioGroup) findViewById(R.id.langModel_radioGroup);
    switch (radioG.getCheckedRadioButtonId()) {
    case R.id.langModelFree_radio:
        languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
        break;
    case R.id.langModelWeb_radio:
        languageModel = RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH;
        break;
    default:
        languageModel = DEFAULT_LANG_MODEL;
        break;
    }
}

From source file:root.gast.playground.speech.SpeechRecognitionPlay.java

/**
 * create the {@link RecognizerIntent} based on the many preferences
 *///from  w ww  .jav  a 2 s .c o  m
private Intent readRecognizerIntentFromPreferences() {
    Intent intentToSend;

    //web search handling
    boolean isWebSearchAction = preferences.getBoolean(this, R.string.pref_websearch,
            R.string.pref_websearch_default);

    boolean isHandsFreeAction = preferences.getBoolean(this, R.string.pref_handsfree,
            R.string.pref_handsfree_default);

    if (isWebSearchAction) {
        intentToSend = RecognizerIntentFactory.getWebSearchRecognizeIntent();
        final boolean ADD_ORIGIN = true;
        if (ADD_ORIGIN && Build.VERSION.SDK_INT >= 14) {
            intentToSend.putExtra(RecognizerIntent.EXTRA_ORIGIN, true);
        }
    } else {
        if (isHandsFreeAction && Build.VERSION.SDK_INT >= 16) {
            intentToSend = RecognizerIntentFactory.getHandsFreeRecognizeIntent();
        } else {
            intentToSend = RecognizerIntentFactory.getBlankRecognizeIntent();
        }
    }

    //language model
    boolean isFreeFormModel = preferences.getBoolean(this, R.string.pref_languagemodel,
            R.string.pref_languagemodel_default);
    if (isFreeFormModel) {
        intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    } else {
        intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    }

    //common extras
    String language = preferences.getString(getResources().getString(R.string.pref_language),
            getResources().getString(R.string.pref_language_default));
    intentToSend.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    String prompt = getResources().getString(R.string.speech_prompt) + ": "
            + whatYouAreTryingToSay.getText().toString();
    intentToSend.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    intentToSend.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,
            preferences.getInt(this, R.string.pref_maxresults, R.string.pref_maxresults_default));
    intentToSend.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,
            preferences.getBoolean(this, R.string.pref_partial, R.string.pref_partial_default));

    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,
            R.string.pref_complete_silence, R.string.pref_complete_silence_default, intentToSend);
    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS,
            R.string.pref_minimum_input_length, R.string.pref_minimum_input_length_default, intentToSend);
    setIfValueSpecified(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,
            R.string.pref_possibly_complete_silence_length,
            R.string.pref_possibly_complete_silence_length_default, intentToSend);

    //pendingIntent handling
    boolean doPending = preferences.getBoolean(this, R.string.pref_withpendingintent,
            R.string.pref_withpendingintent);
    if (doPending) {
        Intent pendingIntentSource = new Intent(this, SpeechRecognitionResultsActivity.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0, pendingIntentSource, 0);

        Bundle extraInfoBundle = new Bundle();
        // pass in what you are trying to say so the results activity can
        // show it
        extraInfoBundle.putString(SpeechRecognitionResultsActivity.WHAT_YOU_ARE_TRYING_TO_SAY_INTENT_INPUT,
                whatYouAreTryingToSay.getText().toString());
        // set the variables in the intent this is sending
        intentToSend.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pi);
        intentToSend.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, extraInfoBundle);
    }

    Log.d(TAG, "sending recognizer intent: " + intentToSend.getExtras().toString());
    return intentToSend;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

public SearchView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.c = context;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO) {
        throw new IllegalStateException("SearchView is API 8+ only.");
    }/*from  w  w w .  j  a  v  a2s . c  o  m*/

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(getResources().getIdentifier("abs__search_view", "layout", context.getPackageName()), this,
            true);
    // inflater.inflate(R.layout.abs__search_view, this, true);

    mSearchButton = findViewById(
            getResources().getIdentifier("abs__search_button", "id", context.getPackageName()));
    // mSearchButton = findViewById(R.id.abs__search_button);
    mQueryTextView = (SearchAutoComplete) findViewById(
            getResources().getIdentifier("abs__search_src_text", "id", context.getPackageName()));
    // mQueryTextView = (SearchAutoComplete)
    // findViewById(R.id.abs__search_src_text);
    mQueryTextView.setSearchView(this);

    mSearchEditFrame = findViewById(
            getResources().getIdentifier("abs__search_edit_frame", "id", context.getPackageName()));
    // mSearchEditFrame = findViewById(R.id.abs__search_edit_frame);
    mSearchPlate = findViewById(
            getResources().getIdentifier("abs__search_plate", "id", context.getPackageName()));
    // mSearchPlate = findViewById(R.id.abs__search_plate);
    mSubmitArea = findViewById(
            getResources().getIdentifier("abs__submit_area", "id", context.getPackageName()));
    // mSubmitArea = findViewById(R.id.abs__submit_area);
    mSubmitButton = findViewById(
            getResources().getIdentifier("abs__search_go_btn", "id", context.getPackageName()));
    // mSubmitButton = findViewById(R.id.abs__search_go_btn);
    mCloseButton = (ImageView) findViewById(
            getResources().getIdentifier("abs__search_close_btn", "id", context.getPackageName()));
    // mCloseButton = (ImageView) findViewById(R.id.abs__search_close_btn);
    mVoiceButton = findViewById(
            getResources().getIdentifier("abs__search_voice_btn", "id", context.getPackageName()));
    // mVoiceButton = findViewById(R.id.abs__search_voice_btn);
    mSearchHintIcon = (ImageView) findViewById(
            getResources().getIdentifier("abs__search_mag_icon", "id", context.getPackageName()));
    // mSearchHintIcon = (ImageView)
    // findViewById(R.id.abs__search_mag_icon);

    mSearchButton.setOnClickListener(mOnClickListener);
    mCloseButton.setOnClickListener(mOnClickListener);
    mSubmitButton.setOnClickListener(mOnClickListener);
    mVoiceButton.setOnClickListener(mOnClickListener);
    mQueryTextView.setOnClickListener(mOnClickListener);

    mQueryTextView.addTextChangedListener(mTextWatcher);
    mQueryTextView.setOnEditorActionListener(mOnEditorActionListener);
    mQueryTextView.setOnItemClickListener(mOnItemClickListener);
    mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener);
    mQueryTextView.setOnKeyListener(mTextKeyListener);
    // Inform any listener of focus changes
    mQueryTextView.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(SearchView.this, hasFocus);
            }
        }
    });

    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] {
                    getResources().getIdentifier("SherlockSearchView", "styleable", context.getPackageName()) },
            0, 0);
    // R.styleable.SherlockSearchView, 0, 0);
    setIconifiedByDefault(a.getBoolean(getResources().getIdentifier("SherlockSearchView_iconifiedByDefault",
            "styleable", context.getPackageName()), true));
    // R.styleable.SherlockSearchView_iconifiedByDefault, true));
    int maxWidth = a.getDimensionPixelSize(getResources().getIdentifier("SherlockSearchView_android_maxWidth",
            "styleable", context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_maxWidth, -1);
    if (maxWidth != -1) {
        setMaxWidth(maxWidth);
    }
    CharSequence queryHint = a.getText(getResources().getIdentifier("SherlockSearchView_queryHint", "styleable",
            context.getPackageName()));
    // .getText(R.styleable.SherlockSearchView_queryHint);
    if (!TextUtils.isEmpty(queryHint)) {
        setQueryHint(queryHint);
    }
    int imeOptions = a.getInt(getResources().getIdentifier("SherlockSearchView_android_imeOptions", "styleable",
            context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_imeOptions, -1);
    if (imeOptions != -1) {
        setImeOptions(imeOptions);
    }
    int inputType = a.getInt(getResources().getIdentifier("SherlockSearchView_android_inputType", "styleable",
            context.getPackageName()), -1);
    // R.styleable.SherlockSearchView_android_inputType, -1);
    if (inputType != -1) {
        setInputType(inputType);
    }

    a.recycle();

    boolean focusable = true;

    a = context.obtainStyledAttributes(attrs,
            new int[] { getResources().getIdentifier("SherlockView", "styleable", context.getPackageName()) },
            0,
            // a = context.obtainStyledAttributes(attrs,
            // R.styleable.SherlockView, 0,
            0);
    focusable = a.getBoolean(
            getResources().getIdentifier("SherlockView_android_focusable", "styleable",
                    context.getPackageName()),
            // focusable =
            // a.getBoolean(R.styleable.SherlockView_android_focusable,
            focusable);
    a.recycle();
    setFocusable(focusable);

    // Save voice intent for later queries/launching
    mVoiceWebSearchIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
    mVoiceWebSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mVoiceWebSearchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    mDropDownAnchor = findViewById(mQueryTextView.getDropDownAnchor());
    if (mDropDownAnchor != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            mDropDownAnchor.addOnLayoutChangeListener(new OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
                        int oldTop, int oldRight, int oldBottom) {
                    adjustDropDownSizeAndPosition();
                }
            });
        } else {
            mDropDownAnchor.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            adjustDropDownSizeAndPosition();
                        }
                    });
        }
    }

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}