BluetoothMapMessageListingElement.java revision 5a60e47497f21f64e6d79420dc4c56c1907df22a
1/*
2* Copyright (C) 2013 Samsung System LSI
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7*      http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15package com.android.bluetooth.map;
16
17import java.io.IOException;
18import java.io.StringWriter;
19
20import java.text.SimpleDateFormat;
21import java.util.Date;
22
23import org.xmlpull.v1.XmlSerializer;
24
25import android.telephony.PhoneNumberUtils;
26import android.util.Log;
27import android.util.Xml;
28
29import com.android.bluetooth.map.BluetoothMapUtils.TYPE;
30
31public class BluetoothMapMessageListingElement
32    implements Comparable<BluetoothMapMessageListingElement> {
33
34    private static final String TAG = "BluetoothMapMessageListingElement";
35    private static final boolean D = false;
36    private static final boolean V = false;
37
38    private long mCpHandle = 0; /* The content provider handle - without type information */
39    private String mSubject = null;
40    private long mDateTime = 0;
41    private String mSenderName = null;
42    private String mSenderAddressing = null;
43    private String mReplytoAddressing = null;
44    private String mRecipientName = null;
45    private String mRecipientAddressing = null;
46    private TYPE mType = null;
47    private boolean mMsgTypeAppParamSet = false;
48    private int mSize = -1;
49    private String mText = null;
50    private String mReceptionStatus = null;
51    private String mDeliveryStatus = null;
52    private int mAttachmentSize = -1;
53    private String mPriority = null;
54    private boolean mRead = false;
55    private String mSent = null;
56    private String mProtect = null;
57    private String mFolderType = null;
58    private String mThreadId = null;
59    private String mThreadName = null;
60    private String mAttachmentMimeTypes = null;
61
62    private boolean mReportRead = false;
63    private int mCursorIndex = 0;
64
65    public int getCursorIndex() {
66        return mCursorIndex;
67    }
68
69    public void setCursorIndex(int cursorIndex) {
70        this.mCursorIndex = cursorIndex;
71    }
72
73    public long getHandle() {
74        return mCpHandle;
75    }
76
77    public void setHandle(long handle) {
78        this.mCpHandle = handle;
79    }
80
81    public long getDateTime() {
82        return mDateTime;
83    }
84
85    public String getDateTimeString() {
86        /* TODO: if the feature bit mask of the client supports it, add the time-zone
87         *       (as for MSETime) */
88        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
89        Date date = new Date(mDateTime);
90        return format.format(date); // Format to YYYYMMDDTHHMMSS local time
91    }
92
93    public void setDateTime(long dateTime) {
94        this.mDateTime = dateTime;
95    }
96
97    public String getSubject() {
98        return mSubject;
99    }
100
101    public void setSubject(String subject) {
102        this.mSubject = subject;
103    }
104
105    public String getSenderName() {
106        return mSenderName;
107    }
108
109    public void setSenderName(String senderName) {
110        this.mSenderName = senderName;
111    }
112
113    public String getSenderAddressing() {
114        return mSenderAddressing;
115    }
116
117    public void setSenderAddressing(String senderAddressing) {
118        this.mSenderAddressing = senderAddressing;
119    }
120
121    public String getReplyToAddressing() {
122        return mReplytoAddressing;
123    }
124
125    public void setReplytoAddressing(String replytoAddressing) {
126        this.mReplytoAddressing = replytoAddressing;
127    }
128
129    public String getRecipientName() {
130        return mRecipientName;
131    }
132
133    public void setRecipientName(String recipientName) {
134        this.mRecipientName = recipientName;
135    }
136
137    public String getRecipientAddressing() {
138        return mRecipientAddressing;
139    }
140
141    public void setRecipientAddressing(String recipientAddressing) {
142        this.mRecipientAddressing = recipientAddressing;
143    }
144
145    public TYPE getType() {
146        return mType;
147    }
148
149    public void setType(TYPE type, boolean appParamSet) {
150        this.mMsgTypeAppParamSet = appParamSet;
151        this.mType = type;
152    }
153
154    public int getSize() {
155        return mSize;
156    }
157
158    public void setSize(int size) {
159        this.mSize = size;
160    }
161
162    public String getText() {
163        return mText;
164    }
165
166    public void setText(String text) {
167        this.mText = text;
168    }
169
170    public String getReceptionStatus() {
171        return mReceptionStatus;
172    }
173
174    public void setReceptionStatus(String receptionStatus) {
175        this.mReceptionStatus = receptionStatus;
176    }
177
178    public String getDeliveryStatus() {
179        return mDeliveryStatus;
180    }
181
182    public void setDeliveryStatus(String deliveryStatus) {
183        this.mDeliveryStatus = deliveryStatus;
184    }
185
186    public int getAttachmentSize() {
187        return mAttachmentSize;
188    }
189
190    public void setAttachmentSize(int attachmentSize) {
191        this.mAttachmentSize = attachmentSize;
192    }
193
194    public String getAttachmentMimeTypes() {
195        return mAttachmentMimeTypes;
196    }
197
198    public void setAttachmentMimeTypes(String attachmentMimeTypes) {
199        this.mAttachmentMimeTypes = attachmentMimeTypes;
200    }
201
202    public String getPriority() {
203        return mPriority;
204    }
205
206    public void setPriority(String priority) {
207        this.mPriority = priority;
208    }
209
210    public String getRead() {
211        return (mRead?"yes":"no");
212    }
213    public boolean getReadBool() {
214        return mRead;
215    }
216    public void setRead(boolean read, boolean reportRead) {
217        this.mRead = read;
218        this.mReportRead = reportRead;
219    }
220
221    public String getSent() {
222        return mSent;
223    }
224
225    public void setSent(String sent) {
226        this.mSent = sent;
227    }
228
229    public String getProtect() {
230        return mProtect;
231    }
232
233    public void setProtect(String protect) {
234        this.mProtect = protect;
235    }
236
237    public void setThreadId(long threadId, TYPE type) {
238        if(threadId != -1) {
239            this.mThreadId = BluetoothMapUtils.getMapConvoHandle(threadId, type);
240        }
241    }
242
243    public String getThreadName() {
244        return mThreadName;
245    }
246
247    public void setThreadName(String name) {
248        this.mThreadName = name;
249    }
250
251    public String getFolderType() {
252        return mFolderType;
253    }
254
255    public void setFolderType(String folderType) {
256        this.mFolderType = folderType;
257    }
258
259    public int compareTo(BluetoothMapMessageListingElement e) {
260        if (this.mDateTime < e.mDateTime) {
261            return 1;
262        } else if (this.mDateTime > e.mDateTime) {
263            return -1;
264        } else {
265            return 0;
266        }
267    }
268
269    /* Encode the MapMessageListingElement into the StringBuilder reference.
270     * */
271    public void encode(XmlSerializer xmlMsgElement, boolean includeThreadId)
272            throws IllegalArgumentException, IllegalStateException, IOException
273    {
274            // contruct the XML tag for a single msg in the msglisting
275            xmlMsgElement.startTag(null, "msg");
276            xmlMsgElement.attribute(null, "handle",
277                    BluetoothMapUtils.getMapHandle(mCpHandle, mType));
278            if(mSubject != null){
279                String stripped = BluetoothMapUtils.stripInvalidChars(mSubject);
280                xmlMsgElement.attribute(null, "subject",
281                        stripped.substring(0,  stripped.length() < 256 ? stripped.length() : 256));
282            }
283            if(mDateTime != 0)
284                xmlMsgElement.attribute(null, "datetime", this.getDateTimeString());
285            if(mSenderName != null)
286                xmlMsgElement.attribute(null, "sender_name",
287                        BluetoothMapUtils.stripInvalidChars(mSenderName));
288            if(mSenderAddressing != null)
289                xmlMsgElement.attribute(null, "sender_addressing", mSenderAddressing);
290            if(mReplytoAddressing != null)
291                xmlMsgElement.attribute(null, "replyto_addressing",mReplytoAddressing);
292            if(mRecipientName != null)
293                xmlMsgElement.attribute(null, "recipient_name",
294                        BluetoothMapUtils.stripInvalidChars(mRecipientName));
295            if(mRecipientAddressing != null)
296                xmlMsgElement.attribute(null, "recipient_addressing", mRecipientAddressing);
297            if(mMsgTypeAppParamSet == true)
298                xmlMsgElement.attribute(null, "type", mType.name());
299            if(mSize != -1)
300                xmlMsgElement.attribute(null, "size", Integer.toString(mSize));
301            if(mText != null)
302                xmlMsgElement.attribute(null, "text", mText);
303            if(mReceptionStatus != null)
304                xmlMsgElement.attribute(null, "reception_status", mReceptionStatus);
305            if(mDeliveryStatus != null)
306                xmlMsgElement.attribute(null, "delivery_status", mDeliveryStatus);
307            if(mAttachmentSize != -1)
308                xmlMsgElement.attribute(null, "attachment_size",
309                        Integer.toString(mAttachmentSize));
310            if(mAttachmentMimeTypes != null)
311                xmlMsgElement.attribute(null, "attachment_mime_types", mAttachmentMimeTypes);
312            if(mPriority != null)
313                xmlMsgElement.attribute(null, "priority", mPriority);
314            if(mReportRead)
315                xmlMsgElement.attribute(null, "read", getRead());
316            if(mSent != null)
317                xmlMsgElement.attribute(null, "sent", mSent);
318            if(mProtect != null)
319                xmlMsgElement.attribute(null, "protected", mProtect);
320            if(mThreadId != null && includeThreadId == true)
321                xmlMsgElement.attribute(null, "conversation_id", mThreadId);
322            if(mThreadName != null && includeThreadId == true)
323                xmlMsgElement.attribute(null, "conversation_name", mThreadName);
324            if(mFolderType != null )
325                xmlMsgElement.attribute(null, "folder_type", mFolderType);
326            xmlMsgElement.endTag(null, "msg");
327
328    }
329}
330
331
332