From f8ed0b3d871240e75e3439eb85d88a51e005e200 Mon Sep 17 00:00:00 2001 From: dosomder Date: Sat, 27 Jun 2020 13:49:55 +0200 Subject: [PATCH 1/2] Add getters for TextView Allows to change TextView properties dynamically. Fixes #228 --- .../main/java/com/tapadoo/alerter/Alert.kt | 23 ++++++++++++--- .../alerter/demo/JavaDemoActivity.java | 28 ++++++++++++++----- .../alerter/demo/KotlinDemoActivity.kt | 14 ++++++++++ app/src/main/res/layout/content_example.xml | 7 +++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt index cad2353..9cbb80d 100644 --- a/alerter/src/main/java/com/tapadoo/alerter/Alert.kt +++ b/alerter/src/main/java/com/tapadoo/alerter/Alert.kt @@ -17,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 @@ -77,7 +78,7 @@ class Alert @JvmOverloads constructor(context: Context, /** * Uri to set sound */ - private var soundUri : Uri? = null + private var soundUri: Uri? = null /** * Sets the Layout Gravity of the Alert @@ -632,9 +633,9 @@ class Alert @JvmOverloads constructor(context: Context, */ fun setRightIconPosition(position: Int) { if (position == Gravity.TOP - || position == Gravity.CENTER - || position == Gravity.CENTER_VERTICAL - || position == Gravity.BOTTOM) { + || position == Gravity.CENTER + || position == Gravity.CENTER_VERTICAL + || position == Gravity.BOTTOM) { flRightIconContainer.layoutParams = (flRightIconContainer.layoutParams as LinearLayout.LayoutParams).apply { gravity = position } @@ -780,6 +781,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/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java b/app/src/main/java/com/tapadoo/alerter/demo/JavaDemoActivity.java index c74ae4a..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,8 +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; @@ -10,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; @@ -72,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(); @@ -133,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...") @@ -186,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") @@ -227,7 +241,7 @@ private void showAlertSound() { .setTitle("Alert Title") .setText("Alert text...") .setBackgroundColorRes(R.color.colorAccent) - .setSound(Uri.parse("android.resource://"+getPackageName()+"/raw/ringtone")) + .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 b8dccfa..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,5 +1,6 @@ package com.tapadoo.alerter.demo +import android.graphics.Color import android.graphics.Typeface import android.net.Uri import android.os.Bundle @@ -122,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") @@ -265,6 +275,10 @@ class KotlinDemoActivity : AppCompatActivity() { showAlertWithCustomFont() } + btnAlertWithCustomColor.setOnClickListener { + showAlertWithCustomColor() + } + btnAlertSwipeToDismissEnabled.setOnClickListener { showAlertSwipeToDismissEnabled() } diff --git a/app/src/main/res/layout/content_example.xml b/app/src/main/res/layout/content_example.xml index 3518d62..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" /> + + Infinity Duration Alert Progress Alert Custom Font + Custom Color Swipe To Dismiss Alert Custom Enter/Exit Animations With Buttons From eea096cc3c9dd3d161a4e497209635211bcfc87a Mon Sep 17 00:00:00 2001 From: dosomder Date: Sat, 27 Jun 2020 13:52:36 +0200 Subject: [PATCH 2/2] Update to 6.1.0 --- CHANGELOG.md | 3 +++ alerter/build.gradle | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f777737..03af90a 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.1.0 - 27/06/2020 +* Readded getters for title & text TextView + ## 6.0.0 - 27/06/2020 * Support custom sound diff --git a/alerter/build.gradle b/alerter/build.gradle index c7e3977..430be2a 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 = "6.0.0" +final String VERSION = "6.1.0" final String DESCRIPTION = "An Android Alerting Library" final String GITHUB_URL = "https://github.com/Tapadoo/Alerter"