Adds the lightning badge for Instant Apps

Adds the lightning bolt badge for Instant Apps to the
InstalledAppDetails page.

Test: Robolectric test to ensure the badge is shown for Instant Apps
and also that it is not shown for installed apps.

Bug: 36512295
Change-Id: I8496d684fa3a9dc316fa5af16399e6d07f68255a
(cherry picked from commit 2400d31651142214159ec571064485a4346cb732)
diff --git a/res/drawable/ic_instant_apps_badge.xml b/res/drawable/ic_instant_apps_badge.xml
new file mode 100644
index 0000000..115aa83
--- /dev/null
+++ b/res/drawable/ic_instant_apps_badge.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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
+  -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="48dp"
+        android:height="48dp"
+        android:viewportWidth="48"
+        android:viewportHeight="48">
+    <path
+        android:fillColor="#FFFFFF"
+        android:fillType="evenOdd"
+        android:pathData="M 24.5 2.7 C 35.5456949966 2.7 44.5 11.6543050034 44.5 22.7 C 44.5 33.7456949966 35.5456949966 42.7 24.5 42.7 C 13.4543050034 42.7 4.5 33.7456949966 4.5 22.7 C 4.5 11.6543050034 13.4543050034 2.7 24.5 2.7 Z" />
+    <path
+        android:fillColor="#757575"
+        android:fillType="evenOdd"
+        android:pathData="M 33.3 19.1 L 26.4 19.1 L 26.4 5.8 L 16.6 26.4 L 23.5 26.3 L 23.5 39.6 Z" />
+    <path
+        android:fillType="evenOdd"
+        android:pathData="M 0.5 0 H 48.5 V 48 H 0.5 V 0 Z" />
+</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_instant_apps_badge_bg.xml b/res/drawable/ic_instant_apps_badge_bg.xml
new file mode 100644
index 0000000..bf8d3ea
--- /dev/null
+++ b/res/drawable/ic_instant_apps_badge_bg.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 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
+  -->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+    <gradient android:type="radial"
+        android:startColor="#4d000000"
+        android:endColor="#00000000"
+        android:gradientRadius="12dp"/>
+</shape>
\ No newline at end of file
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 00d4cca..4aa1496 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -34,13 +34,26 @@
         android:layout_height="wrap_content"
         android:paddingStart="8dp">
 
-        <ImageView
-            android:id="@+id/app_detail_icon"
-            android:layout_width="80dp"
-            android:layout_height="80dp"
-            android:scaleType="fitXY"
-            android:layout_gravity="center_horizontal"
-            android:antialias="true"/>
+        <FrameLayout android:id="@+id/app_icon_frame"
+                     android:layout_width="80dp"
+                     android:layout_height="80dp">
+            <ImageView
+                android:id="@+id/app_detail_icon"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:scaleType="fitXY"
+                android:layout_gravity="center_horizontal"
+                android:antialias="true"/>
+            <ImageView android:id="@+id/app_icon_instant_apps_badge"
+                android:layout_width="22dp"
+                android:layout_height="22dp"
+                android:layout_gravity="end|bottom"
+                android:layout_margin="8dp"
+                android:visibility="gone"
+                android:elevation="20dp"
+                android:background="@drawable/ic_instant_apps_badge_bg"
+                android:src="@drawable/ic_instant_apps_badge" />
+        </FrameLayout>
 
         <LinearLayout
             android:id="@+id/app_detail_links"
@@ -71,7 +84,7 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_toEndOf="@id/app_detail_icon"
+            android:layout_toEndOf="@id/app_icon_frame"
             android:layout_toStartOf="@id/app_detail_links"
             android:paddingStart="24dp"
             android:paddingEnd="24dp"
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index 0bc9f8f..bb4b80d 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -212,6 +212,10 @@
         ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
         if (iconView != null) {
             iconView.setImageDrawable(mIcon);
+            ImageView badgeView = mAppHeader.findViewById(R.id.app_icon_instant_apps_badge);
+            if (badgeView != null) {
+                badgeView.setVisibility(mIsInstantApp ? View.VISIBLE : View.GONE);
+            }
         }
         setText(R.id.app_detail_title, mLabel);
         setText(R.id.app_detail_summary, mSummary);
diff --git a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
index 79f452a..f325453 100644
--- a/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppHeaderControllerTest.java
@@ -28,6 +28,7 @@
 import android.support.v7.preference.Preference;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.android.settings.R;
@@ -276,6 +277,17 @@
                 .isEqualTo(View.GONE);
     }
 
+    // Ensure that the instant app label does not show up when we haven't told the controller the
+    // app is instant.
+    @Test
+    public void instantApps_normalAppsDontGetInstantAppsBadge() {
+        final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
+        mController = new AppHeaderController(mContext, mFragment, appHeader);
+        mController.done();
+        assertThat(appHeader.findViewById(R.id.app_icon_instant_apps_badge).getVisibility())
+                .isEqualTo(View.GONE);
+    }
+
     // Test that the "instant apps" label is present in the header when we have an instant app.
     @Test
     public void instantApps_expectedHeaderItem() {
@@ -284,6 +296,8 @@
         mController.setIsInstantApp(true);
         mController.done();
         TextView label = (TextView)appHeader.findViewById(R.id.install_type);
+        ImageView badgeView = appHeader.findViewById(R.id.app_icon_instant_apps_badge);
+        assertThat(badgeView.getVisibility()).isEqualTo(View.VISIBLE);
         assertThat(label.getVisibility()).isEqualTo(View.VISIBLE);
         assertThat(label.getText()).isEqualTo(
                 appHeader.getResources().getString(R.string.install_type_instant));