OSDN Git Service

video
[smackclient/smackclient.git] / app / src / main / java / cc / minsnail / beans / YgMessage.java
1 package cc.minsnail.beans;
2
3 import android.os.Parcel;
4 import android.os.Parcelable;
5
6 import org.jivesoftware.smack.packet.Message;
7
8 /**
9  * Created by yg on 2016/9/27.
10  */
11 public class YgMessage implements Parcelable {
12     private String to;
13     private String from;
14     private String type;
15     private String body;
16     private int custom;
17
18     public YgMessage() {
19     }
20
21     public void setBody(String body) {
22         this.body = body;
23     }
24
25     public void setTo(String to) {
26         this.to = to;
27     }
28
29     public void setFrom(String from) {
30         this.from = from;
31     }
32
33     public void setType(String type) {
34         this.type = type;
35     }
36
37     public void setCustom(int isCustom) {
38         this.custom = isCustom;
39     }
40
41     public String getBody() {
42         return body;
43     }
44
45     public String getFrom() {
46         return from;
47     }
48
49     public String getTo() {
50         return to;
51     }
52
53     public String getType() {
54         return type;
55     }
56
57     public int getCustom() {
58         return custom;
59     }
60
61     public YgMessage getFromMessage(Message message) {
62         this.setTo(message.getTo());
63         this.setFrom(message.getFrom());
64         this.setBody(message.getBody());
65         this.setType(message.getType().toString());
66         return this;
67     }
68
69     protected YgMessage(Parcel in) {
70         this.to = in.readString();
71         this.from = in.readString();
72         this.type = in.readString();
73         this.body = in.readString();
74         this.custom = in.readInt();
75     }
76
77     public static final Creator<YgMessage> CREATOR = new Creator<YgMessage>() {
78         @Override
79         public YgMessage createFromParcel(Parcel in) {
80             return new YgMessage(in);
81         }
82
83         @Override
84         public YgMessage[] newArray(int size) {
85             return new YgMessage[size];
86         }
87     };
88
89     @Override
90     public int describeContents() {
91         return 0;
92     }
93
94     @Override
95     public void writeToParcel(Parcel parcel, int i) {
96         parcel.writeString(this.to);
97         parcel.writeString(this.from);
98         parcel.writeString(this.type);
99         parcel.writeString(this.body);
100         parcel.writeInt(this.custom);
101     }
102
103     public String toJson() {
104         return "{\"to\":" + to + ",\"from\":" + from + ",\"body\":" + body + ",\"type\":" + type + "}";
105     }
106 }