AbstractEvent.java
Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2005-2015 Team XBMC
00003  *      http://xbmc.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with XBMC Remote; see the file license.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00018  *  http://www.gnu.org/copyleft/gpl.html
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 }


smarthome_media_kodi_driver
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Thu Jun 6 2019 21:03:49