Android Cardboard: Support new phones/systems intents (for loading config

file), add analytics json support, fix app name
parent 2029a2d0
package com.google.vr.ndk.samples.treasurehunt;
//https://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore/7265235#7265235
class Filepath {
//@SuppressLint("NewApi")
public static String getFilePath(android.content.Context context, android.net.Uri uri) throws java.net.URISyntaxException {
String selection = null;
String[] selectionArgs = null;
// Uri is different in versions after KITKAT (Android 4.4), we need to
if (android.os.Build.VERSION.SDK_INT >= 19 && android.provider.DocumentsContract.isDocumentUri(context.getApplicationContext(), uri)) {
if (isExternalStorageDocument(uri)) {
final String docId = android.provider.DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
return android.os.Environment.getExternalStorageDirectory() + "/" + split[1];
} else if (isDownloadsDocument(uri)) {
final String id = android.provider.DocumentsContract.getDocumentId(uri);
uri = android.content.ContentUris.withAppendedId(
android.net.Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
} else if (isMediaDocument(uri)) {
final String docId = android.provider.DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("image".equals(type)) {
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
uri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
selection = "_id=?";
selectionArgs = new String[]{
split[1]
};
}
}
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = {
android.provider.MediaStore.Images.Media.DATA
};
android.database.Cursor cursor = null;
try {
cursor = context.getContentResolver()
.query(uri, projection, selection, selectionArgs, null);
int column_index = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Images.Media.DATA);
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
}
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
public static boolean isExternalStorageDocument(android.net.Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
public static boolean isDownloadsDocument(android.net.Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
public static boolean isMediaDocument(android.net.Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
}
......@@ -91,7 +91,13 @@ public static void verifyStoragePermissions(Activity activity) {
} else if (s.startsWith("content://com.asus.filemanager.OpenFileProvider/file")) {
uriString=s.substring(52);
} else {
uriString=s;
android.net.Uri u=android.net.Uri.parse(s);
try {
uriString=Filepath.getFilePath (this.getApplicationContext(), u);
} catch (java.net.URISyntaxException e) {
android.util.Log.d("NOMADgvrT","URISyntaxException, e="+e);
uriString=null;
}
}
android.util.Log.d("NOMADgvrT","OnActivityResult, uri="+uriString);
nativeSetConfigFile(uriString, android.os.Environment.getExternalStorageDirectory().getPath() + "/");
......
......@@ -658,14 +658,16 @@ if (animateTimesteps) {
frame.BindBuffer(0);
if (error<0) {
//rgh: FIXME, add textures with messages here
if (-100<error) {
if (-100<error) { //error with ncfg file
glClearColor(1.f, 0.f, 0.f, 1.f);
} else if (-200<error){
} else if (-200<error){//error loading xyz
glClearColor(0.f, 1.f, 0.f, 1.f);
} else if (-300<error) {
} else if (-300<error) {//error loading gaussian
glClearColor(0.f, 0.f, 1.f, 1.f);
} else if (-400<error) {
glClearColor(0.f, 1.f, 1.f, 1.f);
} else if (-400<error) {//error loading encyclopedia json
glClearColor(0.f, 1.f, 1.f, 1.f);
} else if (-500<error) {//error loading analytics json
glClearColor(1.f, 1.f, 0.f, 1.f);
} else {
glClearColor(1.f, 0.f, 1.f, 1.f);
}
......@@ -853,7 +855,7 @@ if ((e = glGetError()) != GL_NO_ERROR)
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("5 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
eprintf ("Drawing %d vertices, isos", numISOIndices[currentSet*ISOS+i]);
glDrawElements(GL_TRIANGLES,numISOIndices[currentSet*ISOS+i] , GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES,numISOIndices[currentSet*ISOS+i] , GL_UNSIGNED_INT, 0);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("6 Gl error RenderIsos timestep =%d: %d\n", currentSet, e);
}
......
<resources>
<string name="app_name">NOMADgvrT</string>
<string name="app_name">NOMAD VR</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment