Add animation for fingerprint icon

Also show the "Whoops" dialog when the finger is resting on the icon,
in addition to show it after clicking it for 3 times.

Bug: 20495507
Change-Id: I771da0671f61c13065b011d613f508827cb3b54f
(cherry picked from commit 2c2a41669f276058f7241f86a3aca68d960ac453)
diff --git a/res/anim/enrollment_fingerprint_isolated_ridge_1_path_animation.xml b/res/anim/enrollment_fingerprint_isolated_ridge_1_path_animation.xml
new file mode 100644
index 0000000..3332715
--- /dev/null
+++ b/res/anim/enrollment_fingerprint_isolated_ridge_1_path_animation.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<set
+    xmlns:android="http://schemas.android.com/apk/res/android" >
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="233"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="566"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/fast_out_slow_in" />
+    </set>
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="700"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="433"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_1" />
+    </set>
+</set>
diff --git a/res/anim/enrollment_fingerprint_isolated_ridge_2_path_animation.xml b/res/anim/enrollment_fingerprint_isolated_ridge_2_path_animation.xml
new file mode 100644
index 0000000..9285122
--- /dev/null
+++ b/res/anim/enrollment_fingerprint_isolated_ridge_2_path_animation.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<set
+    xmlns:android="http://schemas.android.com/apk/res/android" >
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="733"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="1.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="533"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="1.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_2" />
+    </set>
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="366"
+            android:propertyName="trimPathStart"
+            android:valueFrom="1.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="633"
+            android:propertyName="trimPathStart"
+            android:valueFrom="1.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_2" />
+    </set>
+</set>
diff --git a/res/anim/enrollment_fingerprint_isolated_ridge_5_path_animation.xml b/res/anim/enrollment_fingerprint_isolated_ridge_5_path_animation.xml
new file mode 100644
index 0000000..1329b7b
--- /dev/null
+++ b/res/anim/enrollment_fingerprint_isolated_ridge_5_path_animation.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<set
+    xmlns:android="http://schemas.android.com/apk/res/android" >
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="166"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="900"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/fast_out_slow_in" />
+    </set>
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="600"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="833"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_1" />
+    </set>
+</set>
diff --git a/res/anim/enrollment_fingerprint_isolated_ridge_6_path_animation.xml b/res/anim/enrollment_fingerprint_isolated_ridge_6_path_animation.xml
new file mode 100644
index 0000000..eeb9681
--- /dev/null
+++ b/res/anim/enrollment_fingerprint_isolated_ridge_6_path_animation.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<set
+    xmlns:android="http://schemas.android.com/apk/res/android" >
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="400"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="1.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="900"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="1.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_0" />
+    </set>
+    <objectAnimator
+        android:duration="866"
+        android:propertyName="trimPathStart"
+        android:valueFrom="1.0"
+        android:valueTo="0.0"
+        android:valueType="floatType"
+        android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_2" />
+</set>
diff --git a/res/anim/enrollment_fingerprint_isolated_ridge_7_path_animation.xml b/res/anim/enrollment_fingerprint_isolated_ridge_7_path_animation.xml
new file mode 100644
index 0000000..69acef6
--- /dev/null
+++ b/res/anim/enrollment_fingerprint_isolated_ridge_7_path_animation.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<set
+    xmlns:android="http://schemas.android.com/apk/res/android" >
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="100"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="966"
+            android:propertyName="trimPathEnd"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/fast_out_slow_in" />
+    </set>
+    <set
+        android:ordering="sequentially" >
+        <objectAnimator
+            android:duration="533"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="0.0"
+            android:valueType="floatType"
+            android:interpolator="@android:interpolator/linear" />
+        <objectAnimator
+            android:duration="900"
+            android:propertyName="trimPathStart"
+            android:valueFrom="0.0"
+            android:valueTo="1.0"
+            android:valueType="floatType"
+            android:interpolator="@interpolator/enrollment_fingerprint_isolated_animation_interpolator_1" />
+    </set>
+</set>
diff --git a/res/drawable/enrollment_fingerprint_isolated.xml b/res/drawable/enrollment_fingerprint_isolated.xml
new file mode 100644
index 0000000..2f1db7a
--- /dev/null
+++ b/res/drawable/enrollment_fingerprint_isolated.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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:name="enrollment_fingerprint_isolated"
+    android:width="75dp"
+    android:viewportWidth="75"
+    android:height="88dp"
+    android:viewportHeight="88" >
+    <group
+        android:name="fingerprint_ridges_2"
+        android:translateX="37.5835"
+        android:translateY="43.66685" >
+        <group
+            android:name="ridge_5" >
+            <path
+                android:name="ridge_5_path"
+                android:pathData="M 24.9488677979,32.3508300781 c -1.81059265137,0.338500976562 -3.58520507812,0.447387695312 -4.62879943848,0.447387695312 c -4.12730407715,0.0 -8.05894470215,-0.96842956543 -11.5207061768,-3.45275878906 c -5.33699035645,-3.830078125 -8.56369018555,-10.0885009766 -8.56369018555,-17.1589355469"
+                android:strokeColor="#10000000"
+                android:strokeWidth="5"
+                android:strokeLineCap="round"
+                android:trimPathEnd="0" />
+        </group>
+        <group
+            android:name="ridge_4" >
+            <path
+                android:name="ridge_7_path"
+                android:pathData="M -9.23379516602,40.8356933594 c -3.24549865723,-3.46032714844 -5.1540222168,-5.77195739746 -7.87710571289,-10.9068603516 c -2.76379394531,-5.21166992188 -4.04838562012,-11.3482666016 -4.04838562012,-17.6915283203 c 0.0,-11.6563720703 9.44940185547,-21.1059570312 21.1058959961,-21.1059570312 c 11.6564941406,0.0 21.1058959961,9.44958496094 21.1058959961,21.1059570312"
+                android:strokeColor="#10000000"
+                android:strokeWidth="5"
+                android:strokeLineCap="round"
+                android:trimPathEnd="0" />
+        </group>
+        <group
+            android:name="ridge_3" >
+            <path
+                android:name="ridge_6_path"
+                android:pathData="M -28.8249053955,28.5169677734 c -2.41259765625,-6.82202148438 -2.85319519043,-12.3121337891 -2.85319519043,-16.3226318359 c 0.0,-4.64868164062 0.792999267578,-9.06323242188 2.59269714355,-13.0396728516 c 4.96929931641,-10.9801025391 16.0211029053,-18.619140625 28.857208252,-18.619140625 c 17.4846954346,0.0 31.6587982178,14.1740722656 31.6587982178,31.6588134766 c 0.0,5.82824707031 -4.72470092773,10.5529785156 -10.5529022217,10.5529785156 c -5.82820129395,0.0 -10.5529937744,-4.72473144531 -10.5529937744,-10.5529785156 c 0.0,-5.82824707031 -4.72470092773,-10.5529785156 -10.5529022217,-10.5529785156 c -5.82820129395,0.0 -10.5529022217,4.72473144531 -10.5529022217,10.5529785156 c 0.0,8.17932128906 3.10879516602,15.5925292969 8.25030517578,21.0004882812 c 3.88919067383,4.09069824219 7.77758789062,6.64123535156 14.2838897705,8.52136230469"
+                android:strokeColor="#10000000"
+                android:strokeWidth="5"
+                android:strokeLineCap="round"
+                android:trimPathStart="1" />
+        </group>
+        <group
+            android:name="ridge_2" >
+            <path
+                android:name="ridge_2_path"
+                android:pathData="M -34.4861907959,-11.6943359375 c 3.78790283203,-5.64636230469 8.36389160156,-9.94665527344 14.3594970703,-13.2164306641 c 5.99560546875,-3.26977539062 12.8716125488,-5.1279296875 20.1817016602,-5.1279296875 c 7.27980041504,0.0 14.129196167,1.84289550781 20.1071014404,5.08740234375 c 5.97790527344,3.24450683594 10.7957000732,7.759765625 14.5897064209,13.3666992188"
+                android:strokeColor="#10000000"
+                android:strokeWidth="5"
+                android:strokeLineCap="round"
+                android:trimPathStart="1" />
+        </group>
+        <group
+            android:name="ridge_1"
+            android:translateX="-97.5"
+            android:translateY="-142.5" >
+            <path
+                android:name="ridge_1_path"
+                android:pathData="M 121.472564697,107.859741211 c -7.39790344238,-4.03979492188 -15.2462921143,-6.34167480469 -24.3116912842,-6.34167480469 c -9.06539916992,0.0 -16.2951049805,2.40405273438 -23.12550354,6.34167480469"
+                android:strokeColor="#10000000"
+                android:strokeWidth="5"
+                android:strokeLineCap="round"
+                android:trimPathEnd="0" />
+        </group>
+    </group>
+</vector>
diff --git a/res/drawable/enrollment_fingerprint_isolated_animation.xml b/res/drawable/enrollment_fingerprint_isolated_animation.xml
new file mode 100644
index 0000000..39c27f0
--- /dev/null
+++ b/res/drawable/enrollment_fingerprint_isolated_animation.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<animated-vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:drawable="@drawable/enrollment_fingerprint_isolated" >
+    <target
+        android:name="ridge_5_path"
+        android:animation="@anim/enrollment_fingerprint_isolated_ridge_5_path_animation" />
+    <target
+        android:name="ridge_7_path"
+        android:animation="@anim/enrollment_fingerprint_isolated_ridge_7_path_animation" />
+    <target
+        android:name="ridge_6_path"
+        android:animation="@anim/enrollment_fingerprint_isolated_ridge_6_path_animation" />
+    <target
+        android:name="ridge_2_path"
+        android:animation="@anim/enrollment_fingerprint_isolated_ridge_2_path_animation" />
+    <target
+        android:name="ridge_1_path"
+        android:animation="@anim/enrollment_fingerprint_isolated_ridge_1_path_animation" />
+</animated-vector>
diff --git a/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_0.xml b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_0.xml
new file mode 100644
index 0000000..7f442ee
--- /dev/null
+++ b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_0.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<pathInterpolator
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:pathData="M 0.0,0.0 c 0.4,0.0 0.5,1.0 1.0,1.0" />
diff --git a/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_1.xml b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_1.xml
new file mode 100644
index 0000000..e10db01
--- /dev/null
+++ b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_1.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<pathInterpolator
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:pathData="M 0.0,0.0 c 0.8,0.0 0.5,1.0 1.0,1.0" />
diff --git a/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_2.xml b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_2.xml
new file mode 100644
index 0000000..736eac6
--- /dev/null
+++ b/res/interpolator/enrollment_fingerprint_isolated_animation_interpolator_2.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2015 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
+  -->
+<pathInterpolator
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:pathData="M 0.0,0.0 c 0.4,0.0 0.6,1.0 1.0,1.0" />
diff --git a/res/layout/fingerprint_enroll_enrolling_content.xml b/res/layout/fingerprint_enroll_enrolling_content.xml
index 6da744e..9fa503b 100644
--- a/res/layout/fingerprint_enroll_enrolling_content.xml
+++ b/res/layout/fingerprint_enroll_enrolling_content.xml
@@ -23,12 +23,18 @@
     android:layout_gravity="center_horizontal">
 
     <ImageView
