Skip to content

Commit

Permalink
Theme pixel launcher
Browse files Browse the repository at this point in the history
Add same-toned monochrome icon and search bar color
Add option to make monochrome icons darker
Add option to make monochrome icons and search bar semi-transparent
Refactor and clean codes for better readability
  • Loading branch information
Mahmud0808 committed Oct 28, 2024
1 parent e8e6d1f commit 0d942fb
Show file tree
Hide file tree
Showing 14 changed files with 627 additions and 442 deletions.
11 changes: 10 additions & 1 deletion app/src/main/java/com/drdisagree/colorblendr/common/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ object Const {
// Preferences file
const val SHARED_PREFS: String = BuildConfig.APPLICATION_ID + "_preferences"

// System packages
// Package names
const val FRAMEWORK_PACKAGE: String = "android"
const val SYSTEMUI_PACKAGE: String = "com.android.systemui"
const val SHELL_PACKAGE: String = "com.android.shell"
const val SYSTEMUI_CLOCKS: String = "com.android.systemui.clocks."
const val GOOGLE_FEEDS: String = "com.google.android.googlequicksearchbox"
const val GOOGLE_NEWS: String = "com.google.android.apps.magazines"
const val PLAY_GAMES: String = "com.google.android.play.games"
const val SETTINGS: String = "com.android.settings"
const val SETTINGS_SEARCH: String = "com.google.android.settings.intelligence"
const val PIXEL_LAUNCHER: String = "com.google.android.apps.nexuslauncher"

// General preferences
const val FIRST_RUN: String = "firstRun"
const val THEMING_ENABLED: String = "themingEnabled"
const val MONET_STYLE: String = "customMonetStyle"
const val MODE_SPECIFIC_THEMES: String = "modeSpecificThemes"
const val DARKER_LAUNCHER_ICONS: String = "darkerLauncherIcons"
const val SEMI_TRANSPARENT_LAUNCHER_ICONS: String = "semiTransparentLauncherIcons"
private val modeSpecificThemes: Boolean
get() = RPrefs.getBoolean(MODE_SPECIFIC_THEMES, false)
val MONET_ACCENT_SATURATION: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import android.widget.CompoundButton
import androidx.fragment.app.Fragment
import com.drdisagree.colorblendr.R
import com.drdisagree.colorblendr.common.Const
import com.drdisagree.colorblendr.common.Const.DARKER_LAUNCHER_ICONS
import com.drdisagree.colorblendr.common.Const.MODE_SPECIFIC_THEMES
import com.drdisagree.colorblendr.common.Const.MONET_LAST_UPDATED
import com.drdisagree.colorblendr.common.Const.MONET_SECONDARY_COLOR
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED
import com.drdisagree.colorblendr.common.Const.MONET_TERTIARY_COLOR
import com.drdisagree.colorblendr.common.Const.PIXEL_LAUNCHER
import com.drdisagree.colorblendr.common.Const.SEMI_TRANSPARENT_LAUNCHER_ICONS
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.config.RPrefs.getBoolean
import com.drdisagree.colorblendr.config.RPrefs.getInt
Expand All @@ -24,6 +27,7 @@ import com.drdisagree.colorblendr.config.RPrefs.putLong
import com.drdisagree.colorblendr.databinding.FragmentSettingsAdvancedBinding
import com.drdisagree.colorblendr.utils.MiscUtil.setToolbarTitle
import com.drdisagree.colorblendr.utils.OverlayManager.applyFabricatedColors
import com.drdisagree.colorblendr.utils.SystemUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand All @@ -36,6 +40,7 @@ class SettingsAdvancedFragment : Fragment() {

private lateinit var binding: FragmentSettingsAdvancedBinding
private val notShizukuMode: Boolean = workingMethod != Const.WorkMethod.SHIZUKU
private val hasPixelLauncher: Boolean = SystemUtil.isAppInstalled(PIXEL_LAUNCHER)

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -93,14 +98,34 @@ class SettingsAdvancedFragment : Fragment() {
.show(getChildFragmentManager(), "tertiaryColorPicker")
}

// Accurate shades
// Mode specific themes
binding.modeSpecificThemes.setEnabled(notShizukuMode)
binding.modeSpecificThemes.isSwitchChecked = getBoolean(MODE_SPECIFIC_THEMES, false)
binding.modeSpecificThemes.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
putBoolean(MODE_SPECIFIC_THEMES, isChecked)
applyFabricatedColors()
}

// Darker launcher icons
binding.darkerLauncherIcons.setEnabled(notShizukuMode)
binding.darkerLauncherIcons.visibility = if (hasPixelLauncher) View.VISIBLE else View.GONE
binding.darkerLauncherIcons.isSwitchChecked = getBoolean(DARKER_LAUNCHER_ICONS, false)
binding.darkerLauncherIcons.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
putBoolean(DARKER_LAUNCHER_ICONS, isChecked)
applyFabricatedColors()
}

