Skip to content

Commit aa8fdf1

Browse files
committed
'Clean some code'
1 parent ebabf12 commit aa8fdf1

File tree

1 file changed

+20
-21
lines changed
  • app/src/main/java/com/example/lightweightalerter

1 file changed

+20
-21
lines changed

app/src/main/java/com/example/lightweightalerter/Alerter.kt

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.view.Window
1010
import android.view.WindowManager
1111
import android.view.animation.Animation
1212
import android.view.animation.AnimationUtils
13+
import android.view.animation.Interpolator
1314
import androidx.annotation.LayoutRes
1415
import androidx.appcompat.widget.AppCompatTextView
1516
import com.example.lightweightalerter.R
@@ -34,7 +35,6 @@ object Alerter {
3435
): Dialog {
3536
val dialog = Dialog(context)
3637
try {
37-
3838
dialog.inflateOnTop(
3939
when (alertLevel) {
4040
AlertLevel.SUCCESS -> R.layout.layout_top_success_message
@@ -61,8 +61,8 @@ object Alerter {
6161
}, 3000)
6262

6363
dialog.findViewById<View>(R.id.imgIcon).startBounceAnimation()
64-
} catch (e: Exception) {
65-
e.printStackTrace()
64+
} catch (throwable: Throwable) {
65+
throwable.printStackTrace()
6666
}
6767
return dialog
6868
}
@@ -76,13 +76,13 @@ object Alerter {
7676
this.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
7777
this.setCancelable(true)
7878

79-
val lp = WindowManager.LayoutParams()
80-
lp.copyFrom(this.window!!.attributes)
81-
lp.width = WindowManager.LayoutParams.MATCH_PARENT
82-
lp.height = WindowManager.LayoutParams.WRAP_CONTENT
83-
lp.gravity = Gravity.TOP
79+
val layoutParams = WindowManager.LayoutParams()
80+
layoutParams.copyFrom(this.window!!.attributes)
81+
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT
82+
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT
83+
layoutParams.gravity = Gravity.TOP
8484

85-
this.window!!.attributes = lp
85+
this.window!!.attributes = layoutParams
8686
return this
8787
}
8888

@@ -106,25 +106,24 @@ object Alerter {
106106
}
107107

108108
private fun View.startBounceAnimation() {
109-
val myAnim = AnimationUtils.loadAnimation(this.context, R.anim.bounce)
110-
val interpolator = MyBounceInterpolator(0.2, 20.0)
111-
myAnim.interpolator = interpolator
112-
this.startAnimation(myAnim)
109+
val anim = AnimationUtils.loadAnimation(this.context, R.anim.bounce)
110+
val interpolator = BounceInterpolator(0.2, 20.0)
111+
anim.interpolator = interpolator
112+
this.startAnimation(anim)
113113
}
114114

115-
internal class MyBounceInterpolator(amplitude: Double, frequency: Double) :
116-
android.view.animation.Interpolator {
117-
private var mAmplitude = 1.0
118-
private var mFrequency = 10.0
115+
internal class BounceInterpolator(amplitude: Double, frequency: Double) : Interpolator {
116+
private var amplitude = 1.0
117+
private var frequency = 10.0
119118

120119
init {
121-
mAmplitude = amplitude
122-
mFrequency = frequency
120+
this.amplitude = amplitude
121+
this.frequency = frequency
123122
}
124123

125124
override fun getInterpolation(time: Float): Float {
126-
return (-1.0 * Math.E.pow(-time / mAmplitude) *
127-
cos(mFrequency * time) + 1).toFloat()
125+
return (-1.0 * Math.E.pow(-time / amplitude) *
126+
cos(frequency * time) + 1).toFloat()
128127
}
129128
}
130129
}

0 commit comments

Comments
 (0)