diff options
author | calderwoodra <calderwoodra@google.com> | 2017-10-25 15:01:37 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-10-26 16:39:14 +0000 |
commit | 32257fdc92016ed2f76e62af8425937284e0d61b (patch) | |
tree | b9ce398cfbe4c8ba07272916ca0a05bf14035a8b /java | |
parent | 2827dd135647dab6f414f06b38f80537bff9a58a (diff) |
Search fragment now closes after placing a call.
Moved SearchContactViewHolder listener logic from SearchAdapter
to SearchFragment to make it easier to close search after placing a call.
Bug: 68201142
Test: existing + DialtactsActivityTest
PiperOrigin-RevId: 173454972
Change-Id: Ib5715d0f427d62344641b4bf841d34145fc3f65e
Diffstat (limited to 'java')
3 files changed, 93 insertions, 84 deletions
diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index b9ca67f62..b5ec20246 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -124,7 +124,7 @@ import com.android.dialer.performancereport.PerformanceReport; import com.android.dialer.postcall.PostCall; import com.android.dialer.proguard.UsedByReflection; import com.android.dialer.searchfragment.list.NewSearchFragment; -import com.android.dialer.searchfragment.list.NewSearchFragment.SearchFragmentListTouchListener; +import com.android.dialer.searchfragment.list.NewSearchFragment.SearchFragmentListener; import com.android.dialer.simulator.Simulator; import com.android.dialer.simulator.SimulatorComponent; import com.android.dialer.smartdial.SmartDialNameMatcher; @@ -164,7 +164,7 @@ public class DialtactsActivity extends TransactionSafeActivity PhoneNumberInteraction.DisambigDialogDismissedListener, ActivityCompat.OnRequestPermissionsResultCallback, DialpadListener, - SearchFragmentListTouchListener { + SearchFragmentListener { public static final boolean DEBUG = false; @VisibleForTesting public static final String TAG_DIALPAD_FRAGMENT = "dialpad"; @@ -1664,6 +1664,14 @@ public class DialtactsActivity extends TransactionSafeActivity return false; } + @Override + public void onCallPlaced() { + if (mIsDialpadShown) { + hideDialpadFragment(false, true); + } + exitSearchUi(); + } + /** Popup menu accessible from the search bar */ protected class OptionsPopupMenu extends PopupMenu { diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index ef1b4fc19..c200b946c 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -20,6 +20,7 @@ import static android.Manifest.permission.ACCESS_FINE_LOCATION; import android.app.Fragment; import android.app.LoaderManager.LoaderCallbacks; +import android.content.Intent; import android.content.Loader; import android.content.pm.PackageManager; import android.database.Cursor; @@ -31,6 +32,7 @@ import android.support.annotation.VisibleForTesting; import android.support.v13.app.FragmentCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.telephony.TelephonyManager; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -42,13 +44,23 @@ import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; import com.android.contacts.common.extensions.PhoneDirectoryExtenderAccessor; import com.android.dialer.animation.AnimUtils; +import com.android.dialer.assisteddialing.ConcreteCreator; +import com.android.dialer.callcomposer.CallComposerActivity; import com.android.dialer.callintent.CallInitiationType; +import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.callintent.CallSpecificAppData; import com.android.dialer.common.Assert; import com.android.dialer.common.FragmentUtils; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.ThreadUtil; +import com.android.dialer.constants.ActivityRequestCodes; +import com.android.dialer.dialercontact.DialerContact; +import com.android.dialer.duo.DuoComponent; import com.android.dialer.enrichedcall.EnrichedCallComponent; import com.android.dialer.enrichedcall.EnrichedCallManager.CapabilitiesListener; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; +import com.android.dialer.searchfragment.common.RowClickListener; import com.android.dialer.searchfragment.common.SearchCursor; import com.android.dialer.searchfragment.cp2.SearchContactsCursorLoader; import com.android.dialer.searchfragment.list.SearchActionViewHolder.Action; @@ -72,7 +84,8 @@ public final class NewSearchFragment extends Fragment implements LoaderCallbacks<Cursor>, OnEmptyViewActionButtonClickedListener, CapabilitiesListener, - OnTouchListener { + OnTouchListener, + RowClickListener { // Since some of our queries can generate network requests, we should delay them until the user // stops typing to prevent generating too much network traffic. @@ -124,9 +137,8 @@ public final class NewSearchFragment extends Fragment public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_search, parent, false); - adapter = new SearchAdapter(getActivity(), new SearchCursorManager()); + adapter = new SearchAdapter(getContext(), new SearchCursorManager(), this); adapter.setQuery(query); - adapter.setCallInitiationType(callInitiationType); adapter.setSearchActions(getActions()); adapter.setZeroSuggestVisible(getArguments().getBoolean(KEY_SHOW_ZERO_SUGGEST)); emptyContentView = view.findViewById(R.id.empty_view); @@ -241,7 +253,6 @@ public final class NewSearchFragment extends Fragment this.callInitiationType = callInitiationType; if (adapter != null) { adapter.setQuery(query); - adapter.setCallInitiationType(callInitiationType); adapter.setSearchActions(getActions()); adapter.setZeroSuggestVisible(isRegularSearch()); loadNearbyPlacesCursor(); @@ -449,12 +460,59 @@ public final class NewSearchFragment extends Fragment if (event.getAction() == MotionEvent.ACTION_UP) { v.performClick(); } - return FragmentUtils.getParentUnsafe(this, SearchFragmentListTouchListener.class) + return FragmentUtils.getParentUnsafe(this, SearchFragmentListener.class) .onSearchListTouch(event); } - /** Callback to {@link NewSearchFragment}'s parent to notify when the list is touched. */ - public interface SearchFragmentListTouchListener { + @Override + public void placeVoiceCall(String phoneNumber, int ranking) { + placeCall(phoneNumber, ranking, false, true); + } + + @Override + public void placeVideoCall(String phoneNumber, int ranking) { + placeCall(phoneNumber, ranking, true, false); + } + + private void placeCall( + String phoneNumber, int position, boolean isVideoCall, boolean allowAssistedDial) { + CallSpecificAppData callSpecificAppData = + CallSpecificAppData.newBuilder() + .setCallInitiationType(callInitiationType) + .setPositionOfSelectedSearchResult(position) + .setCharactersInSearchString(query == null ? 0 : query.length()) + .setAllowAssistedDialing(allowAssistedDial) + .build(); + Intent intent = + new CallIntentBuilder(phoneNumber, callSpecificAppData) + .setIsVideoCall(isVideoCall) + .setAllowAssistedDial( + allowAssistedDial, + ConcreteCreator.createNewAssistedDialingMediator( + getContext().getSystemService(TelephonyManager.class), + getContext().getApplicationContext())) + .build(); + DialerUtils.startActivityWithErrorToast(getActivity(), intent); + FragmentUtils.getParentUnsafe(this, SearchFragmentListener.class).onCallPlaced(); + } + + @Override + public void placeDuoCall(String phoneNumber) { + Logger.get(getContext()) + .logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_SEARCH); + Intent intent = DuoComponent.get(getContext()).getDuo().getIntent(getContext(), phoneNumber); + getActivity().startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_DUO); + FragmentUtils.getParentUnsafe(this, SearchFragmentListener.class).onCallPlaced(); + } + + @Override + public void openCallAndShare(DialerContact contact) { + Intent intent = CallComposerActivity.newIntent(getContext(), contact); + DialerUtils.startActivityWithErrorToast(getContext(), intent); + } + + /** Callback to {@link NewSearchFragment}'s parent to be notified of important events. */ + public interface SearchFragmentListener { /** * Called when the list view in {@link NewSearchFragment} is touched. @@ -462,5 +520,8 @@ public final class NewSearchFragment extends Fragment * @see OnTouchListener#onTouch(View, MotionEvent) */ boolean onSearchListTouch(MotionEvent event); + + /** Called when a call is placed from the search fragment. */ + void onCallPlaced(); } } diff --git a/java/com/android/dialer/searchfragment/list/SearchAdapter.java b/java/com/android/dialer/searchfragment/list/SearchAdapter.java index 949c2a2c5..dc78953b5 100644 --- a/java/com/android/dialer/searchfragment/list/SearchAdapter.java +++ b/java/com/android/dialer/searchfragment/list/SearchAdapter.java @@ -16,55 +16,43 @@ package com.android.dialer.searchfragment.list; -import android.app.Activity; -import android.content.Intent; +import android.content.Context; import android.support.annotation.VisibleForTesting; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; -import android.telephony.TelephonyManager; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; -import com.android.dialer.assisteddialing.ConcreteCreator; -import com.android.dialer.callcomposer.CallComposerActivity; -import com.android.dialer.callintent.CallInitiationType; -import com.android.dialer.callintent.CallIntentBuilder; -import com.android.dialer.callintent.CallSpecificAppData; import com.android.dialer.common.Assert; -import com.android.dialer.constants.ActivityRequestCodes; -import com.android.dialer.dialercontact.DialerContact; -import com.android.dialer.duo.DuoComponent; -import com.android.dialer.logging.DialerImpression; -import com.android.dialer.logging.Logger; import com.android.dialer.searchfragment.common.RowClickListener; import com.android.dialer.searchfragment.common.SearchCursor; import com.android.dialer.searchfragment.cp2.SearchContactViewHolder; import com.android.dialer.searchfragment.list.SearchCursorManager.RowType; import com.android.dialer.searchfragment.nearbyplaces.NearbyPlaceViewHolder; import com.android.dialer.searchfragment.remote.RemoteContactViewHolder; -import com.android.dialer.util.DialerUtils; import java.util.List; /** RecyclerView adapter for {@link NewSearchFragment}. */ @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) -public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> - implements RowClickListener { +public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> { private final SearchCursorManager searchCursorManager; - private final Activity activity; + private final Context context; private boolean showZeroSuggest; private String query; - private CallInitiationType.Type callInitiationType = CallInitiationType.Type.UNKNOWN_INITIATION; private OnClickListener allowClickListener; private OnClickListener dismissClickListener; + private RowClickListener rowClickListener; @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) - public SearchAdapter(Activity activity, SearchCursorManager searchCursorManager) { - this.activity = activity; + public SearchAdapter( + Context context, SearchCursorManager searchCursorManager, RowClickListener rowClickListener) { + this.context = context; this.searchCursorManager = searchCursorManager; + this.rowClickListener = rowClickListener; } @Override @@ -72,24 +60,25 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> switch (rowType) { case RowType.CONTACT_ROW: return new SearchContactViewHolder( - LayoutInflater.from(activity).inflate(R.layout.search_contact_row, root, false), this); + LayoutInflater.from(context).inflate(R.layout.search_contact_row, root, false), + rowClickListener); case RowType.NEARBY_PLACES_ROW: return new NearbyPlaceViewHolder( - LayoutInflater.from(activity).inflate(R.layout.search_contact_row, root, false)); + LayoutInflater.from(context).inflate(R.layout.search_contact_row, root, false)); case RowType.CONTACT_HEADER: case RowType.DIRECTORY_HEADER: case RowType.NEARBY_PLACES_HEADER: return new HeaderViewHolder( - LayoutInflater.from(activity).inflate(R.layout.header_layout, root, false)); + LayoutInflater.from(context).inflate(R.layout.header_layout, root, false)); case RowType.DIRECTORY_ROW: return new RemoteContactViewHolder( - LayoutInflater.from(activity).inflate(R.layout.search_contact_row, root, false)); + LayoutInflater.from(context).inflate(R.layout.search_contact_row, root, false)); case RowType.SEARCH_ACTION: return new SearchActionViewHolder( - LayoutInflater.from(activity).inflate(R.layout.search_action_layout, root, false)); + LayoutInflater.from(context).inflate(R.layout.search_action_layout, root, false)); case RowType.LOCATION_REQUEST: return new LocationPermissionViewHolder( - LayoutInflater.from(activity).inflate(R.layout.location_permission_row, root, false), + LayoutInflater.from(context).inflate(R.layout.location_permission_row, root, false), allowClickListener, dismissClickListener); case RowType.INVALID: @@ -168,10 +157,6 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> } } - void setCallInitiationType(CallInitiationType.Type callInitiationType) { - this.callInitiationType = callInitiationType; - } - public void setNearbyPlacesCursor(SearchCursor nearbyPlacesCursor) { if (searchCursorManager.setNearbyPlacesCursor(nearbyPlacesCursor)) { notifyDataSetChanged(); @@ -209,51 +194,6 @@ public final class SearchAdapter extends RecyclerView.Adapter<ViewHolder> } } - @Override - public void placeVoiceCall(String phoneNumber, int ranking) { - placeCall(phoneNumber, ranking, false, true); - } - - @Override - public void placeVideoCall(String phoneNumber, int ranking) { - placeCall(phoneNumber, ranking, true, false); - } - - private void placeCall( - String phoneNumber, int position, boolean isVideoCall, boolean allowAssistedDial) { - CallSpecificAppData callSpecificAppData = - CallSpecificAppData.newBuilder() - .setCallInitiationType(callInitiationType) - .setPositionOfSelectedSearchResult(position) - .setCharactersInSearchString(query == null ? 0 : query.length()) - .setAllowAssistedDialing(allowAssistedDial) - .build(); - Intent intent = - new CallIntentBuilder(phoneNumber, callSpecificAppData) - .setIsVideoCall(isVideoCall) - .setAllowAssistedDial( - allowAssistedDial, - ConcreteCreator.createNewAssistedDialingMediator( - activity.getSystemService(TelephonyManager.class), - activity.getApplicationContext())) - .build(); - DialerUtils.startActivityWithErrorToast(activity, intent); - } - - @Override - public void placeDuoCall(String phoneNumber) { - Logger.get(activity) - .logImpression(DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_SEARCH); - Intent intent = DuoComponent.get(activity).getDuo().getIntent(activity, phoneNumber); - activity.startActivityForResult(intent, ActivityRequestCodes.DIALTACTS_DUO); - } - - @Override - public void openCallAndShare(DialerContact contact) { - Intent intent = CallComposerActivity.newIntent(activity, contact); - DialerUtils.startActivityWithErrorToast(activity, intent); - } - /** Viewholder for R.layout.location_permission_row that requests the location permission. */ private static class LocationPermissionViewHolder extends RecyclerView.ViewHolder { |