Skip to content

Commit

Permalink
Start adding events to InAppBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst committed Nov 28, 2012
1 parent 48f5811 commit a42dc08
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions framework/src/org/apache/cordova/InAppBrowser.java
Expand Up @@ -209,6 +209,7 @@ public String openExternal(String url) {
*/
private void closeDialog() {
// TODO: fire 'exit' event
this.webView.sendJavascript("cordova.fireWindowEvent('exit');");
if (dialog != null) {
dialog.dismiss();
}
Expand Down Expand Up @@ -271,6 +272,8 @@ public String showWebPage(final String url, HashMap<String, Boolean> features) {
if (features != null) {
showLocationBar = features.get(LOCATION).booleanValue();
}

final CordovaWebView thatWebView = this.webView;

// Create dialog in new thread
Runnable runnable = new Runnable() {
Expand Down Expand Up @@ -394,7 +397,7 @@ public void onClick(View v) {
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);
Expand Down Expand Up @@ -464,14 +467,16 @@ private void sendUpdate(JSONObject obj, boolean keepCallback) {
*/
public class InAppBrowserClient extends WebViewClient {
EditText edittext;
CordovaWebView webView;

/**
* Constructor.
*
* @param mContext
* @param edittext
*/
public InAppBrowserClient(EditText mEditText) {
public InAppBrowserClient(CordovaWebView webView, EditText mEditText) {
this.webView = webView;
this.edittext = mEditText;
}

Expand All @@ -495,21 +500,14 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
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 + "');");
}
}
}

0 comments on commit a42dc08

Please sign in to comment.