GlobalModel.java
Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2005-2013 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 package org.xbmc.android.jsonrpc.api.model;
00022 
00023 import android.os.Parcel;
00024 import android.os.Parcelable;
00025 import java.util.ArrayList;
00026 import java.util.Arrays;
00027 import java.util.HashSet;
00028 import java.util.List;
00029 import java.util.Set;
00030 import org.codehaus.jackson.JsonNode;
00031 import org.codehaus.jackson.node.ArrayNode;
00032 import org.codehaus.jackson.node.BooleanNode;
00033 import org.codehaus.jackson.node.ObjectNode;
00034 import org.codehaus.jackson.node.TextNode;
00035 import org.xbmc.android.jsonrpc.api.AbstractModel;
00036 
00037 public final class GlobalModel {
00038 
00045         public static class Time extends AbstractModel {
00046                 public final static String API_TYPE = "Global.Time";
00047 
00048                 // field names
00049                 public static final String HOURS = "hours";
00050                 public static final String MILLISECONDS = "milliseconds";
00051                 public static final String MINUTES = "minutes";
00052                 public static final String SECONDS = "seconds";
00053 
00054                 // class members
00055                 public final Integer hours;
00056                 public final Integer milliseconds;
00057                 public final Integer minutes;
00058                 public final Integer seconds;
00059 
00066                 public Time(Integer hours, Integer milliseconds, Integer minutes, Integer seconds) {
00067                         this.hours = hours;
00068                         this.milliseconds = milliseconds;
00069                         this.minutes = minutes;
00070                         this.seconds = seconds;
00071                 }
00072 
00077                 public long getMilliseconds() {
00078                         return hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds;
00079                 }
00080 
00085                 public Time(JsonNode node) {
00086                         hours = node.get(HOURS).getIntValue(); // required value
00087                         milliseconds = node.get(MILLISECONDS).getIntValue(); // required value
00088                         minutes = node.get(MINUTES).getIntValue(); // required value
00089                         seconds = node.get(SECONDS).getIntValue(); // required value
00090                 }
00091 
00092                 @Override
00093                 public JsonNode toJsonNode() {
00094                         final ObjectNode node = OM.createObjectNode();
00095                         node.put(HOURS, hours);
00096                         node.put(MILLISECONDS, milliseconds);
00097                         node.put(MINUTES, minutes);
00098                         node.put(SECONDS, seconds);
00099                         return node;
00100                 }
00101 
00107                 static List<Time> getGlobalModelTimeList(JsonNode node, String key) {
00108                         if (node.has(key)) {
00109                                 final ArrayNode a = (ArrayNode)node.get(key);
00110                                 final List<Time> l = new ArrayList<Time>(a.size());
00111                                 for (int i = 0; i < a.size(); i++) {
00112                                         l.add(new Time((JsonNode)a.get(i)));
00113                                 }
00114                                 return l;
00115                         }
00116                         return new ArrayList<Time>(0);
00117                 }
00118 
00124                 @Override
00125                 public void writeToParcel(Parcel parcel, int flags) {
00126                         parcel.writeValue(hours);
00127                         parcel.writeValue(milliseconds);
00128                         parcel.writeValue(minutes);
00129                         parcel.writeValue(seconds);
00130                 }
00131 
00135                 protected Time(Parcel parcel) {
00136                         hours = parcel.readInt();
00137                         milliseconds = parcel.readInt();
00138                         minutes = parcel.readInt();
00139                         seconds = parcel.readInt();
00140                 }
00141 
00145                 public static final Parcelable.Creator<Time> CREATOR = new Parcelable.Creator<Time>() {
00146                         @Override
00147                         public Time createFromParcel(Parcel parcel) {
00148                                 return new Time(parcel);
00149                         }
00150                         @Override
00151                         public Time[] newArray(int n) {
00152                                 return new Time[n];
00153                         }
00154                 };
00155 
00156                 @Override
00157                 public int describeContents() {
00158                         return 0;
00159                 }
00160         }
00161 
00168         public static class Toggle extends AbstractModel {
00169                 public final static String API_TYPE = "Global.Toggle";
00170 
00171                 // class members
00172                 public final Boolean booleanArg;
00173                 public final String stringArg;
00174 
00178                 public Toggle(Boolean booleanArg) {
00179                         this.booleanArg = booleanArg;
00180                         this.stringArg = null;
00181                 }
00182 
00186                 public Toggle(String stringArg) {
00187                         this.stringArg = stringArg;
00188                         this.booleanArg = null;
00189                 }
00190 
00191                 @Override
00192                 public JsonNode toJsonNode() {
00193                         if (booleanArg != null) {
00194                                 return booleanArg ? BooleanNode.TRUE : BooleanNode.FALSE;
00195                         }
00196                         if (stringArg != null) {
00197                                 return new TextNode(stringArg); // 3num
00198                         }
00199                         return null; // this is completely excluded. theoretically.
00200                 }
00201 
00207                 @Override
00208                 public void writeToParcel(Parcel parcel, int flags) {
00209                         parcel.writeInt(booleanArg ? 1 : 0);
00210                         parcel.writeValue(stringArg); // enum
00211                 }
00212 
00216                 protected Toggle(Parcel parcel) {
00217                         booleanArg = parcel.readInt() == 1;
00218                         stringArg = parcel.readString(); // enum
00219                 }
00220 
00224                 public static final Parcelable.Creator<Toggle> CREATOR = new Parcelable.Creator<Toggle>() {
00225                         @Override
00226                         public Toggle createFromParcel(Parcel parcel) {
00227                                 return new Toggle(parcel);
00228                         }
00229                         @Override
00230                         public Toggle[] newArray(int n) {
00231                                 return new Toggle[n];
00232                         }
00233                 };
00234 
00235                 @Override
00236                 public int describeContents() {
00237                         return 0;
00238                 }
00239 
00243                 public interface StringArg {
00244 
00245                         public final String TOGGLE = "toggle";
00246 
00247                         public final static Set<String> values = new HashSet<String>(Arrays.asList(TOGGLE));
00248                 }
00249         }
00250 
00254         public interface IncrementDecrement {
00255 
00256                 public final String INCREMENT = "increment";
00257                 public final String DECREMENT = "decrement";
00258 
00259                 public final static Set<String> values = new HashSet<String>(Arrays.asList(INCREMENT, DECREMENT));
00260         }
00261 }


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