📄 uiutils.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* 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
*
*/
/*
* Utils.java
*/
package com.funambol.mailclient.ui.utils;
import com.funambol.mail.Message;
import com.funambol.mailclient.mm.MessageManager;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.util.Log;
import com.funambol.util.MailDateFormatter;
import java.util.Calendar;
import java.util.Date;
import javax.microedition.lcdui.Font;
public class UiUtils {
private static String CONTINUE_STRING = "..";
//private constructor to avoid instantiation
private UiUtils() {
}
/**
* @return the best string to be drawn in the given region, i.e. the complete
* string if it fits, or partial string with ".." if it does not fit
*
* @param text the text to be drawn
* @g the graphics object
* @w the width of the region
*
*/
//Should we put this somewhere else??
public static String cutString(String text, int w, Font font) {
if(font.stringWidth(text)<=w) {
return text;
} else {
int width=0;
for (int i=1;i<text.length();i++) {
//width = font.substringWidth( text, 0, text.length()-i)+font.stringWidth(CONTINUE_STRING);
width=font.stringWidth(text.substring(0,text.length()-i).trim())+font.stringWidth(CONTINUE_STRING);
if (width<w) {
return text.substring(0,text.length()-i).trim()+ CONTINUE_STRING;
}
}
}
//we should never arrive here!
return "";
}
/**
* @return true if message is in inbox
* @param message the message
*/
public static boolean isIncoming(Message message) {
return (UIController.getFolderInfo(MessageManager.INBOX).getName().equals(
message.getParent().getName() ));
}
/**
* @return true if message is in outbox or draft
* @param message the message
*/
public static boolean isOutgoing(Message message) {
return (UIController.getFolderInfo(MessageManager.OUTBOX).getName().equals(
message.getParent().getName()) ||
(UIController.getFolderInfo(MessageManager.DRAFTS).getName().equals(
message.getParent().getName() )) );
}
/**
* @return true if message is in sent
* @param message the message
*/
public static boolean isSent(Message message) {
return (UIController.getFolderInfo(MessageManager.SENT).getName().equals(
message.getParent().getName() )) ;
}
/**
*
* @param inDate the input date
* @return the given date as a formatted string, if the date is in the
* same day we are now it return the time, otherwise the day and month
*/
public static String formatDate(Date inDate) {
String date;
Calendar now=Calendar.getInstance();
Calendar sent=Calendar.getInstance();
sent.setTime(inDate);
if (now.get(Calendar.DAY_OF_MONTH)==sent.get(Calendar.DAY_OF_MONTH)
&& now.get(Calendar.MONTH)==sent.get(Calendar.MONTH) &&
now.get(Calendar.YEAR)==sent.get(Calendar.YEAR) )
date= MailDateFormatter.getFormattedStringFromDate(inDate,
MailDateFormatter.FORMAT_HOURS_MINUTES, ":");
else
date= MailDateFormatter.getFormattedStringFromDate(inDate,
MailDateFormatter.FORMAT_MONTH_DAY, "/");
return date;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -