Пример #1
0
  private void getTrafficSpots() {
    controller.showProgressBar();
    String uploadWebsite =
        "http://" + controller.selectedCity.URL + "/php/trafficstatus.cache?dummy=ert43";
    String[] ArrayOfData = null;
    StreamConnection c = null;
    InputStream s = null;
    StringBuffer b = new StringBuffer();

    String url = uploadWebsite;
    System.out.print(url);
    try {
      c = (StreamConnection) Connector.open(url);
      s = c.openDataInputStream();
      int ch;
      int k = 0;
      while ((ch = s.read()) != -1) {
        System.out.print((char) ch);
        b.append((char) ch);
      }
      // System.out.println("b"+b);
      try {
        JSONObject ff1 = new JSONObject(b.toString());
        String data1 = ff1.getString("locations");
        JSONArray jsonArray1 = new JSONArray(data1);
        Vector TrafficStatus = new Vector();
        for (int i = 0; i < jsonArray1.length(); i++) {

          System.out.println(jsonArray1.getJSONArray(i).getString(3));
          double aDoubleLat = Double.parseDouble(jsonArray1.getJSONArray(i).getString(1));
          double aDoubleLon = Double.parseDouble(jsonArray1.getJSONArray(i).getString(2));
          System.out.println(aDoubleLat + " " + aDoubleLon);
          TrafficStatus.addElement(
              new LocationPointer(
                  jsonArray1.getJSONArray(i).getString(3),
                  (float) aDoubleLon,
                  (float) aDoubleLat,
                  1,
                  true));
        }
        controller.setCurrentScreen(controller.TrafficSpots(TrafficStatus));
      } catch (Exception E) {
        controller.setCurrentScreen(traf);
        new Thread() {
          public void run() {
            controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO);
          }
        }.start();
      }

    } catch (Exception e) {

      controller.setCurrentScreen(traf);
      new Thread() {
        public void run() {
          controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO);
        }
      }.start();
    }
  }
Пример #2
0
  public JSONArray serializeJSON() throws JSONException {

    JSONArray a = new JSONArray();

    //  Mandatory items

    for (int i = 0; i < contacts.length; i++) {
      Contact c = contacts[i];
      JSONObject o = new JSONObject();
      o.put("contact", c.serializeJSON());
      a.put(o);
    }

    return a;
  }
