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

Commit 91460d05 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

SystemUI: Add navbar layout inversion tuning

* Originally implemented by jesec but since
  then has been reworked by me to use RTL
  instead of replacing left / right buttons.

Change-Id: I6159f0232ba2ee9f45d2afbba7d11072d902d9ac
parent 85c22de2
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -43,18 +43,20 @@ import com.android.systemui.navigationbar.buttons.ReverseLinearLayout;
import com.android.systemui.navigationbar.buttons.ReverseLinearLayout.ReverseRelativeLayout;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.tuner.TunerService;

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

public class NavigationBarInflaterView extends FrameLayout
        implements NavigationModeController.ModeChangedListener {
        implements NavigationModeController.ModeChangedListener, TunerService.Tunable {

    private static final String TAG = "NavBarInflater";

    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";
@@ -102,6 +104,8 @@ public class NavigationBarInflaterView extends FrameLayout
    private OverviewProxyService mOverviewProxyService;
    private int mNavBarMode = NAV_BAR_MODE_3BUTTON;

    private boolean mInverseLayout;

    public NavigationBarInflaterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        createInflaters();
@@ -151,12 +155,33 @@ public class NavigationBarInflaterView extends FrameLayout
        mNavBarMode = mode;
    }

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

    @Override
    protected void onDetachedFromWindow() {
        Dependency.get(NavigationModeController.class).removeListener(this);
        Dependency.get(TunerService.class).removeTunable(this);
        super.onDetachedFromWindow();
    }

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (NAV_BAR_INVERSE.equals(key)) {
            mInverseLayout = TunerService.parseIntegerSwitch(newValue, false);
            updateLayoutInversion();
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        updateLayoutInversion();
    }

    public void onLikelyDefaultLayoutChange() {
        // Reevaluate new layout
        final String newValue = getDefaultLayout();
@@ -271,6 +296,19 @@ public class NavigationBarInflaterView extends FrameLayout
        updateButtonDispatchersCurrentView();
    }

    private void updateLayoutInversion() {
        if (mInverseLayout) {
            Configuration config = mContext.getResources().getConfiguration();
            if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
                setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
            } else {
                setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            }
        } else {
            setLayoutDirection(View.LAYOUT_DIRECTION_INHERIT);
        }
    }

    private void addGravitySpacer(LinearLayout layout) {
        layout.addView(new Space(mContext), new LinearLayout.LayoutParams(0, 0, 1));
    }