Skip to content

Commit

Permalink
Merge pull request #210 from bilgehankalkan/feature/right-icon
Browse files Browse the repository at this point in the history
Right Icon
  • Loading branch information
kpmmmurphy committed Feb 16, 2020
2 parents d7f28e3 + 68a849c commit dc2e6c4
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 11 deletions.
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.

## 5.1.2 - 16/02/2020
* Added support for rightIcon.

## 5.1.1 - 28/01/2020
* Minor refactoring

Expand Down
2 changes: 1 addition & 1 deletion alerter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "5.1.2"

final String DESCRIPTION = "An Android Alerting Library"
final String GITHUB_URL = "https://github.com/Tapadoo/Alerter"
Expand Down
143 changes: 136 additions & 7 deletions alerter/src/main/java/com/tapadoo/alerter/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Alert @JvmOverloads constructor(context: Context,
private var enableInfiniteDuration: Boolean = false
private var enableProgress: Boolean = false

private var showRightIcon: Boolean = false
private var enableRightIconPurse = true

private var runningAnimation: Runnable? = null

private var isDismissible = true
Expand Down Expand Up @@ -229,15 +232,27 @@ class Alert @JvmOverloads constructor(context: Context,

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
}
}
}
}
Expand Down Expand Up @@ -526,6 +541,111 @@ 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 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
*
Expand Down Expand Up @@ -573,6 +693,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
*
Expand Down
133 changes: 133 additions & 0 deletions alerter/src/main/java/com/tapadoo/alerter/Alerter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,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
*
Expand Down Expand Up @@ -389,6 +498,30 @@ 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
}

/**
* Enable or disable infinite duration of the alert
*
Expand Down
22 changes: 21 additions & 1 deletion alerter/src/main/res/layout/alerter_alert_default_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<FrameLayout
Expand Down Expand Up @@ -39,7 +40,8 @@
</FrameLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
Expand Down Expand Up @@ -75,4 +77,22 @@
tools:visibility="visible" />

</LinearLayout>

<FrameLayout
android:id="@+id/flRightIconContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ivRightIcon"
android:layout_width="@dimen/alerter_alert_icn_size"
android:layout_height="@dimen/alerter_alert_icn_size"
android:maxWidth="@dimen/alerter_alert_icn_size"
android:maxHeight="@dimen/alerter_alert_icn_size"
android:visibility="gone"
app:srcCompat="@drawable/alerter_ic_notifications"
app:tint="@color/alert_default_icon_color"
tools:visibility="visible" />
</FrameLayout>
</LinearLayout>
Loading

0 comments on commit dc2e6c4

Please sign in to comment.