Merge "Support icons in the FloatingToolbar" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
da1b398173
@@ -26,6 +26,7 @@ import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Size;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -44,6 +45,7 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.PopupWindow;
|
||||
@@ -902,7 +904,7 @@ public final class FloatingToolbar {
|
||||
boolean isFirstItem = true;
|
||||
while (!remainingMenuItems.isEmpty()) {
|
||||
final MenuItem menuItem = remainingMenuItems.peek();
|
||||
Button menuItemButton = createMenuItemButton(mContext, menuItem);
|
||||
View menuItemButton = createMenuItemButton(mContext, menuItem);
|
||||
|
||||
// Adding additional start padding for the first button to even out button spacing.
|
||||
if (isFirstItem) {
|
||||
@@ -926,8 +928,7 @@ public final class FloatingToolbar {
|
||||
menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
||||
int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
|
||||
if (menuItemButtonWidth <= availableWidth) {
|
||||
menuItemButton.setTag(menuItem);
|
||||
menuItemButton.setOnClickListener(mMenuItemButtonOnClickListener);
|
||||
setButtonTagAndClickListener(menuItemButton, menuItem);
|
||||
mContentView.addView(menuItemButton);
|
||||
ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
|
||||
params.width = menuItemButtonWidth;
|
||||
@@ -936,7 +937,7 @@ public final class FloatingToolbar {
|
||||
remainingMenuItems.pop();
|
||||
} else {
|
||||
if (mOpenOverflowButton == null) {
|
||||
mOpenOverflowButton = (ImageButton) LayoutInflater.from(mContext)
|
||||
mOpenOverflowButton = LayoutInflater.from(mContext)
|
||||
.inflate(R.layout.floating_popup_open_overflow_button, null);
|
||||
mOpenOverflowButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -980,6 +981,15 @@ public final class FloatingToolbar {
|
||||
mContentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
|
||||
return new Size(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight());
|
||||
}
|
||||
|
||||
private void setButtonTagAndClickListener(View menuItemButton, MenuItem menuItem) {
|
||||
View button = menuItemButton;
|
||||
if (isIconOnlyMenuItem(menuItem)) {
|
||||
button = menuItemButton.findViewById(R.id.floating_toolbar_menu_item_image_button);
|
||||
}
|
||||
button.setTag(menuItem);
|
||||
button.setOnClickListener(mMenuItemButtonOnClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1141,10 +1151,34 @@ public final class FloatingToolbar {
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
overflowListView.setDivider(null);
|
||||
overflowListView.setDividerHeight(0);
|
||||
|
||||
final int viewTypeCount = 2;
|
||||
final int stringLabelViewType = 0;
|
||||
final int iconOnlyViewType = 1;
|
||||
final ArrayAdapter overflowListViewAdapter =
|
||||
new ArrayAdapter<MenuItem>(context, 0) {
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return viewTypeCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (isIconOnlyMenuItem(getItem(position))) {
|
||||
return iconOnlyViewType;
|
||||
}
|
||||
return stringLabelViewType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (getItemViewType(position) == iconOnlyViewType) {
|
||||
return getIconOnlyView(position, convertView);
|
||||
}
|
||||
return getStringTitleView(position, convertView);
|
||||
}
|
||||
|
||||
private View getStringTitleView(int position, View convertView) {
|
||||
TextView menuButton;
|
||||
if (convertView != null) {
|
||||
menuButton = (TextView) convertView;
|
||||
@@ -1157,6 +1191,22 @@ public final class FloatingToolbar {
|
||||
menuButton.setMinimumWidth(mOverflowWidth);
|
||||
return menuButton;
|
||||
}
|
||||
|
||||
private View getIconOnlyView(int position, View convertView) {
|
||||
View menuButton;
|
||||
if (convertView != null) {
|
||||
menuButton = convertView;
|
||||
} else {
|
||||
menuButton = LayoutInflater.from(context).inflate(
|
||||
R.layout.floating_popup_overflow_image_list_item, null);
|
||||
}
|
||||
MenuItem menuItem = getItem(position);
|
||||
((ImageView) menuButton
|
||||
.findViewById(R.id.floating_toolbar_menu_item_image_button))
|
||||
.setImageDrawable(menuItem.getIcon());
|
||||
menuButton.setMinimumWidth(mOverflowWidth);
|
||||
return menuButton;
|
||||
}
|
||||
};
|
||||
overflowListView.setAdapter(overflowListViewAdapter);
|
||||
return overflowListView;
|
||||
@@ -1208,11 +1258,30 @@ public final class FloatingToolbar {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the menu item does not not have a string title but has an icon.
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
private static boolean isIconOnlyMenuItem(MenuItem menuItem) {
|
||||
if (TextUtils.isEmpty(menuItem.getTitle()) && menuItem.getIcon() != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a menu button for the specified menu item.
|
||||
*/
|
||||
private static Button createMenuItemButton(Context context, MenuItem menuItem) {
|
||||
private static View createMenuItemButton(Context context, MenuItem menuItem) {
|
||||
if (isIconOnlyMenuItem(menuItem)) {
|
||||
View imageMenuItemButton = LayoutInflater.from(context)
|
||||
.inflate(R.layout.floating_popup_menu_image_button, null);
|
||||
((ImageButton) imageMenuItemButton
|
||||
.findViewById(R.id.floating_toolbar_menu_item_image_button))
|
||||
.setImageDrawable(menuItem.getIcon());
|
||||
return imageMenuItemButton;
|
||||
}
|
||||
|
||||
Button menuItemButton = (Button) LayoutInflater.from(context)
|
||||
.inflate(R.layout.floating_popup_menu_button, null);
|
||||
menuItemButton.setText(menuItem.getTitle());
|
||||
|
||||
32
core/res/res/layout/floating_popup_menu_image_button.xml
Normal file
32
core/res/res/layout/floating_popup_menu_image_button.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/* Copyright 2015, 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.
|
||||
*/
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:layout_height="@dimen/floating_toolbar_height"
|
||||
android:minWidth="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:minHeight="@dimen/floating_toolbar_height"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:importantForAccessibility="no">
|
||||
<ImageButton
|
||||
android:id="@+id/floating_toolbar_menu_item_image_button"
|
||||
android:layout_width="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:layout_height="@dimen/floating_toolbar_height"
|
||||
android:scaleType="centerInside"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/* Copyright 2015, 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.
|
||||
*/
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:layout_height="@dimen/floating_toolbar_height"
|
||||
android:minWidth="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:minHeight="@dimen/floating_toolbar_height"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:importantForAccessibility="no">
|
||||
<ImageView
|
||||
android:id="@+id/floating_toolbar_menu_item_image_button"
|
||||
android:layout_width="@dimen/floating_toolbar_menu_button_minimum_width"
|
||||
android:layout_height="@dimen/floating_toolbar_height"
|
||||
android:layout_marginStart="18dp"
|
||||
android:scaleType="centerInside"/>
|
||||
</LinearLayout>
|
||||
@@ -94,6 +94,7 @@
|
||||
<item type="id" name="redo" />
|
||||
<item type="id" name="replaceText" />
|
||||
<item type="id" name="shareText" />
|
||||
<item type="id" name="floating_toolbar_menu_item_image_button" />
|
||||
|
||||
<!-- Accessibility action identifier for {@link android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction#ACTION_SHOW_ON_SCREEN}. -->
|
||||
<item type="id" name="accessibilityActionShowOnScreen" />
|
||||
|
||||
@@ -2243,11 +2243,14 @@
|
||||
<java-symbol type="drawable" name="ic_usb_48dp" />
|
||||
|
||||
<!-- Floating toolbar -->
|
||||
<java-symbol type="id" name="floating_toolbar_menu_item_image_button" />
|
||||
<java-symbol type="layout" name="floating_popup_container" />
|
||||
<java-symbol type="layout" name="floating_popup_menu_button" />
|
||||
<java-symbol type="layout" name="floating_popup_open_overflow_button" />
|
||||
<java-symbol type="layout" name="floating_popup_close_overflow_button" />
|
||||
<java-symbol type="layout" name="floating_popup_menu_image_button" />
|
||||
<java-symbol type="layout" name="floating_popup_overflow_list_item" />
|
||||
<java-symbol type="layout" name="floating_popup_overflow_image_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" />
|
||||
|
||||
Reference in New Issue
Block a user