lgxqf  
日历

导航

随笔分类

 

2011年9月21日

#Usage: monkeyrunner recorder.py

#recorder.py  http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_recorder.py

from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder

device = mr.waitForConnection()
recorder.start(device)
#END recorder.py
#Press ExportAction to save recorded scrip to a file
#Example of result:
#PRESS|{'name':'MENU','type':'downAndUp',}
#TOUCH|{'x':190,'y':195,'type':'downAndUp',}
#TYPE|{'message':'',}
============================================================================================
#Usage: monkeyrunner playback.py "myscript"
#playback.py   http://mirror.yongbok.net/linux/android/repository/platform/sdk/monkeyrunner/scripts/monkey_playback.py
import sys
from com.android.monkeyrunner import MonkeyRunner

# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command.  The line is split into 2
# parts with a | character.  Text to the left of the pipe denotes
# which command to run.  The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command.  In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command. 

# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
    'TOUCH': lambda dev, arg: dev.touch(**arg),
    'DRAG': lambda dev, arg: dev.drag(**arg),
    'PRESS': lambda dev, arg: dev.press(**arg),
    'TYPE': lambda dev, arg: dev.type(**arg),
    'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
    }

# Process a single file for the specified device.
def process_file(fp, device):
    for line in fp:
        (cmd, rest) = line.split('|')
        try:
            # Parse the pydict
            rest = eval(rest)
        except:
            print 'unable to parse options'
            continue

        if cmd not in CMD_MAP:
            print 'unknown command: ' + cmd
            continue

        CMD_MAP[cmd](device, rest)


def main():
    file = sys.argv[1]
    fp = open(file, 'r')

    device = MonkeyRunner.waitForConnection()
    
    process_file(fp, device)
    fp.close();
    

if __name__ == '__main__':
    main()



posted @ 2011-09-21 12:01 Justin_Ma 阅读(190) 评论(1) 编辑

2011年9月18日

#Save this file as mms.py and run it by Command: MonkeyRunner mms.py

# Imports the monkeyrunner modules used by this program

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object

device = MonkeyRunner.waitForConnection()

# sets a variable with the package's internal name

package = 'com.android.mms'

# sets a variable with the name of an Activity in the package

activity = '.ui.ConversationList'

# sets the name of the component to start

runComponent = package + '/' + activity

# Runs the component

device.startActivity(component=runComponent)

# Presses the Menu button

device.press('KEYCODE_MENU',MonkeyDevice.DOWN_AND_UP)

# Takes a screenshot

result = device.takeSnapshot()

# Writes the screenshot to a file

result.writeToFile('shot1.png','png')

posted @ 2011-09-18 21:25 Justin_Ma 阅读(133) 评论(0) 编辑
 

写一个help.py

然后用命令 monkeyrunner.bat help.py

即可生成help.html

#help.py

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

text = MonkeyRunner.help("html");

f = open('help.html', 'w')

f.write(text);

f.close();

posted @ 2011-09-18 20:53 Justin_Ma 阅读(50) 评论(0) 编辑

2010年11月22日

第三章 C++中的C
    1. .hxx .hpp也是C++头文件
    2.写可移植的C++程序:用C++标准库,和尽量使用符合POSIX标准的函数
    3.头文件<climits>和<cfloat>中定义了不同基本数据类型可能存储的最大值和最小值
    4.sizeof 是一个运算符 不是函数, 如果对一个变量使用它,可以不要括号: int i = sizeof i;
    5.同类型指针相减,其结果是两个指针之间相隔元素的个数
    6.把变量和表达式转换成字符串:在一个预处理器宏中的参数前加一个#,预处理器会把这个参数转换为一个字符数组
            #define P(A) cout<< #A <<": result" << A << endl;
    7.## 标志粘贴:它允许设两个标识符并把它们粘贴在一起自动产生一个新的标识符。
            #deifine FIELD(a)  char * a##_string;
            FIELD(my);  ===> char*  my_string;


