Merge "Use floats for face enrollment dimensions" am: 59baff6ef9 am: fd493b221a

Change-Id: Ia4ac6e428666fb82f39e6b43620623e141f716c0
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 31a1592..5ee7171 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -218,8 +218,8 @@
     <dimen name="fingerprint_finish_max_size">288dp</dimen>
 
     <!-- Face -->
-    <dimen name="face_preview_translate_y">0dp</dimen>
-    <dimen name="face_preview_translate_x">0dp</dimen>
+    <item name="face_preview_translate_y" format="float" type="dimen">0</item>
+    <item name="face_preview_translate_x" format="float" type="dimen">0</item>
     <item name="face_preview_scale" format="float" type="dimen">1.0</item>
 
     <!-- Confirm device credentials -->
diff --git a/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java b/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
index 8806712..853ca7c 100644
--- a/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
+++ b/src/com/android/settings/biometrics/face/FaceEnrollPreviewFragment.java
@@ -18,6 +18,7 @@
 
 import android.app.settings.SettingsEnums;
 import android.content.Context;
+import android.graphics.Matrix;
 import android.graphics.SurfaceTexture;
 import android.hardware.camera2.CameraAccessException;
 import android.hardware.camera2.CameraCaptureSession;
@@ -316,14 +317,19 @@
         scaleX = scaleX / smaller;
         scaleY = scaleY / smaller;
 
-        // Apply the transformation/scale
-        mTextureView.setTranslationX(getResources().getDimension(R.dimen.face_preview_translate_x));
-        mTextureView.setTranslationY(getResources().getDimension(R.dimen.face_preview_translate_y));
-
+        final TypedValue tx = new TypedValue();
+        final TypedValue ty = new TypedValue();
         final TypedValue scale = new TypedValue();
+        getResources().getValue(R.dimen.face_preview_translate_x, tx, true /* resolveRefs */);
+        getResources().getValue(R.dimen.face_preview_translate_y, ty, true /* resolveRefs */);
         getResources().getValue(R.dimen.face_preview_scale, scale, true /* resolveRefs */);
-        mTextureView.setScaleX(scaleX * scale.getFloat());
-        mTextureView.setScaleY(scaleY * scale.getFloat());
+
+        // Apply the transformation/scale
+        final Matrix transform = new Matrix();
+        mTextureView.getTransform(transform);
+        transform.setScale(scaleX * scale.getFloat(), scaleY * scale.getFloat());
+        transform.postTranslate(tx.getFloat(), ty.getFloat());
+        mTextureView.setTransform(transform);
     }
 
     private void closeCamera() {