Skip to content

Commit

Permalink
Merge pull request #273 from anderscheow/master
Browse files Browse the repository at this point in the history
Add support for elevation
  • Loading branch information
kpmmmurphy authored Aug 12, 2021
2 parents 53330d5 + 71aec16 commit 719cbd3
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## 7.2.3 - 12/08/2021
* Added ability to set background elevation

## 7.2.2 - 09/08/2021
* bugfix notchHeight() cast

Expand Down
2 changes: 1 addition & 1 deletion alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply from: rootProject.file('quality.gradle')

final String GROUP_ID = "com.tapadoo.android"

final String VERSION = "7.2.2"
final String VERSION = "7.2.3"

final String DESCRIPTION = "An Android Alerting Library"
final String GITHUB_URL = "https://github.com/Tapadoo/Alerter"
Expand Down
12 changes: 12 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,18 @@ class Alert @JvmOverloads constructor(context: Context,
this.soundUri = soundUri
}

/**
* Set elevation of the alert background.
*
* Only available for version LOLLIPOP and above.
*
* @param elevation Elevation value, in pixel.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun setBackgroundElevation(elevation: Float) {
llAlertBackground.elevation = elevation
}

/**
* Show a button with the given text, and on click listener
*
Expand Down
15 changes: 15 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
import android.os.Looper
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -703,6 +704,20 @@ class Alerter private constructor() {
return this
}

/**
* Set elevation of the alert background.
*
* Only available for version LOLLIPOP and above.
*
* @param elevation Elevation value, in pixel.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun setElevation(elevation: Float): Alerter {
alert?.setBackgroundElevation(elevation)

return this
}

fun getLayoutContainer(): View? {
return alert?.layoutContainer
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/tapadoo/alerter/demo/KotlinDemoActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.tapadoo.alerter.demo
import android.graphics.Color
import android.graphics.Typeface
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.Gravity
import android.view.View
Expand Down Expand Up @@ -40,6 +41,16 @@ class KotlinDemoActivity : AppCompatActivity() {
.show()
}

private fun showAlertDefaultWithElevation() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Alerter.create(this@KotlinDemoActivity)
.setTitle(R.string.title_activity_example)
.setText("Alert text...")
.setElevation(30f)
.show()
}
}

private fun showAlertColoured() {
Alerter.create(this@KotlinDemoActivity)
.setTitle("Alert Title")
Expand Down Expand Up @@ -239,6 +250,10 @@ class KotlinDemoActivity : AppCompatActivity() {
showAlertDefault()
}

btnAlertDefaultWithElevation.setOnClickListener {
showAlertDefaultWithElevation()
}

btnAlertColoured.setOnClickListener {
showAlertColoured()
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/content_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
android:text="@string/default_alert"
android:textColor="@android:color/white" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnAlertDefaultWithElevation"
style="@style/ExampleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_alert_with_elevation"
android:textColor="@android:color/white" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btnAlertColoured"
style="@style/ExampleButton"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<string name="app_name">Alerter</string>
<string name="title_activity_example">Alerter Demo</string>
<string name="default_alert">Default Alert</string>
<string name="default_alert_with_elevation">Default Alert With Elevation</string>
<string name="coloured_alert">Coloured Alert</string>
<string name="text_only_alert">Text Only Alert</string>
<string name="on_click_alert">On Click Alert</string>
Expand Down

0 comments on commit 719cbd3

Please sign in to comment.