mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Add a clickable settings icon
Make it easier and more intuitive for users to acess settings. Thanks for the feedback that helped me think of this.
This commit is contained in:
parent
c32018f72d
commit
0e4cc63554
3 changed files with 60 additions and 5 deletions
|
@ -32,7 +32,12 @@ class MainActivity : AppCompatActivity(),
|
|||
|
||||
// get device dimensions
|
||||
private val displayMetrics = DisplayMetrics()
|
||||
|
||||
// timers
|
||||
private var clockTimer = Timer()
|
||||
private var tooltipTimer = Timer()
|
||||
|
||||
private var settingsIconShown = false
|
||||
|
||||
/** Activity Lifecycle functions */
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -54,6 +59,9 @@ class MainActivity : AppCompatActivity(),
|
|||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// Start by showing the settings icon
|
||||
showSettingsIcon()
|
||||
}
|
||||
|
||||
override fun onStart(){
|
||||
|
@ -75,12 +83,13 @@ class MainActivity : AppCompatActivity(),
|
|||
val dateFormat = SimpleDateFormat("yyyy-MM-dd", 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 {
|
||||
dateView.text = dateFormat.format(Date())
|
||||
timeView.text = timeFormat.format(Date())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -88,6 +97,11 @@ class MainActivity : AppCompatActivity(),
|
|||
clockTimer.cancel()
|
||||
}
|
||||
|
||||
|
||||
private fun openSettings(){
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
}
|
||||
|
||||
/** Touch- and Key-related functions to start activities */
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
|
@ -120,10 +134,35 @@ class MainActivity : AppCompatActivity(),
|
|||
return true
|
||||
}
|
||||
|
||||
// Open Settings Activity
|
||||
override fun onLongPress(event: MotionEvent) {
|
||||
startActivity(Intent(this, SettingsActivity::class.java))
|
||||
override fun onLongPress(event: MotionEvent) { openSettings() }
|
||||
|
||||
// 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 {
|
||||
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 onScroll(e1: MotionEvent, e2: MotionEvent, dX: Float, dY: Float): Boolean { return true }
|
||||
override fun onShowPress(event: MotionEvent) {}
|
||||
override fun onSingleTapUp(event: MotionEvent): Boolean { return true }
|
||||
override fun onSingleTapConfirmed(event: MotionEvent): Boolean { return true }
|
||||
}
|
||||
|
|
|
@ -36,4 +36,20 @@
|
|||
app:layout_constraintStart_toStartOf="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>
|
|
@ -3,6 +3,7 @@
|
|||
<string name="fas_bars" translatable="false"></string>
|
||||
<string name="fas_home" 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="far_star" translatable="false"></string>
|
||||
|
|
Loading…
Add table
Reference in a new issue