From 8731fa285386886a98fc5dcb9ca9d1a264ed4f13 Mon Sep 17 00:00:00 2001 From: JIWON1923 Date: Sat, 22 Apr 2023 04:00:57 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20player=20=EA=B7=B8=EB=9D=BC=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/soi/moya/PlaySongActivity.kt | 49 ++++++++++++++++ .../main/res/layout/activity_play_song.xml | 57 +++++++++++++++---- 2 files changed, 94 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/soi/moya/PlaySongActivity.kt b/app/src/main/java/com/soi/moya/PlaySongActivity.kt index 717c419..5e29f83 100644 --- a/app/src/main/java/com/soi/moya/PlaySongActivity.kt +++ b/app/src/main/java/com/soi/moya/PlaySongActivity.kt @@ -2,10 +2,16 @@ package com.soi.moya import android.annotation.SuppressLint import android.content.Context +import android.graphics.Color +import android.graphics.LinearGradient +import android.graphics.Shader +import android.graphics.drawable.GradientDrawable import android.media.MediaPlayer import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.view.View import androidx.core.content.ContextCompat +import androidx.core.graphics.ColorUtils import androidx.databinding.DataBindingUtil import com.soi.moya.databinding.ActivityPlaySongBinding @@ -39,6 +45,34 @@ class PlaySongActivity : AppCompatActivity() { binding.playSongButton.setOnClickListener { onTappedPlayButton() } + + // scoll 위치에 따른 gradient + binding.scrollView.viewTreeObserver.addOnGlobalLayoutListener { + val scrollView = binding.scrollView + val scrollViewHeight = scrollView.height + val contentHeight = binding.songLyricLayout.height + + if (binding.songLyric.height <= scrollViewHeight) { + // 스크롤뷰의 높이보다 TextView가 작을 때 + binding.scrollTopOfGradientView.visibility = View.GONE + binding.scrollBottomOfGradientView.visibility = View.GONE + } else { + // 스크롤뷰의 높이보다 TextView가 클 때 + scrollView.viewTreeObserver.addOnScrollChangedListener { + val scrollY = scrollView.scrollY + if (scrollY == 0) { + binding.scrollTopOfGradientView.visibility = View.GONE + binding.scrollBottomOfGradientView.visibility = View.VISIBLE + } else if (scrollY + scrollViewHeight == contentHeight) { + binding.scrollTopOfGradientView.visibility = View.VISIBLE + binding.scrollBottomOfGradientView.visibility = View.GONE + } else { + binding.scrollTopOfGradientView.visibility = View.VISIBLE + binding.scrollBottomOfGradientView.visibility = View.VISIBLE + } + } + } + } } private fun onTappedPlayButton() { @@ -66,9 +100,24 @@ class PlaySongActivity : AppCompatActivity() { subColor = resources.getIdentifier("${selectedTeam}_sub", "color", "com.soi.moya") + // gradient view + val gradientSubColor = ContextCompat.getColor(this, subColor) + val alphaValue = 1 + val alphaColor = ColorUtils.setAlphaComponent(gradientSubColor, alphaValue) + val topOfGradientDrawable = GradientDrawable( + GradientDrawable.Orientation.BOTTOM_TOP, + intArrayOf(alphaColor, gradientSubColor) + ) + val bottomOfGradientDrawable = GradientDrawable( + GradientDrawable.Orientation.TOP_BOTTOM, + intArrayOf(alphaColor, gradientSubColor) + ) + binding.playSongLayout.setBackgroundColor(ContextCompat.getColor(this, subColor)) binding.songTitle.text = intent.getStringExtra("title") binding.songLyric.text = intent.getStringExtra("lyrics")?.replace("\\n", "\n") + binding.scrollTopOfGradientView.background = topOfGradientDrawable + binding.scrollBottomOfGradientView.background = bottomOfGradientDrawable window.statusBarColor = ContextCompat.getColor(this, subColor) } diff --git a/app/src/main/res/layout/activity_play_song.xml b/app/src/main/res/layout/activity_play_song.xml index 0133705..d38bbbe 100644 --- a/app/src/main/res/layout/activity_play_song.xml +++ b/app/src/main/res/layout/activity_play_song.xml @@ -26,29 +26,62 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - - + app:layout_constraintTop_toTopOf="parent"> + + + + + + + + + + + + + - +