Some visual fixes for when header is in footer position + proper radius

* Uses the radius value from the theme
* Applies that to the header / permission viewWrapper based on orientation
  of the bubbles
* Also swaps position of the divider when its a footer

Test: manual / visual
      - toggle bubbles to show at bottom with a footer and make sure
        rounded corners are in right place

Change-Id: Ieb6db4aedfda125ddf590876aa8b0ee0ee7fc473
diff --git a/packages/SystemUI/res/drawable/bubble_expanded_header_bg.xml b/packages/SystemUI/res/drawable/bubble_expanded_header_bg.xml
deleted file mode 100644
index a76b7b1..0000000
--- a/packages/SystemUI/res/drawable/bubble_expanded_header_bg.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ Copyright (C) 2018 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
-  -->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
-    <item>
-        <shape android:shape="rectangle">
-            <solid android:color="?android:attr/colorBackgroundFloating"/>
-            <corners
-                    android:topLeftRadius="@dimen/corner_size"
-                    android:topRightRadius="@dimen/corner_size"/>
-        </shape>
-    </item>
-</layer-list>
\ No newline at end of file
diff --git a/packages/SystemUI/res/layout/bubble_expanded_view.xml b/packages/SystemUI/res/layout/bubble_expanded_view.xml
index a8b1b2e..56a3cd5 100644
--- a/packages/SystemUI/res/layout/bubble_expanded_view.xml
+++ b/packages/SystemUI/res/layout/bubble_expanded_view.xml
@@ -29,10 +29,9 @@
 
     <FrameLayout
         android:id="@+id/header_permission_wrapper"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:animateLayoutChanges="true"
-        android:background="@drawable/bubble_expanded_header_bg">
+        android:animateLayoutChanges="true">
 
         <LinearLayout
             android:id="@+id/header_layout"
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
index b635033..22e904f 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java
@@ -39,6 +39,7 @@
 import android.graphics.Insets;
 import android.graphics.Point;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
 import android.graphics.drawable.ShapeDrawable;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -189,6 +190,8 @@
         mPointerView.setBackground(triangleDrawable);
 
         FrameLayout viewWrapper = findViewById(R.id.header_permission_wrapper);
+        viewWrapper.setBackground(createHeaderPermissionBackground(bgColor));
+
         LayoutTransition transition = new LayoutTransition();
         transition.setDuration(200);
 
@@ -204,6 +207,7 @@
         viewWrapper.setLayoutTransition(transition);
         viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
 
+
         mHeaderHeight = getContext().getResources().getDimensionPixelSize(
                 R.dimen.bubble_expanded_header_height);
         mPermissionHeight = getContext().getResources().getDimensionPixelSize(
@@ -243,7 +247,10 @@
         if (!mShowOnTop) {
             removeView(mPointerView);
             if (mUseFooter) {
+                View divider = findViewById(R.id.divider);
+                viewWrapper.removeView(divider);
                 removeView(viewWrapper);
+                addView(divider);
                 addView(viewWrapper);
             }
             addView(mPointerView);
@@ -251,6 +258,25 @@
     }
 
     /**
+     * Creates a background with corners rounded based on how the view is configured to display
+     */
+    private Drawable createHeaderPermissionBackground(int bgColor) {
+        TypedArray ta2 = getContext().obtainStyledAttributes(
+                new int[] {android.R.attr.dialogCornerRadius});
+        final float cr = ta2.getDimension(0, 0f);
+        ta2.recycle();
+
+        float[] radii = mUseFooter
+                ? new float[] {0, 0, 0, 0, cr, cr, cr, cr}
+                : new float[] {cr, cr, cr, cr, 0, 0, 0, 0};
+        GradientDrawable chromeBackground = new GradientDrawable();
+        chromeBackground.setShape(GradientDrawable.RECTANGLE);
+        chromeBackground.setCornerRadii(radii);
+        chromeBackground.setColor(bgColor);
+        return chromeBackground;
+    }
+
+    /**
      * Sets the listener to notify when a bubble has been blocked.
      */
     public void setOnBlockedListener(OnBubbleBlockedListener listener) {