From cb18030f6b4aec8cd88aff333d7fbeea7572a347 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 16 Oct 2013 19:53:32 +0400 Subject: Revert "use scrollview/webview instead of titlewebview hack" This reverts commit 780629fff539128065970011931b141b1eb723ed. Conflicts: res/layout/article_fragment.xml src/org/fox/ttrss/ArticleFragment.java src/org/fox/ttrss/offline/OfflineArticleFragment.java --- res/layout/article_fragment.xml | 202 ++++++++++----------- res/xml/preferences.xml | 4 +- src/org/fox/ttrss/ArticleFragment.java | 7 +- src/org/fox/ttrss/TitleWebView.java | 91 ++++++++++ .../fox/ttrss/offline/OfflineArticleFragment.java | 4 +- src/org/fox/ttrss/util/NoChildFocusScrollView.java | 34 ---- 6 files changed, 195 insertions(+), 147 deletions(-) create mode 100644 src/org/fox/ttrss/TitleWebView.java delete mode 100644 src/org/fox/ttrss/util/NoChildFocusScrollView.java diff --git a/res/layout/article_fragment.xml b/res/layout/article_fragment.xml index 5caab8ae..60683838 100644 --- a/res/layout/article_fragment.xml +++ b/res/layout/article_fragment.xml @@ -1,105 +1,97 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 7f247d92..4290a519 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -161,11 +161,11 @@ android:title="@string/offline_oldest_first" /> - + android:title="@string/accel_webview_title" /> --> = 11) { web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } @@ -281,7 +280,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl } } - content += ""; + content += "

 

 

 

 

"; try { String baseUrl = null; diff --git a/src/org/fox/ttrss/TitleWebView.java b/src/org/fox/ttrss/TitleWebView.java new file mode 100644 index 00000000..d55f2e35 --- /dev/null +++ b/src/org/fox/ttrss/TitleWebView.java @@ -0,0 +1,91 @@ +package org.fox.ttrss; + +// 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(); + } + } \ No newline at end of file diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index b8f60bd7..dabf84b0 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -211,7 +211,7 @@ 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)) { + if (android.os.Build.VERSION.SDK_INT >= 11) { web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } @@ -280,7 +280,7 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. cssOverride + "" + "" + - "" + articleContent + ""; + "" + articleContent + "

 

 

 

 

"; try { String baseUrl = null; diff --git a/src/org/fox/ttrss/util/NoChildFocusScrollView.java b/src/org/fox/ttrss/util/NoChildFocusScrollView.java deleted file mode 100644 index 3dea82a4..00000000 --- a/src/org/fox/ttrss/util/NoChildFocusScrollView.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.fox.ttrss.util; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; -import android.webkit.WebView; -import android.widget.ScrollView; - -public class NoChildFocusScrollView extends ScrollView { - - public NoChildFocusScrollView(Context context) { - super(context); - // TODO Auto-generated constructor stub - } - - - public NoChildFocusScrollView(Context context, AttributeSet attrs) { - super(context, attrs); - // TODO Auto-generated constructor stub - } - - public NoChildFocusScrollView(Context context, AttributeSet attrs, - int defStyle) { - super(context, attrs, defStyle); - // TODO Auto-generated constructor stub - } - - @Override - public void requestChildFocus(View child, View focused) { - if (focused instanceof WebView ) - return; - super.requestChildFocus(child, focused); - } -} -- cgit v1.2.3