mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-05 09:57:26 +00:00
Alignment, Size and Gesture settings now work
This commit is contained in:
parent
40c3e2dd72
commit
01f1be6235
3 changed files with 89 additions and 83 deletions
|
|
@ -19,6 +19,7 @@ import androidx.appcompat.widget.AppCompatButton
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.marginLeft
|
import androidx.core.view.marginLeft
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class AppMenuAdapter(
|
class AppMenuAdapter(
|
||||||
|
|
@ -34,6 +35,7 @@ class AppMenuAdapter(
|
||||||
var shortcutTextView: TextView? = null
|
var shortcutTextView: TextView? = null
|
||||||
|
|
||||||
private val sharedPreferenceManager = SharedPreferenceManager()
|
private val sharedPreferenceManager = SharedPreferenceManager()
|
||||||
|
private var preferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
|
|
||||||
interface OnItemClickListener {
|
interface OnItemClickListener {
|
||||||
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle)
|
||||||
|
|
@ -115,46 +117,34 @@ class AppMenuAdapter(
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,null,null)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
when (preferences.getString("appMenuAlignment", "left")) {
|
||||||
0 = left
|
"left" -> {
|
||||||
1 = center
|
|
||||||
2 = right
|
|
||||||
*/
|
|
||||||
when (sharedPreferenceManager.getAppMenuAlignment(activity)) {
|
|
||||||
0 -> {
|
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null, null, null)
|
||||||
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||||
}
|
}
|
||||||
1 -> {
|
"center" -> {
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(holder.textView.compoundDrawables.filterNotNull().first(),null,holder.textView.compoundDrawables.filterNotNull().first(), null)
|
||||||
holder.textView.gravity = Gravity.CENTER
|
holder.textView.gravity = Gravity.CENTER
|
||||||
|
|
||||||
}
|
}
|
||||||
2 -> {
|
"right" -> {
|
||||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null)
|
holder.textView.setCompoundDrawablesWithIntrinsicBounds(null,null, holder.textView.compoundDrawables.filterNotNull().first(), null)
|
||||||
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
holder.textView.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
when (preferences.getString("appMenuSize", "medium")) {
|
||||||
0 = small
|
"small" -> {
|
||||||
1 = medium
|
|
||||||
2 = large
|
|
||||||
|
|
||||||
Text sizes hardcoded because code returns 77 instead of 28
|
|
||||||
*/
|
|
||||||
when (sharedPreferenceManager.getAppSize(activity)) {
|
|
||||||
0 -> {
|
|
||||||
holder.textView.textSize = 24F
|
holder.textView.textSize = 24F
|
||||||
holder.editText.textSize = 24F
|
holder.editText.textSize = 24F
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
"medium" -> {
|
||||||
holder.textView.textSize = 26F
|
holder.textView.textSize = 26F
|
||||||
holder.editText.textSize = 26F
|
holder.editText.textSize = 26F
|
||||||
}
|
}
|
||||||
|
|
||||||
2 -> {
|
"large" -> {
|
||||||
holder.textView.textSize = 28F
|
holder.textView.textSize = 28F
|
||||||
holder.editText.textSize = 28F
|
holder.editText.textSize = 28F
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,20 @@ class AppUtils {
|
||||||
sharedPreferenceManager.getAppName(activity, it.first.applicationInfo.packageName,it.second.second, activity.packageManager.getApplicationLabel(it.first.applicationInfo)).toString().lowercase()
|
sharedPreferenceManager.getAppName(activity, it.first.applicationInfo.packageName,it.second.second, activity.packageManager.getApplicationLabel(it.first.applicationInfo)).toString().lowercase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getHiddenApps(activity: Activity): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||||
|
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||||
|
val launcherApps = activity.getSystemService(AppCompatActivity.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||||
|
for (i in launcherApps.profiles.indices) {
|
||||||
|
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||||
|
if (sharedPreferenceManager.isAppHidden(activity, app.applicationInfo.packageName, i)) {
|
||||||
|
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allApps.sortedBy {
|
||||||
|
sharedPreferenceManager.getAppName(activity, it.first.applicationInfo.packageName,it.second.second, activity.packageManager.getApplicationLabel(it.first.applicationInfo)).toString().lowercase()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,6 @@ 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.activity.viewModels
|
|
||||||
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.ConstraintLayout
|
||||||
|
|
@ -74,12 +73,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
private lateinit var clock: TextClock
|
private lateinit var clock: TextClock
|
||||||
private var clockMargin = 0
|
private var clockMargin = 0
|
||||||
private lateinit var constraintLayout: ConstraintLayout
|
private lateinit var clockLayout: ConstraintLayout
|
||||||
|
|
||||||
private lateinit var dateText: TextClock
|
private lateinit var dateText: TextClock
|
||||||
|
|
||||||
private var cameraSwipeEnabled = true
|
private var cameraSwipeEnabled = true
|
||||||
private var contactsSwipeEnabled = true
|
private var phoneSwipeEnabled = true
|
||||||
|
|
||||||
private lateinit var preferences: SharedPreferences
|
private lateinit var preferences: SharedPreferences
|
||||||
|
|
||||||
|
|
@ -105,7 +104,9 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
clockMargin = clock.marginLeft
|
clockMargin = clock.marginLeft
|
||||||
|
|
||||||
constraintLayout = findViewById(R.id.clock_layout)
|
clockLayout = findViewById(R.id.clock_layout)
|
||||||
|
|
||||||
|
dateText = findViewById(R.id.text_date)
|
||||||
|
|
||||||
setClockAlignment(preferences.getString("clockAlignment", "left"), clock.id, clockMargin)
|
setClockAlignment(preferences.getString("clockAlignment", "left"), clock.id, clockMargin)
|
||||||
|
|
||||||
|
|
@ -113,7 +114,15 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
|
|
||||||
setShortcutAlignment(preferences.getString("shortcutAlignment", "left"), binding.homeView)
|
setShortcutAlignment(preferences.getString("shortcutAlignment", "left"), binding.homeView)
|
||||||
|
|
||||||
dateText = findViewById(R.id.text_date)
|
setSearchAlignment(preferences.getString("searchAlignment", "left"))
|
||||||
|
|
||||||
|
setClockSize(preferences.getString("clockSize","medium"))
|
||||||
|
|
||||||
|
setDateSize(preferences.getString("dateSize", "medium"))
|
||||||
|
|
||||||
|
setShortcutSize(binding.homeView, preferences.getString("shortcutSize", "medium"))
|
||||||
|
|
||||||
|
setSearchSize(preferences.getString("searchSize", "medium"))
|
||||||
|
|
||||||
batteryReceiver = BatteryReceiver.register(this, dateText)
|
batteryReceiver = BatteryReceiver.register(this, dateText)
|
||||||
|
|
||||||
|
|
@ -141,6 +150,26 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
"shortcutAlignment" -> {
|
"shortcutAlignment" -> {
|
||||||
setShortcutAlignment(preferences?.getString("shortcutAlignment", "left"), binding.homeView)
|
setShortcutAlignment(preferences?.getString("shortcutAlignment", "left"), binding.homeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"searchAlignment" -> {
|
||||||
|
setSearchAlignment(preferences?.getString("searchAlignment", "left"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"clockSize" -> {
|
||||||
|
setClockSize(preferences?.getString("clockSize","medium"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"dateSize" -> {
|
||||||
|
setDateSize(preferences?.getString("dateSize", "medium"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"shortcutSize" -> {
|
||||||
|
setShortcutSize(binding.homeView, preferences?.getString("shortcutSize", "medium"))
|
||||||
|
}
|
||||||
|
|
||||||
|
"searchSize" -> {
|
||||||
|
setSearchSize(preferences?.getString("searchSize", "medium"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,10 +201,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setTextSizes()
|
|
||||||
setSearchAlignment()
|
|
||||||
|
|
||||||
setGestures()
|
|
||||||
|
|
||||||
adapter?.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
@ -208,12 +233,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect swipe left
|
// Detect swipe left
|
||||||
else if (cameraSwipeEnabled && deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold){
|
else if (deltaX < -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("cameraSwipe", true)){
|
||||||
startActivity(cameraIntent)
|
startActivity(cameraIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect swipe right
|
// Detect swipe right
|
||||||
else if (contactsSwipeEnabled && deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold) {
|
else if (deltaX > -swipeThreshold && abs(velocityX) > swipeVelocityThreshold && preferences.getBoolean("phoneSwipe", true)) {
|
||||||
startActivity(phoneIntent)
|
startActivity(phoneIntent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -566,7 +591,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
private fun setClockAlignment(alignment: String?, widgetId: Int, margin: Int) {
|
private fun setClockAlignment(alignment: String?, widgetId: Int, margin: Int) {
|
||||||
|
|
||||||
val constraintSet = ConstraintSet()
|
val constraintSet = ConstraintSet()
|
||||||
constraintSet.clone(constraintLayout)
|
constraintSet.clone(clockLayout)
|
||||||
println(alignment)
|
println(alignment)
|
||||||
|
|
||||||
if (alignment == "right") {
|
if (alignment == "right") {
|
||||||
|
|
@ -597,7 +622,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
constraintSet.applyTo(constraintLayout)
|
constraintSet.applyTo(clockLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setShortcutAlignment(alignment: String?, shortcuts: LinearLayout) {
|
private fun setShortcutAlignment(alignment: String?, shortcuts: LinearLayout) {
|
||||||
|
|
@ -625,40 +650,30 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setSearchAlignment() {
|
private fun setSearchAlignment(alignment: String?) {
|
||||||
|
|
||||||
/*
|
when (alignment) {
|
||||||
0 = left
|
"left" -> {
|
||||||
1 = center
|
|
||||||
2 = right
|
|
||||||
*/
|
|
||||||
when (sharedPreferenceManager.getSearchAlignment(this@MainActivity)) {
|
|
||||||
0 -> {
|
|
||||||
searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START
|
searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START
|
||||||
}
|
}
|
||||||
1 -> {
|
"center" -> {
|
||||||
searchView.textAlignment = View.TEXT_ALIGNMENT_CENTER
|
searchView.textAlignment = View.TEXT_ALIGNMENT_CENTER
|
||||||
}
|
}
|
||||||
2 -> {
|
"right" -> {
|
||||||
searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END
|
searchView.textAlignment = View.TEXT_ALIGNMENT_VIEW_END
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setShortcutSize(shortcuts: LinearLayout) {
|
private fun setShortcutSize(shortcuts: LinearLayout, size: String?) {
|
||||||
val viewTreeObserver = shortcuts.viewTreeObserver
|
val viewTreeObserver = shortcuts.viewTreeObserver
|
||||||
if (viewTreeObserver.isAlive) {
|
if (viewTreeObserver.isAlive) {
|
||||||
viewTreeObserver.addOnGlobalLayoutListener {
|
viewTreeObserver.addOnGlobalLayoutListener {
|
||||||
shortcuts.children.forEach {
|
shortcuts.children.forEach {
|
||||||
if (it is TextView) {
|
if (it is TextView) {
|
||||||
|
|
||||||
/*
|
when (size) {
|
||||||
0 = small
|
"small" -> {
|
||||||
1 = medium
|
|
||||||
2 = large
|
|
||||||
*/
|
|
||||||
when (sharedPreferenceManager.getShortcutSize(this@MainActivity)) {
|
|
||||||
0 -> {
|
|
||||||
it.setPadding(
|
it.setPadding(
|
||||||
it.paddingLeft,
|
it.paddingLeft,
|
||||||
it.height / 4,
|
it.height / 4,
|
||||||
|
|
@ -667,7 +682,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
"medium" -> {
|
||||||
it.setPadding(
|
it.setPadding(
|
||||||
it.paddingLeft,
|
it.paddingLeft,
|
||||||
(it.height / 4.5).toInt(),
|
(it.height / 4.5).toInt(),
|
||||||
|
|
@ -676,7 +691,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
2 -> {
|
"large" -> {
|
||||||
it.setPadding(it.paddingLeft, 0, it.paddingRight, 0)
|
it.setPadding(it.paddingLeft, 0, it.paddingRight, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -687,59 +702,46 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setTextSizes() {
|
private fun setClockSize(size: String?) {
|
||||||
setShortcutSize(binding.homeView)
|
when (size) {
|
||||||
|
"small" -> {
|
||||||
/*
|
|
||||||
0 = small
|
|
||||||
1 = medium
|
|
||||||
2 = large
|
|
||||||
*/
|
|
||||||
|
|
||||||
when (sharedPreferenceManager.getClockSize(this@MainActivity)) {
|
|
||||||
0 -> {
|
|
||||||
clock.textSize = 48F
|
clock.textSize = 48F
|
||||||
}
|
}
|
||||||
1 -> {
|
"medium" -> {
|
||||||
clock.textSize = 58F
|
clock.textSize = 58F
|
||||||
}
|
}
|
||||||
2 -> {
|
"large" -> {
|
||||||
clock.textSize = 68F
|
clock.textSize = 68F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when (sharedPreferenceManager.getDateSize(this@MainActivity)) {
|
|
||||||
0 -> {
|
|
||||||
dateText.textSize = 17F
|
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
dateText.textSize = 20F
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
dateText.textSize = 23F
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
when (sharedPreferenceManager.getSearchSize(this@MainActivity)) {
|
|
||||||
0 -> {
|
|
||||||
searchView.textSize = 21F
|
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
searchView.textSize = 23F
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
searchView.textSize = 25F
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setGestures() {
|
private fun setDateSize(size: String?) {
|
||||||
val cameraGesture = sharedPreferenceManager.getCameraEnabled(this@MainActivity)
|
when (size) {
|
||||||
val contactsGesture = sharedPreferenceManager.getContactsEnabled(this@MainActivity)
|
"small" -> {
|
||||||
|
dateText.textSize = 17F
|
||||||
|
}
|
||||||
|
"medium" -> {
|
||||||
|
dateText.textSize = 20F
|
||||||
|
}
|
||||||
|
"large" -> {
|
||||||
|
dateText.textSize = 23F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cameraSwipeEnabled = cameraGesture
|
private fun setSearchSize(size: String?) {
|
||||||
|
when (size) {
|
||||||
contactsSwipeEnabled = contactsGesture
|
"small" -> {
|
||||||
|
searchView.textSize = 21F
|
||||||
|
}
|
||||||
|
"medium" -> {
|
||||||
|
searchView.textSize = 23F
|
||||||
|
}
|
||||||
|
"large" -> {
|
||||||
|
searchView.textSize = 25F
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isJobActive(): Boolean {
|
fun isJobActive(): Boolean {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue