Пример #1
0
 private static int[] getVersionDate(String str) {
   String[] svers = Util.explode(str, '.');
   int[] ivers = new int[3];
   for (int num = 0; num < ivers.length; num++) {
     ivers[num] = Util.strToIntDef(num < svers.length ? svers[num] : "", 0);
   }
   return ivers;
 }
Пример #2
0
 // Generates String for Traffic Info Screen
 protected String getTrafficString() {
   Calendar time = Calendar.getInstance();
   time.setTime(savedSince);
   return (Util.makeTwo(time.get(Calendar.DAY_OF_MONTH))
       + "."
       + Util.makeTwo(time.get(Calendar.MONTH) + 1)
       + "."
       + time.get(Calendar.YEAR)
       + " "
       + Util.makeTwo(time.get(Calendar.HOUR_OF_DAY))
       + ":"
       + Util.makeTwo(time.get(Calendar.MINUTE)));
 }
Пример #3
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));
     }
   }
 }
Пример #4
0
 public static String getLocalDayOfWeek(long gmtTime) {
   // local
   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
   cal.setTime(new Date(Util.gmtTimeToLocalTime(gmtTime) * 1000));
   String[] days = {
     "", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"
   };
   return JLocale.getString(days[cal.get(Calendar.DAY_OF_WEEK)]);
 }
Пример #5
0
 private void initItems(FormEx form, String name, boolean[] values) {
   String[] names = Util.explode(name, '|');
   items = new LineChoiseBoolean[names.length];
   int size = Math.min(names.length, values.length);
   for (int i = 0; i < size; i++) {
     items[i] = new LineChoiseBoolean(ResourceBundle.getString(names[i]), values[i]);
     form.append(items[i]);
   }
 }
Пример #6
0
 private boolean[] toByteArray(int values) {
   int size = Util.explode(getNames(), '|').length;
   boolean[] result = new boolean[size];
   int key;
   for (int i = 0; i < size; i++) {
     key = 1 << i;
     result[i] = (values & key) != 0;
   }
   return result;
 }
Пример #7
0
 private String selectSoundType(String name) {
   /* Test other extensions */
   String[] exts = Util.explode("mp3|wav|mid|midi|mmf|amr|imy|", '|');
   for (int i = 0; i < exts.length; ++i) {
     String testFile = name + exts[i];
     if (testSoundFile(testFile)) {
       return testFile;
     }
   }
   return null;
 }
Пример #8
0
 public void commandAction(Command c, Displayable d) {
   boolean[] vals = new boolean[Util.explode(getNames(), '|').length];
   useItems(vals);
   Options.setInt(Options.OPTION_MAGIC_EYE, getValues(vals));
   Options.safe_save();
   if (eye != null) {
     Jimm.setDisplay(eye);
     return;
   }
   Jimm.back();
 }
Пример #9
0
  public static String getLocalDateString(long gmtDate, boolean onlyTime) {
    if (0 == gmtDate) return "***error***";
    int[] localDate = createDate(gmtTimeToLocalTime(gmtDate));

    StringBuilder sb = new StringBuilder(16);

    if (!onlyTime) {
      sb.append(Util.makeTwo(localDate[TIME_DAY]))
          .append('.')
          .append(Util.makeTwo(localDate[TIME_MON]))
          .append('.')
          .append(localDate[TIME_YEAR])
          .append(' ');
    }

    sb.append(Util.makeTwo(localDate[TIME_HOUR]))
        .append(':')
        .append(Util.makeTwo(localDate[TIME_MINUTE]));

    return sb.toString();
  }
Пример #10
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);
   }
 }
