Merge "Fix the problem that the "Turn off SIM" dialog will be displayed when the MobileNetwork page is slid to to top." into sc-dev

This commit is contained in:
Stanley Wang
2021-06-16 11:42:00 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 6 deletions

View File

@@ -82,15 +82,15 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
holder.setDividerAllowedAbove(false);
holder.setDividerAllowedBelow(false);
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
mMainSwitchBar.show();
if (mRestrictedHelper != null) {
mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced();
}
updateStatus(isChecked());
registerListenerToSwitchBar();
if (!mIsVisible) {
mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
if (mIsVisible) {
mMainSwitchBar.show();
updateStatus(isChecked());
registerListenerToSwitchBar();
} else {
mMainSwitchBar.hide();
}
}

View File

@@ -24,6 +24,10 @@ import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +43,7 @@ public class SettingsMainSwitchPreferenceTest {
@Mock
private EnforcedAdmin mEnforcedAdmin;
private SettingsMainSwitchPreference mPreference;
private PreferenceViewHolder mHolder;
@Before
public void setUp() {
@@ -48,6 +53,9 @@ public class SettingsMainSwitchPreferenceTest {
mPreference = new SettingsMainSwitchPreference(context);
ReflectionHelpers.setField(mPreference, "mEnforcedAdmin", mEnforcedAdmin);
ReflectionHelpers.setField(mPreference, "mMainSwitchBar", switchBar);
final View rootView = View.inflate(context, R.layout.preference_widget_main_switch,
null /* parent */);
mHolder = PreferenceViewHolder.createInstanceForTests(rootView);
}
@Test
@@ -60,4 +68,22 @@ public class SettingsMainSwitchPreferenceTest {
assertThat(restrictedIcon.getVisibility() == View.VISIBLE).isTrue();
}
@Test
public void show_preferenceShouldDisplay() {
mPreference.show();
mPreference.onBindViewHolder(mHolder);
assertThat(mPreference.isShowing()).isTrue();
}
@Test
public void hide_preferenceShouldNotDisplay() {
mPreference.hide();
mPreference.onBindViewHolder(mHolder);
assertThat(mPreference.isShowing()).isFalse();
}
}