From ac96ae00d3fa887a7bb1ad0b67821cadd60fe887 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 19 Nov 2013 20:07:17 +0400 Subject: [PATCH] add workaround for webview not working correctly inside viewpager or w/e (the no rect test based nodes found issue) thanks, google engineers, amazing work --- res/layout/article_fragment.xml | 2 +- src/org/fox/ttrss/ArticleFragment.java | 70 +------------------ .../ttrss/offline/OfflineArticleFragment.java | 68 +----------------- src/org/fox/ttrss/util/LessBrokenWebView.java | 37 ++++++++++ 4 files changed, 41 insertions(+), 136 deletions(-) create mode 100644 src/org/fox/ttrss/util/LessBrokenWebView.java diff --git a/res/layout/article_fragment.xml b/res/layout/article_fragment.xml index 5caab8ae..8ea27c55 100644 --- a/res/layout/article_fragment.xml +++ b/res/layout/article_fragment.xml @@ -94,7 +94,7 @@ - diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 73312c48..d2b94b98 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -41,13 +41,12 @@ import android.webkit.WebView; import android.webkit.WebView.HitTestResult; import android.widget.TextView; -public class ArticleFragment extends Fragment implements GestureDetector.OnDoubleTapListener { +public class ArticleFragment extends Fragment { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; private Article m_article; private OnlineActivity m_activity; - private GestureDetector m_detector; public void initialize(Article article) { m_article = article; @@ -173,7 +172,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl } } - web.setWebChromeClient(new WebChromeClient() { + web.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { m_activity.setProgress(Math.round(((float)progress / 100f) * 10000)); @@ -183,13 +182,6 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl } }); - web.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - return m_detector.onTouchEvent(event); - } - }); - String content; String cssOverride = ""; @@ -385,63 +377,5 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl m_activity = (OnlineActivity)activity; //m_article = m_onlineServices.getSelectedArticle(); - m_detector = new GestureDetector(m_activity, new GestureDetector.OnGestureListener() { - @Override - public boolean onSingleTapUp(MotionEvent e) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, - float distanceY) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - m_activity.openContextMenu(getView()); - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, - float velocityY) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onDown(MotionEvent e) { - // TODO Auto-generated method stub - return false; - } - }); - - m_detector.setOnDoubleTapListener(this); - } - - @Override - public boolean onDoubleTap(MotionEvent arg0) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onDoubleTapEvent(MotionEvent arg0) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onSingleTapConfirmed(MotionEvent arg0) { - // TODO Auto-generated method stub - return false; } } diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index f3d6f5d9..248827cd 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -43,7 +43,7 @@ import android.webkit.WebView; import android.webkit.WebView.HitTestResult; import android.widget.TextView; -public class OfflineArticleFragment extends Fragment implements GestureDetector.OnDoubleTapListener { +public class OfflineArticleFragment extends Fragment { private final String TAG = this.getClass().getSimpleName(); private SharedPreferences m_prefs; @@ -51,7 +51,6 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. private boolean m_isCat = false; // FIXME use private Cursor m_cursor; private OfflineActivity m_activity; - private GestureDetector m_detector; public void initialize(int articleId) { m_articleId = articleId; @@ -191,13 +190,6 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. } }); - web.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - return m_detector.onTouchEvent(event); - } - }); - String content; String cssOverride = ""; @@ -379,63 +371,5 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. m_activity = (OfflineActivity) activity; - m_detector = new GestureDetector(m_activity, new GestureDetector.OnGestureListener() { - @Override - public boolean onSingleTapUp(MotionEvent e) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, - float distanceY) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void onLongPress(MotionEvent e) { - m_activity.openContextMenu(getView()); - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, - float velocityY) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onDown(MotionEvent e) { - // TODO Auto-generated method stub - return false; - } - }); - - m_detector.setOnDoubleTapListener(this); - } - - @Override - public boolean onDoubleTap(MotionEvent arg0) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onDoubleTapEvent(MotionEvent arg0) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - // TODO Auto-generated method stub - return false; } } diff --git a/src/org/fox/ttrss/util/LessBrokenWebView.java b/src/org/fox/ttrss/util/LessBrokenWebView.java new file mode 100644 index 00000000..c6cab513 --- /dev/null +++ b/src/org/fox/ttrss/util/LessBrokenWebView.java @@ -0,0 +1,37 @@ +package org.fox.ttrss.util; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.webkit.WebView; + +public class LessBrokenWebView extends WebView { + + public LessBrokenWebView(Context context) { + super(context); + // TODO Auto-generated constructor stub + } + + public LessBrokenWebView(Context context, AttributeSet attrs) { + super(context, attrs); + // TODO Auto-generated constructor stub + } + + public LessBrokenWebView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + // TODO Auto-generated constructor stub + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + + if (event.getAction() == MotionEvent.ACTION_DOWN) { + int temp_ScrollY = getScrollY(); + scrollTo(getScrollX(), getScrollY() + 1); + scrollTo(getScrollX(), temp_ScrollY); + } + + return super.onTouchEvent(event); + } + +}