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.geecko.QuickLyric.AboutActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    int[] themes = new int[] { R.style.Theme_QuickLyric, R.style.Theme_QuickLyric_Red,
            R.style.Theme_QuickLyric_Purple, R.style.Theme_QuickLyric_Indigo, R.style.Theme_QuickLyric_Green,
            R.style.Theme_QuickLyric_Lime, R.style.Theme_QuickLyric_Brown, R.style.Theme_QuickLyric_Dark };
    int themeNum = Integer.valueOf(sharedPref.getString("pref_theme", "0"));
    boolean nightMode = sharedPref.getBoolean("pref_night_mode", false);
    if (nightMode && NightTimeVerifier.check(this))
        setTheme(R.style.Theme_QuickLyric_Night);
    else/*from ww  w.j  ava 2  s .com*/
        setTheme(themes[themeNum]);
    TypedValue primaryColor = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, primaryColor, true);
    setStatusBarColor(null);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    Toolbar toolbar = new Toolbar(this);
    toolbar.setTitle(R.string.pref_about);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        toolbar.setElevation(8f);
    toolbar.setBackgroundColor(primaryColor.data);
    toolbar.setTitleTextColor(Color.WHITE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(null, null,
                primaryColor.data);
        this.setTaskDescription(taskDescription);
    }

    View.OnClickListener productTourAction = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setupDemoScreen();
        }
    };

    Element productTourElement = new Element().setTitle(getString(R.string.about_product_tour));
    productTourElement.setOnClickListener(productTourAction);
    Element crowdinElement = new Element().setTitle(getString(R.string.about_crowdin));
    crowdinElement
            .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://crowdin.com/project/quicklyric")));
    Element ossLicensesElement = new Element().setTitle("Open Source Licenses");
    ossLicensesElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.open_source_librairies_licenses);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element tosElement = new Element().setTitle(getString(R.string.about_read_ToS));
    tosElement.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            WebView webView = new WebView(AboutActivity.this);
            String data = getResources().getString(R.string.QL_EULA);
            webView.loadData(data, "text/html; charset=utf-8", "UTF-8");
            new AlertDialog.Builder(AboutActivity.this).setView(webView).show();
        }
    });
    Element cookElement = new Element().setTitle("Icon Designer");
    cookElement.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://cookicons.co/")));

    View aboutView = new AboutPage(this).setDescription("QuickLyric is made with love in Brussels, Belgium.") // FixMe
            .addEmail("contact@QuickLyric.be").addFacebook("QuickLyric").addGitHub("geecko86/QuickLyric")
            .addPlayStore("test").addTwitter("QuickLyric").addWebsite("http://www.quicklyric.be")
            .setImage(R.drawable.icon).addItem(productTourElement).addItem(crowdinElement).addItem(cookElement)
            .addItem(ossLicensesElement).addItem(tosElement).create();
    aboutView.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    linearLayout.addView(toolbar);
    linearLayout.addView(aboutView);
    setContentView(linearLayout);

    final Drawable upArrow;
    if (Build.VERSION.SDK_INT >= 21) {
        upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        upArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    } else
        upArrow = getResources().getDrawable(R.drawable.ic_arrow_back);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);
}

From source file:de.appplant.cordova.plugin.printer.Printer.java

/**
 * Configures the WebView components which will call the Google Cloud Print
 * Service.//from  w w  w.  j a va  2 s .  c  om
 *
 * @param props
 *      The JSON object with the containing page properties
 */
private void initWebView(JSONObject props) {
    Activity ctx = cordova.getActivity();
    view = new WebView(ctx);

    view.getSettings().setDatabaseEnabled(true);

    setWebViewClient(props);
}

From source file:com.renren.api.connect.android.view.RenrenDialog.java

private void setUpWebView() {
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new RenrenDialog.RenrenWebViewClient());
    if (isPost) {
        webView.postUrl(mUrl, EncodingUtils.getBytes(mPostData, "BASE64"));
    } else {/*  w w w  . j  av  a  2 s .  co m*/
        webView.loadUrl(mUrl);
    }
    FrameLayout.LayoutParams fill = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    webView.setLayoutParams(fill);
    content.addView(webView);
}

From source file:com.facebook.android.FbDialog.java

private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    mWebView = new WebView(getContext());
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);/*from   www . ja v a 2s .c o  m*/
    mWebView.setLayoutParams(FILL);
    mWebView.setVisibility(View.INVISIBLE);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(mWebView);
    mContent.addView(webViewContainer);
}

