Ejemplo n.º 1
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);
   }
 }
Ejemplo n.º 2
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);
   }
 }
Ejemplo n.º 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));
     }
   }
 }
Ejemplo n.º 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);
  }
Ejemplo n.º 5
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;
      }
    }
  }
Ejemplo n.º 6
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));
     }
   }
 }
Ejemplo 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;
 }
Ejemplo n.º 8
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);
     }
   }
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
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;
  }
Ejemplo n.º 11
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);
  }
 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();
 }
Ejemplo n.º 14
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);
  }
Ejemplo n.º 15
0
 private boolean isMoveAvailable() {
   return moves.size() > 0;
 }