|
16 | 16 | import android.support.design.widget.CoordinatorLayout;
|
17 | 17 | import android.support.design.widget.FloatingActionButton;
|
18 | 18 |
|
| 19 | +import android.util.Log; |
| 20 | +import android.view.Gravity; |
19 | 21 | import android.view.KeyEvent;
|
20 | 22 | import android.view.LayoutInflater;
|
21 | 23 | import android.view.View;
|
@@ -508,22 +510,54 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
|
508 | 510 | }
|
509 | 511 |
|
510 | 512 | private void hideFAB() {
|
511 |
| - //get rid of anchors |
512 |
| - //Somehow this was the only way https://stackoverflow.com/questions/32732932/floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone |
513 |
| - CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fabPlus |
514 |
| - .getLayoutParams(); |
515 |
| - p.setAnchorId(View.NO_ID); |
516 |
| - fabPlus.setLayoutParams(p); |
| 513 | + |
| 514 | + removeAnchorFromFABs(fabPlus); |
517 | 515 | fabPlus.hide();
|
| 516 | + |
| 517 | + removeAnchorFromFABs(fabCamera); |
518 | 518 | fabCamera.hide();
|
| 519 | + |
| 520 | + removeAnchorFromFABs(fabGallery); |
519 | 521 | fabGallery.hide();
|
| 522 | + |
| 523 | + } |
| 524 | + |
| 525 | + /* |
| 526 | + * We are not able to hide FABs without removing anchors, this method removes anchors |
| 527 | + * */ |
| 528 | + private void removeAnchorFromFABs(FloatingActionButton floatingActionButton) { |
| 529 | + //get rid of anchors |
| 530 | + //Somehow this was the only way https://stackoverflow.com/questions/32732932 |
| 531 | + // /floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone |
| 532 | + CoordinatorLayout.LayoutParams param = (CoordinatorLayout.LayoutParams) floatingActionButton |
| 533 | + .getLayoutParams(); |
| 534 | + param.setAnchorId(View.NO_ID); |
| 535 | + // If we don't set them to zero, then they become visible for a moment on upper left side |
| 536 | + param.width = 0; |
| 537 | + param.height = 0; |
| 538 | + floatingActionButton.setLayoutParams(param); |
520 | 539 | }
|
521 | 540 |
|
522 | 541 | private void showFAB() {
|
523 |
| - CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fabPlus.getLayoutParams(); |
524 |
| - p.setAnchorId(getActivity().findViewById(R.id.bottom_sheet_details).getId()); |
525 |
| - fabPlus.setLayoutParams(p); |
| 542 | + |
| 543 | + addAnchorToFABs(fabPlus, getActivity().findViewById(R.id.bottom_sheet_details).getId()); |
526 | 544 | fabPlus.show();
|
| 545 | + |
| 546 | + addAnchorToFABs(fabGallery, getActivity().findViewById(R.id.empty_view).getId()); |
| 547 | + |
| 548 | + addAnchorToFABs(fabCamera, getActivity().findViewById(R.id.empty_view1).getId()); |
| 549 | + |
| 550 | + } |
| 551 | + |
| 552 | + /* |
| 553 | + * Add amnchors back before making them visible again. |
| 554 | + * */ |
| 555 | + private void addAnchorToFABs(FloatingActionButton floatingActionButton, int anchorID) { |
| 556 | + CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams |
| 557 | + (ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); |
| 558 | + params.setAnchorId(anchorID); |
| 559 | + params.anchorGravity = Gravity.TOP|Gravity.RIGHT|Gravity.END; |
| 560 | + floatingActionButton.setLayoutParams(params); |
527 | 561 | }
|
528 | 562 |
|
529 | 563 | private void passInfoToSheet(Place place) {
|
@@ -554,25 +588,28 @@ private void passInfoToSheet(Place place) {
|
554 | 588 | distance.setText(place.distance.toString());
|
555 | 589 |
|
556 | 590 | fabCamera.setOnClickListener(view -> {
|
557 |
| - Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); |
558 |
| - controller = new ContributionController(this); |
| 591 | + if (fabCamera.isShown()) { |
| 592 | + Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); |
| 593 | + controller = new ContributionController(this); |
559 | 594 |
|
560 |
| - DirectUpload directUpload = new DirectUpload(this, controller); |
561 |
| - storeSharedPrefs(); |
562 |
| - directUpload.initiateCameraUpload(); |
| 595 | + DirectUpload directUpload = new DirectUpload(this, controller); |
| 596 | + storeSharedPrefs(); |
| 597 | + directUpload.initiateCameraUpload(); |
| 598 | + } |
563 | 599 | });
|
564 | 600 |
|
565 | 601 | fabGallery.setOnClickListener(view -> {
|
566 |
| - Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); |
567 |
| - controller = new ContributionController(this); |
| 602 | + if (fabGallery.isShown()) { |
| 603 | + Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); |
| 604 | + controller = new ContributionController(this); |
568 | 605 |
|
569 |
| - DirectUpload directUpload = new DirectUpload(this, controller); |
570 |
| - storeSharedPrefs(); |
571 |
| - directUpload.initiateGalleryUpload(); |
572 |
| - |
573 |
| - //TODO: App crashes after image upload completes |
574 |
| - //TODO: Handle onRequestPermissionsResult |
| 606 | + DirectUpload directUpload = new DirectUpload(this, controller); |
| 607 | + storeSharedPrefs(); |
| 608 | + directUpload.initiateGalleryUpload(); |
575 | 609 |
|
| 610 | + //TODO: App crashes after image upload completes |
| 611 | + //TODO: Handle onRequestPermissionsResult |
| 612 | + } |
576 | 613 | });
|
577 | 614 | }
|
578 | 615 |
|
@@ -627,20 +664,22 @@ private void openWebView(Uri link) {
|
627 | 664 | }
|
628 | 665 |
|
629 | 666 | private void animateFAB(boolean isFabOpen) {
|
630 |
| - if (isFabOpen) { |
631 |
| - fabPlus.startAnimation(rotate_backward); |
632 |
| - fabCamera.startAnimation(fab_close); |
633 |
| - fabGallery.startAnimation(fab_close); |
634 |
| - fabCamera.hide(); |
635 |
| - fabGallery.hide(); |
636 |
| - } else { |
637 |
| - fabPlus.startAnimation(rotate_forward); |
638 |
| - fabCamera.startAnimation(fab_open); |
639 |
| - fabGallery.startAnimation(fab_open); |
640 |
| - fabCamera.show(); |
641 |
| - fabGallery.show(); |
| 667 | + if (fabPlus.isShown()){ |
| 668 | + if (isFabOpen) { |
| 669 | + fabPlus.startAnimation(rotate_backward); |
| 670 | + fabCamera.startAnimation(fab_close); |
| 671 | + fabGallery.startAnimation(fab_close); |
| 672 | + fabCamera.hide(); |
| 673 | + fabGallery.hide(); |
| 674 | + } else { |
| 675 | + fabPlus.startAnimation(rotate_forward); |
| 676 | + fabCamera.startAnimation(fab_open); |
| 677 | + fabGallery.startAnimation(fab_open); |
| 678 | + fabCamera.show(); |
| 679 | + fabGallery.show(); |
| 680 | + } |
| 681 | + this.isFabOpen=!isFabOpen; |
642 | 682 | }
|
643 |
| - this.isFabOpen=!isFabOpen; |
644 | 683 | }
|
645 | 684 |
|
646 | 685 | private void closeFabs(boolean isFabOpen){
|
|
0 commit comments