xwords/xwords4/android/scripts/genPrefsWrapper.sh
Eric House 309fcece03 generate mapping from prefs file to binding to fix reset
I balked at writing code consisting of a bunch of classes there only to
provide a mapping to resource file IDs, instead opting to generate them.
(The right move might have been to generate everything from the old
xwprefs.xml, but it's too late for that. :-)
2021-02-18 15:57:10 -08:00

45 lines
1,001 B
Bash
Executable file

#!/bin/bash
# Generate a java file providing the mapping of class name to xml file
# name that Android's system requires but doesn't provide. I hate
# leaving that sort of thing to chance.
mkClass() {
XMLFILE=$1
NAME=${XMLFILE/.xml/}
cat <<EOF
public static class ${NAME} extends BasePrefsFrag {
@Override
public int getResID() { return R.xml.${NAME}; }
}
EOF
}
cat <<EOF
/******************************************************************
* file generated by $0. Changes will be overwritten!!
******************************************************************/
package org.eehouse.android.xw4.gen;
import org.eehouse.android.xw4.PrefsActivity.BasePrefsFrag;
import org.eehouse.android.xw4.R;
public class PrefsWrappers {
EOF
IDS=""
while [ "$#" -gt 0 ]; do
FILE=$(basename $1)
mkClass $FILE
IDS="${IDS} R.xml.${FILE/.xml/}, "
shift
done
cat <<EOF
private static final int[] sIDS = {$IDS};
public static final int[] getPrefsResIDs() { return sIDS; }
}
EOF