Skip to content

Commit

Permalink
first commit of ARCore-Data-Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
PyojinKim committed Aug 30, 2019
1 parent 18ca664 commit a5d638f
Show file tree
Hide file tree
Showing 39 changed files with 952 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.pjinkim.arcore_data_logger"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pjinkim.arcore_data_logger;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.pjinkim.arcore_data_logger", appContext.getPackageName());
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pjinkim.arcore_data_logger">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
107 changes: 107 additions & 0 deletions app/src/main/java/com/pjinkim/arcore_data_logger/FileStreamer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.pjinkim.arcore_data_logger;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.security.KeyException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;

public class FileStreamer {

// properties
private final static String LOG_TAG = FileStreamer.class.getName();

private Context mContext;
private HashMap<String, BufferedWriter> mFileWriters = new HashMap<>();
private String mOutputFolder;


// constructor
public FileStreamer(Context mContext, final String mOutputFolder) {
this.mContext = mContext;
this.mOutputFolder = mOutputFolder;
}


// methods
public void addFile(final String writerId, final String fileName) throws IOException {

// check if there is a already generated text file
if (mFileWriters.containsKey(writerId)) {
Log.w(LOG_TAG, "addFile: " + writerId + " already exist.");
return;
}

// get current time information
Calendar fileTimestamp = Calendar.getInstance();
String timeHeader = "# Created at " + fileTimestamp.getTime().toString() + " in Burnaby Canada \n";

// generate text file
BufferedWriter newWriter = createFile(mOutputFolder + "/" + fileName, timeHeader);
mFileWriters.put(writerId, newWriter);
}

private BufferedWriter createFile(final String path, final String timeHeader) throws IOException {

File file = new File(path);
BufferedWriter writer = new BufferedWriter((new FileWriter(file)));

Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
scanIntent.setData(Uri.fromFile(file));
mContext.sendBroadcast(scanIntent);
if ((timeHeader != null) && (timeHeader.length() != 0)) {
writer.append(timeHeader);
writer.flush();
}
return writer;
}

public String getOutputFolder() {
return mOutputFolder;
}

public BufferedWriter getFileWriter(final String writerId) {
return mFileWriters.get(writerId);
}

public void addRecord(final long timestamp, final String writerId, final int numValues, final float[] values) throws IOException, KeyException {

// execute the block with only one thread
synchronized (this) {

// get BufferedWriter of 'writerId'
BufferedWriter writer = getFileWriter(writerId);
if (writer == null) {
throw new KeyException("addRecord: " + writerId + " not found.");
}

// record timestamp, and values in text file
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(timestamp);
for (int i = 0; i < numValues; ++i) {
stringBuilder.append(String.format(Locale.US, " %.6f", values[i]));
}
stringBuilder.append(" \n");
writer.write(stringBuilder.toString());
}
}

public void endFiles() throws IOException {

// execute the block with only one thread
synchronized (this) {
for (BufferedWriter eachWriter : mFileWriters.values()) {
eachWriter.flush();
eachWriter.close();
}
}
}
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/pjinkim/arcore_data_logger/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.pjinkim.arcore_data_logger;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

// properties
private final static String LOG_TAG = MainActivity.class.getName();


// Android activity lifecycle states
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


// methods
public static boolean checkIsSupportedDeviceOrFinish(final Activity activity) {

// check Android version
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.e(LOG_TAG, "Sceneform requires Android N or later");
Toast.makeText(activity, "Sceneform requires Android N or later", Toast.LENGTH_LONG).show();
activity.finish();
return false;
}

String openGlVersionString = ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo()
.getGlEsVersion();

// check OpenGL version
if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION) {
Log.e(LOG_TAG, "Sceneform requires OpenGL ES 3.0 later");
Toast.makeText(activity, "Sceneform requires OpenGL ES 3.0 or later", Toast.LENGTH_LONG).show();
activity.finish();
return false;
}
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.pjinkim.arcore_data_logger;

import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class OutputDirectoryManager {

// properties
private final static String LOG_TAG = OutputDirectoryManager.class.getName();

private String mOutputDirectory;


// constructors
public OutputDirectoryManager(final String prefix, final String suffix) throws FileNotFoundException {
update(prefix, suffix);
}

public OutputDirectoryManager(final String prefix) throws FileNotFoundException {
update(prefix);
}

public OutputDirectoryManager() throws FileNotFoundException {
update();
}


// methods
private void update(final String prefix, final String suffix) throws FileNotFoundException {

// initialize folder name with current time information
Calendar currentTime = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss");
File externalDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String folderName = formatter.format(currentTime.getTime());

// combine prefix and suffix
if (prefix != null) {
folderName = prefix + folderName;
}
if (suffix != null) {
folderName = folderName + suffix;
}

// generate output directory folder
File outputDirectory = new File(externalDirectory.getAbsolutePath() + "/" + folderName);
if (!outputDirectory.exists()) {
if (!outputDirectory.mkdir()) {
Log.e(LOG_TAG, "update: Cannot create output directory.");
throw new FileNotFoundException();
}
}
mOutputDirectory = outputDirectory.getAbsolutePath();
Log.i(LOG_TAG, "update: Output directory: " + outputDirectory.getAbsolutePath());
}

private void update(final String prefix) throws FileNotFoundException {
update(prefix, null);
}

private void update() throws FileNotFoundException {
update(null, null);
}


// getter and setter
public String getOutputDirectory() {
return mOutputDirectory;
}
}
Loading

0 comments on commit a5d638f

Please sign in to comment.