Home Fragment theme 1:
PressableImageView class setup icons setup: made dynamic with screen size changes tv view moving tv view other ui: more button, woka fm, user details
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
package com.woka.home
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.renderscript.Allocation
|
||||
import android.renderscript.Element
|
||||
import android.renderscript.RenderScript
|
||||
import android.renderscript.ScriptIntrinsicBlur
|
||||
|
||||
class BlurBackground {
|
||||
companion object {
|
||||
private const val BITMAP_SCALE = 0.4f
|
||||
private const val BLUR_RADIUS = 7.5f
|
||||
|
||||
fun blur(context: Context, image: Bitmap): Bitmap {
|
||||
val width = (image.width * BITMAP_SCALE).toInt()
|
||||
val height = (image.height * BITMAP_SCALE).toInt()
|
||||
|
||||
val inputBitmap = Bitmap.createScaledBitmap(image, width, height, false)
|
||||
val outputBitmap = Bitmap.createBitmap(inputBitmap)
|
||||
|
||||
val rs = RenderScript.create(context)
|
||||
val script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs))
|
||||
val tmpIn = Allocation.createFromBitmap(rs, inputBitmap)
|
||||
val tmpOut = Allocation.createFromBitmap(rs, outputBitmap)
|
||||
|
||||
script.setRadius(BLUR_RADIUS)
|
||||
script.setInput(tmpIn)
|
||||
script.forEach(tmpOut)
|
||||
tmpOut.copyTo(outputBitmap)
|
||||
|
||||
return outputBitmap
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/src/main/java/com/woka/home/PressableImageView.kt
Normal file
56
app/src/main/java/com/woka/home/PressableImageView.kt
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.woka.home
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
|
||||
class PressableImageView : AppCompatImageView {
|
||||
constructor(context: Context?) : super(context!!)
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(
|
||||
context!!, attrs
|
||||
)
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
|
||||
context!!, attrs, defStyle
|
||||
)
|
||||
|
||||
private fun refresh() {
|
||||
if (isPressed) {
|
||||
setAlpha(DEFAULT_ALPHA_WHEN_PRESS)
|
||||
invalidate()
|
||||
return
|
||||
}
|
||||
setAlpha(DEFAULT_ALPHA)
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun setPressed(pressed: Boolean) {
|
||||
super.setPressed(pressed)
|
||||
refresh()
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
setPressed(true)
|
||||
} else if (event.action == MotionEvent.ACTION_UP) {
|
||||
setPressed(false)
|
||||
val x = event.x
|
||||
val y = event.y
|
||||
val isInside = x > 0 && x < width && y > 0 && y < height
|
||||
if (isInside) {
|
||||
performClick()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun performClick(): Boolean {
|
||||
return super.performClick()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DEFAULT_ALPHA_WHEN_PRESS = 0.5f
|
||||
private const val DEFAULT_ALPHA = 1f
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.woka.home.fragments
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_TIME_TICK
|
||||
import android.content.IntentFilter
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -44,6 +47,8 @@ class Home1Fragment : Fragment() {
|
||||
private var currentBackground: TimePeriod? = null
|
||||
private var minuteReceiver: BroadcastReceiver? = null
|
||||
|
||||
private var valueAnimator: ValueAnimator? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -55,15 +60,47 @@ class Home1Fragment : Fragment() {
|
||||
minuteReceiver = object : BroadcastReceiver(){
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// this function is called every minute
|
||||
updateBackground()
|
||||
if (intent?.action == ACTION_TIME_TICK){
|
||||
updateBackground()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activity?.registerReceiver(minuteReceiver, IntentFilter(ACTION_TIME_TICK))
|
||||
|
||||
clickEvents()
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (valueAnimator == null) {
|
||||
binding.tvView.post {
|
||||
val endMargin: Float = 25f * (resources.displayMetrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)
|
||||
valueAnimator = ObjectAnimator.ofFloat(binding.tvView, "translationX", resources.displayMetrics.widthPixels - binding.tvView.width - (2 * endMargin)).apply {
|
||||
duration = 12000
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
repeatMode = ValueAnimator.REVERSE
|
||||
start()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
valueAnimator?.resume()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
valueAnimator?.pause()
|
||||
}
|
||||
|
||||
private fun clickEvents() {
|
||||
binding.apply {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
activity?.unregisterReceiver(minuteReceiver)
|
||||
@@ -89,6 +126,10 @@ class Home1Fragment : Fragment() {
|
||||
ContextCompat.getDrawable(it, R.drawable.evening_bg)
|
||||
}
|
||||
TimePeriod.NIGHT -> {
|
||||
// text colors
|
||||
binding.userName.setTextColor(ContextCompat.getColor(it, R.color.white))
|
||||
binding.welcomeText.setTextColor(ContextCompat.getColor(it, R.color.white))
|
||||
|
||||
it.window.statusBarColor = ContextCompat.getColor(it, R.color.night_status)
|
||||
ContextCompat.getDrawable(it, R.drawable.night_bg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user