Honor min and max snackbar widths in 2 pane layouts
b/16395550
When the fab was changed to sit in the TL in 2 pane layout
the min and max widths were never updated to match.
Note: we chose different max widths of the snack bar for
7" and 10" displays.
Change-Id: I8b3e31b4db2c1c721bb32b68b422cb5e36e7bd4e
diff --git a/res/layout-sw600dp/floating_actions.xml b/res/layout-sw600dp/floating_actions.xml
index fed20f9..c98e06c 100644
--- a/res/layout-sw600dp/floating_actions.xml
+++ b/res/layout-sw600dp/floating_actions.xml
@@ -29,19 +29,18 @@
android:visibility="gone">
<LinearLayout
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/description_text"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
+ android:layout_weight="1"
android:layout_marginLeft="@dimen/snack_bar_margin_horizontal"
android:layout_marginRight="@dimen/snack_bar_margin_horizontal"
- android:minWidth="240dp"
- android:maxWidth="350dp"
android:paddingTop="@dimen/snack_bar_margin_vertical"
android:paddingBottom="@dimen/snack_bar_margin_vertical"
android:textColor="@android:color/white" />
diff --git a/res/values-sw600dp/dimen.xml b/res/values-sw600dp/dimen.xml
index 550e444..77d2aa5 100644
--- a/res/values-sw600dp/dimen.xml
+++ b/res/values-sw600dp/dimen.xml
@@ -56,4 +56,7 @@
<dimen name="chip_wrapper_start_padding">64dp</dimen>
<dimen name="action_bar_content_inset_start">60dp</dimen>
+
+ <dimen name="snack_bar_min_width">288dp</dimen>
+ <dimen name="snack_bar_max_width">320dp</dimen>
</resources>
diff --git a/res/values-sw720dp/dimen.xml b/res/values-sw720dp/dimen.xml
new file mode 100644
index 0000000..3b775b3
--- /dev/null
+++ b/res/values-sw720dp/dimen.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2011 Google Inc.
+ Licensed to 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.
+-->
+<resources>
+ <dimen name="snack_bar_max_width">420dp</dimen>
+</resources>
diff --git a/src/com/android/mail/ui/ActionableToastBar.java b/src/com/android/mail/ui/ActionableToastBar.java
index b207da4..f9a8a58 100644
--- a/src/com/android/mail/ui/ActionableToastBar.java
+++ b/src/com/android/mail/ui/ActionableToastBar.java
@@ -88,6 +88,12 @@
* always <tt>null</tt> in two-pane layouts. */
private TextView mMultiLineActionView;
+ /** The minimum width of this view; applicable when description text is very short. */
+ private int mMinWidth;
+
+ /** The maximum width of this view; applicable when description text is long enough to wrap. */
+ private int mMaxWidth;
+
private ToastBarOperation mOperation;
public ActionableToastBar(Context context) {
@@ -104,6 +110,8 @@
mAnimationDuration = getResources().getInteger(R.integer.toast_bar_animation_duration_ms);
mMinToastDuration = getResources().getInteger(R.integer.toast_bar_min_duration_ms);
mMaxToastDuration = getResources().getInteger(R.integer.toast_bar_max_duration_ms);
+ mMinWidth = getResources().getDimensionPixelOffset(R.dimen.snack_bar_min_width);
+ mMaxWidth = getResources().getDimensionPixelOffset(R.dimen.snack_bar_max_width);
mHideToastBarHandler = new Handler();
mHideToastBarRunnable = new Runnable() {
@Override
@@ -150,13 +158,26 @@
// measure the view and its content
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- // if the description does not fit, switch to multi line display if one is present
- final boolean descriptionIsMultiLine = mSingleLineDescriptionView.getLineCount() > 1;
- final boolean haveMultiLineView = mMultiLineDescriptionView != null;
- if (descriptionIsMultiLine && haveMultiLineView) {
- setVisibility(true /* multiLine */, showAction);
+ // if specific views exist to handle the multiline case
+ if (mMultiLineDescriptionView != null) {
+ // if the description does not fit on a single line
+ if (mSingleLineDescriptionView.getLineCount() > 1) {
+ //switch to multi line display views
+ setVisibility(true /* multiLine */, showAction);
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+ } else {
+ // otherwise, adjust the the single line view so wrapping occurs at the desired width
+ // (the total width of the toast bar must always fall between the given min and max
+ // width; if max width cannot accommodate all of the description text, it wraps)
+ if (getMeasuredWidth() < mMinWidth) {
+ widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mMinWidth, MeasureSpec.EXACTLY);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ } else if (getMeasuredWidth() > mMaxWidth) {
+ widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
}
}