summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java
diff options
context:
space:
mode:
authorEric Erfanian <erfanian@google.com>2018-05-30 16:17:27 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-05-30 16:17:27 +0000
commit2c3d81eeac82472d06027bc65d661e16735c8608 (patch)
tree293aeb0012d8db8f3f4606a75a422cf4da328477 /java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java
parent4efd0ebf003e985e7cbe40d8ffd9f7ff227a9611 (diff)
parent152c3fd58f83a1882bcdc8bc55f46bbb8f3173c9 (diff)
Merge changes Ica13ee39,I5e0fedc8,I8e7efad0,I0ecc1f91,Iee1e658a, ...
* changes: Drop maps.impl from packages.mk Check if ID column is null before retrieving data from the smart dial database. Rename theme/private to theme/hidden. Some improvements to the answer fragment layouts. Better a11y for the bottom sheet. Fix a few UI bugs. Log IMS video call available state Better a11y for contact badge in the new call log. Use lookup key to determine the letter tile color Use Dialer Light Theme for SpeakEasyFragment Better a11y for new call log entries. Use Maps SDK lite mode instead of static API for emergency call. Updating locations where PrimaryInfo#setPhoto is used to also PrimaryInfo#setPhotoUri for new GlidePhotoManager implementation. As part of this addition, we also are cleaning the setPhoto(null) because this is not explicitly needed. Converted ThemeUtil into a DaggerModule. Delete AppCompatConstants Remove photo support in PhoneNumberService Began implementation of Dialer dark theme.
Diffstat (limited to 'java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java')
-rw-r--r--java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java154
1 files changed, 154 insertions, 0 deletions
diff --git a/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java b/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java
new file mode 100644
index 000000000..244087989
--- /dev/null
+++ b/java/com/android/dialer/calllogutils/CallLogEntryDescriptions.java
@@ -0,0 +1,154 @@
+/*
+ * 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.calllogutils;
+
+import android.content.Context;
+import android.provider.CallLog.Calls;
+import android.support.annotation.PluralsRes;
+import android.telecom.PhoneAccountHandle;
+import android.text.TextUtils;
+import com.android.dialer.calllog.model.CoalescedRow;
+import com.android.dialer.telecom.TelecomUtil;
+import com.android.dialer.time.Clock;
+import com.google.common.collect.Collections2;
+import java.util.List;
+
+/** Builds descriptions of call log entries for accessibility users. */
+public final class CallLogEntryDescriptions {
+
+ private CallLogEntryDescriptions() {}
+
+ /**
+ * Builds the content description for a call log entry.
+ *
+ * <p>The description is of format<br>
+ * {primary description}, {secondary description}, {phone account description}.
+ *
+ * <ul>
+ * <li>The primary description depends on the number of calls in the entry. For example:<br>
+ * "1 answered call from Jane Smith", or<br>
+ * "2 calls, the latest is an answered call from Jane Smith".
+ * <li>The secondary description is the same as the secondary text for the call log entry,
+ * except that date/time is not abbreviated. For example:<br>
+ * "mobile, 11 minutes ago".
+ * <li>The phone account description is of format "on {phone_account_label}, via {number}". For
+ * example:<br>
+ * "on SIM 1, via 6502531234".<br>
+ * Note that the phone account description will be empty if the device has only one SIM.
+ * </ul>
+ *
+ * <p>An example of the full description can be:<br>
+ * "2 calls, the latest is an answered call from Jane Smith, mobile, 11 minutes ago, on SIM 1, via
+ * 6502531234".
+ */
+ public static CharSequence buildDescriptionForEntry(
+ Context context, Clock clock, CoalescedRow row) {
+
+ // Build the primary description.
+ // Examples:
+ // (1) For an entry containing only 1 call:
+ // "1 missed call from James Smith".
+ // (2) For entries containing multiple calls:
+ // "2 calls, the latest is a missed call from Jame Smith".
+ CharSequence primaryDescription =
+ context
+ .getResources()
+ .getQuantityString(
+ getPrimaryDescriptionResIdForCallType(row),
+ row.getCoalescedIds().getCoalescedIdCount(),
+ row.getCoalescedIds().getCoalescedIdCount(),
+ CallLogEntryText.buildPrimaryText(context, row));
+
+ // Build the secondary description.
+ // An example: "mobile, 11 minutes ago".
+ CharSequence secondaryDescription =
+ joinSecondaryTextComponents(
+ CallLogEntryText.buildSecondaryTextListForEntries(
+ context, clock, row, /* abbreviateDateTime = */ false));
+
+ // Build the phone account description.
+ // Note that this description can be an empty string.
+ CharSequence phoneAccountDescription = buildPhoneAccountDescription(context, row);
+
+ return TextUtils.isEmpty(phoneAccountDescription)
+ ? context
+ .getResources()
+ .getString(
+ R.string.a11y_new_call_log_entry_full_description_without_phone_account_info,
+ primaryDescription,
+ secondaryDescription)
+ : context
+ .getResources()
+ .getString(
+ R.string.a11y_new_call_log_entry_full_description_with_phone_account_info,
+ primaryDescription,
+ secondaryDescription,
+ phoneAccountDescription);
+ }
+
+ private static @PluralsRes int getPrimaryDescriptionResIdForCallType(CoalescedRow row) {
+ switch (row.getCallType()) {
+ case Calls.INCOMING_TYPE:
+ case Calls.ANSWERED_EXTERNALLY_TYPE:
+ return R.plurals.a11y_new_call_log_entry_answered_call;
+ case Calls.OUTGOING_TYPE:
+ return R.plurals.a11y_new_call_log_entry_outgoing_call;
+ case Calls.MISSED_TYPE:
+ return R.plurals.a11y_new_call_log_entry_missed_call;
+ case Calls.VOICEMAIL_TYPE:
+ throw new IllegalStateException("Voicemails not expected in call log");
+ case Calls.BLOCKED_TYPE:
+ return R.plurals.a11y_new_call_log_entry_blocked_call;
+ default:
+ // It is possible for users to end up with calls with unknown call types in their
+ // call history, possibly due to 3rd party call log implementations (e.g. to
+ // distinguish between rejected and missed calls). Instead of crashing, just
+ // assume that all unknown call types are missed calls.
+ return R.plurals.a11y_new_call_log_entry_missed_call;
+ }
+ }
+
+ private static CharSequence buildPhoneAccountDescription(Context context, CoalescedRow row) {
+ PhoneAccountHandle phoneAccountHandle =
+ TelecomUtil.composePhoneAccountHandle(
+ row.getPhoneAccountComponentName(), row.getPhoneAccountId());
+ if (phoneAccountHandle == null) {
+ return "";
+ }
+
+ String phoneAccountLabel = PhoneAccountUtils.getAccountLabel(context, phoneAccountHandle);
+ if (TextUtils.isEmpty(phoneAccountLabel)) {
+ return "";
+ }
+
+ if (TextUtils.isEmpty(row.getNumber().getNormalizedNumber())) {
+ return "";
+ }
+
+ return context
+ .getResources()
+ .getString(
+ R.string.a11y_new_call_log_entry_phone_account,
+ phoneAccountLabel,
+ row.getNumber().getNormalizedNumber());
+ }
+
+ private static CharSequence joinSecondaryTextComponents(List<CharSequence> components) {
+ return TextUtils.join(
+ ", ", Collections2.filter(components, (text) -> !TextUtils.isEmpty(text)));
+ }
+}