📄 addressbook.java
字号:
pointerEventListener.slash(); } else if (keyCode == '*' && input.length() >= textCur && textCur != 0) { pointerEventListener.star(); } byte index = (byte) (keyCode - KEY_NUM0); if (keyTimer != null && keyMajor == index) //its repeated key { keyTimer.cancel(); } //cancel confirming input if (index < 0 || index > KEYS.length) { keyMajor = -1; } else { if (index != keyMajor) { //again, test if its a repeated key keyMinor = 0; //if no take the key code keyMajor = index; } else { //if yes, change keyMinor keyMinor = (byte) ((keyMinor + 1) % KEYS[keyMajor].length()); } keyTimer = new Timer(); //created new Timer and/or confirm the previously task(can not be canceled anymore) keyTimer.schedule(new KeyConfirmer(), 500);// and schedule new task } repaint(); } //#ifdef MUJMAIL_TOUCH_SCR protected void pointerPressed(int arg0, int arg1) { super.pointerPressed(arg0, arg1); pointerEventProducer.pointerPressed(arg0, arg1); } //#endif private void cancelTimers() { if (curTimer != null) { curTimer.cancel(); curTimer = null; } if (keyTimer != null) { keyTimer.cancel(); } } private void hideButtons() { if (!btnHidden) { removeCommand(view); removeCommand(sendMail); removeCommand(edit); removeCommand(delete); if (mode == MODE_SENDMAIL_BROWSE) { removeCommand(add); removeCommand(delAll); } btnHidden = true; } } private void showButtons() { if (btnHidden) { addCommand(view); addCommand(sendMail); addCommand(edit); addCommand(delete); addCommand(delAll); btnHidden = false; } } protected void hideNotify() { cancelTimers(); } public void paint(Graphics g) { if (busy) { mujMail.alert.setAlert(this,mujMail.getMenu(), Lang.get(Lang.ALRT_AD_LOAD) + Lang.get(Lang.ALRT_WAIT), MyAlert.DEFAULT, AlertType.INFO); return; } if (getAddresses().isEmpty() || mode == MODE_SENDMAIL_BROWSE) { hideButtons(); } else { showButtons(); } if (inputChanged) { int index = search(input.toString()); if (index != -1) { cur = index; } else { cur = 0; } inputChanged = false; } short sh = (short) getHeight(), sw = (short) getWidth(); short size = (short) getAddresses().size(); int y = 0; short fh = (short) g.getFont().getHeight(); int item = 0; g.setColor(0x00ffffff); //background color g.fillRect(0, 0, sw, sh); if (Settings.fontSize == Settings.FONT_NORMAL) g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM)); //set font size for box's headline else g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE)); //set font size for box's headline int maxItemsPerPage = (sh - g.getFont().getHeight() * 2 - 10) / (2 * fh + 2); //headline+searchbar takes some space if (cur >= maxItemsPerPage) { int currentPage = cur / maxItemsPerPage; item = currentPage * maxItemsPerPage; } //headline g.setColor(184, 179, 255); //headline background color y += g.getFont().getHeight() + 3; g.fillRect(0, 0, sw, y); String boxName = mode == MODE_SENDMAIL_BROWSE ? Lang.get(Lang.AD_ADDDING_RCPS) : Lang.get(Lang.AD_ADDRESSBOOK); if (size != 0) { boxName = boxName + " (" + (cur + 1) + "/" + size + ") - " + recipientChoiceStr; } g.setColor(0x00000000); //text color g.drawString(boxName, sw / 2 - g.getFont().stringWidth(boxName) / 2, 1, Graphics.TOP | Graphics.LEFT); //search bar g.setColor(217, 236, 255); //search tab background color g.fillRect(0, y, sw, y + 4); g.setColor(0x00000000); if (Settings.fontSize == Settings.FONT_NORMAL) g.setFont(Font.getDefaultFont()); else g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE)); g.drawImage(img_search, 4, y + 4, Graphics.TOP | Graphics.LEFT); if (keyMajor != -1) { //draw the pressed key char c = shift ? KEYS[keyMajor].charAt(KEYS[keyMajor].length() - 1) : KEYS[keyMajor].charAt(keyMinor); g.setColor(0x0033cc00); g.drawChar(c, sw - 17, y + 4, Graphics.TOP | Graphics.LEFT); } g.setColor(0x00ffffff); //input text background color byte img_search_width = (byte) img_search.getWidth(); g.fillRect(6 + img_search_width, y + 3, sw - 34 - img_search_width, y - 2); g.setColor(0x00000000); if (Settings.fontSize == Settings.FONT_NORMAL) g.setFont(Font.getDefaultFont()); else g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE)); if (!textCurShow) //show the blinking cursor | { g.drawString(input.toString(), 8 + img_search_width, y + 4, Graphics.TOP | Graphics.LEFT); } else { StringBuffer inputString = new StringBuffer(input.toString()); inputString.insert(textCur, '|'); g.drawString(inputString.toString(), 8 + img_search_width, y + 4, Graphics.TOP | Graphics.LEFT); } y = y * 2 + 4; while (y < sh && item < size) { Contact contact = (Contact) getAddresses().elementAt(item); if (item == cur) { g.setColor(121, 111, 255); g.fillRect(0, y, sw, 2 * fh + 1); g.setColor(255, 255, 255); } else { g.setColor(0x00000000); } String cn = contact.name; if (marked.containsKey(contact.getEmail())) //if the contact was marked { cn = "[x] " + contact.name; } if (g.getFont().stringWidth(cn) > sw - 2) { cn = Functions.cutString(cn, 0, sw - 2 - g.getFont().stringWidth(".."), g).trim() + ".."; } g.drawString(cn, 2, y, Graphics.TOP | Graphics.LEFT); y += fh; String ce = contact.getEmail(); if (g.getFont().stringWidth(contact.getEmail()) > sw - 2) { ce = Functions.cutString(contact.getEmail(), 0, sw - 2 - g.getFont().stringWidth(".."), g).trim() + ".."; } g.drawString(ce, 2, y, Graphics.TOP | Graphics.LEFT); y += fh; g.setColor(228, 228, 228); y++; g.drawLine(0, y, sw, y); y++; ++item; } //recursively call repaint() after 500sec to have blinking textcursor if (curTimer == null) { curTimer = new Timer(); curTimer.schedule(new CursorShow(), 0, 500); } } //when user exits from the addressbook, defaults values public void back() { showButtons(); if (mode == MODE_SENDMAIL_BROWSE) { removeCommand(mark); removeCommand(done); removeCommand(flipRcps); addCommand(add); addCommand(delAll); marked.clear(); } if (nextDisplay != this) { mujMail.getDisplay().setCurrent(nextDisplay); } else { mujMail.mainMenu(); } mode = MODE_DEFAULT; nextDisplay = this; input.delete(0, input.length()); keyMajor = -1; textCur = 0; cur = 0; cntForm = null; viewForm = null; } //deletes a selected contact public void delete(int index, boolean sure) { if (0 <= index && index < getAddresses().size()) { Contact contact = (Contact) getAddresses().elementAt(index); ; if (!sure) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_SYS_DEL_CONFIRM) + contact.getEmail() + "?", MyAlert.DEL_CONFIRM, AlertType.CONFIRMATION); return; } try { delFromDB(contact); } catch (MyException ex) { mujMail.alert.setAlert(this, this, ex.getDetails(), MyAlert.DEFAULT, AlertType.ERROR); return; } cur = 0; getEmailHash().remove(contact.getEmail()); getAddresses().removeElementAt(index); initHash(); repaint(); } } //deletes a selected contact from DB only public void delFromDB(Contact contact) throws MyException { MyException exception = null; RecordStore ADRS = Functions.openRecordStore("AddressBook", true); try { ADRS.deleteRecord(contact.DBIndex); } catch (Exception ex) { exception = new MyException(MyException.DB_CANNOT_DEL_CONTACT); } Functions.closeRecordStore(ADRS); if (exception != null) { throw exception; } } public void deleteAll(boolean sure) { if (!sure) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_SYS_DEL_ALL_CONFIRM), MyAlert.DB_CLEAR_CONFIRM, AlertType.CONFIRMATION); return; } try { RecordStore.deleteRecordStore("AddressBook"); } catch (Exception ex) { mujMail.alert.setAlert(this, this, Lang.get(Lang.ALRT_AD_DELETE) + Lang.get(Lang.FAILED), MyAlert.DEFAULT, AlertType.ERROR); return; } getAddresses().removeAllElements(); getEmailHash().clear(); nameHash.clear(); repaint(); } /** * Saves a contact from the form; returns a saved contact or null * (when something's gone wrong); */ public void saveContactForm() { if (cntForm != null) { Contact contact = new Contact( ((TextField) cntForm.get(0)).getString().trim(), ((TextField) cntForm.get(1)).getString().trim(), ((TextField) cntForm.get(2)).getString().trim()); try { saveContact(contact); mujMail.getDisplay().setCurrent(nextDisplay); } catch (MyException ex) { mujMail.alert.setAlert(this, cntForm, ex.getDetailsNocode(), MyAlert.DEFAULT, AlertType.INFO); } } } /** * Saves to DB and containers, hashes * @param contact the contact to be saved * @throws MyException */ public void saveContact(Contact contact) throws MyException { if (contact == null) { throw new MyException(MyException.DB_CANNOT_SAVE_CONTACT); } contact = saveContactToDB(contact); if (mode == MODE_EDIT) { Contact cnt = (Contact) getAddresses().elementAt(cur); getAddresses().removeElementAt(cur); //remove the old one getEmailHash().remove(cnt.getEmail()); mode = MODE_DEFAULT; } //refresh hashes and container getAddresses().addElement(contact); getEmailHash().put(contact.getEmail(), contact); Functions.sort(getAddresses(), Functions.SRT_ORDER_INC, Functions.SRT_CNT_NAME); initHash(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -