Skip to content

Custom actions and categories for BroadcastReceiver #189

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

Merged
merged 4 commits into from
Feb 10, 2014
Merged
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
24 changes: 10 additions & 14 deletions recipes/android/src/android/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@ def __init__(self, callback, actions=None, categories=None):
if not actions and not categories:
raise Exception('You need to define at least actions or categories')

# resolve actions/categories first
Intent = autoclass('android.content.Intent')
resolved_actions = []
if actions:
for x in actions:
name = 'ACTION_{}'.format(x.upper())
def _expand_partial_name(partial_name):
if '.' in partial_name:
return partial_name # Its actually a full dotted name
else:
name = 'ACTION_{}'.format(partial_name.upper())
if not hasattr(Intent, name):
raise Exception('The intent {} doesnt exist'.format(name))
resolved_actions += [getattr(Intent, name)]
return getattr(Intent, name)

resolved_categories = []
if categories:
for x in categories:
name = 'CATEGORY_{}'.format(x.upper())
if not hasattr(Intent, name):
raise Exception('The intent {} doesnt exist'.format(name))
resolved_categories += [getattr(Intent, name)]
# resolve actions/categories first
Intent = autoclass('android.content.Intent')
resolved_actions = [_expand_partial_name(x) for x in actions or []]
resolved_categories = [_expand_partial_name(x) for x in categories or []]

# resolve android API
PythonActivity = autoclass('org.renpy.android.PythonActivity')
Expand Down