📄 mailform.java
字号:
//#endif break; // attachment contexts case MODE_BROWSE: removeCommand(listAttachments); removeCommand(showHeader); removeCommand(showAddresses); //#ifdef MUJMAIL_FS removeCommand(exportToFS); //#endif break; } } /** * Returns a contextID value. */ public byte getContext() { return contextID; } /** * Shows an *.PNG image attachment on the display. We use <code>scaleImage</code> * function to resize image. Since MIDP 1.0 dosn't support loading of pixels from the * image to the buffer, the resized image will lose some information compared to the * previous one. */ private void drawImage(Graphics g) { // clear the display g.setColor(BACKGROUND_COLOR); g.fillRect(0, 0, getWidth(), getHeight()); // encoding is base64 if (msgHeader.getBpEncoding(currAttachmentID) == BodyPart.ENC_BASE64) { try { byte[] data = msgHeader.getBodyPartContentRaw(currAttachmentID); if (data == null) { throw new MyException(MyException.DB_CANNOT_LOAD_BODY); } Image img = Image.createImage(data, 0, data.length); int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); short width = (short) getWidth(), height = (short) getHeight(); short dstHeight, dstWidth; int widthRatio = (width << 16) / imgWidth; int heightRatio = (height << 16) / imgHeight; if (imgWidth <= width && imgHeight <= height) { g.drawImage(img, ((width - imgWidth) >> 1), ((height - imgHeight) >> 1), Graphics.TOP | Graphics.LEFT); } // if image is bigger than display then scale it. else { if (widthRatio > heightRatio) { dstHeight = height; dstWidth = (short) ((imgWidth * heightRatio) >> 16); g.drawImage(Functions.scaleImage(img, dstWidth, dstHeight), ((width - dstWidth) >> 1), 0, Graphics.TOP | Graphics.LEFT); } else { dstHeight = (short) ((imgHeight * widthRatio) >> 16); dstWidth = width; g.drawImage(Functions.scaleImage(img, dstWidth, dstHeight), 0, ((height - dstHeight) >> 1), Graphics.TOP | Graphics.LEFT); } } } catch (MyException ex) { back(); mujMail.alert.setAlert(this, callBox, ex.getDetails(), MyAlert.DEFAULT, AlertType.ERROR); } catch (Exception ex) { back(); mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_VIEW_ATT) + Lang.get(Lang.FAILED) + " " + ex.toString(), MyAlert.DEFAULT, AlertType.ERROR); } catch (Error e) { back(); mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_VIEW_ATT) + Lang.get(Lang.FAILED) + " " + e.toString(), MyAlert.DEFAULT, AlertType.ERROR); } } else { back(); mujMail.alert.setAlert(this, callBox, Lang.get(Lang.ALRT_MF_UNSUPPORTED_FORMAT), MyAlert.DEFAULT, AlertType.ERROR); } } /** * <p> * This method draws all text body parts on the <code> Canvas </code>. It also count replies represented * by ">" character at the beginning of each line and changes a color of the line. * <p> * If the message contains any attachment, the Canvas has a command <code>listAttachments<code> that serves to * list out all attachments available. * * @param dsplText - a Vector that contains displays of text. * @param g - a graphical object. */ private void drawText(String body, Vector dsplText, Graphics g) { // init if (dsplText == null || dsplText.size() == 0) { return; } int fontHeight = g.getFont().getHeight(); int width = getWidth(), height = getHeight(); // clear the display g.setColor(BACKGROUND_COLOR); g.fillRect(0, 0, getWidth(), getHeight()); // draw a scrollbar g.setColor(0x00CCCCCC); g.fillRect(width - 2, 0, 2, height); g.setColor(0x00FF0000); short scrollStep = (short) (height / dsplText.size()); short minStep = 10; if (scrollStep < minStep) { g.fillRect(width - 2, (currDisplay * height) / dsplText.size(), 2, minStep); } else { g.fillRect(width - 2, (currDisplay * height) / dsplText.size(), 2, scrollStep); } // draw a display of text Vector lines = (Vector) dsplText.elementAt(currDisplay); int lineCount = lines.size(); TextDisplayLine line; int x = 0, y = 0; //String substr; int k; for (int i = 0; i < lineCount; i++) { line = (TextDisplayLine) lines.elementAt(i); g.setColor(0x00000000); for (byte j = 1; j <= line.countReplies; j++) { x += 2; g.setColor(COLOR[j % MAX_COLORS]); g.drawLine(x - 1, y, x - 1, y + fontHeight); } k = line.endLn; while (line.beginLn < k) { //we have to remove the '\r' as its displayed on nokia 7370 and maybe others as "..." if (body.charAt(k - 1) == '\n' || body.charAt(k - 1) == '\r') { --k; } else { break; } } if (line.beginLn < k) { g.drawSubstring(body, line.beginLn, k - line.beginLn, x + 1, y, Graphics.TOP | Graphics.LEFT); } x = 0; y += fontHeight; } } private Vector addLineToPage(TextDisplayLine line, Vector page, Vector pages, int maxLinesPerPage) { if (page.size() < maxLinesPerPage) { //this line still fit in the page page.addElement(line); return page; } Vector newPage = new Vector(); //we have to create a new page newPage.addElement(line); pages.addElement(newPage); return newPage; } private Vector parseTextToDisplay(String body, Graphics g) { int bodyLen = body.length(); int x = 0; int dspWidth = getWidth() - 4; // -(left + scrollbarWidth) Vector currentPage = new Vector(); Vector pages = new Vector(); TextDisplayLine line = new TextDisplayLine(); int cursor = 0; char c; Font font = g.getFont(); int maxLinesPerPage = getHeight() / font.getHeight(); byte repliesCounter = 0; boolean quoteMayFollow = true; int bow; //position of the beginning of a word int wordWidth; pages.addElement(currentPage); while (cursor < bodyLen) { c = body.charAt(cursor); switch (c) { case ' ': case '\t': if (x + repliesCounter * 2 + font.charWidth(c) > dspWidth) { //this space doesnt fit in //we add the line to page currentPage = addLineToPage(line, currentPage, pages, maxLinesPerPage); //create a new line that begins where the current line end //with this extra space char in the beginning line = new TextDisplayLine(line.endLn, line.endLn, repliesCounter); //reset to the left x = 0; } ++line.endLn; x += font.charWidth(c); //move to right by this space char break; case '\r': ++line.endLn; break; case '\n': repliesCounter = 0; ++line.endLn; currentPage = addLineToPage(line, currentPage, pages, maxLinesPerPage); line = new TextDisplayLine(line.endLn, line.endLn, repliesCounter); x = 0; break; case '>': if (quoteMayFollow) { //needs to raise line's counter because it can not be affected bt repliesCounter ++line.countReplies; ++repliesCounter; ++line.beginLn; //don't draw this char ++line.endLn; break; } default: //non-whitespace bow = cursor; //beginning of the word is this position wordWidth = font.charWidth(c); //read the whole word while ((cursor + 1) < bodyLen && (c = body.charAt(cursor + 1)) != ' ' && c != '\r' && c != '\t' && c != '\n') { wordWidth += font.charWidth(c); ++cursor; } if (x + repliesCounter * 2 + wordWidth <= dspWidth) {//the word does fit in display width //don't forget +1 because of char at cursor position is the last char of the word line.endLn = cursor + 1; //and String.substring's endIndex is the last char?s position+1 x += wordWidth; } else {//doesn't fit in if (wordWidth + repliesCounter * 2 <= dspWidth) { //does fit in next new line currentPage = addLineToPage(line, currentPage, pages, maxLinesPerPage); //create a new line with the word including the last word's char - cursor+1 line = new TextDisplayLine(line.endLn, cursor + 1, repliesCounter); } else { //too long word that doesn't even fit in new line int i = 0; wordWidth = 0; while (bow + i <= cursor) { //let's try to break it to smaller parts that fit in c = body.charAt(bow + i); if (x + wordWidth + repliesCounter * 2 + font.charWidth(c) <= dspWidth) { ++line.endLn; wordWidth += font.charWidth(c); ++i; } else { //this part of the word doesn't fit in display width //break the word currentPage = addLineToPage(line, currentPage, pages, maxLinesPerPage); line = new TextDisplayLine(line.endLn, line.endLn, repliesCounter); //and reread the char at position (bow+i) -- don't increase i wordWidth = 0; x = 0; } } } x = wordWidth; } break; }//end of switch ++cursor; //for each iteration the cursor moves forward if (c == '\n' || (c == '>' && quoteMayFollow)) { quoteMayFollow = true; } else { quoteMayFollow = false; } } if (line.beginLn != line.endLn) //something remained { addLineToPage(line, currentPage, pages, maxLinesPerPage); } return pages; } protected void paint(Graphics g) { updateEditButton(); setFont(g); //when no first viewable body is not available or is deleted if (getFirstViewableBody(msgHeader) == -1 || (getFirstViewableBody(msgHeader) != firstViewable && contextID != MODE_BROWSE)) { back(); return; } setContextCommand(); // display bodyparts switch (contextID) { case MODE_LIST: listAttachments(); break; case MODE_BASIC: getBPViewingModeWithActions().prepareBeforeDisplayingBP(this); currAttachmentID = firstViewable; //useful when the attachments list returns focus back to the mailform case MODE_BROWSE: // and MODE_BASIC if (!getBPViewingModeWithActions().displayBodyPart(g, this)) return; break; } if (Settings.smallFontMailForm) //set font to back to the default { g.setFont(Font.getDefaultFont()); } } private void setContextCommand() { if (msgHeader.getBox() == mujMail.getInBox()) { addCommand(reply); addCommand(quotedReply); addCommand(replyAll); } else { removeCommand(reply); removeCommand(quotedReply); removeCommand(replyAll); } } //defaults values public void back() { currDisplay = 0; currAttachmentID = 0; textBodyDisplays = null; textBodyString = null; attchList = null; mailAdrList = null; headerForm = null; if (previewMode) { previewMode = false; mujMail.outBox.deleteNowFromBoxAndDB(msgHeader, Trash.TrashModes.NOT_MOVE_TO_TRASH); mujMail.getDisplay().setCurrent(mujMail.sendMail); return; } mujMail.getDisplay().setCurrent(callBox); } //#ifdef MUJMAIL_TOUCH_SCR protected void pointerPressed(int x, int y) { super.pointerPressed(x, y); System.out.println("Pointer pressed: " + x + "; " + y); pointerEventTransformer.pointerPressed(x, y); } //#endif protected void keyPressed(int keyCode) { switch (getGameAction(keyCode)) { case UP: pointerEventListener.up(); break; case DOWN: pointerEventListener.down(); break; case LEFT: pointerEventListener.left(); break; case RIGHT: pointerEventListener.right(); break; case FIRE: pointerEventListener.fire(); } if (keyCode == '7') { pointerEventListener.right(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -