minor efforts to speedup article fragment a bit
This commit is contained in:
parent
9523151a25
commit
e52e597a3d
@ -33,7 +33,7 @@ dependencies {
|
|||||||
compile 'com.android.support:appcompat-v7:22.2.0'
|
compile 'com.android.support:appcompat-v7:22.2.0'
|
||||||
compile 'com.shamanland:fab:0.0.5'
|
compile 'com.shamanland:fab:0.0.5'
|
||||||
compile 'ch.acra:acra:4.5.0'
|
compile 'ch.acra:acra:4.5.0'
|
||||||
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.1.0@aar'
|
compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
|
||||||
compile 'me.relex:circleindicator:1.1.1@aar'
|
compile 'me.relex:circleindicator:1.1.1@aar'
|
||||||
compile 'com.viewpagerindicator:library:2.4.1'
|
compile 'com.viewpagerindicator:library:2.4.1'
|
||||||
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
|
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
|
||||||
|
@ -88,7 +88,6 @@
|
|||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" name="cardview-v7-21.0.0" level="project" />
|
<orderEntry type="library" exported="" name="cardview-v7-21.0.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="jsoup-1.6.1" level="project" />
|
<orderEntry type="library" exported="" name="jsoup-1.6.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="view-pager-transforms-1.1.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="library-2.4.1" level="project" />
|
<orderEntry type="library" exported="" name="library-2.4.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="nineoldandroids-2.4.0" level="project" />
|
<orderEntry type="library" exported="" name="nineoldandroids-2.4.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
|
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
|
||||||
@ -101,6 +100,7 @@
|
|||||||
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
|
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="fab-0.0.5" level="project" />
|
<orderEntry type="library" exported="" name="fab-0.0.5" level="project" />
|
||||||
<orderEntry type="library" exported="" name="lib-core-3.1.0" level="project" />
|
<orderEntry type="library" exported="" name="lib-core-3.1.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="view-pager-transforms-1.2.32" level="project" />
|
||||||
<orderEntry type="module" module-name="taskerlocaleapi" exported="" />
|
<orderEntry type="module" module-name="taskerlocaleapi" exported="" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -7,11 +7,11 @@ import android.content.SharedPreferences;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
@ -54,6 +54,10 @@ public class ArticleFragment extends Fragment {
|
|||||||
protected View m_contentView;
|
protected View m_contentView;
|
||||||
protected FSVideoChromeClient m_chromeClient;
|
protected FSVideoChromeClient m_chromeClient;
|
||||||
protected View m_fab;
|
protected View m_fab;
|
||||||
|
protected int m_articleFontSize;
|
||||||
|
protected int m_articleSmallFontSize;
|
||||||
|
protected boolean m_acceleratedWebview = true;
|
||||||
|
private boolean m_isVisible;
|
||||||
|
|
||||||
public void initialize(Article article) {
|
public void initialize(Article article) {
|
||||||
m_article = article;
|
m_article = article;
|
||||||
@ -150,6 +154,15 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||||
|
super.setUserVisibleHint(isVisibleToUser);
|
||||||
|
|
||||||
|
m_isVisible = isVisibleToUser;
|
||||||
|
|
||||||
|
renderContent(null);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
|
||||||
@ -214,14 +227,14 @@ public class ArticleFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int articleFontSize = Integer.parseInt(m_prefs.getString("article_font_size_sp", "16"));
|
m_articleFontSize = Integer.parseInt(m_prefs.getString("article_font_size_sp", "16"));
|
||||||
final int articleSmallFontSize = Math.max(10, Math.min(18, articleFontSize - 2));
|
m_articleSmallFontSize = Math.max(10, Math.min(18, m_articleFontSize - 2));
|
||||||
|
|
||||||
TextView title = (TextView)view.findViewById(R.id.title);
|
TextView title = (TextView)view.findViewById(R.id.title);
|
||||||
|
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
|
|
||||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, m_articleFontSize + 3));
|
||||||
|
|
||||||
String titleStr;
|
String titleStr;
|
||||||
|
|
||||||
@ -266,7 +279,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
if (comments != null) {
|
if (comments != null) {
|
||||||
if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) {
|
if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) {
|
||||||
comments.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize);
|
comments.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize);
|
||||||
|
|
||||||
String commentsTitle = getResources().getQuantityString(R.plurals.article_comments, m_article.comments_count, m_article.comments_count);
|
String commentsTitle = getResources().getQuantityString(R.plurals.article_comments, m_article.comments_count, m_article.comments_count);
|
||||||
comments.setText(commentsTitle);
|
comments.setText(commentsTitle);
|
||||||
@ -298,7 +311,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
if (m_article.note != null && !"".equals(m_article.note)) {
|
if (m_article.note != null && !"".equals(m_article.note)) {
|
||||||
note.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize);
|
note.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize);
|
||||||
note.setText(m_article.note);
|
note.setText(m_article.note);
|
||||||
} else {
|
} else {
|
||||||
note.setVisibility(View.GONE);
|
note.setVisibility(View.GONE);
|
||||||
@ -311,7 +324,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
TextView dv = (TextView)view.findViewById(R.id.date);
|
TextView dv = (TextView)view.findViewById(R.id.date);
|
||||||
|
|
||||||
if (dv != null) {
|
if (dv != null) {
|
||||||
dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize);
|
dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize);
|
||||||
|
|
||||||
Date d = new Date(m_article.updated * 1000L);
|
Date d = new Date(m_article.updated * 1000L);
|
||||||
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
DateFormat df = new SimpleDateFormat("MMM dd, HH:mm");
|
||||||
@ -323,7 +336,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
boolean hasAuthor = false;
|
boolean hasAuthor = false;
|
||||||
|
|
||||||
if (author != null) {
|
if (author != null) {
|
||||||
author.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize);
|
author.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize);
|
||||||
|
|
||||||
if (m_article.author != null && m_article.author.length() > 0) {
|
if (m_article.author != null && m_article.author.length() > 0) {
|
||||||
author.setText(getString(R.string.author_formatted, m_article.author));
|
author.setText(getString(R.string.author_formatted, m_article.author));
|
||||||
@ -336,7 +349,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
TextView tagv = (TextView)view.findViewById(R.id.tags);
|
TextView tagv = (TextView)view.findViewById(R.id.tags);
|
||||||
|
|
||||||
if (tagv != null) {
|
if (tagv != null) {
|
||||||
tagv.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize);
|
tagv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize);
|
||||||
|
|
||||||
if (m_article.feed_title != null) {
|
if (m_article.feed_title != null) {
|
||||||
String fTitle = m_article.feed_title;
|
String fTitle = m_article.feed_title;
|
||||||
@ -376,17 +389,25 @@ public class ArticleFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean acceleratedWebview = true;
|
|
||||||
|
|
||||||
// prevent flicker in ics
|
// prevent flicker in ics
|
||||||
if (!m_prefs.getBoolean("webview_hardware_accel", true)) {
|
if (!m_prefs.getBoolean("webview_hardware_accel", true)) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||||
m_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
m_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
acceleratedWebview = false;
|
m_acceleratedWebview = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String cssOverride = "";
|
m_web.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
if (savedInstanceState != null || m_isVisible) renderContent(savedInstanceState);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void renderContent(Bundle savedInstanceState) {
|
||||||
|
if (!isAdded()) return;
|
||||||
|
|
||||||
|
Log.d(TAG, "renderContent: " + m_article.title);
|
||||||
|
|
||||||
WebSettings ws = m_web.getSettings();
|
WebSettings ws = m_web.getSettings();
|
||||||
ws.setSupportZoom(false);
|
ws.setSupportZoom(false);
|
||||||
@ -396,6 +417,8 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
String backgroundHexColor = String.format("#%06X", (0xFFFFFF & tvBackground.data));
|
String backgroundHexColor = String.format("#%06X", (0xFFFFFF & tvBackground.data));
|
||||||
|
|
||||||
|
String cssOverride = "";
|
||||||
|
|
||||||
cssOverride = "body { background : "+ backgroundHexColor+"; }";
|
cssOverride = "body { background : "+ backgroundHexColor+"; }";
|
||||||
|
|
||||||
TypedValue tvTextColor = new TypedValue();
|
TypedValue tvTextColor = new TypedValue();
|
||||||
@ -416,7 +439,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
ws.setJavaScriptEnabled(true);
|
ws.setJavaScriptEnabled(true);
|
||||||
|
|
||||||
m_chromeClient = new FSVideoChromeClient(view);
|
m_chromeClient = new FSVideoChromeClient(getView());
|
||||||
m_web.setWebChromeClient(m_chromeClient);
|
m_web.setWebChromeClient(m_chromeClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +447,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
cssOverride += "body { text-align : justify; } ";
|
cssOverride += "body { text-align : justify; } ";
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.setDefaultFontSize(articleFontSize);
|
ws.setDefaultFontSize(m_articleFontSize);
|
||||||
|
|
||||||
StringBuilder content = new StringBuilder("<html>" +
|
StringBuilder content = new StringBuilder("<html>" +
|
||||||
"<head>" +
|
"<head>" +
|
||||||
@ -478,7 +501,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedInstanceState == null || !acceleratedWebview) {
|
if (savedInstanceState == null || !m_acceleratedWebview) {
|
||||||
m_web.loadDataWithBaseURL(baseUrl, content.toString(), "text/html", "utf-8", null);
|
m_web.loadDataWithBaseURL(baseUrl, content.toString(), "text/html", "utf-8", null);
|
||||||
} else {
|
} else {
|
||||||
WebBackForwardList rc = m_web.restoreState(savedInstanceState);
|
WebBackForwardList rc = m_web.restoreState(savedInstanceState);
|
||||||
@ -493,9 +516,6 @@ public class ArticleFragment extends Fragment {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_web.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -186,18 +186,6 @@ public class OfflineArticleFragment extends Fragment {
|
|||||||
|
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
|
|
||||||
/* if (m_prefs.getBoolean("enable_condensed_fonts", false)) {
|
|
||||||
Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", Typeface.NORMAL);
|
|
||||||
|
|
||||||
if (tf != null && !tf.equals(title.getTypeface())) {
|
|
||||||
title.setTypeface(tf);
|
|
||||||
}
|
|
||||||
|
|
||||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 5));
|
|
||||||
} else {
|
|
||||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
|
||||||
} */
|
|
||||||
|
|
||||||
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));
|
||||||
|
|
||||||
String titleStr;
|
String titleStr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user