Module: HighFive::AndroidHelper

Included in:
Thor::Tasks::Android, Thor::Tasks::Dist
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
23
24
25
26
27
28
29
30
31
32
# File 'lib/high_five/android_helper.rb', line 12

def android_manifest_path
  if options[:platform_path]
    platform_path = File.join(options[:platform_path], "AndroidManifest.xml")
    return platform_path if File.exists?(platform_path)
  end

  platform_config = base_config.build_platform_config(:android)
  if options[:environment]
    platform_config = platform_config.build_platform_config(options[:environment])
  end
  return platform_config.android_manifest if platform_config.android_manifest

  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



44
45
46
# File 'lib/high_five/android_helper.rb', line 44

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

#res_mapObject



34
35
36
37
38
39
40
41
42
# File 'lib/high_five/android_helper.rb', line 34

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



50
51
52
53
54
55
56
57
58
# File 'lib/high_five/android_helper.rb', line 50

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