react-native-alarmageddon 1.1.1 → 2.1.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.
- package/LICENSE +1 -1
- package/README.md +169 -187
- package/android/build/.transforms/33d69af0aa8d226a34981fd71aab63e2/results.bin +1 -0
- package/android/build/.transforms/33d69af0aa8d226a34981fd71aab63e2/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/4aeb440f8cdf777de34ab1099140d239/results.bin +1 -0
- package/android/build/.transforms/4aeb440f8cdf777de34ab1099140d239/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/generated/source/buildConfig/debug/com/rnalarmmodule/BuildConfig.java +10 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +41 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output-metadata.json +18 -0
- package/android/build/intermediates/aar_metadata/debug/writeDebugAarMetadata/aar-metadata.properties +6 -0
- package/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug/annotationProcessors.json +1 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/generateDebugRFile/R.txt +1 -0
- package/android/build/intermediates/compiled_local_resources/debug/compileDebugLibraryResources/out/raw_alarm_default.wav.flat +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +2 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugAssets/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/build/intermediates/java_res/debug/processDebugJavaRes/out/META-INF/react-native-alarmageddon_debug.kotlin_module +0 -0
- package/android/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/rnalarmmodule/BuildConfig.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/parseDebugLocalResources/R-def.txt +3 -0
- package/android/build/intermediates/manifest_merge_blame_file/debug/processDebugManifest/manifest-merger-blame-debug-report.txt +68 -0
- package/android/build/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml +41 -0
- package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +1 -0
- package/android/build/intermediates/nested_resources_validation_report/debug/generateDebugResources/nestedResourcesValidationReport.txt +1 -0
- package/android/build/intermediates/packaged_res/debug/packageDebugResources/raw/alarm_default.wav +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/generateDebugRFile/package-aware-r.txt +2 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +2 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +71 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build/tmp/kotlin-classes/debug/META-INF/react-native-alarmageddon_debug.kotlin_module +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/AlarmModule$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/AlarmModule.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/AlarmPackage.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/AlarmReceiver$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/AlarmReceiver.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/BootReceiver$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/rnalarmmodule/BootReceiver.class +0 -0
- package/android/build.gradle +11 -21
- package/android/src/main/AndroidManifest.xml +16 -35
- package/android/src/main/java/com/rnalarmmodule/AlarmModule.kt +163 -387
- package/android/src/main/java/com/rnalarmmodule/AlarmPackage.kt +0 -1
- package/android/src/main/java/com/rnalarmmodule/AlarmReceiver.kt +300 -129
- package/android/src/main/java/com/rnalarmmodule/BootReceiver.kt +66 -124
- package/android/src/main/res/raw/alarm_default.wav +0 -0
- package/ios/{RNAlarmModule.m → AlarmModule.m} +9 -20
- package/ios/AlarmModule.swift +241 -36
- package/ios/RNAlarmModule-Bridging-Header.h +5 -1
- package/lib/index.d.ts +51 -85
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +60 -120
- package/lib/index.js.map +1 -1
- package/package.json +14 -23
- package/react-native-alarmageddon.podspec +10 -8
- package/react-native.config.js +3 -1
- package/src/index.ts +98 -201
- package/android/gradle.properties +0 -13
- package/android/src/main/java/com/rnalarmmodule/AlarmActivity.kt +0 -79
- package/android/src/main/java/com/rnalarmmodule/AlarmService.kt +0 -290
- package/android/src/main/res/raw/README.md +0 -36
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
package com.rnalarmmodule
|
|
2
|
-
|
|
3
|
-
import android.app.Notification
|
|
4
|
-
import android.app.NotificationChannel
|
|
5
|
-
import android.app.NotificationManager
|
|
6
|
-
import android.app.PendingIntent
|
|
7
|
-
import android.app.Service
|
|
8
|
-
import android.content.Context
|
|
9
|
-
import android.content.Intent
|
|
10
|
-
import android.media.AudioAttributes
|
|
11
|
-
import android.media.AudioManager
|
|
12
|
-
import android.media.MediaPlayer
|
|
13
|
-
import android.media.RingtoneManager
|
|
14
|
-
import android.net.Uri
|
|
15
|
-
import android.os.Build
|
|
16
|
-
import android.os.Handler
|
|
17
|
-
import android.os.IBinder
|
|
18
|
-
import android.os.Looper
|
|
19
|
-
import android.os.VibrationEffect
|
|
20
|
-
import android.os.Vibrator
|
|
21
|
-
import android.os.VibratorManager
|
|
22
|
-
import android.util.Log
|
|
23
|
-
import androidx.core.app.NotificationCompat
|
|
24
|
-
|
|
25
|
-
class AlarmService : Service() {
|
|
26
|
-
|
|
27
|
-
companion object {
|
|
28
|
-
private const val TAG = "AlarmService"
|
|
29
|
-
private const val NOTIFICATION_ID = 1001
|
|
30
|
-
private const val CHANNEL_ID = "alarm_channel"
|
|
31
|
-
private const val CHANNEL_NAME = "Alarm Notifications"
|
|
32
|
-
|
|
33
|
-
const val ACTION_START = "com.rnalarmmodule.ACTION_START"
|
|
34
|
-
const val ACTION_STOP = "com.rnalarmmodule.ACTION_STOP"
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private var mediaPlayer: MediaPlayer? = null
|
|
38
|
-
private var vibrator: Vibrator? = null
|
|
39
|
-
private var autoStopHandler: Handler? = null
|
|
40
|
-
private var autoStopRunnable: Runnable? = null
|
|
41
|
-
private var currentAlarmId: String? = null
|
|
42
|
-
|
|
43
|
-
override fun onCreate() {
|
|
44
|
-
super.onCreate()
|
|
45
|
-
createNotificationChannel()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override fun onBind(intent: Intent?): IBinder? = null
|
|
49
|
-
|
|
50
|
-
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
51
|
-
when (intent?.action) {
|
|
52
|
-
ACTION_START -> {
|
|
53
|
-
val alarmId = intent.getStringExtra("alarmId") ?: "unknown"
|
|
54
|
-
val title = intent.getStringExtra("title") ?: "Alarm"
|
|
55
|
-
val body = intent.getStringExtra("body") ?: ""
|
|
56
|
-
val soundUri = intent.getStringExtra("soundUri") ?: ""
|
|
57
|
-
val vibrate = intent.getBooleanExtra("vibrate", true)
|
|
58
|
-
val snoozeMinutes = intent.getIntExtra("snoozeMinutes", 5)
|
|
59
|
-
val autoStopSeconds = intent.getIntExtra("autoStopSeconds", 60)
|
|
60
|
-
|
|
61
|
-
currentAlarmId = alarmId
|
|
62
|
-
startForeground(NOTIFICATION_ID, createNotification(alarmId, title, body, snoozeMinutes))
|
|
63
|
-
startAlarm(soundUri, vibrate, autoStopSeconds)
|
|
64
|
-
}
|
|
65
|
-
ACTION_STOP -> {
|
|
66
|
-
stopAlarm()
|
|
67
|
-
stopForeground(STOP_FOREGROUND_REMOVE)
|
|
68
|
-
stopSelf()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return START_NOT_STICKY
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
override fun onDestroy() {
|
|
75
|
-
stopAlarm()
|
|
76
|
-
super.onDestroy()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private fun createNotificationChannel() {
|
|
80
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
81
|
-
val channel = NotificationChannel(
|
|
82
|
-
CHANNEL_ID,
|
|
83
|
-
CHANNEL_NAME,
|
|
84
|
-
NotificationManager.IMPORTANCE_HIGH
|
|
85
|
-
).apply {
|
|
86
|
-
description = "Alarm notifications"
|
|
87
|
-
setBypassDnd(true)
|
|
88
|
-
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
|
89
|
-
setSound(null, null) // We handle sound separately
|
|
90
|
-
enableVibration(false) // We handle vibration separately
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
val notificationManager = getSystemService(NotificationManager::class.java)
|
|
94
|
-
notificationManager?.createNotificationChannel(channel)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private fun createNotification(alarmId: String, title: String, body: String, snoozeMinutes: Int): Notification {
|
|
99
|
-
// Stop action
|
|
100
|
-
val stopIntent = Intent(this, AlarmReceiver::class.java).apply {
|
|
101
|
-
action = AlarmReceiver.ACTION_STOP
|
|
102
|
-
putExtra("alarmId", alarmId)
|
|
103
|
-
}
|
|
104
|
-
val stopPendingIntent = PendingIntent.getBroadcast(
|
|
105
|
-
this,
|
|
106
|
-
alarmId.hashCode() + 1,
|
|
107
|
-
stopIntent,
|
|
108
|
-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
// Snooze action
|
|
112
|
-
val snoozeIntent = Intent(this, AlarmReceiver::class.java).apply {
|
|
113
|
-
action = AlarmReceiver.ACTION_SNOOZE
|
|
114
|
-
putExtra("alarmId", alarmId)
|
|
115
|
-
putExtra("snoozeMinutes", snoozeMinutes)
|
|
116
|
-
}
|
|
117
|
-
val snoozePendingIntent = PendingIntent.getBroadcast(
|
|
118
|
-
this,
|
|
119
|
-
alarmId.hashCode() + 2,
|
|
120
|
-
snoozeIntent,
|
|
121
|
-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
// Full screen intent to open app
|
|
125
|
-
val fullScreenIntent = packageManager.getLaunchIntentForPackage(packageName)?.apply {
|
|
126
|
-
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
127
|
-
putExtra("alarmId", alarmId)
|
|
128
|
-
}
|
|
129
|
-
val fullScreenPendingIntent = fullScreenIntent?.let {
|
|
130
|
-
PendingIntent.getActivity(
|
|
131
|
-
this,
|
|
132
|
-
alarmId.hashCode() + 3,
|
|
133
|
-
it,
|
|
134
|
-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
|
|
139
|
-
.setContentTitle(title)
|
|
140
|
-
.setContentText(body)
|
|
141
|
-
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
|
|
142
|
-
.setPriority(NotificationCompat.PRIORITY_MAX)
|
|
143
|
-
.setCategory(NotificationCompat.CATEGORY_ALARM)
|
|
144
|
-
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
145
|
-
.setOngoing(true)
|
|
146
|
-
.setAutoCancel(false)
|
|
147
|
-
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Stop", stopPendingIntent)
|
|
148
|
-
.addAction(android.R.drawable.ic_popup_sync, "Snooze ($snoozeMinutes min)", snoozePendingIntent)
|
|
149
|
-
|
|
150
|
-
if (fullScreenPendingIntent != null) {
|
|
151
|
-
builder.setFullScreenIntent(fullScreenPendingIntent, true)
|
|
152
|
-
builder.setContentIntent(fullScreenPendingIntent)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return builder.build()
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
private fun startAlarm(soundUri: String, vibrate: Boolean, autoStopSeconds: Int) {
|
|
159
|
-
Log.d(TAG, "Starting alarm: soundUri=$soundUri, vibrate=$vibrate, autoStop=${autoStopSeconds}s")
|
|
160
|
-
|
|
161
|
-
// Start sound
|
|
162
|
-
try {
|
|
163
|
-
mediaPlayer?.release()
|
|
164
|
-
mediaPlayer = MediaPlayer().apply {
|
|
165
|
-
setAudioAttributes(
|
|
166
|
-
AudioAttributes.Builder()
|
|
167
|
-
.setUsage(AudioAttributes.USAGE_ALARM)
|
|
168
|
-
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
169
|
-
.build()
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
val uri = if (soundUri.isNotEmpty()) {
|
|
173
|
-
try {
|
|
174
|
-
Uri.parse(soundUri)
|
|
175
|
-
} catch (e: Exception) {
|
|
176
|
-
getDefaultAlarmUri()
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
getDefaultAlarmUri()
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
setDataSource(this@AlarmService, uri)
|
|
184
|
-
} catch (e: Exception) {
|
|
185
|
-
Log.w(TAG, "Failed to set data source, using default: ${e.message}")
|
|
186
|
-
setDataSource(this@AlarmService, getDefaultAlarmUri())
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
isLooping = true
|
|
190
|
-
|
|
191
|
-
// Set volume to max for alarm
|
|
192
|
-
val audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
|
193
|
-
val maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)
|
|
194
|
-
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume, 0)
|
|
195
|
-
|
|
196
|
-
prepare()
|
|
197
|
-
start()
|
|
198
|
-
}
|
|
199
|
-
} catch (e: Exception) {
|
|
200
|
-
Log.e(TAG, "Failed to start alarm sound: ${e.message}", e)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Start vibration
|
|
204
|
-
if (vibrate) {
|
|
205
|
-
startVibration()
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Schedule auto-stop
|
|
209
|
-
if (autoStopSeconds > 0) {
|
|
210
|
-
autoStopHandler = Handler(Looper.getMainLooper())
|
|
211
|
-
autoStopRunnable = Runnable {
|
|
212
|
-
Log.d(TAG, "Auto-stopping alarm after ${autoStopSeconds}s")
|
|
213
|
-
stopAlarm()
|
|
214
|
-
stopForeground(STOP_FOREGROUND_REMOVE)
|
|
215
|
-
stopSelf()
|
|
216
|
-
|
|
217
|
-
// Clear active alarm state
|
|
218
|
-
val prefs = getSharedPreferences("rn_alarm_module_alarms", Context.MODE_PRIVATE)
|
|
219
|
-
prefs.edit().remove("active_alarm_id").apply()
|
|
220
|
-
AlarmModule.emitActiveAlarmId(null)
|
|
221
|
-
}
|
|
222
|
-
autoStopHandler?.postDelayed(autoStopRunnable!!, autoStopSeconds * 1000L)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private fun getDefaultAlarmUri(): Uri {
|
|
227
|
-
// Try to get default alarm sound
|
|
228
|
-
var uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
|
|
229
|
-
if (uri == null) {
|
|
230
|
-
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
|
|
231
|
-
}
|
|
232
|
-
if (uri == null) {
|
|
233
|
-
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
|
234
|
-
}
|
|
235
|
-
return uri ?: Uri.parse("android.resource://${packageName}/${R.raw.alarm_default}")
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private fun startVibration() {
|
|
239
|
-
try {
|
|
240
|
-
vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
241
|
-
val vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
|
|
242
|
-
vibratorManager.defaultVibrator
|
|
243
|
-
} else {
|
|
244
|
-
@Suppress("DEPRECATION")
|
|
245
|
-
getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// Vibration pattern: wait 0ms, vibrate 500ms, wait 500ms, repeat
|
|
249
|
-
val pattern = longArrayOf(0, 500, 500, 500, 500, 500)
|
|
250
|
-
|
|
251
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
252
|
-
val effect = VibrationEffect.createWaveform(pattern, 0) // 0 = repeat from index 0
|
|
253
|
-
vibrator?.vibrate(effect)
|
|
254
|
-
} else {
|
|
255
|
-
@Suppress("DEPRECATION")
|
|
256
|
-
vibrator?.vibrate(pattern, 0)
|
|
257
|
-
}
|
|
258
|
-
} catch (e: Exception) {
|
|
259
|
-
Log.e(TAG, "Failed to start vibration: ${e.message}", e)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private fun stopAlarm() {
|
|
264
|
-
Log.d(TAG, "Stopping alarm")
|
|
265
|
-
|
|
266
|
-
// Stop sound
|
|
267
|
-
try {
|
|
268
|
-
mediaPlayer?.stop()
|
|
269
|
-
mediaPlayer?.release()
|
|
270
|
-
mediaPlayer = null
|
|
271
|
-
} catch (e: Exception) {
|
|
272
|
-
Log.e(TAG, "Error stopping media player: ${e.message}", e)
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Stop vibration
|
|
276
|
-
try {
|
|
277
|
-
vibrator?.cancel()
|
|
278
|
-
vibrator = null
|
|
279
|
-
} catch (e: Exception) {
|
|
280
|
-
Log.e(TAG, "Error stopping vibration: ${e.message}", e)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Cancel auto-stop
|
|
284
|
-
autoStopRunnable?.let { autoStopHandler?.removeCallbacks(it) }
|
|
285
|
-
autoStopHandler = null
|
|
286
|
-
autoStopRunnable = null
|
|
287
|
-
|
|
288
|
-
currentAlarmId = null
|
|
289
|
-
}
|
|
290
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Alarm Sound Resources
|
|
2
|
-
|
|
3
|
-
This directory contains the default alarm sound for the react-native-alarmageddon library.
|
|
4
|
-
|
|
5
|
-
## Default Alarm Sound
|
|
6
|
-
|
|
7
|
-
The library looks for `alarm_default.wav` (or `.mp3`, `.ogg`) in this directory as a fallback when:
|
|
8
|
-
1. No custom sound URI is provided
|
|
9
|
-
2. The system's default alarm sound cannot be loaded
|
|
10
|
-
|
|
11
|
-
## Adding Your Own Default Sound
|
|
12
|
-
|
|
13
|
-
To include a default alarm sound with the library:
|
|
14
|
-
|
|
15
|
-
1. Add your audio file to this directory with one of these names:
|
|
16
|
-
- `alarm_default.wav`
|
|
17
|
-
- `alarm_default.mp3`
|
|
18
|
-
- `alarm_default.ogg`
|
|
19
|
-
|
|
20
|
-
2. The file should be:
|
|
21
|
-
- A short, loopable alarm sound (5-15 seconds recommended)
|
|
22
|
-
- Optimized for size
|
|
23
|
-
- Clear and alerting
|
|
24
|
-
|
|
25
|
-
## Sound Priority
|
|
26
|
-
|
|
27
|
-
The library uses sounds in this order:
|
|
28
|
-
1. Custom `soundUri` provided in `scheduleAlarm()` params
|
|
29
|
-
2. Android system's default alarm sound (`RingtoneManager.TYPE_ALARM`)
|
|
30
|
-
3. Android system's default notification sound
|
|
31
|
-
4. Android system's default ringtone
|
|
32
|
-
5. The `alarm_default` file from this directory (if exists)
|
|
33
|
-
|
|
34
|
-
## Note
|
|
35
|
-
|
|
36
|
-
Since the system default alarm sound is usually available on all Android devices, you may not need to include a custom sound file. The library will gracefully fall back to system sounds.
|