34
34
import android .support .v4 .graphics .BitmapCompat ;
35
35
import android .support .v7 .app .AlertDialog ;
36
36
import android .util .Log ;
37
+ import android .view .KeyEvent ;
37
38
import android .view .MenuItem ;
38
39
import android .view .View ;
39
40
import android .view .WindowManager ;
40
41
import android .view .animation .DecelerateInterpolator ;
41
42
import android .view .inputmethod .InputMethodManager ;
43
+ import android .widget .ImageView ;
42
44
import android .widget .TextView ;
43
45
import android .widget .Toast ;
44
46
@@ -146,8 +148,13 @@ public class ShareActivity
146
148
private FloatingActionButton zoomInButton ;
147
149
private FloatingActionButton zoomOutButton ;
148
150
private FloatingActionButton mainFab ;
151
+ private PhotoView expandedImageView ;
149
152
private boolean isFABOpen = false ;
150
-
153
+ private Rect startBounds = new Rect ();
154
+ private Rect finalBounds = new Rect ();
155
+ private Point globalOffset = new Point ();
156
+ private float startScale ;
157
+ private boolean isZoom = false ;
151
158
152
159
/**
153
160
* Called when user taps the submit button.
@@ -783,6 +790,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
783
790
return super .onOptionsItemSelected (item );
784
791
}
785
792
793
+
794
+
786
795
/*
787
796
* Get SHA1 of file from input stream
788
797
*/
@@ -831,6 +840,7 @@ private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
831
840
if (CurrentAnimator != null ) {
832
841
CurrentAnimator .cancel ();
833
842
}
843
+ isZoom = true ;
834
844
ViewUtil .hideKeyboard (ShareActivity .this .findViewById (R .id .titleEdit | R .id .descEdit ));
835
845
closeFABMenu ();
836
846
mainFab .setVisibility (View .GONE );
@@ -865,17 +875,17 @@ private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
865
875
scaled = bitmap ;
866
876
}
867
877
// Load the high-resolution "zoomed-in" image.
868
- PhotoView expandedImageView = (PhotoView ) findViewById (
878
+ expandedImageView = (PhotoView ) findViewById (
869
879
R .id .expanded_image );
870
880
expandedImageView .setImageBitmap (scaled );
871
881
872
882
873
883
874
884
// Calculate the starting and ending bounds for the zoomed-in image.
875
- // This step involves lots of math. Yay, math.
876
- final Rect startBounds = new Rect ();
877
- final Rect finalBounds = new Rect ();
878
- final Point globalOffset = new Point ();
885
+ // This step involves lots of math.
886
+ startBounds = new Rect ();
887
+ finalBounds = new Rect ();
888
+ globalOffset = new Point ();
879
889
880
890
// The start bounds are the global visible rectangle of the thumbnail,
881
891
// and the final bounds are the global visible rectangle of the container
@@ -892,7 +902,7 @@ private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
892
902
// bounds using the "center crop" technique. This prevents undesirable
893
903
// stretching during the animation. Also calculate the start scaling
894
904
// factor (the end scaling factor is always 1.0).
895
- float startScale ;
905
+
896
906
if ((float ) finalBounds .width () / finalBounds .height ()
897
907
> (float ) startBounds .width () / startBounds .height ()) {
898
908
// Extend start bounds horizontally
@@ -962,46 +972,66 @@ public void onClick(View view) {
962
972
if (CurrentAnimator != null ) {
963
973
CurrentAnimator .cancel ();
964
974
}
965
- zoomOutButton .setVisibility (View .GONE );
966
- mainFab .setVisibility (View .VISIBLE );
967
-
968
- // Animate the four positioning/sizing properties in parallel,
969
- // back to their original values.
970
- AnimatorSet set = new AnimatorSet ();
971
- set .play (ObjectAnimator
972
- .ofFloat (expandedImageView , View .X , startBounds .left ))
973
- .with (ObjectAnimator
974
- .ofFloat (expandedImageView ,
975
- View .Y ,startBounds .top ))
976
- .with (ObjectAnimator
977
- .ofFloat (expandedImageView ,
978
- View .SCALE_X , startScaleFinal ))
979
- .with (ObjectAnimator
980
- .ofFloat (expandedImageView ,
981
- View .SCALE_Y , startScaleFinal ));
982
- set .setDuration (ShortAnimationDuration );
983
- set .setInterpolator (new DecelerateInterpolator ());
984
- set .addListener (new AnimatorListenerAdapter () {
985
- @ Override
986
- public void onAnimationEnd (Animator animation ) {
987
- thumbView .setAlpha (1f );
988
- expandedImageView .setVisibility (View .GONE );
989
- CurrentAnimator = null ;
990
- }
975
+ zoomOut (thumbView ,startScaleFinal ,startBounds );
991
976
992
- @ Override
993
- public void onAnimationCancel (Animator animation ) {
994
- thumbView .setAlpha (1f );
995
- expandedImageView .setVisibility (View .GONE );
996
- CurrentAnimator = null ;
997
- }
998
- });
999
- set .start ();
1000
- CurrentAnimator = set ;
977
+ }
978
+
979
+ });
980
+ }
981
+
982
+ @ Override
983
+ public boolean onKeyDown (int keyCode , KeyEvent event ) {
984
+ switch (keyCode ) {
985
+ case KeyEvent .KEYCODE_BACK :
986
+ if (isZoom ) {
987
+ zoomOut (backgroundImageView , startScale , startBounds );
988
+ return true ;
989
+ }
990
+ }
991
+ return super .onKeyDown (keyCode ,event );
992
+
993
+ }
1001
994
995
+ void zoomOut (View thumbView , float startScaleFinal ,Rect startBounds ){
996
+ zoomOutButton .setVisibility (View .GONE );
997
+ mainFab .setVisibility (View .VISIBLE );
998
+ isZoom = false ;
999
+
1000
+ // Animate the four positioning/sizing properties in parallel,
1001
+ // back to their original values.
1002
+ AnimatorSet set = new AnimatorSet ();
1003
+ set .play (ObjectAnimator
1004
+ .ofFloat (expandedImageView , View .X , startBounds .left ))
1005
+ .with (ObjectAnimator
1006
+ .ofFloat (expandedImageView ,
1007
+ View .Y ,startBounds .top ))
1008
+ .with (ObjectAnimator
1009
+ .ofFloat (expandedImageView ,
1010
+ View .SCALE_X , startScaleFinal ))
1011
+ .with (ObjectAnimator
1012
+ .ofFloat (expandedImageView ,
1013
+ View .SCALE_Y , startScaleFinal ));
1014
+ set .setDuration (ShortAnimationDuration );
1015
+ set .setInterpolator (new DecelerateInterpolator ());
1016
+ set .addListener (new AnimatorListenerAdapter () {
1017
+ @ Override
1018
+ public void onAnimationEnd (Animator animation ) {
1019
+ thumbView .setAlpha (1f );
1020
+ expandedImageView .setVisibility (View .GONE );
1021
+ CurrentAnimator = null ;
1002
1022
}
1003
1023
1024
+ @ Override
1025
+ public void onAnimationCancel (Animator animation ) {
1026
+ thumbView .setAlpha (1f );
1027
+ expandedImageView .setVisibility (View .GONE );
1028
+ CurrentAnimator = null ;
1029
+ }
1004
1030
});
1031
+ set .start ();
1032
+ CurrentAnimator = set ;
1005
1033
}
1006
1034
1035
+
1036
+
1007
1037
}
0 commit comments