mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 01:47:24 +00:00
Returns to home on every resume so that back key also brings the app back home
This commit is contained in:
parent
a088a1edeb
commit
fc418e6a2c
4 changed files with 16 additions and 23 deletions
|
|
@ -258,11 +258,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
private fun setShortcutListeners(textView: TextView, savedView: List<String>?) {
|
private fun setShortcutListeners(textView: TextView, savedView: List<String>?) {
|
||||||
textView.setOnClickListener {
|
textView.setOnClickListener {
|
||||||
val mainActivity = launcherApps.getActivityList(savedView?.get(0).toString(), launcherApps.profiles[savedView?.get(1)!!.toInt()]).firstOrNull()
|
if (savedView != null) {
|
||||||
if (mainActivity != null) {
|
appUtils.launchApp(savedView[0], launcherApps.profiles[savedView[1].toInt()])
|
||||||
launcherApps.startMainActivity(mainActivity.componentName, launcherApps.profiles[savedView[1].toInt()], null, null)
|
|
||||||
} else {
|
|
||||||
Toast.makeText(this, "Cannot launch app", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -425,11 +422,10 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
dateText.format24Hour = "${dateElements[1]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}"
|
dateText.format24Hour = "${dateElements[1]}${stringUtils.addStartTextIfNotEmpty(dateElements[2], " | ")}${stringUtils.addStartTextIfNotEmpty(dateElements[3], " | ")}"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun backToHome() {
|
fun backToHome(animSpeed: Long = sharedPreferenceManager.getAnimationSpeed()) {
|
||||||
closeKeyboard()
|
closeKeyboard()
|
||||||
animations.showHome(binding.homeView, binding.appView)
|
animations.showHome(binding.homeView, binding.appView, animSpeed)
|
||||||
animations.backgroundOut(this@MainActivity)
|
animations.backgroundOut(this@MainActivity, animSpeed)
|
||||||
val animSpeed = sharedPreferenceManager.getAnimationSpeed()
|
|
||||||
|
|
||||||
// Delay app menu changes so that the user doesn't see them
|
// Delay app menu changes so that the user doesn't see them
|
||||||
|
|
||||||
|
|
@ -651,11 +647,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
backToHome(0)
|
||||||
adapter?.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
||||||
appUtils.launchApp(appInfo, userHandle)
|
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onShortcut(
|
override fun onShortcut(
|
||||||
|
|
@ -678,7 +675,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
shortcutView.text = textView.text.toString()
|
shortcutView.text = textView.text.toString()
|
||||||
shortcutView.setOnClickListener {
|
shortcutView.setOnClickListener {
|
||||||
appUtils.launchApp(appInfo, userHandle)
|
appUtils.launchApp(appInfo.applicationInfo.packageName, userHandle)
|
||||||
}
|
}
|
||||||
sharedPreferenceManager.setShortcut(
|
sharedPreferenceManager.setShortcut(
|
||||||
shortcutView,
|
shortcutView,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.graphics.toColor
|
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import eu.ottop.yamlauncher.R
|
import eu.ottop.yamlauncher.R
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ class Animations (context: Context) {
|
||||||
view.fadeOut()
|
view.fadeOut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showHome(homeView: View, appView: View) {
|
fun showHome(homeView: View, appView: View, duration: Long) {
|
||||||
appView.slideOutToBottom()
|
appView.slideOutToBottom(duration)
|
||||||
homeView.fadeIn()
|
homeView.fadeIn(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showApps(homeView: View, appView: View) {
|
fun showApps(homeView: View, appView: View) {
|
||||||
|
|
@ -58,7 +58,7 @@ class Animations (context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun backgroundOut(activity: Activity) {
|
fun backgroundOut(activity: Activity, duration: Long) {
|
||||||
val newColor = sharedPreferenceManager.getBgColor()
|
val newColor = sharedPreferenceManager.getBgColor()
|
||||||
|
|
||||||
// Only animate darkness onto the transparent background
|
// Only animate darkness onto the transparent background
|
||||||
|
|
@ -72,7 +72,6 @@ class Animations (context: Context) {
|
||||||
colorDrawable.color = animator.animatedValue as Int
|
colorDrawable.color = animator.animatedValue as Int
|
||||||
}
|
}
|
||||||
|
|
||||||
val duration = sharedPreferenceManager.getAnimationSpeed()
|
|
||||||
backgroundColorAnimator.duration = duration
|
backgroundColorAnimator.duration = duration
|
||||||
|
|
||||||
backgroundColorAnimator.start()
|
backgroundColorAnimator.start()
|
||||||
|
|
@ -97,9 +96,8 @@ class Animations (context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun View.slideOutToBottom() {
|
private fun View.slideOutToBottom(duration: Long) {
|
||||||
if (visibility == View.VISIBLE) {
|
if (visibility == View.VISIBLE) {
|
||||||
val duration = sharedPreferenceManager.getAnimationSpeed()
|
|
||||||
|
|
||||||
animate()
|
animate()
|
||||||
.translationY(height.toFloat() / 5)
|
.translationY(height.toFloat() / 5)
|
||||||
|
|
@ -114,12 +112,11 @@ class Animations (context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun View.fadeIn() {
|
private fun View.fadeIn(duration: Long = sharedPreferenceManager.getAnimationSpeed()) {
|
||||||
if (visibility != View.VISIBLE) {
|
if (visibility != View.VISIBLE) {
|
||||||
alpha = 0f
|
alpha = 0f
|
||||||
translationY = -height.toFloat()/100
|
translationY = -height.toFloat()/100
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
val duration = sharedPreferenceManager.getAnimationSpeed()
|
|
||||||
|
|
||||||
animate()
|
animate()
|
||||||
.alpha(1f)
|
.alpha(1f)
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,8 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun launchApp(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
|
fun launchApp(packageName: String, userHandle: UserHandle) {
|
||||||
val mainActivity = launcherApps.getActivityList(appInfo.applicationInfo.packageName, userHandle).firstOrNull()
|
val mainActivity = launcherApps.getActivityList(packageName, userHandle).firstOrNull()
|
||||||
if (mainActivity != null) {
|
if (mainActivity != null) {
|
||||||
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
|
launcherApps.startMainActivity(mainActivity.componentName, userHandle, null, null)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue