Simplify ActivityStarter and remove app start animation preference
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
package de.mm20.launcher2.ui.preferences
|
||||
|
||||
import android.animation.Animator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.postDelayed
|
||||
import androidx.preference.Preference
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import com.airbnb.lottie.LottieAnimationView
|
||||
import de.mm20.launcher2.R
|
||||
import de.mm20.launcher2.preferences.AppStartAnimation
|
||||
import de.mm20.launcher2.preferences.LauncherPreferences
|
||||
|
||||
class AppStartAnimPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.preferenceStyle) : Preference(context, attrs, defStyleAttr) {
|
||||
|
||||
init {
|
||||
summary = getNameForAnimation(LauncherPreferences.instance.appStartAnim)
|
||||
|
||||
setOnPreferenceClickListener {
|
||||
val anims = mutableListOf(
|
||||
AppStartAnimation.M to R.raw.app_start_anim_m,
|
||||
AppStartAnimation.SLIDE_BOTTOM to R.raw.app_start_anim_slide_bottom,
|
||||
AppStartAnimation.FADE to R.raw.app_start_anim_fade
|
||||
)
|
||||
|
||||
val dialog = MaterialDialog(context)
|
||||
val layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
|
||||
val list = LinearLayout(context)
|
||||
|
||||
list.orientation = LinearLayout.VERTICAL
|
||||
|
||||
anims.forEachIndexed { _, anim ->
|
||||
val view = View.inflate(context, R.layout.preference_start_anim_item, null)
|
||||
view.findViewById<LottieAnimationView>(R.id.icon).also { iconView ->
|
||||
iconView.setAnimation(anim.second)
|
||||
iconView.addAnimatorListener(object : Animator.AnimatorListener {
|
||||
override fun onAnimationRepeat(animation: Animator?) {
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
iconView.postDelayed(500) {
|
||||
iconView.frame = 0
|
||||
}
|
||||
iconView.postDelayed(1300) {
|
||||
iconView.playAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAnimationCancel(animation: Animator?) {
|
||||
}
|
||||
|
||||
override fun onAnimationStart(animation: Animator?) {
|
||||
}
|
||||
|
||||
})
|
||||
iconView.postDelayed(300) {
|
||||
iconView.playAnimation()
|
||||
}
|
||||
}
|
||||
view.findViewById<TextView>(R.id.label).also { labelView ->
|
||||
labelView.setText(getNameForAnimation(anim.first))
|
||||
}
|
||||
view.layoutParams = layoutParams
|
||||
list.addView(view)
|
||||
view.setOnClickListener {
|
||||
LauncherPreferences.instance.appStartAnim = anim.first
|
||||
summary = getNameForAnimation(anim.first)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
dialog.customView(view = list, scrollable = true)
|
||||
.title(R.string.preference_app_start_animation)
|
||||
.negativeButton(android.R.string.cancel) {
|
||||
dialog.cancel()
|
||||
}
|
||||
.show()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNameForAnimation(anim: AppStartAnimation): String {
|
||||
return when (anim) {
|
||||
AppStartAnimation.FADE -> context.getString(R.string.preference_app_start_animation_fade)
|
||||
AppStartAnimation.SLIDE_BOTTOM -> context.getString(R.string.preference_app_start_animation_slide_bottom)
|
||||
AppStartAnimation.M -> context.getString(R.string.preference_app_start_animation_m)
|
||||
else -> context.getString(R.string.preference_app_start_animation_default)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.airbnb.lottie.LottieAnimationView
|
||||
android:id="@+id/icon"
|
||||
android:background="@color/blue"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
tools:rawRes="@raw/app_start_anim_fade"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="4dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
tools:text="Fade"/>
|
||||
</LinearLayout>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -56,7 +56,6 @@
|
||||
app:title="@string/preference_icon_shape" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory app:title="@string/preference_category_animations">
|
||||
<de.mm20.launcher2.ui.preferences.AppStartAnimPreference app:title="@string/preference_app_start_animation" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory app:title="@string/preference_category_searchbar">
|
||||
<ListPreference
|
||||
|
||||
Reference in New Issue
Block a user