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

📄 chathistory.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* Jimm - Mobile Messaging - J2ME ICQ clone Copyright (C) 2003-08  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/ChatHistory.java Version: ###VERSION###  Date: ###DATE### Author(s): Andreas Rossbacher, Artyomov Denis, Dmitry Tunin *******************************************************************************/package jimm;import java.util.*;import javax.microedition.lcdui.*;import jimm.comm.Icq;import jimm.comm.Message;import jimm.comm.PlainMessage;import jimm.comm.SearchAction;import jimm.comm.SysNoticeAction;import jimm.comm.SystemNotice;import jimm.comm.UrlMessage;import jimm.comm.Util;import jimm.util.ResourceBundle;//#sijapp cond.if modules_HISTORY is "true" #import jimm.HistoryStorage;//#sijapp cond.end#import DrawControls.TextList;import DrawControls.VirtualList;import DrawControls.VirtualListCommands;class MessData{	private long time;	private int rowData;	private int messId;	public MessData(boolean incoming, long time, int textOffset,			boolean contains_url, int messId)	{		this.messId = messId;		this.time = time;		this.rowData = (textOffset & 0xFFFFFF) | (contains_url ? 0x8000000 : 0)				| (incoming ? 0x4000000 : 0);	}	public boolean getIncoming()	{		return (rowData & 0x4000000) != 0;	}	public long getTime()	{		return time;	}	public int getOffset()	{		return (rowData & 0xFFFFFF);	}		public int getMessId()	{		return messId;	}	//#sijapp cond.if target is "MIDP2" | target is "SIEMENS2" | target is "MOTOROLA"#	public boolean isURL()	{		return (rowData & 0x8000000) != 0;	}	//#sijapp cond.end#}class ChatTextList implements VirtualListCommands, CommandListener, JimmScreen{	// UI modes	final public static int UI_MODE_NONE = 0;	final public static int UI_MODE_DEL_CHAT = 1;		// Chat	TextList textList;	private static final Command cmdMsgReply = new Command(ResourceBundle.getString("reply", ResourceBundle.FLAG_ELLIPSIS), Command.OK, 1);	private static final Command cmdCloseChat = new Command(ResourceBundle.getString("close"), Jimm.cmdBack, 2);	private static final Command cmdCopyText = new Command(ResourceBundle.getString("copy_text"), Command.ITEM, 4);	private static final Command cmdReplWithQuota = new Command(ResourceBundle.getString("quote", ResourceBundle.FLAG_ELLIPSIS), Command.ITEM, 3);	private static final Command cmdAddUrs = new Command(ResourceBundle.getString("add_user", ResourceBundle.FLAG_ELLIPSIS), Command.ITEM, 5);	private static final Command cmdDenyAuth = new Command(ResourceBundle.getString("deny"), Command.CANCEL, 1);		/* Request authorisation from a contact */	private static final Command cmdReqAuth = new Command(ResourceBundle.getString("requauth"), Command.ITEM, 1);			/* Grand authorisation a for authorisation asking contact */	private static final  Command cmdGrantAuth = new Command(ResourceBundle.getString("grant"), Command.ITEM, 1);	//#sijapp cond.if modules_HISTORY is "true" #	private static final  Command cmdAddToHistory = new Command(ResourceBundle.getString("add_to_history"), Command.ITEM, 6);	//#sijapp cond.end#	// Delete Chat History	private static final  Command cmdDelChat = new Command(ResourceBundle.getString("delete_chat", ResourceBundle.FLAG_ELLIPSIS), Command.ITEM, 8);		/* Show the message menu */	private static final Command cmdContactMenu = new Command(ResourceBundle.getString("user_menu"), Command.ITEM, 7);		public String ChatName;	ContactItem contact;	private Vector messData = new Vector();	private int messTotalCounter = 0;	private long lastMsgTime = 0;	private boolean lastDirection;	ChatTextList(String name, ContactItem contact)	{		textList = new TextList(null);		textList.setMode(VirtualList.CURSOR_MODE_DISABLED);		textList.setFontSize(Options.getBoolean(Options.OPTION_CHAT_SMALL_FONT) ? VirtualList.SMALL_FONT : VirtualList.MEDIUM_FONT);		this.contact = contact;		ChatName = name;		textList.setVLCommands(this);	}		public ContactItem getContact()	{		return contact;	}		public Object getUIControl()	{		return textList;	}		void buildMenu()	{		textList.removeAllCommands();		//#sijapp cond.if target!="RIM" & target!="DEFAULT"#		textList.addCommandEx(JimmUI.cmdMenu, VirtualList.MENU_TYPE_RIGHT_BAR);//#sijapp cond.end#				textList.addCommandEx(cmdMsgReply, VirtualList.MENU_TYPE_RIGHT);		textList.addCommandEx(cmdDelChat, VirtualList.MENU_TYPE_RIGHT);		textList.addCommandEx(cmdCopyText, VirtualList.MENU_TYPE_RIGHT);				if (contact.getBooleanValue(ContactItem.CONTACTITEM_IS_TEMP)) 			textList.addCommandEx(cmdAddUrs, VirtualList.MENU_TYPE_RIGHT);				if (JimmUI.getClipBoardText() != null) textList.addCommandEx(cmdReplWithQuota, VirtualList.MENU_TYPE_RIGHT);				//#sijapp cond.if modules_HISTORY is "true" #		if (!Options.getBoolean(Options.OPTION_HISTORY)) textList.addCommandEx(cmdAddToHistory, VirtualList.MENU_TYPE_RIGHT);		//#sijapp cond.end#				if (contact.getBooleanValue(ContactItem.CONTACTITEM_NO_AUTH))			textList.addCommandEx(cmdReqAuth, VirtualList.MENU_TYPE_RIGHT);				textList.addCommandEx(cmdContactMenu, VirtualList.MENU_TYPE_RIGHT);				textList.addCommandEx(cmdCloseChat, VirtualList.MENU_TYPE_LEFT_BAR);				checkTextForURL();		checkForAuthReply();				textList.setCommandListener(this);	}		public boolean isVisible()	{		if (textList != null) return textList.isActive();		return false;	}		public void commandAction(Command c, Displayable d)	{		Jimm.aaUserActivity();				/* User selected chat to delete */		if (JimmUI.getCurScreenTag() == UI_MODE_DEL_CHAT)		{			if (c == JimmUI.cmdOk)			{				int delType = -1;				switch (JimmUI.getLastSelIndex())				{				case 0:					delType = ChatHistory.DEL_TYPE_CURRENT;					break;				case 1:					delType = ChatHistory.DEL_TYPE_ALL_EXCEPT_CUR;					break;				case 2:					delType = ChatHistory.DEL_TYPE_ALL;					break;				}				ChatHistory.chatHistoryDelete(contact.getStringValue(ContactItem.CONTACTITEM_UIN), delType);				ContactList.activateList();				return;			}			else activate();		}				/* Write new message */		else if (c == cmdMsgReply)		{			JimmUI.writeMessage(contact, null);		}				/* Close current chat */		else if (c == cmdCloseChat)		{			contact.resetUnreadMessages();			JimmUI.backToLastScreen();		}				/* Delete current chat */		else if (c == cmdDelChat)		{			JimmUI.showSelector("delete_chat", JimmUI.stdSelector, this, UI_MODE_DEL_CHAT, true);		}				/* Copy selected text to clipboard */		else if (c == cmdCopyText)		{			ChatHistory.copyText(contact.getStringValue(ContactItem.CONTACTITEM_UIN), ChatName);			textList.addCommandEx(cmdReplWithQuota, VirtualList.MENU_TYPE_RIGHT);		}				/* Reply with quotation */		else if (c == cmdReplWithQuota)		{			JimmUI.writeMessage(contact, JimmUI.getClipBoardText());		}				/* Open URL in web brouser */		//#sijapp cond.if target is "MIDP2" | target is "MOTOROLA" | target is "SIEMENS2"#		else if (c == JimmUI.cmdGotoURL)		{			JimmUI.gotoURL(textList.getCurrText(0, false));		}		//#sijapp cond.end#				/* Add temporary user to contact list */		else if (c == cmdAddUrs)		{			Search search = new Search();			String data[] = new String[Search.LAST_INDEX];			data[Search.UIN] = contact.getStringValue(ContactItem.CONTACTITEM_UIN);			SearchAction act = new SearchAction(search, data, SearchAction.CALLED_BY_ADDUSER);			try			{				Icq.requestAction(act);			} catch (JimmException e)			{				JimmException.handleException(e);			}			SplashCanvas.addTimerTask("wait", act, false);		}				/* Add selected text to history */		//#sijapp cond.if modules_HISTORY is "true" #		else if (c == cmdAddToHistory)		{			int textIndex = textList.getCurrTextIndex();			MessData data = (MessData) getMessData().elementAt(textIndex);			String text = textList.getCurrText(data.getOffset(), false);			if (text == null)				return;			String uin = contact.getStringValue(ContactItem.CONTACTITEM_UIN);			HistoryStorage.addText(uin, text, data.getIncoming() ? (byte) 0					: (byte) 1, data.getIncoming() ? ChatName : ResourceBundle					.getString("me"), data.getTime());		}		//#sijapp cond.end#				/* Grant authorization */		else if (c == cmdGrantAuth)		{			SystemNotice notice = new SystemNotice(					SystemNotice.SYS_NOTICE_AUTHORISE,					contact.getStringValue(ContactItem.CONTACTITEM_UIN),					true, "");			SysNoticeAction sysNotAct = new SysNoticeAction(notice);			try			{				Icq.requestAction(sysNotAct);							contact.setBooleanValue(ContactItem.CONTACTITEM_B_AUTREQUESTS, false);				buildMenu();			} catch (JimmException e)			{				JimmException.handleException(e);				if (e.isCritical()) return;			}		}				/* Deny authorization */		else if (c == cmdDenyAuth)		{			JimmUI.authMessage(JimmUI.AUTH_TYPE_DENY, contact, "reason", null);		}				/* Request autorization */		else if (c == cmdReqAuth)		{			JimmUI.authMessage(JimmUI.AUTH_TYPE_REQ_AUTH, contact, "requauth", "plsauthme");		}				/* Show contact menu */		else if (c == cmdContactMenu)		{			JimmUI.showContactMenu(contact);		}	}		static int getInOutColor(boolean incoming)	{		return incoming 			? JimmUI.INDEXED_COLOR_INCOMING			: JimmUI.INDEXED_COLOR_OUTGOING;	}	Vector getMessData()	{		return messData;	}	public void vlCursorMoved(VirtualList sender)	{		checkTextForURL();	}		void checkTextForURL()	{		//#sijapp cond.if target is "MIDP2" | target is "SIEMENS2" | target is "MOTOROLA"#		textList.removeCommandEx(JimmUI.cmdGotoURL);		int messIndex = textList.getCurrTextIndex();		if (messIndex != -1)		{			MessData md = (MessData) getMessData().elementAt(messIndex);			if (md.isURL()) textList.addCommandEx(JimmUI.cmdGotoURL, VirtualList.MENU_TYPE_RIGHT);		}		//#sijapp cond.end#	}		void checkForAuthReply()	{		if (contact.getBooleanValue(ContactItem.CONTACTITEM_B_AUTREQUESTS))		{			textList.addCommandEx(cmdGrantAuth, VirtualList.MENU_TYPE_RIGHT);			textList.addCommandEx(cmdDenyAuth, VirtualList.MENU_TYPE_RIGHT);		}	}		public void setImages(Image[] images)	{		textList.setCapImage(images);	}	public void vlItemClicked(VirtualList sender)	{	}	public void vlKeyPress(VirtualList sender, int keyCode, int type)	{		boolean keyWasProcessed = false;				Jimm.aaUserActivity();				try // getGameAction can raise exception		{			if (type == VirtualList.KEY_PRESSED)			{				switch (sender.getGameAction(keyCode))				{				case Canvas.LEFT:					keyWasProcessed = ChatHistory.selectNextChat_Internal(this, false);					return;				case Canvas.RIGHT:					keyWasProcessed = ChatHistory.selectNextChat_Internal(this, true);					return;				}			}			if (!keyWasProcessed) JimmUI.execHotKey(contact, keyCode, type);		} 		catch (Exception e) { /* do nothing */ }	}	//#sijapp cond.if target isnot "DEFAULT"#	public void BeginTyping(boolean type)	{		System.out.println("ChatHistory.BeginTyping");		textList.repaint();	}	//#sijapp cond.end#	boolean inOneMinute (long time1, long time2) {		return ( ((time1 / 60) % 60 == (time2 / 60) % 60) ? true : false );	}	void addTextToForm(String from, String message, String url, long time,			boolean red, boolean offline, int messId)	{		int texOffset = 0;		boolean deliveryReqOn = Options.getBoolean(Options.OPTION_DELIV_MES_INFO); 		textList.lock();			boolean shortMsg = (inOneMinute (lastMsgTime, time)) 			&& (lastDirection == red) 			&& !deliveryReqOn;		int lastSize = textList.getSize();				StringBuffer messHeader = new StringBuffer();				if (((Options.getBoolean(Options.OPTION_SHOW_MESS_ICON)) && (!shortMsg)) || deliveryReqOn)		{			textList.addImage(JimmUI.eventPlainMessageImg, "", messTotalCounter);			messHeader.append(' ');		}				if ((Options.getBoolean(Options.OPTION_SHOW_NICK)) && (!shortMsg))		{			messHeader.append(from);			messHeader.append(' ');		}		

⌨️ 快捷键说明

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