mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-22 04:12:07 +01:00
Add option to display flat image
This commit is contained in:
parent
4b187ede43
commit
915faa139e
9 changed files with 138 additions and 45 deletions
|
@ -1,28 +1,68 @@
|
||||||
package de.trac.spherical;
|
package de.trac.spherical;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.davemorrissey.labs.subscaleview.ImageSource;
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 17.09.17.
|
* Created by vanitas on 17.09.17.
|
||||||
*/
|
*/
|
||||||
|
public class FlatFragment extends ImageFragment {
|
||||||
|
|
||||||
public class FlatFragment extends Fragment {
|
private static final String TAG = "SphericalFFrag";
|
||||||
|
|
||||||
private SubsamplingScaleImageView imageView;
|
private SubsamplingScaleImageView imageView;
|
||||||
|
private Bitmap bitmap;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
|
Log.d(TAG, "onCreateView");
|
||||||
return inflater.inflate(R.layout.fragment_flat, parent, false);
|
return inflater.inflate(R.layout.fragment_flat, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
Log.d(TAG, "onViewCreated");
|
||||||
|
setHasOptionsMenu(true);
|
||||||
imageView = (SubsamplingScaleImageView) view.findViewById(R.id.image_view);
|
imageView = (SubsamplingScaleImageView) view.findViewById(R.id.image_view);
|
||||||
|
updateBitmap(getMainActivity().getBitmap());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.menu_flat, menu);
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_force_sphere:
|
||||||
|
getMainActivity().displayPhotoSphere();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MainActivity getMainActivity() {
|
||||||
|
return (MainActivity) getActivity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBitmap(Bitmap bitmap) {
|
||||||
|
if (imageView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.bitmap = bitmap;
|
||||||
|
imageView.setImage(ImageSource.cachedBitmap(bitmap));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
app/src/main/java/de/trac/spherical/ImageFragment.java
Normal file
13
app/src/main/java/de/trac/spherical/ImageFragment.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package de.trac.spherical;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by vanitas on 19.09.17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract class ImageFragment extends Fragment {
|
||||||
|
|
||||||
|
public abstract void updateBitmap(Bitmap bitmap);
|
||||||
|
}
|
|
@ -28,7 +28,6 @@ import android.view.WindowManager;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import de.trac.spherical.parser.PhotoSphereMetadata;
|
import de.trac.spherical.parser.PhotoSphereMetadata;
|
||||||
|
@ -49,9 +48,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
private GestureDetectorCompat gestureDetector;
|
private GestureDetectorCompat gestureDetector;
|
||||||
|
|
||||||
private ProgressFragment progressFragment;
|
private ProgressFragment progressFragment = new ProgressFragment();
|
||||||
private FlatFragment flatFragment;
|
private FlatFragment flatFragment = new FlatFragment();
|
||||||
private SphereFragment sphereFragment;
|
private SphereFragment sphereFragment = new SphereFragment();
|
||||||
|
private ImageFragment currentlyShownImageFragment;
|
||||||
|
|
||||||
//Cache
|
//Cache
|
||||||
private Intent cachedIntent;
|
private Intent cachedIntent;
|
||||||
|
@ -69,28 +69,19 @@ public class MainActivity extends AppCompatActivity {
|
||||||
handleIntent(getIntent());
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProgressFragment showProgressFragment() {
|
private void showProgressFragment() {
|
||||||
if (progressFragment == null) {
|
|
||||||
progressFragment = new ProgressFragment();
|
|
||||||
}
|
|
||||||
fm.beginTransaction().replace(R.id.container_fragment, progressFragment, "prog").commit();
|
fm.beginTransaction().replace(R.id.container_fragment, progressFragment, "prog").commit();
|
||||||
return progressFragment;
|
this.currentlyShownImageFragment = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FlatFragment showFlatImageFragment() {
|
private void showFlatImageFragment() {
|
||||||
if (flatFragment == null) {
|
|
||||||
flatFragment = new FlatFragment();
|
|
||||||
}
|
|
||||||
fm.beginTransaction().replace(R.id.container_fragment, flatFragment, "flat").commit();
|
fm.beginTransaction().replace(R.id.container_fragment, flatFragment, "flat").commit();
|
||||||
return flatFragment;
|
this.currentlyShownImageFragment = flatFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SphereFragment showSphereFragment() {
|
private void showSphereFragment() {
|
||||||
if (sphereFragment == null) {
|
|
||||||
sphereFragment = new SphereFragment();
|
|
||||||
}
|
|
||||||
fm.beginTransaction().replace(R.id.container_fragment, sphereFragment, "sphere").commit();
|
fm.beginTransaction().replace(R.id.container_fragment, sphereFragment, "sphere").commit();
|
||||||
return sphereFragment;
|
this.currentlyShownImageFragment = sphereFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUI() {
|
private void setupUI() {
|
||||||
|
@ -129,6 +120,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
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:
|
||||||
|
showProgressFragment();
|
||||||
checkPermissionAndHandleSentImage(intent);
|
checkPermissionAndHandleSentImage(intent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -142,8 +134,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private void checkPermissionAndHandleSentImage(Intent intent) {
|
private void checkPermissionAndHandleSentImage(Intent intent) {
|
||||||
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
if (status == PackageManager.PERMISSION_GRANTED) {
|
if (status == PackageManager.PERMISSION_GRANTED) {
|
||||||
showProgressFragment();
|
handleSentImageIntent(intent);
|
||||||
new HandleSentImageTask().doInBackground(intent);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +151,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
// If request is cancelled, the result arrays are empty.
|
// If request is cancelled, the result arrays are empty.
|
||||||
if (grantResults.length > 0
|
if (grantResults.length > 0
|
||||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
showProgressFragment();
|
handleSentImageIntent(cachedIntent);
|
||||||
new HandleSentImageTask().doInBackground(cachedIntent);
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, R.string.toast_missing_permission, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.toast_missing_permission, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
@ -188,14 +178,14 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.main_menu, menu);
|
inflater.inflate(R.menu.menu_main, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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_about:
|
||||||
Toast.makeText(this, R.string.toast_not_yet_implemented, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.toast_not_yet_implemented, Toast.LENGTH_SHORT).show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -209,6 +199,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
* @param intent incoming intent.
|
* @param intent incoming intent.
|
||||||
*/
|
*/
|
||||||
void handleSentImageIntent(Intent intent) {
|
void handleSentImageIntent(Intent intent) {
|
||||||
|
if (intent == null) {
|
||||||
|
throw new AssertionError("Intent is null!");
|
||||||
|
}
|
||||||
String type = intent.getType();
|
String type = intent.getType();
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
|
|
||||||
|
@ -222,8 +215,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
try {
|
try {
|
||||||
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
|
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
|
||||||
metadata = PhotoSphereParser.parse(getContentResolver().openInputStream(imageUri));
|
metadata = PhotoSphereParser.parse(getContentResolver().openInputStream(imageUri));
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -251,17 +242,17 @@ public class MainActivity extends AppCompatActivity {
|
||||||
/**
|
/**
|
||||||
* Display a photo sphere.
|
* Display a photo sphere.
|
||||||
*/
|
*/
|
||||||
private void displayPhotoSphere() {
|
public void displayPhotoSphere() {
|
||||||
SphereFragment spf = showSphereFragment();
|
showSphereFragment();
|
||||||
spf.displayPhotoSphere(bitmap);
|
currentlyShownImageFragment.updateBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a flat bitmap.
|
* Display a flat bitmap.
|
||||||
*/
|
*/
|
||||||
private void displayFlatImage() {
|
public void displayFlatImage() {
|
||||||
Log.d(TAG, "Display Flat Image!");
|
showFlatImageFragment();
|
||||||
//displayPhotoSphere(inputStream, new PhotoSphereMetadata());
|
currentlyShownImageFragment.updateBitmap(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStatusBarHeight() {
|
private int getStatusBarHeight() {
|
||||||
|
@ -286,6 +277,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Intent... params) {
|
protected Void doInBackground(Intent... params) {
|
||||||
handleSentImageIntent(params[0]);
|
handleSentImageIntent(params[0]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ package de.trac.spherical;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -15,17 +17,23 @@ import de.trac.spherical.rendering.PhotoSphereSurfaceView;
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 17.09.17.
|
* Created by vanitas on 17.09.17.
|
||||||
*/
|
*/
|
||||||
public class SphereFragment extends Fragment implements View.OnTouchListener {
|
public class SphereFragment extends ImageFragment implements View.OnTouchListener {
|
||||||
|
|
||||||
|
private static final String TAG = "SphericalSFrag";
|
||||||
|
|
||||||
private PhotoSphereSurfaceView surfaceView;
|
private PhotoSphereSurfaceView surfaceView;
|
||||||
|
private Bitmap bitmap;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
|
Log.d(TAG, "onCreateView");
|
||||||
return inflater.inflate(R.layout.fragment_sphere, parent, false);
|
return inflater.inflate(R.layout.fragment_sphere, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
|
Log.d(TAG, "onViewCreated");
|
||||||
|
setHasOptionsMenu(true);
|
||||||
FrameLayout fragmentRoot = (FrameLayout) view.findViewById(R.id.container_sphere);
|
FrameLayout fragmentRoot = (FrameLayout) view.findViewById(R.id.container_sphere);
|
||||||
surfaceView = new PhotoSphereSurfaceView(getContext());
|
surfaceView = new PhotoSphereSurfaceView(getContext());
|
||||||
|
|
||||||
|
@ -33,12 +41,7 @@ public class SphereFragment extends Fragment implements View.OnTouchListener {
|
||||||
fragmentRoot.addView(surfaceView);
|
fragmentRoot.addView(surfaceView);
|
||||||
|
|
||||||
surfaceView.setOnTouchListener(this);
|
surfaceView.setOnTouchListener(this);
|
||||||
surfaceView.setBitmap(getMainActivity().getBitmap());
|
updateBitmap(getMainActivity().getBitmap());
|
||||||
}
|
|
||||||
|
|
||||||
public void displayPhotoSphere(Bitmap bitmap) {
|
|
||||||
//surfaceView.setBitmap(bitmap);
|
|
||||||
Log.d(MainActivity.TAG, "Display Photo Sphere!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,7 +49,32 @@ public class SphereFragment extends Fragment implements View.OnTouchListener {
|
||||||
return getMainActivity().getGestureDetector().onTouchEvent(event);
|
return getMainActivity().getGestureDetector().onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.menu_sphere, menu);
|
||||||
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.menu_force_flat:
|
||||||
|
getMainActivity().displayFlatImage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
private MainActivity getMainActivity() {
|
private MainActivity getMainActivity() {
|
||||||
return (MainActivity) getActivity();
|
return (MainActivity) getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBitmap(Bitmap bitmap) {
|
||||||
|
if (surfaceView == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.bitmap = bitmap;
|
||||||
|
surfaceView.setBitmap(bitmap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
8
app/src/main/res/menu/menu_main.xml
Normal file
8
app/src/main/res/menu/menu_main.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_about"
|
||||||
|
android:title="@string/menu_about"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
8
app/src/main/res/menu/menu_sphere.xml
Normal file
8
app/src/main/res/menu/menu_sphere.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_force_flat"
|
||||||
|
android:title="@string/menu_force_flat"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
</menu>
|
|
@ -1,9 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="menu_force_sphere">Erzwinge Kugelansicht</string>
|
<string name="menu_force_sphere">Kugelansicht</string>
|
||||||
<string name="toast_file_not_found">Datei nicht gefunden.</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_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_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_not_yet_implemented">Noch nicht implementiert!</string>
|
||||||
<string name="toast_prompt_share_image">Teile ein Bild mit der App!</string>
|
<string name="toast_prompt_share_image">Teile ein Bild mit der App!</string>
|
||||||
|
<string name="menu_about">Über Spherical</string>
|
||||||
|
<string name="menu_force_flat">Flache Ansicht</string>
|
||||||
</resources>
|
</resources>
|
|
@ -3,7 +3,9 @@
|
||||||
<string name="toast_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="toast_file_not_found">File not found.</string>
|
<string name="toast_file_not_found">File not found.</string>
|
||||||
<string name="toast_io_error">An Error has occurred: IO-Error.</string>
|
<string name="toast_io_error">An Error has occurred: IO-Error.</string>
|
||||||
<string name="menu_force_sphere">Show as Sphere</string>
|
<string name="menu_force_sphere">Sphere View</string>
|
||||||
<string name="toast_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>
|
<string name="toast_missing_permission">Cannot display photo: Missing permissions to access external storage.</string>
|
||||||
|
<string name="menu_force_flat">Flat View</string>
|
||||||
|
<string name="menu_about">About Spherical</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue