Skip to content

Instantly share code, notes, and snippets.

@xiprox
Last active November 4, 2015 13:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiprox/ced872ec357b17bbd3a0 to your computer and use it in GitHub Desktop.
Save xiprox/ced872ec357b17bbd3a0 to your computer and use it in GitHub Desktop.
Android Drawable Animation Configuration Generator – A simple script for easily creating configuration xml files for drawable animations in android
#!/bin/bash
SCRIPT_CONFIGURED=false # CHANGE THIS TO TRUE ONCE YOU MAKE YOUR CHANGES
DRAWABLE_NAME="rocket_animation" # Name of final drawable
FRAME_PREFIX="rocket_animation_" # Prefix in the names of each frame under your res/drawable folder
FRAME_NUMBER=100 # Number of frames the animation has
FRAME_DURATION=200 # Duration of a single frame (in milliseconds)
ONESHOT="false" # Animation plays only once if this is set true
OUT_FILE="$DRAWABLE_NAME.xml"
if [ $SCRIPT_CONFIGURED = false ] ; then
echo ERROR: Please make sure to properly configure the script
fi
if [ ! -e "$OUT_FILE" ] ; then
touch "$OUT_FILE"
fi
if [ ! -w "$OUT_FILE" ] ; then
echo ERROR: Failed to write to $OUT_FILE
exit 1
fi
(cat << EOF) > $OUT_FILE
<!-- File created by Android Drawable Animation Configuration Generator
(https://gist.github.com/xiprox/ced872ec357b17bbd3a0)
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2014 İhsan Işık
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: İhsan Işık (x.ihsan@gmail.com)
-->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="$ONESHOT">
EOF
for ((i = 1; i <= $FRAME_NUMBER; i++));
do
echo " <item android:drawable=\"@drawable/$FRAME_PREFIX$i\" android:duration=\"$FRAME_DURATION\" />" >> $OUT_FILE
done
(cat << EOF) >> $OUT_FILE
</animation-list>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment