From 7f6a2ab20893c6b40124efc8854e08443ba11e03 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Fri, 21 Apr 2017 13:48:19 -0400 Subject: [PATCH] Update nav bar layout for universal grid Test: visual Bug: 37115488 Change-Id: I43fe6648f56d25f41fadefcaa27d2c0cf3f077ba --- packages/SystemUI/res/layout/navigation_layout.xml | 6 +- .../res/layout/navigation_layout_rot90.xml | 6 +- packages/SystemUI/res/values-sw372dp/config.xml | 25 +++++++ packages/SystemUI/res/values/config.xml | 2 +- .../src/com/android/systemui/RoundedCorners.java | 8 -- .../statusbar/phone/NavigationBarInflaterView.java | 86 ++++++++++++++-------- 6 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 packages/SystemUI/res/values-sw372dp/config.xml diff --git a/packages/SystemUI/res/layout/navigation_layout.xml b/packages/SystemUI/res/layout/navigation_layout.xml index 2bf4d9cb535f..a621c7c0f836 100644 --- a/packages/SystemUI/res/layout/navigation_layout.xml +++ b/packages/SystemUI/res/layout/navigation_layout.xml @@ -18,7 +18,11 @@ 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"> + android:layout_height="match_parent" + android:layout_marginStart="@dimen/rounded_corner_content_padding" + android:layout_marginEnd="@dimen/rounded_corner_content_padding" + android:paddingStart="8dp" + android:paddingEnd="8dp"> + android:layout_height="match_parent" + android:layout_marginTop="@dimen/rounded_corner_content_padding" + android:layout_marginBottom="@dimen/rounded_corner_content_padding" + android:paddingTop="8dp" + android:paddingBottom="8dp"> + + + + + + left[.25W],back[.5WC];home;recent[.5WC],right[.25W] + diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 74b0702ce5f6..2ad6f2da7fb0 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -293,7 +293,7 @@ com.android.systemui.SystemUIFactory - left,back;home;recent,right + left[.5W],back[1WC];home;recent[1WC],right[.5W] false diff --git a/packages/SystemUI/src/com/android/systemui/RoundedCorners.java b/packages/SystemUI/src/com/android/systemui/RoundedCorners.java index 61325400846a..74a150551c15 100644 --- a/packages/SystemUI/src/com/android/systemui/RoundedCorners.java +++ b/packages/SystemUI/src/com/android/systemui/RoundedCorners.java @@ -98,14 +98,6 @@ public class RoundedCorners extends SystemUI implements Tunable { TunablePadding.addTunablePadding(statusBar.findViewById(R.id.keyguard_header), PADDING, padding, FLAG_END); - View navigationBarWindow = sb.getNavigationBarWindow(); - // Not all devices have on screen navigation bars. - if (navigationBarWindow != null) { - FragmentHostManager.get(navigationBarWindow).addTagListener( - NavigationBarFragment.TAG, - new TunablePaddingTagListener(padding, 0)); - } - FragmentHostManager fragmentHostManager = FragmentHostManager.get(statusBar); fragmentHostManager.addTagListener(CollapsedStatusBarFragment.TAG, new TunablePaddingTagListener(padding, R.id.status_bar)); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java index 720ca1499bf1..a14d1bc564ff 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java @@ -19,9 +19,11 @@ import android.content.Context; import android.content.res.Configuration; 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.View; import android.view.ViewGroup; @@ -43,6 +45,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; + public class NavigationBarInflaterView extends FrameLayout implements Tunable, PluginListener { @@ -71,6 +75,8 @@ public class NavigationBarInflaterView extends FrameLayout public static final String KEY_CODE_START = "("; public static final String KEY_IMAGE_DELIM = ":"; public static final String KEY_CODE_END = ")"; + private static final String WEIGHT_SUFFIX = "W"; + private static final String WEIGHT_CENTERED_SUFFIX = "WC"; private final List mPlugins = new ArrayList<>(); @@ -219,26 +225,27 @@ 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, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape); - inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape); + inflateButtons(start, mRot0.findViewById(R.id.ends_group), isRot0Landscape, true); + inflateButtons(start, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, true); - inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group), isRot0Landscape); - inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group), !isRot0Landscape); + inflateButtons(center, mRot0.findViewById(R.id.center_group), isRot0Landscape, false); + inflateButtons(center, mRot90.findViewById(R.id.center_group), !isRot0Landscape, false); - addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group)); - addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group)); + addGravitySpacer(mRot0.findViewById(R.id.ends_group)); + addGravitySpacer(mRot90.findViewById(R.id.ends_group)); - inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape); - inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape); + inflateButtons(end, mRot0.findViewById(R.id.ends_group), isRot0Landscape, false); + inflateButtons(end, mRot90.findViewById(R.id.ends_group), !isRot0Landscape, false); } private void addGravitySpacer(LinearLayout layout) { layout.addView(new Space(mContext), new LinearLayout.LayoutParams(0, 0, 1)); } - private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape) { + private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape, + boolean start) { for (int i = 0; i < buttons.length; i++) { - inflateButton(buttons[i], parent, landscape); + inflateButton(buttons[i], parent, landscape, start); } } @@ -251,16 +258,13 @@ public class NavigationBarInflaterView extends FrameLayout } @Nullable - protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape) { + protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape, + boolean start) { LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater; - float size = extractSize(buttonSpec); - View v = createView(buttonSpec, parent, inflater, landscape); + View v = createView(buttonSpec, parent, inflater); if (v == null) return null; - if (size != 0) { - ViewGroup.LayoutParams params = v.getLayoutParams(); - params.width = (int) (params.width * size); - } + v = applySize(v, buttonSpec, landscape, start); parent.addView(v); addToDispatchers(v); View lastView = landscape ? mLastLandscape : mLastPortrait; @@ -275,16 +279,41 @@ public class NavigationBarInflaterView extends FrameLayout return v; } - private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater, - boolean landscape) { + private View applySize(View v, String buttonSpec, boolean landscape, boolean start) { + String sizeStr = extractSize(buttonSpec); + if (sizeStr == null) return v; + + if (sizeStr.contains(WEIGHT_SUFFIX)) { + float weight = Float.parseFloat(sizeStr.substring(0, sizeStr.indexOf(WEIGHT_SUFFIX))); + FrameLayout frame = new FrameLayout(mContext); + LayoutParams childParams = new LayoutParams(v.getLayoutParams()); + if (sizeStr.endsWith(WEIGHT_CENTERED_SUFFIX)) { + childParams.gravity = Gravity.CENTER; + } else { + childParams.gravity = landscape ? (start ? Gravity.BOTTOM : Gravity.TOP) + : (start ? Gravity.START : Gravity.END); + } + frame.addView(v, childParams); + frame.setLayoutParams(new LinearLayout.LayoutParams(0, MATCH_PARENT, weight)); + frame.setClipChildren(false); + frame.setClipToPadding(false); + return frame; + } + float size = Float.parseFloat(sizeStr); + ViewGroup.LayoutParams params = v.getLayoutParams(); + params.width = (int) (params.width * size); + return v; + } + + private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater) { View v = null; String button = extractButton(buttonSpec); if (LEFT.equals(button)) { - buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE); - button = extractButton(buttonSpec); + String s = Dependency.get(TunerService.class).getValue(NAV_BAR_LEFT, NAVSPACE); + button = extractButton(s); } else if (RIGHT.equals(button)) { - buttonSpec = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME); - button = extractButton(buttonSpec); + String s = Dependency.get(TunerService.class).getValue(NAV_BAR_RIGHT, MENU_IME); + button = extractButton(s); } // Let plugins go first so they can override a standard view if they want. for (NavBarButtonProvider provider : mPlugins) { @@ -340,13 +369,12 @@ public class NavigationBarInflaterView extends FrameLayout return Integer.parseInt(subStr); } - public static float extractSize(String buttonSpec) { + public static String extractSize(String buttonSpec) { if (!buttonSpec.contains(SIZE_MOD_START)) { - return 1; + return null; } final int sizeStart = buttonSpec.indexOf(SIZE_MOD_START); - String sizeStr = buttonSpec.substring(sizeStart + 1, buttonSpec.indexOf(SIZE_MOD_END)); - return Float.parseFloat(sizeStr); + return buttonSpec.substring(sizeStart + 1, buttonSpec.indexOf(SIZE_MOD_END)); } public static String extractButton(String buttonSpec) { @@ -379,8 +407,8 @@ public class NavigationBarInflaterView extends FrameLayout mButtonDispatchers.valueAt(i).clear(); } } - clearAllChildren((ViewGroup) mRot0.findViewById(R.id.nav_buttons)); - clearAllChildren((ViewGroup) mRot90.findViewById(R.id.nav_buttons)); + clearAllChildren(mRot0.findViewById(R.id.nav_buttons)); + clearAllChildren(mRot90.findViewById(R.id.nav_buttons)); } private void clearAllChildren(ViewGroup group) { -- 2.11.0