Пример #11
0
  public static long createGmtDate(String sdate) {
    Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    try {
      sdate = sdate.trim();
      int[] ofs = sdate.endsWith("Z") ? ofsFieldsB : ofsFieldsA;
      long result;
      if (Character.isDigit(sdate.charAt(0))) {
        int fieldLength = 4; // yearlen
        for (int i = 0; i < calFields.length; ++i) {
          int begIndex = ofs[i];
          int field = strToIntDef(sdate.substring(begIndex, begIndex + fieldLength), 0);
          if (1 == i) {
            field += Calendar.JANUARY - 1;
          }
          fieldLength = 2;
          c.set(calFields[i], field);
        }
        result = Math.max(0, c.getTime().getTime() / 1000);

      } else {
        String[] rfcDate = Util.explode(sdate, ' ');
        c.set(Calendar.YEAR, strToIntDef(rfcDate[3], 0));

        for (int i = 0; i < months.length; ++i) {
          if (months[i].equals(rfcDate[2])) {
            c.set(Calendar.MONTH, i);
            break;
          }
        }
        c.set(Calendar.DAY_OF_MONTH, strToIntDef(rfcDate[1], 0));
        c.set(Calendar.HOUR_OF_DAY, strToIntDef(rfcDate[4].substring(0, 2), 0));
        c.set(Calendar.MINUTE, strToIntDef(rfcDate[4].substring(3, 5), 0));
        c.set(Calendar.SECOND, strToIntDef(rfcDate[4].substring(6), 0));

        long delta =
            strToIntDef(rfcDate[5].substring(1, 3), 0) * 60 * 60
                + strToIntDef(rfcDate[5].substring(3, 5), 0) * 60;
        if ('+' == rfcDate[5].charAt(0)) {
          delta = -delta;
        }
        result = Math.max(0, c.getTime().getTime() / 1000 + delta);
      }
      return result;
    } catch (Exception ignored) {
    }
    return 0;
  }
Пример #12
0
 public static long createLocalDate(String date) {
   try {
     date = date.replace('.', ' ').replace(':', ' ');
     String[] values = Util.explode(date, ' ');
     Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
     c.set(Calendar.YEAR, Util.strToIntDef(values[2], 0));
     c.set(Calendar.MONTH, Util.strToIntDef(values[1], 0) - 1);
     c.set(Calendar.DAY_OF_MONTH, Util.strToIntDef(values[0], 0));
     c.set(Calendar.HOUR_OF_DAY, Util.strToIntDef(values[3], 0));
     c.set(Calendar.MINUTE, Util.strToIntDef(values[4], 0));
     c.set(Calendar.SECOND, 0);
     return localTimeToGmtTime(c.getTime().getTime() / 1000);
   } catch (Exception ignored) {
     return 0;
   }
 }
Пример #13
0
 public static String xmlUnescape(String text) {
   if (-1 == text.indexOf('&')) {
     return text;
   }
   return Util.replace(text, escapedChars, unescapedChars, "&&&&&");
 }
Пример #14
0
  private void playNotification(int notType) {
    final long now = System.currentTimeMillis();
    if (!isCompulsory(playingType) && isCompulsory(notType)) {
      nextPlayTime = 0;
    }
    if (NOTIFY_ALARM == notType) {
      if (!Options.getBoolean(Options.OPTION_ALARM)) return;
      if (now < nextPlayTime) return;
      nextPlayTime = now + 0; // it is changed
      playingType = notType;
      vibrate(1500);
      if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return;
      playNotify(notType, 100);
      return;
    }

    // #sijapp cond.if modules_MAGIC_EYE is "true" #
    // //eye sound
    if (NOTIFY_EYE == notType) { // eye sound
      if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return; // eye sound
      if (Options.getBoolean(Options.OPTION_EYE_NOTIF)) { // eye sound
        if (!_this.play("eye.wav", 60))
          if (!_this.play("eye.amr", 60)) _this.play("eye.mp3", 60); // eye sound
      } // eye sound
    } // eye sound
    // #sijapp cond.end #
    // //eye sound

    int vibraKind = Options.getInt(Options.OPTION_VIBRATOR);
    if (vibraKind == 2) {
      vibraKind = Jimm.isLocked() ? 1 : 0;
    }
    if ((vibraKind > 0) && ((NOTIFY_MESSAGE == notType) || (NOTIFY_MULTIMESSAGE == notType))) {
      vibrate(Util.strToIntDef(Options.getString(Options.OPTION_VIBRATOR_TIME), 150)); // vibra time
    }

    if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return;
    if (now < nextPlayTime) return;
    nextPlayTime = now + 2000;
    playingType = notType;

    // #sijapp cond.if target is "MIDP2" | target is "MOTOROLA" | target is "SIEMENS2"#
    switch (getNotificationMode(notType)) {
      case 1:
        try {
          switch (notType) {
            case NOTIFY_MESSAGE:
              Manager.playTone(ToneControl.C4, 750, Options.getInt(Options.OPTION_MESS_NOTIF_VOL));
              break;
            case NOTIFY_ONLINE:
            case NOTIFY_OFFLINE: // offline sound
            case NOTIFY_TYPING:
            case NOTIFY_OTHER: // other sound
              Manager.playTone(
                  ToneControl.C4 + 7, 750, Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL));
          }

        } catch (Exception e) {
        }
        break;

      case 2:
        int notifyType = NOTIFY_MESSAGE;
        int volume = 0;
        switch (notType) {
          case NOTIFY_MESSAGE:
            volume = Options.getInt(Options.OPTION_MESS_NOTIF_VOL);
            break;

          case NOTIFY_ONLINE:
            volume = Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL);
            break;

          case NOTIFY_OFFLINE: // offline sound
            volume = Options.getInt(Options.OPTION_OFFLINE_NOTIF_VOL); // offline sound
            break; // offline sound

          case NOTIFY_TYPING:
            volume = Options.getInt(Options.OPTION_TYPING_VOL); // typing
            break;

          case NOTIFY_OTHER: // other sound
            volume = Options.getInt(Options.OPTION_OTHER_NOTIF_VOL); // other sound
            break; // other sound
        }
        playNotify(notType, volume);
        break;
    }
  }
