blob: 146c0922434cd1347b93ad296f11561fdf8c0360 [file] [log] [blame]
John Spurlock86b63572012-10-24 11:24:25 -04001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jim Miller5ecd8112013-01-09 18:50:26 -080017package com.android.keyguard;
John Spurlock86b63572012-10-24 11:24:25 -040018
John Spurlock86b63572012-10-24 11:24:25 -040019import android.content.Context;
John Spurlock86b63572012-10-24 11:24:25 -040020import android.content.pm.PackageManager.NameNotFoundException;
John Spurlock86b63572012-10-24 11:24:25 -040021import android.graphics.Color;
John Spurlock73779822012-10-30 11:47:23 -040022import android.graphics.Point;
John Spurlock0552c5d2012-11-15 08:04:45 -050023import android.graphics.Rect;
John Spurlock86b63572012-10-24 11:24:25 -040024import android.os.Handler;
John Spurlock86b63572012-10-24 11:24:25 -040025import android.os.SystemClock;
John Spurlock86b63572012-10-24 11:24:25 -040026import android.util.Log;
John Spurlock86b63572012-10-24 11:24:25 -040027import android.view.LayoutInflater;
John Spurlock4b976ea2012-10-28 12:34:11 -040028import android.view.MotionEvent;
John Spurlock86b63572012-10-24 11:24:25 -040029import android.view.View;
John Spurlock73779822012-10-30 11:47:23 -040030import android.view.ViewGroup;
John Spurlocke2ac5202012-10-30 11:05:55 -040031import android.view.WindowManager;
John Spurlockdcc96812012-10-25 14:35:19 -040032import android.widget.FrameLayout;
33import android.widget.ImageView;
34import android.widget.ImageView.ScaleType;
John Spurlock86b63572012-10-24 11:24:25 -040035
Jim Miller5ecd8112013-01-09 18:50:26 -080036import com.android.keyguard.KeyguardActivityLauncher.CameraWidgetInfo;
John Spurlock86b63572012-10-24 11:24:25 -040037
John Spurlock4b976ea2012-10-28 12:34:11 -040038public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnClickListener {
John Spurlock86b63572012-10-24 11:24:25 -040039 private static final String TAG = CameraWidgetFrame.class.getSimpleName();
40 private static final boolean DEBUG = KeyguardHostView.DEBUG;
John Spurlock57f928f2012-11-02 13:09:25 -040041 private static final int WIDGET_ANIMATION_DURATION = 250; // ms
42 private static final int WIDGET_WAIT_DURATION = 650; // ms
43 private static final int RECOVERY_DELAY = 1000; // ms
John Spurlock86b63572012-10-24 11:24:25 -040044
45 interface Callbacks {
46 void onLaunchingCamera();
John Spurlock57f928f2012-11-02 13:09:25 -040047 void onCameraLaunchedSuccessfully();
48 void onCameraLaunchedUnsuccessfully();
John Spurlock86b63572012-10-24 11:24:25 -040049 }
50
51 private final Handler mHandler = new Handler();
John Spurlockdcc96812012-10-25 14:35:19 -040052 private final KeyguardActivityLauncher mActivityLauncher;
John Spurlock86b63572012-10-24 11:24:25 -040053 private final Callbacks mCallbacks;
John Spurlock0552c5d2012-11-15 08:04:45 -050054 private final CameraWidgetInfo mWidgetInfo;
John Spurlocke2ac5202012-10-30 11:05:55 -040055 private final WindowManager mWindowManager;
John Spurlock73779822012-10-30 11:47:23 -040056 private final Point mRenderedSize = new Point();
John Spurlock0552c5d2012-11-15 08:04:45 -050057 private final int[] mTmpLoc = new int[2];
58 private final Rect mTmpRect = new Rect();
John Spurlock86b63572012-10-24 11:24:25 -040059
John Spurlock86b63572012-10-24 11:24:25 -040060 private long mLaunchCameraStart;
John Spurlock4b976ea2012-10-28 12:34:11 -040061 private boolean mActive;
John Spurlock4b976ea2012-10-28 12:34:11 -040062 private boolean mTransitioning;
63 private boolean mDown;
John Spurlock86b63572012-10-24 11:24:25 -040064
John Spurlock0552c5d2012-11-15 08:04:45 -050065 private FixedSizeFrameLayout mPreview;
66 private View mFullscreenPreview;
67
John Spurlock57f928f2012-11-02 13:09:25 -040068 private final Runnable mTransitionToCameraRunnable = new Runnable() {
69 @Override
70 public void run() {
71 transitionToCamera();
72 }};
73
74 private final Runnable mTransitionToCameraEndAction = new Runnable() {
John Spurlock86b63572012-10-24 11:24:25 -040075 @Override
76 public void run() {
John Spurlockdbe24b72012-11-01 13:01:05 -040077 if (!mTransitioning)
78 return;
John Spurlock57f928f2012-11-02 13:09:25 -040079 Handler worker = getWorkerHandler() != null ? getWorkerHandler() : mHandler;
John Spurlock47cde772012-10-26 08:25:51 -040080 mLaunchCameraStart = SystemClock.uptimeMillis();
John Spurlockdbe24b72012-11-01 13:01:05 -040081 if (DEBUG) Log.d(TAG, "Launching camera at " + mLaunchCameraStart);
John Spurlock57f928f2012-11-02 13:09:25 -040082 mActivityLauncher.launchCamera(worker, mSecureCameraActivityStartedRunnable);
83 }};
84
John Spurlock0552c5d2012-11-15 08:04:45 -050085 private final Runnable mPostTransitionToCameraEndAction = new Runnable() {
86 @Override
87 public void run() {
88 mHandler.post(mTransitionToCameraEndAction);
89 }};
90
John Spurlock57f928f2012-11-02 13:09:25 -040091 private final Runnable mRecoverRunnable = new Runnable() {
92 @Override
93 public void run() {
94 recover();
95 }};
96
John Spurlockdcc96812012-10-25 14:35:19 -040097 private final Runnable mRenderRunnable = new Runnable() {
98 @Override
99 public void run() {
100 render();
101 }};
102
John Spurlock57f928f2012-11-02 13:09:25 -0400103 private final Runnable mSecureCameraActivityStartedRunnable = new Runnable() {
John Spurlock4b976ea2012-10-28 12:34:11 -0400104 @Override
105 public void run() {
John Spurlock57f928f2012-11-02 13:09:25 -0400106 onSecureCameraActivityStarted();
107 }
108 };
John Spurlock4b976ea2012-10-28 12:34:11 -0400109
John Spurlock6275b3f2012-11-04 13:48:42 -0500110 private final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback() {
111 private boolean mShowing;
John Spurlock6275b3f2012-11-04 13:48:42 -0500112 void onKeyguardVisibilityChanged(boolean showing) {
113 if (mShowing == showing)
114 return;
115 mShowing = showing;
116 CameraWidgetFrame.this.onKeyguardVisibilityChanged(mShowing);
117 };
118 };
119
John Spurlock0552c5d2012-11-15 08:04:45 -0500120 private static final class FixedSizeFrameLayout extends FrameLayout {
121 int width;
122 int height;
123
124 FixedSizeFrameLayout(Context context) {
125 super(context);
126 }
127
128 @Override
129 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
130 measureChildren(
131 MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
132 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
133 setMeasuredDimension(width, height);
134 }
135 }
136
John Spurlockdcc96812012-10-25 14:35:19 -0400137 private CameraWidgetFrame(Context context, Callbacks callbacks,
John Spurlock0552c5d2012-11-15 08:04:45 -0500138 KeyguardActivityLauncher activityLauncher,
139 CameraWidgetInfo widgetInfo, View previewWidget) {
John Spurlock86b63572012-10-24 11:24:25 -0400140 super(context);
John Spurlock86b63572012-10-24 11:24:25 -0400141 mCallbacks = callbacks;
John Spurlockdcc96812012-10-25 14:35:19 -0400142 mActivityLauncher = activityLauncher;
John Spurlock0552c5d2012-11-15 08:04:45 -0500143 mWidgetInfo = widgetInfo;
John Spurlocke2ac5202012-10-30 11:05:55 -0400144 mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
John Spurlock6275b3f2012-11-04 13:48:42 -0500145 KeyguardUpdateMonitor.getInstance(context).registerCallback(mCallback);
John Spurlock0552c5d2012-11-15 08:04:45 -0500146
147 mPreview = new FixedSizeFrameLayout(context);
148 mPreview.addView(previewWidget);
149 addView(mPreview);
150
151 View clickBlocker = new View(context);
152 clickBlocker.setBackgroundColor(Color.TRANSPARENT);
153 clickBlocker.setOnClickListener(this);
154 addView(clickBlocker);
155
156 setContentDescription(context.getString(R.string.keyguard_accessibility_camera));
John Spurlock6275b3f2012-11-04 13:48:42 -0500157 if (DEBUG) Log.d(TAG, "new CameraWidgetFrame instance " + instanceId());
John Spurlock86b63572012-10-24 11:24:25 -0400158 }
159
John Spurlockdcc96812012-10-25 14:35:19 -0400160 public static CameraWidgetFrame create(Context context, Callbacks callbacks,
161 KeyguardActivityLauncher launcher) {
162 if (context == null || callbacks == null || launcher == null)
163 return null;
164
165 CameraWidgetInfo widgetInfo = launcher.getCameraWidgetInfo();
166 if (widgetInfo == null)
167 return null;
John Spurlock0552c5d2012-11-15 08:04:45 -0500168 View previewWidget = getPreviewWidget(context, widgetInfo);
169 if (previewWidget == null)
John Spurlockdcc96812012-10-25 14:35:19 -0400170 return null;
171
John Spurlock0552c5d2012-11-15 08:04:45 -0500172 return new CameraWidgetFrame(context, callbacks, launcher, widgetInfo, previewWidget);
173 }
174
175 private static View getPreviewWidget(Context context, CameraWidgetInfo widgetInfo) {
176 return widgetInfo.layoutId > 0 ?
177 inflateWidgetView(context, widgetInfo) :
178 inflateGenericWidgetView(context);
John Spurlockdcc96812012-10-25 14:35:19 -0400179 }
180
181 private static View inflateWidgetView(Context context, CameraWidgetInfo widgetInfo) {
John Spurlock4b976ea2012-10-28 12:34:11 -0400182 if (DEBUG) Log.d(TAG, "inflateWidgetView: " + widgetInfo.contextPackage);
John Spurlockdcc96812012-10-25 14:35:19 -0400183 View widgetView = null;
John Spurlock86b63572012-10-24 11:24:25 -0400184 Exception exception = null;
185 try {
John Spurlockdcc96812012-10-25 14:35:19 -0400186 Context cameraContext = context.createPackageContext(
187 widgetInfo.contextPackage, Context.CONTEXT_RESTRICTED);
John Spurlock86b63572012-10-24 11:24:25 -0400188 LayoutInflater cameraInflater = (LayoutInflater)
189 cameraContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
190 cameraInflater = cameraInflater.cloneInContext(cameraContext);
John Spurlockdcc96812012-10-25 14:35:19 -0400191 widgetView = cameraInflater.inflate(widgetInfo.layoutId, null, false);
John Spurlock86b63572012-10-24 11:24:25 -0400192 } catch (NameNotFoundException e) {
193 exception = e;
194 } catch (RuntimeException e) {
195 exception = e;
196 }
197 if (exception != null) {
198 Log.w(TAG, "Error creating camera widget view", exception);
199 }
John Spurlockdcc96812012-10-25 14:35:19 -0400200 return widgetView;
John Spurlock86b63572012-10-24 11:24:25 -0400201 }
202
John Spurlockdcc96812012-10-25 14:35:19 -0400203 private static View inflateGenericWidgetView(Context context) {
John Spurlock4b976ea2012-10-28 12:34:11 -0400204 if (DEBUG) Log.d(TAG, "inflateGenericWidgetView");
John Spurlockdcc96812012-10-25 14:35:19 -0400205 ImageView iv = new ImageView(context);
Jim Miller5ecd8112013-01-09 18:50:26 -0800206 iv.setImageResource(R.drawable.ic_lockscreen_camera);
John Spurlockdcc96812012-10-25 14:35:19 -0400207 iv.setScaleType(ScaleType.CENTER);
208 iv.setBackgroundColor(Color.argb(127, 0, 0, 0));
209 return iv;
210 }
211
John Spurlock0552c5d2012-11-15 08:04:45 -0500212 private void render() {
213 final View root = getRootView();
214 final int width = root.getWidth();
215 final int height = root.getHeight();
216 if (mRenderedSize.x == width && mRenderedSize.y == height) {
217 if (DEBUG) Log.d(TAG, String.format("Already rendered at size=%sx%s", width, height));
218 return;
219 }
220 if (width == 0 || height == 0) {
221 return;
John Spurlock47cde772012-10-26 08:25:51 -0400222 }
John Spurlock37d84ae2012-11-04 11:11:47 -0500223
John Spurlock0552c5d2012-11-15 08:04:45 -0500224 mPreview.width = width;
225 mPreview.height = height;
226 mPreview.requestLayout();
John Spurlock37d84ae2012-11-04 11:11:47 -0500227
John Spurlock0552c5d2012-11-15 08:04:45 -0500228 final int thisWidth = getWidth() - getPaddingLeft() - getPaddingRight();
229 final int thisHeight = getHeight() - getPaddingTop() - getPaddingBottom();
230
231 final float pvScaleX = (float) thisWidth / width;
232 final float pvScaleY = (float) thisHeight / height;
233 final float pvScale = Math.min(pvScaleX, pvScaleY);
234
235 final int pvWidth = (int) (pvScale * width);
236 final int pvHeight = (int) (pvScale * height);
237
238 final float pvTransX = pvWidth < thisWidth ? (thisWidth - pvWidth) / 2 : 0;
239 final float pvTransY = pvHeight < thisHeight ? (thisHeight - pvHeight) / 2 : 0;
240
241 mPreview.setPivotX(0);
242 mPreview.setPivotY(0);
243 mPreview.setScaleX(pvScale);
244 mPreview.setScaleY(pvScale);
245 mPreview.setTranslationX(pvTransX);
246 mPreview.setTranslationY(pvTransY);
247
248 mRenderedSize.set(width, height);
249 if (DEBUG) Log.d(TAG, String.format("Rendered camera widget size=%sx%s instance=%s",
250 width, height, instanceId()));
John Spurlock86b63572012-10-24 11:24:25 -0400251 }
252
253 private void transitionToCamera() {
John Spurlockbb5c9412012-10-31 09:46:15 -0400254 if (mTransitioning || mDown) return;
John Spurlockcf69c562012-10-30 08:46:57 -0400255
John Spurlock4b976ea2012-10-28 12:34:11 -0400256 mTransitioning = true;
John Spurlockdcc96812012-10-25 14:35:19 -0400257
John Spurlocke2ac5202012-10-30 11:05:55 -0400258 enableWindowExitAnimation(false);
John Spurlockcf69c562012-10-30 08:46:57 -0400259
John Spurlock0552c5d2012-11-15 08:04:45 -0500260 mPreview.getLocationInWindow(mTmpLoc);
261 final float pvHeight = mPreview.getHeight() * mPreview.getScaleY();
262 final float pvCenter = mTmpLoc[1] + pvHeight / 2f;
263
264 final ViewGroup root = (ViewGroup) getRootView();
265 if (mFullscreenPreview == null) {
266 mFullscreenPreview = getPreviewWidget(mContext, mWidgetInfo);
267 mFullscreenPreview.setClickable(false);
268 root.addView(mFullscreenPreview);
269 }
270
271 root.getWindowVisibleDisplayFrame(mTmpRect);
272 final float fsHeight = mTmpRect.height();
273 final float fsCenter = mTmpRect.top + fsHeight / 2;
274
275 final float fsScaleY = pvHeight / fsHeight;
276 final float fsTransY = pvCenter - fsCenter;
277 final float fsScaleX = mPreview.getScaleX();
278
279 mPreview.setVisibility(View.GONE);
280 mFullscreenPreview.setVisibility(View.VISIBLE);
281 mFullscreenPreview.setTranslationY(fsTransY);
282 mFullscreenPreview.setScaleX(fsScaleX);
283 mFullscreenPreview.setScaleY(fsScaleY);
284 mFullscreenPreview
285 .animate()
286 .scaleX(1)
287 .scaleY(1)
288 .translationX(0)
289 .translationY(0)
290 .setDuration(WIDGET_ANIMATION_DURATION)
291 .withEndAction(mPostTransitionToCameraEndAction)
292 .start();
John Spurlock86b63572012-10-24 11:24:25 -0400293 mCallbacks.onLaunchingCamera();
294 }
295
John Spurlock57f928f2012-11-02 13:09:25 -0400296 private void recover() {
297 if (DEBUG) Log.d(TAG, "recovering at " + SystemClock.uptimeMillis());
John Spurlock0552c5d2012-11-15 08:04:45 -0500298 mCallbacks.onCameraLaunchedUnsuccessfully();
299 reset();
300 }
301
302 @Override
303 public void setOnLongClickListener(OnLongClickListener l) {
304 // ignore
John Spurlock57f928f2012-11-02 13:09:25 -0400305 }
306
John Spurlock86b63572012-10-24 11:24:25 -0400307 @Override
John Spurlock4b976ea2012-10-28 12:34:11 -0400308 public void onClick(View v) {
309 if (DEBUG) Log.d(TAG, "clicked");
310 if (mTransitioning) return;
John Spurlockbb5c9412012-10-31 09:46:15 -0400311 if (mActive) {
John Spurlock4b976ea2012-10-28 12:34:11 -0400312 cancelTransitionToCamera();
313 transitionToCamera();
314 }
315 }
316
317 @Override
John Spurlock6275b3f2012-11-04 13:48:42 -0500318 protected void onDetachedFromWindow() {
319 if (DEBUG) Log.d(TAG, "onDetachedFromWindow: instance " + instanceId()
320 + " at " + SystemClock.uptimeMillis());
321 super.onDetachedFromWindow();
322 KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mCallback);
John Spurlock57f928f2012-11-02 13:09:25 -0400323 cancelTransitionToCamera();
324 mHandler.removeCallbacks(mRecoverRunnable);
John Spurlock86b63572012-10-24 11:24:25 -0400325 }
326
327 @Override
328 public void onActive(boolean isActive) {
John Spurlock4b976ea2012-10-28 12:34:11 -0400329 mActive = isActive;
330 if (mActive) {
331 rescheduleTransitionToCamera();
John Spurlock86b63572012-10-24 11:24:25 -0400332 } else {
333 reset();
334 }
335 }
336
John Spurlock4b976ea2012-10-28 12:34:11 -0400337 @Override
John Spurlockbb5c9412012-10-31 09:46:15 -0400338 public boolean onUserInteraction(MotionEvent event) {
John Spurlockbb5c9412012-10-31 09:46:15 -0400339 if (mTransitioning) {
340 if (DEBUG) Log.d(TAG, "onUserInteraction eaten: mTransitioning");
341 return true;
342 }
343
John Spurlock0552c5d2012-11-15 08:04:45 -0500344 getLocationOnScreen(mTmpLoc);
345 int rawBottom = mTmpLoc[1] + getHeight();
John Spurlockbb5c9412012-10-31 09:46:15 -0400346 if (event.getRawY() > rawBottom) {
347 if (DEBUG) Log.d(TAG, "onUserInteraction eaten: below widget");
348 return true;
349 }
350
351 int action = event.getAction();
John Spurlock4b976ea2012-10-28 12:34:11 -0400352 mDown = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE;
John Spurlockbb5c9412012-10-31 09:46:15 -0400353 if (mActive) {
John Spurlock4b976ea2012-10-28 12:34:11 -0400354 rescheduleTransitionToCamera();
355 }
John Spurlockbb5c9412012-10-31 09:46:15 -0400356 if (DEBUG) Log.d(TAG, "onUserInteraction observed, not eaten");
John Spurlock4b976ea2012-10-28 12:34:11 -0400357 return false;
358 }
359
360 @Override
361 protected void onFocusLost() {
John Spurlock57f928f2012-11-02 13:09:25 -0400362 if (DEBUG) Log.d(TAG, "onFocusLost at " + SystemClock.uptimeMillis());
John Spurlock4b976ea2012-10-28 12:34:11 -0400363 cancelTransitionToCamera();
364 super.onFocusLost();
365 }
366
John Spurlockdbe24b72012-11-01 13:01:05 -0400367 public void onScreenTurnedOff() {
368 if (DEBUG) Log.d(TAG, "onScreenTurnedOff");
369 reset();
370 }
371
John Spurlock4b976ea2012-10-28 12:34:11 -0400372 private void rescheduleTransitionToCamera() {
373 if (DEBUG) Log.d(TAG, "rescheduleTransitionToCamera at " + SystemClock.uptimeMillis());
374 mHandler.removeCallbacks(mTransitionToCameraRunnable);
375 mHandler.postDelayed(mTransitionToCameraRunnable, WIDGET_WAIT_DURATION);
376 }
377
378 private void cancelTransitionToCamera() {
379 if (DEBUG) Log.d(TAG, "cancelTransitionToCamera at " + SystemClock.uptimeMillis());
380 mHandler.removeCallbacks(mTransitionToCameraRunnable);
381 }
382
John Spurlock86b63572012-10-24 11:24:25 -0400383 private void onCameraLaunched() {
John Spurlock57f928f2012-11-02 13:09:25 -0400384 mCallbacks.onCameraLaunchedSuccessfully();
John Spurlock4b976ea2012-10-28 12:34:11 -0400385 reset();
John Spurlock86b63572012-10-24 11:24:25 -0400386 }
387
388 private void reset() {
John Spurlock57f928f2012-11-02 13:09:25 -0400389 if (DEBUG) Log.d(TAG, "reset at " + SystemClock.uptimeMillis());
John Spurlock4b976ea2012-10-28 12:34:11 -0400390 mLaunchCameraStart = 0;
391 mTransitioning = false;
John Spurlock4b976ea2012-10-28 12:34:11 -0400392 mDown = false;
393 cancelTransitionToCamera();
John Spurlock57f928f2012-11-02 13:09:25 -0400394 mHandler.removeCallbacks(mRecoverRunnable);
John Spurlock0552c5d2012-11-15 08:04:45 -0500395 mPreview.setVisibility(View.VISIBLE);
396 if (mFullscreenPreview != null) {
397 mFullscreenPreview.animate().cancel();
398 mFullscreenPreview.setVisibility(View.GONE);
399 }
John Spurlocke2ac5202012-10-30 11:05:55 -0400400 enableWindowExitAnimation(true);
John Spurlock86b63572012-10-24 11:24:25 -0400401 }
402
John Spurlockdcc96812012-10-25 14:35:19 -0400403 @Override
John Spurlock73779822012-10-30 11:47:23 -0400404 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
405 if (DEBUG) Log.d(TAG, String.format("onSizeChanged new=%sx%s old=%sx%s at %s",
406 w, h, oldw, oldh, SystemClock.uptimeMillis()));
John Spurlock0552c5d2012-11-15 08:04:45 -0500407 mHandler.post(mRenderRunnable);
John Spurlock73779822012-10-30 11:47:23 -0400408 super.onSizeChanged(w, h, oldw, oldh);
John Spurlock86b63572012-10-24 11:24:25 -0400409 }
John Spurlocke2ac5202012-10-30 11:05:55 -0400410
John Spurlock0552c5d2012-11-15 08:04:45 -0500411 @Override
412 public void onBouncerShowing(boolean showing) {
413 if (showing) {
414 mTransitioning = false;
415 mHandler.post(mRecoverRunnable);
416 }
417 }
418
John Spurlocke2ac5202012-10-30 11:05:55 -0400419 private void enableWindowExitAnimation(boolean isEnabled) {
420 View root = getRootView();
John Spurlock73779822012-10-30 11:47:23 -0400421 ViewGroup.LayoutParams lp = root.getLayoutParams();
422 if (!(lp instanceof WindowManager.LayoutParams))
423 return;
424 WindowManager.LayoutParams wlp = (WindowManager.LayoutParams) lp;
Jim Miller5ecd8112013-01-09 18:50:26 -0800425 int newWindowAnimations = isEnabled ? R.style.Animation_LockScreen : 0;
John Spurlock73779822012-10-30 11:47:23 -0400426 if (newWindowAnimations != wlp.windowAnimations) {
John Spurlock57f928f2012-11-02 13:09:25 -0400427 if (DEBUG) Log.d(TAG, "setting windowAnimations to: " + newWindowAnimations
428 + " at " + SystemClock.uptimeMillis());
John Spurlock73779822012-10-30 11:47:23 -0400429 wlp.windowAnimations = newWindowAnimations;
430 mWindowManager.updateViewLayout(root, wlp);
John Spurlocke2ac5202012-10-30 11:05:55 -0400431 }
432 }
John Spurlock6275b3f2012-11-04 13:48:42 -0500433
434 private void onKeyguardVisibilityChanged(boolean showing) {
435 if (DEBUG) Log.d(TAG, "onKeyguardVisibilityChanged " + showing
436 + " at " + SystemClock.uptimeMillis());
437 if (mTransitioning && !showing) {
John Spurlock0552c5d2012-11-15 08:04:45 -0500438 mTransitioning = false;
439 mHandler.removeCallbacks(mRecoverRunnable);
440 if (mLaunchCameraStart > 0) {
441 long launchTime = SystemClock.uptimeMillis() - mLaunchCameraStart;
442 if (DEBUG) Log.d(TAG, String.format("Camera took %sms to launch", launchTime));
443 mLaunchCameraStart = 0;
444 onCameraLaunched();
445 }
John Spurlock6275b3f2012-11-04 13:48:42 -0500446 }
447 }
448
John Spurlock57f928f2012-11-02 13:09:25 -0400449 private void onSecureCameraActivityStarted() {
450 if (DEBUG) Log.d(TAG, "onSecureCameraActivityStarted at " + SystemClock.uptimeMillis());
451 mHandler.postDelayed(mRecoverRunnable, RECOVERY_DELAY);
452 }
453
John Spurlock6275b3f2012-11-04 13:48:42 -0500454 private String instanceId() {
455 return Integer.toHexString(hashCode());
456 }
John Spurlock86b63572012-10-24 11:24:25 -0400457}