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
This commit is contained in:
Jigar Thakkar
2025-03-20 19:19:32 +00:00
parent 4bc471f61e
commit e4201e8af4
4 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
/*
* 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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}