-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
50e73d6
sensor-graph: fork from hello-gl2
proppy 27fbc89
sensor-graph: load shader from file
proppy dd62ce3
sensor-graph: draw line
proppy 607010b
sensor-graph: draw ring buffer
proppy 7db7f20
sensor-graph: get sensor data
proppy d84882a
sensor-graph: draw 3 axis
proppy 08069ba
sensor-graph: filter sensor data
proppy 6539df7
sensor-graph: add pause and resume native handler
proppy 1861c03
sensor-graph: re-organize native code and split init from surfaceChan…
proppy c246a53
sensor-graph/java: rename activity and remove GLSurfaceView wrapper
proppy 6fcec0f
sensor-graph/jni: rename cpp file, fix lint warning
proppy 4de9a05
sensor-graph/jni: rename cpp file, fix lint warning
proppy 9469a51
sensor-graph/java: rename package and fix lint warning
proppy b6185f3
sensor-graph: add README and screenshot
proppy c36b258
sensor-graph: bump gradle plugin version
proppy 6e99cc0
sensor-graph/README: fix typo
proppy 3dec732
sensor-graph: fix activity name and label
proppy 7f91010
sensorgraph: add missing glDeleteShader calls
proppy a1f1b21
sensor-graph: bump sdk version
proppy 76f4a1e
sensor-graph: fix README formatting
proppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
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") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/gl2jni/sensorgraph/ There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
81 changes: 81 additions & 0 deletions
81
sensor-graph/app/src/main/java/com/android/sensorgraph/SensorGraphActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
sensor-graph/app/src/main/java/com/android/sensorgraph/SensorGraphJNI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/gl2jni/sensorgraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.