List of usage examples for android.webkit WebView setWebChromeClient
public void setWebChromeClient(WebChromeClient client)
From source file:it.redturtle.mobile.apparpav.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.showbulletin, container, false); // Set button in order to start the bulletin fragmnet final Button mv = (Button) view.findViewById(R.id.mv); mv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "MV"); startActivity(newintent);/*w w w. j a va 2s.com*/ } }); // Set button in order to start the bulletin fragmnet final Button dm = (Button) view.findViewById(R.id.dm); dm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "DM"); startActivity(newintent); } }); // Set button in order to start the bulletin fragmnet final Button pm = (Button) view.findViewById(R.id.pm); pm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent newintent = new Intent(); newintent.setClass(activity, BulletinActivity.class); newintent.putExtra("bulletinid", "MP"); startActivity(newintent); } }); WebView webview = (WebView) view.findViewById(R.id.datail_content); webview.setWebChromeClient(new WebChromeClient() { }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); webview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); String html = "<!doctype html>"; html += "<html>"; html += "<head>"; html += "<meta name=\"author\" content=\"RedTurtle.it\" />"; html += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />"; html += "</head>"; html += "<body style=\"font-family:Helvetica;font-size:small;\">"; html += "<div style=\"text-align:center;\"><b>" + forecast.getName() + "</b></div>"; if (forecast.getType() == 1) { html += "<div style=\"text-align:center;\">"; html += "<p>" + forecast.getCaptionAt(0) + "</p>"; html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; } if (forecast.getType() == 2) { html += "<div style=\"text-align:center;\">"; html += "<div style=\"display:inline-block;\">"; html += "<div style=\"float:left;\">"; html += "<p>" + forecast.getCaptionAt(0) + "</p>"; html += "<img src=\"" + forecast.getPathAt(0) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; html += "<div style=\"float:left;\">"; html += "<p>" + forecast.getCaptionAt(1) + "</p>"; html += "<img src=\"" + forecast.getPathAt(1) + "\" width=\"140\" style=\"padding:2px;\"/>"; html += "</div>"; html += "</div>"; html += "</div>"; } html += forecast.getBody(); html += "</body>"; html += "</html>"; webview.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null); return view; }
From source file:com.chatwingsdk.fragments.EnterpriseAuthenticateFragment.java
private void setup(WebView mWebView) { mWebView.setWebViewClient(mWebviewClient); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebChromeClient(new WebChromeClient() { @Override/*from w w w . j a va2 s . co m*/ public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); mProgressView.setProgress(newProgress); if (newProgress == 100) { mProgressView.setVisibility(View.GONE); } } }); }
From source file:com.example.ruby.mygetgps.ui.activities.MainActivity.java
private void setupWebView() { WebView webview = (WebView) findViewById(R.id.webview); webview.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); }/*from w ww. j a v a2 s . com*/ }); webview.setWebViewClient(new WebViewClient()); webview.clearCache(true); webview.clearHistory(); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webview.loadUrl("https://getgpsserverrails-0.herokuapp.com/summaries"); }
From source file:cn.sharesdk.analysis.MobclickAgentJSInterface.java
public MobclickAgentJSInterface(Context paramContext, WebView paramWebView, WebChromeClient paramWebChromeClient) { this.context = paramContext; paramWebView.getSettings().setJavaScriptEnabled(true); paramWebView.setWebChromeClient(new StatisticsWebClient(paramWebChromeClient)); }
From source file:org.quizreader.android.PageReadActivity.java
/** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled") @Override/*from ww w.jav a 2s. c o m*/ 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:io.github.hidroh.materialistic.SubmitActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AppUtils.setStatusBarColor(getWindow(), ContextCompat.getColor(this, R.color.blackT12)); setContentView(R.layout.activity_submit); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); //noinspection ConstantConditions getSupportActionBar().setDisplayOptions( ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP); mTitleLayout = (TextInputLayout) findViewById(R.id.textinput_title); mContentLayout = (TextInputLayout) findViewById(R.id.textinput_content); mTitleEditText = (TextView) findViewById(R.id.edittext_title); mContentEditText = (TextView) findViewById(R.id.edittext_content); String text, subject;//from w w w.j a v a2s . c om if (savedInstanceState == null) { subject = getIntent().getStringExtra(Intent.EXTRA_SUBJECT); text = getIntent().getStringExtra(Intent.EXTRA_TEXT); } else { subject = savedInstanceState.getString(STATE_SUBJECT); text = savedInstanceState.getString(STATE_TEXT); } mTitleEditText.setText(subject); mContentEditText.setText(text); if (TextUtils.isEmpty(subject)) { if (isUrl(text)) { WebView webView = new WebView(this); webView.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedTitle(WebView view, String title) { if (mTitleEditText.length() == 0) { mTitleEditText.setText(title); } } }); webView.loadUrl(text); } else if (!TextUtils.isEmpty(text)) { extractUrl(text); } } }
From source file:com.just.agentweb.AgentWebUtils.java
static final void clearWebView(WebView m) { if (m == null) { return;/* www.jav a 2s .c o m*/ } if (Looper.myLooper() != Looper.getMainLooper()) { return; } m.loadUrl("about:blank"); m.stopLoading(); if (m.getHandler() != null) { m.getHandler().removeCallbacksAndMessages(null); } m.removeAllViews(); ViewGroup mViewGroup = null; if ((mViewGroup = ((ViewGroup) m.getParent())) != null) { mViewGroup.removeView(m); } m.setWebChromeClient(null); m.setWebViewClient(null); m.setTag(null); m.clearHistory(); m.destroy(); m = null; }
From source file:io.github.hidroh.materialistic.OfflineWebActivity.java
@SuppressWarnings("ConstantConditions") @Override//from w w w. j a v a2 s .c o 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:org.esupportail.nfctagdroid.NfcTacDroidActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext()); //To keep session for desfire async requests CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); LocalStorage.getInstance(getApplicationContext()); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext())); setContentView(R.layout.activity_main); mAdapter = NfcAdapter.getDefaultAdapter(this); checkHardware(mAdapter);//from w ww . ja v a 2 s . c o m localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext()); String numeroId = localStorageDBHelper.getValue("numeroId"); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress=" + getMacAddr() + "&apkVersion=" + getApkVersion(); view = (WebView) this.findViewById(R.id.webView); view.clearCache(true); view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()), "AndroidLocalStorage"); view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android"); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { if (progress == 100) { AUTH_TYPE = localStorageDBHelper.getValue("authType"); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { log.info("Webview console message : " + consoleMessage.message()); return false; } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { view.reload(); return true; } }); view.getSettings().setAllowContentAccess(true); WebSettings webSettings = view.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/"); view.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } }); view.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView view, String url) { } }); view.loadUrl(url); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); }
From source file:com.brayanarias.alarmproject.activity.MainActivity.java
private void setupNavigationView() { navigationView = (NavigationView) findViewById(R.id.navigation); MenuItem item = navigationView.getMenu().findItem(actualItem); View nav_header = LayoutInflater.from(this).inflate(R.layout.nav_header, null); final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation); navigationView.addHeaderView(nav_header); //salute// w w w . ja v a 2 s .co m String salute = AlarmUtilities.getSalute(getApplicationContext()); TextView tvWellcome = (TextView) nav_header.findViewById(R.id.tvWellcome); tvWellcome.setText(salute); if (item != null) { item.setChecked(true); } navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { CharSequence title = menuItem.getTitle(); closeDrawer(); switch (menuItem.getItemId()) { case R.id.itMyAlarms: showFragment(R.id.itMyAlarms); actualItem = menuItem.getItemId(); menuItem.setChecked(true); getSupportActionBar().setTitle(title); return true; case R.id.itAddAlarm: Calendar calendar = Calendar.getInstance(); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); TimePickerDialog timePickerDialog = TimePickerDialog .newInstance(new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) { Alarm alarm = AlarmUtilities.createDefaultAlarm(); String min = minute < 10 ? "0" + minute : "" + minute; if (hourOfDay == 12) { alarm.setAmPm("PM"); alarm.setHour(hourOfDay); alarm.setHourFormatted((hourOfDay) + ":" + min); } else if (hourOfDay > 12) { alarm.setAmPm("PM"); alarm.setHour(hourOfDay - 12); alarm.setHourFormatted((hourOfDay - 12) + ":" + min); } else { if (hourOfDay == 0) { hourOfDay = 12; } alarm.setAmPm("AM"); alarm.setHour(hourOfDay); alarm.setHourFormatted(hourOfDay + ":" + min); } alarm.setMinute(minute); Intent intent = new Intent(getApplicationContext(), AddAlarmActivity.class); intent.putExtra(Constant.actionAlarmKey, Constant.addAlarm); intent.putExtra(Constant.alarmSerializableKey, alarm); startActivity(intent); } }, hour, minute, false); timePickerDialog.show(getSupportFragmentManager(), "tag"); return true; case R.id.itCurrentMonth: actualItem = menuItem.getItemId(); menuItem.setChecked(true); showFragment(R.id.itCurrentMonth); getSupportActionBar().setTitle(title); return true; /* case R.id.itConfig: actualItem = menuItem.getItemId(); menuItem.setChecked(true); showFragment(R.id.itConfig); getSupportActionBar().setTitle(title); closeDrawer(); return true; */ case R.id.itAbout: AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this); WebView wvLegal = (WebView) LayoutInflater.from(getApplication()) .inflate(R.layout.web_view_legal, null); wvLegal.loadData(getString(R.string.html_legal), "text/html", "UTF-8"); wvLegal.setWebChromeClient(new WebChromeClient()); alertBuilder.setView(wvLegal); alertBuilder.setTitle(R.string.txt_about_app); alertBuilder.setCancelable(true).setPositiveButton(getString(R.string.txt_button_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); alertBuilder.show(); return true; default: return false; } } }); }