-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_android_xml_ids
More file actions
executable file
·46 lines (43 loc) · 1.6 KB
/
filter_android_xml_ids
File metadata and controls
executable file
·46 lines (43 loc) · 1.6 KB
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
#!/usr/bin/env gawk -f
#
# Converts all or a portion of a layout file into lines of java
# code that pull those views out with the appropriate class. E.g.
# if you pipe in this section of layout xml:
#
# android:layout_height="fill_parent">
# <RelativeLayout
# android:layout_width="fill_parent"
# android:layout_height="fill_parent"
# >
# <include
# layout="@layout/title_view"
# android:id="@+id/titleArea"
# android:layout_alignParentTop="true"
# />
# <LinearLayout
# android:id="@+id/dosDontsContainer"
# android:orientation="vertical"
#
# ...and there is a title_view.xml in your working directory with R.id.title_view_titleTextView,
# you'll get the following from this script:
#
# TextView titleTextView = (TextView)v.findViewById(R.id.title_view_titleTextView);
# View titleArea = (View)v.findViewById(R.id.titleArea);
# LinearLayout dosDontsContainer = (LinearLayout)v.findViewById(R.id.dosDontsContainer);
#
/<[a-zA-Z.]*/ {
tagName = gensub(/^.*<([a-zA-Z.]*\.)?([a-zA-Z]*).*/, "\\2", $0);
}
/android:id=\"@\+id\// {
rawId = gensub(/^.*:id=\"@\+id\/([a-zA-Z0-9_]*)\".*/, "\\1", "", $0);
fieldName = gensub(/^.*_/, "", "", rawId);
if (tagName == "include") {
tagName = "View";
}
print tagName " " fieldName " = (" tagName ")v.findViewById(R.id." rawId ");"
}
/layout=\"@layout\/[a-z_]+"/ {
layoutFile = gensub(/^.*layout=\"@layout\/([a-zA-Z0-9_]*)\".*/, "\\1", "", $0) ".xml";
# assumes that the layout file is in this same folder. because seriously.
system("cat " layoutFile " | filter_android_xml_ids");
}