@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explore);
iv = (ImageView) findViewById(R.id.search);
text = (EditText) findViewById(R.id.text);
searchToBar = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.anim_search_to_bar);
barToSearch = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.anim_bar_to_search);
interp = AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in);
duration = getResources().getInteger(R.integer.duration_bar);
// iv is sized to hold the search+bar so when only showing the search icon, translate the
// whole view left by half the difference to keep it centered
offset = -71f * (int) getResources().getDisplayMetrics().scaledDensity;
iv.setTranslationX(offset);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animate();
}
});
}
java类android.graphics.drawable.AnimatedVectorDrawable的实例源码
ExploreActivity.java 文件源码
项目:Quadro
阅读 20
收藏 0
点赞 0
评论 0
OpenOnPhoneAnimationActivity.java 文件源码
项目:android-WearAccessibilityApp
阅读 19
收藏 0
点赞 0
评论 0
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_on_phone_animation);
AmbientMode.attachAmbientSupport(this);
mAnimationCallback =
new AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
super.onAnimationEnd(drawable);
// Go back to main Dialogs screen after animation.
finish();
}
};
// Play 'swipe left' animation only once.
ImageView phoneImage = findViewById(R.id.open_on_phone_animation_image);
mAnimatedVectorDrawablePhone = (AnimatedVectorDrawable) phoneImage.getDrawable();
mAnimatedVectorDrawablePhone.registerAnimationCallback(mAnimationCallback);
mAnimatedVectorDrawablePhone.start();
}
NoHotelsActivity.java 文件源码
项目:betterHotels
阅读 35
收藏 0
点赞 0
评论 0
@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");
}
});
}
SocialFragment.java 文件源码
项目:iosched-reader
阅读 25
收藏 0
点赞 0
评论 0
@TargetApi(21)
private void setupLogoAnim() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final ImageView iv = (ImageView) getActivity().findViewById(R.id.io_logo);
final AnimatedVectorDrawable logoAnim =
(AnimatedVectorDrawable) getActivity().getDrawable(
R.drawable.io_logo_social_anim);
iv.setImageDrawable(logoAnim);
logoAnim.start();
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoAnim.start();
}
});
}
}
HabitAdapter.java 文件源码
项目:UdacityAndroidBasicsNanodegree
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void onBindViewHolder(final HabitViewHolder holder, int position) {
final Habit habit = habits.get(position);
holder.habitName.setText(habit.name);
holder.count.setText(String.format(Locale.getDefault(), "%d", habit.timesCompleted));
holder.timesPerDay.setText(context.getString(R.string.times_per_day, habit.timesPerDay));
holder.doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((AnimatedVectorDrawable) holder.doneButton.getDrawable()).start();
dbHelper.incrementHabit(habit.name);
Storage.incrementHabit(context, habit.name);
}
});
}
MainActivity.java 文件源码
项目:android-samples
阅读 23
收藏 0
点赞 0
评论 0
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView mFabView = (ImageView) findViewById(R.id.fab_view);
// animate head to leaf
final AnimatedVectorDrawable faceAVD = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.face_avd);
mFabView.setImageDrawable(faceAVD);
findViewById(R.id.animate_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
faceAVD.start();
}
});
}
SocialFragment.java 文件源码
项目:smconf-android
阅读 25
收藏 0
点赞 0
评论 0
@TargetApi(21)
private void setupLogoAnim() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final ImageView iv = (ImageView) getActivity().findViewById(R.id.io_logo);
final AnimatedVectorDrawable logoAnim =
(AnimatedVectorDrawable) getActivity().getDrawable(
R.drawable.io_logo_social_anim);
iv.setImageDrawable(logoAnim);
logoAnim.start();
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoAnim.start();
}
});
}
}
NoHotelsActivity.java 文件源码
项目:betterHotels
阅读 23
收藏 0
点赞 0
评论 0
@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");
}
});
}
FloatingNavigationView.java 文件源码
项目:Floating-Navigation-View
阅读 21
收藏 0
点赞 0
评论 0
private void startOpenAnimations() {
// Icon
AnimatedVectorDrawable menuIcon = (AnimatedVectorDrawable) ContextCompat.getDrawable(getContext(),
R.drawable.ic_menu_animated);
mFabView.setImageDrawable(menuIcon);
menuIcon.start();
// Reveal
int centerX = mFabRect.centerX();
int centerY = mFabRect.centerY();
float startRadius = getMinRadius();
float endRadius = getMaxRadius();
Animator reveal = ViewAnimationUtils
.createCircularReveal(mNavigationView,
centerX, centerY, startRadius, endRadius);
// Fade in
mNavigationMenuView.setAlpha(0);
Animator fade = ObjectAnimator.ofFloat(mNavigationMenuView, View.ALPHA, 0, 1);
// Animations
AnimatorSet set = new AnimatorSet();
set.playSequentially(reveal, fade);
set.start();
}
RecyclerFragment.java 文件源码
项目:materialup
阅读 27
收藏 0
点赞 0
评论 0
public void checkEmptyOrConnection() {
if (!Utils.hasInternet(getActivity())) {
if (getAdapter().getItemCount() == 0) {
mEmpty.setVisibility(View.GONE);
mEmptyImage.setVisibility(View.VISIBLE);
if (UI.isLollipop()) {
final AnimatedVectorDrawable avd =
(AnimatedVectorDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.avd_no_connection);
mEmptyImage.setImageDrawable(avd);
avd.start();
} else {
mEmptyImage.setImageResource(R.drawable.no_connection);
}
} else {
Toast.makeText(getActivity(), R.string.check_network, Toast.LENGTH_SHORT).show();
}
}
}
MovableMarker.java 文件源码
项目:TrekAdvisor
阅读 26
收藏 0
点赞 0
评论 0
/**
* The {@code mRounded} drawable is just the end state of the {@code mStaticToDynamic}
* {@link AnimatedVectorDrawable}.
* The {@code mStatic} drawable is the end state of the {@code mDynamicToStatic}
* {@link AnimatedVectorDrawable}. <br>
*
*/
public MovableMarker(Context context, boolean staticForm, MarkerGson.Marker marker) {
super(context);
mRounded = (AnimatedVectorDrawable) context.getDrawable(R.drawable.avd_marker_rounded);
mStatic = context.getDrawable(R.drawable.vd_marker_location_rounded);
mStaticToDynamic = (AnimatedVectorDrawable) context.getDrawable(R.drawable.avd_marker_location_rounded);
mDynamicToStatic = (AnimatedVectorDrawable) context.getDrawable(R.drawable.avd_marker_rounded_location);
/* Keep a reference on the model object */
mMarker = marker;
/* Init the drawable */
if (staticForm) {
initStatic();
} else {
initRounded();
}
}
HomeActivity.java 文件源码
项目:Amumu
阅读 25
收藏 0
点赞 0
评论 0
private void checkConnectivity() {
final ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
if (!connected) {
loading.setVisibility(View.GONE);
if (noConnection == null) {
final ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
noConnection = (ImageView) stub.inflate();
}
final AnimatedVectorDrawable avd =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
noConnection.setImageDrawable(avd);
avd.start();
connectivityManager.registerNetworkCallback(
new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(),
connectivityCallback);
monitoringConnectivity = true;
}
}
SocialFragment.java 文件源码
项目:2015-Google-I-O-app
阅读 19
收藏 0
点赞 0
评论 0
@TargetApi(21)
private void setupLogoAnim() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final ImageView iv = (ImageView) getActivity().findViewById(R.id.io_logo);
final AnimatedVectorDrawable logoAnim =
(AnimatedVectorDrawable) getActivity().getDrawable(
R.drawable.io_logo_social_anim);
iv.setImageDrawable(logoAnim);
logoAnim.start();
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoAnim.start();
}
});
}
}
HomeActivity.java 文件源码
项目:android-proguards
阅读 32
收藏 0
点赞 0
评论 0
void revealPostingProgress() {
Animator reveal = ViewAnimationUtils.createCircularReveal(fabPosting,
(int) fabPosting.getPivotX(),
(int) fabPosting.getPivotY(),
0f,
fabPosting.getWidth() / 2)
.setDuration(600L);
reveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(this));
reveal.start();
AnimatedVectorDrawable uploading =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_uploading);
if (uploading != null) {
fabPosting.setImageDrawable(uploading);
uploading.start();
}
}
HomeActivity.java 文件源码
项目:android-proguards
阅读 32
收藏 0
点赞 0
评论 0
private void checkConnectivity() {
final ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
if (!connected) {
loading.setVisibility(View.GONE);
if (noConnection == null) {
final ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
noConnection = (ImageView) stub.inflate();
}
final AnimatedVectorDrawable avd =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
if (noConnection != null && avd != null) {
noConnection.setImageDrawable(avd);
avd.start();
}
connectivityManager.registerNetworkCallback(
new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(),
connectivityCallback);
monitoringConnectivity = true;
}
}
HomeActivity.java 文件源码
项目:OldDriver-master
阅读 29
收藏 0
点赞 0
评论 0
private void checkConnectivity() {
final ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
connected = activeNetworkInfo != null && activeNetworkInfo.isConnected();
if (!connected) {
loading.setVisibility(View.GONE);
if (noConnection == null) {
final ViewStub stub = (ViewStub) findViewById(R.id.stub_no_connection);
noConnection = (ImageView) stub.inflate();
}
final AnimatedVectorDrawable avd =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_no_connection);
noConnection.setImageDrawable(avd);
avd.start();
connectivityManager.registerNetworkCallback(
new NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build(),
connectivityCallback);
monitoringConnectivity = true;
}
}
MovieDetailsActivity.java 文件源码
项目:Reactive-Popular-Movies
阅读 25
收藏 0
点赞 0
评论 0
@Override
public void showFavoriteMovie() {
if (!isFavorite) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AnimatedVectorDrawable emptyHeart = (AnimatedVectorDrawable)
emptyHeartConstantState.newDrawable();
fab.setImageDrawable(emptyHeart);
emptyHeart.start();
} else {
fab.setImageResource(R.drawable.heart_fill);
}
isFavorite = true;
}
}
MovieDetailsActivity.java 文件源码
项目:Reactive-Popular-Movies
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void showNonFavoriteMovie() {
if (isFavorite) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AnimatedVectorDrawable fullHeart = (AnimatedVectorDrawable)
fullHeartConstantState.newDrawable();
fab.setImageDrawable(fullHeart);
fullHeart.start();
} else {
fab.setImageResource(R.drawable.fab_heart_empty);
}
isFavorite = false;
}
}
SocialFragment.java 文件源码
项目:FMTech
阅读 18
收藏 0
点赞 0
评论 0
@TargetApi(21)
private void setupLogoAnim() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final ImageView iv = (ImageView) getActivity().findViewById(R.id.io_logo);
final AnimatedVectorDrawable logoAnim =
(AnimatedVectorDrawable) getActivity().getDrawable(
R.drawable.io_logo_social_anim);
iv.setImageDrawable(logoAnim);
logoAnim.start();
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoAnim.start();
}
});
}
}
AnimatedPinDrawable.java 文件源码
项目:multi-seek-bar
阅读 24
收藏 0
点赞 0
评论 0
public AnimatedPinDrawable(Context context) {
super();
Drawable collapsed = context.getDrawable(R.drawable.pin_collapsed);
Drawable expanded = context.getDrawable(R.drawable.pin_expanded);
AnimatedVectorDrawable expanding = (AnimatedVectorDrawable) context
.getDrawable(R.drawable.pin_collapsed_to_expanded_animation);
AnimatedVectorDrawable collapsing = (AnimatedVectorDrawable) context
.getDrawable(R.drawable.pin_expanded_to_collapsed_animation);
addState(STATE_SET_PRESSED, expanded, STATE_EXPANDED_ID);
addState(STATE_SET_UNPRESSED, collapsed, STATE_COLLAPSED_ID);
addTransition(STATE_COLLAPSED_ID, STATE_EXPANDED_ID, expanding, false);
addTransition(STATE_EXPANDED_ID, STATE_COLLAPSED_ID, collapsing, false);
paint.setColor(Color.BLUE);
paint.setTextSize(24f);
paint.setTextAlign(Paint.Align.CENTER);
paint.setAntiAlias(true);
duration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);
}
SearchAnimateDecorator.java 文件源码
项目:Decor
阅读 20
收藏 0
点赞 0
评论 0
@Override
protected void apply(ImageView view, TypedArray typedArray) {
boolean shouldAnimate = typedArray.getBoolean(R.styleable.SearchAnimateDecorator_decorAnimateSearch, false);
if(!shouldAnimate) return;
mIv = view;
mSearchToBar = (AnimatedVectorDrawable) view.getContext().getResources().getDrawable(R.drawable.anim_search_to_bar);
mBarToSearch = (AnimatedVectorDrawable) view.getContext().getResources().getDrawable(R.drawable.anim_bar_to_search);
mInterp = AnimationUtils.loadInterpolator(view.getContext(), android.R.interpolator.linear_out_slow_in);
mDuration = view.getContext().getResources().getInteger(R.integer.duration_bar);
// iv is sized to hold the search+bar so when only showing the search icon, translate the
// whole view left by half the difference to keep it centered
mOffset = -71f * (int) view.getContext().getResources().getDisplayMetrics().scaledDensity;
view.setTranslationX(mOffset);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animate(v);
}
});
}
SocialFragment.java 文件源码
项目:JJCamera
阅读 20
收藏 0
点赞 0
评论 0
@TargetApi(21)
private void setupLogoAnim() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final ImageView iv = (ImageView) getActivity().findViewById(R.id.io_logo);
final AnimatedVectorDrawable logoAnim =
(AnimatedVectorDrawable) getActivity().getDrawable(
R.drawable.io_logo_social_anim);
iv.setImageDrawable(logoAnim);
logoAnim.start();
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
logoAnim.start();
}
});
}
}
HomeActivity.java 文件源码
项目:plaid
阅读 34
收藏 0
点赞 0
评论 0
void revealPostingProgress() {
Animator reveal = ViewAnimationUtils.createCircularReveal(fabPosting,
(int) fabPosting.getPivotX(),
(int) fabPosting.getPivotY(),
0f,
fabPosting.getWidth() / 2)
.setDuration(600L);
reveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(this));
reveal.start();
AnimatedVectorDrawable uploading =
(AnimatedVectorDrawable) getDrawable(R.drawable.avd_uploading);
if (uploading != null) {
fabPosting.setImageDrawable(uploading);
uploading.start();
}
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 21
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
*/
private void launchAnimBackup(){
if(!backupRoundTripFirstLaunched) {
if (backupRoundTrip.getLevel() == 1) {
//then reverse
backupRoundTrip.setLevel(0);
} else {
//then reverse
backupRoundTrip.setLevel(1);
}
}else{
backupRoundTripFirstLaunched=false;
}
//find the current AnimatedVectorDrawable displayed
currentBackupDrawable = (AnimatedVectorDrawable) backupRoundTrip.getCurrent();
//start the animation
currentBackupDrawable.start();
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 22
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
* As the levellist solution (ahead) has a bug, I do it in a simple way
*/
private void launchAnimBackup() {
//initialize
if (backupRoundTripFirstLaunched) {
reverse = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.animated_ic_check_box_black_24dp_reverse, getTheme());
initial = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.animated_ic_check_box_black_24dp, getTheme());
//if you want to avoid the color bug (animation not played on color at the second time)
//comment that line (ok it's memory consumption)
backupRoundTripFirstLaunched=false;
}
//set the drawable depending on the direction (reverse or not)
if (reverseState) {
//then reverse
imageView2.setImageDrawable(reverse);
} else {
//then reverse
imageView2.setImageDrawable(initial);
}
reverseState=!reverseState;
//launch the animation
((AnimatedVectorDrawable) imageView2.getDrawable()).start();
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 18
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
*/
private void launchAnimBackup(){
if(!backupRoundTripFirstLaunched) {
if (backupRoundTrip.getLevel() == 1) {
//then reverse
backupRoundTrip.setLevel(0);
} else {
//then reverse
backupRoundTrip.setLevel(1);
}
}else{
backupRoundTripFirstLaunched=false;
}
//find the current AnimatedVectorDrawable displayed
currentBackupDrawable = (AnimatedVectorDrawable) backupRoundTrip.getCurrent();
//start the animation
currentBackupDrawable.start();
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 21
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
*/
private void launchAnimBackup(){
if(!backupRoundTripFirstLaunched) {
if (backupRoundTrip.getLevel() == 1) {
//then reverse
backupRoundTrip.setLevel(0);
} else {
//then reverse
backupRoundTrip.setLevel(1);
}
}else{
backupRoundTripFirstLaunched=false;
}
//find the current AnimatedVectorDrawable displayed
currentBackupDrawable = (AnimatedVectorDrawable) backupRoundTrip.getCurrent();
//start the animation
currentBackupDrawable.start();
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 21
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
* As the levellist solution (ahead) has a bug, I do it in a simple way
*/
private void launchAnimBackup() {
//initialize
if (backupRoundTripFirstLaunched) {
reverse = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.animated_ic_check_box_black_24dp_reverse, getTheme());
initial = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.animated_ic_check_box_black_24dp, getTheme());
//if you want to avoid the color bug (animation not played on color at the second time)
//comment that line (ok it's memory consumption)
backupRoundTripFirstLaunched=false;
}
//set the drawable depending on the direction (reverse or not)
if (reverseState) {
//then reverse
imageView2.setImageDrawable(reverse);
} else {
//then reverse
imageView2.setImageDrawable(initial);
}
reverseState=!reverseState;
//launch the animation
((AnimatedVectorDrawable) imageView2.getDrawable()).start();
}
MainActivity.java 文件源码
项目:AnimatedVectorMorphingTool
阅读 21
收藏 0
点赞 0
评论 0
/**
* Launch the animation on the currentAnimatedVectorDrawable
*/
private void launchAnimBackup(){
if(!backupRoundTripFirstLaunched) {
if (backupRoundTrip.getLevel() == 1) {
//then reverse
backupRoundTrip.setLevel(0);
} else {
//then reverse
backupRoundTrip.setLevel(1);
}
}else{
backupRoundTripFirstLaunched=false;
}
//find the current AnimatedVectorDrawable displayed
currentBackupDrawable = (AnimatedVectorDrawable) backupRoundTrip.getCurrent();
//start the animation
currentBackupDrawable.start();
}
PhotoDetailActivity.java 文件源码
项目:appcutt
阅读 22
收藏 0
点赞 0
评论 0
@OnClick(R.id.fab)
void onClickFab() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Drawable drawable = fab.getDrawable();
if (drawable instanceof AnimatedVectorDrawable) {
if (((AnimatedVectorDrawable) drawable).isRunning()) return;
int drawableResId = fab.isSelected() ? R.drawable.ic_pause_to_play : R.drawable.ic_play_to_pause;
fab.setImageResource(drawableResId);
drawable = fab.getDrawable();
((AnimatedVectorDrawable) drawable).start();
}
}
if (fab.isSelected()) {
imgPreview.pause();
} else {
imgPreview.resume();
}
fab.setSelected(!fab.isSelected());
}