2
0
mirror of synced 2025-02-23 14:58:12 +00:00

599 Commits

Author SHA1 Message Date
David Crawshaw
48637192de gl: fix comment, simplify queue capacity
Change-Id: I24f4cc3267c8db117a2c9551c5236fa2453da9f3
Reviewed-on: https://go-review.googlesource.com/15393
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-05 21:06:53 +00:00
Dan Caddigan
ca60936f19 example/ivy/android: fix parens grouping example
The current example 2**(2+3) yields the same result as not using
parenthesis.  The "grouped differently" example should use (2**2)+3
so that it yields a different result.

Change-Id: If5f63ec03adba4402c51822d6c13646a26384730
Reviewed-on: https://go-review.googlesource.com/14960
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
2015-10-02 19:42:16 +00:00
Burcu Dogan
c58aba718c cmd/gomobile: title case framework bundles
Traditionally, framework bundles have title case names such as
CoreFoundation.framework and UIKIt.framework.

gomobile bind should generate framework bundles named similarly,
following this convention.

Change-Id: Ia6082ed351ddc6fc97e0435e24e5f79c5afbaea4
Reviewed-on: https://go-review.googlesource.com/15330
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-02 04:47:58 +00:00
David Crawshaw
560c1bec66 cmd/gomobile: print stderr on xcrun failure
The stderr includes a helpful note from Xcode about how to fix it.

Fixes golang/go#12515

Change-Id: I4eb944f29a7a3e39e2f4150c27a53e04d02e5d09
Reviewed-on: https://go-review.googlesource.com/15300
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-10-01 18:48:56 +00:00
Hyang-Ah (Hana) Kim
c3c5f8745b cmd/gomobile: fix minSdkVersion formatting for bind.
The fix for golang/go#12661 was incorrect.

Fixes golang/go#12809.

Change-Id: Ic2cfedcc99ced0241a5756fb36f6f9ae5a6b7287
Reviewed-on: https://go-review.googlesource.com/15270
Reviewed-by: Burcu Dogan <jbd@google.com>
2015-10-01 16:59:24 +00:00
Hyang-Ah (Hana) Kim
60728759f9 bind: add const type support
Update golang/go#12475

Change-Id: I7fdc22462b5925c84ebbeb54517032c2fbd0545b
Reviewed-on: https://go-review.googlesource.com/15120
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-30 20:56:48 +00:00
Hyang-Ah (Hana) Kim
2cd6a4d2c6 cmd/gomobile: specify minSdkVersion for .aar file.
Fixes golang/go#12661.

Change-Id: I9f37159cd8090454bf2dd59126bece6647b9f3b8
Reviewed-on: https://go-review.googlesource.com/14883
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-30 19:08:35 +00:00
David Crawshaw
27e7ed5775 gl: check for concurrent use of a gl.Context
It is an error to use a gl.Context concurrently. (Each Context
contains a state machine, so there is no way this can work.)
Up until now only the GL driver could report such a misuse, and
it generally does a poor job of it. Our command buffer adds some
small oppertunity for the race detector to help, but it makes it
harder to debug other kinds of driver crashes, so it is worth
disabling in debug mode.

To make it easy, compiling with -tags gldebug now inserts an
explicit check that there are no other active GL calls outstanding.

Adding something like:

	go func() {
		for {
			glctx.GetInteger(gl.ALPHA_BITS)
		}
	}()

to x/mobile/example/basic now reliably crashes when compiled
with -tags gldebug, providing a stack trace that includes both
misbehaving goroutines.

Change-Id: I3d85d94220bca2a15eaf2742f13b44db1f3428bf
Reviewed-on: https://go-review.googlesource.com/15180
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-30 15:23:41 +00:00
David Crawshaw
aacc7aa5ab gl: mark all functions as blocking in debug mode
This means that if the OpenGL driver crashes, the stack trace will
contain a goroutine blocked in the function that caused the panic.

Fixes golang/go#12786

Change-Id: I039c74f9e24de777b925475a50e8c96129692f70
Reviewed-on: https://go-review.googlesource.com/15160
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-30 12:17:57 +00:00
David Crawshaw
0081b7ad84 gl: compatibility with cgo pointer rules proposal
The current cgo proposal (golang/go#12416) is at:

https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md

Maybe relevant to golang/go#12718

Change-Id: I5a399eec703ba3a793ab64d979bb73b083f23df9
Reviewed-on: https://go-review.googlesource.com/15100
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-29 13:55:20 +00:00
Burcu Dogan
8cf29b651f cmd/gomobile: add modulemaps to framework bundles for simpler imports
Modulemaps allow users to use the import directives without
providing the specific header file but by using a module name
in Objective-C and Swift.

  gomobile bind -target=ios golang.org/x/mobile/example/bind/hello

Add the generated framework to an Xcode project. You will be able
to import the library header and use the library by importing hello
in Swift.

  import hello
  // ...
  hello.GoHelloGreetings("burcu");

In Objective-C, you will be able to import with the module name
similarly by using the import directive below.

  #import hello

This CL also enables Go bindings to be used from Swift without an
Objective-C bridging header.

Fixes golang/go#12422

Change-Id: I7c60349caad100861d0b642ddfa873d7ada47598
Reviewed-on: https://go-review.googlesource.com/15044
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-28 16:36:07 +00:00
Paul Hankin
c846a131a8 testapp: Use methods of gl.Context rather than package-level OpenGL calls.
The package-level OpenGL calls in golang.org/x/mobile/gl were removed.
This change fixes testapp to use their replacement.

This change also moves the location of the test taps to be further away
from the top of the screen. On my phone (running L), a tap at 50,60 is
opens the draggy menu thing that Android has and the running app doesn't
see it (which causes the test to not complete).

Change-Id: I679c9b61919a332f9b4a53e0950ff96f6aefbbbb
Reviewed-on: https://go-review.googlesource.com/15050
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-27 12:25:12 +00:00
Paul Hankin
80ead7f4f8 sprite: Use gl.Context instead of package-level OpenGL calls.
The package-level OpenGL calls in golang.org/x/mobile/gl were removed.
This change fixes the example sprite app to use their replacement.

Change-Id: I1884e9292133375194c963e71540acaef0908d66
Reviewed-on: https://go-review.googlesource.com/15051
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-26 17:12:14 +00:00
Nigel Tao
159023b619 example/basic: fix typo.
Change-Id: I53c6804729211ceb4546c5276314dc67eeff7a51
Reviewed-on: https://go-review.googlesource.com/14935
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-09-24 06:47:40 +00:00
Nigel Tao
338d60c30b gl: fix a comment typo.
Change-Id: Ib87232f67bd38ad5b7dbec5c0862ff244bdec5b0
Reviewed-on: https://go-review.googlesource.com/14930
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-09-24 01:48:26 +00:00
David Crawshaw
59ab51f73f gl: move to context methods
All OpenGL functions are now methods on a Context interface. The
gl.Context matches the one loaded into thread-local storage in C.

For mobile apps, the context is owned by an app.App. For now, it is
provided through the events channel on a lifecycle event. Long-term,
it should probably be available by a method on app.App, but this is
inherently racey with our current use of a channel to deliver events.

Shiny-based programs will have a gl.Context associated with a each
shiny.Window. The expectation is each Window will have different
contexts, allowing them to draw separately.

Change-Id: Ie09986fb74e493129f2ea542a151c95c6fa29812
Reviewed-on: https://go-review.googlesource.com/13431
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 23:46:16 +00:00
Burcu Dogan
ae2f847064 cmd/gomobile: skip the hidden asset files
gomobile builds apps with hidden files from the assets directory.
The final applications should skip files like .DS_Store, .gitignore,
etc. Therefore, walker needs to skip the hidden files.

Change-Id: Ibbf7010d525cc831a009f3680f84063f40ac570f
Reviewed-on: https://go-review.googlesource.com/14825
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-23 17:04:59 +00:00
Burcu Dogan
18875a7b5b cmd/gomobile: follow the symlink if assets is a symlink
Fixes golang/go#12713.

Change-Id: Ie63a48b2ab3f39d6481fab702e00c762587501b2
Reviewed-on: https://go-review.googlesource.com/14824
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-23 17:04:24 +00:00
Nigel Tao
5291eb5e09 app: fix broken build.
Change-Id: I9c41f81bc287679cce5372f3aaf0b14a406eebd2
Reviewed-on: https://go-review.googlesource.com/14864
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 09:47:24 +00:00
David Crawshaw
9e848912c3 app: turn filtering functions into methods on App
Change-Id: I69a6ac9930303945bd2d69a1995f28021bb3b0b0
Reviewed-on: https://go-review.googlesource.com/14796
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 05:17:31 +00:00
David Crawshaw
0064789433 exp/gl/glutil: remove global texture cache
It is now the user's job to track the lifetime of a glutil.Image
relative to a (currently implicit, soon to be explicit) GL context.

This is an attempt to move glutil.Image closer to the model for
buffers and textures in shiny. Long-term, I would like to adopt that
model, and this is a step in that direction. It also makes the
introduction of *gl.Context possible, so this is a pre-req for
cl/13431.

Change-Id: I8e6855211b3e67c97d5831c5c4e443e857c83d50
Reviewed-on: https://go-review.googlesource.com/14795
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-23 04:24:22 +00:00
Nigel Tao
afa8a11c1d app: re-use the input queue goroutine.
We now have one such goroutine for the life of the process, not one per
onInputQueueCreated call (e.g. whenever the app re-gains visibility).

Also use ALooper_wake instead of rolling our own os.Pipe.

Change-Id: I4fa045972289144e083033f2e243cac65f35ee46
Reviewed-on: https://go-review.googlesource.com/14670
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-18 00:19:08 +00:00
David Crawshaw
9b7eb80c57 app: skip android test if no device attached
Change-Id: Ie2c81af6cb380ae22d285d0f274755ec421e8d6a
Reviewed-on: https://go-review.googlesource.com/14653
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-17 16:14:44 +00:00
Nigel Tao
ef84e0538a app: remove unused windowCreated channel.
Change-Id: Iabe5a9d346ee54ddc4f39475606d262f581b5c63
Reviewed-on: https://go-review.googlesource.com/14667
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-17 03:25:18 +00:00
Nigel Tao
4c15c79e19 app: change EndPaint to Publish.
More than a name change, the painting model changes so that the app, not
the library, is responsible for driving painting. If the app is
animating and wants paint events at 60 Hz, it has to ask for that. If
the app is not animating and doesn't need to update its screen, it
shouldn't get any paint events.

Plenty of TODOs, and this CL doesn't get us to a perfect place, but it
is a checkpoint along the way.

The darwin_*.go code changes were minimal. I don't even have a Mac or
iOS device to test that this even builds. Even so, the TODOs about not
sending paint.Events unconditionally are important TODOs. That's the
whole point of switching to this model. I'll leave the actual
implementation to you (crawshaw).

Out of all the example apps, the change to example/network/main.go is
probably the most interesting.

It seems like there ought to be some way to reduce the copy/paste
between all of the example app code, but I'll leave that for future CLs.

Change-Id: I17e11c06174110c68e17f7183b2d8af19b6a170e
Reviewed-on: https://go-review.googlesource.com/14300
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-17 03:17:09 +00:00
Nigel Tao
11f6745c3d app: process input and other events concurrently, not consecutively.
Previously, we did:

for {
  processEvents() // Process any pending Android input events.
  select {        // Select Go events (channel send/receives).
  etc
  }
}

The problem was that if you were blocked on the select because there
were no incoming Go events, then you weren't reading new input events,
and the UI could block indefinitely.

After this CL, input events are processed in a dedicated goroutine,
where it's fine for

for C.AInputQueue_getEvent(q, &e) >= 0 { etc }

to block, and the main loop deals only with Go channels:

for {
  select {
  etc
  }
}

Change-Id: I8ec27a40e220b1d95a6b6fc14347a59833ccfdc8
Reviewed-on: https://go-review.googlesource.com/14500
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-17 03:05:17 +00:00
David Crawshaw
7a70f37cf6 bind/objc: remove a constructor and retain blocks
A framework generated with gomobile bind -target=ios has two global
constructors: one initializing a data structure and another using it.
These constructors are defined in different translation units, which
(I believe, reasoning from C++ global constructors) means their order
of initialization is undefined.

A capturing block is stack allocated. Its memory is invalid after the
function returns. Make a copy of the interface initializer blocks so
they can be saved to the heap.

Block implementation background:
http://www.cocoawithlove.com/2009/10/how-blocks-are-implemented-and.html

Updates golang/go#12590

Change-Id: Ia7ae9f4bbd8df6e6e79949de54b3e6c48148c700
Reviewed-on: https://go-review.googlesource.com/14549
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-15 17:38:26 +00:00
David Crawshaw
b10f681911 example/ivy/ios: remove unnecessary indentation
Change-Id: Ie4898a25eeb3230be6acb0fb85d2cff636f2880e
Reviewed-on: https://go-review.googlesource.com/14600
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-15 12:59:24 +00:00
David Crawshaw
b0ae6f9325 example/ivy/ios: add iOS source code
Change-Id: Ifabbfcfd75a92b0eb81631e3bb6eca1e4228139a
Reviewed-on: https://go-review.googlesource.com/14208
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-14 21:08:49 +00:00
Hyang-Ah (Hana) Kim
24e7a6212f cmd/gomobile: use ARC when compiling generated objective-c files.
Gobind -lang=objc generates code that assume use of ARC.
Set -fobjc-arc to explicitly enable ARC.

Change-Id: Ib0ec7b19773c112c01ed23cb00f1ec9d64946e6b
Reviewed-on: https://go-review.googlesource.com/14544
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-14 20:55:34 +00:00
Hyang-Ah (Hana) Kim
ffd5bae668 cmd/gomobile: add a dummy Info.plist for happy manual codesign.
Fixes golang/go#12604.

Change-Id: I94e94c32ce42022b58097c349fcbb90edb0a2f13
Reviewed-on: https://go-review.googlesource.com/14543
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-14 20:44:35 +00:00
David Crawshaw
eadadb8667 internal/mobileinit: standardize JNIEnv* access
Replace the direct access to JavaVM* and the global android Context
instance with a function responsible for running attached correctly
to the JVM. This saves having to replicate the logic for attaching an
OS thread to the JVM. While here, check for any unhandled Java
exceptions.

This supersedes cl/11812.

Change-Id: Ic9291fe64083d2bd983c4f8e309941b9c47d60c2
Reviewed-on: https://go-review.googlesource.com/14162
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-14 17:30:52 +00:00
Hyang-Ah (Hana) Kim
65551d85b6 misc/androidstudio: handle missing local.properties.
Fixes golang/go#12543

Change-Id: Ifb91e073ff2ebcba111e279949d5120a77b0dc2d
Reviewed-on: https://go-review.googlesource.com/14475
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-11 20:14:45 +00:00
David Crawshaw
1f77c34859 cmd/gomobile: copy libopenal.so explicitly
Fixes golang/go#12550.

Change-Id: I744729cfd702f0e044eac22858ee746096977665
Reviewed-on: https://go-review.googlesource.com/14474
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-11 14:46:26 +00:00
Burcu Dogan
c76d5c8830 exp/sensor: remove the manager type
The manager type is not required, because the APIs don't allow
more than one event sources as they used to. In this CL, I am
flattening out the underlying implementations by removing the
manager type.

Change-Id: I3b606ac160b9cecd85cb657e3df1d7d789604764
Reviewed-on: https://go-review.googlesource.com/14293
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 16:23:41 +00:00
Burcu Dogan
043428404d exp/sensor: enable magnetometer on darwin{arm,arm64}
Change-Id: Ib188121501ac96cb8743e57f907b23d0fdfc37a0
Reviewed-on: https://go-review.googlesource.com/14292
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 04:58:24 +00:00
Burcu Dogan
d4f6353bc3 exp/sensor: support gyro events on darwin{arm,arm64}
Change-Id: I47aa12cc942261b8035312d0eeba0caf52b562ac
Reviewed-on: https://go-review.googlesource.com/14257
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-04 03:40:30 +00:00
Burcu Dogan
931e394f4f exp/sensor: don't allow delays smaller than 10ms on ios
"You can set the reporting interval to be as small as 10 milliseconds
(ms), which corresponds to a 100 Hz update rate, but most app operate
sufficiently with a larger interval."

from https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html

Larger delay values makes the library poll more frequently than needed.

Change-Id: Ie3057813209746bff00b8ef534c9ae239396366e
Reviewed-on: https://go-review.googlesource.com/14252
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-03 16:03:29 +00:00
David Crawshaw
70b9ad3e00 .gitignore: remove *.xcodeproj
I'm about to add one to the tree.

Change-Id: Iad25d8965d1095349588e11a5050f986e5ad2e76
Reviewed-on: https://go-review.googlesource.com/14260
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-03 14:46:33 +00:00
Burcu Dogan
7e79d05d9e exp/sensor: set sensor interval on ios
Change-Id: I5559f721b2e2c7506db89f804569c0b0f78abea8
Reviewed-on: https://go-review.googlesource.com/14251
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 06:02:53 +00:00
Burcu Dogan
679c68b58d exp/sensor: block forever until new events occur on android
The former Reader inspired APIs were designed to timeout if no events
occur after an excessive amount of time. As we switch to the app
event based model, timing out is not required. We can block on
pollAll forever until new events arrive.

Change-Id: I086fc908ebfe6ae9bd96ce9199636ad0242bbec5
Reviewed-on: https://go-review.googlesource.com/14223
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:54:22 +00:00
Burcu Dogan
5651add1eb exp/sensor: initiate the darwin/{arm,arm64} backend
The CL provides accelerometer events only, upcoming CLs will add
support for gyroscope and magnetometer.

Change-Id: Ib5629ca7c49c9dfc8ca533fe7acde371efc102b2
Reviewed-on: https://go-review.googlesource.com/14036
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-03 02:10:28 +00:00
Hyang-Ah (Hana) Kim
9e2ad8c60e example/ivy/android: configure version code/name (3/1.0.2)
Change-Id: I378f41a54c7bb6cf81988c344a086e6a506e9dfe
Reviewed-on: https://go-review.googlesource.com/14202
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-02 21:16:25 +00:00
Hyang-Ah (Hana) Kim
e565eadcd6 example/ivy/android: fix problems caused by old bugs in WebView.
1) Clear button did not shrink the WebView size. It's an old bug in
Android WebView, and fixed recently (android-L, maybe). This CL avoids
the problem by replacing the webview with a freshly allocated new webview
object. It's heavy-weight, but the Clear event should be rare.

