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

Commit 3d2dc3fd authored by Jesse Chan's avatar Jesse Chan Committed by Michael Bestas
Browse files

SystemUI: Implement hide gestural navigation hint bar [1/5]



Author: Jesse Chan <jc@lineageos.org>
Date:   Tue Jun 2 13:59:52 2020 +0800

    SystemUI: Set no hint overlay to highest priority

    As overlays are also used to apply navigation mode, it is needed to set
    our customization overlay to highest priority to ensure it is applied.

    Change-Id: I41ca4b7ea99fea9f62d2e8ece5114f682e8e7fe9
    Signed-off-by: default avatarJesse Chan <jc@lineageos.org>

Change-Id: Ic6695dfe929db443f169d59f153e14a6de249590
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 91460d05
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -18,11 +18,16 @@ package com.android.systemui.navigationbar;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.content.Context;
import android.content.om.IOverlayManager;
import android.content.res.Configuration;
import android.graphics.drawable.Icon;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
@@ -45,6 +50,8 @@ import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import java.io.PrintWriter;
import java.util.Objects;

@@ -85,6 +92,11 @@ public class NavigationBarInflaterView extends FrameLayout
    private static final String ABSOLUTE_SUFFIX = "A";
    private static final String ABSOLUTE_VERTICAL_CENTERED_SUFFIX = "C";

    private static final String KEY_NAVIGATION_HINT =
            "lineagesystem:" + LineageSettings.System.NAVIGATION_BAR_HINT;
    private static final String OVERLAY_NAVIGATION_HIDE_HINT =
            "org.lineageos.overlay.customization.navbar.nohint";

    protected LayoutInflater mLayoutInflater;
    protected LayoutInflater mLandscapeInflater;

@@ -105,6 +117,7 @@ public class NavigationBarInflaterView extends FrameLayout
    private int mNavBarMode = NAV_BAR_MODE_3BUTTON;

    private boolean mInverseLayout;
    private boolean mIsHintEnabled;

    public NavigationBarInflaterView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -147,18 +160,23 @@ public class NavigationBarInflaterView extends FrameLayout
                : mOverviewProxyService.shouldShowSwipeUpUI()
                        ? R.string.config_navBarLayoutQuickstep
                        : R.string.config_navBarLayout;
        if (!mIsHintEnabled && defaultResource == R.string.config_navBarLayoutHandle) {
            return getContext().getString(defaultResource).replace(HOME_HANDLE, "");
        }
        return getContext().getString(defaultResource);
    }

    @Override
    public void onNavigationModeChanged(int mode) {
        mNavBarMode = mode;
        updateHint();
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        Dependency.get(TunerService.class).addTunable(this, NAV_BAR_INVERSE);
        Dependency.get(TunerService.class).addTunable(this, KEY_NAVIGATION_HINT);
    }

    @Override
@@ -173,6 +191,10 @@ public class NavigationBarInflaterView extends FrameLayout
        if (NAV_BAR_INVERSE.equals(key)) {
            mInverseLayout = TunerService.parseIntegerSwitch(newValue, false);
            updateLayoutInversion();
        } else if (KEY_NAVIGATION_HINT.equals(key)) {
            mIsHintEnabled = TunerService.parseIntegerSwitch(newValue, true);
            updateHint();
            onLikelyDefaultLayoutChange();
        }
    }

@@ -234,6 +256,24 @@ public class NavigationBarInflaterView extends FrameLayout
        }
    }

    private void updateHint() {
        final IOverlayManager iom = IOverlayManager.Stub.asInterface(
                ServiceManager.getService(Context.OVERLAY_SERVICE));
        final boolean state = mNavBarMode == NAV_BAR_MODE_GESTURAL && !mIsHintEnabled;
        final int userId = ActivityManager.getCurrentUser();
        try {
            iom.setEnabled(OVERLAY_NAVIGATION_HIDE_HINT, state, userId);
            if (state) {
                // As overlays are also used to apply navigation mode, it is needed to set
                // our customization overlay to highest priority to ensure it is applied.
                iom.setHighestPriority(OVERLAY_NAVIGATION_HIDE_HINT, userId);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to " + (state ? "enable" : "disable")
                    + " overlay " + OVERLAY_NAVIGATION_HIDE_HINT + " for user " + userId);
        }
    }

    private void initiallyFill(ButtonDispatcher buttonDispatcher) {
        addAll(buttonDispatcher, mHorizontal.findViewById(R.id.ends_group));
        addAll(buttonDispatcher, mHorizontal.findViewById(R.id.center_group));