`
wuhua
  • 浏览: 2110320 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

全面进行真机JSR以及按键测试

    博客分类:
  • J2ME
阅读更多
http://www.3geye.net/?uid-3-action-viewspace-itemid-265

前阵子看到,有J2me的朋友对真机测试做了一个比较详细的代码,我重新整理了下,补全了一些参数。不敢独享,现在与大家分享下,体验下开发的快乐

package com.ucfly.jsrdemo;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.Manager;
import javax.microedition.midlet.MIDlet;

/**
 *
 * <P>标题:JSRDemoForm类,程序的显示窗口  </P>
 * <P>描述:手机JSR支持测试.这个类处理的逻辑太多了,不适合</P>
 * <p>在适当的适合,应该采用mvc的结构,Form只管自己绘制UI,逻辑应该放到另外一个类去实现</P>
 * <P>作者:fox</P>

 *
 */

public class JSRDemoForm extends Canvas {


    private static final int MENU = 0;
    private static final int MAIN = 1;
    private static final int KEY = 2;
    private static final int ABOUT = 3;
    private int state;

    private int key;

    private String cldc;
    private String midp;
    private boolean too = true;
    private int width;
    private int height;

    private JSRDemoMIDlet midlet;
    private int sumHeight;

    private static String[] menu_text = {
                                        "主要信息与JSR支持",
                                        "手机键值测试",
                                        "退出程序"
    };
    private int point = 0;

    private int count = 0;

    private int x = 0; //绘画坐标
    private int y = 0;


    private long total = 0;
    private long free = Runtime.getRuntime().freeMemory();

    private Font big = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                                    Font.SIZE_LARGE);

    private Font normal = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                                       Font.SIZE_MEDIUM);

    private Font small = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                                      Font.SIZE_SMALL);

    private String platform;

    private String encoding;
    private String locale;
    private String m3g;


    private String sms;
    private String mms;

    private String mmapi;

    private String pim;

    private String bluetooth;

    private String fileConnection;
    private String sip;
    private String location;
    private String jtwi;
    private String jsr177;


    /**
     * 构造函数
     *
     */
    public JSRDemoForm(JSRDemoMIDlet midlet) {
        this.midlet = midlet;
        this.init();
        this.getSystemInfo();
    }

    //重构初始化
    private void init() {
        cldc = System.getProperty("microedition.configuration");
        //userAgent = System.getProperty("microedition.platform");
        midp = System.getProperty("microedition.profiles");
        setFullScreenMode(true);
        too = true;
        state = MENU;
        this.width = this.getWidth();
        this.height = this.getHeight();
    }

    protected void paint(Graphics g) {
        clean(g, width, height);
        switch (state) {
        case MENU:
            paintMenu(g);
            break;
        case KEY:
            piantKeyInfo(g);
            break;
        case MAIN:
            paintSystemInfo(g);
            break;

        }

    }

    //绘制菜单
    private void paintMenu(Graphics g) {
        if (!too) {
            g.setColor(0x00FF00);
            g.drawString("MIDP1.0的手机,", 0, 0, Graphics.LEFT | Graphics.TOP);
            g.drawString("不支持后面的测", 0, 20, Graphics.LEFT | Graphics.TOP);
            g.drawString("试,按任意键退出", 0, 40, Graphics.LEFT | Graphics.TOP);
        } else {
            width = getWidth();
            height = getHeight();
            g.setColor(0xFFFFFF);
            if (count % 2 == 0) {
                g.fillTriangle(width / 2, height / 2 - 30, width / 2 - 5,
                               height / 2 - 20, width / 2 + 5, height / 2 - 20);
                g.fillTriangle(width / 2, height / 2 + 30, width / 2 - 5,
                               height / 2 + 20, width / 2 + 5, height / 2 + 20);
            } else {
                g.fillTriangle(width / 2, height / 2 - 30, width / 2 - 3,
                               height / 2 - 20, width / 2 + 3, height / 2 - 20);
                g.fillTriangle(width / 2, height / 2 + 30, width / 2 - 3,
                               height / 2 + 20, width / 2 + 3, height / 2 + 20);
            }
            g.setColor(0x00FF00);
            g.drawString(menu_text[point], width / 2, height / 2 - 7,
                         Graphics.HCENTER | Graphics.TOP);
            g.drawString("按2,5,8键", width / 2, height,
                         Graphics.HCENTER | Graphics.BOTTOM);
        }
    }

    //绘制key信息
    private void piantKeyInfo(Graphics g) {
        g.setColor(0xFFFFFF);
        g.drawString("键值是:", width / 2, height / 2 - 20,
                     Graphics.HCENTER | Graphics.TOP);
        g.setColor(0x00FF00);
        g.drawString("" + key, width / 2, height / 2,
                     Graphics.HCENTER | Graphics.TOP);
        g.drawString("按5键退出", width / 2, height,
                     Graphics.HCENTER | Graphics.BOTTOM);
    }


    /**获取系统值,因为系统性能问题,所以一开始就载入
     *
     */

    private void getSystemInfo() {
        total = Runtime.getRuntime().totalMemory();
        free = Runtime.getRuntime().freeMemory();

        big = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                           Font.SIZE_LARGE);

        normal = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                              Font.SIZE_MEDIUM);

        small = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
                             Font.SIZE_SMALL);

        platform = System.getProperty("microedition.platform");

        encoding = System.getProperty("microedition.encoding");
        locale = System.getProperty("microedition.locale");
        m3g = System.getProperty("microedition.m3g.version");
        m3g = m3g == null ? "false" : m3g;

        sms = System.getProperty("wireless.messaging.sms.smsc");
        sms = sms == null ? "false" : sms;
        mms = System.getProperty("wireless.messaging.mms.mmsc");
        mms = mms == null ? "false" : mms;

        mmapi = System.getProperty("microedition.media.version");
        mmapi = mmapi == null ? "false" : mmapi;

        pim = System.getProperty("microedition.pim.version");
        pim = pim == null ? "false" : pim;

        bluetooth = System.getProperty("bluetooth.api.version");
        bluetooth = bluetooth == null ? "false" : bluetooth;

        fileConnection = System.getProperty(
                "microedition.io.file.FileConnection.version");
        fileConnection = fileConnection == null ? "false" : fileConnection;
        sip = System.getProperty("microedition.sip.version");
        sip = sip == null ? "false" : sip;
        location = System.getProperty("microedition.location.version");
        location = location == null ? "false" : location;
        jtwi = System.getProperty("microedition.jtwi.version");
        jtwi = jtwi == null ? "false" : jtwi;
        jsr177 = System.getProperty("microedition.smartcardslots");
        jsr177 = jsr177 == null ? "false" : jsr177;

    }

    //绘制并获取JSR支持以及其他相关信息
    private void paintSystemInfo(Graphics g) {
        g.setClip(0, 0, width, height - 20);
        //内存
        g.setColor(0x00FF00);
        g.drawString(">>>", x, y, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);

        g.drawString("总共内存:" + total, x, y + 20, Graphics.LEFT | Graphics.TOP);

        g.drawString("可用内存:" + free, x, y + 40, Graphics.LEFT | Graphics.TOP);
        //屏幕
        g.setColor(0x00FF00);
        g.drawString(">>>", x, y + 60, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);
        g.drawString("屏幕宽:" + width, x, y + 80, Graphics.LEFT | Graphics.TOP);
        g.drawString("屏幕高:" + height, x, y + 100, Graphics.LEFT | Graphics.TOP);
        //字体:
        g.setColor(0x00FF00);
        g.drawString(">>>", x, y + 120, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);

        int fontw = big.stringWidth("国");
        int fonth = big.getHeight();
        g.drawString("大字体(宽&高):" + fontw + "&" + fonth, x, y + 140,
                     Graphics.LEFT | Graphics.TOP);

        fontw = normal.stringWidth("国");
        fonth = normal.getHeight();
        g.drawString("中字体(宽&高):" + fontw + "&" + fonth, x, y + 160,
                     Graphics.LEFT | Graphics.TOP);

        fontw = small.stringWidth("国");
        fonth = small.getHeight();
        g.drawString("小字体(宽&高):" + fontw + "&" + fonth, x, y + 180,
                     Graphics.LEFT | Graphics.TOP);
        //系统属性
        g.setColor(0x00FF00);
        g.drawString(">>>", x, y + 200, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);
        g.drawString("CLDC:" + cldc, x, y + 220, Graphics.LEFT | Graphics.TOP);
        g.drawString("MIDP:" + midp, x, y + 240, Graphics.LEFT | Graphics.TOP);

        g.drawString("平台:" + platform, x, y + 260, Graphics.LEFT | Graphics.TOP);

        g.drawString("编码:" + encoding, x, y + 280, Graphics.LEFT | Graphics.TOP);

        g.drawString("地区:" + locale, x, y + 300, Graphics.LEFT | Graphics.TOP);

        g.drawString("3D:" + m3g, x, y + 320, Graphics.LEFT | Graphics.TOP);

        g.drawString("WMA SMS:" + sms, x, y + 340,
                     Graphics.LEFT | Graphics.TOP);

        g.drawString("WMA MMS:" + mms, x, y + 360, Graphics.LEFT | Graphics.TOP);

        g.drawString("MMAPI:" + mmapi, x, y + 380, Graphics.LEFT | Graphics.TOP);

        g.drawString("PIM:" + pim, x, y + 400, Graphics.LEFT | Graphics.TOP);

        g.drawString("BlueTooth:" + bluetooth, x, y + 420,
                     Graphics.LEFT | Graphics.TOP);

        g.drawString("FileConnection:" + fileConnection, x, y + 440,
                     Graphics.LEFT | Graphics.TOP);

        g.drawString("SIP:" + sip, x, y + 460, Graphics.LEFT | Graphics.TOP);

        g.drawString("LOCATION:" + location, x, y + 480,
                     Graphics.LEFT | Graphics.TOP);

        g.drawString("JTWI:" + jtwi, x, y + 500, Graphics.LEFT | Graphics.TOP);

        String ch = System.getProperty("CHAPI-Version");
        ch = ch == null ? "false" : ch;
        g.drawString("CHAPI-JSR-211:" + ch, x, y + 520,
                     Graphics.LEFT | Graphics.TOP);

        g.drawString("JSR-177:" + jsr177, x, y + 540,
                     Graphics.LEFT | Graphics.TOP);

        //媒体格式
        g.setColor(0x00FF00);
        g.drawString(">>>", x, y + 560, Graphics.LEFT | Graphics.TOP);
        g.setColor(0xFFFFFF);
        String[] mime = Manager.getSupportedContentTypes(null);
        g.drawString("支持的媒体格式:", x, y + 580, Graphics.LEFT | Graphics.TOP);
        this.sumHeight = 600;
        for (int i = 0; i < mime.length; i++) {
            this.sumHeight = this.sumHeight + 20;
            g.drawString(mime[i], x, y + 600 + i * 20,
                         Graphics.LEFT | Graphics.TOP);
        }

        g.setClip(0, 0, width, height);
        g.setColor(0x00FF00);
        g.drawString("按2,4,5,6,8键", width / 2, height,
                     Graphics.HCENTER | Graphics.BOTTOM);
    }

    private void clean(Graphics g, int width, int height) {
        g.setColor(0x000000);
        g.fillRect(0, 0, width, height);
    }


    public void keyPressed(int keyCode) {
        switch (state) {
        case MENU:
            if (!too) {
                midlet.Exit();
            } else {
                actionMenu(keyCode);
            }
            break;
        case KEY:
            key = keyCode;
            if (key == KEY_NUM5) {
                state = MENU;
            }
            break;
        case MAIN:
            actionMain(keyCode);
            break;
        case ABOUT:
            if (keyCode == KEY_NUM5) {
                state = MENU;
            }
            break;
        }
        repaint();
    }

    private void actionMenu(int keyCode) {
        switch (keyCode) {
        case KEY_NUM8:
            if (point > 0) {
                point--;
            } else {
                point = menu_text.length - 1;
            }
            break;
        case KEY_NUM2:
            if (point < menu_text.length - 1) {
                point++;
            } else {
                point = 0;
            }
            break;
        case KEY_NUM5:
            if (point == menu_text.length - 1) {
                midlet.Exit();
            } else {
                state = point + 1;
            }
            break;
        }
    }

    private void actionMain(int keyCode) {
        switch (keyCode) {
        case KEY_NUM2:

            if(y<=-20)
                y += 20;
            break;
        case KEY_NUM8:


           if(-y<=(this.sumHeight - this.height+20))
               y -= 20;
            break;
        case KEY_NUM4:
            x -= 20;
            break;
        case KEY_NUM6:
            x += 20;
            break;
        case KEY_NUM5:
            state = MENU;
            break;
        }
    }

    protected void sizeChanged(int w, int h) {
        if (h > this.height) {
            this.height = h;
        }
    }


}

分享到:
评论

相关推荐

    j2me 手机jsr支持测试

    3. **结果反馈**: 测试完成后,程序将展示一个报告,详细列出每个JSR的测试结果,包括是否支持、支持的程度以及可能遇到的错误信息。 4. **报告导出**: 用户可以选择将测试结果保存为文件,以便日后参考或与他人...

    jsr168和jsr268中文文档及开发手册

    JSR268,也称为“portlet API 2.0”,是在JSR168的基础上进行了扩展和增强,于2006年发布。JSR268引入了许多新特性,以提高portlet的灵活性和用户体验: 1. 完善的本地化支持:使得portlet可以更好地适应多语言环境...

    portlet 规范和API(jsr 168/286)

    JSR 286是在JSR 168的基础上进行扩展和增强的版本,于2006年发布。它引入了更多高级功能,以提高portlet的交互性和性能: 1. Ajax支持:通过异步更新,JSR 286使得portlet可以实现更流畅的用户体验,无需刷新整个...

    JSR268门户标准

    这一规范是在JSR168的基础上进行了大量改进和扩展的结果,旨在提供更加丰富的功能集,支持更高级别的用例,并确保更好的互操作性。 #### 二、JSR286新特性详解 ##### 1. 资源服务(Resource Services) 资源服务是...

    jsr133_content.pdf

    该规范与Java平台Tiger(5.0)版本的JSR-176项目紧密相关,并且其规范内容会被整合进《Java语言规范》(JLS)、《Java虚拟机规范》(JVMS)以及`java.lang`包中的类规范。 JSR-133不再通过Java社区进程(JCP)进行...

    23 Spring Core参数校验之JSR303_JSR-349注解-慕课专栏1

    以下是一个简单的例子,展示如何使用JSR 303/349/380注解进行参数校验: ```java public class User { @NotNull(message = "名称不能为空") private String name; @Min(value = 18, message = "年龄不能小于18岁...

    JSR133中文版.pdf

    本文是JSR-133规范,即JavaTM内存模型与线程规范,由JSR-133专家组开发。本规范是JSR-176(定义了JavaTM平台 Tiger(5.0)发布版的主要特性)的一部分。本规范的标准内容将合并到JavaTM语言规范、JavaTM虚拟机规范...

    JSR303Test.zip

    通过这样的示例项目,开发者可以学习如何在实际项目中有效地应用JSR 303进行参数验证,包括基本的注解使用、分组验证以及自定义验证的实现。这对于提高代码质量和安全性至关重要,因为有效的数据验证可以防止无效的...

    JSR133中文版

    JSR133正是为了解决这些问题而提出的,它对JMM进行了重大改进,使得Java的并发性能和正确性得到了显著提升。 JSR133引入了一些关键概念,如**volatile变量**、**happens-before关系**和**内存屏障**。**volatile...

    jsr311-api-1.1.1-API文档-中文版.zip

    赠送jar包:jsr311-api-1.1.1.jar; 赠送原API文档:jsr311-api-1.1.1-javadoc.jar; 赠送源代码:jsr311-api-1.1.1-sources.jar; 赠送Maven依赖信息文件:jsr311-api-1.1.1.pom; 包含翻译后的API文档:jsr311-api...

    jsr173_api

    **JSR 173 API**,全称为Java Specification Request 173,是Java社区进程(Java Community Process)发布的一个标准,旨在为Java平台引入标准化的可扩展性框架,以便处理XML流数据。该API的主要目标是为Java开发者...

    JSR303依赖的jar包

    JSR 303 用于对 Java Bean 中的字段的值进行验证。 Spring MVC 3.x 之中也大力支持 JSR-303,可以在控制器中对表单提交的数据方便地验证。 该压缩包包含了hibernate-validator-5.2.4.Final.jar、hibernate-...

    JSR256 API

    这个API专注于在Java 2 Micro Edition (J2ME) 平台上提供传感器接口,使得移动设备和嵌入式系统能够有效地与各种传感器进行交互。JSR256的主要目标是创建一个标准化的框架,允许开发者轻松地访问和处理来自不同类型...

    JSR303jar包

    JSR303主要应用于Web应用、企业级服务以及任何形式的数据处理中。 JSR303 jar包是一个包含了JSR303规范实现的软件包,用于在Java项目中实现数据验证功能。这个jar包中的实现通常会包括各种预定义的校验注解,如`@...

    WMA+2.0(JSR+205

    JSR 205专门针对无线多媒体应用,提供了在Java平台上进行多媒体处理的标准化接口和实现。这个规范的发布对于开发者来说,意味着他们可以利用统一的标准开发跨平台的多媒体应用,提高开发效率并确保兼容性。 **2. ...

    JSR 223

    - **单元测试**:使用脚本语言编写单元测试,利用其动态特性快速构建测试案例。 - **数据处理**:利用脚本语言的强大数据处理能力,进行数据清洗、转换和分析。 - **GUI脚本化**:使用脚本语言控制和自定义Java ...

    jsr 303需要的jar包

    JSR 303,全称为Java Specification Request 303,是Java平台的一个标准,主要关注于数据验证。这个标准定义了一套API,用于在Java应用程序中进行bean对象的数据验证,大大简化了验证逻辑的编写。JSR 303的实现之一...

    JSR133规范中文版

    JSR133规范

    JSR-107 标准手册 Specification

    根据许可协议,允许对规范进行评估,包括为内部非商业使用开发实现,与任何第三方讨论规范,以及在讨论规范的口头或书面交流中摘录规范的简短部分。然而,这些摘录的总和不得构成技术的显著部分。此外,许可证规定了...

Global site tag (gtag.js) - Google Analytics