diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileBaseView.java | 13 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileBaseViewTest.kt | 146 |
2 files changed, 156 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileBaseView.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileBaseView.java index 38e2ba4df79a..33ca7d6bafd8 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileBaseView.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileBaseView.java @@ -259,23 +259,30 @@ public class QSTileBaseView extends com.android.systemui.plugins.qs.QSTileView { mIcon.setIcon(state, allowAnimations); setContentDescription(state.contentDescription); final StringBuilder stateDescription = new StringBuilder(); + String text = ""; switch (state.state) { case Tile.STATE_UNAVAILABLE: - stateDescription.append(mContext.getString(R.string.tile_unavailable)); + text = mContext.getString(R.string.tile_unavailable); break; case Tile.STATE_INACTIVE: if (state instanceof QSTile.BooleanState) { - stateDescription.append(mContext.getString(R.string.switch_bar_off)); + text = mContext.getString(R.string.switch_bar_off); } break; case Tile.STATE_ACTIVE: if (state instanceof QSTile.BooleanState) { - stateDescription.append(mContext.getString(R.string.switch_bar_on)); + text = mContext.getString(R.string.switch_bar_on); } break; default: break; } + if (!TextUtils.isEmpty(text)) { + stateDescription.append(text); + if (TextUtils.isEmpty(state.secondaryLabel)) { + state.secondaryLabel = text; + } + } if (!TextUtils.isEmpty(state.stateDescription)) { stateDescription.append(", "); stateDescription.append(state.stateDescription); diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileBaseViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileBaseViewTest.kt new file mode 100644 index 000000000000..998e070009cc --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSTileBaseViewTest.kt @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.qs.tileimpl + +import android.service.quicksettings.Tile +import android.testing.AndroidTestingRunner +import android.text.TextUtils +import androidx.test.filters.SmallTest +import com.android.systemui.R +import com.android.systemui.SysuiTestCase +import com.android.systemui.plugins.qs.QSIconView +import com.android.systemui.plugins.qs.QSTile +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +@RunWith(AndroidTestingRunner::class) +@SmallTest +class QSTileBaseViewTest : SysuiTestCase() { + + @Mock + private lateinit var iconView: QSIconView + + private lateinit var tileView: QSTileBaseView + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + tileView = QSTileBaseView(context, iconView, false) + } + + @Test + fun testSecondaryLabelNotModified_unavailable() { + val state = QSTile.State() + val testString = "TEST STRING" + state.state = Tile.STATE_UNAVAILABLE + state.secondaryLabel = testString + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo(testString) + } + + @Test + fun testSecondaryLabelNotModified_booleanInactive() { + val state = QSTile.BooleanState() + val testString = "TEST STRING" + state.state = Tile.STATE_INACTIVE + state.secondaryLabel = testString + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo(testString) + } + + @Test + fun testSecondaryLabelNotModified_booleanActive() { + val state = QSTile.BooleanState() + val testString = "TEST STRING" + state.state = Tile.STATE_ACTIVE + state.secondaryLabel = testString + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo(testString) + } + + @Test + fun testSecondaryLabelNotModified_availableNotBoolean_inactive() { + val state = QSTile.State() + state.state = Tile.STATE_INACTIVE + state.secondaryLabel = "" + + tileView.handleStateChanged(state) + + assertThat(TextUtils.isEmpty(state.secondaryLabel)).isTrue() + } + + @Test + fun testSecondaryLabelNotModified_availableNotBoolean_active() { + val state = QSTile.State() + state.state = Tile.STATE_ACTIVE + state.secondaryLabel = "" + + tileView.handleStateChanged(state) + + assertThat(TextUtils.isEmpty(state.secondaryLabel)).isTrue() + } + + @Test + fun testSecondaryLabelDescription_unavailable() { + val state = QSTile.State() + state.state = Tile.STATE_UNAVAILABLE + state.secondaryLabel = "" + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo( + context.getString(R.string.tile_unavailable) + ) + } + + @Test + fun testSecondaryLabelDescription_booleanInactive() { + val state = QSTile.BooleanState() + state.state = Tile.STATE_INACTIVE + state.secondaryLabel = "" + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo( + context.getString(R.string.switch_bar_off) + ) + } + + @Test + fun testSecondaryLabelDescription_booleanActive() { + val state = QSTile.BooleanState() + state.state = Tile.STATE_ACTIVE + state.secondaryLabel = "" + + tileView.handleStateChanged(state) + + assertThat(state.secondaryLabel as CharSequence).isEqualTo( + context.getString(R.string.switch_bar_on) + ) + } +}
\ No newline at end of file |