Search in sources :

Example 71 with WebView

use of android.webkit.WebView in project android-test-demo by abdyer.

the class WebViewActivity method loadUrl.

private void loadUrl() {
    String url = getIntent().getStringExtra(EXTRA_URL);
    webview.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
    webview.loadUrl(url);
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 72 with WebView

use of android.webkit.WebView in project DesignLibrary by StylingAndroid.

the class ItemFragment method onCreateView.

@Override
@SuppressLint("SetJavaScriptEnabled")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Item item = (Item) getArguments().getSerializable(KEY_ITEM);
    View view = inflater.inflate(R.layout.fragment_item, container, false);
    if (item != null) {
        WebView webView = (WebView) view.findViewById(R.id.web_view);
        String html = item.getContent();
        html = html.replaceAll(NEWLINE, BR);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadData(html, HTML_MIME_TYPE, null);
    }
    return view;
}
Also used : Item(com.stylingandroid.designlibrary.rss.model.Item) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) SuppressLint(android.annotation.SuppressLint)

Example 73 with WebView

use of android.webkit.WebView in project Reader by TheKeeperOfPie.

the class FragmentWeb method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_web, container, false);
    layoutRoot = (RelativeLayout) view;
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.loading_web_page));
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setOnClickListener(this);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hasExited = true;
            mListener.onNavigationBackClick();
        }
    });
    setUpOptionsMenu();
    progressBar = (ProgressBar) view.findViewById(R.id.progress_web);
    webView = (WebView) view.findViewById(R.id.web);
    webView.setBackgroundColor(getResources().getColor(R.color.darkThemeBackground));
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            toolbar.setTitle(url);
            progressBar.setIndeterminate(true);
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            toolbar.setTitle(view.getTitle());
        }

        //            @Override
        //            public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //                Log.d(TAG, "shouldOverrideUrlLoading: " + url);
        //
        //                Intent intent = new Intent(Intent.ACTION_VIEW);
        //                intent.setData(Uri.parse(url));
        //                PackageManager packageManager = view.getContext().getPackageManager();
        //                List<ResolveInfo> listResolveInfo = packageManager.queryIntentActivities(intent, 0);
        //
        //                Log.d(TAG, "listResolveInfo: " + listResolveInfo);
        //
        //                boolean containsAll = true;
        //
        //                for (ResolveInfo info : listResolveInfo) {
        //
        //                    boolean contains = false;
        //                    for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
        //                        if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
        //                                infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
        //                            contains = true;
        //                            break;
        //                        }
        //                    }
        //                    if (!contains) {
        //                        containsAll = false;
        //                        break;
        //                    }
        //                }
        //
        //                if (!containsAll) {
        //                    Iterator<ResolveInfo> iterator = listResolveInfo.iterator();
        //                    while (iterator.hasNext()) {
        //                        ResolveInfo info = iterator.next();
        //                        boolean contains = false;
        //                        for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
        //                            if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
        //                                    infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
        //                                contains = true;
        //                                break;
        //                            }
        //                        }
        //                        if (contains) {
        //                            iterator.remove();
        //                        }
        //                    }
        //
        //                    listResolveInfo.removeAll(listDefaultWebResolveInfo);
        //                    Collections.sort(listResolveInfo, new ResolveInfo.DisplayNameComparator(packageManager));
        //                    listResolveInfo.addAll(listDefaultWebResolveInfo);
        //                    showExternalLaunchDialog(url, listResolveInfo, packageManager);
        //                    return true;
        //                }
        //                return false;
        //            }
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            Log.e(TAG, "WebView error: " + error);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setIndeterminate(false);
            progressBar.setProgress(newProgress);
        }

        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            viewWebFullscreen = view;
            viewWebFullscreen.setBackgroundColor(0xFF000000);
            customViewCallback = callback;
            layoutRoot.addView(viewWebFullscreen, ViewGroup.LayoutParams.MATCH_PARENT);
            viewWebFullscreen.bringToFront();
        }

        @Override
        public void onHideCustomView() {
            super.onHideCustomView();
            layoutRoot.removeView(viewWebFullscreen);
            viewWebFullscreen = null;
        }
    });
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setSupportMultipleWindows(false);
    webView.setBackgroundColor(0xFFFFFFFF);
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    Log.d(TAG, "savedInstanceState: " + savedInstanceState);
    if (savedInstanceState == null) {
        webView.loadUrl(url);
    } else {
        webView.restoreState(savedInstanceState);
    }
    toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
    toolbarActions.inflateMenu(R.menu.menu_web_search);
    toolbarActions.setOnMenuItemClickListener(this);
    Menu menuActions = toolbarActions.getMenu();
    for (int index = 0; index < menuActions.size(); index++) {
        menuActions.getItem(index).getIcon().mutate().setColorFilter(themer.getColorFilterIcon());
    }
    return view;
}
Also used : WebResourceRequest(android.webkit.WebResourceRequest) SearchView(android.support.v7.widget.SearchView) View(android.view.View) WebView(android.webkit.WebView) Bitmap(android.graphics.Bitmap) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) Menu(android.view.Menu) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 74 with WebView

