Merge "Style floating toolbar."
diff --git a/core/java/com/android/internal/widget/FloatingToolbar.java b/core/java/com/android/internal/widget/FloatingToolbar.java
index 2219ad1..0b1e0e5 100644
--- a/core/java/com/android/internal/widget/FloatingToolbar.java
+++ b/core/java/com/android/internal/widget/FloatingToolbar.java
@@ -203,8 +203,8 @@
if (mContentRect.top > mPopup.getHeight()) {
y = mContentRect.top - mPopup.getHeight();
mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_UP;
- } else if (mContentRect.top > getEstimatedToolbarHeight(mContext)) {
- y = mContentRect.top - getEstimatedToolbarHeight(mContext);
+ } else if (mContentRect.top > mPopup.getToolbarHeightWithVerticalMargin()) {
+ y = mContentRect.top - mPopup.getToolbarHeightWithVerticalMargin();
mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_DOWN;
} else {
y = mContentRect.bottom;
@@ -264,7 +264,8 @@
private final View mParent;
private final PopupWindow mPopupWindow;
private final ViewGroup mContentContainer;
- private final int mPadding;
+ private final int mMarginHorizontal;
+ private final int mMarginVertical;
private final Animation.AnimationListener mOnOverflowOpened =
new Animation.AnimationListener() {
@@ -365,7 +366,10 @@
.TOUCHABLE_INSETS_REGION);
}
});
- mPadding = parent.getResources().getDimensionPixelSize(R.dimen.floating_toolbar_margin);
+ mMarginHorizontal = parent.getResources()
+ .getDimensionPixelSize(R.dimen.floating_toolbar_horizontal_margin);
+ mMarginVertical = parent.getResources()
+ .getDimensionPixelSize(R.dimen.floating_toolbar_vertical_margin);
}
/**
@@ -474,6 +478,10 @@
return mContentContainer.getContext();
}
+ int getToolbarHeightWithVerticalMargin() {
+ return getEstimatedToolbarHeight(mParent.getContext()) + mMarginVertical * 2;
+ }
+
/**
* Performs the "grow and fade in from the bottom" animation on the floating popup.
*/
@@ -506,7 +514,7 @@
mMainPanel.fadeOut(true);
Size overflowPanelSize = mOverflowPanel.measure();
- final int targetWidth = getOverflowWidth(mParent.getContext());
+ final int targetWidth = overflowPanelSize.getWidth();
final int targetHeight = overflowPanelSize.getHeight();
final boolean morphUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP);
final int startWidth = mContentContainer.getWidth();
@@ -624,10 +632,14 @@
// Make sure the main panel is at the correct position.
if (mContentContainer.getChildAt(0) == mMainPanel.getView()) {
- mContentContainer.setX(mPadding);
- float y = mPadding;
+ float x = mPopupWindow.getWidth()
+ - (mMainPanel.getView().getMeasuredWidth() + mMarginHorizontal);
+ mContentContainer.setX(x);
+
+ float y = mMarginVertical;
if (mOverflowDirection == OVERFLOW_DIRECTION_UP) {
- y = getHeight() - getEstimatedToolbarHeight(mParent.getContext()) - mPadding;
+ y = getHeight()
+ - (mMainPanel.getView().getMeasuredHeight() + mMarginVertical);
}
mContentContainer.setY(y);
}
@@ -661,8 +673,8 @@
width = Math.max(width, overflowPanelSize.getWidth());
height = Math.max(height, overflowPanelSize.getHeight());
}
- mPopupWindow.setWidth(width + mPadding * 2);
- mPopupWindow.setHeight(height + mPadding * 2);
+ mPopupWindow.setWidth(width + mMarginHorizontal * 2);
+ mPopupWindow.setHeight(height + mMarginVertical * 2);
}
/**
@@ -748,22 +760,22 @@
final MenuItem menuItem = remainingMenuItems.peek();
Button menuItemButton = createMenuItemButton(mContext, menuItem);
- // Adding additional left padding for the first button to even out button spacing.
+ // Adding additional start padding for the first button to even out button spacing.
if (isFirstItem) {
- menuItemButton.setPadding(
- 2 * menuItemButton.getPaddingLeft(),
+ menuItemButton.setPaddingRelative(
+ (int) (1.5 * menuItemButton.getPaddingStart()),
menuItemButton.getPaddingTop(),
- menuItemButton.getPaddingRight(),
+ menuItemButton.getPaddingEnd(),
menuItemButton.getPaddingBottom());
isFirstItem = false;
}
- // Adding additional right padding for the last button to even out button spacing.
+ // Adding additional end padding for the last button to even out button spacing.
if (remainingMenuItems.size() == 1) {
- menuItemButton.setPadding(
- menuItemButton.getPaddingLeft(),
+ menuItemButton.setPaddingRelative(
+ menuItemButton.getPaddingStart(),
menuItemButton.getPaddingTop(),
- 2 * menuItemButton.getPaddingRight(),
+ (int) (1.5 * menuItemButton.getPaddingEnd()),
menuItemButton.getPaddingBottom());
}
@@ -836,10 +848,12 @@
private final ViewGroup mBackButtonContainer;
private final View mBackButton;
private final ListView mListView;
+ private final TextView mListViewItemWidthCalculator;
private final ViewFader mViewFader;
private final Runnable mCloseOverflow;
private MenuItem.OnMenuItemClickListener mOnMenuItemClickListener;
+ private int mOverflowWidth = 0;
/**
* Initializes a floating toolbar popup overflow view panel.
@@ -865,7 +879,7 @@
mBackButtonContainer = new LinearLayout(context);
mBackButtonContainer.addView(mBackButton);
- mListView = createOverflowListView(context);
+ mListView = createOverflowListView();
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@@ -878,6 +892,10 @@
mContentView.addView(mListView);
mContentView.addView(mBackButtonContainer);
+
+ mListViewItemWidthCalculator = createOverflowMenuItemButton(context);
+ mListViewItemWidthCalculator.setLayoutParams(new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
/**
@@ -888,6 +906,7 @@
overflowListViewAdapter.clear();
overflowListViewAdapter.addAll(menuItems);
setListViewHeight();
+ setOverflowWidth();
}
public void setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener listener) {
@@ -943,7 +962,21 @@
mListView.setLayoutParams(params);
}
- private static ListView createOverflowListView(final Context context) {
+ private int setOverflowWidth() {
+ for (int i = 0; i < mListView.getAdapter().getCount(); i++) {
+ MenuItem menuItem = (MenuItem) mListView.getAdapter().getItem(i);
+ Preconditions.checkNotNull(menuItem);
+ mListViewItemWidthCalculator.setText(menuItem.getTitle());
+ mListViewItemWidthCalculator.measure(
+ MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
+ mOverflowWidth = Math.max(
+ mListViewItemWidthCalculator.getMeasuredWidth(), mOverflowWidth);
+ }
+ return mOverflowWidth;
+ }
+
+ private ListView createOverflowListView() {
+ final Context context = mContentView.getContext();
final ListView overflowListView = new ListView(context);
overflowListView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
@@ -962,6 +995,7 @@
MenuItem menuItem = getItem(position);
menuButton.setText(menuItem.getTitle());
menuButton.setContentDescription(menuItem.getTitle());
+ menuButton.setMinimumWidth(mOverflowWidth);
return menuButton;
}
};
@@ -1077,11 +1111,6 @@
return shrinkFadeOutFromBottomAnimation;
}
- private static int getOverflowWidth(Context context) {
- return context.getResources()
- .getDimensionPixelSize(R.dimen.floating_toolbar_overflow_width);
- }
-
private static int getEstimatedToolbarHeight(Context context) {
return context.getResources().getDimensionPixelSize(R.dimen.floating_toolbar_height);
}
diff --git a/core/res/res/layout/floating_popup_container.xml b/core/res/res/layout/floating_popup_container.xml
index f247919..e1af94c 100644
--- a/core/res/res/layout/floating_popup_container.xml
+++ b/core/res/res/layout/floating_popup_container.xml
@@ -19,7 +19,9 @@
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="@dimen/floating_toolbar_height"
+ android:padding="0dp"
+ android:layout_margin="0dp"
android:elevation="2dp"
android:focusable="true"
android:focusableInTouchMode="true"
- android:background="@android:color/background_light" />
+ android:background="@color/floating_toolbar_background_color"/>
diff --git a/core/res/res/layout/floating_popup_menu_button.xml b/core/res/res/layout/floating_popup_menu_button.xml
index 9fa13bd..70227fa 100644
--- a/core/res/res/layout/floating_popup_menu_button.xml
+++ b/core/res/res/layout/floating_popup_menu_button.xml
@@ -19,13 +19,15 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:minWidth="@dimen/floating_toolbar_menu_button_side_padding"
- android:paddingLeft="@dimen/floating_toolbar_menu_button_side_padding"
- android:paddingRight="@dimen/floating_toolbar_menu_button_side_padding"
+ android:paddingStart="@dimen/floating_toolbar_menu_button_side_padding"
+ android:paddingEnd="@dimen/floating_toolbar_menu_button_side_padding"
android:paddingTop="0dp"
android:paddingBottom="0dp"
+ android:layout_margin="0dp"
android:singleLine="true"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="@dimen/floating_toolbar_text_size"
android:textAllCaps="true"
- android:background="?attr/selectableItemBackground" />
\ No newline at end of file
+ android:textColor="@color/floating_toolbar_text_color"
+ android:background="?attr/selectableItemBackground" />
diff --git a/core/res/res/layout/floating_popup_overflow_list_item b/core/res/res/layout/floating_popup_overflow_list_item
index 9294f3b..c0db1bd 100644
--- a/core/res/res/layout/floating_popup_overflow_list_item
+++ b/core/res/res/layout/floating_popup_overflow_list_item
@@ -22,12 +22,14 @@
android:gravity="center_vertical"
android:minWidth="@dimen/floating_toolbar_menu_button_side_padding"
android:minHeight="@dimen/floating_toolbar_height"
- android:paddingLeft="@dimen/floating_toolbar_menu_button_side_padding"
- android:paddingRight="@dimen/floating_toolbar_menu_button_side_padding"
+ android:paddingStart="@dimen/floating_toolbar_overflow_side_padding"
+ android:paddingEnd="@dimen/floating_toolbar_overflow_side_padding"
android:paddingTop="0dp"
android:paddingBottom="0dp"
+ android:layout_margin="0dp"
android:singleLine="true"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:textSize="@dimen/floating_toolbar_text_size"
+ android:textColor="@color/floating_toolbar_text_color"
android:textAllCaps="true" />
diff --git a/core/res/res/values/colors.xml b/core/res/res/values/colors.xml
index b9825c5..f1d2242 100644
--- a/core/res/res/values/colors.xml
+++ b/core/res/res/values/colors.xml
@@ -174,4 +174,8 @@
<color name="Pink_800">#ffad1457</color>
<color name="Red_700">#ffc53929</color>
<color name="Red_800">#ffb93221</color>
+
+ <!-- Floating toolbar colors -->
+ <color name="floating_toolbar_text_color">#DD000000</color>
+ <color name="floating_toolbar_background_color">#FAFAFA</color>
</resources>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 100b161..bbba712 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -387,12 +387,14 @@
<!-- Floating toolbar dimensions -->
<dimen name="floating_toolbar_height">48dp</dimen>
- <dimen name="floating_toolbar_menu_button_side_padding">8dp</dimen>
+ <dimen name="floating_toolbar_menu_button_side_padding">16dp</dimen>
+ <dimen name="floating_toolbar_overflow_side_padding">18dp</dimen>
<dimen name="floating_toolbar_text_size">14sp</dimen>
<dimen name="floating_toolbar_menu_button_minimum_width">48dp</dimen>
- <dimen name="floating_toolbar_default_width">250dp</dimen>
- <dimen name="floating_toolbar_minimum_overflow_height">192dp</dimen>
- <dimen name="floating_toolbar_overflow_width">130dp</dimen>
- <dimen name="floating_toolbar_margin">2dp</dimen>
+ <dimen name="floating_toolbar_default_width">264dp</dimen>
+ <dimen name="floating_toolbar_minimum_overflow_height">144dp</dimen>
+ <dimen name="floating_toolbar_horizontal_margin">16dp</dimen>
+ <dimen name="floating_toolbar_vertical_margin">8dp</dimen>
+
<dimen name="chooser_grid_padding">0dp</dimen>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index f6471e1..d4e502a 100755
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2223,12 +2223,13 @@
<java-symbol type="layout" name="floating_popup_overflow_list_item" />
<java-symbol type="dimen" name="floating_toolbar_height" />
<java-symbol type="dimen" name="floating_toolbar_menu_button_side_padding" />
+ <java-symbol type="dimen" name="floating_toolbar_overflow_side_padding" />
<java-symbol type="dimen" name="floating_toolbar_text_size" />
<java-symbol type="dimen" name="floating_toolbar_menu_button_minimum_width" />
<java-symbol type="dimen" name="floating_toolbar_default_width" />
<java-symbol type="dimen" name="floating_toolbar_minimum_overflow_height" />
- <java-symbol type="dimen" name="floating_toolbar_overflow_width" />
- <java-symbol type="dimen" name="floating_toolbar_margin" />
+ <java-symbol type="dimen" name="floating_toolbar_horizontal_margin" />
+ <java-symbol type="dimen" name="floating_toolbar_vertical_margin" />
<java-symbol type="drawable" name="ic_chevron_left" />
<java-symbol type="drawable" name="ic_chevron_right" />