[WifiSetup] Update illustration

Update the illustration assets and make the tablet illustration
always 256dp height according to mock.

Bug: 17133710
Change-Id: I6d84bbb25a9f443e4eb6bf4c1002d8a1438029ef
diff --git a/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..428b2f4
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-hdpi/setup_illustration_tile.jpg b/res/drawable-hdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..ed6575c
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..fccea72
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..52e7993
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_tile.jpg b/res/drawable-mdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..9dbe131
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..f21dffb
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_tile.png b/res/drawable-nodpi/setup_illustration_tile.png
deleted file mode 100644
index ae6d244..0000000
--- a/res/drawable-nodpi/setup_illustration_tile.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_wifi_image.jpg b/res/drawable-nodpi/setup_illustration_wifi_image.jpg
index 2579225..a27c93e 100644
--- a/res/drawable-nodpi/setup_illustration_wifi_image.jpg
+++ b/res/drawable-nodpi/setup_illustration_wifi_image.jpg
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg
deleted file mode 100644
index b876fa6..0000000
--- a/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..2733f8e
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_tile.jpg b/res/drawable-xhdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..71dabd5
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..3d1b3f3
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..aec8d0f
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_tile.jpg b/res/drawable-xxhdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..46b3d02
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..6a590b7
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/illustration_tile.jpg b/res/drawable-xxxhdpi/illustration_tile.jpg
new file mode 100644
index 0000000..ab3899e
--- /dev/null
+++ b/res/drawable-xxxhdpi/illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..448a651
--- /dev/null
+++ b/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..d6f2f82
--- /dev/null
+++ b/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable/setup_illustration_wifi_wide.xml b/res/drawable/setup_illustration_wifi_wide.xml
index 3af3561..33ee2f6 100644
--- a/res/drawable/setup_illustration_wifi_wide.xml
+++ b/res/drawable/setup_illustration_wifi_wide.xml
@@ -15,6 +15,19 @@
      limitations under the License.
 -->
 
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:autoMirrored="true"
-    android:src="@drawable/setup_illustration_wifi_wide_image" />
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    android:autoMirrored="true">
+
+    <item>
+        <bitmap android:src="@drawable/setup_illustration_horizontal_tile"
+            android:gravity="top"
+            android:tileModeX="repeat"
+            android:tileModeY="disabled" />
+    </item>
+
+    <item android:id="@+id/illustration_image">
+        <bitmap android:src="@drawable/setup_illustration_wifi_wide_image"
+            android:gravity="top|start" />
+    </item>
+
+</layer-list>
\ No newline at end of file
diff --git a/res/layout-land/setup_preference.xml b/res/layout-land/setup_preference.xml
index b2e1cc7..ce655d6 100644
--- a/res/layout-land/setup_preference.xml
+++ b/res/layout-land/setup_preference.xml
@@ -33,13 +33,14 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="@string/wifi_setup_wizard_title" />
+
     </FrameLayout>
 
     <TextView
         android:id="@+id/wifi_required_info"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginBottom="6dip"
+        android:layout_marginBottom="6dp"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:text="@string/wifi_required_info_text"
         android:visibility="gone" />
diff --git a/res/layout-sw600dp-land/setup_preference.xml b/res/layout-sw600dp-land/setup_preference.xml
index 3d4db3d..2bb8f96 100644
--- a/res/layout-sw600dp-land/setup_preference.xml
+++ b/res/layout-sw600dp-land/setup_preference.xml
@@ -39,6 +39,7 @@
                 style="@style/SetupCardTitle"
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/setup_wizard_tablet_illustration_height"
                 android:layout_weight="6"
                 android:text="@string/wifi_setup_wizard_title"/>
 
diff --git a/res/layout-sw720dp-port/setup_preference.xml b/res/layout-sw600dp/setup_preference.xml
similarity index 94%
rename from res/layout-sw720dp-port/setup_preference.xml
rename to res/layout-sw600dp/setup_preference.xml
index 8d1f53b..1e772d9 100644
--- a/res/layout-sw720dp-port/setup_preference.xml
+++ b/res/layout-sw600dp/setup_preference.xml
@@ -15,9 +15,7 @@
     limitations under the License.
 -->
 
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
@@ -28,12 +26,12 @@
         android:layout_height="0dp"
         android:layout_weight="1"
         android:background="@drawable/setup_illustration_bg"
-        android:foreground="@drawable/setup_illustration_wifi_wide"
-        settings:aspectRatio="4.0">
+        android:foreground="@drawable/setup_illustration_wifi_wide">
 
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
+            android:layout_marginTop="@dimen/setup_wizard_tablet_illustration_height"
             android:orientation="vertical"
             android:paddingLeft="@dimen/setup_wizard_card_port_margin_sides"
             android:paddingRight="@dimen/setup_wizard_card_port_margin_sides">
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index 1aa4b55..5f524af 100755
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -45,7 +45,6 @@
     <!-- Dashboard tile image margin start / end -->
     <dimen name="dashboard_tile_image_margin_start">12dp</dimen>
 
