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

Commit aa94d95b authored by Charles Chen's avatar Charles Chen
Browse files

Use size to inflate nav bar buttons instead of rotation

For a landscape or close-to-square device, the button layout of
nav bar was abnormal since System UI assumes the nav bar position
would change if device rotated.
However, for default landscape device, nav bar will be always on
the buttom.

This patch resolve the assumption by using nav bar
direction (horizon/vertical) instead of rotation.
Also renaming the layout for consistency.

Test: atest SystemUITests
Test: atest NavigationBarFlaterViewTest
Test: manual - rotate the phone and comapre to my Pixel2
Test: manual - test the peproduce steps and the layout of nav bar buttons is normal
Fix: 124428114

Change-Id: I23444bcb2a44555e7116f6140a29147c5a03ed69
parent aa7b6826
Loading
Loading
Loading
Loading
+0 −44
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/nav_buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/ends_group"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:clipChildren="false" />

        <LinearLayout
            android:id="@+id/center_group"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="horizontal"
            android:clipChildren="false" />

    </FrameLayout>

</FrameLayout>
+2 −2
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
    android:layout_width="match_parent"
    android:layout_height="@dimen/navigation_bar_size">

    <include android:id="@+id/rot0" layout="@layout/navigation_layout" />
    <include android:id="@+id/horizontal" layout="@layout/navigation_layout" />

    <include android:id="@+id/rot90" layout="@layout/navigation_layout_rot90" />
    <include android:id="@+id/vertical" layout="@layout/navigation_layout_vertical" />

</com.android.systemui.tuner.PreviewNavInflater>
+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@
    android:layout_marginStart="@dimen/rounded_corner_content_padding"
    android:layout_marginEnd="@dimen/rounded_corner_content_padding"
    android:paddingStart="@dimen/nav_content_padding"
    android:paddingEnd="@dimen/nav_content_padding">
    android:paddingEnd="@dimen/nav_content_padding"
    android:id="@+id/horizontal">

    <com.android.systemui.statusbar.phone.NearestTouchFrame
        android:id="@+id/nav_buttons"
+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@
    android:layout_marginTop="@dimen/rounded_corner_content_padding"
    android:layout_marginBottom="@dimen/rounded_corner_content_padding"
    android:paddingTop="@dimen/nav_content_padding"
    android:paddingBottom="@dimen/nav_content_padding">
    android:paddingBottom="@dimen/nav_content_padding"
    android:id="@+id/vertical">

    <com.android.systemui.statusbar.phone.NearestTouchFrame
        android:id="@+id/nav_buttons"
+47 −45
Original line number Diff line number Diff line
@@ -23,18 +23,15 @@ import android.graphics.drawable.Icon;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display.Mode;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Space;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.plugins.PluginListener;
@@ -83,21 +80,21 @@ public class NavigationBarInflaterView extends FrameLayout
    private static final String WEIGHT_CENTERED_SUFFIX = "WC";

    private final List<NavBarButtonProvider> mPlugins = new ArrayList<>();
    private final Display mDisplay;

    protected LayoutInflater mLayoutInflater;
    protected LayoutInflater mLandscapeInflater;

    protected FrameLayout mRot0;
    protected FrameLayout mRot90;
    private boolean isRot0Landscape;
    protected FrameLayout mHorizontal;
    protected FrameLayout mVertical;

    private SparseArray<ButtonDispatcher> mButtonDispatchers;
    @VisibleForTesting
    SparseArray<ButtonDispatcher> mButtonDispatchers;
    private String mCurrentLayout;

    private View mLastPortrait;
    private View mLastLandscape;

    private boolean mIsVertical;
    private boolean mAlternativeOrder;
    private boolean mUsingCustomLayout;

@@ -106,14 +103,11 @@ public class NavigationBarInflaterView extends FrameLayout
    public NavigationBarInflaterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        createInflaters();
        mDisplay = ((WindowManager)
                context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Mode displayMode = mDisplay.getMode();
        isRot0Landscape = displayMode.getPhysicalWidth() > displayMode.getPhysicalHeight();
        mOverviewProxyService = Dependency.get(OverviewProxyService.class);
    }

    private void createInflaters() {
    @VisibleForTesting
    void createInflaters() {
        mLayoutInflater = LayoutInflater.from(mContext);
        Configuration landscape = new Configuration();
        landscape.setTo(mContext.getResources().getConfiguration());
@@ -131,13 +125,12 @@ public class NavigationBarInflaterView extends FrameLayout

    private void inflateChildren() {
        removeAllViews();
        mRot0 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout, this, false);
        mRot0.setId(R.id.rot0);
        addView(mRot0);
        mRot90 = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_rot90, this,
                false);
        mRot90.setId(R.id.rot90);
        addView(mRot90);
        mHorizontal = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout,
                this /* root */, false /* attachToRoot */);
        addView(mHorizontal);
        mVertical = (FrameLayout) mLayoutInflater.inflate(R.layout.navigation_layout_vertical,
                this /* root */, false /* attachToRoot */);
        addView(mVertical);
        updateAlternativeOrder();
    }