From source file:org.tomahawk.libtomahawk.resolver.ScriptAccount.java

public ScriptAccount(String path, boolean manuallyInstalled) {
    String prefix = manuallyInstalled ? "file://" : "file:///android_asset";
    mPath = prefix + path;/*  w  w w .j a v  a  2s  .co m*/
    mManuallyInstalled = manuallyInstalled;
    String[] parts = mPath.split("/");
    mName = parts[parts.length - 1];
    try {
        InputStream inputStream;
        if (mManuallyInstalled) {
            File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json");
            inputStream = new FileInputStream(metadataFile);
        } else {
            inputStream = TomahawkApp.getContext().getAssets()
                    .open(path.substring(1) + "/content/metadata.json");
        }
        String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8);
        mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class);
        if (mMetaData == null) {
            Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
            return;
        }
    } catch (IOException e) {
        Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage());
        Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
        return;
    }

    mWebView = new WebView(TomahawkApp.getContext());
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        //noinspection deprecation
        settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath());
    }
    settings.setDomStorageEnabled(true);
    mWebView.setWebChromeClient(new TomahawkWebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            //initalize WebView
            String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>"
                    + "<script src=\"file:///android_asset/js/rsvp-latest.min.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/cryptojs-core.js"
                    + "\" type=\"text/javascript\"></script>";
            if (mMetaData.manifest.scripts != null) {
                for (String scriptPath : mMetaData.manifest.scripts) {
                    data += "<script src=\"" + mPath + "/content/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            }
            try {
                String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs");
                for (String scriptPath : cryptoJsScripts) {
                    data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            } catch (IOException e) {
                Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
            data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk_android_post.js"
                    + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/"
                    + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>";
            mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this));
            mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME);
            mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null);
        }
    });
}

From source file:com.iStudy.Study.Renren.View.RenrenDialog.java

@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new RenrenDialog.RenrenWebViewClient());
    if (isPost) {
        webView.postUrl(mUrl, EncodingUtils.getBytes(mPostData, "BASE64"));
    } else {/*from   w  w w  .ja  v  a2  s . com*/
        webView.loadUrl(mUrl);
    }
    @SuppressWarnings("deprecation")
    FrameLayout.LayoutParams fill = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    webView.setLayoutParams(fill);
    content.addView(webView);
}

From source file:com.ztspeech.weibo.sdk.renren.view.RenrenDialog.java

@TargetApi(5)
private void setUpWebView() {
    webView = new WebView(getContext());
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new RenrenDialog.RenrenWebViewClient());
    if (isPost) {
        webView.postUrl(mUrl, EncodingUtils.getBytes(mPostData, "BASE64"));
    } else {/*from  w  w w. ja v  a2s  .co m*/
        webView.loadUrl(mUrl);
    }
    FrameLayout.LayoutParams fill = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    webView.setLayoutParams(fill);
    content.addView(webView);
}

From source file:illab.nabal.proxy.AuthWebDialog.java

/**
 * Sets up web view.//from   ww  w .  ja va  2s.com
 */
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView() {
    mWebView = new WebView(getContext());
    mWebView.setLayoutParams(FILL);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDefaultTextEncodingName(HTTP.UTF_8);

    // DO NOT set user agent to 'Android' if current web view is up for Facebook
    // it will cause blank screen problem on Facebook auth page
    // (problem found and fixed on 2013-04-23)
    //
    // YOU MUST set user agent to 'Android' if current web view is up for Weibo
    // otherwise log-in page will redirect to open.weibo.cn and not work properly
    // (problem found and fixed on 2013-08-23)
    if (mNetworkWebViewClient.getSnsUid() == SocialNetwork.WEIBO) {
        mWebView.getSettings().setUserAgentString(SystemProperties.USER_AGENT_ANDROID);
    }

    mWebView.setWebViewClient(mNetworkWebViewClient);
    mWebView.loadUrl(mUrl);
    mLayout.addView(mWebView);
}

From source file:nya.miku.wishmaster.http.recaptcha.RecaptchaAjax.java

