📄 contactlist.java.svn-base
字号:
if (p == null) return; setVolume(p, volume); startPlayer (p); } catch (Exception e) {} } private static void playSound(String fileName, int volume) { if (playerFree) playSound_Internal(fileName, volume); else { soundQueue.addElement(fileName); soundQueue.addElement(new Integer(volume)); } } // Reaction to player events. (Thanks to Alexander Barannik for idea!) public void playerUpdate(final Player player, final String event, Object eventData) { if (event.equals(PlayerListener.END_OF_MEDIA)) { if (player!=null) { player.removePlayerListener(_this); player.close(); } playerFree = true; if (soundQueue.size() != 0) { String name = (String)soundQueue.elementAt(0); Integer volume = (Integer)soundQueue.elementAt(1); playSound(name, volume.intValue()); soundQueue.removeElementAt(0); soundQueue.removeElementAt(0); } } else if (event.equals(PlayerListener.CLOSED)) { playerFree = true; } } /* Creates player for file 'source' */ static private Player createPlayer(String source) { if (!playerFree) return null; Player p = Util.createPlayer(source); if (p == null) return null; try { p.realize(); p.prefetch(); updateStopTime(p); p.addPlayerListener(_this); playerFree = false; } catch (MediaException e) { return null; } return p; } // sets volume for player static private void setVolume(Player p, int value) throws MediaException { VolumeControl c = (VolumeControl) p.getControl("VolumeControl"); if (c != null) c.setLevel(value); } static private void updateStopTime(Player p) { StopTimeControl c = (StopTimeControl) p.getControl("StopTimeControl"); if (c != null) c.setStopTime(stopTime); } synchronized static public void BeginTyping(String uin, boolean type) { ContactItem item = getItembyUIN(uin); if (item == null) return; // If the user does not have it add the typing capability if (!item.hasCapability(Icq.CAPF_TYPING)) item.addCapability(Icq.CAPF_TYPING); item.BeginTyping(type); if (type) playSoundNotification(ContactList.SOUND_TYPE_TYPING); if (ChatHistory.chatHistoryShown(uin)) ChatHistory.getChatHistoryAt(uin).BeginTyping(type); else tree.repaint(); } // Play a sound notification static public void playSoundNotification(int notType) { synchronized (_this) { if (Options.getBoolean(Options.OPTION_SILENT_MODE)) return; int not_mode = 0; switch (notType) { case SOUND_TYPE_MESSAGE: not_mode = Options.getInt(Options.OPTION_MESS_NOTIF_MODE); break; case SOUND_TYPE_ONLINE: if ((System.currentTimeMillis()-lastLoginTime) < 3000) return; not_mode = Options.getInt(Options.OPTION_ONLINE_NOTIF_MODE); break; case SOUND_TYPE_TYPING: not_mode = Options.getInt(Options.OPTION_TYPING_MODE) - 1; break; } switch (not_mode) { case 1: try { switch (notType) { case SOUND_TYPE_MESSAGE: Manager.playTone(ToneControl.C4, 500, Options.getInt(Options.OPTION_MESS_NOTIF_VOL)); break; case SOUND_TYPE_ONLINE: case SOUND_TYPE_TYPING: Manager.playTone(ToneControl.C4 + 7, 500, Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL)); } } catch (Exception e) { //Do nothing } break; case 2: if (notType == SOUND_TYPE_MESSAGE) { playSound ( Options.getString(Options.OPTION_MESS_NOTIF_FILE), Options.getInt(Options.OPTION_MESS_NOTIF_VOL) ); } else if (notType == SOUND_TYPE_ONLINE) { playSound ( Options.getString(Options.OPTION_ONLINE_NOTIF_FILE), Options.getInt(Options.OPTION_ONLINE_NOTIF_VOL) ); } else { playSound ( Options.getString(Options.OPTION_TYPING_FILE), Options.getInt(Options.OPTION_TYPING_VOL) ); } break; } } } static public boolean changeSoundMode(boolean activate) { boolean newValue = !Options.getBoolean(Options.OPTION_SILENT_MODE); Options.setBoolean(Options.OPTION_SILENT_MODE, newValue); Options.safeSave(); Alert alert = new Alert(null, ResourceBundle .getString(newValue ? "#sound_is_off" : "#sound_is_on"), null, null); alert.setTimeout(1000); if (activate) tree.activate(Jimm.display, alert); else { Jimm.display.setCurrent(alert, Jimm.display.getCurrent()); Jimm.setBkltOn(false); } return newValue; }//#sijapp cond.end# static ContactItem lastChatItem = null; public void vtGetItemDrawData(TreeNode src, ListItem dst) { ContactListItem item = (ContactListItem) src.getData(); dst.text = item.getText(); dst.leftImage = item.getLeftImage(src.getExpanded()); dst.rightImage = Params[0] ? item.getRightImage() : null; dst.secondLeftImage = Params[1] ? item.getSecondLeftImage() : null; dst.color = item.getTextColor(); dst.fontStyle = item.getFontStyle(); } public void vlCursorMoved(VirtualList sender) {} public void vlItemClicked(VirtualList sender) {} public void vlKeyPress(VirtualList sender, int keyCode, int type) { TreeNode node = tree.getCurrentItem(); ContactItem item = ((node != null) && (node.getData() instanceof ContactItem)) ? (ContactItem) node .getData() : null; JimmUI.execHotKey(item, keyCode, type); if (type == VirtualList.KEY_PRESSED) Jimm.aaUserActivity(); } // Returns number of unread messages static protected boolean getUnreadMessCount() { int count = cItems.size(); for (int i = 0; i < count; i++) if (getCItem(i).isContainingUnreadMessages()) return true; return false; } static public ContactItem[] getItems(ContactListGroupItem group) { Vector data = new Vector(); int gid = group.getId(); int size = getSize(); ContactItem item; for (int i = 0; i < size; i++) { item = getCItem(i); if (item.getIntValue(ContactItem.CONTACTITEM_GROUP) == gid) data.addElement(item); } item = null; ContactItem[] result = new ContactItem[data .size()]; data.copyInto(result); return result; } // Command listener public void commandAction(Command c, Displayable d) { Jimm.aaUserActivity(); // Activate main menu if (c == JimmUI.cmdMenu) { MainMenu.activateMenu(); } // Contact item has been selected else if (c == JimmUI.cmdSelect) { TreeNode node = tree.getCurrentItem(); if (node == null) return; ContactListItem item = (ContactListItem) node.getData(); if (item instanceof ContactItem) { // Activate the contact item menu //#sijapp cond.if target is "RIM"# //# LED.setState(LED.STATE_OFF); //#sijapp cond.end# lastChatItem = (ContactItem) item; lastChatItem.activate(); } if (item instanceof ContactListGroupItem) { boolean newExpanded = !node.getExpanded(); if (!newExpanded) { ContactListGroupItem gItem = (ContactListGroupItem)item; ContactItem[] cItems = getItems(gItem); int unreadCounter = 0; for (int i = 0; i < cItems.length; i++) unreadCounter += (cItems[i].isContainingUnreadMessages() ? 1 : 0); gItem.setMessCount(unreadCounter); } tree.setExpandFlag(node, newExpanded); } } } static private boolean checkIfIdExists(int id) { ContactItem ci; for (int i = cItems.size()-1; i >= 0; i--) { ci = getCItem(i); if (ci.getIntValue(ContactItem.CONTACTITEM_ID) == id) return true; if (ci.getIntValue(ContactItem.CONTACTITEM_INV_ID) == id) return true; if (ci.getIntValue(ContactItem.CONTACTITEM_VIS_ID) == id) return true; if (ci.getIntValue(ContactItem.CONTACTITEM_IGN_ID) == id) return true; } ci = null; ContactListGroupItem gi; for (int i = gItems.size()-1; i >= 0; i--) { gi = (ContactListGroupItem)gItems.elementAt(i); if (gi.getId() == id) return true; } gi = null; return false; } static public int generateNewIdForBuddy() { int range = 0x6FFF; Random rand = new Random(System.currentTimeMillis()); int randint = 0; do { randint = rand.nextInt(); if (randint < 0) randint = randint * (-1); randint = randint % range + 4096; } while ( checkIfIdExists(randint) ); return randint; }//#sijapp cond.if modules_ANTISPAM="true" # static private final String ANTISPAM_RMS_NAME = "antispam_"; static private final int ANTISPAM_RMS_VERS = 1; static private final Hashtable antiSpamList = new Hashtable(); static private final Object antiSpamTrue = new Object(); static private final Object antiSpamAnsSent = new Object(); static public boolean antiSpamCheckContactFor(String uin, String message) { if (Options.getBoolean(Options.OPTION_ANTI_SPAM) == false) return true; Object state = antiSpamList.get(uin); if (state == antiSpamTrue) return true; if (state == antiSpamAnsSent) { if (message != null && Options.getString(Options.OPTION_ANTI_SPAM_ANS).equals(message.trim())) { antiSpamSendMess(uin, ResourceBundle.getString("antispam_good")); antiSpamList.put(uin, antiSpamTrue); antiSpamSaveList(); } return false; } else { long status = Options.getLong(Options.OPTION_ONLINE_STATUS); if (status != ContactList.STATUS_INVIS_ALL && status != ContactList.STATUS_INVISIBLE) { String messText = ResourceBundle.getString("antispam_mess")+Options.getString(Options.OPTION_ANTI_SPAM_QUESTION); boolean ok = antiSpamSendMess(uin, messText); if (ok) antiSpamList.put(uin, antiSpamAnsSent); } } return false; } static private boolean antiSpamSendMess(String uin, String text) { ContactItem ci = new ContactItem(); ci.setStringValue(ContactItem.CONTACTITEM_UIN, uin); PlainMessage plainMsg = new PlainMessage(Options.getString(Options.OPTION_UIN), ci, Message.MESSAGE_TYPE_NORM, Util.createCurrentDate(false), text); try { Icq.requestAction(new SendMessageAction(plainMsg)); } catch (JimmException e) { return false; } return true; } static public void antiSpamSaveList() { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(ANTISPAM_RMS_VERS); int size = 0; Enumeration e = antiSpamList.keys(); while (e.hasMoreElements()) if (antiSpamList.get(e.nextElement()) == antiSpamTrue) size++; System.out.println("antiSpamSaveList, size="+size); dos.writeInt(size); e = antiSpamList.keys(); String uin; while (e.hasMoreElements()) { uin = (String)e.nextElement(); if (antiSpamList.get(uin) == antiSpamTrue) dos.writeUTF(uin); } RecordStore rs = RecordStore.openRecordStore(ANTISPAM_RMS_NAME, true); while (rs.getNumRecords() < 1) rs.addRecord(null, 0, 0); dos.flush(); byte[] buf = baos.toByteArray(); rs.setRecord(1, buf, 0, buf.length); dos.close(); baos.close(); rs.closeRecordStore(); } catch (Exception e) { e.printStackTrace(); } } static public void antiSpamLoadList() { try { antiSpamList.clear(); RecordStore account = RecordStore.openRecordStore(ANTISPAM_RMS_NAME, false); byte[] buf = account.getRecord(1); account.closeRecordStore(); ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream dis = new DataInputStream(bais); int vers = dis.readInt(); if (vers != ANTISPAM_RMS_VERS) return; int count = dis.readInt(); String uin; for (int i = 0; i < count; i++) { uin = dis.readUTF(); antiSpamList.put(uin, antiSpamTrue); } } catch (Exception e) { e.printStackTrace(); } }//#sijapp cond.end# }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -