71 lines
2.3 KiB
Kotlin
71 lines
2.3 KiB
Kotlin
package io.xdrm.lebonprix
|
|
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.os.Bundle
|
|
import android.os.Handler
|
|
import android.util.Log
|
|
import android.view.WindowManager
|
|
import io.xdrm.lebonprix.anim.BarChart
|
|
import io.xdrm.lebonprix.anim.ResultOpeningAnimation
|
|
import io.xdrm.lebonprix.anim.ResultRangeAnimation
|
|
import kotlinx.android.synthetic.main.activity_result.*
|
|
|
|
class ResultActivity : AppCompatActivity() {
|
|
|
|
private var results: Array<Int>? = arrayOf()
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
setContentView(R.layout.activity_result)
|
|
|
|
// show results form calling activity (intent)
|
|
results = intent?.extras?.getSerializable("prices") as Array<Int>
|
|
|
|
// show opening transition
|
|
val anim = ResultOpeningAnimation(applicationContext, filter)
|
|
anim.duration = 500
|
|
anim.start()
|
|
|
|
// show results after animation
|
|
Handler().postDelayed({
|
|
showResultRange(result_range.measuredWidth, result_range.measuredHeight)
|
|
showResultChart(result_chart.measuredWidth, result_chart.measuredHeight)
|
|
|
|
// bind on layout changes
|
|
result_range.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
|
|
showResultRange(right-left, bottom-top)
|
|
}
|
|
result_chart.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
|
|
showResultChart(right-left, bottom-top)
|
|
}
|
|
}, 300)
|
|
|
|
}
|
|
|
|
private fun showResultRange(width: Int, height: Int) {
|
|
if( results.isNullOrEmpty() )
|
|
return
|
|
|
|
// (1) slider range
|
|
val slider = ResultRangeAnimation(this, result_range, width, height)
|
|
slider.setData(results!!.size, results!!.min()!!.toFloat(), results!!.average().toFloat(), results!!.max()!!.toFloat())
|
|
slider.duration = 1000
|
|
slider.start()
|
|
|
|
}
|
|
|
|
private fun showResultChart(width: Int, height: Int){
|
|
if( results.isNullOrEmpty() )
|
|
return
|
|
|
|
// (1) bar chart
|
|
val chart = BarChart(results!!, width, height, applicationContext)
|
|
result_chart.setImageDrawable(chart)
|
|
|
|
|
|
|
|
}
|
|
}
|