App 2.31.0: full screen from the navigation, swipe in from the left to return
The Overview's full-screen button moved from the page's corner into the navigation, beside the MG4 logo. A swipe in from the left edge (EdgeSwipe, unit-tested) brings the navigation back; a faint handle marks the edge. Sideways swipes no longer change the page: only the navigation does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
@@ -183,6 +183,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Keep all pages alive: the log and vehicle readings are refreshed
|
||||
// by the tick even when their page is off screen.
|
||||
pager.setOffscreenPageLimit(panes.length - 1);
|
||||
// Pages change only by the navigation: a sideways swipe on a page (a slider, a chart,
|
||||
// the swipe that brings the navigation back) must not turn it.
|
||||
pager.setUserInputEnabled(false);
|
||||
pager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override public void onPageSelected(int position) {
|
||||
markCurrentPage(position);
|
||||
@@ -196,30 +199,72 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
for (int i = 0; i < TAB_IDS.length; i++) {
|
||||
final int index = i;
|
||||
// Animated, so the button does the same thing the swipe does: the direction of
|
||||
// travel is what tells the driver where they are in the row.
|
||||
findViewById(TAB_IDS[i]).setOnClickListener(v -> pager.setCurrentItem(index, false));
|
||||
}
|
||||
markCurrentPage(pager.getCurrentItem());
|
||||
applyOverviewFullScreen(pager.getCurrentItem());
|
||||
}
|
||||
|
||||
/** Whether the Overview hides the navigation (the button in its corner). */
|
||||
/** Whether the Overview hides the navigation (the button in the navigation's header). */
|
||||
static final String PREF_OVERVIEW_FULLSCREEN = "overview_fullscreen";
|
||||
|
||||
/** True while the Overview is full screen: the navigation hidden, the edge swipe armed. */
|
||||
private boolean overviewFull;
|
||||
|
||||
/**
|
||||
* The Overview full screen: the navigation hidden while the Overview is the page and the
|
||||
* driver chose it; every other page always has its navigation, and swiping still works.
|
||||
* The button only shows on the Overview, its icon saying what a tap does.
|
||||
* driver chose it, with a handle at the left edge where a swipe brings it back. Every
|
||||
* other page always has its navigation. The button sits in the navigation and only shows
|
||||
* on the Overview (invisible elsewhere, so the header keeps its layout).
|
||||
*/
|
||||
private void applyOverviewFullScreen(int position) {
|
||||
boolean overview = position == 0;
|
||||
boolean full = overview && prefs.getBoolean(PREF_OVERVIEW_FULLSCREEN, false);
|
||||
findViewById(R.id.nav_bar).setVisibility(full ? View.GONE : View.VISIBLE);
|
||||
android.widget.ImageButton button = findViewById(R.id.overview_fullscreen);
|
||||
button.setVisibility(overview ? View.VISIBLE : View.GONE);
|
||||
button.setImageResource(full ? R.drawable.ic_fullscreen_exit : R.drawable.ic_fullscreen);
|
||||
button.setContentDescription(getString(full ? R.string.overview_fullscreen_exit : R.string.overview_fullscreen_enter));
|
||||
overviewFull = overview && prefs.getBoolean(PREF_OVERVIEW_FULLSCREEN, false);
|
||||
findViewById(R.id.nav_bar).setVisibility(overviewFull ? View.GONE : View.VISIBLE);
|
||||
findViewById(R.id.edge_handle).setVisibility(overviewFull ? View.VISIBLE : View.GONE);
|
||||
findViewById(R.id.overview_fullscreen).setVisibility(overview ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
/** The swipe in from the left edge, set up with this screen's density. */
|
||||
private EdgeSwipe edgeSwipe;
|
||||
/** The rest of a touch that became the edge swipe: kept from the page underneath. */
|
||||
private boolean swallowTouch;
|
||||
|
||||
/**
|
||||
* Watches every touch in the Overview's full screen for the swipe in from the left edge,
|
||||
* which brings the navigation back. The page still gets the touch until it becomes the
|
||||
* swipe; then it gets a cancel and nothing more of that touch.
|
||||
*/
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(android.view.MotionEvent ev) {
|
||||
int action = ev.getActionMasked();
|
||||
if (swallowTouch) {
|
||||
if (action == android.view.MotionEvent.ACTION_UP
|
||||
|| action == android.view.MotionEvent.ACTION_CANCEL) swallowTouch = false;
|
||||
return true;
|
||||
}
|
||||
if (overviewFull) {
|
||||
if (edgeSwipe == null) {
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
edgeSwipe = new EdgeSwipe(48 * density, 64 * density);
|
||||
}
|
||||
if (action == android.view.MotionEvent.ACTION_DOWN) {
|
||||
edgeSwipe.down(ev.getX(), ev.getY());
|
||||
} else if (action == android.view.MotionEvent.ACTION_MOVE && edgeSwipe.move(ev.getX(), ev.getY())) {
|
||||
android.view.MotionEvent cancel = android.view.MotionEvent.obtain(ev);
|
||||
cancel.setAction(android.view.MotionEvent.ACTION_CANCEL);
|
||||
super.dispatchTouchEvent(cancel);
|
||||
cancel.recycle();
|
||||
swallowTouch = true;
|
||||
prefs.edit().putBoolean(PREF_OVERVIEW_FULLSCREEN, false).apply();
|
||||
applyOverviewFullScreen(((ViewPager2) findViewById(R.id.content)).getCurrentItem());
|
||||
return true;
|
||||
} else if (action == android.view.MotionEvent.ACTION_UP
|
||||
|| action == android.view.MotionEvent.ACTION_CANCEL) {
|
||||
edgeSwipe.up();
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user