2021-07-24 11:41:24 +03:00
#!/bin/bash
set -e
shopt -s globstar
my_dir = " $( dirname " $( realpath " $0 " ) " ) "
pushd " $my_dir " > /dev/null
function add_alpha_to_color( ) {
local color = " $1 "
local alpha = " $2 "
echo " $color " | sed " s|#|# $alpha | "
}
function add_noalpha_to_color( ) {
local color = " $1 "
local alpha = " $2 "
python -c " print('#' + hex(int(255 - $alpha *(255-int(' $color '[1:3], 16))))[2:] + hex(int(255 - $alpha *(255-int(' $color '[3:5], 16))))[2:] + hex(int(255 - $alpha *(255-int(' $color '[5:7], 16))))[2:]) "
}
function theme_file( ) {
local file = " $1 "
local name = " $2 "
local color = " $3 "
2021-11-12 13:30:08 +03:00
local presence_color = " $4 "
2021-07-24 11:41:24 +03:00
local name_lc = ` echo " $name " | tr '[:upper:]' '[:lower:]' `
local color_alpha25 = ` add_alpha_to_color " $color " "3f" `
local color_noalpha12 = ` add_noalpha_to_color " $color " '0.12' `
local target_file = ` echo " $file " | sed " s|bluelight| $name_lc |g " `
if [ " $file " = " $target_file " ] ; then
return
fi
cp " $file " " $target_file "
sed -i " s|BlueLight| $name |g;s|bluelight| $name_lc |g;s|#03a9f4| $color |g;s|#3f03a9f4| $color_alpha25 |g;s|#e0f4f3| $color_noalpha12 |g " " $target_file "
2021-11-12 13:30:08 +03:00
# Note: following might reference accent_sc again, without it being changed back
sed -i " s|\\(<item name=\"vctr_presence_indicator_online\">\\).*\\(</item>\\)|\\1 $presence_color \\2|g " " $target_file "
2021-07-24 11:41:24 +03:00
}
function insert_above_comment( ) {
local comment_pre = " $1 "
local comment_post = " $2 "
local file = " $3 "
local comment = " $4 "
local insert = " $5 "
local indention = " $6 "
if ! grep -q " $insert " " $file " ; then
cat " $file " | tr '\n' '\r' | sed " s|\\( $comment_pre $comment $comment_post \\)| $insert \r $indention \\1| " | tr '\r' '\n' > " $file .tmp "
mv " $file .tmp " " $file "
fi
}
function insert_above_java_comment( ) {
insert_above_comment "// " "" " $@ "
}
function insert_above_xml_comment( ) {
insert_above_comment "<!-- " " -->" " $@ "
}
function generate_accent_common( ) {
local name = " $1 "
local name_str = " $2 "
local name_lc = ` echo " $name " | tr '[:upper:]' '[:lower:]' `
insert_above_xml_comment "vector/src/main/res/values/strings_sc.xml" "do not change this comment for accent generation" " <string name=\"sc_accent_ $name_lc \"> $name_str </string> " " "
}
function generate_accent_light( ) {
# Usage:
2021-11-12 13:30:08 +03:00
# generate_accent <name> <color_for_light_themes> <color_for_presence_indicator>
2021-07-24 11:41:24 +03:00
local name = " $1 "
local name_str = " $2 "
local color_lt = " $3 "
2021-11-12 13:30:08 +03:00
local color_presence_lt = " $4 "
2021-07-24 11:41:24 +03:00
local name_lc = ` echo " $name " | tr '[:upper:]' '[:lower:]' `
# String
generate_accent_common " $name " " $name_str "
# Settings arrays
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for light accent entry generation" \
" <item>@string/sc_accent_ $name_lc </item> <!-- Light $name name --> " \
" "
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for light accent value generation" \
" <item> $name_lc </item> <!-- Light $name id --> " \
" "
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for light accent preview generation" \
" <item> $color_lt </item> <!-- Light $name accent --> " \
" "
# Actual theming
for f in **/"theme_sc_light_accent_bluelight.xml" ; do
2021-11-12 13:30:08 +03:00
theme_file " $f " " $name " " $color_lt " " $color_presence_lt " \;
2021-07-24 11:41:24 +03:00
done
# Selection code
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic light theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_SC_Light_ $name " \
" "
}
function generate_accent_dark( ) {
# Usage:
2021-11-12 13:30:08 +03:00
# generate_accent <name> <color_for_dark_themes> <color_for_presence_indicator>
2021-07-24 11:41:24 +03:00
local name = " $1 "
local name_str = " $2 "
local color_dk = " $3 "
2021-11-12 13:30:08 +03:00
local color_presence_dk = " $4 "
2021-07-24 11:41:24 +03:00
local name_lc = ` echo " $name " | tr '[:upper:]' '[:lower:]' `
# String
generate_accent_common " $name " " $name_str "
# Settings arrays
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for dark accent entry generation" \
" <item>@string/sc_accent_ $name_lc </item> <!-- Dark $name name --> " \
" "
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for dark accent value generation" \
" <item> $name_lc </item> <!-- Dark $name id --> " \
" "
insert_above_xml_comment "vector/src/main/res/values/arrays_sc.xml" \
"do not change this comment for dark accent preview generation" \
" <item> $color_dk </item> <!-- Dark $name accent --> " \
" "
# Actual theming
for f in **/"theme_sc_accent_bluelight.xml" ; do
2021-11-12 13:30:08 +03:00
theme_file " $f " " $name " " $color_dk " " $color_presence_dk " \;
2021-07-24 11:41:24 +03:00
done
# Selection code
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic black theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_SC_ $name " \
" "
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic dark theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_SC_Dark_ $name " \
" "
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic black colored theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_SC_Colored_ $name " \
" "
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic dark colored theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_SC_Dark_Colored_ $name " \
" "
2022-04-19 11:26:10 +03:00
insert_above_java_comment "vector/src/main/java/im/vector/app/features/themes/ThemeUtils.kt" \
"Do not change this comment for automatic attachment theme insertion" \
" \" $name_lc \" -> R.style.AppTheme_AttachmentsPreview_SC_ $name " \
" "
2021-07-24 11:41:24 +03:00
}
function generate_accent( ) {
# Usage:
2021-11-12 13:30:08 +03:00
# generate_accent <name> <color_for_light_themes> <color_for_dark_themes> [<color_for_presence_indicator> [<name_string>]]
2021-07-24 11:41:24 +03:00
local name = " $1 "
local color_lt = " $2 "
local color_dk = " $3 "
2021-11-12 13:30:08 +03:00
local color_presence = " $4 "
local name_str = " $5 "
if [ -z " $color_presence " ] ; then
color_presence_lt = "?colorAccent"
color_presence_dk = "?colorAccent"
else
color_presence_lt = " $color_presence "
color_presence_dk = " $color_presence "
fi
2021-07-24 11:41:24 +03:00
if [ -z " $name_str " ] ; then
name_str = " $name "
fi
2021-11-12 13:30:08 +03:00
generate_accent_light " $name " " $name_str " " $color_lt " " $color_presence_lt "
generate_accent_dark " $name " " $name_str " " $color_dk " " $color_presence_dk "
2021-07-24 11:41:24 +03:00
}
2021-11-12 13:30:08 +03:00
default_accent = "@color/accent_sc"
generate_accent "Amber" "#ffa000" "#ffab00" " $default_accent "
generate_accent "BlueLight" "#03a9f4" "#03a9f4" "" "Light blue"
generate_accent "Blue" "#2196F3" "#2196F3" ""
generate_accent "Carnation" "#fb83b2" "#ffa6c9" ""
generate_accent "Cyan" "#00bcd4" "#00bcd4" ""
generate_accent "Denim" "#1560BD" "#1560BD" ""
generate_accent "Gold" "#CFB53B" "#CFB53B" ""
#generate_accent "GreenLight" "#8bc34a" "#8bc34a" "" "Light green"
generate_accent "GreenDark" "#4CAF50" "#4CAF50" "" "Dark green"
#generate_accent "Grey" "#808080" "#808080" ""
#generate_accent "Hope" "#5fc72d" "#59ff3a" ""
generate_accent "Indigo" "#5C6BC0" "#5C6BC0" ""
generate_accent "Lava" "#B20120" "#EB0028" " $default_accent "
generate_accent "Lime" "#C0CA33" "#AFB42B" ""
generate_accent "Orange" "#ff9800" "#ff9800" " $default_accent "
#generate_accent "Oxygen" "#53ADEF" "#53ADEF" ""
generate_accent "Pink" "#e91e63" "#f48fb1" ""
#generate_accent "Pixel" "#4285f4" "#3367d6" ""
generate_accent "Purple" "#673ab7" "#9575CD" ""
generate_accent "Red" "#ff0000" "#ff0000" " $default_accent "
generate_accent "Teal" "#008577" "#80cbc4" ""
generate_accent "Turquoise" "#00C1C1" "#00C1C1" ""
generate_accent "Yellow" "#FBC02D" "#FBC02D" " $default_accent "
2021-07-24 11:41:24 +03:00
# We have foreground on accent colors, better skip these
#generate_accent "Grey" "#808080" "#808080"
#generate_accent_light "Black" "Black" "#212121"
#generate_accent_dark "White" "White" "#eeeeee"
popd > /dev/null