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

Implemented Divider Widget on Android. #2181

Merged
merged 7 commits into from
Nov 1, 2023
Merged
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
28 changes: 18 additions & 10 deletions android/src/toga_android/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .widgets.canvas import Canvas
from .widgets.dateinput import DateInput
from .widgets.detailedlist import DetailedList
from .widgets.divider import Divider
from .widgets.imageview import ImageView
from .widgets.label import Label
from .widgets.multilinetextinput import MultilineTextInput
Expand All @@ -33,34 +34,41 @@ def not_implemented(feature):

__all__ = [
"App",
"Box",
"Button",
"Canvas",
"Command",
"DateInput",
"MainWindow",
"not_implemented",
# Resources
"dialogs",
"Font",
"Icon",
"Image",
"Paths",
# Widgets
# ActivityIndicator
"Box",
"Button",
"Canvas",
"DateInput",
"DetailedList",
"Divider",
"ImageView",
"Label",
"MainWindow",
"MultilineTextInput",
"NumberInput",
# "OptionContainer",
"PasswordInput",
"ProgressBar",
"ScrollContainer",
# "SplitContainer",
"Selection",
"Slider",
"ScrollContainer",
"Switch",
"Table",
"TextInput",
"TimeInput",
# "Tree",
"WebView",
"Window",
"DetailedList",
"not_implemented",
"Paths",
"dialogs",
]


Expand Down
42 changes: 42 additions & 0 deletions android/src/toga_android/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from android.graphics import Color
from android.view import View
from android.widget import LinearLayout
from travertino.size import at_least

from .base import Widget


class Divider(Widget):
def create(self):
self.native = View(self._native_activity)

# Background color needs to be set or else divider will not be visible.
self.native.setBackgroundColor(Color.LTGRAY)

self._direction = self.interface.HORIZONTAL

def set_background_color(self, value):
self.set_background_simple(value)

def get_direction(self):
return self._direction

def set_direction(self, value):
self._direction = value

if value == self.interface.VERTICAL:
# Set the height for a vertical divider
params = LinearLayout.LayoutParams(1, self.interface._MIN_HEIGHT)
else:
# Set the width for a horizontal divider
params = LinearLayout.LayoutParams(self.interface._MIN_WIDTH, 1)

self.native.setLayoutParams(params)

def rehint(self):
if self.get_direction() == self.interface.VERTICAL:
self.interface.intrinsic.width = 1
self.interface.intrinsic.height = at_least(self.native.getHeight())
else:
self.interface.intrinsic.width = at_least(self.native.getWidth())
self.interface.intrinsic.height = 1
7 changes: 7 additions & 0 deletions android/tests_backend/widgets/divider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from java import jclass

from .base import SimpleProbe


class DividerProbe(SimpleProbe):
native_class = jclass("android.view.View")
1 change: 1 addition & 0 deletions changes/2181.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Divider widget was implemented on Android.
2 changes: 1 addition & 1 deletion docs/reference/data/widgets_by_platform.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Button,General Widget,:class:`~toga.Button`,Basic clickable Button,|y|,|y|,|y|,|
Canvas,General Widget,:class:`~toga.Canvas`,A drawing area for 2D vector graphics.,|y|,|y|,|y|,|y|,|y|,,
DateInput,General Widget,:class:`~toga.DateInput`,A widget to select a calendar date,,,|y|,,|y|,,
DetailedList,General Widget,:class:`~toga.DetailedList`,"An ordered list of content where each item has an icon, a main heading, and a line of supplementary text.",|y|,|y|,|b|,|y|,|y|,,
Divider,General Widget,:class:`~toga.Divider`,A horizontal or vertical line,|y|,|y|,|y|,,,|b|,
Divider,General Widget,:class:`~toga.Divider`,A horizontal or vertical line,|y|,|y|,|y|,,|y|,|b|,
ImageView,General Widget,:class:`~toga.ImageView`,A widget that displays an image,|y|,|y|,|y|,|y|,|y|,,
Label,General Widget,:class:`~toga.Label`,Text label,|y|,|y|,|y|,|y|,|y|,|b|,|b|
MultilineTextInput,General Widget,:class:`~toga.MultilineTextInput`,Multi-line Text Input field,|y|,|y|,|y|,|y|,|y|,,
Expand Down
2 changes: 1 addition & 1 deletion testbed/tests/widgets/test_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@pytest.fixture
async def widget():
skip_on_platforms("android", "iOS")
skip_on_platforms("iOS")
return toga.Divider()


Expand Down