summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/contactactions
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/contactactions')
-rw-r--r--java/com/android/dialer/contactactions/ContactActionBottomSheet.java66
-rw-r--r--java/com/android/dialer/contactactions/ContactPrimaryActionInfo.java118
-rw-r--r--java/com/android/dialer/contactactions/IntentModule.java24
-rw-r--r--java/com/android/dialer/contactactions/res/layout/contact_layout.xml4
4 files changed, 175 insertions, 37 deletions
diff --git a/java/com/android/dialer/contactactions/ContactActionBottomSheet.java b/java/com/android/dialer/contactactions/ContactActionBottomSheet.java
index 9bf7ca095..f2f1d189b 100644
--- a/java/com/android/dialer/contactactions/ContactActionBottomSheet.java
+++ b/java/com/android/dialer/contactactions/ContactActionBottomSheet.java
@@ -29,33 +29,38 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.dialer.common.Assert;
+import com.android.dialer.contactactions.ContactPrimaryActionInfo.PhotoInfo;
import com.android.dialer.contactphoto.ContactPhotoManager;
-import com.android.dialer.dialercontact.DialerContact;
import java.util.List;
/**
* {@link BottomSheetDialog} used for building a list of contact actions in a bottom sheet menu.
*
- * <p>{@link #show(Context, DialerContact, List)} should be used to create and display the menu.
- * Modules are built using {@link ContactActionModule} and some defaults are provided by {@link
- * IntentModule} and {@link DividerModule}.
+ * <p>{@link #show(Context, ContactPrimaryActionInfo, List)} should be used to create and display
+ * the menu. Modules are built using {@link ContactActionModule} and some defaults are provided by
+ * {@link IntentModule} and {@link DividerModule}.
*/
public class ContactActionBottomSheet extends BottomSheetDialog implements OnClickListener {
private final List<ContactActionModule> modules;
- private final DialerContact contact;
+ private final ContactPrimaryActionInfo contactPrimaryActionInfo;
private ContactActionBottomSheet(
- Context context, DialerContact contact, List<ContactActionModule> modules) {
+ Context context,
+ ContactPrimaryActionInfo contactPrimaryActionInfo,
+ List<ContactActionModule> modules) {
super(context);
this.modules = modules;
- this.contact = contact;
+ this.contactPrimaryActionInfo = contactPrimaryActionInfo;
setContentView(LayoutInflater.from(context).inflate(R.layout.sheet_layout, null));
}
public static ContactActionBottomSheet show(
- Context context, DialerContact contact, List<ContactActionModule> modules) {
- ContactActionBottomSheet sheet = new ContactActionBottomSheet(context, contact, modules);
+ Context context,
+ ContactPrimaryActionInfo contactPrimaryActionInfo,
+ List<ContactActionModule> modules) {
+ ContactActionBottomSheet sheet =
+ new ContactActionBottomSheet(context, contactPrimaryActionInfo, modules);
sheet.show();
return sheet;
}
@@ -75,38 +80,37 @@ public class ContactActionBottomSheet extends BottomSheetDialog implements OnCli
}
}
- // TODO(calderwoodra): add on click action to contact.
private View getContactView(ViewGroup container) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View contactView = inflater.inflate(R.layout.contact_layout, container, false);
+ // TODO(zachh): The contact image should be badged with a video icon if it is for a video call.
+ PhotoInfo photoInfo = contactPrimaryActionInfo.photoInfo();
ContactPhotoManager.getInstance(getContext())
.loadDialerThumbnailOrPhoto(
contactView.findViewById(R.id.quick_contact_photo),
- contact.hasContactUri() ? Uri.parse(contact.getContactUri()) : null,
- contact.getPhotoId(),
- contact.hasPhotoUri() ? Uri.parse(contact.getPhotoUri()) : null,
- contact.getNameOrNumber(),
- contact.getContactType());
+ photoInfo.lookupUri() != null ? Uri.parse(photoInfo.lookupUri()) : null,
+ photoInfo.photoId(),
+ photoInfo.photoUri() != null ? Uri.parse(photoInfo.photoUri()) : null,
+ photoInfo.displayName(),
+ photoInfo.contactType());
- TextView nameView = contactView.findViewById(R.id.contact_name);
- TextView numberView = contactView.findViewById(R.id.phone_number);
+ TextView primaryTextView = contactView.findViewById(R.id.primary_text);
+ TextView secondaryTextView = contactView.findViewById(R.id.secondary_text);
- nameView.setText(contact.getNameOrNumber());
- if (!TextUtils.isEmpty(contact.getDisplayNumber())) {
- numberView.setVisibility(View.VISIBLE);
- String secondaryInfo =
- TextUtils.isEmpty(contact.getNumberLabel())
- ? contact.getDisplayNumber()
- : getContext()
- .getString(
- com.android.contacts.common.R.string.call_subject_type_and_number,
- contact.getNumberLabel(),
- contact.getDisplayNumber());
- numberView.setText(secondaryInfo);
+ primaryTextView.setText(contactPrimaryActionInfo.primaryText());
+ if (!TextUtils.isEmpty(contactPrimaryActionInfo.secondaryText())) {
+ secondaryTextView.setText(contactPrimaryActionInfo.secondaryText());
} else {
- numberView.setVisibility(View.GONE);
- numberView.setText(null);
+ secondaryTextView.setVisibility(View.GONE);
+ secondaryTextView.setText(null);
+ }
+ if (contactPrimaryActionInfo.intent() != null) {
+ contactView.setOnClickListener(
+ (view) -> {
+ getContext().startActivity(contactPrimaryActionInfo.intent());
+ dismiss();
+ });
}
return contactView;
}
diff --git a/java/com/android/dialer/contactactions/ContactPrimaryActionInfo.java b/java/com/android/dialer/contactactions/ContactPrimaryActionInfo.java
new file mode 100644
index 000000000..2535f853d
--- /dev/null
+++ b/java/com/android/dialer/contactactions/ContactPrimaryActionInfo.java
@@ -0,0 +1,118 @@
+/*
+ * 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.contactactions;
+
+import android.content.Intent;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import com.android.dialer.DialerPhoneNumber;
+import com.android.dialer.lettertile.LetterTileDrawable;
+import com.google.auto.value.AutoValue;
+
+/**
+ * Contains information necessary to construct the primary action for a contact bottom sheet.
+ *
+ * <p>This may include information about the call, for instance when the bottom sheet is shown from
+ * the call log.
+ */
+@AutoValue
+public abstract class ContactPrimaryActionInfo {
+
+ @Nullable
+ public abstract DialerPhoneNumber number();
+
+ /** Information used to construct the photo for the contact. */
+ @AutoValue
+ public abstract static class PhotoInfo {
+ public abstract long photoId();
+
+ @Nullable
+ public abstract String photoUri();
+
+ @Nullable
+ public abstract String lookupUri();
+
+ /** Badges the photo with a video icon if true. */
+ public abstract boolean isVideo();
+
+ @LetterTileDrawable.ContactType
+ public abstract int contactType();
+
+ /** Used to generate letter tile if there is no photo. */
+ @Nullable
+ public abstract String displayName();
+
+ /** Builder for {@link PhotoInfo}. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ public abstract Builder setPhotoId(long photoId);
+
+ public abstract Builder setPhotoUri(@Nullable String photoUri);
+
+ public abstract Builder setLookupUri(@Nullable String lookupUri);
+
+ public abstract Builder setIsVideo(boolean isVideo);
+
+ public abstract Builder setContactType(@LetterTileDrawable.ContactType int contactType);
+
+ public abstract Builder setDisplayName(@Nullable String displayName);
+
+ public abstract PhotoInfo build();
+ }
+
+ public static Builder builder() {
+ return new AutoValue_ContactPrimaryActionInfo_PhotoInfo.Builder();
+ }
+ }
+
+ @NonNull
+ public abstract PhotoInfo photoInfo();
+
+ @Nullable
+ public abstract CharSequence primaryText();
+
+ @Nullable
+ public abstract CharSequence secondaryText();
+
+ /**
+ * The intent to fire when the user clicks the top row of the bottom sheet. Null if no action
+ * should occur (e.g. if the number is unknown).
+ */
+ @Nullable
+ public abstract Intent intent();
+
+ // TODO(zachh): Add SIM info here if should be shown in bottom sheet.
+
+ /** Builder for {@link ContactPrimaryActionInfo}. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ public abstract Builder setNumber(@Nullable DialerPhoneNumber dialerPhoneNumber);
+
+ public abstract Builder setPhotoInfo(@NonNull PhotoInfo photoInfo);
+
+ public abstract Builder setPrimaryText(@Nullable CharSequence primaryText);
+
+ public abstract Builder setSecondaryText(@Nullable CharSequence secondaryText);
+
+ public abstract Builder setIntent(@Nullable Intent intent);
+
+ public abstract ContactPrimaryActionInfo build();
+ }
+
+ public static Builder builder() {
+ return new AutoValue_ContactPrimaryActionInfo.Builder();
+ }
+}
diff --git a/java/com/android/dialer/contactactions/IntentModule.java b/java/com/android/dialer/contactactions/IntentModule.java
index 201f52192..5a4870cbe 100644
--- a/java/com/android/dialer/contactactions/IntentModule.java
+++ b/java/com/android/dialer/contactactions/IntentModule.java
@@ -19,7 +19,9 @@ package com.android.dialer.contactactions;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.DrawableRes;
+import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
+import android.telecom.PhoneAccountHandle;
import com.android.dialer.callintent.CallInitiationType.Type;
import com.android.dialer.callintent.CallIntentBuilder;
@@ -56,19 +58,33 @@ public class IntentModule implements ContactActionModule {
return true;
}
- public static IntentModule newCallModule(Context context, String number, Type initiationType) {
+ public static IntentModule newCallModule(
+ Context context,
+ String number,
+ @Nullable PhoneAccountHandle phoneAccountHandle,
+ Type initiationType) {
+ // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber.
return new IntentModule(
context,
- new CallIntentBuilder(number, initiationType).build(),
+ new CallIntentBuilder(number, initiationType)
+ .setPhoneAccountHandle(phoneAccountHandle)
+ .build(),
R.string.call,
R.drawable.quantum_ic_call_white_24);
}
public static IntentModule newVideoCallModule(
- Context context, String number, Type initiationType) {
+ Context context,
+ String number,
+ @Nullable PhoneAccountHandle phoneAccountHandle,
+ Type initiationType) {
+ // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber.
return new IntentModule(
context,
- new CallIntentBuilder(number, initiationType).setIsVideoCall(true).build(),
+ new CallIntentBuilder(number, initiationType)
+ .setPhoneAccountHandle(phoneAccountHandle)
+ .setIsVideoCall(true)
+ .build(),
R.string.video_call,
R.drawable.quantum_ic_videocam_white_24);
}
diff --git a/java/com/android/dialer/contactactions/res/layout/contact_layout.xml b/java/com/android/dialer/contactactions/res/layout/contact_layout.xml
index bf3297153..8ea05d4d6 100644
--- a/java/com/android/dialer/contactactions/res/layout/contact_layout.xml
+++ b/java/com/android/dialer/contactactions/res/layout/contact_layout.xml
@@ -38,13 +38,13 @@
android:gravity="center_vertical">
<TextView
- android:id="@+id/contact_name"
+ android:id="@+id/primary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/PrimaryText"/>
<TextView
- android:id="@+id/phone_number"
+ android:id="@+id/secondary_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"