@cond/simasdk 0.0.0-stage → 0.2.0

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 (85) hide show
  1. package/CondSimasdk.podspec +18 -0
  2. package/Package.swift +31 -0
  3. package/README.md +508 -2
  4. package/android/build.gradle +63 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/simasdk/SimaFirebasePlugin.java +139 -0
  7. package/android/src/main/java/com/simasdk/SimaGamesPlugin.java +235 -0
  8. package/android/src/main/java/com/simasdk/SimaHapticsPlugin.java +101 -0
  9. package/android/src/main/java/com/simasdk/SimaReviewPlugin.java +48 -0
  10. package/android/src/main/java/com/simasdk/SimaStoragePlugin.java +79 -0
  11. package/dist/ads.cjs +214 -0
  12. package/dist/ads.cjs.map +1 -0
  13. package/dist/ads.d.cts +98 -0
  14. package/dist/ads.d.ts +98 -0
  15. package/dist/ads.js +211 -0
  16. package/dist/ads.js.map +1 -0
  17. package/dist/att.cjs +37 -0
  18. package/dist/att.cjs.map +1 -0
  19. package/dist/att.d.cts +31 -0
  20. package/dist/att.d.ts +31 -0
  21. package/dist/att.js +33 -0
  22. package/dist/att.js.map +1 -0
  23. package/dist/back-button.cjs +95 -0
  24. package/dist/back-button.cjs.map +1 -0
  25. package/dist/back-button.d.cts +45 -0
  26. package/dist/back-button.d.ts +45 -0
  27. package/dist/back-button.js +88 -0
  28. package/dist/back-button.js.map +1 -0
  29. package/dist/cli.js +723 -0
  30. package/dist/firebase.cjs +102 -0
  31. package/dist/firebase.cjs.map +1 -0
  32. package/dist/firebase.d.cts +40 -0
  33. package/dist/firebase.d.ts +40 -0
  34. package/dist/firebase.js +99 -0
  35. package/dist/firebase.js.map +1 -0
  36. package/dist/games.cjs +98 -0
  37. package/dist/games.cjs.map +1 -0
  38. package/dist/games.d.cts +73 -0
  39. package/dist/games.d.ts +73 -0
  40. package/dist/games.js +95 -0
  41. package/dist/games.js.map +1 -0
  42. package/dist/haptics.cjs +81 -0
  43. package/dist/haptics.cjs.map +1 -0
  44. package/dist/haptics.d.cts +51 -0
  45. package/dist/haptics.d.ts +51 -0
  46. package/dist/haptics.js +78 -0
  47. package/dist/haptics.js.map +1 -0
  48. package/dist/index.cjs +233 -0
  49. package/dist/index.cjs.map +1 -0
  50. package/dist/index.d.cts +99 -0
  51. package/dist/index.d.ts +99 -0
  52. package/dist/index.js +226 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/react.cjs +118 -0
  55. package/dist/react.cjs.map +1 -0
  56. package/dist/react.d.cts +51 -0
  57. package/dist/react.d.ts +51 -0
  58. package/dist/react.js +113 -0
  59. package/dist/react.js.map +1 -0
  60. package/dist/review.cjs +195 -0
  61. package/dist/review.cjs.map +1 -0
  62. package/dist/review.d.cts +76 -0
  63. package/dist/review.d.ts +76 -0
  64. package/dist/review.js +192 -0
  65. package/dist/review.js.map +1 -0
  66. package/dist/shell.cjs +97 -0
  67. package/dist/shell.cjs.map +1 -0
  68. package/dist/shell.d.cts +36 -0
  69. package/dist/shell.d.ts +36 -0
  70. package/dist/shell.js +91 -0
  71. package/dist/shell.js.map +1 -0
  72. package/dist/storage.cjs +140 -0
  73. package/dist/storage.cjs.map +1 -0
  74. package/dist/storage.d.cts +48 -0
  75. package/dist/storage.d.ts +48 -0
  76. package/dist/storage.js +136 -0
  77. package/dist/storage.js.map +1 -0
  78. package/ios/Sources/SimasdkPlugin/SimaAttPlugin.swift +41 -0
  79. package/ios/Sources/SimasdkPlugin/SimaFirebasePlugin.swift +188 -0
  80. package/ios/Sources/SimasdkPlugin/SimaGamesPlugin.swift +145 -0
  81. package/ios/Sources/SimasdkPlugin/SimaHapticsPlugin.swift +61 -0
  82. package/ios/Sources/SimasdkPlugin/SimaReviewPlugin.swift +40 -0
  83. package/ios/Sources/SimasdkPlugin/SimaStoragePlugin.swift +58 -0
  84. package/package.json +128 -4
  85. package/skills/simasdk/SKILL.md +189 -0
@@ -0,0 +1,139 @@
1
+ package com.simasdk;
2
+
3
+ import android.content.Context;
4
+ import android.os.Bundle;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import com.google.firebase.FirebaseApp;
11
+ import com.google.firebase.analytics.FirebaseAnalytics;
12
+ import java.util.Iterator;
13
+
14
+ @CapacitorPlugin(name = "SimaFirebaseAnalytics")
15
+ public class SimaFirebasePlugin extends Plugin {
16
+
17
+ /**
18
+ * Separate helper class so FirebaseApp / FirebaseAnalytics are resolved lazily
19
+ * only after confirming the host app linked Firebase Analytics.
20
+ */
21
+ private static final class FirebaseAnalyticsBridge {
22
+ static boolean isConfigured(Context context) {
23
+ return !FirebaseApp.getApps(context).isEmpty();
24
+ }
25
+
26
+ static void logEvent(Context context, String name, Bundle params) {
27
+ FirebaseAnalytics.getInstance(context).logEvent(name, params);
28
+ }
29
+
30
+ static void setCollectionEnabled(Context context, boolean enabled) {
31
+ FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(enabled);
32
+ }
33
+ }
34
+
35
+ private boolean isFirebaseSdkOnClasspath() {
36
+ try {
37
+ Class.forName("com.google.firebase.FirebaseApp");
38
+ Class.forName("com.google.firebase.analytics.FirebaseAnalytics");
39
+ return true;
40
+ } catch (ClassNotFoundException ignored) {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ @PluginMethod
46
+ public void logEvent(PluginCall call) {
47
+ if (!isFirebaseSdkOnClasspath()) {
48
+ call.reject(
49
+ "Firebase Analytics Android SDK is not included in this app. Add com.google.firebase:firebase-analytics to android/app/build.gradle.",
50
+ "NOT_CONFIGURED"
51
+ );
52
+ return;
53
+ }
54
+
55
+ Context context = getContext();
56
+ if (!FirebaseAnalyticsBridge.isConfigured(context)) {
57
+ call.reject(
58
+ "Firebase is not configured. Ensure google-services.json and the com.google.gms.google-services Gradle plugin are configured in your Android app.",
59
+ "NOT_CONFIGURED"
60
+ );
61
+ return;
62
+ }
63
+
64
+ String name = call.getString("name");
65
+ if (name == null || name.isEmpty()) {
66
+ call.reject("Missing required event name.", "INVALID_EVENT_NAME");
67
+ return;
68
+ }
69
+
70
+ JSObject rawParams = call.getObject("params");
71
+ Bundle bundle = new Bundle();
72
+ if (rawParams != null) {
73
+ Iterator<String> keys = rawParams.keys();
74
+ while (keys.hasNext()) {
75
+ String key = keys.next();
76
+ Object value = rawParams.opt(key);
77
+ if (value instanceof String) {
78
+ bundle.putString(key, (String) value);
79
+ } else if (value instanceof Integer) {
80
+ bundle.putLong(key, ((Integer) value).longValue());
81
+ } else if (value instanceof Long) {
82
+ bundle.putLong(key, (Long) value);
83
+ } else if (value instanceof Double) {
84
+ double d = (Double) value;
85
+ if (!Double.isFinite(d)) {
86
+ call.reject("Parameter \"" + key + "\" must be a finite number.", "INVALID_PARAM_VALUE");
87
+ return;
88
+ }
89
+ bundle.putDouble(key, d);
90
+ } else if (value instanceof Float) {
91
+ float f = (Float) value;
92
+ if (!Float.isFinite(f)) {
93
+ call.reject("Parameter \"" + key + "\" must be a finite number.", "INVALID_PARAM_VALUE");
94
+ return;
95
+ }
96
+ bundle.putDouble(key, f);
97
+ } else {
98
+ call.reject(
99
+ "Parameter \"" + key + "\" has an unsupported value type. Only string and finite number values are supported.",
100
+ "INVALID_PARAM_VALUE"
101
+ );
102
+ return;
103
+ }
104
+ }
105
+ }
106
+
107
+ FirebaseAnalyticsBridge.logEvent(context, name, bundle.isEmpty() ? null : bundle);
108
+ call.resolve();
109
+ }
110
+
111
+ @PluginMethod
112
+ public void setAnalyticsCollectionEnabled(PluginCall call) {
113
+ if (!isFirebaseSdkOnClasspath()) {
114
+ call.reject(
115
+ "Firebase Analytics Android SDK is not included in this app. Add com.google.firebase:firebase-analytics to android/app/build.gradle.",
116
+ "NOT_CONFIGURED"
117
+ );
118
+ return;
119
+ }
120
+
121
+ Context context = getContext();
122
+ if (!FirebaseAnalyticsBridge.isConfigured(context)) {
123
+ call.reject(
124
+ "Firebase is not configured. Ensure google-services.json and the com.google.gms.google-services Gradle plugin are configured in your Android app.",
125
+ "NOT_CONFIGURED"
126
+ );
127
+ return;
128
+ }
129
+
130
+ Boolean enabled = call.getBoolean("enabled");
131
+ if (enabled == null) {
132
+ call.reject("Missing required boolean parameter \"enabled\".", "INVALID_PARAM_VALUE");
133
+ return;
134
+ }
135
+
136
+ FirebaseAnalyticsBridge.setCollectionEnabled(context, enabled);
137
+ call.resolve();
138
+ }
139
+ }
@@ -0,0 +1,235 @@
1
+ package com.simasdk;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Intent;
5
+ import androidx.activity.result.ActivityResult;
6
+ import com.getcapacitor.JSObject;
7
+ import com.getcapacitor.Plugin;
8
+ import com.getcapacitor.PluginCall;
9
+ import com.getcapacitor.PluginMethod;
10
+ import com.getcapacitor.annotation.ActivityCallback;
11
+ import com.getcapacitor.annotation.CapacitorPlugin;
12
+ import com.google.android.gms.games.GamesSignInClient;
13
+ import com.google.android.gms.games.LeaderboardsClient;
14
+ import com.google.android.gms.games.PlayGames;
15
+ import com.google.android.gms.games.leaderboard.LeaderboardVariant;
16
+
17
+ @CapacitorPlugin(name = "SimaGames")
18
+ public class SimaGamesPlugin extends Plugin {
19
+
20
+ /**
21
+ * Separate helper class so Play Games SDK classes are resolved lazily
22
+ * only after confirming the host app linked play-services-games-v2.
23
+ */
24
+ private static final class PlayGamesBridge {
25
+ static void isAuthenticated(Activity activity, PluginCall call) {
26
+ PlayGames.getGamesSignInClient(activity)
27
+ .isAuthenticated()
28
+ .addOnCompleteListener(task -> {
29
+ boolean ok = task.isSuccessful() && task.getResult().isAuthenticated();
30
+ JSObject ret = new JSObject();
31
+ ret.put("authenticated", ok);
32
+ call.resolve(ret);
33
+ });
34
+ }
35
+
36
+ static void signIn(Activity activity, PluginCall call) {
37
+ GamesSignInClient client = PlayGames.getGamesSignInClient(activity);
38
+ client.isAuthenticated().addOnCompleteListener(authTask -> {
39
+ boolean already = authTask.isSuccessful() && authTask.getResult().isAuthenticated();
40
+ if (already) {
41
+ JSObject ret = new JSObject();
42
+ ret.put("authenticated", true);
43
+ call.resolve(ret);
44
+ return;
45
+ }
46
+ client.signIn().addOnCompleteListener(signInTask -> {
47
+ boolean ok = signInTask.isSuccessful() && signInTask.getResult().isAuthenticated();
48
+ JSObject ret = new JSObject();
49
+ ret.put("authenticated", ok);
50
+ call.resolve(ret);
51
+ });
52
+ });
53
+ }
54
+
55
+ static void submitScore(Activity activity, String leaderboardId, long score, PluginCall call) {
56
+ PlayGames.getGamesSignInClient(activity)
57
+ .isAuthenticated()
58
+ .addOnCompleteListener(authTask -> {
59
+ boolean ok = authTask.isSuccessful() && authTask.getResult().isAuthenticated();
60
+ if (!ok) {
61
+ JSObject ret = new JSObject();
62
+ ret.put("submitted", false);
63
+ call.resolve(ret);
64
+ return;
65
+ }
66
+ LeaderboardsClient client = PlayGames.getLeaderboardsClient(activity);
67
+ client.submitScoreImmediate(leaderboardId, score)
68
+ .addOnSuccessListener(data -> {
69
+ JSObject ret = new JSObject();
70
+ ret.put("submitted", true);
71
+ call.resolve(ret);
72
+ })
73
+ .addOnFailureListener(err -> {
74
+ // Fire-and-forget fallback supports offline queuing
75
+ client.submitScore(leaderboardId, score);
76
+ JSObject ret = new JSObject();
77
+ ret.put("submitted", true);
78
+ call.resolve(ret);
79
+ });
80
+ });
81
+ }
82
+
83
+ static void getLeaderboardIntent(
84
+ Activity activity,
85
+ String leaderboardId,
86
+ String timeSpan,
87
+ SimaGamesPlugin plugin,
88
+ PluginCall call
89
+ ) {
90
+ int span = LeaderboardVariant.TIME_SPAN_ALL_TIME;
91
+ if ("daily".equalsIgnoreCase(timeSpan)) {
92
+ span = LeaderboardVariant.TIME_SPAN_DAILY;
93
+ } else if ("weekly".equalsIgnoreCase(timeSpan)) {
94
+ span = LeaderboardVariant.TIME_SPAN_WEEKLY;
95
+ }
96
+ PlayGames.getLeaderboardsClient(activity)
97
+ .getLeaderboardIntent(leaderboardId, span, LeaderboardVariant.COLLECTION_PUBLIC)
98
+ .addOnSuccessListener(intent -> plugin.launchLeaderboard(call, intent))
99
+ .addOnFailureListener(err -> call.reject("Failed to open leaderboard.", "LEADERBOARD_ERROR", err));
100
+ }
101
+
102
+ static void unlockAchievement(Activity activity, String achievementId, PluginCall call) {
103
+ PlayGames.getGamesSignInClient(activity)
104
+ .isAuthenticated()
105
+ .addOnCompleteListener(authTask -> {
106
+ boolean ok = authTask.isSuccessful() && authTask.getResult().isAuthenticated();
107
+ if (!ok) {
108
+ JSObject ret = new JSObject();
109
+ ret.put("unlocked", false);
110
+ call.resolve(ret);
111
+ return;
112
+ }
113
+ PlayGames.getAchievementsClient(activity).unlock(achievementId);
114
+ JSObject ret = new JSObject();
115
+ ret.put("unlocked", true);
116
+ call.resolve(ret);
117
+ });
118
+ }
119
+ }
120
+
121
+ private boolean isPlayGamesSdkOnClasspath() {
122
+ try {
123
+ Class.forName("com.google.android.gms.games.PlayGames");
124
+ return true;
125
+ } catch (ClassNotFoundException ignored) {
126
+ return false;
127
+ }
128
+ }
129
+
130
+ private void launchLeaderboard(PluginCall call, Intent intent) {
131
+ startActivityForResult(call, intent, "handleLeaderboardResult");
132
+ }
133
+
134
+ @ActivityCallback
135
+ private void handleLeaderboardResult(PluginCall call, ActivityResult result) {
136
+ JSObject ret = new JSObject();
137
+ ret.put("shown", true);
138
+ call.resolve(ret);
139
+ }
140
+
141
+ @PluginMethod
142
+ public void isAuthenticated(PluginCall call) {
143
+ if (!isPlayGamesSdkOnClasspath() || getActivity() == null) {
144
+ JSObject ret = new JSObject();
145
+ ret.put("authenticated", false);
146
+ call.resolve(ret);
147
+ return;
148
+ }
149
+ PlayGamesBridge.isAuthenticated(getActivity(), call);
150
+ }
151
+
152
+ @PluginMethod
153
+ public void signIn(PluginCall call) {
154
+ if (!isPlayGamesSdkOnClasspath()) {
155
+ call.reject(
156
+ "Google Play Games Services v2 SDK is not included. Add com.google.android.gms:play-services-games-v2 to android/app/build.gradle.",
157
+ "NOT_CONFIGURED"
158
+ );
159
+ return;
160
+ }
161
+ Activity activity = getActivity();
162
+ if (activity == null) {
163
+ call.reject("Activity not available.", "NO_ACTIVITY");
164
+ return;
165
+ }
166
+ PlayGamesBridge.signIn(activity, call);
167
+ }
168
+
169
+ @PluginMethod
170
+ public void submitScore(PluginCall call) {
171
+ if (!isPlayGamesSdkOnClasspath()) {
172
+ JSObject ret = new JSObject();
173
+ ret.put("submitted", false);
174
+ call.resolve(ret);
175
+ return;
176
+ }
177
+ String leaderboardId = call.getString("leaderboardId", "").trim();
178
+ // Use getDouble + Math.round so both Integer and Long JSON numbers are handled safely.
179
+ Double scoreDouble = call.getDouble("score");
180
+ if (leaderboardId.isEmpty() || scoreDouble == null || !Double.isFinite(scoreDouble)) {
181
+ call.reject("leaderboardId and finite numeric score are required.", "INVALID_ARGUMENT");
182
+ return;
183
+ }
184
+ Activity activity = getActivity();
185
+ if (activity == null) {
186
+ call.reject("Activity not available.", "NO_ACTIVITY");
187
+ return;
188
+ }
189
+ PlayGamesBridge.submitScore(activity, leaderboardId, Math.round(scoreDouble), call);
190
+ }
191
+
192
+ @PluginMethod
193
+ public void showLeaderboard(PluginCall call) {
194
+ if (!isPlayGamesSdkOnClasspath()) {
195
+ call.reject(
196
+ "Google Play Games Services v2 SDK is not included. Add com.google.android.gms:play-services-games-v2 to android/app/build.gradle.",
197
+ "NOT_CONFIGURED"
198
+ );
199
+ return;
200
+ }
201
+ String leaderboardId = call.getString("leaderboardId", "").trim();
202
+ String timeSpan = call.getString("timeSpan", "allTime");
203
+ if (leaderboardId.isEmpty()) {
204
+ call.reject("leaderboardId is required.", "INVALID_ARGUMENT");
205
+ return;
206
+ }
207
+ Activity activity = getActivity();
208
+ if (activity == null) {
209
+ call.reject("Activity not available.", "NO_ACTIVITY");
210
+ return;
211
+ }
212
+ PlayGamesBridge.getLeaderboardIntent(activity, leaderboardId, timeSpan, this, call);
213
+ }
214
+
215
+ @PluginMethod
216
+ public void unlockAchievement(PluginCall call) {
217
+ if (!isPlayGamesSdkOnClasspath()) {
218
+ JSObject ret = new JSObject();
219
+ ret.put("unlocked", false);
220
+ call.resolve(ret);
221
+ return;
222
+ }
223
+ String achievementId = call.getString("achievementId", "").trim();
224
+ if (achievementId.isEmpty()) {
225
+ call.reject("achievementId is required.", "INVALID_ARGUMENT");
226
+ return;
227
+ }
228
+ Activity activity = getActivity();
229
+ if (activity == null) {
230
+ call.reject("Activity not available.", "NO_ACTIVITY");
231
+ return;
232
+ }
233
+ PlayGamesBridge.unlockAchievement(activity, achievementId, call);
234
+ }
235
+ }
@@ -0,0 +1,101 @@
1
+ package com.simasdk;
2
+
3
+ import android.content.Context;
4
+ import android.os.Build;
5
+ import android.os.VibrationEffect;
6
+ import android.os.Vibrator;
7
+ import android.os.VibratorManager;
8
+ import android.view.HapticFeedbackConstants;
9
+ import android.view.View;
10
+ import com.getcapacitor.Plugin;
11
+ import com.getcapacitor.PluginCall;
12
+ import com.getcapacitor.PluginMethod;
13
+ import com.getcapacitor.annotation.CapacitorPlugin;
14
+
15
+ @CapacitorPlugin(name = "SimaHaptics")
16
+ public class SimaHapticsPlugin extends Plugin {
17
+
18
+ @PluginMethod
19
+ public void impact(PluginCall call) {
20
+ String style = call.getString("style", "medium");
21
+ long durationMs;
22
+ int amplitude;
23
+ if ("light".equals(style)) {
24
+ durationMs = 15L;
25
+ amplitude = 70;
26
+ } else if ("heavy".equals(style)) {
27
+ durationMs = 40L;
28
+ amplitude = 220;
29
+ } else {
30
+ durationMs = 25L;
31
+ amplitude = 140;
32
+ }
33
+ vibrateOnce(durationMs, amplitude);
34
+ call.resolve();
35
+ }
36
+
37
+ @PluginMethod
38
+ public void notification(PluginCall call) {
39
+ String type = call.getString("type", "success");
40
+ long[] timings;
41
+ int[] amplitudes;
42
+ if ("error".equals(type)) {
43
+ timings = new long[] { 0L, 35L, 45L, 35L, 45L, 50L };
44
+ amplitudes = new int[] { 0, 200, 0, 200, 0, 255 };
45
+ } else if ("warning".equals(type)) {
46
+ timings = new long[] { 0L, 30L, 60L, 30L };
47
+ amplitudes = new int[] { 0, 180, 0, 180 };
48
+ } else {
49
+ timings = new long[] { 0L, 20L, 40L, 30L };
50
+ amplitudes = new int[] { 0, 120, 0, 200 };
51
+ }
52
+ vibrateWaveform(timings, amplitudes);
53
+ call.resolve();
54
+ }
55
+
56
+ @PluginMethod
57
+ public void selection(PluginCall call) {
58
+ View rootView = getBridge() != null ? getBridge().getWebView() : null;
59
+ if (rootView != null) {
60
+ rootView.post(() -> rootView.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK));
61
+ } else {
62
+ vibrateOnce(10L, 60);
63
+ }
64
+ call.resolve();
65
+ }
66
+
67
+ private Vibrator getVibrator() {
68
+ Context context = getContext();
69
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
70
+ VibratorManager manager = (VibratorManager) context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
71
+ return manager != null ? manager.getDefaultVibrator() : null;
72
+ }
73
+ return (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
74
+ }
75
+
76
+ @SuppressWarnings("deprecation")
77
+ private void vibrateOnce(long durationMs, int amplitude) {
78
+ Vibrator vibrator = getVibrator();
79
+ if (vibrator == null || !vibrator.hasVibrator()) {
80
+ return;
81
+ }
82
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
83
+ vibrator.vibrate(VibrationEffect.createOneShot(durationMs, amplitude));
84
+ } else {
85
+ vibrator.vibrate(durationMs);
86
+ }
87
+ }
88
+
89
+ @SuppressWarnings("deprecation")
90
+ private void vibrateWaveform(long[] timings, int[] amplitudes) {
91
+ Vibrator vibrator = getVibrator();
92
+ if (vibrator == null || !vibrator.hasVibrator()) {
93
+ return;
94
+ }
95
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
96
+ vibrator.vibrate(VibrationEffect.createWaveform(timings, amplitudes, -1));
97
+ } else {
98
+ vibrator.vibrate(timings, -1);
99
+ }
100
+ }
101
+ }
@@ -0,0 +1,48 @@
1
+ package com.simasdk;
2
+
3
+ import android.app.Activity;
4
+ import com.getcapacitor.Plugin;
5
+ import com.getcapacitor.PluginCall;
6
+ import com.getcapacitor.PluginMethod;
7
+ import com.getcapacitor.annotation.CapacitorPlugin;
8
+ import com.google.android.play.core.review.ReviewInfo;
9
+ import com.google.android.play.core.review.ReviewManager;
10
+ import com.google.android.play.core.review.ReviewManagerFactory;
11
+
12
+ @CapacitorPlugin(name = "SimaReview")
13
+ public class SimaReviewPlugin extends Plugin {
14
+
15
+ @PluginMethod
16
+ public void requestReview(PluginCall call) {
17
+ Activity currentActivity = getActivity();
18
+ if (currentActivity == null || currentActivity.isFinishing()) {
19
+ call.reject("Unable to locate an active Android Activity for in-app review.", "NO_ACTIVITY");
20
+ return;
21
+ }
22
+
23
+ ReviewManager manager = ReviewManagerFactory.create(currentActivity);
24
+ manager.requestReviewFlow().addOnCompleteListener(task -> {
25
+ if (!task.isSuccessful()) {
26
+ Exception ex = task.getException();
27
+ String message = ex != null && ex.getLocalizedMessage() != null
28
+ ? ex.getLocalizedMessage()
29
+ : "Failed to request Play in-app review flow.";
30
+ call.reject(message, "REVIEW_REQUEST_FAILED", ex);
31
+ return;
32
+ }
33
+
34
+ ReviewInfo reviewInfo = task.getResult();
35
+ manager.launchReviewFlow(currentActivity, reviewInfo).addOnCompleteListener(flowTask -> {
36
+ if (flowTask.isSuccessful()) {
37
+ call.resolve();
38
+ } else {
39
+ Exception ex = flowTask.getException();
40
+ String message = ex != null && ex.getLocalizedMessage() != null
41
+ ? ex.getLocalizedMessage()
42
+ : "Failed to launch Play in-app review flow.";
43
+ call.reject(message, "REVIEW_LAUNCH_FAILED", ex);
44
+ }
45
+ });
46
+ });
47
+ }
48
+ }
@@ -0,0 +1,79 @@
1
+ package com.simasdk;
2
+
3
+ import android.content.Context;
4
+ import android.content.SharedPreferences;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import java.util.Map;
11
+
12
+ @CapacitorPlugin(name = "SimaStorage")
13
+ public class SimaStoragePlugin extends Plugin {
14
+
15
+ private static final String PREFS_NAME = "simasdk_storage";
16
+
17
+ private SharedPreferences getPrefs() {
18
+ return getContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
19
+ }
20
+
21
+ @PluginMethod
22
+ public void get(PluginCall call) {
23
+ String key = call.getString("key");
24
+ if (key == null || key.isEmpty()) {
25
+ call.reject("Missing required storage key.", "INVALID_KEY");
26
+ return;
27
+ }
28
+ String value = getPrefs().getString(key, null);
29
+ JSObject ret = new JSObject();
30
+ ret.put("value", value);
31
+ call.resolve(ret);
32
+ }
33
+
34
+ @PluginMethod
35
+ public void set(PluginCall call) {
36
+ String key = call.getString("key");
37
+ if (key == null || key.isEmpty()) {
38
+ call.reject("Missing required storage key.", "INVALID_KEY");
39
+ return;
40
+ }
41
+ String value = call.getString("value");
42
+ if (value == null) {
43
+ call.reject("Missing required string value.", "INVALID_VALUE");
44
+ return;
45
+ }
46
+ getPrefs().edit().putString(key, value).apply();
47
+ call.resolve();
48
+ }
49
+
50
+ @PluginMethod
51
+ public void remove(PluginCall call) {
52
+ String key = call.getString("key");
53
+ if (key == null || key.isEmpty()) {
54
+ call.reject("Missing required storage key.", "INVALID_KEY");
55
+ return;
56
+ }
57
+ getPrefs().edit().remove(key).apply();
58
+ call.resolve();
59
+ }
60
+
61
+ @PluginMethod
62
+ public void clearPrefix(PluginCall call) {
63
+ String prefix = call.getString("prefix");
64
+ if (prefix == null || prefix.isEmpty()) {
65
+ call.reject("Missing required prefix.", "INVALID_KEY");
66
+ return;
67
+ }
68
+ SharedPreferences prefs = getPrefs();
69
+ SharedPreferences.Editor editor = prefs.edit();
70
+ Map<String, ?> all = prefs.getAll();
71
+ for (String key : all.keySet()) {
72
+ if (key.startsWith(prefix)) {
73
+ editor.remove(key);
74
+ }
75
+ }
76
+ editor.apply();
77
+ call.resolve();
78
+ }
79
+ }