Skip to content
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

add sensor graph sample #51

Merged
merged 20 commits into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions sensor-graph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Sensor-Graph
============
Sensor graph is a C++ Android sample that read current accelerometer values and draw them using OpenGL.

It demonstrate usage of the following Native C++ API:
- [Sensors](http://developer.android.com/ndk/reference/group___sensor.html)
- [Assets](http://developer.android.com/ndk/reference/group___asset.html)

Pre-requisites
--------------

- Android Studio 1.3 with [NDK](https://developer.android.com/ndk/) bundle.

Getting Started
---------------

1. [Download Android Studio](http://developer.android.com/sdk/index.html)
1. Launch Android Studio.
1. Open `android-ndk/sensor-graph` sample.
1. Open *File/Project Structure...*
1. Click *Download* or *Select NDK location*.
1. Click *Tools/Android/Sync Project with Gradle Files*.
1. Click *Run/Run 'app'*.

Screenshots
-----------

![screenshot](screenshot.png)

Support
-------

If you've found an error in these samples, please [file an issue](https://github.com/googlesamples/android-ndk/issues/new).

Patches are encouraged, and may be submitted by [forking this project](https://github.com/googlesamples/android-ndk/fork) and
submitting a pull request through GitHub. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for more details.

- [Stack Overflow](http://stackoverflow.com/questions/tagged/android-ndk)
- [Google+ Community](https://plus.google.com/communities/105153134372062985968)
- [Android Tools Feedbacks](http://tools.android.com/feedback)

License
-------

Copyright 2015 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
45 changes: 45 additions & 0 deletions sensor-graph/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.android.model.application'

model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"

defaultConfig.with {
applicationId = "com.android.gl2jni"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/gl2jni/sensorgraph

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

minSdkVersion.apiLevel = 8
targetSdkVersion.apiLevel = 8
}
}
android.ndk {
moduleName = "sensorgraph"
cppFlags += "-Werror"
ldLibs += ["log", "GLESv2", "android"]
stl = "c++_static"
}

android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}

android.productFlavors {
create ("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create ("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create ("x86-32") {
ndk.abiFilters += "x86"
}
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa

// build one including all cpu architectures
create("all")
}
}

38 changes: 38 additions & 0 deletions sensor-graph/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2009, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.sensorgraph">
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:label="@string/gl2jni_activity">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/gl2jni/sensorgraph/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

<activity android:name="com.android.sensorgraph.SensorGraphActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
7 changes: 7 additions & 0 deletions sensor-graph/app/src/main/assets/shader.glslf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
precision mediump float;

uniform vec4 uFragColor;

void main() {
gl_FragColor = uFragColor;
}
6 changes: 6 additions & 0 deletions sensor-graph/app/src/main/assets/shader.glslv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
attribute float vPosition;
attribute float vSensorValue;

void main() {
gl_Position = vec4(vPosition, vSensorValue/9.81, 0, 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.sensorgraph;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;


public class SensorGraphActivity extends Activity {

GLSurfaceView mView;

@Override protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mView = new GLSurfaceView(getApplication());
mView.setEGLContextClientVersion(2);
mView.setRenderer(new GLSurfaceView.Renderer() {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
SensorGraphJNI.surfaceCreated();
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
SensorGraphJNI.surfaceChanged(width, height);
}

@Override
public void onDrawFrame(GL10 gl) {
SensorGraphJNI.drawFrame();
}
});
mView.queueEvent(new Runnable() {
@Override
public void run() {
SensorGraphJNI.init(getAssets());
}
});
setContentView(mView);
}

@Override protected void onPause() {
super.onPause();
mView.onPause();
mView.queueEvent(new Runnable() {
@Override
public void run() {
SensorGraphJNI.pause();
}
});
}

@Override protected void onResume() {
super.onResume();
mView.onResume();
mView.queueEvent(new Runnable() {
@Override
public void run() {
SensorGraphJNI.resume();
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.sensorgraph;

// Wrapper for native library

import android.content.res.AssetManager;

public class SensorGraphJNI {

static {
System.loadLibrary("sensorgraph");
}

public static native void init(AssetManager assetManager);
public static native void surfaceCreated();
public static native void surfaceChanged(int width, int height);
public static native void drawFrame();
public static native void pause();
public static native void resume();
}
Loading