Skip to content

Commit aca3f0f

Browse files
tanvidaduVivek Maskara
authored and
Vivek Maskara
committed
Open map of place where picture was taken (#1360)
* Intent to map added * Merge conflicts resolved * Added the functionality to hide FAB incase of null coordinate * Merge Conflict resolved * Improve pr quality * Improve Quality * Added nested FAB animations * Nested FAB implemented * Improve Quality * Added up arrow * Javadocs Added
1 parent 539c03b commit aca3f0f

File tree

5 files changed

+135
-6
lines changed

5 files changed

+135
-6
lines changed

app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java

+101-4
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@
8181
import fr.free.nrw.commons.utils.ViewUtil;
8282
import timber.log.Timber;
8383

84-
85-
84+
import android.support.design.widget.FloatingActionButton;
8685
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
8786
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
8887
import static java.lang.Long.min;
@@ -122,6 +121,7 @@ public class ShareActivity
122121
private Uri mediaUri;
123122
private Contribution contribution;
124123
private SimpleDraweeView backgroundImageView;
124+
private FloatingActionButton maps_fragment;
125125

126126
private boolean cacheFound;
127127

@@ -145,6 +145,8 @@ public class ShareActivity
145145
private long ShortAnimationDuration;
146146
private FloatingActionButton zoomInButton;
147147
private FloatingActionButton zoomOutButton;
148+
private FloatingActionButton mainFab;
149+
private boolean isFABOpen = false;
148150

149151

150152
/**
@@ -284,6 +286,24 @@ R.drawable.ic_error_outline_black_24dp, getTheme()))
284286
if (mediaUri != null) {
285287
backgroundImageView.setImageURI(mediaUri);
286288
}
289+
290+
mainFab = (FloatingActionButton) findViewById(R.id.main_fab);
291+
/*
292+
* called when upper arrow floating button
293+
*/
294+
mainFab.setOnClickListener(new View.OnClickListener() {
295+
@Override
296+
public void onClick(View v) {
297+
if(!isFABOpen){
298+
showFABMenu();
299+
}else{
300+
closeFABMenu();
301+
}
302+
}
303+
});
304+
305+
306+
287307
zoomInButton = (FloatingActionButton) findViewById(R.id.media_upload_zoom_in);
288308
try {
289309
zoomInButton.setOnClickListener(new View.OnClickListener() {
@@ -358,8 +378,75 @@ public void onClick(View v) {
358378
.commitAllowingStateLoss();
359379
}
360380
uploadController.prepareService();
381+
maps_fragment = (FloatingActionButton) findViewById(R.id.media_map);
382+
maps_fragment.setVisibility(View.VISIBLE);
383+
if( imageObj == null || imageObj.imageCoordsExists != true){
384+
maps_fragment.setVisibility(View.INVISIBLE);
385+
}
386+
387+
388+
maps_fragment.setOnClickListener(new View.OnClickListener() {
389+
@Override
390+
public void onClick(View v) {
391+
if( imageObj != null && imageObj.imageCoordsExists == true) {
392+
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=" + imageObj.getDecLatitude() + "," + imageObj.getDecLongitude());
393+
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
394+
mapIntent.setPackage("com.google.android.apps.maps");
395+
startActivity(mapIntent);
396+
}
397+
}
398+
});
399+
}
400+
/*
401+
* Function to display the zoom and map FAB
402+
*/
403+
private void showFABMenu(){
404+
isFABOpen=true;
405+
406+
if( imageObj != null && imageObj.imageCoordsExists == true)
407+
maps_fragment.setVisibility(View.VISIBLE);
408+
zoomInButton.setVisibility(View.VISIBLE);
409+
410+
mainFab.animate().rotationBy(180);
411+
maps_fragment.animate().translationY(-getResources().getDimension(R.dimen.second_fab));
412+
zoomInButton.animate().translationY(-getResources().getDimension(R.dimen.first_fab));
413+
}
414+
415+
/*
416+
* function to close the zoom and map FAB
417+
*/
418+
private void closeFABMenu(){
419+
isFABOpen=false;
420+
mainFab.animate().rotationBy(-180);
421+
maps_fragment.animate().translationY(0);
422+
zoomInButton.animate().translationY(0).setListener(new Animator.AnimatorListener() {
423+
@Override
424+
public void onAnimationStart(Animator animator) {
425+
426+
}
427+
428+
@Override
429+
public void onAnimationEnd(Animator animator) {
430+
if(!isFABOpen){
431+
maps_fragment.setVisibility(View.GONE);
432+
zoomInButton.setVisibility(View.GONE);
433+
}
434+
435+
}
436+
437+
@Override
438+
public void onAnimationCancel(Animator animator) {
439+
440+
}
441+
442+
@Override
443+
public void onAnimationRepeat(Animator animator) {
444+
445+
}
446+
});
361447
}
362448

449+
363450
@Override
364451
public void onRequestPermissionsResult(int requestCode,
365452
@NonNull String[] permissions, @NonNull int[] grantResults) {
@@ -461,6 +548,9 @@ private void performUnwantedPictureDetectionProcess() {
461548
detectUnwantedPicturesAsync.execute();
462549
}
463550

551+
/*
552+
* to display permission snackbar in share activity
553+
*/
464554
private Snackbar requestPermissionUsingSnackBar(String rationale,
465555
final String[] perms,
466556
final int code) {
@@ -693,7 +783,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
693783
return super.onOptionsItemSelected(item);
694784
}
695785

696-
// Get SHA1 of file from input stream
786+
/*
787+
* Get SHA1 of file from input stream
788+
*/
697789
private String getSHA1(InputStream is) {
698790

699791
MessageDigest digest;
@@ -730,13 +822,18 @@ private String getSHA1(InputStream is) {
730822
}
731823
}
732824

825+
/*
826+
* function to provide pinch zoom
827+
*/
733828
private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
734829
// If there's an animation in progress, cancel it
735830
// immediately and proceed with this one.
736831
if (CurrentAnimator != null) {
737832
CurrentAnimator.cancel();
738833
}
739834
ViewUtil.hideKeyboard(ShareActivity.this.findViewById(R.id.titleEdit | R.id.descEdit));
835+
closeFABMenu();
836+
mainFab.setVisibility(View.GONE);
740837
InputStream input = null;
741838
Bitmap scaled = null;
742839
try {
@@ -866,7 +963,7 @@ public void onClick(View view) {
866963
CurrentAnimator.cancel();
867964
}
868965
zoomOutButton.setVisibility(View.GONE);
869-
zoomInButton.setVisibility(View.VISIBLE);
966+
mainFab.setVisibility(View.VISIBLE);
870967

871968
// Animate the four positioning/sizing properties in parallel,
872969
// back to their original values.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FFFFFF"
2+
android:viewportHeight="24.0" android:viewportWidth="24.0"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#FF000000" android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
5+
</vector>

app/src/main/res/layout/activity_share.xml

+25-2
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,28 @@
4141

4242
</FrameLayout>
4343

44-
45-
4644
<android.support.design.widget.FloatingActionButton
4745
android:layout_width="wrap_content"
4846
android:layout_height="wrap_content"
4947
android:layout_alignParentRight="true"
5048
android:layout_alignParentBottom="true"
5149
android:layout_marginRight="@dimen/standard_gap"
5250
android:layout_marginBottom="@dimen/standard_gap"
51+
app:backgroundTint="@color/button_blue"
52+
app:srcCompat="@drawable/ic_keyboard_arrow_up_black_24dp"
53+
android:id="@+id/main_fab"/>
54+
55+
56+
<android.support.design.widget.FloatingActionButton
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
android:layout_alignParentRight="true"
60+
android:visibility="gone"
61+
android:layout_marginRight="@dimen/standard_gap"
5362
android:src="@drawable/ic_zoom_in_white_24dp"
63+
android:layout_above="@+id/main_fab"
5464
android:id="@+id/media_upload_zoom_in"/>
65+
5566
<android.support.design.widget.FloatingActionButton
5667
android:layout_width="wrap_content"
5768
android:layout_height="wrap_content"
@@ -61,7 +72,19 @@
6172
android:layout_marginRight="@dimen/standard_gap"
6273
android:layout_marginBottom="@dimen/standard_gap"
6374
android:src="@drawable/ic_zoom_out_white_24dp"
75+
android:layout_above="@+id/main_fab"
6476
android:id="@+id/media_upload_zoom_out"/>
77+
78+
<android.support.design.widget.FloatingActionButton
79+
android:layout_width="wrap_content"
80+
android:layout_height="wrap_content"
81+
android:layout_alignParentRight="true"
82+
android:layout_above="@+id/media_upload_zoom_in"
83+
android:visibility="gone"
84+
android:layout_marginRight="@dimen/standard_gap"
85+
app:srcCompat="@drawable/ic_map_white_24dp"
86+
android:id="@+id/media_map"/>
87+
6588
</RelativeLayout>
6689

6790
<android.support.design.widget.NavigationView

app/src/main/res/values/dimens.xml

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
<dimen name="subheading_text_size">20sp</dimen>
2424
<dimen name="normal_text">16sp</dimen>
2525
<dimen name="description_text_size">14sp</dimen>
26+
<dimen name="first_fab">15dp</dimen>
27+
<dimen name="second_fab">25dp</dimen>
2628
</resources>

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,6 @@
275275
<string name="error_loading_images">Error occurred while loading images.</string>
276276
<string name="image_uploaded_by">Uploaded by: %1$s</string>
277277
<string name="share_app_title">Share App</string>
278+
<string name="share_coordinates_not_present">Coordinates were not specified during image selection</string>
279+
278280
</resources>

0 commit comments

Comments
 (0)