grand unified toast bar sizing

Death to constants.

Bug: 8872920
Change-Id: Ic90ddac4b741ec57dd59aadf4d3d426d9813e105
diff --git a/res/values-sw600dp-land/constants.xml b/res/values-sw600dp-land/constants.xml
index ddddcae..714ce00 100644
--- a/res/values-sw600dp-land/constants.xml
+++ b/res/values-sw600dp-land/constants.xml
@@ -18,11 +18,6 @@
     <!-- Whether to show conversation subject in conversation view -->
     <bool name="show_conversation_subject">false</bool>
 
-    <dimen name="undo_bar_width_list">718dp</dimen>
-    <dimen name="undo_bar_width_conv">600dp</dimen>
-    <dimen name="undo_bar_width_conv_list">360dp</dimen>
-    <dimen name="undo_bar_width_search_list">380dp</dimen>
-
     <!-- Whether the list is collapsed in conversation view mode -->
     <bool name="list_collapsed">false</bool>
     <!-- Whether to show single or 2 pane search results -->
diff --git a/res/values-sw600dp/constants.xml b/res/values-sw600dp/constants.xml
index b41b7fa..f8ecaf0 100644
--- a/res/values-sw600dp/constants.xml
+++ b/res/values-sw600dp/constants.xml
@@ -33,8 +33,4 @@
     <!-- Whether to show the archive item as disabled rather than hiding it entirely -->
     <bool name="show_disabled_archive_menu_item">false</bool>
 
-    <dimen name="undo_bar_width_list">400dp</dimen>
-    <dimen name="undo_bar_width_conv">600dp</dimen>
-    <dimen name="undo_bar_width_conv_list">600dp</dimen>
-    <dimen name="undo_bar_width_search_list">600dp</dimen>
 </resources>
diff --git a/res/values-sw720dp-land/constants.xml b/res/values-sw720dp-land/constants.xml
index 00158cd..b643d82 100644
--- a/res/values-sw720dp-land/constants.xml
+++ b/res/values-sw720dp-land/constants.xml
@@ -22,11 +22,6 @@
     <!-- Whether to show single or 2 pane search results -->
     <bool name="show_two_pane_search_results">true</bool>
 
-    <dimen name="undo_bar_width_list">960dp</dimen>
-    <dimen name="undo_bar_width_conv">844dp</dimen>
-    <dimen name="undo_bar_width_conv_list">426dp</dimen>
-    <dimen name="undo_bar_width_search_list">400dp</dimen>
-
     <!-- Whether to show the priority indicator inline with the senders in conversation list view.
         Wide mode on 10" tablet is the only place we currently don't do this -->
     <bool name="inline_personal_level">false</bool>
diff --git a/res/values-sw720dp/dimen.xml b/res/values-sw720dp/dimen.xml
index 4516dc4..b018380 100644
--- a/res/values-sw720dp/dimen.xml
+++ b/res/values-sw720dp/dimen.xml
@@ -16,8 +16,4 @@
      limitations under the License.
 -->
 <resources>
-    <dimen name="undo_bar_width_list">600dp</dimen>
-    <dimen name="undo_bar_width_conv">800dp</dimen>
-    <dimen name="undo_bar_width_conv_list">800dp</dimen>
-    <dimen name="undo_bar_width_search_list">800dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 2a04877..510fd9e 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -449,26 +449,6 @@
                 && shouldEnterSearchConvMode();
     }
 
