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:Main.java

private static String i(Context context) {
    if (h == null) {
        String s = (new WebView(context)).getSettings().getUserAgentString();
        if (s == null || s.length() == 0 || s.equals("Java0")) {
            String s1 = System.getProperty("os.name", "Linux");
            String s2 = (new StringBuilder()).append("Android ").append(android.os.Build.VERSION.RELEASE)
                    .toString();/*from   ww  w  .j  av  a 2 s.  c  o m*/
            Locale locale = Locale.getDefault();
            String s3 = locale.getLanguage().toLowerCase();
            if (s3.length() == 0)
                s3 = "en";
            String s4 = locale.getCountry().toLowerCase();
            String s5;
            String s6;
            if (s4.length() > 0)
                s5 = (new StringBuilder()).append(s3).append("-").append(s4).toString();
            else
                s5 = s3;
            s6 = (new StringBuilder()).append(Build.MODEL).append(" Build/").append(Build.ID).toString();
            s = (new StringBuilder()).append("Mozilla/5.0 (").append(s1).append("; U; ").append(s2).append("; ")
                    .append(s5).append("; ").append(s6).append(") AppleWebKit/0.0 (KHTML, like ")
                    .append("Gecko) Version/0.0 Mobile Safari/0.0").toString();
        }
        h = (new StringBuilder()).append(s).append(" (Mobile; ").append("afma-sdk-a-v").append("4.1.0")
                .append(")").toString();
    }
    return h;
}

From source file:Main.java

/**
 * <p>Creates the shared webView used throughout the lifetime of the TurbolinksSession.</p>
 *
 * @param applicationContext An application context.
 * @return The shared WebView.// w ww .j  av a  2  s . co m
 */
static WebView createWebView(Context applicationContext) {
    MutableContextWrapper contextWrapper = new MutableContextWrapper(applicationContext);
    WebView webView = new WebView(contextWrapper);
    configureWebViewDefaults(webView);
    setWebViewLayoutParams(webView);

    return webView;
}

From source file:Main.java

public static String getDefaultUserAgentString(Context context) {
    //      String userAgent = System.getProperty("http.agent");
    try {/* w w w .ja va  2  s.  c o  m*/
        Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class,
                WebView.class);
        constructor.setAccessible(true);
        try {
            WebSettings settings = constructor.newInstance(context, null);
            return settings.getUserAgentString();
        } finally {
            constructor.setAccessible(false);
        }
    } catch (Exception e) {
        return new WebView(context).getSettings().getUserAgentString();
    }
}

From source file:Main.java

public static String getUserAgentString(Context context) {
    if (userAgent == null) {
        try {//from w  w w .ja va 2 s . co  m
            Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class,
                    WebView.class);
            constructor.setAccessible(true);
            try {
                WebSettings settings = constructor.newInstance(context, null);
                userAgent = settings.getUserAgentString();
            } finally {
                constructor.setAccessible(false);
            }
        } catch (Exception e) {
            userAgent = new WebView(context).getSettings().getUserAgentString();
        }
    }
    return userAgent;
}

From source file:Main.java

public static String getUA(Context ctx) {
    final String system_ua = System.getProperty("http.agent");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return new WebView(ctx).getSettings().getDefaultUserAgent(ctx) + "__" + system_ua;
    } else {/*w w w. j av a 2  s.c om*/
        return new WebView(ctx).getSettings().getUserAgentString() + "__" + system_ua;
    }
}

From source file:cheng.app.cnbeta.OpenSourceLicensesFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.loadUrl("file:///android_asset/licenses.html");

    return new AlertDialog.Builder(getActivity()).setTitle(R.string.about_licenses).setView(webView)
            .setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();//from ww  w .  j  av a 2 s .c  o  m
                }
            }).create();
}

From source file:com.github.ekulf.spotifystreamer.LicensesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    webView.loadUrl("file:///android_asset/licences.html");
    return webView;
}

From source file:com.github.pennyfive.cinemafinlando.ui.fragment.OpenSourceLicensesDialogFragment.java

@NonNull
@Override/*from w  w w . ja va2 s  . com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new Builder(getActivity());
    builder.setTitle(R.string.about_open_source_licenses_text);
    WebView webView = new WebView(getActivity());
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setTextZoom(60);
    webView.loadUrl("file:///android_asset/licenses.html");
    builder.setView(webView);
    return builder.create();
}

From source file:MainActivity.java

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

    WebView webview = new WebView(this);
    setContentView(webview);/*from   ww  w  .ja v a  2  s . c  om*/
    webview.loadUrl("https://www.java2s.com/");
    webview.setWebViewClient(new WebViewClient());

    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
}

From source file:com.customlbs.android.presentation.legal.LicenseDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    WebView webView = new WebView(getActivity());
    webView.loadUrl("file:///android_asset/" + licensePath);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);

    return webView;
}