Example #1
1
  public void commandAction(Command command, Displayable displayable) {

    if (command == back) {
      controller.MainMenu();
    }
    if (command == viewStages) {
      busNos = busNo.getString().toUpperCase();
      fetchStagesData(busNos);
    }
    if (command == backToNo) {

      controller.getDisp().setCurrent(this);
    }
    if (command == MapStages) {
      controller.pointresultCanvas.busStagesPoints.removeAllElements();
      for (int mapStages = 0; mapStages < PostionAddress.length - 1; mapStages++) {
        String pos = PostionAddress[mapStages];
        String[] point = StringUtil.split(pos, "||");
        System.out.println(point[0] + "== " + point[1]);
        controller.pointBusStages(point[0], point[1]);
      }

      String pos = PostionAddress[Stages.getSelectedIndex()];
      String[] point = StringUtil.split(pos, "||");
      controller.gotoSpot(point[0], point[1]);
      controller.ShowPointingCanvas();
    }
    if (command == backToPlaces) {

      controller.getDisp().setCurrent(Stages);
    }
    if (command == showBuses) {
      controller.showProgressBar();
      fetchBusNoData();
    }
    if (command == showStages) {
      busNos = busesNearMe.getString(busesNearMe.getSelectedIndex()).toUpperCase();
      fetchStagesData(busNos);
    }
    if (command == viewBusPosition) {

      String[] data = GetBusPosition("Tt");
      String Message = "" + data[0] + "\n" + data[1] + "\n" + data[2];
      controller.showBusPosition(Message, data[3], data[4]);
    }
  }
Example #2
1
  public String fetchStagesData(String busno) {
    controller.showProgressBar();
    Stages.deleteAll();

    Stages.setTitle("Stages of " + busno);
    new Thread() {
      public void run() {

        String addloc = "";

        StreamConnection c = null;
        InputStream s = null;
        StringBuffer b = new StringBuffer();

        try {
          System.out.println("The Bus URL is " + uploadWebsite + busNos);
          c = (StreamConnection) Connector.open(uploadWebsite + busNos);
          s = c.openDataInputStream();
          int ch;
          int k = 0;
          while ((ch = s.read()) != -1) {
            // System.out.print((char) ch);
            b.append((char) ch);
          }

          result = b.toString();
          System.out.print(result);
          // String stagesString = fetchStagesData();
          JSONObject ff = new JSONObject(result);
          String data = ff.getString("stagepts");
          JSONArray jsonArray = new JSONArray(data);
          for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonUser = jsonArray.getJSONObject(i);
            String lat = jsonUser.getString("lat");
            String lon = jsonUser.getString("lon");
            String stagename = jsonUser.getString("stagename");
            Stages.append(stagename, null);
            System.out.println(stagename);
            //   Location[i] = stagename;
            addloc = lat + "||" + lon + "~~" + addloc;
          }
          if (Stages.size() < 1) {

            // controller.showAlert("Entered Bus number not found", 3, AlertType.ERROR);
            Stages.append("Entered Bus number not found", null);

            Stages.removeCommand(MapStages);
            Stages.removeCommand(showBuses);

            //   controller.setCurrentScreen(FormData);

          } else {
            PostionAddress = StringUtil.split(addloc, "~~");
            Stages.addCommand(MapStages);
            Stages.addCommand(showBuses);
            //  Stages.setCommandListener(FormData);

          }
          controller.getDisp().setCurrent(Stages);
        } catch (Exception e) {
          System.out.print(e);

          /*   new Thread(){
              public void run(){
                    controller.showAlert("Network Error", 3, AlertType.ERROR);
              }
          }.start();*/

          controller.setCurrentScreen(FormData);
          new Thread() {
            public void run() {
              controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO);
            }
          }.start();
        }
      }
    }.start();

    return result;
  }
Example #3
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();
    }
  }
Example #4
0
  private void refreshImage() {
    controller.showProgressBar();
    new Thread() {

      public void run() {

        if (fmViewPng.size() > 0) for (int i = 0; i < fmViewPng.size(); i++) fmViewPng.delete(i);

        // Download image and set as the first (only) item on the form
        Image im;

        try {
          String[] chunk;

          String tt = ArrayOfResults[LiveCameras.getSelectedIndex()];

          chunk = StringUtil.split(tt, "~");
          String imagename = chunk[0].toString();

          if ((im = getImage(imagename)) != null) {
            ImageItem ii = new ImageItem(null, im, ImageItem.LAYOUT_DEFAULT, null);
            // If there is already an image, set (replace) it
            if (fmViewPng.size() != 0) fmViewPng.set(0, ii);
            else // Append the image to the empty form
            fmViewPng.append(ii);
          } else fmViewPng.append("Unsuccessful download.");

          // Display the form with the image
          controller.getDisp().setCurrent(fmViewPng);

        } catch (Exception e) {
          System.err.println("Msg: " + e.toString());
          // alert.setString(e.toString());
          controller.showAlert("Network Error", 0, AlertType.ERROR);
          // controller.getDisp().setCurrent(ListCams);
          // switchDisplayable(getAlert(), getCamList());
        }
      }
    }.start();
  }
Example #5
0
  public void commandAction(Command command, Displayable displayable) {
    if (command == camList) {
      controller.setCurrentScreen(this);
      controller.setCurrentScreen(this);
    }
    if (command == refreshList) {
      controller.showProgressBar();
      refreshCamList();
    }
    if (command == cmBack) {
      controller.getDisp().setCurrent(LiveCameras);
    }
    if (command == RefreshImage) {
      refreshImage();
    }
    if (command == viewImage) {

      refreshImage();
    }
    if (command == TrafOption) {
      if (this.getString(this.getSelectedIndex()).equals("Cameras")) {
        LiveCameras();

      } else if (this.getString(this.getSelectedIndex()).equals("Traffic Fines")) {

        if (VehicleNoForm == null) {

          VehicleNoForm = new Form("Traffic Fines");
          vehNo = new TextField("Vehicle Number", "", 100, TextField.ANY);

          VehicleNoForm.append(vehNo);
          VehicleNoForm.addCommand(Vehicleback);
          VehicleNoForm.addCommand(VehicleOk);

          VehicleNoForm.setCommandListener(this);
        }

        controller.setCurrentScreen(VehicleNoForm);

      } else {
        new Thread() {
          public void run() {
            getTrafficSpots();
          }
        }.start();
      }
    }
    if (command == bckMenu) {
      controller.MainMenu();
    }

    if (command == Vehicleback) {
      controller.setCurrentScreen(this);
    }
    if (command == VehicleOk) {
      if (vehNo.getString().equals("")) {

        controller.showAlert("Enter the vehicle number", 0, AlertType.ERROR);
      } else {

        controller.showProgressBar();
        new Thread() {
          public void run() {

            Downloader dwn = new Downloader(controller);
            String message =
                dwn.requestForData(
                    "http://125.17.140.50/notices/vehiclefinedetails.aspx?veh_no="
                        + vehNo.getString());
            vehNo.setString("");
            controller.showAlert(message, 0, AlertType.INFO);
          }
        }.start();

        new Thread() {
          public void run() {

            controller.setCurrentScreen(VehicleNoForm);
          }
        }.start();
      }
    }
  }