Пример #15
0
 public static String getDate(String format, long anyDate) {
   if (0 == anyDate) return "error";
   int[] localDate = createDate(anyDate);
   format = Util.replace(format, "%H", Util.makeTwo(localDate[TIME_HOUR]));
   format = Util.replace(format, "%M", Util.makeTwo(localDate[TIME_MINUTE]));
   format = Util.replace(format, "%S", Util.makeTwo(localDate[TIME_SECOND]));
   format = Util.replace(format, "%Y", "" + localDate[TIME_YEAR]);
   format = Util.replace(format, "%y", Util.makeTwo(localDate[TIME_YEAR] % 100));
   format = Util.replace(format, "%m", Util.makeTwo(localDate[TIME_MON]));
   format = Util.replace(format, "%d", Util.makeTwo(localDate[TIME_DAY]));
   return format;
 }
Пример #16
0
  public boolean execCommand(Protocol protocol, String msg) {
    final String cmd;
    final String param;
    int endCmd = msg.indexOf(' ');
    if (-1 != endCmd) {
      cmd = msg.substring(1, endCmd);
      param = msg.substring(endCmd + 1);
    } else {
      cmd = msg.substring(1);
      param = "";
    }
    String resource = param;
    String newMessage = "";

    int endNick = param.indexOf('\n');
    if (-1 != endNick) {
      resource = param.substring(0, endNick);
      newMessage = param.substring(endNick + 1);
    }
    String xml = null;
    final String on = "o" + "n";
    final String off = "o" + "f" + "f";
    if (on.equals(param) || off.equals(param)) {
      xml = Config.getConfigValue(cmd + ' ' + param, "/jabber-commands.txt");
    }
    if (null == xml) {
      xml = Config.getConfigValue(cmd, "/jabber-commands.txt");
    }
    if (null == xml) {
      return false;
    }

    XmppConnection xmppXml = ((Xmpp) protocol).getConnection();

    String jid = Jid.jimmJidToRealJid(getUserId());
    String fullJid = jid;
    if (isConference()) {
      String nick = ((XmppServiceContact) this).getMyName();
      fullJid = Jid.jimmJidToRealJid(getUserId() + '/' + nick);
    }

    xml = Util.replace(xml, "${jimm.caps}", xmppXml.getCaps());
    xml = Util.replace(xml, "${c.jid}", Util.xmlEscape(jid));
    xml = Util.replace(xml, "${c.fulljid}", Util.xmlEscape(fullJid));
    xml = Util.replace(xml, "${param.full}", Util.xmlEscape(param));
    xml = Util.replace(xml, "${param.res}", Util.xmlEscape(resource));
    xml = Util.replace(xml, "${param.msg}", Util.xmlEscape(newMessage));
    xml = Util.replace(xml, "${param.res.realjid}", Util.xmlEscape(getSubContactRealJid(resource)));
    xml = Util.replace(xml, "${param.full.realjid}", Util.xmlEscape(getSubContactRealJid(param)));

    xmppXml.requestRawXml(xml);
    return true;
  }
Пример #17
0
 public static String xmlEscape(String text) {
   text = StringUtils.notNull(text);
   return Util.replace(text, unescapedChars, escapedChars, "\"'><&");
 }