第五章 隐藏实现
    1.友元
        class My{
            public:
                friend void g();//友元:全局函数
                friend class z;//友元:类
                friend Y::fun();//友元:其它类的成员函数
        }
    2.友元是可以嵌套的

 


第七章 函数重载与默认参数
    1.union(联合)可以带有构造函数、析构函数、成员函数甚至访问控制,但它不能在继承时做基类使用
    2.没有类型名和标识符的union叫匿名联合
        int main(){
            union{
                int i;
                float f;
            };
            i=12; f = 1.0;
        }

 


第八章 常量
    1.临时变量按引用传递给一个函数时,这个函数的参数必须是const引用
        class X{};
       
        X fun()(return X();}
       
        void g1(X&){}
        void g2(const X&){}
       
        main(){
            g1( fun() );//This line will cause build error : const temporary created by fun()
            g2( fun() );
        }
    2.类的const实例对象只能调用const成员函数。类的非const实例对象,可调用const和非const成员函数 但会优先调用非const成员函数。

 


第十章 名字空间
    1.静态对象的构造和析构函数
        全局变量、对象的构造函数在main()之前被调用,且存储空间分配在静态存储区
        所有静态对象无论是全局还是局部,它的析构函数都在main()之后被调用
        如果一个包含局部静态对象的函数从未被调用过,那么这个对象的构造函数也不会被执行
    2.内部连接
        在文件作用域内,一个被明确声明为static的对象或函数是内部连接的
        内部连接的一个好处是这个名字可以放在一个头文件中而不用担心连接时发生冲突。
        那些通常入在头文件里的名字。如常量、内联函数、在默认情况下都是内部连接的(当然常量只在C++中默认为是内部连接,在C中外部连接)
    3.namesapce可以有别名。一个namespace可以在多个头文件中用一个标识符来定义,从而往namespace中添加内容

 


posted @ 2010-11-22 10:45 Justin_Ma 阅读(83) 评论(0) 编辑

2010年1月20日

public class HowToUseArray {
    
public static void main(String[] args)
    {

        //Correct usage 

 

        int [] ary;
        
        
int [] aryA = {1,2};
        
        
int [] aryB = new int[2];
        aryB[
0= 1;
        aryB[
1= 2;
        
        
int [] aryC = new int[]{1,2};
        
        
//Wrong usage
        
        
//int [] aryD = new int[2]{1,2};
     //
Cannot define dimension expressions when an array initializer is provided

        
//int aryE[4];
    }
}
posted @ 2010-01-20 23:32 Justin_Ma 阅读(50) 评论(0) 编辑

2009年12月30日

第八章 多态
    静态方法不具备多态因为它是与类,而非单个对象相关联的。
    Java中除了final和static方法之外,其它所有的方法都是后期绑定的
    构造函数中的虚函数是动态联编的,但在C++中是静态联编的 TIJ书 P163
    子类不可改变基类中函数的可见性。若基类中某函数为public,在继承时该函数仍需为public
    Java SE5 添加了返回类型,它允许子类在虚函数中返回基类的子类型。在实现protype设计模式时会用到该功能。
        public class Grain
        {    
            public Grain cloneObject()
            {
                return new Grain();
            }
        }

        class Wheat extends Grain
        {
            public Wheat cloneObject()
            {
                return new Wheat();
            }
        }
    向下转型:
        Base b = new Derive();   
        ((Derive)b).deriveClassFunction();
        若转型失败就会返回一个ClassCastException异常

第九章 接口
    abstract 抽象类或方法的关键字
    interface 接口类的关键字,interface中的方法只能是public的,且只有原型没有实现。
    interface 中的任何成员变量默认是 public static final的
    基类和子类都共享基类的静态变量
    抽象类与接口类的区别:
        抽象类中可以有函数的定义,接口类不能有函数的定义
    实现多个接口的语法:
        Class Hero extends Human  implements Fly, Swim,Fight{}
    接口中的成员变量不能是空白final, 但可以被非常量表达式初始化

    public interface Rand    { int VAL = Rand.nextInt(10);}

 

第十章 内部类
    在外部类的非静态方法中可以直接创建内部类对象,但在外部类的非静态方法之外只能通过外部的函数创建内部类。
    例:
        Outter out = new Outter();
        Outter.Inner in = out.getInner();
    .this .new
        .this 在内部类的函数中返回外部类的引用
            public class Outter{
                public class Inner{
                    Outter getOutter(){ return Outter.this}
                }
        .new 通过外部类对象的引用创建内部类对象。
            Outter out = new Outter();
            Outter.Inner in = out.new Inner();
        若inner是静态内部类,若内部类是静态类则可直接创建
            Outter.Inner in =  new Outter.Inner();

    在作用域和方法内的类仅在作用域内可用,在作用域外不能访问。
    内部类可以直接访问外部内的成员变量,但访问在外部定义的对象时,如外部类函数的参数,该参数必须声明为final
    匿名类:
        匿名类不能有构造函数,但可以通过实例初始化{}来初始化匿名类的成员变量
        匿名类相当于new 后面的所指定的类的子类,return new Base(){ void BaseClassMethod(){} } 相当于返回了一个Base的子类对象。 详见书中练习12 P199
    
    嵌套类:
        将内部类声明为static.
        它与内部类的区别:
            1.内部类有一个指向外部类的引用,而嵌套类没有,所以嵌套类不可直接访问外部类的非静态成员或方法。
            2.内部类不能有静态的成员或方法,但嵌套类可以有。
        可以将测试代码放在嵌套类中, 在发布产品时将嵌套类的class文件删就可以了。如  Outter$inner.class
        
    为什么需要内部类:
        每个内部类都能独立地继承自一个(接口的)实现,所以无论外围类是否已经继承了某个(接口)的实现,对于内部类都没有影响
        内部类有效地实现了“多重继承”. 

posted @ 2009-12-30 15:57 Justin_Ma 阅读(112) 评论(0) 编辑

2009年12月2日

摘要: 第三章 操作符CLASSPATH环境变量用来查找编译时所需的类.java文件s1.关系操作符 引用比较:== 用于判断引用所指的对象(对象的内存地址)是否相同。 对象比较:equals()。比较两个对象中的内容是否相同则需覆盖equals()函数。 &&, ||, ! 只可用于boolean变量 如:int i; !(i < 10)//correct !i //wrong2...阅读全文
posted @ 2009-12-02 11:25 Justin_Ma 阅读(27) 评论(0) 编辑

2009年10月27日

摘要: Java also has a “default” access, which comes into play if you don’t use one of the aforementioned specifiers. This is usually called package access because classes can access the me...阅读全文
posted @ 2009-10-27 22:12 Justin_Ma 阅读(85) 评论(0) 编辑

2009年10月10日

摘要: 常用命令 android list target android create avd --name and16 --target 2 adb shell adb devices adb kill-server adb install adb push/pull /sdcard/music.mp3 mksdcard -l lable 1024M d:\sdcardfile adb shell a...阅读全文
posted @ 2009-10-10 13:54 Justin_Ma 阅读(114) 评论(0) 编辑

2009年5月3日

摘要: 把filelist中列出的文件拷贝到mydir中 cat filelist | xargs -i cp {} mydir修改程序的默认打开方式: sudo /etc/gnome/defaults.list 保存了全局的打开方式 ~/.local/share/applications/mimeapps.list 保存了个人的打开方式提升权限 sudo -i 或 sudo su查看Ubuntu版本 ...阅读全文
posted @ 2009-05-03 14:56 Justin_Ma 阅读(65) 评论(0) 编辑
 
Copyright © Justin_Ma Powered by: 博客园 模板提供:沪江博客