Skip to content

Commit 6f093e5

Browse files
author
shebyimran@gmail.com
committed
added autohiding statusbar with scrollView.SetOnScrollChangeListener()
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
1 parent a96a44f commit 6f093e5

8 files changed

Lines changed: 83 additions & 15 deletions

File tree

app/src/main/assets/dark.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ h2:after {
178178
========================================================================== */
179179

180180
#content {
181-
margin-top: 1em;
181+
margin-top: 100px;
182182
min-height: 30em;
183183
}
184184

app/src/main/assets/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ h2:after {
168168
========================================================================== */
169169

170170
#content {
171-
margin-top: 1em;
171+
margin-top: 100px;
172172
min-height: 30em;
173173
}
174174

app/src/main/assets/solarized.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ h2:after {
185185
========================================================================== */
186186

187187
#content {
188-
margin-top: 1em;
188+
margin-top: 100px;
189189
min-height: 30em;
190190
}
191191

app/src/main/java/fr/gaulupeau/apps/Poche/data/Settings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ public boolean isFullscreenArticleView() {
368368
return getBoolean(R.string.pref_key_ui_article_fullscreen, false);
369369
}
370370

371+
public boolean isAutoFullscreenArticleView() {
372+
return getBoolean(R.string.pref_key_ui_article_fullscreen_auto, true);
373+
}
374+
371375
public void setFullScreenArticleView(boolean value) {
372376
setBoolean(R.string.pref_key_ui_article_fullscreen, value);
373377
}

app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.widget.ScrollView;
3636
import android.widget.TextView;
3737
import android.widget.Toast;
38+
import android.support.v7.widget.Toolbar;
3839

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

@@ -144,6 +145,9 @@ public class ReadArticleActivity extends BaseActionBarActivity {
144145
private boolean onPageFinishedCallPostponedUntilResume;
145146
private boolean loadingFinished;
146147

148+
private boolean isFullscreen;
149+
private View decorView;
150+
147151
public void onCreate(Bundle savedInstanceState) {
148152

149153
settings = App.getInstance().getSettings();
@@ -153,7 +157,7 @@ public void onCreate(Bundle savedInstanceState) {
153157
getWindow().setFlags(
154158
WindowManager.LayoutParams.FLAG_FULLSCREEN,
155159
WindowManager.LayoutParams.FLAG_FULLSCREEN
156-
);
160+
);
157161
ActionBar actionBar = super.getSupportActionBar();
158162
if(actionBar != null) actionBar.hide();
159163
}
@@ -199,7 +203,35 @@ public void onCreate(Bundle savedInstanceState) {
199203
// article is loaded - update menu
200204
invalidateOptionsMenu();
201205

206+
// Grab the action bar and decorView for making reading view fullscreen
207+
decorView = getWindow().getDecorView();
208+
isFullscreen = false;
209+
210+
// Toggle stable and fullscreen layout flags so everything is overlaid by the
211+
// actionbar AND the status bar when article is opened
212+
decorView.setSystemUiVisibility(
213+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
214+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
215+
);
216+
217+
202218
scrollView = (ScrollView)findViewById(R.id.scroll);
219+
220+
// // Hide status and action bar when scrolling down, show when scrolling up
221+
// // TODO: change to a method compatible with API 14.
222+
if (Build.VERSION.SDK_INT >= 23 && settings.isAutoFullscreenArticleView()) {
223+
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener(){
224+
@Override
225+
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
226+
if (oldScrollY - scrollY > 5 && isFullscreen){
227+
isFullscreen = goFullscreen(false);
228+
} else if (oldScrollY - scrollY < -5 && !isFullscreen) {
229+
isFullscreen = goFullscreen(true);
230+
}
231+
}
232+
});
233+
}
234+
203235
scrollViewLastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
204236
webViewContent = (WebView)findViewById(R.id.webViewContent);
205237
loadingPlaceholder = (TextView)findViewById(R.id.tv_loading_article);
@@ -481,6 +513,24 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) {
481513
}
482514
}
483515

