[2/2] OmniControl: add support to turn monet on and off

allow using our own overlays

Change-Id: I537f5326e691dd510223d3965e84849cdf51b3a5
diff --git a/app/src/main/java/org/omnirom/control/OverlaysFragment.kt b/app/src/main/java/org/omnirom/control/OverlaysFragment.kt
index c5c8fd2..c51e05c 100644
--- a/app/src/main/java/org/omnirom/control/OverlaysFragment.kt
+++ b/app/src/main/java/org/omnirom/control/OverlaysFragment.kt
@@ -26,10 +26,13 @@
 import android.graphics.drawable.Drawable
 import android.graphics.drawable.ShapeDrawable
 import android.graphics.drawable.shapes.PathShape
+import android.os.AsyncTask
 import android.os.Bundle
+import android.provider.Settings
 import android.view.*
 import android.widget.ImageView
 import android.widget.LinearLayout
+import android.widget.Switch
 import androidx.appcompat.app.AlertDialog
 import androidx.appcompat.app.AppCompatActivity
 import androidx.core.graphics.PathParser
@@ -59,39 +62,39 @@
     private val TAG = "OverlaysFragment"
 
     val COLORS_NEUTRAL1 = arrayOf(
-            "system_neutral1_50",
-            "system_neutral1_100",
-            "system_neutral1_200",
-            "system_neutral1_300",
-            "system_neutral1_400",
-            "system_neutral1_500",
-            "system_neutral1_600",
-            "system_neutral1_700",
-            "system_neutral1_800",
-            "system_neutral1_900"
+        "system_neutral1_50",
+        "system_neutral1_100",
+        "system_neutral1_200",
+        "system_neutral1_300",
+        "system_neutral1_400",
+        "system_neutral1_500",
+        "system_neutral1_600",
+        "system_neutral1_700",
+        "system_neutral1_800",
+        "system_neutral1_900"
     )
 
     val COLORS_ACCENT1 = arrayOf(
-            "system_accent1_100",
-            "system_accent1_600"
+        "system_accent1_100",
+        "system_accent1_600"
     )
 
     val CUSTOM_ACCENT_COLORS = arrayOf(
-            Color.parseColor("#a1c729"),
-            Color.parseColor("#ff8000"),
-            Color.parseColor("#a020f0"),
-            Color.parseColor("#ff005a"),
-            Color.parseColor("#e5141b"),
-            Color.parseColor("#f0b50b"),
-            Color.parseColor("#009ed8"),
-            Color.parseColor("#00897b"),
+        Color.parseColor("#a1c729"),
+        Color.parseColor("#ff8000"),
+        Color.parseColor("#a020f0"),
+        Color.parseColor("#ff005a"),
+        Color.parseColor("#e5141b"),
+        Color.parseColor("#f0b50b"),
+        Color.parseColor("#009ed8"),
+        Color.parseColor("#00897b"),
     )
 
     abstract class GridItem(
-            packageName: String,
-            isEnabled: Boolean,
-            isSystem: Boolean,
-            category: String
+        packageName: String,
+        isEnabled: Boolean,
+        isSystem: Boolean,
+        category: String
     ) {
         val packageName: String = packageName
         val isEnabled: Boolean = isEnabled
@@ -100,40 +103,41 @@
     }
 
     class IconShapeGridItem(
-            packageName: String,
-            iconShape: String,
-            isEnabled: Boolean,
-            isSystem: Boolean,
-            category: String
+        packageName: String,
+        iconShape: String,
+        isEnabled: Boolean,
+        isSystem: Boolean,
+        category: String
     ) : GridItem(packageName, isEnabled, isSystem, category) {
         val iconShape: String = iconShape
     }
 
     open class ColorsGridItem(
-            packageName: String,
-            colorList: ArrayList<Int>,
-            isEnabled: Boolean,
-            isSystem: Boolean,
-            category: String
+        packageName: String,
+        colorList: ArrayList<Int>,
+        isEnabled: Boolean,
+        isSystem: Boolean,
+        category: String
     ) : GridItem(packageName, isEnabled, isSystem, category) {
         val colorList: ArrayList<Int> = colorList
     }
 
     open class AccentColorsGridItem(
-            packageName: String,
-            colorList: ArrayList<Int>,
-            isEnabled: Boolean,
-            isSystem: Boolean,
-            category: String
+        packageName: String,
+        colorList: ArrayList<Int>,
+        isEnabled: Boolean,
+        isSystem: Boolean,
+        category: String
     ) : ColorsGridItem(packageName, colorList, isEnabled, isSystem, category) {
     }
 
-    class FabricatedAccentColorsGridItem(packageName: String,
-                                         colorList: ArrayList<Int>,
-                                         isEnabled: Boolean,
-                                         isSystem: Boolean,
-                                         category: String,
-                                         customAccentColor: CustomAccentColor
+    class FabricatedAccentColorsGridItem(
+        packageName: String,
+        colorList: ArrayList<Int>,
+        isEnabled: Boolean,
+        isSystem: Boolean,
+        category: String,
+        customAccentColor: CustomAccentColor
     ) : AccentColorsGridItem(packageName, colorList, isEnabled, isSystem, category) {
         val customAccentColor = customAccentColor
     }
@@ -153,10 +157,10 @@
     }
 
     inner class IconShapeListViewAdapter(
-            val context: Context,
-            val gridItems: ArrayList<IconShapeGridItem>
+        val context: Context,
+        val gridItems: ArrayList<IconShapeGridItem>
     ) :
-            RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+        RecyclerView.Adapter<RecyclerView.ViewHolder>() {
         private val iconShapeSize = context.resources.getDimensionPixelSize(R.dimen.icon_shape_size)
         private val PATH_SIZE = 100f
 
@@ -172,7 +176,7 @@
 
         override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
             return IconShapeListItem(
-                    LayoutInflater.from(context).inflate(R.layout.icon_shape_item, parent, false)
+                LayoutInflater.from(context).inflate(R.layout.icon_shape_item, parent, false)
             )
         }
 
