📄 multimediaviewer.java
字号:
/*
* JVending - J2ME MMS Client
* Copyright (C) 2004 Shane Isbell
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jvending.messaging.client;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.midlet.MIDlet;
import org.jvending.messaging.*;
/**
* @author Shane Isbell
* @version 1.0.0a
* @created 04/03/27
*/
public class MultimediaViewer implements CommandListener {
private Command next = new Command("Next", Command.SCREEN, 1);
private Command send = new Command("Send", Command.SCREEN, 1);
private Command info = new Command("Info", Command.SCREEN, 1);
private Command back = new Command("Back", Command.SCREEN, 1);
private Form[] mimeForm;
private int head;
private int size;
private Display display;
private MultimediaMessage mediaMessage;
private MIDlet controller;
public MultimediaViewer(MIDlet controller, MultimediaMessage mediaMessage) {
this.controller = controller;
this.mediaMessage = mediaMessage;
}
public void commandAction(Command command, Displayable displayable) {
if(command == next) {
head = ++head % size;
display.setCurrent(mimeForm[head]);
} else if(command == send) {
//send MMS
} else if(command == info) {
Form f = new Form("Client Info");
f.append("This product includes software developed by JVending (http://www.jvending.org/).");
f.addCommand(back);
f.setCommandListener(this);
display.setCurrent(f);
} else if(command == back) {
display.setCurrent(mimeForm[0]);
}
}
public void displayWaitPage() {
Form form = new Form("Wait");
form.append("Please wait for the MMS Notification to Arrive");
display = Display.getDisplay(controller);
display.setCurrent(form);
}
int num = 0;
public void displayView() {
MimeMessage mimeMessage = mediaMessage.getMimeMessage();
if(mimeMessage != null) {
size = (int) mimeMessage.getNumberOfEntries() + 1;
mimeForm = new Form[size];
MultipartEntry[] multipartEntry = mimeMessage.getEntries();
int contentType = 0;
byte[] data = null;
Image image = null;
for (int i = 1; i < size; i++) {
mimeForm[i] = new Form("Content");
contentType = (int) multipartEntry[i - 1].getContentType();
if(contentType == ContentType.TEXT_PLAIN) {
mimeForm[i].append(new String(multipartEntry[i - 1].getData()));
} else {
data = multipartEntry[i - 1].getData();
try {
image = Image.createImage(data, 0, data.length);
mimeForm[i].append(image);
} catch(IllegalArgumentException e) { mimeForm[i].append("Could Not Recognize Content Type");}//skips unrec. types
}
mimeForm[i].append(ContentType.intToString(contentType));
mimeForm[i].addCommand(next);
mimeForm[i].addCommand(send);
mimeForm[i].setCommandListener(this);
}
} else {
size = 1;
mimeForm = new Form[size];
}
TextField[] tf = fillInHeaders(mediaMessage);
mimeForm[0] = new Form("MMS Header Info", tf);
mimeForm[0].addCommand(next);
mimeForm[0].addCommand(send);
mimeForm[0].addCommand(info);
mimeForm[0].setCommandListener(this);
display = Display.getDisplay(controller);
display.setCurrent(mimeForm[0]);
}
//FIX ME: Need a more dynamic way of doing this. Not all of these fields are required
private TextField[] fillInHeaders(MultimediaMessage message) {
TextField[] tf = {
new TextField("Message Id", message.getHeader("X_MMS_MESSAGE_TYPE"), 50, TextField.ANY),
new TextField("Transaction Id", message.getHeader("X_MMS_TRANSACTION_ID"), 50, TextField.ANY),
// new TextField("Version", message.getHeader("X_MMS_MMS_VERSION"), 50, TextField.ANY),
new TextField("From", message.getHeader("FROM"), 30, TextField.ANY),
new TextField("To", message.getHeader("TO"), 30, TextField.ANY),
// new TextField("Size", String.valueOf(size), 30, TextField.ANY),
// new TextField("CC", message.getHeader("CC"), 30, TextField.ANY),
// new TextField("BCC", message.getHeader("BCC"), 30, TextField.ANY),
// new TextField("Date", message.getHeader("DATE"), 20, TextField.ANY),
new TextField("Subject", message.getHeader("SUBJECT"), 50, TextField.ANY),
// new TextField("Class", message.getHeader("X_MMS_MESSAGE_CLASS"), 20, TextField.ANY),
new TextField("Priority", message.getHeader("X_MMS_PRIORITY"), 20, TextField.ANY)
};
return tf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -