Esempio n. 1
0
  public static ArrayList<Listing> fromJSON(JSONArray jsonArray) {
    ArrayList<Listing> bizs = new ArrayList<Listing>(jsonArray.length());
    Listing biz;
    for (int i = 0; i < jsonArray.length(); i++) {
      JSONObject bizJson = null;
      try {
        bizJson = jsonArray.getJSONObject(i);
      } catch (JSONException e) {
        e.printStackTrace();
        continue;
      }

      biz = Listing.fromJSON(bizJson);
      if (biz != null) {
        bizs.add(biz);
      }
    }

    return bizs;
  }
Esempio n. 2
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    Listing biz = this.getItem(position);
    View view = convertView;
    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.biz_item, null);
    } else {
      ((SmartImageView) view.findViewById(R.id.imgBiz))
          .setImageResource(android.R.color.transparent);
    }

    if (biz.getImage() != null) {
      ((SmartImageView) view.findViewById(R.id.imgBiz)).setImageUrl(biz.getImage());
    }

    ((TextView) view.findViewById(R.id.tvTitle)).setText(biz.getTitle());
    ((TextView) view.findViewById(R.id.tvPhone)).setText(biz.getPhone());
    ((TextView) view.findViewById(R.id.tvAddress)).setText(biz.getAddress());
    return view;
  }
Esempio n. 3
0
  public static Listing fromJSON(JSONObject jsonObj) {
    Listing biz = new Listing(jsonObj);
    try {
      biz.id = jsonObj.getString("id");
      biz.title = jsonObj.getString("dtitle");
      biz.street = jsonObj.getString("addr");
      biz.city = jsonObj.getString("city");
      biz.state = jsonObj.getString("state");
      biz.rating = jsonObj.getString("rating");
      biz.phone = jsonObj.getString("phone");
      biz.lat = jsonObj.getString("lat");
      biz.lon = jsonObj.getString("lon");

      // reviews..
      JSONObject reviewObj = biz.getJSONObject("reviews");
      if (reviewObj != null && reviewObj.getInt("count") > 0) {
        biz.reviews = Review.fromJSON(reviewObj.getJSONArray("review"));
      } else {
        biz.reviews = new ArrayList<Review>();
      }

      // Image
      JSONObject imgObj = biz.getJSONObject("fullsize_photos");
      if (imgObj.getInt("count") > 0) {
        biz.imageUrl = imgObj.getJSONArray("content").getJSONObject(0).getString("url");
      } else {
        biz.imageUrl = null;
      }
    } catch (JSONException e) {
      Log.d("pinank", e.getMessage());
      return null;
    }

    return biz;
  }