⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 funcanvascontactlist.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
         * used so that height is recalculated at the next paint call.
         */
        public void resetHeight() {
            this.height = 0;
        }
        
        public Contact getContact() {
            return contact;
        }
        
        public int paint(Graphics graphics) {
            
            int h = calculateHeight();
            int w = getWidth();//- H_MARGIN;
            
            drawer.drawBackground(graphics,getWidth(),h, isActive());
            
            if (isActive()) {
                graphics.setColor(graphicalTheme.getHighlightedForegroundColor());
            } else {
                graphics.setColor(graphicalTheme.getForegroundColor());
            }
            
            // translate the graphics to position the icon
            
            //clip the rect where we'll draw the icon
            //graphics.setClip(0,0,getMaxLabelWidth()/2,font.getHeight()/3 - 2 * V_MARGIN);
            graphics.translate( w -15, 1);
            //graphics.setClip(w-15,1,12,8);
            graphics.setClip(0,0,12,8);
            
            drawSwitchEmailIcon(graphics);
            
            graphics.translate( -w +15, -1);
            graphics.setClip( 0, 0, getWidth(), getHeight() );
            
            
            graphics.drawLine(getMaxLabelWidth()+2*H_MARGIN,0,getMaxLabelWidth()+2*H_MARGIN,h);
            graphics.setClip(H_MARGIN,V_MARGIN, getMaxLabelWidth(),h-V_MARGIN);
            graphics.translate(H_MARGIN,V_MARGIN);
            drawLabel(graphics,w,h,isActive());
            graphics.translate(-H_MARGIN, -V_MARGIN);
            graphics.setClip(0,0,w,h);
            graphics.setClip(getMaxLabelWidth()+3*H_MARGIN,V_MARGIN,w-(getMaxLabelWidth()+3*H_MARGIN), h);
            graphics.translate(getMaxLabelWidth()+3*H_MARGIN,V_MARGIN);
            drawName(graphics,w,h,isActive());
            
            
            
            //back to the original graphic
            graphics.translate(-getMaxLabelWidth()-3*H_MARGIN,-V_MARGIN);
            graphics.setClip(0,0,getWidth(),getHeight());
            
            return h;
        }
        
        /**
         * draws the label ("to:", "cc:","bcc:")
         */
        private void drawLabel(Graphics graphics, int w, int h, boolean b) {
            if (isActive())
                graphics.setColor(graphicalTheme.getHighlightedForegroundColor());
            else
                graphics.setColor(graphicalTheme.getForegroundColor());
            
            graphics.setFont(labelFont);
            graphics.drawString(getAddressTypeLabel(),0,0,Graphics.TOP|Graphics.LEFT);
            
        }
        
        private String getAddressTypeLabel() {
            
            switch (state) {
                
                case Address.TO:
                    return Localization.getMessages().TO_LABEL.trim();
                    
                case Address.CC:
                    return Localization.getMessages().CC_LABEL.trim();
                    
                case Address.BCC:
                    return Localization.getMessages().BCC_LABEL.trim();
                    
                default: //and NONE
                    return "";
            }
            
        }
        /**
         * change the state of the item the the next one. <br>
         * sequence is NONE -> TO -> CC -> BCC -> NONE ...
         */
        public void toNextState() {
            
            //Log.debug(this, "To nextState! ");
            
            switch (state) {
                case NONE:
                    state=Address.TO;
                    enableDisableOKCommand();
                    break;
                case Address.TO:
                    state=Address.CC;
                    break;
                case Address.CC:
                    state=Address.BCC;
                    break;
                case Address.BCC:
                    state=NONE;
                    enableDisableOKCommand();
                    break;
                default:state=NONE;
            }
            repaint();
        }
        
        
        /**
         * cycle to the next email changing the value of selectedImailIndex
         */
        private void toNextEmail() {
            //we know we have at least 2 emails, and we have defaultemail
            switch (selectedEmailIndex) {
                
                case Contact.DEFAULT_EMAIL:
                    if (! StringUtil.isNullOrEmpty( contact.getEmail_2()) ) {
                        selectedEmailIndex = Contact.SECONDARY_EMAIL;
                    } else {
                        selectedEmailIndex = Contact.TERTIARY_EMAIL;
                    }
                    break;
                    
                case Contact.SECONDARY_EMAIL:
                    if (! StringUtil.isNullOrEmpty( contact.getEmail_3()) ) {
                        selectedEmailIndex = Contact.TERTIARY_EMAIL;
                    } else {
                        selectedEmailIndex = Contact.DEFAULT_EMAIL;
                    }
                    break;
                    
                default: //tertiary or unknown cases
                    selectedEmailIndex = Contact.DEFAULT_EMAIL;
                    break;
            }
        }
        
        
        /**
         * cycle to the previous email changing the value of selectedImailIndex
         */
        private void toPreviousEmail() {
            
            switch (selectedEmailIndex) {
                
                case Contact.DEFAULT_EMAIL:
                    if (! StringUtil.isNullOrEmpty( contact.getEmail_3()) ) {
                        selectedEmailIndex = Contact.TERTIARY_EMAIL;
                    } else {
                        selectedEmailIndex = Contact.SECONDARY_EMAIL;
                    }
                    break;
                    
                case Contact.TERTIARY_EMAIL:
                    if (! StringUtil.isNullOrEmpty( contact.getEmail_2()) ) {
                        selectedEmailIndex = Contact.SECONDARY_EMAIL;
                    } else {
                        selectedEmailIndex = Contact.DEFAULT_EMAIL;
                    }
                    break;
                    
                default: //secondary and unknown
                    selectedEmailIndex = Contact.DEFAULT_EMAIL;
                    break;
            }
        }
        
        /**
         * draws the visiblename
         */
        private void drawName(Graphics graphics, int w, int h, boolean b) {
            if (isActive()) {
                graphics.setColor(graphicalTheme.getHighlightedForegroundColor());
            } else {
                graphics.setColor(graphicalTheme.getForegroundColor());
            }
            graphics.setFont(font);
            //TODO: use something to avoid cutstring calls every time this function
            //is called
            drawer.drawString(UiUtils.cutString(getName(),graphics.getClipWidth(),font),graphics,0,0,isActive());
            if ( hasMultipleEmails() ) {
                drawer.drawString(UiUtils.cutString(getSelectedEmail(),graphics.getClipWidth(),font),graphics,H_MARGIN, font.getHeight(),isActive());
            }
        }
        
        /**
         * @return the selected email as a string
         */
        private String getSelectedEmail() {
            switch (selectedEmailIndex) {
                case Contact.DEFAULT_EMAIL:
                    return contact.getDefaultEmail();
                case Contact.SECONDARY_EMAIL:
                    return contact.getEmail_2();
                case Contact.TERTIARY_EMAIL:
                    return contact.getEmail_3();
                default:
                    return contact.getDefaultEmail();
                    
            }
        }
        
        
        private String getName() {
            return contact.getVisibleName();
        }
        
        
        private int getMaxLabelWidth() {
            
            if (maxLabelWidth==0) {
                int w1=labelFont.stringWidth(Localization.getMessages().TO_LABEL.trim());
                int w2=labelFont.stringWidth(Localization.getMessages().CC_LABEL.trim());
                int w3=labelFont.stringWidth(Localization.getMessages().BCC_LABEL.trim());
                maxLabelWidth= Math.max( w1, Math.max(w2,w3));
            }
            
            return maxLabelWidth;
            
        }
        
        private void drawSwitchEmailIcon(final Graphics graphics) {
            
            if ( hasMultipleEmails() ) {
                //graphics.setColor(0xff3333);
                graphics.fillTriangle(
                        graphics.getClipWidth() / 2 + 2 , 0    ,
                        graphics.getClipWidth(), graphics.getClipHeight() / 2,
                        graphics.getClipWidth() / 2 + 2 , graphics.getClipHeight()
                        );
                
                graphics.fillTriangle(
                        graphics.getClipWidth() / 2 - 2 , 0    ,
                        0, graphics.getClipHeight() / 2,
                        graphics.getClipWidth() / 2 - 2  , graphics.getClipHeight()
                        );
            }
        }
        
        
        private int calculateHeight() {
            if (height==0) {
                height= V_MARGIN;
                height+=Math.max(font.getHeight(), labelFont.getHeight());
                height+=V_MARGIN;
                if ( hasMultipleEmails() ) {
                    height += font.getHeight();
                }
            }
            return height;
        }
        
        private boolean hasMultipleEmails() {
            if ( StringUtil.isNullOrEmpty( contact.getEmail_2() ) &&
                    StringUtil.isNullOrEmpty( contact.getEmail_3() ) )  {
                return false;
            } else {
                return true;
            }
        }
        
        /**
         * @return the address or null if no selection has been done
         */
        public Address getAddress() {
            
            if (state==NONE)
                return null;
            else {
                //     Log.debug(this, "returning address for " + contact.getVisibleName() + " with state " + getAddressTypeLabel());
                try {
                    return contact.getAddress(state, selectedEmailIndex);
                } catch (MailException ex) {
                    //TODO: better exception handling and localization
                    //UIController.showErrorAlert("Error getting Address [this string need localization]");
                    Log.error(this, "Error getting Address from contact item");
                    ex.printStackTrace();
                    return null;
                }
            }
        }
        
        private boolean isActive(){
            //   Log.debug("active = " + activeElement + " id = " + id);
            return this.id == getActiveElement();
        }
        
        public int getElementID(){
            return id;
        }
        
        
    }
    
    
    //---------------------- ResetContactsPopupAction Class -------------------//
    
    /**
     * popupaction to reset contacts
     */
    public class ResetContactsPopupAction implements PopupAction {
        public ResetContactsPopupAction() {
        }
        
        public void cancel() {
            UIController.showBackScreen();
        }
        
        public void confirm() {
            // disableSyncCommand(true);
            // UIController.enableSyncCommands(false);
            UIController.showInboxScreen();
            UIController.resetContacts();
            // UIController.enableSyncCommands(true);
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -