forked from github/cordova-android
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d8c755b95a | ||
![]() |
187c6a6bd1 | ||
![]() |
bc04ce4ce3 | ||
![]() |
b2b1ae2b33 | ||
![]() |
fbd6b559d4 | ||
![]() |
89002514f5 | ||
![]() |
a96d340b12 | ||
![]() |
a044e88a1a | ||
![]() |
56587bfb46 | ||
![]() |
0264019c87 | ||
![]() |
fbeba54740 | ||
![]() |
338216beca | ||
![]() |
d36b1cc89d | ||
![]() |
6b5535e91e | ||
![]() |
f64cd2ee8a | ||
![]() |
aa81966e0b | ||
![]() |
f5232f4c26 | ||
![]() |
38b769a2c5 | ||
![]() |
d7e962dba0 |
20
README.md
20
README.md
@ -1,3 +1,23 @@
|
||||
<!--
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
-->
|
||||
Cordova Android
|
||||
===
|
||||
|
||||
|
@ -1,3 +1,20 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%check_reqs.js (
|
||||
@ -6,4 +23,4 @@ IF EXIST %full_path%check_reqs.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -153,6 +153,7 @@ cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/version "$PROJECT_PATH"/cordova/version
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/lib/cordova "$PROJECT_PATH"/cordova/lib/cordova
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/lib/install-device "$PROJECT_PATH"/cordova/lib/install-device
|
||||
cp "$BUILD_PATH"/bin/templates/cordova/lib/install-emulator "$PROJECT_PATH"/cordova/lib/install-emulator
|
||||
|
@ -1,2 +1,18 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
%~dp0\cordova.bat build %*
|
||||
%~dp0\cordova.bat build %*
|
||||
|
@ -1,2 +1,18 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
%~dp0\cordova.bat clean %*
|
||||
|
@ -1,5 +1,3 @@
|
||||
@ECHO OFF
|
||||
GOTO BEGIN
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
@ -16,7 +14,7 @@ GOTO BEGIN
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
:BEGIN
|
||||
@ECHO OFF
|
||||
IF NOT DEFINED JAVA_HOME GOTO MISSING
|
||||
FOR %%X in (java.exe ant.bat android.bat) do (
|
||||
SET FOUND=%%~$PATH:X
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,3 +1,19 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
SET full_path=%~dp0
|
||||
IF EXIST %full_path%cordova.js (
|
||||
@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js (
|
||||
ECHO.
|
||||
ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2
|
||||
EXIT /B 1
|
||||
)
|
||||
)
|
||||
|
@ -1,2 +1,18 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
%~dp0\cordova.bat log %*
|
||||
|
@ -1,2 +1,18 @@
|
||||
:: Licensed to the Apache Software Foundation (ASF) under one
|
||||
:: or more contributor license agreements. See the NOTICE file
|
||||
:: distributed with this work for additional information
|
||||
:: regarding copyright ownership. The ASF licenses this file
|
||||
:: to you under the Apache License, Version 2.0 (the
|
||||
:: "License"); you may not use this file except in compliance
|
||||
:: with the License. You may obtain a copy of the License at
|
||||
::
|
||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
||||
::
|
||||
:: Unless required by applicable law or agreed to in writing,
|
||||
:: software distributed under the License is distributed on an
|
||||
:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
:: KIND, either express or implied. See the License for the
|
||||
:: specific language governing permissions and limitations
|
||||
:: under the License.
|
||||
@ECHO OFF
|
||||
%~dp0\cordova.bat run %*
|
||||
%~dp0\cordova.bat run %*
|
||||
|
@ -64,8 +64,6 @@ function createAppInfoJar {
|
||||
|
||||
function on_error {
|
||||
echo "An unexpected error occurred: $previous_command exited with $?"
|
||||
echo "Deleting project..."
|
||||
[ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
182
framework/assets/www/cordova.js
vendored
182
framework/assets/www/cordova.js
vendored
@ -1,9 +1,5 @@
|
||||
// Platform: android
|
||||
|
||||
// commit d0ffb852378ff018bac2f3b12c38098a19b8ce00
|
||||
|
||||
// File generated at :: Thu Apr 18 2013 15:10:54 GMT-0400 (EDT)
|
||||
|
||||
// 2.8.0-0-g6208c95
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
@ -22,26 +18,36 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
;(function() {
|
||||
|
||||
var CORDOVA_JS_BUILD_LABEL = '2.8.0-0-g6208c95';
|
||||
// file: lib/scripts/require.js
|
||||
|
||||
var require,
|
||||
define;
|
||||
|
||||
(function () {
|
||||
var modules = {};
|
||||
var modules = {},
|
||||
// Stack of moduleIds currently being built.
|
||||
var requireStack = [];
|
||||
requireStack = [],
|
||||
// Map of module ID -> index into requireStack of modules currently being built.
|
||||
var inProgressModules = {};
|
||||
inProgressModules = {},
|
||||
SEPERATOR = ".";
|
||||
|
||||
|
||||
|
||||
function build(module) {
|
||||
var factory = module.factory;
|
||||
var factory = module.factory,
|
||||
localRequire = function (id) {
|
||||
var resultantId = id;
|
||||
//Its a relative path, so lop off the last portion and add the id (minus "./")
|
||||
if (id.charAt(0) === ".") {
|
||||
resultantId = module.id.slice(0, module.id.lastIndexOf(SEPERATOR)) + SEPERATOR + id.slice(2);
|
||||
}
|
||||
return require(resultantId);
|
||||
};
|
||||
module.exports = {};
|
||||
delete module.factory;
|
||||
factory(require, module.exports, module);
|
||||
factory(localRequire, module.exports, module);
|
||||
return module.exports;
|
||||
}
|
||||
|
||||
@ -1314,8 +1320,6 @@ var CaptureAudioOptions = function(){
|
||||
this.limit = 1;
|
||||
// Maximum duration of a single sound clip in seconds.
|
||||
this.duration = 0;
|
||||
// The selected audio mode. Must match with one of the elements in supportedAudioModes array.
|
||||
this.mode = null;
|
||||
};
|
||||
|
||||
module.exports = CaptureAudioOptions;
|
||||
@ -1356,8 +1360,6 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module)
|
||||
var CaptureImageOptions = function(){
|
||||
// Upper limit of images user can take. Value must be equal or greater than 1.
|
||||
this.limit = 1;
|
||||
// The selected image mode. Must match with one of the elements in supportedImageModes array.
|
||||
this.mode = null;
|
||||
};
|
||||
|
||||
module.exports = CaptureImageOptions;
|
||||
@ -1375,8 +1377,6 @@ var CaptureVideoOptions = function(){
|
||||
this.limit = 1;
|
||||
// Maximum duration of a single video clip in seconds.
|
||||
this.duration = 0;
|
||||
// The selected video mode. Must match with one of the elements in supportedVideoModes array.
|
||||
this.mode = null;
|
||||
};
|
||||
|
||||
module.exports = CaptureVideoOptions;
|
||||
@ -2396,11 +2396,7 @@ function initRead(reader, file) {
|
||||
reader._error = null;
|
||||
reader._readyState = FileReader.LOADING;
|
||||
|
||||
if (typeof file == 'string') {
|
||||
// Deprecated in Cordova 2.4.
|
||||
console.warn('Using a string argument with FileReader.readAs functions is deprecated.');
|
||||
reader._fileName = file;
|
||||
} else if (typeof file.fullPath == 'string') {
|
||||
if (typeof file.fullPath == 'string') {
|
||||
reader._fileName = file.fullPath;
|
||||
} else {
|
||||
reader._fileName = '';
|
||||
@ -4071,6 +4067,10 @@ module.exports = {
|
||||
// file: lib/android/plugin/android/nativeapiprovider.js
|
||||
define("cordova/plugin/android/nativeapiprovider", function(require, exports, module) {
|
||||
|
||||
/**
|
||||
* Exports the ExposedJsApi.java object if available, otherwise exports the PromptBasedNativeApi.
|
||||
*/
|
||||
|
||||
var nativeApi = this._cordovaNative || require('cordova/plugin/android/promptbasednativeapi');
|
||||
var currentApi = nativeApi;
|
||||
|
||||
@ -4149,6 +4149,11 @@ module.exports = {
|
||||
// file: lib/android/plugin/android/promptbasednativeapi.js
|
||||
define("cordova/plugin/android/promptbasednativeapi", function(require, exports, module) {
|
||||
|
||||
/**
|
||||
* Implements the API of ExposedJsApi.java, but uses prompt() to communicate.
|
||||
* This is used only on the 2.3 simulator, where addJavascriptInterface() is broken.
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
exec: function(service, action, callbackId, argsJson) {
|
||||
return prompt(argsJson, 'gap:'+JSON.stringify([service, action, callbackId]));
|
||||
@ -5072,7 +5077,6 @@ function Device() {
|
||||
this.available = false;
|
||||
this.platform = null;
|
||||
this.version = null;
|
||||
this.name = null;
|
||||
this.uuid = null;
|
||||
this.cordova = null;
|
||||
this.model = null;
|
||||
@ -5081,12 +5085,15 @@ function Device() {
|
||||
|
||||
channel.onCordovaReady.subscribe(function() {
|
||||
me.getInfo(function(info) {
|
||||
var buildLabel = info.cordova;
|
||||
if (buildLabel != CORDOVA_JS_BUILD_LABEL) {
|
||||
buildLabel += ' JS=' + CORDOVA_JS_BUILD_LABEL;
|
||||
}
|
||||
me.available = true;
|
||||
me.platform = info.platform;
|
||||
me.version = info.version;
|
||||
me.name = info.name;
|
||||
me.uuid = info.uuid;
|
||||
me.cordova = info.cordova;
|
||||
me.cordova = buildLabel;
|
||||
me.model = info.model;
|
||||
channel.onCordovaInfoReady.fire();
|
||||
},function(e) {
|
||||
@ -5843,10 +5850,13 @@ var exec = require('cordova/exec');
|
||||
var utils = require('cordova/utils');
|
||||
|
||||
var UseConsole = true;
|
||||
var UseLogger = true;
|
||||
var Queued = [];
|
||||
var DeviceReady = false;
|
||||
var CurrentLevel;
|
||||
|
||||
var originalConsole = console;
|
||||
|
||||
/**
|
||||
* Logging levels
|
||||
*/
|
||||
@ -5907,8 +5917,7 @@ logger.level = function (value) {
|
||||
* Getter/Setter for the useConsole functionality
|
||||
*
|
||||
* When useConsole is true, the logger will log via the
|
||||
* browser 'console' object. Otherwise, it will use the
|
||||
* native Logger plugin.
|
||||
* browser 'console' object.
|
||||
*/
|
||||
logger.useConsole = function (value) {
|
||||
if (arguments.length) UseConsole = !!value;
|
||||
@ -5932,6 +5941,18 @@ logger.useConsole = function (value) {
|
||||
return UseConsole;
|
||||
};
|
||||
|
||||
/**
|
||||
* Getter/Setter for the useLogger functionality
|
||||
*
|
||||
* When useLogger is true, the logger will log via the
|
||||
* native Logger plugin.
|
||||
*/
|
||||
logger.useLogger = function (value) {
|
||||
// Enforce boolean
|
||||
if (arguments.length) UseLogger = !!value;
|
||||
return UseLogger;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a message at the LOG level.
|
||||
*
|
||||
@ -6001,24 +6022,26 @@ logger.logLevel = function(level /* , ... */) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if not using the console, use the native logger
|
||||
if (!UseConsole) {
|
||||
// Log using the native logger if that is enabled
|
||||
if (UseLogger) {
|
||||
exec(null, null, "Logger", "logLevel", [level, message]);
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure console is not using logger
|
||||
if (console.__usingCordovaLogger) {
|
||||
throw new Error("console and logger are too intertwingly");
|
||||
}
|
||||
// Log using the console if that is enabled
|
||||
if (UseConsole) {
|
||||
// make sure console is not using logger
|
||||
if (console.__usingCordovaLogger) {
|
||||
throw new Error("console and logger are too intertwingly");
|
||||
}
|
||||
|
||||
// log to the console
|
||||
switch (level) {
|
||||
case logger.LOG: console.log(message); break;
|
||||
case logger.ERROR: console.log("ERROR: " + message); break;
|
||||
case logger.WARN: console.log("WARN: " + message); break;
|
||||
case logger.INFO: console.log("INFO: " + message); break;
|
||||
case logger.DEBUG: console.log("DEBUG: " + message); break;
|
||||
// log to the console
|
||||
switch (level) {
|
||||
case logger.LOG: originalConsole.log(message); break;
|
||||
case logger.ERROR: originalConsole.log("ERROR: " + message); break;
|
||||
case logger.WARN: originalConsole.log("WARN: " + message); break;
|
||||
case logger.INFO: originalConsole.log("INFO: " + message); break;
|
||||
case logger.DEBUG: originalConsole.log("DEBUG: " + message); break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -6279,7 +6302,7 @@ module.exports = {
|
||||
// Some platforms take an array of button label names.
|
||||
// Other platforms take a comma separated list.
|
||||
// For compatibility, we convert to the desired type based on the platform.
|
||||
if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone") {
|
||||
if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone" || platform.id == "blackberry10") {
|
||||
if (typeof _buttonLabels === 'string') {
|
||||
var buttonLabelString = _buttonLabels;
|
||||
_buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here
|
||||
@ -6303,12 +6326,14 @@ module.exports = {
|
||||
* @param {Function} resultCallback The callback that is called when user clicks on a button.
|
||||
* @param {String} title Title of the dialog (default: "Prompt")
|
||||
* @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
|
||||
* @param {String} defaultText Textbox input value (default: "Default text")
|
||||
*/
|
||||
prompt: function(message, resultCallback, title, buttonLabels) {
|
||||
prompt: function(message, resultCallback, title, buttonLabels, defaultText) {
|
||||
var _message = (message || "Prompt message");
|
||||
var _title = (title || "Prompt");
|
||||
var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
|
||||
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]);
|
||||
var _defaultText = (defaultText || "Default text");
|
||||
exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -6650,12 +6675,15 @@ function UUIDcreatePart(length) {
|
||||
|
||||
});
|
||||
|
||||
|
||||
window.cordova = require('cordova');
|
||||
|
||||
// file: lib/scripts/bootstrap.js
|
||||
|
||||
(function (context) {
|
||||
if (context._cordovaJsLoaded) {
|
||||
throw new Error('cordova.js included multiple times.');
|
||||
}
|
||||
context._cordovaJsLoaded = true;
|
||||
|
||||
var channel = require('cordova/channel');
|
||||
var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
|
||||
|
||||
@ -6768,7 +6796,7 @@ require('cordova/channel').onNativeReady.fire();
|
||||
// See plugman's plugin_loader.js for the details of this object.
|
||||
// This function is only called if the really is a plugins array that isn't empty.
|
||||
// Otherwise the XHR response handler will just call finishPluginLoading().
|
||||
function handlePluginsObject(modules) {
|
||||
function handlePluginsObject(modules, path) {
|
||||
// First create the callback for when all plugins are loaded.
|
||||
var mapper = context.cordova.require('cordova/modulemapper');
|
||||
onScriptLoadingComplete = function() {
|
||||
@ -6802,35 +6830,49 @@ require('cordova/channel').onNativeReady.fire();
|
||||
|
||||
// Now inject the scripts.
|
||||
for (var i = 0; i < modules.length; i++) {
|
||||
injectScript(modules[i].file);
|
||||
injectScript(path + modules[i].file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Try to XHR the cordova_plugins.json file asynchronously.
|
||||
try { // we commented we were going to try, so let us actually try and catch
|
||||
var xhr = new context.XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
// If the response is a JSON string which composes an array, call handlePluginsObject.
|
||||
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
|
||||
var obj = JSON.parse(this.responseText);
|
||||
if (obj && obj instanceof Array && obj.length > 0) {
|
||||
handlePluginsObject(obj);
|
||||
} else {
|
||||
finishPluginLoading();
|
||||
}
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
finishPluginLoading();
|
||||
};
|
||||
xhr.open('GET', 'cordova_plugins.json', true); // Async
|
||||
xhr.send();
|
||||
// Find the root of the app
|
||||
var path = '';
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var term = 'cordova.js';
|
||||
for (var n = scripts.length-1; n>-1; n--) {
|
||||
var src = scripts[n].src;
|
||||
if (src.indexOf(term) == (src.length - term.length)) {
|
||||
path = src.substring(0, src.length - term.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(err){
|
||||
// Try to XHR the cordova_plugins.json file asynchronously.
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onload = function() {
|
||||
// If the response is a JSON string which composes an array, call handlePluginsObject.
|
||||
// If the request fails, or the response is not a JSON array, just call finishPluginLoading.
|
||||
var obj;
|
||||
try {
|
||||
obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
|
||||
} catch (err) {
|
||||
// obj will be undefined.
|
||||
}
|
||||
if (Array.isArray(obj) && obj.length > 0) {
|
||||
handlePluginsObject(obj, path);
|
||||
} else {
|
||||
finishPluginLoading();
|
||||
}
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
finishPluginLoading();
|
||||
};
|
||||
var plugins_json = path + 'cordova_plugins.json';
|
||||
try { // we commented we were going to try, so let us actually try and catch
|
||||
xhr.open('GET', plugins_json, true); // Async
|
||||
xhr.send();
|
||||
} catch(err){
|
||||
finishPluginLoading();
|
||||
}
|
||||
}(window));
|
||||
|
||||
|
||||
|
||||
})();
|
@ -1,18 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<widget xmlns = "http://www.w3.org/ns/widgets"
|
||||
id = "io.cordova.helloCordova"
|
||||
|
@ -20,7 +20,7 @@ package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.DataResource;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
|
||||
@ -56,14 +56,6 @@ public class AudioHandler extends CordovaPlugin {
|
||||
this.pausedForPhone = new ArrayList<AudioPlayer>();
|
||||
}
|
||||
|
||||
public String getFilePath(String url, String source){
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source);
|
||||
if(dataResource.getUri().getScheme().equals("http") || dataResource.getUri().getScheme().equals("https"))
|
||||
return dataResource.getUri().toString();
|
||||
else
|
||||
return dataResource.getRealFile().getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
* @param action The action to execute.
|
||||
@ -76,13 +68,13 @@ public class AudioHandler extends CordovaPlugin {
|
||||
String result = "";
|
||||
|
||||
if (action.equals("startRecordingAudio")) {
|
||||
this.startRecordingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startRecordingAudio"));
|
||||
this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
|
||||
}
|
||||
else if (action.equals("stopRecordingAudio")) {
|
||||
this.stopRecordingAudio(args.getString(0));
|
||||
}
|
||||
else if (action.equals("startPlayingAudio")) {
|
||||
this.startPlayingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startPlayingAudio"));
|
||||
this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
|
||||
}
|
||||
else if (action.equals("seekToAudio")) {
|
||||
this.seekToAudio(args.getString(0), args.getInt(1));
|
||||
@ -110,7 +102,7 @@ public class AudioHandler extends CordovaPlugin {
|
||||
}
|
||||
else if (action.equals("create")) {
|
||||
String id = args.getString(0);
|
||||
String src = getFilePath(args.getString(1), "AudioHandler.create");
|
||||
String src = FileHelper.stripFileProtocol(args.getString(1));
|
||||
AudioPlayer audio = new AudioPlayer(this, id, src);
|
||||
this.players.put(id, audio);
|
||||
}
|
||||
|
@ -20,16 +20,15 @@ package org.apache.cordova;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.DataResource;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
@ -43,6 +42,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
|
||||
import android.net.Uri;
|
||||
@ -290,7 +290,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
|
||||
// If sending base64 image back
|
||||
if (destType == DATA_URL) {
|
||||
bitmap = getScaledBitmap(imageUri.toString());
|
||||
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
|
||||
if (bitmap == null) {
|
||||
// Try to get the bitmap from intent.
|
||||
bitmap = (Bitmap)intent.getExtras().get("data");
|
||||
@ -316,9 +316,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
if (this.saveToPhotoAlbum) {
|
||||
Uri inputUri = getUriFromMediaStore();
|
||||
//Just because we have a media URI doesn't mean we have a real file, we need to make it
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(inputUri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
|
||||
File file = dataResource.getRealFile();
|
||||
uri = Uri.fromFile(file);
|
||||
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
|
||||
} else {
|
||||
uri = Uri.fromFile(new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg"));
|
||||
}
|
||||
@ -334,15 +332,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
|
||||
this.callbackContext.success(uri.toString());
|
||||
} else {
|
||||
bitmap = getScaledBitmap(imageUri.toString());
|
||||
bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
|
||||
|
||||
if (rotate != 0 && this.correctOrientation) {
|
||||
bitmap = getRotatedBitmap(rotate, bitmap, exif);
|
||||
}
|
||||
|
||||
// Add compressed version of captured image to returned media store Uri
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
|
||||
OutputStream os = dataResource.getOutputStream();
|
||||
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||
os.close();
|
||||
|
||||
@ -350,7 +347,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
if (this.encodingType == JPEG) {
|
||||
String exifPath;
|
||||
if (this.saveToPhotoAlbum) {
|
||||
exifPath = dataResource.getRealFile().getPath();
|
||||
exifPath = FileHelper.getRealPath(uri, this.cordova);
|
||||
} else {
|
||||
exifPath = uri.getPath();
|
||||
}
|
||||
@ -401,9 +398,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
this.callbackContext.success(uri.toString());
|
||||
} else {
|
||||
String uriString = uri.toString();
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
|
||||
// Get the path to the image. Makes loading so much easier.
|
||||
String mimeType = dataResource.getMimeType();
|
||||
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
|
||||
// If we don't have a valid image so quit.
|
||||
if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
|
||||
Log.d(LOG_TAG, "I either have a null image path or bitmap");
|
||||
@ -444,8 +440,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
// Create an ExifHelper to save the exif data that is lost during compression
|
||||
String resizePath = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
|
||||
// Some content: URIs do not map to file paths (e.g. picasa).
|
||||
File realFile = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent").getRealFile();
|
||||
String realPath = realFile != null? realFile.getPath() : null;
|
||||
String realPath = FileHelper.getRealPath(uri, this.cordova);
|
||||
ExifHelper exif = new ExifHelper();
|
||||
if (realPath != null && this.encodingType == JPEG) {
|
||||
try {
|
||||
@ -539,15 +534,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
*/
|
||||
private void writeUncompressedImage(Uri uri) throws FileNotFoundException,
|
||||
IOException {
|
||||
DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
|
||||
InputStream fis = inputDataResource.getInputStream();
|
||||
DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
|
||||
OutputStream os = outDataResource.getOutputStream();
|
||||
if(fis == null) {
|
||||
throw new FileNotFoundException("Could not get the input file");
|
||||
} else if(os == null) {
|
||||
throw new FileNotFoundException("Could not get the output file");
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(FileHelper.stripFileProtocol(imageUri.toString()));
|
||||
OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
|
||||
byte[] buffer = new byte[4096];
|
||||
int len;
|
||||
while ((len = fis.read(buffer)) != -1) {
|
||||
@ -590,15 +578,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
*/
|
||||
private Bitmap getScaledBitmap(String imageUrl) throws IOException {
|
||||
// If no new width or height were specified return the original bitmap
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap");
|
||||
if (this.targetWidth <= 0 && this.targetHeight <= 0) {
|
||||
return BitmapFactory.decodeStream(dataResource.getInputStream());
|
||||
return BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova));
|
||||
}
|
||||
|
||||
// figure out the original width and height of the image
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
|
||||
BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
|
||||
|
||||
//CB-2292: WTF? Why is the width null?
|
||||
if(options.outWidth == 0 || options.outHeight == 0)
|
||||
@ -612,7 +599,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
// Load in the smallest bitmap possible that is closest to the size we want
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight);
|
||||
Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
|
||||
Bitmap unscaledBitmap = BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
|
||||
if (unscaledBitmap == null) {
|
||||
return null;
|
||||
}
|
||||
@ -711,20 +698,16 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(oldImage, webView.pluginManager, cordova, "CameraLauncher.cleanup");
|
||||
File file = dataResource.getRealFile();
|
||||
if(file != null) {
|
||||
// Clean up initial camera-written image file.
|
||||
file.delete();
|
||||
// Clean up initial camera-written image file.
|
||||
(new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete();
|
||||
|
||||
checkForDuplicateImage(imageType);
|
||||
// Scan for the gallery to update pic refs in gallery
|
||||
if (this.saveToPhotoAlbum && newImage != null) {
|
||||
this.scanForGallery(newImage);
|
||||
}
|
||||
|
||||
System.gc();
|
||||
checkForDuplicateImage(imageType);
|
||||
// Scan for the gallery to update pic refs in gallery
|
||||
if (this.saveToPhotoAlbum && newImage != null) {
|
||||
this.scanForGallery(newImage);
|
||||
}
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,6 @@ import java.io.OutputStream;
|
||||
import android.os.Build;
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.DataResource;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
@ -130,8 +129,7 @@ public class Capture extends CordovaPlugin {
|
||||
// If the mimeType isn't set the rest will fail
|
||||
// so let's see if we can determine it.
|
||||
if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.dataResource");
|
||||
mimeType = dataResource.getMimeType();
|
||||
mimeType = FileHelper.getMimeType(filePath, cordova);
|
||||
}
|
||||
Log.d(LOG_TAG, "Mime type = " + mimeType);
|
||||
|
||||
@ -158,8 +156,7 @@ public class Capture extends CordovaPlugin {
|
||||
private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.getImageData");
|
||||
BitmapFactory.decodeFile(dataResource.getRealFile().getPath(), options);
|
||||
BitmapFactory.decodeFile(FileHelper.stripFileProtocol(filePath), options);
|
||||
obj.put("height", options.outHeight);
|
||||
obj.put("width", options.outWidth);
|
||||
return obj;
|
||||
@ -351,8 +348,7 @@ public class Capture extends CordovaPlugin {
|
||||
* @throws IOException
|
||||
*/
|
||||
private JSONObject createMediaFile(Uri data) {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(data, webView.pluginManager, cordova, "Capture.createMediaFile");
|
||||
File fp = dataResource.getRealFile();
|
||||
File fp = new File(FileHelper.getRealPath(data, this.cordova));
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
@ -362,7 +358,6 @@ public class Capture extends CordovaPlugin {
|
||||
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
|
||||
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
|
||||
// is stored in the audio or video content store.
|
||||
|
||||
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
|
||||
if (data.toString().contains("/audio/")) {
|
||||
obj.put("type", AUDIO_3GPP);
|
||||
@ -370,7 +365,7 @@ public class Capture extends CordovaPlugin {
|
||||
obj.put("type", VIDEO_3GPP);
|
||||
}
|
||||
} else {
|
||||
obj.put("type", dataResource.getMimeType());
|
||||
obj.put("type", FileHelper.getMimeType(fp.getAbsolutePath(), cordova));
|
||||
}
|
||||
|
||||
obj.put("lastModifiedDate", fp.lastModified());
|
||||
|
@ -38,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends CordovaPlugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String cordovaVersion = "dev"; // Cordova version
|
||||
public static String cordovaVersion = "2.8.1"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
@ -26,11 +26,10 @@ import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.LOG;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Locale;
|
||||
|
||||
public class FileHelper {
|
||||
private static final String LOG_TAG = "FileUtils";
|
||||
@ -91,65 +90,18 @@ public class FileHelper {
|
||||
* @throws IOException
|
||||
*/
|
||||
public static InputStream getInputStreamFromUriString(String uriString, CordovaInterface cordova) throws IOException {
|
||||
if (uriString.startsWith("content:")) {
|
||||
if (uriString.startsWith("content")) {
|
||||
Uri uri = Uri.parse(uriString);
|
||||
return cordova.getActivity().getContentResolver().openInputStream(uri);
|
||||
} else if (uriString.startsWith("file:///android_asset/")) {
|
||||
Uri uri = Uri.parse(uriString);
|
||||
String relativePath = uri.getPath().substring(15);
|
||||
return cordova.getActivity().getAssets().open(relativePath);
|
||||
} else if (uriString.startsWith("file://")) {
|
||||
} else {
|
||||
return new FileInputStream(getRealPath(uriString, cordova));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static OutputStream getOutputStreamFromUriString(String uriString, CordovaInterface cordova) throws FileNotFoundException{
|
||||
if (uriString.startsWith("content:")) {
|
||||
Uri uri = Uri.parse(uriString);
|
||||
return cordova.getActivity().getContentResolver().openOutputStream(uri);
|
||||
} else if (uriString.startsWith("file:") && !uriString.startsWith("file:///android_asset/")) {
|
||||
String realPath = uriString.substring(7);
|
||||
return new FileOutputStream(realPath);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns whether the uri can be written to by openeing a File to that uri
|
||||
*
|
||||
* @param the URI to test
|
||||
* @return boolean indicating whether the uri is writable
|
||||
*/
|
||||
public static boolean isUriWritable(String uriString) {
|
||||
String scheme = uriString.split(":")[0];
|
||||
|
||||
if(scheme.equals("file")){
|
||||
// special case file
|
||||
return !uriString.startsWith("file:///android_asset/");
|
||||
}
|
||||
return "content".equals(scheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the "file://" prefix exists for the given string
|
||||
* If the given URI string already has a scheme, it is returned unchanged
|
||||
*
|
||||
* @param path - the path string to operate on
|
||||
* @return a String with the "file://" scheme set
|
||||
*/
|
||||
public static String insertFileProtocol(String path) {
|
||||
if(!path.matches("^[a-z0-9+.-]+:.*")){
|
||||
//Ensure it is not a relative path
|
||||
if(!path.startsWith("/")){
|
||||
throw new IllegalArgumentException("Relative paths" + path + "are not allowed.");
|
||||
}
|
||||
path = "file://" + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the "file://" prefix from the given URI string, if applicable.
|
||||
* If the given URI string doesn't have a "file://" prefix, it is returned unchanged.
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.cordova;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
@ -25,7 +27,6 @@ import android.util.Log;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.DataResource;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.apache.cordova.file.EncodingException;
|
||||
import org.apache.cordova.file.FileExistsException;
|
||||
@ -45,6 +46,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
/**
|
||||
@ -231,7 +234,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param filePath the path to check
|
||||
*/
|
||||
private void notifyDelete(String filePath) {
|
||||
String newFilePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.notifyDelete").getRealFile().getPath();
|
||||
String newFilePath = FileHelper.getRealPath(filePath, cordova);
|
||||
try {
|
||||
this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
MediaStore.Images.Media.DATA + " = ?",
|
||||
@ -253,10 +256,37 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws IOException if the user can't read the file
|
||||
* @throws JSONException
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
|
||||
File fp = DataResource.initiateNewDataRequestForUri(url, webView.pluginManager, cordova, "FileUtils.resolveLocalFileSystemURI").getRealFile();
|
||||
String decoded = URLDecoder.decode(url, "UTF-8");
|
||||
|
||||
if (fp == null || !fp.exists()) {
|
||||
File fp = null;
|
||||
|
||||
// Handle the special case where you get an Android content:// uri.
|
||||
if (decoded.startsWith("content:")) {
|
||||
Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
|
||||
// Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
|
||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
cursor.moveToFirst();
|
||||
fp = new File(cursor.getString(column_index));
|
||||
} else {
|
||||
// Test to see if this is a valid URL first
|
||||
@SuppressWarnings("unused")
|
||||
URL testUrl = new URL(decoded);
|
||||
|
||||
if (decoded.startsWith("file://")) {
|
||||
int questionMark = decoded.indexOf("?");
|
||||
if (questionMark < 0) {
|
||||
fp = new File(decoded.substring(7, decoded.length()));
|
||||
} else {
|
||||
fp = new File(decoded.substring(7, questionMark));
|
||||
}
|
||||
} else {
|
||||
fp = new File(decoded);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fp.exists()) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
if (!fp.canRead()) {
|
||||
@ -274,9 +304,9 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException {
|
||||
File fp = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
|
||||
File fp = createFileObject(fileName);
|
||||
|
||||
if (fp == null || !fp.exists()) {
|
||||
if (!fp.exists()) {
|
||||
// The directory we are listing doesn't exist so we should fail.
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
@ -311,10 +341,8 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws FileExistsException
|
||||
*/
|
||||
private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
|
||||
DataResource dataResourceFrom = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.transferTo");
|
||||
String newFileName = dataResourceFrom.getRealFile().getPath();
|
||||
DataResource dataResourceTo = DataResource.initiateNewDataRequestForUri(newParent, webView.pluginManager, cordova, "FileUtils.transferTo");
|
||||
newParent = dataResourceTo.getRealFile().getPath();
|
||||
String newFileName = FileHelper.getRealPath(fileName, cordova);
|
||||
newParent = FileHelper.getRealPath(newParent, cordova);
|
||||
|
||||
// Check for invalid file name
|
||||
if (newName != null && newName.contains(":")) {
|
||||
@ -585,7 +613,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws FileExistsException
|
||||
*/
|
||||
private boolean removeRecursively(String filePath) throws FileExistsException {
|
||||
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
|
||||
File fp = createFileObject(filePath);
|
||||
|
||||
// You can't delete the root directory.
|
||||
if (atRootDirectory(filePath)) {
|
||||
@ -626,7 +654,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws InvalidModificationException
|
||||
*/
|
||||
private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException {
|
||||
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
|
||||
File fp = createFileObject(filePath);
|
||||
|
||||
// You can't delete the root directory.
|
||||
if (atRootDirectory(filePath)) {
|
||||
@ -670,8 +698,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
throw new EncodingException("This file has a : in it's name");
|
||||
}
|
||||
|
||||
String filePath = getFullFilePath(dirPath, fileName);
|
||||
File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getFile").getRealFile();
|
||||
File fp = createFileObject(dirPath, fileName);
|
||||
|
||||
if (create) {
|
||||
if (exclusive && fp.exists()) {
|
||||
@ -713,14 +740,15 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param fileName new file name
|
||||
* @return
|
||||
*/
|
||||
private String getFullFilePath(String dirPath, String fileName) {
|
||||
private File createFileObject(String dirPath, String fileName) {
|
||||
File fp = null;
|
||||
if (fileName.startsWith("/")) {
|
||||
return fileName;
|
||||
fp = new File(fileName);
|
||||
} else {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(dirPath, webView.pluginManager, cordova, "FileUtils.getFullFilePath");
|
||||
dirPath = dataResource.getRealFile().getPath();
|
||||
return dirPath + File.separator + fileName;
|
||||
dirPath = FileHelper.getRealPath(dirPath, cordova);
|
||||
fp = new File(dirPath + File.separator + fileName);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -732,13 +760,12 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getParent(String filePath) throws JSONException {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getParent");
|
||||
filePath = dataResource.getRealFile().getPath();
|
||||
filePath = FileHelper.getRealPath(filePath, cordova);
|
||||
|
||||
if (atRootDirectory(filePath)) {
|
||||
return getEntry(filePath);
|
||||
}
|
||||
return getEntry(dataResource.getRealFile().getParent());
|
||||
return getEntry(new File(filePath).getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -749,7 +776,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return true if we are at the root, false otherwise.
|
||||
*/
|
||||
private boolean atRootDirectory(String filePath) {
|
||||
filePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.atRootDirectory").getRealFile().getPath();
|
||||
filePath = FileHelper.getRealPath(filePath, cordova);
|
||||
|
||||
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
|
||||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
|
||||
@ -759,6 +786,19 @@ public class FileUtils extends CordovaPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a File object from the passed in path
|
||||
*
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
private File createFileObject(String filePath) {
|
||||
filePath = FileHelper.getRealPath(filePath, cordova);
|
||||
|
||||
File file = new File(filePath);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up metadata about this entry.
|
||||
*
|
||||
@ -767,9 +807,9 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private long getMetadata(String filePath) throws FileNotFoundException {
|
||||
File file = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata").getRealFile();
|
||||
File file = createFileObject(filePath);
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("Failed to find file in getMetadata");
|
||||
}
|
||||
|
||||
@ -785,16 +825,15 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata");
|
||||
File file = dataResource.getRealFile();
|
||||
File file = createFileObject(filePath);
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("File: " + filePath + " does not exist.");
|
||||
}
|
||||
|
||||
JSONObject metadata = new JSONObject();
|
||||
metadata.put("size", file.length());
|
||||
metadata.put("type", dataResource.getMimeType());
|
||||
metadata.put("type", FileHelper.getMimeType(filePath, cordova));
|
||||
metadata.put("name", file.getName());
|
||||
metadata.put("fullPath", filePath);
|
||||
metadata.put("lastModifiedDate", file.lastModified());
|
||||
@ -896,8 +935,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
this.cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs");
|
||||
byte[] bytes = readAsBinaryHelper(dataResource.getInputStream(), start, end);
|
||||
byte[] bytes = readAsBinaryHelper(filename, start, end);
|
||||
|
||||
PluginResult result;
|
||||
switch (resultType) {
|
||||
@ -911,7 +949,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
result = new PluginResult(PluginResult.Status.OK, bytes, true);
|
||||
break;
|
||||
default: // Base64.
|
||||
String contentType = dataResource.getMimeType();
|
||||
String contentType = FileHelper.getMimeType(filename, cordova);
|
||||
byte[] base64 = Base64.encodeBase64(bytes);
|
||||
String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
|
||||
result = new PluginResult(PluginResult.Status.OK, s);
|
||||
@ -938,9 +976,10 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return Contents of the file as a byte[].
|
||||
* @throws IOException
|
||||
*/
|
||||
private byte[] readAsBinaryHelper(InputStream inputStream, int start, int end) throws IOException {
|
||||
private byte[] readAsBinaryHelper(String filename, int start, int end) throws IOException {
|
||||
int numBytesToRead = end - start;
|
||||
byte[] bytes = new byte[numBytesToRead];
|
||||
InputStream inputStream = FileHelper.getInputStreamFromUriString(filename, cordova);
|
||||
int numBytesRead = 0;
|
||||
|
||||
if (start > 0) {
|
||||
@ -969,8 +1008,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
throw new NoModificationAllowedException("Couldn't write to file given its content URI");
|
||||
}
|
||||
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.write");
|
||||
filename = dataResource.getRealFile().getPath();
|
||||
filename = FileHelper.getRealPath(filename, cordova);
|
||||
|
||||
boolean append = false;
|
||||
if (offset > 0) {
|
||||
@ -999,16 +1037,13 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws NoModificationAllowedException
|
||||
*/
|
||||
private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.truncateFile");
|
||||
if(!dataResource.isWritable()) {
|
||||
throw new NoModificationAllowedException("Couldn't truncate file as it is not writable");
|
||||
}
|
||||
File file = dataResource.getRealFile();
|
||||
if(file == null) {
|
||||
throw new FileNotFoundException("Couldn't get the file");
|
||||
if (filename.startsWith("content://")) {
|
||||
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
|
||||
}
|
||||
|
||||
RandomAccessFile raf = new RandomAccessFile(file, "rw");
|
||||
filename = FileHelper.getRealPath(filename, cordova);
|
||||
|
||||
RandomAccessFile raf = new RandomAccessFile(filename, "rw");
|
||||
try {
|
||||
if (raf.length() >= size) {
|
||||
FileChannel channel = raf.getChannel();
|
||||
|
@ -22,8 +22,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.DataResource;
|
||||
import org.apache.cordova.api.DataResourceContext;
|
||||
import org.apache.cordova.api.LOG;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
@ -45,27 +43,41 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
|
||||
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
// We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism.
|
||||
DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova,
|
||||
"WebViewClient.shouldInterceptRequest");
|
||||
url = dataResource.getUri().toString();
|
||||
|
||||
// This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it.
|
||||
//Check if plugins intercept the request
|
||||
WebResourceResponse ret = super.shouldInterceptRequest(view, url);
|
||||
|
||||
if(ret == null) {
|
||||
try {
|
||||
InputStream is;
|
||||
String mimeType;
|
||||
if((is = dataResource.getInputStream()) != null && (mimeType = dataResource.getMimeType()) != null) {
|
||||
// If we don't know how to open this file, let the browser continue loading
|
||||
ret = new WebResourceResponse(mimeType, "UTF-8", is);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e);
|
||||
}
|
||||
if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
|
||||
ret = generateWebResourceResponse(url);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private WebResourceResponse generateWebResourceResponse(String url) {
|
||||
if (url.startsWith("file:///android_asset/")) {
|
||||
String mimetype = FileHelper.getMimeType(url, cordova);
|
||||
|
||||
try {
|
||||
InputStream stream = FileHelper.getInputStreamFromUriString(url, cordova);
|
||||
WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8", stream);
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
LOG.e("generateWebResourceResponse", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean needsIceCreamSpaceInAssetUrlFix(String url) {
|
||||
if (!url.contains("%20")){
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(android.os.Build.VERSION.SDK_INT){
|
||||
case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
|
||||
case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -175,20 +175,6 @@ public class CordovaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* All plugins can now choose if they want to modify any uri requests. This includes all webview requests, opening of files, content uri's etc.
|
||||
* This mechanism allows several plugins to modify the same request
|
||||
* @param requestSource The source of the incoming request
|
||||
*
|
||||
* @param dataResource The resource to be loaded.
|
||||
* @param dataResourceContext Context associated with the resource load
|
||||
* @return Return a new DataResource if the plugin wants to assist in loading the request or null if it doesn't.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public DataResource handleDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the WebView does a top-level navigation or refreshes.
|
||||
*
|
||||
|
@ -1,141 +0,0 @@
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.cordova.FileHelper;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
/*
|
||||
* All requests to access files, browser network requests etc have to go through this class.
|
||||
*/
|
||||
public class DataResource {
|
||||
private CordovaInterface cordova;
|
||||
|
||||
// Uri of the request. Always required.
|
||||
private Uri uri;
|
||||
// Remaining fields may or may not be null
|
||||
private InputStream is;
|
||||
private OutputStream os;
|
||||
private String mimeType;
|
||||
private Boolean writable;
|
||||
private File realFile;
|
||||
private boolean retryIsLoad = true;
|
||||
private boolean retryOsLoad = true;
|
||||
private boolean retryMimeTypeLoad = true;
|
||||
private boolean retryWritableLoad = true;
|
||||
private boolean retryRealFileLoad = true;
|
||||
|
||||
public DataResource(CordovaInterface cordova, Uri uri) {
|
||||
this.cordova = cordova;
|
||||
this.uri = uri;
|
||||
}
|
||||
public DataResource(CordovaInterface cordova, Uri uri, InputStream is,
|
||||
OutputStream os, String mimeType, boolean writable, File realFile) {
|
||||
this(cordova, uri);
|
||||
this.is = is;
|
||||
this.mimeType = mimeType;
|
||||
this.writable = Boolean.valueOf(writable);
|
||||
this.realFile = realFile;
|
||||
}
|
||||
public Uri getUri() {
|
||||
// Uri is always provided
|
||||
return uri;
|
||||
}
|
||||
public InputStream getInputStream() throws IOException {
|
||||
if(is == null && retryIsLoad) {
|
||||
try {
|
||||
is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova);
|
||||
} finally {
|
||||
// We failed loading once, don't try loading anymore
|
||||
if(is == null) {
|
||||
retryIsLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
public OutputStream getOutputStream() throws FileNotFoundException {
|
||||
if(os == null && retryOsLoad) {
|
||||
try {
|
||||
os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova);
|
||||
} finally {
|
||||
// We failed loading once, don't try loading anymore
|
||||
if(os == null) {
|
||||
retryOsLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return os;
|
||||
}
|
||||
public String getMimeType() {
|
||||
if(mimeType == null && retryMimeTypeLoad) {
|
||||
try {
|
||||
mimeType = FileHelper.getMimeType(uri.toString(), cordova);
|
||||
} finally {
|
||||
// We failed loading once, don't try loading anymore
|
||||
if(mimeType == null) {
|
||||
retryMimeTypeLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mimeType;
|
||||
}
|
||||
public boolean isWritable() {
|
||||
if(writable == null && retryWritableLoad) {
|
||||
try {
|
||||
writable = FileHelper.isUriWritable(uri.toString());
|
||||
} finally {
|
||||
// We failed loading once, don't try loading anymore
|
||||
if(writable == null) {
|
||||
retryWritableLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// default to false
|
||||
return writable != null && writable.booleanValue();
|
||||
}
|
||||
public File getRealFile() {
|
||||
if(realFile == null && retryRealFileLoad) {
|
||||
try {
|
||||
String realPath = FileHelper.getRealPath(uri, cordova);
|
||||
if(realPath != null) {
|
||||
realFile = new File(realPath);
|
||||
}
|
||||
} finally {
|
||||
// We failed loading once, don't try loading anymore
|
||||
if(realFile == null) {
|
||||
retryRealFileLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return realFile;
|
||||
}
|
||||
|
||||
// static instantiation methods
|
||||
public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
|
||||
// if no protocol is specified, assume its file:
|
||||
uriString = FileHelper.insertFileProtocol(uriString);
|
||||
return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag);
|
||||
}
|
||||
public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
|
||||
return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag));
|
||||
}
|
||||
public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
|
||||
// if no protocol is specified, assume its file:
|
||||
uriString = FileHelper.insertFileProtocol(uriString);
|
||||
return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, dataResourceContext);
|
||||
}
|
||||
public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
|
||||
DataResource dataResource = new DataResource(cordova, uri);
|
||||
if (pluginManager != null) {
|
||||
// get the resource as returned by plugins
|
||||
dataResource = pluginManager.handleDataResourceRequestWithPlugins(dataResource, dataResourceContext);
|
||||
}
|
||||
return dataResource;
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
/*
|
||||
* Some context information associated with a DataRequest.
|
||||
*/
|
||||
public class DataResourceContext {
|
||||
// A random id that is unique for a particular request.
|
||||
private int requestId;
|
||||
// A tag associated with the source of this dataResourceContext
|
||||
private String source;
|
||||
// If needed, any data associated with core plugins can be a part of the context object
|
||||
// If needed, any data associated with non core plugins should store data in a Map so as to not clutter the context object
|
||||
private Map<String, Object> dataMap;
|
||||
public DataResourceContext(String source) {
|
||||
this.requestId = new Random().nextInt();
|
||||
this.source = source;
|
||||
this.dataMap = new HashMap<String, Object>();
|
||||
}
|
||||
public int getRequestId() {
|
||||
return requestId;
|
||||
}
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
public Map<String, Object> getDataMap() {
|
||||
return dataMap;
|
||||
}
|
||||
}
|
177
framework/src/org/apache/cordova/api/Plugin.java
Executable file
177
framework/src/org/apache/cordova/api/Plugin.java
Executable file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Legacy Plugin class. This acts as a shim to support the old execute() signature.
|
||||
* New plugins should extend CordovaPlugin directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class Plugin extends CordovaPlugin {
|
||||
public LegacyContext ctx; // LegacyContext object
|
||||
|
||||
public abstract PluginResult execute(String action, JSONArray args, String callbackId);
|
||||
|
||||
public boolean isSynch(String action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
this.setContext(cordova);
|
||||
this.setView(webView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the context of the Plugin. This can then be used to do things like
|
||||
* get file paths associated with the Activity.
|
||||
*
|
||||
* @param ctx The context of the main Activity.
|
||||
*/
|
||||
public void setContext(CordovaInterface ctx) {
|
||||
this.cordova = ctx;
|
||||
this.ctx = new LegacyContext(cordova);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the main View of the application, this is the WebView within which
|
||||
* a Cordova app runs.
|
||||
*
|
||||
* @param webView The Cordova WebView
|
||||
*/
|
||||
public void setView(CordovaWebView webView) {
|
||||
this.webView = webView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
||||
final String callbackId = callbackContext.getCallbackId();
|
||||
boolean runAsync = !isSynch(action);
|
||||
if (runAsync) {
|
||||
// Run this on a different thread so that this one can return back to JS
|
||||
cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
PluginResult cr;
|
||||
try {
|
||||
cr = execute(action, args, callbackId);
|
||||
} catch (Throwable e) {
|
||||
cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
||||
}
|
||||
sendPluginResult(cr, callbackId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PluginResult cr = execute(action, args, callbackId);
|
||||
|
||||
// Interpret a null response as NO_RESULT, which *does* clear the callbacks on the JS side.
|
||||
if (cr == null) {
|
||||
cr = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
}
|
||||
|
||||
callbackContext.sendPluginResult(cr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send generic JavaScript statement back to JavaScript.
|
||||
* sendPluginResult() should be used instead where possible.
|
||||
*/
|
||||
public void sendJavascript(String statement) {
|
||||
this.webView.sendJavascript(statement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send generic JavaScript statement back to JavaScript.
|
||||
*/
|
||||
public void sendPluginResult(PluginResult pluginResult, String callbackId) {
|
||||
this.webView.sendPluginResult(pluginResult, callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the JavaScript success callback for this plugin.
|
||||
*
|
||||
* This can be used if the execute code for the plugin is asynchronous meaning
|
||||
* that execute should return null and the callback from the async operation can
|
||||
* call success(...) or error(...)
|
||||
*
|
||||
* @param pluginResult The result to return.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void success(PluginResult pluginResult, String callbackId) {
|
||||
this.webView.sendPluginResult(pluginResult, callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for success callbacks that just returns the Status.OK by default
|
||||
*
|
||||
* @param message The message to add to the success result.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void success(JSONObject message, String callbackId) {
|
||||
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.OK, message), callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for success callbacks that just returns the Status.OK by default
|
||||
*
|
||||
* @param message The message to add to the success result.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void success(String message, String callbackId) {
|
||||
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.OK, message), callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the JavaScript error callback for this plugin.
|
||||
*
|
||||
* @param pluginResult The result to return.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void error(PluginResult pluginResult, String callbackId) {
|
||||
this.webView.sendPluginResult(pluginResult, callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for error callbacks that just returns the Status.ERROR by default
|
||||
*
|
||||
* @param message The message to add to the error result.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void error(JSONObject message, String callbackId) {
|
||||
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message), callbackId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for error callbacks that just returns the Status.ERROR by default
|
||||
*
|
||||
* @param message The message to add to the error result.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
*/
|
||||
public void error(String message, String callbackId) {
|
||||
this.webView.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message), callbackId);
|
||||
}
|
||||
|
||||
}
|
@ -54,7 +54,6 @@ public class PluginManager {
|
||||
// Map URL schemes like foo: to plugins that want to handle those schemes
|
||||
// This would allow how all URLs are handled to be offloaded to a plugin
|
||||
protected HashMap<String, String> urlMap = new HashMap<String, String>();
|
||||
private int MAX_REPITIONS = 1000;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -401,32 +400,4 @@ public class PluginManager {
|
||||
LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml");
|
||||
LOG.e(TAG, "=====================================================================================");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the any resource is going to be loaded - either from the webview, files or any other resource
|
||||
*
|
||||
*
|
||||
* @param dataResource The resource request to be loaded.
|
||||
* @param dataResourceContext The context of the dataResource request
|
||||
* @return Return the resource request that will be loaded. The returned request may be modified or unchanged.
|
||||
*/
|
||||
public DataResource handleDataResourceRequestWithPlugins(DataResource dataResource, DataResourceContext dataResourceContext){
|
||||
int repetitions = 0;
|
||||
boolean requestModified = true;
|
||||
while(requestModified && repetitions < MAX_REPITIONS) {
|
||||
requestModified = false;
|
||||
repetitions ++;
|
||||
for (PluginEntry entry : this.entries.values()) {
|
||||
if (entry.plugin != null) {
|
||||
DataResource ret = entry.plugin.handleDataResourceRequest(dataResource, dataResourceContext);
|
||||
if(ret != null) {
|
||||
dataResource = ret;
|
||||
requestModified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataResource;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,23 @@
|
||||
<!--
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
-->
|
||||
# Android Native Tests #
|
||||
|
||||
These tests are designed to verify Android native features and other Android specific features.
|
||||
|
@ -1,4 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
<widget xmlns = "http://www.w3.org/ns/widgets"
|
||||
id = "io.cordova.helloCordova"
|
||||
version = "2.0.0">
|
||||
|
Loading…
Reference in New Issue
Block a user