mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-12-22 02:48:00 +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;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource;
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
||||
|
||||
/**
|
||||
* 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 Bitmap bitmap;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onCreateView");
|
||||
return inflater.inflate(R.layout.fragment_flat, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onViewCreated");
|
||||
setHasOptionsMenu(true);
|
||||
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.Toast;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import de.trac.spherical.parser.PhotoSphereMetadata;
|
||||
|
@ -49,9 +48,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
private Toolbar toolbar;
|
||||
private GestureDetectorCompat gestureDetector;
|
||||
|
||||
private ProgressFragment progressFragment;
|
||||
private FlatFragment flatFragment;
|
||||
private SphereFragment sphereFragment;
|
||||
private ProgressFragment progressFragment = new ProgressFragment();
|
||||
private FlatFragment flatFragment = new FlatFragment();
|
||||
private SphereFragment sphereFragment = new SphereFragment();
|
||||
private ImageFragment currentlyShownImageFragment;
|
||||
|
||||
//Cache
|
||||
private Intent cachedIntent;
|
||||
|
@ -69,28 +69,19 @@ public class MainActivity extends AppCompatActivity {
|
|||
handleIntent(getIntent());
|
||||
}
|
||||
|
||||
private ProgressFragment showProgressFragment() {
|
||||
if (progressFragment == null) {
|
||||
progressFragment = new ProgressFragment();
|
||||
}
|
||||
private void showProgressFragment() {
|
||||
fm.beginTransaction().replace(R.id.container_fragment, progressFragment, "prog").commit();
|
||||
return progressFragment;
|
||||
this.currentlyShownImageFragment = null;
|
||||
}
|
||||
|
||||
private FlatFragment showFlatImageFragment() {
|
||||
if (flatFragment == null) {
|
||||
flatFragment = new FlatFragment();
|
||||
}
|
||||
private void showFlatImageFragment() {
|
||||
fm.beginTransaction().replace(R.id.container_fragment, flatFragment, "flat").commit();
|
||||
return flatFragment;
|
||||
this.currentlyShownImageFragment = flatFragment;
|
||||
}
|
||||
|
||||
private SphereFragment showSphereFragment() {
|
||||
if (sphereFragment == null) {
|
||||
sphereFragment = new SphereFragment();
|
||||
}
|
||||
private void showSphereFragment() {
|
||||
fm.beginTransaction().replace(R.id.container_fragment, sphereFragment, "sphere").commit();
|
||||
return sphereFragment;
|
||||
this.currentlyShownImageFragment = sphereFragment;
|
||||
}
|
||||
|
||||
private void setupUI() {
|
||||
|
@ -129,6 +120,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
switch (intent.getAction()) {
|
||||
//Image was sent into the app
|
||||
case Intent.ACTION_SEND:
|
||||
showProgressFragment();
|
||||
checkPermissionAndHandleSentImage(intent);
|
||||
break;
|
||||
|
||||
|
@ -142,8 +134,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
private void checkPermissionAndHandleSentImage(Intent intent) {
|
||||
int status = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (status == PackageManager.PERMISSION_GRANTED) {
|
||||
showProgressFragment();
|
||||
new HandleSentImageTask().doInBackground(intent);
|
||||
handleSentImageIntent(intent);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -160,8 +151,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
showProgressFragment();
|
||||
new HandleSentImageTask().doInBackground(cachedIntent);
|
||||
handleSentImageIntent(cachedIntent);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_missing_permission, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
@ -188,14 +178,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.main_menu, menu);
|
||||
inflater.inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
|
@ -209,6 +199,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
* @param intent incoming intent.
|
||||
*/
|
||||
void handleSentImageIntent(Intent intent) {
|
||||
if (intent == null) {
|
||||
throw new AssertionError("Intent is null!");
|
||||
}
|
||||
String type = intent.getType();
|
||||
if (type != null) {
|
||||
|
||||
|
@ -222,8 +215,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
try {
|
||||
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
|
||||
metadata = PhotoSphereParser.parse(getContentResolver().openInputStream(imageUri));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -251,17 +242,17 @@ public class MainActivity extends AppCompatActivity {
|
|||
/**
|
||||
* Display a photo sphere.
|
||||
*/
|
||||
private void displayPhotoSphere() {
|
||||
SphereFragment spf = showSphereFragment();
|
||||
spf.displayPhotoSphere(bitmap);
|
||||
public void displayPhotoSphere() {
|
||||
showSphereFragment();
|
||||
currentlyShownImageFragment.updateBitmap(bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a flat bitmap.
|
||||
*/
|
||||
private void displayFlatImage() {
|
||||
Log.d(TAG, "Display Flat Image!");
|
||||
//displayPhotoSphere(inputStream, new PhotoSphereMetadata());
|
||||
public void displayFlatImage() {
|
||||
showFlatImageFragment();
|
||||
currentlyShownImageFragment.updateBitmap(bitmap);
|
||||
}
|
||||
|
||||
private int getStatusBarHeight() {
|
||||
|
@ -286,6 +277,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
@Override
|
||||
protected Void doInBackground(Intent... params) {
|
||||
handleSentImageIntent(params[0]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package de.trac.spherical;
|
|||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -15,17 +17,23 @@ import de.trac.spherical.rendering.PhotoSphereSurfaceView;
|
|||
/**
|
||||
* 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 Bitmap bitmap;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onCreateView");
|
||||
return inflater.inflate(R.layout.fragment_sphere, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
Log.d(TAG, "onViewCreated");
|
||||
setHasOptionsMenu(true);
|
||||
FrameLayout fragmentRoot = (FrameLayout) view.findViewById(R.id.container_sphere);
|
||||
surfaceView = new PhotoSphereSurfaceView(getContext());
|
||||
|
||||
|
@ -33,12 +41,7 @@ public class SphereFragment extends Fragment implements View.OnTouchListener {
|
|||
fragmentRoot.addView(surfaceView);
|
||||
|
||||
surfaceView.setOnTouchListener(this);
|
||||
surfaceView.setBitmap(getMainActivity().getBitmap());
|
||||
}
|
||||
|
||||
public void displayPhotoSphere(Bitmap bitmap) {
|
||||
//surfaceView.setBitmap(bitmap);
|
||||
Log.d(MainActivity.TAG, "Display Photo Sphere!");
|
||||
updateBitmap(getMainActivity().getBitmap());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +49,32 @@ public class SphereFragment extends Fragment implements View.OnTouchListener {
|
|||
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() {
|
||||
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"?>
|
||||
<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_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>
|
||||
<string name="menu_about">Über Spherical</string>
|
||||
<string name="menu_force_flat">Flache Ansicht</string>
|
||||
</resources>
|
|
@ -3,7 +3,9 @@
|
|||
<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_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_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>
|
||||
|
|
Loading…
Reference in a new issue