package com.adsdk.sdk.banner;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.adsdk.sdk.Const;
import com.adsdk.sdk.Log;

public class InAppWebView extends Activity {

	public static final String URL_EXTRA = "extra_url";

	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

		final Intent intent = this.getIntent();

		initializeWebView(intent);

	}

	private void initializeWebView(Intent intent) {
		WebView webView = new WebView(this);
		this.setContentView(webView);
		WebSettings webSettings = webView.getSettings();

		webSettings.setJavaScriptEnabled(true);

		webSettings.setSupportZoom(true);
		webSettings.setBuiltInZoomControls(true);
		webSettings.setUseWideViewPort(true);
		webView.setWebViewClient(new WebViewClient() {
			@Override
			public void onReceivedError(WebView view, int errorCode, String description, 
					String failingUrl) {
				Activity a = (Activity) view.getContext();
				Toast.makeText(a, "MRAID error: " + description, Toast.LENGTH_SHORT).show();
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				if (url == null) return false;

				Uri uri = Uri.parse(url);
				String host = uri.getHost();

				if ((url.startsWith("http:") || url.startsWith("https:"))
						&& !"play.google.com".equals(host)
						&& !"market.android.com".equals(host)) {
					view.loadUrl(url);
					return true;
				}

				try {
					startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
				} catch (ActivityNotFoundException exception) {
					Log.w("MoPub", "Unable to start activity for " + url + ". " +
							"Ensure that your phone can handle this intent.");
				}

				finish();
				return true;

			}

		});

		webView.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int progress) {
				Activity a = (Activity) view.getContext();
				a.setTitle("Loading...");
				a.setProgress(progress * 100);
				if (progress == 100) a.setTitle(view.getUrl());
			}
		});
		webView.loadUrl(intent.getStringExtra(Const.REDIRECT_URI));
	}

}

@@ -22,24 +22,65 @@
 .banner;%0D%0A%0D%0A
+import android.annotation.SuppressLint;%0D%0A
 import andro
@@ -97,16 +97,16 @@
 ivity;%0D%0A
-
 import a
@@ -437,18 +437,16 @@
 Toast;%0D%0A
-%0D%0A
 import c
@@ -937,16 +937,56 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@SuppressLint(%22SetJavaScriptEnabled%22)%0D%0A
 %09private
@@ -1466,23 +1466,16 @@
 iption, 
-%0D%0A%09%09%09%09%09
 String f
@@ -1732,17 +1732,23 @@
 == null)
- 
+%0D%0A%09%09%09%09%09
 return f
@@ -1884,24 +1884,17 @@
 ttps:%22))
-%0D%0A%09%09%09%09%09%09
+ 
 && !%22pla
@@ -1919,24 +1919,17 @@
 ls(host)
-%0D%0A%09%09%09%09%09%09
+ 
 && !%22mar
@@ -1957,16 +1957,41 @@
 ls(host)
+ && !url.endsWith(%22.apk%22)
 ) %7B%0D%0A%09%09%09
@@ -2243,17 +2243,9 @@
  %22 +
-%0D%0A%09%09%09%09%09%09%09
+ 
 %22Ens
@@ -2610,17 +2610,23 @@
  == 100)
- 
+%0D%0A%09%09%09%09%09
 a.setTit

Fix .apk handling in in-app links.