0

I am trying to achieve this loading with Maps. I have tried loading my animation after the Google Map is created and location is found. But the location loading starts after the animation is completed. How can I achieve the reveal animation after the map camera has navigated to the user's location.

I am trying to achieve this loading with Maps

I am not using Splash Screen. The animation code is within the MapsActivity.

private void setupRevealBackground(){
        final int revealX = (int) (mBackgroundView.getX() + mBackgroundView.getWidth() / 2);
        final int revealY = (int) (mBackgroundView.getY() + mBackgroundView.getHeight() / 2);
        ViewTreeObserver viewTreeObserver = mBackgroundView.getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    revealActivity(revealX, revealY);
                    mBackgroundView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                }
            });
        }
    }

    protected void revealActivity(int x, int y) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            float finalRadius = (float) (Math.max(mBackgroundView.getWidth(), mBackgroundView.getHeight()) * 1.1);

            // create the animator for this view (the start radius is zero)
            Animator circularReveal = ViewAnimationUtils.createCircularReveal(mBackgroundView, x, y, 0, finalRadius);
            circularReveal.setDuration(400);
            circularReveal.setInterpolator(new AccelerateInterpolator());

            // make the view visible and start the animation
            circularReveal.start();
            circularReveal.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    mBackgroundView.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
        } else {
            finish();
        }
    }

I am updating the location after the location is found Preference Change Listener.

@Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key.equals(Constants.LatitudePref)) {
            Latitude = LocationResultHelper.getSavedLatitude(sharedPreferences);
            Longitude = LocationResultHelper.getSavedLongitude(sharedPreferences);
            if (mPickUpLatLng == null){
                updateMarker(new LatLng(Latitude, Longitude));
            }
        } else if (key.equals(Constants.KEY_LOCATION_UPDATES_REQUESTED)) {
            LocationRequestHelper.getRequesting(this);
        }
    }

This is my updateMarker Method after location is found

private void updateMarker(LatLng userLocation) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 16));
        setupRevealBackground();
     }

I have tried adding setupRevealBackground() method in the CameraIdleListener but the method is never called.

ColdFire
  • 6,764
  • 6
  • 35
  • 51
Sagar Atalatti
  • 486
  • 1
  • 8
  • 21

1 Answers1

0

As indicated in this answer you can use OnMapLoadedCallback

When you have a reference to the map set the call back.

mMap.setOnMapLoadedCallback(this);

When the onMapLoaded event fires take the snapshot.

@Override
public void onMapLoaded() {
    // Here you can display your map with animation
}
ColdFire
  • 6,764
  • 6
  • 35
  • 51