eclipse ios
2012-08-16 13:29:17 zheyiw 阅读数 19


终于忍不住,要表达一下蜀黍对eclipse 对andriod 对 java的热爱
我喜欢android开发,我享受android开发
用eclipse开发简直就是一种享受
1、eclipse是免费的,跨平台的,甚至有32位和64位的版本提供选择,获取eclipse也是非常的容易
2、eclipse还很小,200M级别的大小,下载很快,为千千万万的开发者节省了宝贵的时间
3、eclipse能让你方便,快速,简单的在各个文件之间导航,
4、eclipse能让你方便的定位每一个文件,类,方法甚至文本
5、eclipse能帮你快速的完成代码重构
6、eclipse会给你很多提示,帮你完成代码,如果它只是工具,那它必是高级智能工具
7、用eclipse编辑你的代码,你会发现它跟你的思绪一样快速精准
8、eclipse的格式化功能只能说完美,格式化出来的代码整洁,有序,看着真舒服
9、eclipse提供了丰富的插件,使用也相当方便
10、用svn管理你的代码吧,每天提交代码后我会觉得今天的工作完美了
11、eclipse会实时侦错,会自动修复,还能提供更好的解决办法,提示不友好的代码片段
12、eclipse会智能导入需要的包,删除无用的包,代码优美,编译高效


android,我了解我的每一行代码
用android开发最好不要用可视化开发,用xml布局很方便,很精准


xcode我很失望,但我没得选择
ios开发:触摸到你之前,我得有钱买苹果机,我得有时间,好网速下载好几个G的工具,我还要看大量教程才知道去哪里下载,怎么下载
xcode一更新,我又要用大量的带宽,大量的时间,大量的精力跟着你升级
甚至我要更新我的系统
我很无语,
objective-c 每一个变量,方法你至少要输入两遍,因为定义跟实现是分开的
几乎每个类都要写两个文件一个头文件,一个实现文件,冗余,麻烦,TMD
xcode还不能自动添加需要实现的方法,无语,

2015-09-02 23:38:55 fei_xiang_feng 阅读数 2906

小编趁着抗战70周年之际,写了一片关于ios 系统下的安卓开发环境搭建,长话短说,直接奔主题。主要步骤:

-开发工具的准备


1 下载 JDK ,下载链接:http://www.oracle.com/technetwork/java/javase/archive-139210.html
2 下载eclipse ,下载链接:http://www.eclipse.org/downloads/packages/release/luna/sr2;
3 下载ADT zip包,下载链接:https://developer.android.com/sdk/installing/installing-adt.html
4 下载NDK bin文件 ,下载链接:https://developer.android.com/ndk/downloads/index.html
5 下载robovm plugin,下载链接:http://download.robovm.org/eclipse/
6 下载 virtualbox,下载链接:https://www.virtualbox.org/wiki/Downloads
7 下载Genymotion ,下载链接:https://www.genymotion.com


-开发工具的安装


