Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/GioView.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -80,7 +82,7 @@ public GioView(Context context, AttributeSet attrs) {
setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

// Late initialization of the Go runtime to wait for a valid context.
Gio.init(context.getApplicationContext());

Expand Down Expand Up @@ -171,6 +173,12 @@ private void setCursor(int id) {
setPointerIcon(pointerIcon);
}

private void openURL(String url) {
Uri webpage = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
((Activity) this.getContext()).startActivity(intent);
}

private void setOrientation(int id, int fallback) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
id = fallback;
Expand Down
2 changes: 2 additions & 0 deletions app/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ type driver interface {
SetCursor(cursor pointer.Cursor)
// Wakeup wakes up the event loop and sends a WakeupEvent.
Wakeup()
// OpenUrl open explorer at a specific url location
OpenUrl(url string)
// Perform actions on the window.
Perform(system.Action)
// EditorStateChanged notifies the driver that the editor state changed.
Expand Down
9 changes: 9 additions & 0 deletions app/os_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ var gioView struct {
restartInput C.jmethodID
updateSelection C.jmethodID
updateCaret C.jmethodID
openURL C.jmethodID
}

type pixelInsets struct {
Expand Down Expand Up @@ -482,6 +483,7 @@ func Java_org_gioui_GioView_onCreateView(env *C.JNIEnv, class C.jclass, view C.j
m.restartInput = getMethodID(env, class, "restartInput", "()V")
m.updateSelection = getMethodID(env, class, "updateSelection", "()V")
m.updateCaret = getMethodID(env, class, "updateCaret", "(FFFFFFFFFF)V")
m.openURL = getMethodID(env, class, "openURL", "(Ljava/lang/String;)V")
})
view = C.jni_NewGlobalRef(env, view)
wopts := <-mainWindow.out
Expand Down Expand Up @@ -1361,6 +1363,13 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
})
}

func (w *window) OpenUrl(url string) {
runInJVM(javaVM(), func(env *C.JNIEnv) {
str := javaString(env, url)
callVoidMethod(env, w.view, gioView.openURL, jvalue(str))
})
}

func (w *window) Wakeup() {
runOnMain(func(env *C.JNIEnv) {
w.callbacks.Event(wakeupEvent{})
Expand Down
15 changes: 15 additions & 0 deletions app/os_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ static void writeClipboard(unichar *chars, NSUInteger length) {
}
}

static void openURL(CFTypeRef str) {
@autoreleasepool {
NSString *s = (__bridge NSString *)str;
NSURL *url = [NSURL URLWithString:s];
UIApplication *application = [UIApplication sharedApplication];
[application openURL:url options:@{} completionHandler:nil];
}
}

static CFTypeRef readClipboard(void) {
@autoreleasepool {
UIPasteboard *p = UIPasteboard.generalPasteboard;
Expand Down Expand Up @@ -303,6 +312,12 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
w.cursor = windowSetCursor(w.cursor, cursor)
}

func (w *window) OpenUrl(url string) {
cstr := stringToNSString(url)
defer C.CFRelease(cstr)
C.openURL(cstr)
}

func (w *window) onKeyCommand(name string) {
w.w.Event(key.Event{
Name: name,
Expand Down
4 changes: 4 additions & 0 deletions app/os_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
style.Set("cursor", webCursor[cursor])
}

func (w *window) OpenUrl(url string) {
js.Global().Call("open", url, "_blank", "")
}

func (w *window) Wakeup() {
select {
case w.wakeups <- struct{}{}:
Expand Down
6 changes: 6 additions & 0 deletions app/os_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package app
import (
"errors"
"image"
"os/exec"
"runtime"
"time"
"unicode"
Expand Down Expand Up @@ -443,6 +444,11 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
w.cursor = windowSetCursor(w.cursor, cursor)
}

func (w *window) OpenUrl(url string) {
cmd := exec.Command("open", url)
cmd.Run()
}

func (w *window) EditorStateChanged(old, new editorState) {
if old.Selection.Range != new.Selection.Range || old.Snippet != new.Snippet {
C.discardMarkedText(w.view)
Expand Down
6 changes: 6 additions & 0 deletions app/os_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package app

import (
"errors"
"os/exec"
"unsafe"

"gioui.org/io/pointer"
Expand Down Expand Up @@ -98,3 +99,8 @@ var xCursor = [...]string{
pointer.CursorNorthEastSouthWestResize: "fd_double_arrow",
pointer.CursorNorthWestSouthEastResize: "bd_double_arrow",
}

func (w *window) OpenUrl(url string) {
cmd := exec.Command("xdg-open", url)
cmd.Run()
}
6 changes: 6 additions & 0 deletions app/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"image"
"os/exec"
"runtime"
"sort"
"strings"
Expand Down Expand Up @@ -768,6 +769,11 @@ func (w *window) SetCursor(cursor pointer.Cursor) {
}
}

func (w *window) OpenUrl(url string) {
cmd := exec.Command("cmd", "/c", "start", url)
cmd.Run()
}

// windowsCursor contains mapping from pointer.Cursor to an IDC.
var windowsCursor = [...]uint16{
pointer.CursorDefault: windows.IDC_ARROW,
Expand Down
1 change: 1 addition & 0 deletions app/permission/networkstate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Package networkstate implements permissions to access network connectivity infor

The following entries will be added to AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
*/
package networkstate
6 changes: 6 additions & 0 deletions app/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ func (w *Window) frame(frame *op.Ops, viewport image.Point) error {
return w.gpu.Frame(frame, target, viewport)
}

func (w *Window) OpenUrl(url string) {
w.driverDefer(func(d driver) {
d.OpenUrl(url)
})
}

func (w *Window) processFrame(d driver, frameStart time.Time) {
for k := range w.semantic.ids {
delete(w.semantic.ids, k)
Expand Down