android, ios & linux: implement `open_in_browser`
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 23 Jun 2016 16:13:42 +0000 (12:13 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 27 Jun 2016 15:26:07 +0000 (11:26 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/ui/ui.nit
lib/ios/ui/ui.nit
lib/linux/ui.nit

index cd9f4ea..7e14b19 100644 (file)
@@ -348,3 +348,18 @@ redef class Android_app_Fragment
                };
        `}
 end
+
+redef class Text
+       redef fun open_in_browser
+       do to_java_string.native_open_in_browser(app.native_activity)
+end
+
+redef class JavaString
+       private fun native_open_in_browser(context: NativeContext)
+       in "Java" `{
+               android.content.Intent intent = new android.content.Intent(
+                       android.content.Intent.ACTION_VIEW,
+                       android.net.Uri.parse(self));
+               context.startActivity(intent);
+       `}
+end
index 48c7e12..d6ea633 100644 (file)
@@ -523,3 +523,15 @@ redef class UITableView
                self.dataSource = objc_delegate;
        `}
 end
+
+redef class Text
+       redef fun open_in_browser do to_nsstring.native_open_in_browser
+end
+
+redef class NSString
+       private fun native_open_in_browser
+       in "ObjC" `{
+               NSURL *nsurl = [NSURL URLWithString: self];
+               [[UIApplication sharedApplication] openURL: nsurl];
+       `}
+end
index 1e26f17..2c0eec1 100644 (file)
@@ -343,3 +343,7 @@ redef class TextInput
                super
        end
 end
+
+redef class Text
+       redef fun open_in_browser do system("xdg-open '{self.escape_to_sh}' &")
+end