diff options
author | Yorke Lee <yorkelee@google.com> | 2013-07-31 15:39:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-07-31 15:39:04 +0000 |
commit | a72918aa52df4dbf6d69ace7f05cb046175e878e (patch) | |
tree | 310a991501b024b6af1080156857f7cd390603ac | |
parent | f00e1cfc307d37ac2cb693c701a3dcc2790b84c2 (diff) | |
parent | 191df33b47d28586652582499847ca3a2683cfcd (diff) |
Merge "Add voice search button in Dialer"
-rw-r--r-- | res/drawable-hdpi/ic_voice_search.png | bin | 0 -> 1271 bytes | |||
-rw-r--r-- | res/drawable-mdpi/ic_voice_search.png | bin | 0 -> 913 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_voice_search.png | bin | 0 -> 1603 bytes | |||
-rw-r--r-- | res/layout/new_dialtacts_activity.xml | 10 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/dialer/NewDialtactsActivity.java | 32 |
6 files changed, 44 insertions, 1 deletions
diff --git a/res/drawable-hdpi/ic_voice_search.png b/res/drawable-hdpi/ic_voice_search.png Binary files differnew file mode 100644 index 000000000..6caf4a43d --- /dev/null +++ b/res/drawable-hdpi/ic_voice_search.png diff --git a/res/drawable-mdpi/ic_voice_search.png b/res/drawable-mdpi/ic_voice_search.png Binary files differnew file mode 100644 index 000000000..e290f9277 --- /dev/null +++ b/res/drawable-mdpi/ic_voice_search.png diff --git a/res/drawable-xhdpi/ic_voice_search.png b/res/drawable-xhdpi/ic_voice_search.png Binary files differnew file mode 100644 index 000000000..614758188 --- /dev/null +++ b/res/drawable-xhdpi/ic_voice_search.png diff --git a/res/layout/new_dialtacts_activity.xml b/res/layout/new_dialtacts_activity.xml index 7845d0fef..b9d417b36 100644 --- a/res/layout/new_dialtacts_activity.xml +++ b/res/layout/new_dialtacts_activity.xml @@ -49,8 +49,18 @@ android:layout_width="40dp" android:padding="6dp" android:src="@drawable/ic_close_dk" + android:clickable="true" android:background="?android:attr/selectableItemBackground" android:visibility="gone" /> + <ImageView + android:id="@+id/voice_search_button" + android:layout_height="40dp" + android:layout_width="40dp" + android:padding="6dp" + android:src="@drawable/ic_voice_search" + android:clickable="true" + android:contentDescription="@string/description_start_voice_search" + android:background="?android:attr/selectableItemBackground" /> </LinearLayout> <FrameLayout android:layout_height="0dp" diff --git a/res/values/strings.xml b/res/values/strings.xml index 7d4a4d9b4..3845e2dd4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -452,6 +452,9 @@ --> <string name="description_call_log_unheard_voicemail">Unheard voicemail</string> + <!-- String describing the icon used to start a voice search --> + <string name="description_start_voice_search">Start voice search</string> + <!-- The string used to represent an unknown location for a phone number in the call log [CHAR LIMIT=3] --> <string name="call_log_empty_gecode">-</string> diff --git a/src/com/android/dialer/NewDialtactsActivity.java b/src/com/android/dialer/NewDialtactsActivity.java index 36e4a546a..61f2e41f3 100644 --- a/src/com/android/dialer/NewDialtactsActivity.java +++ b/src/com/android/dialer/NewDialtactsActivity.java @@ -38,6 +38,7 @@ import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Intents.UI; import android.provider.Settings; +import android.speech.RecognizerIntent; import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextUtils; @@ -74,6 +75,8 @@ import com.android.dialer.list.OnListFragmentScrolledListener; import com.android.dialer.list.SmartDialSearchFragment; import com.android.internal.telephony.ITelephony; +import java.util.ArrayList; + /** * The dialer tab's title is 'phone', a more common name (see strings.xml). * @@ -110,6 +113,8 @@ public class NewDialtactsActivity extends TransactionSafeActivity implements Vie private static final int SUBACTIVITY_ACCOUNT_FILTER = 1; + private static final int ACTIVITY_REQUEST_CODE_VOICE_SEARCH = 1; + private String mFilterText; /** @@ -146,6 +151,7 @@ public class NewDialtactsActivity extends TransactionSafeActivity implements Vie private boolean mInSearchUi; private View mSearchViewContainer; private View mSearchViewCloseButton; + private View mVoiceSearchButton; private EditText mSearchView; /** @@ -349,6 +355,10 @@ public class NewDialtactsActivity extends TransactionSafeActivity implements Vie mSearchView.setText(""); } break; + case R.id.voice_search_button: + final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); + startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH); + break; default: { Log.wtf(TAG, "Unexpected onClick event from " + view); break; @@ -356,6 +366,25 @@ public class NewDialtactsActivity extends TransactionSafeActivity implements Vie } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) { + if (resultCode == RESULT_OK) { + final ArrayList<String> matches = data.getStringArrayListExtra( + RecognizerIntent.EXTRA_RESULTS); + if (matches.size() > 0) { + final String match = matches.get(0); + mSearchView.setText(match); + } else { + Log.e(TAG, "Voice search - nothing heard"); + } + } else { + Log.e(TAG, "Voice search failed"); + } + } + super.onActivityResult(requestCode, resultCode, data); + } + private void showDialpadFragment(boolean animate) { final FragmentTransaction ft = getFragmentManager().beginTransaction(); if (animate) { @@ -377,8 +406,9 @@ public class NewDialtactsActivity extends TransactionSafeActivity implements Vie private void prepareSearchView() { mSearchViewContainer = findViewById(R.id.search_view_container); mSearchViewCloseButton = findViewById(R.id.search_close_button); - mSearchViewCloseButton.setClickable(true); mSearchViewCloseButton.setOnClickListener(this); + mVoiceSearchButton = findViewById(R.id.voice_search_button); + mVoiceSearchButton.setOnClickListener(this); mSearchView = (EditText) findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); |