From 4db07410fbf823158a8cd3edcc7a6e1d72cc607f Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Thu, 26 Apr 2018 13:00:04 -0700 Subject: Build out the bottom sheet for suggested contacts in Speed Dial. The bottom sheet should include: - contact row - voice call - video call - sms - divider - add favorite (follow up) - remove (follow up) - contact info Bug: 77761183 Test: WIP PiperOrigin-RevId: 194440839 Change-Id: I78e0e0fc0a4834338a59b458fe7639786de57877 --- .../dialer/callintent/CallIntentBuilder.java | 1 + .../HistoryItemActionBottomSheet.java | 8 ++ .../HistoryItemActionModule.java | 5 + .../res/layout/module_layout.xml | 1 - .../dialer/speeddial/SpeedDialFragment.java | 114 ++++++++++++++++++++- .../dialer/speeddial/SuggestionViewHolder.java | 35 +++---- .../dialer/speeddial/loader/SpeedDialUiItem.java | 12 +++ .../speeddial/res/layout/suggestion_row_layout.xml | 5 +- 8 files changed, 156 insertions(+), 25 deletions(-) diff --git a/java/com/android/dialer/callintent/CallIntentBuilder.java b/java/com/android/dialer/callintent/CallIntentBuilder.java index 0f9f8905d..92efd392b 100644 --- a/java/com/android/dialer/callintent/CallIntentBuilder.java +++ b/java/com/android/dialer/callintent/CallIntentBuilder.java @@ -152,6 +152,7 @@ public class CallIntentBuilder implements Parcelable { return isVideoCall; } + /** Default false. Should only be set to true if the number has a lookup URI. */ public CallIntentBuilder setAllowAssistedDial(boolean allowAssistedDial) { this.allowAssistedDial = allowAssistedDial; return this; diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java b/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java index 79205a7d9..28663c17d 100644 --- a/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java +++ b/java/com/android/dialer/historyitemactions/HistoryItemActionBottomSheet.java @@ -17,8 +17,10 @@ package com.android.dialer.historyitemactions; import android.content.Context; +import android.content.res.ColorStateList; import android.os.Bundle; import android.support.design.widget.BottomSheetDialog; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -109,6 +111,12 @@ public class HistoryItemActionBottomSheet extends BottomSheetDialog implements O ((TextView) moduleView.findViewById(R.id.module_text)).setText(module.getStringId()); ((ImageView) moduleView.findViewById(R.id.module_image)) .setImageResource(module.getDrawableId()); + if (module.tintDrawable()) { + ((ImageView) moduleView.findViewById(R.id.module_image)) + .setImageTintList( + ColorStateList.valueOf( + ContextCompat.getColor(getContext(), R.color.secondary_text_color))); + } moduleView.setOnClickListener(this); moduleView.setTag(module); return moduleView; diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java b/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java index d64cbca53..e948924d7 100644 --- a/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java +++ b/java/com/android/dialer/historyitemactions/HistoryItemActionModule.java @@ -32,6 +32,11 @@ public interface HistoryItemActionModule { @DrawableRes int getDrawableId(); + /** Returns true if tint can be applied to the drawable. */ + default boolean tintDrawable() { + return true; + } + /** @return true if the bottom sheet should close, false otherwise */ boolean onClick(); } diff --git a/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml b/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml index 9aee67937..063051947 100644 --- a/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml +++ b/java/com/android/dialer/historyitemactions/res/layout/module_layout.xml @@ -28,7 +28,6 @@ android:layout_height="@dimen/contact_actions_image_size" android:layout_marginStart="@dimen/contact_actions_image_margin" android:layout_marginEnd="@dimen/contact_actions_image_margin" - android:tint="@color/dialer_secondary_text_color" android:scaleType="center"/> modules = new ArrayList<>(); + Channel defaultChannel = speedDialUiItem.defaultChannel(); + + // Add voice call module + Channel voiceChannel = speedDialUiItem.getDeterministicVoiceChannel(); + if (voiceChannel != null) { + modules.add( + IntentModule.newCallModule( + getContext(), + new CallIntentBuilder(voiceChannel.number(), CallInitiationType.Type.SPEED_DIAL) + .setAllowAssistedDial(true))); + } else { + modules.add(new DisambigDialogModule(speedDialUiItem, /* isVideo = */ false)); + } + + // Add video if we can determine the correct channel + Channel videoChannel = speedDialUiItem.getDeterministicVideoChannel(); + if (videoChannel != null) { + modules.add( + IntentModule.newCallModule( + getContext(), + new CallIntentBuilder(videoChannel.number(), CallInitiationType.Type.SPEED_DIAL) + .setIsVideoCall(true) + .setAllowAssistedDial(true))); + } else if (speedDialUiItem.hasVideoChannels()) { + modules.add(new DisambigDialogModule(speedDialUiItem, /* isVideo = */ true)); + } + + // Add sms module + Optional smsModule = + SharedModules.createModuleForSendingTextMessage( + getContext(), defaultChannel.number(), false); + if (smsModule.isPresent()) { + modules.add(smsModule.get()); + } + + modules.add(new DividerModule()); + + // TODO(calderwoodra): add to favorites module + // TODO(calderwoodra): remove from strequent module + + // Contact info module + modules.add( + new ContactInfoModule( + getContext(), + new Intent( + Intent.ACTION_VIEW, + Uri.withAppendedPath( + Contacts.CONTENT_URI, String.valueOf(speedDialUiItem.contactId()))), + R.string.contact_menu_contact_info, + R.drawable.context_menu_contact_icon)); + + HistoryItemActionBottomSheet.show(getContext(), headerInfo, modules); } @Override @@ -321,6 +384,53 @@ public class SpeedDialFragment extends Fragment { new CallIntentBuilder(channel.number(), CallInitiationType.Type.SPEED_DIAL) .setIsVideoCall(channel.isVideoTechnology())); } + + private final class ContactInfoModule extends IntentModule { + + public ContactInfoModule(Context context, Intent intent, int text, int image) { + super(context, intent, text, image); + } + + @Override + public boolean tintDrawable() { + return false; + } + } + + private final class DisambigDialogModule implements HistoryItemActionModule { + + private final SpeedDialUiItem speedDialUiItem; + private final boolean isVideo; + + DisambigDialogModule(SpeedDialUiItem speedDialUiItem, boolean isVideo) { + this.speedDialUiItem = speedDialUiItem; + this.isVideo = isVideo; + } + + @Override + public int getStringId() { + if (isVideo) { + return R.string.contact_menu_video_call; + } else { + return R.string.contact_menu_voice_call; + } + } + + @Override + public int getDrawableId() { + if (isVideo) { + return R.drawable.quantum_ic_videocam_vd_theme_24; + } else { + return R.drawable.quantum_ic_phone_vd_theme_24; + } + } + + @Override + public boolean onClick() { + DisambigDialog.show(speedDialUiItem, getChildFragmentManager()); + return true; + } + } } private static final class SpeedDialContextMenuItemListener implements ContextMenuItemListener { diff --git a/java/com/android/dialer/speeddial/SuggestionViewHolder.java b/java/com/android/dialer/speeddial/SuggestionViewHolder.java index 546ffbdff..578e0b328 100644 --- a/java/com/android/dialer/speeddial/SuggestionViewHolder.java +++ b/java/com/android/dialer/speeddial/SuggestionViewHolder.java @@ -17,27 +17,25 @@ package com.android.dialer.speeddial; import android.content.Context; -import android.provider.ContactsContract.Contacts; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; -import android.widget.QuickContactBadge; import android.widget.TextView; import com.android.dialer.common.Assert; -import com.android.dialer.glidephotomanager.GlidePhotoManagerComponent; -import com.android.dialer.glidephotomanager.PhotoInfo; +import com.android.dialer.historyitemactions.HistoryItemBottomSheetHeaderInfo; import com.android.dialer.location.GeoUtil; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.speeddial.database.SpeedDialEntry.Channel; import com.android.dialer.speeddial.loader.SpeedDialUiItem; +import com.android.dialer.widget.ContactPhotoView; /** ViewHolder for displaying suggested contacts in {@link SpeedDialFragment}. */ public class SuggestionViewHolder extends RecyclerView.ViewHolder implements OnClickListener { private final SuggestedContactsListener listener; - private final QuickContactBadge photoView; + private final ContactPhotoView photoView; private final TextView nameOrNumberView; private final TextView numberView; @@ -71,34 +69,31 @@ public class SuggestionViewHolder extends RecyclerView.ViewHolder implements OnC nameOrNumberView.setText(speedDialUiItem.name()); numberView.setText(secondaryInfo); - GlidePhotoManagerComponent.get(context) - .glidePhotoManager() - .loadQuickContactBadge( - photoView, - PhotoInfo.newBuilder() - .setPhotoId(speedDialUiItem.photoId()) - .setPhotoUri(speedDialUiItem.photoUri()) - .setName(speedDialUiItem.name()) - .setIsVideo(speedDialUiItem.defaultChannel().isVideoTechnology()) - .setLookupUri( - Contacts.getLookupUri(speedDialUiItem.contactId(), speedDialUiItem.lookupKey()) - .toString()) - .build()); + photoView.setPhoto(speedDialUiItem.getPhotoInfo()); } @Override public void onClick(View v) { if (v.getId() == R.id.overflow) { - listener.onOverFlowMenuClicked(speedDialUiItem); + listener.onOverFlowMenuClicked(speedDialUiItem, getHeaderInfo()); } else { listener.onRowClicked(speedDialUiItem.defaultChannel()); } } + private HistoryItemBottomSheetHeaderInfo getHeaderInfo() { + return HistoryItemBottomSheetHeaderInfo.newBuilder() + .setPhotoInfo(speedDialUiItem.getPhotoInfo()) + .setPrimaryText(nameOrNumberView.getText().toString()) + .setSecondaryText(numberView.getText().toString()) + .build(); + } + /** Listener/Callback for {@link SuggestionViewHolder} parents. */ public interface SuggestedContactsListener { - void onOverFlowMenuClicked(SpeedDialUiItem speedDialUiItem); + void onOverFlowMenuClicked( + SpeedDialUiItem speedDialUiItem, HistoryItemBottomSheetHeaderInfo headerInfo); /** Called when a suggested contact is clicked. */ void onRowClicked(Channel channel); diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java index a2bdfb89a..c5a3ea3ed 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java @@ -18,10 +18,12 @@ package com.android.dialer.speeddial.loader; import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; import android.support.annotation.Nullable; import android.text.TextUtils; import com.android.dialer.common.Assert; +import com.android.dialer.glidephotomanager.PhotoInfo; import com.android.dialer.speeddial.database.SpeedDialEntry; import com.android.dialer.speeddial.database.SpeedDialEntry.Channel; import com.google.auto.value.AutoValue; @@ -139,6 +141,16 @@ public abstract class SpeedDialUiItem { return builder.build(); } + public PhotoInfo getPhotoInfo() { + return PhotoInfo.newBuilder() + .setPhotoId(photoId()) + .setPhotoUri(photoUri()) + .setName(name()) + .setIsVideo(defaultChannel() != null && defaultChannel().isVideoTechnology()) + .setLookupUri(Contacts.getLookupUri(contactId(), lookupKey()).toString()) + .build(); + } + public SpeedDialEntry buildSpeedDialEntry() { return SpeedDialEntry.builder() .setId(speedDialEntryId()) diff --git a/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml b/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml index ff95b5906..868606065 100644 --- a/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml +++ b/java/com/android/dialer/speeddial/res/layout/suggestion_row_layout.xml @@ -21,7 +21,7 @@ android:minHeight="72dp" android:background="?android:attr/selectableItemBackground"> - + android:background="?android:selectableItemBackgroundBorderless" + android:contentDescription="@string/content_description_overflow"/> \ No newline at end of file -- cgit v1.2.3