-        android:id="@+id/fingerprint_animator"
         android:layout_width="88dp"
         android:layout_height="88dp"
         android:layout_centerInParent="true"
         android:src="@drawable/fingerprint_indicator" />
 
+    <ImageView
+        android:id="@+id/fingerprint_animator"
+        android:layout_width="88dp"
+        android:layout_height="88dp"
+        android:layout_centerInParent="true"
+        android:src="@drawable/enrollment_fingerprint_isolated_animation" />
+
     <ProgressBar
         android:id="@+id/fingerprint_progress_bar"
         android:layout_width="192dp"
diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
index e70c405..6d0d10b 100644
--- a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java
@@ -17,17 +17,15 @@
 package com.android.settings.fingerprint;
 
 import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
 import android.animation.ObjectAnimator;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.hardware.fingerprint.FingerprintManager;
+import android.graphics.drawable.AnimatedVectorDrawable;
 import android.os.Bundle;
-import android.os.CancellationSignal;
-import android.os.PowerManager;
-import android.os.SystemClock;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.animation.AnimationUtils;
@@ -51,6 +49,11 @@
     private static final int FINISH_DELAY = 250;
 
     /**
+     * How long the user needs to touch the icon until we show the dialog.
+     */
+    private static final long ICON_TOUCH_DURATION_UNTIL_DIALOG_SHOWN = 500;
+
+    /**
      * How many times the user needs to touch the icon until we show the dialog that this is not the
      * fingerprint sensor.
      */
