Merge "Update "none selected" state to align with mocks:" into main

This commit is contained in:
Becca Hughes
2024-02-13 20:15:18 +00:00
committed by Android (Google) Code Review
5 changed files with 37 additions and 64 deletions

View File

@@ -473,4 +473,8 @@
<!-- An arbitrarily large number to make the max size fit the parent -->
<dimen name="animation_max_size">1000dp</dimen>
<!-- Credential Manager settings dimensions -->
<dimen name="credman_primary_provider_pref_left_padding">80dp</dimen>
<dimen name="credman_primary_provider_pref_left_padding_compact">24dp</dimen>
</resources>

View File

@@ -10802,6 +10802,8 @@
<string name="credman_button_change">Change</string>
<!-- Button for opening credman service settings. [CHAR LIMIT=40] -->
<string name="credman_button_open">Open</string>
<!-- Label for None item in Credential Manager service selection [CHAR LIMIT=40] -->
<string name="credman_app_list_preference_none">None selected</string>
<!-- Message of the warning dialog for setting the auto-fill app. [CHAR_LIMIT=NONE] -->
<string name="autofill_confirmation_message">

View File

@@ -114,7 +114,7 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
@Nullable CharSequence packageName,
@Nullable CharSequence settingsActivity) {
if (appName == null) {
preference.setTitle(R.string.app_list_preference_none);
preference.setTitle(R.string.credman_app_list_preference_none);
} else {
preference.setTitle(appName);
}
@@ -144,7 +144,7 @@ public class DefaultCombinedPreferenceController extends DefaultAppPreferenceCon
// Hide the open button if there is no defined settings activity.
primaryPref.setOpenButtonVisible(!TextUtils.isEmpty(settingsActivity));
primaryPref.setButtonsVisible(appName != null);
primaryPref.setButtonsCompactMode(appName != null);
}
}

View File

@@ -46,7 +46,7 @@ public class PrimaryProviderPreference extends GearPreference {
private @Nullable View mButtonFrameView = null;
private @Nullable View mGearView = null;
private @Nullable Delegate mDelegate = null;
private boolean mButtonsVisible = false;
private boolean mButtonsCompactMode = false;
private boolean mOpenButtonVisible = false;
/** Called to send messages back to the parent controller. */
@@ -141,26 +141,7 @@ public class PrimaryProviderPreference extends GearPreference {
});
mButtonFrameView = holder.findViewById(R.id.credman_button_frame);
mButtonFrameView.setVisibility(mButtonsVisible ? View.VISIBLE : View.GONE);
// There is a special case where if the provider == none then we should
// hide the buttons and when the preference is tapped we can open the
// provider selection dialog.
setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(@NonNull Preference preference) {
return handlePreferenceClickNewSettingsUi();
}
});
}
private boolean handlePreferenceClickNewSettingsUi() {
if (mDelegate != null && !mButtonsVisible) {
mDelegate.onChangeButtonClicked();
return true;
}
return false;
updateButtonFramePadding();
}
public void setOpenButtonVisible(boolean isVisible) {
@@ -172,12 +153,27 @@ public class PrimaryProviderPreference extends GearPreference {
mOpenButtonVisible = isVisible;
}
public void setButtonsVisible(boolean isVisible) {
if (mButtonFrameView != null) {
setVisibility(mButtonFrameView, isVisible);
private void updateButtonFramePadding() {
if (mButtonFrameView == null) {
return;
}
mButtonsVisible = isVisible;
int paddingLeft = mButtonsCompactMode ?
getContext().getResources().getDimensionPixelSize(
R.dimen.credman_primary_provider_pref_left_padding) :
getContext().getResources().getDimensionPixelSize(
R.dimen.credman_primary_provider_pref_left_padding_compact);
mButtonFrameView.setPadding(
paddingLeft,
mButtonFrameView.getPaddingTop(),
mButtonFrameView.getPaddingRight(),
mButtonFrameView.getPaddingBottom());
}
public void setButtonsCompactMode(boolean isCompactMode) {
mButtonsCompactMode = isCompactMode;
updateButtonFramePadding();
}
public void setDelegate(@NonNull Delegate delegate) {

View File

@@ -114,50 +114,21 @@ public class PrimaryProviderPreferenceTest {
}
@Test
public void ensureButtonsClicksCallDelegate_newDesign_buttonsHidden() {
public void ensureButtonsClicksCallDelegate_newDesign_buttonsCompactMode() {
if (!PrimaryProviderPreference.shouldUseNewSettingsUi()) {
return;
}
PrimaryProviderPreference ppp = createTestPreferenceWithNewLayout();
int initialPaddingLeft = ppp.getButtonFrameView().getPaddingLeft();
// Test that the buttons are visible.
assertThat(ppp.getButtonFrameView()).isNotNull();
assertThat(ppp.getButtonFrameView().getVisibility()).isEqualTo(View.GONE);
assertThat(mReceivedChangeButtonClicked).isFalse();
// If we show the buttons the left padding should be updated.
ppp.setButtonsCompactMode(true);
assertThat(ppp.getButtonFrameView().getPaddingLeft()).isNotEqualTo(initialPaddingLeft);
// If we show the buttons the visiblility should be updated.
ppp.setButtonsVisible(true);
assertThat(ppp.getButtonFrameView().getVisibility()).isEqualTo(View.VISIBLE);
// If we hide the buttons the visibility should be updated.
ppp.setButtonsVisible(false);
assertThat(ppp.getButtonFrameView().getVisibility()).isEqualTo(View.GONE);
}
@Test
public void ensureButtonsClicksCallDelegate_oldDesign() {
if (PrimaryProviderPreference.shouldUseNewSettingsUi()) {
return;
}
PrimaryProviderPreference ppp = createTestPreference("preference_widget_gear");
// Test that clicking the preference results in the delegate being
// called.
assertThat(mReceivedOpenButtonClicked).isFalse();
ppp.getOnPreferenceClickListener().onPreferenceClick(ppp);
assertThat(mReceivedOpenButtonClicked).isTrue();
// Test that the gear button is present and visible.
assertThat(ppp.getGearView()).isNotNull();
assertThat(ppp.getGearView().getVisibility()).isEqualTo(View.VISIBLE);
// Test that clicking the gear button results in the delegate being
// called.
assertThat(mReceivedChangeButtonClicked).isFalse();
ppp.getGearView().performClick();
assertThat(mReceivedChangeButtonClicked).isTrue();
// If we hide the buttons the left padding should be updated.
ppp.setButtonsCompactMode(false);
assertThat(ppp.getButtonFrameView().getPaddingLeft()).isEqualTo(initialPaddingLeft);
}
private PrimaryProviderPreference createTestPreferenceWithNewLayout() {