clach04 avatar clach04 committed 601498c Draft

Android support for QR code display (requires "ZXing Team" "Barcode Scanner" app).

Comments (0)

Files changed (1)

 # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
 """Serve a single file, showing a QR code of the shared file URL.
-Uses Google chart API to generate URL and then opens that URL (which
-requires an internet connection).
-Alternatives are PIL/SVG generators:
+On Android expects and uses SL4A and "ZXing Team" "Barcode Scanner" app.
+On desktop uses Google chart API to generate URL and then opens
+that URL (which requires an internet connection).
+Alternatives to consider are PIL/SVG generators:
 import os
 import sys
-import webbrowser
+    import webbrowser
+except ImportError:
+    webbrowser = None
 import urllib
 import woof
+    # from
+    import android
+except ImportError:
+    android = None
     import easydialogs
         easydialogs = None
+def gen_and_show_qr(t):
+    if android:
+        # NOTE this also requires
+        #
+        droid = android.Android()
+        #
+        extras = {}
+        extras['ENCODE_TYPE'] = 'TEXT_TYPE'
+        extras['ENCODE_DATA'] = t
+        intent = droid.makeIntent('', None, None, extras).result
+        droid.startActivityIntent(intent)
+    else:
+        print t
+        url_str = gen_url(t)
+        if webbrowser:
 def gen_url(url, image_size=547):
     """Construct QR generator google URL with max size, from:
     port = 8080
     url_str = "http://%s:%s/" % (ip_addr, port)
     print url_str
-    url_str = gen_url(url_str)
-    print url_str
+    gen_and_show_qr(url_str)
     woof.serve_files(filename, port=port)
     return 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.