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
147
|
/*
* Copyright (C) 2016 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.contactgrid;
import android.content.Context;
import android.support.annotation.Nullable;
import android.telephony.PhoneNumberUtils;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.incallui.call.DialerCall.State;
import com.android.incallui.incall.protocol.PrimaryCallState;
import com.android.incallui.incall.protocol.PrimaryInfo;
/**
* Gets the content of the bottom row. For example:
*
* <ul>
* <li>Mobile +1 (650) 253-0000
* <li>[HD attempting icon]/[HD icon] 00:15
* <li>Call ended
* <li>Hanging up
* </ul>
*/
public class BottomRow {
/** Content of the bottom row. */
public static class Info {
@Nullable public final CharSequence label;
public final boolean isTimerVisible;
public final boolean isWorkIconVisible;
public final boolean isHdAttemptinIconVisible;
public final boolean isHdIconVisible;
public final boolean isForwardIconVisible;
public final boolean isSpamIconVisible;
public final boolean shouldPopulateAccessibilityEvent;
public Info(
@Nullable CharSequence label,
boolean isTimerVisible,
boolean isWorkIconVisible,
boolean isHdAttemptinIconVisible,
boolean isHdIconVisible,
boolean isForwardIconVisible,
boolean isSpamIconVisible,
boolean shouldPopulateAccessibilityEvent) {
this.label = label;
this.isTimerVisible = isTimerVisible;
this.isWorkIconVisible = isWorkIconVisible;
this.isHdAttemptinIconVisible = isHdAttemptinIconVisible;
this.isHdIconVisible = isHdIconVisible;
this.isForwardIconVisible = isForwardIconVisible;
this.isSpamIconVisible = isSpamIconVisible;
this.shouldPopulateAccessibilityEvent = shouldPopulateAccessibilityEvent;
}
}
private BottomRow() {}
public static Info getInfo(Context context, PrimaryCallState state, PrimaryInfo primaryInfo) {
CharSequence label;
boolean isTimerVisible = state.state == State.ACTIVE;
boolean isForwardIconVisible = state.isForwardedNumber;
boolean isWorkIconVisible = state.isWorkCall;
boolean isHdIconVisible = state.isHdAudioCall && !isForwardIconVisible;
boolean isHdAttemptingIconVisible = state.isHdAttempting;
boolean isSpamIconVisible = false;
boolean shouldPopulateAccessibilityEvent = true;
if (isIncoming(state) && primaryInfo.isSpam) {
label = context.getString(R.string.contact_grid_incoming_suspected_spam);
isSpamIconVisible = true;
isHdIconVisible = false;
} else if (state.state == State.DISCONNECTING) {
// While in the DISCONNECTING state we display a "Hanging up" message in order to make the UI
// feel more responsive. (In GSM it's normal to see a delay of a couple of seconds while
// negotiating the disconnect with the network, so the "Hanging up" state at least lets the
// user know that we're doing something. This state is currently not used with CDMA.)
label = context.getString(R.string.incall_hanging_up);
} else if (state.state == State.DISCONNECTED) {
label = state.disconnectCause.getLabel();
if (TextUtils.isEmpty(label)) {
label = context.getString(R.string.incall_call_ended);
}
} else if (!TextUtils.isEmpty(state.callbackNumber)) {
// This is used for carriers like Project Fi to show the callback number for emergency calls.
label =
context.getString(
R.string.contact_grid_callback_number,
PhoneNumberUtils.formatNumber(state.callbackNumber));
isTimerVisible = false;
} else {
label = getLabelForPhoneNumber(primaryInfo);
shouldPopulateAccessibilityEvent = primaryInfo.nameIsNumber;
}
return new Info(
label,
isTimerVisible,
isWorkIconVisible,
isHdAttemptingIconVisible,
isHdIconVisible,
isForwardIconVisible,
isSpamIconVisible,
shouldPopulateAccessibilityEvent);
}
private static CharSequence getLabelForPhoneNumber(PrimaryInfo primaryInfo) {
if (primaryInfo.nameIsNumber) {
return primaryInfo.location;
}
if (!TextUtils.isEmpty(primaryInfo.number)) {
CharSequence spannedNumber = spanDisplayNumber(primaryInfo.number);
if (primaryInfo.label == null) {
return spannedNumber;
} else {
return TextUtils.concat(primaryInfo.label, " ", spannedNumber);
}
}
return null;
}
private static CharSequence spanDisplayNumber(String displayNumber) {
return PhoneNumberUtilsCompat.createTtsSpannable(
BidiFormatter.getInstance().unicodeWrap(displayNumber, TextDirectionHeuristics.LTR));
}
private static boolean isIncoming(PrimaryCallState state) {
return state.state == State.INCOMING || state.state == State.CALL_WAITING;
}
}
|