• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.media.AudioManager;
4 import com.xtremelabs.robolectric.internal.Implementation;
5 import com.xtremelabs.robolectric.internal.Implements;
6 
7 @SuppressWarnings({"UnusedDeclaration"})
8 @Implements(AudioManager.class)
9 public class ShadowAudioManager {
10 
11     private int streamMaxVolume = 15;
12     private int streamVolume = 7;
13     private int flags;
14     private AudioFocusRequest lastAudioFocusRequest;
15     private int nextResponseValue = AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
16     private AudioManager.OnAudioFocusChangeListener lastAbandonedAudioFocusListener;
17 
18     @Implementation
getStreamMaxVolume(int streamType)19     public int getStreamMaxVolume(int streamType) {
20         return streamMaxVolume;
21     }
22 
23     @Implementation
getStreamVolume(int streamType)24     public int getStreamVolume(int streamType) {
25         return streamVolume;
26     }
27 
28     @Implementation
setStreamVolume(int streamType, int index, int flags)29     public void setStreamVolume(int streamType, int index, int flags) {
30         this.streamVolume = index;
31         this.flags = flags;
32     }
33 
34     @Implementation
requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint)35     public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener l, int streamType, int durationHint) {
36         lastAudioFocusRequest = new AudioFocusRequest(l, streamType, durationHint);
37         return nextResponseValue;
38     }
39 
40     @Implementation
abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l)41     public int abandonAudioFocus(AudioManager.OnAudioFocusChangeListener l) {
42         lastAbandonedAudioFocusListener = l;
43         return nextResponseValue;
44     }
45 
getStreamMaxVolume()46     public int getStreamMaxVolume() {
47         return streamMaxVolume;
48     }
49 
setStreamMaxVolume(int streamMaxVolume)50     public void setStreamMaxVolume(int streamMaxVolume) {
51         this.streamMaxVolume = streamMaxVolume;
52     }
53 
getStreamVolume()54     public int getStreamVolume() {
55         return streamVolume;
56     }
57 
setStreamVolume(int streamVolume)58     public void setStreamVolume(int streamVolume) {
59         this.streamVolume = streamVolume;
60     }
61 
getFlags()62     public int getFlags() {
63         return flags;
64     }
65 
setFlags(int flags)66     public void setFlags(int flags) {
67         this.flags = flags;
68     }
69 
getLastAudioFocusRequest()70     public AudioFocusRequest getLastAudioFocusRequest() {
71         return lastAudioFocusRequest;
72     }
73 
setNextFocusRequestResponse(int nextResponseValue)74     public void setNextFocusRequestResponse(int nextResponseValue) {
75         this.nextResponseValue = nextResponseValue;
76     }
77 
getLastAbandonedAudioFocusListener()78     public AudioManager.OnAudioFocusChangeListener getLastAbandonedAudioFocusListener() {
79         return lastAbandonedAudioFocusListener;
80     }
81 
82     public static class AudioFocusRequest {
83         public final AudioManager.OnAudioFocusChangeListener listener;
84         public final int streamType;
85         public final int durationHint;
86 
AudioFocusRequest(AudioManager.OnAudioFocusChangeListener listener, int streamType, int durationHint)87         private AudioFocusRequest(AudioManager.OnAudioFocusChangeListener listener, int streamType, int durationHint) {
88             this.listener = listener;
89             this.streamType = streamType;
90             this.durationHint = durationHint;
91         }
92     }
93 }
94