Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
Load page data with base URL, otherwise links don't work on Android 4…
Browse files Browse the repository at this point in the history
….4.3
  • Loading branch information
itkach committed Jun 15, 2014
1 parent 9d460d5 commit 1714d3f
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions src/aarddict/android/ArticleViewActivity.java
Expand Up @@ -69,6 +69,8 @@

public class ArticleViewActivity extends BaseDictionaryActivity {

private static final String BASE_URL = "aard://A/";

private final static String TAG = ArticleViewActivity.class
.getName();

Expand Down Expand Up @@ -210,20 +212,11 @@ public void onPageFinished(WebView view, String url) {
}

@Override
public boolean shouldOverrideUrlLoading(WebView view,
final String url) {
Log.d(TAG, "URL clicked: " + url);
String urlLower = url.toLowerCase();
if (urlLower.startsWith("http://")
|| urlLower.startsWith("https://")
|| urlLower.startsWith("ftp://")
|| urlLower.startsWith("sftp://")
|| urlLower.startsWith("mailto:")
|| urlLower.startsWith("tel:")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse(url));
startActivity(browserIntent);
} else {
public boolean shouldOverrideUrlLoading(WebView view, String origUrl) {
Log.d(TAG, "URL clicked: " + origUrl);
final String url;
if (origUrl.startsWith(BASE_URL)) {
url = origUrl.substring(BASE_URL.length());
if (currentTask == null) {
currentTask = new TimerTask() {
public void run() {
Expand Down Expand Up @@ -267,6 +260,17 @@ public void run() {
}
}
}
else {
try {
Uri uri = Uri.parse(origUrl);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(browserIntent);
}
catch (Exception e) {
Toast.makeText(ArticleViewActivity.this, String.format("Failed to parse URL %s", origUrl),
Toast.LENGTH_SHORT).show();
}
}
return true;
}
});
Expand Down Expand Up @@ -409,31 +413,25 @@ private boolean textZoomOut() {
}

private void goBack() {
if (articleView.canGoBack()) {
articleView.goBack();
if (backItems.size() == 1) {
finish();
}
if (currentTask != null) {
return;
}
else {
if (backItems.size() == 1) {
finish();
}
if (currentTask != null) {
return;
}
if (backItems.size() > 1) {
HistoryItem current = backItems.remove(backItems.size() - 1);
HistoryItem prev = backItems.get(backItems.size() - 1);

Article prevArticle = prev.article;
if (prevArticle.equalsIgnoreSection(current.article)) {
resetTitleToCurrent();
if (!prevArticle.sectionEquals(current.article)
&& !restoreScrollPos()) {
goToSection(prevArticle.section);
}
} else {
showCurrentArticle();
if (backItems.size() > 1) {
HistoryItem current = backItems.remove(backItems.size() - 1);
HistoryItem prev = backItems.get(backItems.size() - 1);

Article prevArticle = prev.article;
if (prevArticle.equalsIgnoreSection(current.article)) {
resetTitleToCurrent();
if (!prevArticle.sectionEquals(current.article)
&& !restoreScrollPos()) {
goToSection(prevArticle.section);
}
} else {
showCurrentArticle();
}
}
}
Expand Down Expand Up @@ -660,7 +658,6 @@ private boolean restoreScrollPos() {
}

private void showNext(HistoryItem item_) {
articleView.clearHistory();
final HistoryItem item = new HistoryItem(item_);
final Entry entry = item.next();
runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -744,7 +741,7 @@ public void run() {
resetTitleToCurrent();
Article a = backItems.get(backItems.size() - 1).article;
Log.d(TAG, "Show article: " + a.text);
articleView.loadDataWithBaseURL("", wrap(a.text), "text/html",
articleView.loadDataWithBaseURL(BASE_URL, wrap(a.text), "text/html",
"utf-8", null);
}
});
Expand Down

0 comments on commit 1714d3f

Please sign in to comment.