diff --git a/CHANGELOG.md b/CHANGELOG.md index 89660c9..c04098c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,24 @@ # Change Log All notable changes to this project will be documented in this file. +## 6.2.1 - 03/09/2020 +* Updated negative margin to fix overshoot on Samsung S10 + +## 6.2.0 - 03/09/2020 +* Added the ability to enable\disable click animation + +## 6.1.0 - 27/06/2020 +* Readded getters for title & text TextView + +## 6.0.0 - 27/06/2020 +* Support custom sound + +## 5.1.3 - 06/06/2020 +* Bug Fixes + +## 5.1.2 - 16/02/2020 +* Added support for rightIcon. + ## 5.1.1 - 28/01/2020 * Minor refactoring @@ -64,7 +82,7 @@ All notable changes to this project will be documented in this file. * Added isShowing method * Added additional icon setting methods * Added styling methods -* added progress bar +* Added progress bar ## 1.0.9 - 27/06/2017 * Added Swipe to Dismiss diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aed2653..3f7eeda 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,8 +3,25 @@ ### Issues Make sure to search through any issues that have already been filed at https://github.com/Tapadoo/Alerter/issues before opening a new issue. +When creating an issue, please include: + +1. The version of the library you're using +2. The version of Android you're testing on +3. The device you're testing on +4. A code snippet of how you're using the library +5. A short description of the issue +6. Optional - a potential solution to the issue (Remember, PRs are always welcome!) + +Also, please read this [article on how to write the perfect bug report](https://medium.com/pitch-perfect/how-to-write-the-perfect-bug-report-6430f5a45cd). + ### Pull requests -If you would like to contribute to the code you can do so through GitHub by forking the repository and submitting a pull request into the develop branch. When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. + +We welcome, and encourage PRs! + +If you would like to contribute to the code you can do so through GitHub by forking the repository and submitting a pull +request into the develop branch. When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. + +It's important to give motivations & use cases for new features, as we want to keep the library lean & focused. ### Checkstyles Make sure to run a check `./gradlew :alerter:assemble check` on the code against the quality checkers that are used by the project and fix error that get raised. See `app/build/reports/` for generated report files. diff --git a/README.md b/README.md index 24ee3ba..bd32858 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,18 @@ complexity of your layouts. [![Download](https://api.bintray.com/packages/tapadoo/maven/alerter/images/download.svg)](https://bintray.com/tapadoo/maven/alerter/_latestVersion) [![API](https://img.shields.io/badge/API-14%2B-orange.svg?style=flat)](https://android-arsenal.com/api?level=14) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Alerter-blue.svg?style=flat)](https://android-arsenal.com/details/1/5302) [![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23245-blue.svg)](http://androidweekly.net/issues/issue-245) -[![Header](./documentation/header.png)](https://play.google.com/store/apps/details?id=com.tapadoo.alerter_demo) +![Header](./documentation/header.png) ## General With simplicity in mind, the Alerter employs the builder pattern to facilitate easy integration into any app. -A customisable Alert view is dynamically added to the Decor View of the Window, overlaying all content. +A customisable Alert View is dynamically added to the Decor View of the Window, overlaying all content. ## Gradle ```groovy dependencies { - implementation 'com.tapadoo.android:alerter:4.1.0' + implementation 'com.tapadoo.android:alerter:$current-version' } ``` @@ -240,9 +240,9 @@ Alerter.create(this@DemoActivity) ![Verbose Alert](./documentation/alert_with_custom_layout.gif) -## Sample +# Contributing & Reporting Issues -Clone this repo and check out the `app-base` module. +[Please read this if you're reporting an issue, or thinking of contributing!](./CONTRIBUTING.md) ## Licence @@ -250,4 +250,4 @@ See the [LICENSE](LICENSE.md) file for license rights and limitations (MIT). Copyright 2017 Tapadoo, Dublin. -![Alt Text](https://tapadoo.com/wp-content/themes/tapadoo/assets/images/tapadoo_logo_dark.png) + diff --git a/alerter/build.gradle b/alerter/build.gradle index d8eabe0..96a589e 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.1" +final String VERSION = "6.2.1" 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 8d45885..6830504 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 @@ -16,6 +17,7 @@ import android.view.animation.AnimationUtils import android.widget.Button import android.widget.FrameLayout import android.widget.LinearLayout +import android.widget.TextView import androidx.annotation.* import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.view.ContextThemeWrapper @@ -23,6 +25,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.core.widget.TextViewCompat import com.tapadoo.alerter.utils.getDimenPixelSize +import com.tapadoo.alerter.utils.getRippleDrawable import com.tapadoo.alerter.utils.notchHeight import kotlinx.android.synthetic.main.alerter_alert_default_layout.view.* import kotlinx.android.synthetic.main.alerter_alert_view.view.* @@ -53,6 +56,10 @@ class Alert @JvmOverloads constructor(context: Context, private var enableInfiniteDuration: Boolean = false private var enableProgress: Boolean = false + private var showRightIcon: Boolean = false + private var enableClickAnimation: Boolean = true + private var enableRightIconPurse = true + private var runningAnimation: Runnable? = null private var isDismissible = true @@ -71,9 +78,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 @@ -128,13 +135,20 @@ class Alert @JvmOverloads constructor(context: Context, super.onAttachedToWindow() llAlertBackground.apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + foreground = if (enableClickAnimation.not()) { + null + } else { + context.getRippleDrawable() + } + } (layoutParams as LayoutParams).gravity = layoutGravity if (layoutGravity != Gravity.TOP) { setPadding( - 0, getDimenPixelSize(R.dimen.alerter_padding_default), - 0, getDimenPixelSize(R.dimen.alerter_alert_padding) + paddingLeft, getDimenPixelSize(R.dimen.alerter_padding_default), + paddingRight, getDimenPixelSize(R.dimen.alerter_alert_padding) ) } } @@ -216,28 +230,34 @@ 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) { ivIcon?.visibility = View.INVISIBLE + ivRightIcon?.visibility = View.INVISIBLE pbProgress?.visibility = View.VISIBLE - } else if (showIcon) { - ivIcon?.visibility = View.VISIBLE - // Only pulse if we're not showing the progress - if (enableIconPulse) { - ivIcon?.startAnimation(AnimationUtils.loadAnimation(context, R.anim.alerter_pulse)) - } } else { - flIconContainer?.visibility = View.GONE + if (showIcon) { + ivIcon?.visibility = View.VISIBLE + // Only pulse if we're not showing the progress + if (enableIconPulse) { + ivIcon?.startAnimation(AnimationUtils.loadAnimation(context, R.anim.alerter_pulse)) + } + } else { + flIconContainer?.visibility = View.GONE + } + if (showRightIcon) { + ivRightIcon?.visibility = View.VISIBLE + + if (enableRightIconPurse) { + ivRightIcon?.startAnimation(AnimationUtils.loadAnimation(context, R.anim.alerter_pulse)) + } + } else { + flRightIconContainer?.visibility = View.GONE + } } } } @@ -526,6 +546,120 @@ class Alert @JvmOverloads constructor(context: Context, this.showIcon = showIcon } + /** + * Set the inline right icon for the Alert + * + * @param iconId Drawable resource id of the right icon to use in the Alert + */ + fun setRightIcon(@DrawableRes iconId: Int) { + ivRightIcon?.setImageDrawable(AppCompatResources.getDrawable(context, iconId)) + } + + /** + * Set the right icon color for the Alert + * + * @param color Color int + */ + fun setRightIconColorFilter(@ColorInt color: Int) { + ivRightIcon?.setColorFilter(color) + } + + /** + * Set the right icon color for the Alert + * + * @param colorFilter ColorFilter + */ + fun setRightIconColorFilter(colorFilter: ColorFilter) { + ivRightIcon?.colorFilter = colorFilter + } + + /** + * Set the right icon color for the Alert + * + * @param color Color int + * @param mode PorterDuff.Mode + */ + fun setRightIconColorFilter(@ColorInt color: Int, mode: PorterDuff.Mode) { + ivRightIcon?.setColorFilter(color, mode) + } + + /** + * Set the inline right icon for the Alert + * + * @param bitmap Bitmap image of the right icon to use in the Alert. + */ + fun setRightIcon(bitmap: Bitmap) { + ivRightIcon?.setImageBitmap(bitmap) + } + + /** + * Set the inline right icon for the Alert + * + * @param drawable Drawable image of the right icon to use in the Alert. + */ + fun setRightIcon(drawable: Drawable) { + ivRightIcon?.setImageDrawable(drawable) + } + + /** + * Set the inline right icon size for the Alert + * + * @param size Dimension int. + */ + fun setRightIconSize(@DimenRes size: Int) { + val pixelSize = context.resources.getDimensionPixelSize(size) + setRightIconPixelSize(pixelSize) + } + + /** + * Set the inline right icon size for the Alert + * + * @param size Icon size in pixel. + */ + fun setRightIconPixelSize(@Px size: Int) { + ivRightIcon.layoutParams = ivRightIcon.layoutParams.apply { + width = size + height = size + minimumWidth = size + minimumHeight = size + } + } + + /** + * Set whether to show the right icon in the alert or not + * + * @param showRightIcon True to show the right icon, false otherwise + */ + fun showRightIcon(showRightIcon: Boolean) { + this.showRightIcon = showRightIcon + } + + /** + * Set whether to show the animation on focus/pressed states + * + * @param enabled True to show the animation, false otherwise + */ + fun enableClickAnimation(enabled: Boolean) { + this.enableClickAnimation = enabled + } + + /** + * Set right icon position + * + * @param position gravity of an right icon's parent. Can be: Gravity.TOP, + * Gravity.CENTER, Gravity.CENTER_VERTICAL or Gravity.BOTTOM + */ + fun setRightIconPosition(position: Int) { + if (position == Gravity.TOP + || position == Gravity.CENTER + || position == Gravity.CENTER_VERTICAL + || position == Gravity.BOTTOM) { + flRightIconContainer.layoutParams = (flRightIconContainer.layoutParams as LinearLayout.LayoutParams).apply { + gravity = position + } + } + } + /** * Set if the alerter is isDismissible or not * @@ -573,6 +707,15 @@ class Alert @JvmOverloads constructor(context: Context, this.enableIconPulse = shouldPulse } + /** + * Set if the Right Icon should pulse or not + * + * @param shouldPulse True if the right icon should be animated + */ + fun pulseRightIcon(shouldPulse: Boolean) { + this.enableRightIconPurse = shouldPulse + } + /** * Set if the duration of the alert is infinite * @@ -628,12 +771,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 } /** @@ -656,6 +799,20 @@ class Alert @JvmOverloads constructor(context: Context, } } + /** + * @return the TextView for the title + */ + fun getTitle(): TextView { + return tvTitle + } + + /** + * @return the TextView for the text + */ + fun getText(): TextView { + return tvText + } + override fun canDismiss(): Boolean { return isDismissible } diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt b/alerter/src/main/java/com/tapadoo/alerter/Alerter.kt index a658c6f..6d85787 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 @@ -341,6 +343,115 @@ class Alerter private constructor() { return this } + /** + * Set the Alert's Right Icon + * + * @param iconId The Drawable's Resource Idw + * @return This Alerter + */ + fun setRightIcon(@DrawableRes rightIconId: Int): Alerter { + alert?.setRightIcon(rightIconId) + + return this + } + + /** + * Set the Alert's Right Icon + * + * @param bitmap The Bitmap object to use for the right icon. + * @return This Alerter + */ + fun setRightIcon(bitmap: Bitmap): Alerter { + alert?.setRightIcon(bitmap) + + return this + } + + /** + * Set the Alert's Right Icon + * + * @param drawable The Drawable to use for the right icon. + * @return This Alerter + */ + fun setRightIcon(drawable: Drawable): Alerter { + alert?.setRightIcon(drawable) + + return this + } + + /** + * Set the Alert's Right Icon size + * + * @param size Dimension int. + * @return This Alerter + */ + fun setRightIconSize(@DimenRes size: Int): Alerter { + alert?.setRightIconSize(size) + + return this + } + + /** + * Set the Alert's Right Icon size + * + * @param size Right Icon size in pixel. + * @return This Alerter + */ + fun setRightIconPixelSize(@Px size: Int): Alerter { + alert?.setRightIconPixelSize(size) + + return this + } + + /** + * Set the right icon color for the Alert + * + * @param color Color int + * @return This Alerter + */ + fun setRightIconColorFilter(@ColorInt color: Int): Alerter { + alert?.setRightIconColorFilter(color) + + return this + } + + /** + * Set the right icon color for the Alert + * + * @param colorFilter ColorFilter + * @return This Alerter + */ + fun setRightIconColorFilter(colorFilter: ColorFilter): Alerter { + alert?.setRightIconColorFilter(colorFilter) + + return this + } + + /** + * Set the right icon color for the Alert + * + * @param color Color int + * @param mode PorterDuff.Mode + * @return This Alerter + */ + fun setRightIconColorFilter(@ColorInt color: Int, mode: PorterDuff.Mode): Alerter { + alert?.setRightIconColorFilter(color, mode) + + return this + } + + /** + * Set the right icons's position for the Alert + * + * @param gravity Gravity int + * @return This Alerter + */ + fun setRightIconPosition(gravity: Int): Alerter { + alert?.setRightIconPosition(gravity) + + return this + } + /** * Set the onClickListener for the Alert * @@ -389,6 +500,41 @@ class Alerter private constructor() { return this } + /** + * Enable or Disable Right Icon Pulse Animations + * + * @param pulse True if the right icon should pulse + * @return This Alerter + */ + fun enableRightIconPulse(pulse: Boolean): Alerter { + alert?.pulseRightIcon(pulse) + + return this + } + + /** + * Set whether to show the right icon in the alert or not + * + * @param showRightIcon True to show the right icon, false otherwise + * @return This Alerter + */ + fun showRightIcon(showRightIcon: Boolean): Alerter { + alert?.showRightIcon(showRightIcon) + + return this + } + + /** + * Set whether to show the animation on focus/pressed states + * + * @param enabled True to show the animation, false otherwise + */ + fun enableClickAnimation(enabled: Boolean): Alerter { + alert?.enableClickAnimation(enabled) + + return this + } + /** * Enable or disable infinite duration of the alert * @@ -449,17 +595,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/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt b/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt index af8e900..5ffdca6 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/utils/ExAlert.kt @@ -1,13 +1,25 @@ package com.tapadoo.alerter.utils import android.app.Activity +import android.content.Context +import android.graphics.drawable.Drawable import android.os.Build +import android.util.TypedValue import androidx.annotation.DimenRes import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat import com.tapadoo.alerter.Alert +import com.tapadoo.alerter.R fun Alert.getDimenPixelSize(@DimenRes id: Int) = resources.getDimensionPixelSize(id) @RequiresApi(Build.VERSION_CODES.P) fun Alert.notchHeight() = (context as? Activity)?.window?.decorView?.rootWindowInsets?.displayCutout?.safeInsetTop - ?: 0 \ No newline at end of file + ?: 0 + +fun Context.getRippleDrawable(): Drawable? { + val typedValue = TypedValue() + theme.resolveAttribute(R.attr.selectableItemBackground, typedValue, true) + val imageResId = typedValue.resourceId + return ContextCompat.getDrawable(this, imageResId) +} \ No newline at end of file diff --git a/alerter/src/main/res/layout/alerter_alert_default_layout.xml b/alerter/src/main/res/layout/alerter_alert_default_layout.xml index 7993040..6590965 100644 --- a/alerter/src/main/res/layout/alerter_alert_default_layout.xml +++ b/alerter/src/main/res/layout/alerter_alert_default_layout.xml @@ -8,6 +8,7 @@ android:clipToPadding="false" tools:background="@android:color/darker_gray" tools:foreground="?android:attr/selectableItemBackground" + android:orientation="horizontal" tools:style="@style/AlertStyle"> @@ -75,4 +77,22 @@ tools:visibility="visible" /> + + + + + \ No newline at end of file diff --git a/alerter/src/main/res/values/dimens.xml b/alerter/src/main/res/values/dimens.xml index 8f2d307..e71a82e 100644 --- a/alerter/src/main/res/values/dimens.xml +++ b/alerter/src/main/res/values/dimens.xml @@ -8,7 +8,7 @@ 8dp 16dp 30dp - -28dp + -32dp 2dp 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..1bae7a8 100644 --- a/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java +++ b/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java @@ -1,7 +1,10 @@ package com.tapadoo.alerter.demo; +import android.graphics.Color; import android.graphics.Typeface; +import android.net.Uri; import android.os.Bundle; + import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -9,6 +12,7 @@ import android.view.View; import android.widget.Toast; +import com.tapadoo.alerter.Alert; import com.tapadoo.alerter.Alerter; import com.tapadoo.alerter.OnHideAlertListener; import com.tapadoo.alerter.OnShowAlertListener; @@ -71,13 +75,15 @@ public void onClick(View view) { showAlertWithProgress(); } else if (i == com.tapadoo.alerter.demo.R.id.btnAlertWithCustomFont) { showAlertWithCustomFont(); + } else if (i == com.tapadoo.alerter.demo.R.id.btnAlertWithCustomColor) { + showAlertWithCustomColor(); } else if (i == com.tapadoo.alerter.demo.R.id.btnAlertSwipeToDismissEnabled) { showAlertSwipeToDismissEnabled(); - } else if (i == com.tapadoo.alerter.demo.R.id.btnAlertSound){ + } else if (i == com.tapadoo.alerter.demo.R.id.btnAlertSound) { showAlertSound(); - }else if (i == com.tapadoo.alerter.demo.R.id.btnCenterAlert){ + } else if (i == com.tapadoo.alerter.demo.R.id.btnCenterAlert) { showAlertFromCenter(); - }else if (i == com.tapadoo.alerter.demo.R.id.btnBottomAlert){ + } else if (i == com.tapadoo.alerter.demo.R.id.btnBottomAlert) { showAlertFromBottom(); } else { showAlertDefault(); @@ -132,12 +138,12 @@ private void showAlertVerbose() { Alerter.create(JavaDemoActivity.this) .setTitle("Alert Title") .setText("The alert scales to accommodate larger bodies of text. " + - "The alert scales to accommodate larger bodies of text. " + - "The alert scales to accommodate larger bodies of text.") + "The alert scales to accommodate larger bodies of text. " + + "The alert scales to accommodate larger bodies of text.") .show(); } - private void showAlertCallbacks(){ + private void showAlertCallbacks() { Alerter.create(JavaDemoActivity.this) .setTitle("Alert Title") .setText("Alert text...") @@ -185,6 +191,15 @@ private void showAlertWithCustomFont() { .show(); } + private void showAlertWithCustomColor() { + Alert alert = Alerter.create(JavaDemoActivity.this) + .setTitle("Yellow Alert Title") + .setText("Red Alert text...") + .show(); + alert.getTitle().setTextColor(Color.YELLOW); + alert.getText().setTextColor(Color.RED); + } + private void showAlertSwipeToDismissEnabled() { Alerter.create(JavaDemoActivity.this) .setTitle("Alert Title") @@ -226,7 +241,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 e1fb475..224bd3b 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,14 @@ package com.tapadoo.alerter.demo +import android.graphics.Color 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 @@ -121,6 +123,15 @@ class KotlinDemoActivity : AppCompatActivity() { .show() } + private fun showAlertWithCustomColor() { + var alert = Alerter.create(this@KotlinDemoActivity) + .setTitle("Yellow Alert Title") + .setText("Red Alert text...") + .show() + alert?.getTitle()?.setTextColor(Color.YELLOW) + alert?.getText()?.setTextColor(Color.RED) + } + private fun showAlertSwipeToDismissEnabled() { Alerter.create(this@KotlinDemoActivity) .setTitle("Alert Title") @@ -159,7 +170,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() } @@ -173,7 +184,6 @@ class KotlinDemoActivity : AppCompatActivity() { .show() } - private fun showAlertFromCenter() { Alerter.create(this@KotlinDemoActivity) .setTitle(R.string.title_activity_example) @@ -191,6 +201,39 @@ class KotlinDemoActivity : AppCompatActivity() { .show() } + private fun showAlertWithRightIcon() { + Alerter.create(this@KotlinDemoActivity) + .setText("Alert text...") + .setIcon(R.drawable.alerter_ic_mail_outline) + .setIconColorFilter(0) // Optional - Removes white tint + .setIconSize(R.dimen.custom_icon_size) // Optional - default is 38dp + .setRightIcon(R.drawable.alerter_ic_face) + .showRightIcon(true) + .setRightIconSize(R.dimen.custom_icon_size) // Optional - default is 38dp + .show() + } + + private fun showAlertWithOnlyRightIcon() { + Alerter.create(this@KotlinDemoActivity) + .setText("Alert text...") + .showIcon(false) + .setRightIcon(R.drawable.alerter_ic_face) + .showRightIcon(true) + .show() + } + + private fun showAlertRightIconOnTop() { + Alerter.create(this) + .setText("The alert scales to accommodate larger bodies of text." + + "The alert scales to accommodate larger bodies of text. " + + "The alert scales to accommodate larger bodies of text.") + .showIcon(false) + .setRightIcon(R.drawable.alerter_ic_face) + .setRightIconPosition(Gravity.TOP) // Optional - default is center + .showRightIcon(true) + .show() + } + private fun setupOnClickListeners() { btnAlertDefault.setOnClickListener { showAlertDefault() @@ -232,6 +275,10 @@ class KotlinDemoActivity : AppCompatActivity() { showAlertWithCustomFont() } + btnAlertWithCustomColor.setOnClickListener { + showAlertWithCustomColor() + } + btnAlertSwipeToDismissEnabled.setOnClickListener { showAlertSwipeToDismissEnabled() } @@ -259,5 +306,17 @@ class KotlinDemoActivity : AppCompatActivity() { btnBottomAlert.setOnClickListener { showAlertFromBottom() } + + btnShowAlertWithRightIcon.setOnClickListener { + showAlertWithRightIcon() + } + + btnShowAlertWithOnlyRightIcon.setOnClickListener { + showAlertWithOnlyRightIcon() + } + + btnRightIconOnTop.setOnClickListener { + showAlertRightIconOnTop() + } } } diff --git a/app/src/main/res/layout/content_example.xml b/app/src/main/res/layout/content_example.xml index 0bc473d..a31c614 100644 --- a/app/src/main/res/layout/content_example.xml +++ b/app/src/main/res/layout/content_example.xml @@ -91,6 +91,13 @@ android:layout_height="wrap_content" android:text="@string/custom_font" /> + + - + + + + + \ No newline at end of file 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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index deaaaae..4a255d6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,7 @@ Infinity Duration Alert Progress Alert Custom Font + Custom Color Swipe To Dismiss Alert Custom Enter/Exit Animations With Buttons @@ -19,4 +20,7 @@ With Custom Layout Default Bottom Alert Default Center Alert + With Right Icon + With Only Right Icon + Right icon on top diff --git a/documentation/google-play-badge.png b/documentation/google-play-badge.png deleted file mode 100644 index c77b746..0000000 Binary files a/documentation/google-play-badge.png and /dev/null differ diff --git a/documentation/header.png b/documentation/header.png index 1b3e92e..950d146 100644 Binary files a/documentation/header.png and b/documentation/header.png differ diff --git a/play-store-assets/feature_image.png b/play-store-assets/feature_image.png index 1c5433e..8faa5be 100644 Binary files a/play-store-assets/feature_image.png and b/play-store-assets/feature_image.png differ diff --git a/play-store-assets/feature_image_large.png b/play-store-assets/feature_image_large.png index 6bcc248..6b7ab32 100644 Binary files a/play-store-assets/feature_image_large.png and b/play-store-assets/feature_image_large.png differ diff --git a/play-store-assets/feature_image_old.png b/play-store-assets/feature_image_old.png deleted file mode 100644 index ba4f5ab..0000000 Binary files a/play-store-assets/feature_image_old.png and /dev/null differ