// Semi-transparent launcher icons
binding.semitransparentLauncher.setEnabled(notShizukuMode)
binding.semitransparentLauncher.visibility =
if (hasPixelLauncher) View.VISIBLE else View.GONE
binding.semitransparentLauncher.isSwitchChecked =
getBoolean(SEMI_TRANSPARENT_LAUNCHER_ICONS, false)
binding.semitransparentLauncher.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
putBoolean(SEMI_TRANSPARENT_LAUNCHER_ICONS, isChecked)
applyFabricatedColors()
}

return binding.getRoot()
}

Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/drdisagree/colorblendr/utils/ColorMapUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.drdisagree.colorblendr.utils

import androidx.core.util.Pair
import com.drdisagree.colorblendr.utils.ColorUtil.modifyBrightness

data class ColorMapping(
val resourceName: String,
val tonalPalette: TonalPalette? = null,
val colorIndex: Int? = null,
val lightModeColorIndex: Int? = null,
val darkModeColorIndex: Int? = null,
val lightModeColorCode: Int? = null,
val colorCode: Int? = null,
val darkModeColorCode: Int? = null,
val lightnessAdjustment: Int? = null,
val lightModeLightnessAdjustment: Int? = null,
val darkModeLightnessAdjustment: Int? = null
)

fun ColorMapping.extractResourceFromColorMap(
prefix: String = "",
suffix: String = "",
palette: ArrayList<ArrayList<Int>>,
isDark: Boolean = false
): Pair<String, Int> {
val resourceName = prefix + resourceName + suffix

val colorValue: Int = if (tonalPalette != null) {
if (colorIndex != null) {
palette[tonalPalette.index][colorIndex]
} else {
if (isDark) {
palette[tonalPalette.index][darkModeColorIndex!!]
} else {
palette[tonalPalette.index][lightModeColorIndex!!]
}
}
} else {
colorCode ?: if (isDark) {
darkModeColorCode
} else {
lightModeColorCode
}
}!!

return Pair(resourceName, colorValue)
}

fun ColorMapping.adjustColorBrightnessIfRequired(
colorValue: Int,
isDark: Boolean
): Int {
return if (lightnessAdjustment != null) {
modifyBrightness(colorValue, lightnessAdjustment)
} else if (darkModeLightnessAdjustment != null && isDark) {
modifyBrightness(colorValue, darkModeLightnessAdjustment)
} else if (lightModeLightnessAdjustment != null && !isDark) {
modifyBrightness(colorValue, lightModeLightnessAdjustment)
} else {
colorValue
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/drdisagree/colorblendr/utils/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -681,4 +681,16 @@ object ColorUtil {
)
return colors
}

fun Int.applyAlphaToColor(percentage: Int): Int {
require(percentage in 0..100) { "Percentage must be between 0 and 100" }

val alpha = (percentage * 255 / 100).coerceIn(0, 255)

val red = (this shr 16) and 0xFF
val green = (this shr 8) and 0xFF
val blue = this and 0xFF

return (alpha shl 24) or (red shl 16) or (green shl 8) or blue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ package com.drdisagree.colorblendr.utils
import android.graphics.Color
import android.os.Build

data class ColorMapping(
val resourceName: String,
val tonalPalette: TonalPalette? = null,
val colorIndex: Int? = null,
val lightModeColorIndex: Int? = null,
val darkModeColorIndex: Int? = null,
val lightModeColorCode: Int? = null,
val colorCode: Int? = null,
val darkModeColorCode: Int? = null,
val lightnessAdjustment: Int? = null,
val lightModeLightnessAdjustment: Int? = null,
val darkModeLightnessAdjustment: Int? = null
)

enum class TonalPalette(val index: Int) {
PRIMARY(0),
SECONDARY(1),
Expand Down
Loading

0 comments on commit 0d942fb

Please sign in to comment.