Class: Android::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/android/layout.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#docREXML::Document (readonly)

Returns xml document object.

Returns:

  • (REXML::Document)

    xml document object



26
27
28
# File 'lib/android/layout.rb', line 26

def doc
  @doc
end

#pathString (readonly)

Returns layout file path.

Returns:

  • (String)

    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 }.

Returns:

  • (Hash)

    { 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.

Returns:

  • (String)

    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