@SmallTest
  @MediumTest
  @LargeTest
  public void testCollectionPutOfWrapperPutsJSONObject() throws JSONException {
    JSONObject jsonObject = new JSONObject();

    GraphObject graphObject = GraphObject.Factory.create(jsonObject);
    graphObject.setProperty("hello", "world");
    graphObject.setProperty("hocus", "pocus");

    GraphObjectList<GraphObject> parentList = GraphObject.Factory.createList(GraphObject.class);
    parentList.add(graphObject);

    JSONArray jsonArray = parentList.getInnerJSONArray();

    Object obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);

    parentList.set(0, graphObject);

    obj = jsonArray.opt(0);

    assertNotNull(obj);
    assertEquals(jsonObject, obj);
  }
 /* package */ List<Object> convertJSONArrayToList(JSONArray array) {
   List<Object> list = new ArrayList<>();
   for (int i = 0; i < array.length(); ++i) {
     list.add(decode(array.opt(i)));
   }
   return list;
 }
Exemplo n.º 3
0
 /**
  * 获取新闻回复内容
  *
  * @param nid 新闻编号
  */
 private void getComments(int nid) {
   String url = "http://192.168.3.80:9292/getComments";
   String params = "nid=" + nid + "&startnid=0&count=10";
   SyncHttp http = new SyncHttp();
   try {
     String retStr = http.httpGet(url, params);
     JSONObject jsonObject = new JSONObject(retStr);
     int retCode = jsonObject.getInt("ret");
     if (retCode == 0) {
       JSONObject dataObject = jsonObject.getJSONObject("data");
       // 获取返回数目
       int totalnum = dataObject.getInt("totalnum");
       if (totalnum > 0) {
         // 获取返回新闻集合
         JSONArray commsList = dataObject.getJSONArray("commentslist");
         for (int i = 0; i < commsList.length(); i++) {
           JSONObject commsObject = (JSONObject) commsList.opt(i);
           HashMap<String, Object> hashMap = new HashMap<String, Object>();
           hashMap.put("cid", commsObject.getInt("cid"));
           hashMap.put("commentator_from", commsObject.getString("region"));
           hashMap.put("comment_content", commsObject.getString("content"));
           hashMap.put("comment_ptime", commsObject.getString("ptime"));
           mCommsData.add(hashMap);
         }
       } else {
         Toast.makeText(CommentsActivity.this, R.string.no_comments, Toast.LENGTH_LONG).show();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     Toast.makeText(CommentsActivity.this, R.string.get_comms_failure, Toast.LENGTH_LONG).show();
   }
 }
  public Object marshall(SerializerState state, Object p, Object o) throws MarshallException {
    // reprocess the raw json in order to fixup circular references and duplicates
    JSONArray jsonIn = (JSONArray) o;
    JSONArray jsonOut = new JSONArray();

    int i = 0;
    try {
      int j = jsonIn.length();

      for (i = 0; i < j; i++) {
        Object json = ser.marshall(state, o, jsonIn.opt(i), new Integer(i));
        if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) {
          jsonOut.put(i, json);
        } else {
          // put a slot where the object would go, so it can be fixed up properly in the fix up
          // phase
          jsonOut.put(i, JSONObject.NULL);
        }
      }
    } catch (MarshallException e) {
      throw new MarshallException("element " + i, e);
    } catch (JSONException e) {
      throw new MarshallException("element " + i, e);
    }
    return jsonOut;
  }
  public static List<AroundFriends> parserAroundFriendsInfoList(String json) throws JSONException {
    List<AroundFriends> mDataList = new ArrayList<AroundFriends>();
    try {
      JSONObject result = new JSONObject(json);
      if (result.getString("status").equals("N")) {
        Log.d("TAG", "请求失败");
        return null;
      }
      JSONArray array = result.getJSONArray("memberList");
      int size = array.length();
      for (int i = 0; i < size; i++) {
        JSONObject object = (JSONObject) array.opt(i);
        AroundFriends friendsInfo = new AroundFriends();
        friendsInfo.setUserName(object.getString("user_name"));
        friendsInfo.setDescription(object.getString("remark"));
        friendsInfo.setAuthentication(
            object.getString("is_cheked").equalsIgnoreCase("Y") ? true : false);
        friendsInfo.setHeadImageURL(object.getString("face"));
        friendsInfo.setLatitude(object.getString("last_lat"));
        friendsInfo.setLongitude(object.getString("last_lng"));
        mDataList.add(friendsInfo);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    return mDataList;
  }
Exemplo n.º 6
0
 public static List<VTagDO> transformJsonToTags(JSONObject jsonObject) throws JSONException {
   List<VTagDO> tags = new ArrayList<VTagDO>();
   JSONArray jsonArrayTags = jsonObject.getJSONArray("list");
   for (int i = 0; i < jsonArrayTags.length(); i++) {
     List<VTypeDO> types = new ArrayList<VTypeDO>();
     JSONObject jsonTag = (JSONObject) jsonArrayTags.opt(i);
     VTagDO tagDO = new VTagDO();
     tagDO.setName(jsonTag.getString("name").trim());
     JSONArray jsonArrayTypes = jsonTag.getJSONArray("types");
     for (int j = 0; j < jsonArrayTypes.length(); j++) {
       JSONObject jsonType = (JSONObject) jsonArrayTypes.opt(j);
       VTypeDO typeDO = new VTypeDO();
       typeDO.setName(jsonType.getString("name"));
       typeDO.setId(jsonType.getString("id"));
       types.add(typeDO);
     }
     tagDO.setTypes(types);
     tags.add(tagDO);
   }
   return tags;
 }
 @SuppressWarnings("unchecked")
 private <T> Set<T> getSet(String key, Set<T> defValue) {
   JSONArray a = getData().optJSONArray(key);
   if (a == null) {
     return defValue;
   }
   Set<T> set = new HashSet<T>(Math.max(a.length(), 0));
   for (int i = 0; i < a.length(); i++) {
     set.add((T) a.opt(i));
   }
   return set;
 }
Exemplo n.º 8
0
 /**
  * 获取指定类型的新闻列表
  *
  * @param cid 类型ID
  * @param newsList 保存新闻信息的集合
  * @param startnid 分页
  * @param firstTimes 是否第一次加载
  */
 private int getSpeCateNews(
     int cid, List<HashMap<String, Object>> newsList, int startnid, Boolean firstTimes) {
   if (firstTimes) {
     // 如果是第一次,则清空集合里数据
     newsList.clear();
   }
   // 请求URL和字符串
   String url = "http://10.0.2.2:8080/web/getSpecifyCategoryNews";
   String params = "startnid=" + startnid + "&count=" + NEWSCOUNT + "&cid=" + cid;
   SyncHttp syncHttp = new SyncHttp();
   try {
     // 以Get方式请求,并获得返回结果
     String retStr = syncHttp.httpGet(url, params);
     JSONObject jsonObject = new JSONObject(retStr);
     // 获取返回码,0表示成功
     int retCode = jsonObject.getInt("ret");
     if (0 == retCode) {
       JSONObject dataObject = jsonObject.getJSONObject("data");
       // 获取返回数目
       int totalnum = dataObject.getInt("totalnum");
       if (totalnum > 0) {
         // 获取返回新闻集合
         JSONArray newslist = dataObject.getJSONArray("newslist");
         for (int i = 0; i < newslist.length(); i++) {
           JSONObject newsObject = (JSONObject) newslist.opt(i);
           HashMap<String, Object> hashMap = new HashMap<String, Object>();
           hashMap.put("nid", newsObject.getInt("nid"));
           hashMap.put("newslist_item_title", newsObject.getString("title"));
           hashMap.put("newslist_item_digest", newsObject.getString("digest"));
           hashMap.put("newslist_item_source", newsObject.getString("source"));
           hashMap.put("newslist_item_ptime", newsObject.getString("ptime"));
           hashMap.put("newslist_item_comments", newsObject.getString("commentcount"));
           newsList.add(hashMap);
         }
         return SUCCESS;
       } else {
         if (firstTimes) {
           return NONEWS;
         } else {
           return NOMORENEWS;
         }
       }
     } else {
       return LOADERROR;
     }
   } catch (Exception e) {
     e.printStackTrace();
     return LOADERROR;
   }
 }
Exemplo n.º 9
0
 public static List<VFilmDO> transformJsonToList(JSONObject jsonObject) throws JSONException {
   List<VFilmDO> list = new ArrayList<VFilmDO>();
   JSONArray jsonArrayTags = jsonObject.getJSONArray("list");
   for (int i = 0; i < jsonArrayTags.length(); i++) {
     JSONObject jsonList = (JSONObject) jsonArrayTags.opt(i);
     VFilmDO filmDO = new VFilmDO();
     filmDO.setName(jsonList.getString("name").trim());
     filmDO.setType(jsonList.getString("type").trim());
     filmDO.setId(jsonList.getString("id").trim());
     filmDO.setPic(jsonList.getString("pic").trim());
     list.add(filmDO);
   }
   return list;
 }
  /**
   * 获取新闻回复内容
   *
   * @param mNid
   */
  private void getComments(int mNid) {
    // http://10.0.2.2:8080/web/getComments
    String url = "http://10.0.2.2:8080/web/getComments";
    String params = "nid=" + mNid + "&startnid=0&count=10";
    SyncHttp syncHttp = new SyncHttp();

    try {
      // 通过Http协议发送Get请求,返回字符串
      String retStr = syncHttp.httpGet(url, params);
      JSONObject jsonObject = new JSONObject(retStr);
      int retCode = jsonObject.getInt("ret");
      if (retCode == 0) {
        JSONObject dataObj = jsonObject.getJSONObject("data");
        // 获取返回数目
        int totalNum = dataObj.getInt("totalnum");
        if (totalNum > 0) {
          // 获取返回新闻集合
          JSONArray commentsList = dataObj.getJSONArray("commentslist");
          // 将用JSON格式解析的数据添加到数据集合当中
          for (int i = 0; i < commentsList.length(); i++) {
            JSONObject commentsObject = (JSONObject) commentsList.opt(i);
            HashMap<String, Object> hashMap = new HashMap<String, Object>();
            hashMap.put("cid", commentsObject.getInt("cid"));
            hashMap.put("commentator_from", commentsObject.getString("region"));
            hashMap.put("comment_ptime", commentsObject.getString("ptime"));
            hashMap.put("comment_content", commentsObject.getString("content"));
            mCommentsData.add(hashMap);
          }
        } else {
          // 没有回复信息
          Toast.makeText(CommentsActivity.this, R.string.noreply, Toast.LENGTH_SHORT).show();
        }
      } else {
        // 获取回复信息失败
        Toast.makeText(CommentsActivity.this, R.string.getreplyfaild, Toast.LENGTH_SHORT).show();
      }
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      // 获取回复信息失败
      Toast.makeText(CommentsActivity.this, R.string.getreplyfaild, Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      // 获取回复信息失败
      Toast.makeText(CommentsActivity.this, R.string.getreplyfaild, Toast.LENGTH_SHORT).show();
    }
  }
Exemplo n.º 11
0
 /**
  * Returns an array with the values corresponding to {@code names}. The array contains null for
  * names that aren't mapped. This method returns null if {@code names} is either null or empty.
  */
 public JSONArray toJSONArray(JSONArray names) throws JSONException {
   JSONArray result = new JSONArray();
   if (names == null) {
     return null;
   }
   int length = names.length();
   if (length == 0) {
     return null;
   }
   for (int i = 0; i < length; i++) {
     String name = JSON.toString(names.opt(i));
     result.put(opt(name));
   }
   return result;
 }
 /**
  * Filters the given default values from all {@link JSONObject}s in the "valueArray". If the array
  * contains more arrays, the method is called recursively on those arrays. Otherwise, nothing is
  * filtered. If an element is completely equal to the defaultValueObject it is <b>not</b> removed,
  * i.e. an empty object remains at this position in the array. Otherwise, we could not restore the
  * object later.
  */
 protected void filterDefaultObject(JSONArray valueArray, JSONObject defaultValueObject) {
   for (int i = 0; i < valueArray.length(); i++) {
     Object value = valueArray.opt(i);
     // Can only filter
     if (value instanceof JSONObject) {
       JSONObject jsonValue = (JSONObject) value;
       // Filter, but ignore return value. Element in the array must never be removed,
       // otherwise we could not restore it later.
       filterDefaultObject(jsonValue, defaultValueObject);
     } else if (value instanceof JSONArray) {
       JSONArray jsonArray = (JSONArray) value;
       filterDefaultObject(jsonArray, defaultValueObject);
     }
   }
 }
 private String buildArguments(JSONArray array) {
   if (array.length() == 0) {
     return "";
   } else {
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < array.length(); i++) {
       Object value = array.opt(i);
       builder.append(convert(value));
       if (i < array.length() - 1) {
         builder.append(",");
       }
     }
     return builder.toString();
   }
 }
 private static <T> Set<T> stringToSet(String string, Class<T> clazz) {
   try {
     JSONArray array = new JSONArray(string);
     Set<T> set = new HashSet<T>(array.length());
     for (int i = 0; i < array.length(); i++) {
       set.add(clazz.cast(array.opt(i)));
     }
     return set;
   } catch (ClassCastException e) {
     Log.e(_SharedPreferencesImpl_XML.class.getSimpleName(), "Error of cast", e);
     return null;
   } catch (JSONException e) {
     return null;
   }
 }
 protected Collection<Object> jsonArrayToCollection(JSONArray array, boolean preserveOrder) {
   if (array == null) {
     return null;
   }
   Collection<Object> result = (preserveOrder ? new ArrayList<>() : new HashSet<>());
   for (int i = 0; i < array.length(); i++) {
     Object element = array.opt(i);
     if (element instanceof JSONArray) {
       result.add(jsonArrayToCollection((JSONArray) element, preserveOrder));
     } else {
       result.add(element);
     }
   }
   return result;
 }
Exemplo n.º 16
0
  private ArrayList<BaseChannel> getResultData(JSONObject object) {
    ArrayList<BaseChannel> otherHuanChannelList = new ArrayList<BaseChannel>();
    JSONObject error = object.optJSONObject("error");
    String errorCode = error.optString("code");
    Log.i("errorCode", errorCode);
    String errorInfo = error.optString("info");
    Log.i("errorInfo", errorInfo);
    if ("0".equals(errorCode)) {
      JSONArray channels = object.optJSONArray("channels");
      BaseChannel basechannel = null;
      for (int i = 0; i < channels.length(); i++) {
        JSONObject channel = (JSONObject) channels.opt(i);
        String name = channel.optString("name");
        String memo = channel.optString("memo");
        String code = channel.optString("code");
        String type = channel.optString("type");
        String logo = channel.optString("logo");

        basechannel = new BaseChannel();
        basechannel.setName(name);
        basechannel.setMemo(memo);
        basechannel.setCode(code);
        basechannel.setType(type);
        basechannel.setLogo(logo);
        Log.i("name111", name);
        Log.i("memo111", name);
        Log.i("code111", code);
        Log.i("type111", type);
        Log.i("logo111", logo);
        if (code != null && !code.equals("")) {
          /*for (DTVChannelBaseInfo dtvchannel : dtvChannelList) {
          	if (dtvchannel.mstrServiceName.equals(name)) {
          		basechannel.setIndex(dtvchannel.miChannelIndex);
          		BaseChannelDBUtil.getInstance(mContext).save(basechannel);
          		Log.i("index111", dtvchannel.miChannelIndex + "");
          		basechannel = null;
          		break;
          	}
          }*/
          otherHuanChannelList.add(basechannel);
        } else {
          Log.i("no code name=", name);
        }
        basechannel = null;
      }
    }
    return otherHuanChannelList;
  }
Exemplo n.º 17
0
 public static VSeriesDO transformJsonToVSeriesDO(JSONObject jsonObject) throws JSONException {
   VSeriesDO seriesDO = new VSeriesDO();
   seriesDO.setInfo(jsonObject.getString("info"));
   JSONArray jsonArraySets = jsonObject.getJSONArray("list");
   List<VSetDO> setDOs = new ArrayList<VSetDO>();
   for (int i = 0; i < jsonArraySets.length(); i++) {
     JSONObject jsonSet = (JSONObject) jsonArraySets.opt(i);
     VSetDO set = new VSetDO();
     set.setName(jsonSet.getString("name").trim());
     set.setVideoType(jsonSet.getString("video_type").trim());
     set.setSource("http://" + jsonSet.getString("source").trim());
     set.setPic("http://" + jsonSet.getString("pic").trim());
     setDOs.add(set);
   }
   seriesDO.setSets(setDOs);
   return seriesDO;
 }
Exemplo n.º 18
0
 private static Object fromJSONValue(Object value) throws JSONException {
   if (value instanceof JSONObject || value == JSONObject.NULL) {
     return fromJSONObject((JSONObject) value);
   }
   if (value instanceof JSONArray) {
     final JSONArray array = (JSONArray) value;
     final int len = array.length();
     if (len == 0) {
       return EMPTY_BOOLEAN_ARRAY;
     }
     Object out = null;
     for (int i = 0; i < len; i++) {
       final Object element = fromJSONValue(array.opt(i));
       if (element == null) {
         continue;
       }
       if (out == null) {
         Class<?> type = element.getClass();
         if (type == Boolean.class) {
           type = boolean.class;
         } else if (type == Integer.class) {
           type = int.class;
         } else if (type == Double.class) {
           type = double.class;
         }
         out = Array.newInstance(type, len);
       }
       Array.set(out, i, element);
     }
     if (out == null) {
       // Treat all-null arrays as String arrays.
       return new String[len];
     }
     return out;
   }
   if (value instanceof Boolean) {
     return value;
   }
   if (value instanceof Byte || value instanceof Short || value instanceof Integer) {
     return ((Number) value).intValue();
   }
   if (value instanceof Float || value instanceof Double || value instanceof Long) {
     return ((Number) value).doubleValue();
   }
   return value != null ? value.toString() : null;
 }
Exemplo n.º 19
0
 /**
  * Gets a list property deserialized values from the cache or from the underlying JSONObject
  *
  * @param property the property name
  * @return the list of primitive or simple supported objects associated to this property in the
  *     JSON response
  */
 @SuppressWarnings("unchecked")
 private <T> List<T> getElementCollection(String property) {
   List<T> list = null;
   if (!propertyMap.containsKey(property)) {
     JSONArray jsonArray = delegate.optJSONArray(property);
     if (jsonArray != null) {
       list = new ArrayList<T>(jsonArray.length());
       for (int i = 0; i < jsonArray.length(); i++) {
         T item = (T) jsonArray.opt(i);
         list.add(item);
       }
     }
     propertyMap.put(property, list);
   } else {
     list = (List<T>) propertyMap.get(property);
   }
   return list;
 }
Exemplo n.º 20
0
 /*     */ private static void stringify(JSONArray ja, StringBuffer b)
     /*     */ throws JSONException
       /*     */ {
   /* 243 */ b.append('<');
   /* 244 */ b.append(ja.get(0));
   /* 245 */ Object o = ja.opt(1);
   /*     */ int i;
   /*     */ int i;
   /* 246 */ if ((o instanceof JSONObject))
   /*     */ {
     /* 250 */ JSONObject jo = (JSONObject) o;
     /* 251 */ Iterator keys = jo.keys();
     /* 252 */ while (keys.hasNext()) {
       /* 253 */ String k = keys.next().toString();
       /* 254 */ Object v = jo.get(k).toString();
       /* 255 */ b.append(' ');
       /* 256 */ b.append(k);
       /* 257 */ b.append("=\"");
       /* 258 */ b.append(XML.escape((String) v));
       /* 259 */ b.append('"');
       /*     */ }
     /* 261 */ i = 2;
     /*     */ } else {
     /* 263 */ i = 1;
     /*     */ }
   /* 265 */ int len = ja.length();
   /*     */
   /* 267 */ if (i >= len) {
     /* 268 */ b.append("/>");
     /*     */ } else {
     /* 270 */ b.append('>');
     /* 271 */ while (i < len) {
       /* 272 */ Object v = ja.get(i);
       /* 273 */ if ((v instanceof JSONArray)) /* 274 */ stringify((JSONArray) v, b);
       /*     */ else {
         /* 276 */ b.append(XML.escape(v.toString()));
         /*     */ }
       /* 278 */ i++;
       /*     */ }
     /* 280 */ b.append("</");
     /* 281 */ b.append(ja.get(0));
     /* 282 */ b.append('>');
     /*     */ }
   /*     */ }
  private String convert(Object value) {
    if (value instanceof Integer) {
      return value.toString();
    }
    if (value instanceof Double) {
      return value.toString();
    }
    if (value instanceof Double) {
      return value.toString();
    }
    if (value instanceof String) {
      return "'" + value.toString() + "'";
    }
    if (value instanceof Boolean) {
      return value.toString();
    }
    if (value instanceof JSONObject) {
      JSONObject v = (JSONObject) value;
      if (v.has("ELEMENT")) {
        Integer i = v.optInt("ELEMENT");
        return "UIAutomation.cache.get(" + i + ",false)";
      } else {
        return v.toString();
      }
    }
    if (value instanceof JSONArray) {
      StringBuilder builder = new StringBuilder();
      builder.append("[");
      JSONArray a = (JSONArray) value;
      for (int i = 0; i < a.length(); i++) {
        Object element = a.opt(i);
        builder.append(convert(element));
        if (i < a.length() - 1) {
          builder.append(",");
        }
      }
      builder.append("]");
      return builder.toString();
    }

    log.warning("Not implemented, JS argument is a " + value.getClass());
    throw new WebDriverException("Not implemented, JS argument is a " + value.getClass());
  }
Exemplo n.º 22
0
  /*Filter Arrival Airport*/
  public static void filterArrivalAirport(String code) {
    Log.e("Filter", "TRUE");

    JSONArray jsonFlight = getFlight(MainFragmentActivity.getContext());
    dataFlightArrival = new ArrayList<>();

    /*Display Arrival*/
    for (int i = 0; i < jsonFlight.length(); i++) {
      JSONObject row = (JSONObject) jsonFlight.opt(i);
      if (code.equals(row.optString("location_code")) && row.optString("status").equals("Y")) {
        Log.e(code, row.optString("location_code"));

        DropDownItem itemFlight = new DropDownItem();
        itemFlight.setText(row.optString("travel_location"));
        itemFlight.setCode(row.optString("travel_location_code" + ""));
        itemFlight.setTag("FLIGHT_DEPARTURE");
        dataFlightArrival.add(itemFlight);
      }
    }
    Log.e("Arrive", dataFlightArrival.toString());
  }
 /**
  * Parses array from given JSONArray. Supports parsing of primitive types and {@link
  * com.vk.sdk.api.model.VKApiModel} instances.
  *
  * @param array JSONArray to parse
  * @param arrayClass type of array field in class.
  * @return object to set to array field in class
  * @throws org.json.JSONException if given array have incompatible type with given field.
  */
 private static Object parseArrayViaReflection(JSONArray array, Class arrayClass)
     throws JSONException {
   Object result = Array.newInstance(arrayClass.getComponentType(), array.length());
   Class<?> subType = arrayClass.getComponentType();
   for (int i = 0; i < array.length(); i++) {
     try {
       Object item = array.opt(i);
       if (VKApiModel.class.isAssignableFrom(subType) && item instanceof JSONObject) {
         VKApiModel model = (VKApiModel) subType.newInstance();
         item = model.parse((JSONObject) item);
       }
       Array.set(result, i, item);
     } catch (InstantiationException e) {
       throw new JSONException(e.getMessage());
     } catch (IllegalAccessException e) {
       throw new JSONException(e.getMessage());
     } catch (IllegalArgumentException e) {
       throw new JSONException(e.getMessage());
     }
   }
   return result;
 }
Exemplo n.º 24
0
 private Intent setIntentFilter(Intent intent, String filterJson) {
   try {
     JSONObject json = new JSONObject(filterJson);
     if (json.has("category")) {
       JSONArray category = json.getJSONArray("category");
       if (category != null) {
         for (int i = 0; i < category.length(); i++) {
           String ctg = category.opt(i).toString();
           if (!TextUtils.isEmpty(ctg)) {
             intent.addCategory(ctg);
           }
         }
       }
     }
     if (json.has("data")) {
       JSONObject dataJson = json.getJSONObject("data");
       String mimeType = null;
       String scheme = null;
       if (dataJson != null) {
         if (dataJson.has("mimeType")) {
           mimeType = dataJson.getString("mimeType");
         }
         if (dataJson.has("scheme")) {
           scheme = dataJson.getString("scheme");
         }
         if (TextUtils.isEmpty(mimeType) && !TextUtils.isEmpty(scheme)) {
           intent.setData(Uri.parse(scheme));
         } else if (!TextUtils.isEmpty(mimeType) && !TextUtils.isEmpty(scheme)) {
           intent.setDataAndType(Uri.parse(scheme), mimeType);
         } else if (!TextUtils.isEmpty(mimeType) && TextUtils.isEmpty(scheme)) {
           intent.setType(mimeType);
         }
       }
     }
   } catch (JSONException e) {
     e.printStackTrace();
   }
   return intent;
 }
Exemplo n.º 25
0
  /**
   * Convert a JSONObject into a well-formed, element-normal XML string.
   *
   * @param o A JSONObject.
   * @param tagName The optional name of the enclosing tag.
   * @return A string.
   * @throws JSONException
   */
  public static String toString(final Object o, final String tagName) throws JSONException {
    final StringBuffer b = new StringBuffer();
    int i;
    JSONArray ja;
    JSONObject jo;
    String k;
    Iterator keys;
    int len;
    String s;
    Object v;
    if (o instanceof JSONObject) {

      // Emit <tagName>

      if (tagName != null) {
        b.append('<');
        b.append(tagName);
        b.append('>');
      }

      // Loop thru the keys.

      jo = (JSONObject) o;
      keys = jo.keys();
      while (keys.hasNext()) {
        k = keys.next().toString();
        v = jo.get(k);
        if (v instanceof String) {
          s = (String) v;
        } else {
          s = null;
        }

        // Emit content in body

        if (k.equals("content")) {
          if (v instanceof JSONArray) {
            ja = (JSONArray) v;
            len = ja.length();
            for (i = 0; i < len; i += 1) {
              if (i > 0) {
                b.append('\n');
              }
              b.append(escape(ja.get(i).toString()));
            }
          } else {
            b.append(escape(v.toString()));
          }

          // Emit an array of similar keys

        } else if (v instanceof JSONArray) {
          ja = (JSONArray) v;
          len = ja.length();
          for (i = 0; i < len; i += 1) {
            b.append(toString(ja.get(i), k));
          }
        } else if (v.equals("")) {
          b.append('<');
          b.append(k);
          b.append("/>");

          // Emit a new tag <k>

        } else {
          b.append(toString(v, k));
        }
      }
      if (tagName != null) {

        // Emit the </tagname> close tag

        b.append("</");
        b.append(tagName);
        b.append('>');
      }
      return b.toString();

      // XML does not have good support for arrays. If an array appears in a place
      // where XML is lacking, synthesize an <array> element.

    } else if (o instanceof JSONArray) {
      ja = (JSONArray) o;
      len = ja.length();
      for (i = 0; i < len; ++i) {
        b.append(toString(ja.opt(i), (tagName == null) ? "array" : tagName));
      }
      return b.toString();
    } else {
      s = (o == null) ? "null" : escape(o.toString());
      return (tagName == null)
          ? "\"" + s + "\""
          : (s.length() == 0)
              ? "<" + tagName + "/>"
              : "<" + tagName + ">" + s + "</" + tagName + ">";
    }
  }
Exemplo n.º 26
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.mobile_checkin_1, container, false);
    ButterKnife.inject(this, view);

    /*Preference Manager*/
    pref = new SharedPrefManager(MainFragmentActivity.getContext());

    txtDeparture.setTag(DEPARTURE_FLIGHT);
    txtArrive.setTag(ARRIVAL_FLIGHT);

    /*Retrieve All Flight Data From Preference Manager - Display Flight Data*/
    JSONArray jsonFlight = getFlight(getActivity());
    dataFlightDeparture = new ArrayList<>();

    ArrayList<String> tempFlight = new ArrayList<>();

    /*Get All Airport - remove redundant*/
    List<String> al = new ArrayList<>();
    Set<String> hs = new LinkedHashSet<>();
    for (int i = 0; i < jsonFlight.length(); i++) {
      JSONObject row = (JSONObject) jsonFlight.opt(i);
      al.add(row.optString("location") + "-" + row.optString("location_code"));
    }
    hs.addAll(al);
    al.clear();
    al.addAll(hs);

    /*Display Airport*/
    for (int i = 0; i < al.size(); i++) {
      String flightSplit = al.get(i).toString();
      String[] str1 = flightSplit.split("-");
      String p1 = str1[0];
      String p2 = str1[1];

      DropDownItem itemFlight = new DropDownItem();
      itemFlight.setText(p1);
      itemFlight.setCode(p2);
      itemFlight.setTag("FLIGHT");
      dataFlightDeparture.add(itemFlight);
    }

    /*Departure Flight Clicked*/
    txtDeparture.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            AnalyticsApplication.sendEvent("Click", "txtDeparture");
            popupSelection(dataFlightDeparture, getActivity(), txtDeparture, true);
            // txtDeparture.setText("ARRIVAL AIRPORT");
          }
        });

    /*Arrival Flight Clicked*/
    txtArrive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            AnalyticsApplication.sendEvent("Click", "btnArrivalFlight");
            if (txtDeparture.getTag().toString().equals("NOT SELECTED")) {
              popupAlert("Select Departure Airport First");
            } else {
              popupSelection(dataFlightArrival, getActivity(), txtArrive, true);
            }
          }
        });

    mobileCheckInNext1.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            checkinFlight();
            // goCheckin2Page();
          }
        });
    return view;
  }
  @Override
  public void configure(JSONObject config, GameTypeCollector typeCollector) {
    JSONArray gameTypes = config.optJSONArray("gameTypes");
    int typesAdded = 0;
    if (gameTypes == null || gameTypes.length() == 0) {
      Log.e(GameTypeCollectorConfig.class, "There is no one game type!");
    } else {
      for (int i = 0; i < gameTypes.length(); i++) {
        JSONObject gameType = (JSONObject) gameTypes.opt(i);
        String name = gameType.optString("name");
        if (name == null) {
          Log.e(
              GameTypeCollectorConfig.class,
              "Can`t get name of Assignment. Looks like incorrect config. JSON="
                  + gameType.toString());
        } else {
          Class groupClass = null;
          if ("CustomClass".equalsIgnoreCase(name)) {
            String customClassName = config.optString("class", null);
            if (customClassName != null) {
              try {
                groupClass = Class.forName(name);
              } catch (Exception ex) {
                Log.e(
                    GameTypeCollectorConfig.class, "Can`t get CustomClass for name = " + name, ex);
                groupClass = null;
              }
            } else {
              Log.e(GameTypeCollectorConfig.class, "CustomClass name is empty");
            }
          } else {
            groupClass = groupsByName.get(name);
            if (groupClass == null) {
              Log.e(GameTypeCollectorConfig.class, "Can`t find class for name = " + name);
            }
          }

          if (groupClass == null) {
            Log.e(GameTypeCollectorConfig.class, "Fail to create GameType for json=" + gameType);
          } else {
            Object testNewGroup = null;
            try {
              testNewGroup = groupClass.newInstance();
            } catch (Exception ex) {
              Log.e(
                  GameTypeCollectorConfig.class,
                  "fail to create { name = "
                      + name
                      + ", class = "
                      + groupClass.getSimpleName()
                      + "}");
              testNewGroup = null;
            }
            if (testNewGroup != null) {
              if (testNewGroup instanceof GamePlayersLevelAssignmentGroup) {
                GamePlayersLevelAssignmentGroup newgroup =
                    (GamePlayersLevelAssignmentGroup) testNewGroup;
                JSONObject typeConfig = gameType.optJSONObject("config");
                if (typeConfig == null) {
                  Log.e(
                      GameTypeCollectorConfig.class,
                      "Threr is no Config for { name = "
                          + name
                          + ", class = "
                          + groupClass.getSimpleName()
                          + "}, but class added!");
                  typeCollector.addAssignment(newgroup);
                  typesAdded++;
                } else {
                  try {
                    newgroup.configure(typeConfig);
                    typeCollector.addAssignment(newgroup);
                    typesAdded++;
                  } catch (Exception ex) {
                    Log.e(
                        GameTypeCollectorConfig.class,
                        "Can`t configure: { name = "
                            + name
                            + ", class = "
                            + groupClass.getSimpleName()
                            + "}",
                        ex);
                  }
                }
              } else {
                Log.e(
                    GameTypeCollectorConfig.class,
                    "Created class for { name = "
                        + name
                        + ", class = "
                        + groupClass.getSimpleName()
                        + "} is not subclass of GamePlayersLevelAssignmentGroup");
              }
            }
          }
        }
      }
      Log.i(GameTypeCollectorConfig.class, "Added: " + typesAdded + " game types");
    }
  }
