do no ttry setting web software rendering before api 11

reimplement titlewebview as an alternative rendering option
bump version
This commit is contained in:
Andrew Dolgov 2013-10-19 10:13:51 +04:00
parent 0a7c9640d7
commit b8ee3dab39
7 changed files with 224 additions and 11 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
android:versionCode="211"
android:versionName="1.16b8" >
android:versionCode="212"
android:versionName="1.16b9" >
<uses-sdk
android:minSdkVersion="8"

View File

@ -0,0 +1,97 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/article_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?articleBackground"
android:orientation="vertical"
android:padding="5sp" >
<org.fox.ttrss.util.TitleWebView
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/article_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="vertical"
android:paddingBottom="2dp" >
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="4dp"
android:text="My simple headline"
android:textColor="?linkColor"
android:textSize="18sp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="right"
android:singleLine="true"
android:text="by Author"
android:textColor="?headlineSecondaryTextColor"
android:textSize="12sp" />
<TextView
android:id="@+id/comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="24 comments"
android:textColor="?linkColor"
android:textSize="12sp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="0"
android:background="?ttrssHorizontalDivider"
android:paddingTop="2dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="4dp"
android:layout_weight="1" >
<TextView
android:id="@+id/tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ellipsize="end"
android:singleLine="true"
android:text="Example Feed"
android:textColor="?headlineSecondaryTextColor"
android:textSize="12sp" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="right"
android:text="Jan 01, 12:00"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?headlineSecondaryTextColor"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</org.fox.ttrss.util.TitleWebView>
</LinearLayout>

View File

@ -209,4 +209,6 @@
<string name="download_articles_and_go_offline">Download articles and go offline</string>
<string name="tasker_save_and_close">Save and close</string>
<string name="synchronize_read_articles_and_go_online">Synchronize read articles and go online</string>
<string name="prefs_compatible_article_layout">Compatible article layout</string>
<string name="prefs_compatible_layout_summary">Enable if you see glitches in article content</string>
</resources>

View File

@ -161,6 +161,11 @@
android:title="@string/offline_oldest_first" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/debugging" >
<CheckBoxPreference
android:defaultValue="false"
android:key="article_compat_view"
android:title="@string/prefs_compatible_article_layout"
android:summary="@string/prefs_compatible_layout_summary" />
<CheckBoxPreference
android:defaultValue="true"
android:key="webview_hardware_accel"

View File

@ -48,7 +48,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
private Article m_article;
private OnlineActivity m_activity;
private GestureDetector m_detector;
public void initialize(Article article) {
m_article = article;
}
@ -92,7 +92,9 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
m_article = savedInstanceState.getParcelable("article");
}
View view = inflater.inflate(R.layout.article_fragment, container, false);
boolean useTitleWebView = m_prefs.getBoolean("article_compat_view", false);
View view = inflater.inflate(useTitleWebView ? R.layout.article_fragment_compat : R.layout.article_fragment, container, false);
if (m_article != null) {
@ -165,8 +167,10 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
registerForContextMenu(web);
// prevent flicker in ics
if (!m_prefs.getBoolean("webview_hardware_accel", true)) {
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
if (!m_prefs.getBoolean("webview_hardware_accel", true) || useTitleWebView) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
web.setWebChromeClient(new WebChromeClient() {
@ -259,6 +263,10 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
"</head>" +
"<body>" + articleContent;
if (useTitleWebView) {
content += "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
}
if (m_article.attachments != null && m_article.attachments.size() != 0) {
String flatContent = articleContent.replaceAll("[\r\n]", "");
boolean hasImages = flatContent.matches(".*?<img[^>+].*?");

View File

@ -123,7 +123,9 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
m_articleId = savedInstanceState.getInt("articleId");
}
View view = inflater.inflate(R.layout.article_fragment, container, false);
boolean useTitleWebView = m_prefs.getBoolean("article_compat_view", false);
View view = inflater.inflate(useTitleWebView ? R.layout.article_fragment_compat : R.layout.article_fragment, container, false);
m_cursor = m_activity.getReadableDb().query("articles LEFT JOIN feeds ON (feed_id = feeds."+BaseColumns._ID+")",
new String[] { "articles.*", "feeds.title AS feed_title" }, "articles." + BaseColumns._ID + "=?",
@ -212,8 +214,10 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true);
// prevent flicker in ics
if (!m_prefs.getBoolean("webview_hardware_accel", true)) {
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
if (!m_prefs.getBoolean("webview_hardware_accel", true) || useTitleWebView) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
String theme = m_prefs.getString("theme", "THEME_DARK");
@ -282,8 +286,14 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
cssOverride +
"</style>" +
"</head>" +
"<body>" + articleContent + "</body></html>";
"<body>" + articleContent;
if (useTitleWebView) {
content += "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
}
content += "</body></html>";
try {
String baseUrl = null;

View File

@ -0,0 +1,91 @@
package org.fox.ttrss.util;
// http://www.techques.com/question/1-9718245/Webview-in-Scrollview
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
public class TitleWebView extends WebView{
public TitleWebView(Context context, AttributeSet attrs){
super(context, attrs);
}
private int titleHeight;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// determine height of title bar
View title = getChildAt(0);
titleHeight = title==null ? 0 : title.getMeasuredHeight();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
return true; // don't pass our touch events to children (title bar), we send these in dispatchTouchEvent
}
private boolean touchInTitleBar;
@Override
public boolean dispatchTouchEvent(MotionEvent me){
boolean wasInTitle = false;
switch(me.getActionMasked()){
case MotionEvent.ACTION_DOWN:
touchInTitleBar = (me.getY() <= visibleTitleHeight());
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
wasInTitle = touchInTitleBar;
touchInTitleBar = false;
break;
}
if(touchInTitleBar || wasInTitle) {
View title = getChildAt(0);
if(title!=null) {
// this touch belongs to title bar, dispatch it here
me.offsetLocation(0, getScrollY());
return title.dispatchTouchEvent(me);
}
}
// this is our touch, offset and process
me.offsetLocation(0, -titleHeight);
return super.dispatchTouchEvent(me);
}
/**
* @return visible height of title (may return negative values)
*/
private int visibleTitleHeight(){
return titleHeight-getScrollY();
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt){
super.onScrollChanged(l, t, oldl, oldt);
View title = getChildAt(0);
if(title!=null) // undo horizontal scroll, so that title scrolls only vertically
title.offsetLeftAndRight(l - title.getLeft());
}
@Override
protected void onDraw(Canvas c){
c.save();
int tH = visibleTitleHeight();
if(tH>0) {
// clip so that it doesn't clear background under title bar
int sx = getScrollX(), sy = getScrollY();
c.clipRect(sx, sy+tH, sx+getWidth(), sy+getHeight());
}
c.translate(0, titleHeight);
super.onDraw(c);
c.restore();
}
}