enable webview zoom controls
bump version
This commit is contained in:
parent
4057f5ac69
commit
2c71f2e829
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fox.ttrss"
|
package="org.fox.ttrss"
|
||||||
android:versionCode="181"
|
android:versionCode="182"
|
||||||
android:versionName="1.8.1" >
|
android:versionName="1.8.2" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="8"
|
android:minSdkVersion="8"
|
||||||
|
@ -95,256 +95,245 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
m_article = savedInstanceState.getParcelable("article");
|
m_article = savedInstanceState.getParcelable("article");
|
||||||
}
|
}
|
||||||
|
|
||||||
final View view = inflater.inflate(R.layout.article_fragment, container, false);
|
View view = inflater.inflate(R.layout.article_fragment, container, false);
|
||||||
|
|
||||||
WebView content = (WebView) view.findViewById(R.id.content);
|
|
||||||
|
|
||||||
if (content != null) content.setVisibility(View.INVISIBLE);
|
if (m_article != null) {
|
||||||
|
|
||||||
// prevent flicker in ics
|
TextView title = (TextView)view.findViewById(R.id.title);
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
|
||||||
content.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
if (title != null) {
|
||||||
}
|
|
||||||
|
|
||||||
new Handler().postDelayed(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (isAdded()) {
|
|
||||||
|
|
||||||
if (m_article != null) {
|
String titleStr;
|
||||||
|
|
||||||
TextView title = (TextView)view.findViewById(R.id.title);
|
if (m_article.title.length() > 200)
|
||||||
|
titleStr = m_article.title.substring(0, 200) + "...";
|
||||||
if (title != null) {
|
else
|
||||||
|
titleStr = m_article.title;
|
||||||
String titleStr;
|
|
||||||
|
|
||||||
if (m_article.title.length() > 200)
|
title.setText(Html.fromHtml(titleStr));
|
||||||
titleStr = m_article.title.substring(0, 200) + "...";
|
//title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
else
|
title.setOnClickListener(new OnClickListener() {
|
||||||
titleStr = m_article.title;
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
try {
|
||||||
title.setText(Html.fromHtml(titleStr));
|
URL url = new URL(m_article.link.trim());
|
||||||
//title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||||
title.setOnClickListener(new OnClickListener() {
|
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||||
@Override
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
|
||||||
public void onClick(View v) {
|
startActivity(intent);
|
||||||
try {
|
} catch (Exception e) {
|
||||||
URL url = new URL(m_article.link.trim());
|
e.printStackTrace();
|
||||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
m_activity.toast(R.string.error_other_error);
|
||||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
|
|
||||||
startActivity(intent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
m_activity.toast(R.string.error_other_error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
registerForContextMenu(title);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
TextView comments = (TextView)view.findViewById(R.id.comments);
|
});
|
||||||
|
|
||||||
if (comments != null) {
|
registerForContextMenu(title);
|
||||||
if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) {
|
}
|
||||||
String commentsTitle = getString(R.string.article_comments, m_article.comments_count);
|
|
||||||
comments.setText(commentsTitle);
|
TextView comments = (TextView)view.findViewById(R.id.comments);
|
||||||
//comments.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
|
||||||
comments.setOnClickListener(new OnClickListener() {
|
if (comments != null) {
|
||||||
@Override
|
if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) {
|
||||||
public void onClick(View v) {
|
String commentsTitle = getString(R.string.article_comments, m_article.comments_count);
|
||||||
try {
|
comments.setText(commentsTitle);
|
||||||
URL url = new URL((m_article.comments_link != null && m_article.comments_link.length() > 0) ?
|
//comments.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
m_article.comments_link : m_article.link);
|
comments.setOnClickListener(new OnClickListener() {
|
||||||
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
@Override
|
||||||
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW,
|
|
||||||
Uri.parse(uri));
|
|
||||||
startActivity(intent);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
m_activity.toast(R.string.error_other_error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
comments.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WebView web = (WebView)view.findViewById(R.id.content);
|
|
||||||
|
|
||||||
if (web != null) {
|
|
||||||
registerForContextMenu(web);
|
|
||||||
|
|
||||||
web.setWebChromeClient(new WebChromeClient() {
|
|
||||||
@Override
|
|
||||||
public void onProgressChanged(WebView view, int progress) {
|
|
||||||
m_activity.setProgress(Math.round(((float)progress / 100f) * 10000));
|
|
||||||
if (progress == 100) {
|
|
||||||
m_activity.setProgressBarVisibility(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
web.setOnTouchListener(new View.OnTouchListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
|
||||||
return m_detector.onTouchEvent(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String content;
|
|
||||||
String cssOverride = "";
|
|
||||||
|
|
||||||
WebSettings ws = web.getSettings();
|
|
||||||
ws.setSupportZoom(true);
|
|
||||||
ws.setBuiltInZoomControls(false);
|
|
||||||
|
|
||||||
web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
|
||||||
|
|
||||||
TypedValue tv = new TypedValue();
|
|
||||||
getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true);
|
|
||||||
|
|
||||||
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
|
||||||
cssOverride = "body { background : transparent; color : #e0e0e0}";
|
|
||||||
} else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK_GRAY")) {
|
|
||||||
cssOverride = "body { background : transparent; color : #e0e0e0}";
|
|
||||||
} else {
|
|
||||||
cssOverride = "body { background : transparent; }";
|
|
||||||
}
|
|
||||||
web.setBackgroundColor(getResources().getColor(android.R.color.transparent));
|
|
||||||
|
|
||||||
String hexColor = String.format("#%06X", (0xFFFFFF & tv.data));
|
|
||||||
cssOverride += " a:link {color: "+hexColor+";} a:visited { color: "+hexColor+";}";
|
|
||||||
|
|
||||||
cssOverride += " table { width : 100%; }";
|
|
||||||
|
|
||||||
String articleContent = m_article.content != null ? m_article.content : "";
|
|
||||||
|
|
||||||
Document doc = Jsoup.parse(articleContent);
|
|
||||||
|
|
||||||
if (doc != null) {
|
|
||||||
// thanks webview for crashing on <video> tag
|
|
||||||
Elements videos = doc.select("video");
|
|
||||||
|
|
||||||
for (Element video : videos)
|
|
||||||
video.remove();
|
|
||||||
|
|
||||||
articleContent = doc.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
String align = m_prefs.getBoolean("justify_article_text", true) ? "text-align : justify;" : "";
|
|
||||||
|
|
||||||
switch (Integer.parseInt(m_prefs.getString("font_size", "0"))) {
|
|
||||||
case 0:
|
|
||||||
cssOverride += "body { "+align+" font-size : 14px; } ";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
cssOverride += "body { "+align+" font-size : 18px; } ";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
cssOverride += "body { "+align+" font-size : 21px; } ";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
content =
|
|
||||||
"<html>" +
|
|
||||||
"<head>" +
|
|
||||||
"<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" +
|
|
||||||
"<style type=\"text/css\">" +
|
|
||||||
"body { padding : 0px; margin : 0px; }" +
|
|
||||||
cssOverride +
|
|
||||||
/* "img { max-width : 98%; height : auto; }" + */
|
|
||||||
"</style>" +
|
|
||||||
"</head>" +
|
|
||||||
"<body>" + articleContent;
|
|
||||||
|
|
||||||
if (m_article.attachments != null && m_article.attachments.size() != 0) {
|
|
||||||
String flatContent = articleContent.replaceAll("[\r\n]", "");
|
|
||||||
boolean hasImages = flatContent.matches(".*?<img[^>+].*?");
|
|
||||||
|
|
||||||
for (Attachment a : m_article.attachments) {
|
|
||||||
if (a.content_type != null && a.content_url != null) {
|
|
||||||
try {
|
|
||||||
if (a.content_type.indexOf("image") != -1 &&
|
|
||||||
(!hasImages || m_article.always_display_attachments)) {
|
|
||||||
|
|
||||||
URL url = new URL(a.content_url.trim());
|
|
||||||
String strUrl = url.toString().trim();
|
|
||||||
|
|
||||||
content += "<p><img src=\"" + strUrl.replace("\"", "\\\"") + "\"></p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
//
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
content += "<p> </p><p> </p><p> </p><p> </p></body></html>";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
|
URL url = new URL((m_article.comments_link != null && m_article.comments_link.length() > 0) ?
|
||||||
} catch (RuntimeException e) {
|
m_article.comments_link : m_article.link);
|
||||||
|
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
|
||||||
|
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse(uri));
|
||||||
|
startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
m_activity.toast(R.string.error_other_error);
|
||||||
|
|
||||||
if (m_activity.isSmallScreen())
|
|
||||||
web.setOnTouchListener(m_gestureListener);
|
|
||||||
|
|
||||||
web.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView dv = (TextView)view.findViewById(R.id.date);
|
|
||||||
|
|
||||||
if (dv != null) {
|
|
||||||
Date d = new Date(m_article.updated * 1000L);
|
|
||||||
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
|
||||||
dv.setText(df.format(d));
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView tagv = (TextView)view.findViewById(R.id.tags);
|
|
||||||
|
|
||||||
if (tagv != null) {
|
|
||||||
if (m_article.feed_title != null) {
|
|
||||||
tagv.setText(m_article.feed_title);
|
|
||||||
} else if (m_article.tags != null) {
|
|
||||||
String tagsStr = "";
|
|
||||||
|
|
||||||
for (String tag : m_article.tags)
|
|
||||||
tagsStr += tag + ", ";
|
|
||||||
|
|
||||||
tagsStr = tagsStr.replaceAll(", $", "");
|
|
||||||
|
|
||||||
tagv.setText(tagsStr);
|
|
||||||
} else {
|
|
||||||
tagv.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
TextView author = (TextView)view.findViewById(R.id.author);
|
|
||||||
|
|
||||||
if (author != null) {
|
|
||||||
if (m_article.author != null && m_article.author.length() > 0) {
|
|
||||||
author.setText(getString(R.string.author_formatted, m_article.author));
|
|
||||||
} else {
|
|
||||||
author.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
comments.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 50);
|
|
||||||
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
|
||||||
|
if (web != null) {
|
||||||
|
registerForContextMenu(web);
|
||||||
|
|
||||||
|
// prevent flicker in ics
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||||
|
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
web.setWebChromeClient(new WebChromeClient() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(WebView view, int progress) {
|
||||||
|
m_activity.setProgress(Math.round(((float)progress / 100f) * 10000));
|
||||||
|
if (progress == 100) {
|
||||||
|
m_activity.setProgressBarVisibility(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
web.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
return m_detector.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String content;
|
||||||
|
String cssOverride = "";
|
||||||
|
|
||||||
|
WebSettings ws = web.getSettings();
|
||||||
|
ws.setSupportZoom(true);
|
||||||
|
ws.setBuiltInZoomControls(true);
|
||||||
|
|
||||||
|
if (!m_activity.isCompatMode())
|
||||||
|
ws.setDisplayZoomControls(false);
|
||||||
|
|
||||||
|
web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||||
|
|
||||||
|
TypedValue tv = new TypedValue();
|
||||||
|
getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true);
|
||||||
|
|
||||||
|
if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) {
|
||||||
|
cssOverride = "body { background : transparent; color : #e0e0e0}";
|
||||||
|
} else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK_GRAY")) {
|
||||||
|
cssOverride = "body { background : transparent; color : #e0e0e0}";
|
||||||
|
} else {
|
||||||
|
cssOverride = "body { background : transparent; }";
|
||||||
|
}
|
||||||
|
web.setBackgroundColor(getResources().getColor(android.R.color.transparent));
|
||||||
|
|
||||||
|
String hexColor = String.format("#%06X", (0xFFFFFF & tv.data));
|
||||||
|
cssOverride += " a:link {color: "+hexColor+";} a:visited { color: "+hexColor+";}";
|
||||||
|
|
||||||
|
cssOverride += " table { width : 100%; }";
|
||||||
|
|
||||||
|
String articleContent = m_article.content != null ? m_article.content : "";
|
||||||
|
|
||||||
|
Document doc = Jsoup.parse(articleContent);
|
||||||
|
|
||||||
|
if (doc != null) {
|
||||||
|
// thanks webview for crashing on <video> tag
|
||||||
|
Elements videos = doc.select("video");
|
||||||
|
|
||||||
|
for (Element video : videos)
|
||||||
|
video.remove();
|
||||||
|
|
||||||
|
articleContent = doc.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
String align = m_prefs.getBoolean("justify_article_text", true) ? "text-align : justify;" : "";
|
||||||
|
|
||||||
|
switch (Integer.parseInt(m_prefs.getString("font_size", "0"))) {
|
||||||
|
case 0:
|
||||||
|
cssOverride += "body { "+align+" font-size : 14px; } ";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cssOverride += "body { "+align+" font-size : 18px; } ";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cssOverride += "body { "+align+" font-size : 21px; } ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
content =
|
||||||
|
"<html>" +
|
||||||
|
"<head>" +
|
||||||
|
"<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" +
|
||||||
|
"<style type=\"text/css\">" +
|
||||||
|
"body { padding : 0px; margin : 0px; }" +
|
||||||
|
cssOverride +
|
||||||
|
/* "img { max-width : 98%; height : auto; }" + */
|
||||||
|
"</style>" +
|
||||||
|
"</head>" +
|
||||||
|
"<body>" + articleContent;
|
||||||
|
|
||||||
|
if (m_article.attachments != null && m_article.attachments.size() != 0) {
|
||||||
|
String flatContent = articleContent.replaceAll("[\r\n]", "");
|
||||||
|
boolean hasImages = flatContent.matches(".*?<img[^>+].*?");
|
||||||
|
|
||||||
|
for (Attachment a : m_article.attachments) {
|
||||||
|
if (a.content_type != null && a.content_url != null) {
|
||||||
|
try {
|
||||||
|
if (a.content_type.indexOf("image") != -1 &&
|
||||||
|
(!hasImages || m_article.always_display_attachments)) {
|
||||||
|
|
||||||
|
URL url = new URL(a.content_url.trim());
|
||||||
|
String strUrl = url.toString().trim();
|
||||||
|
|
||||||
|
content += "<p><img src=\"" + strUrl.replace("\"", "\\\"") + "\"></p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
//
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content += "<p> </p><p> </p><p> </p><p> </p></body></html>";
|
||||||
|
|
||||||
|
try {
|
||||||
|
web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_activity.isSmallScreen())
|
||||||
|
web.setOnTouchListener(m_gestureListener);
|
||||||
|
|
||||||
|
web.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView dv = (TextView)view.findViewById(R.id.date);
|
||||||
|
|
||||||
|
if (dv != null) {
|
||||||
|
Date d = new Date(m_article.updated * 1000L);
|
||||||
|
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
||||||
|
dv.setText(df.format(d));
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView tagv = (TextView)view.findViewById(R.id.tags);
|
||||||
|
|
||||||
|
if (tagv != null) {
|
||||||
|
if (m_article.feed_title != null) {
|
||||||
|
tagv.setText(m_article.feed_title);
|
||||||
|
} else if (m_article.tags != null) {
|
||||||
|
String tagsStr = "";
|
||||||
|
|
||||||
|
for (String tag : m_article.tags)
|
||||||
|
tagsStr += tag + ", ";
|
||||||
|
|
||||||
|
tagsStr = tagsStr.replaceAll(", $", "");
|
||||||
|
|
||||||
|
tagv.setText(tagsStr);
|
||||||
|
} else {
|
||||||
|
tagv.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView author = (TextView)view.findViewById(R.id.author);
|
||||||
|
|
||||||
|
if (author != null) {
|
||||||
|
if (m_article.author != null && m_article.author.length() > 0) {
|
||||||
|
author.setText(getString(R.string.author_formatted, m_article.author));
|
||||||
|
} else {
|
||||||
|
author.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,10 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
|
|||||||
|
|
||||||
WebSettings ws = web.getSettings();
|
WebSettings ws = web.getSettings();
|
||||||
ws.setSupportZoom(true);
|
ws.setSupportZoom(true);
|
||||||
ws.setBuiltInZoomControls(false);
|
ws.setBuiltInZoomControls(true);
|
||||||
|
|
||||||
|
if (!m_activity.isCompatMode())
|
||||||
|
ws.setDisplayZoomControls(false);
|
||||||
|
|
||||||
web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user