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