cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject cordova-lib git commit: CB-8616 Support 9-patch images for default android splashscreen
Date Thu, 05 Mar 2015 15:22:51 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 7e225f351 -> 811ad9577


CB-8616 Support 9-patch images for default android splashscreen

This also fixes us not deleting splash.9.png files when we should have been.


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

Branch: refs/heads/master
Commit: 811ad9577c91d09060d9927642b9f0c79d12edc3
Parents: 7e225f3
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Mar 5 10:21:55 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Mar 5 10:21:55 2015 -0500

----------------------------------------------------------------------
 .../src/cordova/metadata/android_parser.js      | 31 +++++++++-----------
 1 file changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/811ad957/cordova-lib/src/cordova/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/android_parser.js b/cordova-lib/src/cordova/metadata/android_parser.js
index e668118..83abf16 100644
--- a/cordova-lib/src/cordova/metadata/android_parser.js
+++ b/cordova-lib/src/cordova/metadata/android_parser.js
@@ -69,35 +69,37 @@ android_parser.prototype.findAndroidLaunchModePreference = function(config)
{
 // remove the default resource name from all drawable folders
 // return the array of the densities in this project
 android_parser.prototype.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
+            var imgPath = path.join(res, filename, name);
+            if (fs.existsSync(imgPath)) {
+                fs.unlinkSync(imgPath);
+                events.emit('verbose', 'deleted: ' + imgPath);
+            }
+            imgPath = imgPath.replace(/\.png$/, '.9.png');
+            if (fs.existsSync(imgPath)) {
+                fs.unlinkSync(imgPath);
+                events.emit('verbose', 'deleted: ' + imgPath);
             }
         }
     }
-    return densities;
 };
 
 android_parser.prototype.copyImage = function(src, density, name) {
     var destFolder = path.join(this.path, 'res', (density ? 'drawable-': 'drawable') + density);
-    var destFilePath = path.join(destFolder, name);
+    var isNinePatch = !!/\.9\.png$/.exec(src);
+    var ninePatchName = name.replace(/\.png$/, '.9.png');
 
     // default template does not have default asset for this density
     if (!fs.existsSync(destFolder)) {
         fs.mkdirSync(destFolder);
     }
+
+    var destFilePath = path.join(destFolder, isNinePatch ? ninePatchName : name);
     events.emit('verbose', 'copying image from ' + src + ' to ' + destFilePath);
     shell.cp('-f', src, destFilePath);
 };
@@ -119,12 +121,7 @@ android_parser.prototype.handleSplashes = function(config) {
             if (!resource.density) {
                 return;
             }
-            var screenname = 'screen.png';
-            if (resource.src.match(/\.9\.png$/)) {
-                screenname = 'screen.9.png';
-            }
-
-            me.copyImage(path.join(projectRoot, resource.src), resource.density, screenname);
+            me.copyImage(path.join(projectRoot, resource.src), resource.density, 'screen.png');
         });
     }
 };


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


Mime
View raw message