mirror of
https://github.com/He4eT/yamf_launcher.git
synced 2026-05-04 17:37:25 +00:00
Background and text color can now be changed
This commit is contained in:
parent
8953202be9
commit
dfc08513f5
11 changed files with 209 additions and 38 deletions
|
|
@ -6,6 +6,7 @@ import android.animation.ArgbEvaluator
|
|||
import android.animation.ObjectAnimator
|
||||
import android.animation.ValueAnimator
|
||||
import android.app.Activity
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
|
|
@ -31,9 +32,13 @@ class Animations () {
|
|||
binding.appView.slideInFromBottom()
|
||||
}
|
||||
|
||||
fun backgroundIn(activity: Activity, duration: Long = 100) {
|
||||
val originalColor = ContextCompat.getColor(activity, R.color.original_color)
|
||||
val newColor = ContextCompat.getColor(activity, R.color.new_color)
|
||||
fun backgroundIn(activity: Activity, originalColor: Int, duration: Long = 100) {
|
||||
|
||||
val newColor: Int = if (originalColor == Color.parseColor("#00000000")) {
|
||||
Color.parseColor("#3F000000")
|
||||
} else {
|
||||
originalColor
|
||||
}
|
||||
|
||||
val colorDrawable = ColorDrawable(originalColor)
|
||||
activity.window.setBackgroundDrawable(colorDrawable)
|
||||
|
|
@ -47,9 +52,13 @@ class Animations () {
|
|||
backgroundColorAnimator.start()
|
||||
}
|
||||
|
||||
fun backgroundOut(activity: Activity, duration: Long = 100) {
|
||||
val originalColor = ContextCompat.getColor(activity, R.color.new_color)
|
||||
val newColor = ContextCompat.getColor(activity, R.color.original_color)
|
||||
fun backgroundOut(activity: Activity, newColor: Int, duration: Long = 100) {
|
||||
|
||||
val originalColor: Int = if (newColor == Color.parseColor("#00000000")) {
|
||||
Color.parseColor("#3F000000")
|
||||
} else {
|
||||
newColor
|
||||
}
|
||||
|
||||
val colorDrawable = ColorDrawable(originalColor)
|
||||
activity.window.setBackgroundDrawable(colorDrawable)
|
||||
|
|
|
|||
|
|
@ -1,28 +1,27 @@
|
|||
package eu.ottop.yamlauncher
|
||||
|
||||
import android.R.color
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.graphics.BlendMode
|
||||
import android.graphics.BlendModeColorFilter
|
||||
import android.graphics.Color
|
||||
import android.os.UserHandle
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Space
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
|
||||
class AppMenuAdapter(
|
||||
private val activity: Context,
|
||||
var apps: MutableList<Pair<LauncherActivityInfo, Pair<UserHandle, Int>>>,
|
||||
|
|
@ -113,6 +112,8 @@ class AppMenuAdapter(
|
|||
|
||||
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.compoundDrawables[0].colorFilter =
|
||||
BlendModeColorFilter(Color.parseColor(preferences?.getString("textColor", "#FFF3F3F3")), BlendMode.SRC_ATOP)
|
||||
}
|
||||
else {
|
||||
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
|
||||
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.editText.setText(holder.textView.text)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.content.pm.LauncherActivityInfo
|
||||
import android.content.pm.LauncherApps
|
||||
import android.graphics.BlendMode
|
||||
import android.graphics.BlendModeColorFilter
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
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_TEXT_END
|
||||
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.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
|
|
@ -32,11 +38,13 @@ import androidx.activity.OnBackPressedCallback
|
|||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import eu.ottop.yamlauncher.databinding.ActivityMainBinding
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
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 recyclerView: RecyclerView
|
||||
private lateinit var searchView: EditText
|
||||
private lateinit var searchView: TextInputEditText
|
||||
private var adapter: AppMenuAdapter? = null
|
||||
private var job: Job? = null
|
||||
private var weatherJob: Job? = null
|
||||
|
|
@ -88,6 +96,8 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private val weatherSystem = WeatherSystem()
|
||||
|
||||
private val uiUtils = UIUtils()
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -99,6 +109,12 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
preferences.registerOnSharedPreferenceChangeListener(this)
|
||||
|
||||
window.setBackgroundDrawable(
|
||||
ColorDrawable(
|
||||
Color.parseColor(preferences.getString("bgColor", "#00000000"))
|
||||
)
|
||||
)
|
||||
|
||||
searchView = findViewById(R.id.searchView)
|
||||
|
||||
launcherApps = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps
|
||||
|
|
@ -126,10 +142,14 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
setDateSize(preferences.getString("dateSize", "medium"))
|
||||
|
||||
setShortcutSize(binding.homeView, preferences.getString("shortcutSize", "medium"))
|
||||
setShortcutSize(binding.homeView)
|
||||
|
||||
setSearchSize(preferences.getString("searchSize", "medium"))
|
||||
|
||||
setSearchColors()
|
||||
|
||||
uiUtils.setAllColors(binding.homeView, Color.parseColor(preferences.getString("textColor", "#FFF3F3F3")))
|
||||
|
||||
batteryReceiver = BatteryReceiver.register(this, this@MainActivity)
|
||||
|
||||
binding.homeView.setOnTouchListener { _, event ->
|
||||
|
|
@ -173,28 +193,63 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
}
|
||||
|
||||
"shortcutAlignment" -> {
|
||||
setShortcutAlignment(preferences?.getString("shortcutAlignment", "left"), binding.homeView)
|
||||
setShortcutAlignment(preferences?.getString(key, "left"), binding.homeView)
|
||||
}
|
||||
|
||||
"searchAlignment" -> {
|
||||
setSearchAlignment(preferences?.getString("searchAlignment", "left"))
|
||||
setSearchAlignment(preferences?.getString(key, "left"))
|
||||
}
|
||||
|
||||
"clockSize" -> {
|
||||
setClockSize(preferences?.getString("clockSize","medium"))
|
||||
setClockSize(preferences?.getString(key,"medium"))
|
||||
}
|
||||
|
||||
"dateSize" -> {
|
||||
setDateSize(preferences?.getString("dateSize", "medium"))
|
||||
setDateSize(preferences?.getString(key, "medium"))
|
||||
}
|
||||
|
||||
"shortcutSize" -> {
|
||||
setShortcutSize(binding.homeView, preferences?.getString("shortcutSize", "medium"))
|
||||
setShortcutSize(binding.homeView)
|
||||
}
|
||||
|
||||
"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() {
|
||||
closeKeyboard()
|
||||
animations.showHome(binding)
|
||||
animations.backgroundOut(this@MainActivity)
|
||||
animations.backgroundOut(this@MainActivity, Color.parseColor(preferences.getString("bgColor", "#00000000")))
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
handler.postDelayed({
|
||||
try {
|
||||
|
|
@ -504,7 +559,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
private fun toAppMenu() {
|
||||
animations.showApps(binding)
|
||||
animations.backgroundIn(this@MainActivity)
|
||||
animations.backgroundIn(this@MainActivity, Color.parseColor(preferences.getString("bgColor", "#00000000")))
|
||||
}
|
||||
|
||||
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
|
||||
if (viewTreeObserver.isAlive) {
|
||||
viewTreeObserver.addOnGlobalLayoutListener {
|
||||
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
|
||||
shortcuts.children.forEach {
|
||||
if (it is TextView) {
|
||||
|
||||
when (size) {
|
||||
when (preferences?.getString("shortcutSize", "medium")) {
|
||||
"small" -> {
|
||||
it.setPadding(
|
||||
it.paddingLeft,
|
||||
|
|
@ -703,8 +760,15 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||
|
||||
}
|
||||
}
|
||||
if (viewTreeObserver.isAlive) {
|
||||
viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (viewTreeObserver.isAlive) {
|
||||
viewTreeObserver.addOnGlobalLayoutListener(globalLayoutListener)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setClockSize(size: String?) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import androidx.core.content.ContextCompat
|
||||
import eu.ottop.yamlauncher.databinding.ActivitySettingsBinding
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
|
|
|||
52
app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt
Normal file
52
app/src/main/java/eu/ottop/yamlauncher/UIUtils.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,6 @@
|
|||
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
|
||||
android:textSize="25sp" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:clickable="true"
|
||||
android:elegantTextHeight="false"
|
||||
android:imeOptions="actionDone"
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="0.3"
|
||||
android:background="#89000000"
|
||||
android:background="#C3000000"
|
||||
android:gravity="center"
|
||||
android:insetTop="0dp"
|
||||
android:insetBottom="0dp"
|
||||
|
|
@ -78,7 +78,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:foreground="@drawable/app_action_foreground"
|
||||
android:text="Info"
|
||||
android:textAlignment="center"
|
||||
|
|
@ -91,7 +91,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:foreground="@drawable/app_action_foreground"
|
||||
android:text="Uninstall"
|
||||
android:textAlignment="center"
|
||||
|
|
@ -104,7 +104,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:foreground="@drawable/app_action_foreground"
|
||||
android:text="Rename"
|
||||
android:textAlignment="center"
|
||||
|
|
@ -117,7 +117,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:foreground="@drawable/app_action_foreground"
|
||||
android:text="Hide"
|
||||
android:textAlignment="center"
|
||||
|
|
@ -130,7 +130,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="#6F000000"
|
||||
android:background="#A7000000"
|
||||
android:foreground="@drawable/app_action_foreground"
|
||||
android:text="Close"
|
||||
android:textAlignment="center"
|
||||
|
|
|
|||
|
|
@ -43,4 +43,26 @@
|
|||
<item>celsius</item>
|
||||
<item>fahrenheit</item>
|
||||
</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>
|
||||
|
|
@ -3,9 +3,6 @@
|
|||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
|
||||
<color name="original_color">#00000000</color>
|
||||
<color name="new_color">#3F000000</color>
|
||||
|
||||
<color name="settings_bg">#88000000</color>
|
||||
<color name="settings_bg">#FF1B1B1B</color>
|
||||
|
||||
</resources>
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
<style name="SettingsTheme" parent="Base.Theme.YamLauncher">
|
||||
<item name="android:windowBackground">@color/settings_bg</item>
|
||||
<item name="android:windowShowWallpaper">false</item>
|
||||
</style>
|
||||
|
||||
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
|
||||
|
|
|
|||
|
|
@ -1,6 +1,30 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
app:allowDividerAbove="false"
|
||||
app:title="Alignment">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue