Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-android into CordovaActivity

This commit is contained in:
Joe Bowser 2013-01-10 16:26:24 -08:00
commit 6db9a7cb12
18 changed files with 490 additions and 457 deletions

View File

@ -29,11 +29,11 @@ Building
To create your cordova.jar, copy the commons codec: To create your cordova.jar, copy the commons codec:
mv commons-codec-1.6.jar framework/libs mv commons-codec-1.7.jar framework/libs
then run in the framework directory: then run in the framework directory:
android update project -p . -t android-16 android update project -p . -t android-17
ant jar ant jar

View File

@ -1 +1 @@
2.3.0rc1 2.3.0

View File

@ -23,7 +23,7 @@
# #
set -e set -e
if [ -n "$1" ] && [ "$1" == "-h" ] if [ -z "$1" ] || [ "$1" == "-h" ]
then then
echo 'usage: create path package activity' echo 'usage: create path package activity'
echo "Make sure the Android SDK tools folder is in your PATH!" echo "Make sure the Android SDK tools folder is in your PATH!"

View File

@ -33,7 +33,7 @@
<p class="event received">Device is Ready</p> <p class="event received">Device is Ready</p>
</div> </div>
</div> </div>
<script type="text/javascript" src="cordova-2.3.0rc1.js"></script> <script type="text/javascript" src="cordova-2.3.0.js"></script>
<script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript"> <script type="text/javascript">
app.initialize(); app.initialize();

View File

@ -1,6 +1,6 @@
// commit 54335c8f70223b053f4c039185d13cb95801d043 // commit 4082ee0ba3a8902cba7bd087d0584bb7534e694b
// File generated at :: Mon Nov 26 2012 16:05:15 GMT-0500 (EST) // File generated at :: Wed Jan 02 2013 16:43:38 GMT-0800 (PST)
/* /*
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one
@ -3323,18 +3323,55 @@ define("cordova/plugin/InAppBrowser", function(require, exports, module) {
var exec = require('cordova/exec'); var exec = require('cordova/exec');
var InAppBrowser = { function InAppBrowser()
open : function(strUrl, strWindowName, strWindowFeatures) { {
exec(null, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); var _channel = require('cordova/channel');
return InAppBrowser; this.channels = {
}, 'loadstart': _channel.create('loadstart'),
close : function() { 'loadstop' : _channel.create('loadstop'),
exec(null, null, "InAppBrowser", "close", []); 'exit' : _channel.create('exit')
};
}
InAppBrowser.prototype._eventHandler = function(event)
{
if (event.type in this.channels) {
this.channels[event.type].fire(event);
} }
}; }
InAppBrowser.open = function(strUrl, strWindowName, strWindowFeatures)
{
var iab = new InAppBrowser();
var cb = function(eventname) {
iab._eventHandler(eventname);
}
exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return iab;
}
InAppBrowser.prototype.close = function(eventname, f)
{
exec(null, null, "InAppBrowser", "close", []);
}
InAppBrowser.prototype.addEventListener = function(eventname, f)
{
if (eventname in this.channels) {
this.channels[eventname].subscribe(f);
}
}
InAppBrowser.prototype.removeEventListener = function(eventname, f)
{
if (eventname in this.channels) {
this.channels[eventname].unsubscribe(f);
}
}
module.exports = InAppBrowser.open; module.exports = InAppBrowser.open;
}); });
// file: lib/common/plugin/LocalFileSystem.js // file: lib/common/plugin/LocalFileSystem.js
@ -6383,12 +6420,12 @@ window.cordova = require('cordova');
// Drop the common globals into the window object, but be nice and don't overwrite anything. // Drop the common globals into the window object, but be nice and don't overwrite anything.
builder.buildIntoButDoNotClobber(base.defaults, context); builder.buildIntoButDoNotClobber(base.defaults, context);
builder.buildIntoAndMerge(base.merges, context);
builder.buildIntoAndClobber(base.clobbers, context); builder.buildIntoAndClobber(base.clobbers, context);
builder.buildIntoAndMerge(base.merges, context);
builder.buildIntoButDoNotClobber(platform.defaults, context); builder.buildIntoButDoNotClobber(platform.defaults, context);
builder.buildIntoAndMerge(platform.merges, context);
builder.buildIntoAndClobber(platform.clobbers, context); builder.buildIntoAndClobber(platform.clobbers, context);
builder.buildIntoAndMerge(platform.merges, context);
// Call the platform-specific initialization // Call the platform-specific initialization
platform.initialize(); platform.initialize();

View File

@ -19,7 +19,7 @@
<html> <html>
<head> <head>
<title></title> <title></title>
<script src="cordova-2.3.0rc1.js"></script> <script src="cordova-2.3.0.js"></script>
</head> </head>
<body> <body>

View File

@ -64,7 +64,7 @@ public class App extends CordovaPlugin {
this.loadUrl(args.getString(0), args.optJSONObject(1)); this.loadUrl(args.getString(0), args.optJSONObject(1));
} }
else if (action.equals("cancelLoadUrl")) { else if (action.equals("cancelLoadUrl")) {
this.cancelLoadUrl(); //this.cancelLoadUrl();
} }
else if (action.equals("clearHistory")) { else if (action.equals("clearHistory")) {
this.clearHistory(); this.clearHistory();
@ -160,14 +160,6 @@ public class App extends CordovaPlugin {
this.webView.showWebPage(url, openExternal, clearHistory, params); this.webView.showWebPage(url, openExternal, clearHistory, params);
} }
/**
* Cancel loadUrl before it has been loaded (Only works on a CordovaInterface class)
*/
@Deprecated
public void cancelLoadUrl() {
this.cordova.cancelLoadUrl();
}
/** /**
* Clear page history for the app. * Clear page history for the app.
*/ */

