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

📄 logviewerform.java

📁 The Funambol J2ME Mail Client aims to be a light, easy to use, free email client for J2ME devices.
💻 JAVA
字号:
/*
 * Copyright (C) 2006-2007 Funambol
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.funambol.mailclient.ui.view;

import com.funambol.mail.Address;
import com.funambol.mail.MailException;
import com.funambol.mail.Message;
import com.funambol.mailclient.config.ConfigManager;
import com.funambol.mailclient.sm.SyncClientConfig;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.mailclient.loc.Localization;
import com.funambol.util.Log;
import com.funambol.util.LogViewer;
import com.funambol.util.MailDateFormatter;
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import java.util.Enumeration;

/**
 * This form shows the log content collected by using the
 * application
 */
public class LogViewerForm extends Form implements CommandListener {
    
    private Command backCommand;
    private Command sendCommand;
    String[] logEntries;
    String messageContent;
    StringBuffer sb;
    Message message;

    private String deviceId;

    private String SUPPORT_ADDRESS = "fjm_logs@funambol.com";
    
    /** Creates a new instance of LogViewerForm */
    public LogViewerForm() {
        super(Localization.getMessages().LOG_VIEWER_FORM_TITLE);
        sb = new StringBuffer();
        //append the log content
        LogViewer lv = new LogViewer();
        logEntries = lv.getLogEntries(lv.RMSLOG);
        getDeviceID();
        sb.append("DeviceId: " + deviceId);
        messageContent = createContent();
        append(messageContent);
        /*
        for (int i=0; i<logEntries.length; i++) {
            append(logEntries[i] + "\n");
        }*/
        backCommand = UIController.backCommand;
        sendCommand = new Command("Send Log", Command.OK, 0);
        addCommand(backCommand);
        addCommand(sendCommand);
        setCommandListener(this);
    }
    
    public void commandAction(Command command, Displayable displayable) {
        if (command == backCommand) {
            UIController.showBackScreen();
        } else if (command == sendCommand) {
            
            message = new Message();
            message.setFrom(UIController.getMyFrom());
            message.setSubject(createSubject());
            
            try {
                message.setContent(messageContent);
                
                message.setTo(new Address[]
                {new Address(Address.TO, SUPPORT_ADDRESS)}
                );
            } catch (MailException ex) {
                ex.printStackTrace();
                Log.error(this, "Mail exception creating address for support email");
            }
            FunModalPopup popup =
                    new FunModalPopup(Localization.getMessages().SEND_LOG_POPUP_TITLE,
                    Localization.getMessages().SEND_LOG,
                    new SendLogPopupAction());
            UIController.showModalPopup(popup, this);
        }
    }
    
    private String createContent() {
        long totalMemory = Runtime.getRuntime().totalMemory();
        long freeMemory = Runtime.getRuntime().freeMemory();
        sb.append("\nMemory stats");
        sb.append("\nTotal Memory: ").append(totalMemory);
        sb.append("\nStartup FreeMem: ").append(UIController.startupFreeMem);
        sb.append("\nFree Memory: ").append(freeMemory);
        
        //appendProbes();
        sb.append("\nClient Configuration\n");
        sb.append(UIController.getConfig().toString());
        sb.append("\n");
        
        
        sb.append("\n\nLog\n");
        for (int i=0; i<logEntries.length; i++) {
            sb.append(logEntries[i] + "\n");
        }
        String content = sb.toString();        
        return content;
    }
    
    private String createSubject() {
        
        
        String subject = "" + deviceId + " - FJM_Log [" +
                MailDateFormatter.dateToRfc2822(
                new Date()) +
                "]";
        return subject;
    }

    private void getDeviceID() {
        
        SyncClientConfig conf = new SyncClientConfig();
        try {
            ConfigManager.load("syncml.config", conf);
        } catch (Exception ce) {
            ce.printStackTrace();
            Log.error(this, "error loading config");
        }
        
        deviceId = conf.getDeviceId();
    }
    
    private void appendProbes() {
        sb.append("\nProbes\n--------------------");
        Enumeration probesEnum = Log.probes.elements();
        String probe = "";
        
        long start = 0L;
        long startMilliSecs = 0L;
        String sep = " = ";
        String probeStart = "_probe_start_";
        String probeEnd = "_probe_end_";
        while (probesEnum.hasMoreElements()) {
            probe = (String)probesEnum.nextElement();
            //sb.append(probe);
            int sepIndex = probe.indexOf(sep);
            int startMethodIndex = probe.indexOf(probeStart);
            if (startMethodIndex!=-1) {
                String methodStart = probe.substring(startMethodIndex +
                        probeStart.length(), sepIndex);
                String startTime = probe.substring(sepIndex + sep.length(), probe.length());
                startMilliSecs = Long.parseLong(startTime);
            } else {
                int endMethodIndex = probe.indexOf(probeEnd);
                String methodEnd = probe.substring(endMethodIndex +
                        probeEnd.length(), sepIndex);
                String endTime = probe.substring(sepIndex + sep.length(), probe.length());
                long endMillisecs = Long.parseLong(endTime);
                sb.append("\n"+methodEnd + sep + (endMillisecs-startMilliSecs));
            }
        }
        sb.append("\n--------------------\n");
    }
    
    private class SendLogPopupAction implements PopupAction {
        public void cancel() {
            UIController.showBackScreen();
        }

        public void confirm() {
            UIController.sendMessage(message);
            
        }
        
    }
}

⌨️ 快捷键说明

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