comparison cagou/core/platform_/android.py @ 380:9d3481663964

android: handle new SàT specific "action" dict which may be attach to an intent: this data is used with notifications to tell the frontend which widget/target to open.
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents 4d660b252487
children eb3f622d8791
comparison
equal deleted inserted replaced
379:1da3c379205b 380:9d3481663964
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import sys 19 import sys
20 import os 20 import os
21 import socket 21 import socket
22 import json
22 from functools import partial 23 from functools import partial
24 from urllib.parse import urlparse
23 from jnius import autoclass, cast 25 from jnius import autoclass, cast
24 from android import activity 26 from android import activity
25 from sat.core.i18n import _ 27 from sat.core.i18n import _
26 from sat.core import log as logging 28 from sat.core import log as logging
27 from urllib.parse import urlparse 29 from sat_frontends.tools import jid
28 from cagou.core.constants import Const as C 30 from cagou.core.constants import Const as C
29 from cagou.core import dialog 31 from cagou.core import dialog
30 from cagou import G 32 from cagou import G
31 from kivy.clock import Clock 33 from kivy.clock import Clock
32 from .base import Platform as BasePlatform 34 from .base import Platform as BasePlatform
50 STATE_RUNNING = b"running" 52 STATE_RUNNING = b"running"
51 STATE_PAUSED = b"paused" 53 STATE_PAUSED = b"paused"
52 STATE_STOPPED = b"stopped" 54 STATE_STOPPED = b"stopped"
53 SOCKET_DIR = "/data/data/org.salutatoi.cagou/" 55 SOCKET_DIR = "/data/data/org.salutatoi.cagou/"
54 SOCKET_FILE = ".socket" 56 SOCKET_FILE = ".socket"
57 INTENT_EXTRA_ACTION = AndroidString("org.salut-a-toi.IntentAction")
55 58
56 59
57 class Platform(BasePlatform): 60 class Platform(BasePlatform):
58 61
59 def __init__(self): 62 def __init__(self):
188 191
189 def on_new_intent(self, intent): 192 def on_new_intent(self, intent):
190 log.debug("on_new_intent") 193 log.debug("on_new_intent")
191 action = intent.getAction(); 194 action = intent.getAction();
192 intent_type = intent.getType(); 195 intent_type = intent.getType();
193 if action == Intent.ACTION_SEND: 196 if action == Intent.ACTION_MAIN:
197 action_str = intent.getStringExtra(INTENT_EXTRA_ACTION)
198 if action_str is not None:
199 action = json.loads(action_str)
200 log.debug(f"Extra action found: {action}")
201 action_type = action.get('type')
202 if action_type == "open":
203 try:
204 widget = action['widget']
205 target = action['target']
206 except KeyError as e:
207 log.warning(f"incomplete action {action}: {e}")
208 else:
209 current_profile = next(iter(G.host.profiles))
210 Clock.schedule_once(
211 lambda *args: G.host.doAction(
212 widget, jid.JID(target), [current_profile]),
213 0)
214 else:
215 log.warning(f"unexpected action: {action}")
216
217 text = None
218 uri = None
219 path = None
220 elif action == Intent.ACTION_SEND:
194 # we have receiving data to share, we parse the intent data 221 # we have receiving data to share, we parse the intent data
195 # and show the share widget 222 # and show the share widget
196 data = {} 223 data = {}
197 text = intent.getStringExtra(Intent.EXTRA_TEXT) 224 text = intent.getStringExtra(Intent.EXTRA_TEXT)
198 if text is not None: 225 if text is not None: