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