⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 historystorage.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
		// previous message command 		else if (c == cmdMsgPrev)		{			moveInList(-1);		}		// find command		else if (c == cmdFind)		{			if (frmFind == null)			{				frmFind = new Form(ResourceBundle.getString("find"));				cmdFindOk = new Command(ResourceBundle.getString("find"),						Command.ITEM, 1);				cmdFindCancel = new Command(ResourceBundle.getString("back"),						Jimm.cmdBack, 2);				tfldFind = new TextField(ResourceBundle						.getString("text_to_find"), "", 64, TextField.ANY);				chsFind = new ChoiceGroup(ResourceBundle.getString("options"),						Choice.MULTIPLE);				chsFind						.append(ResourceBundle.getString("find_backwards"),								null);				chsFind.append(ResourceBundle.getString("find_case_sensitiv"),						null);				chsFind.setSelectedIndex(0, true);				frmFind.addCommand(cmdFindOk);				frmFind.addCommand(cmdFindCancel);				frmFind.append(tfldFind);				frmFind.append(chsFind);				frmFind.setCommandListener(this);			}			Jimm.display.setCurrent(frmFind);			Jimm.setBkltOn(true);		}		// user select ok command in find screen		else if (c == cmdFindOk)		{			HistoryStorage.find(currUin, tfldFind.getString(), chsFind					.isSelected(1), chsFind.isSelected(0));		}		else if (c == cmdFindCancel)		{			activate(Jimm.display);		}		// commands info		else if (c == cmdInfo)		{			RecordStore rs = HistoryStorage.getRS();			try			{				Alert alert = new Alert(ResourceBundle						.getString("history_info"), (new StringBuffer())						.append(ResourceBundle.getString("hist_cur")).append(								": ").append(getSize()).append("\n").append(								ResourceBundle.getString("hist_size")).append(								": ").append(rs.getSize() / 1024).append("\n")						.append(ResourceBundle.getString("hist_avail")).append(								": ").append(rs.getSizeAvailable() / 1024)						.append("\n").toString(), null, AlertType.INFO);				alert.setTimeout(Alert.FOREVER);				Jimm.setBkltOn(true);				Jimm.display.setCurrent(alert);			} catch (Exception e)			{			}		}	} // end 'commandAction'	// Show text message of current message of messages list	void showMessText()	{		if (this.getCurrIndex() >= this.getSize())			return;		if (messText == null)		{			messText = new TextList(null);			messText.setMode(VirtualList.CURSOR_MODE_DISABLED);			messText.setCommandListener(this);						messText.addCommandEx(cmdMsgBack, VirtualList.MENU_TYPE_LEFT_BAR);			//#sijapp cond.if target!="RIM" & target!="DEFAULT"#			messText.addCommandEx(JimmUI.cmdMenu, VirtualList.MENU_TYPE_RIGHT_BAR);//#sijapp cond.end#						messText.addCommandEx(cmdMsgNext, VirtualList.MENU_TYPE_RIGHT);			messText.addCommandEx(cmdMsgPrev, VirtualList.MENU_TYPE_RIGHT);			messText.addCommandEx(cmdMsgCopyText, VirtualList.MENU_TYPE_RIGHT);			messText.setVLCommands(this);			JimmUI.setColorScheme(messText, false, -1, true);		}		CachedRecord record = HistoryStorage.getRecord(currUin, this				.getCurrIndex());		messText.clear();		messText.addBigText(record.date + ":", messText.getTextColor(),				Font.STYLE_BOLD, -1);		messText.doCRLF(-1);//#sijapp cond.if modules_SMILES_STD="true" | modules_SMILES_ANI="true" #		Emotions.addTextWithEmotions(messText, record.text, Font.STYLE_PLAIN, messText.getTextColor(), -1);//#sijapp cond.else#		messText.addBigText(record.text, messText.getTextColor(), Font.STYLE_PLAIN, -1);//#sijapp cond.end#//#sijapp cond.if target != "DEFAULT"#		messText.removeCommandEx(cmdGotoURL);		if (record.contains_url)			messText.addCommandEx(cmdGotoURL, VirtualList.MENU_TYPE_RIGHT);//#sijapp cond.end#		messText.doCRLF(-1);		messText.setCaption(record.from);		messText.activate(Jimm.display);		messText.repaint();	}	// returns UIN of list	static String getCurrUin()	{		return currUin;	}	// sets UIN for list	static void setCurrUin(String currUin_, String currName_)	{		currUin = currUin_;		currName = currName_;	}	// returns size of messages history list	protected int getSize()	{		return HistoryStorage.getRecordCount(currUin);	}	// returns messages history list item data	protected void get(int index, ListItem item)	{		CachedRecord record = HistoryStorage.getCachedRecord(currUin, index);		if (record == null)			return;		item.text = record.shortText;		item.color = (record.type == 0) ? getTextColor() : Options				.getSchemeColor(Options.CLRSCHHEME_OUTGOING, -1);	}}// History storage implementationpublic class HistoryStorage{	//===================================//	//                                   //	//    Data storage implementation    //	//                                   //	//===================================//	static final public int CLEAR_EACH_DAY = 0;	static final public int CLEAR_EACH_WEEK = 1;	static final public int CLEAR_EACH_MONTH = 2;	//static final private int VERSION = 1;	static final private String prefix = "hist";	private static RecordStore recordStore;	private static HistoryStorageList list;	private static String currCacheUin = new String();	private static Hashtable cachedRecords;	private static Vector cachedRecordsOrder;	final static private int TEXT_START_INDEX = 1;	public HistoryStorage()	{		try		{			RecordStore.deleteRecordStore("history");		} catch (Exception e)		{		}	}	// Add message text to contact history	static synchronized public void addText(String uin, // uin sended text  			String text, // text to save			byte type, // type of message 0 - incoming, 1 - outgouing			String from, // text sender			long time // date of message	)	{		byte[] buffer, textData;		int textLen;		boolean lastLine = false;		RecordStore recordStore = null;		if (list != null)		{			if (list.getSize() == 0)				lastLine = true;			else if (list.getCurrIndex() == (list.getSize() - 1))				lastLine = true;		}		boolean isCurrenty = currCacheUin.equals(uin);		try		{			recordStore = isCurrenty ? HistoryStorage.recordStore : RecordStore					.openRecordStore(getRSName(uin), true);			ByteArrayOutputStream baos = new ByteArrayOutputStream();			DataOutputStream das = new DataOutputStream(baos);			das.writeUTF(from);			das.writeUTF(text);			das.writeUTF(Util.getDateString(false, time));			textData = baos.toByteArray();			textLen = textData.length;			buffer = new byte[textLen + TEXT_START_INDEX];			Util.putDWord(buffer, 0, recordStore.getNextRecordID());			buffer[0] = type;			System.arraycopy(textData, 0, buffer, TEXT_START_INDEX, textLen);			recordStore.addRecord(buffer, 0, buffer.length);			if (!isCurrenty && (recordStore != null))			{				recordStore.closeRecordStore();				recordStore = null;			}		} catch (Exception e)		{		}		if ((list != null) && HistoryStorageList.getCurrUin().equals(uin))		{			list.repaint();			if (lastLine)				list.setCurrentItem(list.getSize() - 1);		}	}	// Returns reference for record store	static RecordStore getRS()	{		return recordStore;	}	// Returns record store name for UIN	static private String getRSName(String uin)	{		return prefix + uin;	}	// Opens record store for UIN	static private void openUINRecords(String uin)	{		if (currCacheUin.equals(uin))			return;		try		{			if (recordStore != null)			{				recordStore.closeRecordStore();				recordStore = null;				System.gc();			}			recordStore = RecordStore.openRecordStore(getRSName(uin), true);		} catch (Exception e)		{			recordStore = null;			return;		}		currCacheUin = uin;		if (cachedRecords == null) cachedRecords = new Hashtable();		if (cachedRecordsOrder == null) cachedRecordsOrder = new Vector();	}	// Returns record count for UIN	static public int getRecordCount(String uin)	{		openUINRecords(uin);		int result;		try		{			result = recordStore.getNumRecords();		} catch (Exception e)		{			result = 0;		}		return result;	}	// Returns full data of stored message	static synchronized public CachedRecord getRecord(String uin, int recNo)	{		openUINRecords(uin);		byte[] data;		CachedRecord result = new CachedRecord();		try		{			data = recordStore.getRecord(recNo + 1);			result.type = data[0];			ByteArrayInputStream bais = new ByteArrayInputStream(data,					TEXT_START_INDEX, data.length - TEXT_START_INDEX);			DataInputStream dis = new DataInputStream(bais);			result.from = dis.readUTF();			result.text = dis.readUTF();			result.date = dis.readUTF();//#sijapp cond.if target != "DEFAULT"#			if (Util.parseMessageForURL(result.text) != null)				result.contains_url = true;			else				result.contains_url = false;//#sijapp cond.end#		} 		catch (Exception e)		{			result.text = result.date = result.from = "error";//#sijapp cond.if target != "DEFAULT"#						result.contains_url = false;//#sijapp cond.end#			return null;		}		return result;	}	// returns cached short text of the message for history list	static public CachedRecord getCachedRecord(String uin, int recNo)	{		int maxLen = 20;		CachedRecord cachedRec = (CachedRecord) cachedRecords.get(new Integer(recNo));		if (cachedRec == null)		{			cachedRec = getRecord(uin, recNo);			if (cachedRec == null) return null;			if (cachedRec.text.length() > maxLen)				cachedRec.shortText = cachedRec.text.substring(0, maxLen) + "...";			else				cachedRec.shortText = cachedRec.text;			cachedRec.shortText = cachedRec.shortText.replace('\n', ' ');			cachedRec.shortText = cachedRec.shortText.replace('\r', ' ');			cachedRec.index = new Integer(recNo);			cachedRecords.put(cachedRec.index, cachedRec);		}				// Place record at top of cache		cachedRecordsOrder.removeElement(cachedRec);		cachedRecordsOrder.addElement(cachedRec);		// Maximum 50 records in cache		CachedRecord record;		while (cachedRecordsOrder.size() > 50) 		{			record = (CachedRecord)cachedRecordsOrder.firstElement();			cachedRecordsOrder.removeElementAt(0);			cachedRecords.remove(record.index);		}		record = null;		return cachedRec;	}	// Shows history list on mobile phone screen	static public void showHistoryList(String uin, String nick)	{		clearCache();		openUINRecords(uin);				if (list == null)		{			String caption = ResourceBundle.getString("history");			list = new HistoryStorageList();			list.setCaption(caption);		}				HistoryStorageList.setCurrUin(uin, nick);		list.lock();		if (list.getSize() != 0)			list.setCurrentItem(list.getSize() - 1);		list.unlock();		list.activate(Jimm.display);	}	// Clears messages history for UIN	static synchronized public void clearHistory(String uin)	{		try		{			openUINRecords(uin);			recordStore.closeRecordStore();			recordStore = null;			System.gc();			RecordStore.deleteRecordStore(getRSName(uin));			if (cachedRecords != null) cachedRecords.clear();			if (cachedRecordsOrder != null) cachedRecordsOrder.removeAllElements(); 			currCacheUin = new String();		} catch (Exception e)		{		}	}	// Clears cache before hiding history list	static public void clearCache()	{		cachedRecordsOrder = null;		cachedRecords = null;		list = null;		currCacheUin = new String();	}	static synchronized private boolean find_intern(String uin, String text,			boolean case_sens, boolean back)	{		int index = list.getCurrIndex();		if ((index < 0) || (index >= list.getSize()))			return false;		if (!case_sens)			text = text.toLowerCase();		int size = getRecordCount(uin);		String search_text;		CachedRecord record;		for (;;)		{			if ((index < 0) || (index >= size))				break;			record = getRecord(uin, index);			search_text = case_sens ? record.text : record.text					.toLowerCase();			if (search_text.indexOf(text) != -1)			{				list.setCurrentItem(index);				list.activate(Jimm.display);				record = null;				return true;			}			if (back)				index--;			else				index++;		}		record = null;		return false;	}	// find text	static void find(String uin, String text, boolean case_sens, boolean back)	{		if (list == null)			return;		boolean result = find_intern(uin, text, case_sens, back);		if (result == true)			return;		Alert alert = new Alert(ResourceBundle.getString("find"),				(new StringBuffer()).append(text).append("\n").append(						ResourceBundle.getString("not_found")).toString(),				null, AlertType.INFO);		alert.setTimeout(Alert.FOREVER);		list.activate(Jimm.display, alert);	}	// Clears all records for all uins	static synchronized void clear_all(String except)	{		String exceptRMS = (except == null) ? null : getRSName(except);		try		{			if (recordStore != null)			{				recordStore.closeRecordStore();				recordStore = null;				System.gc();				currCacheUin = new String();			}			String[] stores = RecordStore.listRecordStores();			String store;			for (int i = 0; i < stores.length; i++)			{				store = stores[i];				if (store.indexOf(prefix) == -1)					continue;				if (exceptRMS != null)					if (exceptRMS.equals(store))						continue;				RecordStore.deleteRecordStore(store);			}		} catch (Exception e)		{		}	}}//#sijapp cond.end#

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -