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
33
34
35
# File 'lib/high_five/android_helper.rb', line 12

def android_manifest_path
  if options[:platform_path]
    platform_path = Dir[File.join(options[:platform_path], "**/AndroidManifest.xml")][0]
    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
  if platform_config.cordova_path
    destination_dir ||= "#{platform_config.cordova_path}/platforms/android"
  end
  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

#gradle_file_pathObject



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

def gradle_file_path
  if options[:platform_path]
    gradle_path = Dir[File.join(options[:platform_path], "/app/build.gradle")][0]
    return gradle_path if gradle_path && File.exists?(gradle_path)
  end
  return nil
end

#parse_resolution(dir, prefix = "drawable") ⇒ Object



57
58
59
# File 'lib/high_five/android_helper.rb', line 57

def parse_resolution(dir, prefix="drawable")
  dir.gsub(/.*\//, '').gsub("#{prefix}-", '').to_sym
end

#res_mapObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/high_five/android_helper.rb', line 45

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

#valid_directories(drawable_dir, prefix = "drawable") ⇒ Object

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



63
64
65
66
67
68
69
70
71
# File 'lib/high_five/android_helper.rb', line 63

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