Skip to content

Commit

Permalink
drawable function added, example code changes and update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kishandonga committed Feb 21, 2019
1 parent 59b2c5c commit 64618e7
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 18 deletions.
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Android custom snackbar is derived from the android default snackbar control
- Custom view applies in the snackbar control
- Typeface applies easily on text
- Corner radius and Padding applies
- Androidx support
- Androidx supported
- More to find out yourself

## Installation
Expand All @@ -23,7 +23,7 @@ dependencies {
implementation 'com.github.kishandonga:custom-snackbar:1.0'
}
//required support lib modules
//required lib modules
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha03'
```
Expand Down Expand Up @@ -96,35 +96,56 @@ CustomSnackbar(this).show {
```java
```

#### With Drawable

Kotlin
```kotlin
CustomSnackbar(this).show {
drawableRes(R.drawable.ic_gradient)
...
}
```

```java
```

## API Documents

|Function |Parameter |Description |
|:-------------------:|:-------------------:|:-------------------:|
|actionTextColor | Integer Color Value | Change the action button text color, default value is colorAccent
|actionTextColorRes | Color Resource | Change the action button text color, default value is colorAccent
|actionTextColorRes | Color Resource | Refer actionTextColor function description
|textColor | Integer Color Value | Change the message text color, default value is white color
|textColorRes | Color Resource | Change the message text color, default value is white color
|textColorRes | Color Resource | Refer textColor function description
|backgroundColor | Integer Color Value | Change the background color of the snackbar, default value is same as snackbar background also you can't make it transparent
|backgroundColorRes | Color Resource | Change the background color of the snackbar, default value is same as snackbar background also you can't make it transparent
|backgroundColorRes | Color Resource | Refer backgroundColor function description
|cornerRadius | Float Value | Apply corner radius all the side (Left, Top, Right, Bottom), default value is 0
|cornerRadiusRes | Dimension Resource | Apply corner radius all the side (Left, Top, Right, Bottom), default value is 0
|cornerRadiusRes | Dimension Resource | Refer cornerRadius function description
|border | Width as Integer and Integer Color Value | Apply border width and color around the snackbar, default value of the width is 0 and color is transparent
|borderRes | Width as Dimension Resource and Color Resource | Apply border width and color around the snackbar, default value of the width is 0 and color is transparent
|customView | View or Layout Resource | set the your customized view as snackbar, default value is null view
|borderRes | Width as Dimension Resource and Color Resource | Refer border function description
|customView | View or Layout Resource | set the your customized view as snackbar, default value is null also when you apply custom view then other api are not in use as shown in the example code
|message | String | set the message as string and default value is empty string
|messageRes | String Resource | set the message as string and default value is empty string
|messageRes | String Resource | Refer message function description
|duration | Integer Value | set the time duration default value is Snackbar.LENGTH_SHORT
|padding | Integer Value | apply the padding at the (Left, Right, Bottom) side, default value is 0
|paddingRes | Dimension Resource | apply the padding at the (Left, Right, Bottom) side, default value is 0
|paddingRes | Dimension Resource | Refer padding function description
|textTypeface | Typeface | Change the message text Typeface, default value is Typeface.NORMAL
|actionTypeface | Typeface | Change the action button text Typeface, default value is Typeface.NORMAL
|withAction | String Resource or String and Snackbar as anonymous function | pass the first argument as action button name and default value is empty string, second argument as lamda function with snackbar reference
|withCustomView | View as anonymous function | when custom view initialze then passing here for your further use
|drawable | GradientDrawable | set the gradient drawable as snackbar background, default value is null also when you apply drawable then background color, cornerRadius, border width and color api are not in use as shown in the example code
|drawableRes | Drawable Resource| Refer drawable function description
|show | Void Or Koltin DSL | Show the snackbar view
|dismiss | Void Or Unit | Dismiss the snackbar view
|getView | Void and return View? | Same as withCustomView but it will return null value too


### About me

Kishan Donga ([@ikishan92](https://twitter.com/ikishan92))
I am mobility developer.





2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".ui.DrawableAct">
</activity>
<activity android:name=".ui.CustomViewAct">
</activity>
<activity android:name=".ui.SimpleAct">
Expand Down
107 changes: 107 additions & 0 deletions app/src/main/java/com/example/custom_snackbar/ui/DrawableAct.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.example.custom_snackbar.ui

import android.content.DialogInterface
import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.example.custom_snackbar.R
import com.example.custom_snackbar.utils.themeConst
import com.google.android.material.snackbar.Snackbar
import com.kishandonga.csbx.CustomSnackbar
import com.skydoves.colorpickerview.ColorPickerDialog
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
import kotlinx.android.synthetic.main.activity_drawable.*

class DrawableAct : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val themeConst = intent.getIntExtra(themeConst, 0)
setTheme(if (themeConst == 0) R.style.AppCompat_ActionBar else R.style.Material_ActionBar)

setContentView(R.layout.activity_drawable)
title = "Custom Drawable"

var textColor = Color.WHITE
var actionTxtColor = ContextCompat.getColor(this, R.color.colorAccent)

btnActionTextColor.setOnClickListener {
ColorPickerDialog.Builder(this)
.setTitle("ColorPicker Dialog")
.setPositiveButton(getString(android.R.string.ok), ColorEnvelopeListener { envelope, _ ->
llActionTextColor.setBackgroundColor(envelope.color)
actionTxtColor = envelope.color
})
.setNegativeButton(getString(android.R.string.cancel)) { di: DialogInterface, _: Int ->
di.cancel()
}
.show()
}

btnTextColor.setOnClickListener {
ColorPickerDialog.Builder(this)
.setTitle("ColorPicker Dialog")
.setPositiveButton(getString(android.R.string.ok), ColorEnvelopeListener { envelope, _ ->
llTextColor.setBackgroundColor(envelope.color)
textColor = envelope.color
})
.setNegativeButton(getString(android.R.string.cancel)) { di: DialogInterface, _: Int ->
di.cancel()
}
.show()
}

sbPadding.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar?, p1: Int, p2: Boolean) {
tvPaddingIndicator.text = p0?.progress.toString()
}

override fun onStartTrackingTouch(p0: SeekBar?) {
}

override fun onStopTrackingTouch(p0: SeekBar?) {
}
})

var snackbar: CustomSnackbar? = null

btnShow.setOnClickListener {

val timeDuration: Int = when {
rbLengthIndefinite.isChecked -> Snackbar.LENGTH_INDEFINITE
rbLengthLong.isChecked -> Snackbar.LENGTH_LONG
else -> Snackbar.LENGTH_SHORT
}

val typeface: Typeface = when {
rbBold.isChecked -> Typeface.defaultFromStyle(Typeface.BOLD)
rbBoldItalic.isChecked -> Typeface.defaultFromStyle(Typeface.BOLD_ITALIC)
rbItalic.isChecked -> Typeface.defaultFromStyle(Typeface.ITALIC)
else -> Typeface.defaultFromStyle(Typeface.NORMAL)
}

snackbar = CustomSnackbar(this).show {
drawableRes(R.drawable.ic_gradient)
textColor(textColor)
actionTextColor(actionTxtColor)
textTypeface(typeface)
actionTypeface(typeface)
padding(sbPadding.progress)
duration(timeDuration)
message("Testing Message...")
if (rbWithAction.isChecked) {
withAction(android.R.string.ok) {
it.dismiss()
}
}
}
}

btnHide.setOnClickListener {
snackbar?.dismiss()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class MainActivity : AppCompatActivity() {
btnCustomView.setOnClickListener {
startNewActivity(CustomViewAct::class.java)
}

btnDrawableAct.setOnClickListener {
startNewActivity(DrawableAct::class.java)
}
}

private fun startNewActivity(cls: Class<*>) {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/ic_gradient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

<gradient
android:angle="45"
android:centerColor="#C8C8B0"
android:endColor="#FADC96"
android:startColor="#67B2CF"
android:type="linear"/>

<corners
android:radius="8dp"/>

</shape>
Loading

0 comments on commit 64618e7

Please sign in to comment.