RobotMessage.java
Go to the documentation of this file.
00001 package com.riverlab.robotmanager.messages;
00002 
00003 import android.graphics.Bitmap;
00004 import android.graphics.BitmapFactory;
00005 import android.os.Parcel;
00006 import android.os.Parcelable;
00007 import android.util.Base64;
00008 
00009 public class RobotMessage implements Parcelable
00010 {
00011         private String sender;
00012         private String type;            //Text, Image, Video
00013         private String text;
00014         private Bitmap image;   
00015         private int priority;           //Zero means unimportant, One means important
00016         private String timestamp;
00017         
00018         public RobotMessage()
00019         {}
00020 
00021         public RobotMessage(String sender, String type, String text, int prioirty) 
00022         {
00023                 this.sender = sender;
00024                 this.type = type;
00025                 this.text = text;
00026         }
00027         
00028         public RobotMessage(String sender, String type, Bitmap img, int priority)
00029         {
00030                 this.sender = sender;
00031                 this.type = type;
00032                 this.image = image;
00033         }
00034         
00035     private RobotMessage(Parcel in) {
00036         sender = in.readString();
00037         type = in.readString();
00038         text = in.readString();
00039         image = (Bitmap)in.readParcelable(null);
00040     }
00041         
00042         public void fromByteArray(byte[] data)
00043         {
00044                 String strData = new String(data);
00045                 String[] parts = strData.split(";");
00046                 
00047                 setSender(parts[0]);
00048                 setType(parts[1]);
00049                 setText(parts[2]);
00050         }
00051         
00052         public byte[] toByteArray()
00053         {
00054                 String catString = getSender() + ";" + 
00055                                 getType() + ";" + 
00056                                 getText();
00057                 return catString.getBytes();
00058         }
00059 
00063         public String getSender() {
00064                 return sender;
00065         }
00066 
00070         public String getType() {
00071                 return type;
00072         }
00073 
00077         public String getText() {
00078                 return text;
00079         }
00080         
00081         public Bitmap getImage()
00082         {
00083                 return image;
00084         }
00085         
00089         public int getPriority() {
00090                 return priority;
00091         }
00092         
00093         public String getTimestamp() 
00094         {
00095                 return timestamp;
00096         }
00097 
00098 
00102         public void setSender(String sender) {
00103                 this.sender = sender;
00104         }
00105 
00109         public void setType(String type) {
00110                 this.type = type;
00111         }
00112 
00116         public void setText(String text) {
00117                 this.text = text;
00118         }
00119         //
00120         public void setImage(String encodedImage) {
00121                 byte[] decodedByte = Base64.decode(encodedImage, 0);
00122             this.image = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
00123         }
00124         
00128         public void setPriority(int priority) {
00129                 this.priority = priority;
00130         }
00131         
00132         public void setTimestamp(String timestamp)
00133         {
00134                 this.timestamp = timestamp;
00135         }
00136 
00137         @Override
00138         public int describeContents() {
00139                 // TODO Auto-generated method stub
00140                 return 0;
00141         }
00142 
00143         @Override
00144         public void writeToParcel(Parcel dest, int flags) 
00145         {
00146                 dest.writeString(sender);
00147                 dest.writeString(type);
00148                 dest.writeString(text);
00149         }
00150         
00151         public static final Parcelable.Creator<RobotMessage> CREATOR = new Parcelable.Creator<RobotMessage>() {
00152         public RobotMessage createFromParcel(Parcel in) {
00153             return new RobotMessage(in);
00154         }
00155 
00156         public RobotMessage[] newArray(int size) {
00157             return new RobotMessage[size];
00158         }
00159     };
00160 
00161 }


google_glass_driver
Author(s): Nicholas Otero
autogenerated on Fri Aug 28 2015 10:51:44