diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-01-26 22:26:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-26 22:26:29 +0000 |
commit | e5f1e62682bec9f7bfa019b1820328fe98fa45bf (patch) | |
tree | 5e53c4dd5bbfcde694c8a177473d2e0c0f5edb65 /java/com/android/dialer/main/impl/MainSearchController.java | |
parent | f0d56cafa4c8284cd83f23e08877f6a5cf0c5fac (diff) | |
parent | 351cbcf3aed969db9b03fbcfc941cf3e086b0720 (diff) |
Merge changes If1ecc3b4,Ied1b369d,I4e492279,I30a4b7fe
* changes:
Disable phone icon for unknown numbers in NUI Voicemail
Pressing dial with an empty dialpad now queries the last number in NUI.
Disable seekbar user seeking
Add voice search to NUI.
Diffstat (limited to 'java/com/android/dialer/main/impl/MainSearchController.java')
-rw-r--r-- | java/com/android/dialer/main/impl/MainSearchController.java | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java index 041e32ed7..b01f80de6 100644 --- a/java/com/android/dialer/main/impl/MainSearchController.java +++ b/java/com/android/dialer/main/impl/MainSearchController.java @@ -17,16 +17,22 @@ package com.android.dialer.main.impl; import android.app.FragmentTransaction; +import android.content.ActivityNotFoundException; +import android.content.Intent; import android.os.Bundle; +import android.speech.RecognizerIntent; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; +import android.widget.Toast; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.constants.ActivityRequestCodes; import com.android.dialer.dialpadview.DialpadFragment; import com.android.dialer.dialpadview.DialpadFragment.DialpadListener; import com.android.dialer.dialpadview.DialpadFragment.OnDialpadQueryChangedListener; @@ -36,6 +42,7 @@ import com.android.dialer.searchfragment.list.NewSearchFragment; import com.android.dialer.searchfragment.list.NewSearchFragment.SearchFragmentListener; import com.android.dialer.util.ViewUtil; import com.google.common.base.Optional; +import java.util.ArrayList; /** * Search controller for handling all the logic related to entering and exiting the search UI. @@ -255,8 +262,12 @@ final class MainSearchController implements SearchBarListener { */ @Override public void onSearchBarClicked() { + openSearch(Optional.absent()); + } + + private void openSearch(Optional<String> query) { fab.hide(); - toolbar.expand(/* animate=*/ true, Optional.absent()); + toolbar.expand(/* animate=*/ true, query); toolbar.showKeyboard(); hideBottomNav(); @@ -294,7 +305,28 @@ final class MainSearchController implements SearchBarListener { } @Override - public void onVoiceButtonClicked(VoiceSearchResultCallback voiceSearchResultCallback) {} + public void onVoiceButtonClicked(VoiceSearchResultCallback voiceSearchResultCallback) { + try { + Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + mainActivity.startActivityForResult(voiceIntent, ActivityRequestCodes.DIALTACTS_VOICE_SEARCH); + } catch (ActivityNotFoundException e) { + Toast.makeText(mainActivity, R.string.voice_search_not_available, Toast.LENGTH_SHORT).show(); + } + } + + public void onVoiceResults(int resultCode, Intent data) { + if (resultCode == AppCompatActivity.RESULT_OK) { + ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); + if (matches.size() > 0) { + LogUtil.i("MainSearchController.onVoiceResults", "voice search - match found"); + openSearch(Optional.of(matches.get(0))); + } else { + LogUtil.i("MainSearchController.onVoiceResults", "voice search - nothing heard"); + } + } else { + LogUtil.e("MainSearchController.onVoiceResults", "voice search failed"); + } + } @Override public void openSettings() {} |