use scrollview/webview instead of titlewebview hack
This commit is contained in:
parent
75cee54972
commit
780629fff5
@ -1,97 +1,105 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/article_fragment"
|
android:id="@+id/article_fragment"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:background="?articleBackground"
|
android:background="?articleBackground"
|
||||||
android:orientation="vertical"
|
android:padding="5sp" >
|
||||||
android:padding="5sp" >
|
|
||||||
|
<org.fox.ttrss.util.NoChildFocusScrollView
|
||||||
<org.fox.ttrss.TitleWebView
|
android:id="@+id/scrollView1"
|
||||||
android:id="@+id/content"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:fillViewport="false" >
|
||||||
android:layout_weight="1">
|
|
||||||
|
<LinearLayout
|
||||||
<LinearLayout
|
android:layout_width="match_parent"
|
||||||
android:id="@+id/article_header"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:orientation="vertical" >
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="0"
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:id="@+id/article_header"
|
||||||
android:paddingBottom="2dp" >
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
<TextView
|
android:orientation="vertical"
|
||||||
android:id="@+id/title"
|
android:paddingBottom="2dp" >
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_weight="1"
|
android:id="@+id/title"
|
||||||
android:paddingBottom="4dp"
|
android:layout_width="match_parent"
|
||||||
android:text="My simple headline"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="?linkColor"
|
android:layout_weight="1"
|
||||||
android:textSize="18sp" />
|
android:paddingBottom="4dp"
|
||||||
|
android:text="My simple headline"
|
||||||
<TextView
|
android:textColor="?linkColor"
|
||||||
android:id="@+id/author"
|
android:textSize="18sp" />
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_weight="1"
|
android:id="@+id/author"
|
||||||
android:ellipsize="end"
|
android:layout_width="match_parent"
|
||||||
android:gravity="right"
|
android:layout_height="wrap_content"
|
||||||
android:singleLine="true"
|
android:layout_weight="1"
|
||||||
android:text="by Author"
|
android:ellipsize="end"
|
||||||
android:textColor="?headlineSecondaryTextColor"
|
android:gravity="right"
|
||||||
android:textSize="14sp" />
|
android:singleLine="true"
|
||||||
|
android:text="by Author"
|
||||||
<TextView
|
android:textColor="?headlineSecondaryTextColor"
|
||||||
android:id="@+id/comments"
|
android:textSize="14sp" />
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_weight="1"
|
android:id="@+id/comments"
|
||||||
android:gravity="right"
|
android:layout_width="match_parent"
|
||||||
android:text="24 comments"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="?linkColor"
|
android:layout_weight="1"
|
||||||
android:textSize="12sp" />
|
android:gravity="right"
|
||||||
|
android:text="24 comments"
|
||||||
<ImageView
|
android:textColor="?linkColor"
|
||||||
android:layout_width="match_parent"
|
android:textSize="12sp" />
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="4dp"
|
<ImageView
|
||||||
android:layout_marginTop="4dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_weight="0"
|
android:layout_height="wrap_content"
|
||||||
android:background="?ttrssHorizontalDivider"
|
android:layout_marginBottom="4dp"
|
||||||
android:paddingTop="2dip" />
|
android:layout_marginTop="4dp"
|
||||||
|
android:layout_weight="0"
|
||||||
<LinearLayout
|
android:background="?ttrssHorizontalDivider"
|
||||||
android:layout_width="match_parent"
|
android:paddingTop="2dip" />
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingBottom="4dp"
|
<LinearLayout
|
||||||
android:layout_weight="1" >
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
<TextView
|
android:layout_weight="1"
|
||||||
android:id="@+id/tags"
|
android:paddingBottom="4dp" >
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_weight="0.5"
|
android:id="@+id/tags"
|
||||||
android:ellipsize="end"
|
android:layout_width="wrap_content"
|
||||||
android:singleLine="true"
|
android:layout_height="wrap_content"
|
||||||
android:text="Example Feed"
|
android:layout_weight="0.5"
|
||||||
android:textColor="?headlineSecondaryTextColor"
|
android:ellipsize="end"
|
||||||
android:textSize="12sp" />
|
android:singleLine="true"
|
||||||
|
android:text="Example Feed"
|
||||||
<TextView
|
android:textColor="?headlineSecondaryTextColor"
|
||||||
android:id="@+id/date"
|
android:textSize="12sp" />
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
<TextView
|
||||||
android:layout_weight="0.5"
|
android:id="@+id/date"
|
||||||
android:gravity="right"
|
android:layout_width="wrap_content"
|
||||||
android:text="Jan 01, 12:00"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:layout_weight="0.5"
|
||||||
android:textColor="?headlineSecondaryTextColor"
|
android:gravity="right"
|
||||||
android:textSize="12sp" />
|
android:text="Jan 01, 12:00"
|
||||||
</LinearLayout>
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
</LinearLayout>
|
android:textColor="?headlineSecondaryTextColor"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
</org.fox.ttrss.TitleWebView>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
<WebView
|
||||||
|
android:id="@+id/content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
|
</org.fox.ttrss.util.NoChildFocusScrollView>
|
||||||
|
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -23,6 +23,7 @@ import android.os.Bundle;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
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;
|
||||||
@ -161,9 +162,9 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
|
|
||||||
if (web != null) {
|
if (web != null) {
|
||||||
registerForContextMenu(web);
|
registerForContextMenu(web);
|
||||||
|
|
||||||
// prevent flicker in ics
|
// prevent flicker in ics
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
if (android.os.Build.VERSION.SDK_INT >= 11 && android.os.Build.VERSION.SDK_INT < 14) {
|
||||||
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +281,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content += "<p> </p><p> </p><p> </p><p> </p></body></html>";
|
content += "</body></html>";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String baseUrl = null;
|
String baseUrl = null;
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -211,7 +211,7 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
|
|||||||
getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true);
|
getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true);
|
||||||
|
|
||||||
// prevent flicker in ics
|
// prevent flicker in ics
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
if (android.os.Build.VERSION.SDK_INT >= 11 && android.os.Build.VERSION.SDK_INT < 14) {
|
||||||
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector.
|
|||||||
cssOverride +
|
cssOverride +
|
||||||
"</style>" +
|
"</style>" +
|
||||||
"</head>" +
|
"</head>" +
|
||||||
"<body>" + articleContent + "<p> </p><p> </p><p> </p><p> </p></body></html>";
|
"<body>" + articleContent + "</body></html>";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String baseUrl = null;
|
String baseUrl = null;
|
||||||
|
34
src/org/fox/ttrss/util/NoChildFocusScrollView.java
Normal file
34
src/org/fox/ttrss/util/NoChildFocusScrollView.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user