New message bar fixes and better undo background.

Fixes b/10705091 by changing strings.
Also provides K backgrounds.
Finally, fixes undo background on K,
making the highlight be the entire area to the
right of the divider. b/11292303.

Change-Id: Ice98f3569274a953c1ef5b859d7ff182466cb9dc
diff --git a/res/drawable-hdpi-v19/panel_undo_holo.9.png b/res/drawable-hdpi-v19/panel_undo_holo.9.png
deleted file mode 100644
index a804a8a..0000000
--- a/res/drawable-hdpi-v19/panel_undo_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/toast_frame_focused.9.png b/res/drawable-hdpi/toast_frame_focused.9.png
new file mode 100644
index 0000000..b0fd972
--- /dev/null
+++ b/res/drawable-hdpi/toast_frame_focused.9.png
Binary files differ
diff --git a/res/drawable-hdpi/toast_frame_normal.9.png b/res/drawable-hdpi/toast_frame_normal.9.png
new file mode 100644
index 0000000..ba89bf2
--- /dev/null
+++ b/res/drawable-hdpi/toast_frame_normal.9.png
Binary files differ
diff --git a/res/drawable-hdpi/toast_frame_pressed.9.png b/res/drawable-hdpi/toast_frame_pressed.9.png
new file mode 100644
index 0000000..f21d795
--- /dev/null
+++ b/res/drawable-hdpi/toast_frame_pressed.9.png
Binary files differ
diff --git a/res/drawable-mdpi-v19/panel_undo_holo.9.png b/res/drawable-mdpi-v19/panel_undo_holo.9.png
deleted file mode 100644
index 778e4e6..0000000
--- a/res/drawable-mdpi-v19/panel_undo_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/toast_frame_focused.9.png b/res/drawable-mdpi/toast_frame_focused.9.png
new file mode 100644
index 0000000..08d0635
--- /dev/null
+++ b/res/drawable-mdpi/toast_frame_focused.9.png
Binary files differ
diff --git a/res/drawable-mdpi/toast_frame_normal.9.png b/res/drawable-mdpi/toast_frame_normal.9.png
new file mode 100644
index 0000000..165494f
--- /dev/null
+++ b/res/drawable-mdpi/toast_frame_normal.9.png
Binary files differ
diff --git a/res/drawable-mdpi/toast_frame_pressed.9.png b/res/drawable-mdpi/toast_frame_pressed.9.png
new file mode 100644
index 0000000..d5a3edf
--- /dev/null
+++ b/res/drawable-mdpi/toast_frame_pressed.9.png
Binary files differ
diff --git a/res/drawable-v19/new_message_toast_background.xml b/res/drawable-v19/new_message_toast_background.xml
new file mode 100644
index 0000000..66f0d9b
--- /dev/null
+++ b/res/drawable-v19/new_message_toast_background.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_window_focused="false"
+          android:state_enabled="true"
+          android:drawable="@drawable/toast_frame_normal" />
+
+    <item android:state_pressed="true"
+          android:drawable="@drawable/toast_frame_pressed" />
+
+    <item android:state_focused="true"
+          android:state_enabled="true"
+          android:drawable="@drawable/toast_frame_focused" />
+
+    <item android:drawable="@drawable/toast_frame_normal" />
+</selector>
diff --git a/res/drawable-xhdpi-v19/panel_undo_holo.9.png b/res/drawable-xhdpi-v19/panel_undo_holo.9.png
deleted file mode 100644
index 77e69c7..0000000
--- a/res/drawable-xhdpi-v19/panel_undo_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/toast_frame_focused.9.png b/res/drawable-xhdpi/toast_frame_focused.9.png
new file mode 100644
index 0000000..479ea6e
--- /dev/null
+++ b/res/drawable-xhdpi/toast_frame_focused.9.png
Binary files differ
diff --git a/res/drawable-xhdpi/toast_frame_normal.9.png b/res/drawable-xhdpi/toast_frame_normal.9.png
new file mode 100644
index 0000000..f696ec4
--- /dev/null
+++ b/res/drawable-xhdpi/toast_frame_normal.9.png
Binary files differ
diff --git a/res/drawable-xhdpi/toast_frame_pressed.9.png b/res/drawable-xhdpi/toast_frame_pressed.9.png
new file mode 100644
index 0000000..79ad140
--- /dev/null
+++ b/res/drawable-xhdpi/toast_frame_pressed.9.png
Binary files differ
diff --git a/res/drawable-xxhdpi-v19/panel_undo_holo.9.png b/res/drawable-xxhdpi-v19/panel_undo_holo.9.png
deleted file mode 100644
index edecb63..0000000
--- a/res/drawable-xxhdpi-v19/panel_undo_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/toast_frame_focused.9.png b/res/drawable-xxhdpi/toast_frame_focused.9.png
new file mode 100644
index 0000000..9509796
--- /dev/null
+++ b/res/drawable-xxhdpi/toast_frame_focused.9.png
Binary files differ
diff --git a/res/drawable-xxhdpi/toast_frame_normal.9.png b/res/drawable-xxhdpi/toast_frame_normal.9.png
new file mode 100644
index 0000000..365bf35
--- /dev/null
+++ b/res/drawable-xxhdpi/toast_frame_normal.9.png
Binary files differ
diff --git a/res/drawable-xxhdpi/toast_frame_pressed.9.png b/res/drawable-xxhdpi/toast_frame_pressed.9.png
new file mode 100644
index 0000000..02a2818
--- /dev/null
+++ b/res/drawable-xxhdpi/toast_frame_pressed.9.png
Binary files differ
diff --git a/res/drawable/btn_default.xml b/res/drawable/new_message_toast_background.xml
similarity index 100%
rename from res/drawable/btn_default.xml
rename to res/drawable/new_message_toast_background.xml
diff --git a/res/drawable/toast_button_background.xml b/res/drawable/toast_button_background.xml
new file mode 100644
index 0000000..0bd9650
--- /dev/null
+++ b/res/drawable/toast_button_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2013 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_pressed="true" android:drawable="@drawable/toast_frame_pressed" />
+    <item android:drawable="@android:color/transparent" />
+</selector>
\ No newline at end of file
diff --git a/res/layout/actionable_toast_row.xml b/res/layout/actionable_toast_row.xml
index 68dc6d0..c9b87d6 100644
--- a/res/layout/actionable_toast_row.xml
+++ b/res/layout/actionable_toast_row.xml
@@ -41,11 +41,11 @@
         android:id="@+id/action_button"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
