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

Commit 4dcd7d21 authored by Jesse Chan's avatar Jesse Chan Committed by Bruno Martins
Browse files

Implement hide gestural navigation hint bar [1/5]



Change-Id: Ic6695dfe929db443f169d59f153e14a6de249590
Signed-off-by: default avatarJesse Chan <jc@lineageos.org>
parent 783a1293
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -16,11 +16,15 @@ package com.android.systemui.statusbar.phone;

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.OverlayManager;
import android.content.res.Configuration;
import android.graphics.drawable.Icon;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
@@ -41,6 +45,8 @@ import com.android.systemui.statusbar.phone.ReverseLinearLayout.ReverseRelativeL
import com.android.systemui.statusbar.policy.KeyButtonView;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;

import java.util.Objects;

public class NavigationBarInflaterView extends FrameLayout
@@ -80,6 +86,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;

@@ -101,6 +112,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);
@@ -143,12 +155,16 @@ 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();
        onLikelyDefaultLayoutChange();
    }

@@ -156,6 +172,7 @@ public class NavigationBarInflaterView extends FrameLayout
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        Dependency.get(TunerService.class).addTunable(this, NAV_BAR_INVERSE);
        Dependency.get(TunerService.class).addTunable(this, KEY_NAVIGATION_HINT);
    }

    @Override
@@ -170,6 +187,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();
        }
    }

@@ -242,6 +263,18 @@ public class NavigationBarInflaterView extends FrameLayout
        }
    }

    private void updateHint() {
        final boolean state = mNavBarMode == NAV_BAR_MODE_GESTURAL && !mIsHintEnabled;
        UserHandle userId = UserHandle.of(ActivityManager.getCurrentUser());
        try {
            mContext.getSystemService(OverlayManager.class).setEnabled(
                    OVERLAY_NAVIGATION_HIDE_HINT, state, userId);
        } catch (Exception 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));