1 jdk 安装,一般在ios本本或一体机,直接将下载jdk.dmg文件直接解压出来,系统会弹出一个drag框,直接将应用包drag到Application中,
(系统会提示是否打开jdk,选中“好“按钮,如果打不开,可能需要在到launchpad 中找到系统偏好,打开它,找到“安全与隐私“,点击它,
然后在launchpad中找到“其他“打开它,找到“终端“,双击运行,在命令行中输入:java -version 出现如图1-1信息,说明安装成功。如效果图1-1
图1-1
2 eclipse 安装,一般直接解压到指定目录即可,打开解压文件,找到eclipse.app 文件,运行即可。
3 adt 安装,adt 安装有两种方式(1)在线安装(2)离线安装。在这里我们就讲讲离线安装,打开eclipse ,找到help菜单,选中它,找到“install new software“,点击它,弹出install 窗口,找到work with 右边的add 点击它,弹出Add Repository 窗口,选择Archive按钮,添加你下载的adt.zip包,点击OK。然后就出现安装插件,选中它,点击next, 这时候可能需要下载一些资源,时间有点长(可能需要翻墙),下载完后安装,重启 eclipse 即可。
4 ndk 安装,安装前需要将下载的 bin文件,变成可以使用的文件,google 官网有两种方法解决(1) 使用7zip 压缩(2)使用命令操作。本例采用第二种。如图1-2
图1-2
在mac 切换到该文件所在目录,一般切换目录“cd +空格+ 路径“,运行 ndkchmoda+xandroidndkr10cdarwinx8664.binndk ./android-ndk-r10c-darwin-x86_64.bin (注:斜体为文件名)即可在同目录下自动生成相应文件夹如图1-3
图1-3
然后在eclipse 中找到偏好设置,打开设置ndk 路径如图1-4
图1-4
点击OK 即可。
5 robovm 安装,目前robovm只能在线安装,与adt 在线安装一样,这里就不多讲了。
6 virtualbox 安装,该软件傻瓜式安装,直接next 即可。
7 Genymotion 安装,安装该软件时,必须先安装virtualbox,安装成功后,才能正常运行。


-开发工具的测试


1 new android project ,and then run it android well.
2 import ndk demo ,and then run it android well.
3 open the genymotion ,and then run it with android app well.
4 new robovm project ,and then run it on ios or android well.


2014-11-18 12:36:34 fallenink 阅读数 822
Eclipse背景颜色修改: 

操作界面默认颜色为白色。对于我们长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以我经常会改变workspace的背景色,使眼睛舒服一些。设置方法如下: 
1、打开window->Preference,弹出Preference面板 
2、展开General标签,选中Editors选项,展开。 
3、选中 Test Editors,右边出现Test Editors面板。 面板中有这样一个选项:Appearance color options; 其中是各种板块颜色的设置,其中有一项是background color,根据自己的喜好选择颜色。 
4、 选中background color,勾掉System Default,点击'color',弹出颜色选择面板,选择喜好的颜色,单击确定。 
5、返回Test Editors,单击Apply即可。展开Test Editors,还有其他选项,比如对错误提示的颜色样式,如果你对此感兴趣也可尝试更改一下。 

背景颜色向你推荐:色调:85。饱和度:1 2 3。亮度:2 0 5 

文档都不再是刺眼的白底黑字,而是非常柔和的豆沙绿色,这个色调是眼科专家配置的,长时间使用会很有效的缓解眼睛疲劳保护眼睛。 

改变背景颜色
windows->Preferences->General->Editor->Text Editors
右边选择Appearance color options 
选Background color 选择背景颜色
选Current line highlight 来改变 当前选中行 的颜色

配色方案详细following: 



Eclipse字体大小调整: 
窗口(Window)-首选项(Preferences)-常规(General)-外观(Appearence)-颜色与字体(Colors And Fonts),在右边的对话框里选择Java - Java Editor Text Font,点击出现的修改(Change)按钮,可以设置显示在在主窗体中程序的字体大小,设置完之后点击右下角的应用(Apply),最后点击确定(OK)即可。 

xml的字体大小调整: 
window--preferences--General--appearance--colors and fonts--Basic-- "Text font "  

然后点change,可以设置字体的大小



eclipse 改变颜色,背景



一款看上去十分舒服的代码配色,会让Coding过程变得惬意,让编写效率提升不少。而Eclipse默认的代码配色实在丑陋,除了关键字为褐色加粗、字符串为蓝色外,其余颜色均为黑色。在这样的配色中,最难分辨的就是局部变量和类型的私有字段(其他好歹可以通过大小写规则来判断,如果代码编写够规范的话)。而且过于单调的颜色,不容易刺激视觉神经乃至中枢神经,会增加疲劳感,带来困意。

为了改变这一现状,我们必须对Eclipse的代码配色进行更改。


我的代码颜色



改变字体颜色
windows->Preferences->Java->Editor->Syntax Coloring
右边选择Java 然后可以自由选择颜色了

Annotations(注释): 107, 147, 186  浅蓝色
Deprecated members(不建议使用的成员): 0, 0, 0  
Fields(字段): 128, 0, 128  紫色
KeyWord 'return'(关键字'return'): 255, 0, 0   红色
Keyword excluding 'return'(除了关键字以外的return): 255, 128 ,0  橙色
Local variable declarations(局部变量声明): 128, 128, 128   灰色
Method declarations(方法声明): 255, 128, 64    橙色
Method(方法): 0, 48, 96 暗浅蓝色
Operators and brackets(运算符与方括号): 255, 128, 0  橙色
Others(其他): 96 153, 0   深绿色
Static fields(静态字段): 33, 0, 189  深蓝色
Static Method invocations(静态方法调用): 77, 166 255  天蓝色 
Strings(字符串): 132, 26, 238   中天蓝色
Type variables(类型变量): 128, 0, 25   红罗色

学习从现在开始


第二方案

改变背景颜色(黑底背景的设置)
windows->Preferences->General->Editor->Text Editors
右边选择Appearance color options 
选Background color 选择背景颜色
选Current line highlight 来改变 当前选中行 的颜色

配色方案详细following: 
Annotations(注释): 107, 147, 186 
Deprecated members(不建议使用的成员): 0, 0, 0 
Fields(字段):128,255,0 绿色
KeyWord 'return'(关键字'return'): 255, 0, 0  红色
Keyword excluding 'return'(除了关键字以外的return): 255,80, 0  深深橘色
Local variable declarations(局部变量声明): 70,140,179  深蓝色
Method declarations(方法声明): 247,197,39  淡橘色
Method(方法): 241,196,54  深淡橘色
Operators and brackets(运算符与方括号): 255, 128, 0   深橘色
Others(其他): 126, 202, 0  淡绿色
Static fields(静态字段): 128,255,0 绿色
Static Method invocations(静态方法调用): 77, 166 255  
Strings(字符串):  89,196,196  墨蓝色
Type variables(类型变量): 222, 0, 25  红色


2012-07-26 13:35:50 zishuiyi 阅读数 3619

最近看到一个不错的ios应用“周末-要出发”,觉得整个APP应用的UX挺好,所以对于热门推荐模块进行了模拟实现。

实现步骤:

1.在Eclipse中新建iPhone项目,获得firebug.js文件以及原始的index.html文件;

2.新建Web Project,将之前iPhone项目中js和html文件拷贝过来,这样得到的样式将适合ios系统展示

3.引用dwr.jar和mysql驱动

4.编写java类,以及配置xml(dwr.xml,web.xml)

备注:

a.在数据库中写的图片链接要写http://192.168.1.114:8080/Weekly/IMG/x1.jpg,之前一直写的相对位置,无法显示图片,后来想到是服务器的位置

b.在html页面中通过js调用java代码的话,采用DWR是比较合适的选择,方便,简洁


项目文件夹情况如下:


源代码如下:

mysql数据库,sql:

/*
MySQL Data Transfer
Source Host: localhost
Source Database: iosweb
Target Host: localhost
Target Database: iosweb
Date: 2012-7-26 14:11:25
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for img
-- ----------------------------
CREATE TABLE `img` (
  `id` smallint(6) NOT NULL,
  `addr` varchar(50) NOT NULL,
  `com_top` varchar(50) NOT NULL,
  `com_btm_left` varchar(50) NOT NULL,
  `com_btm_right` varchar(20) NOT NULL,
  `img_description` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `img` VALUES ('0', 'http://192.168.1.114:8080/Weekly/IMG/x1.jpg', '桂峰山高端自驾游2天1晚套餐,避暑仙源独享清幽', '广东 惠州 | 桂峰山度假山庄', '29988元', 'http://192.168.1.114:8080/Weekly/IMG/x1.jpg');
INSERT INTO `img` VALUES ('1', 'http://192.168.1.114:8080/Weekly/IMG/x2.jpg', 'sss', 'sss', 'sss', 'http://192.168.1.114:8080/Weekly/IMG/x2.jpg');
INSERT INTO `img` VALUES ('2', 'http://192.168.1.114:8080/Weekly/IMG/x3.jpg', 'sss', 'sss', 'sss', 'http://192.168.1.114:8080/Weekly/IMG/x3.jpg');
INSERT INTO `img` VALUES ('3', 'http://192.168.1.114:8080/Weekly/IMG/x4.jpg', 'sss', 'sss', 'sss', 'http://192.168.1.114:8080/Weekly/IMG/x4.jpg');
INSERT INTO `img` VALUES ('4', 'http://192.168.1.114:8080/Weekly/IMG/x5.jpg', 'sss', 'sss', 'sss', 'http://192.168.1.114:8080/Weekly/IMG/x5.jpg');

1.index.html
<!-- Based on work by Joe Hewitt : http://www.joehewitt.com/blog/iphone_tips_loo.php --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
	 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
        <title>要出发</title>
        <link rel="stylesheet" type="text/css" media="screen" href="CSS/styles.css"/>
        <script type="text/javascript" src="JS/firebug.js">
        </script>
        <script type='text/javascript' src='/Weekly/dwr/interface/DWRExample.js'>
        </script>
        <script type='text/javascript' src='/Weekly/dwr/engine.js'>
        </script>
        <script type='text/javascript' src='/Weekly/dwr/util.js'>
        </script>
        <script type="text/javascript" src="JS/main.js">
        </script>
		
    </head>
    <body>
        <div class="container">           
            <div class="center">
                <div class="refresh" id="r1">
                    下拉即可更新.../松开即可更新.../滚动条+  加载中...
                    <br/>
                    最后更新:
                </div>
                <div id="contents">
                    <script type="text/javascript">
                        show();
                    </script>
                </div>
                <button id='addMore' onclick="show();" value=" ok ">
                    加载更多
                </button>
            </div>
        </div>
    </body>
</html>

2. styles.css

body {
       margin: 0;
       font-family: Helvetica;
       background: #000000;
       color: #FFFFFF;
       overflow: hidden;
   } .container {
       position: absolute;
       width: 100%;
   }
   
   body[orient =
   "profile"] .container {
       height: 416px;
   }
   
   body[orient =
   "landscape"] .container {
       height: 268px;
   }  .center {
       position: absolute;
       top: 0px;
       bottom: 0px;
       background: #FFFFFF;
       width: 100%;
   }
   
   body[orient =
   "landscape"] .center {
       top: 0px;
       bottom: 0px;
       width: 100%;
   } .item {
       border-bottom: 1px solid #E0E0E0;
       background: #ffffff;
       color: #000000;
       padding: 2%;
       height: 210px;
   } #addMore {
       background-color: #ffffff;
       border-width: 0;
       height: 30px;
       width: 100%;
       font-size: 20px;
   } img {
       width: 100%;
       height: 150px;
   } .refresh {
       padding: 10px 0;
       width: 100%;
       height: 20px;
       font-size: 10px;
       font-weight: bold;
       text-align: center;
       text-shadow: #3F4E63 0px -1px 1px;
       background: #d3d5d8;
       display: none;
   } .comments_top {
       margin-top:10px;
       word-break:keep-all;/* 不换行 */  
       white-space:nowrap;/* 不换行 */  
       overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */  
       text-overflow:ellipsis;
   } .comments_bottom {
       margin-top: 10px;
   } .comments_bottom_left {
       float: left;
       margin-bottom:0px;
   } .comments_bottom_right {
       float: right;
       color: #F6680C;
       margin-bottom:0px;
   }

