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

Commit e4201e8a authored by Jigar Thakkar's avatar Jigar Thakkar
Browse files

Fix accessibility labels for private space animations

The change adds appropriate content descriptions to animations used
within the private space setup flow based on the state of the animation.

Bug: 403398693
Test: manual
Change-Id: I6ac7a5d206083b651b48f9bcf28e3639bdce60b4
parent 4bc471f6
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.settings.privatespace;

import static com.android.settingslib.widget.preference.illustration.R.string.settingslib_action_label_pause;
import static com.android.settingslib.widget.preference.illustration.R.string.settingslib_action_label_resume;
import static com.android.settingslib.widget.preference.illustration.R.string.settingslib_illustration_content_description;

import android.content.Context;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;

import com.airbnb.lottie.LottieAnimationView;

public class PrivateSpaceAccessibilityUtils {

    static void updateAccessibilityActionForAnimation(Context context,
            LottieAnimationView animationView, boolean isAnimationPlaying) {
        animationView.setContentDescription(
                context.getString(settingslib_illustration_content_description));
        ViewCompat.setAccessibilityDelegate(animationView, new AccessibilityDelegateCompat() {
            @Override
            public void onInitializeAccessibilityNodeInfo(
                    View host, AccessibilityNodeInfoCompat info) {
                super.onInitializeAccessibilityNodeInfo(host, info);
                // Clearing the class name to ensure the animation is not called out as "button"
                // inside the TalkBack flows
                info.setClassName("");
                info.removeAction(
                        AccessibilityNodeInfoCompat.AccessibilityActionCompat.ACTION_CLICK);

                final AccessibilityNodeInfoCompat.AccessibilityActionCompat clickAction =
                        new AccessibilityNodeInfoCompat.AccessibilityActionCompat(
                                AccessibilityNodeInfo.ACTION_CLICK,
                                getActionLabelForAnimation(context, isAnimationPlaying));
                info.addAction(clickAction);
            }
        });
    }

    private static String getActionLabelForAnimation(Context context, boolean isAnimationPlaying) {
        if (isAnimationPlaying) {
            return context.getString(settingslib_action_label_pause);
        } else {
            return context.getString(settingslib_action_label_resume);
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ public class PrivateSpaceEducation extends InstrumentedFragment {
        LottieAnimationView lottieAnimationView = rootView.findViewById(R.id.lottie_animation);
        LottieColorUtils.applyDynamicColors(getContext(), lottieAnimationView);
        lottieAnimationView.setOnClickListener(v -> handleAnimationClick(lottieAnimationView));
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);

        TextView infoTextView = rootView.findViewById(R.id.learn_more);
        Pattern pattern = Pattern.compile(infoTextView.getText().toString());
@@ -121,5 +123,7 @@ public class PrivateSpaceEducation extends InstrumentedFragment {
            lottieAnimationView.playAnimation();
        }
        mIsAnimationPlaying = !mIsAnimationPlaying;
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -94,6 +94,8 @@ public class PrivateSpaceSetLockFragment extends InstrumentedFragment {
        LottieAnimationView lottieAnimationView = rootView.findViewById(R.id.lottie_animation);
        LottieColorUtils.applyDynamicColors(getContext(), lottieAnimationView);
        lottieAnimationView.setOnClickListener(v -> handleAnimationClick(lottieAnimationView));
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);

        return rootView;
    }
@@ -141,5 +143,7 @@ public class PrivateSpaceSetLockFragment extends InstrumentedFragment {
            lottieAnimationView.playAnimation();
        }
        mIsAnimationPlaying = !mIsAnimationPlaying;
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ public class SetupSuccessFragment extends InstrumentedFragment {
        LottieAnimationView lottieAnimationView = rootView.findViewById(R.id.lottie_animation);
        LottieColorUtils.applyDynamicColors(getContext(), lottieAnimationView);
        lottieAnimationView.setOnClickListener(v -> handleAnimationClick(lottieAnimationView));
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);

        return rootView;
    }
@@ -152,5 +154,7 @@ public class SetupSuccessFragment extends InstrumentedFragment {
            lottieAnimationView.playAnimation();
        }
        mIsAnimationPlaying = !mIsAnimationPlaying;
        PrivateSpaceAccessibilityUtils.updateAccessibilityActionForAnimation(getContext(),
                lottieAnimationView, mIsAnimationPlaying);
    }
}