aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java')
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java80
1 files changed, 28 insertions, 52 deletions
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java
index 19762d193..203e43968 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowCaptioningManager.java
@@ -1,72 +1,48 @@
package org.robolectric.shadows;
-import android.annotation.NonNull;
-import android.util.ArraySet;
+import static android.os.Build.VERSION_CODES.TIRAMISU;
+import static org.robolectric.util.reflector.Reflector.reflector;
+
+import android.content.ContentResolver;
+import android.provider.Settings;
import android.view.accessibility.CaptioningManager;
-import android.view.accessibility.CaptioningManager.CaptioningChangeListener;
-import java.util.Locale;
-import javax.annotation.Nullable;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.RealObject;
+import org.robolectric.util.reflector.Accessor;
+import org.robolectric.util.reflector.ForType;
/** Shadow of {@link android.view.accessibility.CaptioningManager}. */
@Implements(CaptioningManager.class)
public class ShadowCaptioningManager {
- private float fontScale = 1;
- private boolean isEnabled = false;
- @Nullable private Locale locale;
-
- private final ArraySet<CaptioningChangeListener> listeners = new ArraySet<>();
-
- /** Returns 1.0 as default or the most recent value passed to {@link #setFontScale()} */
- @Implementation(minSdk = 19)
- protected float getFontScale() {
- return fontScale;
- }
-
- /** Sets the value to be returned by {@link CaptioningManager#getFontScale()} */
- public void setFontScale(float fontScale) {
- this.fontScale = fontScale;
+ @RealObject private CaptioningManager realCaptioningManager;
- for (CaptioningChangeListener captioningChangeListener : listeners) {
- captioningChangeListener.onFontScaleChanged(fontScale);
- }
+ @Implementation(minSdk = TIRAMISU)
+ protected void setSystemAudioCaptioningEnabled(boolean isEnabled) {
+ Settings.Secure.putInt(
+ getContentResolver(), Settings.Secure.ODI_CAPTIONS_ENABLED, isEnabled ? 1 : 0);
}
- /** Returns false or the most recent value passed to {@link #setEnabled(boolean)} */
- @Implementation(minSdk = 19)
- protected boolean isEnabled() {
- return isEnabled;
+ @Implementation(minSdk = TIRAMISU)
+ protected void setSystemAudioCaptioningUiEnabled(boolean isEnabled) {
+ Settings.Secure.putInt(
+ getContentResolver(), Settings.Secure.ODI_CAPTIONS_VOLUME_UI_ENABLED, isEnabled ? 1 : 0);
}
- /** Sets the value to be returned by {@link CaptioningManager#isEnabled()} */
- public void setEnabled(boolean isEnabled) {
- this.isEnabled = isEnabled;
+ @Implementation(minSdk = TIRAMISU)
+ protected boolean isSystemAudioCaptioningUiEnabled() {
+ return Settings.Secure.getInt(
+ getContentResolver(), Settings.Secure.ODI_CAPTIONS_VOLUME_UI_ENABLED, 1)
+ == 1;
}
- @Implementation(minSdk = 19)
- protected void addCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
- listeners.add(listener);
+ private ContentResolver getContentResolver() {
+ return reflector(CaptioningManagerReflector.class, realCaptioningManager).getContentResolver();
}
- @Implementation(minSdk = 19)
- protected void removeCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
- listeners.remove(listener);
- }
-
- /** Returns null or the most recent value passed to {@link #setLocale(Locale)} */
- @Implementation(minSdk = 19)
- @Nullable
- protected Locale getLocale() {
- return locale;
- }
-
- /** Sets the value to be returned by {@link CaptioningManager#getLocale()} */
- public void setLocale(@Nullable Locale locale) {
- this.locale = locale;
-
- for (CaptioningChangeListener captioningChangeListener : listeners) {
- captioningChangeListener.onLocaleChanged(locale);
- }
+ @ForType(CaptioningManager.class)
+ interface CaptioningManagerReflector {
+ @Accessor("mContentResolver")
+ ContentResolver getContentResolver();
}
}