Skip to content

Loading…

Added android confirm dialog for removing containers. #2

Merged
merged 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 39 additions and 4 deletions.
  1. +2 −2 AndroidManifest.xml
  2. +37 −2 src/com/boxmeup/app/MainActivity.java
View
4 AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.boxmeup.app"
- android:versionCode="2"
- android:versionName="1.1">
+ android:versionCode="3"
+ android:versionName="1.2">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8"/>
View
39 src/com/boxmeup/app/MainActivity.java
@@ -1,7 +1,9 @@
package com.boxmeup.app;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.net.http.SslError;
import android.os.Bundle;
@@ -10,7 +12,9 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
+import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
@@ -20,8 +24,6 @@
import com.boxmeup.app.scans.UpcScanResult;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
-import java.util.logging.Level;
-import java.util.logging.Logger;
public class MainActivity extends Activity {
@@ -29,6 +31,7 @@
ImageView mImageView;
boolean loggedIn = false;
private String currentContainerSlug;
+ final Context boxmeupApp = this;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -41,6 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(getString(R.string.url_source));
mWebView.setWebViewClient(new BoxmeupWebViewClient());
+ mWebView.setWebChromeClient(new BoxmeupWebChromeClient());
// Initialize the javascript interface
mWebView.addJavascriptInterface(new BoxmeupJavascriptInterface(this), getString(R.string.javascript_interface));
@@ -171,6 +175,37 @@ public void onPageFinished(WebView view, String url) {
view.setVisibility(View.VISIBLE);
}
}
+
+ /**
+ * Nested class that controls webview chrome events.
+ */
+ private class BoxmeupWebChromeClient extends WebChromeClient {
+
+ /**
+ * Handle a webview's JS confirm dialog
+ */
+ @Override
+ public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
+ new AlertDialog.Builder(boxmeupApp)
+ .setTitle(R.string.app_name)
+ .setMessage(message)
+ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ result.confirm();
+ }
+ })
+
+ .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ result.cancel();
+ }
+ })
+ .create()
+ .show();
+
+ return true;
+ }
+ }
/**
* Javascript interface that allows the web application to talk to the
Something went wrong with that request. Please try again.