-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
952 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,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' | ||
} |
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,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 |
27 changes: 27 additions & 0 deletions
27
app/src/androidTest/java/com/pjinkim/arcore_data_logger/ExampleInstrumentedTest.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,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()); | ||
} | ||
} |
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,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
107
app/src/main/java/com/pjinkim/arcore_data_logger/FileStreamer.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,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
52
app/src/main/java/com/pjinkim/arcore_data_logger/MainActivity.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,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; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/pjinkim/arcore_data_logger/OutputDirectoryManager.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,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; | ||
} | ||
} |
Oops, something went wrong.