Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add launcher adaptive icon generation #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions lib/fastlane/plugin/appicon/actions/android_appicon_action.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# frozen_string_literal: true

require 'mini_magick'

module Fastlane
module Actions
class AndroidAppiconAction < Action

def self.needed_icons
{
launcher: {
Expand All @@ -14,13 +15,21 @@ def self.needed_icons
:xxhdpi => ['144x144'],
:xxxhdpi => ['192x192']
},
launcher_adaptive: {
:ldpi => ['81x81'],
:mdpi => ['108x108'],
:hdpi => ['162x162'],
:xhdpi => ['216x216'],
:xxhdpi => ['324x324'],
:xxxhdpi => ['432x432']
},
notification: {
:ldpi => ['18x18'],
:mdpi => ['24x24'],
:hdpi => ['36x36'],
:xhdpi => ['48x48'],
:xxhdpi => ['72x72'],
:xxxhdpi => ['96x96'],
:xxxhdpi => ['96x96']
},
splash_land: {
'land-ldpi' => ['320x200'],
Expand All @@ -42,7 +51,6 @@ def self.needed_icons
end

def self.run(params)

Helper::AppiconHelper.set_cli(params[:minimagick_cli])

fname = params[:appicon_image_file]
Expand All @@ -55,7 +63,7 @@ def self.run(params)
Helper::AppiconHelper.check_input_image_size(image, 1024, 1024)

# Custom icons will have basepath and filename already defined
if icon.has_key?('basepath') && icon.has_key?('filename')
if icon.key?('basepath') && icon.key?('filename')
basepath = Pathname.new(icon['basepath'])
filename = icon['filename']
else
Expand All @@ -72,11 +80,11 @@ def self.run(params)

unless width == height
offset =
if width > height
"+0+#{(width - height) / 2}"
elsif height > width
"+#{(height - width) / 2}+0"
end
if width > height
"+0+#{(width - height) / 2}"
elsif height > width
"+#{(height - width) / 2}+0"
end

image.crop "#{icon['size']}#{offset}"
end
Expand All @@ -85,18 +93,18 @@ def self.run(params)
image.write basepath + filename

if basepath.to_s.match("port-")
default_portrait_path = basepath.to_s.gsub("port-","")
default_portrait_path = basepath.to_s.gsub("port-", "")
FileUtils.mkdir_p(default_portrait_path)
image.write default_portrait_path + '/' + filename
end

if params[:generate_rounded]
rounded_image = MiniMagick::Image.open(fname)
rounded_image.format 'png'
rounded_image.resize "#{width}x#{height}"
rounded_image = round(rounded_image)
rounded_image.write basepath + filename.gsub('.png', '_round.png')
end
next unless params[:generate_rounded]

rounded_image = MiniMagick::Image.open(fname)
rounded_image.format 'png'
rounded_image.resize "#{width}x#{height}"
rounded_image = round(rounded_image)
rounded_image.write basepath + filename.gsub('.png', '_round.png')
end

UI.success("Successfully stored launcher icons at '#{params[:appicon_path]}'")
Expand All @@ -106,8 +114,8 @@ def self.round(img)
require 'mini_magick'
img.format 'png'

width = img[:width]-2
radius = width/2
width = img[:width] - 2
radius = width / 2

mask = ::MiniMagick::Image.open img.path
mask.format 'png'
Expand All @@ -116,7 +124,7 @@ def self.round(img)
m.alpha 'transparent'
m.background 'none'
m.fill 'white'
m.draw 'roundrectangle 1,1,%s,%s,%s,%s' % [width, width, radius, radius]
m.draw format('roundrectangle 1,1,%s,%s,%s,%s', width, width, radius, radius)
end

masked = img.composite(mask, 'png') do |i|
Expand All @@ -127,9 +135,7 @@ def self.round(img)
return masked
end

def self.get_custom_sizes(image, custom_sizes)

end
def self.get_custom_sizes(image, custom_sizes); end

def self.description
"Generate required icon sizes from a master application icon"
Expand Down Expand Up @@ -179,9 +185,9 @@ def self.available_options
optional: true,
type: String,
verify_block: proc do |value|
av = %w(graphicsmagick imagemagick)
UI.user_error!("Unsupported minimagick cli '#{value}', must be: #{av}") unless av.include?(value)
end)
av = %w[graphicsmagick imagemagick]
UI.user_error!("Unsupported minimagick cli '#{value}', must be: #{av}") unless av.include?(value)
end)
]
end

Expand Down