From 49555346a92980b28bb676a8c5f86f072a93edac Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Mon, 7 Aug 2023 14:59:00 +0200 Subject: [PATCH 1/9] added App.beep() for Android; updated example "window" --- android/src/toga_android/app.py | 10 +++++++++- examples/window/window/app.py | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index 269bf49171..8db0a905a9 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -10,6 +10,10 @@ from .libs.android.view import Menu, MenuItem from .window import Window +import java +from android.net import Uri +from android.media import Ringtone, RingtoneManager + # `MainWindow` is defined here in `app.py`, not `window.py`, to mollify the test suite. MainWindow = Window @@ -207,7 +211,11 @@ def show_about_dialog(self): self.interface.factory.not_implemented("App.show_about_dialog()") def beep(self): - self.interface.factory.not_implemented("App.beep()") + uri_obj = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + uri = java.cast(Uri, uri_obj) + ring_obj = RingtoneManager.getRingtone(self.native.getApplicationContext(), uri) + ring = java.cast(Ringtone, ring_obj) + ring.play() def exit(self): pass diff --git a/examples/window/window/app.py b/examples/window/window/app.py index 2e770f561d..7dece3bb1c 100644 --- a/examples/window/window/app.py +++ b/examples/window/window/app.py @@ -105,6 +105,9 @@ def do_hide(self, widget): self.main_window.visible = True self.main_window.info_dialog("Here we go again", "I'm back!") + def do_beep(self, widget): + self.app.beep() + def exit_handler(self, app, **kwargs): self.close_count += 1 if self.close_count % 2 == 1: @@ -167,7 +170,10 @@ def startup(self): "Change content", on_press=self.do_next_content, style=btn_style ) btn_hide = toga.Button("Hide", on_press=self.do_hide, style=btn_style) - self.main_box = toga.Box( + btn_beep = toga.Button("Beep", on_press=self.do_beep, style=btn_style) + + self.main_box = toga.Box(style=Pack(direction=COLUMN)) + self.inner_box = toga.Box( children=[ self.label, btn_do_origin, @@ -183,9 +189,17 @@ def startup(self): btn_do_report, btn_change_content, btn_hide, + btn_beep, ], style=Pack(direction=COLUMN), ) + self.scroller = toga.ScrollContainer( + horizontal=False, + vertical=True, + style=Pack(flex=1, padding=10), + ) + self.scroller.content = self.inner_box + self.main_box.add(self.scroller) btn_change_back = toga.Button( "Go back", on_press=self.do_prev_content, style=btn_style From 476e4a2302c5b48a6f9c553abc66f7c85b27f7a0 Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Mon, 7 Aug 2023 15:16:19 +0200 Subject: [PATCH 2/9] added newsfragment --- changes/2068.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/2068.feature.rst diff --git a/changes/2068.feature.rst b/changes/2068.feature.rst new file mode 100644 index 0000000000..16e1a04a63 --- /dev/null +++ b/changes/2068.feature.rst @@ -0,0 +1 @@ +App.beep() has been implemented for Android. From 11f77dab451fa7fff1b5e7e25fa3fe8615736e5d Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Mon, 7 Aug 2023 15:42:58 +0200 Subject: [PATCH 3/9] fix pre-commit check --- android/src/toga_android/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index 8db0a905a9..bc8fab42c8 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -1,8 +1,11 @@ import asyncio +import java from rubicon.java import android_events import toga +from android.net import Uri +from android.media import Ringtone, RingtoneManager from toga.command import Group from .libs.activity import IPythonApp, MainActivity @@ -10,9 +13,6 @@ from .libs.android.view import Menu, MenuItem from .window import Window -import java -from android.net import Uri -from android.media import Ringtone, RingtoneManager # `MainWindow` is defined here in `app.py`, not `window.py`, to mollify the test suite. MainWindow = Window From 024a00fc97017743f4d9ca9abb62fd53aee0a91c Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Mon, 7 Aug 2023 15:48:01 +0200 Subject: [PATCH 4/9] fix pre-commit check --- android/src/toga_android/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index bc8fab42c8..a0dc85b406 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -4,8 +4,8 @@ from rubicon.java import android_events import toga -from android.net import Uri from android.media import Ringtone, RingtoneManager +from android.net import Uri from toga.command import Group from .libs.activity import IPythonApp, MainActivity From ca78120c09452b2f57629a1dd6f8698636f1777e Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Mon, 7 Aug 2023 15:54:34 +0200 Subject: [PATCH 5/9] fix pre-commit check --- android/src/toga_android/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index a0dc85b406..a2fe8cdf38 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -13,7 +13,6 @@ from .libs.android.view import Menu, MenuItem from .window import Window - # `MainWindow` is defined here in `app.py`, not `window.py`, to mollify the test suite. MainWindow = Window From bf84b962028447420ba3b8d6704e17d2b51f746c Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Sat, 19 Aug 2023 08:41:08 +0200 Subject: [PATCH 6/9] applied changes requested in the review --- examples/window/window/app.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/window/window/app.py b/examples/window/window/app.py index 7dece3bb1c..184ad0cc76 100644 --- a/examples/window/window/app.py +++ b/examples/window/window/app.py @@ -95,7 +95,7 @@ def do_next_content(self, widget): self.main_window.content = self.next_box def do_prev_content(self, widget): - self.main_window.content = self.main_box + self.main_window.content = self.main_scroller def do_hide(self, widget): self.main_window.visible = False @@ -172,7 +172,6 @@ def startup(self): btn_hide = toga.Button("Hide", on_press=self.do_hide, style=btn_style) btn_beep = toga.Button("Beep", on_press=self.do_beep, style=btn_style) - self.main_box = toga.Box(style=Pack(direction=COLUMN)) self.inner_box = toga.Box( children=[ self.label, @@ -193,13 +192,12 @@ def startup(self): ], style=Pack(direction=COLUMN), ) - self.scroller = toga.ScrollContainer( + self.main_scroller = toga.ScrollContainer( horizontal=False, vertical=True, - style=Pack(flex=1, padding=10), + style=Pack(flex=1), ) - self.scroller.content = self.inner_box - self.main_box.add(self.scroller) + self.main_scroller.content = self.inner_box btn_change_back = toga.Button( "Go back", on_press=self.do_prev_content, style=btn_style @@ -218,7 +216,7 @@ def startup(self): self.main_window.toolbar.add(restore_command) # Add the content on the main window - self.main_window.content = self.main_box + self.main_window.content = self.main_scroller # Show the main window self.main_window.show() From 0180452f401ea1ae33714cd1e8185ff6498290c5 Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Wed, 23 Aug 2023 20:25:15 +0200 Subject: [PATCH 7/9] removed unnecessary casts --- android/src/toga_android/app.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index a2fe8cdf38..0823217404 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -1,11 +1,9 @@ import asyncio -import java from rubicon.java import android_events import toga -from android.media import Ringtone, RingtoneManager -from android.net import Uri +from android.media import RingtoneManager from toga.command import Group from .libs.activity import IPythonApp, MainActivity @@ -210,11 +208,9 @@ def show_about_dialog(self): self.interface.factory.not_implemented("App.show_about_dialog()") def beep(self): - uri_obj = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) - uri = java.cast(Uri, uri_obj) - ring_obj = RingtoneManager.getRingtone(self.native.getApplicationContext(), uri) - ring = java.cast(Ringtone, ring_obj) - ring.play() + uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + ringtone = RingtoneManager.getRingtone(self.native.getApplicationContext(), uri) + ringtone.play() def exit(self): pass From a08823171c58e942dfa4027fd8124d0d147764e5 Mon Sep 17 00:00:00 2001 From: Tom Arn Date: Wed, 23 Aug 2023 22:18:35 +0200 Subject: [PATCH 8/9] fixes the error message which appeared during beep() --- android/src/toga_android/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/toga_android/app.py b/android/src/toga_android/app.py index 0823217404..cdea6612d1 100644 --- a/android/src/toga_android/app.py +++ b/android/src/toga_android/app.py @@ -208,7 +208,9 @@ def show_about_dialog(self): self.interface.factory.not_implemented("App.show_about_dialog()") def beep(self): - uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) + uri = RingtoneManager.getActualDefaultRingtoneUri( + self.native.getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION + ) ringtone = RingtoneManager.getRingtone(self.native.getApplicationContext(), uri) ringtone.play() From 608ec531e94772597bdf25bb5ce72c3086d99095 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 24 Aug 2023 07:19:24 +0800 Subject: [PATCH 9/9] Rename 2068.feature.rst to 2068.misc.rst --- changes/{2068.feature.rst => 2068.misc.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes/{2068.feature.rst => 2068.misc.rst} (100%) diff --git a/changes/2068.feature.rst b/changes/2068.misc.rst similarity index 100% rename from changes/2068.feature.rst rename to changes/2068.misc.rst