Exemplo n.º 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();
    }
  }
  /** Creates a new instance of AccountPicker */
  public AccountSelect(Display display, boolean enableQuit) {
    super();
    // this.display=display;

    setTitleItem(new Title(SR.MS_ACCOUNTS));

    accountList = new Vector();
    Account a;

    int index = 0;
    activeAccount = Config.getInstance().accountIndex;
    do {
      a = Account.createFromStorage(index);
      if (a != null) {
        accountList.addElement(a);
        a.active = (activeAccount == index);
        index++;
      }
    } while (a != null);
    if (accountList.isEmpty()) {
      a = Account.createFromJad();
      if (a != null) {
        // a.updateJidCache();
        accountList.addElement(a);
        rmsUpdate();
      }
    }
    attachDisplay(display);
    addCommand(cmdAdd);

    if (enableQuit) addCommand(cmdQuit);

    commandState();
    setCommandListener(this);
  }
Exemplo n.º 3
0
  public void load(String resName, int width, int height) throws IOException {
    Image resImage = ImageList.loadImage(resName);
    if (null == resImage) {
      return;
    }
    int imgHeight = resImage.getHeight();
    int imgWidth = resImage.getWidth();

    if (width == -1) {
      width = Math.min(imgHeight, imgWidth);
    }
    if (height == -1) {
      height = imgHeight;
    }

    this.width = width;
    this.height = height;

    Vector<Icon> tmpIcons = new Vector<Icon>();
    for (int y = 0; y < imgHeight; y += height) {
      for (int x = 0; x < imgWidth; x += width) {
        Icon icon = new Icon(resImage, x, y, width, height);
        tmpIcons.addElement(icon);
      }
    }
    icons = new Icon[tmpIcons.size()];
    tmpIcons.copyInto(icons);
  }
Exemplo n.º 4
0
 public static void addAll(Vector to, Vector all) {
   synchronized (to) {
     for (int i = 0; i < all.size(); ++i) {
       to.addElement(all.elementAt(i));
     }
   }
 }
Exemplo n.º 5
0
 public static void addNew(Vector to, Vector all) {
   synchronized (to) {
     for (int i = 0; i < all.size(); ++i) {
       if (0 <= Util.getIndex(to, all.elementAt(i))) continue;
       to.addElement(all.elementAt(i));
     }
   }
 }
Exemplo n.º 6
0
 public static boolean hasURL(String msg) {
   if (null == msg) return false;
   Vector<String> result = new Vector<String>();
   parseForUrl(result, msg, '.', URL_CHAR_PREV, URL_CHAR_OTHER, 1);
   parseForUrl(result, msg, ':', URL_CHAR_PROTOCOL, URL_CHAR_OTHER, 1);
   parseForUrl(result, msg, '+', URL_CHAR_NONE, URL_CHAR_DIGIT, 1);
   parseForUrl(result, msg, '@', URL_CHAR_PREV, URL_CHAR_OTHER, 1);
   return !result.isEmpty();
 }
Exemplo n.º 7
0
 public static int getIndex(Vector v, Object o) {
   synchronized (v) {
     int size = v.size();
     for (int i = 0; i < size; ++i) {
       if (v.elementAt(i) == o) {
         return i;
       }
     }
   }
   return -1;
 }
Exemplo n.º 8
0
 public static Vector parseMessageForURL(String msg) {
   if (null == msg) return null;
   // we are parsing 100 links only
   final int MAX_LINK_COUNT = 100;
   Vector<String> result = new Vector<String>();
   parseForUrl(result, msg, '.', URL_CHAR_PREV, URL_CHAR_OTHER, MAX_LINK_COUNT);
   parseForUrl(result, msg, ':', URL_CHAR_PROTOCOL, URL_CHAR_OTHER, MAX_LINK_COUNT);
   parseForUrl(result, msg, '+', URL_CHAR_NONE, URL_CHAR_DIGIT, MAX_LINK_COUNT);
   parseForUrl(result, msg, '@', URL_CHAR_PREV, URL_CHAR_OTHER, MAX_LINK_COUNT);
   return result.isEmpty() ? null : result;
 }
Exemplo n.º 9
0
 private void moveCursor(int inc) {
   if (isMoveSelected()) {
     int newIndex = moveIndex + inc;
     if (newIndex >= moves.size()) {
       newIndex = 0;
     }
     if (newIndex < 0) {
       newIndex = moves.size() - 1;
     }
     setCursor(newIndex);
   }
 }