2) ScrollToBottom from the java side and the java script side interacted
strangely and prevented long results from displayed properly.

Also,

- now the gomobile bind generates the Java class in the
org.golang.ivy package. (ivy/build.gradle)

- modified the javascript in tape.html so long result texts are not
shortened initially. (tape.html)

Change-Id: I60660f3392cf17719daad4af89e05c2d82788175
Reviewed-on: https://go-review.googlesource.com/14201
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-02 14:49:09 +00:00
David Crawshaw
471eeebd99 cmd/gomobile: always display stdout from abd
Fixes golang/go#12418

Change-Id: Ie0f2e669b3e516787b548c69a624e9063cd7f68f
Reviewed-on: https://go-review.googlesource.com/14160
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-02 14:17:25 +00:00
Hyang-Ah (Hana) Kim
fee22db634 example/ivy/android: initial check in.
This version is not yet released to Play store.
Compared to the version in the play store

- fixed the reappearing keyboard bug
- allows app install on SD card
- when demo is enabled, the demo mode message is displayed
- when demo is enabled, the submit action button appears next to the
  edit text.
- use robpike.io/ivy/mobile instead of the wrapper in my personal repo.
- the demo script read code was moved from go to java.
- use the up-to-date help message retrieved with mobile.Help.
- textview was replaced with webview with javascript.

