Fix the problem that when the MainSwitchPreference is gone,

there will be a blank area.

- Disable the visibility of preference when the the hide() method
  is invoked.

Fix: 192332931
Test: robotest and see the UI
Change-Id: Iec5a06ca689843ebb692b1b7040f1d2be9f45bc2
This commit is contained in:
Stanley Wang
2021-07-01 22:47:55 +08:00
parent f1b07d7ddd
commit b757a6e9f2
2 changed files with 5 additions and 5 deletions

View File

@@ -50,7 +50,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
private SettingsMainSwitchBar mMainSwitchBar; private SettingsMainSwitchBar mMainSwitchBar;
private CharSequence mTitle; private CharSequence mTitle;
private boolean mIsVisible;
private EnforcedAdmin mEnforcedAdmin; private EnforcedAdmin mEnforcedAdmin;
private RestrictedPreferenceHelper mRestrictedHelper; private RestrictedPreferenceHelper mRestrictedHelper;
@@ -87,7 +86,7 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
} }
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar); mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
initMainSwitchBar(); initMainSwitchBar();
if (mIsVisible) { if (isVisible()) {
mMainSwitchBar.show(); mMainSwitchBar.show();
if (mMainSwitchBar.isChecked() != isChecked()) { if (mMainSwitchBar.isChecked() != isChecked()) {
setChecked(isChecked()); setChecked(isChecked());
@@ -101,7 +100,6 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
private void init(Context context, AttributeSet attrs) { private void init(Context context, AttributeSet attrs) {
setLayoutResource(R.layout.preference_widget_main_switch); setLayoutResource(R.layout.preference_widget_main_switch);
mSwitchChangeListeners.add(this); mSwitchChangeListeners.add(this);
mIsVisible = true;
if (attrs != null) { if (attrs != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, final TypedArray a = context.obtainStyledAttributes(attrs,
@@ -151,7 +149,7 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
* Show the MainSwitchBar * Show the MainSwitchBar
*/ */
public void show() { public void show() {
mIsVisible = true; setVisible(true);
if (mMainSwitchBar != null) { if (mMainSwitchBar != null) {
mMainSwitchBar.show(); mMainSwitchBar.show();
} }
@@ -161,7 +159,7 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
* Hide the MainSwitchBar * Hide the MainSwitchBar
*/ */
public void hide() { public void hide() {
mIsVisible = false; setVisible(false);
if (mMainSwitchBar != null) { if (mMainSwitchBar != null) {
mMainSwitchBar.hide(); mMainSwitchBar.hide();
} }

View File

@@ -76,6 +76,7 @@ public class SettingsMainSwitchPreferenceTest {
mPreference.onBindViewHolder(mHolder); mPreference.onBindViewHolder(mHolder);
assertThat(mPreference.isShowing()).isTrue(); assertThat(mPreference.isShowing()).isTrue();
assertThat(mPreference.isVisible()).isTrue();
} }
@Test @Test
@@ -85,5 +86,6 @@ public class SettingsMainSwitchPreferenceTest {
mPreference.onBindViewHolder(mHolder); mPreference.onBindViewHolder(mHolder);
assertThat(mPreference.isShowing()).isFalse(); assertThat(mPreference.isShowing()).isFalse();
assertThat(mPreference.isVisible()).isFalse();
} }
} }