Skip to content
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
31 changes: 22 additions & 9 deletions android/src/toga_android/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
from android.widget import ImageView, LinearLayout, RelativeLayout, ScrollView, TextView
from java import dynamic_proxy

from .base import Widget


def _resolve_theme_color(view, attr_id):
ctx = view.getContext()
ta = ctx.getTheme().obtainStyledAttributes([attr_id])
try:
if not ta.hasValue(0):
# CI's emulator theme always defines textColorPrimary/Secondary,
# so this path can't be exercised there.
raise RuntimeError( # pragma: no cover
f"Required theme color attribute not found: {attr_id}"
)
return ta.getColor(0, 0)
finally:
ta.recycle()
Comment on lines +14 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... is there anywhere else where we might anticipate that this function gets used? If so maybe move it into libs folder? I'm not so sure though so don't do this yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I suggest moving it to the base Widget class, and then it can also be used by the calls to getColor in DetailedList.create and Table.create. Note that self._native_activity is already a Context, so there's no need to require the existence of a View.



try:
from androidx.swiperefreshlayout.widget import SwipeRefreshLayout
except ImportError: # pragma: no cover
Expand All @@ -16,9 +34,6 @@
SwipeRefreshLayout = None


from .base import Widget


class DetailedListOnClickListener(dynamic_proxy(View.OnClickListener)):
def __init__(self, impl, row_number):
super().__init__()
Expand Down Expand Up @@ -180,15 +195,13 @@ def get_string(value):
top_text = TextView(self._native_activity)
top_text.setText(get_string(title))
top_text.setTextSize(20.0)
top_text.setTextColor(
self._native_activity.getResources().getColor(R.color.black)
)
top_text.setTextColor(_resolve_theme_color(top_text, R.attr.textColorPrimary))
bottom_text = TextView(self._native_activity)
bottom_text.setTextColor(
self._native_activity.getResources().getColor(R.color.black)
)
bottom_text.setText(get_string(subtitle))
bottom_text.setTextSize(16.0)
bottom_text.setTextColor(
_resolve_theme_color(bottom_text, R.attr.textColorSecondary)
)
top_text_params = LinearLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.MATCH_PARENT,
Expand Down
1 change: 1 addition & 0 deletions changes/3751.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Android: DetailedList now uses theme-resolved text colors (Primary/Secondary) instead of hard-coded black, fixing unreadable text in dark mode.
Loading