Skip to content

Commit 182c838

Browse files
committed
android app: add scale animation to social links + fix statusbar
1 parent 3f7b5f4 commit 182c838

File tree

4 files changed

+36
-82
lines changed

4 files changed

+36
-82
lines changed

android/app/src/main/java/org/toni/customfetch_android/MainActivity.kt

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6363
class 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

android/app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
android:layout_margin="20dp"
122122
app:layout_constraintTop_toBottomOf="@id/aboutMe"
123123
app:layout_constraintStart_toStartOf="parent"
124-
app:layout_constraintEnd_toEndOf="parent">
124+
app:layout_constraintEnd_toEndOf="parent"
125+
tools:ignore="MissingConstraints" >
125126

126127
<TextView
127128
android:id="@+id/_text_discord"
@@ -162,7 +163,8 @@
162163
android:layout_margin="20dp"
163164
app:layout_constraintTop_toBottomOf="@id/join_discord_link"
164165
app:layout_constraintStart_toStartOf="parent"
165-
app:layout_constraintEnd_toEndOf="parent">
166+
app:layout_constraintEnd_toEndOf="parent"
167+
tools:ignore="MissingConstraints" >
166168

167169
<TextView
168170
android:id="@+id/_text_reddit"
@@ -191,57 +193,4 @@
191193
app:layout_constraintEnd_toEndOf="parent" />
192194

193195
</androidx.constraintlayout.widget.ConstraintLayout>
194-
195-
<!--
196-
<LinearLayout
197-
android:id="@+id/join_discord_link_layout"
198-
android:layout_width="wrap_content"
199-
android:layout_height="wrap_content"
200-
android:layout_gravity="center"
201-
android:layout_marginTop="55dp"
202-
app:layout_constraintTop_toBottomOf="@id/join_discord_link"
203-
app:layout_constraintStart_toStartOf="parent"
204-
app:layout_constraintEnd_toEndOf="parent">
205-
206-
<com.google.android.material.imageview.ShapeableImageView
207-
android:layout_width="20dp"
208-
android:layout_height="20dp"
209-
android:src="@drawable/discord_mark_blue" />
210-
211-
<TextView
212-
android:id="@+id/discord_link"
213-
android:layout_width="wrap_content"
214-
android:layout_height="wrap_content"
215-
android:layout_marginStart="4dp"
216-
android:layout_gravity="center"
217-
android:textColor="#ffffff"
218-
android:text="@string/join_discord_server" />
219-
220-
</LinearLayout>
221-
222-
<LinearLayout
223-
android:layout_width="wrap_content"
224-
android:layout_height="wrap_content"
225-
android:layout_gravity="center"
226-
android:layout_marginTop="15dp"
227-
app:layout_constraintTop_toBottomOf="@id/join_discord_link_layout"
228-
app:layout_constraintStart_toStartOf="parent"
229-
app:layout_constraintEnd_toEndOf="parent">
230-
231-
<com.google.android.material.imageview.ShapeableImageView
232-
android:layout_width="20dp"
233-
android:layout_height="20dp"
234-
android:src="@drawable/reddit_logo_16" />
235-
236-
<TextView
237-
android:id="@+id/reddit_link"
238-
android:layout_width="wrap_content"
239-
android:layout_height="wrap_content"
240-
android:layout_marginStart="4dp"
241-
android:layout_gravity="center"
242-
android:textColor="#ffffff"
243-
android:text="@string/join_subreddit" />
244-
245-
</LinearLayout>
246-
-->
247196
</androidx.constraintlayout.widget.ConstraintLayout>

android/app/src/main/res/values-night/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<item name="colorSecondaryVariant">@color/teal_200</item>
1111
<item name="colorOnSecondary">@color/black</item>
1212
<!-- Status bar color. -->
13-
<item name="android:statusBarColor">#2a2a2a</item>
13+
<item name="android:statusBarColor">@color/background</item>
1414
<!-- Customize your theme here. -->
1515
<item name="preferenceTheme">@style/PrefsTheme</item>
1616
</style>

android/app/src/main/res/values/themes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<item name="colorSecondaryVariant">@color/teal_700</item>
1111
<item name="colorOnSecondary">@color/black</item>
1212
<!-- Status bar color. -->
13-
<item name="android:statusBarColor">#2a2a2a</item>
13+
<item name="android:statusBarColor">@color/background</item>
1414
<!-- Customize your theme here. -->
1515
<item name="preferenceTheme">@style/PrefsTheme</item>
1616
</style>

0 commit comments

Comments
 (0)