Background and text color can now be changed

This commit is contained in:
ottoptj 2024-08-02 20:49:59 +03:00
commit dfc08513f5
11 changed files with 209 additions and 38 deletions

View file

@ -6,6 +6,7 @@ import android.animation.ArgbEvaluator
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.app.Activity import android.app.Activity
import android.graphics.Color
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
@ -31,9 +32,13 @@ class Animations () {
binding.appView.slideInFromBottom() binding.appView.slideInFromBottom()
} }
fun backgroundIn(activity: Activity, duration: Long = 100) { fun backgroundIn(activity: Activity, originalColor: Int, duration: Long = 100) {
val originalColor = ContextCompat.getColor(activity, R.color.original_color)
val newColor = ContextCompat.getColor(activity, R.color.new_color) val newColor: Int = if (originalColor == Color.parseColor("#00000000")) {
Color.parseColor("#3F000000")
} else {
originalColor
}
val colorDrawable = ColorDrawable(originalColor) val colorDrawable = ColorDrawable(originalColor)
activity.window.setBackgroundDrawable(colorDrawable) activity.window.setBackgroundDrawable(colorDrawable)
@ -47,9 +52,13 @@ class Animations () {
backgroundColorAnimator.start() backgroundColorAnimator.start()
} }
fun backgroundOut(activity: Activity, duration: Long = 100) { fun backgroundOut(activity: Activity, newColor: Int, duration: Long = 100) {
val originalColor = ContextCompat.getColor(activity, R.color.new_color)
val newColor = ContextCompat.getColor(activity, R.color.original_color) val originalColor: Int = if (newColor == Color.parseColor("#00000000")) {
Color.parseColor("#3F000000")
} else {
newColor
}
val colorDrawable = ColorDrawable(originalColor) val colorDrawable = ColorDrawable(originalColor)
activity.window.setBackgroundDrawable(colorDrawable) activity.window.setBackgroundDrawable(colorDrawable)

View file

@ -1,28 +1,27 @@
package eu.ottop.yamlauncher package eu.ottop.yamlauncher
import android.R.color
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherActivityInfo
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color
import android.os.UserHandle import android.os.UserHandle
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Space
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.widget.AppCompatButton
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.marginLeft
import androidx.fragment.app.FragmentActivity
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
class AppMenuAdapter( class AppMenuAdapter(
private val activity: Context, private val activity: Context,
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>, var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
@ -113,6 +112,8 @@ class AppMenuAdapter(
if (app.second.second != 0) { if (app.second.second != 0) {
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_work_app, null),null, ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null)
holder.textView.compoundDrawables[0].colorFilter =
BlendModeColorFilter(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3")), BlendMode.SRC_ATOP)
} }
else { else {
holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null) holder.textView.setCompoundDrawablesWithIntrinsicBounds(ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null,ResourcesCompat.getDrawable(activity.resources, R.drawable.ic_empty, null),null)
@ -152,6 +153,7 @@ class AppMenuAdapter(
} }
val appInfo = app.first.activityInfo.applicationInfo val appInfo = app.first.activityInfo.applicationInfo
holder.textView.setTextColor(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3")))
holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo)) holder.textView.text = sharedPreferenceManager.getAppName(activity, app.first.applicationInfo.packageName,app.second.second, holder.itemView.context.packageManager.getApplicationLabel(appInfo))
holder.editText.setText(holder.textView.text) holder.editText.setText(holder.textView.text)

View file

@ -6,7 +6,10 @@ import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.pm.LauncherActivityInfo import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps import android.content.pm.LauncherApps
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
@ -22,6 +25,9 @@ import android.view.View
import android.view.View.TEXT_ALIGNMENT_CENTER import android.view.View.TEXT_ALIGNMENT_CENTER
import android.view.View.TEXT_ALIGNMENT_TEXT_END import android.view.View.TEXT_ALIGNMENT_TEXT_END
import android.view.View.TEXT_ALIGNMENT_TEXT_START import android.view.View.TEXT_ALIGNMENT_TEXT_START
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.WindowManager
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
@ -32,11 +38,13 @@ 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.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.children import androidx.core.view.children
import androidx.core.view.marginLeft import androidx.core.view.marginLeft
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textfield.TextInputEditText
import eu.ottop.yamlauncher.databinding.ActivityMainBinding import eu.ottop.yamlauncher.databinding.ActivityMainBinding
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -57,7 +65,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private lateinit var installedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>> private lateinit var installedApps: List<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
private lateinit var searchView: EditText private lateinit var searchView: TextInputEditText
private var adapter: AppMenuAdapter? = null private var adapter: AppMenuAdapter? = null
private var job: Job? = null private var job: Job? = null
private var weatherJob: Job? = null private var weatherJob: Job? = null
@ -88,6 +96,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private val weatherSystem = WeatherSystem() private val weatherSystem = WeatherSystem()
private val uiUtils = UIUtils()
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -99,6 +109,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
preferences.registerOnSharedPreferenceChangeListener(this) preferences.registerOnSharedPreferenceChangeListener(this)
window.setBackgroundDrawable(
ColorDrawable(
Color.parseColor(preferences.getString("bgColor", "#00000000"))
)
)
searchView = findViewById(R.id.searchView) searchView = findViewById(R.id.searchView)
launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
@ -126,10 +142,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setDateSize(preferences.getString("dateSize", "medium")) setDateSize(preferences.getString("dateSize", "medium"))
setShortcutSize(binding.homeView, preferences.getString("shortcutSize", "medium")) setShortcutSize(binding.homeView)
setSearchSize(preferences.getString("searchSize", "medium")) setSearchSize(preferences.getString("searchSize", "medium"))
setSearchColors()
uiUtils.setAllColors(binding.homeView, Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")))
batteryReceiver = BatteryReceiver.register(this, this@MainActivity) batteryReceiver = BatteryReceiver.register(this, this@MainActivity)
binding.homeView.setOnTouchListener { _, event -> binding.homeView.setOnTouchListener { _, event ->
@ -173,28 +193,63 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
"shortcutAlignment" -> { "shortcutAlignment" -> {
setShortcutAlignment(preferences?.getString("shortcutAlignment", "left"), binding.homeView) setShortcutAlignment(preferences?.getString(key, "left"), binding.homeView)
} }
"searchAlignment" -> { "searchAlignment" -> {
setSearchAlignment(preferences?.getString("searchAlignment", "left")) setSearchAlignment(preferences?.getString(key, "left"))
} }
"clockSize" -> { "clockSize" -> {
setClockSize(preferences?.getString("clockSize","medium")) setClockSize(preferences?.getString(key,"medium"))
} }
"dateSize" -> { "dateSize" -> {
setDateSize(preferences?.getString("dateSize", "medium")) setDateSize(preferences?.getString(key, "medium"))
} }
"shortcutSize" -> { "shortcutSize" -> {
setShortcutSize(binding.homeView, preferences?.getString("shortcutSize", "medium")) setShortcutSize(binding.homeView)
} }
"searchSize" -> { "searchSize" -> {
setSearchSize(preferences?.getString("searchSize", "medium")) setSearchSize(preferences?.getString(key, "medium"))
} }
"bgColor" -> {
window.setBackgroundDrawable(
ColorDrawable(
Color.parseColor(preferences?.getString(key, "#00000000"))
)
)
}
"textColor" -> {
uiUtils.setAllColors(binding.homeView, Color.parseColor(preferences?.getString(key, "#FFF3F3F3")))
setSearchColors()
}
}
}
private fun setSearchColors() {
val viewTreeObserver = searchView.viewTreeObserver
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
// Your code here
searchView.setTextColor(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")))
searchView.setHintTextColor(uiUtils.setAlpha(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")), "A9"))
searchView.compoundDrawables[0].colorFilter =
BlendModeColorFilter(Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")), BlendMode.SRC_ATOP)
// Remove the listener
if (viewTreeObserver.isAlive) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
}
}
}
if (viewTreeObserver.isAlive) {
viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener)
} }
} }
@ -475,7 +530,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
fun backToHome() { fun backToHome() {
closeKeyboard() closeKeyboard()
animations.showHome(binding) animations.showHome(binding)
animations.backgroundOut(this@MainActivity) animations.backgroundOut(this@MainActivity, Color.parseColor(preferences.getString("bgColor", "#00000000")))
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
handler.postDelayed({ handler.postDelayed({
try { try {
@ -504,7 +559,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
private fun toAppMenu() { private fun toAppMenu() {
animations.showApps(binding) animations.showApps(binding)
animations.backgroundIn(this@MainActivity) animations.backgroundIn(this@MainActivity, Color.parseColor(preferences.getString("bgColor", "#00000000")))
} }
override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) { override fun onItemClick(appInfo: LauncherActivityInfo, userHandle: UserHandle) {
@ -670,14 +725,16 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
private fun setShortcutSize(shortcuts: LinearLayout, size: String?) { private fun setShortcutSize(shortcuts: LinearLayout) {
val viewTreeObserver = shortcuts.viewTreeObserver val viewTreeObserver = shortcuts.viewTreeObserver
if (viewTreeObserver.isAlive) { val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
viewTreeObserver.addOnGlobalLayoutListener { override fun onGlobalLayout() {
shortcuts.children.forEach { shortcuts.children.forEach {
if (it is TextView) { if (it is TextView) {
when (size) { when (preferences?.getString("shortcutSize", "medium")) {
"small" -> { "small" -> {
it.setPadding( it.setPadding(
it.paddingLeft, it.paddingLeft,
@ -703,10 +760,17 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
} }
if (viewTreeObserver.isAlive) {
viewTreeObserver.removeOnGlobalLayoutListener(this)
} }
} }
} }
if (viewTreeObserver.isAlive) {
viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener)
}
}
private fun setClockSize(size: String?) { private fun setClockSize(size: String?) {
when (size) { when (size) {
"small" -> { "small" -> {

View file

@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import androidx.core.content.ContextCompat
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
class SettingsActivity : AppCompatActivity() { class SettingsActivity : AppCompatActivity() {

View file

@ -0,0 +1,52 @@
package eu.ottop.yamlauncher
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.children
class UIUtils {
fun setAllColors(view: View, color: Int) {
when {
view is ViewGroup -> {
view.children.forEach { child ->
setAllColors(child, color)
}
}
hasMethod(view, "setTextColor") -> {
// Check if the method setTextColor exists
(view as? TextView)?.setTextColor(color)
}
else -> {
view.setBackgroundColor(color)
}
}
}
// Helper function to check if a view has a method
private fun hasMethod(view: View, methodName: String): Boolean {
return try {
view.javaClass.getMethod(methodName, Int::class.java)
true
} catch (e: NoSuchMethodException) {
false
}
}
private fun setAlpha(color: Int, newAlpha: Int): Int {
// Extract the RGB components
val r = Color.red(color)
val g = Color.green(color)
val b = Color.blue(color)
// Combine the new alpha with the RGB components
return Color.argb(newAlpha, r, g, b)
}
fun setAlpha(color: Int, alphaHex: String): Int {
val newAlpha = Integer.parseInt(alphaHex, 16) // Convert hex alpha to integer
return setAlpha(color, newAlpha)
}
}

View file

@ -69,7 +69,6 @@
android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:textSize="25sp" /> android:textSize="25sp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -20,7 +20,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:clickable="true" android:clickable="true"
android:elegantTextHeight="false" android:elegantTextHeight="false"
android:imeOptions="actionDone" android:imeOptions="actionDone"
@ -40,7 +40,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_weight="0.3" android:layout_weight="0.3"
android:background="#89000000" android:background="#C3000000"
android:gravity="center" android:gravity="center"
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
@ -78,7 +78,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:foreground="@drawable/app_action_foreground" android:foreground="@drawable/app_action_foreground"
android:text="Info" android:text="Info"
android:textAlignment="center" android:textAlignment="center"
@ -91,7 +91,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:foreground="@drawable/app_action_foreground" android:foreground="@drawable/app_action_foreground"
android:text="Uninstall" android:text="Uninstall"
android:textAlignment="center" android:textAlignment="center"
@ -104,7 +104,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:foreground="@drawable/app_action_foreground" android:foreground="@drawable/app_action_foreground"
android:text="Rename" android:text="Rename"
android:textAlignment="center" android:textAlignment="center"
@ -117,7 +117,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:foreground="@drawable/app_action_foreground" android:foreground="@drawable/app_action_foreground"
android:text="Hide" android:text="Hide"
android:textAlignment="center" android:textAlignment="center"
@ -130,7 +130,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:background="#6F000000" android:background="#A7000000"
android:foreground="@drawable/app_action_foreground" android:foreground="@drawable/app_action_foreground"
android:text="Close" android:text="Close"
android:textAlignment="center" android:textAlignment="center"

View file

@ -43,4 +43,26 @@
<item>celsius</item> <item>celsius</item>
<item>fahrenheit</item> <item>fahrenheit</item>
</string-array> </string-array>
<string-array name="bg_options">
<item>Transparent</item>
<item>Black</item>
<item>White</item>
</string-array>
<string-array name="bg_values">
<item>#00000000</item>
<item>#FF000000</item>
<item>#FFD6D6D6</item>
</string-array>
<string-array name="color_options">
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="color_values">
<item>#FFF3F3F3</item>
<item>#FF0C0C0C</item>
</string-array>
</resources> </resources>

View file

@ -3,9 +3,6 @@
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="original_color">#00000000</color> <color name="settings_bg">#FF1B1B1B</color>
<color name="new_color">#3F000000</color>
<color name="settings_bg">#88000000</color>
</resources> </resources>

View file

@ -14,6 +14,7 @@
<style name="SettingsTheme" parent="Base.Theme.YamLauncher"> <style name="SettingsTheme" parent="Base.Theme.YamLauncher">
<item name="android:windowBackground">@color/settings_bg</item> <item name="android:windowBackground">@color/settings_bg</item>
<item name="android:windowShowWallpaper">false</item>
</style> </style>
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" > <style name="AppSearchView" parent="Widget.AppCompat.SearchView" >

View file

@ -1,6 +1,30 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:allowDividerAbove="false"
app:title="Colors">
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="#00000000"
app:entries="@array/bg_options"
app:entryValues="@array/bg_values"
app:key="bgColor"
app:title="Background Color"
app:useSimpleSummaryProvider="true" />
<ListPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:defaultValue="#FFF3F3F3"
app:entries="@array/color_options"
app:entryValues="@array/color_values"
app:key="textColor"
app:title="Text Color"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:title="Alignment"> app:title="Alignment">