Example usage for android.webkit WebView WebView

List of usage examples for android.webkit WebView WebView

Introduction

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

Prototype

public WebView(Context context) 

Source Link

Document

Constructs a new WebView with an Activity Context object.

Usage

From source file:com.klinker.android.spotify.fragment.BaseOAuthFragment.java

/**
 * Craete a webview to display information in
 *//*from   w  w w .j a v  a2s.  co  m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
    loginWebView = new WebView(getActivity());

    try {
        loginWebView.getSettings().setJavaScriptEnabled(true);
    } catch (Exception e) {
    }

    loginWebView.setWebViewClient(getWebViewClient());
    return loginWebView;
}

From source file:com.snappydb.snippets.app.fragment.SnippetWebViewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    if (null == mWebView) {
        mWebView = new WebView(getActivity());
        configureWebSettings();/*from  w  w  w.j  a  v  a  2s.  c  o m*/
    }

    mWebView.loadUrl(mUrl);
    return mWebView;
}

From source file:com.cerema.cloud2.ui.dialog.ChangelogDialog.java

/**
 * {@inheritDoc}/*from w w w  .  j av a  2 s .  co m*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    /// load the custom view to insert in the dialog, between title and 
    WebView webview = new WebView(getActivity());
    webview.loadUrl(
            "file:///android_res/raw/" + getResources().getResourceEntryName(R.raw.changelog) + ".html");

    /// build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    Dialog dialog = builder.setView(webview).setIcon(DisplayUtils.getSeasonalIconId())
            //.setTitle(R.string.whats_new)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    dialog.setCancelable(getArguments().getBoolean(ARG_CANCELABLE));
    return dialog;
}

From source file:com.example.jarida.PayPalLoginActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    webView = new WebView(this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new PPWebViewClient());

    setContentView(webView);/*w  w w.j a va  2s  . c  o m*/

    helper = AccessHelperConnect.init(CLIENT_ID, CLIENT_SECRET);

    progress = ProgressDialog.show(PayPalLoginActivity.this, getString(R.string.progress_loading_title),
            getString(R.string.progress_loading_msg));

    webView.loadUrl(helper.getAuthUrl());
}

From source file:com.huangyu.mdeditor.ui.widget.MarkdownPreviewView.java

@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
private void init(Context context) {
    if (!isInEditMode()) {
        this.mContext = context;
        if (VERSION.SDK_INT >= 21) {
            WebView.enableSlowWholeDocumentDraw();
        }/*from w  w  w .ja  v  a 2  s.  c  o m*/
        this.mWebView = new WebView(this.mContext);
        this.mWebView.getSettings().setJavaScriptEnabled(true);
        this.mWebView.setVerticalScrollBarEnabled(false);
        this.mWebView.setHorizontalScrollBarEnabled(false);
        this.mWebView.addJavascriptInterface(new JavaScriptInterface(this), "handler");
        this.mWebView.setWebViewClient(new MdWebViewClient(this));
        this.mWebView.loadUrl("file:///android_asset/markdown.html");
        addView(this.mWebView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }
}

From source file:org.lib.MarkdownPreviewView.java

@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
private void init(Context context) {
    if (!isInEditMode()) {
        this.mContext = context;

        if (Build.VERSION.SDK_INT >= 21) {
            WebView.enableSlowWholeDocumentDraw();
        }//from   w w  w .  j a  v a  2 s . c  o m
        this.mWebView = new WebView(this.mContext);
        this.mWebView.getSettings().setJavaScriptEnabled(true);
        this.mWebView.setVerticalScrollBarEnabled(false);
        this.mWebView.setHorizontalScrollBarEnabled(false);
        this.mWebView.addJavascriptInterface(new JavaScriptInterface(this), "handler");
        this.mWebView.setWebViewClient(new MdWebViewClient(this));
        this.mWebView.loadUrl("file:///android_asset/markdown.html");
        addView(this.mWebView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }
}

From source file:com.usabusi.newsreader.ArticleFragment.java

/**
 * Sets up the UI. It consists if a single WebView.
 *///from  ww w .j a  v  a  2s . com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mWebView = new WebView(getActivity());
    //http://stackoverflow.com/questions/17259537/load-webview-from-cache
    WebSettings webSettings = mWebView.getSettings();
    // Enable JavaScript
    webSettings.setJavaScriptEnabled(true); // enable javascript
    mWebView.setHorizontalScrollBarEnabled(false);
    webSettings.setAppCacheMaxSize(5 * 1024 * 1024); // 5MB
    webSettings.setAppCachePath(getActivity().getApplicationContext().getCacheDir().getAbsolutePath());
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); // load online by default
    //http://stackoverflow.com/questions/25161720/url-opened-in-browser-instead-of-web-view
    mWebView.setVisibility(View.VISIBLE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setBuiltInZoomControls(true);

    //final Activity activity = this;
    // Make WebClient
    mWebView.setWebViewClient(new WebViewClient() {
        // Trace Errors
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(getActivity().getApplicationContext(), description, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //http://developer.android.com/guide/webapps/webview.html#HandlingNavigation
            //                view.loadUrl(url);
            //                return true;
            return false;
        }
    });

    loadWebView();
    return mWebView;
}

From source file:com.github.yuukis.businessmap.app.LicenseDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    String html = AssetUtils.getText(getActivity(), FILEPATH);
    try {/*from  w  w w  . j ava  2 s. c  o m*/
        html = URLEncoder.encode(html, "utf-8").replaceAll("\\+", "%20");
    } catch (UnsupportedEncodingException e) {
    }
    WebView webView = new WebView(getActivity());
    webView.loadData(html, "text/html", "utf-8");
    return webView;
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedMapFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ContentResolver resolver = getActivity().getContentResolver();
    resolver.registerContentObserver(mFeedUri, true, mFeedObserver);

    View view = new WebView(getActivity());
    view.setLayoutParams(LAYOUT_FULL_WIDTH);
    view.setId(android.R.id.custom);/*  w  w  w. j  a va2  s. c om*/
    return view;
}

From source file:at.alladin.rmbt.android.help.RMBTHelpFragment.java

/**
* 
*///from   www  .j  a v  a 2  s .  c  o m
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    final Bundle args = getArguments();

    String url = args.getString(ARG_URL);

    if (url == null || url.length() == 0)
        url = this.getString(R.string.url_help);

    final Activity activity = getActivity();

    final WebView webview = new WebView(activity) {
        @Override
        public boolean onKeyDown(final int keyCode, final KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && canGoBack()) {
                goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    };

    final WebSettings webSettings = webview.getSettings();
    final String userAgent = AppConstants.getUserAgentString(getActivity());
    if (userAgent != null) {
        webSettings.setUserAgentString(userAgent);
    }
    webSettings.setJavaScriptEnabled(true);

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(final WebView view, final int errorCode, final String description,
                final String failingUrl) {
            Log.w(getTag(), "error code:" + errorCode);
            Log.d(getTag(), "error desc:" + description);
            Log.d(getTag(), "error url:" + failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });

    if (!url.matches("^https?://.*")) {
        final String protocol = ConfigHelper.isControlSeverSSL(activity) ? "https" : "http";
        url = protocol + "://" + url;
    }

    webview.loadUrl(url);

    return webview;
}