You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/04/24 22:35:13 UTC
git commit: android-parser: Add AndroidLaunchMode preference
Repository: cordova-cli
Updated Branches:
refs/heads/master 3b6d2bd09 -> bedba7589
android-parser: Add AndroidLaunchMode preference
This allows users to set `android:launchMode` from **config.xml**
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/bedba758
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/bedba758
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/bedba758
Branch: refs/heads/master
Commit: bedba75897299b54f0b281b36965c0d2d5b470f7
Parents: 3b6d2bd
Author: Fardjad Davari <pu...@fardjad.com>
Authored: Sun Apr 13 18:39:37 2014 +0430
Committer: Michal Mocny <mm...@gmail.com>
Committed: Thu Apr 24 16:34:37 2014 -0400
----------------------------------------------------------------------
src/ConfigParser.js | 2 +-
src/metadata/android_parser.js | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bedba758/src/ConfigParser.js
----------------------------------------------------------------------
diff --git a/src/ConfigParser.js b/src/ConfigParser.js
index 7ea2604..3e1e57d 100644
--- a/src/ConfigParser.js
+++ b/src/ConfigParser.js
@@ -90,7 +90,7 @@ ConfigParser.prototype = {
var ret = null;
preferences.forEach(function (preference) {
// Take the last one that matches.
- if (preference.attrib.name.toLowerCase() === name) {
+ if (preference.attrib.name.toLowerCase() === name.toLowerCase()) {
ret = preference.attrib.value;
}
});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/bedba758/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index a460fa8..856a9cd 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -59,6 +59,17 @@ module.exports.prototype = {
return ret;
},
+ 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;
+ }
+
+ return ret;
+ },
+
update_from_config:function(config) {
if (config instanceof ConfigParser) {
} else throw new Error('update_from_config requires a ConfigParser object');
@@ -177,10 +188,11 @@ module.exports.prototype = {
var orig_pkg = manifest.getroot().attrib.package;
manifest.getroot().attrib.package = pkg;
+ var act = manifest.getroot().find('./application/activity');
+
// Set the orientation in the AndroidManifest
var orientationPref = this.findOrientationPreference(config);
if (orientationPref) {
- var act = manifest.getroot().find('./application/activity');
switch (orientationPref) {
case 'default':
delete act.attrib["android:screenOrientation"];
@@ -193,6 +205,14 @@ module.exports.prototype = {
}
}
+ // Set android:launchMode in AndroidManifest
+ var androidLaunchModePref = this.findAndroidLaunchModePreference(config);
+ if (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)
+ }
+
// Write out AndroidManifest.xml
fs.writeFileSync(this.manifest, manifest.write({indent: 4}), 'utf-8');