Exemplo n.º 10
0
 public static void sort(Vector subnodes) {
   for (int i = 1; i < subnodes.size(); ++i) {
     Sortable currNode = (Sortable) subnodes.elementAt(i);
     int j = i - 1;
     for (; j >= 0; --j) {
       Sortable itemJ = (Sortable) subnodes.elementAt(j);
       if (compareNodes(itemJ, currNode) <= 0) {
         break;
       }
       subnodes.setElementAt(itemJ, j + 1);
     }
     if (j + 1 != i) {
       subnodes.setElementAt(currNode, j + 1);
     }
   }
 }
Exemplo n.º 11
0
 private Move getSelectedMove() {
   if (isMoveSelected()) {
     return (Move) moves.elementAt(moveIndex);
   } else {
     return null;
   }
 }
Exemplo n.º 12
0
  private static void parseForUrl(
      Vector<String> result, String msg, char ch, int before, int after, int limit) {
    if (limit <= result.size()) {
      return;
    }
    int size = msg.length();
    int findIndex = 0;
    int beginIdx;
    int endIdx;
    for (; ; ) {
      if (findIndex >= size) break;
      int ptIndex = msg.indexOf(ch, findIndex);
      if (ptIndex == -1) break;

      for (endIdx = ptIndex + 1; endIdx < size; ++endIdx) {
        if (!isURLChar(msg.charAt(endIdx), after)) {
          break;
        }
      }

      findIndex = endIdx;
      if (endIdx - ptIndex < 2) continue;

      if (URL_CHAR_NONE != before) {
        for (beginIdx = ptIndex - 1; beginIdx >= 0; --beginIdx) {
          if (!isURLChar(msg.charAt(beginIdx), before)) {
            break;
          }
        }
        if ((beginIdx == -1) || !isURLChar(msg.charAt(beginIdx), before)) {
          beginIdx++;
        }
        if (ptIndex == beginIdx) continue;

      } else {
        beginIdx = ptIndex;
        if ((0 < beginIdx) && !isURLChar(msg.charAt(beginIdx - 1), before)) {
          continue;
        }
      }
      if (endIdx - beginIdx < 5) continue;
      putUrl(result, msg.substring(beginIdx, endIdx));
      if (limit < result.size()) {
        return;
      }
    }
  }
Exemplo n.º 13
0
 /* Divide text to array of parts using serparator charaster */
 public static String[] explode(String text, char separator) {
   if (StringUtils.isEmpty(text)) {
     return new String[0];
   }
   Vector<String> tmp = new Vector<String>();
   int start = 0;
   int end = text.indexOf(separator, start);
   while (end >= start) {
     tmp.addElement(text.substring(start, end));
     start = end + 1;
     end = text.indexOf(separator, start);
   }
   tmp.addElement(text.substring(start));
   String[] result = new String[tmp.size()];
   tmp.copyInto(result);
   return result;
 }
Exemplo n.º 14
0
 public void stateChanged(State state) {
   BoardGame game = (BoardGame) getGame();
   if ((state == game.STATE_THINKING) && (game.getCurrentPlayer() == this)) {
     it.reset(this, game.getBoard());
     while (it.hasMoreElements()) {
       moves.addElement(it.nextElement());
     }
     if (isMoveAvailable()) {
       setCursor(0);
     }
   }
 }
Exemplo n.º 15
0
  /**
   * Gets the amount of storage on the device that this suite is using. This includes the JAD, JAR,
   * management data, and RMS.
   *
   * @return number of bytes of storage the suite is using
   */
  public int getStorageUsed() {
    File file = new File(classSecurityToken);
    RandomAccessStream stream = new RandomAccessStream(classSecurityToken);
    Vector files;
    int storageUsed = 0;

    files = file.filenamesThatStartWith(getStorageRoot());
    for (int i = 0; i < files.size(); i++) {
      try {
        stream.connect((String) files.elementAt(i), Connector.READ);
        try {
          storageUsed += stream.getSizeOf();
        } finally {
          stream.disconnect();
        }
      } catch (IOException ioe) {
        // just move on to the next file
      }
    }

    return storageUsed;
  }
Exemplo n.º 16
0
  public void commandAction(Command command, Displayable displayable) {
    if (command == cmdOk) {
      JabberDataBlock resultForm = new JabberDataBlock("x", null, null);
      resultForm.setNameSpace("jabber:x:data");
      resultForm.setTypeAttribute("submit");

      for (Enumeration e = items.elements(); e.hasMoreElements(); ) {
        JabberDataBlock ch = ((XDataField) e.nextElement()).constructJabberDataBlock();
        if (ch != null) resultForm.addChild(ch);
      }
      XDataFormSubmit(resultForm);
    }
    BombusQD.sd.canvas.show(parentView);
  }
 void commandState() {
   if (accountList.isEmpty()) {
     removeCommand(cmdEdit);
     removeCommand(cmdDel);
     removeCommand(cmdSelect);
     removeCommand(cmdLogin);
     removeCommand(cmdCancel);
   } else {
     addCommand(cmdEdit);
     addCommand(cmdDel);
     addCommand(cmdLogin);
     addCommand(cmdSelect);
     if (activeAccount >= 0) addCommand(cmdCancel); // нельзя выйти без активного аккаунта
   }
 }
Exemplo n.º 18
0
 public static void removeAll(Vector to, Vector all) {
   synchronized (to) {
     int current = 0;
     for (int index = 0; index < to.size(); ++index) {
       if (0 <= Util.getIndex(all, to.elementAt(index))) continue;
       if (current < index) {
         to.setElementAt(to.elementAt(index), current);
         current++;
       }
     }
     if (current < to.size()) to.setSize(current);
   }
 }
Exemplo n.º 19
0
 public void gameAction(int action) {
   BoardGame game = (BoardGame) getGame();
   if ((game.getCurrentPlayer() == this)
       && (game.getState() == game.STATE_THINKING)
       && (getSelectedMove() != null)) {
     switch (action) {
       case Canvas.FIRE:
         game.queueMove(getSelectedMove());
         moves.removeAllElements();
         break;
       case Canvas.LEFT:
       case Canvas.UP:
         moveCursor(-1);
         break;
       case Canvas.DOWN:
       case Canvas.RIGHT:
         moveCursor(1);
         break;
     }
   }
 }
Exemplo n.º 20
0
  /**
   * Install a suite.
   *
   * @param selectedSuite index into the installList
   */
  private void installSuite(int selectedSuite) {
    MIDletStateHandler midletStateHandler = MIDletStateHandler.getMidletStateHandler();
    MIDletSuite midletSuite = midletStateHandler.getMIDletSuite();
    SuiteDownloadInfo suite;
    String displayName;

    suite = (SuiteDownloadInfo) installList.elementAt(selectedSuite);

    midletSuite.setTempProperty(null, "arg-0", "I");
    midletSuite.setTempProperty(null, "arg-1", suite.url);
    midletSuite.setTempProperty(null, "arg-2", suite.label);

    displayName = Resource.getString(ResourceConstants.INSTALL_APPLICATION);
    try {
      midletStateHandler.startMIDlet("com.sun.midp.installer.GraphicalInstaller", displayName);
      /*
       * Give the create MIDlet notification 1 second to get to
       * AMS.
       */
      Thread.sleep(1000);
      notifyDestroyed();
    } catch (Exception ex) {
      StringBuffer sb = new StringBuffer();

      sb.append(displayName);
      sb.append("\n");
      sb.append(Resource.getString(ResourceConstants.ERROR));
      sb.append(": ");
      sb.append(ex.toString());

      Alert a =
          new Alert(
              Resource.getString(ResourceConstants.AMS_CANNOT_START),
              sb.toString(),
              null,
              AlertType.ERROR);
      a.setTimeout(Alert.FOREVER);
      display.setCurrent(a, urlTextBox);
    }
  }
 public void commandAction(Command c, Displayable d) {
   if (c == cmdQuit) {
     destroyView();
     Bombus.getInstance().notifyDestroyed();
   }
   if (c == cmdCancel) {
     destroyView();
     // Account.launchAccount();
     // StaticData.getInstance().account_index=0;
   }
   if (c == cmdLogin) switchAccount(true);
   if (c == cmdSelect) switchAccount(false);
   if (c == cmdEdit) new AccountForm(this, display, (Account) getFocusedObject());
   if (c == cmdAdd) {
     new AccountForm(this, display, null);
   }
   if (c == cmdDel) {
     accountList.removeElement(getFocusedObject());
     rmsUpdate();
     moveCursorHome();
     commandState();
     redraw();
   }
 }
Exemplo n.º 22
0
  public ContactEdit(Display display, Contact c) {
    this.display = display;
    parentView = display.getCurrent();

    StaticData sd = StaticData.getInstance();
    roster = sd.roster;

    Vector groups = sd.roster.groups.getRosterGroupNames();
    cf = Config.getInstance();

    f = new Form(SR.MS_ADD_CONTACT); // locale

    tJid = new TextField(SR.MS_USER_JID, null, 150, TextField.EMAILADDR);

    tNick = new TextField("Name", null, 32, TextField.ANY); // locale
    tGroup = new TextField(SR.MS_GROUP, null, 32, TextField.ANY); // locale

    tGrpList = new ChoiceGroup(SR.MS_GROUP, ConstMIDP.CHOICE_POPUP);
    tTranspList = new ChoiceGroup(SR.MS_TRANSPORT, ConstMIDP.CHOICE_POPUP);

    tAskSubscrCheckBox = new ChoiceGroup(SR.MS_SUBSCRIPTION, ChoiceGroup.MULTIPLE); // locale
    tAskSubscrCheckBox.append(SR.MS_ASK_SUBSCRIPTION, null); // locale

    tGrpList.addCommand(cmdSet);
    tGrpList.setItemCommandListener(this);

    tTranspList.addCommand(cmdSet);
    tTranspList.setItemCommandListener(this);

    // Transport droplist
    tTranspList.append(sd.account.getServer(), null);
    for (Enumeration e = sd.roster.getHContacts().elements(); e.hasMoreElements(); ) {
      Contact ct = (Contact) e.nextElement();
      Jid transpJid = ct.jid;
      if (transpJid.isTransport()) tTranspList.append(transpJid.getBareJid(), null);
    }
    tTranspList.append(SR.MS_OTHER, null); // locale

    try {
      String jid;
      if (c instanceof MucContact) {
        jid = Jid.toBareJid(((MucContact) c).realJid);
      } else {
        jid = c.getBareJid();
      }
      // edit contact
      tJid.setString(jid);
      tNick.setString(c.nick);

      if (c instanceof MucContact) {
        c = null;
        throw new Exception();
      }

      if (c.getGroupType() != Groups.TYPE_NOT_IN_LIST
          && c.getGroupType() != Groups.TYPE_SEARCH_RESULT) {
        // edit contact
        f.setTitle(jid);
        cmdOk = new Command("Update", Command.OK, 1); // locale
        newContact = false;
      } else c = null; // adding not-in-list
    } catch (Exception e) {
      c = null;
    } // if MucContact does not contains realJid

    int sel = -1;
    ngroups = 0;
    String grpName = "";
    if (c != null) grpName = c.getGroup().name;

    if (groups != null) {
      ngroups = groups.size();
      for (int i = 0; i < ngroups; i++) {
        String gn = (String) groups.elementAt(i);
        tGrpList.append(gn, null);

        if (gn.equals(grpName)) sel = i;
      }
    }

    // if (sel==-1) sel=groups.size()-1;
    if (sel < 0) sel = 0;
    // tGroup.setString(group(sel));

    if (c == null) {
      f.append(tJid);
      f.append(tTranspList);
    }
    updateChoise(tJid.getString(), tTranspList);
    f.append(tNick);

    tGrpList.append(SR.MS_NEWGROUP, null);

    tGrpList.setSelectedIndex(sel, true);

    grpFIndex = f.append(tGrpList);

    if (newContact) {
      f.append(tAskSubscrCheckBox);
      tAskSubscrCheckBox.setSelectedIndex(0, true);
    }

    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    f.setCommandListener(this);
    f.setItemStateListener(this);

    display.setCurrent(f);
  }
Exemplo n.º 23
0
 private boolean isMoveAvailable() {
   return moves.size() > 0;
 }
 void rmsUpdate() {
   DataOutputStream outputStream = NvStorage.CreateDataOutputStream();
   for (int i = 0; i < accountList.size(); i++)
     ((Account) accountList.elementAt(i)).saveToDataOutputStream(outputStream);
   NvStorage.writeFileRecord(outputStream, Account.storage, 0, true);
 }
 protected int getItemCount() {
   return accountList.size();
 }
 public VirtualElement getItemRef(int Index) {
   return (VirtualElement) accountList.elementAt(Index);
 }
 public void addElement(Object obj) {
   height = width = 0; // discarding cached values
   super.addElement(obj);
 }
 /**
  * Safe version of setElementAt Sets the component at the specified index of this vector to be the
  * specified object. The previous component at that position is discarded. If index is greater or
  * equal to the current size of the vector, size will be automatically enlarged
  *
  * @param obj
  * @param index
  */
 public void setElementAt(Object obj, int index) {
   height = width = 0; // discarding cached values
   if (index >= elementCount) this.setSize(index + 1);
   super.setElementAt(obj, index);
 }
