Skip to content
This repository has been archived by the owner on Mar 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #59 from googlesamples/release-capella
Browse files Browse the repository at this point in the history
release capella
  • Loading branch information
jguomoto committed Dec 15, 2015
2 parents 8f460d0 + 1b9096a commit bf26788
Show file tree
Hide file tree
Showing 51 changed files with 458 additions and 291 deletions.
3 changes: 2 additions & 1 deletion area-description-jni-example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ task ndkBuild(type: Exec) {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@

import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Point;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import java.lang.Override;

// The AreaDescriptionActivity of the application which shows debug information
// and a glSurfaceView that renders graphic content.
Expand All @@ -60,7 +56,7 @@ public class AreaDescriptionActivity extends Activity implements
// The interval at which we'll update our UI debug text in milliseconds.
// This is the rate at which we query our native wrapper around the tango
// service for pose and event information.
private static final int kUpdateIntervalMs = 100;
private static final int UPDATE_UI_INTERVAL_MS = 100;

// The flag to check if the surface is created.
public boolean mIsSurfaceCreated = false;
Expand Down Expand Up @@ -102,6 +98,9 @@ public class AreaDescriptionActivity extends Activity implements
// Long-running task to save an ADF.
private SaveAdfTask mSaveAdfTask;

// Handles the debug text UI update loop.
private Handler mHandler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -122,9 +121,6 @@ protected void onCreate(Bundle savedInstanceState) {
// between the application and Tango Service.
// The activity object is used for checking if the API version is outdated.
TangoJNINative.initialize(this);

// UI thread handles the task of updating all debug text.
startUIThread();
}

@Override
Expand Down Expand Up @@ -153,6 +149,9 @@ protected void onResume() {
Toast.makeText(this, R.string.tango_cant_initialize, Toast.LENGTH_LONG).show();
finish();
}

// Start the debug text UI update loop.
mHandler.post(mUpdateUiLoopRunnable);
}

@Override
Expand All @@ -170,6 +169,9 @@ protected void onPause() {
TangoJNINative.disconnect();
mIsConnectedService = false;
}

// Stop the debug text UI update loop.
mHandler.removeCallbacksAndMessages(null);
}

@Override
Expand Down Expand Up @@ -365,45 +367,31 @@ private void showSetADFNameDialog() {
setADFNameDialog.show(manager, "ADFNameDialog");
}

// UI thread for handling debug text changes.
private void startUIThread() {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(kUpdateIntervalMs);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
updateUI();
} catch (Exception e) {
e.printStackTrace();
}
}
});

} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
// Debug text UI update loop, updating at 10Hz.
private Runnable mUpdateUiLoopRunnable = new Runnable() {
public void run() {
updateUi();
mHandler.postDelayed(this, UPDATE_UI_INTERVAL_MS);
}
};

