Example usage for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL

List of usage examples for android.speech RecognizerIntent EXTRA_LANGUAGE_MODEL

Introduction

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

Prototype

String EXTRA_LANGUAGE_MODEL

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

Click Source Link

Document

Informs the recognizer which speech model to prefer when performing #ACTION_RECOGNIZE_SPEECH .

Usage

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

/***
 * Start the voice input activity manually
 *///from  w ww  . java  2  s.  co m
public void startVoiceRecognition() {
    if (isMicEnabled()) {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "pt-BR");

        if (mContainerActivity != null) {
            mContainerActivity.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
        } else if (mContainerFragment != null) {
            mContainerFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
        } else if (mContainerSupportFragment != null) {
            mContainerSupportFragment.startActivityForResult(intent, VOICE_RECOGNITION_CODE);
        }
    }
}

From source file:org.botlibre.sdk.activity.MicConfiguration.java

public void googleListening(View v) {
    txt.setText("Status: ON");
    setMicIcon(true, false);//from w ww. ja v a 2s. c o  m
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language);
    try {
        startActivityForResult(intent, 1);
        editTextForGoogle.setText("");
    } catch (ActivityNotFoundException a) {
        Toast t = Toast.makeText(getApplicationContext(), "Your device doesn't support Speech to Text",
                Toast.LENGTH_SHORT);
        t.show();
    }
}

From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java