use of android.webkit.WebView in project Reader by TheKeeperOfPie.

the class ActivityLogin method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    CustomApplication.getComponentMain().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    layoutRoot = (ViewGroup) findViewById(R.id.layout_root);
    Themer themer = new Themer(this);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    progressAuth = (ProgressBar) findViewById(R.id.progress_auth);
    webAuth = (WebView) findViewById(R.id.web_auth);
    webAuth.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d(TAG, "onPageStarted() called with: " + "view = [" + view + "], url = [" + url + "], favicon = [" + favicon + "]");
            progressAuth.setIndeterminate(true);
            progressAuth.setVisibility(View.VISIBLE);
            Uri uri = Uri.parse(url);
            if (uri.getHost().equals(Reddit.REDIRECT_URI.replaceFirst("https://", ""))) {
                String error = uri.getQueryParameter("error");
                String returnedState = uri.getQueryParameter("state");
                if (!TextUtils.isEmpty(error) || !state.equals(returnedState)) {
                    Toast.makeText(ActivityLogin.this, error, Toast.LENGTH_LONG).show();
                    webAuth.loadUrl(Reddit.getUserAuthUrl(state));
                    return;
                }
                // TODO: Failsafe with error and state
                String code = uri.getQueryParameter("code");
                fetchTokens(code);
            }
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressAuth.setVisibility(View.GONE);
            toolbar.setTitle(view.getTitle());
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            Log.e(TAG, "WebView error: " + error);
        }
    });
    webAuth.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressAuth.setIndeterminate(false);
            progressAuth.setProgress(newProgress);
        }
    });
    webAuth.loadUrl(Reddit.getUserAuthUrl(state));
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) Themer(com.winsonchiu.reader.theme.Themer) WebView(android.webkit.WebView) Uri(android.net.Uri) WebViewClient(android.webkit.WebViewClient)

Example 75 with WebView

use of android.webkit.WebView in project FinestWebView-Android by TheFinestArtist.

the class FinestWebViewActivity method bindViews.

protected void bindViews() {
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);
    appBar = (AppBarLayout) findViewById(R.id.appBar);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbarLayout = (RelativeLayout) findViewById(R.id.toolbarLayout);
    title = (TextView) findViewById(R.id.title);
    urlTv = (TextView) findViewById(R.id.url);
    close = (AppCompatImageButton) findViewById(R.id.close);
    back = (AppCompatImageButton) findViewById(R.id.back);
    forward = (AppCompatImageButton) findViewById(R.id.forward);
    more = (AppCompatImageButton) findViewById(R.id.more);
    close.setOnClickListener(this);
    back.setOnClickListener(this);
    forward.setOnClickListener(this);
    more.setOnClickListener(this);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    gradient = findViewById(R.id.gradient);
    divider = findViewById(R.id.divider);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    menuLayout = (RelativeLayout) findViewById(R.id.menuLayout);
    shadowLayout = (ShadowLayout) findViewById(R.id.shadowLayout);
    menuBackground = (LinearLayout) findViewById(R.id.menuBackground);
    menuRefresh = (LinearLayout) findViewById(R.id.menuRefresh);
    menuRefreshTv = (TextView) findViewById(R.id.menuRefreshTv);
    menuFind = (LinearLayout) findViewById(R.id.menuFind);
    menuFindTv = (TextView) findViewById(R.id.menuFindTv);
    menuShareVia = (LinearLayout) findViewById(R.id.menuShareVia);
    menuShareViaTv = (TextView) findViewById(R.id.menuShareViaTv);
    menuCopyLink = (LinearLayout) findViewById(R.id.menuCopyLink);
    menuCopyLinkTv = (TextView) findViewById(R.id.menuCopyLinkTv);
    menuOpenWith = (LinearLayout) findViewById(R.id.menuOpenWith);
    menuOpenWithTv = (TextView) findViewById(R.id.menuOpenWithTv);
    webLayout = (FrameLayout) findViewById(R.id.webLayout);
    webView = new WebView(this);
    webLayout.addView(webView);
}
Also used : WebView(android.webkit.WebView)

Aggregations

WebView (android.webkit.WebView)328 WebViewClient (android.webkit.WebViewClient)108 View (android.view.View)82 WebSettings (android.webkit.WebSettings)48 Intent (android.content.Intent)42 SuppressLint (android.annotation.SuppressLint)37 WebChromeClient (android.webkit.WebChromeClient)37 TextView (android.widget.TextView)28 DialogInterface (android.content.DialogInterface)23 LinearLayout (android.widget.LinearLayout)23 ImageView (android.widget.ImageView)22 Bitmap (android.graphics.Bitmap)19 AlertDialog (android.app.AlertDialog)17 Test (org.junit.Test)15 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 Handler (android.os.Handler)11 WebResourceRequest (android.webkit.WebResourceRequest)11 Drawable (android.graphics.drawable.Drawable)10 Button (android.widget.Button)10