@@ -65,6 +68,8 @@
     private Interpolator mFastOutSlowInInterpolator;
     private int mIconTouchCount;
     private FingerprintEnrollSidecar mSidecar;
+    private boolean mAnimationCancelled;
+    private AnimatedVectorDrawable mIconAnimationDrawable;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -76,17 +81,24 @@
         mErrorText = (TextView) findViewById(R.id.error_text);
         mProgressBar = (ProgressBar) findViewById(R.id.fingerprint_progress_bar);
         mFingerprintAnimator = (ImageView) findViewById(R.id.fingerprint_animator);
+        mIconAnimationDrawable = (AnimatedVectorDrawable) mFingerprintAnimator.getDrawable();
+        mIconAnimationDrawable.addListener(mIconAnimationListener);
         mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(
                 this, android.R.interpolator.fast_out_slow_in);
-        findViewById(R.id.fingerprint_animator).setOnTouchListener(new View.OnTouchListener() {
+        mFingerprintAnimator.setOnTouchListener(new View.OnTouchListener() {
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                     mIconTouchCount++;
                     if (mIconTouchCount == ICON_TOUCH_COUNT_SHOW_UNTIL_DIALOG_SHOWN) {
                         showIconTouchDialog();
-                        mIconTouchCount = 0;
+                    } else {
+                        mFingerprintAnimator.postDelayed(mShowDialogRunnable,
+                                ICON_TOUCH_DURATION_UNTIL_DIALOG_SHOWN);
                     }
+                } else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL
+                        || event.getActionMasked() == MotionEvent.ACTION_UP) {
+                    mFingerprintAnimator.removeCallbacks(mShowDialogRunnable);
                 }
                 return true;
             }
@@ -102,18 +114,31 @@
             getFragmentManager().beginTransaction().add(mSidecar, TAG_SIDECAR).commit();
         }
         mSidecar.setListener(this);