-    <dimen name="setup_wizard_card_title_margin_top">256dp</dimen>
     <dimen name="setup_wizard_card_title_padding_end">32dp</dimen>
     <dimen name="setup_wizard_card_title_padding_start">56dp</dimen>
     <dimen name="setup_wizard_card_title_padding_top">24dp</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index bbe62a5..0baabb8 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -50,7 +50,7 @@
     <dimen name="setup_add_network_item_height">56dp</dimen>
     <dimen name="setup_wizard_card_corner_radius">2dp</dimen>
     <dimen name="setup_wizard_card_elevation">5dp</dimen>
-    <dimen name="setup_wizard_card_title_margin_top">0dp</dimen>
+    <dimen name="setup_wizard_tablet_illustration_height">256dp</dimen>
     <dimen name="setup_wizard_card_title_padding_end">0dp</dimen>
     <dimen name="setup_wizard_card_title_padding_start">0dp</dimen>
     <dimen name="setup_wizard_card_title_padding_top">16dp</dimen>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 3f5f39d..c3d2564 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -176,7 +176,6 @@
 
     <!-- Alternate title style used for some tablet layouts -->
     <style name="SetupCardTitle">
-        <item name="android:layout_marginTop">@dimen/setup_wizard_card_title_margin_top</item>
         <item name="android:paddingBottom">@dimen/setup_wizard_card_title_padding_bottom</item>
         <item name="android:paddingEnd">@dimen/setup_wizard_card_title_padding_end</item>
         <item name="android:paddingStart">@dimen/setup_wizard_card_title_padding_start</item>
diff --git a/src/com/android/settings/widget/SetupWizardIllustration.java b/src/com/android/settings/widget/SetupWizardIllustration.java
index fa8dd80..acdb5b3 100644
--- a/src/com/android/settings/widget/SetupWizardIllustration.java
+++ b/src/com/android/settings/widget/SetupWizardIllustration.java
@@ -20,9 +20,11 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.Gravity;
 import android.widget.FrameLayout;
 
 import com.android.settings.R;
@@ -42,7 +44,8 @@
     private float mBaselineGridSize;
     private Drawable mBackground;
     private Drawable mForeground;
-    private int mForegroundHeight = 0;
+    private final Rect mViewBounds = new Rect();
+    private final Rect mForegroundBounds = new Rect();
     private float mScale = 1.0f;
     private float mAspectRatio = 0.0f;
 
@@ -112,36 +115,35 @@
         final int layoutWidth = right - left;
         final int layoutHeight = bottom - top;
         if (mForeground != null) {
-            final float intrinsicWidth = mForeground.getIntrinsicWidth();
-            final float intrinsicHeight = mForeground.getIntrinsicHeight();
-            if (intrinsicWidth <= 0 || intrinsicHeight <= 0) {
-                Log.e(TAG, "Foreground drawable intrinsic size must be defined and positive");
-                mForeground = null;
-                mForegroundHeight = 0;
-                mScale = 1.0f;
-            } else {
-                // Scale the foreground to fill the width of the view
-                mScale = layoutWidth / intrinsicWidth;
-                mForegroundHeight = (int) (intrinsicHeight * mScale);
-                mForeground.setBounds(0, 0, layoutWidth, mForegroundHeight);
+            int intrinsicWidth = mForeground.getIntrinsicWidth();
+            int intrinsicHeight = mForeground.getIntrinsicHeight();
+            final int layoutDirection = getLayoutDirection();
+
+            mViewBounds.set(0, 0, layoutWidth, layoutHeight);
+            if (mAspectRatio != 0f) {
+                mScale = layoutWidth / (float) intrinsicWidth;
+                intrinsicWidth = layoutWidth;
+                intrinsicHeight = (int) (intrinsicHeight * mScale);
             }
+            Gravity.apply(Gravity.FILL_HORIZONTAL | Gravity.TOP, intrinsicWidth, intrinsicHeight,
+                    mViewBounds, mForegroundBounds, layoutDirection);
+            mForeground.setBounds(mForegroundBounds);
         }
         if (mBackground != null) {
             // Scale the bounds by mScale to compensate for the scale done to the canvas before
             // drawing.
             mBackground.setBounds(0, 0, (int) Math.ceil(layoutWidth / mScale),
-                    (int) Math.ceil((layoutHeight - mForegroundHeight) / mScale));
+                    (int) Math.ceil((layoutHeight - mForegroundBounds.height()) / mScale));
         }
         super.onLayout(changed, left, top, right, bottom);
     }
 
     @Override
     public void onDraw(Canvas canvas) {
-        canvas.save();
         if (mBackground != null) {
             canvas.save();
             // Draw the background filling parts not covered by the illustration
-            canvas.translate(0, mForegroundHeight);
+            canvas.translate(0, mForegroundBounds.height());
             // Scale the background so its size matches the foreground
             canvas.scale(mScale, mScale, 0, 0);
             mBackground.draw(canvas);
@@ -153,7 +155,6 @@
             mForeground.draw(canvas);
             canvas.restore();
         }
-        canvas.restore();
         super.onDraw(canvas);
     }
 }