You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/10/27 23:05:33 UTC

[4/4] git commit: Some more amazon-fireos related changes.

Some more amazon-fireos related changes.


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/e6f8dc7c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/e6f8dc7c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/e6f8dc7c

Branch: refs/heads/master
Commit: e6f8dc7c573c65e2f1ebdf8e42476698958003af
Parents: 94fa4f3
Author: Archana Naik <na...@lab126.com>
Authored: Mon Oct 27 15:05:10 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Oct 27 15:05:10 2014 -0700

----------------------------------------------------------------------
 .../cordova/metadata/amazon_fireos_parser.js    | 237 ++++++++++---------
 1 file changed, 120 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/e6f8dc7c/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js b/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
index 50f0957..269e719 100644
--- a/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
+++ b/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
@@ -74,136 +74,130 @@ module.exports.prototype = {
     
     // remove the default resource name from all drawable folders
     // return the array of the densities in this project
-deleteDefaultResource:function(name) {
-    var densities = [];
-    var res = path.join(this.path, 'res');
-    var dirs = fs.readdirSync(res);
-    
-    for (var i=0; i<dirs.length; i++) {
-        var filename = dirs[i];
-        if (filename.indexOf('drawable-') === 0) {
-            var density = filename.substr(9);
-            densities.push(density);
-            var template = path.join(res, filename, name);
-            try {
-                fs.unlinkSync(template);
-                events.emit('verbose', 'deleted: ' + template);
-            } catch(e) {
-                // ignored. template screen does probably not exist
-            }
-        }
-    }
-    return densities;
-},
-    
-handleSplashes:function(config) {
-    var resources = config.getSplashScreens('android');
-    var destfilepath;
-    // if there are "splash" elements in config.xml
-    if (resources.length > 0) {
-        var densities = this.deleteDefaultResource('screen.png');
-        events.emit('verbose', 'splash screens: ' + JSON.stringify(resources));
+    deleteDefaultResource:function (name) {
+        var densities = [];
         var res = path.join(this.path, 'res');
-        
-        if (resources.defaultResource) {
-            destfilepath = path.join(res, 'drawable', 'screen.png');
-            events.emit('verbose', 'copying splash icon from ' + resources.defaultResource.src + ' to ' + destfilepath);
-            shell.cp('-f', resources.defaultResource.src, destfilepath);
-        }
-        for (var i=0; i<densities.length; i++) {
-            var density = densities[i];
-            var resource = resources.getByDensity(density);
-            if (resource) {
-                // copy splash screens.
-                destfilepath = path.join(res, 'drawable-' + density, 'screen.png');
-                events.emit('verbose', 'copying splash icon from ' + resource.src + ' to ' + destfilepath);
-                shell.cp('-f', resource.src, destfilepath);
+        var dirs = fs.readdirSync(res);
+
+        for (var i = 0; i < dirs.length; i++) {
+            var filename = dirs[i];
+            if (filename.indexOf('drawable-') === 0) {
+                var density = filename.substr(9);
+                densities.push(density);
+                var template = path.join(res, filename, name);
+                try {
+                    fs.unlinkSync(template);
+                    events.emit('verbose', 'deleted: ' + template);
+                } catch (e) {
+                    // ignored. template screen does probably not exist
+                }
             }
         }
-    }
-},
-    
-handleIcons: function(config) {
-    var icons = config.getIcons('android');
-    // if there are icon elements in config.xml
-    if (icons.length === 0) {
-        events.emit('verbose', 'This app does not have launcher icons defined');
-        return;
-    }
-    
-    var densities = this.deleteDefaultResource('icon.png');
-    
-    var android_icons = {};
-    var default_icon;
-    // http://developer.android.com/design/style/iconography.html
-    var densityToSizeMap = {
-        'ldpi' : 36,
-        'mdpi' : 48,
-        'hdpi' : 72,
-        'xhdpi' : 96
-    };
-    // find the best matching icon for a given density or size
-    // @output android_icons
-    var parseIcon = function(icon, icon_size, size, density) {
-        // do I have a platform icon for that density already
-        var previous = android_icons[density];
-        if (previous && previous.platform) {
-            return;
+        return densities;
+    },
+
+    copyImage: function(src, density, name) {
+        var destFolder = path.join(this.path, 'res', (density ? 'drawable-': 'drawable') + density);
+        var destFilePath = path.join(destFolder, name);
+
+        // default template does not have default asset for this density
+        if (!fs.existsSync(destFolder)) {
+            fs.mkdirSync(destFolder);
         }
-        // already have one but this one is a platform icon
-        if (previous && icon.platform && icon.density == density) {
-            android_icons[density] = icon;
-            return;
+        events.emit('verbose', 'copying image from ' + src + ' to ' + destFilePath);
+        shell.cp('-f', src, destFilePath);
+    },
+
+    handleSplashes:function (config) {
+        var resources = config.getSplashScreens('android');
+        var destfilepath;
+        // if there are "splash" elements in config.xml
+        if (resources.length > 0) {
+            var densities = this.deleteDefaultResource('screen.png');
+            events.emit('verbose', 'splash screens: ' + JSON.stringify(resources));
+            var res = path.join(this.path, 'res');
+
+            if (resources.defaultResource) {
+                destfilepath = path.join(res, 'drawable', 'screen.png');
+                events.emit('verbose', 'copying splash icon from ' + resources.defaultResource.src + ' to ' + destfilepath);
+                shell.cp('-f', resources.defaultResource.src, destfilepath);
+            }
+            for (var i = 0; i < densities.length; i++) {
+                var density = densities[i];
+                var resource = resources.getByDensity(density);
+                if (resource) {
+                    // copy splash screens.
+                    destfilepath = path.join(res, 'drawable-' + density, 'screen.png');
+                    events.emit('verbose', 'copying splash icon from ' + resource.src + ' to ' + destfilepath);
+                    shell.cp('-f', resource.src, destfilepath);
+                }
+            }
         }
-        // if density is explicitly defined take this one
-        if (density === icon.density) {
-            android_icons[density] = icon;
+    },
+
+    handleIcons: function(config) {
+        var icons = config.getIcons('android');
+
+        // if there are icon elements in config.xml
+        if (icons.length === 0) {
+            events.emit('verbose', 'This app does not have launcher icons defined');
             return;
         }
-        if (size === parseInt(icon_size)) {
+
+        this.deleteDefaultResource('icon.png');
+
+        var android_icons = {};
+        var default_icon;
+        // http://developer.android.com/design/style/iconography.html
+        var sizeToDensityMap = {
+            36: 'ldpi',
+            48: 'mdpi',
+            72: 'hdpi',
+            96: 'xhdpi',
+            144: 'xxhdpi',
+            192: 'xxxhdpi'
+        };
+        // find the best matching icon for a given density or size
+        // @output android_icons
+        var parseIcon = function(icon, icon_size) {
+            // do I have a platform icon for that density already
+            var density = icon.density || sizeToDensityMap[icon_size];
+            if (!density) {
+                // invalid icon defition ( or unsupported size)
+                return;
+            }
+            var previous = android_icons[density];
+            if (previous && previous.platform) {
+                return;
+            }
             android_icons[density] = icon;
-        }
-    };
-    // iterate over all icon elements to find the default icon and call parseIcon
-    for (var i=0; i<icons.length; i++) {
-        var icon = icons[i];
-        var size = icon.width;
-        if (!size) {
-            size = icon.height;
-        }
-        if (!size && !icon.density) {
-            if (default_icon) {
-                events.emit('verbose', 'more than one default icon: ' + JSON.stringify(icon));
-            } else {
-                default_icon = icon;
+        };
+
+        // iterate over all icon elements to find the default icon and call parseIcon
+        for (var i=0; i<icons.length; i++) {
+            var icon = icons[i];
+            var size = icon.width;
+            if (!size) {
+                size = icon.height;
             }
-        } else {
-            for (var k=0; k<densities.length; k++) {
-                    parseIcon(icon, size, densityToSizeMap[densities[k]], densities[k]);
+            if (!size && !icon.density) {
+                if (default_icon) {
+                    events.emit('verbose', 'more than one default icon: ' + JSON.stringify(icon));
+                } else {
+                    default_icon = icon;
                 }
+            } else {
+                parseIcon(icon, size);
             }
         }
         var projectRoot = util.isCordova(this.path);
-        var srcfilepath;
-        var destfilepath;
         // copy the default icon to the drawable folder
         if (default_icon) {
-            srcfilepath = path.join(projectRoot, default_icon.src);
-            destfilepath = path.join(this.path, 'res', 'drawable', 'icon.png');
-            events.emit('verbose', 'Copying default icon from ' + srcfilepath + ' to ' + destfilepath);
-            shell.cp('-f', srcfilepath, destfilepath);
+            this.copyImage(path.join(projectRoot, default_icon.src), '', 'icon.png');
         }
-        // copyIcon does the actual copying into the drawable folders
-        var copyIcon = function(density) {
-            if (android_icons[density]) {
-                srcfilepath = path.join(projectRoot, android_icons[density].src);
-                destfilepath = path.join(this.path, 'res', 'drawable-'+density, 'icon.png');
-                events.emit('verbose', 'Copying icon from ' + srcfilepath + ' to ' + destfilepath);
-                shell.cp('-f', srcfilepath, destfilepath);
-            }
-        }.bind(this);
-        for (var j=0; j<densities.length; j++) {
-            copyIcon(densities[j]);
+
+        for (var density in android_icons) {
+            this.copyImage(path.join(projectRoot, android_icons[density].src), density, 'icon.png');
         }
     },
     
@@ -340,7 +334,6 @@ handleIcons: function(config) {
         }
     },
 
-
     // Returns a promise.
     update_project:function(cfg) {
         var platformWww = path.join(this.path, 'assets');
@@ -356,11 +349,21 @@ handleIcons: function(config) {
     }
 };
 
+
 // Consturct the default value for versionCode as
 // PATCH + MINOR * 100 + MAJOR * 10000
 // see http://developer.android.com/tools/publishing/versioning.html
 function default_versionCode(version) {
-    var nums = version.split('-')[0].split('.').map(Number);
-    var versionCode = nums[0] * 10000 + nums[1] * 100 + nums[2];
+    var nums = version.split('-')[0].split('.');
+    var versionCode = 0;
+    if (+nums[0]) {
+        versionCode += +nums[0] * 10000;
+    }
+    if (+nums[1]) {
+        versionCode += +nums[1] * 100;
+    }
+    if (+nums[2]) {
+        versionCode += +nums[2];
+    }
     return versionCode;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org