@@ -180,18 +184,18 @@
             if (holder is IconShapeListItem) {
                 val gridItem: IconShapeGridItem = gridItems[position]
                 holder.shapeImage.setImageDrawable(
-                        createShapeIconDrawable(
-                                PathParser.createPathFromPathData(
-                                        gridItem.iconShape
-                                ), context.resources.getDrawable(R.mipmap.ic_launcher, null)
-                        )
+                    createShapeIconDrawable(
+                        PathParser.createPathFromPathData(
+                            gridItem.iconShape
+                        ), context.resources.getDrawable(R.mipmap.ic_launcher, null)
+                    )
                 )
                 if (gridItem.isEnabled || (gridItem.isSystem && !isOverlayEnabled())) {
                     holder.enabledImage.visibility =
-                            View.VISIBLE
+                        View.VISIBLE
                 } else {
                     holder.enabledImage.visibility =
-                            View.GONE
+                        View.GONE
                 }
                 holder.itemView.setOnClickListener {
                     if (gridItem.isSystem) {
@@ -216,8 +220,8 @@
         private fun createShapeIconDrawable(path: Path, appIcon: Drawable): Drawable {
             if (appIcon is AdaptiveIconDrawable) {
                 return DynamicAdaptiveIconDrawable(
-                        appIcon.background,
-                        appIcon.foreground, path
+                    appIcon.background,
+                    appIcon.foreground, path
                 )
             }
             return createShapeDrawable(path)
@@ -229,10 +233,10 @@
     }
 
     inner class PrimaryColorsListViewAdapter(
-            val context: Context,
-            private val gridItems: ArrayList<ColorsGridItem>
+        val context: Context,
+        private val gridItems: ArrayList<ColorsGridItem>
     ) :
-            RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+        RecyclerView.Adapter<RecyclerView.ViewHolder>() {
 
         inner class ColorsListItem(view: View) : RecyclerView.ViewHolder(view) {
             val colorList: LinearLayout = view.findViewById(R.id.colors_item_list)
@@ -245,7 +249,7 @@
 
         override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
             return ColorsListItem(
-                    LayoutInflater.from(context).inflate(R.layout.primary_colors_item, parent, false)
+                LayoutInflater.from(context).inflate(R.layout.primary_colors_item, parent, false)
             )
         }
 
@@ -256,21 +260,21 @@
 
                 for (color in gridItem.colorList) {
                     val colorItem: ImageView =
-                            LayoutInflater.from(context).inflate(R.layout.color_item, null) as ImageView
+                        LayoutInflater.from(context).inflate(R.layout.color_item, null) as ImageView
                     colorItem.setImageDrawable(createColorDrawable(color))
                     holder.colorList.addView(
-                            colorItem,
-                            context.resources.getDimensionPixelSize(R.dimen.color_item_width),
-                            context.resources.getDimensionPixelSize(R.dimen.color_item_height)
+                        colorItem,
+                        context.resources.getDimensionPixelSize(R.dimen.color_item_width),
+                        context.resources.getDimensionPixelSize(R.dimen.color_item_height)
                     )
                 }
 
                 if (gridItem.isEnabled || (gridItem.isSystem && !isOverlayEnabled())) {
                     holder.enabledImage.visibility =
-                            View.VISIBLE
+                        View.VISIBLE
                 } else {
                     holder.enabledImage.visibility =
-                            View.GONE
+                        View.GONE
                 }
                 holder.colorList.setOnClickListener {
                     if (gridItem.isSystem) {
@@ -278,8 +282,9 @@
                     } else if (!gridItem.isEnabled) {
                         overlayProvider.enableOverlayExclusive(gridItem.packageName)
                     }
-                    loadPrimaryColorsOverlays()
-                    notifyDataSetChanged()
+                    // will trigger onResume()
+                    //loadPrimaryColorsOverlays()
+                    //notifyDataSetChanged()
                 }
             }
         }
@@ -294,10 +299,10 @@
     }
 
     inner class AccentColorsListViewAdapter(
-            val context: Context,
-            private val gridItems: ArrayList<AccentColorsGridItem>
+        val context: Context,
+        private val gridItems: ArrayList<AccentColorsGridItem>
     ) :
-            RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+        RecyclerView.Adapter<RecyclerView.ViewHolder>() {
 
         open inner class AccentColorsListItem(view: View) : RecyclerView.ViewHolder(view) {
             val colorList: LinearLayout = view.findViewById(R.id.colors_item_list)
@@ -327,15 +332,16 @@
         override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
             return if (viewType == 0) {
                 AddAccentColorsListItem(
-                        LayoutInflater.from(context).inflate(R.layout.add_accent_colors_item, parent, false)
+                    LayoutInflater.from(context)
+                        .inflate(R.layout.add_accent_colors_item, parent, false)
                 )
             } else if (viewType == 1) {
                 FabricatedAccentColorsListItem(
-                        LayoutInflater.from(context).inflate(R.layout.accent_colors_item, parent, false)
+                    LayoutInflater.from(context).inflate(R.layout.accent_colors_item, parent, false)
                 )
             } else {
                 AccentColorsListItem(
-                        LayoutInflater.from(context).inflate(R.layout.accent_colors_item, parent, false)
+                    LayoutInflater.from(context).inflate(R.layout.accent_colors_item, parent, false)
                 )
             }
         }
@@ -352,40 +358,42 @@
             } else if (holder is AccentColorsListItem) {
                 holder.colorList.removeAllViews()
                 if (holder is FabricatedAccentColorsListItem) {
-                    val v = LayoutInflater.from(context).inflate(R.layout.edit_dark_accent_colors_item, null) as ImageView
+                    val v = LayoutInflater.from(context)
+                        .inflate(R.layout.edit_dark_accent_colors_item, null) as ImageView
                     holder.colorList.addView(
-                            v,
-                            context.resources.getDimensionPixelSize(R.dimen.color_item_width),
-                            context.resources.getDimensionPixelSize(R.dimen.edit_accent_color_item_height)
+                        v,
+                        context.resources.getDimensionPixelSize(R.dimen.color_item_width),
+                        context.resources.getDimensionPixelSize(R.dimen.edit_accent_color_item_height)
                     )
                     holder.accentColorDarkBackground = v
                 }
                 for (color in gridItem.colorList) {
                     val colorItem: ImageView =
-                            LayoutInflater.from(context).inflate(R.layout.color_item, null) as ImageView
+                        LayoutInflater.from(context).inflate(R.layout.color_item, null) as ImageView
                     colorItem.setImageDrawable(createColorDrawable(color))
                     holder.colorList.addView(
-                            colorItem,
-                            context.resources.getDimensionPixelSize(R.dimen.color_item_width),
-                            context.resources.getDimensionPixelSize(R.dimen.accent_color_item_height)
+                        colorItem,
+                        context.resources.getDimensionPixelSize(R.dimen.color_item_width),
+                        context.resources.getDimensionPixelSize(R.dimen.accent_color_item_height)
                     )
                 }
                 if (holder is FabricatedAccentColorsListItem) {
-                    val v = LayoutInflater.from(context).inflate(R.layout.edit_light_accent_colors_item, null) as ImageView
+                    val v = LayoutInflater.from(context)
+                        .inflate(R.layout.edit_light_accent_colors_item, null) as ImageView
                     holder.colorList.addView(
-                            v,
-                            context.resources.getDimensionPixelSize(R.dimen.color_item_width),
-                            context.resources.getDimensionPixelSize(R.dimen.edit_accent_color_item_height)
+                        v,
+                        context.resources.getDimensionPixelSize(R.dimen.color_item_width),
+                        context.resources.getDimensionPixelSize(R.dimen.edit_accent_color_item_height)
                     )
                     holder.accentColorLightBackground = v
                 }
 
                 if (gridItem.isEnabled || (gridItem.isSystem && !isOverlayEnabled())) {
                     holder.enabledImage.visibility =
-                            View.VISIBLE
+                        View.VISIBLE
                 } else {
                     holder.enabledImage.visibility =
-                            View.GONE
+                        View.GONE
                 }
 
                 if (holder is FabricatedAccentColorsListItem) {
@@ -416,8 +424,9 @@
                         } else if (!gridItem.isEnabled) {
                             overlayProvider.enableAccentOverlayTransaction(gridItem.packageName)
                         }
-                        loadAccentColorsOverlays()
-                        notifyDataSetChanged()
+                        // will trigger onResume()
+                        //loadAccentColorsOverlays()
+                        //notifyDataSetChanged()
                     }
                 }
             }
