Skip to content

Commit

Permalink
Open webview links in external browser
Browse files Browse the repository at this point in the history
- fixes #45
  • Loading branch information
hameno committed Sep 11, 2015
1 parent 0d11337 commit 43dd792
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 20 additions & 3 deletions library/src/main/java/de/psdev/licensesdialog/LicensesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@

package de.psdev.licensesdialog;

import java.util.List;

import javax.annotation.Nullable;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Message;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import de.psdev.licensesdialog.licenses.ApacheSoftwareLicense20;
import de.psdev.licensesdialog.model.Notice;
import de.psdev.licensesdialog.model.Notices;

import javax.annotation.Nullable;
import java.util.List;

public class LicensesDialog {
public static final Notice LICENSES_DIALOG_NOTICE = new Notice("LicensesDialog", "http://psdev.de/LicensesDialog",
"Copyright 2013 Philip Schiffer",
Expand Down Expand Up @@ -71,6 +76,18 @@ public LicensesDialog setOnDismissListener(final DialogInterface.OnDismissListen
public Dialog create() {
//Get resources
final WebView webView = new WebView(mContext);
webView.getSettings().setSupportMultipleWindows(true);
webView.setWebChromeClient(new WebChromeClient() {
@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();
final Context context = view.getContext();
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
context.startActivity(browserIntent);
return false;
}
});
webView.loadDataWithBaseURL(null, mLicensesText, "text/html", "utf-8", null);
final AlertDialog.Builder builder;
if (mThemeResourceId != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ private void appendNoticeBlock(final StringBuilder noticesHtmlBuilder, final Not
noticesHtmlBuilder.append("<ul><li>").append(notice.getName());
final String currentNoticeUrl = notice.getUrl();
if (currentNoticeUrl != null && currentNoticeUrl.length() > 0) {
noticesHtmlBuilder.append(" (<a href=\"").append(currentNoticeUrl).append("\">").append(currentNoticeUrl).append("</a>)");
noticesHtmlBuilder.append(" (<a href=\"")
.append(currentNoticeUrl)
.append("\" target=\"_blank\">")
.append(currentNoticeUrl)
.append("</a>)");
}
noticesHtmlBuilder.append("</li></ul>");
noticesHtmlBuilder.append("<pre>");
Expand Down

0 comments on commit 43dd792

Please sign in to comment.