Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package org.xbmc.android.jsonrpc.notification;
00023
00024 import org.codehaus.jackson.node.ObjectNode;
00025
00026 import android.os.Parcel;
00027 import android.os.Parcelable;
00028
00034 public abstract class AbstractEvent implements Parcelable {
00035
00036 public final String sender;
00037
00038 public AbstractEvent(ObjectNode node) {
00039 sender = node.get("sender").getTextValue();
00040 }
00041 protected AbstractEvent(Parcel parcel) {
00042 sender = parcel.readString();
00043 }
00044
00045 public abstract int getId();
00046
00052 public static AbstractEvent parse(ObjectNode node) {
00053 final String method = node.get("method").getTextValue();
00054 final ObjectNode params = (ObjectNode)node.get("params");
00055 if (method.equals(PlayerEvent.Play.METHOD)) {
00056 return new PlayerEvent.Play(params);
00057 } else if (method.equals(PlayerEvent.Pause.METHOD)) {
00058 return new PlayerEvent.Pause(params);
00059 } else if (method.equals(PlayerEvent.Stop.METHOD)) {
00060 return new PlayerEvent.Stop(params);
00061 } else if (method.equals(PlayerEvent.SpeedChanged.METHOD)) {
00062 return new PlayerEvent.SpeedChanged(params);
00063 } else if (method.equals(PlayerEvent.Seek.METHOD)) {
00064 return new PlayerEvent.Seek(params);
00065 } else if (method.equals(SystemEvent.Quit.METHOD)) {
00066 return new SystemEvent.Quit(params);
00067 } else if (method.equals(SystemEvent.Restart.METHOD)) {
00068 return new SystemEvent.Restart(params);
00069 } else if (method.equals(SystemEvent.Wake.METHOD)) {
00070 return new SystemEvent.Wake(params);
00071 } else if (method.equals(SystemEvent.LowBattery.METHOD)) {
00072 return new SystemEvent.LowBattery(params);
00073 } else{
00074 return null;
00075 }
00076 }
00077
00078 public static int parseInt(ObjectNode node, String key) {
00079 return node.has(key) ? node.get(key).getIntValue() : -1;
00080 }
00081
00082 public static String parseString(ObjectNode node, String key) {
00083 return node.has(key) ? node.get(key).getTextValue() : null;
00084 }
00085
00086 @Override
00087 public void writeToParcel(Parcel parcel, int flags) {
00088 parcel.writeString(sender);
00089 }
00090
00091 }