?? contactlist.java.svn-base
字號:
/******************************************************************************* Jimm - Mobile Messaging - J2ME ICQ clone Copyright (C) 2003-05 Jimm Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************** File: src/jimm/ContactList.java Version: ###VERSION### Date: ###DATE### Author(s): Manuel Linsmayer, Andreas Rossbacher, Artyomov Denis *******************************************************************************/package jimm;import jimm.Jimm;import jimm.comm.Message;import jimm.comm.PlainMessage;import jimm.comm.SendMessageAction;import jimm.comm.Util;import jimm.comm.Icq;import jimm.util.ResourceBundle;import java.util.Hashtable;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.util.Enumeration;import java.util.Random;import java.util.Vector;import javax.microedition.lcdui.*;import javax.microedition.rms.RecordStore;import javax.microedition.rms.RecordStoreException;import javax.microedition.rms.RecordStoreNotFoundException;//#sijapp cond.if target!="DEFAULT"#import javax.microedition.media.*;import javax.microedition.media.control.*;//#sijapp cond.end#//#sijapp cond.if target is "RIM"#//import net.rim.device.api.system.Alert;//# import net.rim.device.api.system.LED;//#sijapp cond.end#import DrawControls.*;import jimm.Options;//////////////////////////////////////////////////////////////////////////////////public class ContactList implements CommandListener, VirtualTreeCommands, VirtualListCommands, JimmScreen//#sijapp cond.if target!="DEFAULT"# , PlayerListener//#sijapp cond.end#{ /* Status (all are mutual exclusive) TODO: move status to ContactItem */ public static final int STATUS_EVIL = 0x00003000; public static final int STATUS_DEPRESSION = 0x00004000; public static final int STATUS_HOME = 0x00005000; public static final int STATUS_WORK = 0x00006000; public static final int STATUS_LUNCH = 0x00002001; public static final int STATUS_AWAY = 0x00000001; public static final int STATUS_CHAT = 0x00000020; public static final int STATUS_DND = 0x00000002; public static final int STATUS_INVISIBLE = 0x00000100; public static final int STATUS_INVIS_ALL = 0x00000200; public static final int STATUS_NA = 0x00000004; public static final int STATUS_OCCUPIED = 0x00000010; public static final int STATUS_OFFLINE = 0xFFFFFFFF; public static final int STATUS_NONE = 0x10000000; public static final int STATUS_ONLINE = 0x00000000; /* Sound notification typs */ public static final int SOUND_TYPE_MESSAGE = 1; public static final int SOUND_TYPE_ONLINE = 2; public static final int SOUND_TYPE_TYPING = 3; private static long lastLoginTime; private static boolean needPlayMessNotif = false; //#sijapp cond.if target!="DEFAULT"# public static boolean playerFree = true; private static long stopTime = StopTimeControl.RESET;//#sijapp cond.end# private static ContactList _this; /** ************************************************************************* */ /* Version id numbers */ static private int ssiListLastChangeTime = -1; static private int ssiNumberOfItems = 0; /* Update help variable */ private static boolean haveToBeCleared; /* Contact items */ private static Vector cItems; /* Group items */ private static Vector gItems; private static boolean treeBuilt = false, treeSorted = false; /* Contains tree nodes by groip ids */ private static Hashtable gNodes = new Hashtable(); /* Tree object */ private static VirtualTree tree; /* Images for icons */ final public static ImageList cliImages = new ImageList(); // private static int onlineCounter; private static boolean Params[] = new boolean[2]; /* Initializer */ static { try {//#sijapp cond.if target="MIDP2" | target="SIEMENS2"# cliImages.setScale(Options.getInt(Options.OPTION_IMG_SCALE));//#sijapp cond.end# cliImages.load("/clicons.png", -1, -1, -1, Jimm.getPhoneVendor() == Jimm.PHONE_NOKIA); } catch (Exception e) { e.printStackTrace(); } } /* Constructor */ public ContactList() { _this = this; try { load(); } catch (Exception e) { haveToBeCleared = false; cItems = new Vector(); gItems = new Vector(); } //#sijapp cond.if modules_ANTISPAM="true"# antiSpamLoadList();//#sijapp cond.end# tree = new VirtualTree(null, false); tree.setVTCommands(this); tree.setVLCommands(this); tree.setCyclingCursor(true); tree.setFontSize( (JimmUI.statusOnlineImg != null & JimmUI.statusOnlineImg.getHeight() < 16) ? VirtualList.SMALL_FONT : VirtualList.MEDIUM_FONT); tree.setStepSize(0); //#sijapp cond.if modules_TRAFFIC is "true" # updateTitle(Traffic.getSessionTraffic()); //#sijapp cond.else # //# updateTitle(0); //#sijapp cond.end# tree.setCommandListener(this); } /* *********************************************************** */ final static public int SORT_BY_NAME = 1; final static public int SORT_BY_STATUS = 0; static private int sortType; public int vtCompareNodes(TreeNode node1, TreeNode node2) { Object obj1 = node1.getData(); Object obj2 = node2.getData(); ContactListItem item1 = (ContactListItem) obj1; ContactListItem item2 = (ContactListItem) obj2; int result = 0; switch (sortType) { case SORT_BY_NAME: result = item1.getSortText().compareTo(item2.getSortText()); break; case SORT_BY_STATUS: int weight1 = item1.getSortWeight(); int weight2 = item2.getSortWeight(); if (weight1 == weight2) result = item1.getSortText().compareTo(item2.getSortText()); else result = (weight1 < weight2) ? -1 : 1; break; } return result; } /* *********************************************************** */ static void resetLoginTimer() { lastLoginTime = System.currentTimeMillis(); } /* Returns reference to tree */ static public VirtualList getVisibleContactListRef() { return tree; } /* Returns the id number #1 which identifies (together with id number #2) the saved contact list version */ static public int getSsiListLastChangeTime() { return ssiListLastChangeTime; } /* Returns the id number #2 which identifies (together with id number #1) the saved contact list version */ static public int getSsiNumberOfItems() { return (ssiNumberOfItems); } // Returns number of contact items static public int getSize() { return cItems.size(); } static private ContactItem getCItem(int index) { return (ContactItem) cItems.elementAt(index); } // Returns all contact items as array static public synchronized ContactItem[] getContactItems() { ContactItem[] cItems_ = new ContactItem[cItems .size()]; ContactList.cItems.copyInto(cItems_); return (cItems_); } // Returns all group items as array static public ContactListGroupItem[] getGroupItems() { synchronized (_this) { ContactListGroupItem[] gItems_ = new ContactListGroupItem[gItems.size()]; ContactList.gItems.copyInto(gItems_); return (gItems_); } } static public void showStatusInCaption(int status, int xStatus) { StatusInfo statInfo = JimmUI.findStatus(StatusInfo.TYPE_STATUS, status == -1 ? Icq.getCurrentStatus() : status); StatusInfo xStatInfo = JimmUI.findStatus(StatusInfo.TYPE_X_STATUS, xStatus == -1 ? Options.getInt(Options.OPTION_XSTATUS) : xStatus); tree.setCapImage(new Image[] { statInfo != null ? statInfo.getImage() : null, xStatInfo != null ? xStatInfo.getImage() : null }); } public void activate() { ContactList.activateList(); } public boolean isScreenActive() { return tree.isActive(); } // Request display of the given alert and the main menu afterwards static public void activateList(Alert alert) { ContactList.tree.activate(Jimm.display, alert); } // Request display of the main menu static public void activateList() { Params[0] = Options.getBoolean(Options.OPTION_CL_CLIENTS); Params[1] = Options.getBoolean(Options.OPTION_XSTATUSES); showStatusInCaption(-1, -1); //#sijapp cond.if modules_TRAFFIC is "true" # updateTitle(Traffic.getSessionTraffic()); //#sijapp cond.else # updateTitle(0); //#sijapp cond.end# // show contact list tree.lock(); buildTree(); sortAll(); tree.unlock(); JimmUI.setColorScheme(tree, true, -1, true); tree.removeAllCommands(); tree.addCommandEx(JimmUI.cmdSelect, VirtualList.MENU_TYPE_RIGHT_BAR); tree.addCommandEx(JimmUI.cmdMenu, VirtualList.MENU_TYPE_LEFT_BAR); ContactList.tree.activate(Jimm.display); JimmUI.setLastScreen(_this, true); //#sijapp cond.if target isnot "DEFAULT" # if (needPlayMessNotif) { needPlayMessNotif = false; playSoundNotification(SOUND_TYPE_MESSAGE); } //#sijapp cond.end# } // is called by options form when options changed static public void optionsChanged(boolean needToRebuildTree, boolean needToSortContacts) { if (needToRebuildTree) treeBuilt = false; if (needToSortContacts) treeSorted = false; } // Tries to load contact list from record store static private void load() throws Exception, IOException, RecordStoreException { // Initialize vectors ContactList.cItems = new Vector(); ContactList.gItems = new Vector(); // Check whether record store exists String[] recordStores = RecordStore.listRecordStores(); boolean exist = false; for (int i = 0; i < recordStores.length; i++) { if (recordStores[i].equals("contactlist")) { exist = true; break; } } if (!exist) throw (new Exception()); // Open record store RecordStore cl = RecordStore.openRecordStore("contactlist", false); try { // Temporary variables byte[] buf; ByteArrayInputStream bais; DataInputStream dis; // Get version info from record store buf = cl.getRecord(1); bais = new ByteArrayInputStream(buf); dis = new DataInputStream(bais); if (!(dis.readUTF().equals(Jimm.VERSION))) throw (new IOException()); // Get version ids from the record store buf = cl.getRecord(2); bais = new ByteArrayInputStream(buf); dis = new DataInputStream(bais); ssiListLastChangeTime = dis.readInt(); ssiNumberOfItems = dis.readUnsignedShort(); // Read all remaining items from the record store int marker = 3; //#sijapp cond.if modules_DEBUGLOG is "true"# System.gc(); long mem = Runtime.getRuntime().freeMemory(); //#sijapp cond.end# byte type; while (marker <= cl.getNumRecords()) { // Get type of the next item buf = cl.getRecord(marker++); bais = new ByteArrayInputStream(buf); dis = new DataInputStream(bais); // Loop until no more items are available //int load = 0; while (dis.available() > 0) { // Get item type type = dis.readByte(); // Normal contact if (type == 0) { // Instantiate ContactItem object and add to vector ContactItem ci = new ContactItem(); ci.loadFromStream(dis); ContactList.cItems.addElement(ci); } // Group of contacts else if (type == 1) { // Instantiate ContactListGroupItem object and add to vector ContactListGroupItem gi = new ContactListGroupItem(); gi.loadFromStream(dis); ContactList.gItems.addElement(gi); } } } //#sijapp cond.if modules_DEBUGLOG is "true"# buf = null; dis = null; bais = null; System.gc(); System.out.println("\n clload mem used: " + (mem - Runtime.getRuntime().freeMemory())); //#sijapp cond.end# } finally { // Close record store cl.closeRecordStore(); } } // Save contact list to record store static protected void save() throws IOException, RecordStoreException { // Try to delete the record store try { RecordStore.deleteRecordStore("contactlist"); } catch (RecordStoreNotFoundException e) { // Do nothing } // Create new record store
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -