88import android .animation .ObjectAnimator ;
99import android .content .ContentResolver ;
1010import android .content .Context ;
11- import android .content .DialogInterface ;
1211import android .content .Intent ;
1312import android .content .SharedPreferences ;
1413import android .content .pm .PackageManager ;
3231import android .support .v4 .app .FragmentManager ;
3332import android .support .v4 .content .ContextCompat ;
3433import android .support .v4 .graphics .BitmapCompat ;
35- import android .support .v7 .app .AlertDialog ;
3634import android .util .Log ;
3735import android .view .MenuItem ;
3836import android .view .View ;
39- import android .view .WindowManager ;
4037import android .view .animation .DecelerateInterpolator ;
41- import android .view . inputmethod . InputMethodManager ;
38+ import android .widget . FrameLayout ;
4239import android .widget .TextView ;
4340import android .widget .Toast ;
4441
42+ import butterknife .BindView ;
43+ import butterknife .OnClick ;
4544import com .facebook .drawee .generic .GenericDraweeHierarchyBuilder ;
4645import com .facebook .drawee .view .SimpleDraweeView ;
4746import com .github .chrisbanes .photoview .PhotoView ;
6968import fr .free .nrw .commons .category .CategorizationFragment ;
7069import fr .free .nrw .commons .category .OnCategoriesSaveHandler ;
7170import fr .free .nrw .commons .contributions .Contribution ;
72- import fr .free .nrw .commons .contributions .ContributionsActivity ;
7371import fr .free .nrw .commons .modifications .CategoryModifier ;
7472import fr .free .nrw .commons .modifications .ModificationsContentProvider ;
7573import fr .free .nrw .commons .modifications .ModifierSequence ;
7674import fr .free .nrw .commons .modifications .ModifierSequenceDao ;
7775import fr .free .nrw .commons .modifications .TemplateRemoveModifier ;
7876
79- import fr .free .nrw .commons .utils .ImageUtils ;
8077import fr .free .nrw .commons .mwapi .MediaWikiApi ;
8178import fr .free .nrw .commons .utils .ViewUtil ;
8279import timber .log .Timber ;
8380
84- import android .support .design .widget .FloatingActionButton ;
8581import static fr .free .nrw .commons .upload .ExistingFileAsync .Result .DUPLICATE_PROCEED ;
8682import static fr .free .nrw .commons .upload .ExistingFileAsync .Result .NO_DUPLICATE ;
87- import static java .lang .Long .min ;
8883
8984/**
9085 * Activity for the title/desc screen after image is selected. Also starts processing image
@@ -95,6 +90,22 @@ public class ShareActivity
9590 implements SingleUploadFragment .OnUploadActionInitiated ,
9691 OnCategoriesSaveHandler ,SimilarImageDialogFragment .onResponse {
9792
93+ @ BindView (R .id .container )
94+ FrameLayout flContainer ;
95+ @ BindView (R .id .backgroundImage )
96+ SimpleDraweeView backgroundImageView ;
97+ @ BindView (R .id .media_map )
98+ FloatingActionButton mapsFragment ; //Lets stick to camelCase
99+ @ BindView (R .id .media_upload_zoom_in )
100+ FloatingActionButton zoomInButton ;
101+ @ BindView (R .id .media_upload_zoom_out )
102+ FloatingActionButton zoomOutButton ;
103+ @ BindView (R .id .main_fab )
104+ FloatingActionButton mainFab ;
105+ @ BindView (R .id .expanded_image )
106+ PhotoView expandedImageView ;
107+
108+
98109 private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1 ;
99110 private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2 ;
100111 private static final int REQUEST_PERM_ON_CREATE_STORAGE_AND_LOCATION = 3 ;
@@ -120,9 +131,6 @@ public class ShareActivity
120131
121132 private Uri mediaUri ;
122133 private Contribution contribution ;
123- private SimpleDraweeView backgroundImageView ;
124- private FloatingActionButton maps_fragment ;
125-
126134 private boolean cacheFound ;
127135
128136 private GPSExtractor imageObj ;
@@ -143,11 +151,14 @@ public class ShareActivity
143151
144152 private Animator CurrentAnimator ;
145153 private long ShortAnimationDuration ;
146- private FloatingActionButton zoomInButton ;
147- private FloatingActionButton zoomOutButton ;
148- private FloatingActionButton mainFab ;
149154 private boolean isFABOpen = false ;
150155
156+ //Had to make them class variables, to extract out the click listeners, also I see no harm in this
157+ final Rect startBounds = new Rect ();
158+ final Rect finalBounds = new Rect ();
159+ final Point globalOffset = new Point ();
160+ private float startScaleFinal ;
161+
151162
152163 /**
153164 * Called when user taps the submit button.
@@ -257,7 +268,6 @@ public void onCreate(Bundle savedInstanceState) {
257268 setContentView (R .layout .activity_share );
258269 ButterKnife .bind (this );
259270 initBack ();
260- backgroundImageView = (SimpleDraweeView ) findViewById (R .id .backgroundImage );
261271 backgroundImageView .setHierarchy (GenericDraweeHierarchyBuilder
262272 .newInstance (getResources ())
263273 .setPlaceholderImage (VectorDrawableCompat .create (getResources (),
@@ -286,37 +296,6 @@ R.drawable.ic_error_outline_black_24dp, getTheme()))
286296 if (mediaUri != null ) {
287297 backgroundImageView .setImageURI (mediaUri );
288298 }
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-
307- zoomInButton = (FloatingActionButton ) findViewById (R .id .media_upload_zoom_in );
308- try {
309- zoomInButton .setOnClickListener (new View .OnClickListener () {
310- @ Override
311- public void onClick (View v ) {
312- zoomImageFromThumb (backgroundImageView , mediaUri );
313- }
314- });
315- } catch (Exception e ){
316- Log .i ("exception" , e .toString ());
317- }
318- zoomOutButton = (FloatingActionButton ) findViewById (R .id .media_upload_zoom_out );
319-
320299 if (savedInstanceState != null ) {
321300 contribution = savedInstanceState .getParcelable ("contribution" );
322301 }
@@ -378,37 +357,25 @@ public void onClick(View v) {
378357 .commitAllowingStateLoss ();
379358 }
380359 uploadController .prepareService ();
381- maps_fragment = (FloatingActionButton ) findViewById (R .id .media_map );
382- maps_fragment .setVisibility (View .VISIBLE );
360+ mapsFragment .setVisibility (View .VISIBLE );
383361 if ( imageObj == null || imageObj .imageCoordsExists != true ){
384- maps_fragment .setVisibility (View .INVISIBLE );
362+ mapsFragment .setVisibility (View .INVISIBLE );
385363 }
386364
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- });
399365 }
366+
400367 /*
401368 * Function to display the zoom and map FAB
402369 */
403370 private void showFABMenu (){
404371 isFABOpen =true ;
405372
406373 if ( imageObj != null && imageObj .imageCoordsExists == true )
407- maps_fragment .setVisibility (View .VISIBLE );
374+ mapsFragment .setVisibility (View .VISIBLE );
408375 zoomInButton .setVisibility (View .VISIBLE );
409376
410377 mainFab .animate ().rotationBy (180 );
411- maps_fragment .animate ().translationY (-getResources ().getDimension (R .dimen .second_fab ));
378+ mapsFragment .animate ().translationY (-getResources ().getDimension (R .dimen .second_fab ));
412379 zoomInButton .animate ().translationY (-getResources ().getDimension (R .dimen .first_fab ));
413380 }
414381
@@ -418,7 +385,7 @@ private void showFABMenu(){
418385 private void closeFABMenu (){
419386 isFABOpen =false ;
420387 mainFab .animate ().rotationBy (-180 );
421- maps_fragment .animate ().translationY (0 );
388+ mapsFragment .animate ().translationY (0 );
422389 zoomInButton .animate ().translationY (0 ).setListener (new Animator .AnimatorListener () {
423390 @ Override
424391 public void onAnimationStart (Animator animator ) {
@@ -428,7 +395,7 @@ public void onAnimationStart(Animator animator) {
428395 @ Override
429396 public void onAnimationEnd (Animator animator ) {
430397 if (!isFABOpen ){
431- maps_fragment .setVisibility (View .GONE );
398+ mapsFragment .setVisibility (View .GONE );
432399 zoomInButton .setVisibility (View .GONE );
433400 }
434401
@@ -700,8 +667,9 @@ private void findOtherImages(boolean gpsEnabled) {
700667 return ;
701668 }
702669
670+ //I might not be supposed to change it, but still, I saw it
703671 @ Override
704- public void onPostiveResponse () {
672+ public void onPositiveResponse () {
705673 imageObj = tempImageObj ;
706674 decimalCoords = imageObj .getCoords (false );// Not necessary to use gps as image already ha EXIF data
707675 Timber .d ("EXIF from tempImageObj" );
@@ -865,26 +833,19 @@ private void zoomImageFromThumb(final View thumbView, Uri imageuri ) {
865833 scaled = bitmap ;
866834 }
867835 // Load the high-resolution "zoomed-in" image.
868- PhotoView expandedImageView = (PhotoView ) findViewById (
869- R .id .expanded_image );
870836 expandedImageView .setImageBitmap (scaled );
871837
872838
873-
839+
874840 // Calculate the starting and ending bounds for the zoomed-in image.
875841 // 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 ();
879-
880842 // The start bounds are the global visible rectangle of the thumbnail,
881843 // and the final bounds are the global visible rectangle of the container
882844 // view. Also set the container view's offset as the origin for the
883845 // bounds, since that's the origin for the positioning animation
884846 // properties (X, Y).
885847 thumbView .getGlobalVisibleRect (startBounds );
886- findViewById (R .id .container )
887- .getGlobalVisibleRect (finalBounds , globalOffset );
848+ flContainer .getGlobalVisibleRect (finalBounds , globalOffset );
888849 startBounds .offset (-globalOffset .x , -globalOffset .y );
889850 finalBounds .offset (-globalOffset .x , -globalOffset .y );
890851
@@ -955,53 +916,86 @@ public void onAnimationCancel(Animator animation) {
955916 // Upon clicking the zoomed-in image, it should zoom back down
956917 // to the original bounds and show the thumbnail instead of
957918 // the expanded image.
958- final float startScaleFinal = startScale ;
959- zoomOutButton .setOnClickListener (new View .OnClickListener () {
960- @ Override
961- public void onClick (View view ) {
962- if (CurrentAnimator != null ) {
963- CurrentAnimator .cancel ();
964- }
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- }
919+ startScaleFinal = startScale ;
991920
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 ;
921+ }
922+
923+ /*
924+ * called when upper arrow floating button
925+ */
926+ @ OnClick (R .id .main_fab )
927+ public void onMainFabClicked () {
928+ if (!isFABOpen ) {
929+ showFABMenu ();
930+ } else {
931+ closeFABMenu ();
932+ }
933+ }
934+
935+ @ OnClick (R .id .media_upload_zoom_in )
936+ public void onZoomInFabClicked () {
937+ //This try catch block was originally holding the entire click listener on the fab button, I did not wanted to risk exceptions
938+ try {
939+ zoomImageFromThumb (backgroundImageView , mediaUri );
940+ } catch (Exception e ) {
941+ Log .i ("exception" , e .toString ());
942+ }
943+ }
944+
945+ @ OnClick (R .id .media_upload_zoom_out )
946+ public void onZoomOutFabClicked () {
947+ if (CurrentAnimator != null ) {
948+ CurrentAnimator .cancel ();
949+ }
950+ zoomOutButton .setVisibility (View .GONE );
951+ mainFab .setVisibility (View .VISIBLE );
1001952
953+ // Animate the four positioning/sizing properties in parallel,
954+ // back to their original values.
955+ AnimatorSet set = new AnimatorSet ();
956+ set .play (ObjectAnimator
957+ .ofFloat (expandedImageView , View .X , startBounds .left ))
958+ .with (ObjectAnimator
959+ .ofFloat (expandedImageView ,
960+ View .Y , startBounds .top ))
961+ .with (ObjectAnimator
962+ .ofFloat (expandedImageView ,
963+ View .SCALE_X , startScaleFinal ))
964+ .with (ObjectAnimator
965+ .ofFloat (expandedImageView ,
966+ View .SCALE_Y , startScaleFinal ));
967+ set .setDuration (ShortAnimationDuration );
968+ set .setInterpolator (new DecelerateInterpolator ());
969+ set .addListener (new AnimatorListenerAdapter () {
970+ @ Override
971+ public void onAnimationEnd (Animator animation ) {
972+ //background image view is thumbView
973+ backgroundImageView .setAlpha (1f );
974+ expandedImageView .setVisibility (View .GONE );
975+ CurrentAnimator = null ;
1002976 }
1003977
978+ @ Override
979+ public void onAnimationCancel (Animator animation ) {
980+ //background image view is thumbView
981+ backgroundImageView .setAlpha (1f );
982+ expandedImageView .setVisibility (View .GONE );
983+ CurrentAnimator = null ;
984+ }
1004985 });
986+ set .start ();
987+ CurrentAnimator = set ;
1005988 }
1006989
990+ @ OnClick (R .id .media_map )
991+ public void onFabShowMapsClicked () {
992+ if (imageObj != null && imageObj .imageCoordsExists == true ) {
993+ Uri gmmIntentUri = Uri
994+ .parse ("google.streetview:cbll=" + imageObj .getDecLatitude () + "," + imageObj
995+ .getDecLongitude ());
996+ Intent mapIntent = new Intent (Intent .ACTION_VIEW , gmmIntentUri );
997+ mapIntent .setPackage ("com.google.android.apps.maps" );
998+ startActivity (mapIntent );
999+ }
1000+ }
10071001}
0 commit comments