Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 634044dc authored by govenliu's avatar govenliu Committed by Goven Liu
Browse files

[Wi-Fi] [a11y] In Wi-Fi data usage page, Talkback should also announce the...

[Wi-Fi] [a11y] In Wi-Fi data usage page, Talkback should also announce the Progress bar percentage instead of "Progress bar" only.

Add conent description for talkback to announce, if the progress bar is 50%, then before modification is "Progress bar", and after modification is "50% Progress bar".

Bug: 146811265
Test: Add following unit test case to test if content description is correct or not:
      createPref_progressBarShouldSetPercentageContentDescription().

Change-Id: I71483df8e12f08c4c8c96ab3964666bf97872a83
parent 4ee5d181
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import com.android.settingslib.net.UidDetailProvider;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.apppreference.AppPreference;

import java.text.NumberFormat;

public class AppDataUsagePreference extends AppPreference {

    private final AppItem mItem;
@@ -66,6 +68,8 @@ public class AppDataUsagePreference extends AppPreference {
            progress.setVisibility(View.VISIBLE);
        }
        progress.setProgress(mPercent);
        progress.setContentDescription(
                NumberFormat.getPercentInstance().format((double) mPercent / 100));
    }

    private void setAppInfo() {
+24 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ import static org.mockito.Mockito.when;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;

import androidx.preference.PreferenceViewHolder;

import com.android.settingslib.AppItem;
import com.android.settingslib.net.UidDetail;
@@ -37,6 +42,7 @@ import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class AppDataUsagePreferenceTest {
    private static final String FIFTY_PERCENT = "50%";

    @Mock
    private UidDetailProvider mUidDetailProvider;
@@ -77,4 +83,22 @@ public class AppDataUsagePreferenceTest {
        assertThat(mPreference.getTitle()).isEqualTo(mUidDetail.label);
        assertThat(mPreference.getIcon()).isEqualTo(mUidDetail.icon);
    }

    @Test
    public void createPref_progressBarShouldSetPercentageContentDescription() {
        when(mUidDetailProvider.getUidDetail(mAppItem.key, true /* blocking */))
                .thenReturn(mUidDetail);
        mPreference = new AppDataUsagePreference(RuntimeEnvironment.application, mAppItem,
                50 /* percent */, mUidDetailProvider);
        final View view = LayoutInflater.from(RuntimeEnvironment.application).inflate(
                com.android.settingslib.R.layout.preference_app, null);
        final PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);
        final ProgressBar progressBar = (ProgressBar) preferenceViewHolder.findViewById(
                android.R.id.progress);

        mPreference.onBindViewHolder(preferenceViewHolder);

        assertThat(progressBar.getContentDescription()).isEqualTo(FIFTY_PERCENT);
    }
}