diff --git a/app/src/main/java/com/bluecat/view404Demo/MainActivity.kt b/app/src/main/java/com/bluecat/view404Demo/MainActivity.kt
index 5460589..32ddbe1 100644
--- a/app/src/main/java/com/bluecat/view404Demo/MainActivity.kt
+++ b/app/src/main/java/com/bluecat/view404Demo/MainActivity.kt
@@ -33,16 +33,19 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
+
button2.setOnClickListener {
view404 = View404(this, R.layout.layout_404)
Toast.makeText(this, "shown", Toast.LENGTH_SHORT).show()
view404?.view404?.button?.setOnClickListener {
- view404?.dismiss()
+ //view404?.dismiss()
+ view404?.dismiss(R.anim.abc_fade_out)
Toast.makeText(this, "dismissed", Toast.LENGTH_SHORT).show()
}
- parentLayout.show404(view404!!)
+ //parentLayout.show404(view404!!)
+ parentLayout.show404(view404!!, R.anim.abc_fade_in)
}
}
}
diff --git a/view404/src/main/java/com/bluecat/view404/View404.kt b/view404/src/main/java/com/bluecat/view404/View404.kt
index 111d4d2..3931381 100644
--- a/view404/src/main/java/com/bluecat/view404/View404.kt
+++ b/view404/src/main/java/com/bluecat/view404/View404.kt
@@ -20,9 +20,10 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.view.animation.AnimationUtils
import androidx.core.view.ViewCompat
-class View404(context: Context, layout: Int) {
+class View404(private val context: Context, layout: Int) {
/** NoneNull type */
private var layoutInflater: LayoutInflater =
@@ -51,11 +52,12 @@ class View404(context: Context, layout: Int) {
}
}
- /** shows the view404 on the parent view. */
- fun show(parentView: ViewGroup?) {
+ /** shows the view404 on the parent view.
+ if you want to put another fadeIn animation, you can do that. */
+ fun show(parentView: ViewGroup?, fadeInAnimation:Int = R.anim.not_move_activity) {
if (!isShowing && parentView != null) {
this.parentView = parentView
-
+ view404.startAnimation(AnimationUtils.loadAnimation(context, fadeInAnimation))
/** 'run' refer to the context object as a lambda receiver by keyword 'this',
it returns the lambda result. */
this.parentView?.run {
@@ -64,14 +66,17 @@ class View404(context: Context, layout: Int) {
requestLayout()
invalidate()
}
+
ViewCompat.setTranslationZ(view404, 99f)
isShowing = true
}
}
- /** dismiss the view404 on the parent view. */
- fun dismiss() {
+ /** dismiss the view404 on the parent view.
+ if you want to put another fadeOut animation, you can do that. */
+ fun dismiss(fadeOutAnimation:Int = R.anim.not_move_activity) {
if (isShowing) {
+ view404.startAnimation(AnimationUtils.loadAnimation(context, fadeOutAnimation))
parentView?.removeView(view404)
isShowing = false
}
diff --git a/view404/src/main/java/com/bluecat/view404/View404Extensions.kt b/view404/src/main/java/com/bluecat/view404/View404Extensions.kt
index 0483d1d..649b433 100644
--- a/view404/src/main/java/com/bluecat/view404/View404Extensions.kt
+++ b/view404/src/main/java/com/bluecat/view404/View404Extensions.kt
@@ -18,6 +18,6 @@ package com.bluecat.view404
import android.view.ViewGroup
-fun ViewGroup.show404(view404: View404) {
- view404.show(this)
+fun ViewGroup.show404(view404: View404, fadeInAnimation:Int = R.anim.not_move_activity) {
+ view404.show(this, fadeInAnimation)
}
diff --git a/view404/src/main/res/anim/abc_fade_in.xml b/view404/src/main/res/anim/abc_fade_in.xml
new file mode 100644
index 0000000..362fdb7
--- /dev/null
+++ b/view404/src/main/res/anim/abc_fade_in.xml
@@ -0,0 +1,17 @@
+
+
+
+
\ No newline at end of file
diff --git a/view404/src/main/res/anim/abc_fade_out.xml b/view404/src/main/res/anim/abc_fade_out.xml
new file mode 100644
index 0000000..eb63b70
--- /dev/null
+++ b/view404/src/main/res/anim/abc_fade_out.xml
@@ -0,0 +1,17 @@
+
+
+
+
\ No newline at end of file
diff --git a/view404/src/main/res/anim/not_move_activity.xml b/view404/src/main/res/anim/not_move_activity.xml
new file mode 100644
index 0000000..7ab9a6a
--- /dev/null
+++ b/view404/src/main/res/anim/not_move_activity.xml
@@ -0,0 +1,4 @@
+
+
+
+