-        android:background="?android:attr/selectableItemBackground"
-        android:clickable="true" >
+        android:clickable="true"
+        style="@style/ToastButtonStyle" >
 
         <View
-            android:id="@+id/separator"
+            android:id="@+id/divider"
             android:layout_width="1dip"
             android:layout_height="match_parent"
             android:background="#aaaaaa"
diff --git a/res/layout/conversation_topmost_overlay_items.xml b/res/layout/conversation_topmost_overlay_items.xml
index f246eda..2ea6c5f 100644
--- a/res/layout/conversation_topmost_overlay_items.xml
+++ b/res/layout/conversation_topmost_overlay_items.xml
@@ -28,10 +28,12 @@
             android:id="@+id/new_message_notification_bar"
             style="@style/NewMessageButtonStyle"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_gravity="bottom"
+            android:layout_height="48dip"
+            android:layout_gravity="bottom|center_horizontal"
             android:animateLayoutChanges="true"
-            android:paddingLeft="24dp"
-            android:paddingRight="24dp"
+            android:gravity="center"
+            android:paddingLeft="@dimen/new_message_button_padding"
+            android:paddingRight="@dimen/new_message_button_padding"
             android:visibility="gone"/>
+
 </merge>
diff --git a/res/values-ldrtl/styles-ldrtl.xml b/res/values-ldrtl/styles-ldrtl.xml
index 399c2d6..cd736b6 100644
--- a/res/values-ldrtl/styles-ldrtl.xml
+++ b/res/values-ldrtl/styles-ldrtl.xml
@@ -71,8 +71,8 @@
     </style>
 
     <style name="NewMessageButtonStyle" parent="AbstractNewMessageButtonStyle">
