From 9ce17e0dc3e17c3a640363247667409e67ca68ae Mon Sep 17 00:00:00 2001 From: Tyler Nijmeh Date: Wed, 31 Mar 2021 00:40:16 -0700 Subject: Animate profile application Signed-off-by: Tyler Nijmeh --- .../buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt | 7 +++++-- app/src/main/java/com/draco/buoy/views/MainActivity.kt | 2 +- app/src/main/res/anim/press.xml | 11 +++++++++++ app/src/main/res/layout/recycler_item_profile.xml | 1 - 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/anim/press.xml diff --git a/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt b/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt index 0957ee7..fe22e4c 100644 --- a/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt +++ b/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt @@ -1,9 +1,11 @@ package com.draco.buoy.recyclers import android.content.ContentResolver +import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.animation.AnimationUtils import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.draco.buoy.R @@ -11,7 +13,7 @@ import com.draco.buoy.repositories.BatterySaverConstantsConfigProfiles import com.draco.buoy.utils.BatterySaverManager class BatterySaverProfileRecyclerAdapter( - contentResolver: ContentResolver + private val context: Context ) : RecyclerView.Adapter() { private val batterySaverProfiles = arrayOf( null, /* Reset */ @@ -21,7 +23,7 @@ class BatterySaverProfileRecyclerAdapter( BatterySaverConstantsConfigProfiles.EXTREME, ) - private val batterySaverManager = BatterySaverManager(contentResolver) + private val batterySaverManager = BatterySaverManager(context.contentResolver) class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { val title = itemView.findViewById(R.id.title) @@ -64,6 +66,7 @@ class BatterySaverProfileRecyclerAdapter( } holder.itemView.setOnClickListener { + it.startAnimation(AnimationUtils.loadAnimation(context, R.anim.press)) if (profile == null) { batterySaverManager.resetConstants() batterySaverManager.setLowPower(false) diff --git a/app/src/main/java/com/draco/buoy/views/MainActivity.kt b/app/src/main/java/com/draco/buoy/views/MainActivity.kt index b8f1fc2..90e06e8 100644 --- a/app/src/main/java/com/draco/buoy/views/MainActivity.kt +++ b/app/src/main/java/com/draco/buoy/views/MainActivity.kt @@ -22,7 +22,7 @@ class MainActivity : AppCompatActivity() { recycler = findViewById(R.id.recycler_profile) recycler.apply { - adapter = BatterySaverProfileRecyclerAdapter(contentResolver) + adapter = BatterySaverProfileRecyclerAdapter(this@MainActivity) layoutManager = LinearLayoutManager(this@MainActivity) } diff --git a/app/src/main/res/anim/press.xml b/app/src/main/res/anim/press.xml new file mode 100644 index 0000000..6a7ab7a --- /dev/null +++ b/app/src/main/res/anim/press.xml @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/recycler_item_profile.xml b/app/src/main/res/layout/recycler_item_profile.xml index 6db4ac0..65e66e1 100644 --- a/app/src/main/res/layout/recycler_item_profile.xml +++ b/app/src/main/res/layout/recycler_item_profile.xml @@ -5,7 +5,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_marginHorizontal="12dp" android:layout_marginTop="12dp" - app:cardCornerRadius="10dp" app:cardBackgroundColor="@color/green">