diff --git a/CHANGELOG.md b/CHANGELOG.md index 002e5c8..f777737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +## 6.0.0 - 27/06/2020 +* Support custom sound + ## 5.1.3 - 06/06/2020 * Bug Fixes diff --git a/alerter/build.gradle b/alerter/build.gradle index 7d0bf4a..c7e3977 100644 --- a/alerter/build.gradle +++ b/alerter/build.gradle @@ -14,7 +14,7 @@ apply from: rootProject.file('quality.gradle') final String GROUP_ID = "com.tapadoo.android" -final String VERSION = "5.1.3" +final String VERSION = "6.0.0" final String DESCRIPTION = "An Android Alerting Library" final String GITHUB_URL = "https://github.com/Tapadoo/Alerter" diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt index 28ad111..cad2353 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt @@ -6,6 +6,7 @@ import android.content.Context import android.graphics.* import android.graphics.drawable.Drawable import android.media.RingtoneManager +import android.net.Uri import android.os.Build import android.text.TextUtils import android.util.AttributeSet @@ -74,9 +75,9 @@ class Alert @JvmOverloads constructor(context: Context, private var vibrationEnabled = true /** - * Flag to enable / disable sound + * Uri to set sound */ - private var soundEnabled = false + private var soundUri : Uri? = null /** * Sets the Layout Gravity of the Alert @@ -219,15 +220,9 @@ class Alert @JvmOverloads constructor(context: Context, if (vibrationEnabled) { performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY) } - - if (soundEnabled) { - try { - val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) - val r = RingtoneManager.getRingtone(context, notification) - r.play() - } catch (e: Exception) { - e.printStackTrace() - } + soundUri?.let { + val r = RingtoneManager.getRingtone(context, soundUri) + r.play() } if (enableProgress) { @@ -757,12 +752,12 @@ class Alert @JvmOverloads constructor(context: Context, } /** - * Enable or Disable sound + * Set sound Uri * - * @param soundEnabled True to enable, false to disable + * @param soundUri To set sound Uri (raw folder) */ - fun setSoundEnabled(soundEnabled: Boolean) { - this.soundEnabled = soundEnabled + fun setSound(soundUri: Uri?) { + this.soundUri = soundUri } /** diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index 9a9c16f..6585f25 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt @@ -6,6 +6,8 @@ import android.graphics.ColorFilter import android.graphics.PorterDuff import android.graphics.Typeface import android.graphics.drawable.Drawable +import android.media.RingtoneManager +import android.net.Uri import android.view.View import android.view.ViewGroup import android.view.animation.AnimationUtils @@ -582,17 +584,18 @@ class Alerter private constructor() { } /** - * Enable or Disable Sound + * Set sound Uri + * if set null, sound will be disabled * - * @param enable True to enable, False to disable + * @param uri To set sound Uri (raw folder) * @return This Alerter */ - fun enableSound(enable: Boolean): Alerter { - alert?.setSoundEnabled(enable) + @JvmOverloads + fun setSound(uri: Uri? = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)): Alerter { + alert?.setSound(uri) return this } - /** * Disable touch events outside of the Alert * diff --git a/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java b/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java index d7f0f9c..c74ae4a 100644 --- a/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java +++ b/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java @@ -1,6 +1,7 @@ package com.tapadoo.alerter.demo; import android.graphics.Typeface; +import android.net.Uri; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -226,7 +227,7 @@ private void showAlertSound() { .setTitle("Alert Title") .setText("Alert text...") .setBackgroundColorRes(R.color.colorAccent) - .enableSound(true) + .setSound(Uri.parse("android.resource://"+getPackageName()+"/raw/ringtone")) .show(); } diff --git a/app/src/main/java/com/tapadoo/alerter/demo/KotlinDemoActivity.kt b/app/src/main/java/com/tapadoo/alerter/demo/KotlinDemoActivity.kt index 09509d0..b8dccfa 100644 --- a/app/src/main/java/com/tapadoo/alerter/demo/KotlinDemoActivity.kt +++ b/app/src/main/java/com/tapadoo/alerter/demo/KotlinDemoActivity.kt @@ -1,12 +1,13 @@ package com.tapadoo.alerter.demo import android.graphics.Typeface +import android.net.Uri import android.os.Bundle import android.view.Gravity -import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.widget.Toolbar import android.view.View import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar import com.tapadoo.alerter.Alerter import com.tapadoo.alerter.OnHideAlertListener import com.tapadoo.alerter.OnShowAlertListener @@ -159,7 +160,7 @@ class KotlinDemoActivity : AppCompatActivity() { .setTitle("Alert Title") .setText("Alert text...") .setBackgroundColorRes(R.color.colorAccent) - .enableSound(true) + .setSound(Uri.parse("android.resource://$packageName/raw/ringtone")) .show() } diff --git a/app/src/main/res/raw/ringtone.mp3 b/app/src/main/res/raw/ringtone.mp3 new file mode 100644 index 0000000..e78f7c3 Binary files /dev/null and b/app/src/main/res/raw/ringtone.mp3 differ