Example #1
0
  public static VoiceRecognizer instantiateVoiceRecognizer(
      Context context, RecognizerApiListener listener, ImageButton voiceAddButton) {
    synchronized (VoiceRecognizer.class) {
      if (instance == null) {
        instance = new VoiceRecognizer();
      }
    }

    if (speechRecordingAvailable(context)) {
      if (instance.recognizerApi != null) {
        instance.recognizerApi.destroy();
      }

      instance.recognizerApi = new RecognizerApi(context);
      instance.recognizerApi.setListener(listener);
    } else {
      instance.voiceInputAssistant = new VoiceInputAssistant(voiceAddButton);
    }
    return instance;
  }
Example #2
0
 public void configureMicrophoneButton(final Fragment fragment, final int prompt) {
   if (Preferences.getBoolean(R.string.p_voiceInputEnabled, true)
       && VoiceRecognizer.voiceInputAvailable(ContextManager.getContext())) {
     voiceButton.setVisibility(View.VISIBLE);
     voiceButton.setOnClickListener(
         new OnClickListener() {
           @Override
           public void onClick(View v) {
             startVoiceRecognitionActivity(fragment, prompt);
           }
         });
   } else {
     voiceButton.setVisibility(View.GONE);
   }
 }
Example #3
0
  private void onVoiceInputStatusChanged(final Preference preference, boolean newValue) {
    if (!newValue) return;

    final Resources r = getResources();
    if (!VoiceRecognizer.voiceInputAvailable(this)) {
      if (AndroidUtilities.getSdkVersion() > 6) {
        DialogUtilities.okCancelDialog(
            this,
            r.getString(R.string.EPr_voiceInputInstall_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                voiceInputAssistant.showVoiceInputMarketSearch(
                    new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog1, int which1) {
                        ((CheckBoxPreference) preference).setChecked(false);
                      }
                    });
              }
            },
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      } else {
        DialogUtilities.okDialog(
            this,
            r.getString(R.string.EPr_voiceInputUnavailable_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog1, int which1) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      }
    }
  }
Example #4
0
 public void destroyRecognizerApi() {
   if (instance != null && instance.recognizerApi != null) {
     instance.recognizerApi.destroy();
     instance.recognizerApi = null;
   }
 }