diff --git a/example/bind/android/README b/example/bind/android/README new file mode 100644 index 0000000..f60569f --- /dev/null +++ b/example/bind/android/README @@ -0,0 +1,4 @@ +Go bind android app example + +Set the GOPATH, GO, GOMOBILE variables in hello/build.gradle +and import this project in Android Studio. diff --git a/example/bind/android/app/build.gradle b/example/bind/android/app/build.gradle new file mode 100644 index 0000000..3fb729e --- /dev/null +++ b/example/bind/android/app/build.gradle @@ -0,0 +1,30 @@ +/* + * 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. + */ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + applicationId "org.golang.example.android" + minSdkVersion 15 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:22.1.1' + compile project(':hello') +} diff --git a/example/bind/android/app/src/main/AndroidManifest.xml b/example/bind/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..fa1a160 --- /dev/null +++ b/example/bind/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java b/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java new file mode 100644 index 0000000..8308bb4 --- /dev/null +++ b/example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java @@ -0,0 +1,30 @@ +/* + * 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. + */ + +package org.golang.example.bind; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +import go.hello.Hello; + + +public class MainActivity extends Activity { + + private TextView mTextView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mTextView = (TextView) findViewById(R.id.mytextview); + + // Call Go function. + String greetings = Hello.Greetings("Android and Gopher"); + mTextView.setText(greetings); + } +} diff --git a/example/bind/android/app/src/main/res/layout/activity_main.xml b/example/bind/android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..43be4e3 --- /dev/null +++ b/example/bind/android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,17 @@ + + + + + + + diff --git a/example/bind/android/app/src/main/res/values/dimens.xml b/example/bind/android/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..cc0636b --- /dev/null +++ b/example/bind/android/app/src/main/res/values/dimens.xml @@ -0,0 +1,8 @@ + + + + 16dp + 16dp + diff --git a/example/bind/android/build.gradle b/example/bind/android/build.gradle new file mode 100644 index 0000000..cc7ccc8 --- /dev/null +++ b/example/bind/android/build.gradle @@ -0,0 +1,22 @@ +/* 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. + */ + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.2.3' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/example/bind/android/hello/build.gradle b/example/bind/android/hello/build.gradle new file mode 100644 index 0000000..7a0e674 --- /dev/null +++ b/example/bind/android/hello/build.gradle @@ -0,0 +1,23 @@ +/* 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. + */ + +plugins { + id "org.golang.mobile.bind" version "0.2.2" +} + +gobind { + /* The Go package path; must be under one of the GOPATH elements or + a relative to the current directory (e.g. ../../hello) */ + pkg = "golang.org/x/mobile/example/bind/hello" + + /* GOPATH where the Go package is; check `go env` */ + GOPATH = "/YOUR/GOPATH" + + /* Absolute path to the go binary */ + GO = "/PATH/TO/GO" + + /* Absolute path to the gomobile binary */ + GOMOBILE = "/PATH/TO/GOMOBILE" +} diff --git a/example/bind/android/settings.gradle b/example/bind/android/settings.gradle new file mode 100644 index 0000000..f37694c --- /dev/null +++ b/example/bind/android/settings.gradle @@ -0,0 +1,5 @@ +/* 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. + */ +include ':app', ':hello' diff --git a/example/bind/hello/hello.go b/example/bind/hello/hello.go new file mode 100644 index 0000000..2d98ff9 --- /dev/null +++ b/example/bind/hello/hello.go @@ -0,0 +1,12 @@ +// 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. + +// Package hello is a trivial package for gomobile bind example. +package hello + +import "fmt" + +func Greetings(name string) string { + return fmt.Sprintf("Hello, %s!", name) +}