example/bind: Android studio example.
Change-Id: I4729e47a4a3c4474f4ad53704e7fec337583d9e2 Reviewed-on: https://go-review.googlesource.com/12800 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
8217477ff5
commit
e0b154b34c
|
@ -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.
|
|
@ -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')
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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. -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.golang.example.bind" >
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:label="GoBindExample">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="GoBindExample" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<!-- 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. -->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/mytextview" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -0,0 +1,8 @@
|
|||
<!-- 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. -->
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
</resources>
|
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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'
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue