From e51b4897a34c8d4430ad8036cff86f7fd95747b8 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Thu, 8 Nov 2012 14:01:46 -0500 Subject: [PATCH 01/43] Guard against null mimeType in MediaFile.getFormatData --- framework/src/org/apache/cordova/Capture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java index 4cf46dd5..3eecf379 100644 --- a/framework/src/org/apache/cordova/Capture.java +++ b/framework/src/org/apache/cordova/Capture.java @@ -127,7 +127,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("")) { + if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) { mimeType = FileUtils.getMimeType(filePath); } Log.d(LOG_TAG, "Mime type = " + mimeType); From 1d26239809fa6c32cc1ed293a911110f551d8985 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Fri, 9 Nov 2012 09:28:26 +0200 Subject: [PATCH 02/43] not getting the path correctly if the URI contains a file:// Previous to 2.2 this function was crashing if the URI wasn't different than a 'content://' but still if it is a 'file://' it fails getting the correct path. This happens for example picking a picture from dropbox instead of local gallery. --- framework/src/org/apache/cordova/FileUtils.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 973b820d..46f2e9c3 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -1069,16 +1069,18 @@ public class FileUtils extends CordovaPlugin { */ @SuppressWarnings("deprecation") protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) { - String uri = contentUri.toString(); - if (uri.startsWith("content:")) { + final String scheme = contentUri.getScheme(); + + if (scheme.compareTo("content") == 0) { String[] proj = { _DATA }; Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(_DATA); cursor.moveToFirst(); return cursor.getString(column_index); + } else if (scheme.compareTo("file") == 0) { + return contentUri.getPath(); } else { - return uri; + return contentUri.toString(); } - } } From dc459c84a36f90f2383203ceab56a47341360937 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Fri, 9 Nov 2012 11:28:50 -0500 Subject: [PATCH 03/43] CB-1829: Online/Offline events do not fire on subsequent pages of an app --- framework/src/org/apache/cordova/NetworkManager.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java index 5d879180..af2fc7d3 100755 --- a/framework/src/org/apache/cordova/NetworkManager.java +++ b/framework/src/org/apache/cordova/NetworkManager.java @@ -147,13 +147,6 @@ public class NetworkManager extends CordovaPlugin { } } - /** - * Stop the network receiver on navigation. - */ - public void onReset() { - this.onDestroy(); - } - //-------------------------------------------------------------------------- // LOCAL METHODS //-------------------------------------------------------------------------- From b9ddc9e678e5fdaca6a49fbfaea5e375ac4c3871 Mon Sep 17 00:00:00 2001 From: Iurii Okhmat Date: Fri, 9 Nov 2012 16:40:56 -0800 Subject: [PATCH 04/43] Camera plugin (HTC Incredible) is crashing on 2.3.4 devices without SD card --- .../src/org/apache/cordova/CameraLauncher.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index f9cfb94a..0dc02a4a 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -35,6 +35,7 @@ import org.json.JSONArray; import org.json.JSONException; import android.app.Activity; +import android.content.ContentResolver; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; @@ -289,6 +290,17 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If sending base64 image back if (destType == DATA_URL) { bitmap = getScaledBitmap(FileUtils.stripFileProtocol(imageUri.toString())); + if (bitmap == null) { + // Try to get the bitmap from intent. + bitmap = (Bitmap)intent.getExtras().get("data"); + } + + // Double-check the bitmap. + if (bitmap == null) { + Log.d(LOG_TAG, "I either have a null image path or bitmap"); + this.failPicture("Unable to create bitmap!"); + return; + } if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); @@ -567,6 +579,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight); Bitmap unscaledBitmap = BitmapFactory.decodeFile(imagePath, options); + if (unscaledBitmap == null) { + return null; + } return Bitmap.createScaledBitmap(unscaledBitmap, widthHeight[0], widthHeight[1], true); } From f9a49efae9cfa80fa01c3a52705ea5d66a077b18 Mon Sep 17 00:00:00 2001 From: Iurii Okhmat Date: Fri, 9 Nov 2012 16:44:33 -0800 Subject: [PATCH 05/43] Removed unnecessary import. --- framework/src/org/apache/cordova/CameraLauncher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 0dc02a4a..49a68c03 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -35,7 +35,6 @@ import org.json.JSONArray; import org.json.JSONException; import android.app.Activity; -import android.content.ContentResolver; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; From 4fe73cf6ad5ebeb85f0c5868c12af25b66b6b2a0 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Mon, 12 Nov 2012 10:00:32 -0500 Subject: [PATCH 06/43] CB-1835: Camera.getPicture gives error when get a picture from photo library with spaces in its name on Android --- framework/src/org/apache/cordova/FileUtils.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 46f2e9c3..c2f90b64 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -984,8 +984,11 @@ public class FileUtils extends CordovaPlugin { * @return a mime type */ public static String getMimeType(String filename) { + // Stupid bug in getFileExtensionFromUrl when the file name has a space + // So we need to replace the space with a url encoded %20 + String url = filename.replace(" ", "%20"); MimeTypeMap map = MimeTypeMap.getSingleton(); - return map.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(filename)); + return map.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)); } /** From e95bde62a24557c903234adcef2f8e9c087d5d45 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Mon, 12 Nov 2012 10:22:35 -0500 Subject: [PATCH 07/43] Correctly report the mime type of 3ga files --- framework/src/org/apache/cordova/FileUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index c2f90b64..8aff2629 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -988,7 +988,12 @@ public class FileUtils extends CordovaPlugin { // So we need to replace the space with a url encoded %20 String url = filename.replace(" ", "%20"); MimeTypeMap map = MimeTypeMap.getSingleton(); - return map.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)); + String extension = MimeTypeMap.getFileExtensionFromUrl(url); + if (extension.toLowerCase().equals("3ga")) { + return "audio/3gpp"; + } else { + return map.getMimeTypeFromExtension(extension); + } } /** From 5212cd4dcdc195e96e3b376bd44e162e2b0b1b57 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 13 Nov 2012 12:50:15 -0500 Subject: [PATCH 08/43] Disable JS Interface on Honeycomb Fixes https://issues.apache.org/jira/browse/CB-1818 --- framework/src/org/apache/cordova/CordovaWebView.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 47406101..95890b18 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -274,13 +274,15 @@ public class CordovaWebView extends WebView { } private void exposeJsInterface() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { + int SDK_INT = Build.VERSION.SDK_INT; + boolean isHoneycomb = (SDK_INT >= Build.VERSION_CODES.HONEYCOMB && SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2); + if (isHoneycomb || (SDK_INT < Build.VERSION_CODES.GINGERBREAD)) { Log.i(TAG, "Disabled addJavascriptInterface() bridge since Android version is old."); // Bug being that Java Strings do not get converted to JS strings automatically. // This isn't hard to work-around on the JS side, but it's easier to just // use the prompt bridge instead. return; - } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && Build.MANUFACTURER.equals("unknown")) { + } else if (SDK_INT < Build.VERSION_CODES.HONEYCOMB && Build.MANUFACTURER.equals("unknown")) { // addJavascriptInterface crashes on the 2.3 emulator. Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator"); return; From 5810a96e622e881939190297e463ec37261756b4 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 14 Nov 2012 11:15:22 -0800 Subject: [PATCH 09/43] Adding reflection so that this compiles, need to test against HTC Desire HD 2.3.6 device before resolving CB-1845 --- .../org/apache/cordova/CordovaWebView.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 95890b18..4a23a61d 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -20,6 +20,8 @@ package org.apache.cordova; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -226,11 +228,24 @@ public class CordovaWebView extends WebView { settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); - - //Set the nav dump for HTC 2.x devices (disabling for ICS/Jellybean) - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) - settings.setNavDump(true); + //Set the nav dump for HTC 2.x devices (disabling for ICS, derecated entirely for Jellybean 4.2) + try { + Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class }); + if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) + { + gingerbread_getMethod.invoke(settings, true); + } + } catch (NoSuchMethodException e) { + Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8"); + } catch (IllegalArgumentException e) { + Log.d(TAG, "Doing the NavDump failed with bad arguments"); + } catch (IllegalAccessException e) { + Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore"); + } catch (InvocationTargetException e) { + Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore."); + } + // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) From dfa514334baa8f5989043bc01001bd4ead8527d7 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Wed, 14 Nov 2012 16:05:50 -0500 Subject: [PATCH 10/43] Bumping Android API version to 17 --- framework/project.properties | 2 +- framework/src/org/apache/cordova/CordovaWebView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/project.properties b/framework/project.properties index 4383e57e..d556741d 100644 --- a/framework/project.properties +++ b/framework/project.properties @@ -10,7 +10,7 @@ # Indicates whether an apk should be generated for each density. split.density=false # Project target. -target=Google Inc.:Google APIs:16 +target=Google Inc.:Google APIs:17 apk-configurations= renderscript.opt.level=O0 android.library=true diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 4a23a61d..1511e302 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -229,7 +229,7 @@ public class CordovaWebView extends WebView { settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); - //Set the nav dump for HTC 2.x devices (disabling for ICS, derecated entirely for Jellybean 4.2) + // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2) try { Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class }); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) From 9233c3a89802a13a9a275911e3a46a714d7e67c7 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 14 Nov 2012 13:22:58 -0800 Subject: [PATCH 11/43] Fixing error with the tests, backbuttonmultipage wasn't added --- test/AndroidManifest.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/AndroidManifest.xml b/test/AndroidManifest.xml index e35f6c67..aee2e04f 100755 --- a/test/AndroidManifest.xml +++ b/test/AndroidManifest.xml @@ -255,5 +255,15 @@ + + + + + + From f93c438067a03a181069baf7228b74659bfc1bf7 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Thu, 15 Nov 2012 11:04:50 -0500 Subject: [PATCH 12/43] CB-1860: NPE in onReceivedError with non local errorUrl --- framework/src/org/apache/cordova/DroidGap.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index f504d2ea..7d9b6d12 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -40,7 +40,6 @@ import android.graphics.Color; import android.media.AudioManager; import android.os.Bundle; import android.os.Handler; -import android.util.Log; import android.view.Display; import android.view.KeyEvent; import android.view.Menu; @@ -156,11 +155,6 @@ public class DroidGap extends Activity implements CordovaInterface { private static int ACTIVITY_EXITING = 2; private int activityState = 0; // 0=starting, 1=running (after 1st resume), 2=shutting down - // The base of the initial URL for our app. - // Does not include file name. Ends with / - // ie http://server/path/ - String baseUrl = null; - // Plugin to call when activity result is received protected CordovaPlugin activityResultCallback = null; protected boolean activityResultKeepRunning; @@ -830,7 +824,7 @@ public class DroidGap extends Activity implements CordovaInterface { // If errorUrl specified, then load it final String errorUrl = me.getStringProperty("errorUrl", null); - if ((errorUrl != null) && (errorUrl.startsWith("file://") || errorUrl.indexOf(me.baseUrl) == 0 || this.appView.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) { + if ((errorUrl != null) && (errorUrl.startsWith("file://") || this.appView.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) { // Load URL on UI thread me.runOnUiThread(new Runnable() { From 04b9a0b09eca789a0bbd23e1ea140159599530ec Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 15 Nov 2012 13:47:52 -0800 Subject: [PATCH 13/43] Death to tabs while working on CB-1864 --- .../org/apache/cordova/CordovaWebView.java | 148 +++++++++--------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 1511e302..4777f25a 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -99,8 +99,8 @@ public class CordovaWebView extends WebView { private long lastMenuEventTime = 0; - NativeToJsMessageQueue jsMessageQueue; - ExposedJsApi exposedJsApi; + NativeToJsMessageQueue jsMessageQueue; + ExposedJsApi exposedJsApi; /** custom view created by the browser (a video player for example) */ private View mCustomView; @@ -184,8 +184,8 @@ public class CordovaWebView extends WebView { * @param defStyle * @param privateBrowsing */ - @TargetApi(11) - public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { + @TargetApi(11) + public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) { super(context, attrs, defStyle, privateBrowsing); if (CordovaInterface.class.isInstance(context)) { @@ -249,7 +249,7 @@ public class CordovaWebView extends WebView { // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) - Level16Apis.enableUniversalAccess(settings); + Level16Apis.enableUniversalAccess(settings); // Enable database settings.setDatabaseEnabled(true); String databasePath = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); @@ -285,7 +285,7 @@ public class CordovaWebView extends WebView { } private void updateUserAgentString() { - this.getSettings().getUserAgentString(); + this.getSettings().getUserAgentString(); } private void exposeJsInterface() { @@ -608,7 +608,7 @@ public class CordovaWebView extends WebView { // Check webview first to see if there is a history // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior) if (super.canGoBack()) { - printBackForwardList(); + printBackForwardList(); super.goBack(); return true; @@ -839,27 +839,27 @@ public class CordovaWebView extends WebView { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // A custom view is currently displayed (e.g. playing a video) - if(mCustomView != null) { - this.hideCustomView(); - } else { - // The webview is currently displayed - // If back key is bound, then send event to JavaScript - if (this.bound) { - this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); - return true; - } else { - // If not bound - // Go to previous page in webview if it is possible to go back - if (this.backHistory()) { - return true; - } - // If not, then invoke default behaviour - else { - //this.activityState = ACTIVITY_EXITING; - return false; - } - } - } + if(mCustomView != null) { + this.hideCustomView(); + } else { + // The webview is currently displayed + // If back key is bound, then send event to JavaScript + if (this.bound) { + this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); + return true; + } else { + // If not bound + // Go to previous page in webview if it is possible to go back + if (this.backHistory()) { + return true; + } + // If not, then invoke default behaviour + else { + //this.activityState = ACTIVITY_EXITING; + return false; + } + } + } } // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { @@ -1002,14 +1002,14 @@ public class CordovaWebView extends WebView { } public void printBackForwardList() { - WebBackForwardList currentList = this.copyBackForwardList(); - int currentSize = currentList.getSize(); - for(int i = 0; i < currentSize; ++i) - { - WebHistoryItem item = currentList.getItemAtIndex(i); - String url = item.getUrl(); - LOG.d(TAG, "The URL at index: " + Integer.toString(i) + "is " + url ); - } + WebBackForwardList currentList = this.copyBackForwardList(); + int currentSize = currentList.getSize(); + for(int i = 0; i < currentSize; ++i) + { + WebHistoryItem item = currentList.getItemAtIndex(i); + String url = item.getUrl(); + LOG.d(TAG, "The URL at index: " + Integer.toString(i) + "is " + url ); + } } @@ -1026,8 +1026,8 @@ public class CordovaWebView extends WebView { } public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) { - // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 - Log.d(TAG, "showing Custom View"); + // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 + Log.d(TAG, "showing Custom View"); // if a view already exists then immediately terminate the new one if (mCustomView != null) { callback.onCustomViewHidden(); @@ -1035,46 +1035,46 @@ public class CordovaWebView extends WebView { } // Store the view and its callback for later (to kill it properly) - mCustomView = view; - mCustomViewCallback = callback; - + mCustomView = view; + mCustomViewCallback = callback; + // Add the custom view to its container. - ViewGroup parent = (ViewGroup) this.getParent(); - parent.addView(view, COVER_SCREEN_GRAVITY_CENTER); - - // Hide the content view. - this.setVisibility(View.GONE); - - // Finally show the custom view container. - parent.setVisibility(View.VISIBLE); - parent.bringToFront(); + ViewGroup parent = (ViewGroup) this.getParent(); + parent.addView(view, COVER_SCREEN_GRAVITY_CENTER); + + // Hide the content view. + this.setVisibility(View.GONE); + + // Finally show the custom view container. + parent.setVisibility(View.VISIBLE); + parent.bringToFront(); } - public void hideCustomView() { - // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 - Log.d(TAG, "Hidding Custom View"); - if (mCustomView == null) return; + public void hideCustomView() { + // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 + Log.d(TAG, "Hidding Custom View"); + if (mCustomView == null) return; - // Hide the custom view. - mCustomView.setVisibility(View.GONE); - - // Remove the custom view from its container. - ViewGroup parent = (ViewGroup) this.getParent(); - parent.removeView(mCustomView); - mCustomView = null; - mCustomViewCallback.onCustomViewHidden(); - + // Hide the custom view. + mCustomView.setVisibility(View.GONE); + + // Remove the custom view from its container. + ViewGroup parent = (ViewGroup) this.getParent(); + parent.removeView(mCustomView); + mCustomView = null; + mCustomViewCallback.onCustomViewHidden(); + // Show the content view. this.setVisibility(View.VISIBLE); - } - - /** - * if the video overlay is showing then we need to know - * as it effects back button handling - * - * @return - */ - public boolean isCustomViewShowing() { - return mCustomView != null; - } + } + + /** + * if the video overlay is showing then we need to know + * as it effects back button handling + * + * @return + */ + public boolean isCustomViewShowing() { + return mCustomView != null; + } } From 6c19a440f5d7faa3955e039749a3a907af012acc Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 15 Nov 2012 16:04:09 -0800 Subject: [PATCH 14/43] CB-1864: Figured out how to simulate back button, test both the CordovaWebView back button and the general DroidGap case using the default implementation --- .../cordova/test/BackButtonMultiPageTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java b/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java index fa3e0b04..6d4a7ac8 100644 --- a/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java +++ b/test/src/org/apache/cordova/test/BackButtonMultiPageTest.java @@ -26,6 +26,7 @@ import org.apache.cordova.test.actions.backbuttonmultipage; import android.test.ActivityInstrumentationTestCase2; import android.view.KeyEvent; +import android.view.inputmethod.BaseInputConnection; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -97,6 +98,54 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2 Date: Wed, 14 Nov 2012 21:11:35 -0500 Subject: [PATCH 15/43] Update .gitignore --- .gitignore | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9f90a6b1..e73b34b3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,28 +4,29 @@ gen assets/www/cordova.js framework/assets/www/.tmp* local.properties -framework/proguard.cfg -framework/cordova.jar -framework/cordova-*.jar -framework/phonegap-*.jar +framework/lib +proguard.cfg +proguard.cfg +proguard-project.txt framework/bin framework/test/org/apache/cordova/*.class framework/assets/www/.DS_Store framework/assets/www/cordova-*.js framework/assets/www/phonegap-*.js framework/libs +test/libs example ./test test/bin test/assets/www/.tmp* tmp/** -*.tmp -test/libs/*.jar bin/node_modules .metadata -*.bak tmp/**/* -*.swp Thumbs.db Desktop.ini - +*.tmp +*.bak +*.swp +*.class +*.jar From c416c77d7a53c8efb2275e147c4f91caac71a334 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Mon, 19 Nov 2012 10:35:47 -0800 Subject: [PATCH 16/43] Fix for CB-1879 by Tom Clarkson. Hacked in due to lack of pull request --- framework/src/org/apache/cordova/CordovaWebView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index 4777f25a..efd3cf89 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -302,6 +302,10 @@ public class CordovaWebView extends WebView { Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator"); return; } + else if (SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { + Log.i(TAG, "Disabled addJavascriptInterface() bridge callback for 4.2. Symbols are broken, and we can't compile the annotation needed to expose the exec."); + return; + } this.addJavascriptInterface(exposedJsApi, "_cordovaNative"); } From df90bdb3504995293995e043a674250021457401 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Mon, 19 Nov 2012 10:36:26 -0800 Subject: [PATCH 17/43] Fixing up the tests so they crash less. --- .../org/apache/cordova/test/CordovaTest.java | 2 ++ .../actions/CordovaWebViewTestActivity.java | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/src/org/apache/cordova/test/CordovaTest.java b/test/src/org/apache/cordova/test/CordovaTest.java index 22c5b4be..8dd409c6 100644 --- a/test/src/org/apache/cordova/test/CordovaTest.java +++ b/test/src/org/apache/cordova/test/CordovaTest.java @@ -49,6 +49,8 @@ public class CordovaTest extends } public void testForCordovaView() { + //Sleep for no reason!!!! + sleep(); String className = testView.getClass().getSimpleName(); assertTrue(className.equals("CordovaWebView")); } diff --git a/test/src/org/apache/cordova/test/actions/CordovaWebViewTestActivity.java b/test/src/org/apache/cordova/test/actions/CordovaWebViewTestActivity.java index 4f832830..ee651906 100644 --- a/test/src/org/apache/cordova/test/actions/CordovaWebViewTestActivity.java +++ b/test/src/org/apache/cordova/test/actions/CordovaWebViewTestActivity.java @@ -25,6 +25,7 @@ import java.util.concurrent.Executors; import org.apache.cordova.CordovaWebView; import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.CordovaPlugin; +import org.apache.cordova.api.LOG; import org.apache.cordova.test.R; import org.apache.cordova.test.R.id; import org.apache.cordova.test.R.layout; @@ -52,14 +53,6 @@ public class CordovaWebViewTestActivity extends Activity implements CordovaInter } - public void onDestroy() - { - super.onDestroy(); - if (cordovaWebView.pluginManager != null) { - cordovaWebView.pluginManager.onDestroy(); - } - } - public Context getContext() { return this; } @@ -95,4 +88,17 @@ public class CordovaWebViewTestActivity extends Activity implements CordovaInter // TODO Auto-generated method stub return threadPool; } + + @Override + /** + * The final call you receive before your activity is destroyed. + */ + public void onDestroy() { + super.onDestroy(); + if (cordovaWebView != null) { + // Send destroy event to JavaScript + cordovaWebView.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};"); + cordovaWebView.handleDestroy(); + } + } } \ No newline at end of file From 28ef7659137f00571f52eab566340b279031baeb Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Mon, 19 Nov 2012 11:33:21 -0800 Subject: [PATCH 18/43] Upgrading App plugin to CordovaPlugin --- framework/src/org/apache/cordova/App.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 7bdf1166..5433d314 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -19,6 +19,7 @@ package org.apache.cordova; +import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.LOG; import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; @@ -30,7 +31,7 @@ import java.util.HashMap; /** * This class exposes methods in DroidGap that can be called from JavaScript. */ -public class App extends Plugin { +public class App extends CordovaPlugin { /** * Executes the request and returns PluginResult. From 7657faa9c3ba88d9a2ae7660abe14bf91238c96c Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Mon, 19 Nov 2012 13:26:22 -0800 Subject: [PATCH 19/43] CB-1852: Android version of model implemented, too bad it's all code names and not human readable --- framework/src/org/apache/cordova/Device.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/Device.java b/framework/src/org/apache/cordova/Device.java index 6a164740..90a20335 100644 --- a/framework/src/org/apache/cordova/Device.java +++ b/framework/src/org/apache/cordova/Device.java @@ -80,9 +80,7 @@ public class Device extends CordovaPlugin { r.put("platform", Device.platform); r.put("name", this.getProductName()); r.put("cordova", Device.cordovaVersion); - //JSONObject pg = new JSONObject(); - //pg.put("version", Device.CordovaVersion); - //r.put("cordova", pg); + r.put("model", this.getProductName()); callbackContext.success(r); } else { From e1347e434e7bda8e0f0ff98fe22e603237102c1b Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 14:39:33 -0800 Subject: [PATCH 20/43] refactoring android commands --- bin/create | 7 ++-- .../ApplicationInfo/ApplicationInfo.class | Bin 0 -> 2045 bytes bin/templates/cordova/appinfo.jar | Bin 0 -> 1574 bytes bin/templates/cordova/{debug => build} | 2 +- bin/templates/cordova/{BOOM.bat => build.bat} | 2 +- bin/templates/cordova/cordova | 35 +++++++++++++----- bin/templates/cordova/debug.bat | 18 --------- bin/templates/cordova/emulate | 24 ------------ bin/templates/cordova/emulate.bat | 1 - bin/templates/cordova/{BOOM => run} | 2 +- bin/templates/cordova/run.bat | 1 + 11 files changed, 32 insertions(+), 60 deletions(-) create mode 100644 bin/templates/cordova/ApplicationInfo/ApplicationInfo.class create mode 100644 bin/templates/cordova/appinfo.jar rename bin/templates/cordova/{debug => build} (96%) rename bin/templates/cordova/{BOOM.bat => build.bat} (97%) delete mode 100644 bin/templates/cordova/debug.bat delete mode 100755 bin/templates/cordova/emulate delete mode 100644 bin/templates/cordova/emulate.bat rename bin/templates/cordova/{BOOM => run} (96%) create mode 100644 bin/templates/cordova/run.bat diff --git a/bin/create b/bin/create index 1bce739e..903f55ee 100755 --- a/bin/create +++ b/bin/create @@ -147,13 +147,12 @@ replace "s/__ACTIVITY__/${ACTIVITY}/g" "$MANIFEST_PATH" replace "s/__PACKAGE__/${PACKAGE}/g" "$MANIFEST_PATH" replace "s/__APILEVEL__/${API_LEVEL}/g" "$MANIFEST_PATH" -# creating cordova folder and copying emulate/debug/log/launch scripts +# creating cordova folder and copying run/build/log/launch scripts mkdir "$PROJECT_PATH"/cordova createAppInfoJar cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar cp "$BUILD_PATH"/bin/templates/cordova/cordova "$PROJECT_PATH"/cordova/cordova -cp "$BUILD_PATH"/bin/templates/cordova/debug "$PROJECT_PATH"/cordova/debug +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/emulate "$PROJECT_PATH"/cordova/emulate -cp "$BUILD_PATH"/bin/templates/cordova/BOOM "$PROJECT_PATH"/cordova/BOOM +cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class new file mode 100644 index 0000000000000000000000000000000000000000..2ef42a46862f75fffa8b780ff7cc579396224638 GIT binary patch literal 2045 zcma)7TUQ%Z6#h7 z@?0NM&}Em;{w9~Y&m_ni|L_(?$mcNBbpyJEPf;6qHu zF@v0p**N0(NXC7!e-OvVn3FIsW1$O+Sdy_U;h~IAWUMIo6rYJ9uV57g32O>^u`c0r z1t~Fqp%Y0kF7f{pEJvjWt3NS)7asz$IzS3@9F!xR@KdlR`eXhtmK59D@9K) zJzLf7KwZKU30s7eKoUN3Q_~HTp)dWUv$|5We5b^hjllJsZC8zw?irT3V(wU3;ZeoA z7$Ku7zQMODzQa=qbhwR@gt7{b9R|rJ40?sDs9={t)=QqTZ+J&44D3mGrlN`(!!^sP zXa~1TTG^^;OI2RuCNWd>2Gc3JW&HYsA&EBQ8VtYu;S3lH> zbC1uz6Y9XfVQDLCEvKp1s2aC1?;F)JcZj`D&a!2LfE{92#Sy+|NNL%ucHvU9VnxQuR& zAxX*?3^R;e#s(=5|1U^}XmC3WnNEqFZ_Si57-YDo(>Z~yaPLg&Jg-s&wpG0Ofvl(` zKIc&lZTlWY=2k}p7w=biC%vW>cm8NYuM{X_FT6LcS zLV~nfYM^-J2BKlh7j2#4dG;_F(ABL$;)|t-lH)V9A1YaDwozI%3_eICjtHmLiw>e!i9-U9g)@XQ$!hNA_I|R>=aT6 zGtu#+e2T6R!lzI|_yh5z+V~Rt1y_=9M1MzOGdvJ2Zbk-T$?oLUI+Dc`T&tt!82yEb zI{J>$E$04X$YQ?!f^bK$MeVsam@D)`iM>THR49PFjH?80h)!>yi})spWr}#-Bnq=c zVhfX`oxxL#p-k%v#<7bD>fDoLB?}uGJbGI*WMvSMe@HkaVN4=1CSl^Cge?8F2pONm z`;C~8u@L=$(afu#p=82S`C|+`!w1D6Q|( ccn>P332iPwD*SgLr2d5zxhFqUfy(WF0XzW=od5s; literal 0 HcmV?d00001 diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar new file mode 100644 index 0000000000000000000000000000000000000000..31d01d75aa31c5d82b443b37f9eb43de3f694c9d GIT binary patch literal 1574 zcmWIWW@Zs#-~d9+oMJ}?B*4kQ!r%MB z$s^LUwKFWlM4l|ss(7aQI`dP}PqnmXFRh-dh>1sQHmDd)7WQsnt9Z8b>F1)4MT}r~ z#oHQLgaK`h1Y+Fo5(UaS78K-UCMT9;=I43lrRD1-=Oh*v_lCX>mv$BT?;E!}XIopF z`+^AF&@2v>?k(G#HcUW+<-8O4f$?3}!+A~ohJwdcJ{c{0)bUtZ z^83+0jxzGeQHOeZZt|T;j62rU(r#ooF)-kRrk${J;6WuXp=lyt5+V;h=L&MFTeu+p z#HJ?3I}}io`Y}tE*Pm8+%?Y%9EOX=c`23rK7pE?$=-KioASkUh<5sdp;B|ee-ha z^6p)-GrTL55_=~Ic^q<2l-iYO^kv!nE#~2;ro9jO(InV1Z`<2lffsEL8*x8dHdR)ufT%g~R!`$9j;UQ?Y=#4O4gDk?LZXOgeP7pd^T!(z>A!fld|fA|(Eabwzt5La2= zHoem;Gk0&-j=Gwa@wxQg12x0ouVU9dgYyL#gIif=e=>cNwNr8W!q283miFexDGEhZg8zp!jOws-Q))w{fw zp5J8|r=YKuJO7);mA3bSP0_i6F#&-ko2*STZ&D?uyjUmB`<}ufiEbDmgyU4&* z<(h%pHOV!}ETO;FC5l9!2zoB3tZ#Ya!h?&qXDRA4cl>dl?JVS`a_g8%ioDl}i}BqP zJ{#_-pR=!&OHRphPUTPIDLxf@DjFK^8*KQ+l&`j4{?S^sdw%y8EbKh^=!9Zkm&o=H z-;}%_$4b3-Jj$~0EW3y6AHJ3=`zI{=Ad+rlu=B4zs7Rb^rzda0!ocvC9aQu%GKnyt zmZ-4e5>%q10(cP#DqqpHB9~~O@)QAVflRnoq|z1L1Z0PSN 0) { print }}'` + local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device` if [ -z "$devices" ] ; then echo "1" else @@ -37,7 +37,7 @@ function emulate { # Do not launch an emulator if there is already one running or if a device is attached if [ $(check_devices) == 0 ] ; then - echo "Device attached or emulator already running" + # echo "Device attached or emulator already running" return fi @@ -78,25 +78,40 @@ function log { adb logcat } -function debug { +function run { if [ $(check_devices) == 0 ] ; then - ant debug install + clean && emulate && install && launch else - ant debug + build echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/emulate #" + echo "# Plug in your device or launch an emulator with cordova/run #" echo "##################################################################" fi } +function install { + ant debug install +} + +function build { + ant debug +} + +function wait_for_device { + local i=0 + echo "Waiting for emulator..." + while [ check_devices -eq 0 || timeout -lt 300 ] + do + sleep 1 + i=$[i+1] + end + +} + function launch { local launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml) adb shell am start -n $launch_str } -function BOOM { - clean && debug && launch -} - # TODO parse arguments (cd "$PROJECT_PATH" && $1) diff --git a/bin/templates/cordova/debug.bat b/bin/templates/cordova/debug.bat deleted file mode 100644 index f980eb72..00000000 --- a/bin/templates/cordova/debug.bat +++ /dev/null @@ -1,18 +0,0 @@ -:: 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. - -%~dp0\cordova.bat debug diff --git a/bin/templates/cordova/emulate b/bin/templates/cordova/emulate deleted file mode 100755 index fe27b2f3..00000000 --- a/bin/templates/cordova/emulate +++ /dev/null @@ -1,24 +0,0 @@ -# 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. - -#!/bin/bash - -set -e - -CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) - -bash "$CORDOVA_PATH"/cordova emulate diff --git a/bin/templates/cordova/emulate.bat b/bin/templates/cordova/emulate.bat deleted file mode 100644 index 87ef969f..00000000 --- a/bin/templates/cordova/emulate.bat +++ /dev/null @@ -1 +0,0 @@ -%~dp0\cordova.bat emulate diff --git a/bin/templates/cordova/BOOM b/bin/templates/cordova/run similarity index 96% rename from bin/templates/cordova/BOOM rename to bin/templates/cordova/run index 443502d8..840a8d5a 100755 --- a/bin/templates/cordova/BOOM +++ b/bin/templates/cordova/run @@ -21,4 +21,4 @@ set -e CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) -bash $CORDOVA_PATH/cordova BOOM +bash "$CORDOVA_PATH"/cordova run diff --git a/bin/templates/cordova/run.bat b/bin/templates/cordova/run.bat new file mode 100644 index 00000000..7c470ed8 --- /dev/null +++ b/bin/templates/cordova/run.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat run From 3f3a0b9140be5b07264fb33bf0a4a76348178679 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 14:49:49 -0800 Subject: [PATCH 21/43] adding install function --- bin/templates/cordova/cordova | 76 ++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 561663b5..759f5905 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -17,11 +17,11 @@ #!/bin/bash -set -e PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd ) function check_devices { +# FIXME local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device` if [ -z "$devices" ] ; then echo "1" @@ -37,7 +37,6 @@ function emulate { # Do not launch an emulator if there is already one running or if a device is attached if [ $(check_devices) == 0 ] ; then - # echo "Device attached or emulator already running" return fi @@ -62,8 +61,9 @@ function emulate { do echo "$i) ${avd_list[$i]}" done - echo -n "> " - read avd_id + read -t 5 -p "> " avd_id + # default value if input timeout + if [ $avd_id -eq 1000 ] ; then avd_id=0 ; fi done emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 & fi @@ -79,17 +79,41 @@ function log { } function run { - if [ $(check_devices) == 0 ] ; then - clean && emulate && install && launch - else - build - echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/run #" - echo "##################################################################" - fi + clean && emulate && wait_for_device && install && launch } function install { + + declare -a devices=($(adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device | cut -f 1)) + local device_id="1000" #FIXME: hopefully user does not have 1000 AVDs + + if [ ${#devices[@]} == 0 ] + then + # should not reach here. Emulator should launch or device should be attached + echo "Emulator not running or device not attached. Could not install debug package" + exit 70 + fi + + if [ ${#devices[@]} == 1 ] + then + export ANDROID_SERIAL=${devices[0]} + # User has more than 1 AVD + elif [ ${#devices[@]} -gt 1 ] + then + while [ -z ${devices[$device_id]} ] + do + echo "Choose from one of the following devices/emulators [0 to $((${#devices[@]}-1))]:" + for(( i = 0 ; i < ${#devices[@]} ; i++ )) + do + echo "$i) ${devices[$i]}" + done + read -t 5 -p "> " device_id + # default value if input timeout + if [ $device_id -eq 1000 ] ; then device_id=0 ; fi + done + export ANDROID_SERIAL=${devices[$device_id]} + fi + ant debug install } @@ -98,14 +122,28 @@ function build { } function wait_for_device { - local i=0 - echo "Waiting for emulator..." - while [ check_devices -eq 0 || timeout -lt 300 ] - do - sleep 1 - i=$[i+1] - end + local i="0" + echo -n "Waiting for device..." + while [ $i -lt 300 ] + do + if [ $(check_devices) -eq 0 ] + then + break + else + sleep 1 + i=$[i+1] + echo -n "." + fi + done + # Device timeout: emulator has not started in time or device not attached + if [ $i -eq 300 ] + then + echo "device timeout!" + exit 69 + else + echo "connected!" + fi } function launch { From d9107bcac6e328f4e28298db2f64968416ee4560 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 18:49:16 -0800 Subject: [PATCH 22/43] refactoring windows scripts --- bin/create.js | 5 ++-- bin/templates/cordova/cordova.js | 46 +++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/bin/create.js b/bin/create.js index 2d6b8d61..258c32cd 100644 --- a/bin/create.js +++ b/bin/create.js @@ -198,10 +198,9 @@ exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\appinfo.jar ' + PRO exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.bat /Y'); +exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\build.bat ' + PROJECT_PATH + '\\cordova\\build.bat /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\log.bat ' + PROJECT_PATH + '\\cordova\\log.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y'); +exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\run.bat ' + PROJECT_PATH + '\\cordova\\run.bat /Y'); // interpolate the activity name and package WScript.Echo("Updating AndroidManifest.xml and Main Activity..."); diff --git a/bin/templates/cordova/cordova.js b/bin/templates/cordova/cordova.js index ff91430b..51533cb9 100644 --- a/bin/templates/cordova/cordova.js +++ b/bin/templates/cordova/cordova.js @@ -34,17 +34,19 @@ function exec(command) { return output; } -function emulator_running() { +function device_running() { var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll(); - if(local_devices.match(/emulator/)) { + if(local_devices.match(/\w+\tdevice/)) { + WScript.Echo("Yes"); return true; } + WScript.Echo("No"); return false; } function emulate() { // don't run emulator if a device is plugged in or if emulator is already running - if(emulator_running()) { - WScript.Echo("Device or Emulator already running!"); + if(device_running()) { + //WScript.Echo("Device or Emulator already running!"); return; } var oExec = shell.Exec("%comspec% /c android.bat list avd"); @@ -84,18 +86,18 @@ function emulate() { } function clean() { + WScript.Echo("Cleaning project..."); exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1"); } -function debug() { - if(emulator_running()) { - exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); - } else { - exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); - WScript.Echo("##################################################################"); - WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #"); - WScript.Echo("##################################################################"); - } +function build() { + WScript.Echo("Building project..."); + exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); +} + +function install() { + WScript.Echo("Building/Installing project..."); + exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); } function log() { @@ -103,14 +105,28 @@ function log() { } function launch() { + WScript.Echo("Launching app..."); var launch_str=exec("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml"); //WScript.Echo(launch_str); exec("%comspec% /c adb shell am start -n "+launch_str+" 2>&1"); } -function BOOM() { +function run() { + var i=0; clean(); - debug(); + emulate(); + WScript.Stdout.Write('Waiting for device...'); + while(!device_running() && i < 300) { + WScript.Stdout.Write('.'); + WScript.sleep(1000); + i += 1; + } + if(i == 300) { + WScript.Stderr.WriteLine("device/emulator timeout!"); + } else { + WScript.Stdout.WriteLine("connected!"); + } + install(); launch(); } var args = WScript.Arguments; From 538e90f23aaeebe4cc08ad87d17d0ab2dde6185d Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Wed, 21 Nov 2012 11:27:25 -0500 Subject: [PATCH 23/43] CB-1888: Can't add a Photo from a HTTPS address to Contact --- framework/src/org/apache/cordova/ContactAccessorSdk5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/ContactAccessorSdk5.java b/framework/src/org/apache/cordova/ContactAccessorSdk5.java index 8497135e..73d05bc0 100644 --- a/framework/src/org/apache/cordova/ContactAccessorSdk5.java +++ b/framework/src/org/apache/cordova/ContactAccessorSdk5.java @@ -1579,7 +1579,7 @@ public class ContactAccessorSdk5 extends ContactAccessor { Uri uri = Uri.parse(path); return mApp.getActivity().getContentResolver().openInputStream(uri); } - if (path.startsWith("http:") || path.startsWith("file:")) { + if (path.startsWith("http:") || path.startsWith("https:") || path.startsWith("file:")) { URL url = new URL(path); return url.openStream(); } From 54979f2fc4192be020554f32e810919070362d5f Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 13:33:09 -0800 Subject: [PATCH 24/43] removing appinfo.jar --- bin/templates/cordova/appinfo.jar | Bin 1574 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bin/templates/cordova/appinfo.jar diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar deleted file mode 100644 index 31d01d75aa31c5d82b443b37f9eb43de3f694c9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1574 zcmWIWW@Zs#-~d9+oMJ}?B*4kQ!r%MB z$s^LUwKFWlM4l|ss(7aQI`dP}PqnmXFRh-dh>1sQHmDd)7WQsnt9Z8b>F1)4MT}r~ z#oHQLgaK`h1Y+Fo5(UaS78K-UCMT9;=I43lrRD1-=Oh*v_lCX>mv$BT?;E!}XIopF z`+^AF&@2v>?k(G#HcUW+<-8O4f$?3}!+A~ohJwdcJ{c{0)bUtZ z^83+0jxzGeQHOeZZt|T;j62rU(r#ooF)-kRrk${J;6WuXp=lyt5+V;h=L&MFTeu+p z#HJ?3I}}io`Y}tE*Pm8+%?Y%9EOX=c`23rK7pE?$=-KioASkUh<5sdp;B|ee-ha z^6p)-GrTL55_=~Ic^q<2l-iYO^kv!nE#~2;ro9jO(InV1Z`<2lffsEL8*x8dHdR)ufT%g~R!`$9j;UQ?Y=#4O4gDk?LZXOgeP7pd^T!(z>A!fld|fA|(Eabwzt5La2= zHoem;Gk0&-j=Gwa@wxQg12x0ouVU9dgYyL#gIif=e=>cNwNr8W!q283miFexDGEhZg8zp!jOws-Q))w{fw zp5J8|r=YKuJO7);mA3bSP0_i6F#&-ko2*STZ&D?uyjUmB`<}ufiEbDmgyU4&* z<(h%pHOV!}ETO;FC5l9!2zoB3tZ#Ya!h?&qXDRA4cl>dl?JVS`a_g8%ioDl}i}BqP zJ{#_-pR=!&OHRphPUTPIDLxf@DjFK^8*KQ+l&`j4{?S^sdw%y8EbKh^=!9Zkm&o=H z-;}%_$4b3-Jj$~0EW3y6AHJ3=`zI{=Ad+rlu=B4zs7Rb^rzda0!ocvC9aQu%GKnyt zmZ-4e5>%q10(cP#DqqpHB9~~O@)QAVflRnoq|z1L1Z0PSN Date: Wed, 21 Nov 2012 13:37:19 -0800 Subject: [PATCH 25/43] removing ApplicationInfo.class --- .../ApplicationInfo/ApplicationInfo.class | Bin 2045 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bin/templates/cordova/ApplicationInfo/ApplicationInfo.class diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class deleted file mode 100644 index 2ef42a46862f75fffa8b780ff7cc579396224638..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2045 zcma)7TUQ%Z6#h7 z@?0NM&}Em;{w9~Y&m_ni|L_(?$mcNBbpyJEPf;6qHu zF@v0p**N0(NXC7!e-OvVn3FIsW1$O+Sdy_U;h~IAWUMIo6rYJ9uV57g32O>^u`c0r z1t~Fqp%Y0kF7f{pEJvjWt3NS)7asz$IzS3@9F!xR@KdlR`eXhtmK59D@9K) zJzLf7KwZKU30s7eKoUN3Q_~HTp)dWUv$|5We5b^hjllJsZC8zw?irT3V(wU3;ZeoA z7$Ku7zQMODzQa=qbhwR@gt7{b9R|rJ40?sDs9={t)=QqTZ+J&44D3mGrlN`(!!^sP zXa~1TTG^^;OI2RuCNWd>2Gc3JW&HYsA&EBQ8VtYu;S3lH> zbC1uz6Y9XfVQDLCEvKp1s2aC1?;F)JcZj`D&a!2LfE{92#Sy+|NNL%ucHvU9VnxQuR& zAxX*?3^R;e#s(=5|1U^}XmC3WnNEqFZ_Si57-YDo(>Z~yaPLg&Jg-s&wpG0Ofvl(` zKIc&lZTlWY=2k}p7w=biC%vW>cm8NYuM{X_FT6LcS zLV~nfYM^-J2BKlh7j2#4dG;_F(ABL$;)|t-lH)V9A1YaDwozI%3_eICjtHmLiw>e!i9-U9g)@XQ$!hNA_I|R>=aT6 zGtu#+e2T6R!lzI|_yh5z+V~Rt1y_=9M1MzOGdvJ2Zbk-T$?oLUI+Dc`T&tt!82yEb zI{J>$E$04X$YQ?!f^bK$MeVsam@D)`iM>THR49PFjH?80h)!>yi})spWr}#-Bnq=c zVhfX`oxxL#p-k%v#<7bD>fDoLB?}uGJbGI*WMvSMe@HkaVN4=1CSl^Cge?8F2pONm z`;C~8u@L=$(afu#p=82S`C|+`!w1D6Q|( ccn>P332iPwD*SgLr2d5zxhFqUfy(WF0XzW=od5s; From 08a190ef5bab924659f948d9be72c2245ebb9b04 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 16:35:16 -0800 Subject: [PATCH 26/43] adding release command --- bin/templates/cordova/cordova | 4 ++++ bin/templates/cordova/release | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 bin/templates/cordova/release diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 759f5905..1945a4c4 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -121,6 +121,10 @@ function build { ant debug } +function release { + ant release +} + function wait_for_device { local i="0" echo -n "Waiting for device..." diff --git a/bin/templates/cordova/release b/bin/templates/cordova/release new file mode 100755 index 00000000..73d873e3 --- /dev/null +++ b/bin/templates/cordova/release @@ -0,0 +1,24 @@ +# 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. + +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash "$CORDOVA_PATH"/cordova release From 92d69e320f29767a07b8bc74a42146a72742bdee Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 16:35:27 -0800 Subject: [PATCH 27/43] updating create command --- bin/create | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/create b/bin/create index 903f55ee..e01cef98 100755 --- a/bin/create +++ b/bin/create @@ -153,6 +153,7 @@ createAppInfoJar cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar cp "$BUILD_PATH"/bin/templates/cordova/cordova "$PROJECT_PATH"/cordova/cordova cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build +cp "$BUILD_PATH"/bin/templates/cordova/release "$PROJECT_PATH"/cordova/release 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 From 3566154cd02b10cc1fb5dde39db30a02dc56a953 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 22 Nov 2012 12:39:18 -0500 Subject: [PATCH 28/43] Add @JavascriptInterface annotations to ExposedJsApi. And re-enable the JS bridge on 4.2. https://issues.apache.org/jira/browse/CB-1879 --- framework/src/org/apache/cordova/CordovaWebView.java | 4 ---- framework/src/org/apache/cordova/ExposedJsApi.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index efd3cf89..4777f25a 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -302,10 +302,6 @@ public class CordovaWebView extends WebView { Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator"); return; } - else if (SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { - Log.i(TAG, "Disabled addJavascriptInterface() bridge callback for 4.2. Symbols are broken, and we can't compile the annotation needed to expose the exec."); - return; - } this.addJavascriptInterface(exposedJsApi, "_cordovaNative"); } diff --git a/framework/src/org/apache/cordova/ExposedJsApi.java b/framework/src/org/apache/cordova/ExposedJsApi.java index b386a402..a36bb62b 100755 --- a/framework/src/org/apache/cordova/ExposedJsApi.java +++ b/framework/src/org/apache/cordova/ExposedJsApi.java @@ -18,6 +18,7 @@ */ package org.apache.cordova; +import android.webkit.JavascriptInterface; import org.apache.cordova.api.PluginManager; import org.apache.cordova.api.PluginResult; import org.json.JSONException; @@ -37,6 +38,7 @@ import org.json.JSONException; this.jsMessageQueue = jsMessageQueue; } + @JavascriptInterface public String exec(String service, String action, String callbackId, String arguments) throws JSONException { jsMessageQueue.setPaused(true); try { @@ -51,10 +53,12 @@ import org.json.JSONException; } } + @JavascriptInterface public void setNativeToJsBridgeMode(int value) { jsMessageQueue.setBridgeMode(value); } + @JavascriptInterface public String retrieveJsMessages() { return jsMessageQueue.popAndEncode(); } From a87825dbeebed27381836c2ee1615e1673055313 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Thu, 22 Nov 2012 12:54:53 -0500 Subject: [PATCH 29/43] CB-1508: Implement InAppBrowser feature Initial checkin. Need to clean up the UI and add eventing. --- framework/res/xml/config.xml | 1 + .../src/org/apache/cordova/InAppBrowser.java | 515 ++++++++++++++++++ 2 files changed, 516 insertions(+) create mode 100644 framework/src/org/apache/cordova/InAppBrowser.java diff --git a/framework/res/xml/config.xml b/framework/res/xml/config.xml index da9c1f46..b6900078 100644 --- a/framework/res/xml/config.xml +++ b/framework/res/xml/config.xml @@ -51,6 +51,7 @@ + diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java new file mode 100644 index 00000000..9b747d3a --- /dev/null +++ b/framework/src/org/apache/cordova/InAppBrowser.java @@ -0,0 +1,515 @@ +/* + 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.io.InputStream; +import java.util.HashMap; +import java.util.StringTokenizer; + +import org.apache.cordova.api.CallbackContext; +import org.apache.cordova.api.CordovaPlugin; +import org.apache.cordova.api.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.text.InputType; +import android.util.Log; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.view.WindowManager.LayoutParams; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; + +public class InAppBrowser extends CordovaPlugin { + + private static final String NULL = "null"; + protected static final String LOG_TAG = "InAppBrowser"; + private static final String SELF = "_self"; + private static final String SYSTEM = "_system"; + private static final String BLANK = "_blank"; + private static final String LOCATION = "location"; + private static int CLOSE_EVENT = 0; + private static int LOCATION_CHANGED_EVENT = 1; + + private String browserCallbackId = null; + + private Dialog dialog; + private WebView inAppWebView; + private EditText edittext; + private boolean showLocationBar = true; + private CallbackContext callbackContext; + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackId The callback id used when calling back into JavaScript. + * @return A PluginResult object with a status and message. + */ + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + PluginResult.Status status = PluginResult.Status.OK; + String result = ""; + this.callbackContext = callbackContext; + + try { + if (action.equals("open")) { + String url = args.getString(0); + String target = args.optString(1); + if (target == null || target.equals("") || target.equals(NULL)) { + target = SELF; + } + HashMap features = parseFeature(args.optString(2)); + + Log.d(LOG_TAG, "target = " + target); + + url = updateUrl(url); + + // SELF + if (SELF.equals(target)) { + Log.d(LOG_TAG, "in self"); + // load in webview + if (url.startsWith("file://") || url.startsWith("javascript:") + || this.webView.isUrlWhiteListed(url)) { + this.webView.loadUrl(url); + } + // load in InAppBrowser + else { + result = this.showWebPage(url, features); + } + } + // SYSTEM + else if (SYSTEM.equals(target)) { + Log.d(LOG_TAG, "in system"); + result = this.openExternal(url); + } + // BLANK - or anything else + else { + Log.d(LOG_TAG, "in blank"); + result = this.showWebPage(url, features); + } + } + else if (action.equals("close")) { + closeDialog(); + + JSONObject obj = new JSONObject(); + obj.put("type", CLOSE_EVENT); + + PluginResult pluginResult = new PluginResult(status, obj); + pluginResult.setKeepCallback(false); + this.callbackContext.sendPluginResult(pluginResult); + } + else { + status = PluginResult.Status.INVALID_ACTION; + } + this.callbackContext.sendPluginResult(new PluginResult(status, result)); + } catch (JSONException e) { + this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + } + return true; + } + + /** + * Put the list of features into a hash map + * + * @param optString + * @return + */ + private HashMap parseFeature(String optString) { + if (optString.equals(NULL)) { + return null; + } else { + HashMap map = new HashMap(); + StringTokenizer features = new StringTokenizer(optString, ","); + StringTokenizer option; + while(features.hasMoreElements()) { + option = new StringTokenizer(features.nextToken(), "="); + if (option.hasMoreElements()) { + String key = option.nextToken(); + Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE; + map.put(key, value); + } + } + return map; + } + } + + /** + * Convert relative URL to full path + * + * @param url + * @return + */ + private String updateUrl(String url) { + Uri newUrl = Uri.parse(url); + if (newUrl.isRelative()) { + url = this.webView.getUrl().substring(0, this.webView.getUrl().lastIndexOf("/")+1) + url; + } + return url; + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param usePhoneGap Load url in PhoneGap webview + * @return "" if ok, or error message. + */ + public String openExternal(String url) { + try { + Intent intent = null; + intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + this.cordova.getActivity().startActivity(intent); + return ""; + } catch (android.content.ActivityNotFoundException e) { + Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); + return e.toString(); + } + } + + /** + * Closes the dialog + */ + private void closeDialog() { + // TODO: fire 'exit' event + if (dialog != null) { + dialog.dismiss(); + } + } + + /** + * Checks to see if it is possible to go back one page in history, then does so. + */ + private void goBack() { + if (this.inAppWebView.canGoBack()) { + this.inAppWebView.goBack(); + } + } + + /** + * Checks to see if it is possible to go forward one page in history, then does so. + */ + private void goForward() { + if (this.inAppWebView.canGoForward()) { + this.inAppWebView.goForward(); + } + } + + /** + * Navigate to the new page + * + * @param url to load + */ + private void navigate(String url) { + InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0); + + if (!url.startsWith("http") && !url.startsWith("file:")) { + this.inAppWebView.loadUrl("http://" + url); + } else { + this.inAppWebView.loadUrl(url); + } + this.inAppWebView.requestFocus(); + } + + + /** + * Should we show the location bar? + * + * @return boolean + */ + private boolean getShowLocationBar() { + return this.showLocationBar; + } + + /** + * Display a new browser with the specified URL. + * + * @param url The url to load. + * @param jsonObject + */ + public String showWebPage(final String url, HashMap features) { + // Determine if we should hide the location bar. + showLocationBar = true; + if (features != null) { + showLocationBar = features.get(LOCATION).booleanValue(); + } + + // Create dialog in new thread + Runnable runnable = new Runnable() { + /** + * Convert our DIP units to Pixels + * + * @return int + */ + private int dpToPixels(int dipValue) { + int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, + (float) dipValue, + cordova.getActivity().getResources().getDisplayMetrics() + ); + + return value; + } + + public void run() { + // Let's create the main dialog + dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); + dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + dialog.setCancelable(true); + dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + public void onDismiss(DialogInterface dialog) { + try { + JSONObject obj = new JSONObject(); + obj.put("type", CLOSE_EVENT); + + sendUpdate(obj, false); + } catch (JSONException e) { + Log.d(LOG_TAG, "Should never happen"); + } + } + }); + + // Main container layout + LinearLayout main = new LinearLayout(cordova.getActivity()); + main.setOrientation(LinearLayout.VERTICAL); + + // Toolbar layout + RelativeLayout toolbar = new RelativeLayout(cordova.getActivity()); + toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44))); + toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); + toolbar.setHorizontalGravity(Gravity.LEFT); + toolbar.setVerticalGravity(Gravity.TOP); + + // Action Button Container layout + RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); + actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + actionButtonContainer.setHorizontalGravity(Gravity.LEFT); + actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); + actionButtonContainer.setId(1); + + // Back button + Button back = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); + backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); + back.setLayoutParams(backLayoutParams); + back.setContentDescription("Back Button"); + back.setId(2); + back.setText("<"); + back.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goBack(); + } + }); + + // Forward button + Button forward = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); + forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); + forward.setLayoutParams(forwardLayoutParams); + forward.setContentDescription("Forward Button"); + forward.setId(3); + forward.setText(">"); + forward.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + goForward(); + } + }); + + // Edit Text Box + edittext = new EditText(cordova.getActivity()); + RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); + textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1); + textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5); + edittext.setLayoutParams(textLayoutParams); + edittext.setId(4); + edittext.setSingleLine(true); + edittext.setText(url); + edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI); + edittext.setImeOptions(EditorInfo.IME_ACTION_GO); + edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE + edittext.setOnKeyListener(new View.OnKeyListener() { + public boolean onKey(View v, int keyCode, KeyEvent event) { + // If the event is a key-down event on the "enter" button + if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + navigate(edittext.getText().toString()); + return true; + } + return false; + } + }); + + // Close button + Button close = new Button(cordova.getActivity()); + RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); + closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + close.setLayoutParams(closeLayoutParams); + forward.setContentDescription("Close Button"); + close.setId(5); + close.setText("Done"); + close.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + closeDialog(); + } + }); + + // WebView + inAppWebView = new WebView(cordova.getActivity()); + inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); + inAppWebView.setWebChromeClient(new WebChromeClient()); + WebViewClient client = new InAppBrowserClient(edittext); + inAppWebView.setWebViewClient(client); + WebSettings settings = inAppWebView.getSettings(); + settings.setJavaScriptEnabled(true); + settings.setJavaScriptCanOpenWindowsAutomatically(true); + settings.setBuiltInZoomControls(true); + settings.setPluginsEnabled(true); + settings.setDomStorageEnabled(true); + inAppWebView.loadUrl(url); + inAppWebView.setId(6); + inAppWebView.getSettings().setLoadWithOverviewMode(true); + inAppWebView.getSettings().setUseWideViewPort(true); + inAppWebView.requestFocus(); + inAppWebView.requestFocusFromTouch(); + + // Add the back and forward buttons to our action button container layout + actionButtonContainer.addView(back); + actionButtonContainer.addView(forward); + + // Add the views to our toolbar + toolbar.addView(actionButtonContainer); + toolbar.addView(edittext); + toolbar.addView(close); + + // Don't add the toolbar if its been disabled + if (getShowLocationBar()) { + // Add our toolbar to our main view/layout + main.addView(toolbar); + } + + // Add our webview to our main view/layout + main.addView(inAppWebView); + + WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); + lp.copyFrom(dialog.getWindow().getAttributes()); + lp.width = WindowManager.LayoutParams.FILL_PARENT; + lp.height = WindowManager.LayoutParams.FILL_PARENT; + + dialog.setContentView(main); + dialog.show(); + 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); + return ""; + } + + /** + * Create a new plugin result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + */ + private void sendUpdate(JSONObject obj, boolean keepCallback) { + if (this.browserCallbackId != null) { + PluginResult result = new PluginResult(PluginResult.Status.OK, obj); + result.setKeepCallback(keepCallback); + this.callbackContext.sendPluginResult(result); + } + } + + /** + * The webview client receives notifications about appView + */ + public class InAppBrowserClient extends WebViewClient { + EditText edittext; + + /** + * Constructor. + * + * @param mContext + * @param edittext + */ + public InAppBrowserClient(EditText mEditText) { + this.edittext = mEditText; + } + + /** + * Notify the host application that a page has started loading. + * + * @param view The webview initiating the callback. + * @param url The url of the page. + */ + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + super.onPageStarted(view, url, favicon); + String newloc; + if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { + newloc = url; + } else { + newloc = "http://" + url; + } + + if (!newloc.equals(edittext.getText().toString())) { + edittext.setText(newloc); + } + + // TODO: Fire 'loadstart' event + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOCATION_CHANGED_EVENT); + obj.put("location", url); + + sendUpdate(obj, true); + } catch (JSONException e) { + Log.d("InAppBrowser", "This should never happen"); + } + } + + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + // TODO: Fire 'loadstop' event + } + } +} \ No newline at end of file From 0084c6f96a3a7d0c7983300a3a73504ea757a44c Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 14:39:33 -0800 Subject: [PATCH 30/43] refactoring android commands --- bin/create | 7 ++-- .../ApplicationInfo/ApplicationInfo.class | Bin 0 -> 2045 bytes bin/templates/cordova/appinfo.jar | Bin 0 -> 1574 bytes bin/templates/cordova/{debug => build} | 2 +- bin/templates/cordova/{BOOM.bat => build.bat} | 2 +- bin/templates/cordova/cordova | 35 +++++++++++++----- bin/templates/cordova/debug.bat | 18 --------- bin/templates/cordova/emulate | 24 ------------ bin/templates/cordova/emulate.bat | 1 - bin/templates/cordova/{BOOM => run} | 2 +- bin/templates/cordova/run.bat | 1 + 11 files changed, 32 insertions(+), 60 deletions(-) create mode 100644 bin/templates/cordova/ApplicationInfo/ApplicationInfo.class create mode 100644 bin/templates/cordova/appinfo.jar rename bin/templates/cordova/{debug => build} (96%) rename bin/templates/cordova/{BOOM.bat => build.bat} (97%) delete mode 100644 bin/templates/cordova/debug.bat delete mode 100755 bin/templates/cordova/emulate delete mode 100644 bin/templates/cordova/emulate.bat rename bin/templates/cordova/{BOOM => run} (96%) create mode 100644 bin/templates/cordova/run.bat diff --git a/bin/create b/bin/create index 1bce739e..903f55ee 100755 --- a/bin/create +++ b/bin/create @@ -147,13 +147,12 @@ replace "s/__ACTIVITY__/${ACTIVITY}/g" "$MANIFEST_PATH" replace "s/__PACKAGE__/${PACKAGE}/g" "$MANIFEST_PATH" replace "s/__APILEVEL__/${API_LEVEL}/g" "$MANIFEST_PATH" -# creating cordova folder and copying emulate/debug/log/launch scripts +# creating cordova folder and copying run/build/log/launch scripts mkdir "$PROJECT_PATH"/cordova createAppInfoJar cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar cp "$BUILD_PATH"/bin/templates/cordova/cordova "$PROJECT_PATH"/cordova/cordova -cp "$BUILD_PATH"/bin/templates/cordova/debug "$PROJECT_PATH"/cordova/debug +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/emulate "$PROJECT_PATH"/cordova/emulate -cp "$BUILD_PATH"/bin/templates/cordova/BOOM "$PROJECT_PATH"/cordova/BOOM +cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class new file mode 100644 index 0000000000000000000000000000000000000000..2ef42a46862f75fffa8b780ff7cc579396224638 GIT binary patch literal 2045 zcma)7TUQ%Z6#h7 z@?0NM&}Em;{w9~Y&m_ni|L_(?$mcNBbpyJEPf;6qHu zF@v0p**N0(NXC7!e-OvVn3FIsW1$O+Sdy_U;h~IAWUMIo6rYJ9uV57g32O>^u`c0r z1t~Fqp%Y0kF7f{pEJvjWt3NS)7asz$IzS3@9F!xR@KdlR`eXhtmK59D@9K) zJzLf7KwZKU30s7eKoUN3Q_~HTp)dWUv$|5We5b^hjllJsZC8zw?irT3V(wU3;ZeoA z7$Ku7zQMODzQa=qbhwR@gt7{b9R|rJ40?sDs9={t)=QqTZ+J&44D3mGrlN`(!!^sP zXa~1TTG^^;OI2RuCNWd>2Gc3JW&HYsA&EBQ8VtYu;S3lH> zbC1uz6Y9XfVQDLCEvKp1s2aC1?;F)JcZj`D&a!2LfE{92#Sy+|NNL%ucHvU9VnxQuR& zAxX*?3^R;e#s(=5|1U^}XmC3WnNEqFZ_Si57-YDo(>Z~yaPLg&Jg-s&wpG0Ofvl(` zKIc&lZTlWY=2k}p7w=biC%vW>cm8NYuM{X_FT6LcS zLV~nfYM^-J2BKlh7j2#4dG;_F(ABL$;)|t-lH)V9A1YaDwozI%3_eICjtHmLiw>e!i9-U9g)@XQ$!hNA_I|R>=aT6 zGtu#+e2T6R!lzI|_yh5z+V~Rt1y_=9M1MzOGdvJ2Zbk-T$?oLUI+Dc`T&tt!82yEb zI{J>$E$04X$YQ?!f^bK$MeVsam@D)`iM>THR49PFjH?80h)!>yi})spWr}#-Bnq=c zVhfX`oxxL#p-k%v#<7bD>fDoLB?}uGJbGI*WMvSMe@HkaVN4=1CSl^Cge?8F2pONm z`;C~8u@L=$(afu#p=82S`C|+`!w1D6Q|( ccn>P332iPwD*SgLr2d5zxhFqUfy(WF0XzW=od5s; literal 0 HcmV?d00001 diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar new file mode 100644 index 0000000000000000000000000000000000000000..31d01d75aa31c5d82b443b37f9eb43de3f694c9d GIT binary patch literal 1574 zcmWIWW@Zs#-~d9+oMJ}?B*4kQ!r%MB z$s^LUwKFWlM4l|ss(7aQI`dP}PqnmXFRh-dh>1sQHmDd)7WQsnt9Z8b>F1)4MT}r~ z#oHQLgaK`h1Y+Fo5(UaS78K-UCMT9;=I43lrRD1-=Oh*v_lCX>mv$BT?;E!}XIopF z`+^AF&@2v>?k(G#HcUW+<-8O4f$?3}!+A~ohJwdcJ{c{0)bUtZ z^83+0jxzGeQHOeZZt|T;j62rU(r#ooF)-kRrk${J;6WuXp=lyt5+V;h=L&MFTeu+p z#HJ?3I}}io`Y}tE*Pm8+%?Y%9EOX=c`23rK7pE?$=-KioASkUh<5sdp;B|ee-ha z^6p)-GrTL55_=~Ic^q<2l-iYO^kv!nE#~2;ro9jO(InV1Z`<2lffsEL8*x8dHdR)ufT%g~R!`$9j;UQ?Y=#4O4gDk?LZXOgeP7pd^T!(z>A!fld|fA|(Eabwzt5La2= zHoem;Gk0&-j=Gwa@wxQg12x0ouVU9dgYyL#gIif=e=>cNwNr8W!q283miFexDGEhZg8zp!jOws-Q))w{fw zp5J8|r=YKuJO7);mA3bSP0_i6F#&-ko2*STZ&D?uyjUmB`<}ufiEbDmgyU4&* z<(h%pHOV!}ETO;FC5l9!2zoB3tZ#Ya!h?&qXDRA4cl>dl?JVS`a_g8%ioDl}i}BqP zJ{#_-pR=!&OHRphPUTPIDLxf@DjFK^8*KQ+l&`j4{?S^sdw%y8EbKh^=!9Zkm&o=H z-;}%_$4b3-Jj$~0EW3y6AHJ3=`zI{=Ad+rlu=B4zs7Rb^rzda0!ocvC9aQu%GKnyt zmZ-4e5>%q10(cP#DqqpHB9~~O@)QAVflRnoq|z1L1Z0PSN 0) { print }}'` + local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device` if [ -z "$devices" ] ; then echo "1" else @@ -37,7 +37,7 @@ function emulate { # Do not launch an emulator if there is already one running or if a device is attached if [ $(check_devices) == 0 ] ; then - echo "Device attached or emulator already running" + # echo "Device attached or emulator already running" return fi @@ -78,25 +78,40 @@ function log { adb logcat } -function debug { +function run { if [ $(check_devices) == 0 ] ; then - ant debug install + clean && emulate && install && launch else - ant debug + build echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/emulate #" + echo "# Plug in your device or launch an emulator with cordova/run #" echo "##################################################################" fi } +function install { + ant debug install +} + +function build { + ant debug +} + +function wait_for_device { + local i=0 + echo "Waiting for emulator..." + while [ check_devices -eq 0 || timeout -lt 300 ] + do + sleep 1 + i=$[i+1] + end + +} + function launch { local launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml) adb shell am start -n $launch_str } -function BOOM { - clean && debug && launch -} - # TODO parse arguments (cd "$PROJECT_PATH" && $1) diff --git a/bin/templates/cordova/debug.bat b/bin/templates/cordova/debug.bat deleted file mode 100644 index f980eb72..00000000 --- a/bin/templates/cordova/debug.bat +++ /dev/null @@ -1,18 +0,0 @@ -:: 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. - -%~dp0\cordova.bat debug diff --git a/bin/templates/cordova/emulate b/bin/templates/cordova/emulate deleted file mode 100755 index fe27b2f3..00000000 --- a/bin/templates/cordova/emulate +++ /dev/null @@ -1,24 +0,0 @@ -# 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. - -#!/bin/bash - -set -e - -CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) - -bash "$CORDOVA_PATH"/cordova emulate diff --git a/bin/templates/cordova/emulate.bat b/bin/templates/cordova/emulate.bat deleted file mode 100644 index 87ef969f..00000000 --- a/bin/templates/cordova/emulate.bat +++ /dev/null @@ -1 +0,0 @@ -%~dp0\cordova.bat emulate diff --git a/bin/templates/cordova/BOOM b/bin/templates/cordova/run similarity index 96% rename from bin/templates/cordova/BOOM rename to bin/templates/cordova/run index 443502d8..840a8d5a 100755 --- a/bin/templates/cordova/BOOM +++ b/bin/templates/cordova/run @@ -21,4 +21,4 @@ set -e CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) -bash $CORDOVA_PATH/cordova BOOM +bash "$CORDOVA_PATH"/cordova run diff --git a/bin/templates/cordova/run.bat b/bin/templates/cordova/run.bat new file mode 100644 index 00000000..7c470ed8 --- /dev/null +++ b/bin/templates/cordova/run.bat @@ -0,0 +1 @@ +%~dp0\cordova.bat run From a6473cb826ee269108d287ed74dce2a1d1b54100 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 14:49:49 -0800 Subject: [PATCH 31/43] adding install function --- bin/templates/cordova/cordova | 76 ++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 561663b5..759f5905 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -17,11 +17,11 @@ #!/bin/bash -set -e PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd ) function check_devices { +# FIXME local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device` if [ -z "$devices" ] ; then echo "1" @@ -37,7 +37,6 @@ function emulate { # Do not launch an emulator if there is already one running or if a device is attached if [ $(check_devices) == 0 ] ; then - # echo "Device attached or emulator already running" return fi @@ -62,8 +61,9 @@ function emulate { do echo "$i) ${avd_list[$i]}" done - echo -n "> " - read avd_id + read -t 5 -p "> " avd_id + # default value if input timeout + if [ $avd_id -eq 1000 ] ; then avd_id=0 ; fi done emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 & fi @@ -79,17 +79,41 @@ function log { } function run { - if [ $(check_devices) == 0 ] ; then - clean && emulate && install && launch - else - build - echo "##################################################################" - echo "# Plug in your device or launch an emulator with cordova/run #" - echo "##################################################################" - fi + clean && emulate && wait_for_device && install && launch } function install { + + declare -a devices=($(adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device | cut -f 1)) + local device_id="1000" #FIXME: hopefully user does not have 1000 AVDs + + if [ ${#devices[@]} == 0 ] + then + # should not reach here. Emulator should launch or device should be attached + echo "Emulator not running or device not attached. Could not install debug package" + exit 70 + fi + + if [ ${#devices[@]} == 1 ] + then + export ANDROID_SERIAL=${devices[0]} + # User has more than 1 AVD + elif [ ${#devices[@]} -gt 1 ] + then + while [ -z ${devices[$device_id]} ] + do + echo "Choose from one of the following devices/emulators [0 to $((${#devices[@]}-1))]:" + for(( i = 0 ; i < ${#devices[@]} ; i++ )) + do + echo "$i) ${devices[$i]}" + done + read -t 5 -p "> " device_id + # default value if input timeout + if [ $device_id -eq 1000 ] ; then device_id=0 ; fi + done + export ANDROID_SERIAL=${devices[$device_id]} + fi + ant debug install } @@ -98,14 +122,28 @@ function build { } function wait_for_device { - local i=0 - echo "Waiting for emulator..." - while [ check_devices -eq 0 || timeout -lt 300 ] - do - sleep 1 - i=$[i+1] - end + local i="0" + echo -n "Waiting for device..." + while [ $i -lt 300 ] + do + if [ $(check_devices) -eq 0 ] + then + break + else + sleep 1 + i=$[i+1] + echo -n "." + fi + done + # Device timeout: emulator has not started in time or device not attached + if [ $i -eq 300 ] + then + echo "device timeout!" + exit 69 + else + echo "connected!" + fi } function launch { From 68161d2714c9d966139f3c9fe485b582884939c3 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Tue, 20 Nov 2012 18:49:16 -0800 Subject: [PATCH 32/43] refactoring windows scripts --- bin/create.js | 5 ++-- bin/templates/cordova/cordova.js | 46 +++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/bin/create.js b/bin/create.js index 2d6b8d61..258c32cd 100644 --- a/bin/create.js +++ b/bin/create.js @@ -198,10 +198,9 @@ exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\appinfo.jar ' + PRO exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.bat /Y'); +exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\build.bat ' + PROJECT_PATH + '\\cordova\\build.bat /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\log.bat ' + PROJECT_PATH + '\\cordova\\log.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.bat /Y'); -exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y'); +exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\run.bat ' + PROJECT_PATH + '\\cordova\\run.bat /Y'); // interpolate the activity name and package WScript.Echo("Updating AndroidManifest.xml and Main Activity..."); diff --git a/bin/templates/cordova/cordova.js b/bin/templates/cordova/cordova.js index ff91430b..51533cb9 100644 --- a/bin/templates/cordova/cordova.js +++ b/bin/templates/cordova/cordova.js @@ -34,17 +34,19 @@ function exec(command) { return output; } -function emulator_running() { +function device_running() { var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll(); - if(local_devices.match(/emulator/)) { + if(local_devices.match(/\w+\tdevice/)) { + WScript.Echo("Yes"); return true; } + WScript.Echo("No"); return false; } function emulate() { // don't run emulator if a device is plugged in or if emulator is already running - if(emulator_running()) { - WScript.Echo("Device or Emulator already running!"); + if(device_running()) { + //WScript.Echo("Device or Emulator already running!"); return; } var oExec = shell.Exec("%comspec% /c android.bat list avd"); @@ -84,18 +86,18 @@ function emulate() { } function clean() { + WScript.Echo("Cleaning project..."); exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1"); } -function debug() { - if(emulator_running()) { - exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); - } else { - exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); - WScript.Echo("##################################################################"); - WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #"); - WScript.Echo("##################################################################"); - } +function build() { + WScript.Echo("Building project..."); + exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1"); +} + +function install() { + WScript.Echo("Building/Installing project..."); + exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); } function log() { @@ -103,14 +105,28 @@ function log() { } function launch() { + WScript.Echo("Launching app..."); var launch_str=exec("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml"); //WScript.Echo(launch_str); exec("%comspec% /c adb shell am start -n "+launch_str+" 2>&1"); } -function BOOM() { +function run() { + var i=0; clean(); - debug(); + emulate(); + WScript.Stdout.Write('Waiting for device...'); + while(!device_running() && i < 300) { + WScript.Stdout.Write('.'); + WScript.sleep(1000); + i += 1; + } + if(i == 300) { + WScript.Stderr.WriteLine("device/emulator timeout!"); + } else { + WScript.Stdout.WriteLine("connected!"); + } + install(); launch(); } var args = WScript.Arguments; From 5bebf11b370f20176f6375685b4659bc891a0bd6 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Wed, 21 Nov 2012 11:27:25 -0500 Subject: [PATCH 33/43] CB-1888: Can't add a Photo from a HTTPS address to Contact --- framework/src/org/apache/cordova/ContactAccessorSdk5.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/ContactAccessorSdk5.java b/framework/src/org/apache/cordova/ContactAccessorSdk5.java index 8497135e..73d05bc0 100644 --- a/framework/src/org/apache/cordova/ContactAccessorSdk5.java +++ b/framework/src/org/apache/cordova/ContactAccessorSdk5.java @@ -1579,7 +1579,7 @@ public class ContactAccessorSdk5 extends ContactAccessor { Uri uri = Uri.parse(path); return mApp.getActivity().getContentResolver().openInputStream(uri); } - if (path.startsWith("http:") || path.startsWith("file:")) { + if (path.startsWith("http:") || path.startsWith("https:") || path.startsWith("file:")) { URL url = new URL(path); return url.openStream(); } From 6137c7ca0654b863a80a39bb7ff60a503eb055d9 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 13:33:09 -0800 Subject: [PATCH 34/43] removing appinfo.jar --- bin/templates/cordova/appinfo.jar | Bin 1574 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bin/templates/cordova/appinfo.jar diff --git a/bin/templates/cordova/appinfo.jar b/bin/templates/cordova/appinfo.jar deleted file mode 100644 index 31d01d75aa31c5d82b443b37f9eb43de3f694c9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1574 zcmWIWW@Zs#-~d9+oMJ}?B*4kQ!r%MB z$s^LUwKFWlM4l|ss(7aQI`dP}PqnmXFRh-dh>1sQHmDd)7WQsnt9Z8b>F1)4MT}r~ z#oHQLgaK`h1Y+Fo5(UaS78K-UCMT9;=I43lrRD1-=Oh*v_lCX>mv$BT?;E!}XIopF z`+^AF&@2v>?k(G#HcUW+<-8O4f$?3}!+A~ohJwdcJ{c{0)bUtZ z^83+0jxzGeQHOeZZt|T;j62rU(r#ooF)-kRrk${J;6WuXp=lyt5+V;h=L&MFTeu+p z#HJ?3I}}io`Y}tE*Pm8+%?Y%9EOX=c`23rK7pE?$=-KioASkUh<5sdp;B|ee-ha z^6p)-GrTL55_=~Ic^q<2l-iYO^kv!nE#~2;ro9jO(InV1Z`<2lffsEL8*x8dHdR)ufT%g~R!`$9j;UQ?Y=#4O4gDk?LZXOgeP7pd^T!(z>A!fld|fA|(Eabwzt5La2= zHoem;Gk0&-j=Gwa@wxQg12x0ouVU9dgYyL#gIif=e=>cNwNr8W!q283miFexDGEhZg8zp!jOws-Q))w{fw zp5J8|r=YKuJO7);mA3bSP0_i6F#&-ko2*STZ&D?uyjUmB`<}ufiEbDmgyU4&* z<(h%pHOV!}ETO;FC5l9!2zoB3tZ#Ya!h?&qXDRA4cl>dl?JVS`a_g8%ioDl}i}BqP zJ{#_-pR=!&OHRphPUTPIDLxf@DjFK^8*KQ+l&`j4{?S^sdw%y8EbKh^=!9Zkm&o=H z-;}%_$4b3-Jj$~0EW3y6AHJ3=`zI{=Ad+rlu=B4zs7Rb^rzda0!ocvC9aQu%GKnyt zmZ-4e5>%q10(cP#DqqpHB9~~O@)QAVflRnoq|z1L1Z0PSN Date: Wed, 21 Nov 2012 13:37:19 -0800 Subject: [PATCH 35/43] removing ApplicationInfo.class --- .../ApplicationInfo/ApplicationInfo.class | Bin 2045 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bin/templates/cordova/ApplicationInfo/ApplicationInfo.class diff --git a/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class b/bin/templates/cordova/ApplicationInfo/ApplicationInfo.class deleted file mode 100644 index 2ef42a46862f75fffa8b780ff7cc579396224638..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2045 zcma)7TUQ%Z6#h7 z@?0NM&}Em;{w9~Y&m_ni|L_(?$mcNBbpyJEPf;6qHu zF@v0p**N0(NXC7!e-OvVn3FIsW1$O+Sdy_U;h~IAWUMIo6rYJ9uV57g32O>^u`c0r z1t~Fqp%Y0kF7f{pEJvjWt3NS)7asz$IzS3@9F!xR@KdlR`eXhtmK59D@9K) zJzLf7KwZKU30s7eKoUN3Q_~HTp)dWUv$|5We5b^hjllJsZC8zw?irT3V(wU3;ZeoA z7$Ku7zQMODzQa=qbhwR@gt7{b9R|rJ40?sDs9={t)=QqTZ+J&44D3mGrlN`(!!^sP zXa~1TTG^^;OI2RuCNWd>2Gc3JW&HYsA&EBQ8VtYu;S3lH> zbC1uz6Y9XfVQDLCEvKp1s2aC1?;F)JcZj`D&a!2LfE{92#Sy+|NNL%ucHvU9VnxQuR& zAxX*?3^R;e#s(=5|1U^}XmC3WnNEqFZ_Si57-YDo(>Z~yaPLg&Jg-s&wpG0Ofvl(` zKIc&lZTlWY=2k}p7w=biC%vW>cm8NYuM{X_FT6LcS zLV~nfYM^-J2BKlh7j2#4dG;_F(ABL$;)|t-lH)V9A1YaDwozI%3_eICjtHmLiw>e!i9-U9g)@XQ$!hNA_I|R>=aT6 zGtu#+e2T6R!lzI|_yh5z+V~Rt1y_=9M1MzOGdvJ2Zbk-T$?oLUI+Dc`T&tt!82yEb zI{J>$E$04X$YQ?!f^bK$MeVsam@D)`iM>THR49PFjH?80h)!>yi})spWr}#-Bnq=c zVhfX`oxxL#p-k%v#<7bD>fDoLB?}uGJbGI*WMvSMe@HkaVN4=1CSl^Cge?8F2pONm z`;C~8u@L=$(afu#p=82S`C|+`!w1D6Q|( ccn>P332iPwD*SgLr2d5zxhFqUfy(WF0XzW=od5s; From 226e72ac1843b43fbf45437e3d6260d2de4f4145 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 16:35:16 -0800 Subject: [PATCH 36/43] adding release command --- bin/templates/cordova/cordova | 4 ++++ bin/templates/cordova/release | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 bin/templates/cordova/release diff --git a/bin/templates/cordova/cordova b/bin/templates/cordova/cordova index 759f5905..1945a4c4 100755 --- a/bin/templates/cordova/cordova +++ b/bin/templates/cordova/cordova @@ -121,6 +121,10 @@ function build { ant debug } +function release { + ant release +} + function wait_for_device { local i="0" echo -n "Waiting for device..." diff --git a/bin/templates/cordova/release b/bin/templates/cordova/release new file mode 100755 index 00000000..73d873e3 --- /dev/null +++ b/bin/templates/cordova/release @@ -0,0 +1,24 @@ +# 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. + +#!/bin/bash + +set -e + +CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd ) + +bash "$CORDOVA_PATH"/cordova release From 2ee4326a4d21e2ca25f7f075645882e6d59d9bfc Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 21 Nov 2012 16:35:27 -0800 Subject: [PATCH 37/43] updating create command --- bin/create | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/create b/bin/create index 903f55ee..e01cef98 100755 --- a/bin/create +++ b/bin/create @@ -153,6 +153,7 @@ createAppInfoJar cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar cp "$BUILD_PATH"/bin/templates/cordova/cordova "$PROJECT_PATH"/cordova/cordova cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build +cp "$BUILD_PATH"/bin/templates/cordova/release "$PROJECT_PATH"/cordova/release 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 From 11e0ffa90abe3c818887706cc22286cbb4b54742 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 22 Nov 2012 12:39:18 -0500 Subject: [PATCH 38/43] Add @JavascriptInterface annotations to ExposedJsApi. And re-enable the JS bridge on 4.2. https://issues.apache.org/jira/browse/CB-1879 --- framework/src/org/apache/cordova/CordovaWebView.java | 4 ---- framework/src/org/apache/cordova/ExposedJsApi.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index efd3cf89..4777f25a 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -302,10 +302,6 @@ public class CordovaWebView extends WebView { Log.i(TAG, "Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator"); return; } - else if (SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { - Log.i(TAG, "Disabled addJavascriptInterface() bridge callback for 4.2. Symbols are broken, and we can't compile the annotation needed to expose the exec."); - return; - } this.addJavascriptInterface(exposedJsApi, "_cordovaNative"); } diff --git a/framework/src/org/apache/cordova/ExposedJsApi.java b/framework/src/org/apache/cordova/ExposedJsApi.java index b386a402..a36bb62b 100755 --- a/framework/src/org/apache/cordova/ExposedJsApi.java +++ b/framework/src/org/apache/cordova/ExposedJsApi.java @@ -18,6 +18,7 @@ */ package org.apache.cordova; +import android.webkit.JavascriptInterface; import org.apache.cordova.api.PluginManager; import org.apache.cordova.api.PluginResult; import org.json.JSONException; @@ -37,6 +38,7 @@ import org.json.JSONException; this.jsMessageQueue = jsMessageQueue; } + @JavascriptInterface public String exec(String service, String action, String callbackId, String arguments) throws JSONException { jsMessageQueue.setPaused(true); try { @@ -51,10 +53,12 @@ import org.json.JSONException; } } + @JavascriptInterface public void setNativeToJsBridgeMode(int value) { jsMessageQueue.setBridgeMode(value); } + @JavascriptInterface public String retrieveJsMessages() { return jsMessageQueue.popAndEncode(); } From 9ca2a1621865a21152bcedfabfaa53f708b3c6f8 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Fri, 23 Nov 2012 09:38:49 -0500 Subject: [PATCH 39/43] Updating JS so that InAppBrowser will work out of the box --- framework/assets/js/cordova.android.js | 241 ++++++++++++++++--------- 1 file changed, 155 insertions(+), 86 deletions(-) diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index b4aa1fec..eac42d6f 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 02b91c5313ff37d74a58f71775170afd360f4a1f +// commit 7203d335b59902a72a374a170b1edb04438b6a47 -// File generated at :: Wed Oct 31 2012 10:40:25 GMT-0700 (PDT) +// File generated at :: Wed Nov 21 2012 16:34:19 GMT-0500 (EST) /* Licensed to the Apache Software Foundation (ASF) under one @@ -329,14 +329,24 @@ function each(objects, func, context) { } } +function clobber(obj, key, value) { + obj[key] = value; + // Getters can only be overridden by getters. + if (obj[key] !== value) { + utils.defineGetter(obj, key, function() { + return value; + }); + } +} + function assignOrWrapInDeprecateGetter(obj, key, value, message) { if (message) { utils.defineGetter(obj, key, function() { - window.console && console.log(message); + console.log(message); return value; }); } else { - obj[key] = value; + clobber(obj, key, value); } } @@ -395,8 +405,11 @@ function recursiveMerge(target, src) { // If the target object is a constructor override off prototype. target.prototype[prop] = src[prop]; } else { - target[prop] = typeof src[prop] === 'object' ? recursiveMerge( - target[prop], src[prop]) : src[prop]; + if (typeof src[prop] === 'object') { + target[prop] = recursiveMerge(target[prop], src[prop]); + } else { + clobber(target, prop, src[prop]); + } } } } @@ -404,18 +417,14 @@ function recursiveMerge(target, src) { } module.exports = { - build: function (objects) { - return { - intoButDoNotClobber: function (target) { - include(target, objects, false, false); - }, - intoAndClobber: function(target) { - include(target, objects, true, false); - }, - intoAndMerge: function(target) { - include(target, objects, true, true); - } - }; + buildIntoButDoNotClobber: function(objects, target) { + include(target, objects, false, false); + }, + buildIntoAndClobber: function(objects, target) { + include(target, objects, true, false); + }, + buildIntoAndMerge: function(objects, target) { + include(target, objects, true, true); } }; @@ -701,7 +710,7 @@ module.exports = { define("cordova/common", function(require, exports, module) { module.exports = { - objects: { + defaults: { cordova: { path: 'cordova', children: { @@ -720,6 +729,9 @@ module.exports = { } } }, + open : { + path: 'cordova/plugin/InAppBrowser' + }, navigator: { children: { notification: { @@ -737,9 +749,6 @@ module.exports = { compass:{ path: 'cordova/plugin/compass' }, - connection: { - path: 'cordova/plugin/network' - }, contacts: { path: 'cordova/plugin/contacts' }, @@ -907,6 +916,15 @@ module.exports = { resolveLocalFileSystemURI:{ path: 'cordova/plugin/resolveLocalFileSystemURI' } + }, + clobbers: { + navigator: { + children: { + connection: { + path: 'cordova/plugin/network' + } + } + } } }; @@ -961,6 +979,7 @@ var cordova = require('cordova'), function androidExec(success, fail, service, action, args) { // Set default bridge modes if they have not already been set. + // By default, we use the failsafe, since addJavascriptInterface breaks too often if (jsToNativeBridgeMode === undefined) { androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT); } @@ -1199,7 +1218,7 @@ module.exports = { exec(null, null, "App", "show", []); }, [channel.onCordovaReady]); }, - objects: { + clobbers: { navigator: { children: { app:{ @@ -1218,6 +1237,9 @@ module.exports = { }, MediaError: { // exists natively on Android WebView on Android 4.x path: "cordova/plugin/MediaError" + }, + open : { + path: 'cordova/plugin/InAppBrowser' } }, merges: { @@ -3237,6 +3259,25 @@ module.exports = GlobalizationError; }); +// file: lib/common/plugin/InAppBrowser.js +define("cordova/plugin/InAppBrowser", function(require, exports, module) { + +var exec = require('cordova/exec'); + +var InAppBrowser = { + open : function(strUrl, strWindowName, strWindowFeatures) { + exec(null, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]); + return InAppBrowser; + }, + close : function() { + exec(null, null, "InAppBrowser", "close", []); + } +}; + +module.exports = InAppBrowser.open; + +}); + // file: lib/common/plugin/LocalFileSystem.js define("cordova/plugin/LocalFileSystem", function(require, exports, module) { @@ -4954,6 +4995,7 @@ function Device() { this.name = null; this.uuid = null; this.cordova = null; + this.model = null; var me = this; @@ -4965,6 +5007,7 @@ function Device() { me.name = info.name; me.uuid = info.uuid; me.cordova = info.cordova; + me.model = info.model; channel.onCordovaInfoReady.fire(); },function(e) { me.available = false; @@ -6004,49 +6047,9 @@ if (typeof navigator != 'undefined') { }); } -var NetworkConnection = function () { - this.type = null; - this._firstRun = true; - this._timer = null; - this.timeout = 500; - - var me = this; - - channel.onCordovaReady.subscribe(function() { - me.getInfo(function (info) { - me.type = info; - if (info === "none") { - // set a timer if still offline at the end of timer send the offline event - me._timer = setTimeout(function(){ - cordova.fireDocumentEvent("offline"); - me._timer = null; - }, me.timeout); - } else { - // If there is a current offline event pending clear it - if (me._timer !== null) { - clearTimeout(me._timer); - me._timer = null; - } - cordova.fireDocumentEvent("online"); - } - - // should only fire this once - if (me._firstRun) { - me._firstRun = false; - channel.onCordovaConnectionReady.fire(); - } - }, - function (e) { - // If we can't get the network info we should still tell Cordova - // to fire the deviceready event. - if (me._firstRun) { - me._firstRun = false; - channel.onCordovaConnectionReady.fire(); - } - console.log("Error initializing Network Connection: " + e); - }); - }); -}; +function NetworkConnection() { + this.type = 'unknown'; +} /** * Get connection info @@ -6054,12 +6057,48 @@ var NetworkConnection = function () { * @param {Function} successCallback The function to call when the Connection data is available * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) */ -NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) { - // Get info +NetworkConnection.prototype.getInfo = function(successCallback, errorCallback) { exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []); }; -module.exports = new NetworkConnection(); +var me = new NetworkConnection(); +var timerId = null; +var timeout = 500; + +channel.onCordovaReady.subscribe(function() { + me.getInfo(function(info) { + me.type = info; + if (info === "none") { + // set a timer if still offline at the end of timer send the offline event + timerId = setTimeout(function(){ + cordova.fireDocumentEvent("offline"); + timerId = null; + }, timeout); + } else { + // If there is a current offline event pending clear it + if (timerId !== null) { + clearTimeout(timerId); + timerId = null; + } + cordova.fireDocumentEvent("online"); + } + + // should only fire this once + if (channel.onCordovaConnectionReady.state !== 2) { + channel.onCordovaConnectionReady.fire(); + } + }, + function (e) { + // If we can't get the network info we should still tell Cordova + // to fire the deviceready event. + if (channel.onCordovaConnectionReady.state !== 2) { + channel.onCordovaConnectionReady.fire(); + } + console.log("Error initializing Network Connection: " + e); + }); +}); + +module.exports = me; }); @@ -6106,10 +6145,20 @@ module.exports = { /** * Causes the device to vibrate. * - * @param {Integer} mills The number of milliseconds to vibrate for. + * @param {Integer} time The number of milliseconds to vibrate for. + * OR + * @param {Integer} pattern A vibration pattern represented by a list of time entries, in milliseconds. */ - vibrate: function(mills) { - exec(null, null, "Notification", "vibrate", [mills]); + vibrate: function(time) { + var pattern = []; + if (time) { + if (typeof time === 'number') { + pattern.push(time); + } else { + pattern = time; + } + } + exec(null, null, "Notification", "vibrate", [pattern]); }, /** @@ -6259,6 +6308,30 @@ utils.defineGetter = function(obj, key, func) { } }; +utils.arrayIndexOf = function(a, item) { + if (a.indexOf) { + return a.indexOf(item); + } + var len = a.length; + for (var i = 0; i < len; ++i) { + if (a[i] == item) { + return i; + } + } + return -1; +}; + +/** + * Returns whether the item was found in the array. + */ +utils.arrayRemove = function(a, item) { + var index = utils.arrayIndexOf(a, item); + if (index != -1) { + a.splice(index, 1); + } + return index != -1; +}; + /** * Returns an indication of whether the argument is an array or not */ @@ -6454,10 +6527,10 @@ window.cordova = require('cordova'); (function (context) { // Replace navigator before any modules are required(), to ensure it happens as soon as possible. // We replace it so that properties that can't be clobbered can instead be overridden. - if (typeof navigator != 'undefined') { - var CordovaNavigator = function () {}; - CordovaNavigator.prototype = navigator; - navigator = new CordovaNavigator(); + if (context.navigator) { + function CordovaNavigator() {} + CordovaNavigator.prototype = context.navigator; + context.navigator = new CordovaNavigator(); } var channel = require("cordova/channel"), @@ -6472,17 +6545,13 @@ window.cordova = require('cordova'); platform = require('cordova/platform'); // Drop the common globals into the window object, but be nice and don't overwrite anything. - builder.build(base.objects).intoButDoNotClobber(window); + builder.buildIntoButDoNotClobber(base.defaults, context); + builder.buildIntoAndMerge(base.merges, context); + builder.buildIntoAndClobber(base.clobbers, context); - // Drop the platform-specific globals into the window object - // and clobber any existing object. - builder.build(platform.objects).intoAndClobber(window); - - // Merge the platform-specific overrides/enhancements into - // the window object. - if (typeof platform.merges !== 'undefined') { - builder.build(platform.merges).intoAndMerge(window); - } + builder.buildIntoButDoNotClobber(platform.defaults, context); + builder.buildIntoAndMerge(platform.merges, context); + builder.buildIntoAndClobber(platform.clobbers, context); // Call the platform-specific initialization platform.initialize(); From 7b3724972bf1cc6eea30ffa83eb35381f394f917 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Mon, 26 Nov 2012 16:09:52 -0500 Subject: [PATCH 40/43] Tagging to 2.3.0rc1 --- VERSION | 2 +- bin/templates/project/assets/www/index.html | 2 +- framework/assets/js/cordova.android.js | 417 ++++++------------- framework/assets/www/index.html | 2 +- framework/src/org/apache/cordova/Device.java | 2 +- 5 files changed, 131 insertions(+), 294 deletions(-) diff --git a/VERSION b/VERSION index ccbccc3d..d2a7ed1f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.0 +2.3.0rc1 diff --git a/bin/templates/project/assets/www/index.html b/bin/templates/project/assets/www/index.html index 4f8dc5f2..0f8a50bc 100644 --- a/bin/templates/project/assets/www/index.html +++ b/bin/templates/project/assets/www/index.html @@ -33,7 +33,7 @@

Device is Ready

- + + diff --git a/framework/src/org/apache/cordova/Device.java b/framework/src/org/apache/cordova/Device.java index 90a20335..8967bf47 100644 --- a/framework/src/org/apache/cordova/Device.java +++ b/framework/src/org/apache/cordova/Device.java @@ -39,7 +39,7 @@ import android.telephony.TelephonyManager; public class Device extends CordovaPlugin { public static final String TAG = "Device"; - public static String cordovaVersion = "2.2.0"; // Cordova version + public static String cordovaVersion = "2.3.0rc1"; // Cordova version public static String platform = "Android"; // Device OS public static String uuid; // Device UUID From 48f58110fec31a6cf8dd4e39962682d21513adaa Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Tue, 27 Nov 2012 12:18:49 -0500 Subject: [PATCH 41/43] CB-1938: Regression, Android back button event is no longer fired --- framework/src/org/apache/cordova/App.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 5433d314..dad34a07 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -19,13 +19,14 @@ package org.apache.cordova; +import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; import org.apache.cordova.api.LOG; -import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; + import java.util.HashMap; /** @@ -36,12 +37,12 @@ public class App extends CordovaPlugin { /** * Executes the request and returns PluginResult. * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackId The callback id used when calling back into JavaScript. - * @return A PluginResult object with a status and message. + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackContext The callback context from which we were invoked. + * @return A PluginResult object with a status and message. */ - public PluginResult execute(String action, JSONArray args, String callbackId) { + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; @@ -80,9 +81,11 @@ public class App extends CordovaPlugin { else if (action.equals("exitApp")) { this.exitApp(); } - return new PluginResult(status, result); + callbackContext.sendPluginResult(new PluginResult(status, result)); + return true; } catch (JSONException e) { - return new PluginResult(PluginResult.Status.JSON_EXCEPTION); + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + return false; } } From a42dc087565efa3e7f414e57693d145297135e3e Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Wed, 28 Nov 2012 15:44:01 -0500 Subject: [PATCH 42/43] Start adding events to InAppBrowser --- .../src/org/apache/cordova/InAppBrowser.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java index 9b747d3a..338d3440 100644 --- a/framework/src/org/apache/cordova/InAppBrowser.java +++ b/framework/src/org/apache/cordova/InAppBrowser.java @@ -209,6 +209,7 @@ public class InAppBrowser extends CordovaPlugin { */ private void closeDialog() { // TODO: fire 'exit' event + this.webView.sendJavascript("cordova.fireWindowEvent('exit');"); if (dialog != null) { dialog.dismiss(); } @@ -271,6 +272,8 @@ public class InAppBrowser extends CordovaPlugin { if (features != null) { showLocationBar = features.get(LOCATION).booleanValue(); } + + final CordovaWebView thatWebView = this.webView; // Create dialog in new thread Runnable runnable = new Runnable() { @@ -394,7 +397,7 @@ public class InAppBrowser extends CordovaPlugin { inAppWebView = new WebView(cordova.getActivity()); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); inAppWebView.setWebChromeClient(new WebChromeClient()); - WebViewClient client = new InAppBrowserClient(edittext); + WebViewClient client = new InAppBrowserClient(thatWebView, edittext); inAppWebView.setWebViewClient(client); WebSettings settings = inAppWebView.getSettings(); settings.setJavaScriptEnabled(true); @@ -464,6 +467,7 @@ public class InAppBrowser extends CordovaPlugin { */ public class InAppBrowserClient extends WebViewClient { EditText edittext; + CordovaWebView webView; /** * Constructor. @@ -471,7 +475,8 @@ public class InAppBrowser extends CordovaPlugin { * @param mContext * @param edittext */ - public InAppBrowserClient(EditText mEditText) { + public InAppBrowserClient(CordovaWebView webView, EditText mEditText) { + this.webView = webView; this.edittext = mEditText; } @@ -495,21 +500,14 @@ public class InAppBrowser extends CordovaPlugin { edittext.setText(newloc); } - // TODO: Fire 'loadstart' event - try { - JSONObject obj = new JSONObject(); - obj.put("type", LOCATION_CHANGED_EVENT); - obj.put("location", url); - - sendUpdate(obj, true); - } catch (JSONException e) { - Log.d("InAppBrowser", "This should never happen"); - } + // TODO: Fire 'loadstart' event only on the InAppBrowser object + this.webView.sendJavascript("cordova.fireWindowEvent('loadstart', '" + url + "');"); } public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); - // TODO: Fire 'loadstop' event + // TODO: Fire 'loadstop' event only on the InAppBrowser object + this.webView.sendJavascript("cordova.fireWindowEvent('loadstop', '" + url + "');"); } } } \ No newline at end of file From 2c202b82d737c00b3b03b9c6988e1780d3f2df68 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 28 Nov 2012 14:42:55 -0800 Subject: [PATCH 43/43] Partial Fix/Workaround for CB-1856. Also removed old deprecated code --- .../src/org/apache/cordova/NetworkManager.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java index af2fc7d3..bb4743f2 100755 --- a/framework/src/org/apache/cordova/NetworkManager.java +++ b/framework/src/org/apache/cordova/NetworkManager.java @@ -74,6 +74,7 @@ public class NetworkManager extends CordovaPlugin { ConnectivityManager sockMan; BroadcastReceiver receiver; + private String lastStatus = ""; /** * Constructor. @@ -99,12 +100,11 @@ public class NetworkManager extends CordovaPlugin { intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { - @SuppressWarnings("deprecation") @Override public void onReceive(Context context, Intent intent) { // (The null check is for the ARM Emulator, please use Intel Emulator for better results) - if(NetworkManager.this.webView != null) - updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO)); + if(NetworkManager.this.webView != null) + updateConnectionInfo(sockMan.getActiveNetworkInfo()); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); @@ -159,7 +159,14 @@ public class NetworkManager extends CordovaPlugin { */ private void updateConnectionInfo(NetworkInfo info) { // send update to javascript "navigator.network.connection" - sendUpdate(this.getConnectionInfo(info)); + // Jellybean sends its own info + String thisStatus = this.getConnectionInfo(info); + if(!thisStatus.equals(lastStatus)) + { + sendUpdate(thisStatus); + lastStatus = thisStatus; + } + } /** @@ -179,6 +186,7 @@ public class NetworkManager extends CordovaPlugin { type = getType(info); } } + Log.d("CordovaNetworkManager", "Connection Type: " + type); return type; } @@ -193,7 +201,6 @@ public class NetworkManager extends CordovaPlugin { result.setKeepCallback(true); connectionCallbackContext.sendPluginResult(result); } - webView.postMessage("networkconnection", type); }