diff options
author | d34d <clark@cyngn.com> | 2016-01-13 11:15:43 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-01-14 10:50:00 -0800 |
commit | 0f4b580ed9af38dabb217e4cb843c0b0acf210ee (patch) | |
tree | 5a05d3898d71220cc1a6f850828787dc46fc30a0 | |
parent | 9501c4aaa1602eb3d2aaa0087f7aacf042253a4a (diff) | |
download | frameworks_base-0f4b580ed9af38dabb217e4cb843c0b0acf210ee.zip frameworks_base-0f4b580ed9af38dabb217e4cb843c0b0acf210ee.tar.gz frameworks_base-0f4b580ed9af38dabb217e4cb843c0b0acf210ee.tar.bz2 |
SysUI: Reuse controllers and managers
Recreating the status bar causes a lot of objects to be recreated
that can easily be reused. This patch only creates these objects
when they are null.
Change-Id: I5f6f475bab386a4cf381ca8c9cc6a4d46449a938
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java | 145 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java | 4 |
2 files changed, 101 insertions, 48 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index ffa8134..b93c17a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -346,6 +346,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // settings private QSDragPanel mQSPanel; + private QSTileHost mQSTileHost; private DevForceNavbarObserver mDevForceNavbarObserver; // top bar @@ -911,7 +912,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, R.color.notification_panel_solid_background))); } - mHeadsUpManager = new HeadsUpManager(context, mStatusBarWindow); + if (mHeadsUpManager == null) { + mHeadsUpManager = new HeadsUpManager(context, mStatusBarWindow); + } mHeadsUpManager.setBar(this); mHeadsUpManager.addListener(this); mHeadsUpManager.addListener(mNotificationPanel); @@ -955,7 +958,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // no window manager? good luck with that } - mAssistManager = new AssistManager(this, context); + if (mAssistManager == null) { + mAssistManager = new AssistManager(this, context); + } if (mNavigationBarView == null) { mAssistManager.onConfigurationChanged(); } @@ -1039,40 +1044,65 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mHandlerThread.start(); // Other icons - mLocationController = new LocationControllerImpl(mContext, - mHandlerThread.getLooper()); // will post a notification - mBatteryController = new BatteryController(mContext, mHandler); - mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() { - @Override - public void onPowerSaveChanged() { - mHandler.post(mCheckBarModes); - if (mDozeServiceHost != null) { - mDozeServiceHost.firePowerSaveChanged(mBatteryController.isPowerSave()); + if (mLocationController == null) { + mLocationController = new LocationControllerImpl(mContext, + mHandlerThread.getLooper()); // will post a notification + } + if (mBatteryController == null) { + mBatteryController = new BatteryController(mContext, mHandler); + mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() { + @Override + public void onPowerSaveChanged() { + mHandler.post(mCheckBarModes); + if (mDozeServiceHost != null) { + mDozeServiceHost.firePowerSaveChanged(mBatteryController.isPowerSave()); + } } - } - @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { - // noop - } - @Override - public void onBatteryStyleChanged(int style, int percentMode) { - // noop - } - }); - mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper()); - mHotspotController = new HotspotControllerImpl(mContext); - mBluetoothController = new BluetoothControllerImpl(mContext, mHandlerThread.getLooper()); - mSecurityController = new SecurityControllerImpl(mContext); + + @Override + public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { + // noop + } + + @Override + public void onBatteryStyleChanged(int style, int percentMode) { + // noop + } + }); + } + if (mNetworkController == null) { + mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper()); + } + if (mHotspotController == null) { + mHotspotController = new HotspotControllerImpl(mContext); + } + if (mBluetoothController == null) { + mBluetoothController = new BluetoothControllerImpl(mContext, + mHandlerThread.getLooper()); + } + if (mSecurityController == null) { + mSecurityController = new SecurityControllerImpl(mContext); + } if (mContext.getResources().getBoolean(R.bool.config_showRotationLock)) { - mRotationLockController = new RotationLockControllerImpl(mContext); + if (mRotationLockController == null) { + mRotationLockController = new RotationLockControllerImpl(mContext); + } + } + if (mUserInfoController == null) { + mUserInfoController = new UserInfoController(mContext); } - mUserInfoController = new UserInfoController(mContext); mVolumeComponent = getComponent(VolumeComponent.class); if (mVolumeComponent != null) { - mZenModeController = mVolumeComponent.getZenController(); + if (mZenModeController == null) { + mZenModeController = mVolumeComponent.getZenController(); + } + } + if (mCastController == null) { + mCastController = new CastControllerImpl(mContext); + } + if (mSuController == null) { + mSuController = new SuControllerImpl(mContext); } - mCastController = new CastControllerImpl(mContext); - mSuController = new SuControllerImpl(mContext); final SignalClusterView signalCluster = (SignalClusterView) mStatusBarView.findViewById(R.id.signal_cluster); final SignalClusterView signalClusterKeyguard = @@ -1093,19 +1123,31 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mNetworkController.addEmergencyListener(mHeader); } - mFlashlightController = new FlashlightController(mContext); + if (mFlashlightController == null) { + mFlashlightController = new FlashlightController(mContext); + } mKeyguardBottomArea.setFlashlightController(mFlashlightController); mKeyguardBottomArea.setPhoneStatusBar(this); mKeyguardBottomArea.setUserSetupComplete(mUserSetup); - mAccessibilityController = new AccessibilityController(mContext); + if (mAccessibilityController == null) { + mAccessibilityController = new AccessibilityController(mContext); + } mKeyguardBottomArea.setAccessibilityController(mAccessibilityController); - mNextAlarmController = new NextAlarmController(mContext); - mKeyguardMonitor = new KeyguardMonitor(mContext); + if (mNextAlarmController == null) { + mNextAlarmController = new NextAlarmController(mContext); + } + if (mKeyguardMonitor == null) { + mKeyguardMonitor = new KeyguardMonitor(mContext); + } if (UserSwitcherController.isUserSwitcherAvailable(UserManager.get(mContext))) { - mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor, - mHandler); + if (mUserSwitcherController == null) { + mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor, + mHandler); + } + } + if (mWeatherController == null) { + mWeatherController = new WeatherControllerImpl(mContext); } - mWeatherController = new WeatherControllerImpl(mContext); mKeyguardUserSwitcher = new KeyguardUserSwitcher(mContext, (ViewStub) mStatusBarWindowContent.findViewById(R.id.keyguard_user_switcher), @@ -1115,24 +1157,28 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // Set up the quick settings tile panel mQSPanel = (QSDragPanel) mStatusBarWindowContent.findViewById(R.id.quick_settings_panel); if (mQSPanel != null) { - final QSTileHost qsh = new QSTileHost(mContext, this, - mBluetoothController, mLocationController, mRotationLockController, - mNetworkController, mZenModeController, mHotspotController, - mCastController, mFlashlightController, - mUserSwitcherController, mKeyguardMonitor, - mSecurityController); - mQSPanel.setHost(qsh); - mQSPanel.setTiles(qsh.getTiles()); - mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindowContent); + if (mQSTileHost == null) { + mQSTileHost = new QSTileHost(mContext, this, + mBluetoothController, mLocationController, mRotationLockController, + mNetworkController, mZenModeController, mHotspotController, + mCastController, mFlashlightController, + mUserSwitcherController, mKeyguardMonitor, + mSecurityController); + } + mQSPanel.setHost(mQSTileHost); + mQSPanel.setTiles(mQSTileHost.getTiles()); + if (mBrightnessMirrorController == null) { + mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindowContent); + } mQSPanel.setBrightnessMirror(mBrightnessMirrorController); mHeader.setQSPanel(mQSPanel); - qsh.setCallback(new QSTileHost.Callback() { + mQSTileHost.setCallback(new QSTileHost.Callback() { @Override public void onTilesChanged() { mHandler.post(new Runnable() { @Override public void run() { - mQSPanel.setTiles(qsh.getTiles()); + mQSPanel.setTiles(mQSTileHost.getTiles()); } }); } @@ -3595,6 +3641,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mNetworkController != null) { removeSignalCallbacks(mNetworkController); } + if (mHeadsUpManager != null) { + mHeadsUpManager.removeListener(mNotificationPanel); + } mStatusBarWindow.removeContent(mStatusBarWindowContent); mStatusBarWindow.clearDisappearingChildren(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java index 4a95d3a..5847f42 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java @@ -160,6 +160,10 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL mListeners.add(listener); } + public void removeListener(OnHeadsUpChangedListener listener) { + mListeners.remove(listener); + } + public PhoneStatusBar getBar() { return mBar; } |