-        <item name="android:layout_marginStart">@dimen/conversation_view_margin_side</item>
-        <item name="android:layout_marginEnd">@dimen/conversation_view_margin_side</item>
+        <item name="android:layout_marginStart">@dimen/toast_bar_margin</item>
+        <item name="android:layout_marginEnd">@dimen/toast_bar_margin</item>
     </style>
 
     <style name="ConversationViewSideMarginMinusGradientStyle">
diff --git a/res/values-v19/colors.xml b/res/values-v19/colors.xml
new file mode 100644
index 0000000..f32eca8
--- /dev/null
+++ b/res/values-v19/colors.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Copyright (C) 2013 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>
+    <!-- The color of the new message bar text. -->
+    <color name="new_message_bar_text">@android:color/white</color>
+</resources>
\ No newline at end of file
diff --git a/res/values-v19/dimen.xml b/res/values-v19/dimen.xml
index 0df47d2..318da51 100644
--- a/res/values-v19/dimen.xml
+++ b/res/values-v19/dimen.xml
@@ -19,7 +19,8 @@
     <dimen name="toast_bar_description_icon_padding_start">0dip</dimen>
     <dimen name="toast_bar_description_icon_padding_end">16dip</dimen>
     <dimen name="toast_bar_description_text_padding_start">0dip</dimen>
-    <dimen name="toast_bar_separator_margin_vertical">0dip</dimen>
+    <dimen name="toast_bar_separator_margin_vertical">11dip</dimen>
     <dimen name="toast_bar_undo_text_padding">0dip</dimen>
     <dimen name="toast_bar_margin">24dip</dimen>
+    <dimen name="new_message_button_padding">0dip</dimen>
 </resources>
\ No newline at end of file
diff --git a/res/values-v19/styles.xml b/res/values-v19/styles.xml
new file mode 100644
index 0000000..f34a004
--- /dev/null
+++ b/res/values-v19/styles.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2013 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>
+    <style name="ToastBarStyle" parent="AbstractToastBarStyle">
+        <item name="android:background">@drawable/toast_frame_normal</item>
+        <item name="android:paddingTop">0dip</item>
+        <item name="android:paddingBottom">0dip</item>
+        <item name="android:paddingEnd">0dip</item>
+    </style>
+
+    <style name="ToastButtonStyle">
+        <item name="android:background">@drawable/toast_button_background</item>
+    </style>
+</resources>
\ No newline at end of file
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 12b7065..27b05c3 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -121,4 +121,8 @@
     <color name="vacation_responder_foreground">@android:color/white</color>
     <color name="vacation_responder_background">#ffe9e9e9</color>
     <color name="vacation_responder_spinner_text">#333333</color>
+
+    <!-- The color of the new message bar text. -->
+    <color name="new_message_bar_text">@color/dark_gray_text_color</color>
+
 </resources>
diff --git a/res/values/dimen.xml b/res/values/dimen.xml
index faedfc9..0aadef4 100644
--- a/res/values/dimen.xml
+++ b/res/values/dimen.xml
@@ -148,4 +148,7 @@
     <dimen name="vacation_responder_padding_horizontal_wide">80dip</dimen>
     <dimen name="vacation_responder_inner_padding">12dip</dimen>
     <dimen name="vacation_responder_padding_between_date_spinners">8dip</dimen>
+
+    <dimen name="new_message_button_padding">24dip</dimen>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2f6e9b1..f6aa8d6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -437,10 +437,10 @@
     <string name="add_label">Add folder</string>
 
     <!-- New Message notification text that appears over conversation view on incoming message. [CHAR LIMIT=40] -->