@@ -433,10 +442,10 @@
     }
 
     inner class OverlayItemListViewAdapter(
-            val context: Context,
-            val overlayItems: ArrayList<View>
+        val context: Context,
+        val overlayItems: ArrayList<View>
     ) :
-            RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+        RecyclerView.Adapter<RecyclerView.ViewHolder>() {
 
         inner class OverlayListItem(view: View) : RecyclerView.ViewHolder(view) {
         }
@@ -469,16 +478,16 @@
         super.onResume()
         (activity as? AppCompatActivity)?.supportActionBar?.setDisplayHomeAsUpEnabled(true)
         (activity as? SettingsActivity)?.updateFragmentTitle(
-                getFragmentTitle(),
-                getFragmentSummary(),
-                getFragmentIcon()
+            getFragmentTitle(),
+            getFragmentSummary(),
+            getFragmentIcon()
         )
     }
 
     override fun onCreateView(
-            inflater: LayoutInflater,
-            container: ViewGroup?,
-            savedInstanceState: Bundle?
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?
     ): View? {
         overlayProvider = OverlaysProvider(requireContext())
         overlayProvider.init()
@@ -488,26 +497,26 @@
     private fun loadIconShapeOverlays() {
         iconShapeGridItems.clear();
         iconShapeGridItems.add(
-                IconShapeGridItem(
-                        "android",
-                        overlayProvider.getSystemIconMask(),
-                        false,
-                        true,
-                        overlayProvider.getIconShapeCategory()
-                )
+            IconShapeGridItem(
+                "android",
+                overlayProvider.getSystemIconMask(),
+                false,
+                true,
+                overlayProvider.getIconShapeCategory()
+            )
         )
         for (packageName in overlayProvider.getIconShapeOverlays().sorted()) {
             try {
                 val iconMask = overlayProvider.loadString("config_icon_mask", packageName)
                 iconShapeGridItems.add(
-                        IconShapeGridItem(
-                                packageName,
-                                iconMask,
-                                overlayProvider.isOverlayEnabled(packageName),
-                                false,
-                                overlayProvider.getIconShapeCategory()
+                    IconShapeGridItem(
+                        packageName,
+                        iconMask,
+                        overlayProvider.isOverlayEnabled(packageName),
+                        false,
+                        overlayProvider.getIconShapeCategory()
 
-                        )
+                    )
                 )
             } catch (e: NotFoundException) {
             }
@@ -521,13 +530,13 @@
             colorList.add(overlayProvider.getSystemColor(color))
         }
         primaryColorsGridItems.add(
-                ColorsGridItem(
-                        "android",
-                        colorList,
-                        false,
-                        true,
-                        overlayProvider.getPrimaryColorCategory()
-                )
+            ColorsGridItem(
+                "android",
+                colorList,
+                false,
+                true,
+                overlayProvider.getPrimaryColorCategory()
+            )
         )
         for (packageName in overlayProvider.getPrimaryColorOverlays().sorted()) {
             try {
@@ -537,13 +546,13 @@
                 }
 
                 primaryColorsGridItems.add(
-                        ColorsGridItem(
-                                packageName,
-                                overlayColorList,
-                                overlayProvider.isOverlayEnabled(packageName),
-                                false,
-                                overlayProvider.getPrimaryColorCategory()
-                        )
+                    ColorsGridItem(
+                        packageName,
+                        overlayColorList,
+                        overlayProvider.isOverlayEnabled(packageName),
+                        false,
+                        overlayProvider.getPrimaryColorCategory()
+                    )
                 )
             } catch (e: NotFoundException) {
             }
@@ -557,13 +566,13 @@
             colorList.add(overlayProvider.getSystemColor(color))
         }
         accentColorsGridItems.add(
-                AccentColorsGridItem(
-                        "android",
-                        colorList,
-                        false,
-                        true,
-                        overlayProvider.getAccentColorCategory()
-                )
+            AccentColorsGridItem(
+                "android",
+                colorList,
+                false,
+                true,
+                overlayProvider.getAccentColorCategory()
+            )
         )
         for (packageName in overlayProvider.getAccentColorOverlays().sorted()) {
             try {
@@ -573,13 +582,13 @@
                 }
 
                 accentColorsGridItems.add(
-                        AccentColorsGridItem(
-                                packageName,
-                                overlayColorList,
-                                overlayProvider.isOverlayEnabled(packageName),
-                                false,
-                                overlayProvider.getAccentColorCategory()
-                        )
+                    AccentColorsGridItem(
+                        packageName,
+                        overlayColorList,
+                        overlayProvider.isOverlayEnabled(packageName),
+                        false,
+                        overlayProvider.getAccentColorCategory()
+                    )
                 )
             } catch (e: NotFoundException) {
             }
@@ -590,14 +599,18 @@
             customColorList.add(customColor.darkColor)
             customColorList.add(customColor.lightColor)
             accentColorsGridItems.add(
-                    FabricatedAccentColorsGridItem(
-                            overlayProvider.getFabricatedOverlayIdentifier(customColor.identifier),
-                            customColorList,
-                            overlayProvider.isOverlayEnabled(overlayProvider.getFabricatedOverlayIdentifier(customColor.identifier)),
-                            false,
-                            overlayProvider.getAccentColorCategory(),
-                            customColor
-                    )
+                FabricatedAccentColorsGridItem(
+                    overlayProvider.getFabricatedOverlayIdentifier(customColor.identifier),
+                    customColorList,
+                    overlayProvider.isOverlayEnabled(
+                        overlayProvider.getFabricatedOverlayIdentifier(
+                            customColor.identifier
+                        )
+                    ),
+                    false,
+                    overlayProvider.getAccentColorCategory(),
+                    customColor
+                )
             )
         }
         accentColorsGridItems.add(AddAccentColorsGridItem())
