Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-258 Redesign "disabled" state of bricks #5023

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -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
Expand All @@ -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) :
Expand Down Expand Up @@ -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)
}
}

@Suppress("EmptyFunctionBlock")
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)
}
}

Expand Down Expand Up @@ -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()
}
Expand Down
7 changes: 6 additions & 1 deletion catroid/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Catroid: An on-device visual programming system for Android devices
~ Copyright (C) 2010-2023 The Catrobat Team
~ Copyright (C) 2010-2024 The Catrobat Team
~ (<http://developer.catrobat.org/credits>)
~
~ This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,6 +36,11 @@
<color name="view_holder_item_details">@color/solid_white</color>
<color name="spinner_icon_and_inactive_elements">@color/solid_white</color>

<!-- Disabled text colors -->
<color name="commented_out_solid_white">#616161</color>
<color name="commented_out_dark_blue">#131F3C</color>
<color name="commented_out_black_layer">#9E000000</color>

<!-- Backgrounds -->
<color name="app_background">#04222C</color>
<color name="button_background">#00475E</color>
Expand Down