Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Deferring size callbacks until boot completed (issue 7469267)"…
Browse files Browse the repository at this point in the history
… into jb-mr1-dev
  • Loading branch information
Adam Cohen authored and Android (Google) Code Review committed Nov 9, 2012
2 parents a46a74f + c276e82 commit 3e9cba4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Expand Up @@ -348,9 +348,13 @@ private KeyguardUpdateMonitor(Context context) {
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
filter.addAction(Intent.ACTION_USER_REMOVED);
filter.addAction(Intent.ACTION_BOOT_COMPLETED);
context.registerReceiver(mBroadcastReceiver, filter);

final IntentFilter bootCompleteFilter = new IntentFilter();
bootCompleteFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
bootCompleteFilter.addAction(Intent.ACTION_BOOT_COMPLETED);
context.registerReceiver(mBroadcastReceiver, bootCompleteFilter);

try {
ActivityManagerNative.getDefault().registerUserSwitchObserver(
new IUserSwitchObserver.Stub() {
Expand Down
Expand Up @@ -69,8 +69,6 @@ public class KeyguardWidgetFrame extends FrameLayout {
private float mBackgroundAlphaMultiplier = 1.0f;
private Drawable mBackgroundDrawable;
private Rect mBackgroundRect = new Rect();
private int mLastMeasuredWidth = -1;
private int mLastMeasuredHeight = 1;

// These variables are all needed in order to size things properly before we're actually
// measured.
Expand All @@ -79,6 +77,7 @@ public class KeyguardWidgetFrame extends FrameLayout {
private boolean mWidgetLockedSmall = false;
private int mMaxChallengeTop = -1;
private int mFrameStrokeAdjustment;
private boolean mPerformAppWidgetSizeUpdateOnBootComplete;

// This will hold the width value before we've actually been measured
private int mFrameHeight;
Expand Down Expand Up @@ -123,9 +122,29 @@ public KeyguardWidgetFrame(Context context, AttributeSet attrs, int defStyle) {

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
cancelLongPress();
KeyguardUpdateMonitor.getInstance(mContext).removeCallback(mUpdateMonitorCallbacks);

}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mUpdateMonitorCallbacks);
}

private KeyguardUpdateMonitorCallback mUpdateMonitorCallbacks =
new KeyguardUpdateMonitorCallback() {
@Override
public void onBootCompleted() {
if (mPerformAppWidgetSizeUpdateOnBootComplete) {
performAppWidgetSizeCallbacksIfNecessary();
mPerformAppWidgetSizeUpdateOnBootComplete = false;
}
}
};

void setIsHoveringOverDeleteDropTarget(boolean isHovering) {
if (ENABLE_HOVER_OVER_DELETE_DROP_TARGET_OVERLAY) {
if (mIsHoveringOverDeleteDropTarget != isHovering) {
Expand Down Expand Up @@ -453,12 +472,14 @@ private void performAppWidgetSizeCallbacksIfNecessary() {
View content = getContent();
if (!(content instanceof AppWidgetHostView)) return;

boolean sizeDirty = content.getMeasuredWidth() != mLastMeasuredWidth ||
content.getMeasuredHeight() != mLastMeasuredHeight;
if (sizeDirty) {

if (!KeyguardUpdateMonitor.getInstance(mContext).hasBootCompleted()) {
mPerformAppWidgetSizeUpdateOnBootComplete = true;
return;
}

// TODO: there's no reason to force the AppWidgetHostView to catch duplicate size calls.
// We can do that even more cheaply here. It's not an issue right now since we're in the
// system process and hence no binder calls.
AppWidgetHostView awhv = (AppWidgetHostView) content;
float density = getResources().getDisplayMetrics().density;

Expand Down

0 comments on commit 3e9cba4

Please sign in to comment.