〖Android〗依据资源信息,Mock Android资源

 1 #!/bin/bash - 
 2 #===============================================================================
 3 #
 4 #          FILE: mock_res.sh
 5 # 
 6 #         USAGE: ./mock_res.sh 
 7 # 
 8 #   DESCRIPTION: 
 9 # 
10 #       OPTIONS: ---
11 #  REQUIREMENTS: ---
12 #          BUGS: ---
13 #         NOTES: ---
14 #        AUTHOR: linkscue (scue), [email protected]
15 #  ORGANIZATION: 
16 #       CREATED: 2014年08月06日 20时37分46秒 CST
17 #      REVISION:  ---
18 #===============================================================================
19 
20 # 传入参数
21 # $1: Mock程序目录 android create project..
22 # $2: Mock资源类型 如 style/AppMyTheme string/app_name_emm ..
23 android_res_mock(){
24     dir=$1
25     res=$2
26     restype=$(echo $res|awk -F/ {print $1})
27     echo "正在处理 $res"
28     case $restype in
29         xml )
30             # TODO: cp
31             path=$dir/res/${res}.xml
32             mkdir -p $(dirname $path)
33             cp ./empty_xml.xml $path
34             ;;
35         drawable )
36             # TODO: touch
37             path=$dir/res/${res}.png
38             mkdir -p $(dirname $path)
39             touch $path
40             ;;
41         string )
42             # TODO: sed -i
43             path=$dir/res/values/strings.xml
44             mkdir -p $(dirname $path)
45             string_name=$(echo $res|awk -F/ {print $2})
46             string_model=    <string name="mock_string_modol">mock_string_modol</string>
47             string_model_file=/tmp/mock_string_model.txt
48             string_empty_file=./empty_strings.xml # TODO: 绝对路径
49             echo "$string_model" >$string_model_file
50             sed -i "s/mock_string_modol/$string_name/g" $string_model_file
51             test ! -e $path && cp $string_empty_file $path
52             grep -qF \"$string_name\" $path || sed -i "2 r $string_model_file" $path
53             rm -f $string_model_file
54             ;;
55         style )
56             # TODO: sed -i
57             path=$dir/res/values/styles.xml
58             mkdir -p $(dirname $path)
59             style_name=$(echo $res|awk -F/ {print $2})
60             style_model=    <style name="MOCK_Style_Model" parent="android:Theme.Light"></style>
61             style_model_file=/tmp/mock_style_model.txt
62             style_empty_file=./empty_styles.xml
63             echo "$style_model" >$style_model_file
64             sed -i "s/MOCK_Style_Model/$style_name/g" $style_model_file
65             test ! -e $path && cp $style_empty_file $path
66             grep -qF \"$style_name\" $path || sed -i "1 r $style_model_file" $path
67             rm -f $style_model_file
68             ;;
69         * )
70             err "未知资源类型,请反馈给 [email protected]"
71             exit 1
72     esac
73 }
74 
75 # 调用方法
76 for i in $(cat ./res_list.txt); do
77     android_res_mock ./app $i
78 done

 

〖Android〗依据资源信息,Mock Android资源,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。