Class: DroidProj::Android::Resources
- Inherits:
-
Object
- Object
- DroidProj::Android::Resources
- Defined in:
- lib/droidproj/res.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#drawables ⇒ Object
Returns the value of attribute drawables.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#drawable(name, &block) ⇒ Object
Public: DSL for creating new drawables in the resources.
-
#filesystem_hash ⇒ Object
Public: A Hash representing how the resources should be created in the filesytem.
-
#initialize ⇒ Resources
constructor
A new instance of Resources.
Constructor Details
#initialize ⇒ Resources
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
#app ⇒ Object
Returns the value of attribute app.
32 33 34 |
# File 'lib/droidproj/res.rb', line 32 def app @app end |
#drawables ⇒ Object
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_hash ⇒ Object
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 |