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 import org.xbmc.android.jsonrpc.api.model.GlobalModel;
00026
00027 import android.os.Parcel;
00028 import android.os.Parcelable;
00029
00035 public class PlayerEvent {
00036
00037
00038
00039
00040
00045 public static class Play extends AbstractEvent {
00046 public final static int ID = 0x01;
00047 public final static String METHOD = "Player.OnPlay";
00048 public final Data data;
00049 public Play(ObjectNode node) {
00050 super(node);
00051 data = new Data((ObjectNode)node.get("data"));
00052 }
00053 protected Play(Parcel parcel) {
00054 super(parcel);
00055 data = parcel.<Data>readParcelable(Data.class.getClassLoader());
00056 }
00057 @Override
00058 public int describeContents() {
00059 return 0;
00060 }
00061 @Override
00062 public void writeToParcel(Parcel parcel, int flags) {
00063 super.writeToParcel(parcel, flags);
00064 parcel.writeParcelable(data, flags);
00065 }
00066 @Override
00067 public String toString() {
00068 return "PLAY: Item " + data.item + " with player " + data.player.playerId + " at speed " + data.player.speed + ".";
00069 }
00070 public static final Parcelable.Creator<Play> CREATOR = new Parcelable.Creator<Play>() {
00071 @Override
00072 public Play createFromParcel(Parcel parcel) {
00073 return new Play(parcel);
00074 }
00075 @Override
00076 public Play[] newArray(int n) {
00077 return new Play[n];
00078 }
00079 };
00080 @Override
00081 public int getId() {
00082 return ID;
00083 }
00084 }
00085
00090 public static class Pause extends AbstractEvent {
00091 public final static int ID = 0x02;
00092 public final static String METHOD = "Player.OnPause";
00093 public final Data data;
00094 public Pause(ObjectNode node) {
00095 super(node);
00096 data = new Data((ObjectNode)node.get("data"));
00097 }
00098 protected Pause(Parcel parcel) {
00099 super(parcel);
00100 data = parcel.<Data>readParcelable(Data.class.getClassLoader());
00101 }
00102 @Override
00103 public String toString() {
00104 return "PAUSE: Item " + data.item + " with player " + data.player.playerId + " at speed " + data.player.speed + ".";
00105 }
00106 @Override
00107 public int describeContents() {
00108 return 0;
00109 }
00110 @Override
00111 public void writeToParcel(Parcel parcel, int flags) {
00112 parcel.writeParcelable(data, flags);
00113 }
00114 @Override
00115 public int getId() {
00116 return ID;
00117 }
00118 public static final Parcelable.Creator<Pause> CREATOR = new Parcelable.Creator<Pause>() {
00119 @Override
00120 public Pause createFromParcel(Parcel parcel) {
00121 return new Pause(parcel);
00122 }
00123 @Override
00124 public Pause[] newArray(int n) {
00125 return new Pause[n];
00126 }
00127 };
00128 }
00129
00134 public static class Stop extends AbstractEvent {
00135 public final static int ID = 0x03;
00136 public final static String METHOD = "Player.OnStop";
00137 public final Data data;
00138 public Stop(ObjectNode node) {
00139 super(node);
00140 data = new Data((ObjectNode)node.get("data"));
00141 }
00142 protected Stop(Parcel parcel) {
00143 super(parcel);
00144 data = parcel.<Data>readParcelable(Data.class.getClassLoader());
00145 }
00146 @Override
00147 public String toString() {
00148 return "STOP: Item " + data.item + ".";
00149 }
00150 @Override
00151 public int describeContents() {
00152 return 0;
00153 }
00154 @Override
00155 public void writeToParcel(Parcel parcel, int flags) {
00156 parcel.writeParcelable(data, flags);
00157 }
00158 public static final Parcelable.Creator<Stop> CREATOR = new Parcelable.Creator<Stop>() {
00159 @Override
00160 public Stop createFromParcel(Parcel parcel) {
00161 return new Stop(parcel);
00162 }
00163 @Override
00164 public Stop[] newArray(int n) {
00165 return new Stop[n];
00166 }
00167 };
00168 @Override
00169 public int getId() {
00170 return ID;
00171 }
00172 public static class Data implements Parcelable {
00173 public final Item item;
00174 public Data(ObjectNode node) {
00175 item = new Item((ObjectNode)node.get("item"));
00176 }
00177 protected Data(Parcel parcel) {
00178 item = parcel.<Item>readParcelable(Item.class.getClassLoader());
00179 }
00180 @Override
00181 public int describeContents() {
00182 return 0;
00183 }
00184 @Override
00185 public void writeToParcel(Parcel parcel, int flags) {
00186 parcel.writeParcelable(item, flags);
00187 }
00188 public static final Parcelable.Creator<Data> CREATOR = new Parcelable.Creator<Data>() {
00189 @Override
00190 public Data createFromParcel(Parcel parcel) {
00191 return new Data(parcel);
00192 }
00193 @Override
00194 public Data[] newArray(int n) {
00195 return new Data[n];
00196 }
00197 };
00198 }
00199 }
00200
00205 public static class SpeedChanged extends AbstractEvent {
00206 public final static int ID = 0x04;
00207 public final static String METHOD = "Player.OnSpeedChanged";
00208 public final Data data;
00209 public SpeedChanged(ObjectNode node) {
00210 super(node);
00211 data = new Data((ObjectNode)node.get("data"));
00212 }
00213 public SpeedChanged(Parcel parcel) {
00214 super(parcel);
00215 data = parcel.<Data>readParcelable(Data.class.getClassLoader());
00216 }
00217 @Override
00218 public String toString() {
00219 return "SPEED-CHANGE: Item " + data.item + " with player " + data.player.playerId + " at speed " + data.player.speed + ".";
00220 }
00221 @Override
00222 public int describeContents() {
00223 return 0;
00224 }
00225 @Override
00226 public void writeToParcel(Parcel parcel, int flags) {
00227 parcel.writeParcelable(data, flags);
00228 }
00229 public static final Parcelable.Creator<SpeedChanged> CREATOR = new Parcelable.Creator<SpeedChanged>() {
00230 @Override
00231 public SpeedChanged createFromParcel(Parcel parcel) {
00232 return new SpeedChanged(parcel);
00233 }
00234 @Override
00235 public SpeedChanged[] newArray(int n) {
00236 return new SpeedChanged[n];
00237 }
00238 };
00239 @Override
00240 public int getId() {
00241 return ID;
00242 }
00243 }
00244
00249 public static class Seek extends AbstractEvent {
00250 public final static int ID = 0x05;
00251 public final static String METHOD = "Player.OnSeek";
00252 public final Data data;
00253 public Seek(ObjectNode node) {
00254 super(node);
00255 data = new Data((ObjectNode)node.get("data"));
00256 }
00257 public Seek(Parcel parcel) {
00258 super(parcel);
00259 data = parcel.<Data>readParcelable(Data.class.getClassLoader());
00260 }
00261
00262 @Override
00263 public String toString() {
00264 return "SEEK: Item " + data.item + " with player " + data.player.playerId + " to " + data.player.time + " at " + data.player.seekoffset + ".";
00265 }
00266 @Override
00267 public int describeContents() {
00268 return 0;
00269 }
00270 @Override
00271 public void writeToParcel(Parcel parcel, int flags) {
00272 parcel.writeParcelable(data, flags);
00273 }
00274 public static final Parcelable.Creator<Seek> CREATOR = new Parcelable.Creator<Seek>() {
00275 @Override
00276 public Seek createFromParcel(Parcel parcel) {
00277 return new Seek(parcel);
00278 }
00279 @Override
00280 public Seek[] newArray(int n) {
00281 return new Seek[n];
00282 }
00283 };
00284 @Override
00285 public int getId() {
00286 return ID;
00287 }
00288 public static class Data implements Parcelable {
00289 public final Item item;
00290 public final PlayerSeek player;
00291 public Data (ObjectNode node) {
00292 item = new Item((ObjectNode)node.get("item"));
00293 player = new PlayerSeek((ObjectNode)node.get("player"));
00294 }
00295 public Data (Parcel parcel) {
00296 item = parcel.<Item>readParcelable(Item.class.getClassLoader());
00297 player = parcel.<PlayerSeek>readParcelable(PlayerSeek.class.getClassLoader());
00298 }
00299 @Override
00300 public int describeContents() {
00301 return 0;
00302 }
00303 @Override
00304 public void writeToParcel(Parcel parcel, int flags) {
00305 parcel.writeParcelable(item, flags);
00306 parcel.writeParcelable(player, flags);
00307 }
00308 public static final Parcelable.Creator<Data> CREATOR = new Parcelable.Creator<Data>() {
00309 @Override
00310 public Data createFromParcel(Parcel parcel) {
00311 return new Data(parcel);
00312 }
00313 @Override
00314 public Data[] newArray(int n) {
00315 return new Data[n];
00316 }
00317 };
00318 }
00319 }
00320
00321
00322
00323
00324
00325
00326 public static class Data implements Parcelable {
00327 public final static String TYPE = "Player.Notifications.Data";
00328 public final Item item;
00329 public final Player player;
00330 public Data (ObjectNode node) {
00331 item = new Item((ObjectNode)node.get("item"));
00332 player = new Player((ObjectNode)node.get("player"));
00333 }
00334 public Data (Parcel parcel) {
00335 item = parcel.<Item>readParcelable(Item.class.getClassLoader());
00336 player = parcel.<Player>readParcelable(Player.class.getClassLoader());
00337 }
00338 @Override
00339 public int describeContents() {
00340 return 0;
00341 }
00342 @Override
00343 public void writeToParcel(Parcel parcel, int flags) {
00344 parcel.writeParcelable(item, flags);
00345 parcel.writeParcelable(player, flags);
00346 }
00347 public static final Parcelable.Creator<Data> CREATOR = new Parcelable.Creator<Data>() {
00348 @Override
00349 public Data createFromParcel(Parcel parcel) {
00350 return new Data(parcel);
00351 }
00352 @Override
00353 public Data[] newArray(int n) {
00354 return new Data[n];
00355 }
00356 };
00357 }
00358
00359 public static class Item implements Parcelable {
00360 public final static String TYPE = "Player.Notifications.Item";
00361 public final int type;
00362 public final int id;
00363 public final String title;
00364 public final int year;
00365 public final int episode;
00366 public final int season;
00367 public final String showtitle;
00368 public final String album;
00369 public final String artist;
00370 public final int track;
00371 public Item (ObjectNode node) {
00372 type = Type.parse(node.get("type").getTextValue());
00373 id = AbstractEvent.parseInt(node, "id");
00374 title = AbstractEvent.parseString(node, "title");
00375 year = AbstractEvent.parseInt(node, "year");
00376 episode = AbstractEvent.parseInt(node, "episode");
00377 season = AbstractEvent.parseInt(node, "season");
00378 showtitle = AbstractEvent.parseString(node, "showtitle");
00379 album = AbstractEvent.parseString(node, "album");
00380 artist = AbstractEvent.parseString(node, "artist");
00381 track = AbstractEvent.parseInt(node, "track");
00382 }
00383 public Item (Parcel parcel) {
00384 type = parcel.readInt();
00385 id = parcel.readInt();
00386 title = parcel.readString();
00387 year = parcel.readInt();
00388 episode = parcel.readInt();
00389 season = parcel.readInt();
00390 showtitle = parcel.readString();
00391 album = parcel.readString();
00392 artist = parcel.readString();
00393 track = parcel.readInt();
00394 }
00395 @Override
00396 public String toString() {
00397 return Type.stringValue(type) + "(" + id + ")";
00398
00399 }
00400 @Override
00401 public int describeContents() {
00402 return 0;
00403 }
00404 @Override
00405 public void writeToParcel(Parcel parcel, int flags) {
00406 parcel.writeInt(type);
00407 parcel.writeInt(id);
00408 parcel.writeString(title);
00409 parcel.writeInt(year);
00410 parcel.writeInt(episode);
00411 parcel.writeInt(season);
00412 parcel.writeString(showtitle);
00413 parcel.writeString(album);
00414 parcel.writeString(artist);
00415 parcel.writeInt(track);
00416 }
00417 public static final Parcelable.Creator<Item> CREATOR = new Parcelable.Creator<Item>() {
00418 @Override
00419 public Item createFromParcel(Parcel parcel) {
00420 return new Item(parcel);
00421 }
00422 @Override
00423 public Item[] newArray(int n) {
00424 return new Item[n];
00425 }
00426 };
00427
00428 public static class Type {
00429 public static final int UNKNOWN = 0x00;
00430 public static final int MOVIE = 0x01;
00431 public static final int EPISODE = 0x02;
00432 public static final int MUSICVIDEO = 0x03;
00433 public static final int SONG = 0x04;
00434 public static int parse(String type) {
00435 if (type.equals("unknown")) {
00436 return UNKNOWN;
00437 } else if (type.equals("movie")) {
00438 return MOVIE;
00439 } else if (type.equals("episode")) {
00440 return EPISODE;
00441 } else if (type.equals("musicvideo")) {
00442 return MUSICVIDEO;
00443 } else if (type.equals("song")) {
00444 return SONG;
00445 } else {
00446 return UNKNOWN;
00447 }
00448 }
00449 public static String stringValue(int type) {
00450 switch (type) {
00451 case MOVIE: return "Movie";
00452 case EPISODE: return "Episode";
00453 case MUSICVIDEO: return "Musicvideo";
00454 case SONG: return "Song";
00455 case UNKNOWN:
00456 default: return "Unknown";
00457 }
00458 }
00459 }
00460 }
00461
00462 public static class Player implements Parcelable {
00463 public final static String TYPE = "Player.Notifications.Player";
00464 public final int playerId;
00465 public final int speed;
00466 public Player (ObjectNode node) {
00467 playerId = node.get("playerid").getIntValue();
00468 speed = node.get("speed").getValueAsInt(0);
00469 }
00470 protected Player(Parcel parcel) {
00471 playerId = parcel.readInt();
00472 speed = parcel.readInt();
00473 }
00474 @Override
00475 public int describeContents() {
00476 return 0;
00477 }
00478 @Override
00479 public void writeToParcel(Parcel parcel, int flags) {
00480 parcel.writeInt(playerId);
00481 parcel.writeInt(speed);
00482 }
00483 public static final Parcelable.Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
00484 @Override
00485 public Player createFromParcel(Parcel parcel) {
00486 return new Player(parcel);
00487 }
00488 @Override
00489 public Player[] newArray(int n) {
00490 return new Player[n];
00491 }
00492 };
00493 }
00494
00495 public static class PlayerSeek extends Player {
00496 public final static String TYPE = "Player.Notifications.Player.Seek";
00497 public final GlobalModel.Time time;
00498 public final GlobalModel.Time seekoffset;
00499 public PlayerSeek(ObjectNode node) {
00500 super(node);
00501 time = new GlobalModel.Time((ObjectNode)node.get("time"));
00502 seekoffset = new GlobalModel.Time((ObjectNode)node.get("seekoffset"));
00503 }
00504 protected PlayerSeek(Parcel parcel) {
00505 super(parcel);
00506 time = parcel.<GlobalModel.Time>readParcelable(GlobalModel.Time.class.getClassLoader());
00507 seekoffset = parcel.<GlobalModel.Time>readParcelable(GlobalModel.Time.class.getClassLoader());
00508 }
00509 @Override
00510 public void writeToParcel(Parcel parcel, int flags) {
00511 super.writeToParcel(parcel, flags);
00512 parcel.writeParcelable(time, flags);
00513 parcel.writeParcelable(seekoffset, flags);
00514 }
00515 public static final Parcelable.Creator<PlayerSeek> CREATOR = new Parcelable.Creator<PlayerSeek>() {
00516 @Override
00517 public PlayerSeek createFromParcel(Parcel parcel) {
00518 return new PlayerSeek(parcel);
00519 }
00520 @Override
00521 public PlayerSeek[] newArray(int n) {
00522 return new PlayerSeek[n];
00523 }
00524 };
00525 }
00526
00527 }