Skip to content

Commit

Permalink
Merge pull request #15 from hpratsch/feature/customizability
Browse files Browse the repository at this point in the history
Customize Toast Colors #12
  • Loading branch information
Spikeysanju authored Sep 25, 2020
2 parents 054371c + 7789fe4 commit 8c850fd
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 49 additions & 21 deletions app/src/main/java/www/sanju/motiontoast/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package www.sanju.motiontoast

import android.os.Bundle
import android.view.View
import android.widget.CompoundButton
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClickListener {
class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClickListener,
CompoundButton.OnCheckedChangeListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

switch_custom_colors?.setOnCheckedChangeListener(this)
successBtn.setOnClickListener(this)
errorBtn.setOnClickListener(this)
warningBtn.setOnClickListener(this)
Expand All @@ -26,49 +28,72 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClick
infoBtn.setOnLongClickListener(this)
deleteBtn.setOnLongClickListener(this)
noInternetBtn.setOnLongClickListener(this)
}


private fun setToastColors(newColorsEnabled: Boolean) {
if (newColorsEnabled) {
MotionToast.setSuccessColor(R.color.custom_success_color)
MotionToast.setErrorColor(R.color.custom_error_color)
MotionToast.setDeleteColor(R.color.custom_delete_color)
MotionToast.setWarningColor(R.color.custom_warning_color)
MotionToast.setInfoColor(R.color.custom_info_color)
MotionToast.setSuccessBackgroundColor(R.color.success_bg_color)
MotionToast.setErrorBackgroundColor(R.color.error_bg_color)
MotionToast.setDeleteBackgroundColor(R.color.delete_bg_color)
MotionToast.setWarningBackgroundColor(R.color.warning_bg_color)
MotionToast.setInfoBackgroundColor(R.color.info_bg_color)
} else {
MotionToast.resetToastColors()
}
}

override fun onClick(v: View?) {
when (v!!.id) {
R.id.successBtn -> {
MotionToast.createToast(this,"Profile Completed!",
MotionToast.TOAST_SUCCESS,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this,R.font.helvetica_regular))

MotionToast.createToast(
this, "Profile Completed!",
MotionToast.TOAST_SUCCESS,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this, R.font.helvetica_regular)
)
}
R.id.errorBtn -> {
MotionToast.createToast(this,"Profile Update Failed!",
MotionToast.createToast(
this, "Profile Update Failed!",
MotionToast.TOAST_ERROR,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this,R.font.helvetica_regular)) }
R.id.warningBtn ->{
ResourcesCompat.getFont(this, R.font.helvetica_regular)
)
}
R.id.warningBtn -> {

MotionToast.createToast(this,"Please Fill All The Details!",
MotionToast.createToast(
this, "Please Fill All The Details!",
MotionToast.TOAST_WARNING,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this,R.font.helvetica_regular))
ResourcesCompat.getFont(this, R.font.helvetica_regular)
)
}
R.id.infoBtn ->{

R.id.infoBtn -> {
MotionToast.createColorToast(
this, "Color Toast testing here!",
MotionToast.TOAST_INFO,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this,R.font.helvetica_regular))
ResourcesCompat.getFont(this, R.font.helvetica_regular)
)
}
R.id.deleteBtn ->{
MotionToast.createToast(this,"Profile Deleted!",
R.id.deleteBtn -> {
MotionToast.createToast(
this, "Profile Deleted!",
MotionToast.TOAST_DELETE,
MotionToast.GRAVITY_BOTTOM,
MotionToast.LONG_DURATION,
ResourcesCompat.getFont(this,R.font.helvetica_regular))
ResourcesCompat.getFont(this, R.font.helvetica_regular)
)
}
R.id.noInternetBtn -> {
MotionToast.createToast(
Expand All @@ -84,7 +109,6 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClick
}

override fun onLongClick(v: View?): Boolean {

when (v!!.id) {
R.id.successBtn -> {
MotionToast.darkToast(
Expand Down Expand Up @@ -146,4 +170,8 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClick

return true
}

override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
setToastColors(isChecked)
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
android:layout_centerInParent="true"
android:orientation="vertical">

<Switch
android:id="@+id/switch_custom_colors"
android:layout_width="200dp"
android:text="Custom toast colors"
android:layout_height="wrap_content" />

<Button
android:id="@+id/successBtn"
android:layout_width="200dp"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'

Expand Down
Loading

0 comments on commit 8c850fd

Please sign in to comment.