-    <string name="new_incoming_messages_one">New message from <xliff:g id="sender">%s</xliff:g>. Show.</string>
+    <string name="new_incoming_messages_one">Show new message from <xliff:g id="sender">%s</xliff:g>.</string>
     <!-- New Message notification text that appears over conversation view on incoming messages. Will only be used if there is more than one new message. [CHAR LIMIT=40] -->
     <plurals name="new_incoming_messages_many">
-        <item quantity="other"><xliff:g id="count">%1$d</xliff:g> new messages. Show.</item>
+        <item quantity="other">Show <xliff:g id="count">%1$d</xliff:g> new messages.</item>
     </plurals>
 
     <!-- Conversation message header strings -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6bdc6d9..5e7c706 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -417,7 +417,7 @@
     <style name="NotificationSecondaryText">
     </style>
 
-    <style name="ToastBarStyle">
+    <style name="AbstractToastBarStyle">
         <item name="android:layout_width">match_parent</item>
         <item name="android:layout_height">48dip</item>
         <item name="android:layout_gravity">bottom</item>
@@ -432,6 +432,10 @@
         <item name="android:clickable">true</item>
     </style>
 
+    <!-- Overridden in v19 -->
+    <style name="ToastBarStyle" parent="AbstractToastBarStyle">
+    </style>
+
     <style name="AccountSpinnerStyle">
         <item name="android:layout_width">wrap_content</item>
     </style>
@@ -501,15 +505,16 @@
     </style>
 
     <style name="AbstractNewMessageButtonStyle" parent="@android:style/Widget.Holo.Light.Button">
-        <item name="android:background">@drawable/btn_default</item>
+        <item name="android:layout_marginBottom">@dimen/toast_bar_margin</item>
+        <item name="android:background">@drawable/new_message_toast_background</item>
         <item name="android:singleLine">true</item>
-        <item name="android:textColor">@color/dark_gray_text_color</item>
+        <item name="android:textColor">@color/new_message_bar_text</item>
         <item name="android:textSize">14sp</item>
     </style>
 
     <style name="NewMessageButtonStyle" parent="AbstractNewMessageButtonStyle">
-        <item name="android:layout_marginLeft">@dimen/conversation_view_margin_side</item>
-        <item name="android:layout_marginRight">@dimen/conversation_view_margin_side</item>
+        <item name="android:layout_marginLeft">@dimen/toast_bar_margin</item>
+        <item name="android:layout_marginRight">@dimen/toast_bar_margin</item>
     </style>
 
     <style name="DismissButtonStyle">
@@ -753,4 +758,9 @@
         <item name="android:paddingLeft">@dimen/vacation_responder_inner_padding</item>
         <item name="android:paddingRight">@dimen/vacation_responder_inner_padding</item>
     </style>
+
+    <!-- Overridden in v19 -->
+    <style name="ToastButtonStyle">
+        <item name="android:background">?android:attr/selectableItemBackground</item>
+    </style>
 </resources>
diff --git a/src/com/android/mail/ui/ActionableToastBar.java b/src/com/android/mail/ui/ActionableToastBar.java
index e08cbe3..dbccf33 100644
--- a/src/com/android/mail/ui/ActionableToastBar.java
+++ b/src/com/android/mail/ui/ActionableToastBar.java
@@ -17,9 +17,15 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorInflater;
+import android.annotation.SuppressLint;
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.ClipDrawable;
+import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.util.AttributeSet;
+import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -28,6 +34,7 @@
 import android.widget.TextView;
 
 import com.android.mail.R;
+import com.android.mail.utils.Utils;
 
 /**
  * A custom {@link View} that exposes an action to the user.
@@ -46,6 +53,8 @@
     private ImageView mActionDescriptionIcon;
     /** The clickable view */
     private View mActionButton;
