Ejemplo n.º 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]);
    }
  }
Ejemplo n.º 2
1
  public String fetchBusNoData() {

    busesNearMe.deleteAll();

    busesNearMe.setTitle("Buses for  " + Stages.getString(Stages.getSelectedIndex()));
    new Thread() {
      public void run() {

        String toF = "";
        try {

          String[] tt = StringUtil.split(Stages.getString(Stages.getSelectedIndex()), " ");
          System.out.println("From field" + tt[0]);
          for (int y = 0; y < tt.length; y++) {
            if (y != tt.length - 1) {
              toF = toF + "" + tt[y] + "%20";
              System.out.println("From field" + toF);
            } else {
              toF = toF + tt[y];
              System.out.print("in else ");
            }
            System.out.print("Out of loop");
          }
          System.out.print(BusNowebsite + toF);
        } catch (Exception e) {
          controller.showAlert("Network Error", 3, AlertType.ERROR);
          displayList();
        }

        String addloc = "";

        StreamConnection c = null;
        InputStream s = null;
        StringBuffer b = new StringBuffer();
        System.out.print(BusNowebsite + toF);
        try {
          c = (StreamConnection) Connector.open(BusNowebsite + toF);
          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 ff1 = new JSONObject(result);
          String data1 = ff1.getString("routes");
          JSONArray jsonArray1 = new JSONArray(data1);

          for (int i = 0; i < jsonArray1.length(); i++) {
            //   JSONObject jsonUser = jsonArray1.getJSONObject(i);
            //    String lat = jsonUser.getString ("lat");
            busesNearMe.append(jsonArray1.optString(i), null);
            System.out.println(jsonArray1.optString(i));
          }

          controller.getDisp().setCurrent(busesNearMe);
        } catch (Exception e) {
          System.out.print("Error " + e);
          //   controller.getDisp().setCurrent(Stages);
          // controller.showAlert("Network Error", 3, AlertType.ERROR);
          //
          //  controller.getDisp().setCurrent(controller.showAlert("Network Error", 3,
          // AlertType.ERROR), Stages);

        }
      }
    }.start();
    controller.getDisp().setCurrent(Stages);
    return result;
  }
Ejemplo n.º 3
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();
      }
    }
  }
Ejemplo n.º 4
0
 public void displayList() {
   controller.getDisp().setCurrent(this);
 }