private void setupFloatingSearch() {
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override//from w ww  .jav  a 2  s  . c o  m
        public void onHomeClicked() {

        }
    });

    mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override
        public void onSearchTextChanged(String oldQuery, final String newQuery) {

            if (!oldQuery.equals("") && newQuery.equals("")) {
                mSearchView.clearSuggestions();
            } else {

                //this shows the top left circular progress
                //you can call it where ever you want, but
                //it makes sense to do it when loading something in
                //the background.
                mSearchView.showProgress();

                //simulates a query call to a data source
                //with a new query.
                NumberDataHelper.findSuggestions(getApplicationContext(), newQuery, 5,
                        FIND_SUGGESTION_SIMULATED_DELAY, new NumberDataHelper.OnFindSuggestionsListener() {

                            @Override
                            public void onResults(List<NumberSuggestion> results) {

                                //this will swap the data and
                                //render the collapse/expand animations as necessary
                                mSearchView.swapSuggestions(results);

                                //let the users know that the background
                                //process has completed
                                mSearchView.hideProgress();
                            }
                        });
            }

            Log.d(TAG, "onSearchTextChanged()");
        }
    });

    mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
        @Override
        public void onSuggestionClicked(final SearchSuggestion searchSuggestion) {

            NumberSuggestion numberSuggestion = (NumberSuggestion) searchSuggestion;
            NumberDataHelper.findNumbers(getApplicationContext(), numberSuggestion.getWord(),
                    new NumberDataHelper.OnFindNumberListener() {

                        @Override
                        public void onResults(List<NumberWrapper> results) {
                            mSearchResultsAdapter.swapData(results);
                        }

                    });
            Log.d(TAG, "onSuggestionClicked()");

            mLastQuery = searchSuggestion.getWord();
        }

        @Override
        public void onSearchAction(String query) {
            mLastQuery = query;

            NumberDataHelper.findNumbers(getApplicationContext(), query,
                    new NumberDataHelper.OnFindNumberListener() {

                        @Override
                        public void onResults(List<NumberWrapper> results) {
                            mSearchResultsAdapter.swapData(results);
                        }

                    });
            Log.d(TAG, "onSearchAction()");
        }
    });

    mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
        @Override
        public void onFocus() {

            //show suggestions when search bar gains focus (typically history suggestions)
            //                NumberDataHelper cdh = new NumberDataHelper();
            //                cdh.setContext(getApplicationContext());
            mSearchView.swapSuggestions(NumberDataHelper.getHistory(getApplicationContext(), 5));

            Log.d(TAG, "onFocus()");
        }

        @Override
        public void onFocusCleared() {

            //set the title of the bar so that when focus is returned a new query begins
            mSearchView.setSearchBarTitle(mLastQuery);

            //you can also set setSearchText(...) to make keep the query there when not focused and when focus returns
            //mSearchView.setSearchText(searchSuggestion.getWord());

            Log.d(TAG, "onFocusCleared()");
        }
    });

    //handle menu clicks the same way as you would
    //in a regular activity
    mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
        @Override
        public void onActionMenuItemSelected(MenuItem item) {

            if (item.getItemId() == R.id.action_refresh_list) {

                /*mIsDarkSearchTheme = true;
                        
                //demonstrate setting colors for items
                mSearchView.setBackgroundColor(Color.parseColor("#787878"));
                mSearchView.setViewTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setHintTextColor(Color.parseColor("#e9e9e9"));
                mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9"));
                mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));
                mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9"));
                mSearchView.setDividerColor(Color.parseColor("#BEBEBE"));
                mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));*/
                populateCardList();
            } else if (item.getItemId() == R.id.action_voice_rec) {
                Intent voiceRecognize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                        getClass().getPackage().getName());
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                        RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG");
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the letter in ARABIC...");
                /*voiceRecognize.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); */
                voiceRecognize.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100);
                startActivityForResult(voiceRecognize, REQUEST_CODE);
            } else {

                //just print action
                //Toast.makeText(getApplicationContext().getApplicationContext(), item.getTitle(),
                //        Toast.LENGTH_SHORT).show();
            }

        }
    });

    //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome"
    mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() {
        @Override
        public void onHomeClicked() {
            startActivity(new Intent(NumberViewActivity.this, MainActivity.class)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
            Log.d(TAG, "onHomeClicked()");
        }
    });

    /*
     * Here you have access to the left icon and the text of a given suggestion
     * item after as it is bound to the suggestion list. You can utilize this
     * callback to change some properties of the left icon and the text. For example, you
     * can load the left icon images using your favorite image loading library, or change text color.
     *
     *
     * Important:
     * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different
     * items in the list.
     */
    mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {
        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView,
                SearchSuggestion item, int itemPosition) {
            NumberSuggestion numberSuggestion = (NumberSuggestion) item;

            String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000";
            String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878";

            if (numberSuggestion.getIsHistory()) {
                leftIcon.setImageDrawable(
                        ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null));

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
            } else {
                leftIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(),
                        R.drawable.ic_lightbulb_outline_black_24dp, null));

                Util.setIconColor(leftIcon, Color.parseColor(textColor));
                leftIcon.setAlpha(.36f);
                /*leftIcon.setAlpha(0.0f);
                leftIcon.setImageDrawable(null);*/
            }

            textView.setTextColor(Color.parseColor(textColor));
            String text = numberSuggestion.getWord().replaceFirst(mSearchView.getQuery(),
                    "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>");
            textView.setText(Html.fromHtml(text));
        }

    });

    //listen for when suggestion list expands/shrinks in order to move down/up the
    //search results list
    mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() {
        @Override
        public void onSuggestionsListHeightChanged(float newHeight) {
            mSearchResultsList.setTranslationY(newHeight);
        }
    });
}

From source file:com.google.sample.cast.refplayer.chatting.MainActivity.java

private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getString(R.string.message_to_cast));
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:com.mhennessy.mapfly.MainActivity.java

public void setMapLocationBasedOnSpeech() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.mhennessy.mapfly");

    SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer(this.getApplicationContext());

    // Stop flying so that messages can be displayed to the user without
    // being overwritten by pitch/roll info.
    setFlyingEnabled(false);//from  w ww  .  ja  v  a  2s.c o  m
    RecognitionListener listener = new RecognitionListener() {
        @Override
        public void onResults(Bundle results) {
            ArrayList<String> voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            if (voiceResults == null) {
                Log.e(TAG, "No voice results");
            } else {
                Log.d(TAG, "Printing matches: ");
                for (String match : voiceResults) {
                    Log.d(TAG, match);
                }
                String bestMatch = voiceResults.get(0);
                setMapLocation(bestMatch);
            }
        }

        @Override
        public void onReadyForSpeech(Bundle params) {
            setTitle("Say something!");
            Log.d(TAG, "Ready for speech");
        }

        @Override
        public void onError(int error) {
            setTitle("Speach Error");
            Log.d(TAG, "Error listening for speech: " + error);
        }

        @Override
        public void onBeginningOfSpeech() {
            Log.d(TAG, "Speech starting");
        }

        @Override
        public void onBufferReceived(byte[] buffer) {
            // no-op
        }

        @Override
        public void onEndOfSpeech() {
            // no-op
        }

        @Override
        public void onEvent(int eventType, Bundle params) {
            // no-op
        }

        @Override
        public void onPartialResults(Bundle partialResults) {
            // no-op
        }

        @Override
        public void onRmsChanged(float rmsdB) {
            // no-op
        }
    };
    recognizer.setRecognitionListener(listener);
    recognizer.startListening(intent);
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java

