Preview layouts for phone/camera affordance.

Bug: 15126905
Change-Id: I72cbb90718e6add22a7c579a647f9f405793961a
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java
index a8a0cb1..9cc559f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardAffordanceHelper.java
@@ -67,7 +67,6 @@
     private Animator mSwipeAnimator;
     private int mMinBackgroundRadius;
     private boolean mMotionPerformedByUser;
-    private PowerManager mPM;
     private AnimatorListenerAdapter mFlingEndListener = new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
@@ -89,11 +88,12 @@
         mLeftIcon.setIsLeft(true);
         mCenterIcon = mCallback.getCenterIcon();
         mRightIcon = mCallback.getRightIcon();
+        mLeftIcon.setPreviewView(mCallback.getLeftPreview());
+        mRightIcon.setPreviewView(mCallback.getRightPreview());
         updateIcon(mLeftIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false);
         updateIcon(mCenterIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false);
         updateIcon(mRightIcon, 0.0f, SWIPE_RESTING_ALPHA_AMOUNT, false);
         initDimens();
-        mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
     }
 
     private void initDimens() {
@@ -334,7 +334,6 @@
         float absTranslation = Math.abs(translation);
         if (absTranslation > Math.abs(mTranslationOnDown) + mMinTranslationAmount ||
                 mMotionPerformedByUser) {
-            userActivity();
             mMotionPerformedByUser = true;
         }
         if (translation != mTranslation || isReset) {
@@ -387,11 +386,6 @@
         return translation * BACKGROUND_RADIUS_SCALE_FACTOR + mMinBackgroundRadius;
     }
 
-
-    private void userActivity() {
-        mPM.userActivity(SystemClock.uptimeMillis(), false);
-    }
-
     public void animateHideLeftRightIcon() {
         updateIcon(mRightIcon, 0f, 0f, true);
         updateIcon(mLeftIcon, 0f, 0f, true);
@@ -475,5 +469,9 @@
         KeyguardAffordanceView getCenterIcon();
 
         KeyguardAffordanceView getRightIcon();
+
+        View getLeftPreview();
+
+        View getRightPreview();
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index b9f012c..b5f517d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -30,6 +30,7 @@
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityManager;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
@@ -40,6 +41,7 @@
 import com.android.systemui.R;
 import com.android.systemui.statusbar.policy.FlashlightController;
 import com.android.systemui.statusbar.KeyguardAffordanceView;
+import com.android.systemui.statusbar.policy.PreviewInflater;
 
 /**
  * Implementation for the bottom area of the Keyguard, including camera/phone affordance and status
@@ -61,6 +63,10 @@
     private KeyguardAffordanceView mPhoneImageView;
     private KeyguardAffordanceView mLockIcon;
     private View mIndicationText;
+    private ViewGroup mPreviewContainer;
+
+    private View mPhonePreview;
+    private View mCameraPreview;
 
     private ActivityStarter mActivityStarter;
     private UnlockMethodCache mUnlockMethodCache;
@@ -88,6 +94,7 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
         mLockPatternUtils = new LockPatternUtils(mContext);
+        mPreviewContainer = (ViewGroup) findViewById(R.id.preview_container);
         mCameraImageView = (KeyguardAffordanceView) findViewById(R.id.camera_button);
         mPhoneImageView = (KeyguardAffordanceView) findViewById(R.id.phone_button);
         mLockIcon = (KeyguardAffordanceView) findViewById(R.id.lock_icon);
@@ -101,6 +108,7 @@
         updateTrust();
         setClipChildren(false);
         setClipToPadding(false);
+        inflatePreviews();
     }
 
     public void setActivityStarter(ActivityStarter activityStarter) {
@@ -239,6 +247,14 @@
         return mCameraImageView;
     }
 
+    public View getPhonePreview() {
+        return mPhonePreview;
+    }
+
+    public View getCameraPreview() {
+        return mCameraPreview;
+    }
+
     public KeyguardAffordanceView getLockIcon() {
         return mLockIcon;
     }
@@ -258,6 +274,20 @@
         updateCameraVisibility();
     }
 
+    private void inflatePreviews() {
+        PreviewInflater inflater = new PreviewInflater(mContext, new LockPatternUtils(mContext));
+        mPhonePreview = inflater.inflatePreview(PHONE_INTENT);
+        mCameraPreview = inflater.inflatePreview(getCameraIntent());
+        if (mPhonePreview != null) {
+            mPreviewContainer.addView(mPhonePreview);
+            mPhonePreview.setVisibility(View.INVISIBLE);
+        }
+        if (mCameraPreview != null) {
+            mPreviewContainer.addView(mCameraPreview);
+            mCameraPreview.setVisibility(View.INVISIBLE);
+        }
+    }
+
     private final BroadcastReceiver mDevicePolicyReceiver = new BroadcastReceiver() {
         public void onReceive(Context context, Intent intent) {
             post(new Runnable() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardPreviewContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardPreviewContainer.java
new file mode 100644
index 0000000..7579039
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardPreviewContainer.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 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
+ */
+
+package com.android.systemui.statusbar.phone;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.WindowInsets;
+import android.widget.FrameLayout;
+
+/**
+ * A view group which contains the preview of phone/camera and draws a black bar at the bottom as
+ * the fake navigation bar.
+ */
+public class KeyguardPreviewContainer extends FrameLayout {
+
+    private Drawable mBlackBarDrawable = new Drawable() {
+        @Override
+        public void draw(Canvas canvas) {
+            canvas.save();
+            canvas.clipRect(0, getHeight() - getPaddingBottom(), getWidth(), getHeight());
+            canvas.drawColor(Color.BLACK);
+            canvas.restore();
+        }
+
+        @Override
+        public void setAlpha(int alpha) {
+            // noop
+        }
+
+        @Override
+        public void setColorFilter(ColorFilter cf) {
+            // noop
+        }
+
+        @Override
+        public int getOpacity() {
+            return android.graphics.PixelFormat.OPAQUE;
+        }
+    };
+
+    public KeyguardPreviewContainer(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        setBackground(mBlackBarDrawable);
+    }
+
+    @Override
+    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
+        setPadding(0, 0, 0, insets.getStableInsetBottom());
+        return super.onApplyWindowInsets(insets);
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 11a38b5..291e692 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -1257,6 +1257,20 @@
     }
 
     @Override
+    public View getLeftPreview() {
+        return getLayoutDirection() == LAYOUT_DIRECTION_RTL
+                ? mKeyguardBottomArea.getCameraPreview()
+                : mKeyguardBottomArea.getPhonePreview();
+    }
+
+    @Override
+    public View getRightPreview() {
+        return getLayoutDirection() == LAYOUT_DIRECTION_RTL
+                ? mKeyguardBottomArea.getPhonePreview()
+                : mKeyguardBottomArea.getCameraPreview();
+    }
+
+    @Override
     protected float getPeekHeight() {
         if (mNotificationStackScroller.getNotGoneChildCount() > 0) {
             return mNotificationStackScroller.getPeekHeight();