Merge "Hide subtitle for dialog from QS when applicable" into oc-mr1-dev

am: 70b438cadf

Change-Id: I288eaa026b8a2e4c11e67a8e00a78b6dd60914b6
This commit is contained in:
Winston Man
2017-08-17 18:11:36 +00:00
committed by android-build-merger
2 changed files with 88 additions and 0 deletions

View File

@@ -310,11 +310,47 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
vpnWarning.setMovementMethod(new LinkMovementMethod());
}
// Note: if a new section is added, should update configSubtitleVisibility to include
// the handling of the subtitle
configSubtitleVisibility(managementMessage != null,
caCertsMessage != null,
networkLoggingMessage != null,
vpnMessage != null,
dialogView);
mDialog.show();
mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
protected void configSubtitleVisibility(boolean showDeviceManagement, boolean showCaCerts,
boolean showNetworkLogging, boolean showVpn, View dialogView) {
// Device Management title should always been shown
// When there is a Device Management message, all subtitles should be shown
if (showDeviceManagement) {
return;
}
// Hide the subtitle if there is only 1 message shown
int mSectionCountExcludingDeviceMgt = 0;
if (showCaCerts) { mSectionCountExcludingDeviceMgt++; }
if (showNetworkLogging) { mSectionCountExcludingDeviceMgt++; }
if (showVpn) { mSectionCountExcludingDeviceMgt++; }
// No work needed if there is no sections or more than 1 section
if (mSectionCountExcludingDeviceMgt != 1) {
return;
}
if (showCaCerts) {
dialogView.findViewById(R.id.ca_certs_subtitle).setVisibility(View.GONE);
}
if (showNetworkLogging) {
dialogView.findViewById(R.id.network_logging_subtitle).setVisibility(View.GONE);
}
if (showVpn) {
dialogView.findViewById(R.id.vpn_subtitle).setVisibility(View.GONE);
}
}
private String getSettingsButton() {
return mContext.getString(R.string.monitoring_button_view_policies);
}

View File

@@ -29,6 +29,7 @@ import android.provider.Settings;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.SpannableStringBuilder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -395,6 +396,57 @@ public class QSSecurityFooterTest extends SysuiTestCase {
mFooter.getVpnMessage(false, true, VPN_PACKAGE, null));
}
@Test
public void testConfigSubtitleVisibility() {
View view = LayoutInflater.from(mContext)
.inflate(R.layout.quick_settings_footer_dialog, null);
// Device Management subtitle should be shown when there is Device Management section only
// Other sections visibility will be set somewhere else so it will not be tested here
mFooter.configSubtitleVisibility(true, false, false, false, view);
assertEquals(View.VISIBLE,
view.findViewById(R.id.device_management_subtitle).getVisibility());
// If there are multiple sections, all subtitles should be shown
mFooter.configSubtitleVisibility(true, true, false, false, view);
assertEquals(View.VISIBLE,
view.findViewById(R.id.device_management_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.ca_certs_subtitle).getVisibility());
// If there are multiple sections, all subtitles should be shown
mFooter.configSubtitleVisibility(true, true, true, true, view);
assertEquals(View.VISIBLE,
view.findViewById(R.id.device_management_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.ca_certs_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.network_logging_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.vpn_subtitle).getVisibility());
// If there are multiple sections, all subtitles should be shown, event if there is no
// Device Management section
mFooter.configSubtitleVisibility(false, true, true, true, view);
assertEquals(View.VISIBLE,
view.findViewById(R.id.ca_certs_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.network_logging_subtitle).getVisibility());
assertEquals(View.VISIBLE,
view.findViewById(R.id.vpn_subtitle).getVisibility());
// If there is only 1 section, the title should be hidden
mFooter.configSubtitleVisibility(false, true, false, false, view);
assertEquals(View.GONE,
view.findViewById(R.id.ca_certs_subtitle).getVisibility());
mFooter.configSubtitleVisibility(false, false, true, false, view);
assertEquals(View.GONE,
view.findViewById(R.id.network_logging_subtitle).getVisibility());
mFooter.configSubtitleVisibility(false, false, false, true, view);
assertEquals(View.GONE,
view.findViewById(R.id.vpn_subtitle).getVisibility());
}
private CharSequence addLink(CharSequence description) {
final SpannableStringBuilder message = new SpannableStringBuilder();
message.append(description);