mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Rudimentary clock aligment setting functionality added
This commit is contained in:
parent
8333864b4e
commit
01b7400083
5 changed files with 102 additions and 12 deletions
|
|
@ -20,15 +20,19 @@ import android.view.View
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.Spinner
|
||||||
import android.widget.TextClock
|
import android.widget.TextClock
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import androidx.core.view.marginLeft
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
@ -56,7 +60,6 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
val cameraIntent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE)
|
val cameraIntent = Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE)
|
||||||
val phoneIntent = Intent(Intent.ACTION_DIAL)
|
val phoneIntent = Intent(Intent.ACTION_DIAL)
|
||||||
private lateinit var batteryReceiver: BatteryReceiver
|
private lateinit var batteryReceiver: BatteryReceiver
|
||||||
private lateinit var dateText: TextClock
|
|
||||||
|
|
||||||
private var appActionMenu = AppActionMenu()
|
private var appActionMenu = AppActionMenu()
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
|
|
@ -64,11 +67,14 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity)
|
private val appMenuLinearLayoutManager = AppMenuLinearLayoutManager(this@MainActivity)
|
||||||
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
|
private val appMenuEdgeFactory = AppMenuEdgeFactory(this@MainActivity)
|
||||||
private val animations = Animations()
|
private val animations = Animations()
|
||||||
private val weatherSystem = WeatherSystem()
|
|
||||||
|
|
||||||
private val swipeThreshold = 100
|
private val swipeThreshold = 100
|
||||||
private val swipeVelocityThreshold = 100
|
private val swipeVelocityThreshold = 100
|
||||||
|
|
||||||
|
private lateinit var clock: TextClock
|
||||||
|
private var clockMargin = 0
|
||||||
|
private lateinit var constraintLayout: ConstraintLayout
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -81,6 +87,12 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
gestureDetector = GestureDetector(this, GestureListener())
|
gestureDetector = GestureDetector(this, GestureListener())
|
||||||
shortcutGestureDetector = GestureDetector(this, TextGestureListener())
|
shortcutGestureDetector = GestureDetector(this, TextGestureListener())
|
||||||
|
|
||||||
|
clock = findViewById(R.id.text_clock)
|
||||||
|
|
||||||
|
clockMargin = clock.marginLeft
|
||||||
|
|
||||||
|
constraintLayout = findViewById(R.id.clock_layout)
|
||||||
|
|
||||||
setupApps()
|
setupApps()
|
||||||
|
|
||||||
val dateText = findViewById<TextClock>(R.id.text_date)
|
val dateText = findViewById<TextClock>(R.id.text_date)
|
||||||
|
|
@ -105,6 +117,7 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
|
|
@ -118,13 +131,17 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
startTask()
|
startTask()
|
||||||
|
|
||||||
// Keyboard is sometimes open when going back to the app, so close it.
|
// Keyboard is sometimes open when going back to the app, so close it.
|
||||||
closeKeyboard()
|
closeKeyboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
setClockAlignment()
|
||||||
|
}
|
||||||
|
|
||||||
open inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
open inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
||||||
|
|
@ -513,6 +530,49 @@ class MainActivity : AppCompatActivity(), AppMenuAdapter.OnItemClickListener, Ap
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setClockAlignment() {
|
||||||
|
val clockAlignment = sharedPreferenceManager.getClockAlignment(this@MainActivity)
|
||||||
|
|
||||||
|
val constraintSet = ConstraintSet()
|
||||||
|
constraintSet.clone(constraintLayout)
|
||||||
|
println(clockAlignment)
|
||||||
|
|
||||||
|
/*
|
||||||
|
0 = left
|
||||||
|
1 = center
|
||||||
|
2 = right
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (clockAlignment == 2) {
|
||||||
|
constraintSet.clear(clock.id, ConstraintSet.START)
|
||||||
|
}
|
||||||
|
else if (clockAlignment == 0) {
|
||||||
|
constraintSet.clear(clock.id, ConstraintSet.END)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clockAlignment == 1 || clockAlignment == 0) {
|
||||||
|
constraintSet.connect(
|
||||||
|
clock.id,
|
||||||
|
ConstraintSet.START,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.START,
|
||||||
|
clockMargin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clockAlignment != 0) {
|
||||||
|
constraintSet.connect(
|
||||||
|
clock.id,
|
||||||
|
ConstraintSet.END,
|
||||||
|
ConstraintSet.PARENT_ID,
|
||||||
|
ConstraintSet.END,
|
||||||
|
clockMargin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
constraintSet.applyTo(constraintLayout)
|
||||||
|
}
|
||||||
|
|
||||||
fun isJobActive(): Boolean {
|
fun isJobActive(): Boolean {
|
||||||
return if (job != null) {
|
return if (job != null) {
|
||||||
job!!.isActive
|
job!!.isActive
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,31 @@ package eu.ottop.yamlauncher
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
import android.view.View
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.Spinner
|
||||||
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
|
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity() {
|
class SettingsActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivitySettingsBinding
|
private lateinit var binding: ActivitySettingsBinding
|
||||||
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
binding.clockAlignment.setSelection(sharedPreferenceManager.getClockAlignment(this@SettingsActivity))
|
||||||
|
|
||||||
|
binding.clockAlignment.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) {
|
||||||
|
// Get the selected item
|
||||||
|
sharedPreferenceManager.setClockAlignment(this@SettingsActivity, position)
|
||||||
|
println(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,4 +72,17 @@ class SharedPreferenceManager {
|
||||||
val key = "location"
|
val key = "location"
|
||||||
return sharedPreferences.getString(key, null)
|
return sharedPreferences.getString(key, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setClockAlignment(cont: Context, alignment: Int) {
|
||||||
|
val editor = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE).edit()
|
||||||
|
val key = "clock_alignment"
|
||||||
|
editor.putInt(key, alignment)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getClockAlignment(cont: Context) : Int {
|
||||||
|
val sharedPreferences = cont.getSharedPreferences("preferences", AppCompatActivity.MODE_PRIVATE)
|
||||||
|
val key = "clock_alignment"
|
||||||
|
return sharedPreferences.getInt(key, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +81,7 @@
|
||||||
android:visibility="visible">
|
android:visibility="visible">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/clock_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
tools:context=".SettingsActivity">
|
tools:context=".SettingsActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/clock_alignment"
|
android:id="@+id/clock_alignment_label"
|
||||||
android:layout_width="250dp"
|
android:layout_width="250dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
|
|
@ -24,21 +24,21 @@
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/spinner"
|
app:layout_constraintEnd_toStartOf="@+id/clock_alignment"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintVertical_bias="0.0" />
|
app:layout_constraintVertical_bias="0.0" />
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/spinner"
|
android:id="@+id/clock_alignment"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:entries="@array/clock_alignment_options"
|
android:entries="@array/clock_alignment_options"
|
||||||
android:spinnerMode="dropdown"
|
android:spinnerMode="dropdown"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/clock_alignment"
|
app:layout_constraintBottom_toBottomOf="@+id/clock_alignment_label"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toEndOf="@+id/clock_alignment"
|
app:layout_constraintStart_toEndOf="@+id/clock_alignment_label"
|
||||||
app:layout_constraintTop_toTopOf="@+id/clock_alignment"
|
app:layout_constraintTop_toTopOf="@+id/clock_alignment_label"
|
||||||
app:layout_constraintVertical_bias="0.1" />
|
app:layout_constraintVertical_bias="0.1" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:background="?android:attr/listDivider"
|
android:background="?android:attr/listDivider"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/clock_alignment" />
|
app:layout_constraintBottom_toBottomOf="@+id/clock_alignment_label" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/home_app_alignment"
|
android:id="@+id/home_app_alignment"
|
||||||
|
|
@ -64,7 +64,7 @@
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/spinner"
|
app:layout_constraintEnd_toStartOf="@+id/clock_alignment"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/divider2"
|
app:layout_constraintTop_toBottomOf="@+id/divider2"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue