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.



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

#docREXML::Document (readonly)

Returns xml document object.

Returns:

  • (REXML::Document)

    xml document object



28
29
30
# File 'lib/android/layout.rb', line 28

def doc
  @doc
end

#pathString (readonly)

Returns layout file path.

Returns:

  • (String)

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

Returns:

  • (Hash)

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

Returns:

  • (String)

    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