+    /** The divider between the description and the action button. */
+    private View mDivider;
     /** Icon for the action button. */
     private View mActionIcon;
     /** The view that contains the description. */
@@ -54,6 +63,10 @@
     private TextView mActionText;
     private ToastBarOperation mOperation;
 
+    private boolean mRtl;
+
+    private ClipBoundsDrawable mButtonDrawable;
+
     public ActionableToastBar(Context context) {
         this(context, null);
     }
@@ -77,14 +90,41 @@
     }
 
     @Override
+    @SuppressLint("NewApi")
     protected void onFinishInflate() {
         super.onFinishInflate();
 
         mActionDescriptionIcon = (ImageView) findViewById(R.id.description_icon);
         mActionDescriptionView = (TextView) findViewById(R.id.description_text);
         mActionButton = findViewById(R.id.action_button);
+        mDivider = findViewById(R.id.divider);
         mActionIcon = findViewById(R.id.action_icon);
         mActionText = (TextView) findViewById(R.id.action_text);
+
+        if (Utils.isRunningKitkatOrLater()) {
+            mRtl = Utils.isLayoutRtl(this);
+
+            // Wrap the drawable so we can clip the bounds (see explanation in onLayout).
+            final Drawable buttonToastBackground = mActionButton.getBackground();
+            mActionButton.setBackground(null);
+            mButtonDrawable = new ClipBoundsDrawable(buttonToastBackground);
+            mActionButton.setBackground(mButtonDrawable);
+        }
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+
+        // The button has the same background on pressed state so it will have rounded corners
+        // on both the right edge. We clip the background before the divider to remove the
+        // rounded edge there, creating a split-pill button effect.
+        if (mButtonDrawable != null) {
+            mButtonDrawable.setClipBounds(
+                    (mRtl ? 0 : mDivider.getLeft()), 0,
+                    (mRtl ? mDivider.getRight() : mActionButton.getWidth()),
+                    mActionButton.getHeight());
+        }
     }
 
     /**
@@ -251,4 +291,36 @@
     public interface ActionClickedListener {
         public void onActionClicked(Context context);
     }
+
+    /**
+     * A wrapper that allows a drawable to be clipped at specific bounds. {@link ClipDrawable} only
+     * supports clipping based on a relative level. This extends {@link ClipDrawable} since it is
+     * the simplest base class that will delegate the rest of the methods to the wrapped drawable.
+     *
+     * <br/><br/><b>Note: Only use on JBMR2 or later as clipRect is not supported until API 18.</b>
+     */
+    private static class ClipBoundsDrawable extends ClipDrawable {
+        private final Drawable mDrawable;
+        private final Rect mClipRect = new Rect();
+
+        public ClipBoundsDrawable(Drawable drawable) {
+            super(drawable, Gravity.START, ClipDrawable.HORIZONTAL);
+            mDrawable = drawable;
+        }
+
+        public void setClipBounds(int left, int top, int right, int bottom) {
+            mClipRect.left = left;
+            mClipRect.top = top;
+            mClipRect.right = right;
+            mClipRect.bottom = bottom;
+        }
+
+        @Override
+        public void draw(Canvas canvas) {
+            canvas.save();
+            canvas.clipRect(mClipRect);
+            mDrawable.draw(canvas);
+            canvas.restore();
+        }
+    }
 }
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index a67facc..407af88 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -1083,7 +1083,6 @@
     *
     * @return normalized Uri (never null)
     * @see {@link android.content.Intent#setData}
-    * @see {@link android.content.Intent#setNormalizedData}
     */
    public static Uri normalizeUri(Uri uri) {
        String scheme = uri.getScheme();
@@ -1500,4 +1499,12 @@
             return email.toLowerCase(Locale.US);
         }
     }
+
+    /**
+     * Determines whether the given view has RTL layout.
+     */
+    public static boolean isLayoutRtl(View view) {
+        return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) ?
+                View.LAYOUT_DIRECTION_RTL == view.getLayoutDirection() : false;
+    }
 }