android, ios & linux: implement `open_in_browser`
[nit.git] / lib / android / ui / ui.nit
index e9ea641..7e14b19 100644 (file)
 # limitations under the License.
 
 # Views and services to use the Android native user interface
-module ui
+module ui is
+       # `adjustPan` allows to use EditText in a ListLayout
+       android_manifest_activity """android:windowSoftInputMode="adjustPan""""
+end
 
 # Implementation note:
 #
@@ -78,6 +81,19 @@ redef class App
        end
 end
 
+redef class Activity
+       redef fun on_back_pressed
+       do
+               var window = app.window
+               if window.enable_back_button then
+                       window.on_back_button
+                       return true
+               end
+
+               return false
+       end
+end
+
 # On Android, a window is implemented with the fragment `native`
 redef class Window
        redef var native = (new Android_app_Fragment(self)).new_global_ref
@@ -228,7 +244,7 @@ redef class TextView
                else // if (align > 0.5d)
                        g = android.view.Gravity.RIGHT;
 
-               view.setGravity(g);
+               view.setGravity(g | android.view.Gravity.CENTER_VERTICAL);
        `}
 end
 
@@ -332,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