3.firebug.js
if (!("console" in window) || !("firebug" in console)) {
(function()
{
    window.console = 
    {
        firebug: "ibug0.1",
        
        log: function()
        {
            logFormatted(arguments, "");
        },
        
        debug: function()
        {
            logFormatted(arguments, "debug");
        },
        
        info: function()
        {
            logFormatted(arguments, "info");
        },
        
        warn: function()
        {
            logFormatted(arguments, "warning");
        },
        
        error: function()
        {
            logFormatted(arguments, "error");
        },
        
        assert: function(truth, message)
        {
            if (!truth)
            {
                var args = [];
                for (var i = 1; i < arguments.length; ++i)
                    args.push(arguments[i]);
                
                logFormatted(args.length ? args : ["Assertion Failure"], "error");
                throw message ? message : "Assertion Failure";
            }
        },
        
        dir: function(object)
        {
            var html = [];
                        
            var pairs = [];
            for (var name in object)
            {
                try
                {
                    pairs.push([name, object[name]]);
                }
                catch (exc)
                {
                }
            }
            
            pairs.sort(function(a, b) { return a[0] < b[0] ? -1 : 1; });
            
            html.push('<table>');
            for (var i = 0; i < pairs.length; ++i)
            {
                var name = pairs[i][0], value = pairs[i][1];
                
                html.push('<tr>', 
                '<td class="propertyNameCell"><span class="propertyName">',
                    escapeHTML(name), '</span></td>', '<td><span class="propertyValue">');
                appendObject(value, html);
                html.push('</span></td></tr>');
            }
            html.push('</table>');
            
            logRow(html, "dir");
        },
        
        dirxml: function(node)
        {
            var html = [];
            
            appendNode(node, html);
            logRow(html, "dirxml");
        },
        
        group: function()
        {
            logRow(arguments, "group", pushGroup);
        },
        
        groupEnd: function()
        {
            logRow(arguments, "", popGroup);
        },
        
        time: function(name)
        {
            timeMap[name] = (new Date()).getTime();
        },
        
        timeEnd: function(name)
        {
            if (name in timeMap)
            {
                var delta = (new Date()).getTime() - timeMap[name];
                logFormatted([name+ ":", delta+"ms"]);
                delete timeMap[name];
            }
        },
        
        count: function()
        {
            this.warn(["count() not supported."]);
        },
        
        trace: function()
        {
            this.warn(["trace() not supported."]);
        },
        
        profile: function()
        {
            this.warn(["profile() not supported."]);
        },
        
        profileEnd: function()
        {
        },
        
        // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       
        $: function(id)
        {
            return document.getElementById(id);
        },

        $$: function(selector)
        {
            // XXXjoe Make this into getElementsBySelector
            return document.getElementsByTagName(selector);
        },
        
        // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
        
        onError: function(msg, href, lineNo)
        {
            var html = [];
        
            var lastSlash = href.lastIndexOf("/");
            var fileName = lastSlash == -1 ? href : href.substr(lastSlash+1);

            html.push(
               msg,  ' (line ', lineNo, ')'
            );
        
            logRow(html, "error");
        },
        
        command: function(text)
        {
            with (console)
            {
                try {
                    var result = eval(text);
                    console.log('return value: '+  result);
                }
                catch (exc)
                {
                    console.onError(exc.message, exc.sourceId+"", exc.line);
                }
            }
        },

        handshake: function(callback)
        {
            sendMessage = callback;
            
            for (var i = 0; i < queue.length; ++i)
                sendMessage(queue[i]);
        }
    };
 
    // ********************************************************************************************
     
    var timeMap = {};
    var queue = [];
    
    function init()
    {
        //var iframe = document.createElement("iframe");
        //document.body.appendChild(iframe);
        //iframe.src = "http://" + ibugHost + "/iphone";
        
        setInterval(checkComand, 1000);
    }

	function checkComand()
	{
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", "/iphone-command");
	 	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4) {
	  	var text = xmlhttp.responseText;
	  	if(text != "" && typeof(text) != "undefined" && text != null)
	  	{
	   		console.command(text);
	   	}
	  }
	 }
	 xmlhttp.send(null)
	}
	
    function sendMessage(message)
    {
        // Until we get a handshake from the iframe, queue messages for delivery
        //queue.push(message);
		
		var request = new XMLHttpRequest();
        request.open("POST", "/iphone");
        request.send(message);
		
    }
        
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
               
    function appendText(object, html)
    {
        html.push(escapeHTML(objectToString(object)));
    }

    function appendNull(object, html)
    {
        html.push(objectToString(object));
    }

    function appendString(object, html)
    {
        html.push(objectToString(object));
    }

    function appendInteger(object, html)
    {
        html.push(objectToString(object));
    }

    function appendFloat(object, html)
    {
        html.push(objectToString(object));
    }

    function appendFunction(object, html)
    {
        var reName = /function ?(.*?)\(/;
        var m = reName.exec(objectToString(object));
        var name = m ? m[1] : "function";
        html.push(name, '()');
    }

    function appendArray(object, html)
    {
        html.push('[');
        for (var i = 0; i < object.length; ++i)
        {
            if (i > 0)
                html.push(',');
            appendObject(object[i], html);
        }
        html.push(']');
    }
    
    function appendObject(object, html)
    {
        try
        {
            if (object == undefined)
                appendNull("undefined", html);
            else if (object == null)
                appendNull("null", html);
            else if (typeof object == "string")
                appendString(object, html);
            else if (typeof object == "number")
                appendInteger(object, html);
            else if (object.nodeType == 1)
                appendSelector(object, html);
            else if (object == window || object == document)
                appendObjectFormatted(object, html);
            else if (typeof(object.length) == "number")
                appendArray(object, html);
            else if (typeof object == "object")
                appendObjectFormatted(object, html);
            else if (typeof object == "function")
                appendFunction(object, html);
            else
                appendText(object, html);
        }
        catch (exc)
        {
        }
    }
        
    function appendObjectFormatted(object, html)
    {
        var text = objectToString(object);
        var reObject = /\[object (.*?)\]/;

        var m = reObject.exec(text);
        html.push('<span class="objectBox-object">', m ? m[1] : text, '</span>')
    }
    
    function appendSelector(object, html)
    {
        html.push('<span class="objectBox-selector">');

        html.push('<span class="selectorTag">', escapeHTML(object.nodeName.toLowerCase()), '</span>');
        if (object.id)
            html.push('<span class="selectorId">#', escapeHTML(object.id), '</span>');
        if (object.className)
            html.push('<span class="selectorClass">.', escapeHTML(object.className), '</span>');

        html.push('</span>');
    }

    function appendNode(node, html)
    {
        if (node.nodeType == 1)
        {
            html.push(
                '<div class="objectBox-element">',
                    '<<span class="nodeTag">', node.nodeName.toLowerCase(), '</span>');

            for (var i = 0; i < node.attributes.length; ++i)
            {
                var attr = node.attributes[i];
                if (!attr.specified)
                    continue;
                
                html.push(' <span class="nodeName">', attr.nodeName.toLowerCase(),
                    '</span>="<span class="nodeValue">', escapeHTML(attr.nodeValue),
                    '</span>"')
            }

            if (node.firstChild)
            {
                html.push('></div><div class="nodeChildren">');

                for (var child = node.firstChild; child; child = child.nextSibling)
                    appendNode(child, html);
                    
                html.push('</div><div class="objectBox-element"></<span class="nodeTag">', 
                    node.nodeName.toLowerCase(), '></span></div>');
            }
            else
                html.push('/></div>');
        }
        else if (node.nodeType == 3)
        {
            html.push('<div class="nodeText">', escapeHTML(node.nodeValue),
                '</div>');
        }
    }
        
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    function logRow(message, className, handler)
    {
        sendMessage(className + ": " + message.join(""));
    }
        
    function logFormatted(objects, className)
    {
        var html = [];

        var format = objects[0];
        var objIndex = 0;

        if (typeof(format) != "string")
        {
            format = "";
            objIndex = -1;
        }

        var parts = parseFormat(format);
        for (var i = 0; i < parts.length; ++i)
        {
            var part = parts[i];
            if (part && typeof(part) == "object")
            {
                var object = objects[++objIndex];
                part.appender(object, html);
            }
            else
                appendText(part, html);
        }

        for (var i = objIndex+1; i < objects.length; ++i)
        {
            appendText(" ", html);
            
            var object = objects[i];
            if (typeof(object) == "string")
                appendText(object, html);
            else
                appendObject(object, html);
        }
        
        if (!className && html.length == 1 && typeof(objects[0]) == "string")
            className = "text";
            
        logRow(html, className);
    }

    function parseFormat(format)
    {
        var parts = [];

        var reg = /((^%|[^\\]%)(\d+)?(\.)([a-zA-Z]))|((^%|[^\\]%)([a-zA-Z]))/;
        var appenderMap = {s: appendText, d: appendInteger, i: appendInteger, f: appendFloat};

        for (var m = reg.exec(format); m; m = reg.exec(format))
        {
            var type = m[8] ? m[8] : m[5];
            var appender = type in appenderMap ? appenderMap[type] : appendObject;
            var precision = m[3] ? parseInt(m[3]) : (m[4] == "." ? -1 : 0);

            parts.push(format.substr(0, m[0][0] == "%" ? m.index : m.index+1));
            parts.push({appender: appender, precision: precision});

            format = format.substr(m.index+m[0].length);
        }

        parts.push(format);

        return parts;
    }

    function escapeHTML(value)
    {
    	return value;
        function replaceChars(ch)
        {
            switch (ch)
            {
                case "<":
                    return "<";
                case ">":
                    return ">";
                case "&":
                    return "&";
                case "'":
                    return "'";
                case '"':
                    return """;
            }
            return "?";
        };
        return String(value).replace(/[<>&"']/g, replaceChars);
    }

    function objectToString(object)
    {
        try
        {
            return object+"";
        }
        catch (exc)
        {
            return null;
        }
    }

    setTimeout(init, 0);
})();
}

4.main.js
var num = 0; // 当前加载次数
            var L = 0; // 第一次用掉的Num
            var R = 0; // 当前剩下的Num
            var allData = 0; // 最后一次的Num
            var step = 0;
            var flag = true;
            
            function show(){
                //display list data
                DWRExample.getList(call);
            }
            
            function call(data){
                var content = document.getElementById("contents").innerHTML;
                if (data) {
                
                    if (num == 0) {
                        allData = data.length;
                        L = 0;
                        step = (allData < 2) ? allData : 2;
                        R = L + step;
                        num++;
                    }
                    else {
                        if ((allData - R) > 0) {
                            L = R;
                            step = ((allData - L) < 2) ? (allData - L) : 2;
                            R = L + step;
							num++;
                        }
                        else {
                            flag = false;
                        }
                    }
                    if (flag) {
                        for (var i = L; i < R; i++) {
                        
                            //alert(data[i].name);
                            
                            var str = "<div class=item><a href='"; 
				
							str += data[i].imgDescription;					
							
							str += "'><img src='";
							
                            str += data[i].addr;
                            
                            str += "'></img></a><div class=comments_top>";
                            
                            str += data[i].comTop;
                            
                            str += "</div><div class=comments_bottom><div class=comments_bottom_left>";
                            
                            str += data[i].comBtmLeft;
                            
                            str += "</div><div class=comments_bottom_right>";
                            
                            str += data[i].comBtmRight;
                            
                            str += "</div></div></div>";
                            
                            content += str;
                        }
                    }
                    else {
                        alert("亲,所有数据都加载完咯!*^_^*");
                    }
                    DWRUtil.setValue("contents", content);                    
                }
            }
			
            addEventListener("load", function(){
                setTimeout(updateLayout, 0);
            }, false);
            
            var currentWidth = 0;
            
            function updateLayout(){
                if (window.innerWidth != currentWidth) {
                    currentWidth = window.innerWidth;
                    
                    var orient = currentWidth == 320 ? "profile" : "landscape";
                    document.body.setAttribute("orient", orient);
                    setTimeout(function(){
                        window.scrollTo(0, 1);
                    }, 100);
                }
            }
            
            setInterval(updateLayout, 1400);
            
            console.info('iPhone logging initialized');

5.dwr.xml
<?xml version="1.0" encoding="utf-8"?>
<dwr>
	<allow>
		<convert converter="bean" match="com.DemoBean"/>
		
		<create creator="new" javascript="DWRExample" class="com.DWRExample" scope="session">
			<include method="getList"/>
		</create>
	</allow>
</dwr>

6.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <!-- DWR2.0  -->
   <servlet>
    <servlet-name>dwrInvoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>classes</param-name>
    <param-value>java.lang.Object</param-value>
    </init-param>
      
      <load-on-startup>10</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>dwrInvoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>


</web-app>

6. DemoBean.java

package com;

import java.io.Serializable;

public class DemoBean
    implements Serializable
{

    public DemoBean()
    {
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getAddr()
    {
        return addr;
    }

    public void setAddr(String addr)
    {
        this.addr = addr;
    }

    public String getComTop()
    {
        return comTop;
    }

    public void setComTop(String comTop)
    {
        this.comTop = comTop;
    }

    public String getComBtmLeft()
    {
        return comBtmLeft;
    }

    public void setComBtmLeft(String comBtmLeft)
    {
        this.comBtmLeft = comBtmLeft;
    }

    public String getComBtmRight()
    {
        return comBtmRight;
    }

    public void setComBtmRight(String comBtmRight)
    {
        this.comBtmRight = comBtmRight;
    }

    public String getImgDescription()
    {
        return imgDescription;
    }

    public void setImgDescription(String imgDescription)
    {
        this.imgDescription = imgDescription;
    }

    private int id;
    private String addr;
    private String comTop;
    private String comBtmLeft;
    private String comBtmRight;
    private String imgDescription;
}

7.DWRExample.java

package com;

import java.io.Serializable;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

// Referenced classes of package com:
//            DemoBean

public class DWRExample
    implements Serializable
{

    public DWRExample()
    {
    }

    public List getList()
    {
        List imgList;
        String sql;
        String driver;
        String url;
        String user;
        String password;
        Statement stmt;
        ResultSet rs;
        Connection conn;
        imgList = new ArrayList();
        DemoBean img = null;
        sql = "select * from img";
        driver = "com.mysql.jdbc.Driver";
        url = "jdbc:MySQL://127.0.0.1:3306/iosweb";
        user = "root";
        password = "root";
        stmt = null;
        rs = null;
        conn = null;
        try
        {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
            if(!conn.isClosed())
            {
                stmt = conn.createStatement();
                img = new DemoBean();
                for(rs = stmt.executeQuery(sql); 
                rs.next(); 
                imgList.add(img))
                {
                    img = new DemoBean();
                    img.setId(Integer.parseInt(rs.getString("id")));
                    img.setAddr(rs.getString("addr"));
                    img.setComTop(rs.getString("com_top"));
                    img.setComBtmLeft(rs.getString("com_btm_left"));
                    img.setComBtmRight(rs.getString("com_btm_right"));
                    img.setImgDescription(rs.getString("img_description"));
                }

            } 
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        try
        {
            rs.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            stmt.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            conn.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        } 
        try
        {
            rs.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            stmt.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            conn.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        } 
        try
        {
            rs.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            stmt.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        try
        {
            conn.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        return imgList;
    }

    public boolean checkUser(String name)
    {
        return "xy".equals(name);
    }
}


2014-01-22 18:46:59 HUANGQIN19880508 阅读数 22

 问题:使用InstrumentDriver框架做ios自动化测试时,eclipse不能正常执行ios测试用例,每次执行printElementTree时都会超时,如下图所示:



 

分析:eclipse找不到设备。测试项目中athrun.properties文件中的isRunSimulator的值为true(实际上应该为false),导致InstrumentDriver框架中的runTests.sh文件最终执行的命令是:

instruments  -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -D instrumentsDriver /Users/qinhuang/Library/Developer/Xcode/DerivedData/TaoTest-crxfytdmxwvbavfwuazuwlgpjuxi/Build/Products/Debug-iphoneos/TaoTest.app -e UIASCRIPT /Users/qinhuang/InstrumentDriver/CSRunner.js -e UIARESULTSPATH /Users/qinhuang/InstrumentDriver/log/ -v

 

而实际上应该为:

instruments -w udid           -t  /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -D instrumentsDriver /Users/qinhuang/Library/Developer/Xcode/DerivedData/TaoTest-crxfytdmxwvbavfwuazuwlgpjuxi/Build/Products/Debug-iphoneos/TaoTest.app -e UIASCRIPT /Users/qinhuang/InstrumentDriver/CSRunner.js -e UIARESULTSPATH /Users/qinhuang/InstrumentDriver/log/ -v

 

 

解决方法:将测试项目中athrun.properties文件中的isRunSimulator的值改为false

没有更多推荐了,返回首页