Class: DroidProj::Android::Resources

Inherits:
Object
  • Object
show all
Defined in:
lib/droidproj/res.rb

Defined Under Namespace

Classes: MoveOp, WriteOp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResources

Returns a new instance of Resources.



35
36
37
# File 'lib/droidproj/res.rb', line 35

def initialize
  @drawables = ResourcesDrawables.new
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



32
33
34
# File 'lib/droidproj/res.rb', line 32

def app
  @app
end

#drawablesObject

Returns the value of attribute drawables.



33
34
35
# File 'lib/droidproj/res.rb', line 33

def drawables
  @drawables
end

Instance Method Details

#[](key) ⇒ Object



71
72
73
# File 'lib/droidproj/res.rb', line 71

def [](key)
  self.drawables[key]
end

#drawable(name, &block) ⇒ Object

Public: DSL for creating new drawables in the resources

name - The String name of the drawable; this is what will be referred to

in your Java code

&block - A DSL block where you can setup aspects of the drawable

Examples

res.drawable 'my_image' do
  hdpi 'some_file.png', state_enabled: false
end
# => #<Android::Drawable>
res.drawable 'my_image' do |drawable|
  drawable.hdpi 'some_file.png', state_enabled: false
end
# => #<Android::Drawable>

Returns the new Android::Drawable instance



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/droidproj/res.rb', line 57

def drawable(name, &block)
  drawable = DroidProj::Android::Drawable.new
  drawable.name = name
  @drawables << drawable

  case block.arity
  when 0
    drawable.instance_eval &block
  when 1
    block.call(drawable)
  end
  drawable
end

#filesystem_hashObject

Public: A Hash representing how the resources should be created in the

filesytem

Examples

res.filesystem_hash
# => {drawable: ["drawable.xml"], drawable-hdpi: ["drawable.png"]}

Returns the Hash



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/droidproj/res.rb', line 84

def filesystem_hash
  hash = {
    drawable: []
  }
  self.drawables.each do |drawable|
    write_op = WriteOp.new
    write_op.at = drawable.name + ".xml"
    write_op.content = drawable.xml_string
    hash[:drawable] << write_op

    drawable.to_size_buckets.each do |size, drawable_states|
      drawable_states.each do |drawable_state|
        folder = (hash["drawable-#{size}".to_sym] ||= [])
        op = MoveOp.new
        op.from = drawable_state.file_path
        op.to = drawable_state.final_file_name
        folder << op
      end
    end
  end

  hash
end