TODO: the app built from this code doesn't work in old android devices.
Next cl will fix it.

TODO: build instruction - not very different from
golang.org/x/mobile/example/bind/android.

Change-Id: Ifb594b79f31091b6864ec3e0d8dbaff7986a5afc
Reviewed-on: https://go-review.googlesource.com/13870
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-02 05:29:24 +00:00
Hyang-Ah (Hana) Kim
4a6caa5fd7 cmd/gomobile: bind allows custom package path/prefix.
New option -javapkg for -target=android, and -prefix for -target=ios.
Fixes golang/go#9660.

Change-Id: I9143f30672672527876524b38f450629452a3161
Reviewed-on: https://go-review.googlesource.com/14023
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-01 19:17:05 +00:00
Meir Fischer
00865a642f bind: improve readability for float default values
To improve readability for default numeric types
represented as strings, use 0.0 for floating point types.
(No tests make use of this change so golden update
not necessary; not significant enough for new test/test mod.)
Fix spelling on error statement; this was the only
instance of that spelling error in the repository.

Change-Id: I373890725b33da11c6780ba93674d89541bf758c
Reviewed-on: https://go-review.googlesource.com/13645
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2015-09-01 18:16:37 +00:00
Burcu Dogan
9ddeada810 exp/sensor: provide sensor events from the app event channel
We are also limiting the number of sensor managers to one.
The application provide sensor events to third-party packages
by consuming them in the main.

An application will be able to consume the sensor events similar
to the other events.

package main

func main() {
  app.Main(func(a app.App) {
    // enables the accelerometer
    sensor.Enable(a, sensor.Accelerometer, 100*time.Millisecond)

    var sz size.Event
    for e := range a.Events() {
      switch e := app.Filter(e).(type) {
      case sensor.Event:
        log.Println(e)
      }
    }
  })
}

Change-Id: Iaad1c59f8d2322c7620df62ed9b9283c91746fa8
Reviewed-on: https://go-review.googlesource.com/13983
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2015-09-01 04:44:55 +00:00
Nigel Tao
b5b6051b23 event/size: add an Event.Size method.
This is similar to the Event.Bounds method. Some functions in other
packages take an image.Rectangle (i.e. bounds), others take an
image.Point (i.e size).

Change-Id: Ie892a8902992d4e6b9edfbf6d12342297fae4068
Reviewed-on: https://go-review.googlesource.com/14003
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-01 00:58:08 +00:00