private void speechToText() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, Locale.getDefault());

    try {/*from  w w  w.j  ava 2s.c  o m*/
        startActivityForResult(intent, RequestCode.TEXT_TO_SPEECH);
    } catch (ActivityNotFoundException a) {
        AlfrescoNotificationManager.getInstance(getActivity()).showToast(R.string.file_editor_error_speech);
    }
}

From source file:org.bishoph.oxdemo.OXDemo.java

public void startVoiceRecognitionActivity() {
    Log.v("OXDemo", "startVoiceRecognitionActivity init...");
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
    if (activities.size() > 0) {
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo");
        startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
        Log.v("OXDemo", "...done");
    } else {/*from   ww  w  . java2 s.c o  m*/
        // createTask(folder_id,
        // "Auto creation  "+getSimpleRandomString());
        Log.v("OXDemo", "No voice recognition!");
    }
}

From source file:org.botlibre.sdk.activity.ChatActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    // Remove flag button if a single bot app.
    if (MainActivity.launchType == LaunchType.Bot) {
        //findViewById(R.id.flagButton).setVisibility(View.GONE);
    }//from  w  w w .ja va2  s. c om

    //permission required.
    ActivityCompat.requestPermissions(ChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, 1);

    //set/Save the current volume from the device.
    setStreamVolume();
    //Music Volume is Enabled.
    muteMicBeep(false);

    //For "scream" issue
    micLastStat = MainActivity.listenInBackground;

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    this.instance = (InstanceConfig) MainActivity.instance;
    if (this.instance == null) {
        return;
    }
    /*if (MainActivity.showAds) {
         AdView mAdView = (AdView) findViewById(R.id.adView);
         AdRequest adRequest = new AdRequest.Builder().build();
         mAdView.loadAd(adRequest);
    } else {
       AdView mAdView = (AdView) findViewById(R.id.adView);
       mAdView.setVisibility(View.GONE);
    }*/

    setTitle(this.instance.name);
    ((TextView) findViewById(R.id.title)).setText(this.instance.name);
    HttpGetImageAction.fetchImage(this, this.instance.avatar, findViewById(R.id.icon));
    ttsInit = false;
    tts = new TextToSpeech(this, this);

    if (!MainActivity.handsFreeSpeech) {
        setMicIcon(false, false);
    } else if (!MainActivity.listenInBackground) {
        setMicIcon(false, false);
    }

    //Last time will be saved for the MIC.
    if (MainActivity.listenInBackground && MainActivity.handsFreeSpeech) {
        microphoneThread(thread);
    }

    speech = SpeechRecognizer.createSpeechRecognizer(this);
    speech.setRecognitionListener(this);
    //scrollVie added and stuff
    scrollView = findViewById(R.id.chatList);
    menuMLayout = (LinearLayout) findViewById(R.id.menuMLayout);
    chatCLayout = (LinearLayout) findViewById(R.id.chatCLayout);
    responseLayout = (LinearLayout) findViewById(R.id.responseLayout);
    chatToolBar = (LinearLayout) findViewById(R.id.chatToolBar);

    videoView = (VideoView) findViewById(R.id.videoView);
    resetVideoErrorListener();
    videoError = false;

    imageView = (ImageView) findViewById(R.id.imageView);
    videoLayout = findViewById(R.id.videoLayout);

    textView = (EditText) findViewById(R.id.messageText);
    textView.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            submitChat();
            return false;
        }
    });

    if (MainActivity.translate) {
        findViewById(R.id.yandex).setVisibility(View.VISIBLE);
    } else {
        findViewById(R.id.yandex).setVisibility(View.GONE);
    }

    Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin);
    emoteSpin.setAdapter(
            new EmoteSpinAdapter(this, R.layout.emote_list, Arrays.asList(EmotionalState.values())));

    ListView list = (ListView) findViewById(R.id.chatList);
    list.setAdapter(new ChatListAdapter(this, R.layout.chat_list, this.messages));
    list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);

    ImageButton button = (ImageButton) findViewById(R.id.speakButton);
    button.setOnClickListener(new View.OnClickListener() {
        @TargetApi(23)
        @Override
        public void onClick(View v) {
            if (MainActivity.handsFreeSpeech) {
                //set the current volume to the setting.
                setStreamVolume();
                //if its ON Or OFF - Switching back and forth 
                MainActivity.listenInBackground = !MainActivity.listenInBackground;

                //saving the boolean data of MainActivity.listeningInBackground
                SharedPreferences.Editor cookies = MainActivity.current.getPreferences(Context.MODE_PRIVATE)
                        .edit();
                cookies.putBoolean("listenInBackground", MainActivity.listenInBackground);
                cookies.commit();
                if (MainActivity.listenInBackground) {
                    micLastStat = true;
                    try {
                        microphoneThread(thread);
                    } catch (Exception ignore) {
                    }
                    beginListening();
                } else {
                    micLastStat = false;
                    microphoneThread(thread);
                    stopListening();
                }
            } else {
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language);
                try {
                    startActivityForResult(intent, RESULT_SPEECH);
                    textView.setText("");
                } catch (ActivityNotFoundException a) {
                    Toast t = Toast.makeText(getApplicationContext(),
                            "Your device doesn't support Speech to Text", Toast.LENGTH_SHORT);
                    t.show();
                }
            }
        }
    });

    //adding functionality on clicking the image  
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (stateLayouts == 4) {
                stateLayouts = 0;
            }
            switch (stateLayouts) {
            case 0:
                scrollView.setVisibility(View.VISIBLE);
                chatCLayout.setVisibility(View.VISIBLE);
                menuMLayout.setVisibility(View.VISIBLE);
                responseLayout.setVisibility(View.VISIBLE);
                chatToolBar.setVisibility(View.VISIBLE);
                break;
            case 1:
                scrollView.setVisibility(View.GONE);
                break;
            case 2:
                responseLayout.setVisibility(View.GONE);
                chatToolBar.setVisibility(View.GONE);
                break;
            case 3:
                menuMLayout.setVisibility(View.GONE);
                chatCLayout.setVisibility(View.GONE);
                break;
            }
            stateLayouts++;
        }
    });

    //adding functionality on clicking the image 
    videoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (stateLayouts == 4) {
                stateLayouts = 0;
            }
            switch (stateLayouts) {
            case 0:
                scrollView.setVisibility(View.VISIBLE);
                chatCLayout.setVisibility(View.VISIBLE);
                menuMLayout.setVisibility(View.VISIBLE);
                responseLayout.setVisibility(View.VISIBLE);
                chatToolBar.setVisibility(View.VISIBLE);
                break;
            case 1:
                scrollView.setVisibility(View.GONE);
                break;
            case 2:
                responseLayout.setVisibility(View.GONE);
                chatToolBar.setVisibility(View.GONE);
                break;
            case 3:
                menuMLayout.setVisibility(View.GONE);
                chatCLayout.setVisibility(View.GONE);
                break;
            }
            stateLayouts++;
        }
    });

    GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTapEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                boolean isVideo = !MainActivity.disableVideo && !videoError && response != null
                        && response.isVideo();
                View imageView = findViewById(R.id.imageView);
                View videoLayout = findViewById(R.id.videoLayout);
                if (imageView.getVisibility() == View.VISIBLE) {
                    imageView.setVisibility(View.GONE);
                } else if (!isVideo) {
                    imageView.setVisibility(View.VISIBLE);
                }
                if (videoLayout.getVisibility() == View.VISIBLE) {
                    videoLayout.setVisibility(View.GONE);
                } else if (isVideo) {
                    videoLayout.setVisibility(View.VISIBLE);
                }
                return true;
            }
            return false;
        }
    };
    final GestureDetector detector = new GestureDetector(this, listener);
    findViewById(R.id.chatList).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    });

    listener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTapEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                View avatarLayout = findViewById(R.id.avatarLayout);
                if (avatarLayout.getVisibility() == View.VISIBLE) {
                    avatarLayout.setVisibility(View.GONE);
                } else {
                    avatarLayout.setVisibility(View.VISIBLE);
                }
                return true;
            }
            return false;
        }
    };
    final GestureDetector detector2 = new GestureDetector(this, listener);
    /*findViewById(R.id.responseText).setOnTouchListener(new View.OnTouchListener() {         
       @Override
       public boolean onTouch(View v, MotionEvent event) {
    return detector2.onTouchEvent(event);
       }
    });*/
    WebView responseView = (WebView) findViewById(R.id.responseText);
    responseView.getSettings().setJavaScriptEnabled(true);
    responseView.getSettings().setDomStorageEnabled(true);
    responseView.addJavascriptInterface(new WebAppInterface(this), "Android");

    findViewById(R.id.responseImageView).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            View avatarLayout = findViewById(R.id.avatarLayout);
            if (avatarLayout.getVisibility() == View.VISIBLE) {
                avatarLayout.setVisibility(View.GONE);
            } else {
                avatarLayout.setVisibility(View.VISIBLE);
            }
        }
    });

    HttpGetImageAction.fetchImage(this, instance.avatar, this.imageView);
    HttpGetImageAction.fetchImage(this, instance.avatar, (ImageView) findViewById(R.id.responseImageView));

    final ChatConfig config = new ChatConfig();
    config.instance = instance.id;
    config.avatar = this.avatarId;
    if (MainActivity.translate && MainActivity.voice != null) {
        config.language = MainActivity.voice.language;
    }
    if (MainActivity.disableVideo) {
        config.avatarFormat = "image";
    } else {
        config.avatarFormat = MainActivity.webm ? "webm" : "mp4";
    }
    config.avatarHD = MainActivity.hd;
    config.speak = !MainActivity.deviceVoice;
    // This is required because of a bug in TextToSpeech that prevents onInit being called if an AsynchTask is called...
    Thread thread1 = new Thread() {
        public void run() {
            for (int count = 0; count < 5; count++) {
                if (ttsInit) {
                    break;
                }
                try {
                    Thread.sleep(1000);
                } catch (Exception exception) {
                }
            }
            HttpAction action = new HttpChatAction(ChatActivity.this, config);
            action.execute();
        }
    };
    thread1.start();
}

