/** 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);
  }
Пример #2
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();
    }
  }
Пример #3
0
 public static void addAll(Vector to, Vector all) {
   synchronized (to) {
     for (int i = 0; i < all.size(); ++i) {
       to.addElement(all.elementAt(i));
     }
   }
 }
Пример #4
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);
  }
Пример #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));
     }
   }
 }
Пример #6
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;
 }
Пример #7
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);
     }
   }
 }
 public void addElement(Object obj) {
   height = width = 0; // discarding cached values
   super.addElement(obj);
 }
Пример #9
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);
    }
  }
Пример #10
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);
  }