@@ -83,13 +83,26 @@ public void run() {
8383 transitionToCamera ();
8484 }};
8585
86+ private final KeyguardUpdateMonitorCallback mCallback = new KeyguardUpdateMonitorCallback () {
87+ private boolean mShowing ;
88+
89+ void onKeyguardVisibilityChanged (boolean showing ) {
90+ if (mShowing == showing )
91+ return ;
92+ mShowing = showing ;
93+ CameraWidgetFrame .this .onKeyguardVisibilityChanged (mShowing );
94+ };
95+ };
96+
8697 private CameraWidgetFrame (Context context , Callbacks callbacks ,
8798 KeyguardActivityLauncher activityLauncher ) {
8899 super (context );
89100
90101 mCallbacks = callbacks ;
91102 mActivityLauncher = activityLauncher ;
92103 mWindowManager = (WindowManager ) context .getSystemService (Context .WINDOW_SERVICE );
104+ KeyguardUpdateMonitor .getInstance (context ).registerCallback (mCallback );
105+ if (DEBUG ) Log .d (TAG , "new CameraWidgetFrame instance " + instanceId ());
93106 }
94107
95108 public static CameraWidgetFrame create (Context context , Callbacks callbacks ,
@@ -179,7 +192,7 @@ public void render() {
179192 "Rendered camera widget in %sms size=%sx%s instance=%s at %s" ,
180193 end - start ,
181194 width , height ,
182- Integer . toHexString ( hashCode () ),
195+ instanceId ( ),
183196 end ));
184197 mRenderedSize .set (width , height );
185198 } catch (Throwable t ) {
@@ -265,18 +278,11 @@ public void onClick(View v) {
265278 }
266279
267280 @ Override
268- public void onWindowFocusChanged (boolean hasWindowFocus ) {
269- super .onWindowFocusChanged (hasWindowFocus );
270- if (DEBUG ) Log .d (TAG , "onWindowFocusChanged: " + hasWindowFocus );
271- if (!hasWindowFocus ) {
272- mTransitioning = false ;
273- if (mLaunchCameraStart > 0 ) {
274- long launchTime = SystemClock .uptimeMillis () - mLaunchCameraStart ;
275- if (DEBUG ) Log .d (TAG , String .format ("Camera took %sms to launch" , launchTime ));
276- mLaunchCameraStart = 0 ;
277- onCameraLaunched ();
278- }
279- }
281+ protected void onDetachedFromWindow () {
282+ if (DEBUG ) Log .d (TAG , "onDetachedFromWindow: instance " + instanceId ()
283+ + " at " + SystemClock .uptimeMillis ());
284+ super .onDetachedFromWindow ();
285+ KeyguardUpdateMonitor .getInstance (mContext ).removeCallback (mCallback );
280286 }
281287
282288 @ Override
@@ -375,4 +381,22 @@ private void enableWindowExitAnimation(boolean isEnabled) {
375381 mWindowManager .updateViewLayout (root , wlp );
376382 }
377383 }
384+
385+ private void onKeyguardVisibilityChanged (boolean showing ) {
386+ if (DEBUG ) Log .d (TAG , "onKeyguardVisibilityChanged " + showing
387+ + " at " + SystemClock .uptimeMillis ());
388+ if (mTransitioning && !showing ) {
389+ mTransitioning = false ;
390+ if (mLaunchCameraStart > 0 ) {
391+ long launchTime = SystemClock .uptimeMillis () - mLaunchCameraStart ;
392+ if (DEBUG ) Log .d (TAG , String .format ("Camera took %sms to launch" , launchTime ));
393+ mLaunchCameraStart = 0 ;
394+ onCameraLaunched ();
395+ }
396+ }
397+ }
398+
399+ private String instanceId () {
400+ return Integer .toHexString (hashCode ());
401+ }
378402}
0 commit comments