-        if (mSidecar.isDone()) {
-            launchFinish(mToken);
-        } else {
-            updateProgress(false /* animate */);
-            updateDescription();
-        }
+        updateProgress(false /* animate */);
+        updateDescription();
+    }
+
+    @Override
+    public void onEnterAnimationComplete() {
+        super.onEnterAnimationComplete();
+        mAnimationCancelled = false;
+        startIconAnimation();
+    }
+
+    private void startIconAnimation() {
+        mIconAnimationDrawable.start();
+    }
+
+    private void stopIconAnimation() {
+        mAnimationCancelled = true;
+        mIconAnimationDrawable.stop();
     }
 
     @Override
     protected void onStop() {
         super.onStop();
         mSidecar.setListener(null);
+        stopIconAnimation();
     }
 
     private void animateProgress(int progress) {
@@ -187,6 +212,7 @@
     }
 
     private void showIconTouchDialog() {
+        mIconTouchCount = 0;
         new IconTouchDialog().show(getFragmentManager(), null /* tag */);
     }
 
@@ -211,13 +237,37 @@
     };
 
     // Give the user a chance to see progress completed before jumping to the next stage.
-    Runnable mDelayedFinishRunnable = new Runnable() {
+    private final Runnable mDelayedFinishRunnable = new Runnable() {
         @Override
         public void run() {
             launchFinish(mToken);
         }
     };
 
+    private final Animator.AnimatorListener mIconAnimationListener = new AnimatorListenerAdapter() {
+        @Override
+        public void onAnimationEnd(Animator animation) {
+            if (mAnimationCancelled) {
+                return;
+            }
+
+            // Start animation after it has ended.
+            mFingerprintAnimator.post(new Runnable() {
+                @Override
+                public void run() {
+                    startIconAnimation();
+                }
+            });
+        }
+    };
+
+    private final Runnable mShowDialogRunnable = new Runnable() {
+        @Override
+        public void run() {
+            showIconTouchDialog();
+        }
+    };
+
     private static class IconTouchDialog extends DialogFragment {
 
         @Override