mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-17 17:30:50 +02:00
Animate (rotate) the settings icon
Also, onBackPress, the icon is hidden
This commit is contained in:
parent
e24b51f3bf
commit
11045cbb0c
2 changed files with 47 additions and 8 deletions
|
@ -12,9 +12,7 @@ import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.animation.AlphaAnimation
|
import android.view.animation.*
|
||||||
import android.view.animation.Animation
|
|
||||||
import android.view.animation.DecelerateInterpolator
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
/** Variables for all of the app */
|
/** Variables for all of the app */
|
||||||
|
@ -67,6 +65,44 @@ fun View.fadeOut(duration: Long = 300L) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun View.fadeRotateIn(duration: Long = 500L) {
|
||||||
|
val combined = AnimationSet(false)
|
||||||
|
combined.addAnimation(
|
||||||
|
AlphaAnimation(0f, 1F).also {
|
||||||
|
it.interpolator = DecelerateInterpolator()
|
||||||
|
it.duration = duration
|
||||||
|
}
|
||||||
|
)
|
||||||
|
combined.addAnimation(
|
||||||
|
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||||
|
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
||||||
|
it.duration = duration * 2
|
||||||
|
it.interpolator = DecelerateInterpolator()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
startAnimation(combined)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.fadeRotateOut(duration: Long = 500L) {
|
||||||
|
val combined = AnimationSet(false)
|
||||||
|
combined.addAnimation(
|
||||||
|
AlphaAnimation(1F, 0F).also {
|
||||||
|
it.interpolator = AccelerateInterpolator()
|
||||||
|
it.duration = duration
|
||||||
|
}
|
||||||
|
)
|
||||||
|
combined.addAnimation(
|
||||||
|
RotateAnimation(0F, 180F, Animation.RELATIVE_TO_SELF,
|
||||||
|
0.5f, Animation.RELATIVE_TO_SELF,0.5f).also {
|
||||||
|
it.duration = duration
|
||||||
|
it.interpolator = AccelerateInterpolator()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
startAnimation(combined)
|
||||||
|
}
|
||||||
|
|
||||||
/** Activity related */
|
/** Activity related */
|
||||||
|
|
||||||
fun isInstalled(uri: String, context: Context): Boolean {
|
fun isInstalled(uri: String, context: Context): Boolean {
|
||||||
|
@ -134,7 +170,7 @@ fun getSavedTheme(context : Context) : String {
|
||||||
val sharedPref = context.getSharedPreferences(
|
val sharedPref = context.getSharedPreferences(
|
||||||
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||||
|
|
||||||
return sharedPref.getString("theme", "finnmglas").toString()
|
return sharedPref.getString("theme", "finn").toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveTheme(context : Context, themeName : String) {
|
fun saveTheme(context : Context, themeName : String) {
|
||||||
|
|
|
@ -6,6 +6,9 @@ import android.os.AsyncTask
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.LinearInterpolator
|
||||||
|
import android.view.animation.RotateAnimation
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.GestureDetectorCompat
|
import androidx.core.view.GestureDetectorCompat
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
@ -14,6 +17,7 @@ import java.util.*
|
||||||
import kotlin.concurrent.fixedRateTimer
|
import kotlin.concurrent.fixedRateTimer
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity(),
|
class MainActivity : AppCompatActivity(),
|
||||||
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
||||||
|
|
||||||
|
@ -116,7 +120,6 @@ class MainActivity : AppCompatActivity(),
|
||||||
loadAppsTimer.cancel()
|
loadAppsTimer.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun openSettings(){
|
private fun openSettings(){
|
||||||
startActivity(Intent(this, SettingsActivity::class.java))
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
|
@ -124,7 +127,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
/** Touch- and Key-related functions to start activities */
|
/** Touch- and Key-related functions to start activities */
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) return true
|
if (keyCode == KeyEvent.KEYCODE_BACK) if (settingsIconShown) hideSettingsIcon()
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) launchApp(volumeUpApp, this)
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) launchApp(volumeUpApp, this)
|
||||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) launchApp(volumeDownApp, this)
|
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) launchApp(volumeDownApp, this)
|
||||||
return true
|
return true
|
||||||
|
@ -166,7 +169,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSettingsIcon(){
|
private fun showSettingsIcon(){
|
||||||
settingstooltip.fadeIn()
|
settingstooltip.fadeRotateIn()
|
||||||
settingstooltip.visibility = View.VISIBLE
|
settingstooltip.visibility = View.VISIBLE
|
||||||
settingsIconShown = true
|
settingsIconShown = true
|
||||||
|
|
||||||
|
@ -177,7 +180,7 @@ class MainActivity : AppCompatActivity(),
|
||||||
|
|
||||||
private fun hideSettingsIcon(){
|
private fun hideSettingsIcon(){
|
||||||
tooltipTimer.cancel()
|
tooltipTimer.cancel()
|
||||||
settingstooltip.fadeOut()
|
settingstooltip.fadeRotateOut()
|
||||||
settingstooltip.visibility = View.INVISIBLE
|
settingstooltip.visibility = View.INVISIBLE
|
||||||
settingsIconShown = false
|
settingsIconShown = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue