back button functionality (#1517)

This commit is contained in:
Tanvi Dadu 2018-06-19 13:36:55 +05:30 committed by Josephine Lim
parent f6c18c6480
commit ac2de1a1fe

View file

@ -25,6 +25,7 @@ import android.support.design.widget.Snackbar;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
@ -137,6 +138,8 @@ public class ShareActivity
private long ShortAnimationDuration;
private boolean isFABOpen = false;
private float startScaleFinal;
private boolean isZoom = false;
/**
* Called when user taps the submit button.
@ -505,6 +508,7 @@ public class ShareActivity
if (CurrentAnimator != null) {
CurrentAnimator.cancel();
}
isZoom = true;
ViewUtil.hideKeyboard(ShareActivity.this.findViewById(R.id.titleEdit | R.id.descEdit));
closeFABMenu();
mainFab.setVisibility(View.GONE);
@ -521,7 +525,6 @@ public class ShareActivity
// Load the high-resolution "zoomed-in" image.
expandedImageView.setImageBitmap(scaledImage);
float startScale = zoomObj.adjustStartEndBounds(startBounds, finalBounds, globalOffset);
// Hide the thumbnail and show the zoomed-in view. When the animation
@ -593,6 +596,7 @@ public class ShareActivity
if (CurrentAnimator != null) {
CurrentAnimator.cancel();
}
isZoom = false;
zoomOutButton.setVisibility(View.GONE);
mainFab.setVisibility(View.VISIBLE);
@ -603,6 +607,7 @@ public class ShareActivity
.with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
set.setDuration(ShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@ -635,4 +640,17 @@ public class ShareActivity
startActivity(mapIntent);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if(isZoom) {
onZoomOutFabClicked();
return true;
}
}
return super.onKeyDown(keyCode,event);
}
}