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

Commit 81d4f715 authored by Shailen Tuli's avatar Shailen Tuli Committed by Android (Google) Code Review
Browse files

Merge "Used RangeInfo.INDETERMINATE in ProgressBar" into main

parents 33e6a6e7 985207a6
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.widget;

import static android.view.accessibility.Flags.indeterminateRangeInfo;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
@@ -2364,15 +2366,22 @@ public class ProgressBar extends View {
    public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfoInternal(info);

        if (!isIndeterminate()) {
            AccessibilityNodeInfo.RangeInfo rangeInfo = AccessibilityNodeInfo.RangeInfo.obtain(
        AccessibilityNodeInfo.RangeInfo rangeInfo = null;
        if (isIndeterminate()) {
            if (indeterminateRangeInfo()) {
                rangeInfo = AccessibilityNodeInfo.RangeInfo.INDETERMINATE;
            }
        }  else {
            rangeInfo = new AccessibilityNodeInfo.RangeInfo(
                    AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT, getMin(), getMax(),
                    getProgress());
            info.setRangeInfo(rangeInfo);
        }

        // Only set the default state description when custom state descripton is null.
        info.setRangeInfo(rangeInfo);

        // Only set the default state description when custom state description is null.
        if (getStateDescription() == null) {
            // TODO(b/380340432): Remove after accessibility services stop relying on this.
            if (isIndeterminate()) {
                info.setStateDescription(getResources().getString(R.string.in_progress));
            } else {
+21 −0
Original line number Diff line number Diff line
@@ -23,8 +23,12 @@ import static org.junit.Assert.assertTrue;

import android.app.Instrumentation;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.Flags;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -32,6 +36,7 @@ import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@@ -40,6 +45,10 @@ import org.junit.runner.RunWith;
@Presubmit
public class ProgressBarTest {
    private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();

    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();
    private ProgressBar mBar;
    private AccessibilityNodeInfo mInfo;

@@ -181,4 +190,16 @@ public class ProgressBarTest {
        mBar.onInitializeAccessibilityNodeInfo(mInfo);
        assertEquals("custom state", mInfo.getStateDescription().toString());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_INDETERMINATE_RANGE_INFO)
    public void testRangeInfo_indeterminateProgressBar_usesTypeIndeterminate() {
        mBar.setIndeterminate(true);
        assertTrue(mBar.isIndeterminate());

        mBar.onInitializeAccessibilityNodeInfo(mInfo);

        assertEquals(mInfo.getRangeInfo().getType(),
                AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INDETERMINATE);
    }
}