1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* 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.calllog.ui.menu;
import android.content.Context;
import android.provider.CallLog.Calls;
import android.telecom.PhoneAccountHandle;
import android.text.TextUtils;
import com.android.dialer.calldetails.CallDetailsActivity;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.calllog.model.CoalescedRow;
import com.android.dialer.calllogutils.CallLogContactTypes;
import com.android.dialer.calllogutils.PhoneAccountUtils;
import com.android.dialer.contactactions.ContactActionModule;
import com.android.dialer.contactactions.DividerModule;
import com.android.dialer.contactactions.IntentModule;
import com.android.dialer.contactactions.SharedModules;
import com.android.dialer.dialercontact.DialerContact;
import java.util.ArrayList;
import java.util.List;
/**
* Configures the modules for the bottom sheet; these are the rows below the top row (primary
* action) in the bottom sheet.
*/
final class Modules {
static List<ContactActionModule> fromRow(Context context, CoalescedRow row) {
// Conditionally add each module, which are items in the bottom sheet's menu.
List<ContactActionModule> modules = new ArrayList<>();
maybeAddModuleForVideoOrAudioCall(context, modules, row);
SharedModules.maybeAddModuleForAddingToContacts(
context,
modules,
row.number(),
row.numberAttributes().getName(),
row.numberAttributes().getLookupUri());
String originalNumber = row.number().getRawInput().getNumber();
SharedModules.maybeAddModuleForSendingTextMessage(context, modules, originalNumber);
if (!modules.isEmpty()) {
modules.add(new DividerModule());
}
// TODO(zachh): Module for blocking/unblocking spam.
// TODO(zachh): Module for CallComposer.
SharedModules.maybeAddModuleForCopyingNumber(context, modules, originalNumber);
// TODO(zachh): Revisit if DialerContact is the best thing to pass to CallDetails; could
// it use a ContactPrimaryActionInfo instead?
addModuleForAccessingCallDetails(context, modules, row);
modules.add(new DeleteCallLogItemModule(context, row.coalescedIds()));
return modules;
}
private static void maybeAddModuleForVideoOrAudioCall(
Context context, List<ContactActionModule> modules, CoalescedRow row) {
String originalNumber = row.number().getRawInput().getNumber();
if (TextUtils.isEmpty(originalNumber)) {
// Skip adding the menu item if the phone number is unknown.
return;
}
PhoneAccountHandle phoneAccountHandle =
PhoneAccountUtils.getAccount(row.phoneAccountComponentName(), row.phoneAccountId());
if ((row.features() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) {
// Add an audio call item for video calls. Clicking the top entry on the bottom sheet will
// trigger a video call.
modules.add(
IntentModule.newCallModule(
context, originalNumber, phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
} else {
// Add a video call item for audio calls. Click the top entry on the bottom sheet will
// trigger an audio call.
// TODO(zachh): Only show video option if video capabilities present?
modules.add(
IntentModule.newVideoCallModule(
context, originalNumber, phoneAccountHandle, CallInitiationType.Type.CALL_LOG));
}
}
private static void addModuleForAccessingCallDetails(
Context context, List<ContactActionModule> modules, CoalescedRow row) {
boolean canReportAsInvalidNumber = row.numberAttributes().getCanReportAsInvalidNumber();
boolean canSupportAssistedDialing = !TextUtils.isEmpty(row.numberAttributes().getLookupUri());
modules.add(
new IntentModule(
context,
CallDetailsActivity.newInstance(
context,
row.coalescedIds(),
createDialerContactFromRow(row),
canReportAsInvalidNumber,
canSupportAssistedDialing),
R.string.call_details_menu_label,
R.drawable.quantum_ic_info_outline_vd_theme_24));
}
private static DialerContact createDialerContactFromRow(CoalescedRow row) {
// TODO(zachh): Do something with parsed values to make more dialable?
String originalNumber = row.number().getRawInput().getNumber();
DialerContact.Builder dialerContactBuilder =
DialerContact.newBuilder()
.setNumber(originalNumber)
.setContactType(CallLogContactTypes.getContactType(row))
.setPhotoId(row.numberAttributes().getPhotoId());
if (!row.numberAttributes().getName().isEmpty()) {
dialerContactBuilder.setNameOrNumber(row.numberAttributes().getName());
if (row.formattedNumber() != null) {
dialerContactBuilder.setDisplayNumber(row.formattedNumber());
}
} else if (!TextUtils.isEmpty(row.formattedNumber())) {
dialerContactBuilder.setNameOrNumber(row.formattedNumber());
}
dialerContactBuilder.setNumberLabel(row.numberAttributes().getNumberTypeLabel());
dialerContactBuilder.setPhotoUri(row.numberAttributes().getPhotoUri());
dialerContactBuilder.setContactUri(row.numberAttributes().getLookupUri());
return dialerContactBuilder.build();
}
}
|