| Index: libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/webviewapp/MainActivity.java |
| diff --git a/libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/webviewapp/MainActivity.java b/libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/webviewapp/MainActivity.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ca73b961ea7e42a7eb07ca040151006a7806b04b |
| --- /dev/null |
| +++ b/libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/webviewapp/MainActivity.java |
| @@ -0,0 +1,128 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2016 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +package org.adblockplus.libadblockplus.webviewapp; |
| + |
| +import org.adblockplus.android.AdblockWebView; |
| + |
| +import android.app.Activity; |
| +import android.graphics.Bitmap; |
| +import android.os.Bundle; |
| +import android.view.View; |
| +import android.webkit.WebChromeClient; |
| +import android.webkit.WebView; |
| +import android.webkit.WebViewClient; |
| +import android.widget.Button; |
| +import android.widget.EditText; |
| +import android.widget.ProgressBar; |
| + |
| +public class MainActivity extends Activity |
| +{ |
| + private static final boolean DEVELOPMENT_BUILD = true; |
| + |
| + private ProgressBar progress; |
| + private EditText url; |
| + private Button ok; |
| + private AdblockWebView webView; |
| + |
| + @Override |
| + protected void onCreate(Bundle savedInstanceState) |
| + { |
| + super.onCreate(savedInstanceState); |
| + setContentView(R.layout.activity_main); |
| + |
| + bindControls(); |
| + initControls(); |
| + } |
| + |
| + private void bindControls() |
| + { |
| + url = (EditText) findViewById(R.id.main_url); |
| + ok = (Button) findViewById(R.id.main_ok); |
| + progress = (ProgressBar) findViewById(R.id.main_progress); |
| + webView = (AdblockWebView) findViewById(R.id.main_webview); |
| + } |
| + |
| + private void setProgressVisible(boolean visible) |
| + { |
| + progress.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| + } |
| + |
| + private WebViewClient webViewClient = new WebViewClient() |
| + { |
| + @Override |
| + public void onPageStarted(WebView view, String url, Bitmap favicon) |
| + { |
| + setProgressVisible(true); |
| + } |
| + |
| + @Override |
| + public void onPageFinished(WebView view, String url) |
| + { |
| + setProgressVisible(false); |
| + } |
| + }; |
| + |
| + private WebChromeClient webChromeClient = new WebChromeClient() |
| + { |
| + @Override |
| + public void onProgressChanged(WebView view, int newProgress) |
| + { |
| + progress.setProgress(newProgress); |
| + } |
| + }; |
| + |
| + private void initControls() |
| + { |
| + ok.setOnClickListener(new View.OnClickListener() |
| + { |
| + @Override |
| + public void onClick(View view) |
| + { |
| + loadUrl(); |
| + } |
| + }); |
| + |
| + setProgressVisible(false); |
| + |
| + // to get debug/warning log output |
| + webView.setDebugMode(DEVELOPMENT_BUILD); |
| + |
| + // render as fast as we can |
| + webView.setAllowDrawDelay(0); |
| + |
| + // to show that external WebViewClient is still working |
| + webView.setWebViewClient(webViewClient); |
| + |
| + // to show that external WebChromeClient is still working |
| + webView.setWebChromeClient(webChromeClient); |
| + } |
| + |
| + private void loadUrl() |
| + { |
| + webView.loadUrl(url.getText().toString()); |
| + } |
| + |
| + @Override |
| + protected void onDestroy() |
| + { |
| + webView.stopLoading(); |
| + webView.dispose(); |
| + |
| + super.onDestroy(); |
| + } |
| +} |