android webview issues - android

i have created a webview
<WebView
android:id="#+id/webview_compontent"
android:layout_marginTop = "10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#FFFFFF"
/>
and in my class.java file
webView = (WebView) findViewById(R.id.webview_compontent);
//Need to enable scrollbars when in zoom
webView.setHorizontalScrollBarEnabled(true);
webView.setVerticalScrollBarEnabled(true);
webView.setPadding(0, 0, 0, 0);
//Page is bigger than view so fit it inside the view
webView.setInitialScale(40);
//Enable zooming
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl("www.xyz.com");
webView.setWebViewClient(new MyWebViewClient());
//To disable the link clicks on the page
webView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return true;
}
});
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
My problem is that i want to diable all the link clicks inside webview but allow zooming with vertical and horizontal scrolls so that the user can zoom and read the text.If i set "webView.setOnTouchListener" to "ture" my webview does not respond to click events which i want but zoom control also stops which i want to be enabled. How can i filter zoom and link clicks event and enable/disable the view accordingly.
Please help me how to go about this.
Thanks

Thanks for your answers.But i got it going by adding
webView.setClickable(false); //To disable link clicks
and
webView.getSettings().setBuiltInZoomControls(true); //Enable zooming

Related

how to detect click on button, video element in webview?

i can detect some events (http://developer.android.com/reference/android/webkit/WebView.HitTestResult.html#constants) in html using WebView.HitTestResult on webview.onTouch event. what i try to achieve is that when user click anywhere in webivew, if it does not start any action like play/pause video, redirect some page etc then toggle visibility of footer linearLayout in same activity. but i can't catch some actions like click on button, play/pause button of video element in webview. So how i can i detect these actions?
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
WebView.HitTestResult hr = ((WebView) v).getHitTestResult();
if (hr != null) {
Log.w("webView.onTouch", "getExtra = " + hr.getExtra() + "\t\t Type=" + hr.getType());
} else {
Log.w("webView.onTouch", event.toString());
}
return false;
}
});
You have to Atleast Get the Element Name or Id or class or any attribute to set onClick attribute if You know It Then It's really easy use Javascript to addattribute for onClick
Webview webview;
.....
Your code or whatever
...
webview.addJavascriptInterface(new javasctiptinterface(),"javasciptinterfaceCall");
webview.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url) {
view.loadUrl("javascript:document.getElementsByName('Element_NameAttribute_Value')[0].setAttribute('onClick','javascriptinterfaceCall.clicked()');");
}
});
Class javasctiptinterface{
#javascriptinterface
public void clicked(){
... Your Code ......
}

How to disable the content touch in WebView without afecting the double tap zoom .

Acually i wanted to load the content in the webview , which is in a xhtml file .
I want to disable the accessibility to the content . Click on the link/texts must not navigate to that particular page .
More particularly , I have the contents page of a book in the xhtml file and click on the contents must not navigate to the particular page .
WebView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Will work good but this stops the doulble tap zoom as well . I want to stop accessing the content without affecting the tap zoom .
And one more is that , what does webview.getSettings().setAllowContentAccess(false); refer to in webview .
Thanks in Advance .
If you only want to prevent navigations (user following links) then you need to use the shouldOverrideUrlLoading API:
webview.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});

how to apply zoom in/out functionality for Image view on button click?

I am new to Android and I have to create one android application that shows the images from the server. I want to apply zoom effects on button click. I have two buttons one for zoom in and another is form zoom out. I want to apply zoom in or out on click of related button click. I searched a lot but did not find any thing related to my specific case. I have so far implemented imageview.onTouchlisterner() for zoom effects but I don't want this I want to do zoom on button click so please help me. Thank you in advance.
a very simple technique that i used for such purpose, make a webview and load you image using its url into that webview on image clicked like this:
WebView web=(WebView)findViewById(R.id.web);
mProgress = ProgressDialog.show(this, "Please wait!", "Loading image and zoom controlls...");
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setBuiltInZoomControls(true);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
String url=getIntent().getExtras().getString("imageURL");
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
// when finish loading page
public void onPageFinished(WebView view, String url) {
if(mProgress.isShowing()) {
mProgress.dismiss();
}
}
});
web.loadUrl(url);
}

Disable selectable links within WebView

I have a webView that is contained within a scrollView. Everything is then contained within a viewPager. When I fling to the next view page, the links that are in the middle of the page are being focused (highlighted with orange around the text). This causes the page to jump down to the nearest link.
Is there a way to disable links from being focusable on touch? I've tried all the settings for the webView such as focusable = false, clickable = false, focusable in touch mode = false, and nothing seems to be working.
I managed to do it programmatically like so:
WebView myWebView = (WebView) storyItem.findViewById(R.id.myWebView);
myWebView.setFocusableInTouchMode(false);
myWebView.setFocusable(false);
This makes the links non-focusable, which solved my problem!
webView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
This prevents the webview from opening any links and will also allow you to navigate the page without problems

How to load a part of an webpage in android webview?

I would like to make an app, that shows a part of the site.
Lets say that i have this site:
I only want to show this:
https://mail.google.com/mail/?ui=2&ik=d5146163e8&view=att&th=132496ec47863fea&attid=0.1&disp=inline&realattid=f_gsbtyog80&zw
Is there anyway to do this?
I hope some of you could help me.
Gaauwe
You could load the url to a WebView and then set the WebView's scroll position and zoom level to display only a specific part of the web page. If you don't want to change zoom level you could initially scroll the WebView to the required location and then override the WebView's onTouch method so that it will only scroll upto the required cordinates.
public class MyWebViewActivity extends Activity implements PictureListener{
private WebView webView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
webView.setPictureListener(this);
// disable scroll on touch
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return (event.getAction() == MotionEvent.ACTION_MOVE);
}
});
webView.loadUrl(url);
}
#Override
public void onNewPicture(WebView view, Picture picture) {
// TODO Auto-generated method stub
webView.scrollTo(x, y);
}
}
One of the way is to use PHP on your own server and CURL the webpage into it and strip out all the unnecessary things .
After that you only load it into your webview.
*This is one of the method, there are others method better then this. *
Another way is coldfusion cfhttp .. not sure,about this http://www.quackit.com/coldfusion/tutorial/coldfusion_http.cfm

Categories

Resources