Exemplo n.º 28
0
  /**
   * Reverse the JSONML transformation, making an XML text from a JSONArray.
   *
   * @param ja A JSONArray.
   * @return An XML string.
   * @throws JSONException
   */
  public static String toString(JSONArray ja) throws JSONException {
    int i;
    JSONObject jo;
    String key;
    Iterator<String> keys;
    int length;
    Object object;
    StringBuilder sb = new StringBuilder();
    String tagName;
    String value;

    // Emit <tagName

    tagName = ja.getString(0);
    XML.noSpace(tagName);
    tagName = XML.escape(tagName);
    sb.append('<');
    sb.append(tagName);

    object = ja.opt(1);
    if (object instanceof JSONObject) {
      i = 2;
      jo = (JSONObject) object;

      // Emit the attributes

      keys = jo.keys();
      while (keys.hasNext()) {
        key = keys.next();
        XML.noSpace(key);
        value = jo.optString(key);
        if (value != null) {
          sb.append(' ');
          sb.append(XML.escape(key));
          sb.append('=');
          sb.append('"');
          sb.append(XML.escape(value));
          sb.append('"');
        }
      }
    } else {
      i = 1;
    }

    // Emit content in body

    length = ja.length();
    if (i >= length) {
      sb.append('/');
      sb.append('>');
    } else {
      sb.append('>');
      do {
        object = ja.get(i);
        i += 1;
        if (object != null) {
          if (object instanceof String) {
            sb.append(XML.escape(object.toString()));
          } else if (object instanceof JSONObject) {
            sb.append(toString((JSONObject) object));
          } else if (object instanceof JSONArray) {
            sb.append(toString((JSONArray) object));
          }
        }
      } while (i < length);
      sb.append('<');
      sb.append('/');
      sb.append(tagName);
      sb.append('>');
    }
    return sb.toString();
  }
