Class: Android::Layout
- Inherits:
-
Object
- Object
- Android::Layout
- Defined in:
- lib/android/layout.rb
Instance Attribute Summary collapse
-
#doc ⇒ REXML::Document
readonly
Xml document object.
-
#path ⇒ String
readonly
Layout file path.
Class Method Summary collapse
-
.collect_layouts(apk) ⇒ Hash
{ path => Layout }.
Instance Method Summary collapse
-
#initialize(data, path = nil) ⇒ Layout
constructor
A new instance of Layout.
-
#to_xml(indent = 4) ⇒ String
Xml string.
Constructor Details
#initialize(data, path = nil) ⇒ Layout
Returns a new instance of Layout.
30 31 32 33 34 |
# File 'lib/android/layout.rb', line 30 def initialize(data, path=nil) @data = data @path = path @doc = AXMLParser.new(data).parse end |
Instance Attribute Details
#doc ⇒ REXML::Document (readonly)
Returns xml document object.
28 29 30 |
# File 'lib/android/layout.rb', line 28 def doc @doc end |
#path ⇒ String (readonly)
Returns layout file path.
26 27 28 |
# File 'lib/android/layout.rb', line 26 def path @path end |
Class Method Details
.collect_layouts(apk) ⇒ Hash
Returns { path => Layout }.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/android/layout.rb', line 9 def self.collect_layouts(apk) targets = apk.find {|name, data| name =~ /^res\/layout\/*/ } ret = {} targets.each do |path| data = apk.file(path) data.force_encoding(Encoding::ASCII_8BIT) ret[path] = nil begin ret[path] = Layout.new(data, path) if AXMLParser.axml?(data) rescue => e $stderr.puts e end end ret end |
Instance Method Details
#to_xml(indent = 4) ⇒ String
Returns xml string.
37 38 39 40 41 42 |
# File 'lib/android/layout.rb', line 37 def to_xml(indent=4) xml = ''.dup formatter = REXML::Formatters::Pretty.new(indent) formatter.write(@doc.root, xml) xml end |