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:
2026-10-25 08:53:41 +01:00
co-authored by Claude Opus 5.5
parent 4a1f178b5c
commit 4cd5f7a7ba
13 changed files with 179 additions and 34 deletions
@@ -0,0 +1,44 @@
package com.evsuite.abrp;
/**
* The swipe in from the left edge that brings the navigation back in the Overview's full
* screen: a touch that starts within {@code edge} of the left side and travels at least
* {@code travel} to the right, more sideways than up or down. Distances in pixels.
* Pure Java, unit-tested.
*/
final class EdgeSwipe {
private final float edge, travel;
private boolean tracking;
private float startX, startY;
EdgeSwipe(float edge, float travel) {
this.edge = edge;
this.travel = travel;
}
/** A finger went down: only one near the left edge can become the swipe. */
void down(float x, float y) {
tracking = x <= edge;
startX = x;
startY = y;
}
/** The finger moved; true once, when this touch has become the swipe. */
boolean move(float x, float y) {
if (!tracking) return false;
float dx = x - startX, dy = Math.abs(y - startY);
if (dx >= travel && dx > dy) {
tracking = false;
return true;
}
// Mostly up or down already: a scroll, not this swipe.
if (dy > travel) tracking = false;
return false;
}
/** The finger lifted or the touch was cancelled. */
void up() {
tracking = false;
}
}
@@ -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);
}
/**
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The handle at the left edge in full screen: where the navigation swipes back in. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/ev_text_secondary" />
<corners android:radius="3dp" />
</shape>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The full-screen button: a small dark disc inside its 72 dp touch area. -->
<!-- The full-screen button in the navigation: a small dark disc inside its touch area. -->
<inset xmlns:android="http://schemas.android.com/apk/res/android" android:inset="16dp">
<shape android:shape="oval">
<solid android:color="#99121212" />
@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Shrink, for the Overview's full-screen button (brings the navigation back). -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/ev_text_primary"
android:pathData="M5,16h3v3h2v-5H5v2zM8,8H5v2h5V5H8v3zM14,19h2v-3h3v-2h-5v5zM16,8V5h-2v5h5V8h-3z" />
</vector>
@@ -4,8 +4,14 @@
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal">
<ScrollView android:id="@+id/nav_bar" android:layout_width="192dp" android:layout_height="match_parent" android:layout_margin="16dp" android:fillViewport="true" android:background="@drawable/bg_sidebar" android:scrollbars="none">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="12dp">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/design_brand" android:textAppearance="@style/Text.EV.Hero" android:textColor="?attr/evAccent" android:paddingStart="14dp" android:paddingTop="8dp" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/design_brand_caption" android:textAppearance="@style/Text.EV.Secondary" android:paddingStart="14dp" android:layout_marginBottom="24dp" />
<!-- The brand, and beside it the button that hides this panel on the Overview. -->
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_vertical" android:layout_marginBottom="24dp">
<LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/design_brand" android:textAppearance="@style/Text.EV.Hero" android:textColor="?attr/evAccent" android:paddingStart="14dp" android:paddingTop="8dp" />
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/design_brand_caption" android:textAppearance="@style/Text.EV.Secondary" android:paddingStart="14dp" />
</LinearLayout>
<ImageButton android:id="@+id/overview_fullscreen" android:layout_width="64dp" android:layout_height="72dp" android:background="@drawable/bg_fullscreen_button" android:src="@drawable/ic_fullscreen" android:padding="22dp" android:scaleType="fitCenter" android:contentDescription="@string/overview_fullscreen_enter" />
</LinearLayout>
<com.google.android.material.button.MaterialButton android:id="@+id/tabVehicle" style="@style/Widget.EV.NavTab" android:layout_width="match_parent" android:layout_height="64dp" android:layout_marginBottom="6dp" android:text="@string/tab_vehicle" app:icon="@drawable/ic_tab_vehicle" />
<com.google.android.material.button.MaterialButton android:id="@+id/tabConsumption" style="@style/Widget.EV.NavTab" android:layout_width="match_parent" android:layout_height="64dp" android:layout_marginBottom="6dp" android:text="@string/tab_consumption" app:icon="@drawable/ic_tab_vehicle" />
<com.google.android.material.button.MaterialButton android:id="@+id/tabCharging" style="@style/Widget.EV.NavTab" android:layout_width="match_parent" android:layout_height="64dp" android:layout_marginBottom="6dp" android:text="@string/tab_charging" app:icon="@drawable/ic_tab_charging" />
@@ -16,10 +22,10 @@
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:orientation="vertical">
<!-- The pages, and over them on the Overview the button that hides the navigation. -->
<!-- The pages, and over them in full screen the handle that says "swipe in from here". -->
<FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1">
<androidx.viewpager2.widget.ViewPager2 android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" />
<ImageButton android:id="@+id/overview_fullscreen" android:layout_width="72dp" android:layout_height="72dp" android:layout_gravity="top|end" android:background="@drawable/bg_fullscreen_button" android:src="@drawable/ic_fullscreen" android:padding="24dp" android:scaleType="fitCenter" android:alpha="0.75" android:contentDescription="@string/overview_fullscreen_enter" />
<View android:id="@+id/edge_handle" android:layout_width="5dp" android:layout_height="96dp" android:layout_gravity="start|center_vertical" android:layout_marginStart="4dp" android:background="@drawable/bg_edge_handle" android:alpha="0.35" android:visibility="gone" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
+3 -2
View File
@@ -2,10 +2,10 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/app_root" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:background="@color/ev_background">
<com.evsuite.abrp.PremiumBackdropView android:layout_width="match_parent" android:layout_height="match_parent"/>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<!-- The pages, and over them on the Overview the button that hides the navigation. -->
<!-- The pages, and over them in full screen the handle that says "swipe in from here". -->
<FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1">
<androidx.viewpager2.widget.ViewPager2 android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent"/>
<ImageButton android:id="@+id/overview_fullscreen" android:layout_width="72dp" android:layout_height="72dp" android:layout_gravity="top|end" android:background="@drawable/bg_fullscreen_button" android:src="@drawable/ic_fullscreen" android:padding="24dp" android:scaleType="fitCenter" android:alpha="0.75" android:contentDescription="@string/overview_fullscreen_enter" />
<View android:id="@+id/edge_handle" android:layout_width="5dp" android:layout_height="96dp" android:layout_gravity="start|center_vertical" android:layout_marginStart="4dp" android:background="@drawable/bg_edge_handle" android:alpha="0.35" android:visibility="gone"/>
</FrameLayout>
<LinearLayout android:id="@+id/nav_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="8dp" android:background="@drawable/bg_sidebar">
<com.google.android.material.button.MaterialButton android:id="@+id/tabVehicle" style="@style/Widget.EV.NavTab.Compact" android:layout_width="0dp" android:layout_height="76dp" android:layout_weight="1" android:text="@string/tab_vehicle" app:icon="@drawable/ic_tab_vehicle"/>
@@ -15,6 +15,7 @@
<com.google.android.material.button.MaterialButton android:id="@+id/tabServer" style="@style/Widget.EV.NavTab.Compact" android:layout_width="0dp" android:layout_height="76dp" android:layout_weight="1" android:text="@string/tab_server" app:icon="@drawable/ic_tab_server"/>
<com.google.android.material.button.MaterialButton android:id="@+id/tabSettings" style="@style/Widget.EV.NavTab.Compact" android:layout_width="0dp" android:layout_height="76dp" android:layout_weight="1" android:text="@string/tab_settings" app:icon="@drawable/ic_tab_service"/>
<com.google.android.material.button.MaterialButton android:id="@+id/tabLog" style="@style/Widget.EV.NavTab.Compact" android:layout_width="0dp" android:layout_height="76dp" android:layout_weight="1" android:text="@string/tab_log" app:icon="@drawable/ic_tab_log"/>
<ImageButton android:id="@+id/overview_fullscreen" android:layout_width="64dp" android:layout_height="76dp" android:background="@drawable/bg_fullscreen_button" android:src="@drawable/ic_fullscreen" android:padding="22dp" android:scaleType="fitCenter" android:contentDescription="@string/overview_fullscreen_enter"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
-1
View File
@@ -132,7 +132,6 @@
<string name="overview_style_mg">MG</string>
<string name="accent_not_used">%1$s has its own colours. To change the accent colour, pick a style that uses it.</string>
<string name="overview_fullscreen_enter">Overview full screen: hide the navigation</string>
<string name="overview_fullscreen_exit">Show the navigation again</string>
<string name="overview_style_minimal">Minimal</string>
<string name="overview_style_terminal">Terminal</string>
<string name="accent_original">Original</string>