Skip to content

Commit

Permalink
Initial support for full control in OneUI #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Dec 17, 2024
1 parent 055591f commit 902b2e6
Show file tree
Hide file tree
Showing 11 changed files with 552 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ interface IShizukuConnection {
void applyFabricatedColors(String jsonString) = 2;
void removeFabricatedColors() = 3;
String getCurrentSettings() = 4;
void applyFabricatedColorsSamsung(String paletteArray) = 5;
void applyThemedIconSamsung(boolean isThemed) = 6;
void removeFabricatedColorsSamsung() = 7;
}
23 changes: 22 additions & 1 deletion app/src/main/java/com/drdisagree/colorblendr/common/Const.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.drdisagree.colorblendr.common

import android.os.Build
import com.drdisagree.colorblendr.BuildConfig
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.utils.RomUtil.isSamsung
import com.drdisagree.colorblendr.utils.SystemUtil
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
Expand Down Expand Up @@ -72,10 +74,21 @@ object Const {
const val SHOW_PER_APP_THEME_WARN: String = "showPerAppThemeWarn"
const val TINT_TEXT_COLOR: String = "tintTextColor"
const val SHIZUKU_PERMISSION_REQUEST_ID: Int = 100
const val THEME_CUSTOMIZATION_OVERLAY_PACKAGES: String = "theme_customization_overlay_packages"
const val SHIZUKU_THEMING_ENABLED: String = "shizukuThemingEnabled"
const val APP_LIST_FILTER_METHOD: String = "appListFilterMethod"
val screenOrientation: AtomicInteger = AtomicInteger(-1)
val isSamsungDevice: Boolean = isSamsung

// AOSP key
const val THEME_CUSTOMIZATION_OVERLAY_PACKAGES: String = "theme_customization_overlay_packages"

// Samsung key
const val WALLPAPER_THEME_STATE: String = "wallpapertheme_state"
const val WALLPAPER_THEME_COLOR_IS_GRAY: String = "wallpapertheme_color_isgray"
const val LOCK_ADAPTIVE_COLOR: String = "lock_adaptive_color"
const val WALLPAPER_THEME_COLORS: String = "wallpapertheme_color"
const val WALLPAPER_THEME_COLORS_FOR_GOOGLE: String = "wallpapertheme_color_for_g"
const val COLOR_THEME_APP_ICON: String = "colortheme_app_icon"

// Service preferences
val GSON: Gson = Gson()
Expand Down Expand Up @@ -151,4 +164,12 @@ object Const {
LAUNCHABLE,
ALL
}

val isRootMode: Boolean = workingMethod == Const.WorkMethod.ROOT
val isShizukuMode: Boolean = workingMethod == Const.WorkMethod.SHIZUKU

val isAtleastA13 = !isShizukuMode ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
val isAtleastA14 = !isShizukuMode ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import android.content.Context
import android.os.Build
import android.util.Log
import androidx.annotation.Keep
import com.drdisagree.colorblendr.common.Const.COLOR_THEME_APP_ICON
import com.drdisagree.colorblendr.common.Const.LOCK_ADAPTIVE_COLOR
import com.drdisagree.colorblendr.common.Const.THEME_CUSTOMIZATION_OVERLAY_PACKAGES
import com.drdisagree.colorblendr.common.Const.WALLPAPER_THEME_COLORS
import com.drdisagree.colorblendr.common.Const.WALLPAPER_THEME_COLORS_FOR_GOOGLE
import com.drdisagree.colorblendr.common.Const.WALLPAPER_THEME_COLOR_IS_GRAY
import com.drdisagree.colorblendr.common.Const.WALLPAPER_THEME_STATE
import com.drdisagree.colorblendr.extension.ThemeOverlayPackage
import com.topjohnwu.superuser.Shell
import org.json.JSONException
Expand All @@ -17,10 +23,12 @@ class ShizukuConnection : IShizukuConnection.Stub {
private val TAG: String = ShizukuConnection::class.java.simpleName
}

@Suppress("unused")
constructor() {
Log.i(TAG, "Constructed with no arguments")
}

@Suppress("unused")
@Keep
constructor(context: Context) {
Log.i(TAG, "Constructed with context: $context")
Expand All @@ -40,6 +48,22 @@ class ShizukuConnection : IShizukuConnection.Stub {
).exec()
}

override fun applyFabricatedColorsSamsung(paletteArray: String) {
Shell.cmd(
"settings put system $LOCK_ADAPTIVE_COLOR '3'",
"settings put system $WALLPAPER_THEME_COLORS '$paletteArray'",
"settings put system $WALLPAPER_THEME_COLORS_FOR_GOOGLE '$paletteArray'",
"settings put system $WALLPAPER_THEME_COLOR_IS_GRAY '0'",
"settings put system $WALLPAPER_THEME_STATE '1'",
).exec()
}

override fun applyThemedIconSamsung(isThemed: Boolean) {
Shell.cmd(
"settings put system $COLOR_THEME_APP_ICON '${if (isThemed) "1" else "0"}'"
).exec()
}

override fun removeFabricatedColors() {
try {
applyFabricatedColors(originalSettings.toString())
Expand All @@ -48,6 +72,19 @@ class ShizukuConnection : IShizukuConnection.Stub {
}
}

override fun removeFabricatedColorsSamsung() {
try {
Shell.cmd(
"settings put system $WALLPAPER_THEME_STATE '0'",
"settings put system $LOCK_ADAPTIVE_COLOR '3'",
"settings put system $WALLPAPER_THEME_COLORS ''",
"settings put system $WALLPAPER_THEME_COLORS_FOR_GOOGLE ''"
).exec()
} catch (e: Exception) {
Log.e(TAG, "removeFabricatedColorsSamsung: ", e)
}
}

override fun getCurrentSettings(): String {
val currentSettings = Shell.cmd(
"settings get secure $THEME_CUSTOMIZATION_OVERLAY_PACKAGES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.drdisagree.colorblendr.R
import com.drdisagree.colorblendr.common.Const
import com.drdisagree.colorblendr.common.Const.MANUAL_OVERRIDE_COLORS
import com.drdisagree.colorblendr.common.Const.MONET_ACCENT_SATURATION
import com.drdisagree.colorblendr.common.Const.MONET_ACCURATE_SHADES
Expand All @@ -25,7 +24,7 @@ import com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_SATURATION
import com.drdisagree.colorblendr.common.Const.MONET_LAST_UPDATED
import com.drdisagree.colorblendr.common.Const.MONET_PITCH_BLACK_THEME
import com.drdisagree.colorblendr.common.Const.MONET_STYLE
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.common.Const.isShizukuMode
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.config.RPrefs.clearPref
import com.drdisagree.colorblendr.config.RPrefs.getBoolean
Expand Down Expand Up @@ -56,7 +55,6 @@ class ColorPaletteFragment : Fragment() {
private lateinit var colorTableRows: Array<LinearLayout>
private lateinit var sharedViewModel: SharedViewModel
private val colorNames: Array<Array<String>> = ColorUtil.colorNames
private val notShizukuMode: Boolean = workingMethod != Const.WorkMethod.SHIZUKU

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -87,7 +85,7 @@ class ColorPaletteFragment : Fragment() {
)

// Warning message
val isOverrideAvailable: Boolean = notShizukuMode &&
val isOverrideAvailable: Boolean = !isShizukuMode &&
getBoolean(MANUAL_OVERRIDE_COLORS, false)

binding.warn.warningText.setText(
Expand Down Expand Up @@ -211,7 +209,7 @@ class ColorPaletteFragment : Fragment() {
Snackbar.LENGTH_INDEFINITE
)
.setAction(snackbarButton) {
if (!manualOverride || !notShizukuMode) {
if (!manualOverride || isShizukuMode) {
val clipboard: ClipboardManager =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip: ClipData = ClipData.newPlainText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.drdisagree.colorblendr.common.Const.MONET_LAST_UPDATED
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR
import com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED
import com.drdisagree.colorblendr.common.Const.WALLPAPER_COLOR_LIST
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.common.Const.isShizukuMode
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.config.RPrefs.getBoolean
import com.drdisagree.colorblendr.config.RPrefs.getInt
Expand Down Expand Up @@ -50,7 +50,6 @@ class ColorsFragment : Fragment() {
private lateinit var binding: FragmentColorsBinding
private lateinit var monetSeedColor: IntArray
private lateinit var sharedViewModel: SharedViewModel
private val notShizukuMode: Boolean = workingMethod != Const.WorkMethod.SHIZUKU

private val wallpaperChangedReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Expand All @@ -65,7 +64,7 @@ class ColorsFragment : Fragment() {

sharedViewModel = ViewModelProvider(requireActivity())[SharedViewModel::class.java]

if (!notShizukuMode) {
if (isShizukuMode) {
SettingsFragment.clearCustomColors()
}
}
Expand Down Expand Up @@ -171,7 +170,7 @@ class ColorsFragment : Fragment() {
PerAppThemeFragment()
)
}
binding.perAppTheme.setEnabled(notShizukuMode)
binding.perAppTheme.setEnabled(!isShizukuMode)
}

private fun updateViewVisibility(visibilityStates: Map<String, Int>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.view.ViewGroup
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.FORCE_PITCH_BLACK_SETTINGS
import com.drdisagree.colorblendr.common.Const.MODE_SPECIFIC_THEMES
Expand All @@ -22,9 +21,9 @@ import com.drdisagree.colorblendr.common.Const.MONET_TERTIARY_COLOR
import com.drdisagree.colorblendr.common.Const.PIXEL_LAUNCHER
import com.drdisagree.colorblendr.common.Const.SCREEN_OFF_UPDATE_COLORS
import com.drdisagree.colorblendr.common.Const.SEMI_TRANSPARENT_LAUNCHER_ICONS
import com.drdisagree.colorblendr.common.Const.isShizukuMode
import com.drdisagree.colorblendr.common.Const.saveSelectedFabricatedApps
import com.drdisagree.colorblendr.common.Const.selectedFabricatedApps
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.config.RPrefs.getBoolean
import com.drdisagree.colorblendr.config.RPrefs.getInt
import com.drdisagree.colorblendr.config.RPrefs.putBoolean
Expand All @@ -45,7 +44,6 @@ import me.jfenn.colorpickerdialog.views.picker.ImagePickerView
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(
Expand All @@ -60,7 +58,7 @@ class SettingsAdvancedFragment : Fragment() {
// Secondary color
var monetSecondaryColor = getInt(MONET_SECONDARY_COLOR, Color.WHITE)
binding.secondaryColorPicker.isEnabled =
getBoolean(MONET_SEED_COLOR_ENABLED, false) && notShizukuMode
getBoolean(MONET_SEED_COLOR_ENABLED, false) && !isShizukuMode
binding.secondaryColorPicker.previewColor =
getInt(MONET_SECONDARY_COLOR, monetSecondaryColor)
binding.secondaryColorPicker.setOnClickListener {
Expand All @@ -84,7 +82,7 @@ class SettingsAdvancedFragment : Fragment() {
// Tertiary color
var monetTertiaryColor = getInt(MONET_TERTIARY_COLOR, Color.WHITE)
binding.tertiaryColorPicker.isEnabled =
getBoolean(MONET_SEED_COLOR_ENABLED, false) && notShizukuMode
getBoolean(MONET_SEED_COLOR_ENABLED, false) && !isShizukuMode
binding.tertiaryColorPicker.previewColor = monetTertiaryColor
binding.tertiaryColorPicker.setOnClickListener {
ColorPickerDialog()
Expand All @@ -111,15 +109,15 @@ class SettingsAdvancedFragment : Fragment() {
}

// Mode specific themes
binding.modeSpecificThemes.isEnabled = notShizukuMode
binding.modeSpecificThemes.isEnabled = !isShizukuMode
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.isEnabled = notShizukuMode && hasPixelLauncher
binding.darkerLauncherIcons.isEnabled = !isShizukuMode && hasPixelLauncher
binding.darkerLauncherIcons.isSwitchChecked = getBoolean(DARKER_LAUNCHER_ICONS, false)
binding.darkerLauncherIcons.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
if (isChecked) {
Expand All @@ -130,7 +128,7 @@ class SettingsAdvancedFragment : Fragment() {
}

// Semi-transparent launcher icons
binding.semitransparentLauncher.isEnabled = notShizukuMode && hasPixelLauncher
binding.semitransparentLauncher.isEnabled = !isShizukuMode && hasPixelLauncher
binding.semitransparentLauncher.isSwitchChecked =
getBoolean(SEMI_TRANSPARENT_LAUNCHER_ICONS, false)
binding.semitransparentLauncher.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
Expand All @@ -143,7 +141,7 @@ class SettingsAdvancedFragment : Fragment() {

// Semi-transparent launcher icons
binding.pitchBlackSettingsWorkaround.isEnabled =
notShizukuMode && getBoolean(MONET_PITCH_BLACK_THEME, false)
!isShizukuMode && getBoolean(MONET_PITCH_BLACK_THEME, false)
binding.pitchBlackSettingsWorkaround.visibility =
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.UPSIDE_DOWN_CAKE) View.VISIBLE else View.GONE
binding.pitchBlackSettingsWorkaround.isSwitchChecked =
Expand All @@ -167,7 +165,7 @@ class SettingsAdvancedFragment : Fragment() {
}

private fun savePixelLauncherInPerAppTheme() {
if (!hasPixelLauncher || !notShizukuMode) {
if (!hasPixelLauncher || isShizukuMode) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.drdisagree.colorblendr.common.Const.SHIZUKU_THEMING_ENABLED
import com.drdisagree.colorblendr.common.Const.THEMING_ENABLED
import com.drdisagree.colorblendr.common.Const.TINT_TEXT_COLOR
import com.drdisagree.colorblendr.common.Const.WALLPAPER_COLOR_LIST
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.common.Const.isShizukuMode
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.config.RPrefs.backupPrefs
import com.drdisagree.colorblendr.config.RPrefs.clearPref
Expand Down Expand Up @@ -71,7 +71,6 @@ class SettingsFragment : Fragment() {
private lateinit var binding: FragmentSettingsBinding
private var sharedViewModel: SharedViewModel? = null
private var isMasterSwitchEnabled: Boolean = true
private val notShizukuMode: Boolean = workingMethod != Const.WorkMethod.SHIZUKU

private val masterSwitch: CompoundButton.OnCheckedChangeListener =
CompoundButton.OnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean ->
Expand Down Expand Up @@ -150,15 +149,15 @@ class SettingsFragment : Fragment() {
sharedViewModel!!.setBooleanState(MONET_ACCURATE_SHADES, isChecked)
applyFabricatedColors()
}
binding.accurateShades.setEnabled(notShizukuMode)
binding.accurateShades.setEnabled(!isShizukuMode)

// Pitch black theme
binding.pitchBlackTheme.isSwitchChecked = getBoolean(MONET_PITCH_BLACK_THEME, false)
binding.pitchBlackTheme.setSwitchChangeListener { _: CompoundButton?, isChecked: Boolean ->
putBoolean(MONET_PITCH_BLACK_THEME, isChecked)
applyFabricatedColors()
}
binding.pitchBlackTheme.setEnabled(notShizukuMode)
binding.pitchBlackTheme.setEnabled(!isShizukuMode)

// Custom primary color
binding.customPrimaryColor.isSwitchChecked = getBoolean(MONET_SEED_COLOR_ENABLED, false)
Expand Down Expand Up @@ -186,7 +185,7 @@ class SettingsFragment : Fragment() {
putBoolean(TINT_TEXT_COLOR, isChecked)
applyFabricatedColors()
}
binding.tintTextColor.setEnabled(notShizukuMode)
binding.tintTextColor.setEnabled(!isShizukuMode)

// Override colors manually
binding.overrideColorsManually.isSwitchChecked = getBoolean(MANUAL_OVERRIDE_COLORS, false)
Expand Down Expand Up @@ -220,7 +219,7 @@ class SettingsFragment : Fragment() {
}
}
}
binding.overrideColorsManually.setEnabled(notShizukuMode)
binding.overrideColorsManually.setEnabled(!isShizukuMode)

binding.backupRestore.container.setOnClickListener {
crossfade(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.drdisagree.colorblendr.ui.fragments

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
Expand All @@ -9,11 +8,12 @@ import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import com.drdisagree.colorblendr.R
import com.drdisagree.colorblendr.common.Const
import com.drdisagree.colorblendr.common.Const.MONET_LAST_UPDATED
import com.drdisagree.colorblendr.common.Const.MONET_STYLE
import com.drdisagree.colorblendr.common.Const.MONET_STYLE_ORIGINAL_NAME
import com.drdisagree.colorblendr.common.Const.workingMethod
import com.drdisagree.colorblendr.common.Const.isAtleastA13
import com.drdisagree.colorblendr.common.Const.isAtleastA14
import com.drdisagree.colorblendr.common.Const.isShizukuMode
import com.drdisagree.colorblendr.config.RPrefs
import com.drdisagree.colorblendr.config.RPrefs.putLong
import com.drdisagree.colorblendr.config.RPrefs.putString
Expand All @@ -23,11 +23,6 @@ import com.drdisagree.colorblendr.utils.MiscUtil.setToolbarTitle
class StylesFragment : Fragment() {

private lateinit var binding: FragmentStylesBinding
private val notShizukuMode = workingMethod != Const.WorkMethod.SHIZUKU
private val isAtleastA13 = notShizukuMode ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
private val isAtleastA14 = notShizukuMode ||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -108,7 +103,7 @@ class StylesFragment : Fragment() {
putString(MONET_STYLE_ORIGINAL_NAME, getOriginalName(R.string.monet_fidelity))
binding.monetFidelity.applyColorScheme()
}
binding.monetFidelity.isEnabled = notShizukuMode
binding.monetFidelity.isEnabled = !isShizukuMode

binding.monetContent.isSelected = getString(R.string.monet_content) == selectedStyle
binding.monetContent.setOnClickListener {
Expand All @@ -118,7 +113,7 @@ class StylesFragment : Fragment() {
putString(MONET_STYLE_ORIGINAL_NAME, getOriginalName(R.string.monet_content))
binding.monetContent.applyColorScheme()
}
binding.monetContent.isEnabled = notShizukuMode
binding.monetContent.isEnabled = !isShizukuMode

binding.monetFruitsalad.isSelected = getString(R.string.monet_fruitsalad) == selectedStyle
binding.monetFruitsalad.setOnClickListener {
Expand Down
Loading

0 comments on commit 902b2e6

Please sign in to comment.