forked from upstream-mirrors/OpenTracks
Fixes NPE on MarkerEditActivity when taking a photo and trigger an orientation change. (#327)
Fixes #325.
This commit is contained in:
@@ -29,7 +29,6 @@ import android.util.Pair;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -59,6 +58,8 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||||
|
|
||||||
|
private static final String BUNDLE_PHOTO_URI = "photo_uri";
|
||||||
|
|
||||||
private static final int CAMERA_REQUEST_CODE = 5;
|
private static final int CAMERA_REQUEST_CODE = 5;
|
||||||
private static final int GALLERY_IMG_REQUEST_CODE = 7;
|
private static final int GALLERY_IMG_REQUEST_CODE = 7;
|
||||||
|
|
||||||
@@ -83,15 +84,19 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
private Button done;
|
private Button done;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle bundle) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||||
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
|
markerId = getIntent().getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(null);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection();
|
||||||
|
|
||||||
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
||||||
|
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
photoUri = savedInstanceState.getParcelable(BUNDLE_PHOTO_URI);
|
||||||
|
}
|
||||||
|
|
||||||
// Setup UI elements
|
// Setup UI elements
|
||||||
waypointName = findViewById(R.id.marker_edit_waypoint_name);
|
waypointName = findViewById(R.id.marker_edit_waypoint_name);
|
||||||
waypointMarkerType = findViewById(R.id.marker_edit_waypoint_marker_type);
|
waypointMarkerType = findViewById(R.id.marker_edit_waypoint_marker_type);
|
||||||
@@ -101,24 +106,17 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
waypointPhoto = findViewById(R.id.marker_edit_waypoint_photo);
|
waypointPhoto = findViewById(R.id.marker_edit_waypoint_photo);
|
||||||
|
|
||||||
waypointDeletePhotoBtn = findViewById(R.id.marker_edit_waypoint_photo_delete);
|
waypointDeletePhotoBtn = findViewById(R.id.marker_edit_waypoint_photo_delete);
|
||||||
waypointDeletePhotoBtn.setOnClickListener(new OnClickListener() {
|
waypointDeletePhotoBtn.setOnClickListener(v -> {
|
||||||
@Override
|
if (waypoint != null && waypoint.hasPhoto()) {
|
||||||
public void onClick(View v) {
|
waypoint.setPhotoUrl(null);
|
||||||
if (waypoint != null && waypoint.hasPhoto())
|
|
||||||
waypoint.setPhotoUrl(null);
|
|
||||||
waypointPhoto.setImageBitmap(null);
|
|
||||||
photoUri = null;
|
|
||||||
hideAndShowOptions();
|
|
||||||
}
|
}
|
||||||
|
waypointPhoto.setImageBitmap(null);
|
||||||
|
photoUri = null;
|
||||||
|
hideAndShowOptions();
|
||||||
});
|
});
|
||||||
|
|
||||||
Button cancel = findViewById(R.id.marker_edit_cancel);
|
Button cancel = findViewById(R.id.marker_edit_cancel);
|
||||||
cancel.setOnClickListener(new OnClickListener() {
|
cancel.setOnClickListener(v -> finish());
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
done = findViewById(R.id.marker_edit_done);
|
done = findViewById(R.id.marker_edit_done);
|
||||||
updateUiByMarkerId();
|
updateUiByMarkerId();
|
||||||
}
|
}
|
||||||
@@ -129,6 +127,12 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
trackRecordingServiceConnection.startConnection(this);
|
trackRecordingServiceConnection.startConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putParcelable(BUNDLE_PHOTO_URI, photoUri);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
@@ -272,13 +276,13 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
*
|
*
|
||||||
* @param uri the uri photo.
|
* @param uri the uri photo.
|
||||||
*/
|
*/
|
||||||
private void setWaypointImageView(Uri uri) {
|
private void setWaypointImageView(@NonNull Uri uri) {
|
||||||
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r")) {
|
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "r")) {
|
||||||
FileDescriptor fd = pfd.getFileDescriptor();
|
FileDescriptor fd = pfd.getFileDescriptor();
|
||||||
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
|
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fd);
|
||||||
waypointPhoto.setImageBitmap(bitmap);
|
waypointPhoto.setImageBitmap(bitmap);
|
||||||
hideAndShowOptions();
|
hideAndShowOptions();
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, e.getMessage());
|
Log.e(TAG, e.getMessage());
|
||||||
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
@@ -295,9 +299,6 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
startActivityForResult(intent, GALLERY_IMG_REQUEST_CODE);
|
startActivityForResult(intent, GALLERY_IMG_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a marker.
|
|
||||||
*/
|
|
||||||
private void addMarker() {
|
private void addMarker() {
|
||||||
trackRecordingServiceConnection.addMarker(this,
|
trackRecordingServiceConnection.addMarker(this,
|
||||||
waypointName.getText().toString(),
|
waypointName.getText().toString(),
|
||||||
@@ -306,9 +307,6 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
photoUri != null ? photoUri.toString() : null);
|
photoUri != null ? photoUri.toString() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves a marker.
|
|
||||||
*/
|
|
||||||
private void saveMarker() {
|
private void saveMarker() {
|
||||||
waypoint.setName(waypointName.getText().toString());
|
waypoint.setName(waypointName.getText().toString());
|
||||||
waypoint.setCategory(waypointMarkerType.getText().toString());
|
waypoint.setCategory(waypointMarkerType.getText().toString());
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public final class Waypoint {
|
|||||||
private double length = 0.0;
|
private double length = 0.0;
|
||||||
private long duration = 0;
|
private long duration = 0;
|
||||||
private Location location;
|
private Location location;
|
||||||
|
@Deprecated //TODO Make an URI instead of String
|
||||||
private String photoUrl = "";
|
private String photoUrl = "";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
Reference in New Issue
Block a user