You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
## Creating Apps with PhoneGap and Android Native Components using the Android Studio extension.
14
+
This tutorial will show you how to add PhoneGap/Cordova support to an existing Android project using PhoneGap's Android Studio extension.
15
15
16
-
### Prerequisites:
16
+
**Notice: make sure you're in `Text` mode when editing XML files. Select the `Text` tab at the bottom of the XML editor.**
17
17
18
-
****PhoneGap Android Studio extension***
18
+
### Create Android project
19
19
20
-
Please install it directly in Android Studio. Under *Preferences* > *Plugins*.
21
-
22
-

23
-
24
-
### Embedding a WebView
25
-
26
-
* create a new android project, set application name to "componentcase", company domain to "phonegapday.com" and edit package name to be "com.phonegapday". click next.
20
+
* Create a new android project, set Application name to "ComponentCase", Company Domain to "phonegapday.com" and edit Package name to be "com.phonegapday". Click next.
27
21
28
22

29
23
30
-
*check "phone and tablet" and set minimum sdk to api 21: android 5.0 (lollipop)
24
+
*Check "Phone and Tablet" and set Minimum SDK to API 21: Android 5.0 (Lollipop)
31
25
32
26

33
27
34
-
*click next and select "navigation drawer activity".
28
+
*Click next and select "Navigation Drawer Activity".
35
29
36
30

37
31
38
-
*click next and click finish
32
+
*Click next and click Finish
39
33
40
34

41
35
42
-
*clean up a few things
36
+
*Clean up a few things
43
37
* open `res/menu/activity_main_drawer.xml` and make sure it looks like this
* open `res/layout/app_bar_main.xml` and delete the `floatingactionbutton`
54
+
* open `res/layout/app_bar_main.xml` and delete the `FloatingActionButton`
61
55
* delete all `ic_menu*` from `res/drawable`
62
-
* open `res/layout/nav_header_main.xml` and change the first textview's text by "componentcase". delete the imageview and the other textview.
56
+
* open `res/layout/nav_header_main.xml` and change the first `TextView`'s text to "**ComponentCase**". Delete the `ImageView` and the other `TextView`.
63
57
* open `res/values/dimens.xml` and change `nav_header_height` to '100dp'
64
-
* open 'mainactivity' and delete lines 26-33 (floatingactionbutton) and make sure your `onnavigationitemselected` method looks like this
* Make sure you have [NodeJS](https://nodejs.org) installed. If you already have [NodeJS](https://nodejs.org) installed make sure you `npm install -g plugman`
85
-
* Go to **Android Studio** > `Preferences` > `Plugins` and click on _install JetBrains Plugin_ button.
81
+
* Go to **Android Studio** > `Preferences` > `Plugins` and click on _Browse Repositories_ button.
86
82
* Search for `PhoneGap` and install it. Make sure you don't install the **PhoneGap/Cordova Plugin**
87
83
* Restart **Android Studio**
88
84
* Go to `Tools` > `PhoneGap` > `Initialize Project`
89
-
* Copy everything from www-shared/www to this newly created assets/www
85
+
* You should see a notification: **"Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly"**. Click on **Sync Now**
86
+
* Copy everything from [www-shared/www](https://github.com/imhotep/PGDayEUWs2016/tree/master/www-shared) to this newly created `assets/www`
87
+
* You can run the following to get `www-shared` easily inside your `app/src/main/assets` folder
* Go to `Tools` > `PhoneGap` > `Install Plugin from npm`
91
92
* Type in `cordova-plugin-device`
92
93
* Go to `Tools` > `PhoneGap` > `Install Plugin from npm`
94
+
* Type in `cordova-plugin-console`
95
+
* Go to `Tools` > `PhoneGap` > `Install Plugin from filesystem`
96
+
* Select `cordova-plugin-pgdayeu16` which can be found at [cordova-plugin-pgdayeu16](https://github.com/imhotep/PGDayEUWs2016/tree/master/cordova-plugin-pgdayeu16)
97
+
* Again you can easily fetch the plugin to your filesystem using the following command
1* Go to `Tools` > `PhoneGap` > `Install Plugin from filesystem`
96
-
1* Select `cordova-plugin-pgdayeu16` which can be found at [cordova-plugin-pgdayeu16](https://github.com/imhotep/PGDayEUWs2016/tree/master/cordova-plugin-pgdayeu16)
102
+
### Embedding CordovaWebView
97
103
98
-
* Add the following line to your `res/values/strings.xml`
104
+
* open `res/layout/content_main.xml` and replace the TextView with the following
105
+
```XML
106
+
<org.apache.cordova.engine.SystemWebView
107
+
android:id="@+id/WebViewComponent"
108
+
android:layout_width="match_parent"
109
+
android:layout_height="match_parent">
110
+
</org.apache.cordova.engine.SystemWebView>
111
+
```
112
+
* Add the following attributes to `MainActivity.java`. Make sure you fix the imports.
* Set up the native ListView by adding the following lines to your `onCreate` method. Fix imports
199
+
* Set up the native ListView by adding the following lines to your `onCreate` method
139
200
140
201
```Java
141
202
// Set up the bookmark view
@@ -182,6 +243,7 @@ Please install it directly in Android Studio. Under *Preferences* > *Plugins*.
182
243
}
183
244
184
245
```
246
+
* Fix imports
185
247
* Add this line to your `res/layout/content_main.xml`
186
248
187
249
```XML
@@ -224,4 +286,8 @@ Please install it directly in Android Studio. Under *Preferences* > *Plugins*.
224
286
```XML
225
287
android:windowSoftInputMode="adjustPan"
226
288
```
289
+
290
+
### Run the application
291
+
292
+
* Run the application by clicking on `Run` -> `Run 'app'`. You notice that elements added in the webview and native view are sychronized. Check out the plugin code for more details.
227
293
* To avoid seeing weird `eglCodecCommon` errors in the console add this to your filter: `^(?!eglCodecCommon)`
0 commit comments