@@ -613,41 +626,60 @@
 
         overlayItemList.clear()
         val overlayItemView =
-                LayoutInflater.from(context).inflate(R.layout.overlays_item, null, false)
+            LayoutInflater.from(context).inflate(R.layout.overlays_item, null, false)
         overlayItemList.add(overlayItemView)
 
         iconShapeListView = overlayItemView.findViewById(R.id.icon_shape_list_view)
         iconShapeListView.layoutManager =
-                LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
+            LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
         iconShapeListView.adapter = IconShapeListViewAdapter(requireContext(), iconShapeGridItems)
 
         primaryColorsListView = overlayItemView.findViewById(R.id.primary_color_list_view)
         primaryColorsListView.layoutManager =
-                LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
+            LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
         primaryColorsListView.adapter =
-                PrimaryColorsListViewAdapter(requireContext(), primaryColorsGridItems)
+            PrimaryColorsListViewAdapter(requireContext(), primaryColorsGridItems)
 
         accentColorsListView = overlayItemView.findViewById(R.id.accent_color_list_view)
         accentColorsListView.layoutManager =
-                LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
+            LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
         accentColorsListView.adapter =
-                AccentColorsListViewAdapter(requireContext(), accentColorsGridItems)
+            AccentColorsListViewAdapter(requireContext(), accentColorsGridItems)
 
         overlayItemListView = view.findViewById(R.id.overlay_item_list)
         overlayItemListView.adapter = OverlayItemListViewAdapter(requireContext(), overlayItemList)
         overlayItemListView.layoutManager =
-                LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
+            LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
+
+        val monetEnableSwitch: Switch = overlayItemView.findViewById(R.id.monet_overlay_enable);
+        val monetEnabled = overlayProvider.isMonetOverlayEnabled()
+        monetEnableSwitch.isChecked = monetEnabled
+        enableOverlaySelect(overlayItemView, !monetEnabled)
+
+        monetEnableSwitch.setOnClickListener {
+            val checked = monetEnableSwitch.isChecked()
+            Settings.System.putInt(
+                requireContext().contentResolver,
+                Settings.System.OMNI_MONET_DISABLE,
+                if (checked) 0 else 1
+            )
+            enableOverlaySelect(overlayItemView, !checked)
+            AsyncTask.execute(Runnable { overlayProvider.enableMonetOverlays(checked) })
+        }
     }
 
