@TargetApi(Build.VERSION_CODES.M) private void initUi() { initializeToolbar(); final AnimatedVectorDrawable avd2 = (AnimatedVectorDrawable) tvButton.getBackground(); tvButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { tvButton.setText("Loading..."); avd2.start(); } }); avd2.registerAnimationCallback(new Animatable2.AnimationCallback() { @Override public void onAnimationEnd(Drawable drawable) { tvButton.setText("Try Again"); } }); }
private void beginAnimation() { if (animId > 0) { anim = AnimationUtils.loadAnimation(getContext(), animId); startAnimation(anim); } if (animatorId > 0) { animator = AnimatorInflater.loadAnimator(getContext(), animatorId); animator.setTarget(this); animator.start(); } Drawable drawable = getDrawable(); if (drawable instanceof Animatable2) { if (callback != null) { ((Animatable2) drawable).registerAnimationCallback(callback); } ((Animatable2) drawable).start(); } }
private void reverse() { Drawable current = getDrawable(); if (current instanceof Animatable2) { ((Animatable2) current).unregisterAnimationCallback(callback); } if (otherDrawable instanceof Animatable2) { ((Animatable2) otherDrawable).registerAnimationCallback(callback); ((Animatable2) otherDrawable).start(); } setImageDrawable(otherDrawable); otherDrawable = current; }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); Drawable drawable = getDrawable(); if (callback != null && drawable instanceof Animatable2) { ((Animatable2) drawable).unregisterAnimationCallback(callback); ((Animatable2) drawable).stop(); } }
@Override public void onMarkerClick() { MovableMarker movableMarker = mMovableMarkerWeakReference.get(); if (movableMarker != null) { movableMarker.morphToStaticForm(); /* After the morph, remove the MarkerGrab */ final MarkerGrab markerGrab = mMarkerGrabWeakReference.get(); markerGrab.morphOut(new Animatable2.AnimationCallback() { @Override public void onAnimationEnd(Drawable drawable) { super.onAnimationEnd(drawable); if (markerGrab != null) { mTileView.removeMarker(markerGrab); } } }); /* The view has been moved, update the associated model object */ MarkerGson.Marker marker = movableMarker.getMarker(); if (mMap.getProjection() == null) { marker.lon = movableMarker.getRelativeX(); marker.lat = movableMarker.getRelativeY(); } else { marker.proj_x = movableMarker.getRelativeX(); marker.proj_y = movableMarker.getRelativeY(); double[] wgs84Coords; wgs84Coords = mMap.getProjection().undoProjection(marker.proj_x, marker.proj_y); if (wgs84Coords != null) { marker.lon = wgs84Coords[0]; marker.lat = wgs84Coords[1]; } } /* Save the changes on the markers.json file */ MapLoader.getInstance().saveMarkers(mMap); } }
public void morphOut(Animatable2.AnimationCallback animationEndCallback) { if (mCurrentDrawable == mInAnimation) { mCurrentDrawable = mOutAnimation; setImageDrawable(mOutAnimation); mOutAnimation.registerAnimationCallback(animationEndCallback); mOutAnimation.start(); } else if (mCurrentDrawable == mOutAnimation) { mOutAnimation.stop(); } }
@CheckResult @NonNull @TargetApi(Build.VERSION_CODES.M) public static Observable<Drawable> starts(Animatable2 animatable2){ checkNotNull(animatable2, "animatable2 == null"); return Observable.create(new Animatable2ListenerOnSubscribe(animatable2, AnimationEvent.START)); }
@CheckResult @NonNull @TargetApi(Build.VERSION_CODES.M) public static Observable<Drawable> ends(Animatable2 animatable2){ checkNotNull(animatable2, "animatable2 == null"); return Observable.create(new Animatable2ListenerOnSubscribe(animatable2, AnimationEvent.END)); }
public static void addListener(AnimatedVectorDrawable drawable, Object callback) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (callback instanceof Animatable2.AnimationCallback) { drawable.registerAnimationCallback((Animatable2.AnimationCallback) callback); } else { throw new IllegalArgumentException("Callback parameter must implement " + Animatable2.AnimationCallback.class.getName()); } } }
public static boolean removeListener(AnimatedVectorDrawable drawable, Object callback) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (callback instanceof Animatable2.AnimationCallback) { return drawable.unregisterAnimationCallback((Animatable2.AnimationCallback) callback); } else { throw new IllegalArgumentException("Callback parameter must implement " + Animatable2.AnimationCallback.class.getName()); } } return true; }
Animatable2ListenerOnSubscribe(Animatable2 animatable2, int eventToCallOn) { this.animatable2 = animatable2; this.eventToCallOn = eventToCallOn; }