Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: added autohiding statusbar with scrollView.SetOnScrollChangeListener() #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/assets/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ h2:after {
========================================================================== */

#content {
margin-top: 1em;
margin-top: 100px;
min-height: 30em;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ h2:after {
========================================================================== */

#content {
margin-top: 1em;
margin-top: 100px;
min-height: 30em;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/assets/solarized.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ h2:after {
========================================================================== */

#content {
margin-top: 1em;
margin-top: 100px;
min-height: 30em;
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ public boolean isFullscreenArticleView() {
return getBoolean(R.string.pref_key_ui_article_fullscreen, false);
}

public boolean isAutoFullscreenArticleView() {
return getBoolean(R.string.pref_key_ui_article_fullscreen_auto, true);
}

public void setFullScreenArticleView(boolean value) {
setBoolean(R.string.pref_key_ui_article_fullscreen, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v7.widget.Toolbar;

import com.di72nn.stuff.wallabag.apiwrapper.WallabagService;

Expand Down Expand Up @@ -144,6 +145,9 @@ public class ReadArticleActivity extends BaseActionBarActivity {
private boolean onPageFinishedCallPostponedUntilResume;
private boolean loadingFinished;

private boolean isFullscreen;
private View decorView;

public void onCreate(Bundle savedInstanceState) {

settings = App.getInstance().getSettings();
Expand All @@ -153,7 +157,7 @@ public void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
);
ActionBar actionBar = super.getSupportActionBar();
if(actionBar != null) actionBar.hide();
}
Expand Down Expand Up @@ -199,7 +203,35 @@ public void onCreate(Bundle savedInstanceState) {
// article is loaded - update menu
invalidateOptionsMenu();

// Grab the action bar and decorView for making reading view fullscreen
decorView = getWindow().getDecorView();
isFullscreen = false;

// Toggle stable and fullscreen layout flags so everything is overlaid by the
// actionbar AND the status bar when article is opened
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);


scrollView = (ScrollView)findViewById(R.id.scroll);

// // Hide status and action bar when scrolling down, show when scrolling up
// // TODO: change to a method compatible with API 14.
if (Build.VERSION.SDK_INT >= 23 && settings.isAutoFullscreenArticleView()) {
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener(){
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (oldScrollY - scrollY > 5 && isFullscreen){
isFullscreen = goFullscreen(false);
} else if (oldScrollY - scrollY < -5 && !isFullscreen) {
isFullscreen = goFullscreen(true);
}
}
});
}

scrollViewLastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
webViewContent = (WebView)findViewById(R.id.webViewContent);
loadingPlaceholder = (TextView)findViewById(R.id.tv_loading_article);
Expand Down Expand Up @@ -481,6 +513,24 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) {
}
}

private boolean goFullscreen(boolean gofs) {
// Hide both status bar and action bar if true else, show them
if(gofs){
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
return true;
} else {
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
return false;
}
}

private void showDisableTouchToast() {
Toast.makeText(this, disableTouch
? R.string.message_disableTouch_inputDisabled
Expand Down Expand Up @@ -598,22 +648,28 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve

@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if(!tapToScroll) return false;

if(e.getPointerCount() > 1) return false;

int viewHeight = scrollView.getHeight();
float y = e.getY() - scrollView.getScrollY();
float x = e.getX();
int viewWidth = scrollView.getWidth();

if(y > viewHeight * 0.25 && y < viewHeight * 0.75) {
int viewWidth = scrollView.getWidth();
float x = e.getX();
if(tapToScroll) {
int viewHeight = scrollView.getHeight();
float y = e.getY() - scrollView.getScrollY();
if (y > viewHeight * 0.25 && y < viewHeight * 0.75) {

if(x < viewWidth * 0.3) { // left part
scroll(true, screenScrollingPercent, smoothScrolling, false);
} else if(x > viewWidth * 0.7) { // right part
scroll(false, screenScrollingPercent, smoothScrolling, false);
if (x < viewWidth * 0.3) { // left part
scroll(true, screenScrollingPercent, smoothScrolling, false);
} else if (x > viewWidth * 0.7) { // right part
scroll(false, screenScrollingPercent, smoothScrolling, false);
}
}
// TODO: Maybe enable this with option in settings menu?
// Toggle fullscreen if touching center of screen
}

if(x > viewWidth * 0.3 && x < viewWidth * 0.7){
isFullscreen = goFullscreen(!isFullscreen);
}

return false;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings-preference-keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<string name="pref_key_ui_screenScrolling_smooth" translatable="false">ui.screenScrolling.smooth</string>
<string name="pref_key_ui_misc_category" translatable="false">ui.misc.category</string>
<string name="pref_key_ui_article_fullscreen" translatable="false">ui.article.fullscreen</string>
<string name="pref_key_ui_article_fullscreen_auto" translatable="false">ui.article.fullscreen_auto</string>
<string name="pref_key_ui_disableTouch_enabled" translatable="false">ui.disableTouch.enabled</string>
<string name="pref_key_ui_disableTouch_lastState" translatable="false">ui.disableTouch.lastState</string>
<string name="pref_key_ui_disableTouch_keyCode" translatable="false">ui.disableTouch.keyCode</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
<string name="pref_desc_ui_article_textAlignment_justify">Stretches lines to equal width (like in newspapers)</string>
<string name="pref_name_ui_article_fullscreen">Fullscreen Article View</string>
<string name="pref_desc_ui_article_fullscreen">Hides system and app bars when reading articles</string>
<string name="pref_name_ui_article_fullscreen_auto">Fullscreen Article View on Scroll</string>
<string name="pref_desc_ui_article_fullscreen_auto">Hides/Shows system and app bars automatically scroll. Only works on Android 6.0 and above.</string>
<string name="pref_name_ui_readingSpeed">Reading speed</string>
<string name="pref_desc_ui_readingSpeed">Your reading speed (measured in words per minute). Used to calculate estimated reading time.</string>
<string name="pref_name_ui_keepScreenOn">Keep screen on while reading</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
android:title="@string/pref_name_ui_article_fullscreen"
android:summary="@string/pref_desc_ui_article_fullscreen"
android:defaultValue="false"/>
<CheckBoxPreference
android:key="@string/pref_key_ui_article_fullscreen_auto"
android:title="@string/pref_name_ui_article_fullscreen_auto"
android:summary="@string/pref_desc_ui_article_fullscreen_auto"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="@string/pref_key_ui_disableTouch_enabled"
android:title="@string/pref_name_ui_disableTouch_enabled"
Expand Down