516+
private boolean goFullscreen(boolean gofs) {
517+
// Hide both status bar and action bar if true else, show them
518+
if(gofs){
519+
decorView.setSystemUiVisibility(
520+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
521+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
522+
| View.SYSTEM_UI_FLAG_FULLSCREEN
523+
);
524+
return true;
525+
} else {
526+
decorView.setSystemUiVisibility(
527+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
528+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
529+
);
530+
return false;
531+
}
532+
}
533+
484534
private void showDisableTouchToast() {
485535
Toast.makeText(this, disableTouch
486536
? R.string.message_disableTouch_inputDisabled
@@ -598,22 +648,28 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
598648

599649
@Override
600650
public boolean onSingleTapConfirmed(MotionEvent e) {
601-
if(!tapToScroll) return false;
602-
603651
if(e.getPointerCount() > 1) return false;
604652

605-
int viewHeight = scrollView.getHeight();
606-
float y = e.getY() - scrollView.getScrollY();
653+
float x = e.getX();
654+
int viewWidth = scrollView.getWidth();
607655

608-
if(y > viewHeight * 0.25 && y < viewHeight * 0.75) {
609-
int viewWidth = scrollView.getWidth();
610-
float x = e.getX();
656+
if(tapToScroll) {
657+
int viewHeight = scrollView.getHeight();
658+
float y = e.getY() - scrollView.getScrollY();
659+
if (y > viewHeight * 0.25 && y < viewHeight * 0.75) {
611660

612-
if(x < viewWidth * 0.3) { // left part
613-
scroll(true, screenScrollingPercent, smoothScrolling, false);
614-
} else if(x > viewWidth * 0.7) { // right part
615-
scroll(false, screenScrollingPercent, smoothScrolling, false);
661+
if (x < viewWidth * 0.3) { // left part
662+
scroll(true, screenScrollingPercent, smoothScrolling, false);
663+
} else if (x > viewWidth * 0.7) { // right part
664+
scroll(false, screenScrollingPercent, smoothScrolling, false);
665+
}
616666
}
667+
// TODO: Maybe enable this with option in settings menu?
668+
// Toggle fullscreen if touching center of screen
669+
}
670+
671+
if(x > viewWidth * 0.3 && x < viewWidth * 0.7){
672+
isFullscreen = goFullscreen(!isFullscreen);
617673
}
618674

619675
return false;

app/src/main/res/values/strings-preference-keys.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<string name="pref_key_ui_screenScrolling_smooth" translatable="false">ui.screenScrolling.smooth</string>
3636
<string name="pref_key_ui_misc_category" translatable="false">ui.misc.category</string>
3737
<string name="pref_key_ui_article_fullscreen" translatable="false">ui.article.fullscreen</string>
38+
<string name="pref_key_ui_article_fullscreen_auto" translatable="false">ui.article.fullscreen_auto</string>
3839
<string name="pref_key_ui_disableTouch_enabled" translatable="false">ui.disableTouch.enabled</string>
3940
<string name="pref_key_ui_disableTouch_lastState" translatable="false">ui.disableTouch.lastState</string>
4041
<string name="pref_key_ui_disableTouch_keyCode" translatable="false">ui.disableTouch.keyCode</string>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
<string name="pref_desc_ui_article_textAlignment_justify">Stretches lines to equal width (like in newspapers)</string>
199199
<string name="pref_name_ui_article_fullscreen">Fullscreen Article View</string>
200200
<string name="pref_desc_ui_article_fullscreen">Hides system and app bars when reading articles</string>
201+
<string name="pref_name_ui_article_fullscreen_auto">Fullscreen Article View on Scroll</string>
202+
<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>
201203
<string name="pref_name_ui_readingSpeed">Reading speed</string>
202204
<string name="pref_desc_ui_readingSpeed">Your reading speed (measured in words per minute). Used to calculate estimated reading time.</string>
203205
<string name="pref_name_ui_keepScreenOn">Keep screen on while reading</string>

app/src/main/res/xml/preferences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@
150150
android:title="@string/pref_name_ui_article_fullscreen"
151151
android:summary="@string/pref_desc_ui_article_fullscreen"
152152
android:defaultValue="false"/>
153+
<CheckBoxPreference
154+
android:key="@string/pref_key_ui_article_fullscreen_auto"
155+
android:title="@string/pref_name_ui_article_fullscreen_auto"
156+
android:summary="@string/pref_desc_ui_article_fullscreen_auto"
157+
android:defaultValue="true"/>
153158
<CheckBoxPreference
154159
android:key="@string/pref_key_ui_disableTouch_enabled"
155160
android:title="@string/pref_name_ui_disableTouch_enabled"

0 commit comments

Comments
 (0)