diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-11-18 18:27:33 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-11-18 18:27:33 +0000 |
commit | 6da64281890bf79e78a19c7dc363570bbc13f0f2 (patch) | |
tree | 2e00a0a7ba6e87cdbed46d3f4137597d7ee236fb /java/com/android | |
parent | f8785b93d38b0e65b5a49500231dc26457792cc9 (diff) | |
parent | 5a2b1b2e7cbe8fd5c402ffe0386920b3a63340fa (diff) |
Merge "Added place voice call search action to regular search."
Diffstat (limited to 'java/com/android')
11 files changed, 57 insertions, 399 deletions
diff --git a/java/com/android/contacts/common/testing/InjectedServices.java b/java/com/android/contacts/common/testing/InjectedServices.java deleted file mode 100644 index 5ab5e5feb..000000000 --- a/java/com/android/contacts/common/testing/InjectedServices.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.contacts.common.testing; - -import android.content.ContentResolver; -import android.content.SharedPreferences; -import android.util.ArrayMap; -import java.util.Map; - -/** - * A mechanism for providing alternative (mock) services to the application while running tests. - * Activities, Services and the Application should check with this class to see if a particular - * service has been overridden. - */ -public class InjectedServices { - - private ContentResolver mContentResolver; - private SharedPreferences mSharedPreferences; - private Map<String, Object> mSystemServices; - - public ContentResolver getContentResolver() { - return mContentResolver; - } - - public void setContentResolver(ContentResolver contentResolver) { - this.mContentResolver = contentResolver; - } - - public SharedPreferences getSharedPreferences() { - return mSharedPreferences; - } - - public void setSharedPreferences(SharedPreferences sharedPreferences) { - this.mSharedPreferences = sharedPreferences; - } - - public void setSystemService(String name, Object service) { - if (mSystemServices == null) { - mSystemServices = new ArrayMap<>(); - } - - mSystemServices.put(name, service); - } - - public Object getSystemService(String name) { - if (mSystemServices != null) { - return mSystemServices.get(name); - } - return null; - } -} diff --git a/java/com/android/dialer/phonelookup/testing/FakePhoneLookup.java b/java/com/android/dialer/phonelookup/testing/FakePhoneLookup.java deleted file mode 100644 index 853116f9a..000000000 --- a/java/com/android/dialer/phonelookup/testing/FakePhoneLookup.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ -package com.android.dialer.phonelookup.testing; - -import android.support.annotation.NonNull; -import android.telecom.Call; -import com.android.dialer.DialerPhoneNumber; -import com.android.dialer.phonelookup.PhoneLookup; -import com.android.dialer.phonelookup.PhoneLookupInfo; -import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; - -/** Fake implementation of {@link PhoneLookup} used for unit tests. */ -@AutoValue -public abstract class FakePhoneLookup implements PhoneLookup { - - abstract PhoneLookupInfo lookupResult(); - - abstract ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> bulkUpdateResult(); - - abstract boolean isDirtyResult(); - - public static Builder builder() { - return new AutoValue_FakePhoneLookup.Builder() - .setLookupResult(PhoneLookupInfo.getDefaultInstance()) - .setBulkUpdateResult(ImmutableMap.of()) - .setIsDirtyResult(false); - } - - /** Builder. */ - @AutoValue.Builder - public abstract static class Builder { - - public abstract Builder setLookupResult(PhoneLookupInfo phoneLookupInfo); - - public abstract Builder setBulkUpdateResult( - ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> map); - - public abstract Builder setIsDirtyResult(boolean isDirty); - - public abstract FakePhoneLookup build(); - } - - @Override - public ListenableFuture<PhoneLookupInfo> lookup(@NonNull Call call) { - SettableFuture<PhoneLookupInfo> future = SettableFuture.create(); - future.set(lookupResult()); - return future; - } - - @Override - public ListenableFuture<Boolean> isDirty( - ImmutableSet<DialerPhoneNumber> phoneNumbers, long lastModified) { - SettableFuture<Boolean> future = SettableFuture.create(); - future.set(isDirtyResult()); - return future; - } - - @Override - public ListenableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> bulkUpdate( - ImmutableMap<DialerPhoneNumber, PhoneLookupInfo> existingInfoMap, long lastModified) { - SettableFuture<ImmutableMap<DialerPhoneNumber, PhoneLookupInfo>> future = - SettableFuture.create(); - future.set(bulkUpdateResult()); - return future; - } -} diff --git a/java/com/android/dialer/precall/testing/TestPreCallModule.java b/java/com/android/dialer/precall/testing/TestPreCallModule.java deleted file mode 100644 index b777de890..000000000 --- a/java/com/android/dialer/precall/testing/TestPreCallModule.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.precall.testing; - -import android.content.Context; -import android.content.Intent; -import android.support.annotation.NonNull; -import com.android.dialer.callintent.CallIntentBuilder; -import com.android.dialer.precall.PreCall; -import com.android.dialer.precall.PreCallAction; -import com.google.common.collect.ImmutableList; -import dagger.Module; -import dagger.Provides; -import javax.inject.Singleton; - -/** Provides test implementation of {@link PreCall} */ -@Module -public class TestPreCallModule { - private static PreCall preCall = new StubPreCall(); - - public static void setPreCall(PreCall preCall) { - TestPreCallModule.preCall = preCall; - } - - @Provides - @Singleton - public static PreCall providePreCall() { - return preCall; - } - - private static class StubPreCall implements PreCall { - - @NonNull - @Override - public ImmutableList<PreCallAction> getActions() { - return ImmutableList.of(); - } - - @NonNull - @Override - public Intent buildIntent(Context context, CallIntentBuilder builder) { - return builder.build(); - } - } -} diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index 93263ceb2..df2714690 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -142,7 +142,7 @@ public final class NewSearchFragment extends Fragment LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_search, parent, false); adapter = new SearchAdapter(getContext(), new SearchCursorManager(), this); - adapter.setQuery(query, rawNumber); + adapter.setQuery(query, rawNumber, callInitiationType); adapter.setSearchActions(getActions()); adapter.setZeroSuggestVisible(getArguments().getBoolean(KEY_SHOW_ZERO_SUGGEST)); emptyContentView = view.findViewById(R.id.empty_view); @@ -260,7 +260,7 @@ public final class NewSearchFragment extends Fragment this.query = query; this.callInitiationType = callInitiationType; if (adapter != null) { - adapter.setQuery(query, rawNumber); + adapter.setQuery(query, rawNumber, callInitiationType); adapter.setSearchActions(getActions()); adapter.setZeroSuggestVisible(isRegularSearch()); loadNearbyPlacesCursor(); @@ -445,19 +445,27 @@ public final class NewSearchFragment extends Fragment * the list of supported actions, see {@link SearchActionViewHolder.Action}. */ private List<Integer> getActions() { - boolean nonDialableQueryInRegularSearch = - isRegularSearch() && !PhoneNumberUtils.isGlobalPhoneNumber(query); + boolean isDialableNumber = PhoneNumberUtils.isGlobalPhoneNumber(query); + boolean nonDialableQueryInRegularSearch = isRegularSearch() && !isDialableNumber; if (TextUtils.isEmpty(query) || query.length() == 1 || nonDialableQueryInRegularSearch) { return Collections.emptyList(); } List<Integer> actions = new ArrayList<>(); - actions.add(Action.CREATE_NEW_CONTACT); - actions.add(Action.ADD_TO_CONTACT); + if (!isRegularSearch()) { + actions.add(Action.CREATE_NEW_CONTACT); + actions.add(Action.ADD_TO_CONTACT); + } + + if (isRegularSearch() && isDialableNumber) { + actions.add(Action.MAKE_VOICE_CALL); + } + actions.add(Action.SEND_SMS); if (CallUtil.isVideoEnabled(getContext())) { actions.add(Action.MAKE_VILTE_CALL); } + return actions; } diff --git a/java/com/android/dialer/searchfragment/list/SearchActionViewHolder.java b/java/com/android/dialer/searchfragment/list/SearchActionViewHolder.java index b557a8259..76c71d6ac 100644 --- a/java/com/android/dialer/searchfragment/list/SearchActionViewHolder.java +++ b/java/com/android/dialer/searchfragment/list/SearchActionViewHolder.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.Intent; import android.support.annotation.IntDef; import android.support.annotation.StringRes; +import android.support.annotation.VisibleForTesting; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.View.OnClickListener; @@ -49,7 +50,8 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On Action.CREATE_NEW_CONTACT, Action.ADD_TO_CONTACT, Action.SEND_SMS, - Action.MAKE_VILTE_CALL + Action.MAKE_VILTE_CALL, + Action.MAKE_VOICE_CALL }) @interface Action { int INVALID = 0; @@ -61,6 +63,8 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On int SEND_SMS = 3; /** Attempts to make a VILTE call to the number. */ int MAKE_VILTE_CALL = 4; + /** Places a voice call to the number. */ + int MAKE_VOICE_CALL = 5; } private final Context context; @@ -70,6 +74,7 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On private @Action int action; private int position; private String query; + private CallInitiationType.Type callInitiationType; SearchActionViewHolder(View view) { super(view); @@ -79,10 +84,11 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On view.setOnClickListener(this); } - void setAction(@Action int action, int position, String query) { + void setAction(@Action int action, int position, String query, CallInitiationType.Type type) { this.action = action; this.position = position; this.query = query; + this.callInitiationType = type; switch (action) { case Action.ADD_TO_CONTACT: actionText.setText(R.string.search_shortcut_add_to_contact); @@ -100,12 +106,23 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On actionText.setText(R.string.search_shortcut_send_sms_message); actionImage.setImageResource(R.drawable.quantum_ic_message_vd_theme_24); break; + case Action.MAKE_VOICE_CALL: + actionText.setText(context.getString(R.string.search_shortcut_make_voice_call, query)); + actionImage.setImageResource(R.drawable.quantum_ic_phone_vd_theme_24); + break; case Action.INVALID: default: throw Assert.createIllegalStateFailException("Invalid action: " + action); + } } + @VisibleForTesting + @Action + int getAction() { + return action; + } + @Override public void onClick(View v) { switch (action) { @@ -123,14 +140,14 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On break; case Action.MAKE_VILTE_CALL: - CallSpecificAppData callSpecificAppData = + CallSpecificAppData videoCallSpecificAppData = CallSpecificAppData.newBuilder() - .setCallInitiationType(CallInitiationType.Type.DIALPAD) + .setCallInitiationType(callInitiationType) .setPositionOfSelectedSearchResult(position) .setCharactersInSearchString(query.length()) .build(); PreCall.start( - context, new CallIntentBuilder(query, callSpecificAppData).setIsVideoCall(true)); + context, new CallIntentBuilder(query, videoCallSpecificAppData).setIsVideoCall(true)); break; case Action.SEND_SMS: @@ -138,6 +155,16 @@ final class SearchActionViewHolder extends RecyclerView.ViewHolder implements On DialerUtils.startActivityWithErrorToast(context, intent); break; + case Action.MAKE_VOICE_CALL: + CallSpecificAppData voiceCallSpecificAppData = + CallSpecificAppData.newBuilder() + .setCallInitiationType(callInitiationType) + .setPositionOfSelectedSearchResult(position) + .setCharactersInSearchString(query.length()) + .build(); + PreCall.start(context, new CallIntentBuilder(query, voiceCallSpecificAppData)); + break; + case Action.INVALID: default: throw Assert.createIllegalStateFailException("Invalid action: " + action); diff --git a/java/com/android/dialer/searchfragment/list/SearchAdapter.java b/java/com/android/dialer/searchfragment/list/SearchAdapter.java index 17cab6db1..1681097bf 100644 --- a/java/com/android/dialer/searchfragment/list/SearchAdapter.java +++ b/java/com/android/dialer/searchfragment/list/SearchAdapter.java @@ -26,6 +26,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.common.Assert; import com.android.dialer.searchfragment.common.RowClickListener; import com.android.dialer.searchfragment.common.SearchCursor; @@ -47,6 +48,7 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> { // Raw query number from dialpad, which may contain special character such as "+". This is used // for actions to add contact or send sms. private String rawNumber; + private CallInitiationType.Type callInitiationType; private OnClickListener allowClickListener; private OnClickListener dismissClickListener; private RowClickListener rowClickListener; @@ -113,7 +115,8 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> { .setAction( searchCursorManager.getSearchAction(position), position, - TextUtils.isEmpty(rawNumber) ? query : rawNumber); + TextUtils.isEmpty(rawNumber) ? query : rawNumber, + callInitiationType); } else if (holder instanceof LocationPermissionViewHolder) { // No-op } else { @@ -143,16 +146,17 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> { /** * @param visible If true and query is empty, the adapter won't show any list elements. - * @see #setQuery(String) + * @see #setQuery(String, String, CallInitiationType.Type) * @see #getItemCount() */ public void setZeroSuggestVisible(boolean visible) { showZeroSuggest = visible; } - public void setQuery(String query, @Nullable String rawNumber) { + public void setQuery(String query, @Nullable String rawNumber, CallInitiationType.Type type) { this.query = query; this.rawNumber = rawNumber; + this.callInitiationType = type; if (searchCursorManager.setQuery(query)) { notifyDataSetChanged(); } diff --git a/java/com/android/dialer/searchfragment/list/res/values/strings.xml b/java/com/android/dialer/searchfragment/list/res/values/strings.xml index ea238fc92..26685a657 100644 --- a/java/com/android/dialer/searchfragment/list/res/values/strings.xml +++ b/java/com/android/dialer/searchfragment/list/res/values/strings.xml @@ -14,7 +14,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> -<resources> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- Shown as a prompt to turn on contacts permissions to allow contact search [CHAR LIMIT=NONE]. See 2424710404207193826 for current translation. --> <string name="new_permission_no_search">To search your contacts, turn on the Contacts permissions.</string> @@ -31,4 +31,7 @@ <!-- Shortcut item used to make a video call directly from search. [CHAR LIMIT=25] --> <string name="search_shortcut_make_video_call">Make video call</string> + + <!-- Shortcut item used to make a voice call directly from search. [CHAR LIMIT=25] --> + <string name="search_shortcut_make_voice_call">Call <xliff:g id="phone_number">%1$s</xliff:g></string> </resources> diff --git a/java/com/android/dialer/searchfragment/testing/TestCursorSchema.java b/java/com/android/dialer/searchfragment/testing/TestCursorSchema.java deleted file mode 100644 index 9117f72cd..000000000 --- a/java/com/android/dialer/searchfragment/testing/TestCursorSchema.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.searchfragment.testing; - -import android.provider.ContactsContract.Data; - -/** Testing class containing cp2 cursor testing utilities. */ -public final class TestCursorSchema { - - /** - * If new rows are added to {@link - * com.android.dialer.searchfragment.common.Projections#CP2_PROJECTION}, this schema should be - * updated. - */ - // TODO(67909522): remove these extra columns and remove all references to "Phone." - public static final String[] SCHEMA = - new String[] { - Data._ID, // 0 - "data2", // 1 Phone Type - "data3", // 2 Phone Label - "data1", // 3 Phone Number, Organization Company - Data.DISPLAY_NAME_PRIMARY, // 4 - Data.PHOTO_ID, // 5 - Data.PHOTO_THUMBNAIL_URI, // 6 - Data.LOOKUP_KEY, // 7 - Data.CARRIER_PRESENCE, // 8 - Data.CONTACT_ID, // 9 - Data.MIMETYPE, // 10 - Data.SORT_KEY_PRIMARY, // 11 - "company_name", // 12, no constant because Organization.COMPANY.equals("data1") - "nick_name" // 13, no constant because Nickname.NAME.equals("data1") - }; -} diff --git a/java/com/android/dialer/searchfragment/testing/TestSearchCursor.java b/java/com/android/dialer/searchfragment/testing/TestSearchCursor.java deleted file mode 100644 index 7e6299eac..000000000 --- a/java/com/android/dialer/searchfragment/testing/TestSearchCursor.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.searchfragment.testing; - -import android.database.Cursor; -import android.database.MatrixCursor; -import android.database.MergeCursor; -import android.support.annotation.Nullable; -import com.android.dialer.searchfragment.common.SearchCursor; - -/** {@link SearchCursor} implementation useful for testing with a header inserted at position 0. */ -public final class TestSearchCursor extends MergeCursor implements SearchCursor { - - public static TestSearchCursor newInstance(Cursor cursor, String header) { - MatrixCursor headerRow = new MatrixCursor(HEADER_PROJECTION); - headerRow.addRow(new String[] {header}); - return new TestSearchCursor(new Cursor[] {headerRow, cursor}); - } - - private TestSearchCursor(Cursor[] cursors) { - super(cursors); - } - - @Override - public boolean isHeader() { - return isFirst(); - } - - @Override - public boolean updateQuery(@Nullable String query) { - return false; - } - - @Override - public long getDirectoryId() { - return 0; - } -} diff --git a/java/com/android/incallui/maps/testing/TestMapsModule.java b/java/com/android/incallui/maps/testing/TestMapsModule.java deleted file mode 100644 index bb096812b..000000000 --- a/java/com/android/incallui/maps/testing/TestMapsModule.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.incallui.maps.testing; - -import android.support.annotation.Nullable; -import com.android.incallui.maps.Maps; -import dagger.Module; -import dagger.Provides; - -/** This module provides a instance of maps for testing. */ -@Module -public final class TestMapsModule { - - @Nullable private static Maps maps; - - public static void setMaps(@Nullable Maps maps) { - TestMapsModule.maps = maps; - } - - @Provides - static Maps getMaps() { - return maps; - } - - private TestMapsModule() {} -} diff --git a/java/com/android/voicemail/testing/TestVoicemailModule.java b/java/com/android/voicemail/testing/TestVoicemailModule.java deleted file mode 100644 index 8b7b34c62..000000000 --- a/java/com/android/voicemail/testing/TestVoicemailModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.voicemail.testing; - -import com.android.voicemail.VoicemailClient; -import dagger.Module; -import dagger.Provides; -import javax.inject.Singleton; - -/** Used to set a mock voicemail client for unit tests. */ -@Module -public final class TestVoicemailModule { - private static VoicemailClient voicemailClient; - - public static void setVoicemailClient(VoicemailClient voicemailClient) { - TestVoicemailModule.voicemailClient = voicemailClient; - } - - @Provides - @Singleton - public static VoicemailClient provideVoicemailClient() { - return voicemailClient; - } -} |