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

added support for launch images for android #56

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions 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 @@ -71,7 +71,14 @@ lane :android do
appicon_image_file: 'spec/fixtures/ThemojiNotification.png',
appicon_icon_types: [:notification],
appicon_path: 'app/res/drawable',
appicon_filename: 'ic_notification'
appicon_filename: 'ic_notification',
generate_rounded: true
)
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
Binary file removed app_rounded/res/mipmap-hdpi/ic_launcher.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-hdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-ldpi/ic_launcher.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-ldpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-mdpi/ic_launcher.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-mdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-xhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-xhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-xxhdpi/ic_launcher.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-xxhdpi/ic_launcher_round.png
Binary file not shown.
Binary file removed app_rounded/res/mipmap-xxxhdpi/ic_launcher.png
Binary file not shown.
Binary file not shown.
14 changes: 8 additions & 6 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ end
lane :android do
android_appicon(
appicon_image_file: 'spec/fixtures/Themoji.png',
appicon_path: 'app/res/mipmap'
appicon_path: 'app/res/mipmap',
generate_rounded: true
)
end

lane :android_rounded do
lane :android_splash do
android_appicon(
appicon_image_file: 'spec/fixtures/Themoji.png',
appicon_path: 'app_rounded/res/mipmap',
generate_rounded: true
)
appicon_image_file: 'spec/fixtures/ThemojiSplash.png',
appicon_icon_types: [:splash_port, :splash_land],
appicon_path: 'app/res/drawable',
appicon_filename: 'splash'
)
end
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,11 +59,34 @@ 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

if params[:generate_rounded]
rounded_image = MiniMagick::Image.open(fname)
rounded_image.format 'png'
Expand Down
Binary file added spec/fixtures/ThemojiSplash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.