Пример #3
0
  public static Vector fromJsonArray(String jsonArray) {
    Vector vectorFacturas = new Vector();
    try {
      JSONArray array = new JSONArray(jsonArray);
      for (int i = 0; i < array.length(); i++) {
        JSONObject json = array.getJSONObject(i);
        Facturas fac = Facturas.fromJson(json.toString());

        vectorFacturas.addElement(fac);
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return vectorFacturas;
  }
Пример #4
0
  private boolean isEqualsJsonArray(JSONArray a, JSONArray b) {
    if (policy == STRICT) {
      if (a.length() != b.length()) {
        return false;
      }
    }

    if (policy == SIMPLE) {
      if (a.length() > b.length()) {
        return false;
      }
    }

    boolean[] am = new boolean[a.length()];
    boolean[] bm = new boolean[b.length()];

    for (int i = 0; i < a.length(); ++i)
      if (am[i] == false) {
        for (int j = 0; j < b.length(); ++j)
          if (bm[j] == false) {
            try {
              if (isEquals(a.get(i), b.get(j))) {
                am[i] = true;
                bm[j] = true;
                break;
              }
            } catch (JSONException e) {
              e.printStackTrace();
            }
          }
      }

    for (int i = 0; i < am.length; ++i)
      if (!am[i]) {
        return false;
      }

    if (policy == STRICT) {
      for (int j = 0; j < bm.length; ++j)
        if (!bm[j]) {
          return false;
        }
    }

    return true;
  }
Пример #5
0
  public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

    for (int i = 0; i < a.length(); i++) {

      JSONObject o = a.getJSONObject(i);
      Contact c = new Contact();
      c.unserializeJSON(o.getJSONObject("contact"));
      v.addElement(c);
    }

    contacts = new Contact[v.size()];
    v.copyInto(contacts);
  }
  public void descargarDatos() {

    try {

      connectionURL = Strings.HTTP_SW + "getMunicipios/" + tipoConexion;

      // Dialog.alert(connectionURL+"<<URL");

      conn = (HttpConnection) Connector.open(connectionURL);
      conn.setRequestProperty("Content-Type", "application/json");
      // System.out.println("Response code : "+conn.getResponseCode());

      if (conn.getResponseCode() == HttpConnection.HTTP_OK) {

        is = conn.openInputStream();
        int ch = -1;
        bos = new ByteArrayOutputStream();
        while ((ch = is.read()) != -1) {
          bos.write(ch);
        }
        response = new String(bos.toByteArray(), "UTF-8");

        // JSONObject temporalError = new  JSONObject ( response );

        // errorCode    = temporalError.getString("errotCode");
        // errorMessage = temporalError.getString("errorMessage");

        JSONObject objeto1 = new JSONObject(response);
        String resultado1 = objeto1.getString("response");
        // Dialog.alert(resultado1+"<<");
        JSONObject objeto2 = new JSONObject(resultado1);
        errorCode = objeto2.getString("errorCode");
        errorMessage = objeto2.getString("errorMessage");

        if (errorCode.equals("0")) {

          JSONArray jsonMainArr = objeto2.getJSONArray("msg");

          for (int i = 0; i < jsonMainArr.length(); i++) {

            JSONObject childJSONObject = jsonMainArr.getJSONObject(i);

            IdMunicipio.addElement(childJSONObject.get("idMunicipio"));
            NombreMunicipio.addElement(childJSONObject.get("municipio"));
          }

        } else if (errorCode.equals("1")) {
          if (Display.getWidth() == 320) {
            errorMessage = "noData1_320.png";
          }
          if (Display.getWidth() == 360) {
            errorMessage = "noData1_360.png";
          }
          if (Display.getWidth() == 480) {
            errorMessage = "noData1_480.png";
          }
          if (Display.getWidth() == 640) {
            errorMessage = "noData1.png";
          }
        }
      }

    } catch (Exception e) {
      // TODO: handle exception
      if (Display.getWidth() == 320) {
        errorMessage = "noData1_320.png";
      }
      if (Display.getWidth() == 360) {
        errorMessage = "noData1_360.png";
      }
      if (Display.getWidth() == 480) {
        errorMessage = "noData1_480.png";
      }
      if (Display.getWidth() == 640) {
        errorMessage = "noData1.png";
      }
    } finally {
      if (conn != null)
        try {
          conn.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (bos != null)
        try {
          bos.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
    municipiocompras.setIdMunicipio(IdMunicipio);
    municipiocompras.setNombreMunicipio(NombreMunicipio);

    municipiocompras.seterrorCode(errorCode);
    municipiocompras.seterrorMessage(errorMessage);
  }
Пример #7
0
  public SearchProductoCx(int idcategoria, String PalabraFiltro) {

    SearchProductoSG searchproducto = new SearchProductoSG();

    try {

      connectionURL =
          Strings.HTTP_SW
              + "getListaDeProductosPorCategoriaPorNombre/"
              + idcategoria
              + "/"
              + PalabraFiltro
              + tipoConexion;

      conn = (HttpConnection) Connector.open(connectionURL);
      conn.setRequestProperty("Content-Type", "application/json");
      // System.out.println("Response code : "+conn.getResponseCode());

      if (conn.getResponseCode() == HttpConnection.HTTP_OK) {

        is = conn.openInputStream();
        int ch = -1;
        bos = new ByteArrayOutputStream();
        while ((ch = is.read()) != -1) {
          bos.write(ch);
        }
        response = new String(bos.toByteArray(), "UTF-8");

        JSONObject objeto1 = new JSONObject(response);
        String resultado1 = objeto1.getString("response");

        JSONObject objeto2 = new JSONObject(resultado1);
        errorCode = objeto2.getString("errorCode");
        errorMessage = objeto2.getString("errorMessage");

        JSONArray jsonMainArr = objeto2.getJSONArray("msg");

        for (int i = 0; i < jsonMainArr.length(); i++) {

          JSONObject childJSONObject = jsonMainArr.getJSONObject(i);

          IdProducto.addElement(childJSONObject.get("idProducto"));
          Nombre.addElement(childJSONObject.get("nombre"));
        }
      }

    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      if (conn != null)
        try {
          conn.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (bos != null)
        try {
          bos.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }

    searchproducto.setIdProducto(IdProducto);
    searchproducto.setNombre(Nombre);
    searchproducto.seterrorCode(errorCode);
    searchproducto.seterrorMessage(errorMessage);
  }
Пример #8
0
    public Object convertToUseForm(Object key, byte[] bytes) {
      JSONObject responseJson;

      try {
        responseJson = new JSONObject(new String(bytes));
      } catch (JSONException ex) {
        // #debug
        L.e("bytes are not a JSON object", featURL, ex);
        return null;
      }

      JSONArray entries = new JSONArray();
      final Vector vector = new Vector();

      try {
        final JSONObject feed = ((JSONObject) responseJson).getJSONObject("feed");
        entries = feed.getJSONArray("entry");
      } catch (JSONException e) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));

        // #debug
        L.e("JSON no result", featURL, e);
      }

      for (int i = 0; i < entries.length(); i++) {
        try {
          final JSONObject jsonObject = entries.getJSONObject(i);
          final String title = jsonObject.getJSONObject("title").getString("$t");
          final String author =
              jsonObject
                  .getJSONArray("author")
                  .getJSONObject(0)
                  .getJSONObject("name")
                  .getString("$t");
          final String thumbUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$thumbnail")
                  .getJSONObject(0)
                  .getString("url");
          final String imageUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$content")
                  .getJSONObject(0)
                  .getString("url");

          // #mdebug
          L.i("JSON parsed title: ", title);
          L.i("JSON parsed author: ", author);
          L.i("JSON parsed thumb url: ", thumbUrl);
          L.i("JSON parsed image url: ", imageUrl);
          // #enddebug

          vector.addElement(new PicasaImageObject(title, author, thumbUrl, imageUrl));
        } catch (JSONException e) {
          // #debug
          L.e("JSON item parse error", featURL, e);
        }
      }

      if (entries.length() == 0) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));
      }

      return vector;
    }