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/08/14 21:07:30 UTC
[1/2] git commit: Taking care of dashes in amazon-fireos platform
name.
Repository: cordova-lib
Updated Branches:
refs/heads/master 13fe6b03b -> 6e1e3d95c
Taking care of dashes in amazon-fireos platform name.
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/6e1e3d95
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/6e1e3d95
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/6e1e3d95
Branch: refs/heads/master
Commit: 6e1e3d95c3b56c016979bc924d94a247fd25da19
Parents: fbf8f28
Author: Archana Naik <na...@lab126.com>
Authored: Thu Aug 14 12:06:39 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Thu Aug 14 12:07:18 2014 -0700
----------------------------------------------------------------------
cordova-lib/src/cordova/platform.js | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/6e1e3d95/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index dca8ed4..2cb8c2e 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -111,6 +111,9 @@ function add(hooks, projectRoot, targets, opts) {
// Package names for Cordova platforms look like "cordova-ios".
var nameParts = pkg.name.split('-');
var name = nameParts[1];
+ if (name == 'amazon') {
+ name = 'amazon-fireos';
+ }
if( !platforms[name] ) {
throw new CordovaError(msg);
}
[2/2] git commit: Upleveled amazon-fireos changes.
Posted by na...@apache.org.
Upleveled amazon-fireos 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/fbf8f283
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/fbf8f283
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/fbf8f283
Branch: refs/heads/master
Commit: fbf8f28356f06d8b68409e73661de48388680cc3
Parents: 13fe6b0
Author: Archana Naik <na...@lab126.com>
Authored: Thu Aug 14 11:42:52 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Thu Aug 14 12:07:18 2014 -0700
----------------------------------------------------------------------
.../cordova/metadata/amazon_fireos_parser.js | 267 +++++++++++--------
1 file changed, 160 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fbf8f283/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 3b39605..4878f4e 100644
--- a/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
+++ b/cordova-lib/src/cordova/metadata/amazon_fireos_parser.js
@@ -54,16 +54,158 @@ module.exports.prototype = {
},
findAndroidLaunchModePreference: function(config) {
- var ret = config.getPreference('AndroidLaunchMode');
- var valid = ['standard', 'singleTop', 'singleTask', 'singleInstance'].indexOf(ret) !== -1;
- if (ret && !valid) {
- events.emit('warn', 'Unknown value for launchMode preference: ' + ret);
- ret = null;
+ var launchMode = config.getPreference('AndroidLaunchMode');
+ if (!launchMode) {
+ // Return a default value
+ return 'singleTop';
}
-
- return ret;
+
+ var expectedValues = ['standard', 'singleTop', 'singleTask', 'singleInstance'];
+ var valid = expectedValues.indexOf(launchMode) !== -1;
+ if (!valid) {
+ events.emit('warn', 'Unrecognized value for AndroidLaunchMode preference: ' + launchMode);
+ events.emit('warn', ' Expected values are: ' + expectedValues.join(', '));
+ // Note: warn, but leave the launch mode as developer wanted, in case the list of options changes in the future
+ }
+
+ return launchMode;
},
-
+
+ // 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));
+ 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);
+ }
+ }
+ }
+},
+
+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;
+ }
+ // already have one but this one is a platform icon
+ if (previous && icon.platform && icon.density == density) {
+ android_icons[density] = icon;
+ return;
+ }
+ // if density is explicitly defined take this one
+ if (density === icon.density) {
+ android_icons[density] = icon;
+ return;
+ }
+ if (size === parseInt(icon_size)) {
+ 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;
+ }
+ } else {
+ for (var k=0; k<densities.length; k++) {
+ parseIcon(icon, size, densityToSizeMap[densities[k]], densities[k]);
+ }
+ }
+ }
+ 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);
+ }
+ // 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]);
+ }
+ },
+
update_from_config:function(config) {
// TODO: share code for this func with Android. Or fix it and remove
// the below JSHint hacks line.
@@ -78,104 +220,15 @@ module.exports.prototype = {
fs.writeFileSync(this.strings, strings.write({indent: 4}), 'utf-8');
events.emit('verbose', 'Wrote out Android application name to "' + name + '"');
- var icons = config.getIcons('amazon-fireos');
- // if there are icon elements in config.xml
- if (icons) {
- var android_icons = {};
- var projectRoot = util.isCordova(this.path);
- var default_icon;
- var max_size;
- var max_density;
- // http://developer.android.com/design/style/iconography.html
- var densities = {
- 'ldpi' : 36,
- 'mdpi' : 48,
- 'hdpi' : 72,
- 'xhdpi' : 96
- };
- for (var i=0; i<icons.length; i++) {
- var icon = icons[i];
- var destfilepath;
- 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;
- }
- } else {
- var parseIcon = function(icon, icon_size, size, density) {
- // if density is explicitly defined, no need to calculate it from width/height
- if (icon.density) {
- android_icons[icon.density] = icon;
- return;
- }
-
- var i = parseInt(icon_size);
- if (size == parseInt(icon_size)) {
- var previous = android_icons[density];
- if (previous) {
- // already have that density. platform rules
- if (!previous.platform) {
- android_icons[density] = icon;
- } // else already have a platform icon of that density
- } else {
- android_icons[density] = icon;
- }
- android_icons[density] = icon;
- if (!max_size) {
- max_size = size;
- max_density = density;
- } else {
- if (max_size < size) {
- max_size = size;
- max_density = density;
- }
- }
- }
- };
- for (var density in densities) {
- parseIcon(icon, size, densities[density], density);
- }
- }
- }
-
- var copyIcon = function(density) {
- var srcfilepath;
- var destfilepath = path.join(this.path, 'res', 'drawable-'+density, 'icon.png');
- if (android_icons[density]) {
- srcfilepath = path.join(projectRoot, android_icons[density].src);
- } else {
- if (default_icon) {
- srcfilepath = path.join(projectRoot, default_icon.src);
- } else {
- if (max_density) {
- srcfilepath = path.join(projectRoot, android_icons[max_density].src);
- } else {
- events.emit('verbose', 'no icon found matching Android typical densities');
- }
- }
- }
- if (srcfilepath) {
- events.emit('verbose', 'Copying icon from ' + srcfilepath + ' to ' + destfilepath);
- shell.cp('-f', srcfilepath, destfilepath);
- }
- }.bind(this);
- for (var density in densities) {
- copyIcon(density);
- }
-
- }
-
+ this.handleSplashes(config);
+ this.handleIcons(config);
+
var manifest = xml.parseElementtreeSync(this.manifest);
// Update the version by changing the AndroidManifest android:versionName
var version = config.version();
var versionCode = config.android_versionCode() || default_versionCode(version);
- manifest.getroot().attrib['android:versionName'] = version;
- manifest.getroot().attrib['android:versionCode'] = versionCode;
+ manifest.getroot().attrib["android:versionName"] = version;
+ manifest.getroot().attrib["android:versionCode"] = versionCode;
// Update package name by changing the AndroidManifest id and moving the entry class around to the proper package directory
var pkg = config.packageName();
@@ -190,22 +243,22 @@ module.exports.prototype = {
if (orientationPref) {
switch (orientationPref) {
case 'default':
- delete act.attrib['android:screenOrientation'];
+ delete act.attrib["android:screenOrientation"];
break;
case 'portrait':
- act.attrib['android:screenOrientation'] = 'portrait';
+ act.attrib["android:screenOrientation"] = 'portrait';
break;
case 'landscape':
- act.attrib['android:screenOrientation'] = 'landscape';
+ act.attrib["android:screenOrientation"] = 'landscape';
}
}
// Set android:launchMode in AndroidManifest
var androidLaunchModePref = this.findAndroidLaunchModePreference(config);
if (androidLaunchModePref) {
- act.attrib['android:launchMode'] = androidLaunchModePref;
+ act.attrib["android:launchMode"] = androidLaunchModePref;
} else { // User has (explicitly) set an invalid value for AndroidLaunchMode preference
- delete act.attrib['android:launchMode']; // use Android default value (standard)
+ delete act.attrib["android:launchMode"]; // use Android default value (standard)
}
// Write out AndroidManifest.xml