class IconBanner::IcLauncher

Constants

BASE_ICON_PATH
PLATFORM
PLATFORM_CODE

Public Instance Methods

append_parent_dirname(path, dir, suffix) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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)

  # Start by computing the text
  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

  # Then restart the image and apply the banner
  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) click to toggle source
# File lib/icon_banner/ic_launcher.rb, line 97
def should_ignore_icon(icon)
  icon[/\/build\//] || icon[/\/generated\//] || icon[/#{BACKUP_EXTENSION}/]
end