Example #1
1
  public void refreshCamList() {

    LiveCameras.deleteAll();
    new Thread() {
      public void run() {
        controller.showProgressBar();
        String[] chunk;
        ArrayOfResults = GetDataFromSite();

        System.out.println("ArrayOfResults " + ArrayOfResults);
        try {
          for (int i = 0; i < ArrayOfResults.length - 1; i++) {
            chunk = StringUtil.split(ArrayOfResults[i].toString(), "~");
            LiveCameras.append(chunk[1], null);
          }
          controller.getDisp().setCurrent(LiveCameras);

        } catch (Exception r) {
          System.out.println("In refreshSearchList :" + r);

          //  new Thread(){public void run(){
          //      controller.setCurrentScreen(NetworkErrorAlert);
          //   }}.start();
          controller.setCurrentScreen(traf);
          new Thread() {
            public void run() {
              controller.showAlert(
                  "No cameras available at this moment.", Alert.FOREVER, AlertType.INFO);
            }
          }.start();

          /*
          //alert.setString("Network Error");*/

        }
      }
    }.start();
  }
Example #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;
  }
Example #3
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 #4
1
  public void commandAction(Command command, Displayable displayable) {
    if ((displayable == D_MAIN) && D_MAIN.Responds()) {
      if (command == c_exit) {
        exitMIDlet();
      }
      if (command == c_history) {
        switchDisplayable(null, getL_history());
        Stack st = D_MAIN.getEqHS();
        Enumeration en = st.elements();
        l_history.deleteAll();
        while (en.hasMoreElements()) {
          l_history.append((String) en.nextElement(), null);
        }
      }
      if (command == c_tovars) {
        getL_vars().deleteAll();
        StringBuffer sb;
        Enumeration values = D_MAIN.getEqVars().elements();
        Enumeration names = D_MAIN.getEqVars().keys();
        String name;
        Real value;
        while ((values.hasMoreElements()) && (names.hasMoreElements())) {
          name = String.valueOf(names.nextElement());
          value = new Real(String.valueOf((values.nextElement())));
          Real.NumberFormat n = new Real.NumberFormat();
          n.maxwidth = 17;
          n.fse = Real.NumberFormat.FSE_NONE;
          sb = new StringBuffer(value.toString(n));
          if (chartools.contains(sb, 'e')) {
            StringBuffer ev = new StringBuffer();
            for (int i = sb.length() - 1; i > -1; --i) {
              if (sb.charAt(i) == 'e') {
                sb.deleteCharAt(i);
                break;
              }
              ev.append(sb.charAt(i));
              sb.deleteCharAt(i);
            }
            ev.reverse();
            sb.append(" * 10^(" + ev + ")");
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              l_vars.append(name + " = " + sb.toString(), null);
            }
          } else {
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              getL_vars().append(name + " = " + sb.toString(), null);
            }
          }
        }
        switchDisplayable(null, getL_vars());
      }
    }
    if (displayable == f_welcome) {
      if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);
      }
    } else if (displayable == form) {
      if (command == c_history) {

      } else if (command == c_tovars) {

      }
    } else if (displayable == l_history) {
      if (command == List.SELECT_COMMAND) {

        l_historyAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_insert) {

        if (l_history.size() != 0) {
          StringBuffer sb = new StringBuffer();
          String his = l_history.getString(l_history.getSelectedIndex());
          boolean p_end = false;
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            if (p_end) {
              sb.append(his.charAt(i));
            }
            if (his.charAt(i) == ':') {
              p_end = true;
            }
          }
          sb.deleteCharAt(sb.length() - 1);
          D_MAIN.appendDispCont(" " + sb.toString());
        }
        switchDisplayable(null, D_MAIN);
        D_MAIN.repaint();
      }
    } else if (displayable == l_vars) {
      if (command == List.SELECT_COMMAND) {

        l_varsAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_delvar) {
        try {
          StringBuffer sb = new StringBuffer();
          String his = l_vars.getString(l_vars.getSelectedIndex());
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            sb.append(his.charAt(i));
          }
          D_MAIN.deletevar(sb.toString().trim());
          l_vars.delete(l_vars.getSelectedIndex());
        } catch (error er) {
          switchDisplayable(null, getA_error());
          a_error.setString(er.getMessage());
        }

      } else if (command == c_insert) {
        StringBuffer sb = new StringBuffer();
        String his = l_vars.getString(l_vars.getSelectedIndex());
        for (int i = 0; i < his.length(); i++) {
          if (his.charAt(i) == '=') {
            break;
          }
          sb.append(his.charAt(i));
        }
        D_MAIN.appendDispCont(sb.toString());
        switchDisplayable(null, D_MAIN);

        D_MAIN.repaint();
      }
    }
  }
Example #5
0
 public void setMessage() {
   super.deleteAll();
   for (int i = 0; i < msgs.size(); i++) {
     CallPacket p = (CallPacket) msgs.elementAt(i);
     String s = p.sender + ": " + p.msg;
     append(s, null);
   } // END: for
 } // END: setMsg
Example #6
0
  public void show() {
    contacts.deleteAll();
    //		contacts.removeCommand(selectCommand);

    Vector contactslist = Engine.getEngine().getContacts();
    if (contactslist.size() > 0) {
      //			contacts.addCommand(selectCommand);
      contacts.setSelectCommand(selectCommand);
    }
    for (Enumeration e = contactslist.elements(); e.hasMoreElements(); ) {
      Contact c = (Contact) e.nextElement();
      contacts.append(c.getContact(), null);
    }
    ContactsBean bean = (ContactsBean) Engine.getEngine().getBean(getId());
    if (bean.getContact() != null) {
      int index = contactslist.indexOf(bean.getContact());
      if (index > 0) {
        contacts.setSelectedIndex(index, true);
      }
    }
    getDisplay().setCurrent(contacts);
  }
Example #7
0
  public void showDevices() {
    // clear the screen
    super.deleteAll();

    // for each devices on the list, show the friend name
    if (Milltooth.devices.size() > 0) {
      for (int i = 0; i < Milltooth.devices.size(); i++) {
        try {
          RemoteDevice device = (RemoteDevice) Milltooth.devices.elementAt(i);
          // we put false, meaning don't contact the remote device for the name
          String name = device.getFriendlyName(false);
          append(name, null);

        } catch (Exception e) {
          e.printStackTrace();
        } // END: try..catch
      } // END: for

    } else {
      // no device on list, tell user to press command
      append("[Press Discover Devices]", null);
    } // END: if..else
  } // END: showDevices
Example #8
0
  public void showStudyList(Vector studyList) {
    this.studyList = studyList;

    screen.setTitle(MenuText.SELECT_STUDY() + " - " + title);
    ((List) screen).deleteAll();
    StudyDef study;
    int selectedIndex = OpenXdataConstants.NO_SELECTION;
    Settings settings = new Settings(OpenXdataConstants.STORAGE_NAME_EPIHANDY_SETTINGS, true);
    String val = settings.getSetting(OpenXdataConstants.KEY_LAST_SELECTED_STUDY);

    for (int i = 0; i < studyList.size(); i++) {
      study = (StudyDef) studyList.elementAt(i);
      if (selectedIndex == OpenXdataConstants.NO_SELECTION && val != null) {
        if (study.getId() == Byte.parseByte(val)) selectedIndex = i;
      }

      ((List) screen).append(study.getName(), null);
    }

    if (selectedIndex != OpenXdataConstants.NO_SELECTION)
      ((List) screen).setSelectedIndex(selectedIndex, true);

    display.setCurrent(screen);
  }