use of android.webkit.WebChromeClient in project JsBridge by lzyzsd.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (BridgeWebView) findViewById(R.id.webView);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
webView.setDefaultHandler(new DefaultHandler());
webView.setWebChromeClient(new WebChromeClient() {
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType, String capture) {
this.openFileChooser(uploadMsg);
}
@SuppressWarnings("unused")
public void openFileChooser(ValueCallback<Uri> uploadMsg, String AcceptType) {
this.openFileChooser(uploadMsg);
}
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
mUploadMessage = uploadMsg;
pickFile();
}
});
webView.loadUrl("file:///android_asset/demo.html");
webView.registerHandler("submitFromWeb", new BridgeHandler() {
@Override
public void handler(String data, CallBackFunction function) {
Log.i(TAG, "handler = submitFromWeb, data from web = " + data);
function.onCallBack("submitFromWeb exe, response data 中文 from Java");
}
});
User user = new User();
Location location = new Location();
location.address = "SDU";
user.location = location;
user.name = "大头鬼";
webView.callHandler("functionInJs", new Gson().toJson(user), new CallBackFunction() {
@Override
public void onCallBack(String data) {
}
});
webView.send("hello");
}
use of android.webkit.WebChromeClient in project android by owncloud.
the class PrivacyPolicyActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_privacy_policy);
setupToolbar();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(getText(R.string.actionbar_privacy_policy));
// Display the progress in a progress bar, like the browser app does.
final ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.syncProgressBar);
DisplayUtils.colorPreLollipopHorizontalProgressBar(mProgressBar);
WebView webview = (WebView) findViewById(R.id.privacyPolicyWebview);
webview.getSettings().setJavaScriptEnabled(true);
//Enable zoom but hide display zoom controls
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setDisplayZoomControls(false);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//Set the web page loading progress
mProgressBar.setProgress(progress);
if (progress == 100) {
mProgressBar.setVisibility(View.GONE);
}
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), getString(R.string.privacy_policy_error) + description, Snackbar.LENGTH_LONG);
snackbar.show();
}
});
String urlPrivacyPolicy = getResources().getString(R.string.url_privacy_policy);
webview.loadUrl(urlPrivacyPolicy);
}
use of android.webkit.WebChromeClient in project 9GAG by Mixiaoxiao.
the class MxxBrowserActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// setmProgressBarIndeterminateVisibility(false);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayHomeAsUpEnabled(true);
// MxxSystemBarTintUtil.setSystemBarTintColor(this);
setContentView(R.layout.mxx_common_activity_browser);
initPadding();
// mActionBar = getActionBar();
// mActionBar.setTitle("");
// mActionBar.setDisplayHomeAsUpEnabled(true);
setActionBarTitle("");
View.OnClickListener toolbar_listener = new OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.mxx_common_activity_browser_toolbar_btn_back:
if (webView.canGoBack()) {
webView.goBack();
}
break;
case R.id.mxx_common_activity_browser_toolbar_btn_forward:
if (webView.canGoForward()) {
webView.goForward();
}
break;
case R.id.mxx_common_activity_browser_toolbar_btn_refresh:
webView.reload();
break;
default:
break;
}
}
};
webView = (WebView) this.findViewById(R.id.mxx_common_activity_browser_webview);
mProgressBar = (ProgressBar) findViewById(R.id.mxx_common_activity_browser_progressbar);
mBtnBack = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_back);
mBtnForward = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_forward);
mBtnRefresh = (ImageButton) this.findViewById(R.id.mxx_common_activity_browser_toolbar_btn_refresh);
mBtnBack.setEnabled(false);
mBtnForward.setEnabled(false);
// mBtnMenu = (ImageButton) this
// .findViewById(R.id.mxx_common_activity_browser_toolbar_btn_menu);
// mBtnClose = (ImageButton) this
// .findViewById(R.id.mxx_common_activity_browser_toolbar_btn_close);
mBtnBack.setOnClickListener(toolbar_listener);
mBtnForward.setOnClickListener(toolbar_listener);
// mBtnMenu.setOnClickListener(toolbar_listener);
// mBtnClose.setOnClickListener(toolbar_listener);
mBtnRefresh.setOnClickListener(toolbar_listener);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
// webView.getSettings().setUseWideViewPort(true);
// webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
webView.getSettings().setCacheMode(WebSettings.LOAD_NORMAL);
webView.setClipToPadding(false);
// webView.setFitsSystemWindows(true);
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
try {
// mActionBar.setTitle("下载");
setActionBarTitle("download");
Uri uri = Uri.parse(url);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(Intent.createChooser(it, "下载"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
MxxToastUtil.showToast(MxxBrowserActivity.this, "没有应用可执行此操作");
}
}
});
// webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// mUrlTitle.setText("鍔犺浇涓?..");
// mActionBar.setTitle("loading...");
setActionBarTitle("loading...");
mProgressBar.setVisibility(View.VISIBLE);
// mPage_title.setVisibility(View.INVISIBLE);
}
public void onPageFinished(WebView view, String url) {
mProgressBar.setVisibility(View.INVISIBLE);
mBtnBack.setEnabled(view.canGoBack());
mBtnForward.setEnabled(view.canGoForward());
// mActionBar.setTitle(url);
// mUrlTitle.setText(url);
}
});
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
// mmProgressBar.setProgress(newProgress);
// 璁剧疆杩涘害鐨勯暱搴︼紝0 <= progress <= 10000.
// setProgress(newProgress * 100);
mProgressBar.setProgress(newProgress);
}
public void onReceivedIcon(WebView view, Bitmap icon) {
// mFavor_icon.setImageBitmap(icon);
// mActionBar.setLogo(new BitmapDrawable(getResources(),icon));
}
public void onReceivedTitle(WebView view, String title) {
// mUrlTitle.setText(title);
// mActionBar.setTitle(title);
setActionBarTitle(title);
}
});
Intent intent = getIntent();
if (intent.hasExtra(extra_string_name)) {
String urlString = intent.getStringExtra(extra_string_name);
// webView.loadDataWithBaseURL(null, htmlString, "text/html",
// "utf-8", null);
webView.loadUrl(urlString);
} else {
// UiUtils.showToast(this, "锟斤拷莶锟斤拷锟饺笔?);
finish();
}
}
use of android.webkit.WebChromeClient in project robotium by RobotiumTech.
the class WebUtils method prepareForStartOfJavascriptExecution.
/**
* Prepares for start of JavaScript execution
*
* @return the JavaScript as a String
*/
private String prepareForStartOfJavascriptExecution(List<WebView> webViews) {
webElementCreator.prepareForStart();
WebChromeClient currentWebChromeClient = getCurrentWebChromeClient();
if (currentWebChromeClient != null && !currentWebChromeClient.getClass().isAssignableFrom(RobotiumWebClient.class)) {
originalWebChromeClient = currentWebChromeClient;
}
robotiumWebCLient.enableJavascriptAndSetRobotiumWebClient(webViews, originalWebChromeClient);
return getJavaScriptAsString();
}
use of android.webkit.WebChromeClient in project robolectric by robolectric.
the class ShadowWebViewTest method shouldRecordWebChromeClient.
@Test
public void shouldRecordWebChromeClient() {
WebChromeClient webChromeClient = new WebChromeClient();
assertThat(shadowWebView.getWebChromeClient()).isNull();
webView.setWebChromeClient(webChromeClient);
assertThat(shadowWebView.getWebChromeClient()).isSameAs(webChromeClient);
}
Aggregations