From ab4881bd8c920916b572ade2cd0e933689e36eb8 Mon Sep 17 00:00:00 2001 From: Orhidea Shatri Date: Wed, 28 Aug 2024 18:00:37 +0200 Subject: [PATCH 1/2] IDE-258 redesign disabled state of bricks to darker instead of grey --- .../content/bricks/EmptyEventBrick.java | 6 +- .../ui/recyclerview/adapter/BrickAdapter.kt | 82 ++++++++++++++++--- catroid/src/main/res/values/colors.xml | 7 +- 3 files changed, 78 insertions(+), 17 deletions(-) diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/EmptyEventBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/EmptyEventBrick.java index 69f1d314c07..3fcd5210523 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/EmptyEventBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/EmptyEventBrick.java @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -23,7 +23,6 @@ package org.catrobat.catroid.content.bricks; import android.content.Context; -import android.graphics.drawable.Drawable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -67,8 +66,7 @@ public View getView(Context context) { view.setAlpha(DISABLED_BRICK_ALPHA); View brickViewContainer = ((ViewGroup) view).getChildAt(1); - Drawable background = brickViewContainer.getBackground(); - BrickAdapter.colorAsCommentedOut(background); + BrickAdapter.colorAsCommentedOut(brickViewContainer); return view; } diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt index 903ef734deb..fec05dc773a 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt @@ -1,6 +1,6 @@ /* * Catroid: An on-device visual programming system for Android devices - * Copyright (C) 2010-2022 The Catrobat Team + * Copyright (C) 2010-2024 The Catrobat Team * () * * This program is free software: you can redistribute it and/or modify @@ -22,15 +22,19 @@ */ package org.catrobat.catroid.ui.recyclerview.adapter -import android.graphics.ColorMatrix -import android.graphics.ColorMatrixColorFilter -import android.graphics.drawable.Drawable +import android.graphics.PorterDuff +import android.graphics.PorterDuffColorFilter import android.view.View import android.view.ViewGroup +import android.view.ViewTreeObserver import android.widget.AdapterView import android.widget.AdapterView.OnItemLongClickListener import android.widget.BaseAdapter +import android.widget.Spinner +import android.widget.TextView import androidx.annotation.IntDef +import androidx.core.content.ContextCompat +import org.catrobat.catroid.R import org.catrobat.catroid.content.Script import org.catrobat.catroid.content.Sprite import org.catrobat.catroid.content.bricks.Brick @@ -42,7 +46,6 @@ import org.catrobat.catroid.content.bricks.UserDefinedReceiverBrick import org.catrobat.catroid.ui.dragndrop.BrickAdapterInterface import org.catrobat.catroid.ui.recyclerview.adapter.draganddrop.ViewStateManager import org.catrobat.catroid.ui.recyclerview.adapter.multiselection.MultiSelectionManager -import java.util.ArrayList import java.util.Collections class BrickAdapter(private val sprite: Sprite) : @@ -81,12 +84,67 @@ class BrickAdapter(private val sprite: Sprite) : const val CONNECTED_ONLY = 3 @JvmStatic - fun colorAsCommentedOut(background: Drawable) { - val matrix = ColorMatrix() - matrix.setSaturation(0f) - val filter = ColorMatrixColorFilter(matrix) - background.mutate() - background.colorFilter = filter + fun colorAsCommentedOut(view: View) { + val blackLayer = ContextCompat.getColor(view.context, R.color.commented_out_black_layer) + val filter = PorterDuffColorFilter(blackLayer, PorterDuff.Mode + .SRC_ATOP) + + view.background?.mutate()?.colorFilter = filter + + if (view is ViewGroup) { + for (i in 0 until view.childCount) { + when (val child = view.getChildAt(i)) { + is TextView -> commentOutTextView(child) + is Spinner -> commentOutSpinner(child) + } + } + } + } + + private fun commentOutTextView(textView: TextView) { + val white = ContextCompat.getColor(textView.context, R.color.solid_white) + val commentedOutWhite = ContextCompat.getColor(textView.context, R.color.commented_out_solid_white) + + val darkBlue = ContextCompat.getColor(textView.context, R.color.dark_blue) + val commentedOutDarkBlue = ContextCompat.getColor(textView.context, R.color.commented_out_dark_blue) + + val commentedOutColor = when (textView.currentTextColor) { + white -> commentedOutWhite + darkBlue -> commentedOutDarkBlue + else -> commentedOutWhite + } + + textView.setTextColor(commentedOutColor) + textView.background?.mutate()?.colorFilter = PorterDuffColorFilter(commentedOutColor, PorterDuff.Mode.SRC_ATOP) + } + + private fun commentOutSpinner(spinner: Spinner) { + val commentedOutWhite = ContextCompat.getColor(spinner.context, R.color + .commented_out_solid_white) + + spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + if (view is TextView) { + view.setTextColor(commentedOutWhite) + } + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + + } + } + + spinner.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + val selectedView = spinner.selectedView + if (selectedView is TextView) { + selectedView.setTextColor(commentedOutWhite) + } + spinner.viewTreeObserver.removeOnGlobalLayoutListener(this) + } + }) + + spinner.background?.mutate()?.colorFilter = PorterDuffColorFilter(commentedOutWhite, PorterDuff.Mode.SRC_ATOP) } } @@ -133,7 +191,7 @@ class BrickAdapter(private val sprite: Sprite) : val background = brickViewContainer.background if (item.isCommentedOut || item is EmptyEventBrick) { - colorAsCommentedOut(background) + colorAsCommentedOut(brickViewContainer) } else { background.clearColorFilter() } diff --git a/catroid/src/main/res/values/colors.xml b/catroid/src/main/res/values/colors.xml index 207b3845b73..1063f2280cb 100644 --- a/catroid/src/main/res/values/colors.xml +++ b/catroid/src/main/res/values/colors.xml @@ -1,7 +1,7 @@ + #616161 + #131F3C + #9E000000 + #04222C #00475E From a19abbb8c981f5db4f76de9aa12bb22778c66ced Mon Sep 17 00:00:00 2001 From: Orhidea Shatri Date: Wed, 28 Aug 2024 21:31:59 +0200 Subject: [PATCH 2/2] IDE-258 fix detekt warnings --- .../catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt index fec05dc773a..78682a0dad4 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt +++ b/catroid/src/main/java/org/catrobat/catroid/ui/recyclerview/adapter/BrickAdapter.kt @@ -129,8 +129,8 @@ class BrickAdapter(private val sprite: Sprite) : } } + @Suppress("EmptyFunctionBlock") override fun onNothingSelected(parent: AdapterView<*>?) { - } }