zoukankan      html  css  js  c++  java
  • 〖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), linkscue@gmail.com
    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 "未知资源类型,请反馈给 linskcue@gmail.com"
    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

     

  • 相关阅读:
    CSS的未来:游戏的变革Flexbox
    2013年第8周一JAVA对象序列化及TODO标签等
    大年初七回杭州
    2013年2月20日星期三
    2013年周六加班杂记
    大家初八但杭州收拾准备开始工作
    大家初六去香山
    2013年第8周四又是低效的一天
    2013年第8周二Delphi中Union结构
    2013年第8周日元宵节
  • 原文地址:https://www.cnblogs.com/scue/p/3895947.html
Copyright © 2011-2022 走看看