private static String getChallengeInternal(final String address, final String data, CancellableTask task,
        final HttpHost proxy) throws Exception {
    Logger.d(TAG, "not intercepting; proxy: " + (proxy == null ? "disabled" : "enabled"));
    if (proxy != null) {
        Logger.d(TAG, "AJAX recaptcha not using (proxy and old API)");
        throw new Exception("proxy && old API");
        //? ? ? ?  reflection  ???, ..    js-antiddos, ?   ( noscript )
    }/* www . j a v a 2 s .  c om*/
    final Context context = MainApplication.getInstance();
    final Holder holder = new Holder();

    sHandler.post(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            holder.webView = new WebView(context);
            holder.webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                    handler.proceed();
                }

                @Override
                public void onLoadResource(WebView view, String url) {
                    String challenge = getChallengeFromImageUrl(url);
                    if (challenge != null)
                        holder.challenge = challenge;
                    super.onLoadResource(view, url);
                }
            });
            holder.webView.getSettings().setUserAgentString(CUSTOM_UA);
            holder.webView.getSettings().setJavaScriptEnabled(true);
            holder.webView.loadDataWithBaseURL(address, data, "text/html", "UTF-8", null);
        }
    });

    long startTime = System.currentTimeMillis();
    while (holder.challenge == null) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > TIMEOUT)
            break;
        Thread.yield();
    }

    sHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                holder.webView.stopLoading();
                holder.webView.clearCache(true);
                holder.webView.destroy();
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
    });

    if (holder.challenge == null)
        throw new RecaptchaException("couldn't get Recaptcha Challenge (AJAX)");
    return holder.challenge;
}

From source file:us.koller.todolist.Activities.InfoActivity.java

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

    setContentView(R.layout.activity_info);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.info_activity_toolbar);
    setSupportActionBar(toolbar);/*from  ww w.j a v a  2  s .c  om*/
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("");
    }

    initTheme(toolbar);

    final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            if (scrollView.getScrollY() != 0) {
                elevateToolbar(toolbar);
            } else {
                deelevateToolbar(toolbar);
            }
        }
    });

    TextView version = (TextView) findViewById(R.id.version);
    if (helper.lightCoordColor()) {
        version.setTextColor(ContextCompat.getColor(this, R.color.grey700));
    }
    version.setText(BuildConfig.VERSION_NAME);

    ImageView icon = (ImageView) findViewById(R.id.icon);
    Glide.with(this).load("http://todolist.koller.us/todolist_icon_512px").into(icon);

    //Glide license
    View license_item_1 = findViewById(R.id.license_item_1);
    ((TextView) license_item_1.findViewById(R.id.text)).setText(R.string.glide);
    license_item_1.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/bumptech/glide/blob/master/LICENSE")));
        }
    });
    license_item_1.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(
                    new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/bumptech/glide")));
        }
    });

    //MaterialNumberPicker license
    View license_item_2 = findViewById(R.id.license_item_2);
    ((TextView) license_item_2.findViewById(R.id.text)).setText(R.string.materialnumberpicker);
    license_item_2.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW).setData(
                    Uri.parse("https://github.com/KasualBusiness/MaterialNumberPicker/blob/master/LICENSE")));
        }
    });
    license_item_2.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse("https://github.com/KasualBusiness/MaterialNumberPicker")));
        }
    });

    //Google Play Service Attribution
    View license_item_3 = findViewById(R.id.license_item_3);
    ((TextView) license_item_3.findViewById(R.id.text)).setText(R.string.google_play_servcie_attribution);
    license_item_3.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            WebView webView = new WebView(InfoActivity.this);
            webView.loadData(
                    GoogleApiAvailability.getInstance().getOpenSourceSoftwareLicenseInfo(InfoActivity.this),
                    "text/plain", "utf-8");

            AlertDialog dialog = new AlertDialog.Builder(InfoActivity.this)
                    .setTitle("Google Play Servcie Attribution").setView(webView).setPositiveButton("Ok", null)
                    .create();
            dialog.show();
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(helper.get(ThemeHelper.FAB_COLOR));
        }
    });
    license_item_3.findViewById(R.id.button).setVisibility(View.GONE);

    //Google Play Service Attribution
    View license_item_4 = findViewById(R.id.license_item_4);
    ((TextView) license_item_4.findViewById(R.id.text)).setText("Privacy Policy");
    license_item_4.findViewById(R.id.text).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW).setData(
                    Uri.parse("https://github.com/kollerlukas/TODOList-Android-App/blob/master/PRIVACY.md")));
        }
    });
    license_item_4.findViewById(R.id.button).setVisibility(View.GONE);
}