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
Related
I am trying to change the visibility of my textview inside onCreate method, but I cant seem to get a handle for it. Or, perhaps something else is wrong. Also, the getUrl() from the WebView class is not behaving as it should. It seems that it detects the url i am looking for after i leave the page with the url i am trying to detect. After reading the documentation, it made it somewhat clear based on the definition of the method getUrl(). Here is what the documentation says: "Gets the URL for the current page. This is not always the same as the URL passed to WebViewClient.onPageStarted because although the load for that URL has begun, the current page may not have changed."
Here's what I mean:
I click on "link within the webpage that has url am trying to detect call it url5", then pressed back button, then click on "some other link within webpage call it url6" . Now, when I go back out of link with url6, the link for url5 is detected and I should be able to setVisibility of my textview as VISIBLE, which i tried but nothing happens. Well, here's my code. Please advise of anything that I might be doing wrong.
"xml format"
<RelativeLayout>
specifications for the relative layout...
<TextView>
android:visibility="invisible"
other specifications such as match_parent for both height and width
/>
<LinearLayout>
specifications of linear layout...
<LinearLayout/>
</RelativeLayout>
"inside onCreate"
relative_layout = (RelativeLayout)getLayoutInflater().inflate(R.layout.content_main, null);
text_view = (TextView)relative_layout.findViewById(R.id.text);
WebView w = (WebView) findViewById(R.id.webview);
w.setWebViewClient(new MyWebViewClient());
//outside of onCreate inside private class MyWebViewClient
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
if(W.getUrl().equals("url I want to detect") ||
W.getUrl().equals("another url I want to detect")){
text_view.setVisibility(View.VISIBLE); //HOWEVER NOTHING SHOWS AT ALL
relative_layout.setVisibility(View.INVISIBLE);
}
return false;
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && w.canGoBack()) {
if(text_view.isShown()){
w.goBack();
text_view.setVisibility(View.INVISIBLE);
relative_layout.setVisibility(View.VISIBLE);
}else w.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
I'm building a web based Android app using the Crosswalk Cordova framework, and
I'm trying to capture any touch events that occur on the XWalk webview within the main activity of my app, but so far everything I've tried I can't get the touch events to be triggered during debugging sessions.
Specifically I'm trying to capture a three finger swipe down anywhere on the web view so I can display a settings pane.
Here is what I've got so far in my main activity:
public class MyActivity extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
super.loadUrl(Config.getStartUrl());
// appView is the main xwalk webview setup in parent
appView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
// Check for three finger swipe...
}
});
}
....
}
I realise I could probably catch the touch event through javascript events that could then trigger the action through a cordova api call, but I'd much rather have this logic within the android app.
I've also tried capturing touch events in onTouchEvent method
public boolean onTouchEvent(View view, MotionEvent event) {
int action = event.getAction();
// Check for three finger swipe...
}
But again this method is never triggered.
Any help or ideas would be much appreciated.
I managed to get this working by overriding the dispatchTouchEvent method defined in Activity class. This was capturing the touch event and delegating them to my cordova webview without ever firing my onTouchEvent.
#Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int action = ev.getAction();
// handle three finger swipe
super.dispatchTouchEvent(ev);
}
I hope this may help someone facing this issue :)
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;
}
});
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
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