Simplify config changes and request media host layout updates
- Each QSPanelController* class had its own OnConfigurationChangeListener, in addition to an overridable method in the base class that was called in the listener - moved the child class listener code into that method so there's a single listener registered. - When reattaching the media host after an orientation change, explicitly call setLayoutParams to ensure that a layout update is requested - Add more info about current config to dumpsys Bug: 198319256 Test: atest com.android.systemui.qs Test: manual - verify media view looks correct when rotating Change-Id: I5b34ba85e98b4fbf8fe3b24893d0423146aa5f75
This commit is contained in:
@@ -473,6 +473,8 @@ public class QSPanel extends LinearLayout implements Tunable {
|
|||||||
? Math.max(mMediaTotalBottomMargin - getPaddingBottom(), 0) : 0;
|
? Math.max(mMediaTotalBottomMargin - getPaddingBottom(), 0) : 0;
|
||||||
layoutParams.topMargin = mediaNeedsTopMargin() && !horizontal
|
layoutParams.topMargin = mediaNeedsTopMargin() && !horizontal
|
||||||
? mMediaTopMargin : 0;
|
? mMediaTopMargin : 0;
|
||||||
|
// Call setLayoutParams explicitly to ensure that requestLayout happens
|
||||||
|
hostView.setLayoutParams(layoutParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import static com.android.systemui.media.dagger.MediaModule.QS_PANEL;
|
|||||||
import static com.android.systemui.qs.QSPanel.QS_SHOW_BRIGHTNESS;
|
import static com.android.systemui.qs.QSPanel.QS_SHOW_BRIGHTNESS;
|
||||||
import static com.android.systemui.qs.dagger.QSFragmentModule.QS_USING_MEDIA_PLAYER;
|
import static com.android.systemui.qs.dagger.QSFragmentModule.QS_USING_MEDIA_PLAYER;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -61,17 +60,6 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
|||||||
private final BrightnessMirrorHandler mBrightnessMirrorHandler;
|
private final BrightnessMirrorHandler mBrightnessMirrorHandler;
|
||||||
private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
|
private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
|
||||||
|
|
||||||
private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
|
|
||||||
new QSPanel.OnConfigurationChangedListener() {
|
|
||||||
@Override
|
|
||||||
public void onConfigurationChange(Configuration newConfig) {
|
|
||||||
mView.updateResources();
|
|
||||||
if (mView.isListening()) {
|
|
||||||
refreshAllTiles();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View.OnTouchListener mTileLayoutTouchListener = new View.OnTouchListener() {
|
private View.OnTouchListener mTileLayoutTouchListener = new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
@@ -130,7 +118,6 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
|||||||
if (mView.isListening()) {
|
if (mView.isListening()) {
|
||||||
refreshAllTiles();
|
refreshAllTiles();
|
||||||
}
|
}
|
||||||
mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
|
||||||
switchTileLayout(true);
|
switchTileLayout(true);
|
||||||
mBrightnessMirrorHandler.onQsPanelAttached();
|
mBrightnessMirrorHandler.onQsPanelAttached();
|
||||||
|
|
||||||
@@ -147,11 +134,18 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
|
|||||||
@Override
|
@Override
|
||||||
protected void onViewDetached() {
|
protected void onViewDetached() {
|
||||||
mTunerService.removeTunable(mView);
|
mTunerService.removeTunable(mView);
|
||||||
mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
|
||||||
mBrightnessMirrorHandler.onQsPanelDettached();
|
mBrightnessMirrorHandler.onQsPanelDettached();
|
||||||
super.onViewDetached();
|
super.onViewDetached();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onConfigurationChanged() {
|
||||||
|
mView.updateResources();
|
||||||
|
if (mView.isListening()) {
|
||||||
|
refreshAllTiles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public void setVisibility(int visibility) {
|
public void setVisibility(int visibility) {
|
||||||
mView.setVisibility(visibility);
|
mView.setVisibility(visibility);
|
||||||
|
|||||||
@@ -101,11 +101,11 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
|||||||
+ newConfig.windowConfiguration);
|
+ newConfig.windowConfiguration);
|
||||||
mQSLogger.logOnConfigurationChanged(mLastOrientation, newConfig.orientation,
|
mQSLogger.logOnConfigurationChanged(mLastOrientation, newConfig.orientation,
|
||||||
mView.getDumpableTag());
|
mView.getDumpableTag());
|
||||||
onConfigurationChanged();
|
|
||||||
if (newConfig.orientation != mLastOrientation) {
|
if (newConfig.orientation != mLastOrientation) {
|
||||||
mLastOrientation = newConfig.orientation;
|
mLastOrientation = newConfig.orientation;
|
||||||
switchTileLayout(false);
|
switchTileLayout(false);
|
||||||
}
|
}
|
||||||
|
onConfigurationChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -422,6 +422,8 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
|
|||||||
}
|
}
|
||||||
if (mMediaHost != null) {
|
if (mMediaHost != null) {
|
||||||
pw.println(" media bounds: " + mMediaHost.getCurrentBounds());
|
pw.println(" media bounds: " + mMediaHost.getCurrentBounds());
|
||||||
|
pw.println(" horizontal layout: " + mUsingHorizontalLayout);
|
||||||
|
pw.println(" last orientation: " + mLastOrientation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,14 +46,6 @@ import javax.inject.Provider;
|
|||||||
@QSScope
|
@QSScope
|
||||||
public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel> {
|
public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel> {
|
||||||
|
|
||||||
private final QSPanel.OnConfigurationChangedListener mOnConfigurationChangedListener =
|
|
||||||
newConfig -> {
|
|
||||||
int newMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_tiles);
|
|
||||||
if (newMaxTiles != mView.getNumQuickTiles()) {
|
|
||||||
setMaxTiles(newMaxTiles);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final Provider<Boolean> mUsingCollapsedLandscapeMediaProvider;
|
private final Provider<Boolean> mUsingCollapsedLandscapeMediaProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -99,13 +91,11 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
|
|||||||
@Override
|
@Override
|
||||||
protected void onViewAttached() {
|
protected void onViewAttached() {
|
||||||
super.onViewAttached();
|
super.onViewAttached();
|
||||||
mView.addOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onViewDetached() {
|
protected void onViewDetached() {
|
||||||
super.onViewDetached();
|
super.onViewDetached();
|
||||||
mView.removeOnConfigurationChangedListener(mOnConfigurationChangedListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMaxTiles(int parseNumTiles) {
|
private void setMaxTiles(int parseNumTiles) {
|
||||||
@@ -115,6 +105,10 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onConfigurationChanged() {
|
protected void onConfigurationChanged() {
|
||||||
|
int newMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_tiles);
|
||||||
|
if (newMaxTiles != mView.getNumQuickTiles()) {
|
||||||
|
setMaxTiles(newMaxTiles);
|
||||||
|
}
|
||||||
updateMediaExpansion();
|
updateMediaExpansion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,7 +226,9 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
|
|||||||
+ " Tile records:\n"
|
+ " Tile records:\n"
|
||||||
+ " " + mockTileString + "\n"
|
+ " " + mockTileString + "\n"
|
||||||
+ " " + mockTileViewString + "\n"
|
+ " " + mockTileViewString + "\n"
|
||||||
+ " media bounds: null\n";
|
+ " media bounds: null\n"
|
||||||
|
+ " horizontal layout: false\n"
|
||||||
|
+ " last orientation: 0\n";
|
||||||
assertEquals(expected, w.getBuffer().toString());
|
assertEquals(expected, w.getBuffer().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,7 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun mediaExpansion_afterConfigChange_inLandscape_collapsedInLandscapeTrue_updatesToCollapsed() {
|
fun mediaExpansion_afterConfigChange_inLandscape_collapsedInLandscapeTrue_updatesToCollapsed() {
|
||||||
// times(2) because both controller and base controller are registering their listeners
|
verify(quickQSPanel).addOnConfigurationChangedListener(captor.capture())
|
||||||
verify(quickQSPanel, times(2)).addOnConfigurationChangedListener(captor.capture())
|
|
||||||
|
|
||||||
// verify that media starts in the expanded state by default
|
// verify that media starts in the expanded state by default
|
||||||
verify(mediaHost).expansion = MediaHostState.EXPANDED
|
verify(mediaHost).expansion = MediaHostState.EXPANDED
|
||||||
@@ -139,8 +138,7 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun mediaExpansion_afterConfigChange_landscape_collapsedInLandscapeFalse_remainsExpanded() {
|
fun mediaExpansion_afterConfigChange_landscape_collapsedInLandscapeFalse_remainsExpanded() {
|
||||||
// times(2) because both controller and base controller are registering their listeners
|
verify(quickQSPanel).addOnConfigurationChangedListener(captor.capture())
|
||||||
verify(quickQSPanel, times(2)).addOnConfigurationChangedListener(captor.capture())
|
|
||||||
reset(mediaHost)
|
reset(mediaHost)
|
||||||
|
|
||||||
usingCollapsedLandscapeMedia = false
|
usingCollapsedLandscapeMedia = false
|
||||||
|
|||||||
Reference in New Issue
Block a user