add experimental hiding actionbar on scroll

This commit is contained in:
Andrew Dolgov 2015-05-11 01:34:24 +04:00
parent 026dc85826
commit 42a4fd5d39
7 changed files with 79 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@ -24,12 +25,14 @@ import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebView.HitTestResult;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.shamanland.fab.ShowHideOnScroll;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.Attachment;
import org.fox.ttrss.util.NotifyingScrollView;
import java.net.MalformedURLException;
import java.net.URI;
@ -165,9 +168,24 @@ public class ArticleFragment extends Fragment {
m_contentView = view.findViewById(R.id.article_scrollview);
m_customViewContainer = (FrameLayout) view.findViewById(R.id.article_fullscreen_video);
View scrollView = view.findViewById(R.id.article_scrollview);
NotifyingScrollView scrollView = (NotifyingScrollView) view.findViewById(R.id.article_scrollview);
m_fab = view.findViewById(R.id.article_fab);
if (scrollView != null && m_activity.isSmallScreen()) {
view.findViewById(R.id.article_heading_spacer).setVisibility(View.VISIBLE);
scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() {
@Override
public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {
if (t > 0 && t > oldt) {
m_activity.getSupportActionBar().hide();
} else {
m_activity.getSupportActionBar().show();
}
}
});
}
if (scrollView != null && m_fab != null) {
if (m_prefs.getBoolean("enable_article_fab", true)) {
scrollView.setOnTouchListener(new ShowHideOnScroll(m_fab));

View File

@ -9,9 +9,11 @@ import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.WindowCompat;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList;
@ -223,6 +225,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
saveArticleUnread(article);
}
if (!getSupportActionBar().isShowing()) getSupportActionBar().show();
if (open) {
final Article fArticle = article;

View File

@ -6,7 +6,7 @@ import android.view.View;
import android.webkit.WebView;
import android.widget.ScrollView;
public class NoChildFocusScrollView extends ScrollView {
public class NoChildFocusScrollView extends NotifyingScrollView {
public NoChildFocusScrollView(Context context) {
super(context);

View File

@ -0,0 +1,45 @@
package org.fox.ttrss.util;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
/**
* @author Cyril Mottier
*/
public class NotifyingScrollView extends ScrollView {
/**
* @author Cyril Mottier
*/
public interface OnScrollChangedListener {
void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);
}
private OnScrollChangedListener mOnScrollChangedListener;
public NotifyingScrollView(Context context) {
super(context);
}
public NotifyingScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
public void setOnScrollChangedListener(OnScrollChangedListener listener) {
mOnScrollChangedListener = listener;
}
}

View File

@ -22,6 +22,14 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- hack for hiding actionbar on small devices -->
<FrameLayout
android:id="@+id/article_heading_spacer"
android:visibility="gone"
android:layout_marginTop="?android:attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:padding="16dp"
android:id="@+id/article_header"

View File

@ -1,6 +1,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/headlines"
android:fitsSystemWindows="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

View File

@ -81,6 +81,8 @@
</style>
<style name="DarkTheme" parent="Theme.AppCompat">
<item name="windowActionBarOverlay">true</item>
<item name="statusBarHintColor">?colorPrimary</item>
<item name="unreadCounterColor">#909090</item>
<item name="feedlistTextColor">@android:color/primary_text_dark</item>