@@ -197,12 +190,9 @@ public class NavigationBarInflaterView extends FrameLayout
        }
    }

    public void updateButtonDispatchersCurrentView() {
    void updateButtonDispatchersCurrentView() {
        if (mButtonDispatchers != null) {
            final int rotation = mDisplay.getRotation();
            final boolean portrait = rotation == Surface.ROTATION_0
                    || rotation == Surface.ROTATION_180;
            final View view = portrait ? mRot0 : mRot90;
            View view = mIsVertical ? mVertical : mHorizontal;
            for (int i = 0; i < mButtonDispatchers.size(); i++) {
                final ButtonDispatcher dispatcher = mButtonDispatchers.valueAt(i);
                dispatcher.setCurrentView(view);
@@ -210,7 +200,13 @@ public class NavigationBarInflaterView extends FrameLayout
        }
    }

    public void setAlternativeOrder(boolean alternativeOrder) {
    void setVertical(boolean vertical) {
        if (vertical != mIsVertical) {
            mIsVertical = vertical;
        }
    }

    void setAlternativeOrder(boolean alternativeOrder) {
        if (alternativeOrder != mAlternativeOrder) {
            mAlternativeOrder = alternativeOrder;
            updateAlternativeOrder();
@@ -218,10 +214,10 @@ public class NavigationBarInflaterView extends FrameLayout
    }

    private void updateAlternativeOrder() {
        updateAlternativeOrder(mRot0.findViewById(R.id.ends_group));
        updateAlternativeOrder(mRot0.findViewById(R.id.center_group));
        updateAlternativeOrder(mRot90.findViewById(R.id.ends_group));
        updateAlternativeOrder(mRot90.findViewById(R.id.center_group));
        updateAlternativeOrder(mHorizontal.findViewById(R.id.ends_group));
        updateAlternativeOrder(mHorizontal.findViewById(R.id.center_group));
        updateAlternativeOrder(mVertical.findViewById(R.id.ends_group));
        updateAlternativeOrder(mVertical.findViewById(R.id.center_group));
    }

    private void updateAlternativeOrder(View v) {
@@ -231,10 +227,10 @@ public class NavigationBarInflaterView extends FrameLayout
    }

    private void initiallyFill(ButtonDispatcher buttonDispatcher) {
        addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.ends_group));
        addAll(buttonDispatcher, (ViewGroup) mRot0.findViewById(R.id.center_group));
        addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.ends_group));
        addAll(buttonDispatcher, (ViewGroup) mRot90.findViewById(R.id.center_group));
        addAll(buttonDispatcher, mHorizontal.findViewById(R.id.ends_group));
        addAll(buttonDispatcher, mHorizontal.findViewById(R.id.center_group));
        addAll(buttonDispatcher, mVertical.findViewById(R.id.ends_group));
        addAll(buttonDispatcher, mVertical.findViewById(R.id.center_group));
    }

    private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) {
@@ -266,17 +262,23 @@ public class NavigationBarInflaterView extends FrameLayout
        String[] center = sets[1].split(BUTTON_SEPARATOR);
        String[] end = sets[2].split(BUTTON_SEPARATOR);
        // 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);
        inflateButtons(start, mHorizontal.findViewById(R.id.ends_group),
                false /* landscape */, true /* start */);
        inflateButtons(start, mVertical.findViewById(R.id.ends_group),
                true /* landscape */, true /* start */);

        inflateButtons(center, mRot0.findViewById(R.id.center_group), isRot0Landscape, false);
        inflateButtons(center, mRot90.findViewById(R.id.center_group), !isRot0Landscape, false);
        inflateButtons(center, mHorizontal.findViewById(R.id.center_group),
                false /* landscape */, false /* start */);
        inflateButtons(center, mVertical.findViewById(R.id.center_group),
                true /* landscape */, false /* start */);

        addGravitySpacer(mRot0.findViewById(R.id.ends_group));
        addGravitySpacer(mRot90.findViewById(R.id.ends_group));
        addGravitySpacer(mHorizontal.findViewById(R.id.ends_group));
        addGravitySpacer(mVertical.findViewById(R.id.ends_group));

        inflateButtons(end, mRot0.findViewById(R.id.ends_group), isRot0Landscape, false);
        inflateButtons(end, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, false);
        inflateButtons(end, mHorizontal.findViewById(R.id.ends_group),
                false /* landscape */, false /* start */);
        inflateButtons(end, mVertical.findViewById(R.id.ends_group),
                true /* landscape */, false /* start */);

        updateButtonDispatchersCurrentView();
    }
@@ -469,8 +471,8 @@ public class NavigationBarInflaterView extends FrameLayout
                mButtonDispatchers.valueAt(i).clear();
            }
        }
        clearAllChildren(mRot0.findViewById(R.id.nav_buttons));
        clearAllChildren(mRot90.findViewById(R.id.nav_buttons));
        clearAllChildren(mHorizontal.findViewById(R.id.nav_buttons));
        clearAllChildren(mVertical.findViewById(R.id.nav_buttons));
    }

    private void clearAllChildren(ViewGroup group) {
Loading