Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image information modal to image viewer #2428

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/androidTest/java/de/blau/android/photos/PhotosTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ public void teardown() {
*/
// @SdkSuppress(minSdkVersion = 26)
@Test
public void selectDisplayDelete() {
public void selectDisplayInfoDelete() {
addLayerAndIndex();
TestUtils.unlock(device);
assertEquals(2, App.getPhotoIndex().count());
TestUtils.clickAtCoordinates(device, main.getMap(), 7.5886112, 47.5519448, true);

TestUtils.clickMenuButton(device, context.getString(R.string.menu_information), false, true);
assertTrue(TestUtils.findText(device, false, context.getString(R.string.image_information_title)));
TestUtils.sleep(20000);
assertTrue(TestUtils.clickText(device, false, context.getString(R.string.done),true, false));

TestUtils.clickMenuButton(device, context.getString(R.string.delete), false, true);
assertTrue(TestUtils.clickText(device, false, context.getString(R.string.photo_viewer_delete_button), true, false));

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ private void processIntents() {
Uri uri = intent.getData();
if (!index.deletePhoto(this, uri)) {
String path = ContentResolverUtil.getPath(this, uri);
if (path != null && !index.deletePhoto(this, path)) {
if (path == null || !index.deletePhoto(this, path)) {
Log.e(DEBUG_TAG, "deleting " + uri + " from index failed");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/contract/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private Urls() {
public static final String DEFAULT_OAM_SERVER = "https://api.openaerialmap.org/";

// these are only configurable for testing
public static final String DEFAULT_MAPILLARY_IMAGES_V4 = "https://graph.mapillary.com/%s?access_token=%s&fields=thumb_2048_url,computed_geometry";
public static final String DEFAULT_MAPILLARY_IMAGES_V4 = "https://graph.mapillary.com/%s?access_token=%s&fields=thumb_2048_url,computed_geometry,computed_compass_angle,captured_at";
public static final String DEFAULT_MAPILLARY_SEQUENCES_URL_V4 = "https://graph.mapillary.com/image_ids?sequence_id=%s&access_token=%s&fields=id";

public static final String DEFAULT_OSM_WIKI = "https://wiki.openstreetmap.org/";
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/de/blau/android/dialogs/ElementInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.text.SpannedString;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
Expand Down Expand Up @@ -60,7 +59,6 @@
import de.blau.android.util.DateFormatter;
import de.blau.android.util.InfoDialogFragment;
import de.blau.android.util.ScreenMessage;
import de.blau.android.util.ThemeUtils;
import de.blau.android.util.Util;
import de.blau.android.validation.Validator;

Expand Down Expand Up @@ -264,24 +262,16 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
return builder.create();
}

/**
* Create the view we want to display
*
* @param container parent view or null
* @return the View
*/
@Override
protected View createView(ViewGroup container) {
FragmentActivity activity = getActivity();
LayoutInflater themedInflater = ThemeUtils.getLayoutInflater(activity);
ScrollView sv = (ScrollView) themedInflater.inflate(R.layout.element_info_view, container, false);
ScrollView sv = createEmptyView(container);
TableLayout tl = (TableLayout) sv.findViewById(R.id.element_info_vertical_layout);
TableLayout.LayoutParams tp = getTableLayoutParams();

boolean compare = ue != null;

TableLayout.LayoutParams tp = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
tp.setMargins(10, 2, 10, 2);
if (element != null) {
FragmentActivity activity = getActivity();
boolean deleted = element.getState() == OsmElement.STATE_DELETED;
tl.setColumnStretchable(1, true);
tl.setColumnStretchable(2, true);
Expand Down
37 changes: 5 additions & 32 deletions src/main/java/de/blau/android/dialogs/FeatureInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.blau.android.dialogs;

import java.util.List;
import java.util.Locale;
import java.util.Set;

import com.google.gson.JsonElement;
Expand All @@ -12,9 +11,7 @@

import android.app.Dialog;
import android.os.Bundle;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
Expand Down Expand Up @@ -167,15 +164,12 @@ public AppCompatDialog onCreateDialog(Bundle savedInstanceState) {

@Override
protected View createView(@Nullable ViewGroup container) {
FragmentActivity activity = getActivity();
LayoutInflater inflater = ThemeUtils.getLayoutInflater(activity);
ScrollView sv = (ScrollView) inflater.inflate(R.layout.element_info_view, container, false);
ScrollView sv = createEmptyView(container);
TableLayout tl = (TableLayout) sv.findViewById(R.id.element_info_vertical_layout);

TableLayout.LayoutParams tp = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
tp.setMargins(10, 2, 10, 2);
TableLayout.LayoutParams tp = getTableLayoutParams();

if (feature != null) {
FragmentActivity activity = getActivity();
tl.setColumnShrinkable(1, true);
Geometry geometry = feature.geometry();
if (geometry != null) {
Expand All @@ -196,8 +190,8 @@ protected View createView(@Nullable ViewGroup container) {

Util.sharePosition(getActivity(), new double[] { p.longitude(), p.latitude() }, null);
});
tl.addView(TableLayoutUtils.createRowWithButton(activity, R.string.location_lon_label, prettyPrint(p.longitude()), button, tp));
tl.addView(TableLayoutUtils.createRow(activity, R.string.location_lat_label, prettyPrint(p.latitude()), tp));
tl.addView(TableLayoutUtils.createRowWithButton(activity, R.string.location_lon_label, prettyPrintCoord(p.longitude()), button, tp));
tl.addView(TableLayoutUtils.createRow(activity, R.string.location_lat_label, prettyPrintCoord(p.latitude()), tp));
}
}
tl.addView(TableLayoutUtils.divider(activity));
Expand All @@ -220,25 +214,4 @@ protected View createView(@Nullable ViewGroup container) {
}
return sv;
}

/**
* Get the string resource formated as an italic string
*
* @param resId String resource id
* @return a Spanned containing the string
*/
private Spanned toItalic(int resId) {
return Util.fromHtml("<i>" + getString(resId) + "</i>");
}

/**
* Pretty print a coordinate value
*
* @param coord the coordinate in WGS84
* @return a reasonable looking string representation
*/
@NonNull
private static String prettyPrint(double coord) {
return String.format(Locale.US, "%.7f", coord) + "°";
}
}
13 changes: 3 additions & 10 deletions src/main/java/de/blau/android/dialogs/GnssPositionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
Expand All @@ -35,7 +34,6 @@
import de.blau.android.util.GeoMath;
import de.blau.android.util.InfoDialogFragment;
import de.blau.android.util.ScreenMessage;
import de.blau.android.util.ThemeUtils;
import de.blau.android.util.Util;

/**
Expand Down Expand Up @@ -251,18 +249,13 @@ public void run() {

@Override
protected View createView(@Nullable ViewGroup container) {
LayoutInflater inflater;
FragmentActivity activity = getActivity();
inflater = ThemeUtils.getLayoutInflater(activity);
ScrollView sv = (ScrollView) inflater.inflate(R.layout.element_info_view, container, false);
ScrollView sv = createEmptyView(container);
tl = (TableLayout) sv.findViewById(R.id.element_info_vertical_layout);

tp = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
tp.setMargins(10, 2, 10, 2);
tp = getTableLayoutParams();

if (location != null) {
tl.setColumnShrinkable(1, true);
updateView(activity, tl, tp);
updateView(getActivity(), tl, tp);
tl.postDelayed(update, 1000);
}
return sv;
Expand Down
142 changes: 142 additions & 0 deletions src/main/java/de/blau/android/dialogs/ImageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package de.blau.android.dialogs;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TableLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.appcompat.app.AppCompatDialog;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import de.blau.android.R;
import de.blau.android.listener.DoNothingListener;
import de.blau.android.photos.Photo;
import de.blau.android.util.ContentResolverUtil;
import de.blau.android.util.DateFormatter;
import de.blau.android.util.InfoDialogFragment;

/**
* Very simple dialog fragment to display some info on a GeoJSON element
*
* @author simon
*
*/
public class ImageInfo extends InfoDialogFragment {

private static final String DEBUG_TAG = ImageInfo.class.getName();

private static final String URI_KEY = "uri";

private static final String TAG = "fragment_image_info";

private Uri uri = null;
private SimpleDateFormat dateFormat = DateFormatter.getUtcFormat("yyyy-MM-dd HH:mm:ssZ");

/**
* Show an info dialog for an image
*
* @param activity the calling Activity
* @param uriString the uri of the image as a string
*/
public static void showDialog(@NonNull FragmentActivity activity, @NonNull String uriString) {
dismissDialog(activity);
try {
FragmentManager fm = activity.getSupportFragmentManager();
ImageInfo elementInfoFragment = newInstance(uriString);
elementInfoFragment.show(fm, TAG);
} catch (IllegalStateException isex) {
Log.e(DEBUG_TAG, "showDialog", isex);
}
}

/**
* Dismiss the dialog
*
* @param activity the calling Activity
*/
private static void dismissDialog(@NonNull FragmentActivity activity) {
de.blau.android.dialogs.Util.dismissDialog(activity, TAG);
}

/**
* Create a new instance of the FeatureInfo dialog
*
* @param feature Feature to display the info on
*
* @return an instance of ElementInfo
*/
@NonNull
private static ImageInfo newInstance(@NonNull String uriString) {
ImageInfo f = new ImageInfo();

Bundle args = new Bundle();
args.putString(URI_KEY, uriString);

f.setArguments(args);
f.setShowsDialog(true);

return f;
}

@Override
public AppCompatDialog onCreateDialog(Bundle savedInstanceState) {
String uriString = getArguments().getString(URI_KEY);
try {
uri = Uri.parse(uriString);
} catch (Exception e) {
Log.e(DEBUG_TAG, "Unable to parse uri " + uriString);
}
Builder builder = new AlertDialog.Builder(getActivity());
DoNothingListener doNothingListener = new DoNothingListener();
builder.setPositiveButton(R.string.done, doNothingListener);
builder.setTitle(R.string.image_information_title);
builder.setView(createView(null));
return builder.create();
}

@Override
protected View createView(@Nullable ViewGroup container) {
ScrollView sv = createEmptyView(container);
TableLayout tl = (TableLayout) sv.findViewById(R.id.element_info_vertical_layout);
TableLayout.LayoutParams tp = getTableLayoutParams();

if (uri != null) {
tl.setColumnShrinkable(1, true);
try {
FragmentActivity activity = getActivity();
Photo image = new Photo(getContext(), uri, null);
tl.addView(TableLayoutUtils.createRow(activity, ContentResolverUtil.getPath(getContext(), uri), null, tp));
long size = ContentResolverUtil.getSizeColumn(getContext(), uri);
if (size > -1) {
tl.addView(TableLayoutUtils.createRow(activity, R.string.file_size, getString(R.string.file_size_kB, size / 1024), tp));
}
String creator = image.getCreator();
if (creator != null) {
tl.addView(TableLayoutUtils.createRow(activity, R.string.created_by, creator, tp));
}
Long captureDate = image.getCaptureDate();
if (captureDate != null) {
tl.addView(TableLayoutUtils.createRow(activity, R.string.capture_date, dateFormat.format(new Date(captureDate)), tp));
}
tl.addView(TableLayoutUtils.createRow(activity, R.string.location_lon_label, prettyPrintCoord(image.getLon() / 1E7D), tp));
tl.addView(TableLayoutUtils.createRow(activity, R.string.location_lat_label, prettyPrintCoord(image.getLat() / 1E7D), tp));
if (image.hasDirection()) {
tl.addView(TableLayoutUtils.createRow(activity, R.string.direction, String.format(Locale.US, "%3d°", image.getDirection()), tp));
}
} catch (Exception ex) {
Log.e(DEBUG_TAG, "Exception displaying image meta data " + ex.getMessage());
}
}
return sv;
}
}
30 changes: 0 additions & 30 deletions src/main/java/de/blau/android/dialogs/LayerInfo.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package de.blau.android.dialogs;

import android.os.Bundle;
import android.text.Spanned;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ScrollView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AlertDialog.Builder;
import androidx.appcompat.app.AppCompatDialog;
Expand All @@ -16,8 +11,6 @@
import de.blau.android.R;
import de.blau.android.listener.DoNothingListener;
import de.blau.android.util.InfoDialogFragment;
import de.blau.android.util.ThemeUtils;
import de.blau.android.util.Util;

/**
* A generic dialog fragment to display some info on layers
Expand Down Expand Up @@ -65,27 +58,4 @@ public AppCompatDialog onCreateDialog(Bundle savedInstanceState) {
builder.setView(createView(null));
return builder.create();
}

/**
* Create the view we want to display
*
* Classes extending LayerInfo need to override this but call through to the super method to get the view
*
* @param container parent view or null
* @return the View
*/
protected ScrollView createEmptyView(@Nullable ViewGroup container) {
LayoutInflater inflater = ThemeUtils.getLayoutInflater(getActivity());
return (ScrollView) inflater.inflate(R.layout.element_info_view, container, false);
}

/**
* Get the string resource formated as an italic string
*
* @param resId String resource id
* @return a Spanned containing the string
*/
protected Spanned toItalic(int resId) {
return Util.fromHtml("<i>" + getString(resId) + "</i>");
}
}
Loading
Loading