List of usage examples for android.webkit WebView setWebChromeClient
public void setWebChromeClient(WebChromeClient client)
From source file:com.saltedge.sdk.webview.SEWebViewTools.java
public void initializeWithUrl(Activity activity, final WebView webView, final String url, WebViewRedirectListener listener) { this.activity = activity; this.webViewRedirectListener = listener; progressDialog = UITools.createProgressDialog(this.activity); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setAllowFileAccess(true); webView.setWebViewClient(new CustomWebViewClient()); webView.setWebChromeClient(new WebChromeClient() { @Override// w ww. j a v a 2s .c o m public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { SETools.uploadMessage = filePathCallback; pickFile(); return true; } }); webView.loadUrl(url); }
From source file:in.ac.dtu.subtlenews.InstapaperViewer.java
@SuppressLint("NewApi") @Override//from w w w .j a va 2 s. c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setImmersive(true); } setTheme(R.style.AppTheme_NoActionBar); setContentView(R.layout.activity_instapaper_viewer); //setupActionBar(); Bundle extras = getIntent().getExtras(); if (extras != null) { urlId = extras.getInt("URLID"); urlList = extras.getStringArrayList("URLList"); } final WebView instapaperView = (WebView) findViewById(R.id.instapaper_viewer); final Activity activity = this; final ProgressBar progressBar; progressBar = (ProgressBar) findViewById(R.id.progressBar); instapaperView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (progress < 100 && progressBar.getVisibility() == ProgressBar.GONE) { progressBar.setVisibility(ProgressBar.VISIBLE); //txtview.setVisibility(View.VISIBLE); } progressBar.setProgress(progress); if (progress == 100) { progressBar.setVisibility(ProgressBar.GONE); //txtview.setVisibility(View.GONE); } } }); final View controlsView = findViewById(R.id.fullscreen_content_controls); final View contentView = findViewById(R.id.instapaper_viewer); final Button prevButton = (Button) findViewById(R.id.summary_prev_button); final Button nextButton = (Button) findViewById(R.id.summary_next_button); // Set up an instance of SystemUiHider to control the system UI for // this activity. mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS); mSystemUiHider.setup(); mSystemUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() { // Cached values. int mControlsHeight; int mShortAnimTime; @Override @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public void onVisibilityChange(boolean visible) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // If the ViewPropertyAnimator API is available // (Honeycomb MR2 and later), use it to animate the // in-layout UI controls at the bottom of the // screen. if (mControlsHeight == 0) { mControlsHeight = controlsView.getHeight(); } if (mShortAnimTime == 0) { mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); } controlsView.animate().translationY(visible ? 0 : mControlsHeight).setDuration(mShortAnimTime); } else { // If the ViewPropertyAnimator APIs aren't // available, simply show or hide the in-layout UI // controls. controlsView.setVisibility(visible ? View.VISIBLE : View.GONE); } if (visible && AUTO_HIDE) { // Schedule a hide(). delayedHide(AUTO_HIDE_DELAY_MILLIS); } } }); // Set up the user interaction to manually show or hide the system UI. contentView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (TOGGLE_ON_CLICK) { mSystemUiHider.toggle(); } else { mSystemUiHider.show(); } } }); // Upon interacting with UI controls, delay any scheduled hide() // operations to prevent the jarring behavior of controls going away // while interacting with the UI. prevButton.setOnTouchListener(mDelayHideTouchListener); nextButton.setOnTouchListener(mDelayHideTouchListener); try { summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(urlId); } catch (Exception e) { e.printStackTrace(); } instapaperView.loadUrl(summaryUrl); prevButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(--urlId); } catch (Exception e) { e.printStackTrace(); } instapaperView.loadUrl(summaryUrl); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(++urlId); } catch (Exception e) { e.printStackTrace(); } instapaperView.loadUrl(summaryUrl); } }); }
From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override//w w w . java 2s . c om public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) return view; view = inflater.inflate(R.layout.webview, container, false); assert view != null; final WebView webView = (WebView) view.findViewById(R.id.webView); WebSettings settings = webView.getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); final ProgressDialog progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage(getResources().getString(R.string.loading)); webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress); if (newProgress < 100) { progressDialog.setProgress(newProgress); progressDialog.show(); } else { progressDialog.hide(); } } }); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) { handler.proceed(); } @SuppressWarnings("ConstantConditions") @Override public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host, String realm) { FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity()); String url = currentServer.getUrl(); String alternativeUrl = trimToNull(currentServer.getAlternateUrl()); try { String fhemUrlHost = new URL(url).getHost(); String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost(); String username = currentServer.getUsername(); String password = currentServer.getPassword(); if (host.startsWith(fhemUrlHost) || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) { handler.proceed(username, password); } else { handler.cancel(); Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication); getActivity().sendBroadcast(intent); } } catch (MalformedURLException e) { Intent intent = new Intent(Actions.SHOW_TOAST); intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection); getActivity().sendBroadcast(intent); LOG.error("malformed URL: " + url, e); handler.cancel(); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if ("about:blank".equalsIgnoreCase(url)) { Optional<String> alternativeUrl = getAlternateLoadUrl(); if (alternativeUrl.isPresent()) { webView.loadUrl(alternativeUrl.get()); } } else { onPageLoadFinishedCallback(view, url); } } }); return view; }
From source file:com.nestlabs.sdk.NestAuthActivity.java
@Override @SuppressLint("SetJavaScriptEnabled") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.nest_auth_webview_layout); WebView clientWebView = (WebView) findViewById(R.id.auth_webview); mProgressBar = (ProgressBar) findViewById(R.id.webview_progress); mNestConfig = getIntent().getParcelableExtra(KEY_CLIENT_METADATA); // If any args are empty, they are invalid and we should finish. if (mNestConfig == null || Utils.isAnyEmpty(mNestConfig.getRedirectURL(), mNestConfig.getClientID(), mNestConfig.getStateValue())) { finishWithResult(RESULT_CANCELED, null); return;/*from w ww. j a v a 2 s.co m*/ } mHttpClient = new OkHttpClient(); clientWebView.setWebChromeClient(new ProgressChromeClient()); clientWebView.setWebViewClient(new RedirectClient()); String url = String.format(NestAPI.CLIENT_CODE_URL, mNestConfig.getClientID(), mNestConfig.getStateValue()); WebSettings webSettings = clientWebView.getSettings(); webSettings.setJavaScriptEnabled(true); clientWebView.loadUrl(url); }
From source file:com.purchasingpower.inappbrowser.WebViewActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); setContentView(getResources().getIdentifier("nativebrowserplugin", "layout", getPackageName())); if (!checkPermission()) { requestPermission();/*from w w w .j a v a2 s .c om*/ } Intent intent = getIntent(); String url = intent.getExtras().getString("url"); final WebView myWebView = (WebView) findViewById( getResources().getIdentifier("webview", "id", getPackageName())); myWebView.setWebViewClient(new MyWebViewClient()); webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); webSettings.setAllowFileAccess(true); myWebView.setWebChromeClient(new PQChromeClient()); //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration if (Build.VERSION.SDK_INT >= 19) { myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) { myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } myWebView.loadUrl(url); back = (ImageView) findViewById(getResources().getIdentifier("back", "id", getPackageName())); back.setImageResource(getResources().getIdentifier("back_gray", "drawable", getPackageName())); forward = (ImageView) findViewById(getResources().getIdentifier("forward", "id", getPackageName())); forward.setImageResource(getResources().getIdentifier("forward_gray", "drawable", getPackageName())); done = (TextView) findViewById(getResources().getIdentifier("done", "id", getPackageName())); pbar = (ProgressBar) findViewById(getResources().getIdentifier("pbar", "id", getPackageName())); pbar.setVisibility(View.VISIBLE); back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myWebView.canGoBack()) { myWebView.goBack(); } } }); forward.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myWebView.canGoForward()) { myWebView.goForward(); } } }); done.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.v("Done", "Clicked"); finish(); } }); }
From source file:org.openqa.selendroid.server.model.SelendroidWebDriver.java
private void configureWebView(final WebView view) { ServerInstrumentation.getInstance().runOnUiThread(new Runnable() { @Override/* ww w .j a v a 2s .co m*/ public void run() { view.clearCache(true); view.clearFormData(); view.clearHistory(); view.setFocusable(true); view.setFocusableInTouchMode(true); view.setNetworkAvailable(true); view.setWebChromeClient(new MyWebChromeClient()); WebSettings settings = view.getSettings(); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setSupportMultipleWindows(true); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCacheMaxSize(10 * 1024 * 1024); settings.setAppCachePath(""); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); settings.setGeolocationEnabled(true); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setRenderPriority(WebSettings.RenderPriority.HIGH); // Flash settings settings.setPluginState(WebSettings.PluginState.ON); // Geo location settings settings.setGeolocationEnabled(true); settings.setGeolocationDatabasePath("/data/data/selendroid"); } }); }
From source file:com.lemon.lime.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getBatteryPercentage();/*from w w w.j a v a2s. c o m*/ setContentView(R.layout.activity_main); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(false); mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview); mWebView.setScrollViewCallbacks(this); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.bar, null); getSupportActionBar().setCustomView(v); WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red); window = getWindow(); favicon = (ImageView) findViewById(R.id.favicon); editurl = (EditText) findViewById(R.id.editurl); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); favicon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (lili == 5) { lilimode(); lili = 0; lilimode = true; } else { lili = lili + 1; } } }); editurl.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (event.getAction() == KeyEvent.ACTION_UP) { if (editurl.getText().toString().contains("file:///")) { filemgr(); } else if (editurl.getText().toString().contains("gaymode")) { gaymode(); } else if (editurl.getText().toString().contains("exitapp")) { finish(); } else if (editurl.getText().toString().contains("light")) { flash(); } if (isconnected()) { if (editurl.getText().toString().contains("http://") || editurl.getText().toString().contains("https://")) { mWebView.loadUrl(editurl.getText().toString()); } else if (editurl.getText().toString().contains(".com") || editurl.getText().toString().contains(".net") || editurl.getText().toString().contains(".org") || editurl.getText().toString().contains(".gov") || editurl.getText().toString().contains(".hu") || editurl.getText().toString().contains(".sk") || editurl.getText().toString().contains(".co.uk") || editurl.getText().toString().contains(".co.in") || editurl.getText().toString().contains(".cn") || editurl.getText().toString().contains(".it") || editurl.getText().toString().contains(".de") || editurl.getText().toString().contains(".aus") || editurl.getText().toString().contains(".hr") || editurl.getText().toString().contains(".cz") || editurl.getText().toString().contains(".xyz") || editurl.getText().toString().contains(".pl") || editurl.getText().toString().contains(".io")) { mWebView.loadUrl("http://" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } else { mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString()); InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0); } } return true; } return false; } return true; } }); // Enable Javascript WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportMultipleWindows(true); if (isconnected()) { mWebView.loadUrl("http://google.com"); } else { final View coordinatorLayoutView = findViewById(R.id.snackbarPosition); mWebView.loadUrl("file:///android_asset/nonet.html"); Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG); snackbar.show(); } mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onReceivedIcon(WebView mWebView, Bitmap icon) { super.onReceivedIcon(mWebView, icon); favicon.setImageBitmap(icon); } public void onProgressChanged(WebView view, int progress) { activity.setProgress(progress * 100); int a = progress; if (lilimode) { editurl.setText("Liling: " + Integer.toString(a) + "?"); } else editurl.setText("Liming: " + Integer.toString(a) + "%"); if (progress == 100) { editurl.setHint(view.getTitle()); activity.setTitle(view.getTitle()); editurl.setText(view.getUrl()); fav(); //battery if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (level <= 20) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(Color.RED); window.setStatusBarColor(Color.RED); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED)); } } } } }); mWebView.setWebViewClient(new WebViewClient() { public void onPageFinished(WebView mWebView, String url) { swipeLayout.setRefreshing(false); } }); }
From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java
private void configureWebView(WebView webView, WebChromeClient webChromeClient, CustomWebViewClient customWebViewClient) { //Set the properties WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setSupportZoom(true); //Zoom Control on web (You don't need this if ROM supports Multi-Touch webSettings.setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM webSettings.setDomStorageEnabled(true); webSettings.setPluginsEnabled(true); webSettings.setUseWideViewPort(true); //normal viewport (such as a normal desktop browser) webView.setWebChromeClient(webChromeClient); webView.setWebViewClient(customWebViewClient); }
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 ww . j av a 2 s. 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:net.oremland.rss.reader.fragments.BrowserFragment.java
private void initializeViews(Bundle savedInstanceState) { if (savedInstanceState == null && getContext() != null) { boolean isTablet = getContext().getResources().getBoolean(R.bool.isTablet); WebSettings.ZoomDensity zoomDensity = isTablet ? WebSettings.ZoomDensity.MEDIUM : WebSettings.ZoomDensity.FAR; WebView description = (WebView) getView().findViewById(R.id.description); description.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); description.getSettings().setJavaScriptEnabled(true); description.getSettings().setPluginState(WebSettings.PluginState.ON); description.getSettings().setDefaultTextEncodingName("utf-8"); description.getSettings().setLoadWithOverviewMode(true); description.getSettings().setDefaultZoom(zoomDensity); description.getSettings().setSupportZoom(true); description.getSettings().setBuiltInZoomControls(true); description.requestFocus(View.FOCUS_DOWN); description.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); description.getSettings().setUseWideViewPort(isTablet); description.setWebChromeClient(this.getWebChromeClient()); description.setWebViewClient(this.getWebViewClient()); }/* w w w. ja va 2s.c om*/ }