forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sugest to reuse architecture direct golang instead of add java code ... #2
Closed
MatejMagat305
wants to merge
23
commits into
andydotxyz:feature/backbutton
from
MatejMagat305:feature/backbutton
Closed
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
08e59d2
Update android.go
MatejMagat305 fc057e7
Update android.go
MatejMagat305 1a09e2a
move keyCode to processKey()
MatejMagat305 8d70fe5
fix func type
MatejMagat305 ce6241c
finish and reload ctx
MatejMagat305 41610bf
delete old ctx
MatejMagat305 500568f
quit
MatejMagat305 a1620c5
delete global
MatejMagat305 141a9e4
fix careless
MatejMagat305 e7d9865
Add files via upload
MatejMagat305 e569968
global ref set only on begin
MatejMagat305 c4d1931
fix mistakes ...
MatejMagat305 ebab39e
reset ctx when start and resume
MatejMagat305 3f35008
fix unwanted change
MatejMagat305 403f8d7
Update x11.go
MatejMagat305 01ca68b
Update android.c
MatejMagat305 c3ed183
Update x11.go
MatejMagat305 181dd7a
Update shiny.go
MatejMagat305 92511ae
Update darwin_ios.go
MatejMagat305 c0382f0
Update darwin_desktop.go
MatejMagat305 30c10c5
Update android.go
MatejMagat305 dafa6aa
Update GoNativeActivity.java
MatejMagat305 94ec8cb
Update x11.go
MatejMagat305 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ void hideKeyboard(JNIEnv* env); | |
void showFileOpen(JNIEnv* env, char* mimes); | ||
void showFileSave(JNIEnv* env, char* mimes, char* filename); | ||
void finish(JNIEnv* env, jobject ctx); | ||
void set_global(ANativeActivity *activity); | ||
void delete_ref(ANativeActivity *activity); | ||
|
||
void Java_org_golang_app_GoNativeActivity_filePickerReturned(JNIEnv *env, jclass clazz, jstring str); | ||
*/ | ||
|
@@ -78,18 +80,6 @@ var mimeMap = map[string]string{ | |
".txt": "text/plain", | ||
} | ||
|
||
// GoBack asks the OS to go to the previous app / activity | ||
func GoBack() { | ||
err := RunOnJVM(func(_, jniEnv, ctx uintptr) error { | ||
env := (*C.JNIEnv)(unsafe.Pointer(jniEnv)) | ||
C.finish(env, C.jobject(ctx)) | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatalf("app: %v", err) | ||
} | ||
} | ||
|
||
// RunOnJVM runs fn on a new goroutine locked to an OS thread with a JNIEnv. | ||
// | ||
// RunOnJVM blocks until the call to fn is complete. Any Java | ||
|
@@ -133,10 +123,12 @@ func callMain(mainPC uintptr) { | |
|
||
//export onStart | ||
func onStart(activity *C.ANativeActivity) { | ||
C.set_global(activity) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set current referencies on start and resume ... |
||
|
||
//export onResume | ||
func onResume(activity *C.ANativeActivity) { | ||
C.set_global(activity) | ||
} | ||
|
||
//export onSaveInstanceState | ||
|
@@ -146,23 +138,12 @@ func onSaveInstanceState(activity *C.ANativeActivity, outSize *C.size_t) unsafe. | |
|
||
//export onPause | ||
func onPause(activity *C.ANativeActivity) { | ||
C.delete_ref(activity) | ||
} | ||
|
||
//export onStop | ||
func onStop(activity *C.ANativeActivity) { | ||
} | ||
|
||
//export onBackPressed | ||
func onBackPressed() { | ||
k := key.Event{ | ||
Code: key.CodeBackButton, | ||
Direction: key.DirPress, | ||
} | ||
log.Println("Logging key event back") | ||
theApp.events.In() <- k | ||
|
||
k.Direction = key.DirRelease | ||
theApp.events.In() <- k | ||
C.delete_ref(activity) | ||
} | ||
|
||
//export onCreate | ||
|
@@ -177,6 +158,7 @@ func onCreate(activity *C.ANativeActivity) { | |
|
||
//export onDestroy | ||
func onDestroy(activity *C.ANativeActivity) { | ||
C.delete_ref(activity) | ||
activityDestroyed <- struct{}{} | ||
} | ||
|
||
|
@@ -230,6 +212,14 @@ type windowConfig struct { | |
pixelsPerPt float32 | ||
} | ||
|
||
func Finish() { | ||
RunOnJVM(func(vm, jniEnv, ctx uintptr) error { | ||
println("finish") | ||
env := (*C.JNIEnv)(unsafe.Pointer(jniEnv)) // not a Go heap pointer | ||
C.finish(env, C.jobject(ctx)) | ||
return nil | ||
}) | ||
} | ||
func windowConfigRead(activity *C.ANativeActivity) windowConfig { | ||
aconfig := C.AConfiguration_new() | ||
C.AConfiguration_fromAssetManager(aconfig, activity.assetManager) | ||
|
@@ -555,21 +545,22 @@ func runInputQueue(vm, jniEnv, ctx uintptr) error { | |
} | ||
} | ||
|
||
|
||
func processEvents(env *C.JNIEnv, q *C.AInputQueue) { | ||
var e *C.AInputEvent | ||
for C.AInputQueue_getEvent(q, &e) >= 0 { | ||
if C.AInputQueue_preDispatchEvent(q, e) != 0 { | ||
continue | ||
} | ||
processEvent(env, e) | ||
C.AInputQueue_finishEvent(q, e, 0) | ||
handle := processEvent(env, e) | ||
C.AInputQueue_finishEvent(q, e, C.int(handle)) | ||
} | ||
} | ||
|
||
func processEvent(env *C.JNIEnv, e *C.AInputEvent) { | ||
func processEvent(env *C.JNIEnv, e *C.AInputEvent) int { | ||
switch C.AInputEvent_getType(e) { | ||
case C.AINPUT_EVENT_TYPE_KEY: | ||
processKey(env, e) | ||
return processKey(env, e) | ||
case C.AINPUT_EVENT_TYPE_MOTION: | ||
// At most one of the events in this batch is an up or down event; get its index and change. | ||
upDownIndex := C.size_t(C.AMotionEvent_getAction(e)&C.AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> C.AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT | ||
|
@@ -596,21 +587,28 @@ func processEvent(env *C.JNIEnv, e *C.AInputEvent) { | |
default: | ||
log.Printf("unknown input event, type=%d", C.AInputEvent_getType(e)) | ||
} | ||
return 0 | ||
} | ||
|
||
func processKey(env *C.JNIEnv, e *C.AInputEvent) { | ||
func processKey(env *C.JNIEnv, e *C.AInputEvent) int { | ||
deviceID := C.AInputEvent_getDeviceId(e) | ||
if deviceID == 0 { | ||
// Software keyboard input, leaving for scribe/IME. | ||
return | ||
return 0 | ||
} | ||
keyCode := C.AKeyEvent_getKeyCode(e) | ||
if (keyCode == C.AKEYCODE_BACK) { | ||
println("back ok") | ||
return 1 // Handle back button press and return handle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well here you can put send event to your architekture ... |
||
} else if (keyCode == C.AKEYCODE_MENU) { | ||
return 1 // Handle menu button press | ||
} | ||
|
||
k := key.Event{ | ||
Rune: rune(C.getKeyRune(env, e)), | ||
Code: convAndroidKeyCode(int32(C.AKeyEvent_getKeyCode(e))), | ||
Code: convAndroidKeyCode(int32(keyCode)), | ||
} | ||
if k.Rune >= '0' && k.Rune <= '9' { // GBoard generates key events for numbers, but we see them in textChanged | ||
return | ||
return 0 | ||
} | ||
switch C.AKeyEvent_getAction(e) { | ||
case C.AKEY_STATE_DOWN: | ||
|
@@ -621,7 +619,8 @@ func processKey(env *C.JNIEnv, e *C.AInputEvent) { | |
k.Direction = key.DirNone | ||
} | ||
// TODO(crawshaw): set Modifiers. | ||
theApp.events.In() <- k | ||
go func() {theApp.events.In() <- k}() | ||
return 0 | ||
} | ||
|
||
func eglGetError() string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-set env at call function ...