Merge branch 'master' of github.com:McPhysix/Spherical

This commit is contained in:
Simon Leistikow 2017-09-15 12:46:08 +02:00
commit 79467563c2
10 changed files with 203 additions and 54 deletions

View File

@ -5,7 +5,7 @@ android {
buildToolsVersion "25.0.3" buildToolsVersion "25.0.3"
defaultConfig { defaultConfig {
applicationId "de.trac.spherical" applicationId "de.trac.spherical"
minSdkVersion 15 minSdkVersion 16
targetSdkVersion 25 targetSdkVersion 25
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"

View File

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application <application
android:allowBackup="true" android:allowBackup="false"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"

View File

@ -0,0 +1,23 @@
package de.trac.spherical;
import android.content.Intent;
import android.os.AsyncTask;
/**
* Created by vanitas on 15.09.17.
*/
public class HandleImageTask extends AsyncTask<Intent, Void, Void> {
private MainActivity mainActivity;
public HandleImageTask(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
@Override
protected Void doInBackground(Intent... params) {
mainActivity.handleSentImageIntent(params[0]);
return null;
}
}

View File

@ -1,11 +1,15 @@
package de.trac.spherical; package de.trac.spherical;
import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
@ -15,7 +19,10 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -34,11 +41,14 @@ public class MainActivity extends AppCompatActivity {
public static final String MIME_PHOTO_SPHERE = "application/vnd.google.panorama360+jpg"; public static final String MIME_PHOTO_SPHERE = "application/vnd.google.panorama360+jpg";
public static final String MIME_IMAGE = "image/*"; public static final String MIME_IMAGE = "image/*";
private static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 387;
private SphereSurfaceView surfaceView; private SphereSurfaceView surfaceView;
private Renderer renderer; private Renderer renderer;
private FloatingActionButton fab; private FloatingActionButton fab;
private Toolbar toolbar; private Toolbar toolbar;
private AppBarLayout appBarLayout;
private Intent cachedIntent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -49,10 +59,9 @@ public class MainActivity extends AppCompatActivity {
toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
appBarLayout = (AppBarLayout) findViewById(R.id.lay_toolbar); RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) toolbar.getLayoutParams();
AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
lp.topMargin += getStatusBarHeight(); lp.topMargin += getStatusBarHeight();
appBarLayout.bringToFront(); toolbar.bringToFront();
fab = (FloatingActionButton) findViewById(R.id.fab); fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() { fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -62,6 +71,11 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
// Initialize renderer and setup surface view. // Initialize renderer and setup surface view.
LinearLayout container = (LinearLayout) findViewById(R.id.container); LinearLayout container = (LinearLayout) findViewById(R.id.container);
surfaceView = new SphereSurfaceView(this); surfaceView = new SphereSurfaceView(this);
@ -85,27 +99,59 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
Intent intent = getIntent(); handleIntent(getIntent());
}
private void handleIntent(Intent intent) {
switch (intent.getAction()) { switch (intent.getAction()) {
//Image was sent into the app //Image was sent into the app
case Intent.ACTION_SEND: case Intent.ACTION_SEND:
handleSentImageIntent(intent); checkPermissionAndHandleSentImage(intent);
break; break;
//App was launched via launcher icon //App was launched via launcher icon
//TODO: Remove later together with launcher intent filter //TODO: Remove later together with launcher intent filter
default: default:
Toast.makeText(this, R.string.prompt_share_image, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.toast_prompt_share_image, Toast.LENGTH_LONG).show();
}
}
private void checkPermissionAndHandleSentImage(Intent intent) {
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (status == PackageManager.PERMISSION_GRANTED) {
new HandleImageTask(this).doInBackground(intent);
}
// Cache intent and request permission
this.cachedIntent = intent;
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_READ_EXTERNAL_STORAGE: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
new HandleImageTask(this).doInBackground(cachedIntent);
} else {
Toast.makeText(this, R.string.toast_missing_permission, Toast.LENGTH_LONG).show();
}
}
} }
} }
private void displayUI(boolean display) { private void displayUI(boolean display) {
if (display) { if (display) {
fab.show(); fab.show();
appBarLayout.setExpanded(true, true); toolbar.setVisibility(View.VISIBLE);
} else { } else {
fab.setVisibility(View.INVISIBLE); fab.setVisibility(View.INVISIBLE);
appBarLayout.setExpanded(false, true); toolbar.setVisibility(View.GONE);
} }
} }
@ -126,7 +172,7 @@ public class MainActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_force_sphere: case R.id.menu_force_sphere:
Toast.makeText(this, R.string.not_yet_implemented, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.toast_not_yet_implemented, Toast.LENGTH_SHORT).show();
return true; return true;
} }
@ -138,13 +184,13 @@ public class MainActivity extends AppCompatActivity {
* displayed, while images with MIME type image/* are being manually tested using {@link PhotoSphereParser}. * displayed, while images with MIME type image/* are being manually tested using {@link PhotoSphereParser}.
* @param intent incoming intent. * @param intent incoming intent.
*/ */
private void handleSentImageIntent(Intent intent) { void handleSentImageIntent(Intent intent) {
String type = intent.getType(); String type = intent.getType();
if (type != null) { if (type != null) {
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri == null) { if (imageUri == null) {
Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.toast_file_not_found, Toast.LENGTH_SHORT).show();
return; return;
} }
@ -180,9 +226,11 @@ public class MainActivity extends AppCompatActivity {
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); Log.e(TAG, "File not found.", e);
Toast.makeText(this, R.string.toast_file_not_found, Toast.LENGTH_SHORT).show();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(TAG, "IOException: ", e);
Toast.makeText(this, R.string.toast_io_error, Toast.LENGTH_SHORT).show();
} }
} }
@ -205,10 +253,10 @@ public class MainActivity extends AppCompatActivity {
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(TAG, "File not found.", e); Log.e(TAG, "File not found.", e);
Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.toast_file_not_found, Toast.LENGTH_SHORT).show();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "IOException: ", e); Log.e(TAG, "IOException: ", e);
Toast.makeText(this, R.string.ioerror, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.toast_io_error, Toast.LENGTH_SHORT).show();
} }
} }
@ -223,6 +271,7 @@ public class MainActivity extends AppCompatActivity {
*/ */
private void displayFlatImage(InputStream inputStream) { private void displayFlatImage(InputStream inputStream) {
Log.d(TAG, "Display Flat Image!"); Log.d(TAG, "Display Flat Image!");
displayPhotoSphere(inputStream, new PhotoSphereMetadata());
} }
public int getStatusBarHeight() { public int getStatusBarHeight() {

View File

@ -169,32 +169,45 @@ public class PhotoSphereParser {
private static Integer parseInteger(String key, String xmp, Integer defaultValue) { private static Integer parseInteger(String key, String xmp, Integer defaultValue) {
String value = parseString(key, xmp); String value = parseString(key, xmp);
return value == null ? defaultValue : Integer.parseInt(value); if (value == null) {
return defaultValue;
}
return Integer.parseInt(value);
} }
private static Float parseFloat(String key, String xmp, Float defaultValue) { private static Float parseFloat(String key, String xmp, Float defaultValue) {
String value = parseString(key, xmp); String value = parseString(key, xmp);
if (value == null) { if (value == null) {
return defaultValue; return defaultValue;
} else {
return Float.parseFloat(value);
} }
return Float.parseFloat(value);
} }
private static Boolean parseBoolean(String key, String xmp, Boolean defaultValue) { private static Boolean parseBoolean(String key, String xmp, Boolean defaultValue) {
String value = parseString(key, xmp); String value = parseString(key, xmp);
return value == null ? defaultValue : Boolean.parseBoolean(value); if (value == null) {
return defaultValue;
}
return Boolean.parseBoolean(value);
} }
private static ProjectionType parseType(String key, String xmp, ProjectionType defaultValue) { private static ProjectionType parseType(String key, String xmp, ProjectionType defaultValue) {
String value = parseString(key, xmp); String value = parseString(key, xmp);
return value == null ? defaultValue : ProjectionType.equirectangular; if (value == null) {
return defaultValue;
}
return ProjectionType.equirectangular;
} }
private static Date parseDate(String key, String xmp, Date defaultValue) { private static Date parseDate(String key, String xmp, Date defaultValue) {
String value = parseString(key, xmp); String value = parseString(key, xmp);
try { try {
return value == null ? defaultValue : dateFormat.parse(value); if (value == null) {
return defaultValue;
}
return dateFormat.parse(value);
} catch (ParseException e) { } catch (ParseException e) {
return defaultValue; return defaultValue;
} }

View File

@ -10,8 +10,55 @@ import android.util.Log;
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import static android.opengl.GLES20.*; import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
import static android.opengl.GLUtils.getEGLErrorString; import static android.opengl.GLES20.GL_COMPILE_STATUS;
import static android.opengl.GLES20.GL_CULL_FACE;
import static android.opengl.GLES20.GL_CW;
import static android.opengl.GLES20.GL_DEPTH_BUFFER_BIT;
import static android.opengl.GLES20.GL_DEPTH_TEST;
import static android.opengl.GLES20.GL_FLOAT;
import static android.opengl.GLES20.GL_FRAGMENT_SHADER;
import static android.opengl.GLES20.GL_LINEAR;
import static android.opengl.GLES20.GL_LINK_STATUS;
import static android.opengl.GLES20.GL_NEAREST;
import static android.opengl.GLES20.GL_TEXTURE0;
import static android.opengl.GLES20.GL_TEXTURE_2D;
import static android.opengl.GLES20.GL_TEXTURE_MAG_FILTER;
import static android.opengl.GLES20.GL_TEXTURE_MIN_FILTER;
import static android.opengl.GLES20.GL_TRIANGLES;
import static android.opengl.GLES20.GL_TRUE;
import static android.opengl.GLES20.GL_UNSIGNED_SHORT;
import static android.opengl.GLES20.GL_VERTEX_SHADER;
import static android.opengl.GLES20.glActiveTexture;
import static android.opengl.GLES20.glAttachShader;
import static android.opengl.GLES20.glBindTexture;
import static android.opengl.GLES20.glClear;
import static android.opengl.GLES20.glClearColor;
import static android.opengl.GLES20.glCompileShader;
import static android.opengl.GLES20.glCreateProgram;
import static android.opengl.GLES20.glCreateShader;
import static android.opengl.GLES20.glDeleteProgram;
import static android.opengl.GLES20.glDeleteShader;
import static android.opengl.GLES20.glDisableVertexAttribArray;
import static android.opengl.GLES20.glDrawElements;
import static android.opengl.GLES20.glEnable;
import static android.opengl.GLES20.glEnableVertexAttribArray;
import static android.opengl.GLES20.glFrontFace;
import static android.opengl.GLES20.glGenTextures;
import static android.opengl.GLES20.glGetAttribLocation;
import static android.opengl.GLES20.glGetProgramInfoLog;
import static android.opengl.GLES20.glGetProgramiv;
import static android.opengl.GLES20.glGetShaderInfoLog;
import static android.opengl.GLES20.glGetShaderiv;
import static android.opengl.GLES20.glGetUniformLocation;
import static android.opengl.GLES20.glLinkProgram;
import static android.opengl.GLES20.glShaderSource;
import static android.opengl.GLES20.glTexParameteri;
import static android.opengl.GLES20.glUniform1i;
import static android.opengl.GLES20.glUniformMatrix4fv;
import static android.opengl.GLES20.glUseProgram;
import static android.opengl.GLES20.glVertexAttribPointer;
import static android.opengl.GLES20.glViewport;
public class Renderer implements GLSurfaceView.Renderer { public class Renderer implements GLSurfaceView.Renderer {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
@ -9,28 +9,18 @@
android:fitsSystemWindows="false" android:fitsSystemWindows="false"
tools:context="de.trac.spherical.MainActivity"> tools:context="de.trac.spherical.MainActivity">
<android.support.design.widget.AppBarLayout <android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lay_toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="false" android:fitsSystemWindows="true"
android:background="@android:color/transparent" android:background="@android:color/transparent"
app:elevation="0dp"> android:layout_alignParentTop="true"
app:layout_scrollFlags="scroll|enterAlways|snap"
<android.support.v7.widget.Toolbar app:theme="@style/AppTheme.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android" app:popupTheme="@style/ThemeOverlay.AppCompat" />
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:theme="@style/AppTheme.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat" />
</android.support.design.widget.AppBarLayout>
<LinearLayout <LinearLayout
android:id="@+id/container" android:id="@+id/container"
@ -45,7 +35,9 @@
android:id="@+id/fab" android:id="@+id/fab"
android:src="@drawable/ic_explore_white_48px" android:src="@drawable/ic_explore_white_48px"
app:fabSize="mini" app:fabSize="mini"
android:layout_gravity="bottom|end" android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="64dp" android:layout_marginBottom="64dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
@ -54,4 +46,4 @@
app:layout_anchor="@id/container" app:layout_anchor="@id/container"
app:layout_anchorGravity="bottom|right|end" /> app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout> </RelativeLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="menu_force_sphere">Erzwinge Kugelansicht</string>
<string name="toast_file_not_found">Datei nicht gefunden.</string>
<string name="toast_io_error">Ein Fehler ist aufgetreten: IO-Error.</string>
<string name="toast_missing_permission">Foto kann nicht angezeigt werden: Fehlende Berechtigung für externen Speicher.</string>
<string name="toast_not_yet_implemented">Noch nicht implementiert!</string>
<string name="toast_prompt_share_image">Teile ein Bild mit der App!</string>
</resources>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionBarOverlay">false</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:fitsSystemWindows">false</item>
</style>
</resources>

View File

@ -1,9 +1,9 @@
<resources> <resources>
<string name="app_name">Spherical</string> <string name="app_name" translatable="false">Spherical</string>
<string name="prompt_share_image">Share an image with the app!</string> <string name="toast_prompt_share_image">Share an image with the app!</string>
<string name="file_not_found">File not found.</string> <string name="toast_file_not_found">File not found.</string>
<string name="ioerror">An Error has occurred: IOError.</string> <string name="toast_io_error">An Error has occurred: IO-Error.</string>
<string name="wow">WOW! SUCH 3D!!!</string>
<string name="menu_force_sphere">Show as Sphere</string> <string name="menu_force_sphere">Show as Sphere</string>
<string name="not_yet_implemented">Not yet implemented!</string> <string name="toast_not_yet_implemented">Not yet implemented!</string>
<string name="toast_missing_permission">Cannot display photo: Missing permissions to access external storage.</string>
</resources> </resources>