Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-webviewapp/src/org/adblockplus/libadblockplus/webviewapp/MainActivity.java

Issue 29351744: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: yet another improvement - working with null urls (for local files) Created Sept. 22, 2016, 8:08 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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 String prepareUrl(String url)
116 {
117 if (!url.startsWith("http"))
118 url = "http://" + url;
119
120 // make sure url is valid URL
121 return url;
122 }
123
124 private void loadUrl()
125 {
126 webView.loadUrl(prepareUrl(url.getText().toString()));
127 }
128
129 @Override
130 protected void onDestroy()
131 {
132 webView.dispose();
133
134 super.onDestroy();
135 }
136 }
OLDNEW
« no previous file with comments | « libadblockplus-android-webviewapp/res/values/strings.xml ('k') | libadblockplus-android/assets/css.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld