Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb57db3e authored by Jesse Chan's avatar Jesse Chan Committed by Luca Stefani
Browse files

SystemUI: add navbar layout inversion tuning



Change-Id: Id6a76c635b3d3927a2ffd8e0c2d912473d7dcde3
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 4262768f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -92,4 +92,7 @@

    <!-- Notify use that they are in Lock-to-app (for devices without navbar)-->
    <string name="screen_pinning_toast_no_navbar">To unpin this screen, touch &amp; hold Back button</string>

    <!-- Button that controls inversion of layout of navigation bar -->
    <string name="nav_bar_layout_inverse">Invert layout</string>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -64,4 +64,8 @@
        android:summary="%s"
        android:title="@string/right_icon" />

    <com.android.systemui.tuner.TunerSwitch
        android:key="sysui_nav_bar_inverse"
        android:title="@string/nav_bar_layout_inverse" />

</PreferenceScreen>
+33 −1
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@@ -58,6 +60,7 @@ public class NavigationBarInflaterView extends FrameLayout
    public static final String NAV_BAR_VIEWS = "sysui_nav_bar";
    public static final String NAV_BAR_LEFT = "sysui_nav_bar_left";
    public static final String NAV_BAR_RIGHT = "sysui_nav_bar_right";
    public static final String NAV_BAR_INVERSE = "sysui_nav_bar_inverse";

    public static final String MENU_IME_ROTATE = "menu_ime";
    public static final String BACK = "back";
@@ -103,6 +106,8 @@ public class NavigationBarInflaterView extends FrameLayout

    private OverviewProxyService mOverviewProxyService;

    private boolean mInverseLayout;

    public NavigationBarInflaterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        createInflaters();
@@ -152,7 +157,7 @@ public class NavigationBarInflaterView extends FrameLayout
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        Dependency.get(TunerService.class).addTunable(this, NAV_BAR_VIEWS, NAV_BAR_LEFT,
                NAV_BAR_RIGHT);
                NAV_BAR_RIGHT, NAV_BAR_INVERSE);
        Dependency.get(PluginManager.class).addPluginListener(this,
                NavBarButtonProvider.class, true /* Allow multiple */);
    }
@@ -175,6 +180,10 @@ public class NavigationBarInflaterView extends FrameLayout
        } else if (NAV_BAR_LEFT.equals(key) || NAV_BAR_RIGHT.equals(key)) {
            clearViews();
            inflateLayout(mCurrentLayout);
        } else if (NAV_BAR_INVERSE.equals(key)) {
            mInverseLayout = newValue != null && Integer.parseInt(newValue) != 0;
            clearViews();
            inflateLayout(mCurrentLayout);
        }
    }

@@ -251,6 +260,17 @@ public class NavigationBarInflaterView extends FrameLayout
        }
    }

    private String[] swapLeftAndRight(String[] set) {
        for (int i = 0; i < set.length; i++) {
            if (set.equals(LEFT)) {
                set[i] = RIGHT;
            } else if (set[i].equals(RIGHT)) {
                set[i] = LEFT;
            }
        }
        return set;
    }

    protected void inflateLayout(String newLayout) {
        mCurrentLayout = newLayout;
        if (newLayout == null) {
@@ -265,6 +285,18 @@ public class NavigationBarInflaterView extends FrameLayout
        String[] start = sets[0].split(BUTTON_SEPARATOR);
        String[] center = sets[1].split(BUTTON_SEPARATOR);
        String[] end = sets[2].split(BUTTON_SEPARATOR);
        // Invert start, center and end if needed.
        if (mInverseLayout) {
            List<String> newStart = Arrays.asList(end);
            List<String> newCenter = Arrays.asList(center);
            List<String> newEnd = Arrays.asList(start);
            Collections.reverse(newStart);
            Collections.reverse(newCenter);
            Collections.reverse(newEnd);
            start = swapLeftAndRight((String[]) newStart.toArray());
            center = swapLeftAndRight((String[]) newCenter.toArray());
            end = swapLeftAndRight((String[]) newEnd.toArray());
        }
        // Inflate these in start to end order or accessibility traversal will be messed up.
        inflateButtons(start, mRot0.findViewById(R.id.ends_group), isRot0Landscape, true);
        inflateButtons(start, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, true);