Exemplo n.º 29
0
  public XDataForm(JabberDataBlock data, String id, String from) {
    this.id = id;
    this.from = from;

    cmdOk = new Command(SR.get(SR.MS_SEND), Command.OK /*Command.SCREEN*/, 1);
    cmdCancel = new Command(SR.get(SR.MS_BACK), Command.BACK, 99);
    // #ifdef DEBUG_CONSOLE
    // #         midlet.BombusQD.debug.add("captcha<<< " + data.toString(),10);
    // #endif

    JabberDataBlock challenge = data.findNamespace("captcha", "urn:xmpp:captcha");
    JabberDataBlock xdata = challenge.findNamespace("x", "jabber:x:data");
    JabberDataBlock oob = data.findNamespace("x", "jabber:x:oob");

    String url = oob.getChildBlockText("url");
    String title = xdata.getChildBlockText("title");

    Vector xData = xdata.getChildBlocks();

    if (null == title) title = "";

    f = new Form(title);
    items = new Vector(0);

    if (url.length() > 0) {
      TextField formItem = new TextField("URL", url, url.length(), TextField.UNEDITABLE);
      f.append(formItem);
    }

    XDataField field;
    String msgcid = "";

    int size = xData.size();
    for (int i = 0; i < size; ++i) {
      JabberDataBlock ch = (JabberDataBlock) xData.elementAt(i);

      if (ch.getTagName().equals("instructions")) {
        f.append(ch.getText());
        f.append("\n");
        continue;
      }
      ;
      if (!ch.getTagName().equals("field")) continue;

      field = new XDataField(ch);
      items.addElement(field);

      if (field.hidden) continue;

      if (field.media != null) msgcid = field.mediaUri.substring(4);
      f.append(field.formItem);
    }

    JabberDataBlock dataImage = data.findNamespace("data", "urn:xmpp:bob");
    String cid = dataImage.getAttribute("cid");
    if (cid.indexOf(msgcid) == 0) {
      try {
        byte[] bytes = Strconv.fromBase64(dataImage.getText());
        Image img = Image.createImage(bytes, 0, bytes.length);
        f.append(new ImageItem(null, img, Item.LAYOUT_CENTER, null));
      } catch (OutOfMemoryError eom) {
        // #ifdef DEBUG_CONSOLE
        // #                 midlet.BombusQD.debug.add("XDataForm OutOfMem",10);
        // #endif
      } catch (Exception e) {
      }
    }

    f.setCommandListener(this);
    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    this.parentView = BombusQD.sd.canvas.getCanvas();
    BombusQD.setCurrentView(f);
  }
Exemplo n.º 30
0
  private static void putUrl(Vector<String> urls, String url) {
    final String skip = "?!;:,.";
    final String openDelemiters = "{[(«";
    final String delemiters = "}])»";
    int cutIndex = url.length() - 1;
    for (; cutIndex >= 0; --cutIndex) {
      char lastChar = url.charAt(cutIndex);
      if (-1 != skip.indexOf(lastChar)) {
        continue;
      }
      int delemiterIndex = delemiters.indexOf(lastChar);
      if (-1 != delemiterIndex) {
        if (-1 == url.indexOf(openDelemiters.charAt(delemiterIndex))) {
          continue;
        }
      }
      break;
    }

    if (cutIndex <= 0) {
      return;

    } else if (cutIndex != url.length() - 1) {
      url = url.substring(0, cutIndex + 1);
    }

    if (-1 == url.indexOf(':')) {
      boolean isPhone = ('+' == url.charAt(0));
      boolean hasDot = false;
      boolean nonDigit = false;
      for (int i = isPhone ? 1 : 0; i < url.length(); ++i) {
        char ch = url.charAt(i);
        if ('.' == ch) {
          hasDot = true;
        } else if (!Character.isDigit(ch)) {
          nonDigit = true;
          break;
        }
      }
      if (isPhone) {
        if (!nonDigit && !hasDot && (7 <= url.length())) {
          url = "tel:" + url;
        } else {
          return;
        }
      } else {
        if (nonDigit) {
          if (-1 == url.indexOf('/')) {
            if (-1 == url.indexOf('@')) return;
            // jid or email
          } else {
            url = "http:\57\57" + url;
          }
        } else {
          return;
        }
      }
    }
    int protoEnd = url.indexOf(':');
    if (-1 != protoEnd) {
      if (url.length() <= protoEnd + 5) {
        return;
      }
      for (int i = 0; i < protoEnd; ++i) {
        if (!isURLChar(url.charAt(i), URL_CHAR_PROTOCOL)) {
          return;
        }
      }
    }
    if (!urls.contains(url)) {
      urls.addElement(url);
    }
  }