List of usage examples for android.webkit WebView loadUrl
public void loadUrl(String url)
From source file:com.rks.musicx.misc.utils.Helper.java
/** * ChangeLogs Dialog/*from w ww . jav a 2 s .co m*/ * * @param context */ public static void Changelogs(Context context) { MaterialDialog.Builder builder = new MaterialDialog.Builder(context); builder.title("Changelogs"); WebView webView = new WebView(context); webView.loadUrl("file:///android_asset/app_changelogs.html"); builder.positiveText(android.R.string.ok); builder.typeface(getFont(context), getFont(context)); builder.onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { dialog.dismiss(); } }); builder.customView(webView, false); builder.build(); builder.show(); }
From source file:com.rks.musicx.misc.utils.Helper.java
/** * Licenses Dialog//from ww w . j av a 2 s . c o m * * @param context */ public static void Licenses(Context context) { MaterialDialog.Builder builder = new MaterialDialog.Builder(context); builder.title("Licenses"); WebView webView = new WebView(context); webView.loadUrl("file:///android_asset/licenses.html"); builder.negativeText(android.R.string.cancel); builder.positiveText(android.R.string.ok); builder.onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { builder.autoDismiss(true); } }); builder.onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { builder.cancelable(true); } }); builder.customView(webView, false); builder.build(); builder.show(); }
From source file:com.mario22gmail.license.nfc_project.FragmentBrowser.java
public void OpenWebSite(String urlFromCredential, String javaScript) { mWebview.loadUrl(urlFromCredential); WebSettings settings = mWebview.getSettings(); settings.setJavaScriptEnabled(true); urlEditText.setText(urlFromCredential); final String javaScriptFinal = javaScript; final String urlFromCredentialFinal = urlFromCredential; mWebview.setWebViewClient(new WebViewClient() { @Override// w ww. ja va2 s . c o m public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (url.startsWith(urlFromCredentialFinal)) { if (Build.VERSION.SDK_INT >= 19) { view.evaluateJavascript(javaScriptFinal, new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }); } else { view.loadUrl(javaScriptFinal); } } } }); }
From source file:com.microsoft.office.integration.test.AbstractTest.java
@Override protected void setUp() throws Exception { if (fatalErrorMessage != null) { fail(fatalErrorMessage);//from w w w. j a va 2 s . com } if (wasStarted) { return; } super.setUp(); prepare(); // Sets authenticator Configuration.setServerBaseUrl(getRootUrl()); switch (TestRunner.getAuthType()) { case BASIC: Configuration.setAuthenticator(new AbstractBasicAuthenticator() { protected String getUsername() { return TestRunner.getUsername(); } protected String getPassword() { return TestRunner.getPassword(); } }); break; case AAD: AbstractOfficeAuthenticator officeAuthenticator = new AbstractOfficeAuthenticator() { @Override protected IOfficeCredentials getCredentials() { OfficeCredentialsImpl creds = new OfficeCredentialsImpl(getAuthorityUrl(), getClientId(), getResourceId(), getRedirectUrl()); creds.setUserHint(getUsername()); return creds; } @Override protected Activity getActivity() { return mainActivity; } @Override public void onDone(String result) { super.onDone(result); sAvailable.release(); } @Override public void onError(Throwable error) { super.onError(error); // FIXME assert fail on it. } }; TestActivity.setOfficeAuthenticator(officeAuthenticator); Configuration.setAuthenticator(officeAuthenticator); if (TestRunner.getAuthType() == AuthType.AAD) { final Future<Void> emails = new AsyncCall<Void>(ODataClientFactory.getV4().getConfiguration()) { @Override public Void call() { Me.getDrafts(); return null; } }; Thread th = new Thread(new Runnable() { public void run() { try { emails.get(120, TimeUnit.SECONDS); } catch (Exception e) { fail(e.toString()); } } }); th.start(); try { if (!waitForAdalActivity(WAIT_ADAL_ACTIVITY_TIMEOUT)) { fatalErrorMessage = "Adal activity not opened"; fail(fatalErrorMessage); } // In case when adal authorized on this devices spinner isn't displayed. if (waitForDialogToOpen(WAIT_OPEN_DIALOG_TIMEOUT)) { if (!waitForDialogToClose(WAIT_CLOSE_DIALOG_TIMEOUT)) { fatalErrorMessage = "Adal activity not opened"; fail(fatalErrorMessage); } } } catch (Exception e) { e.printStackTrace(); } final WebView webView = getWebView(adalActivity.getWindow().getDecorView().getRootView()); assertNotNull(webView); mainActivity.runOnUiThread(new Runnable() { public void run() { webView.loadUrl(String.format(ENTER_PASSWORD_COMMAND, getPassword()) + SEND_AUTHENTICATION_REQUEST_COMMAND); } }); sAvailable.acquire(); } break; default: fatalErrorMessage = "Unknown auth."; fail(fatalErrorMessage); break; } }
From source file:com.google.android.apps.paco.ExploreDataActivity.java
private WebViewClient createWebViewClientThatHandlesFileLinksForCharts() { WebViewClient webViewClient = new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri = Uri.parse(url);/*from w w w . j a va 2 s. co m*/ if (uri.getScheme().startsWith("http")) { return true; } view.loadUrl(FeedbackActivity.stripQuery(url)); return true; } }; return webViewClient; }
From source file:org.bcsphere.components.BCWebViewClient.java
private void injectDeferredObject(String source, String jsWrapper, final WebView view) { String scriptToInject;/*w ww.j a va 2 s.c om*/ if (jsWrapper != null) { org.json.JSONArray jsonEsc = new org.json.JSONArray(); jsonEsc.put(source); String jsonRepr = jsonEsc.toString(); String jsonSourceString = jsonRepr.substring(1, jsonRepr.length() - 1); scriptToInject = String.format(jsWrapper, jsonSourceString); } else { scriptToInject = source; } final String finalScriptToInject = scriptToInject; cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { view.loadUrl("javascript:" + finalScriptToInject); } }); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.GBWebClient.java
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri parsedUri = Uri.parse(url);// w w w . j ava 2 s. com if (parsedUri.getScheme().startsWith("http")) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); GBApplication.getContext().startActivity(i); } else if (parsedUri.getScheme().startsWith("pebblejs")) { url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); view.loadUrl(url); } else if (parsedUri.getScheme().equals("data")) { //clay view.loadUrl(url); } else { LOG.debug("WEBVIEW Ignoring unhandled scheme: " + parsedUri.getScheme()); } return true; }
From source file:gov.whitehouse.ui.fragments.app.ArticleViewerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.article_view, container, false); mWebView = (WebView) v.findViewById(R.id.webview); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); mWebView.getSettings().setJavaScriptEnabled(true); // enabling plugins may yield a better result for YouTube videos mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); mWebView.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d(TAG, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId()); return true; }/*w ww. j a v a2s .c o m*/ }); mWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.e(TAG, "Error in WebView: " + failingUrl + "; " + description); } @Override public void onPageFinished(WebView view, String url) { mProgressBar.setVisibility(View.INVISIBLE); mWebView.setVisibility(View.VISIBLE); Log.d(TAG, "page finished: " + url); if (url.equals(PAGE_TEMPLATE_URL)) { view.loadUrl(String.format("javascript:WhiteHouse.loadPage(%s);", mPageInfo.toString())); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("youtube.com/")) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); return true; } return false; } }); return v; }
From source file:org.feedhenry.saml.fragments.WebViewFragment.java
@Nullable @Override/*from w ww. j a v a 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String ssoStringURL = getArguments().getString(URL); View view = View.inflate(getActivity(), R.layout.fragment_webview, null); WebView webView = (WebView) view.findViewById(R.id.ssoWebView); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // It' logged if (url.endsWith("login/ok")) { SAMLActivity activity = (SAMLActivity) getActivity(); activity.retrieveUserData(); } } }); webView.loadUrl(ssoStringURL); return view; }
From source file:com.phonegap.plugins.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load.// w w w. j a va 2s.com * @param jsonObject */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton((Context) ctx); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); // dda: intercept calls to console.log webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cmsg) { // check secret prefix if (cmsg.message().startsWith("MAGIC")) { String msg = cmsg.message().substring(5); // strip off prefix /* process HTML */ try { JSONObject obj = new JSONObject(); obj.put("type", PAGE_LOADED); obj.put("html", msg); sendUpdate(obj, true); } catch (JSONException e) { Log.d("ChildBrowser", "This should never happen"); } return true; } return false; } }); // dda: inject the JavaScript on page load webview.setWebViewClient(new ChildBrowserClient(edittext) { public void onPageFinished(WebView view, String address) { // have the page spill its guts, with a secret prefix Log.d("ChildBrowser", "\n\nInjecting javascript\n\n"); view.loadUrl( "javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);"); } }); // webview.setWebViewClient(client); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }