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.
28 29 30 31 32 |
# File 'lib/android/layout.rb', line 28 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.
26 27 28 |
# File 'lib/android/layout.rb', line 26 def doc @doc end |
#path ⇒ String (readonly)
Returns layout file path.
24 25 26 |
# File 'lib/android/layout.rb', line 24 def path @path end |
Class Method Details
.collect_layouts(apk) ⇒ Hash
Returns { path => Layout }.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/android/layout.rb', line 7 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.
35 36 37 38 39 40 |
# File 'lib/android/layout.rb', line 35 def to_xml(indent=4) xml = '' formatter = REXML::Formatters::Pretty.new(indent) formatter.write(@doc.root, xml) xml end |