您好我正在尝试使用eclipse制作我的第一个黑莓应用程序,该应用程序的主要思想仅仅是显示基于内部GPS的当前位置LatLong<<跳过这部分。
现在的问题是我一直在寻找关于如何更换“消息预览”窗口的情况,这个窗口会在单击自定义消息时出现 这是我的代码
Class DemoMessage
public final class DemoMessage implements ApplicationMessage
{
static final int DEMO_MESSAGE_TYPE = 0x01;
private String _sender;
private String _subject;
private String _message;
private long _receivedTime;
private boolean _isNew;
private boolean _deleted;
private String _replyMessage;
private long _replyTime;
private EncodedImage _previewPicture;
public DemoMessage()
{
_isNew = true;
}
DemoMessage(String sender, String subject, String message, long receivedTime)
{
_sender = sender;
_subject = subject;
_message = message;
_receivedTime = receivedTime;
_isNew = true;
}
void reply(String message)
{
markRead();
_replyMessage = message;
_replyTime = System.currentTimeMillis();
}
void messageDeleted()
{
_isNew = false;
_deleted = true;
}
void markAsNew()
{
_isNew = true;
_replyMessage = null;
}
void markRead()
{
_isNew = false;
}
boolean isNew()
{
return _isNew;
}
boolean hasReplied()
{
return _replyMessage != null;
}
void setSender(String sender)
{
_sender = sender;
}
void setSubject(String subject)
{
_subject = subject;
}
void setReceivedTime(long receivedTime)
{
_receivedTime = receivedTime;
}
void setMessage(String message)
{
_message = message;
}
String getMessage()
{
return _message;
}
void setPreviewPicture(EncodedImage image)
{
_previewPicture = image;
}
public String getContact()
{
return _sender;
}
public int getStatus()
{
if(_isNew)
{
return MyApp.STATUS_NEW;
}
if(_deleted)
{
return MyApp.STATUS_DELETED;
}
if(_replyMessage != null)
{
return MyApp.STATUS_REPLIED;
}
return MyApp.STATUS_OPENED;
}
public String getSubject()
{
if(_replyMessage != null)
{
return "Re: " + _subject;
}
else
{
return _subject;
}
}
public long getTimestamp()
{
return _receivedTime;
}
public int getType()
{
return DEMO_MESSAGE_TYPE;
}
public String getPreviewText()
{
if(_message == null)
{
return null;
}
StringBuffer buffer = new StringBuffer(_message);
if(_replyMessage != null)
{
buffer.append(". You replied on ").append(new Date(_replyTime)).append(": ").append(_replyMessage);
}
return buffer.length() > 100 ? buffer.toString().substring(0, 100) + " ..." : buffer.toString();
}
public Object getCookie(int cookieId)
{
return null;
}
public Object getPreviewPicture()
{
return _previewPicture;
}
}
Class DemoMessageScreen
public final class DemoMessageScreen extends MainScreen
{
public DemoMessageScreen()
{
setTitle("Title");
ReadableListImpl mylist= new ReadableListImpl();
ApplicationMessageFolder folder = null;
ApplicationFolderIntegrationConfig config = new ApplicationFolderIntegrationConfig(true, true, ApplicationDescriptor.currentApplicationDescriptor());
if(ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL)==null)
{
folder = ApplicationMessageFolderRegistry.getInstance().registerFolder(0x33c7ce29883abe5fL, "Test Folder", new ReadableListImpl(),config );
}
else
{
folder = ApplicationMessageFolderRegistry.getInstance().getApplicationFolder(0x33c7ce29883abe5fL);
}
DemoMessage msg = new DemoMessage("me@here.com", "Pizza Toppings","What would you like on your pizza?", System.currentTimeMillis());
mylist.addMessage(msg);
folder.fireElementAdded(msg,true);
System.out.println("nr of messages"+folder.hasNewMessages());
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
EncodedImage image = EncodedImage.getEncodedImageResource("indicatorOn.png" );
ApplicationIcon icon = new ApplicationIcon( image );
ApplicationIndicator indicator = reg.register( icon, false, true);
indicator.setNotificationState(true);
ApplicationIndicator appIndicator = reg.getApplicationIndicator();
appIndicator.setIcon(icon);
appIndicator.setValue(appIndicator.getValue() + 1);
//appIndicator.setNotificationState(true);
appIndicator.setVisible(true);
}
public boolean onClose()
{
close();
return true;
}
static class ReadableListImpl implements ReadableList
{
private Vector messages;
ReadableListImpl()
{
messages = new Vector();
}
public Object getAt(int index)
{
return messages.elementAt(index);
}
public int getAt(int index, int count, Object[] elements, int destIndex)
{
return 0;
}
public int getIndex(Object element)
{
return messages.indexOf(element);
}
public int size()
{
return messages.size();
}
void addMessage(DemoMessage message)
{
messages.addElement(message);
}
void removeMessage(DemoMessage message)
{
messages.removeElement(message);
}
}
}
和Class MyApp
public class MyApp extends UiApplication
{
static final int FLAG_REPLIED = 1 << 16;
static final int FLAG_DELETED = 1 << 17;
static final int BASE_STATUS = ApplicationMessage.Status.INCOMING;
static final int STATUS_NEW = BASE_STATUS | ApplicationMessage.Status.UNOPENED;
static final int STATUS_OPENED = BASE_STATUS | ApplicationMessage.Status.OPENED;
static final int STATUS_REPLIED = BASE_STATUS | ApplicationMessage.Status.OPENED | FLAG_REPLIED;
static final int STATUS_DELETED = BASE_STATUS | FLAG_DELETED;
public static void main(String[] args)
{
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp()
{
pushScreen(new DemoMessageScreen());
}
}
代码很好,我可以在主屏幕和消息文件夹中看到通知,但是如果点击它会调用“消息预览”窗口,我不知道如何注册点击处理程序以从通知消息栏启动我的应用程序消息文件夹,怎么办?提前谢谢
答案 0 :(得分:0)
问题解决了,我必须在类的主体中声明ApplicationDescriptor。