本文整理了Java中android.webkit.WebView.getHitTestResult()
方法的一些代码示例,展示了WebView.getHitTestResult()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebView.getHitTestResult()
方法的具体详情如下:
包路径:android.webkit.WebView
类名称:WebView
方法名:getHitTestResult
暂无
代码示例来源:origin: k9mail/k-9
WebView.HitTestResult result = webview.getHitTestResult();
代码示例来源:origin: stackoverflow.com
wv.getSettings().setSupportMultipleWindows(true);
wv.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
{
WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Context context = view.getContext();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
context.startActivity(browserIntent);
return false;
}
});
代码示例来源:origin: stackoverflow.com
@Override
public void onLoadResource (WebView view, String url) {
if (url.contains("googleads")) {
if(view.getHitTestResult().getType() > 0){
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
view.stopLoading();
Log.i("RESLOAD", Uri.parse(url).toString());
}
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void onLoadResource (WebView view, String url) {
if (url.contains("googleads")) {
if(view.getHitTestResult() != null &&
(view.getHitTestResult().getType() == HitTestResult.SRC_ANCHOR_TYPE ||
view.getHitTestResult().getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)){
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
view.stopLoading();
}
}
}
代码示例来源:origin: PSDev/LicensesDialog
@Override
public boolean onCreateWindow(final WebView view, final boolean isDialog, final boolean isUserGesture, final Message resultMsg) {
final WebView.HitTestResult result = view.getHitTestResult();
final String data = result.getExtra();
if (data != null) {
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
context.startActivity(browserIntent);
}
return false;
}
});
代码示例来源:origin: stackoverflow.com
@Override
public void onLoadResource(WebView view, String url)
{
// the url that contains the ad to link to contains googleads, this is risky if google
// change it, but there couldn't find a nice way around
if (url.contains("googleads"))
{
HitTestResult hitTestResult = view.getHitTestResult();
// Check is the hit test is a src tag with image anchor (i.e an mobile ad)
if (hitTestResult.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)
{
getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
view.stopLoading();
}
}
}
代码示例来源:origin: AmniX/AdBlockedWebView-Android
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
WebView.HitTestResult result = mWebView.getHitTestResult();
mPresenter.onLongClick(result);
}
代码示例来源:origin: LineageOS/android_packages_apps_Jelly
@Override
public boolean onCreateWindow(WebView view, boolean isDialog,
boolean isUserGesture, Message resultMsg) {
WebView.HitTestResult result = view.getHitTestResult();
String url = result.getExtra();
TabUtils.openInNewTab(mActivity, url, mIncognito);
return true;
}
}
代码示例来源:origin: marzika/Snapprefs
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
WebView.HitTestResult result = ((WebView) v).getHitTestResult();
代码示例来源:origin: indywidualny/FaceSlim
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
WebView.HitTestResult result = webView.getHitTestResult();
if (result != null) {
int type = result.getType();
if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
showLongPressedImageMenu(menu, result.getExtra());
}
}
}
代码示例来源:origin: jahirfiquitiva/IconShowcase
/**
* Links in the flattr iframe should load in the browser not in the iframe itself,
* http:/
* /stackoverflow.com/questions/5641626/how-to-get-webview-iframe-link-to-launch-the
* -browser
*/
@Override
public void onLoadResource(WebView view, String url) {
if (url.contains("flattr")) {
WebView.HitTestResult result = view.getHitTestResult();
if (result != null && result.getType() > 0) {
try {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch (ActivityNotFoundException e) {
openDialog(android.R.drawable.ic_dialog_alert, R.string
.donations__alert_dialog_title,
getString(R.string.donations__alert_dialog_no_browser));
}
view.stopLoading();
}
}
}
代码示例来源:origin: XunMengWinter/Now
@Override
public boolean onTouch(View v, MotionEvent event) {
if (v instanceof WebView) {
WebView.HitTestResult hr = ((WebView) v).getHitTestResult();
Log.i("xyz ", "getExtra = " + hr.getExtra() + "\t\t Type=" + hr.getType());
代码示例来源:origin: stackoverflow.com
webview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final WebView webview = (WebView) v;
final HitTestResult result = webview.getHitTestResult();
if(result.getType()==HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// 2. and here we get the url (remember to remove the WebView client and return true so that the hyperlink will not be really triggered)
mUrl = url; // mUrl is a member variant of the activity
view.setWebViewClient(null);
return true;
}
});
// 1. the picture must be focused, so we simulate a DPAD enter event to trigger the hyperlink
KeyEvent event1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
webview.dispatchKeyEvent(event1);
KeyEvent event2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER);
webview.dispatchKeyEvent(event2);
// 3. now you can do something with the anchor url (and then clear the mUrl for future usage)
String url = mUrl;
if (url!=null) {
Toast.makeText(webview.getContext(), url, Toast.LENGTH_SHORT).show();
}
mUrl = null;
}
return false;
}
});
代码示例来源:origin: indywidualny/FaceSlim
@Override
public boolean onLongClick(View v) {
// activate long clicks on links and image links according to settings
if (preferences.getBoolean("long_clicks", true)) {
WebView.HitTestResult result = webView.getHitTestResult();
if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
Message msg = linkHandler.obtainMessage();
webView.requestFocusNodeHref(msg);
return true;
}
}
return false;
}
});
代码示例来源:origin: yongyu0102/ShowImageFromWebView
/**
* 响应长按点击事件
* @param v
*/
private void setWebImageLongClickListener(View v) {
if (v instanceof WebView) {
HitTestResult result = ((WebView) v).getHitTestResult();
if (result != null) {
int type = result.getType();
if (type == HitTestResult.IMAGE_TYPE || type == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
longClickUrl = result.getExtra();
showDialog(longClickUrl);
}
}
}
}
代码示例来源:origin: powerpoint45/Lucid-Browser
WebView.HitTestResult result = ((WebView) v).getHitTestResult();
if (result != null && result.getExtra()!=null && !result.getExtra().startsWith("file:")) {
int type = result.getType();
代码示例来源:origin: AriesHoo/FastLib
@Override
protected void setAgentWeb(AgentWeb mAgentWeb) {
super.setAgentWeb(mAgentWeb);
WebView mWebView = mAgentWeb.getWebCreator().getWebView();
mWebView.setOnLongClickListener(v -> {
WebView.HitTestResult hitTestResult = mWebView.getHitTestResult();
if (hitTestResult == null) {
return false;
}
if (hitTestResult.getType() == WebView.HitTestResult.IMAGE_TYPE
|| hitTestResult.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
showDownDialog(hitTestResult.getExtra());
} else if (!mIsShowTitle) {
showActionSheet();
}
LoggerManager.d("onLongClick:hitTestResult-Type:" + hitTestResult.getType() + ";Extra:" + hitTestResult.getExtra());
return true;
});
}
内容来源于网络,如有侵权,请联系作者删除!