View File

@ -322,7 +322,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
} }
// If all this is true we shouldn't compress the image. // If all this is true we shouldn't compress the image.
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) { if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 &&
!this.correctOrientation) {
writeUncompressedImage(uri); writeUncompressedImage(uri);
this.callbackContext.success(uri.toString()); this.callbackContext.success(uri.toString());

View File

@ -219,6 +219,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
columnsToFetch.add(ContactsContract.CommonDataKinds.Phone.TYPE); columnsToFetch.add(ContactsContract.CommonDataKinds.Phone.TYPE);
} }
if (isRequired("emails", populate)) { if (isRequired("emails", populate)) {
columnsToFetch.add(ContactsContract.CommonDataKinds.Email._ID);
columnsToFetch.add(ContactsContract.CommonDataKinds.Email.DATA); columnsToFetch.add(ContactsContract.CommonDataKinds.Email.DATA);
columnsToFetch.add(ContactsContract.CommonDataKinds.Email.TYPE); columnsToFetch.add(ContactsContract.CommonDataKinds.Email.TYPE);
} }
@ -1500,7 +1501,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, getJsonString(email, "value")) .withValue(ContactsContract.CommonDataKinds.Email.DATA, getJsonString(email, "value"))
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, getPhoneType(getJsonString(email, "type"))) .withValue(ContactsContract.CommonDataKinds.Email.TYPE, getContactType(getJsonString(email, "type")))
.build()); .build());
} }

View File

@ -296,12 +296,17 @@ public class CordovaChromeClient extends WebChromeClient {
} }
// console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html // console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html
// Expect this to not compile in a future Android release!
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) public void onConsoleMessage(String message, int lineNumber, String sourceID)
{ {
LOG.d(TAG, "%s: Line %d : %s", sourceID, lineNumber, message); //This is only for Android 2.1
super.onConsoleMessage(message, lineNumber, sourceID); if(android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1)
{
LOG.d(TAG, "%s: Line %d : %s", sourceID, lineNumber, message);
super.onConsoleMessage(message, lineNumber, sourceID);
}
} }
@TargetApi(8) @TargetApi(8)

View File