-    private fun setCustomAccentColor(accentColor: FabricatedAccentColorsGridItem, changeDark: Boolean) {
+    private fun setCustomAccentColor(
+        accentColor: FabricatedAccentColorsGridItem,
+        changeDark: Boolean
+    ) {
         val color = accentColor.customAccentColor
         val oldColor = if (changeDark) color.darkColor else color.lightColor
         val dialog = ColorSelectDialog(
-                requireContext(),
-                oldColor, false, CUSTOM_ACCENT_COLORS
+            requireContext(),
+            oldColor, false, CUSTOM_ACCENT_COLORS
         )
         dialog.setButton(
-                AlertDialog.BUTTON_POSITIVE, resources.getString(android.R.string.ok)
+            AlertDialog.BUTTON_POSITIVE, resources.getString(android.R.string.ok)
         ) { _, _ ->
             if (changeDark) color.darkColor = dialog.color
             else color.lightColor = dialog.color
@@ -661,7 +693,7 @@
             }
         }
         dialog.setButton(
-                AlertDialog.BUTTON_NEGATIVE, resources.getString(android.R.string.cancel)
+            AlertDialog.BUTTON_NEGATIVE, resources.getString(android.R.string.cancel)
         ) { _, _ ->
             dialog.dismiss()
         }
@@ -671,7 +703,8 @@
     private fun doDeleteCustomAccentColor(accentColor: FabricatedAccentColorsGridItem) {
         val dialog = AlertDialog.Builder(requireContext())
         dialog.setMessage(getString(R.string.dialog_delete_accent_color_message))
-        dialog.setPositiveButton(resources.getString(android.R.string.ok)
+        dialog.setPositiveButton(
+            resources.getString(android.R.string.ok)
         ) { _, _ ->
             deleteCustomAccentColor(accentColor)
             loadAccentColorsOverlays()
@@ -697,11 +730,11 @@
                         continue
                     }
                     customAccentColors.add(
-                            CustomAccentColor(
-                                    color["identifier"] as String,
-                                    color["system_accent1_100"] as Int,
-                                    color["system_accent1_600"] as Int
-                            )
+                        CustomAccentColor(
+                            color["identifier"] as String,
+                            color["system_accent1_100"] as Int,
+                            color["system_accent1_600"] as Int
+                        )
                     )
                 } catch (e: Exception) {
                 }
@@ -728,15 +761,21 @@
         val prefs = requireContext().getSharedPreferences("overlays", Context.MODE_PRIVATE)
         val firstTime = prefs.getBoolean("firstTimeAdd", true)
         if (firstTime) {
-            Snackbar.make(requireView(), getString(R.string.delete_accent_color_info_message), Snackbar.LENGTH_LONG).setAction(android.R.string.ok, { prefs.edit().putBoolean("firstTimeAdd", false).commit() }).show()
+            Snackbar.make(
+                requireView(),
+                getString(R.string.delete_accent_color_info_message),
+                Snackbar.LENGTH_LONG
+            ).setAction(
+                android.R.string.ok,
+                { prefs.edit().putBoolean("firstTimeAdd", false).commit() }).show()
         }
     }
 
     private fun getDefaultCustomAccentColor(): CustomAccentColor {
         val customColor = CustomAccentColor(
-                "",
-                resources.getColor(android.R.color.system_accent1_100, null),
-                resources.getColor(android.R.color.system_accent1_600, null)
+            "",
+            resources.getColor(android.R.color.system_accent1_100, null),
+            resources.getColor(android.R.color.system_accent1_600, null)
         )
         customColor.identifier = "accent_color_" + customColor.hashCode()
         return customColor
@@ -747,7 +786,8 @@
 
         if (accentColor.isEnabled) {
             val prefs = requireContext().getSharedPreferences("overlays", Context.MODE_PRIVATE)
-            prefs.edit().putString("deletedAccentColor", accentColor.customAccentColor.identifier).commit()
+            prefs.edit().putString("deletedAccentColor", accentColor.customAccentColor.identifier)
+                .commit()
             // set to system default this will trigger a complete reload anyway
             overlayProvider.enableAccentOverlayTransaction(null)
         } else {
@@ -758,7 +798,11 @@
         }
     }
 
-    override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
+    override fun onCreateContextMenu(
+        menu: ContextMenu,
+        v: View,
+        menuInfo: ContextMenu.ContextMenuInfo?
+    ) {
         super.onCreateContextMenu(menu, v, menuInfo)
         menu.setHeaderTitle(resources.getString(R.string.accent_color_title));
         menu.add(0, 0, 0, "Delete");
@@ -772,4 +816,29 @@
         }
         return super.onContextItemSelected(item)
     }
+
+    fun isMonetEnabled(): Boolean {
+        return Settings.System.getInt(
+            requireContext().contentResolver, Settings.System.OMNI_MONET_DISABLE, 0
+        ) == 0
+    }
+
+    private fun enableOverlaySelect(overlayItemView: View, enable: Boolean) {
+        val neutralBlocker =
+            overlayItemView.findViewById<View?>(R.id.primary_color_list_view_blocker)
+        val accentBlocker = overlayItemView.findViewById<View?>(R.id.accent_color_list_view_blocker)
+        if (enable) {
+            neutralBlocker.visibility = View.GONE
+            accentBlocker.visibility = View.GONE
+        } else {
+            neutralBlocker.visibility = View.VISIBLE
+            accentBlocker.visibility = View.VISIBLE
+            neutralBlocker.setOnTouchListener { _, _ ->
+                true
+            }
+            accentBlocker.setOnTouchListener { _, _ ->
+                true
+            }
+        }
+    }
 }
diff --git a/app/src/main/java/org/omnirom/control/OverlaysProvider.kt b/app/src/main/java/org/omnirom/control/OverlaysProvider.kt
index f483595..1d777bc 100644
--- a/app/src/main/java/org/omnirom/control/OverlaysProvider.kt
+++ b/app/src/main/java/org/omnirom/control/OverlaysProvider.kt
@@ -19,11 +19,13 @@
 
 import android.content.Context
 import android.content.om.FabricatedOverlay
-import android.content.om.OverlayInfo
+import android.content.om.IOverlayManager
 import android.content.om.OverlayIdentifier
+import android.content.om.OverlayInfo
 import android.content.om.OverlayManager
 import android.content.om.OverlayManagerTransaction
 import android.content.res.Resources
