Skip to content

Commit

Permalink
Merge pull request #21 from DeployGate/support_weird_adaptive_icon
Browse files Browse the repository at this point in the history
Support weird adaptive icon
  • Loading branch information
jmatsu authored Dec 16, 2019
2 parents 266058f + 14b41ef commit 60e9f0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lib/android_apk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,26 @@ def icon_file(dpi = nil, want_png = false)
icon = dpi ? self.icons[dpi.to_i] : self.icon
return nil if icon.nil? || icon.empty?

# Unfroze just in case
icon = +icon
dpis = dpi_str(dpi)

# neat adaptive icon apk
if want_png && icon.end_with?(".xml")
icon.gsub!(%r{res/(drawable|mipmap)-anydpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png")
end

# 1st fallback is for WEIRD adaptive icon apk e.g. Cordiva generates such apks
if want_png && icon.end_with?(".xml")
dpis = dpi_str(dpi)
icon.gsub! %r{res/(drawable|mipmap)-anydpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png"
icon.gsub!(%r{res/(drawable|mipmap)-.+?dpi-(?:v\d+)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png")
end

# a fallback to a png file which is manually resolved
# 2nd fallback is for vector drawable icon apk. Use a png file which is manually resolved
if want_png && icon.end_with?(".xml")
dpis = dpi_str(dpi)
icon.gsub! %r{res/(drawable|mipmap)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png"
icon.gsub!(%r{res/(drawable|mipmap)/([^/]+)\.xml}, "res/\\1-#{dpis}-v4/\\2.png")
end

# we cannot prepare for any fallbacks but don't return nil for now to keep the behavior
# if want_png && icon.end_with?(".xml")

Dir.mktmpdir do |dir|
output_to = File.join(dir, icon)
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class AndroidApk
VERSION = "0.7.0"
VERSION = "1.1.0"
end

0 comments on commit 60e9f0a

Please sign in to comment.