Skip to content

Commit

Permalink
Merge pull request #13 from Gwamegis/feat/playerGradient
Browse files Browse the repository at this point in the history
player 그라데이션 추가
  • Loading branch information
JIWON1923 authored Apr 21, 2023
2 parents 070ee57 + 8731fa2 commit 4d936bb
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 12 deletions.
49 changes: 49 additions & 0 deletions app/src/main/java/com/soi/moya/PlaySongActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand Down
57 changes: 45 additions & 12 deletions app/src/main/res/layout/activity_play_song.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,62 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="20dp"
app:layout_constraintBottom_toTopOf="@+id/playSongButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/songTitle">

<TextView
android:id="@+id/songLyric"
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/pretendard_bold"
android:lineSpacingExtra="8dp"
android:textColor="@color/white"
android:textSize="26dp"
app:layout_constraintBottom_toTopOf="@+id/playSongButton"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/songTitle" />
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:id="@+id/songLyricLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/songLyric"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:fontFamily="@font/pretendard_bold"
android:lineSpacingExtra="8dp"
android:textColor="@color/white"
android:textSize="26dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</LinearLayout>

</ScrollView>

<View
android:id="@+id/scrollTopOfGradientView"
android:layout_width="match_parent"
android:layout_height="120dp"
android:visibility="gone"
app:layout_constraintTop_toTopOf="@+id/scrollView" />

<View
android:id="@+id/scrollBottomOfGradientView"
android:layout_width="match_parent"
android:layout_height="120dp"
app:layout_constraintBottom_toBottomOf="@+id/scrollView" />


</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>


<ImageView
Expand Down

0 comments on commit 4d936bb

Please sign in to comment.