-    private int getUndoBarWidth(int mode, ToastBarOperation op) {
-        int resId = -1;
-        switch (mode) {
-            case ViewMode.SEARCH_RESULTS_LIST:
-                resId = R.dimen.undo_bar_width_search_list;
-                break;
-            case ViewMode.CONVERSATION_LIST:
-                resId = R.dimen.undo_bar_width_list;
-                break;
-            case ViewMode.SEARCH_RESULTS_CONVERSATION:
-            case ViewMode.CONVERSATION:
-                if (op.isBatchUndo() && !mLayout.isConversationListCollapsed()) {
-                    resId = R.dimen.undo_bar_width_conv_list;
-                } else {
-                    resId = R.dimen.undo_bar_width_conv;
-                }
-        }
-        return resId != -1 ? (int) mContext.getResources().getDimension(resId) : -1;
-    }
-
     @Override
     public void onUndoAvailable(ToastBarOperation op) {
         final int mode = mViewMode.getMode();
@@ -506,30 +486,43 @@
     }
 
     public void repositionToastBar(ToastBarOperation op) {
+        repositionToastBar(op.isBatchUndo());
+    }
+
+    /**
+     * Set the toast bar's layout params to position it in the right place
+     * depending the current view mode.
+     *
+     * @param convModeShowInList if we're in conversation mode, should the toast
+     *            bar appear over the list? no effect when not in conversation mode.
+     */
+    private void repositionToastBar(boolean convModeShowInList) {
         final int mode = mViewMode.getMode();
         final FrameLayout.LayoutParams params =
                 (FrameLayout.LayoutParams) mToastBar.getLayoutParams();
-        int undoBarWidth = getUndoBarWidth(mode, op);
         switch (mode) {
             case ViewMode.SEARCH_RESULTS_LIST:
             case ViewMode.CONVERSATION_LIST:
-                params.width = undoBarWidth - params.leftMargin - params.rightMargin;
+                params.width = mLayout.computeConversationListWidth() - params.leftMargin
+                        - params.rightMargin;
                 params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
                 mToastBar.setLayoutParams(params);
                 mToastBar.setConversationMode(false);
                 break;
             case ViewMode.SEARCH_RESULTS_CONVERSATION:
             case ViewMode.CONVERSATION:
-                if (op.isBatchUndo() && !mLayout.isConversationListCollapsed()) {
+                if (convModeShowInList && !mLayout.isConversationListCollapsed()) {
                     // Show undo bar in the conversation list.
                     params.gravity = Gravity.BOTTOM | Gravity.LEFT;
-                    params.width = undoBarWidth - params.leftMargin - params.rightMargin;
+                    params.width = mLayout.computeConversationListWidth() - params.leftMargin
+                            - params.rightMargin;
                     mToastBar.setLayoutParams(params);
                     mToastBar.setConversationMode(false);
                 } else {
                     // Show undo bar in the conversation.
                     params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
-                    params.width = undoBarWidth - params.leftMargin - params.rightMargin;
+                    params.width = mLayout.computeConversationWidth() - params.leftMargin
+                            - params.rightMargin;
                     mToastBar.setLayoutParams(params);
                     mToastBar.setConversationMode(true);
                 }
@@ -558,27 +551,7 @@
 
     @Override
     public void onError(final Folder folder, boolean replaceVisibleToast) {
-        final int mode = mViewMode.getMode();
-        final FrameLayout.LayoutParams params =
-                (FrameLayout.LayoutParams) mToastBar.getLayoutParams();
-        switch (mode) {
-            case ViewMode.SEARCH_RESULTS_LIST:
-            case ViewMode.CONVERSATION_LIST:
-                params.width = mLayout.computeConversationListWidth()
-                        - params.leftMargin - params.rightMargin;
-                params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
-                mToastBar.setLayoutParams(params);
-                break;
-            case ViewMode.SEARCH_RESULTS_CONVERSATION:
-            case ViewMode.CONVERSATION:
-                // Show error bar in the conversation list.
-                params.gravity = Gravity.BOTTOM | Gravity.LEFT;
-                params.width = mLayout.computeConversationListWidth()
-                        - params.leftMargin - params.rightMargin;
-                mToastBar.setLayoutParams(params);
-                break;
-        }
-
+        repositionToastBar(true /* convModeShowInList */);
         showErrorToast(folder, replaceVisibleToast);
     }
 
diff --git a/src/com/android/mail/ui/TwoPaneLayout.java b/src/com/android/mail/ui/TwoPaneLayout.java
index 8ff45ef..640f1e7 100644
--- a/src/com/android/mail/ui/TwoPaneLayout.java
+++ b/src/com/android/mail/ui/TwoPaneLayout.java
@@ -427,7 +427,7 @@
     /**
      * Computes the width of the conversation list in stable state of the current mode.
      */
-    protected int computeConversationListWidth() {
+    public int computeConversationListWidth() {
         return computeConversationListWidth(getMeasuredWidth());
     }
 
@@ -447,6 +447,10 @@
         return 0;
     }
 
+    public int computeConversationWidth() {
+        return computeConversationWidth(getMeasuredWidth());
+    }
+
     /**
      * Computes the width of the conversation pane in stable state of the
      * current mode.