Skip to content

Commit

Permalink
Radius of dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
shazainali committed Feb 19, 2020
1 parent f4a97af commit 9350477
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SDialog.Builder(this)
.setMessageTextSize(14F)
.setImage(R.drawable.cross) //optional
.setImageTint(Color.CYAN)
.setRadius(10F)
.build()
```
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/example/dialog/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MainActivity : AppCompatActivity() {
.setMessageTextSize(14F)
.setImage(R.drawable.cross) //optional
.setImageTint(Color.CYAN)
.setRadius(10F)
.build()
}

Expand Down
56 changes: 41 additions & 15 deletions sdialog/src/main/java/com/shahzainali/sdialog/SDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class SDialog(
messageTextSize: Float,
titleTextSize: Float,
titleTypeface: Typeface?,
messageTypeface: Typeface?
messageTypeface: Typeface?,
sDialogRadius: Float
) {


Expand All @@ -52,7 +53,8 @@ class SDialog(
private var messageTextSize: Float = 14F,
private var titleTextSize: Float = 18F,
private var titleTypeface: Typeface? = null,
private var messageTypeface: Typeface? = null
private var messageTypeface: Typeface? = null,
private var sDialogRadius: Float = 15F

) {
fun setTitle(title: String) = apply { this.title = title }
Expand All @@ -65,11 +67,35 @@ class SDialog(
fun setMessageColor(descriptionColor: Int) = apply { this.messageColor = descriptionColor }
fun setImage(image: Int?) = apply { this.image = image }
fun setImageTint(imageTint: Int) = apply { this.imageTint = imageTint }
fun setMessageTextSize(messageTextSize: Float) = apply { this.messageTextSize = messageTextSize}
fun setTitleTextSize(titleTextSize: Float) = apply { this.titleTextSize = titleTextSize}
fun setTitleTypeface(titleTypeface: Typeface?)= apply { this.titleTypeface = titleTypeface }
fun setMessageTypeface(messageTypeface: Typeface?)= apply { this.messageTypeface = messageTypeface }
fun build() = SDialog(context, title, message, duration, speed, isCancellable, backColor, titleColor, messageColor, image, imageTint, messageTextSize, titleTextSize, titleTypeface, messageTypeface)
fun setMessageTextSize(messageTextSize: Float) =
apply { this.messageTextSize = messageTextSize }

fun setTitleTextSize(titleTextSize: Float) = apply { this.titleTextSize = titleTextSize }
fun setTitleTypeface(titleTypeface: Typeface?) =
apply { this.titleTypeface = titleTypeface }

fun setMessageTypeface(messageTypeface: Typeface?) =
apply { this.messageTypeface = messageTypeface }

fun setRadius(sDialogRadius: Float) = apply { this.sDialogRadius = sDialogRadius }
fun build() = SDialog(
context,
title,
message,
duration,
speed,
isCancellable,
backColor,
titleColor,
messageColor,
image,
imageTint,
messageTextSize,
titleTextSize,
titleTypeface,
messageTypeface,
sDialogRadius
)

}

Expand Down Expand Up @@ -113,7 +139,7 @@ class SDialog(
dialog.image.setColorFilter(imageTint)
}

ddd.background = generateDrawable(backColor)
ddd.background = generateDrawable(backColor, sDialogRadius)
dialog.show()


Expand All @@ -127,15 +153,15 @@ class SDialog(
}

open fun setFont(typeface: Typeface, textView: TextView) {
// val typeface = Typeface.createFromAsset(assets, font)
// val typeface = Typeface.createFromAsset(assets, font)
textView.typeface = typeface
}

private fun animator(
dialog: Dialog,
dialogLayout: RelativeLayout,
speed: Long,
isReverse: Boolean
dialog: Dialog,
dialogLayout: RelativeLayout,
speed: Long,
isReverse: Boolean
) {
var valueAnimator: ValueAnimator = if (!isReverse)
ValueAnimator.ofFloat(-360f, 0f)
Expand Down Expand Up @@ -170,10 +196,10 @@ class SDialog(
})
}

private fun generateDrawable(backColor: Int): GradientDrawable {
private fun generateDrawable(backColor: Int, radius: Float): GradientDrawable {
val gd = GradientDrawable()
gd.setColor(backColor)
gd.cornerRadius = 15f
gd.cornerRadius = radius
return gd
}

Expand Down

0 comments on commit 9350477

Please sign in to comment.