@capawesome/capacitor-volume 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CapawesomeCapacitorVolume.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +405 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/Volume.java +158 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/VolumeHelper.java +27 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/VolumePlugin.java +178 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/CustomException.java +20 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/CustomExceptions.java +12 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/events/VolumeButtonPressedEvent.java +23 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/events/VolumeChangeEvent.java +22 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/GetVolumeOptions.java +23 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/SetVolumeOptions.java +41 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/options/StartWatchingOptions.java +17 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/results/GetVolumeResult.java +22 -0
  18. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/classes/results/IsWatchingResult.java +22 -0
  19. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/Callback.java +5 -0
  20. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/EmptyCallback.java +5 -0
  21. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/NonEmptyResultCallback.java +7 -0
  22. package/android/src/main/java/io/capawesome/capacitorjs/plugins/volume/interfaces/Result.java +7 -0
  23. package/android/src/main/res/.gitkeep +0 -0
  24. package/dist/docs.json +540 -0
  25. package/dist/esm/definitions.d.ts +255 -0
  26. package/dist/esm/definitions.js +60 -0
  27. package/dist/esm/definitions.js.map +1 -0
  28. package/dist/esm/index.d.ts +4 -0
  29. package/dist/esm/index.js +7 -0
  30. package/dist/esm/index.js.map +1 -0
  31. package/dist/esm/web.d.ts +9 -0
  32. package/dist/esm/web.js +19 -0
  33. package/dist/esm/web.js.map +1 -0
  34. package/dist/plugin.cjs.js +93 -0
  35. package/dist/plugin.cjs.js.map +1 -0
  36. package/dist/plugin.js +96 -0
  37. package/dist/plugin.js.map +1 -0
  38. package/ios/Plugin/Classes/Events/VolumeButtonPressedEvent.swift +16 -0
  39. package/ios/Plugin/Classes/Events/VolumeChangeEvent.swift +16 -0
  40. package/ios/Plugin/Classes/Options/SetVolumeOptions.swift +20 -0
  41. package/ios/Plugin/Classes/Options/StartWatchingOptions.swift +10 -0
  42. package/ios/Plugin/Classes/Results/GetVolumeResult.swift +16 -0
  43. package/ios/Plugin/Classes/Results/IsWatchingResult.swift +16 -0
  44. package/ios/Plugin/Enums/CustomError.swift +24 -0
  45. package/ios/Plugin/Info.plist +24 -0
  46. package/ios/Plugin/Protocols/Result.swift +5 -0
  47. package/ios/Plugin/Volume.swift +192 -0
  48. package/ios/Plugin/VolumePlugin.swift +109 -0
  49. package/package.json +91 -0
@@ -0,0 +1,158 @@
1
+ package io.capawesome.capacitorjs.plugins.volume;
2
+
3
+ import android.content.Context;
4
+ import android.database.ContentObserver;
5
+ import android.media.AudioManager;
6
+ import android.os.Handler;
7
+ import android.os.Looper;
8
+ import android.provider.Settings;
9
+ import android.view.KeyEvent;
10
+ import android.view.View;
11
+ import androidx.annotation.NonNull;
12
+ import androidx.annotation.Nullable;
13
+ import io.capawesome.capacitorjs.plugins.volume.classes.CustomExceptions;
14
+ import io.capawesome.capacitorjs.plugins.volume.classes.events.VolumeButtonPressedEvent;
15
+ import io.capawesome.capacitorjs.plugins.volume.classes.events.VolumeChangeEvent;
16
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.GetVolumeOptions;
17
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.SetVolumeOptions;
18
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.StartWatchingOptions;
19
+ import io.capawesome.capacitorjs.plugins.volume.classes.results.GetVolumeResult;
20
+ import io.capawesome.capacitorjs.plugins.volume.classes.results.IsWatchingResult;
21
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.EmptyCallback;
22
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.NonEmptyResultCallback;
23
+
24
+ public class Volume {
25
+
26
+ private static final String DIRECTION_DOWN = "down";
27
+ private static final String DIRECTION_UP = "up";
28
+
29
+ @NonNull
30
+ private final AudioManager audioManager;
31
+
32
+ private int lastVolume = -1;
33
+
34
+ @NonNull
35
+ private final View.OnKeyListener onKeyListener = (view, keyCode, event) -> handleKeyEvent(keyCode, event);
36
+
37
+ @NonNull
38
+ private final VolumePlugin plugin;
39
+
40
+ private boolean suppressVolumeChange = false;
41
+
42
+ @Nullable
43
+ private ContentObserver volumeObserver;
44
+
45
+ private boolean watching = false;
46
+
47
+ public Volume(@NonNull VolumePlugin plugin) {
48
+ this.plugin = plugin;
49
+ this.audioManager = (AudioManager) plugin.getContext().getSystemService(Context.AUDIO_SERVICE);
50
+ }
51
+
52
+ public void getVolume(@NonNull GetVolumeOptions options, @NonNull NonEmptyResultCallback<GetVolumeResult> callback) {
53
+ double volume = getNormalizedVolume(options.getStreamType());
54
+ callback.success(new GetVolumeResult(volume));
55
+ }
56
+
57
+ public void isWatching(@NonNull NonEmptyResultCallback<IsWatchingResult> callback) {
58
+ callback.success(new IsWatchingResult(watching));
59
+ }
60
+
61
+ public void setVolume(@NonNull SetVolumeOptions options, @NonNull EmptyCallback callback) {
62
+ int streamType = options.getStreamType();
63
+ int maxVolume = audioManager.getStreamMaxVolume(streamType);
64
+ int volume = Math.round(options.getVolume() * maxVolume);
65
+ try {
66
+ audioManager.setStreamVolume(streamType, volume, 0);
67
+ } catch (SecurityException exception) {
68
+ callback.error(CustomExceptions.DO_NOT_DISTURB_ACCESS_REQUIRED);
69
+ return;
70
+ }
71
+ callback.success();
72
+ }
73
+
74
+ public void startWatching(@NonNull StartWatchingOptions options, @NonNull EmptyCallback callback) {
75
+ if (watching) {
76
+ callback.success();
77
+ return;
78
+ }
79
+ suppressVolumeChange = options.isSuppressVolumeChange();
80
+ lastVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
81
+ registerVolumeObserver();
82
+ watching = true;
83
+ plugin
84
+ .getActivity()
85
+ .runOnUiThread(() -> {
86
+ View webView = plugin.getBridge().getWebView();
87
+ webView.setOnKeyListener(onKeyListener);
88
+ webView.requestFocus();
89
+ callback.success();
90
+ });
91
+ }
92
+
93
+ public void stopWatching(@Nullable EmptyCallback callback) {
94
+ if (!watching) {
95
+ if (callback != null) {
96
+ callback.success();
97
+ }
98
+ return;
99
+ }
100
+ unregisterVolumeObserver();
101
+ suppressVolumeChange = false;
102
+ watching = false;
103
+ plugin
104
+ .getActivity()
105
+ .runOnUiThread(() -> {
106
+ plugin.getBridge().getWebView().setOnKeyListener(null);
107
+ if (callback != null) {
108
+ callback.success();
109
+ }
110
+ });
111
+ }
112
+
113
+ private double getNormalizedVolume(int streamType) {
114
+ int volume = audioManager.getStreamVolume(streamType);
115
+ int maxVolume = audioManager.getStreamMaxVolume(streamType);
116
+ return volume / (double) maxVolume;
117
+ }
118
+
119
+ private boolean handleKeyEvent(int keyCode, @NonNull KeyEvent event) {
120
+ if (keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN) {
121
+ return false;
122
+ }
123
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
124
+ String direction = keyCode == KeyEvent.KEYCODE_VOLUME_UP ? DIRECTION_UP : DIRECTION_DOWN;
125
+ plugin.notifyVolumeButtonPressedListeners(new VolumeButtonPressedEvent(direction));
126
+ }
127
+ return suppressVolumeChange;
128
+ }
129
+
130
+ private void handleVolumeChanged() {
131
+ int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
132
+ if (volume == lastVolume) {
133
+ return;
134
+ }
135
+ lastVolume = volume;
136
+ int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
137
+ plugin.notifyVolumeChangeListeners(new VolumeChangeEvent(volume / (double) maxVolume));
138
+ }
139
+
140
+ private void registerVolumeObserver() {
141
+ ContentObserver volumeObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
142
+ @Override
143
+ public void onChange(boolean selfChange) {
144
+ handleVolumeChanged();
145
+ }
146
+ };
147
+ plugin.getContext().getContentResolver().registerContentObserver(Settings.System.CONTENT_URI, true, volumeObserver);
148
+ this.volumeObserver = volumeObserver;
149
+ }
150
+
151
+ private void unregisterVolumeObserver() {
152
+ ContentObserver volumeObserver = this.volumeObserver;
153
+ if (volumeObserver != null) {
154
+ plugin.getContext().getContentResolver().unregisterContentObserver(volumeObserver);
155
+ this.volumeObserver = null;
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,27 @@
1
+ package io.capawesome.capacitorjs.plugins.volume;
2
+
3
+ import android.media.AudioManager;
4
+ import androidx.annotation.NonNull;
5
+ import io.capawesome.capacitorjs.plugins.volume.classes.CustomExceptions;
6
+
7
+ public class VolumeHelper {
8
+
9
+ public static int mapStreamToStreamType(@NonNull String stream) throws Exception {
10
+ switch (stream) {
11
+ case "alarm":
12
+ return AudioManager.STREAM_ALARM;
13
+ case "music":
14
+ return AudioManager.STREAM_MUSIC;
15
+ case "notification":
16
+ return AudioManager.STREAM_NOTIFICATION;
17
+ case "ring":
18
+ return AudioManager.STREAM_RING;
19
+ case "system":
20
+ return AudioManager.STREAM_SYSTEM;
21
+ case "voiceCall":
22
+ return AudioManager.STREAM_VOICE_CALL;
23
+ default:
24
+ throw CustomExceptions.STREAM_INVALID;
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,178 @@
1
+ package io.capawesome.capacitorjs.plugins.volume;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.Logger;
5
+ import com.getcapacitor.Plugin;
6
+ import com.getcapacitor.PluginCall;
7
+ import com.getcapacitor.PluginMethod;
8
+ import com.getcapacitor.annotation.CapacitorPlugin;
9
+ import io.capawesome.capacitorjs.plugins.volume.classes.CustomException;
10
+ import io.capawesome.capacitorjs.plugins.volume.classes.events.VolumeButtonPressedEvent;
11
+ import io.capawesome.capacitorjs.plugins.volume.classes.events.VolumeChangeEvent;
12
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.GetVolumeOptions;
13
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.SetVolumeOptions;
14
+ import io.capawesome.capacitorjs.plugins.volume.classes.options.StartWatchingOptions;
15
+ import io.capawesome.capacitorjs.plugins.volume.classes.results.GetVolumeResult;
16
+ import io.capawesome.capacitorjs.plugins.volume.classes.results.IsWatchingResult;
17
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.EmptyCallback;
18
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.NonEmptyResultCallback;
19
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.Result;
20
+
21
+ @CapacitorPlugin(name = "Volume")
22
+ public class VolumePlugin extends Plugin {
23
+
24
+ public static final String EVENT_VOLUME_BUTTON_PRESSED = "volumeButtonPressed";
25
+ public static final String EVENT_VOLUME_CHANGE = "volumeChange";
26
+ public static final String TAG = "VolumePlugin";
27
+
28
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
29
+
30
+ private Volume implementation;
31
+
32
+ @PluginMethod
33
+ public void getVolume(PluginCall call) {
34
+ try {
35
+ GetVolumeOptions options = new GetVolumeOptions(call);
36
+ NonEmptyResultCallback<GetVolumeResult> callback = new NonEmptyResultCallback<>() {
37
+ @Override
38
+ public void success(@NonNull GetVolumeResult result) {
39
+ resolveCall(call, result);
40
+ }
41
+
42
+ @Override
43
+ public void error(@NonNull Exception exception) {
44
+ rejectCall(call, exception);
45
+ }
46
+ };
47
+
48
+ implementation.getVolume(options, callback);
49
+ } catch (Exception exception) {
50
+ rejectCall(call, exception);
51
+ }
52
+ }
53
+
54
+ @PluginMethod
55
+ public void isWatching(PluginCall call) {
56
+ try {
57
+ NonEmptyResultCallback<IsWatchingResult> callback = new NonEmptyResultCallback<>() {
58
+ @Override
59
+ public void success(@NonNull IsWatchingResult result) {
60
+ resolveCall(call, result);
61
+ }
62
+
63
+ @Override
64
+ public void error(@NonNull Exception exception) {
65
+ rejectCall(call, exception);
66
+ }
67
+ };
68
+
69
+ implementation.isWatching(callback);
70
+ } catch (Exception exception) {
71
+ rejectCall(call, exception);
72
+ }
73
+ }
74
+
75
+ @Override
76
+ public void load() {
77
+ implementation = new Volume(this);
78
+ }
79
+
80
+ public void notifyVolumeButtonPressedListeners(@NonNull VolumeButtonPressedEvent event) {
81
+ notifyListeners(EVENT_VOLUME_BUTTON_PRESSED, event.toJSObject());
82
+ }
83
+
84
+ public void notifyVolumeChangeListeners(@NonNull VolumeChangeEvent event) {
85
+ notifyListeners(EVENT_VOLUME_CHANGE, event.toJSObject());
86
+ }
87
+
88
+ @PluginMethod
89
+ public void setVolume(PluginCall call) {
90
+ try {
91
+ SetVolumeOptions options = new SetVolumeOptions(call);
92
+ EmptyCallback callback = new EmptyCallback() {
93
+ @Override
94
+ public void success() {
95
+ resolveCall(call);
96
+ }
97
+
98
+ @Override
99
+ public void error(@NonNull Exception exception) {
100
+ rejectCall(call, exception);
101
+ }
102
+ };
103
+
104
+ implementation.setVolume(options, callback);
105
+ } catch (Exception exception) {
106
+ rejectCall(call, exception);
107
+ }
108
+ }
109
+
110
+ @PluginMethod
111
+ public void startWatching(PluginCall call) {
112
+ try {
113
+ StartWatchingOptions options = new StartWatchingOptions(call);
114
+ EmptyCallback callback = new EmptyCallback() {
115
+ @Override
116
+ public void success() {
117
+ resolveCall(call);
118
+ }
119
+
120
+ @Override
121
+ public void error(@NonNull Exception exception) {
122
+ rejectCall(call, exception);
123
+ }
124
+ };
125
+
126
+ implementation.startWatching(options, callback);
127
+ } catch (Exception exception) {
128
+ rejectCall(call, exception);
129
+ }
130
+ }
131
+
132
+ @PluginMethod
133
+ public void stopWatching(PluginCall call) {
134
+ try {
135
+ EmptyCallback callback = new EmptyCallback() {
136
+ @Override
137
+ public void success() {
138
+ resolveCall(call);
139
+ }
140
+
141
+ @Override
142
+ public void error(@NonNull Exception exception) {
143
+ rejectCall(call, exception);
144
+ }
145
+ };
146
+
147
+ implementation.stopWatching(callback);
148
+ } catch (Exception exception) {
149
+ rejectCall(call, exception);
150
+ }
151
+ }
152
+
153
+ @Override
154
+ protected void handleOnDestroy() {
155
+ implementation.stopWatching(null);
156
+ }
157
+
158
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
159
+ String message = exception.getMessage();
160
+ if (message == null) {
161
+ message = ERROR_UNKNOWN_ERROR;
162
+ }
163
+ String code = null;
164
+ if (exception instanceof CustomException) {
165
+ code = ((CustomException) exception).getCode();
166
+ }
167
+ Logger.error(TAG, message, exception);
168
+ call.reject(message, code);
169
+ }
170
+
171
+ private void resolveCall(@NonNull PluginCall call) {
172
+ call.resolve();
173
+ }
174
+
175
+ private void resolveCall(@NonNull PluginCall call, @NonNull Result result) {
176
+ call.resolve(result.toJSObject());
177
+ }
178
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ public class CustomException extends Exception {
7
+
8
+ @Nullable
9
+ private final String code;
10
+
11
+ public CustomException(@Nullable String code, @NonNull String message) {
12
+ super(message);
13
+ this.code = code;
14
+ }
15
+
16
+ @Nullable
17
+ public String getCode() {
18
+ return code;
19
+ }
20
+ }
@@ -0,0 +1,12 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes;
2
+
3
+ public class CustomExceptions {
4
+
5
+ public static final CustomException DO_NOT_DISTURB_ACCESS_REQUIRED = new CustomException(
6
+ "DO_NOT_DISTURB_ACCESS_REQUIRED",
7
+ "Do Not Disturb access is required to change the volume of this stream."
8
+ );
9
+ public static final CustomException STREAM_INVALID = new CustomException(null, "stream is invalid.");
10
+ public static final CustomException VOLUME_INVALID = new CustomException(null, "volume must be between 0 and 1.");
11
+ public static final CustomException VOLUME_MISSING = new CustomException(null, "volume must be provided.");
12
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.Result;
6
+
7
+ public class VolumeButtonPressedEvent implements Result {
8
+
9
+ @NonNull
10
+ private final String direction;
11
+
12
+ public VolumeButtonPressedEvent(@NonNull String direction) {
13
+ this.direction = direction;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject result = new JSObject();
20
+ result.put("direction", direction);
21
+ return result;
22
+ }
23
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.Result;
6
+
7
+ public class VolumeChangeEvent implements Result {
8
+
9
+ private final double volume;
10
+
11
+ public VolumeChangeEvent(double volume) {
12
+ this.volume = volume;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("volume", volume);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.PluginCall;
5
+ import io.capawesome.capacitorjs.plugins.volume.VolumeHelper;
6
+
7
+ public class GetVolumeOptions {
8
+
9
+ private final int streamType;
10
+
11
+ public GetVolumeOptions(@NonNull PluginCall call) throws Exception {
12
+ this.streamType = GetVolumeOptions.getStreamTypeFromCall(call);
13
+ }
14
+
15
+ public int getStreamType() {
16
+ return streamType;
17
+ }
18
+
19
+ private static int getStreamTypeFromCall(@NonNull PluginCall call) throws Exception {
20
+ String stream = call.getString("stream", "music");
21
+ return VolumeHelper.mapStreamToStreamType(stream);
22
+ }
23
+ }
@@ -0,0 +1,41 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.PluginCall;
5
+ import io.capawesome.capacitorjs.plugins.volume.VolumeHelper;
6
+ import io.capawesome.capacitorjs.plugins.volume.classes.CustomExceptions;
7
+
8
+ public class SetVolumeOptions {
9
+
10
+ private final int streamType;
11
+ private final float volume;
12
+
13
+ public SetVolumeOptions(@NonNull PluginCall call) throws Exception {
14
+ this.streamType = SetVolumeOptions.getStreamTypeFromCall(call);
15
+ this.volume = SetVolumeOptions.getVolumeFromCall(call);
16
+ }
17
+
18
+ public int getStreamType() {
19
+ return streamType;
20
+ }
21
+
22
+ public float getVolume() {
23
+ return volume;
24
+ }
25
+
26
+ private static int getStreamTypeFromCall(@NonNull PluginCall call) throws Exception {
27
+ String stream = call.getString("stream", "music");
28
+ return VolumeHelper.mapStreamToStreamType(stream);
29
+ }
30
+
31
+ private static float getVolumeFromCall(@NonNull PluginCall call) throws Exception {
32
+ Float volume = call.getFloat("volume");
33
+ if (volume == null) {
34
+ throw CustomExceptions.VOLUME_MISSING;
35
+ }
36
+ if (volume < 0 || volume > 1) {
37
+ throw CustomExceptions.VOLUME_INVALID;
38
+ }
39
+ return volume;
40
+ }
41
+ }
@@ -0,0 +1,17 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.PluginCall;
5
+
6
+ public class StartWatchingOptions {
7
+
8
+ private final boolean suppressVolumeChange;
9
+
10
+ public StartWatchingOptions(@NonNull PluginCall call) {
11
+ this.suppressVolumeChange = call.getBoolean("suppressVolumeChange", false);
12
+ }
13
+
14
+ public boolean isSuppressVolumeChange() {
15
+ return suppressVolumeChange;
16
+ }
17
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.Result;
6
+
7
+ public class GetVolumeResult implements Result {
8
+
9
+ private final double volume;
10
+
11
+ public GetVolumeResult(double volume) {
12
+ this.volume = volume;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("volume", volume);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.volume.interfaces.Result;
6
+
7
+ public class IsWatchingResult implements Result {
8
+
9
+ private final boolean watching;
10
+
11
+ public IsWatchingResult(boolean watching) {
12
+ this.watching = watching;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("watching", watching);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.interfaces;
2
+
3
+ public interface Callback {
4
+ void error(Exception exception);
5
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.interfaces;
2
+
3
+ public interface EmptyCallback extends Callback {
4
+ void success();
5
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.interfaces;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ public interface NonEmptyResultCallback<T extends Result> extends Callback {
6
+ void success(@NonNull T result);
7
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.volume.interfaces;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Result {
6
+ JSObject toJSObject();
7
+ }
File without changes