| OLD | NEW | 
| (Empty) |  | 
 |    1 /* | 
 |    2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
 |    3  * Copyright (C) 2006-2016 Eyeo GmbH | 
 |    4  * | 
 |    5  * Adblock Plus is free software: you can redistribute it and/or modify | 
 |    6  * it under the terms of the GNU General Public License version 3 as | 
 |    7  * published by the Free Software Foundation. | 
 |    8  * | 
 |    9  * Adblock Plus is distributed in the hope that it will be useful, | 
 |   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 |   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 |   12  * GNU General Public License for more details. | 
 |   13  * | 
 |   14  * You should have received a copy of the GNU General Public License | 
 |   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
 |   16  */ | 
 |   17  | 
 |   18 package org.adblockplus.libadblockplus.webviewapp; | 
 |   19  | 
 |   20 import org.adblockplus.android.AdblockWebView; | 
 |   21  | 
 |   22 import android.app.Activity; | 
 |   23 import android.graphics.Bitmap; | 
 |   24 import android.os.Bundle; | 
 |   25 import android.view.View; | 
 |   26 import android.webkit.WebChromeClient; | 
 |   27 import android.webkit.WebView; | 
 |   28 import android.webkit.WebViewClient; | 
 |   29 import android.widget.Button; | 
 |   30 import android.widget.EditText; | 
 |   31 import android.widget.ProgressBar; | 
 |   32  | 
 |   33 public class MainActivity extends Activity | 
 |   34 { | 
 |   35   private static final boolean DEVELOPMENT_BUILD = true; | 
 |   36  | 
 |   37   private ProgressBar progress; | 
 |   38   private EditText url; | 
 |   39   private Button ok; | 
 |   40   private AdblockWebView webView; | 
 |   41  | 
 |   42   @Override | 
 |   43   protected void onCreate(Bundle savedInstanceState) | 
 |   44   { | 
 |   45     super.onCreate(savedInstanceState); | 
 |   46     setContentView(R.layout.activity_main); | 
 |   47  | 
 |   48     bindControls(); | 
 |   49     initControls(); | 
 |   50   } | 
 |   51  | 
 |   52   private void bindControls() | 
 |   53   { | 
 |   54     url = (EditText) findViewById(R.id.main_url); | 
 |   55     ok = (Button) findViewById(R.id.main_ok); | 
 |   56     progress = (ProgressBar) findViewById(R.id.main_progress); | 
 |   57     webView = (AdblockWebView) findViewById(R.id.main_webview); | 
 |   58   } | 
 |   59  | 
 |   60   private void setProgressVisible(boolean visible) | 
 |   61   { | 
 |   62     progress.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); | 
 |   63   } | 
 |   64  | 
 |   65   private WebViewClient webViewClient = new WebViewClient() | 
 |   66   { | 
 |   67     @Override | 
 |   68     public void onPageStarted(WebView view, String url, Bitmap favicon) | 
 |   69     { | 
 |   70       setProgressVisible(true); | 
 |   71     } | 
 |   72  | 
 |   73     @Override | 
 |   74     public void onPageFinished(WebView view, String url) | 
 |   75     { | 
 |   76       setProgressVisible(false); | 
 |   77     } | 
 |   78   }; | 
 |   79  | 
 |   80   private WebChromeClient webChromeClient = new WebChromeClient() | 
 |   81   { | 
 |   82     @Override | 
 |   83     public void onProgressChanged(WebView view, int newProgress) | 
 |   84     { | 
 |   85       progress.setProgress(newProgress); | 
 |   86     } | 
 |   87   }; | 
 |   88  | 
 |   89   private void initControls() | 
 |   90   { | 
 |   91     ok.setOnClickListener(new View.OnClickListener() | 
 |   92     { | 
 |   93       @Override | 
 |   94       public void onClick(View view) | 
 |   95       { | 
 |   96         loadUrl(); | 
 |   97       } | 
 |   98     }); | 
 |   99  | 
 |  100     setProgressVisible(false); | 
 |  101  | 
 |  102     // to get debug/warning log output | 
 |  103     webView.setDebugMode(DEVELOPMENT_BUILD); | 
 |  104  | 
 |  105     // render as fast as we can | 
 |  106     webView.setAllowDrawDelay(0); | 
 |  107  | 
 |  108     // to show that external WebViewClient is still working | 
 |  109     webView.setWebViewClient(webViewClient); | 
 |  110  | 
 |  111     // to show that external WebChromeClient is still working | 
 |  112     webView.setWebChromeClient(webChromeClient); | 
 |  113   } | 
 |  114  | 
 |  115   private void loadUrl() | 
 |  116   { | 
 |  117     webView.loadUrl(url.getText().toString()); | 
 |  118   } | 
 |  119  | 
 |  120   @Override | 
 |  121   protected void onDestroy() | 
 |  122   { | 
 |  123     webView.stopLoading(); | 
 |  124     webView.dispose(); | 
 |  125  | 
 |  126     super.onDestroy(); | 
 |  127   } | 
 |  128 } | 
| OLD | NEW |