mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
A bunch more refactoring and app menu exiting behaviour changed a bit.
This commit is contained in:
parent
6ceed365bb
commit
e769baeed0
13 changed files with 196 additions and 169 deletions
|
|
@ -14,12 +14,13 @@ class AboutFragment : Fragment() {
|
|||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_about, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// Set up about page links
|
||||
stringUtils.setLink(requireActivity().findViewById(R.id.creditText), getString(R.string.my_website_link))
|
||||
stringUtils.setLink(requireActivity().findViewById(R.id.codebergLink), getString(R.string.codeberg_link))
|
||||
stringUtils.setLink(requireActivity().findViewById(R.id.githubLink), getString(R.string.github_link))
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class Animations (context: Context) {
|
|||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||
|
||||
// fadeViewIn and fadeViewOut are for smaller item transitions, such as the action menu
|
||||
|
||||
fun fadeViewIn(view: View) {
|
||||
view.fadeIn()
|
||||
}
|
||||
|
|
@ -22,6 +24,7 @@ class Animations (context: Context) {
|
|||
fun fadeViewOut(view: View) {
|
||||
view.fadeOut()
|
||||
}
|
||||
|
||||
fun showHome(homeView: View, appView: View) {
|
||||
appView.slideOutToBottom()
|
||||
homeView.fadeIn()
|
||||
|
|
@ -35,12 +38,9 @@ class Animations (context: Context) {
|
|||
fun backgroundIn(activity: Activity) {
|
||||
val originalColor = sharedPreferenceManager.getBgColor()
|
||||
|
||||
val newColor: Int = if (originalColor == Color.parseColor("#00000000")) {
|
||||
Color.parseColor("#3F000000")
|
||||
} else {
|
||||
originalColor
|
||||
}
|
||||
|
||||
// Only animate darkness onto the transparent background
|
||||
if (originalColor == Color.parseColor("#00000000")) {
|
||||
val newColor = Color.parseColor("#3F000000")
|
||||
val colorDrawable = ColorDrawable(originalColor)
|
||||
activity.window.setBackgroundDrawable(colorDrawable)
|
||||
|
||||
|
|
@ -48,21 +48,22 @@ class Animations (context: Context) {
|
|||
backgroundColorAnimator.addUpdateListener { animator ->
|
||||
colorDrawable.color = animator.animatedValue as Int
|
||||
}
|
||||
|
||||
val duration = sharedPreferenceManager.getAnimationSpeed()
|
||||
backgroundColorAnimator.duration = duration
|
||||
|
||||
backgroundColorAnimator.start()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fun backgroundOut(activity: Activity) {
|
||||
val newColor = sharedPreferenceManager.getBgColor()
|
||||
|
||||
val originalColor: Int = if (newColor == Color.parseColor("#00000000")) {
|
||||
Color.parseColor("#3F000000")
|
||||
} else {
|
||||
newColor
|
||||
}
|
||||
|
||||
// Only animate darkness onto the transparent background
|
||||
if (newColor == Color.parseColor("#00000000")) {
|
||||
val originalColor = Color.parseColor("#3F000000")
|
||||
val colorDrawable = ColorDrawable(originalColor)
|
||||
activity.window.setBackgroundDrawable(colorDrawable)
|
||||
|
||||
|
|
@ -70,10 +71,14 @@ class Animations (context: Context) {
|
|||
backgroundColorAnimator.addUpdateListener { animator ->
|
||||
colorDrawable.color = animator.animatedValue as Int
|
||||
}
|
||||
|
||||
val duration = sharedPreferenceManager.getAnimationSpeed()
|
||||
backgroundColorAnimator.duration = duration
|
||||
|
||||
backgroundColorAnimator.start()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
private fun View.slideInFromBottom() {
|
||||
if (visibility != View.VISIBLE) {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ class AppActionMenu {
|
|||
val sharedPreferenceManager = SharedPreferenceManager(activity)
|
||||
|
||||
actionMenu.findViewById<TextView>(R.id.info).setOnClickListener {
|
||||
|
||||
// Launch app info in phone settings
|
||||
if (mainActivity != null) {
|
||||
launcherApps.startAppDetailsActivity(
|
||||
mainActivity.componentName,
|
||||
|
|
@ -75,6 +77,7 @@ class AppActionMenu {
|
|||
searchView.visibility = View.INVISIBLE
|
||||
editText.requestFocus()
|
||||
|
||||
// Open keyboard
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
handler.postDelayed({
|
||||
val imm =
|
||||
|
|
@ -83,6 +86,8 @@ class AppActionMenu {
|
|||
}, 100)
|
||||
|
||||
binding.root.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
|
||||
// If the keyboard is closed, exit editing mode
|
||||
if (bottom - top > oldBottom - oldTop) {
|
||||
editLayout.clearFocus()
|
||||
|
||||
|
|
@ -93,6 +98,8 @@ class AppActionMenu {
|
|||
}
|
||||
|
||||
editText.setOnEditorActionListener { _, actionId, _ ->
|
||||
|
||||
// Once the new name is confirmed, close the keyboard, save the new app name and update the apps on screen
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
val imm =
|
||||
activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
|
@ -113,6 +120,8 @@ class AppActionMenu {
|
|||
}
|
||||
|
||||
resetButton.setOnClickListener {
|
||||
|
||||
// If reset is pressed, close keyboard, remove saved edited name and update the apps on screen
|
||||
val imm =
|
||||
activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(editLayout.windowToken, 0)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class AppMenuAdapter(
|
|||
) :
|
||||
RecyclerView.Adapter<AppMenuAdapter.AppViewHolder>() {
|
||||
|
||||
// If the menu is opened to select shortcuts, the below variable is set
|
||||
var shortcutTextView: TextView? = null
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||
|
|
@ -52,8 +53,7 @@ class AppMenuAdapter(
|
|||
textView: TextView,
|
||||
actionMenuLayout: LinearLayout,
|
||||
editView: LinearLayout,
|
||||
position: Int,
|
||||
shortcutTextView: TextView?
|
||||
position: Int
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +71,8 @@ class AppMenuAdapter(
|
|||
textView.setOnClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
val app = apps[position].first
|
||||
|
||||
// If opened to select a shortcut, set the shortcut instead of launching the app
|
||||
if (shortcutTextView != null) {
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
}
|
||||
|
|
@ -79,11 +81,17 @@ class AppMenuAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
textView.setOnLongClickListener {
|
||||
val position = bindingAdapterPosition
|
||||
|
||||
val app = apps[position].first
|
||||
|
||||
// If opened to select a shortcut, set the shortcut instead of opening the action menu
|
||||
if (shortcutTextView != null) {
|
||||
shortcutListener.onShortcut(app, apps[position].second.first, textView, apps[position].second.second, shortcutTextView!!)
|
||||
return@setOnLongClickListener true
|
||||
} else {
|
||||
|
||||
itemLongClickListener.onItemLongClick(
|
||||
app,
|
||||
apps[position].second.first,
|
||||
|
|
@ -91,11 +99,10 @@ class AppMenuAdapter(
|
|||
textView,
|
||||
actionMenuLayout,
|
||||
editView,
|
||||
position,
|
||||
shortcutTextView
|
||||
position
|
||||
)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
}}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -109,6 +116,7 @@ class AppMenuAdapter(
|
|||
override fun onBindViewHolder(holder: AppViewHolder, position: Int) {
|
||||
val app = apps[position]
|
||||
|
||||
// Set initial drawables
|
||||
if (app.second.second != 0) {
|
||||
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null)
|
||||
holder.textView.compoundDrawables[0].colorFilter =
|
||||
|
|
@ -122,12 +130,15 @@ class AppMenuAdapter(
|
|||
|
||||
uiUtils.setAppSize(holder.textView, holder.editText)
|
||||
|
||||
// Update the application information (allows updating apps to work)
|
||||
val appInfo = appUtils.getAppInfo(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second
|
||||
)
|
||||
|
||||
holder.textView.setTextColor(sharedPreferenceManager.getTextColor())
|
||||
|
||||
// Set app name on the menu. If the app has been uninstalled, replace it with "Removing" until the app menu updates.
|
||||
val appLabel: CharSequence = appInfo?.loadLabel(context.packageManager) ?: "Removing..."
|
||||
|
||||
if (appInfo != null) {
|
||||
|
|
@ -139,6 +150,7 @@ class AppMenuAdapter(
|
|||
|
||||
holder.editText.setText(holder.textView.text)
|
||||
|
||||
// Remove the uninstall icon for system apps
|
||||
if (appInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) {
|
||||
holder.actionMenuLayout.findViewById<TextView>(R.id.uninstall).visibility =
|
||||
View.GONE
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ class AppMenuEdgeFactory(private val activity: Activity) : RecyclerView.EdgeEffe
|
|||
}
|
||||
|
||||
inner class AppMenuEdgeEffect(activity: Activity) : EdgeEffect(activity) {
|
||||
|
||||
//This just speeds up the animation when the scrolling hits the edge so that the app menu can be exited sooner
|
||||
private val animationSpeedFactor = 0.75f
|
||||
|
||||
override fun onAbsorb(velocity: Int) {
|
||||
super.onAbsorb((velocity * animationSpeedFactor).toInt())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ class AppMenuLinearLayoutManager(private val activity: MainActivity) : LinearLay
|
|||
val scrollRange = super.scrollVerticallyBy(dy, recycler, state)
|
||||
val overscroll: Int = dy - scrollRange
|
||||
|
||||
if (overscroll < 0 && firstVisibleItemPosition == 0 && scrollStarted && activity.isJobActive) {
|
||||
// If the user scrolls up when already on top, go back to home. Only if the keyboard isn't open, though
|
||||
if (overscroll < 0 && (firstVisibleItemPosition == 0 || firstVisibleItemPosition < 0) && scrollStarted && activity.canExit) {
|
||||
activity.backToHome()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,18 +17,19 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
withContext(Dispatchers.Default) {
|
||||
for (i in launcherApps.profiles.indices) {
|
||||
for (i in launcherApps.profiles.indices) { // Check apps on both, normal and work profiles
|
||||
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||
if (!sharedPreferenceManager.isAppHidden(
|
||||
if (!sharedPreferenceManager.isAppHidden( // Only include the app if it isn't set as hidden
|
||||
app.applicationInfo.packageName,
|
||||
i
|
||||
) && app.applicationInfo.packageName != context.applicationInfo.packageName
|
||||
) && app.applicationInfo.packageName != context.applicationInfo.packageName // Hide the launcher itself
|
||||
) {
|
||||
allApps.add(Pair(app, Pair(launcherApps.profiles[i], i)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort apps by name
|
||||
sortedApps = allApps.sortedBy {
|
||||
sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
|
|
@ -41,8 +42,11 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
|
||||
}
|
||||
|
||||
fun getHiddenApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||
// Get hidden apps for the hidden apps settings
|
||||
suspend fun getHiddenApps(): List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> {
|
||||
val allApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
var sortedApps = listOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
withContext(Dispatchers.Default) {
|
||||
for (i in launcherApps.profiles.indices) {
|
||||
launcherApps.getActivityList(null, launcherApps.profiles[i]).forEach { app ->
|
||||
if (sharedPreferenceManager.isAppHidden(app.applicationInfo.packageName, i)) {
|
||||
|
|
@ -50,7 +54,8 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
}
|
||||
}
|
||||
}
|
||||
return allApps.sortedBy {
|
||||
|
||||
sortedApps = allApps.sortedBy {
|
||||
sharedPreferenceManager.getAppName(
|
||||
it.first.applicationInfo.packageName,
|
||||
it.second.second,
|
||||
|
|
@ -58,6 +63,8 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
|
|||
).toString().lowercase()
|
||||
}
|
||||
}
|
||||
return sortedApps
|
||||
}
|
||||
|
||||
fun getAppInfo(
|
||||
packageName: String,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class BatteryReceiver(private val activity: MainActivity) : BroadcastReceiver()
|
|||
val level = it.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
|
||||
val scale = it.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
|
||||
val batteryPct = level * 100 / scale.toFloat()
|
||||
activity.modifyDate("${batteryPct.toInt()}%", 3)
|
||||
activity.modifyDate("${batteryPct.toInt()}%", 3) // Add battery to the date
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,9 @@ class GestureAppsAdapter(
|
|||
|
||||
uiUtils.setAppSize(holder.textView)
|
||||
|
||||
// Does not need to be specially updated since it's in a separate activity and thus reloads when opened again
|
||||
val appInfo = app.first.activityInfo.applicationInfo
|
||||
|
||||
holder.textView.text = sharedPreferenceManager.getAppName(
|
||||
app.first.applicationInfo.packageName,
|
||||
app.second.second,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_gesture_apps, container, false)
|
||||
}
|
||||
|
||||
|
|
@ -46,16 +45,12 @@ class GestureAppsFragment : Fragment(), GestureAppsAdapter.OnItemClickListener {
|
|||
|
||||
lifecycleScope.launch {
|
||||
|
||||
withContext(Dispatchers.Default) {
|
||||
|
||||
|
||||
|
||||
adapter = GestureAppsAdapter(
|
||||
requireContext(),
|
||||
appUtils.getInstalledApps().toMutableList(),
|
||||
this@GestureAppsFragment
|
||||
)
|
||||
}
|
||||
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.gestureAppRecycler)
|
||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||
val uiUtils = UIUtils(requireContext())
|
||||
|
|
|
|||
|
|
@ -13,8 +13,10 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
||||
|
||||
|
|
@ -40,10 +42,12 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
appUtils = AppUtils(requireContext(), launcherApps)
|
||||
sharedPreferenceManager = SharedPreferenceManager(requireContext())
|
||||
|
||||
lifecycleScope.launch {
|
||||
|
||||
val recyclerView = view.findViewById<RecyclerView>(R.id.hiddenAppRecycler)
|
||||
val appMenuEdgeFactory = AppMenuEdgeFactory(requireActivity())
|
||||
|
||||
adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps().toMutableList(), this)
|
||||
adapter = HiddenAppsAdapter(requireContext(), appUtils.getHiddenApps().toMutableList(), this@HiddenAppsFragment)
|
||||
|
||||
|
||||
recyclerView.edgeEffectFactory = appMenuEdgeFactory
|
||||
|
|
@ -74,8 +78,9 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
|
||||
lifecycleScope.launch {
|
||||
filterItems(searchView.text.toString())
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
|
@ -87,8 +92,9 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
imm.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun filterItems(query: String?) {
|
||||
private suspend fun filterItems(query: String?) {
|
||||
|
||||
val cleanQuery = stringUtils.cleanString(query)
|
||||
val newFilteredApps = mutableListOf<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>()
|
||||
|
|
@ -128,15 +134,17 @@ class HiddenAppsFragment : Fragment(), HiddenAppsAdapter.OnItemClickListener {
|
|||
setTitle("Confirmation")
|
||||
setMessage("Are you sure you want to unhide $appName?")
|
||||
setPositiveButton("Yes") { _, _ ->
|
||||
lifecycleScope.launch {
|
||||
performConfirmedAction(appInfo, profile)
|
||||
}
|
||||
}
|
||||
|
||||
setNegativeButton("Cancel") { _, _ ->
|
||||
}
|
||||
}.create().show()
|
||||
}
|
||||
|
||||
private fun performConfirmedAction(appInfo: LauncherActivityInfo, profile: Int) {
|
||||
private suspend fun performConfirmedAction(appInfo: LauncherActivityInfo, profile: Int) {
|
||||
sharedPreferenceManager.setAppVisible(appInfo.applicationInfo.packageName, profile)
|
||||
adapter?.updateApps(appUtils.getHiddenApps())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
private lateinit var preferences: SharedPreferences
|
||||
|
||||
private var isBatteryReceiverRegistered = false
|
||||
var isJobActive = true
|
||||
private var isJobActive = true
|
||||
var canExit = true
|
||||
|
||||
private val swipeThreshold = 100
|
||||
private val swipeVelocityThreshold = 100
|
||||
|
|
@ -502,8 +503,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
recyclerView.addOnLayoutChangeListener { _, _, top, _, bottom, _, oldTop, _, oldBottom ->
|
||||
|
||||
if (bottom - top > oldBottom - oldTop) {
|
||||
canExit = true
|
||||
searchView.clearFocus()
|
||||
}
|
||||
else if (bottom - top < oldBottom - oldTop) {
|
||||
canExit = false
|
||||
}
|
||||
}
|
||||
|
||||
searchView.addTextChangedListener(object :
|
||||
|
|
@ -625,7 +630,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
appInfo.applicationInfo.packageName,
|
||||
userProfile
|
||||
)
|
||||
uiUtils.setShortcutDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment())
|
||||
uiUtils.setDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment())
|
||||
backToHome()
|
||||
}
|
||||
|
||||
|
|
@ -637,13 +642,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
textView: TextView,
|
||||
actionMenuLayout: LinearLayout,
|
||||
editView: LinearLayout,
|
||||
position: Int,
|
||||
shortcutTextView: TextView?
|
||||
position: Int
|
||||
) {
|
||||
if (shortcutTextView != null) {
|
||||
onShortcut(appInfo, userHandle, textView, userProfile, shortcutTextView)
|
||||
return
|
||||
}
|
||||
textView.visibility = View.INVISIBLE
|
||||
animations.fadeViewIn(actionMenuLayout)
|
||||
val mainActivity =
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||
import android.graphics.BlendMode
|
||||
import android.graphics.BlendModeColorFilter
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -15,17 +14,14 @@ import android.view.WindowInsetsController
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.TextClock
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.children
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
|
||||
class UIUtils(private val context: Context) {
|
||||
class UIUtils(context: Context) {
|
||||
|
||||
private val sharedPreferenceManager = SharedPreferenceManager(context)
|
||||
|
||||
fun setBackground(window: Window) {
|
||||
window.decorView.background = ColorDrawable(Color.parseColor("#00000000"))
|
||||
|
||||
window.decorView.setBackgroundColor(
|
||||
sharedPreferenceManager.getBgColor()
|
||||
)
|
||||
|
|
@ -97,38 +93,23 @@ class UIUtils(private val context: Context) {
|
|||
fun setShortcutsAlignment(shortcuts: LinearLayout) {
|
||||
val alignment = sharedPreferenceManager.getShortcutAlignment()
|
||||
shortcuts.children.forEach {
|
||||
|
||||
if (it is TextView) {
|
||||
setTextGravity(it, alignment)
|
||||
setDrawables(it, alignment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun setDrawables(shortcut: TextView, alignment: String?) {
|
||||
try {
|
||||
setShortcutAlignment(it, alignment)
|
||||
setShortcutDrawables(it, alignment)
|
||||
} catch(_: Exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setShortcutAlignment(shortcut: TextView, alignment: String?) {
|
||||
when (alignment) {
|
||||
"left" -> {
|
||||
shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||
}
|
||||
|
||||
"center" -> {
|
||||
shortcut.gravity = Gravity.CENTER
|
||||
}
|
||||
|
||||
"right" -> {
|
||||
shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setShortcutDrawables(shortcut: TextView, alignment: String?) {
|
||||
when (alignment) {
|
||||
"left" -> {
|
||||
shortcut.setCompoundDrawablesWithIntrinsicBounds(
|
||||
shortcut.compoundDrawables.filterNotNull().first(), null, null, null
|
||||
shortcut.compoundDrawables.filterNotNull().first(),
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -150,37 +131,25 @@ class UIUtils(private val context: Context) {
|
|||
)
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setAppAlignment(
|
||||
textView: TextView,
|
||||
editText: TextInputEditText? = null,
|
||||
editText: TextView? = null,
|
||||
regionText: TextView? = null
|
||||
) {
|
||||
val alignment = sharedPreferenceManager.getAppAlignment()
|
||||
setTextGravity(textView, alignment)
|
||||
|
||||
if (regionText != null) {
|
||||
setTextGravity(textView, alignment)
|
||||
setTextGravity(regionText, alignment)
|
||||
return
|
||||
}
|
||||
|
||||
when (alignment) {
|
||||
"left" -> {
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null), null)
|
||||
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.START
|
||||
|
||||
}
|
||||
"center" -> {
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(textView.compoundDrawables.filterNotNull().first(),null, textView.compoundDrawables.filterNotNull().first(), null)
|
||||
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||
|
||||
}
|
||||
"right" -> {
|
||||
textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_empty, null),null, textView.compoundDrawables.filterNotNull().first(), null)
|
||||
editText?.gravity = Gravity.CENTER_VERTICAL or Gravity.END
|
||||
}
|
||||
if (editText != null) {
|
||||
setDrawables(textView, alignment)
|
||||
setTextGravity(editText, alignment)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -195,6 +164,7 @@ class UIUtils(private val context: Context) {
|
|||
}
|
||||
|
||||
private fun setTextAlignment(view: TextView, alignment: String?) {
|
||||
try {
|
||||
view.textAlignment = when (alignment) {
|
||||
"left" -> View.TEXT_ALIGNMENT_VIEW_START
|
||||
|
||||
|
|
@ -204,9 +174,11 @@ class UIUtils(private val context: Context) {
|
|||
|
||||
else -> View.TEXT_ALIGNMENT_VIEW_START
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
private fun setTextGravity(view: TextView, alignment: String?) {
|
||||
try {
|
||||
view.gravity = when (alignment) {
|
||||
"left" -> Gravity.CENTER_VERTICAL or Gravity.START
|
||||
|
||||
|
|
@ -216,6 +188,7 @@ class UIUtils(private val context: Context) {
|
|||
|
||||
else -> Gravity.CENTER_VERTICAL or Gravity.START
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setClockSize(clock: TextClock) {
|
||||
|
|
@ -227,6 +200,7 @@ class UIUtils(private val context: Context) {
|
|||
}
|
||||
|
||||
fun setShortcutsSize(shortcuts: LinearLayout) {
|
||||
val alignment = sharedPreferenceManager.getShortcutSize()
|
||||
|
||||
val viewTreeObserver = shortcuts.viewTreeObserver
|
||||
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
|
@ -234,30 +208,8 @@ class UIUtils(private val context: Context) {
|
|||
|
||||
shortcuts.children.forEach {
|
||||
if (it is TextView) {
|
||||
setShortcutSize(it, alignment)
|
||||
|
||||
when (sharedPreferenceManager.getShortcutSize()) {
|
||||
"small" -> {
|
||||
it.setPadding(
|
||||
it.paddingLeft,
|
||||
it.height / 4,
|
||||
it.paddingRight,
|
||||
it.height / 4
|
||||
)
|
||||
}
|
||||
|
||||
"medium" -> {
|
||||
it.setPadding(
|
||||
it.paddingLeft,
|
||||
(it.height / 4.5).toInt(),
|
||||
it.paddingRight,
|
||||
(it.height / 4.5).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
"large" -> {
|
||||
it.setPadding(it.paddingLeft, 0, it.paddingRight, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (viewTreeObserver.isAlive) {
|
||||
|
|
@ -271,6 +223,34 @@ class UIUtils(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setShortcutSize(shortcut: TextView, alignment: String?) {
|
||||
try {
|
||||
when (alignment) {
|
||||
"small" -> {
|
||||
shortcut.setPadding(
|
||||
shortcut.paddingLeft,
|
||||
shortcut.height / 4,
|
||||
shortcut.paddingRight,
|
||||
shortcut.height / 4
|
||||
)
|
||||
}
|
||||
|
||||
"medium" -> {
|
||||
shortcut.setPadding(
|
||||
shortcut.paddingLeft,
|
||||
(shortcut.height / 4.5).toInt(),
|
||||
shortcut.paddingRight,
|
||||
(shortcut.height / 4.5).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
"large" -> {
|
||||
shortcut.setPadding(shortcut.paddingLeft, 0, shortcut.paddingRight, 0)
|
||||
}
|
||||
}
|
||||
} catch(_: Exception) {}
|
||||
}
|
||||
|
||||
fun setAppSize(
|
||||
textView: TextView,
|
||||
editText: TextInputEditText? = null,
|
||||
|
|
@ -291,6 +271,7 @@ class UIUtils(private val context: Context) {
|
|||
}
|
||||
|
||||
private fun setTextSize(view: TextView, size: String?, s: Float, m: Float, l: Float) {
|
||||
try {
|
||||
view.textSize = when (size) {
|
||||
"small" -> s
|
||||
|
||||
|
|
@ -298,9 +279,12 @@ class UIUtils(private val context: Context) {
|
|||
|
||||
"large" -> l
|
||||
|
||||
else -> {0F}
|
||||
else -> {
|
||||
0F
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setStatusBar(window: Window) {
|
||||
val windowInsetsController = window.insetsController
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue