Class: DroidProj::Android::DrawableState

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDrawableState

Returns a new instance of DrawableState.



15
16
17
# File 'lib/droidproj/drawable_state.rb', line 15

def initialize
  @state = {}
end

Instance Attribute Details

#drawableObject

Android::Drawable instance this state is for



13
14
15
# File 'lib/droidproj/drawable_state.rb', line 13

def drawable
  @drawable
end

#file_pathObject

String original path of the image file



11
12
13
# File 'lib/droidproj/drawable_state.rb', line 11

def file_path
  @file_path
end

#sizeObject

Symbol for what size folder this goes into



9
10
11
# File 'lib/droidproj/drawable_state.rb', line 9

def size
  @size
end

#stateObject

Hash of options which define what android:state this is for



7
8
9
# File 'lib/droidproj/drawable_state.rb', line 7

def state
  @state
end

Instance Method Details

#final_drawable_nameObject



32
33
34
35
36
37
38
# File 'lib/droidproj/drawable_state.rb', line 32

def final_drawable_name
  final_file_name = DroidProj::Android::Drawable::FINAL_FILE_PREFIX + self.drawable.name
  self.state.each do |state, value|
    final_file_name << "_#{state}_#{value}"
  end
  final_file_name
end

#final_extensionObject



40
41
42
43
# File 'lib/droidproj/drawable_state.rb', line 40

def final_extension
  file_name = Pathname.new(self.file_path).basename
  file_name.to_s.split('.')[1..-1].join('.')
end

#final_file_nameObject



28
29
30
# File 'lib/droidproj/drawable_state.rb', line 28

def final_file_name
  final_drawable_name + "." + final_extension
end

#xml_stringObject



19
20
21
22
23
24
25
26
# File 'lib/droidproj/drawable_state.rb', line 19

def xml_string
  str = "<item "
  self.state.each do |state, value|
    str << "android:state_#{state}=\"#{value}\" "
  end

  str << "android:drawable=\"@drawable/#{final_drawable_name}\" />"
end