-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgather_search_fragments.sh
executable file
·61 lines (51 loc) · 2.3 KB
/
gather_search_fragments.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
my_dir="$(dirname "$(realpath "$0")")"
fragment_outfile="$1"
manifest_outfile="$2"
disclaimer="/* Do not touch! Auto-generated by $(basename $0)*/"
# Matches SettingsActivity.AE_FRAGMENT_ACTION_PREFIX
intent_action_prefix="com.aicp.extras.fragmentaction"
get_xml_root_string() {
file="$1"
attr="$2"
output="$(echo -e setns android=http://schemas.android.com/apk/res/android \\n cat /PreferenceScreen/@$attr | xmllint "$file" --shell)"
content="$(echo "$output" | grep "$attr=")"
if [ $? = 0 ]; then
echo "$content" | sed "s/.*$attr=//" | sed 's/"//g'
fi
}
string_ref_xml_to_java() {
echo "$1" | sed 's|@string/|R.string.|'
}
components=""
actions=""
for fragment in "$my_dir/src/com/aicp/extras/fragments/"*; do
fragment_short="$(basename "$fragment" .java)"
fragment_full="com.aicp.extras.fragments.$fragment_short"
# Get xml resource
xmlres="$(grep -A1 getPreferenceResource "$fragment" | grep return | sed 's/.* //' | sed 's/;//')"
if echo "$xmlres" | grep -q "R.xml."; then
xmlfile="$my_dir/res/xml/$(echo "$xmlres" | sed 's/R.xml.//').xml"
#cat "$fragment" | tr '\n' '\r' | sed 's/getPreferenceResource()
title="$(get_xml_root_string $xmlfile android:title)"
summary="$(get_xml_root_string $xmlfile android:summary)"
if [ -z "$title" ]; then
>&2 echo "Could not find title in $xmlfile"
else
key="$(get_xml_root_string $xmlfile android:key)"
title="$(string_ref_xml_to_java "$title")"
if [ -z "$summary" ]; then
summary=0
else
summary="$(string_ref_xml_to_java "$summary")"
fi
echo "Adding $fragment_short to searchables"
components="$components\n new AeFragmentInfo(\"$fragment_full\", \"$key\", $title, $summary, $xmlres),"
actions="$actions\n <action android:name=\"$intent_action_prefix.$fragment_full\" />"
fi
else
>&2 echo "Could not find xml resource for $fragment_full"
fi
done
cat "$my_dir/AeFragmentList.java" | sed "s|/\\* xx0xx \\*/|$disclaimer|" | sed "s|/\\* xx1xx \\*/|$components|" > "$fragment_outfile"
cat "$my_dir/AndroidManifest.xml" | sed "s|<!-- xx1xx -->|<!-- automated content: -->$actions|" > "$manifest_outfile"