1 /*
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  */
16 
17 package com.android.bluetooth.mapclient;
18 
19 import com.android.vcard.VCardEntry;
20 
21 import org.json.JSONException;
22 import org.json.JSONObject;
23 
24 import java.util.ArrayList;
25 
26 /**
27  * Object representation of message in bMessage format
28  *
29  * <p>This object will be received in {@link MasClient#EVENT_GET_MESSAGE} callback message.
30  */
31 public class Bmessage {
32 
33     String mBmsgVersion;
34     Status mBmsgStatus;
35     Type mBmsgType;
36     String mBmsgFolder;
37 
38     String mBbodyEncoding;
39     String mBbodyCharset;
40     String mBbodyLanguage;
41     int mBbodyLength;
42 
43     String mMessage;
44 
45     ArrayList<VCardEntry> mOriginators;
46     ArrayList<VCardEntry> mRecipients;
47 
48     /** Constructs empty message object */
Bmessage()49     public Bmessage() {
50         mOriginators = new ArrayList<VCardEntry>();
51         mRecipients = new ArrayList<VCardEntry>();
52     }
53 
getOriginator()54     public VCardEntry getOriginator() {
55         if (mOriginators.size() > 0) {
56             return mOriginators.get(0);
57         } else {
58             return null;
59         }
60     }
61 
getOriginators()62     public ArrayList<VCardEntry> getOriginators() {
63         return mOriginators;
64     }
65 
addOriginator(VCardEntry vcard)66     public Bmessage addOriginator(VCardEntry vcard) {
67         mOriginators.add(vcard);
68         return this;
69     }
70 
getRecipients()71     public ArrayList<VCardEntry> getRecipients() {
72         return mRecipients;
73     }
74 
addRecipient(VCardEntry vcard)75     public Bmessage addRecipient(VCardEntry vcard) {
76         mRecipients.add(vcard);
77         return this;
78     }
79 
getStatus()80     public Status getStatus() {
81         return mBmsgStatus;
82     }
83 
setStatus(Status status)84     public Bmessage setStatus(Status status) {
85         mBmsgStatus = status;
86         return this;
87     }
88 
getType()89     public Type getType() {
90         return mBmsgType;
91     }
92 
setType(Type type)93     public Bmessage setType(Type type) {
94         mBmsgType = type;
95         return this;
96     }
97 
getFolder()98     public String getFolder() {
99         return mBmsgFolder;
100     }
101 
setFolder(String folder)102     public Bmessage setFolder(String folder) {
103         mBmsgFolder = folder;
104         return this;
105     }
106 
getEncoding()107     public String getEncoding() {
108         return mBbodyEncoding;
109     }
110 
setEncoding(String encoding)111     public Bmessage setEncoding(String encoding) {
112         mBbodyEncoding = encoding;
113         return this;
114     }
115 
getCharset()116     public String getCharset() {
117         return mBbodyCharset;
118     }
119 
setCharset(String charset)120     public Bmessage setCharset(String charset) {
121         mBbodyCharset = charset;
122         return this;
123     }
124 
getLanguage()125     public String getLanguage() {
126         return mBbodyLanguage;
127     }
128 
setLanguage(String language)129     public Bmessage setLanguage(String language) {
130         mBbodyLanguage = language;
131         return this;
132     }
133 
getBodyContent()134     public String getBodyContent() {
135         return mMessage;
136     }
137 
setBodyContent(String body)138     public Bmessage setBodyContent(String body) {
139         mMessage = body;
140         return this;
141     }
142 
143     @Override
toString()144     public String toString() {
145         JSONObject json = new JSONObject();
146 
147         try {
148             json.put("status", mBmsgStatus);
149             json.put("type", mBmsgType);
150             json.put("folder", mBmsgFolder);
151             json.put("charset", mBbodyCharset);
152             json.put("message", mMessage);
153         } catch (JSONException e) {
154             // do nothing
155         }
156 
157         return json.toString();
158     }
159 
160     public enum Status {
161         READ,
162         UNREAD
163     }
164 
165     public enum Type {
166         EMAIL,
167         SMS_GSM,
168         SMS_CDMA,
169         MMS
170     }
171 }
172