Search in sources :

Example 1 with AdBlockWebViewClient

use of io.github.hidroh.materialistic.widget.AdBlockWebViewClient in project materialistic by hidroh.

the class WebFragment method setUpWebView.

private void setUpWebView(View view) {
    mProgressBar = (ProgressBar) view.findViewById(R.id.progress);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    mWebView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(getActivity())) {

        @Override
        public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (getActivity() != null) {
                getActivity().supportInvalidateOptionsMenu();
            }
        }

        @Override
        public void onPageFinished(android.webkit.WebView view, String url) {
            super.onPageFinished(view, url);
            if (getActivity() != null) {
                getActivity().supportInvalidateOptionsMenu();
            }
        }
    });
    mWebView.setWebChromeClient(new CacheableWebView.ArchiveClient() {

        @Override
        public void onProgressChanged(android.webkit.WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            mProgressBar.setProgress(newProgress);
            mProgressBar.setVisibility(newProgress == 100 ? GONE : VISIBLE);
            mButtonRefresh.setImageResource(newProgress == 100 ? R.drawable.ic_refresh_white_24dp : R.drawable.ic_clear_white_24dp);
        }
    });
    mWebView.setDownloadListener((url, userAgent, contentDisposition, mimetype, contentLength) -> {
        if (getActivity() == null) {
            return;
        }
        final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
            return;
        }
        mExternalRequired = true;
        mWebView.setVisibility(GONE);
        view.findViewById(R.id.empty).setVisibility(VISIBLE);
        view.findViewById(R.id.download_button).setOnClickListener(v -> startActivity(intent));
    });
    AppUtils.toggleWebViewZoom(mWebView.getSettings(), false);
}
Also used : Bitmap(android.graphics.Bitmap) AdBlockWebViewClient(io.github.hidroh.materialistic.widget.AdBlockWebViewClient) Intent(android.content.Intent) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) SuppressLint(android.annotation.SuppressLint)

Example 2 with AdBlockWebViewClient

use of io.github.hidroh.materialistic.widget.AdBlockWebViewClient in project materialistic by hidroh.

the class OfflineWebActivity method onCreate.

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getStringExtra(EXTRA_URL);
    if (TextUtils.isEmpty(url)) {
        finish();
        return;
    }
    setTitle(url);
    setContentView(R.layout.activity_offline_web);
    final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scroll_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setSubtitle(R.string.offline);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    final WebView webView = (WebView) findViewById(R.id.web_view);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)) {

        @Override
        public void onPageFinished(WebView view, String url) {
            setTitle(view.getTitle());
        }
    });
    webView.setWebChromeClient(new CacheableWebView.ArchiveClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                webView.setBackgroundColor(Color.WHITE);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    AppUtils.toggleWebViewZoom(webView.getSettings(), true);
    webView.loadUrl(url);
}
Also used : AdBlockWebViewClient(io.github.hidroh.materialistic.widget.AdBlockWebViewClient) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) NestedScrollView(android.support.v4.widget.NestedScrollView) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) WebView(android.webkit.WebView) ProgressBar(android.widget.ProgressBar) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with AdBlockWebViewClient

use of io.github.hidroh.materialistic.widget.AdBlockWebViewClient in project materialistic by hidroh.

the class SyncDelegate method loadArticle.

private void loadArticle(@NonNull final HackerNewsItem item) {
    mWebView = new CacheableWebView(mContext);
    mWebView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(mContext)));
    mWebView.setWebChromeClient(new CacheableWebView.ArchiveClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            notifyArticle(newProgress);
        }
    });
    notifyArticle(0);
    mWebView.loadUrl(item.getUrl());
}
Also used : AdBlockWebViewClient(io.github.hidroh.materialistic.widget.AdBlockWebViewClient) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) WebView(android.webkit.WebView) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) SuppressLint(android.annotation.SuppressLint)

Example 4 with AdBlockWebViewClient

use of io.github.hidroh.materialistic.widget.AdBlockWebViewClient in project materialistic by hidroh.

the class WebCacheService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent == null) {
        // restarted
        stopSelf(startId);
        return START_STICKY;
    }
    CacheableWebView webView = new CacheableWebView(this);
    webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)));
    webView.setWebChromeClient(new CacheableWebView.ArchiveClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                stopSelf(startId);
            }
        }
    });
    webView.loadUrl(intent.getStringExtra(EXTRA_URL));
    return START_STICKY;
}
Also used : AdBlockWebViewClient(io.github.hidroh.materialistic.widget.AdBlockWebViewClient) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) WebView(android.webkit.WebView)

Aggregations

AdBlockWebViewClient (io.github.hidroh.materialistic.widget.AdBlockWebViewClient)4 CacheableWebView (io.github.hidroh.materialistic.widget.CacheableWebView)4 WebView (android.webkit.WebView)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 NestedScrollView (android.support.v4.widget.NestedScrollView)1 Toolbar (android.support.v7.widget.Toolbar)1 ProgressBar (android.widget.ProgressBar)1