Java 类android.graphics.drawable.Animatable2 实例源码

项目:betterHotels    文件:NoHotelsActivity.java   
@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");
        }
    });

}
项目:PresenterLite    文件:AnimatedImageView.java   
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();
    }
}
项目:betterHotels    文件:NoHotelsActivity.java   
@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");
        }
    });

}
项目:PresenterLite    文件:AnimatedImageView.java   
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;
}
项目:PresenterLite    文件:AnimatedImageView.java   
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    Drawable drawable = getDrawable();
    if (callback != null && drawable instanceof Animatable2) {
        ((Animatable2) drawable).unregisterAnimationCallback(callback);
        ((Animatable2) drawable).stop();
    }
}
项目:TrekAdvisor    文件:MarkerLayer.java   
@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);
    }
}
项目:TrekAdvisor    文件:MarkerGrab.java   
public void morphOut(Animatable2.AnimationCallback animationEndCallback) {
    if (mCurrentDrawable == mInAnimation) {
        mCurrentDrawable = mOutAnimation;
        setImageDrawable(mOutAnimation);
        mOutAnimation.registerAnimationCallback(animationEndCallback);
        mOutAnimation.start();

    } else if (mCurrentDrawable == mOutAnimation) {
        mOutAnimation.stop();
    }

}
项目:RxAnimationBinding    文件:RxAnimatable2.java   
@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));
}
项目:RxAnimationBinding    文件:RxAnimatable2.java   
@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));
}
项目:binea_project_for_android    文件:AnimatedVectorDrawableCompat.java   
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());
        }
    }
}
项目:binea_project_for_android    文件:AnimatedVectorDrawableCompat.java   
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;
}
项目:RxAnimationBinding    文件:Animatable2ListenerOnSubscribe.java   
Animatable2ListenerOnSubscribe(Animatable2 animatable2, int eventToCallOn) {
    this.animatable2 = animatable2;
    this.eventToCallOn = eventToCallOn;
}