List of usage examples for android.webkit WebView loadUrl
public void loadUrl(String url)
From source file:net.basov.ticketinfo.UI.java
public void displayMainScreen(final WebView wv) { wv.setWebViewClient(new MyWebViewClient() { @Override// ww w. ja v a2s. c o m public void onPageFinished(WebView view, String url) { super.onPageFinished(wv, url); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.evaluateJavascript("javascript:jreplace('" + header_json.toString() + "')", null); view.evaluateJavascript("javascript:jreplace('" + ticket_json.toString() + "')", null); view.evaluateJavascript("javascript:jreplace('" + ic_json.toString() + "')", null); view.evaluateJavascript("javascript:jreplace('" + dump_json.toString() + "')", null); } else { view.loadUrl("javascript:jreplace('" + header_json.toString() + "')"); view.loadUrl("javascript:jreplace('" + ticket_json.toString() + "')"); view.loadUrl("javascript:jreplace('" + ic_json.toString() + "')"); view.loadUrl("javascript:jreplace('" + dump_json.toString() + "')"); } wv.clearCache(true); wv.clearHistory(); //TODO: remove debug //Log.d("hhhh", header_json.toString()); //Log.d("tttt", ticket_json.toString()); //Log.d("iiii", ic_json.toString()); } }); Context c = wv.getContext(); wv.loadUrl("file:///android_asset/" + c.getString(R.string.ticket_ui_file)); }
From source file:com.example.health_connect.MySampleFragment3.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.sample_fragment3, container, false); Parse.initialize(mView.getContext(), "e0FVFRBMAWJi5shg4XF8zL3SIuRwDIufww3338so", "toTJmlHTEF43u7PoAFT4fedwqfhoWiSajj1Se7FT"); ParseUser currentUser = ParseUser.getCurrentUser(); Log.d("Check", currentUser.getObjectId()); ImageView birthdaypic = (ImageView) mView.findViewById(R.id.imageView2); TextView wish = (TextView) mView.findViewById(R.id.textView23); TextView hbday = (TextView) mView.findViewById(R.id.textView24); WebView webview = (WebView) mView.findViewById(R.id.pic); webview.setWebViewClient(new WebViewClient() { @Override//ww w . j av a2 s . com public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Log.i("WEB_VIEW_TEST", "error code: " + errorCode + " " + description); super.onReceivedError(view, errorCode, description, failingUrl); } }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDomStorageEnabled(true); String u_r_l; if (currentUser.getString("image_flag").equalsIgnoreCase("1")) { u_r_l = "http://cdn.filter.to/100x100/http://s3-ap-southeast-1.amazonaws.com/hconnect/" + currentUser.getObjectId(); } else { u_r_l = "http://cdn.filter.to/100x100/cdn1.iconfinder.com/data/icons/PRACTIKA/256/user.png"; } webview.loadUrl(u_r_l); String date_of_birth = currentUser.getString("Dob"); Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String formattedDate = df.format(c.getTime()); //Log.d("Check",formattedDate); String str[] = { "Every patient carries her or his own doctor inside.", "Laughter is the best medicine", "The art of medicine consists in amusing the patient while nature cures the disease.", "Health is wealth", "My health is good,it's my age that's bad.", "A healthy body is a guest-chamber for the soul; a sick body is a prison.", "Fitness:If it came in a bottle,everybody would have a good body.", "Ypu don't get ulcers form what you eat,but from what's eating you.", "Those who don't find time for exercise will have to find time for illness.", "Sickness comes on horseback and departs on foot.", "Health and appetite impart the sweetness to sugar,bread and meat.", "Health is not valued till sickness comes.", "Health is not simply the absence of sickness.", "To eat is a necessity,but to eat intelligently is an art.", "Let food be the medicine,thy medicine shall be thy food.", "Food is fuel,choose wisely.", "Health and intellect are the two blessings of life.", "The greatest wealth is health.", "Think positive and focus on gratitude.", "Get a good night's sleep.", "Use food over supplements.", "Eat 5 servings of fruits and veggies a day.", "Big idea: Be happy :)", "Drink water instead of surgery drinks.", "Swap big serves for smaller ones.", "Park the car and walk the rest of the way.", "No disease that can be treated by diet should be treated with any other means.", "Your body hears everything your mind says/", "Take care of your body. It's the only place you have to live.", "Every human being is the author of his own health or disease." }; Random r = new Random(); int High = 30; // 30 excluded int Low = 0; int random_number = r.nextInt(High - Low) + Low; if ((formattedDate.substring(0, 2).equalsIgnoreCase(date_of_birth.substring(0, 2))) && (formattedDate.substring(3, 5).equalsIgnoreCase(date_of_birth.substring(3, 5)))) // if(d1==d2 && m1==m2) { } else { // Log.d("Check", d1); birthdaypic.setImageDrawable(null); wish.setText(null); hbday.setText(null); wish.setText(str[random_number]); //wish.setVisibility(View.GONE); hbday.setVisibility(View.GONE); } TextView a_name = (TextView) mView.findViewById(R.id.pdob); TextView a_eid = (TextView) mView.findViewById(R.id.textView8); TextView a_add = (TextView) mView.findViewById(R.id.textView10); TextView a_dob = (TextView) mView.findViewById(R.id.textView12); TextView a_lno = (TextView) mView.findViewById(R.id.textView14); TextView a_year = (TextView) mView.findViewById(R.id.textView16); TextView a_mschool = (TextView) mView.findViewById(R.id.textView18); TextView a_spec = (TextView) mView.findViewById(R.id.textView20); TextView a_deg = (TextView) mView.findViewById(R.id.textView22); a_name.setText(currentUser.getUsername()); a_deg.setText(currentUser.getString("Degree")); a_dob.setText(currentUser.getString("Dob")); a_spec.setText(currentUser.getString("Primary_speciality")); a_mschool.setText(currentUser.getString("Medical_School")); a_add.setText(currentUser.getString("Address")); a_year.setText(currentUser.getString("Start_Practice")); a_eid.setText(currentUser.getEmail()); a_lno.setText(currentUser.getString("LicenseNo")); return mView; }
From source file:io.github.hidroh.materialistic.OfflineWebActivity.java
@SuppressWarnings("ConstantConditions") @Override//from w w w . ja v a2s . co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String url = getIntent().getStringExtra(EXTRA_URL); if (TextUtils.isEmpty(url)) { finish(); return; } setTitle(url); setContentView(R.layout.activity_offline_web); final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scroll_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayOptions( ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE); getSupportActionBar().setSubtitle(R.string.offline); final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress); final WebView webView = (WebView) findViewById(R.id.web_view); webView.setBackgroundColor(Color.TRANSPARENT); webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)) { @Override public void onPageFinished(WebView view, String url) { setTitle(view.getTitle()); } }); webView.setWebChromeClient(new CacheableWebView.ArchiveClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(newProgress); if (newProgress == 100) { progressBar.setVisibility(View.GONE); webView.setBackgroundColor(Color.WHITE); webView.setVisibility(View.VISIBLE); } } }); AppUtils.toggleWebViewZoom(webView.getSettings(), true); webView.loadUrl(url); }
From source file:io.selendroid.server.model.AndroidNativeElement.java
public JSONObject toJson() throws JSONException { JSONObject object = new JSONObject(); JSONObject l10n = new JSONObject(); l10n.put("matches", 0); object.put("l10n", l10n); CharSequence cd = getView().getContentDescription(); if (cd != null && cd.length() > 0) { String label = String.valueOf(cd); object.put("name", label); } else {//from w w w . jav a 2s. co m object.put("name", ""); } String id = getNativeId(); object.put("id", id.startsWith("id/") ? id.replace("id/", "") : id); JSONObject rect = new JSONObject(); object.put("rect", rect); JSONObject origin = new JSONObject(); Point location = getLocation(); origin.put("x", location.x); origin.put("y", location.y); rect.put("origin", origin); JSONObject size = new JSONObject(); Dimension s = getSize(); size.put("height", s.getHeight()); size.put("width", s.getWidth()); rect.put("size", size); object.put("ref", ke.getIdOfElement(this)); object.put("type", getView().getClass().getSimpleName()); String value = ""; if (getView() instanceof TextView) { value = String.valueOf(((TextView) getView()).getText()); } object.put("value", value); object.put("shown", getView().isShown()); if (getView() instanceof WebView) { final WebView webview = (WebView) getView(); final WebViewSourceClient client = new WebViewSourceClient(); instrumentation.getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { webview.getSettings().setJavaScriptEnabled(true); webview.setWebChromeClient(client); String script = "document.body.parentNode.innerHTML"; webview.loadUrl("javascript:alert('selendroidSource:'+" + script + ")"); } } }); long end = System.currentTimeMillis() + 10000; waitForDone(end, UI_TIMEOUT, "Error while grabbing web view source code."); object.put("source", "<html>" + client.result + "</html>"); } return object; }
From source file:org.alfresco.mobile.android.application.fragments.help.HelpDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.app_webview, container, false); webView = (WebView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.webview); webView.getSettings().setJavaScriptEnabled(true); emptyView = v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty); emptyTextView = (TextView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty_text); emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline))); final FragmentActivity activity = getActivity(); defaultUrl = activity.getString(R.string.help_user_guide_default_url); webView.setWebViewClient(new WebViewClient() { boolean hasError = false; @Override/*from w ww. j a v a 2s . co m*/ public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); hasError = false; displayProgress(true); if (refreshIcon != null) { refreshIcon.setVisible(false); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); // We redirect to default EN documentation if locale docs are // not available. if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault && failingUrl.equals(rootUrl)) { hasError = true; view.loadUrl(defaultUrl); view.setVisibility(View.GONE); } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) { view.setVisibility(View.GONE); emptyView.setVisibility(View.VISIBLE); hasError = true; } } @Override public void onPageFinished(WebView view, String url) { if (getActivity() == null) { return; } super.onPageFinished(view, url); if (hasError) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } displayProgress(false); if (refreshIcon != null) { refreshIcon.setVisible(true); } } public void onFormResubmission(WebView view, Message dontResend, Message resend) { resend.sendToTarget(); } }); webView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (webView.canGoBack()) { webView.goBack(); return true; } break; } } return false; } }); rootUrl = getUrl(activity); webView.loadUrl(rootUrl); return v; }
From source file:com.sonymobile.androidapp.gridcomputing.fragments.WebviewFragment.java
@Override public final void onViewCreated(final View view, final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final WebView webView = (WebView) view.findViewById(R.id.webview); final View progress = view.findViewById(R.id.webview_progress); final String researchUrl = getArguments().getString(URL_KEY); progress.setVisibility(View.VISIBLE); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setWebViewClient(new WebViewClient() { @Override/*from w w w. ja v a 2s . c om*/ public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (TextUtils.isEmpty(researchUrl) || researchUrl.equals(url)) { return false; } else { view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; } } @Override public void onPageFinished(final WebView view, final String url) { progress.setVisibility(View.GONE); } }); webView.loadUrl(researchUrl); }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitOAuthLoginActivity.java
@SuppressWarnings("nls") @Override/*w w w. ja v a2 s .c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DependencyInjectionService.getInstance().inject(this); setContentView(R.layout.oauth_login_activity); getSupportActionBar().setTitle(R.string.actfm_OLA_prompt); final String urlParam = getIntent().getStringExtra(URL_TOKEN); final WebView webView = (WebView) findViewById(R.id.browser); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setSavePassword(false); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setSupportZoom(true); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { System.err.println("hey error. " + errorCode + ": " + description); } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("?client_id=") && (url.lastIndexOf("?client_id=") != url.indexOf("?client_id="))) { String redirectUrl = url.substring(0, url.lastIndexOf("?client_id=")); webView.loadUrl(redirectUrl); return true; } return super.shouldOverrideUrlLoading(view, url); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); } @Override public void onPageFinished(WebView view, final String url) { super.onPageFinished(view, url); pd.dismiss(); if (url.contains("access_token=")) { String token = url.substring(url.indexOf("access_token="), url.length()); Intent intent = new Intent(); intent.putExtra(DATA_RESPONSE, token); setResult(RESULT_OK, intent); finish(); } } }); pd = DialogUtilities.progressDialog(this, getString(R.string.DLG_wait)); webView.loadUrl(urlParam); }
From source file:org.quizreader.android.PageReadActivity.java
/** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled") @Override//w ww. j a v a 2 s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.page_read); // immediately pop up loading dialog dialog = new ProgressDialog(this); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setMessage("loading page"); dialog.show(); // set up webview WebView webview = (WebView) findViewById(R.id.webView); webview.setWebViewClient(new QRWebViewClient()); webview.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage(ConsoleMessage cm) { Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId()); return true; } }); WebSettings webSettings = webview.getSettings(); webSettings.setJavaScriptEnabled(true); webview.addJavascriptInterface(new QuizReaderInterface(), "qr"); try { random = new Random(); wordDao = new WordDao(this); qzzFile = new QzzFile(title.getFilepath(), this); URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection()); if (htmlURL == null) { // beyond the last section setResult(RESULT_END_TITLE); finish(); } String externalForm = htmlURL.toExternalForm(); webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph()); } catch (Exception ex) { webview.loadData(ex.toString(), "text/plain", null); } }
From source file:at.alladin.rmbt.android.help.RMBTHelpFragment.java
/** * *///from ww w . j a va 2 s .c om @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; }
From source file:edu.cscie71.imm.slacker.plugin.Slacker.java
private void closeAuthScreen() { final WebView childView = this.inAppWebView; // The JS protects against multiple calls, so this should happen only when // closeDialog() is called by other native code. if (childView == null) { return;/* ww w . ja va2s . c o m*/ } this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { childView.setWebViewClient(new WebViewClient() { // NB: wait for about:blank before dismissing public void onPageFinished(WebView view, String url) { if (dialog != null) { dialog.dismiss(); } } }); // NB: From SDK 19: "If you call methods on WebView from any thread // other than your app's UI thread, it can cause unexpected results." // http://developer.android.com/guide/webapps/migrating.html#Threads childView.loadUrl("about:blank"); } }); }