Skip to content

Commit cedda24

Browse files
committed
Merge pull request kivy#189 from alanjds/custom_intent_filters
Custom actions and categories for BroadcastReceiver
2 parents f15640c + 1385f38 commit cedda24

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

recipes/android/src/android/broadcast.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,19 @@ def __init__(self, callback, actions=None, categories=None):
2424
if not actions and not categories:
2525
raise Exception('You need to define at least actions or categories')
2626

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

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

4541
# resolve android API
4642
PythonActivity = autoclass('org.renpy.android.PythonActivity')

0 commit comments

Comments
 (0)