1 package org.robolectric.shadows;
2 
3 import android.annotation.NonNull;
4 import android.util.ArraySet;
5 import android.view.accessibility.CaptioningManager;
6 import android.view.accessibility.CaptioningManager.CaptioningChangeListener;
7 import org.robolectric.annotation.Implementation;
8 import org.robolectric.annotation.Implements;
9 
10 /** Shadow of {@link android.view.accessibility.CaptioningManager}. */
11 @Implements(CaptioningManager.class)
12 public class ShadowCaptioningManager {
13   private float fontScale = 1;
14   private boolean isEnabled = false;
15 
16   private final ArraySet<CaptioningChangeListener> listeners = new ArraySet<>();
17 
18   /** Returns 1.0 as default or the most recent value passed to {@link #setFontScale()} */
19   @Implementation(minSdk = 19)
getFontScale()20   protected float getFontScale() {
21     return fontScale;
22   }
23 
24   /** Sets the value to be returned by {@link CaptioningManager#getFontScale()} */
setFontScale(float fontScale)25   public void setFontScale(float fontScale) {
26     this.fontScale = fontScale;
27 
28     for (CaptioningChangeListener captioningChangeListener : listeners) {
29       captioningChangeListener.onFontScaleChanged(fontScale);
30     }
31   }
32 
33   /** Returns false or the most recent value passed to {@link #setEnabled(boolean)} */
34   @Implementation(minSdk = 19)
isEnabled()35   protected boolean isEnabled() {
36     return isEnabled;
37   }
38 
39   /** Sets the value to be returned by {@link CaptioningManager#isEnabled()} */
setEnabled(boolean isEnabled)40   public void setEnabled(boolean isEnabled) {
41     this.isEnabled = isEnabled;
42   }
43 
44   @Implementation(minSdk = 19)
addCaptioningChangeListener(@onNull CaptioningChangeListener listener)45   protected void addCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
46     listeners.add(listener);
47   }
48 
49   @Implementation(minSdk = 19)
removeCaptioningChangeListener(@onNull CaptioningChangeListener listener)50   protected void removeCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
51     listeners.remove(listener);
52   }
53 }
54