Merge "[Dagger] Remove ConfigurationController from BatteryMeterView." into sc-v2-dev am: df4f102c95
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15362950 Change-Id: Ib666a428909a93d72abfa85efcb980330d2ded61
This commit is contained in:
@@ -18,7 +18,6 @@ package com.android.systemui.battery;
|
||||
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
|
||||
|
||||
import static com.android.systemui.DejankUtils.whitelistIpcs;
|
||||
import static com.android.systemui.util.SysuiLifecycle.viewAttachLifecycle;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
@@ -61,8 +60,6 @@ import com.android.systemui.settings.CurrentUserTracker;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
import com.android.systemui.tuner.TunerService.Tunable;
|
||||
|
||||
@@ -72,8 +69,7 @@ import java.lang.annotation.Retention;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class BatteryMeterView extends LinearLayout implements
|
||||
BatteryStateChangeCallback, Tunable, DarkReceiver, ConfigurationListener {
|
||||
|
||||
BatteryStateChangeCallback, Tunable, DarkReceiver {
|
||||
|
||||
@Retention(SOURCE)
|
||||
@IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF, MODE_ESTIMATE})
|
||||
@@ -167,7 +163,6 @@ public class BatteryMeterView extends LinearLayout implements
|
||||
|
||||
setClipChildren(false);
|
||||
setClipToPadding(false);
|
||||
Dependency.get(ConfigurationController.class).observe(viewAttachLifecycle(this), this);
|
||||
}
|
||||
|
||||
private void setupLayoutTransition() {
|
||||
@@ -398,11 +393,6 @@ public class BatteryMeterView extends LinearLayout implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDensityOrFontScaleChanged() {
|
||||
scaleBatteryMeterViews();
|
||||
}
|
||||
|
||||
private Drawable getUnknownStateDrawable() {
|
||||
if (mUnknownStateDrawable == null) {
|
||||
mUnknownStateDrawable = mContext.getDrawable(R.drawable.ic_battery_unknown);
|
||||
@@ -432,7 +422,7 @@ public class BatteryMeterView extends LinearLayout implements
|
||||
/**
|
||||
* Looks up the scale factor for status bar icons and scales the battery view by that amount.
|
||||
*/
|
||||
private void scaleBatteryMeterViews() {
|
||||
void scaleBatteryMeterViews() {
|
||||
Resources res = getContext().getResources();
|
||||
TypedValue typedValue = new TypedValue();
|
||||
|
||||
|
||||
@@ -15,22 +15,44 @@
|
||||
*/
|
||||
package com.android.systemui.battery;
|
||||
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.util.ViewController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** Controller for {@link BatteryMeterView}. **/
|
||||
public class BatteryMeterViewController extends ViewController<BatteryMeterView> {
|
||||
private final ConfigurationController mConfigurationController;
|
||||
|
||||
private final ConfigurationController.ConfigurationListener mConfigurationListener =
|
||||
new ConfigurationController.ConfigurationListener() {
|
||||
@Override
|
||||
public void onDensityOrFontScaleChanged() {
|
||||
mView.scaleBatteryMeterViews();
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public BatteryMeterViewController(BatteryMeterView view) {
|
||||
public BatteryMeterViewController(
|
||||
BatteryMeterView view,
|
||||
ConfigurationController configurationController) {
|
||||
super(view);
|
||||
mConfigurationController = configurationController;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewAttached() {
|
||||
mConfigurationController.addCallback(mConfigurationListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onViewDetached() {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
mConfigurationController.removeCallback(mConfigurationListener);
|
||||
}
|
||||
}
|
||||
@@ -159,10 +159,16 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
|
||||
@Override
|
||||
protected void onViewDetached() {
|
||||
destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Don't receive future #onViewAttached calls so that we don't accidentally have two
|
||||
// controllers registered for the same view.
|
||||
// TODO(b/194181195): This shouldn't be necessary.
|
||||
destroy();
|
||||
super.destroy();
|
||||
mBatteryMeterViewController.destroy();
|
||||
|
||||
mConfigurationController.removeCallback(mConfigurationListener);
|
||||
mAnimationScheduler.removeCallback(mAnimationCallback);
|
||||
|
||||
@@ -988,7 +988,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
mKeyguardStatusBarViewComponentFactory.build(keyguardStatusBarView);
|
||||
if (mKeyguardStatusBarViewController != null) {
|
||||
// TODO(b/194181195): This shouldn't be necessary.
|
||||
mKeyguardStatusBarViewController.onViewDetached();
|
||||
mKeyguardStatusBarViewController.destroy();
|
||||
}
|
||||
mKeyguardStatusBarViewController =
|
||||
statusBarViewComponent.getKeyguardStatusBarViewController();
|
||||
|
||||
@@ -1212,7 +1212,7 @@ public class StatusBar extends SystemUI implements
|
||||
mPhoneStatusBarViewController.init();
|
||||
|
||||
mBatteryMeterViewController = new BatteryMeterViewController(
|
||||
mStatusBarView.findViewById(R.id.battery)
|
||||
mStatusBarView.findViewById(R.id.battery), mConfigurationController
|
||||
);
|
||||
mBatteryMeterViewController.init();
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.battery;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
public class BatteryMeterViewControllerTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private BatteryMeterView mBatteryMeterView;
|
||||
|
||||
@Mock
|
||||
private ConfigurationController mConfigurationController;
|
||||
|
||||
private BatteryMeterViewController mController;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mController = new BatteryMeterViewController(
|
||||
mBatteryMeterView,
|
||||
mConfigurationController
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onViewAttached_callbacksRegistered() {
|
||||
mController.onViewAttached();
|
||||
|
||||
verify(mConfigurationController).addCallback(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onViewDetached_callbacksUnregistered() {
|
||||
// Set everything up first.
|
||||
mController.onViewAttached();
|
||||
|
||||
mController.onViewDetached();
|
||||
|
||||
verify(mConfigurationController).removeCallback(any());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user