#!/bin/bash# Version: 0.3# Author: linkscue# E-mail: [email protected]# function: get key words start line number,$1=key_wordget_start_line(){    # shell function can't return >255 value, so echo replace return    echo $(grep -n "$1" $style_file | awk -F':' '{print $1}')}# function: get a style(or sub_style) end line number,$1=line_numberget_end_line(){    echo $(sed -n  "$1,/<\/style>/{=}" $style_file | sed -n '$p')}# function: get pattern line number,s1=start s2=end s3=patternget_pattern_line(){    echo $(sed -n -e "$1,$2{/$3/{=;q}}" $style_file)}#function: get a style start and end line numberget_start_end_line(){    echo $(get_start_line "$1")    echo $(get_end_line $(get_start_line "$1") )}# error detectif [[ $# != 2 ]]; then    #statements    echo 'usage: change_xml $style_file $color_file '    exit 1fi# which file will be modified:style_file=$1color_file=$2#style_file=styles.xml#color_file=colors.xml# which style will be changed:theme_main_key='<style name="Theme">'holo_main_key='<style name="Theme.Holo"'holo_light_key='<style name="Theme.Holo.Light"'holo_dialog_key='<style name="Theme.Holo.Dialog"'holo_panel_key='<style name="Theme.Holo.Panel"'holo_input_key='<style name="Theme.Holo.InputMethod"'# style start & end positiontheme_main_pos=$(get_start_end_line "$theme_main_key")holo_main_pos=$(get_start_end_line "$holo_main_key")holo_light_pos=$(get_start_end_line "$holo_light_key")holo_dialog_pos=$(get_start_end_line "$holo_dialog_key")holo_panel_pos=$(get_start_end_line "$holo_panel_key")holo_input_pos=$(get_start_end_line "$holo_input_key")# which line we will change:theme_main_background=$(get_pattern_line $theme_main_pos windowBackground)holo_main_background=$(get_pattern_line $holo_main_pos colorBackground)holo_main_show_wp=$(get_pattern_line $holo_main_pos windowShowWallpaper)holo_light_show_wp=$(get_pattern_line $holo_light_pos windowShowWallpaper)holo_dialog_show_wp=$(get_pattern_line $holo_dialog_pos windowShowWallpaper)holo_panel_show_wp=$(get_pattern_line $holo_panel_pos windowShowWallpaper)holo_input_show_wp=$(get_pattern_line $holo_input_pos windowShowWallpaper)# some text patternstext_fSwp='       <item name=\"windowShowWallpaper\">false</item>'text_tSwp='       <item name=\"windowShowWallpaper\">true</item>'text_cBgd_clr='   <color name=\"background\">\#c8000000<\/color>'text_bBgd_add='       <item name="windowBackground">@color/background</item>'text_bBgd_or='drawable\/screen_background_selector_dark'text_bBgd_new='color\/background'text_cBgd_or='background_holo_dark'text_cBgd_new='transparent'# change the style filea=1; b=1;sed "$theme_main_background{s/$text_bBgd_or'/'$text_bBgd_new'/}" $style_file > $b.xml;a=$b;((b++));sed "$holo_main_background{s/$text_cBgd_or/$text_cBgd_new/}" $a.xml > $b.xml;a=$b;((b++));sed "$holo_main_show_wp c\ $text_tSwp" $a.xml > $b.xml;a=$b;((b++));if [[ $holo_light_show_wp ]]; then    sed "$holo_light_show_wp c\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));else     sed "$(echo $holo_light_pos | awk '{print $2}') i\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));fiif [[ $holo_dialog_show_wp ]]; then    sed "$holo_dialog_show_wp c\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));else     sed "$(echo $holo_dialog_pos | awk '{print $2}') i\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));fiif [[ $holo_panel_show_wp ]]; then    sed "$holo_panel_show_wp c\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));else     sed "$(echo $holo_panel_pos | awk '{print $2}') i\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));fiif [[ $holo_input_show_wp ]]; then    sed "$holo_input_show_wp c\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));else     sed "$(echo $holo_input_pos | awk '{print $2}') i\ $text_fSwp" $a.xml > $b.xml;a=$b;((b++));fised "$holo_main_background i\ $text_bBgd_add" $a.xml > $b.xml;a=$b;((b++));sed "7 i\ $text_cBgd_clr" $color_file > color_new.xml# replace/rm filecp $a.xml style_new.xmlmv style_new.xml $style_filemv color_new.xml $color_filerm [0-9]*.xml

重写了大部分代码,增强了通用性。

更多相关文章

  1. QQ音乐Android客户端Web页面通用性能优化实践
  2. Android命令行启动程序-am命令的使用-纠正网上大部分资料的错误
  3. android中控件的大部分属性解释
  4. 涵盖大部分核心组件使用的 Spring Cloud 教程,一定要收藏哦!

随机推荐

  1. Ubuntu下 eclipse搭建android集成开发环
  2. Android开发人员终于在“app-构建控制台
  3. Android(安卓)EGL
  4. Android(安卓)Develop API 1
  5. Android(安卓)bitmap图片处理
  6. Android(安卓)adb shell 命
  7. Android(安卓)框架模式 MVC 在Android中
  8. 近期工作计划
  9. 画一个可以动的Android(安卓)小机器人
  10. windows android apk,framework 解包,打包