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

Commit c78acd25 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use size to inflate nav bar buttons instead of rotation"

parents 7464798a aa94d95b
Loading
Loading
Loading
Loading
+0 −44
Original line number Original line 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 Original line Diff line number Diff line
@@ -20,8 +20,8 @@
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="@dimen/navigation_bar_size">
    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>
</com.android.systemui.tuner.PreviewNavInflater>
+2 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,8 @@
    android:layout_marginStart="@dimen/rounded_corner_content_padding"
    android:layout_marginStart="@dimen/rounded_corner_content_padding"
    android:layout_marginEnd="@dimen/rounded_corner_content_padding"
    android:layout_marginEnd="@dimen/rounded_corner_content_padding"
    android:paddingStart="@dimen/nav_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
    <com.android.systemui.statusbar.phone.NearestTouchFrame
        android:id="@+id/nav_buttons"
        android:id="@+id/nav_buttons"
+2 −1
Original line number Original line Diff line number Diff line
@@ -22,7 +22,8 @@
    android:layout_marginTop="@dimen/rounded_corner_content_padding"
    android:layout_marginTop="@dimen/rounded_corner_content_padding"
    android:layout_marginBottom="@dimen/rounded_corner_content_padding"
    android:layout_marginBottom="@dimen/rounded_corner_content_padding"
    android:paddingTop="@dimen/nav_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
    <com.android.systemui.statusbar.phone.NearestTouchFrame
        android:id="@+id/nav_buttons"
        android:id="@+id/nav_buttons"
+47 −45
Original line number Original line Diff line number Diff line
@@ -23,18 +23,15 @@ import android.graphics.drawable.Icon;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.Display.Mode;
import android.view.Gravity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout;
import android.widget.Space;
import android.widget.Space;


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


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


    protected LayoutInflater mLayoutInflater;
    protected LayoutInflater mLayoutInflater;
    protected LayoutInflater mLandscapeInflater;
    protected LayoutInflater mLandscapeInflater;


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


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


    private View mLastPortrait;
    private View mLastPortrait;
    private View mLastLandscape;
    private View mLastLandscape;


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


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


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


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


@@ -198,12 +191,9 @@ public class NavigationBarInflaterView extends FrameLayout
        }
        }
    }
    }


    public void updateButtonDispatchersCurrentView() {
    void updateButtonDispatchersCurrentView() {
        if (mButtonDispatchers != null) {
        if (mButtonDispatchers != null) {
            final int rotation = mDisplay.getRotation();
            View view = mIsVertical ? mVertical : mHorizontal;
            final boolean portrait = rotation == Surface.ROTATION_0
                    || rotation == Surface.ROTATION_180;
            final View view = portrait ? mRot0 : mRot90;
            for (int i = 0; i < mButtonDispatchers.size(); i++) {
            for (int i = 0; i < mButtonDispatchers.size(); i++) {
                final ButtonDispatcher dispatcher = mButtonDispatchers.valueAt(i);
                final ButtonDispatcher dispatcher = mButtonDispatchers.valueAt(i);
                dispatcher.setCurrentView(view);
                dispatcher.setCurrentView(view);
@@ -211,7 +201,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) {
        if (alternativeOrder != mAlternativeOrder) {
            mAlternativeOrder = alternativeOrder;
            mAlternativeOrder = alternativeOrder;
            updateAlternativeOrder();
            updateAlternativeOrder();
@@ -219,10 +215,10 @@ public class NavigationBarInflaterView extends FrameLayout
    }
    }


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


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


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


    private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) {
    private void addAll(ButtonDispatcher buttonDispatcher, ViewGroup parent) {
@@ -267,17 +263,23 @@ public class NavigationBarInflaterView extends FrameLayout
        String[] center = sets[1].split(BUTTON_SEPARATOR);
        String[] center = sets[1].split(BUTTON_SEPARATOR);
        String[] end = sets[2].split(BUTTON_SEPARATOR);
        String[] end = sets[2].split(BUTTON_SEPARATOR);
        // Inflate these in start to end order or accessibility traversal will be messed up.
        // 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, mHorizontal.findViewById(R.id.ends_group),
        inflateButtons(start, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, true);
                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, mHorizontal.findViewById(R.id.center_group),
        inflateButtons(center, mRot90.findViewById(R.id.center_group), !isRot0Landscape, false);
                false /* landscape */, false /* start */);
        inflateButtons(center, mVertical.findViewById(R.id.center_group),
                true /* landscape */, false /* start */);


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


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


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


    private void clearAllChildren(ViewGroup group) {
    private void clearAllChildren(ViewGroup group) {
Loading