Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of the box: Listener methods #7

Closed
jflamman opened this issue Jan 21, 2015 · 4 comments
Closed

Out of the box: Listener methods #7

jflamman opened this issue Jan 21, 2015 · 4 comments

Comments

@jflamman
Copy link

Following the steps in the readme, Android Studio still threw warnings the Activity must be either abstract or implement AdvancedWebView's Listener methods.

It stopped complaining when I copied the methods from mWebView.setListener to the Activity class and commented out the mWebView.setListener part in onCreate altogether.

@Override
public void onPageStarted(String url, Bitmap favicon) {
    // a new page started loading
}

@Override
public void onPageFinished(String url) {
    // the new page finished loading
}

@Override
public void onPageError(int errorCode, String description, String failingUrl) {
    // the new page failed to load
}

@Override
public void onDownloadRequested(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
    // some file is available for download
}

@Override
public void onExternalPageRequest(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    mWebView.getContext().startActivity(intent);
}

(I added the Intent to onExternalPageRequest to be able to have external links open in my phone's browser)

@ocram
Copy link
Contributor

ocram commented Jan 21, 2015

Thanks!

This was actually intended behaviour, as there are two ways to implement the listener:

  • by implementing the interface right in the Activity or Fragment class
  • by creating an anonymous class

You don't need both ways, of course.

Adding the methods to the Activity or Fragment class was correct. And then you can remove the anonymous class from setListener() and just call it with this, this.

Does that help?

The documentation was poor, you're right. Has been fixed with 8252c4e

@jflamman
Copy link
Author

OK, that helps! I'm not a Java geek and I wasn't sure my workaround was a hack or an allowed way to make things work. :-)

mWebView.setListener(this, this); is already there, so I guess that takes care of it then.

Thank you for all your work & your quick responses..

@ocram
Copy link
Contributor

ocram commented Jan 21, 2015

Great! That's fine, now things have been clarified :)

The README was definitely confusing before. Thanks for pointing out!

@ocram ocram closed this as completed Jan 21, 2015
@jflamman
Copy link
Author

Glad to be of help, keep up the good work!

@1170762202 1170762202 mentioned this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants