Skip to content

Commit 03fac86

Browse files
feat: Add option to force colored wallpaper
This commit introduces a new experimental feature that allows users to force a solid color wallpaper based on the app's selected background color. The main changes include: - Adding a `SET_WALLPAPER` permission to the `AndroidManifest.xml`. - Implementing the logic in `BaseFragment.kt` to set the system and lock screen wallpaper if the option is enabled. - Introducing a "Force Colored Wallpaper" toggle in the experimental settings UI. - Adding a `forceWallpaper` preference to `Prefs.kt` and `PrefsKeys.kt`. - Refactoring `SettingsComposable.kt` to correctly update the text color of settings options on recomposition.
1 parent 28ba7ce commit 03fac86

File tree

7 files changed

+44
-7
lines changed

7 files changed

+44
-7
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2222
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
2323
<uses-permission android:name="android.permission.READ_CONTACTS" />
24+
<uses-permission android:name="android.permission.SET_WALLPAPER" />
2425
<uses-permission android:name="android.permission.VIBRATE" />
2526
<uses-permission
2627
android:name="android.permission.BIND_APPWIDGET"

app/src/main/java/com/github/droidworksstudio/mlauncher/data/Prefs.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ class Prefs(val context: Context) {
189189
get() = getSetting(AUTO_OPEN_APP, false)
190190
set(value) = prefsNormal.edit { putBoolean(AUTO_OPEN_APP, value) }
191191

192+
var forceWallpaper: Boolean
193+
get() = getSetting(FORCE_COLORED_WALLPAPER, false)
194+
set(value) = prefsNormal.edit { putBoolean(FORCE_COLORED_WALLPAPER, value) }
195+
192196
var openAppOnEnter: Boolean
193197
get() = getSetting(OPEN_APP_ON_ENTER, false)
194198
set(value) = prefsNormal.edit { putBoolean(OPEN_APP_ON_ENTER, value) }

app/src/main/java/com/github/droidworksstudio/mlauncher/data/PrefsKeys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ internal const val LOCK_ORIENTATION_PORTRAIT = "LOCK_ORIENTATION_PORTRAIT"
1111
internal const val HAPTIC_FEEDBACK = "HAPTIC_FEEDBACK"
1212
internal const val FIRST_OPEN = "FIRST_OPEN"
1313
internal const val FIRST_SETTINGS_OPEN = "FIRST_SETTINGS_OPEN"
14+
internal const val FORCE_COLORED_WALLPAPER = "FORCE_COLORED_WALLPAPER"
1415

1516
// Home & Drawer
1617
internal const val HOME_APPS_NUM = "HOME_APPS_NUM"

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/BaseFragment.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.github.droidworksstudio.mlauncher.ui
22

3+
import android.app.WallpaperManager
34
import android.os.Bundle
45
import androidx.appcompat.app.AppCompatDelegate
6+
import androidx.core.graphics.createBitmap
57
import androidx.fragment.app.Fragment
68
import com.github.droidworksstudio.mlauncher.data.Constants
79
import com.github.droidworksstudio.mlauncher.data.Prefs
@@ -28,5 +30,23 @@ open class BaseFragment : Fragment() {
2830
}
2931
AppCompatDelegate.setDefaultNightMode(themeMode)
3032
}
33+
34+
override fun onStart() {
35+
super.onStart()
36+
37+
if (prefs.forceWallpaper) {
38+
val wallpaperManager = WallpaperManager.getInstance(requireContext())
39+
val backgroundColor = prefs.backgroundColor
40+
41+
// Create a solid color bitmap
42+
val bitmap = createBitmap(1, 1).apply {
43+
eraseColor(backgroundColor)
44+
}
45+
46+
// Set the wallpaper
47+
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_SYSTEM) // home
48+
wallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK) // lock
49+
}
50+
}
3151
}
3252

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/SettingsFragment.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class SettingsFragment : BaseFragment() {
344344
// Experimental Settings
345345
var toggledExpertOptions by remember { mutableStateOf(prefs.enableExpertOptions) }
346346
var selectedSettingsSize by remember { mutableIntStateOf(prefs.settingsSize) }
347+
var toggledForceWallpaper by remember { mutableStateOf(prefs.forceWallpaper) }
347348
var toggledSettingsLocked by remember { mutableStateOf(prefs.settingsLocked) }
348349
var toggledLockOrientation by remember { mutableStateOf(prefs.lockOrientation) }
349350
var toggledHapticFeedback by remember { mutableStateOf(prefs.hapticFeedback) }
@@ -1393,7 +1394,7 @@ class SettingsFragment : BaseFragment() {
13931394
title = getLocalizedString(R.string.background_color),
13941395
option = hexBackgroundColor,
13951396
fontSize = titleFontSize,
1396-
fontColor = Color(hexBackgroundColor.toColorInt()),
1397+
fontColor = Color(selectedBackgroundColor),
13971398
onClick = {
13981399
dialogBuilder.showColorPickerBottomSheet(
13991400
context = requireContext(),
@@ -2595,7 +2596,7 @@ class SettingsFragment : BaseFragment() {
25952596
PageHeader(
25962597
iconRes = R.drawable.ic_back,
25972598
title = getLocalizedString(R.string.about_settings_title, getLocalizedString(R.string.app_name)),
2598-
2599+
25992600
onClick = {
26002601
currentScreen = "main"
26012602
}
@@ -2719,6 +2720,17 @@ class SettingsFragment : BaseFragment() {
27192720
}
27202721
)
27212722

2723+
SettingsSwitch(
2724+
text = getLocalizedString(R.string.force_colored_wallpaper),
2725+
fontSize = titleFontSize,
2726+
defaultState = toggledForceWallpaper,
2727+
2728+
onCheckedChange = {
2729+
toggledForceWallpaper = !prefs.forceWallpaper
2730+
prefs.forceWallpaper = toggledForceWallpaper
2731+
}
2732+
)
2733+
27222734
if (requireContext().isBiometricEnabled()) {
27232735
SettingsSwitch(
27242736
text = getLocalizedString(R.string.lock_settings),

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/compose/SettingsComposable.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ object SettingsComposable {
495495
onClick: () -> Unit = {},
496496
) {
497497
val fontSizeSp = fontSize.value
498-
val fontColorInt = fontColor.toArgb()
499498

500499
Row(
501500
modifier = Modifier
@@ -507,31 +506,30 @@ object SettingsComposable {
507506
factory = { context ->
508507
FontAppCompatTextView(context).apply {
509508
setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp)
510-
setTextColor(fontColorInt)
511509
}
512510
},
513511
modifier = Modifier
514512
.weight(1f)
515513
.wrapContentHeight(),
516514
update = { textView ->
517515
textView.text = title
516+
textView.setTextColor(fontColor.toArgb()) // <- update color here
518517
}
519518
)
520519

521520
AndroidView(
522521
factory = { context ->
523522
FontAppCompatTextView(context).apply {
524523
setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp)
525-
setTextColor(fontColorInt)
526524
setOnClickListener { onClick() }
527525
}
528526
},
529527
modifier = Modifier.wrapContentSize(),
530528
update = { textView ->
531-
textView.text = option // update text on recomposition
529+
textView.text = option
530+
textView.setTextColor(fontColor.toArgb()) // <- update color here
532531
}
533532
)
534-
535533
}
536534
}
537535
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<string name="pages_on_home_screen">Number of Pages</string>
9696
<string name="enable_home_pager">Enable Home Pager</string>
9797
<string name="enable_app_timer">Enable App Timer</string>
98+
<string name="force_colored_wallpaper">Force Colored Wallpaper</string>
9899

99100
<string name="info_tiles">Info Tiles</string>
100101

0 commit comments

Comments
 (0)