Example usage for android.webkit WebView findViewById

List of usage examples for android.webkit WebView findViewById

Introduction

In this page you can find the example usage for android.webkit WebView findViewById.

Prototype

@Nullable
public final <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID, the view itself if the ID matches #getId() , or null if the ID is invalid (< 0) or there is no matching view in the hierarchy.

Usage

From source file:org.noise_planet.noisecapture.MapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view == null) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_measurement_map, container, false);
        leaflet = (WebView) view.findViewById(R.id.measurement_webmapview);
        leaflet.clearCache(true);//from   w w  w .  ja  v a  2 s  . c o  m
        leaflet.clearHistory();
        WebSettings webSettings = leaflet.getSettings();
        webSettings.setJavaScriptEnabled(true);
        WebSettings settings = leaflet.getSettings();
        settings.setAppCachePath(new File(getContext().getCacheDir(), "webview").getPath());
        settings.setAppCacheEnabled(true);
        leaflet.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                pageLoaded.set(true);
                if (mapFragmentAvailableListener != null) {
                    mapFragmentAvailableListener.onPageLoaded(MapFragment.this);
                }
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(browserIntent);
                return true;
            }
        });
        if (mapFragmentAvailableListener != null) {
            mapFragmentAvailableListener.onMapFragmentAvailable(this);
        }
    }
    return view;
}

From source file:de.geeksfactory.opacclient.frontend.InfoFragment.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/* www  .  j a  v a2 s  . c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    view = inflater.inflate(R.layout.fragment_info, container, false);
    app = (OpacClient) getActivity().getApplication();

    setHasOptionsMenu(true);

    load();

    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    wvInfo = (WebView) view.findViewById(R.id.wvInfo);

    wvInfo.getSettings().setSupportZoom(true);
    wvInfo.getSettings().setJavaScriptEnabled(true);
    wvInfo.getSettings().setAppCacheMaxSize(5 * 1024 * 1024);
    wvInfo.getSettings().setAppCacheEnabled(true);
    wvInfo.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

    wvInfo.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView v, int progress) {
            ProgressBar Pbar = (ProgressBar) view.findViewById(R.id.pbWebProgress);
            if (progress < 100 && Pbar.getVisibility() == View.GONE) {
                Pbar.setVisibility(View.VISIBLE);
            }
            Pbar.setProgress(progress);
            if (progress == 100) {
                Pbar.setVisibility(View.GONE);
            }
        }

    });
    wvInfo.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains(app.getLibrary().getData().optString("webviewcontain", "NOPE"))) {
                return false;
            }
            if (getActivity() == null) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }

    });

    return view;
}