Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add native custom views to HTML pages in PhoneGap/Cordova?

I am developing an Android PhoneGap application, where I need to add my custom camera/gallery views to HTML page - for example some empty DIV in my HTML Page, whose ID, I already have. How to achieve it?

I know how to write Plugins and basic HTML stuff.

is there any way, I can access elements of current HTML page in Cordova Webview?

my requirement is to add my customized camera view to HTML page with whatever dimensions I can.

like image 210
Ganesh K Avatar asked Feb 28 '14 08:02

Ganesh K


People also ask

Can Cordova/PhoneGap make your web app into a native mobile app?

Although the initial goal of wrapping an existing web app into a native mobile app might look simple enough with Cordova/Phonegap, in practice there a quite a few pitfalls in making sure that the experience is optimal for users and fulfills their expectations for what a native app experience is.

What is PhoneGap native packager?

PhoneGap provides a remote building interface at Adobe PhoneGap Build that lets you package and emulate an application for a single platform in the cloud. The PhoneGap Native Packager components have been updated to take full advantage of this feature. When choosing between Cordova and PhoneGap, it's important to note a few things:

What is Cordova and why should I use it?

What’s interesting about Cordova is that it can be extended using plugins which allow your app to use native device capabilities beyond what is available to pure web apps.

What is Adobe PhoneGap?

Adobe PhoneGap is a distribution of Apache Cordova and Cordova is an open-source mobile development framework that allows you to use standard web technologies — HTML5, CSS3, and JavaScript for cross-platform mobile development.


Video Answer


1 Answers

Update the answer:

I finally figured out how to do this.

First of all, you need to add your view, such as button, into the Cordova WebView. The Cordova WebView takes care the scroll.

webview.addView(button);

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L373

If the device orientation is changed, you need to change the size. But in Cordova, you can't not receive the event in java, so you need to listen the event in JavaScript.

window.addEventListener("orientationchange", onMapResize);

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/www/googlemaps-cdv-plugin.js#L1381

And here is the key point. Change the position in HTML to the point in View, you can do this

Math.round(d * webView.getScale());

https://github.com/wf9a5m75/phonegap-googlemaps-plugin/blob/master/src/android/plugin/google/maps/GoogleMaps.java#L383

Here is my plugin. I embed a Google Maps Android API v2 into the specified div tag.

enter image description here

like image 59
wf9a5m75 Avatar answered Sep 22 '22 04:09

wf9a5m75