private void updateUI() {
// Update the UI debug displays.
mEvent.setText(TangoJNINative.getEventString());
mStartServiceTDevicePoseData.setText(
TangoJNINative.getStartServiceTDeviceString());
mADFTDevicePoseData.setText(TangoJNINative.getAdfTDeviceString());
mADFTStartServicePoseData.setText(TangoJNINative.getAdfTStartServiceString());

// If Tango has relocalized, allow saving the ADF.
// Note: Tango returns TANGO_INVALID if saveAdf() is called before relocalization.
if (TangoJNINative.isRelocalized()) {
findViewById(R.id.save_adf_button).setEnabled(true);
// Update the debug text UI.
private void updateUi() {
try {
// Update the UI debug displays.
mEvent.setText(TangoJNINative.getEventString());
mStartServiceTDevicePoseData.setText(
TangoJNINative.getStartServiceTDeviceString());
mADFTDevicePoseData.setText(TangoJNINative.getAdfTDeviceString());
mADFTStartServicePoseData.setText(TangoJNINative.getAdfTStartServiceString());

// If Tango has relocalized, allow saving the ADF.
// Note: Tango returns TANGO_INVALID if saveAdf() is called before relocalization.
if (TangoJNINative.isRelocalized()) {
findViewById(R.id.save_adf_button).setEnabled(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down
1 change: 1 addition & 0 deletions area-description-jni-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

repositories {
jcenter()
}
Expand Down
Binary file modified area-description-jni-example/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Oct 26 08:02:00 ART 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
3 changes: 2 additions & 1 deletion augmented-reality-jni-example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ task ndkBuild(type: Exec) {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.projecttango.experiments.nativeaugmentedreality;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Point;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
Expand Down Expand Up @@ -56,7 +56,7 @@ public class AugmentedRealityActivity extends Activity implements
// The interval at which we'll update our UI debug text in milliseconds.
// This is the rate at which we query our native wrapper around the tango
// service for pose and event information.
private static final int kUpdateIntervalMs = 100;
private static final int UPDATE_UI_INTERVAL_MS = 100;

// Debug information text.
// Current frame's pose information.
Expand Down Expand Up @@ -87,6 +87,9 @@ public class AugmentedRealityActivity extends Activity implements
// Screen size for normalizing the touch input for orbiting the render camera.
private Point mScreenSize = new Point();

// Handles the debug text UI update loop.
private Handler mHandler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -156,9 +159,6 @@ protected void onCreate(Bundle savedInstanceState) {
// between the application and Tango Service.
// The activity object is used for checking if the API version is outdated.
TangoJNINative.initialize(this);

// UI thread handles the task of updating all debug text.
startUIThread();
}

@Override
Expand All @@ -182,6 +182,9 @@ protected void onResume() {
Toast.makeText(this, "Connect Tango Service Error", Toast.LENGTH_LONG).show();
finish();
}

// Start the debug text UI update loop.
mHandler.post(mUpdateUiLoopRunnable);
}

@Override
Expand All @@ -196,6 +199,15 @@ protected void onPause() {
TangoJNINative.disconnect();
mIsConnectedService = false;
}

// Stop the debug text UI update loop.
mHandler.removeCallbacksAndMessages(null);
}

@Override
protected void onDestroy() {
super.onDestroy();
TangoJNINative.destroyActivity();
}

@Override
Expand Down Expand Up @@ -258,32 +270,22 @@ public void requestRender() {
mGLView.requestRender();
}

// UI thread for handling debug text changes.
private void startUIThread() {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(kUpdateIntervalMs);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
mEvent.setText(TangoJNINative.getEventString());
mPoseData.setText(TangoJNINative.getPoseString());
} catch (Exception e) {
e.printStackTrace();
}
}
});

} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
// Debug text UI update loop, updating at 10Hz.
private Runnable mUpdateUiLoopRunnable = new Runnable() {
public void run() {
updateUi();
mHandler.postDelayed(this, UPDATE_UI_INTERVAL_MS);
}
};

// Update the debug text UI.
private void updateUi() {
try {
mEvent.setText(TangoJNINative.getEventString());
mPoseData.setText(TangoJNINative.getPoseString());
} catch (Exception e) {
e.printStackTrace();
}
}

private boolean CheckTangoCoreVersion(int minVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class TangoJNINative {
// the auto-recovery option from here.
public static native int setupConfig();

// Signal that the activity has been destroyed and remove any cached references.
public static native void destroyActivity();

// Connect the onPoseAvailable callback.
public static native int connectCallbacks();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ void AugmentedRealityApp::onTextureAvailable(TangoCameraId id) {
}
}

AugmentedRealityApp::AugmentedRealityApp() {}
AugmentedRealityApp::AugmentedRealityApp()
: calling_activity_obj_(nullptr), on_demand_render_(nullptr) {}

AugmentedRealityApp::~AugmentedRealityApp() {
TangoConfig_free(tango_config_);
JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
env->DeleteGlobalRef(calling_activity_obj_);
}

int AugmentedRealityApp::TangoInitialize(JNIEnv* env, jobject caller_activity) {
Expand All @@ -89,6 +87,15 @@ int AugmentedRealityApp::TangoInitialize(JNIEnv* env, jobject caller_activity) {
return ret;
}

void AugmentedRealityApp::ActivityDestroyed() {
JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
env->DeleteGlobalRef(calling_activity_obj_);

calling_activity_obj_ = nullptr;
on_demand_render_ = nullptr;
}

int AugmentedRealityApp::TangoSetupConfig() {
// Here, we'll configure the service to run in the way we'd want. For this
// application, we'll start from the default configuration
Expand Down Expand Up @@ -383,6 +390,11 @@ TangoErrorType AugmentedRealityApp::UpdateExtrinsics() {
}

void AugmentedRealityApp::RequestRender() {
if (calling_activity_obj_ == nullptr || on_demand_render_ == nullptr) {
LOGE("Can not reference Activity to request render");
return;
}

// Here, we notify the Java activity that we'd like it to trigger a render.
JNIEnv* env;
java_vm_->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_disconne
app.TangoDisconnect();
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_destroyActivity(
JNIEnv*, jobject) {
app.ActivityDestroyed();
}

JNIEXPORT void JNICALL
Java_com_projecttango_experiments_nativeaugmentedreality_TangoJNINative_resetMotionTracking(
JNIEnv*, jobject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ class AugmentedRealityApp {
~AugmentedRealityApp();

// Initialize Tango Service, this function starts the communication
// between the application and Tango Service.
// The activity object is used for checking if the API version is outdated.
// between the application and Tango Service. This also records a
// reference to the caller activity to request rendering when new
// texture data is available. The activity object is also used to
// check if the API version is outdated.
int TangoInitialize(JNIEnv* env, jobject caller_activity);

// Setup the configuration file for the Tango Service. We'll also se whether
// When the Android activity is destroyed signal the JNI layer to
// remove references to the activity. This should be called from the
// onDestroy() callback of the parent activity lifecycle.
void ActivityDestroyed();

// Setup the configuration file for the Tango Service. We'll also see whether
// we'd like auto-recover enabled.
int TangoSetupConfig();

Expand Down
1 change: 1 addition & 0 deletions augmented-reality-jni-example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

repositories {
jcenter()
}
Expand Down
Binary file modified augmented-reality-jni-example/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit bf26788

Please sign in to comment.