Skip to content

Commit

Permalink
added autohiding statusbar with scrollView.SetOnScrollChangeListener()
Browse files Browse the repository at this point in the history
added goFullscreen method to more easily toggle fullscreen on and off, made both status bar and action bar hide/show on scroll and if tapping center of screen

added layout_marginTop above the paddingTop to give 2x actionbar padding from top edge so that title does not get hidden behind status bar + action bar. Added fullscreen layout flags to onCreate of the article class so that view does not shift up when full screen is toggled

wrapped autohide actionbar on-scroll functionality in an if statement so it only works if API level is >= 23, otherwise it won't autohide. Implemented fullscreen on tap if the central 40% of screen is tapped.

adjusted tolerance of autohide to make it feel more snappy

removed unneccesary <item> tag for action bar overlay

removed padding from article.xml and added padding to CSS files.

added settings option for auto fullscreen

fixed actionbar colour issue - was getting decorview before the activity was loaded. Removed the actionBar.hide() and show() calls, un-neccessary with the decorView stuff
  • Loading branch information
[email protected] committed Oct 1, 2018
1 parent a96a44f commit 6f093e5
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 15 deletions.
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

0 comments on commit 6f093e5

Please sign in to comment.