Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First pass at extracting icon width/height info and assigning to prop…

…er resolution dirs (i.e. ldpi, mdpi, hdpi) during build.
  • Loading branch information...
commit b402efd1f70a84c363b511896add5473a82cd2c5 1 parent 0c3a8fb
@filmaj filmaj authored
Showing with 24 additions and 5 deletions.
  1. +8 −2 lib/classic.rb
  2. +16 −3 lib/create.rb
View
10 lib/classic.rb
@@ -22,6 +22,12 @@ def setup
@android_dir = File.expand_path(File.dirname(__FILE__).gsub(/lib$/,''))
@framework_dir = File.join(@android_dir, "framework")
@icon = File.join(@www, 'icon.png') unless File.exists?(@icon)
+ # Hash that stores the location of icons for each resolution type. Uses the default icon for all resolutions as a baseline.
+ @icons = {
+ "drawable-ldpi" => @icon,
+ "drawable-mdpi" => @icon,
+ "drawable-hdpi" => @icon
+ } if @icons.is_nil?
@app_js_dir = ''
@content = 'index.html'
end
@@ -98,10 +104,10 @@ def copy_libs
end
# icon file copy
# if it is not in the www directory use the default one in the src dir
- @icon = File.join(framework_res_dir, "drawable", "icon.png") unless File.exists?(@icon)
%w(drawable-hdpi drawable-ldpi drawable-mdpi).each do |e|
+ currentIcon = (File.exists?(@icons[e])) ? @icons[e] : File.join(framework_res_dir, "drawable", "icon.png")
FileUtils.mkdir_p(File.join(app_res_dir, e))
- FileUtils.cp(@icon, File.join(app_res_dir, e, "icon.png"))
+ FileUtils.cp(currentIcon, File.join(app_res_dir, e, "icon.png"))
end
# concat JS and put into www folder. this can be overridden in the config.xml via @app_js_dir
js_dir = File.join(@framework_dir, "assets", "js")
View
19 lib/create.rb
@@ -41,15 +41,27 @@ def read_config
require 'rexml/document'
f = File.new config_file
doc = REXML::Document.new(f)
- @config = {}
+ @config = {}
@config[:id] = doc.root.attributes["id"]
@config[:version] = doc.root.attributes["version"]
+ @config[:icons] = {}
doc.root.elements.each do |n|
@config[:name] = n.text.gsub('-','').gsub(' ','') if n.name == 'name'
@config[:description] = n.text if n.name == 'description'
- @config[:icon] = n.attributes["src"] if n.name == 'icon'
- @config[:content] = n.attributes["src"] if n.name == 'content'
+ @config[:content] = n.attributes["src"] if n.name == 'content'
+ if n.name == 'icon'
+ if n.attributes["width"] == '72' && n.attributes["height"] == '72'
+ @config[:icons]["drawable-hdpi".to_sym] = n.attributes["src"]
+ elsif n.attributes["width"] == '48' && n.attributes["height"] == '48'
+ @config[:icons]["drawable-mdpi".to_sym] = n.attributes["src"]
+ elsif n.attributes["width"] == '36' && n.attributes["height"] == '36'
+ @config[:icons]["drawable-ldpi".to_sym] = n.attributes["src"]
+ else
+ @config[:icon] = n.attributes["src"]
+ end
+ end
+
if n.name == "preference" && n.attributes["name"] == 'javascript_folder'
@config[:js_dir] = n.attributes["value"]
@@ -63,6 +75,7 @@ def read_config
@name = @config[:name] if @config[:name]
# set the icon from the config
@icon = File.join(@www, @config[:icon]) if @config[:icon]
+ @icons = @config[:icons] if @config[:icons].length > 0
# sets the app js dir where phonegap.js gets copied
@app_js_dir = @config[:js_dir] ? @config[:js_dir] : ''
# sets the start page
Please sign in to comment.
Something went wrong with that request. Please try again.