Skip to content

Commit e9ff2bf

Browse files
committed
Keep PNGs in repo to avoid running image gen during all CI
- mtransitapps/commons#680
1 parent 2fa682c commit e9ff2bf

1 file changed

Lines changed: 118 additions & 81 deletions

File tree

pub/module-res-mipmap-launcher-icon-adaptive.sh

Lines changed: 118 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@ SRC_DIR="${APP_ANDROID_DIR}/src";
2121
MAIN_DIR="${SRC_DIR}/main";
2222
RES_DIR="${MAIN_DIR}/res";
2323

24-
FILE_NAME_XML="module_app_icon.xml"
25-
MIPMAP_ANYDPI="${RES_DIR}/mipmap-anydpi-v26"
26-
FILE_XML="${MIPMAP_ANYDPI}/${FILE_NAME_XML}";
27-
28-
VALUES_DIR="${RES_DIR}/values"
29-
COLOR_FILE_NAME_XML="module_app_icon_color.xml"
30-
COLOR_FILE_XML="${VALUES_DIR}/${COLOR_FILE_NAME_XML}";
31-
32-
mkdir -p "${MIPMAP_ANYDPI}";
33-
checkResult $?;
34-
mkdir -p "${VALUES_DIR}";
35-
checkResult $?;
36-
3724
requireCommand "xmllint" "libxml2-utils";
3825
requireCommand "jq";
3926

@@ -106,84 +93,134 @@ echoDebug " - svg: $SOURCE"
10693

10794
DEST_FILE_NAME="module_app_icon_foreground.png"
10895

109-
DEST_DIR="$RES_DIR/mipmap-xxxhdpi"
110-
mkdir -p "$DEST_DIR"
111-
112-
DEST="$DEST_DIR/$DEST_FILE_NAME"
113-
echoDebug " - png: $DEST"
114-
rm -rf "$DEST";
96+
XXXHDPI_DIR="$RES_DIR/mipmap-xxxhdpi"
97+
mkdir -p "$XXXHDPI_DIR"
11598
checkResult $?;
99+
XXXHDPI_DEST="$XXXHDPI_DIR/$DEST_FILE_NAME"
100+
echoDebug " - xxxhdpi: $XXXHDPI_DEST"
116101

117-
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
118-
requireCommand "convert" "imagemagick";
119-
120-
echoDebug "> Converting SVG to PNG..."
121-
convert \
122-
-background none \
123-
"$SOURCE" \
124-
-gravity center \
125-
-scale 348x348 \
126-
-extent 432x432 \
127-
"$DEST";
128-
RESULT=$?
129-
if [[ ${RESULT} -ne 0 ]]; then
130-
echo "> Error converting SVG to PNG!"
131-
exit ${RESULT}
132-
fi
133-
echoDebug "> Converting SVG to PNG... DONE"
134-
135-
echoDebug "> Converting XXXHDPI to other DPIs..."
136-
mkdir -p "$RES_DIR/mipmap-xxhdpi"
137-
convert $DEST -resize 75% $RES_DIR/mipmap-xxhdpi/$DEST_FILE_NAME
138-
checkResult $?;
139-
mkdir -p "$RES_DIR/mipmap-xhdpi"
140-
convert $DEST -resize 50% $RES_DIR/mipmap-xhdpi/$DEST_FILE_NAME
102+
XXHDPI_DIR="$RES_DIR/mipmap-xxhdpi"
103+
mkdir -p "$XXHDPI_DIR"
141104
checkResult $?;
142-
mkdir -p "$RES_DIR/mipmap-hdpi"
143-
convert $DEST -resize 37.5% $RES_DIR/mipmap-hdpi/$DEST_FILE_NAME
144-
checkResult $?;
145-
mkdir -p "$RES_DIR/mipmap-mdpi"
146-
convert $DEST -resize 25% $RES_DIR/mipmap-mdpi/$DEST_FILE_NAME
105+
XXHDPI_DEST="$XXHDPI_DIR/$DEST_FILE_NAME"
106+
echoDebug " - xxhdpi: $XXHDPI_DEST"
107+
108+
XHDPI_DIR="$RES_DIR/mipmap-xhdpi"
109+
mkdir -p "$XHDPI_DIR"
147110
checkResult $?;
148-
echoDebug "> Converting XXXHDPI to other DPIs... DONE"
111+
XHDPI_DEST="$XHDPI_DIR/$DEST_FILE_NAME"
112+
echoDebug " - xhdpi: $XHDPI_DEST"
149113

150-
rm -f "${COLOR_FILE_XML}";
114+
HDPI_DIR="$RES_DIR/mipmap-hdpi"
115+
mkdir -p "$HDPI_DIR"
151116
checkResult $?;
152-
touch "${COLOR_FILE_XML}";
117+
HDPI_DEST="$HDPI_DIR/$DEST_FILE_NAME"
118+
echoDebug " - hdpi: $HDPI_DEST"
119+
120+
MDPI_DIR="$RES_DIR/mipmap-mdpi"
121+
mkdir -p "$MDPI_DIR"
153122
checkResult $?;
154-
cat >>"${COLOR_FILE_XML}" <<EOL
155-
<?xml version="1.0" encoding="utf-8"?>
156-
<!-- DO NOT EDIT: this file is generated by mtransitapps/commons-android:pub/module-res-mipmap-launcher-icon-adaptive.sh -->
157-
<resources>
158-
<color name="module_app_icon_color">#${COLOR}</color>
159-
</resources>
160-
EOL
161-
162-
if [[ ${DEBUGING} = true ]]; then
163-
echoDebug "---------------------------------------------------------------------------------------------------------------"
164-
cat "${COLOR_FILE_XML}"; #DEBUG
165-
echoDebug "---------------------------------------------------------------------------------------------------------------"
123+
MDPI_DEST="$MDPI_DIR/$DEST_FILE_NAME"
124+
echoDebug " - mdpi: $MDPI_DEST"
125+
126+
if [ -f "$XXXHDPI_DEST" ]; then
127+
if [[ ${MT_GENERATE_IMAGES} == true ]]; then
128+
echo ">> File '$XXXHDPI_DEST' already exist: overriding image... (MT_GENERATE_IMAGES=$MT_GENERATE_IMAGES)";
129+
rm -f "$XXXHDPI_DEST";
130+
checkResult $?;
131+
else
132+
echo ">> File '$XXXHDPI_DEST' already exist."; # compat with existing mipmap-xxxhdpi/module_app_icon_foreground.png
133+
fi
134+
fi
135+
if [ ! -f "$XXXHDPI_DEST" ]; then
136+
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
137+
requireCommand "convert" "imagemagick";
138+
echoDebug "> Converting SVG to XXXHDPI PNG..."
139+
convert \
140+
-background none \
141+
"$SOURCE" \
142+
-gravity center \
143+
-scale 348x348 \
144+
-extent 432x432 \
145+
"$XXXHDPI_DEST";
146+
RESULT=$?
147+
if [[ ${RESULT} -ne 0 ]]; then
148+
echo "> Error converting SVG to PNG!"
149+
exit ${RESULT}
150+
fi
151+
echoDebug "> Converting SVG to XXXHDPI PNG... DONE"
166152
fi
167153

