Skip to content

Commit

Permalink
Merge pull request #2068 from t-arn/beep_android_1744a34
Browse files Browse the repository at this point in the history
Implementation of App.beep() for Android
  • Loading branch information
freakboy3742 authored Aug 23, 2023
2 parents 55aa2e3 + 608ec53 commit 127e8f7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion android/src/toga_android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rubicon.java import android_events

import toga
from android.media import RingtoneManager
from toga.command import Group

from .libs.activity import IPythonApp, MainActivity
Expand Down Expand Up @@ -207,7 +208,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 = RingtoneManager.getActualDefaultRingtoneUri(
self.native.getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION
)
ringtone = RingtoneManager.getRingtone(self.native.getApplicationContext(), uri)
ringtone.play()

def exit(self):
pass
Expand Down
1 change: 1 addition & 0 deletions changes/2068.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
App.beep() has been implemented for Android.
18 changes: 15 additions & 3 deletions examples/window/window/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -167,7 +170,9 @@ 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.inner_box = toga.Box(
children=[
self.label,
btn_do_origin,
Expand All @@ -183,9 +188,16 @@ def startup(self):
btn_do_report,
btn_change_content,
btn_hide,
btn_beep,
],
style=Pack(direction=COLUMN),
)
self.main_scroller = toga.ScrollContainer(
horizontal=False,
vertical=True,
style=Pack(flex=1),
)
self.main_scroller.content = self.inner_box

btn_change_back = toga.Button(
"Go back", on_press=self.do_prev_content, style=btn_style
Expand All @@ -204,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()
Expand Down

0 comments on commit 127e8f7

Please sign in to comment.