From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java

private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, getResources().getString(R.string.voice_prompt));
    startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
}

From source file:com.delexus.imitationzhihu.MySearchView.java

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

    final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.MySearchView,
            defStyleAttr, 0);/*from   w  w  w.java2  s  .  co  m*/

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.search_view, this);

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

    mNavigationButton = (ImageView) findViewById(R.id.my_search_button);
    mGoButton = (ImageView) findViewById(R.id.my_search_go_btn);
    mCloseButton = (ImageView) findViewById(R.id.my_search_close_btn);
    mVoiceButton = (ImageView) findViewById(R.id.my_search_voice_btn);

    // Set up icons and backgrounds.
    mNavigationButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_navigateIcon));
    mGoButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_goIcon));
    mCloseButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_closeIcon));
    mVoiceButton.setImageDrawable(a.getDrawable(R.styleable.MySearchView_voiceIcon));

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

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

    mSearchSrcTextView.addTextChangedListener(mTextWatcher);
    mSearchSrcTextView.setOnEditorActionListener(mOnEditorActionListener);
    mSearchSrcTextView.setOnKeyListener(mTextKeyListener);

    // Inform any listener of focus changes
    mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (mOnQueryTextFocusChangeListener != null) {
                mOnQueryTextFocusChangeListener.onFocusChange(MySearchView.this, hasFocus);
            }
        }
    });
    setIconifiedByDefault(a.getBoolean(R.styleable.MySearchView_iconifiedByDefault, true));

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

    mDefaultQueryHint = a.getText(R.styleable.MySearchView_defaultQueryHint);
    mQueryHint = a.getText(R.styleable.MySearchView_queryHint);

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

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

    boolean focusable = true;
    focusable = a.getBoolean(R.styleable.MySearchView_android_inputType, 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);

    updateViewsVisibility(mIconifiedByDefault);
    updateQueryHint();
}