mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Merge pull request #17 from finnmglas/feature/open-settings
Feature/open settings
This commit is contained in:
commit
75af3f2866
5 changed files with 95 additions and 21 deletions
|
@ -10,22 +10,6 @@ import android.view.animation.Animation
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import kotlinx.android.synthetic.main.activity_firststartup.*
|
import kotlinx.android.synthetic.main.activity_firststartup.*
|
||||||
|
|
||||||
// Taken from https://stackoverflow.com/questions/47293269
|
|
||||||
fun View.blink(
|
|
||||||
times: Int = Animation.INFINITE,
|
|
||||||
duration: Long = 1000L,
|
|
||||||
offset: Long = 20L,
|
|
||||||
minAlpha: Float = 0.2f,
|
|
||||||
maxAlpha: Float = 1.0f,
|
|
||||||
repeatMode: Int = Animation.REVERSE
|
|
||||||
) {
|
|
||||||
startAnimation(AlphaAnimation(minAlpha, maxAlpha).also {
|
|
||||||
it.duration = duration
|
|
||||||
it.startOffset = offset
|
|
||||||
it.repeatMode = repeatMode
|
|
||||||
it.repeatCount = times
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
class FirstStartupActivity : AppCompatActivity(){
|
class FirstStartupActivity : AppCompatActivity(){
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,43 @@ import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
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.animation.AlphaAnimation
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.DecelerateInterpolator
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
|
// Taken from https://stackoverflow.com/questions/47293269
|
||||||
|
fun View.blink(
|
||||||
|
times: Int = Animation.INFINITE,
|
||||||
|
duration: Long = 1000L,
|
||||||
|
offset: Long = 20L,
|
||||||
|
minAlpha: Float = 0.2f,
|
||||||
|
maxAlpha: Float = 1.0f,
|
||||||
|
repeatMode: Int = Animation.REVERSE
|
||||||
|
) {
|
||||||
|
startAnimation(AlphaAnimation(minAlpha, maxAlpha).also {
|
||||||
|
it.duration = duration
|
||||||
|
it.startOffset = offset
|
||||||
|
it.repeatMode = repeatMode
|
||||||
|
it.repeatCount = times
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.fadeIn(duration: Long = 1000L) {
|
||||||
|
startAnimation(AlphaAnimation(0f, 1f).also {
|
||||||
|
it.interpolator = DecelerateInterpolator()
|
||||||
|
it.duration = duration
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.fadeOut(duration: Long = 1000L) {
|
||||||
|
startAnimation(AlphaAnimation(1f, 0f).also {
|
||||||
|
it.interpolator = DecelerateInterpolator()
|
||||||
|
it.duration = duration
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** Activity related */
|
/** Activity related */
|
||||||
|
|
||||||
fun isInstalled(uri: String, context: Context): Boolean {
|
fun isInstalled(uri: String, context: Context): Boolean {
|
||||||
|
|
|
@ -32,7 +32,12 @@ class MainActivity : AppCompatActivity(),
|
||||||
|
|
||||||
// get device dimensions
|
// get device dimensions
|
||||||
private val displayMetrics = DisplayMetrics()
|
private val displayMetrics = DisplayMetrics()
|
||||||
|
|
||||||
|
// timers
|
||||||
private var clockTimer = Timer()
|
private var clockTimer = Timer()
|
||||||
|
private var tooltipTimer = Timer()
|
||||||
|
|
||||||
|
private var settingsIconShown = false
|
||||||
|
|
||||||
/** Activity Lifecycle functions */
|
/** Activity Lifecycle functions */
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -54,6 +59,9 @@ class MainActivity : AppCompatActivity(),
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
// Start by showing the settings icon
|
||||||
|
showSettingsIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
|
@ -75,12 +83,13 @@ class MainActivity : AppCompatActivity(),
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||||
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
val timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
|
||||||
|
|
||||||
clockTimer = fixedRateTimer("timer", true, 0L, 1000) {
|
clockTimer = fixedRateTimer("clockTimer", true, 0L, 1000) {
|
||||||
this@MainActivity.runOnUiThread {
|
this@MainActivity.runOnUiThread {
|
||||||
dateView.text = dateFormat.format(Date())
|
dateView.text = dateFormat.format(Date())
|
||||||
timeView.text = timeFormat.format(Date())
|
timeView.text = timeFormat.format(Date())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -88,6 +97,11 @@ class MainActivity : AppCompatActivity(),
|
||||||
clockTimer.cancel()
|
clockTimer.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun openSettings(){
|
||||||
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
/** 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 {
|
||||||
|
@ -120,10 +134,35 @@ class MainActivity : AppCompatActivity(),
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open Settings Activity
|
override fun onLongPress(event: MotionEvent) { openSettings() }
|
||||||
override fun onLongPress(event: MotionEvent) {
|
|
||||||
startActivity(Intent(this, SettingsActivity::class.java))
|
// Tooltip
|
||||||
|
override fun onSingleTapUp(event: MotionEvent): Boolean {
|
||||||
|
when(settingsIconShown) {
|
||||||
|
true -> hideSettingsIcon()
|
||||||
|
false -> showSettingsIcon()
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showSettingsIcon(){
|
||||||
|
settingstooltip.fadeIn()
|
||||||
|
settingstooltip.visibility = View.VISIBLE
|
||||||
|
settingsIconShown = true
|
||||||
|
|
||||||
|
tooltipTimer = fixedRateTimer("tooltipTimer", true, 10000, 1000) {
|
||||||
|
this@MainActivity.runOnUiThread { hideSettingsIcon() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideSettingsIcon(){
|
||||||
|
tooltipTimer.cancel()
|
||||||
|
settingstooltip.fadeOut()
|
||||||
|
settingstooltip.visibility = View.INVISIBLE
|
||||||
|
settingsIconShown = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun settingsIconOnTouch(view: View){ openSettings() }
|
||||||
|
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
return if (mDetector.onTouchEvent(event)) { true } else { super.onTouchEvent(event) }
|
return if (mDetector.onTouchEvent(event)) { true } else { super.onTouchEvent(event) }
|
||||||
|
@ -136,6 +175,5 @@ class MainActivity : AppCompatActivity(),
|
||||||
override fun onDown(event: MotionEvent): Boolean { return true }
|
override fun onDown(event: MotionEvent): Boolean { return true }
|
||||||
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
override fun onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
||||||
override fun onShowPress(event: MotionEvent) {}
|
override fun onShowPress(event: MotionEvent) {}
|
||||||
override fun onSingleTapUp(event: MotionEvent): Boolean { return true }
|
|
||||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean { return true }
|
override fun onSingleTapConfirmed(event: MotionEvent): Boolean { return true }
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,20 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<com.finnmglas.launcher.FontAwesomeSolid
|
||||||
|
android:id="@+id/settingstooltip"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:onClick="settingsIconOnTouch"
|
||||||
|
android:text="@string/fas_settings"
|
||||||
|
android:textColor="#ccc"
|
||||||
|
android:textSize="36sp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintHorizontal_bias="0.95"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.95" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,6 +3,7 @@
|
||||||
<string name="fas_bars" translatable="false"></string>
|
<string name="fas_bars" translatable="false"></string>
|
||||||
<string name="fas_home" translatable="false"></string>
|
<string name="fas_home" translatable="false"></string>
|
||||||
<string name="fas_globe" translatable="false"></string>
|
<string name="fas_globe" translatable="false"></string>
|
||||||
|
<string name="fas_settings" translatable="false"></string>
|
||||||
<string name="fas_star" translatable="false"></string>
|
<string name="fas_star" translatable="false"></string>
|
||||||
|
|
||||||
<string name="far_star" translatable="false"></string>
|
<string name="far_star" translatable="false"></string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue