Merge "sysui: fix navbar button view orientation" into nyc-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4eaf8c2d9b
@@ -104,9 +104,6 @@
|
|||||||
|
|
||||||
<dimen name="navigation_key_padding">0dp</dimen>
|
<dimen name="navigation_key_padding">0dp</dimen>
|
||||||
|
|
||||||
<dimen name="navigation_key_width_sw600dp_land">162dp</dimen>
|
|
||||||
<dimen name="navigation_key_padding_sw600dp_land">42dp</dimen>
|
|
||||||
|
|
||||||
<!-- The width of the view containing the menu/ime navigation bar icons -->
|
<!-- The width of the view containing the menu/ime navigation bar icons -->
|
||||||
<dimen name="navigation_extra_key_width">36dp</dimen>
|
<dimen name="navigation_extra_key_width">36dp</dimen>
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class ButtonDispatcher {
|
|||||||
private int mImageResource = -1;
|
private int mImageResource = -1;
|
||||||
private Drawable mImageDrawable;
|
private Drawable mImageDrawable;
|
||||||
private View mCurrentView;
|
private View mCurrentView;
|
||||||
|
private boolean mVertical;
|
||||||
|
|
||||||
public ButtonDispatcher(int id) {
|
public ButtonDispatcher(int id) {
|
||||||
mId = id;
|
mId = id;
|
||||||
@@ -49,13 +50,6 @@ public class ButtonDispatcher {
|
|||||||
mViews.clear();
|
mViews.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addView(View view, boolean landscape) {
|
|
||||||
addView(view);
|
|
||||||
if (view instanceof ButtonInterface) {
|
|
||||||
((ButtonInterface) view).setLandscape(landscape);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addView(View view) {
|
void addView(View view) {
|
||||||
mViews.add(view);
|
mViews.add(view);
|
||||||
view.setOnClickListener(mClickListener);
|
view.setOnClickListener(mClickListener);
|
||||||
@@ -75,6 +69,10 @@ public class ButtonDispatcher {
|
|||||||
} else if (mImageDrawable != null) {
|
} else if (mImageDrawable != null) {
|
||||||
((ButtonInterface) view).setImageDrawable(mImageDrawable);
|
((ButtonInterface) view).setImageDrawable(mImageDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (view instanceof ButtonInterface) {
|
||||||
|
((ButtonInterface) view).setVertical(mVertical);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@@ -186,12 +184,13 @@ public class ButtonDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLandscape(boolean landscape) {
|
public void setVertical(boolean vertical) {
|
||||||
|
mVertical = vertical;
|
||||||
final int N = mViews.size();
|
final int N = mViews.size();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
final View view = mViews.get(i);
|
final View view = mViews.get(i);
|
||||||
if (view instanceof ButtonInterface) {
|
if (view instanceof ButtonInterface) {
|
||||||
((ButtonInterface) view).setLandscape(landscape);
|
((ButtonInterface) view).setVertical(vertical);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +205,7 @@ public class ButtonDispatcher {
|
|||||||
|
|
||||||
void abortCurrentGesture();
|
void abortCurrentGesture();
|
||||||
|
|
||||||
void setLandscape(boolean landscape);
|
void setVertical(boolean vertical);
|
||||||
|
|
||||||
void setCarMode(boolean carMode);
|
void setCarMode(boolean carMode);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ package com.android.systemui.statusbar.phone;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.Display.Mode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
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;
|
||||||
@@ -63,12 +65,13 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
|
|
||||||
protected FrameLayout mRot0;
|
protected FrameLayout mRot0;
|
||||||
protected FrameLayout mRot90;
|
protected FrameLayout mRot90;
|
||||||
|
private boolean isRot0Landscape;
|
||||||
|
|
||||||
private SparseArray<ButtonDispatcher> mButtonDispatchers;
|
private SparseArray<ButtonDispatcher> mButtonDispatchers;
|
||||||
private String mCurrentLayout;
|
private String mCurrentLayout;
|
||||||
|
|
||||||
private View mLastRot0;
|
private View mLastPortrait;
|
||||||
private View mLastRot90;
|
private View mLastLandscape;
|
||||||
|
|
||||||
private boolean mAlternativeOrder;
|
private boolean mAlternativeOrder;
|
||||||
|
|
||||||
@@ -76,6 +79,10 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mDensity = context.getResources().getConfiguration().densityDpi;
|
mDensity = context.getResources().getConfiguration().densityDpi;
|
||||||
createInflaters();
|
createInflaters();
|
||||||
|
Display display = ((WindowManager)
|
||||||
|
context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||||
|
Mode displayMode = display.getMode();
|
||||||
|
isRot0Landscape = displayMode.getPhysicalWidth() > displayMode.getPhysicalHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createInflaters() {
|
private void createInflaters() {
|
||||||
@@ -204,17 +211,17 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
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, (ViewGroup) mRot0.findViewById(R.id.ends_group), false);
|
inflateButtons(start, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape);
|
||||||
inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group), true);
|
inflateButtons(start, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape);
|
||||||
|
|
||||||
inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group), false);
|
inflateButtons(center, (ViewGroup) mRot0.findViewById(R.id.center_group), isRot0Landscape);
|
||||||
inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group), true);
|
inflateButtons(center, (ViewGroup) mRot90.findViewById(R.id.center_group), !isRot0Landscape);
|
||||||
|
|
||||||
addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group));
|
addGravitySpacer((LinearLayout) mRot0.findViewById(R.id.ends_group));
|
||||||
addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group));
|
addGravitySpacer((LinearLayout) mRot90.findViewById(R.id.ends_group));
|
||||||
|
|
||||||
inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group), false);
|
inflateButtons(end, (ViewGroup) mRot0.findViewById(R.id.ends_group), isRot0Landscape);
|
||||||
inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group), true);
|
inflateButtons(end, (ViewGroup) mRot90.findViewById(R.id.ends_group), !isRot0Landscape);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGravitySpacer(LinearLayout layout) {
|
private void addGravitySpacer(LinearLayout layout) {
|
||||||
@@ -223,7 +230,7 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
|
|
||||||
private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape) {
|
private void inflateButtons(String[] buttons, ViewGroup parent, boolean landscape) {
|
||||||
for (int i = 0; i < buttons.length; i++) {
|
for (int i = 0; i < buttons.length; i++) {
|
||||||
inflateButton(buttons[i], parent, landscape, i);
|
inflateButton(buttons[i], parent, landscape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,27 +243,17 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape,
|
protected View inflateButton(String buttonSpec, ViewGroup parent, boolean landscape) {
|
||||||
int indexInParent) {
|
|
||||||
LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
|
LayoutInflater inflater = landscape ? mLandscapeInflater : mLayoutInflater;
|
||||||
float size = extractSize(buttonSpec);
|
float size = extractSize(buttonSpec);
|
||||||
String button = extractButton(buttonSpec);
|
String button = extractButton(buttonSpec);
|
||||||
View v = null;
|
View v = null;
|
||||||
if (HOME.equals(button)) {
|
if (HOME.equals(button)) {
|
||||||
v = inflater.inflate(R.layout.home, parent, false);
|
v = inflater.inflate(R.layout.home, parent, false);
|
||||||
if (landscape && isSw600Dp()) {
|
|
||||||
setupLandButton(v);
|
|
||||||
}
|
|
||||||
} else if (BACK.equals(button)) {
|
} else if (BACK.equals(button)) {
|
||||||
v = inflater.inflate(R.layout.back, parent, false);
|
v = inflater.inflate(R.layout.back, parent, false);
|
||||||
if (landscape && isSw600Dp()) {
|
|
||||||
setupLandButton(v);
|
|
||||||
}
|
|
||||||
} else if (RECENT.equals(button)) {
|
} else if (RECENT.equals(button)) {
|
||||||
v = inflater.inflate(R.layout.recent_apps, parent, false);
|
v = inflater.inflate(R.layout.recent_apps, parent, false);
|
||||||
if (landscape && isSw600Dp()) {
|
|
||||||
setupLandButton(v);
|
|
||||||
}
|
|
||||||
} else if (MENU_IME.equals(button)) {
|
} else if (MENU_IME.equals(button)) {
|
||||||
v = inflater.inflate(R.layout.menu_ime, parent, false);
|
v = inflater.inflate(R.layout.menu_ime, parent, false);
|
||||||
} else if (NAVSPACE.equals(button)) {
|
} else if (NAVSPACE.equals(button)) {
|
||||||
@@ -280,15 +277,15 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
params.width = (int) (params.width * size);
|
params.width = (int) (params.width * size);
|
||||||
}
|
}
|
||||||
parent.addView(v);
|
parent.addView(v);
|
||||||
addToDispatchers(v, landscape);
|
addToDispatchers(v);
|
||||||
View lastView = landscape ? mLastRot90 : mLastRot0;
|
View lastView = landscape ? mLastLandscape : mLastPortrait;
|
||||||
if (lastView != null) {
|
if (lastView != null) {
|
||||||
v.setAccessibilityTraversalAfter(lastView.getId());
|
v.setAccessibilityTraversalAfter(lastView.getId());
|
||||||
}
|
}
|
||||||
if (landscape) {
|
if (landscape) {
|
||||||
mLastRot90 = v;
|
mLastLandscape = v;
|
||||||
} else {
|
} else {
|
||||||
mLastRot0 = v;
|
mLastPortrait = v;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
@@ -327,37 +324,22 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi
|
|||||||
return buttonSpec.substring(0, buttonSpec.indexOf(SIZE_MOD_START));
|
return buttonSpec.substring(0, buttonSpec.indexOf(SIZE_MOD_START));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToDispatchers(View v, boolean landscape) {
|
private void addToDispatchers(View v) {
|
||||||
if (mButtonDispatchers != null) {
|
if (mButtonDispatchers != null) {
|
||||||
final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
|
final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
|
||||||
if (indexOfKey >= 0) {
|
if (indexOfKey >= 0) {
|
||||||
mButtonDispatchers.valueAt(indexOfKey).addView(v, landscape);
|
mButtonDispatchers.valueAt(indexOfKey).addView(v);
|
||||||
} else if (v instanceof ViewGroup) {
|
} else if (v instanceof ViewGroup) {
|
||||||
final ViewGroup viewGroup = (ViewGroup)v;
|
final ViewGroup viewGroup = (ViewGroup)v;
|
||||||
final int N = viewGroup.getChildCount();
|
final int N = viewGroup.getChildCount();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
addToDispatchers(viewGroup.getChildAt(i), landscape);
|
addToDispatchers(viewGroup.getChildAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSw600Dp() {
|
|
||||||
Configuration configuration = mContext.getResources().getConfiguration();
|
|
||||||
return (configuration.smallestScreenWidthDp >= 600);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This manually sets the width of sw600dp landscape buttons because despite
|
|
||||||
* overriding the configuration from the overridden resources aren't loaded currently.
|
|
||||||
*/
|
|
||||||
private void setupLandButton(View v) {
|
|
||||||
Resources res = mContext.getResources();
|
|
||||||
v.getLayoutParams().width = res.getDimensionPixelOffset(
|
|
||||||
R.dimen.navigation_key_width_sw600dp_land);
|
|
||||||
int padding = res.getDimensionPixelOffset(R.dimen.navigation_key_padding_sw600dp_land);
|
|
||||||
v.setPadding(padding, v.getPaddingTop(), padding, v.getPaddingBottom());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearViews() {
|
private void clearViews() {
|
||||||
if (mButtonDispatchers != null) {
|
if (mButtonDispatchers != null) {
|
||||||
|
|||||||
@@ -579,7 +579,7 @@ public class NavigationBarView extends LinearLayout {
|
|||||||
updateTaskSwitchHelper();
|
updateTaskSwitchHelper();
|
||||||
setNavigationIconHints(mNavigationIconHints, true);
|
setNavigationIconHints(mNavigationIconHints, true);
|
||||||
|
|
||||||
getHomeButton().setLandscape(mVertical);
|
getHomeButton().setVertical(mVertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTaskSwitchHelper() {
|
private void updateTaskSwitchHelper() {
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ public class KeyButtonView extends ImageView implements ButtonDispatcher.ButtonI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLandscape(boolean landscape) {
|
public void setVertical(boolean vertical) {
|
||||||
//no op
|
//no op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user