From b402efd1f70a84c363b511896add5473a82cd2c5 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 3 Mar 2011 18:15:12 -0800 Subject: [PATCH] First pass at extracting icon width/height info and assigning to proper resolution dirs (i.e. ldpi, mdpi, hdpi) during build. --- lib/classic.rb | 10 ++++++++-- lib/create.rb | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/classic.rb b/lib/classic.rb index 901129e8..b8317f83 100755 --- a/lib/classic.rb +++ b/lib/classic.rb @@ -22,6 +22,12 @@ class Classic @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 @@ class Classic 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") diff --git a/lib/create.rb b/lib/create.rb index 75925372..fe68806c 100644 --- a/lib/create.rb +++ b/lib/create.rb @@ -41,15 +41,27 @@ class Create < Classic 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 @@ class Create < Classic @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