@ -39,7 +39,7 @@ import android.telephony.TelephonyManager;
public class Device extends CordovaPlugin { public class Device extends CordovaPlugin {
public static final String TAG = "Device"; public static final String TAG = "Device";
public static String cordovaVersion = "2.3.0rc1"; // Cordova version public static String cordovaVersion = "2.3.0"; // Cordova version
public static String platform = "Android"; // Device OS public static String platform = "Android"; // Device OS
public static String uuid; // Device UUID public static String uuid; // Device UUID
@ -80,7 +80,7 @@ public class Device extends CordovaPlugin {
r.put("platform", Device.platform); r.put("platform", Device.platform);
r.put("name", this.getProductName()); r.put("name", this.getProductName());
r.put("cordova", Device.cordovaVersion); r.put("cordova", Device.cordovaVersion);
r.put("model", this.getProductName()); r.put("model", this.getModel());
callbackContext.success(r); callbackContext.success(r);
} }
else { else {

View File

@ -1037,12 +1037,9 @@ public class DroidGap extends Activity implements CordovaInterface {
@Override @Override
public boolean onKeyUp(int keyCode, KeyEvent event) public boolean onKeyUp(int keyCode, KeyEvent event)
{ {
//Determine if the focus is on the current view or not //Get whatever has focus!
if (appView.getHitTestResult() != null && View childView = appView.getFocusedChild();
appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE && if ((appView.isCustomViewShowing() || childView != null ) && keyCode == KeyEvent.KEYCODE_BACK) {
(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) {
return appView.onKeyUp(keyCode, event);
} else if (appView.isCustomViewShowing() && keyCode == KeyEvent.KEYCODE_BACK) {
return appView.onKeyUp(keyCode, event); return appView.onKeyUp(keyCode, event);
} else { } else {
return super.onKeyUp(keyCode, event); return super.onKeyUp(keyCode, event);
@ -1059,10 +1056,10 @@ public class DroidGap extends Activity implements CordovaInterface {
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) public boolean onKeyDown(int keyCode, KeyEvent event)
{ {
//Get whatever has focus!
View childView = appView.getFocusedChild();
//Determine if the focus is on the current view or not //Determine if the focus is on the current view or not
if (appView.getHitTestResult() != null && if (childView != null && keyCode == KeyEvent.KEYCODE_BACK) {
appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE &&
keyCode == KeyEvent.KEYCODE_BACK) {
return appView.onKeyDown(keyCode, event); return appView.onKeyDown(keyCode, event);
} }
else else

View File

@ -676,10 +676,11 @@ public class FileTransfer extends CordovaPlugin {
progress.setTotal(connection.getContentLength()); progress.setTotal(connection.getContentLength());
} }
FileOutputStream outputStream = new FileOutputStream(file); FileOutputStream outputStream = null;
InputStream inputStream = null; InputStream inputStream = null;
try { try {
outputStream = new FileOutputStream(file);
inputStream = getInputStream(connection); inputStream = getInputStream(connection);
synchronized (context) { synchronized (context) {
if (context.aborted) { if (context.aborted) {

View File

@ -112,11 +112,29 @@ public class FileUtils extends CordovaPlugin {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
} }
else if (action.equals("readAsText")) { else if (action.equals("readAsText")) {
String s = this.readAsText(args.getString(0), args.getString(1)); int start = 0;
int end = Integer.MAX_VALUE;
if (args.length() >= 3) {
start = args.getInt(2);
}
if (args.length() >= 4) {
end = args.getInt(3);
}
String s = this.readAsText(args.getString(0), args.getString(1), start, end);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s));
} }
else if (action.equals("readAsDataURL")) { else if (action.equals("readAsDataURL")) {
String s = this.readAsDataURL(args.getString(0)); int start = 0;
int end = Integer.MAX_VALUE;
if (args.length() >= 2) {
start = args.getInt(1);
}
if (args.length() >= 3) {
end = args.getInt(2);
}
String s = this.readAsDataURL(args.getString(0), start, end);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s));
} }
else if (action.equals("write")) { else if (action.equals("write")) {
@ -932,17 +950,27 @@ public class FileUtils extends CordovaPlugin {
* @param filename The name of the file. * @param filename The name of the file.
* @param encoding The encoding to return contents as. Typical value is UTF-8. * @param encoding The encoding to return contents as. Typical value is UTF-8.
* (see http://www.iana.org/assignments/character-sets) * (see http://www.iana.org/assignments/character-sets)
* @param start Start position in the file.
* @param end End position to stop at (exclusive).
* @return Contents of file. * @return Contents of file.
* @throws FileNotFoundException, IOException * @throws FileNotFoundException, IOException
*/ */
public String readAsText(String filename, String encoding) throws FileNotFoundException, IOException { public String readAsText(String filename, String encoding, int start, int end) throws FileNotFoundException, IOException {
int diff = end - start;
byte[] bytes = new byte[1000]; byte[] bytes = new byte[1000];
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024); BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
int numRead = 0; int numRead = 0;
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
if (start > 0) {
bis.skip(start);
}
while ( diff > 0 && (numRead = bis.read(bytes, 0, Math.min(1000, diff))) >= 0) {
diff -= numRead;
bos.write(bytes, 0, numRead); bos.write(bytes, 0, numRead);
} }
return new String(bos.toByteArray(), encoding); return new String(bos.toByteArray(), encoding);
} }
@ -953,12 +981,19 @@ public class FileUtils extends CordovaPlugin {
* @return Contents of file = data:<media type>;base64,<data> * @return Contents of file = data:<media type>;base64,<data>
* @throws FileNotFoundException, IOException * @throws FileNotFoundException, IOException
*/ */
public String readAsDataURL(String filename) throws FileNotFoundException, IOException { public String readAsDataURL(String filename, int start, int end) throws FileNotFoundException, IOException {
int diff = end - start;
byte[] bytes = new byte[1000]; byte[] bytes = new byte[1000];
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024); BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
int numRead = 0; int numRead = 0;
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
if (start > 0) {
bis.skip(start);
}
while (diff > 0 && (numRead = bis.read(bytes, 0, Math.min(1000, diff))) >= 0) {
diff -= numRead;
bos.write(bytes, 0, numRead); bos.write(bytes, 0, numRead);
} }
@ -984,15 +1019,21 @@ public class FileUtils extends CordovaPlugin {
* @return a mime type * @return a mime type
*/ */
public static String getMimeType(String filename) { public static String getMimeType(String filename) {
// Stupid bug in getFileExtensionFromUrl when the file name has a space if (filename != null) {
// So we need to replace the space with a url encoded %20 // Stupid bug in getFileExtensionFromUrl when the file name has a space
String url = filename.replace(" ", "%20"); // So we need to replace the space with a url encoded %20
MimeTypeMap map = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(url); // CB-2185: Stupid bug not putting JPG extension in the mime-type map
if (extension.toLowerCase().equals("3ga")) { String url = filename.replace(" ", "%20").toLowerCase();
return "audio/3gpp"; MimeTypeMap map = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension.toLowerCase().equals("3ga")) {
return "audio/3gpp";
} else {
return map.getMimeTypeFromExtension(extension);
}
} else { } else {
return map.getMimeTypeFromExtension(extension); return "";
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.cordova; package org.apache.cordova;
import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -29,12 +28,12 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.text.InputType; import android.text.InputType;
import android.util.Log; import android.util.Log;
@ -56,18 +55,18 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@SuppressLint("SetJavaScriptEnabled")
public class InAppBrowser extends CordovaPlugin { public class InAppBrowser extends CordovaPlugin {
private static final String NULL = "null"; private static final String NULL = "null";
protected static final String LOG_TAG = "InAppBrowser"; protected static final String LOG_TAG = "InAppBrowser";
private static final String SELF = "_self"; private static final String SELF = "_self";
private static final String SYSTEM = "_system"; private static final String SYSTEM = "_system";
private static final String BLANK = "_blank"; // private static final String BLANK = "_blank";
private static final String LOCATION = "location"; private static final String LOCATION = "location";
private static int CLOSE_EVENT = 0; private static final String EXIT_EVENT = "exit";
private static int LOCATION_CHANGED_EVENT = 1; private static final String LOAD_START_EVENT = "loadstart";
private static final String LOAD_STOP_EVENT = "loadstop";
private String browserCallbackId = null;
private Dialog dialog; private Dialog dialog;
private WebView inAppWebView; private WebView inAppWebView;
@ -128,17 +127,16 @@ public class InAppBrowser extends CordovaPlugin {
else if (action.equals("close")) { else if (action.equals("close")) {
closeDialog(); closeDialog();
JSONObject obj = new JSONObject(); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
obj.put("type", CLOSE_EVENT);
PluginResult pluginResult = new PluginResult(status, obj);
pluginResult.setKeepCallback(false); pluginResult.setKeepCallback(false);
this.callbackContext.sendPluginResult(pluginResult); this.callbackContext.sendPluginResult(pluginResult);
} }
else { else {
status = PluginResult.Status.INVALID_ACTION; status = PluginResult.Status.INVALID_ACTION;
} }
this.callbackContext.sendPluginResult(new PluginResult(status, result)); PluginResult pluginResult = new PluginResult(status, result);
pluginResult.setKeepCallback(true);
this.callbackContext.sendPluginResult(pluginResult);
} catch (JSONException e) { } catch (JSONException e) {
this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
} }
@ -208,8 +206,15 @@ public class InAppBrowser extends CordovaPlugin {
* Closes the dialog * Closes the dialog
*/ */
private void closeDialog() { private void closeDialog() {
// TODO: fire 'exit' event try {
this.webView.sendJavascript("cordova.fireWindowEvent('exit');"); JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
if (dialog != null) { if (dialog != null) {
dialog.dismiss(); dialog.dismiss();
} }
@ -301,7 +306,7 @@ public class InAppBrowser extends CordovaPlugin {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
try { try {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("type", CLOSE_EVENT); obj.put("type", EXIT_EVENT);
sendUpdate(obj, false); sendUpdate(obj, false);
} catch (JSONException e) { } catch (JSONException e) {
@ -316,7 +321,7 @@ public class InAppBrowser extends CordovaPlugin {
// Toolbar layout // Toolbar layout
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
toolbar.setHorizontalGravity(Gravity.LEFT); toolbar.setHorizontalGravity(Gravity.LEFT);
toolbar.setVerticalGravity(Gravity.TOP); toolbar.setVerticalGravity(Gravity.TOP);
@ -330,7 +335,7 @@ public class InAppBrowser extends CordovaPlugin {
// Back button // Back button
Button back = new Button(cordova.getActivity()); Button back = new Button(cordova.getActivity());
RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
back.setLayoutParams(backLayoutParams); back.setLayoutParams(backLayoutParams);
back.setContentDescription("Back Button"); back.setContentDescription("Back Button");
@ -344,7 +349,7 @@ public class InAppBrowser extends CordovaPlugin {
// Forward button // Forward button
Button forward = new Button(cordova.getActivity()); Button forward = new Button(cordova.getActivity());
RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
forward.setLayoutParams(forwardLayoutParams); forward.setLayoutParams(forwardLayoutParams);
forward.setContentDescription("Forward Button"); forward.setContentDescription("Forward Button");
@ -358,7 +363,7 @@ public class InAppBrowser extends CordovaPlugin {
// Edit Text Box // Edit Text Box
edittext = new EditText(cordova.getActivity()); edittext = new EditText(cordova.getActivity());
RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
edittext.setLayoutParams(textLayoutParams); edittext.setLayoutParams(textLayoutParams);
@ -381,7 +386,7 @@ public class InAppBrowser extends CordovaPlugin {
// Close button // Close button
Button close = new Button(cordova.getActivity()); Button close = new Button(cordova.getActivity());
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
close.setLayoutParams(closeLayoutParams); close.setLayoutParams(closeLayoutParams);
forward.setContentDescription("Close Button"); forward.setContentDescription("Close Button");
@ -395,7 +400,7 @@ public class InAppBrowser extends CordovaPlugin {
// WebView // WebView
inAppWebView = new WebView(cordova.getActivity()); inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
inAppWebView.setWebChromeClient(new WebChromeClient()); inAppWebView.setWebChromeClient(new WebChromeClient());
WebViewClient client = new InAppBrowserClient(thatWebView, edittext); WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
inAppWebView.setWebViewClient(client); inAppWebView.setWebViewClient(client);
@ -403,7 +408,15 @@ public class InAppBrowser extends CordovaPlugin {
settings.setJavaScriptEnabled(true); settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setBuiltInZoomControls(true); settings.setBuiltInZoomControls(true);
/**
* We need to be careful of this line as a future Android release may deprecate it out of existence.
* Can't replace it with the API 8 level call right now as our minimum SDK is 7 until May 2013
*/
// @TODO: replace with settings.setPluginState(android.webkit.WebSettings.PluginState.ON)
settings.setPluginsEnabled(true); settings.setPluginsEnabled(true);
settings.setDatabaseEnabled(true);
String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
settings.setDatabasePath(databasePath);
settings.setDomStorageEnabled(true); settings.setDomStorageEnabled(true);
inAppWebView.loadUrl(url); inAppWebView.loadUrl(url);
inAppWebView.setId(6); inAppWebView.setId(6);
@ -432,18 +445,13 @@ public class InAppBrowser extends CordovaPlugin {
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes()); lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT;
dialog.setContentView(main); dialog.setContentView(main);
dialog.show(); dialog.show();
dialog.getWindow().setAttributes(lp); dialog.getWindow().setAttributes(lp);
} }
private Bitmap loadDrawable(String filename) throws java.io.IOException {
InputStream input = cordova.getActivity().getAssets().open(filename);
return BitmapFactory.decodeStream(input);
}
}; };
this.cordova.getActivity().runOnUiThread(runnable); this.cordova.getActivity().runOnUiThread(runnable);
return ""; return "";
@ -455,11 +463,9 @@ public class InAppBrowser extends CordovaPlugin {
* @param obj a JSONObject contain event payload information * @param obj a JSONObject contain event payload information
*/ */
private void sendUpdate(JSONObject obj, boolean keepCallback) { private void sendUpdate(JSONObject obj, boolean keepCallback) {
if (this.browserCallbackId != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
PluginResult result = new PluginResult(PluginResult.Status.OK, obj); result.setKeepCallback(keepCallback);
result.setKeepCallback(keepCallback); this.callbackContext.sendPluginResult(result);
this.callbackContext.sendPluginResult(result);
}
} }
/** /**
@ -500,14 +506,29 @@ public class InAppBrowser extends CordovaPlugin {
edittext.setText(newloc); edittext.setText(newloc);
} }
// TODO: Fire 'loadstart' event only on the InAppBrowser object try {
this.webView.sendJavascript("cordova.fireWindowEvent('loadstart', '" + url + "');"); JSONObject obj = new JSONObject();
obj.put("type", LOAD_START_EVENT);
obj.put("url", newloc);
sendUpdate(obj, true);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
} }
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);
// TODO: Fire 'loadstop' event only on the InAppBrowser object
this.webView.sendJavascript("cordova.fireWindowEvent('loadstop', '" + url + "');"); try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_STOP_EVENT);
obj.put("url", url);
sendUpdate(obj, true);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
} }
} }
} }

View File

@ -54,11 +54,6 @@ public interface CordovaInterface {
*/ */
public abstract Activity getActivity(); public abstract Activity getActivity();
@Deprecated
public abstract Context getContext();
@Deprecated
public abstract void cancelLoadUrl();
/** /**
* Called when a message is sent to plugin. * Called when a message is sent to plugin.

View File

@ -43,7 +43,6 @@ public class LegacyContext implements CordovaInterface {
@Deprecated @Deprecated
public void cancelLoadUrl() { public void cancelLoadUrl() {
Log.i(LOG_TAG, "Replace ctx.cancelLoadUrl() with cordova.cancelLoadUrl()"); Log.i(LOG_TAG, "Replace ctx.cancelLoadUrl() with cordova.cancelLoadUrl()");
this.cordova.cancelLoadUrl();
} }
@Deprecated @Deprecated
@ -55,7 +54,7 @@ public class LegacyContext implements CordovaInterface {
@Deprecated @Deprecated
public Context getContext() { public Context getContext() {
Log.i(LOG_TAG, "Replace ctx.getContext() with cordova.getContext()"); Log.i(LOG_TAG, "Replace ctx.getContext() with cordova.getContext()");
return this.cordova.getContext(); return this.cordova.getActivity();
} }
@Deprecated @Deprecated

File diff suppressed because it is too large Load Diff