Skip to content

Commit

Permalink
Merge pull request #3 from usefulness/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Nov 14, 2022
2 parents 6b12d44 + f8173b5 commit 04a584c
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 382 deletions.
4 changes: 0 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ maven-junit = "5.9.1"
maven-assertj = "3.23.1"
google-androidx-core = "1.9.0"
google-androidx-annotation = "1.5.0"
google-gson = "2.10"
google-androidtest = "1.5.0"
google-androidtestRunner = "1.5.1"
google-androidtestext = "1.1.4"
google-espresso = "3.5.0"
google-appcompat = "1.5.1"
google-material = "1.7.0"
google-constraintLayout = "2.1.4"

[libraries]
Expand All @@ -24,14 +22,12 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "mav
assertj-core = { module = "org.assertj:assertj-core", version.ref = "maven-assertj" }
androidx-core = { module = "androidx.core:core", version.ref = "google-androidx-core" }
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "google-androidx-annotation" }
gson = { module = "com.google.code.gson:gson", version.ref = "google-gson" }
androidtest-core = { module = "androidx.test:core", version.ref = "google-androidtest" }
androidtest-runner = { module = "androidx.test:runner", version.ref = "google-androidtestRunner" }
androidtest-rules = { module = "androidx.test:rules", version.ref = "google-androidtest" }
androidtest-junitext = { module = "androidx.test.ext:junit-ktx", version.ref = "google-androidtestext" }
espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "google-espresso" }
appcompat-core = { module = "androidx.appcompat:appcompat", version.ref = "google-appcompat" }
material-core = { module = "com.google.android.material:material", version.ref = "google-material" }
constraintlayout-core = { module = "androidx.constraintlayout:constraintlayout", version.ref = "google-constraintLayout" }

[plugins]
Expand Down
4 changes: 4 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ android {
defaultConfig {
applicationId "io.github.usefulness.shimmer.sample"
}
buildFeatures {
viewBinding = true
}
}

dependencies {
implementation("io.github.usefulness:shimmer-android-core")
implementation(libs.appcompat.core)
implementation(libs.constraintlayout.core)
}
4 changes: 2 additions & 2 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
>
<activity
android:name="com.facebook.shimmer.sample.MainActivity"
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
134 changes: 0 additions & 134 deletions sample/src/main/java/com/facebook/shimmer/sample/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package io.github.usefulness.shimmer.sample

import android.animation.ValueAnimator
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.facebook.shimmer.Shimmer
import io.github.usefulness.shimmer.sample.databinding.MainBinding

class MainActivity : AppCompatActivity() {

private var toast: Toast? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = MainBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.presetButtons.forEachIndexed { index, button ->
button.setOnClickListener {
binding.selectPreset(preset = index, showToast = true)
}
}
binding.selectPreset(preset = 0, showToast = false)
lifecycle.addObserver(
object : DefaultLifecycleObserver {

override fun onResume(owner: LifecycleOwner) {
binding.shimmerViewContainer.startShimmer()
}

override fun onPause(owner: LifecycleOwner) {
binding.shimmerViewContainer.stopShimmer()
}
},
)
}

private fun MainBinding.selectPreset(preset: Int, showToast: Boolean) {
val context = root.context

presetButtons.forEach { it.setBackgroundResource(R.color.preset_button_background) }
presetButtons[preset].setBackgroundResource(R.color.preset_button_background_selected)

// If a toast is already showing, hide it
toast?.cancel()

val shimmerBuilder = Shimmer.AlphaHighlightBuilder()
shimmerViewContainer.shimmer = when (preset) {
1 -> {
// Slow and reverse
toast = Toast.makeText(context, "Slow and reverse", Toast.LENGTH_SHORT)
shimmerBuilder.setDuration(5000L).setRepeatMode(ValueAnimator.REVERSE)
}

2 -> {
// Thin, straight and transparent
toast = Toast.makeText(context, "Thin, straight and transparent", Toast.LENGTH_SHORT)
shimmerBuilder.setBaseAlpha(0.1f).setDropoff(0.1f).setTilt(0f)
}

3 -> {
// Sweep angle 90
toast = Toast.makeText(context, "Sweep angle 90", Toast.LENGTH_SHORT)
shimmerBuilder.setDirection(Shimmer.Direction.TOP_TO_BOTTOM).setTilt(0f)
}

4 -> {
// Spotlight
toast = Toast.makeText(context, "Spotlight", Toast.LENGTH_SHORT)
shimmerBuilder
.setBaseAlpha(0f)
.setDuration(2000L)
.setDropoff(0.1f)
.setIntensity(0.35f)
.setShape(Shimmer.Shape.RADIAL)
}

5 -> {
// Spotlight angle 45
toast = Toast.makeText(context, "Spotlight angle 45", Toast.LENGTH_SHORT)
shimmerBuilder
.setBaseAlpha(0f)
.setDuration(2000L)
.setDropoff(0.1f)
.setIntensity(0.35f)
.setTilt(45f)
.setShape(Shimmer.Shape.RADIAL)
}

6 -> {
// Off
toast = Toast.makeText(context, "Off", Toast.LENGTH_SHORT)
null
}

else -> {
toast = Toast.makeText(context, "Default", Toast.LENGTH_SHORT)
shimmerBuilder
}
}
?.build()

if (showToast) {
toast?.show()
}
}
}

private val MainBinding.presetButtons
get() = arrayOf(
presetButton0,
presetButton1,
presetButton2,
presetButton3,
presetButton4,
presetButton5,
presetButton6,
)
Loading

0 comments on commit 04a584c

Please sign in to comment.