Module: HighFive::AndroidHelper

Included in:
Thor::Tasks::AndroidTasks, Thor::Tasks::Distribution
Defined in:
lib/high_five/android_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.project_name_from_build_xml(path) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/high_five/android_helper.rb', line 3

def self.project_name_from_build_xml(path)
  File.open(path, 'r', :encoding => 'iso-8859-1').each do |line|
    if line =~ /<project name="(.*)" /
      return $1
    end
  end
  nil
end

Instance Method Details

#android_manifest_pathObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/high_five/android_helper.rb', line 12

def android_manifest_path
  platform_config = base_config.build_platform_config(:android)
  destination_dir = platform_config.destination
  root_dir = destination_dir
  while true
    glob = Dir[File.join(root_dir, "AndroidManifest.xml")]
    return glob.first if (glob.length > 0)
    root_dir = File.expand_path("..", root_dir)
    raise "Couldn't find android manifest near #{destination_dir}" if root_dir == '/'
  end
end

#parse_resolution(dir) ⇒ Object



34
35
36
# File 'lib/high_five/android_helper.rb', line 34

def parse_resolution(dir)
  dir.gsub(/.*\//, '').gsub('drawable-', '').to_sym
end

#res_mapObject



24
25
26
27
28
29
30
31
32
# File 'lib/high_five/android_helper.rb', line 24

def res_map
  {
    ldpi: 36,
    mdpi: 48,
    hdpi: 72,
    xhdpi: 96,
    drawable: 512
  }
end

#valid_directories(drawable_dir) ⇒ Object

drawable_dir: The directory containing drawable/, drawable-hdpi, drawable-mdpi, etc Returns directories which are present & whose resolutions are supported



40
41
42
43
44
45
46
47
48
# File 'lib/high_five/android_helper.rb', line 40

def valid_directories(drawable_dir)
  valid_dirs = []
  Dir.glob(File.join drawable_dir, "drawable*") do |dir|
    res = parse_resolution(dir)
    size = res_map[res]
    valid_dirs << dir unless size.nil?
  end
  valid_dirs
end