diff --git a/src/com/android/settings/panel/MediaOutputPanel.java b/src/com/android/settings/panel/MediaOutputPanel.java index 54efd85fe0d..31ae31b503c 100644 --- a/src/com/android/settings/panel/MediaOutputPanel.java +++ b/src/com/android/settings/panel/MediaOutputPanel.java @@ -166,7 +166,7 @@ public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceC } @Override - public CharSequence getCustomButtonTitle() { + public CharSequence getCustomizedButtonTitle() { return mContext.getText(R.string.media_output_panel_stop_casting_button); } diff --git a/src/com/android/settings/panel/PanelContent.java b/src/com/android/settings/panel/PanelContent.java index 2e8d709e5c1..6c271fd11d9 100644 --- a/src/com/android/settings/panel/PanelContent.java +++ b/src/com/android/settings/panel/PanelContent.java @@ -86,9 +86,9 @@ public interface PanelContent extends Instrumentable { } /** - * @return a string for the title of the custom button. + * @return a string for the title of the customized button. */ - default CharSequence getCustomButtonTitle() { + default CharSequence getCustomizedButtonTitle() { return null; } diff --git a/src/com/android/settings/panel/PanelFragment.java b/src/com/android/settings/panel/PanelFragment.java index 28515fd24d3..14450a32b83 100644 --- a/src/com/android/settings/panel/PanelFragment.java +++ b/src/com/android/settings/panel/PanelFragment.java @@ -216,7 +216,7 @@ public class PanelFragment extends Fragment { mDoneButton.setOnClickListener(getCloseListener()); if (mPanel.isCustomizedButtonUsed()) { - final CharSequence customTitle = mPanel.getCustomButtonTitle(); + final CharSequence customTitle = mPanel.getCustomizedButtonTitle(); if (TextUtils.isEmpty(customTitle)) { mSeeMoreButton.setVisibility(View.GONE); } else { @@ -422,6 +422,7 @@ public class PanelFragment extends Fragment { ThreadUtils.postOnMainThread(() -> { mSeeMoreButton.setVisibility( mPanel.isCustomizedButtonUsed() ? View.VISIBLE : View.GONE); + mSeeMoreButton.setText(mPanel.getCustomizedButtonTitle()); }); } diff --git a/tests/robotests/src/com/android/settings/panel/FakePanelContent.java b/tests/robotests/src/com/android/settings/panel/FakePanelContent.java index bf2ac0dcb8f..0f1889c6e6c 100644 --- a/tests/robotests/src/com/android/settings/panel/FakePanelContent.java +++ b/tests/robotests/src/com/android/settings/panel/FakePanelContent.java @@ -46,6 +46,8 @@ public class FakePanelContent implements PanelContent { private CharSequence mSubTitle; private IconCompat mIcon; private int mViewType; + private boolean mIsCustomizedButtonUsed = false; + private CharSequence mCustomizedButtonTitle; @Override public IconCompat getIcon() { @@ -97,4 +99,22 @@ public class FakePanelContent implements PanelContent { public int getViewType() { return mViewType; } + + @Override + public boolean isCustomizedButtonUsed() { + return mIsCustomizedButtonUsed; + } + + public void setIsCustomizedButtonUsed(boolean isUsed) { + mIsCustomizedButtonUsed = isUsed; + } + + @Override + public CharSequence getCustomizedButtonTitle() { + return mCustomizedButtonTitle; + } + + public void setCustomizedButtonTitle(CharSequence title) { + mCustomizedButtonTitle = title; + } } diff --git a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java index 9df5af17cb5..25d02ed7d94 100644 --- a/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java +++ b/tests/robotests/src/com/android/settings/panel/PanelFragmentTest.java @@ -31,6 +31,7 @@ import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; @@ -250,4 +251,27 @@ public class PanelFragmentTest { verify(mActivity).finish(); } + + @Test + public void onCustomizedButtonStateChanged_isCustomized_showCustomizedTitle() { + final ActivityController activityController = + Robolectric.buildActivity(FakeSettingsPanelActivity.class); + activityController.setup(); + final PanelFragment panelFragment = (PanelFragment) + Objects.requireNonNull(activityController + .get() + .getSupportFragmentManager() + .findFragmentById(R.id.main_content)); + + final Button seeMoreButton = panelFragment.mLayoutView.findViewById(R.id.see_more); + + mFakePanelContent.setIsCustomizedButtonUsed(true); + mFakePanelContent.setCustomizedButtonTitle("test_title"); + verify(mFakePanelContent).registerCallback(mPanelContentCbs.capture()); + final PanelContentCallback panelContentCallbacks = mPanelContentCbs.getValue(); + panelContentCallbacks.onCustomizedButtonStateChanged(); + + assertThat(seeMoreButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(seeMoreButton.getText()).isEqualTo("test_title"); + } } \ No newline at end of file