From 29aa7d1a1fd42157aaebf9eb157ed4d7e9f3cd7e Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Fri, 4 May 2012 15:40:50 +0100 Subject: Fix for disappearing status bar power widgets after changing theme Backported from CM9: Clean up existing widgets before creating new ones to prevent dangling references to the previous dialog's context, which broke the insertion of a new widget set into recently created ExpandedDialog views. Change-Id: I16a3bab85bcc07dcdb3b189809f5dae528eff66a --- .../src/com/android/systemui/statusbar/StatusBarService.java | 6 ++++++ .../com/android/systemui/statusbar/powerwidget/PowerWidget.java | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java index fd4107a..8783a85 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java @@ -400,6 +400,12 @@ public class StatusBarService extends Service implements CommandQueue.Callbacks mDateView = (DateView)sb.findViewById(R.id.date); mCmBatteryMiniIcon = (CmBatteryMiniIcon)sb.findViewById(R.id.CmBatteryMiniIcon); + /* Destroy any existing widgets before recreating the expanded dialog + * to ensure there are no lost context issues */ + if (mPowerWidget != null) { + mPowerWidget.destroyWidget(); + } + mExpandedDialog = new ExpandedDialog(context); mExpandedView = expanded; mExpandedContents = expanded.findViewById(R.id.notificationLinearLayout); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java index 438541a..b51ff3d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/powerwidget/PowerWidget.java @@ -84,7 +84,7 @@ public class PowerWidget extends FrameLayout { updateVisibility(); } - public void setupWidget() { + public void destroyWidget() { Log.i(TAG, "Clearing any old widget stuffs"); // remove all views from the layout removeAllViews(); @@ -92,14 +92,21 @@ public class PowerWidget extends FrameLayout { // unregister our content receiver if(mBroadcastReceiver != null) { mContext.unregisterReceiver(mBroadcastReceiver); + mBroadcastReceiver = null; } // unobserve our content if(mObserver != null) { mObserver.unobserve(); + mObserver = null; } // clear the button instances PowerButton.unloadAllButtons(); + } + + + public void setupWidget() { + destroyWidget(); Log.i(TAG, "Setting up widget"); -- cgit v1.1