blob: 4aad07ba5a4f1a8b9b84784013f31f2108735394 [file] [log] [blame]
Paul Soulosb3054e52014-06-05 16:46:02 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.interactions;
17
Paul Soulosb3054e52014-06-05 16:46:02 -070018import android.content.ContentValues;
19import android.content.Context;
20import android.content.Intent;
21import android.graphics.drawable.Drawable;
22import android.net.Uri;
23import android.provider.Telephony.Sms;
Brian Attwellc62cc792014-10-02 12:35:07 -070024import android.text.BidiFormatter;
Walter Jang7ce53522014-10-29 13:26:43 -070025import android.text.Spannable;
Brian Attwellc62cc792014-10-02 12:35:07 -070026import android.text.TextDirectionHeuristics;
Paul Soulosb3054e52014-06-05 16:46:02 -070027
Gary Mai0a49afa2016-12-05 15:53:58 -080028import com.android.contacts.R;
29import com.android.contacts.util.ContactDisplayUtils;
30
Paul Soulosb3054e52014-06-05 16:46:02 -070031/**
32 * Represents an sms interaction, wrapping the columns in
33 * {@link android.provider.Telephony.Sms}.
34 */
35public class SmsInteraction implements ContactInteraction {
36
37 private static final String URI_TARGET_PREFIX = "smsto:";
John Shaobd9ef3c2016-12-15 12:42:03 -080038 private static final int SMS_ICON_RES = R.drawable.quantum_ic_message_vd_theme_24;
Brian Attwellc62cc792014-10-02 12:35:07 -070039 private static BidiFormatter sBidiFormatter = BidiFormatter.getInstance();
Paul Soulosb3054e52014-06-05 16:46:02 -070040
41 private ContentValues mValues;
42
43 public SmsInteraction(ContentValues values) {
44 mValues = values;
45 }
46
47 @Override
48 public Intent getIntent() {
Paul Soulos75d5a912014-06-24 11:22:37 -070049 String address = getAddress();
50 return address == null ? null : new Intent(Intent.ACTION_VIEW).setData(
51 Uri.parse(URI_TARGET_PREFIX + address));
Paul Soulosb3054e52014-06-05 16:46:02 -070052 }
53
54 @Override
Paul Soulosb3054e52014-06-05 16:46:02 -070055 public long getInteractionDate() {
Paul Soulos75d5a912014-06-24 11:22:37 -070056 Long date = getDate();
57 return date == null ? -1 : date;
Paul Soulosb3054e52014-06-05 16:46:02 -070058 }
59
60 @Override
61 public String getViewHeader(Context context) {
Paul Soulos9f3f8872014-08-20 17:02:16 -070062 String body = getBody();
63 if (getType() == Sms.MESSAGE_TYPE_SENT) {
64 body = context.getResources().getString(R.string.message_from_you_prefix, body);
65 }
66 return body;
Paul Soulosb3054e52014-06-05 16:46:02 -070067 }
68
69 @Override
70 public String getViewBody(Context context) {
71 return getAddress();
72 }
73
74 @Override
75 public String getViewFooter(Context context) {
Paul Soulos75d5a912014-06-24 11:22:37 -070076 Long date = getDate();
77 return date == null ? null : ContactInteractionUtil.formatDateStringFromTimestamp(
78 date, context);
Paul Soulosb3054e52014-06-05 16:46:02 -070079 }
80
81 @Override
82 public Drawable getIcon(Context context) {
83 return context.getResources().getDrawable(SMS_ICON_RES);
84 }
85
86 @Override
87 public Drawable getBodyIcon(Context context) {
88 return null;
89 }
90
91 @Override
92 public Drawable getFooterIcon(Context context) {
93 return null;
94 }
95
96 public String getAddress() {
Jay Shraunerb2215762014-10-22 09:02:53 -070097 final String address = mValues.getAsString(Sms.ADDRESS);
98 return address == null ? null :
99 sBidiFormatter.unicodeWrap(address, TextDirectionHeuristics.LTR);
Paul Soulosb3054e52014-06-05 16:46:02 -0700100 }
101
102 public String getBody() {
103 return mValues.getAsString(Sms.BODY);
104 }
105
Paul Soulos75d5a912014-06-24 11:22:37 -0700106 public Long getDate() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700107 return mValues.getAsLong(Sms.DATE);
108 }
109
110
Paul Soulos75d5a912014-06-24 11:22:37 -0700111 public Long getDateSent() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700112 return mValues.getAsLong(Sms.DATE_SENT);
113 }
114
Paul Soulos75d5a912014-06-24 11:22:37 -0700115 public Integer getErrorCode() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700116 return mValues.getAsInteger(Sms.ERROR_CODE);
117 }
118
Paul Soulos75d5a912014-06-24 11:22:37 -0700119 public Boolean getLocked() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700120 return mValues.getAsBoolean(Sms.LOCKED);
121 }
122
Paul Soulos75d5a912014-06-24 11:22:37 -0700123 public Integer getPerson() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700124 return mValues.getAsInteger(Sms.PERSON);
125 }
126
Paul Soulos75d5a912014-06-24 11:22:37 -0700127 public Integer getProtocol() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700128 return mValues.getAsInteger(Sms.PROTOCOL);
129 }
130
Paul Soulos75d5a912014-06-24 11:22:37 -0700131 public Boolean getRead() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700132 return mValues.getAsBoolean(Sms.READ);
133 }
134
Paul Soulos75d5a912014-06-24 11:22:37 -0700135 public Boolean getReplyPathPresent() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700136 return mValues.getAsBoolean(Sms.REPLY_PATH_PRESENT);
137 }
138
Paul Soulos75d5a912014-06-24 11:22:37 -0700139 public Boolean getSeen() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700140 return mValues.getAsBoolean(Sms.SEEN);
141 }
142
143 public String getServiceCenter() {
144 return mValues.getAsString(Sms.SERVICE_CENTER);
145 }
146
Paul Soulos75d5a912014-06-24 11:22:37 -0700147 public Integer getStatus() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700148 return mValues.getAsInteger(Sms.STATUS);
149 }
150
151 public String getSubject() {
152 return mValues.getAsString(Sms.SUBJECT);
153 }
154
Paul Soulos75d5a912014-06-24 11:22:37 -0700155 public Integer getThreadId() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700156 return mValues.getAsInteger(Sms.THREAD_ID);
157 }
158
Paul Soulos75d5a912014-06-24 11:22:37 -0700159 public Integer getType() {
Paul Soulosb3054e52014-06-05 16:46:02 -0700160 return mValues.getAsInteger(Sms.TYPE);
161 }
Paul Soulos23e28362014-08-29 14:57:08 -0700162
163 @Override
Walter Jang7ce53522014-10-29 13:26:43 -0700164 public Spannable getContentDescription(Context context) {
165 final String phoneNumber = getViewBody(context);
166 final String contentDescription = context.getResources().getString(
167 R.string.content_description_recent_sms,
168 getViewHeader(context), phoneNumber, getViewFooter(context));
169 return ContactDisplayUtils.getTelephoneTtsSpannable(contentDescription, phoneNumber);
Paul Soulos23e28362014-08-29 14:57:08 -0700170 }
Paul Soulos48290be2014-09-08 13:44:51 -0700171
172 @Override
173 public int getIconResourceId() {
174 return SMS_ICON_RES;
175 }
Paul Soulosb3054e52014-06-05 16:46:02 -0700176}