Mercurial > libervia-desktop-kivy
annotate cagou/core/platform_/android.py @ 353:19422bbd9c8e
core (widgets handler): refactoring:
- CagouWidget now has class properties (to be overridden when needed) which indicate how
if the widget handle must add a wrapping ScreenManager (global_screen_manager) or show
all instances of the class in a Carousel (collection_carousel). If none of those
options is used, a ScrollView will be wrapping the widget, to be sure that the widget
will be resized correctly when necessary (without it, the widget could still be
drawn in the backround when the size is too small and overflow on the WidgetWrapper,
this would be the case with WidgetSelector)
- some helper methods/properties have been added to CagouWidget. Check docstrings for
details
- better handling of (in)visible widget in WidgetsHandler
- thanks to the new wrapping ScrollView, WidgetSelect will show scroll bars if the
available space is too small.
- bugs fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 18:44:35 +0100 |
parents | a3cefa7158dc |
children | 4d3a0c4f2430 |
rev | line source |
---|---|
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import sys |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
20 import os |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
21 import socket |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from jnius import autoclass, cast |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from android import activity |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.core import log as logging |
345
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
25 from urllib.parse import urlparse |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from cagou.core.constants import Const as C |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from cagou import G |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from kivy.clock import Clock |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
29 from .base import Platform as BasePlatform |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 log = logging.getLogger(__name__) |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 service = autoclass('org.salutatoi.cagou.ServiceBackend') |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 mActivity = autoclass('org.kivy.android.PythonActivity').mActivity |
345
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
36 Intent = autoclass('android.content.Intent') |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
37 AndroidString = autoclass('java.lang.String') |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
38 Uri = autoclass('android.net.Uri') |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 ImagesMedia = autoclass('android.provider.MediaStore$Images$Media') |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 AudioMedia = autoclass('android.provider.MediaStore$Audio$Media') |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 VideoMedia = autoclass('android.provider.MediaStore$Video$Media') |
345
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
42 |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 DATA = '_data' |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 STATE_RUNNING = b"running" |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 STATE_PAUSED = b"paused" |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 STATE_STOPPED = b"stopped" |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 SOCKET_DIR = "/data/data/org.salutatoi.cagou/" |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 SOCKET_FILE = ".socket" |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
52 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
53 class Platform(BasePlatform): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
54 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
55 def __init__(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
56 super().__init__() |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
57 # cache for callbacks to run when profile is plugged |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
58 self.cache = [] |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
59 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
60 def init_platform(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
61 # sys.platform is "linux" on android by default |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
62 # so we change it to allow backend to detect android |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
63 sys.platform = "android" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
64 C.PLUGIN_EXT = 'pyc' |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
65 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
66 def on_app_build(self, wid): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
67 # we don't want menu on Android |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
68 wid.root_menus.height = 0 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
69 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
70 def on_host_init(self, host): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
71 argument = '' |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
72 service.start(mActivity, argument) |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
74 activity.bind(on_new_intent=self.on_new_intent) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
75 self.cache.append((self.on_new_intent, mActivity.getIntent())) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
76 host.addListener('profilePlugged', self.onProfilePlugged) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
77 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
78 def on_initFrontendState(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
79 # XXX: we use a separated socket instead of bridge because if we |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
80 # try to call a bridge method in on_pause method, the call data |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
81 # is not written before the actual pause |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
82 s = self._frontend_status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
83 s.connect(os.path.join(SOCKET_DIR, SOCKET_FILE)) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
84 s.sendall(STATE_RUNNING) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
85 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
86 def onProfilePlugged(self, profile): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
87 log.debug("ANDROID profilePlugged") |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
88 for method, *args in self.cache: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
89 method(*args) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
90 del self.cache |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
91 G.host.removeListener("profilePlugged", self.onProfilePlugged) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
92 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
93 def on_pause(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
94 G.host.sync = False |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
95 self._frontend_status_socket.sendall(STATE_PAUSED) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
96 return True |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
98 def on_resume(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
99 self._frontend_status_socket.sendall(STATE_RUNNING) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
100 G.host.sync = True |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
101 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
102 def on_stop(self): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
103 self._frontend_status_socket.sendall(STATE_STOPPED) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
104 self._frontend_status_socket.close() |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
105 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
106 def getPathFromUri(self, uri): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
107 cursor = mActivity.getContentResolver().query(uri, None, None, None, None) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
108 if cursor is None: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
109 return uri.getPath() |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 else: |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
111 cursor.moveToFirst() |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
112 # FIXME: using DATA is not recommended (and DATA is deprecated) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
113 # we should read directly the file with |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
114 # ContentResolver#openFileDescriptor(Uri, String) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
115 col_idx = cursor.getColumnIndex(DATA); |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
116 if col_idx == -1: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
117 return uri.getPath() |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
118 return cursor.getString(col_idx) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
119 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
120 def on_new_intent(self, intent): |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
121 log.debug("on_new_intent") |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
122 action = intent.getAction(); |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
123 intent_type = intent.getType(); |
345
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
124 if action == Intent.ACTION_SEND: |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
125 # we have receiving data to share, we parse the intent data |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
126 # and show the share widget |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
127 data = {} |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
128 text = intent.getStringExtra(Intent.EXTRA_TEXT) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
129 if text is not None: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
130 data['text'] = text |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
131 item = intent.getParcelableExtra(Intent.EXTRA_STREAM) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
132 if item is not None: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
133 uri = cast('android.net.Uri', item) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
134 data['uri'] = uri.toString() |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
135 path = self.getPathFromUri(uri) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
136 if path is not None: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
137 data['path'] = path |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
138 else: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
139 uri = None |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
140 path = None |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
141 |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
142 Clock.schedule_once(lambda *args: G.host.share(intent_type, data), 0) |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
143 else: |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
144 text = None |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 uri = None |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 path = None |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
148 msg = (f"NEW INTENT RECEIVED\n" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
149 f"type: {intent_type}\n" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
150 f"action: {action}\n" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
151 f"text: {text}\n" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
152 f"uri: {uri}\n" |
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
153 f"path: {path}") |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
342
89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents:
322
diff
changeset
|
155 log.debug(msg) |
345
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
156 |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
157 def open_url(self, url, wid=None): |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
158 parsed_url = urlparse(url) |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
159 if parsed_url.scheme == "geo": |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
160 intent = Intent(Intent.ACTION_VIEW) |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
161 intent.setData(Uri.parse(url)) |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
162 if mActivity.getPackageManager() is not None: |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
163 activity = cast('android.app.Activity', mActivity) |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
164 activity.startActivity(intent) |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
165 else: |
a3cefa7158dc
android: open "geo:" URL using an Intent
Goffi <goffi@goffi.org>
parents:
342
diff
changeset
|
166 super().open_url(self, url, wid) |