Skip to content

Commit

Permalink
LLS: Use window attachment callbacks
Browse files Browse the repository at this point in the history
Change-Id: Ie25585a120638fb7254bdf43e767aae3c68623e0
  • Loading branch information
0xD34D authored and temasek committed Apr 1, 2016
1 parent 3d923ad commit 3e7e92c
Showing 1 changed file with 43 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,59 @@ public KeyguardExternalView getLiveLockScreenView() {
return mLiveLockScreenView;
}

private Runnable mAddNewLiveLockScreenRunnable = new Runnable() {
@Override
public void run() {
if (mLiveLockScreenComponentName != null) {
mLiveLockScreenView =
getExternalKeyguardView(mLiveLockScreenComponentName);
mLiveLockScreenView.registerKeyguardExternalViewCallback(
mExternalKeyguardViewCallbacks);
if (mStatusBarState != StatusBarState.SHADE) {
mPanelView.addView(mLiveLockScreenView);
mLiveLockScreenView.onKeyguardShowing(true);
}
} else {
mLiveLockScreenView = null;
}
}
};

private void updateLiveLockScreenView(final ComponentName cn) {
// If mThirdPartyKeyguardViewComponent differs from cn, go ahead and update
if (!Objects.equals(mLiveLockScreenComponentName, cn)) {
mHandler.post(new Runnable() {
@Override
public void run() {
mHandler.post(new Runnable() {
@Override
public void run() {
// If mThirdPartyKeyguardViewComponent differs from cn, go ahead and update
if (!Objects.equals(mLiveLockScreenComponentName, cn)) {
mLiveLockScreenComponentName = cn;
if (mLiveLockScreenView != null) {
if (mPanelView.indexOfChild(mLiveLockScreenView) >= 0) {
mPanelView.removeView(mLiveLockScreenView);
}
mLiveLockScreenView.unregisterKeyguardExternalViewCallback(
mExternalKeyguardViewCallbacks);
// setProviderComponent(null) will unbind the existing service
mLiveLockScreenView.setProviderComponent(null);
if (mLiveLockScreenComponentName != null) {
mLiveLockScreenView =
getExternalKeyguardView(mLiveLockScreenComponentName);
mLiveLockScreenView.registerKeyguardExternalViewCallback(
mExternalKeyguardViewCallbacks);
if (mStatusBarState != StatusBarState.SHADE) {
mPanelView.addView(mLiveLockScreenView);
mLiveLockScreenView.onKeyguardShowing(true);
}
if (mPanelView.indexOfChild(mLiveLockScreenView) >= 0) {
mLiveLockScreenView.registerOnWindowAttachmentChangedListener(
new KeyguardExternalView.OnWindowAttachmentChangedListener() {
@Override
public void onAttachedToWindow() {
}

@Override
public void onDetachedFromWindow() {
mLiveLockScreenView
.unregisterOnWindowAttachmentChangedListener(
this);
mHandler.post(mAddNewLiveLockScreenRunnable);
}
}
);
mPanelView.removeView(mLiveLockScreenView);
} else {
mLiveLockScreenView = null;
mAddNewLiveLockScreenRunnable.run();
}
}
}
});
}
}
});
}
}

0 comments on commit 3e7e92c

Please sign in to comment.