2015/gophercon-go-on-mobile: move demo source code out. This will be hosted in a separate repo. Change-Id: I612d478ae03c47fd24478cb7116087cc2f8f759c Reviewed-on: https://go-review.googlesource.com/12338 Reviewed-by: Francesc Campoy Flores <campoy@golang.org>
diff --git a/2015/gophercon-go-on-mobile/README b/2015/gophercon-go-on-mobile/README index 1732cd8..ff64cf0 100644 --- a/2015/gophercon-go-on-mobile/README +++ b/2015/gophercon-go-on-mobile/README
@@ -1,38 +1,2 @@ -Demo Setup ----------------------- - -- Download and install Android SDK - -https://developer.android.com/sdk/index.html -Or, easiest way is to install Android Studio. - - -- Download go1.5 and build for your host. - -- Set the following environment variables. - -GOPATH: your go path -ANDROID_HOME: Android SDK directory -PATH: make sure $GOROOT/bin, $GOPATH/bin are included in the path - -- Install the gomobile tool and run init before demo. - -% go install golang.org/x/mobile/cmd/gomobile -% gomobile init - -- Hello Gopher demo - -% demo1.bash - -For android screen mirroring, I used Mobizen (mobizen.com). -For ios screen mirroring, you can use quicktime. - -- Gobind demo - -% demo2.bash - -- Ivy demo: In my gophercon talk, I used pre-recorded video -clips for mobile versions and ran the command line version from -my laptop in order to emphasize the cross-platform support. - -Enjoy. +Demo source code and set up instruction is in +https://github.com/hyangah/slides/tree/master/2015-gophercon-mobile
diff --git a/2015/gophercon-go-on-mobile/demo1.bash b/2015/gophercon-go-on-mobile/demo1.bash deleted file mode 100755 index 8d750ed..0000000 --- a/2015/gophercon-go-on-mobile/demo1.bash +++ /dev/null
@@ -1,20 +0,0 @@ -#!/bin/bash - -prompt() { - read -p "$1" -} - -cd hello - -declare -a arr=( -"wc -l main.go" -"go run main.go" -"gomobile install -target=android" -) - -for i in "${arr[@]}" -do - prompt "\$ $i" - $i - echo -done
diff --git a/2015/gophercon-go-on-mobile/demo2.bash b/2015/gophercon-go-on-mobile/demo2.bash deleted file mode 100755 index d377162..0000000 --- a/2015/gophercon-go-on-mobile/demo2.bash +++ /dev/null
@@ -1,24 +0,0 @@ -#!/bin/bash - -prompt() { - read -p "$1" -} - -declare -a arr=( -"cd mypkg" -"tree" -"cat mypkg.go" -"export ANDROID_HOME=${ANDROID_HOME}" -"gomobile bind ." -"tree" -"unzip -l mypkg.aar" -) - -for i in "${arr[@]}" -do - prompt "\$ $i" - $i - echo -done - -rm mypkg.aar
diff --git a/2015/gophercon-go-on-mobile/hello/assets/gophersmall.png b/2015/gophercon-go-on-mobile/hello/assets/gophersmall.png deleted file mode 100644 index 53b4b4a..0000000 --- a/2015/gophercon-go-on-mobile/hello/assets/gophersmall.png +++ /dev/null Binary files differ
diff --git a/2015/gophercon-go-on-mobile/hello/assets/hello.wav b/2015/gophercon-go-on-mobile/hello/assets/hello.wav deleted file mode 100644 index 1551ebf..0000000 --- a/2015/gophercon-go-on-mobile/hello/assets/hello.wav +++ /dev/null Binary files differ
diff --git a/2015/gophercon-go-on-mobile/hello/main.go b/2015/gophercon-go-on-mobile/hello/main.go deleted file mode 100644 index 32aba94..0000000 --- a/2015/gophercon-go-on-mobile/hello/main.go +++ /dev/null
@@ -1,207 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Based on golang.org/x/mobile/example/audio - -package main - -import ( - "image" - "log" - "time" - - _ "image/png" - - "golang.org/x/mobile/app" - "golang.org/x/mobile/asset" - "golang.org/x/mobile/event/config" - "golang.org/x/mobile/event/lifecycle" - "golang.org/x/mobile/event/paint" - "golang.org/x/mobile/event/touch" - "golang.org/x/mobile/exp/app/debug" - "golang.org/x/mobile/exp/audio" - "golang.org/x/mobile/exp/f32" - "golang.org/x/mobile/exp/sprite" - "golang.org/x/mobile/exp/sprite/clock" - "golang.org/x/mobile/exp/sprite/glsprite" - "golang.org/x/mobile/geom" - "golang.org/x/mobile/gl" -) - -func main() { - app.Main(func(a app.App) { - for e := range a.Events() { - switch e := app.Filter(e).(type) { - case lifecycle.Event: - switch e.Crosses(lifecycle.StageVisible) { - case lifecycle.CrossOn: - onStart() - case lifecycle.CrossOff: - onStop() - } - case config.Event: - globalCfg = e // dimension change. move to the center. - touchLoc = geom.Point{globalCfg.Width / 2, globalCfg.Height / 2} - case paint.Event: - onPaint(globalCfg) - a.EndPaint() - case touch.Event: - onTouch(e) - } - } - }) -} - -const ( - width = 72 - height = 74 -) - -var ( - startClock = time.Now() - eng = glsprite.Engine() - scene *sprite.Node - - player *audio.Player - - started = false - activate = false - acceptTouch = false - touchLoc geom.Point - globalCfg config.Event -) - -func onTouch(t touch.Event) { - if t.Type != touch.TypeStart { - return - } - - touchLoc = t.Loc - acceptTouch = true - if !activate { - activate = true - } -} - -func onStart() { - gl.Enable(gl.BLEND) - gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) - - rc, err := asset.Open("hello.wav") - if err != nil { - log.Fatal(err) - } - player, err = audio.NewPlayer(rc, 0, 0) - if err != nil { - log.Fatal(err) - } -} - -func onStop() { - player.Close() -} - -func onPaint(c config.Event) { - if !started { - touchLoc = geom.Point{c.Width / 2, c.Height / 2} - started = true - } - if scene == nil { - loadScene() - } - gl.ClearColor(242/255.0, 240/255.0, 217/255.0, 1) // gophercon bg color - gl.Clear(gl.COLOR_BUFFER_BIT) - - now := clock.Time(time.Since(startClock) * 60 / time.Second) - eng.Render(scene, now, c) - debug.DrawFPS(c) -} - -func newNode() *sprite.Node { - n := &sprite.Node{} - eng.Register(n) - scene.AppendChild(n) - return n -} - -func loadScene() { - gopher := loadGopher() - scene = &sprite.Node{} - eng.Register(scene) - eng.SetTransform(scene, f32.Affine{ - {1, 0, 0}, - {0, 1, 0}, - }) - - var x, y float32 - dx, dy := float32(1), float32(1) - - n := newNode() - n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { - eng.SetSubTex(n, gopher) - - if acceptTouch { - dx = (float32(touchLoc.X) - x) / 60 - dy = (float32(touchLoc.Y) - y) / 60 - acceptTouch = false - hello() - x += dx - y += dy - } else if activate { - if x < 0 { - dx = 1 - } - if y < 0 { - dy = 1 - } - if x+width > float32(globalCfg.Width) { - dx = -1 - } - if y+height > float32(globalCfg.Height) { - dy = -1 - } - x += dx - y += dy - } - - if dx < 0 { - eng.SetTransform(n, f32.Affine{ // change direction - {-width, 0, x + width}, - {0, height, y}, - }) - } else { - eng.SetTransform(n, f32.Affine{ - {width, 0, x}, - {0, height, y}, - }) - } - }) -} - -func hello() { - player.Seek(0) - player.Play() -} - -func loadGopher() sprite.SubTex { - a, err := asset.Open("gophersmall.png") - if err != nil { - log.Fatal(err) - } - defer a.Close() - - img, _, err := image.Decode(a) - if err != nil { - log.Fatal(err) - } - t, err := eng.LoadTexture(img) - if err != nil { - log.Fatal(err) - } - return sprite.SubTex{t, image.Rect(0, 0, 360, 370)} -} - -type arrangerFunc func(e sprite.Engine, n *sprite.Node, t clock.Time) - -func (a arrangerFunc) Arrange(e sprite.Engine, n *sprite.Node, t clock.Time) { a(e, n, t) }
diff --git a/2015/gophercon-go-on-mobile/mypkg/assets/myassets.txt b/2015/gophercon-go-on-mobile/mypkg/assets/myassets.txt deleted file mode 100644 index 7e2f179..0000000 --- a/2015/gophercon-go-on-mobile/mypkg/assets/myassets.txt +++ /dev/null
@@ -1 +0,0 @@ -assets
diff --git a/2015/gophercon-go-on-mobile/mypkg/mypkg.go b/2015/gophercon-go-on-mobile/mypkg/mypkg.go deleted file mode 100644 index 12c88ec..0000000 --- a/2015/gophercon-go-on-mobile/mypkg/mypkg.go +++ /dev/null
@@ -1,7 +0,0 @@ -package mypkg - -import "fmt" - -func Hello(name string) string { - return fmt.Sprintf("Hello, %s!", name) -}