@@ -58,7 +58,7 @@ import kotlin.io.path.Path
5858
5959
6060// kinda magic numbers
61- const val TEST_CONFIG_FILE_RC = 2
61+ const val TEST_CONFIG_FILE_RC = 6969
6262
6363class MainActivity : AppCompatActivity () {
6464 private lateinit var binding: ActivityMainBinding
@@ -93,37 +93,30 @@ class MainActivity : AppCompatActivity() {
9393 if (! Files .exists(Path (filesDir.absolutePath + " /ascii" )))
9494 copyToAssetFolder(assets, filesDir.absolutePath, " ascii" )
9595
96+ binding.testConfigFile.setOnTouchListener { view, event -> startAnimation(view, event) }
9697 binding.testConfigFile.setOnClickListener { _ ->
9798 val intent = Intent (Intent .ACTION_OPEN_DOCUMENT ).apply {
9899 addCategory(Intent .CATEGORY_OPENABLE )
99100 type = " */*"
100101 }
101102 startActivityForResult(intent, TEST_CONFIG_FILE_RC )
102103 }
103- binding.testConfigFile.setOnTouchListener { _, event ->
104- startAnimation(binding.testConfigFile, event)
105- }
106104
107- binding.aboutMe.setOnClickListener { _ ->
108- setFragment(AboutMeFragment ())
109- }
110- binding.aboutMe.setOnTouchListener { _, event ->
111- startAnimation(binding.aboutMe, event)
112- }
105+ binding.aboutMe.setOnTouchListener { view, event -> startAnimation(view, event) }
106+ binding.aboutMe.setOnClickListener { setFragment(AboutMeFragment ()) }
113107
114- binding.widgetSettings.setOnClickListener { _ ->
115- setFragment(SettingsFragment ())
116- }
117- binding.widgetSettings.setOnTouchListener { _, event ->
118- startAnimation(binding.widgetSettings, event)
119- }
108+ binding.widgetSettings.setOnTouchListener { view, event -> startAnimation(view, event) }
109+ binding.widgetSettings.setOnClickListener { setFragment(SettingsFragment ()) }
120110
121111 setViewBgColor(binding.joinDiscordLink, 0XFF5865F2 .toInt())
122- setViewBgColor( binding.joinCustomfetchReddit, 0XFFFF4500 .toInt())
123- binding.joinDiscordLink.setOnClickListener { _ ->
112+ binding.joinDiscordLink.setOnTouchListener { view, event -> startAnimation(view, event, true ) }
113+ binding.joinDiscordLink.setOnClickListener {
124114 startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(" https://discord.gg/dcD7d3Qfus" )))
125115 }
126- binding.joinCustomfetchReddit.setOnClickListener { _ ->
116+
117+ setViewBgColor(binding.joinCustomfetchReddit, 0XFFFF4500 .toInt())
118+ binding.joinCustomfetchReddit.setOnTouchListener { view, event -> startAnimation(view, event, true ) }
119+ binding.joinCustomfetchReddit.setOnClickListener {
127120 startActivity(Intent (Intent .ACTION_VIEW , Uri .parse(" https://reddit.com/r/customfetch" )))
128121 }
129122 }
@@ -162,27 +155,39 @@ class MainActivity : AppCompatActivity() {
162155 drawable.setColor(color)
163156 }
164157
165- private fun startAnimation (view : View , event : MotionEvent ): Boolean {
158+ private fun startAnimation (view : View , event : MotionEvent , scaleAnimation : Boolean = false): Boolean {
159+ if (scaleAnimation) {
160+ val animRes = when (event.action) {
161+ MotionEvent .ACTION_DOWN -> R .anim.scale_down
162+ MotionEvent .ACTION_UP , MotionEvent .ACTION_CANCEL -> R .anim.scale_up
163+ else -> return false
164+ }
165+
166+ val animation = AnimationUtils .loadAnimation(this , animRes)
167+ view.startAnimation(animation)
168+ return true
169+ }
170+
166171 val drawable = view.background as GradientDrawable
167172 var colorAnimator = ValueAnimator ()
168173 when (event.action) {
169174 MotionEvent .ACTION_DOWN -> {
170175 colorAnimator =
171- ValueAnimator .ofObject(ArgbEvaluator (), ContextCompat . getColor(this , R .color.buttonBg),
172- ContextCompat . getColor(this , R .color.reverseButtonBg))
176+ ValueAnimator .ofObject(ArgbEvaluator (), getColor(R .color.buttonBg),
177+ getColor(R .color.reverseButtonBg))
173178 }
174179 MotionEvent .ACTION_UP , MotionEvent .ACTION_CANCEL -> {
175180 colorAnimator =
176- ValueAnimator .ofObject(ArgbEvaluator (), ContextCompat . getColor(this , R .color.reverseButtonBg),
177- ContextCompat . getColor(this , R .color.buttonBg))
181+ ValueAnimator .ofObject(ArgbEvaluator (), getColor(R .color.reverseButtonBg),
182+ getColor(R .color.buttonBg))
178183 }
179184 }
180185 colorAnimator.duration = 300
181186 colorAnimator.addUpdateListener { animator ->
182187 drawable.setColor(animator.animatedValue as Int )
183188 }
184189 colorAnimator.start()
185- return false
190+ return true
186191 }
187192}
188193
0 commit comments