From 6dc8836ff669dbd6825093740a3115cb0c08b1c2 Mon Sep 17 00:00:00 2001 From: Martin Horvath Date: Tue, 13 Nov 2018 16:37:35 +0100 Subject: [PATCH 1/7] Update webview.md This update is based on my current findings while embedding a Cordova app into a native Android app. --- .../en/dev/guide/platforms/android/webview.md | 134 ++++++------------ 1 file changed, 45 insertions(+), 89 deletions(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index b07ac6aaa4..3378d8f74f 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -38,97 +38,53 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. [cordova.apache.org](http://cordova.apache.org) and unzip its Android package. -1. Navigate to the Android package's `/framework` directory and run - `ant jar`. It creates the Cordova `.jar` file, formed as - `/framework/cordova-x.x.x.jar`. - -1. Copy the `.jar` file into the Android project's `/libs` directory. - -1. Add the following to the application's `/res/xml/main.xml` file, - with the `layout_height`, `layout_width` and `id` modified to suit - the application: - - + - -1. Modify the activity so that it implements the `CordovaInterface`. - It should implement the included methods. You may wish to copy - them from `/framework/src/org/apache/cordova/CordovaActivity.java`, - or else implement them on your own. The following code fragment - shows a basic application that relies on the interface. Note how - the referenced view id matches the `id` attribute specified in the - XML fragment shown above: - - public class CordovaViewTestActivity extends Activity implements CordovaInterface { - CordovaWebView cwv; - /* Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - cwv = (CordovaWebView) findViewById(R.id.tutorialView); - Config.init(this); - cwv.loadUrl(Config.getStartUrl()); - } - -1. If the application needs to use the camera, implement the - following: - - @Override - public void setActivityResultCallback(CordovaPlugin plugin) { - this.activityResultCallback = plugin; - } - /** - * Launch an activity for which you would like a result when it finished. When this activity exits, - * your onActivityResult() method is called. - * - * @param command The command object - * @param intent The intent to start - * @param requestCode The request code that is passed to callback to identify the activity - */ - public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) { - this.activityResultCallback = command; - this.activityResultKeepRunning = this.keepRunning; - - // If multitasking turned on, then disable it for activities that return results - if (command != null) { - this.keepRunning = false; - } - - // Start activity - super.startActivityForResult(intent, requestCode); - } - - @Override - /** - * Called when an activity you launched exits, giving you the requestCode you started it with, - * the resultCode it returned, and any additional data from it. - * - * @param requestCode The request code originally supplied to startActivityForResult(), - * allowing you to identify who this result came from. - * @param resultCode The integer result code returned by the child activity through its setResult(). - * @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). - */ - protected void onActivityResult(int requestCode, int resultCode, Intent intent) { - super.onActivityResult(requestCode, resultCode, intent); - CordovaPlugin callback = this.activityResultCallback; - if (callback != null) { - callback.onActivityResult(requestCode, resultCode, intent); - } - } - -1. Finally, remember to add the thread pool, otherwise plugins - have no threads on which to run: - - @Override - public ExecutorService getThreadPool() { - return threadPool; - } - -1. Copy the application's HTML and JavaScript files to the Android + Date: Tue, 13 Nov 2018 17:27:52 +0100 Subject: [PATCH 2/7] GH-884 android: Embedding Android WebView doc looks broken The documentation of embedding cordova in native apps is outdated and this updated is considered as a quick update. --- .../en/dev/guide/platforms/android/webview.md | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index 3378d8f74f..5f09040779 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -38,53 +38,57 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. [cordova.apache.org](http://cordova.apache.org) and unzip its Android package. -2. Follow the instructions here to build your first cordova app [CreateYourFirstApp](https://cordova.apache.org/docs/en/8.x/guide/cli/index.html) +1. Follow the instructions here to build your first cordova app [CreateYourFirstApp](https://cordova.apache.org/docs/en/8.x/guide/cli/index.html) -3. Copy Cordova framework files **from platforms/android/CordovaLib/src/** to your android application directory at **/app/main/java**. Also copy additional Cordova framework files **from platforms/android/src/** to your android application directory at **/app/main/java**. +1. Copy Cordova framework files +``` +platforms/android/CordovaLib/src/.* to /app/main/java +platforms/android/src/** to /app/main/java +``` -4. Modify the layout file of the activity that shall host the Cordova view e.g. +1. Modify the layout file of the activity that shall host the Cordova view e.g. ``` - - - + Date: Tue, 13 Nov 2018 17:58:43 +0100 Subject: [PATCH 3/7] GH-884 android: Embedding Android WebView doc looks broken Applied suggested formatting changes --- www/docs/en/dev/guide/platforms/android/webview.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index 5f09040779..7f6a2b9022 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -41,10 +41,9 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. 1. Follow the instructions here to build your first cordova app [CreateYourFirstApp](https://cordova.apache.org/docs/en/8.x/guide/cli/index.html) 1. Copy Cordova framework files -``` -platforms/android/CordovaLib/src/.* to /app/main/java -platforms/android/src/** to /app/main/java -``` + +* `platforms/android/CordovaLib/src/.*` to `/app/main/java/` +* `platforms/android/src/*` to `/app/main/java/` 1. Modify the layout file of the activity that shall host the Cordova view e.g. ``` @@ -58,14 +57,14 @@ platforms/android/src/** to /app/main/java android:layout_height="match_parent" /> Date: Tue, 13 Nov 2018 18:05:59 +0100 Subject: [PATCH 4/7] Update www/docs/en/dev/guide/platforms/android/webview.md Co-Authored-By: martinhorvath --- www/docs/en/dev/guide/platforms/android/webview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index 7f6a2b9022..72e40b6ef3 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -38,7 +38,7 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. [cordova.apache.org](http://cordova.apache.org) and unzip its Android package. -1. Follow the instructions here to build your first cordova app [CreateYourFirstApp](https://cordova.apache.org/docs/en/8.x/guide/cli/index.html) +1. Follow [these instructions](https://cordova.apache.org/docs/en/latest/guide/cli/index.html) to build your first Cordova app 1. Copy Cordova framework files From 3445588e9de86483d857923eacb7602a5ebb7415 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Tue, 13 Nov 2018 18:08:47 +0100 Subject: [PATCH 5/7] Update www/docs/en/dev/guide/platforms/android/webview.md Co-Authored-By: martinhorvath --- www/docs/en/dev/guide/platforms/android/webview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index 72e40b6ef3..dab0ba1687 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -57,7 +57,7 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. android:layout_height="match_parent" /> Date: Tue, 13 Nov 2018 18:09:16 +0100 Subject: [PATCH 6/7] Update www/docs/en/dev/guide/platforms/android/webview.md Co-Authored-By: martinhorvath --- www/docs/en/dev/guide/platforms/android/webview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index dab0ba1687..546fcbdcde 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -69,7 +69,7 @@ public class TestActivity extends CordovaActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_test); //this is the layout file for your activity + setContentView(R.layout.activity_test); // layout file for your activity super.init(); loadUrl(launchUrl); } From f390b41589a840f75f20112047203950fd0eff60 Mon Sep 17 00:00:00 2001 From: Jan Piotrowski Date: Tue, 13 Nov 2018 18:10:10 +0100 Subject: [PATCH 7/7] Update www/docs/en/dev/guide/platforms/android/webview.md Co-Authored-By: martinhorvath --- www/docs/en/dev/guide/platforms/android/webview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/docs/en/dev/guide/platforms/android/webview.md b/www/docs/en/dev/guide/platforms/android/webview.md index 546fcbdcde..8151d6ea23 100644 --- a/www/docs/en/dev/guide/platforms/android/webview.md +++ b/www/docs/en/dev/guide/platforms/android/webview.md @@ -76,7 +76,7 @@ public void onCreate(Bundle savedInstanceState) { @Override protected CordovaWebView makeWebView() { - SystemWebView appView = (SystemWebView) findViewById(R.id.cordovaWebView); //this is the id for the SystemWebView in step 4 + SystemWebView appView = (SystemWebView) findViewById(R.id.cordovaWebView); // id for the SystemWebView in previous step return new CordovaWebViewImpl(new SystemWebViewEngine(appView)); }