+import android.os.ServiceManager
 import android.os.UserHandle
 import android.util.TypedValue
 
@@ -32,11 +34,17 @@
     private val TAG = "OverlayProvider"
     private val context = context
     private var om: OverlayManager? = null
+    private var iOm: IOverlayManager? = null;
     private lateinit var user: UserHandle
+    private val monetNeutral = OverlayIdentifier("com.android.systemui", "neutral")
+    private val monetAccent = OverlayIdentifier("com.android.systemui", "accent")
 
     fun init() {
         user = UserHandle.of(UserHandle.myUserId())
         om = context.getSystemService(OverlayManager::class.java)
+        iOm = IOverlayManager.Stub.asInterface(
+            ServiceManager.getService(Context.OVERLAY_SERVICE)
+        )
         loadOverlayInfo()
     }
 
@@ -87,6 +95,25 @@
         return overlayList
     }
 
+    fun enableMonetOverlays(enable: Boolean) {
+        val transaction = OverlayManagerTransaction.Builder()
+        transaction.setEnabled(
+            monetAccent,
+            enable,
+            UserHandle.myUserId()
+        )
+        transaction.setEnabled(
+            monetNeutral,
+            enable,
+            UserHandle.myUserId()
+        )
+        om!!.commit(transaction.build())
+    }
+
+    fun isMonetOverlayEnabled() : Boolean {
+        return isOverlayEnabled(monetNeutral)
+    }
+
     @Throws(Resources.NotFoundException::class)
     fun loadString(stringName: String, packageName: String): String {
         val overlayRes: Resources = context.packageManager.getResourcesForApplication(
@@ -133,6 +160,14 @@
         return false
     }
 
+    fun isOverlayEnabled(identifier: OverlayIdentifier): Boolean {
+        val overlayInfo = overlaysMap.get(identifier.toString())
+        if (overlayInfo != null) {
+            return overlayInfo.isEnabled()
+        }
+        return false
+    }
+
     fun enableOverlayExclusive(packageName: String) {
         if (om != null) {
             om!!.setEnabledExclusiveInCategory(packageName, user)
@@ -173,7 +208,10 @@
                     )
                 }
             // enable new if provided
-            if (overlay != null && overlaysMap.containsKey(OverlayIdentifier.fromString(overlay).toString())) {
+            if (overlay != null && overlaysMap.containsKey(
+                    OverlayIdentifier.fromString(overlay).toString()
+                )
+            ) {
                 transaction.setEnabled(
                     OverlayIdentifier.fromString(overlay),
                     true,
@@ -185,45 +223,45 @@
     }
 
     fun enableFabricatedAccentOverlayTransaction(
-            accentColor: OverlaysFragment.CustomAccentColor
+        accentColor: OverlaysFragment.CustomAccentColor
     ) {
         if (om != null) {
             val transaction = OverlayManagerTransaction.Builder()
             // disable farbricated
             om!!.getOverlayInfosForTarget("android", user)
-                    .forEach { info ->
-                        if (info.isFabricated() && info.getPackageName() == context.packageName) {
-                            transaction.unregisterFabricatedOverlay(info.getOverlayIdentifier())
-                        }
+                .forEach { info ->
+                    if (info.isFabricated() && info.getPackageName() == context.packageName) {
+                        transaction.unregisterFabricatedOverlay(info.getOverlayIdentifier())
                     }
+                }
             // disable enabled
             getCategoryOverlaysRaw(getAccentColorCategory()).filter { it.isEnabled() }
-                    .forEach {
-                        transaction.setEnabled(
-                                it.getOverlayIdentifier(),
-                                false,
-                                UserHandle.myUserId()
-                        )
-                    }
+                .forEach {
+                    transaction.setEnabled(
+                        it.getOverlayIdentifier(),
+                        false,
+                        UserHandle.myUserId()
+                    )
+                }
             // enable fabricated
             val accentColorOverlay = FabricatedOverlay.Builder(
-                    context.packageName, accentColor.identifier, "android"
+                context.packageName, accentColor.identifier, "android"
             )
-                    .setResourceValue(
-                            "@android:color/system_accent1_100",
-                            TypedValue.TYPE_INT_COLOR_ARGB8,
-                            accentColor.darkColor
-                    )
-                    .setResourceValue(
-                            "@android:color/system_accent1_600",
-                            TypedValue.TYPE_INT_COLOR_ARGB8,
-                            accentColor.lightColor
-                    )
-                    .build()
+                .setResourceValue(
+                    "@android:color/system_accent1_100",
+                    TypedValue.TYPE_INT_COLOR_ARGB8,
+                    accentColor.darkColor
+                )
+                .setResourceValue(
+                    "@android:color/system_accent1_600",
+                    TypedValue.TYPE_INT_COLOR_ARGB8,
+                    accentColor.lightColor
+                )
+                .build()
 
 
             transaction.registerFabricatedOverlay(accentColorOverlay)
-                    .setEnabled(accentColorOverlay!!.getIdentifier(), true, UserHandle.myUserId())
+                .setEnabled(accentColorOverlay!!.getIdentifier(), true, UserHandle.myUserId())
             om!!.commit(transaction.build())
         }
     }
@@ -261,7 +299,7 @@
         }
     }
 
-    fun getFabricatedOverlayIdentifier(overlayName: String) : String {
+    fun getFabricatedOverlayIdentifier(overlayName: String): String {
         return OverlayIdentifier(context.packageName, overlayName).toString()
     }
 }
\ No newline at end of file
diff --git a/app/src/main/res/layout/add_accent_colors_item.xml b/app/src/main/res/layout/add_accent_colors_item.xml
index 5f5ceab..bd29b03 100644
--- a/app/src/main/res/layout/add_accent_colors_item.xml
+++ b/app/src/main/res/layout/add_accent_colors_item.xml
@@ -1,7 +1,7 @@
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="@dimen/color_item_column_width"
     android:layout_height="@dimen/color_item_column_height"
-    android:layout_margin="5dp"
+    android:layout_margin="2dp"
     android:background="@drawable/overlay_item_background">
 
     <FrameLayout
diff --git a/app/src/main/res/layout/overlays_item.xml b/app/src/main/res/layout/overlays_item.xml
index 8b33cac..685d049 100644
--- a/app/src/main/res/layout/overlays_item.xml
+++ b/app/src/main/res/layout/overlays_item.xml
@@ -21,30 +21,82 @@
     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginTop="10dp"
+        android:layout_marginTop="20dp"
+        android:layout_marginBottom="10dp"
+        android:gravity="center_vertical"
+        android:text="@string/system_colors_title"
+        android:textAppearance="@style/Theme.OmniControl.GridItem.TitleTextStyle" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <Switch
+            android:id="@+id/monet_overlay_enable"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:paddingEnd="10dp"
+            android:paddingStart="5dp"/>
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingStart="10dp"
+            android:text="@string/monet_overlay_enable_title" />
+    </LinearLayout>
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="20dp"
         android:layout_marginBottom="10dp"
         android:gravity="center_vertical"
         android:text="@string/primary_color_title"
         android:textAppearance="@style/Theme.OmniControl.GridItem.TitleTextStyle" />
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/primary_color_list_view"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content" />
+        android:layout_height="wrap_content">
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/primary_color_list_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <View
+            android:id="@+id/primary_color_list_view_blocker"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:background="@color/overlay_blocker_color"
+            android:visibility="gone" />
+    </FrameLayout>
 
     <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginTop="10dp"
+        android:layout_marginTop="20dp"
         android:layout_marginBottom="10dp"
         android:gravity="center_vertical"
         android:text="@string/accent_color_title"
         android:textAppearance="@style/Theme.OmniControl.GridItem.TitleTextStyle" />
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/accent_color_list_view"
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content" />
+        android:layout_height="wrap_content">
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/accent_color_list_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <View
+            android:id="@+id/accent_color_list_view_blocker"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:background="@color/overlay_blocker_color"
+            android:visibility="gone" />
+    </FrameLayout>
 
     <Space
         android:layout_width="match_parent"
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index 927d9b7..0de42dc 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -4,4 +4,5 @@
     <color name="colorPrimaryDark">@android:color/system_neutral1_900</color>
     <color name="colorAccent">@android:color/system_accent1_100</color>
     <color name="overlay_item_background">@android:color/system_neutral1_800</color>
+    <color name="overlay_blocker_color">#10ffffff</color>
 </resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index d06af94..e236eb6 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -6,5 +6,5 @@
     <color name="grid_shape_background">@color/colorPrimary</color>
     <color name="overlay_item_background">@android:color/system_neutral1_0</color>
     <color name="overlay_item_system_background">@color/colorAccent</color>
-
+    <color name="overlay_blocker_color">#10000000</color>
 </resources>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 05e3f99..8be464f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -48,7 +48,7 @@
     <string name="overlays_settings_title">Styles</string>
     <string name="overlays_settings_summary">Change system default styles and colors</string>
     <string name="icon_shape_title">Icon shape</string>
-    <string name="primary_color_title">Primary color</string>
+    <string name="primary_color_title">Neutral color</string>
     <string name="accent_color_title">Accent color</string>
 
     <!-- doze on charge -->
@@ -127,4 +127,6 @@
     <string name="incall_vibrate_call_wait_summary">Device vibrate on call waiting</string>
     <string name="incall_vibrate_disconnect_title">Vibrate on disconnect</string>
     <string name="incall_vibrate_disconnect_summary">Device vibrate on call disconnect</string>
+    <string name="monet_overlay_enable_title">Enable dynamic colors based on wallpaper - Monet</string>
+    <string name="system_colors_title">System colors</string>
 </resources>