Class: IconBanner::IcLauncher
Constant Summary
collapse
- BASE_ICON_PATH =
'/**/ic_launcher*.png'
- PLATFORM =
'Android (Legacy)'
- PLATFORM_CODE =
'android'
Constants inherited
from Process
Process::BACKUP_EXTENSION
Instance Method Summary
collapse
Methods inherited from Process
#create_backup, #find_base_color, #generate, #get_app_icons, #process_icon, #restore, #restore_backup, #validate_platform
Instance Method Details
#append_parent_dirname(path, dir, suffix) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/icon_banner/ic_launcher.rb', line 88
def append_parent_dirname(path, dir, suffix)
segments = path.split(File::SEPARATOR)
dir_index = segments.index(dir)
return path unless dir_index && dir_index - 1 >= 0
parent_segment = segments[dir_index-1]
path.gsub("/#{parent_segment}/","/#{parent_segment}#{suffix}/")
end
|
#backup_path(path) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/icon_banner/ic_launcher.rb', line 77
def backup_path(path)
ext = File.extname path
backup_path = path
backup_path = append_parent_dirname(path, 'res', BACKUP_EXTENSION) if path.include?('/res/')
backup_path = path.gsub('/src/', "/src#{BACKUP_EXTENSION}/") if path == backup_path
backup_path = path.gsub('/app/', "/src#{BACKUP_EXTENSION}/") if path == backup_path
backup_path = path.gsub('/android/', "/src#{BACKUP_EXTENSION}/") if path == backup_path
backup_path = path.gsub(ext, BACKUP_EXTENSION + ext) if path == backup_path
backup_path
end
|
#generate_banner(path, label, color, font) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/icon_banner/ic_launcher.rb', line 12
def generate_banner(path, label, color, font)
size = 1024
font_size = 140 - ([label.length - 12, 0].max * 12)
MiniMagick::Tool::Convert.new do |convert|
convert.size '1024x1024'
convert << 'xc:transparent'
convert << path
end
banner = MiniMagick::Image.new path
banner.combine_options do |combine|
combine.font font
combine.fill color
combine.gravity 'Center'
combine.pointsize font_size
combine.draw "text 0,0 \"#{label}\""
combine.trim
end
margin = 20
padding = 60
radius = 25
width = banner.width + padding * 2
height = 262
MiniMagick::Tool::Convert.new do |convert|
convert.size "#{size}x#{size}"
convert << 'xc:transparent'
convert << path
end
banner = MiniMagick::Image.new path
x_start = size - margin * 2 - width
x_end = size - margin
y_start = size - margin - height
y_end = size - margin
polygon = "roundRectangle #{x_start},#{y_start} #{x_end},#{y_end} #{radius},#{radius}"
banner.combine_options do |combine|
combine.fill 'rgba(0,0,0,0.25)'
combine.draw polygon
combine.blur '0x10'
end
banner.combine_options do |combine|
combine.fill 'white'
combine.draw polygon
end
x_middle = x_start + (x_end - x_start) / 2
y_middle = y_start + (y_end - y_start) / 2
banner.combine_options do |combine|
combine.font font
combine.fill color
combine.gravity 'Center'
combine.pointsize font_size
combine.draw "text #{x_middle - size / 2},#{y_middle - size / 2} \"#{label}\""
end
end
|
#should_ignore_icon(icon) ⇒ Object
97
98
99
|
# File 'lib/icon_banner/ic_launcher.rb', line 97
def should_ignore_icon(icon)
icon[/\/build\//] || icon[/\/generated\//] || icon[/#{BACKUP_EXTENSION}/]
end
|