Exemplo n.º 29
0
 public Object opt(int index) {
   return baseArgs.opt(index);
 }
Exemplo n.º 30
0
  /**
   * Convert a JSONObject into a well-formed, element-normal XML string.
   *
   * @param object A JSONObject.
   * @param tagName The optional name of the enclosing tag.
   * @return A string.
   * @throws JSONException
   */
  public static String toString(Object object, String tagName) throws JSONException {
    StringBuilder sb = new StringBuilder();
    int i;
    JSONArray ja;
    JSONObject jo;
    String key;
    Iterator<String> keys;
    int length;
    String string;
    Object value;
    if (object instanceof JSONObject) {

      // Emit <tagName>

      if (tagName != null) {
        sb.append('<');
        sb.append(tagName);
        sb.append('>');
      }

      // Loop thru the keys.

      jo = (JSONObject) object;
      keys = jo.keys();
      while (keys.hasNext()) {
        key = keys.next();
        value = jo.opt(key);
        if (value == null) {
          value = "";
        }
        string = value instanceof String ? (String) value : null;

        // Emit content in body

        if ("content".equals(key)) {
          if (value instanceof JSONArray) {
            ja = (JSONArray) value;
            length = ja.length();
            for (i = 0; i < length; i += 1) {
              if (i > 0) {
                sb.append('\n');
              }
              sb.append(escape(ja.get(i).toString()));
            }
          } else {
            sb.append(escape(value.toString()));
          }

          // Emit an array of similar keys

        } else if (value instanceof JSONArray) {
          ja = (JSONArray) value;
          length = ja.length();
          for (i = 0; i < length; i += 1) {
            value = ja.get(i);
            if (value instanceof JSONArray) {
              sb.append('<');
              sb.append(key);
              sb.append('>');
              sb.append(toString(value));
              sb.append("</");
              sb.append(key);
              sb.append('>');
            } else {
              sb.append(toString(value, key));
            }
          }
        } else if ("".equals(value)) {
          sb.append('<');
          sb.append(key);
          sb.append("/>");

          // Emit a new tag <k>

        } else {
          sb.append(toString(value, key));
        }
      }
      if (tagName != null) {

        // Emit the </tagname> close tag

        sb.append("</");
        sb.append(tagName);
        sb.append('>');
      }
      return sb.toString();

      // XML does not have good support for arrays. If an array appears in a place
      // where XML is lacking, synthesize an <array> element.

    }
    if (object != null) {
      if (object.getClass().isArray()) {
        object = new JSONArray(object);
      }

      if (object instanceof JSONArray) {
        ja = (JSONArray) object;
        length = ja.length();
        for (i = 0; i < length; i += 1) {
          sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
        }
        return sb.toString();
      }
    }
    string = (object == null) ? "null" : escape(object.toString());
    return (tagName == null)
        ? "\"" + string + "\""
        : (string.length() == 0)
            ? "<" + tagName + "/>"
            : "<" + tagName + ">" + string + "</" + tagName + ">";
  }