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