168-
rm -f "${FILE_XML}";
169-
checkResult $?;
170-
touch "${FILE_XML}";
171-
checkResult $?;
172-
cat >>"${FILE_XML}" <<EOL
173-
<?xml version="1.0" encoding="utf-8"?>
174-
<!-- DO NOT EDIT: this file is generated by mtransitapps/commons-android:pub/module-res-mipmap-launcher-icon-adaptive.sh -->
175-
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
176-
<background android:drawable="@color/module_app_icon_color" />
177-
<foreground android:drawable="@mipmap/module_app_icon_foreground" />
178-
<monochrome android:drawable="@mipmap/ic_launcher_monochrome" />
179-
</adaptive-icon>
180-
EOL
181-
182-
if [[ ${DEBUGING} = true ]]; then
183-
echoDebug "---------------------------------------------------------------------------------------------------------------"
184-
cat "${FILE_XML}"; #DEBUG
185-
echoDebug "---------------------------------------------------------------------------------------------------------------"
154+
if [ -f "$XXHDPI_DEST" ]; then
155+
if [[ ${MT_GENERATE_IMAGES} == true ]]; then
156+
echo ">> File '$XXHDPI_DEST' already exist: overriding image... (MT_GENERATE_IMAGES=$MT_GENERATE_IMAGES)";
157+
rm -f "$XXHDPI_DEST";
158+
checkResult $?;
159+
else
160+
echo ">> File '$XXHDPI_DEST' already exist."; # compat with existing mipmap-xxhdpi/module_app_icon_foreground.png
161+
fi
162+
fi
163+
if [ ! -f "$XXHDPI_DEST" ]; then
164+
echoDebug "> Converting XXXHDPI to XXHDPI..."
165+
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
166+
requireCommand "convert" "imagemagick";
167+
convert $XXXHDPI_DEST -resize 75% $XXHDPI_DEST
168+
checkResult $?;
169+
echoDebug "> Converting XXXHDPI to XXHDPI... DONE"
170+
fi
171+
172+
if [ -f "$XHDPI_DEST" ]; then
173+
if [[ ${MT_GENERATE_IMAGES} == true ]]; then
174+
echo ">> File '$XHDPI_DEST' already exist: overriding image... (MT_GENERATE_IMAGES=$MT_GENERATE_IMAGES)";
175+
rm -f "$XHDPI_DEST";
176+
checkResult $?;
177+
else
178+
echo ">> File '$XHDPI_DEST' already exist."; # compat with existing mipmap-xhdpi/module_app_icon_foreground.png
179+
fi
180+
fi
181+
if [ ! -f "$XHDPI_DEST" ]; then
182+
echoDebug "> Converting XXXHDPI to XHDPI..."
183+
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
184+
requireCommand "convert" "imagemagick";
185+
convert $XXXHDPI_DEST -resize 50% $XHDPI_DEST
186+
checkResult $?;
187+
echoDebug "> Converting XXXHDPI to XHDPI... DONE"
188+
fi
189+
190+
if [ -f "$HDPI_DEST" ]; then
191+
if [[ ${MT_GENERATE_IMAGES} == true ]]; then
192+
echo ">> File '$HDPI_DEST' already exist: overriding image... (MT_GENERATE_IMAGES=$MT_GENERATE_IMAGES)";
193+
rm -f "$HDPI_DEST";
194+
checkResult $?;
195+
else
196+
echo ">> File '$HDPI_DEST' already exist."; # compat with existing mipmap-hdpi/module_app_icon_foreground.png
197+
fi
198+
fi
199+
if [ ! -f "$HDPI_DEST" ]; then
200+
echoDebug "> Converting XXXHDPI to HDPI..."
201+
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
202+
requireCommand "convert" "imagemagick";
203+
convert $XXXHDPI_DEST -resize 37.5% $HDPI_DEST
204+
checkResult $?;
205+
echoDebug "> Converting XXXHDPI to HDPI... DONE"
186206
fi
187207

208+
if [ -f "$MDPI_DEST" ]; then
209+
if [[ ${MT_GENERATE_IMAGES} == true ]]; then
210+
echo ">> File '$MDPI_DEST' already exist: overriding image... (MT_GENERATE_IMAGES=$MT_GENERATE_IMAGES)";
211+
rm -f "$MDPI_DEST";
212+
checkResult $?;
213+
else
214+
echo ">> File '$MDPI_DEST' already exist."; # compat with existing mipmap-mdpi/module_app_icon_foreground.png
215+
fi
216+
fi
217+
if [ ! -f "$MDPI_DEST" ]; then
218+
echoDebug "> Converting XXXHDPI to MDPI..."
219+
requireCommand "inkscape"; # used by imagemagick to convert SVG properly
220+
requireCommand "convert" "imagemagick";
221+
convert $XXXHDPI_DEST -resize 25% $MDPI_DEST
222+
checkResult $?;
223+
echoDebug "> Converting XXXHDPI to MDPI... DONE"
224+
fi
188225

189226
echo -e "\n>> Creating Module Adaptive Launcher Icon... DONE";

0 commit comments

Comments
 (0)