Skip to content

Commit

Permalink
Add support for android splash screen images
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-m-sharpe committed Sep 8, 2019
1 parent 275ee6b commit 4be7141
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
lane :test3 do
# `appicon_image_file` defaults to "fastlane/metadata/app_icon.png"
appicon(
appicon_devices: [:iphone],
appicon_devices: [:iphone],
appicon_path: 'wwdcfamily/Images.xcassets' # output path
)
end
Expand All @@ -73,6 +73,12 @@ lane :android do
appicon_path: 'app/res/drawable',
appicon_filename: 'ic_notification'
)
android_appicon(
appicon_image_file: 'spec/fixtures/splash_base_image.png',
appicon_icon_types: [:splash_port, :splash_land],
appicon_path: 'app/res/drawable',
appicon_filename: 'splash'
)
end
```

Expand Down
59 changes: 47 additions & 12 deletions lib/fastlane/plugin/appicon/actions/android_appicon_action.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'mini_magick'

module Fastlane
module Actions
class AndroidAppiconAction < Action

def self.needed_icons
{
launcher: {
Expand All @@ -18,6 +21,22 @@ def self.needed_icons
:xhdpi => ['48x48'],
:xxhdpi => ['72x72'],
:xxxhdpi => ['96x96'],
},
splash_land: {
'land-ldpi' => ['320x200'],
'land-mdpi' => ['480x320'],
'land-hdpi' => ['800x480'],
'land-xhdpi' => ['1280x720'],
'land-xxhdpi' => ['1600x960'],
'land-xxxhdpi' => ['1920x1280']
},
splash_port: {
'port-ldpi' => ['200x320'],
'port-mdpi' => ['320x480'],
'port-hdpi' => ['480x800'],
'port-xhdpi' => ['720x1280'],
'port-xxhdpi' => ['960x1600'],
'port-xxxhdpi' => ['1280x1920']
}
}
end
Expand All @@ -26,18 +45,11 @@ def self.run(params)
fname = params[:appicon_image_file]
custom_sizes = params[:appicon_custom_sizes]

require 'mini_magick'
image = MiniMagick::Image.open(fname)

Helper::AppiconHelper.check_input_image_size(image, 512)

# Convert image to png
image.format 'png'

icons = Helper::AppiconHelper.get_needed_icons(params[:appicon_icon_types], self.needed_icons, true, custom_sizes)
icons.each do |icon|
width = icon['width']
height = icon['height']
image = MiniMagick::Image.open(fname)

Helper::AppiconHelper.check_input_image_size(image, 1024)

# Custom icons will have basepath and filename already defined
if icon.has_key?('basepath') && icon.has_key?('filename')
Expand All @@ -47,10 +59,33 @@ def self.run(params)
basepath = Pathname.new("#{params[:appicon_path]}-#{icon['scale']}")
filename = "#{params[:appicon_filename]}.png"
end
FileUtils.mkdir_p(basepath)

image.resize "#{width}x#{height}"
width_height = [icon['width'], icon['height']].map(&:to_i)
width, height = width_height
max = width_height.max

image.format 'png'
image.resize "#{max}x#{max}"

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

image.crop "#{icon['size']}#{offset}"
end

FileUtils.mkdir_p(basepath)
image.write basepath + filename

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

UI.success("Successfully stored launcher icons at '#{params[:appicon_path]}'")
Expand Down

0 comments on commit 4be7141

Please sign in to comment.