下面列出了怎么用androidx.annotation.AnimRes的API类实例代码及写法,或者点击链接到github查看源代码。
private void setInstantOnClick(@IdRes int viewRes, final Class activityClass, @AnimRes final int inAnimation) {
View view = getActivity().findViewById(viewRes);
view.setOnClickListener(view1 -> {
Intent intent = new Intent(getActivity(), activityClass);
ActivityOptionsCompat searchAnim = ActivityOptionsCompat.makeCustomAnimation(getActivity(), inAnimation, R.anim.fade_out_semi_anim);
ActivityCompat.startActivity(getActivity(), intent, searchAnim.toBundle());
mDrawerLayout.closeDrawer(containerView);
});
}
/**
* 获取 Animation
* @param id resource identifier
* @return XmlResourceParser
*/
public static XmlResourceParser getAnimation(@AnimatorRes @AnimRes final int id) {
try {
return DevUtils.getContext().getResources().getAnimation(id);
} catch (Exception e) {
LogPrintUtils.eTag(TAG, e, "getAnimation");
}
return null;
}
void showTabBarWhenPop(@AnimRes int anim) {
if (tabBar != null) {
tabBarHidden = false;
setNeedsNavigationBarAppearanceUpdate();
if (anim != R.anim.nav_none) {
Animation animation = AnimationUtils.loadAnimation(getContext(), anim);
animation.setAnimationListener(new TabBarAnimationListener(false));
tabBar.startAnimation(animation);
} else {
tabBar.setVisibility(View.VISIBLE);
tabBar.setTranslationY(0);
}
}
}
void hideTabBarWhenPush(@AnimRes int anim) {
if (tabBar != null) {
tabBarHidden = true;
setNeedsNavigationBarAppearanceUpdate();
if (anim != R.anim.nav_none) {
Animation animation = AnimationUtils.loadAnimation(getContext(), anim);
animation.setAnimationListener(new TabBarAnimationListener(true));
tabBar.startAnimation(animation);
} else {
tabBar.setVisibility(View.GONE);
tabBar.setTranslationY(tabBar.getHeight());
}
}
}
/**
* Send the crop Intent from animation an Activity
*
* @param activity Activity to receive result
*/
public void startAnimation(@NonNull Activity activity, @AnimRes int activityCropEnterAnimation) {
if (activityCropEnterAnimation != 0) {
start(activity, REQUEST_MULTI_CROP, activityCropEnterAnimation);
} else {
start(activity, REQUEST_MULTI_CROP);
}
}
/**
* Send the crop Intent from animation an Activity
*
* @param activity Activity to receive result
*/
public void startAnimation(@NonNull Activity activity, @AnimRes int activityCropEnterAnimation) {
if (activityCropEnterAnimation != 0) {
start(activity, REQUEST_CROP, activityCropEnterAnimation);
} else {
start(activity, REQUEST_CROP);
}
}
public PictureWindowAnimationStyle(@AnimRes int activityEnterAnimation,
@AnimRes int activityExitAnimation,
@AnimRes int activityPreviewEnterAnimation,
@AnimRes int activityPreviewExitAnimation) {
super();
this.activityEnterAnimation = activityEnterAnimation;
this.activityExitAnimation = activityExitAnimation;
this.activityPreviewEnterAnimation = activityPreviewEnterAnimation;
this.activityPreviewExitAnimation = activityPreviewExitAnimation;
}
/**
* Send the crop Intent from animation an Activity
*
* @param activity Activity to receive result
*/
public void startAnimationActivity(@NonNull Activity activity, @AnimRes int activityCropEnterAnimation) {
if (activityCropEnterAnimation != 0) {
start(activity, REQUEST_CROP, activityCropEnterAnimation);
} else {
start(activity, REQUEST_CROP);
}
}
/**
* Send the crop Intent from animation an Multiple Activity
*
* @param activity Activity to receive result
*/
public void startAnimationMultipleCropActivity(@NonNull Activity activity,
@AnimRes int activityCropEnterAnimation) {
if (activityCropEnterAnimation != 0) {
startMultiple(activity, REQUEST_MULTI_CROP, activityCropEnterAnimation);
} else {
startMultiple(activity, REQUEST_MULTI_CROP);
}
}
/**
* Set view on error animation
*
* @param errorAnimation new animation
* @return ViewTranslationWrapper object
*/
public ViewTranslationWrapper setErrorAnimation(@AnimRes int errorAnimation) {
if (errorAnimation != 0) {
this.errorAnimation = AnimationUtils.loadAnimation(view.getContext(), errorAnimation);
}
return this;
}
/**
* Generic method for asserting pending transition animation
*
* @param shadowActivity The shadow activity
* @param enterAnim The enter animation resource
* @param exitAnim The exit animation resource
*/
private static void assertOverridePendingTransition(ShadowActivity shadowActivity,
@AnimRes int enterAnim, @AnimRes int exitAnim) {
assertEquals(enterAnim, shadowActivity
.getPendingTransitionEnterAnimationResourceId());
assertEquals(exitAnim, shadowActivity
.getPendingTransitionExitAnimationResourceId());
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void addAnimationToMenuItem(MenuItem menuItem, @LayoutRes int layoutResource,
@AnimRes int animationId) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView iv = (ImageView)inflater.inflate(layoutResource, null);
Animation animation = AnimationUtils.loadAnimation(this, animationId);
iv.startAnimation(animation);
menuItem.setActionView(iv);
}
/**
* Sets the exit animations.
*
* @param context Application context.
* @param enterResId Resource ID of the "enter" animation for the application.
* @param exitResId Resource ID of the "exit" animation for the browser.
*/
public Builder setExitAnimations(
@NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(
context, enterResId, exitResId).toBundle();
mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle);
return this;
}
/**
* Sets the exit animations.
*
* @param context Application context.
* @param enterResId Resource ID of the "enter" animation for the application.
* @param exitResId Resource ID of the "exit" animation for the browser.
*/
public Builder setExitAnimations(
@NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(
context, enterResId, exitResId).toBundle();
mIntent.putExtra(EXTRA_EXIT_ANIMATION_BUNDLE, bundle);
return this;
}
private Animation loadAnimation(@AnimRes int animResId) {
final Animation animation = AnimationUtils.loadAnimation(this, animResId);
animation.setInterpolator(new FastOutSlowInInterpolator());
return animation;
}
/**
* @param activityCropExitAnimation activity exit animation
*/
public Options setCropExitAnimation(@AnimRes int activityCropExitAnimation) {
mOptionBundle.putInt(EXTRA_WINDOW_EXIT_ANIMATION, activityCropExitAnimation);
return this;
}
/**
* @param activityCropExitAnimation activity exit animation
*/
public Options setCropExitAnimation(@AnimRes int activityCropExitAnimation) {
mOptionBundle.putInt(EXTRA_WINDOW_EXIT_ANIMATION, activityCropExitAnimation);
return this;
}
public PictureWindowAnimationStyle(@AnimRes int activityEnterAnimation,
@AnimRes int activityExitAnimation) {
super();
this.activityEnterAnimation = activityEnterAnimation;
this.activityExitAnimation = activityExitAnimation;
}
/**
* @param activityCropExitAnimation activity exit animation
*/
public void setCropExitAnimation(@AnimRes int activityCropExitAnimation) {
mOptionBundle.putInt(EXTRA_WINDOW_EXIT_ANIMATION, activityCropExitAnimation);
}
/**
* @param enterAnimation animation resource that will be used for an appearing activity/fragment
* @param exitAnimation animation resource that will be used for a disappearing activity/fragment
*/
public SimpleTransitionAnimation(@AnimRes int enterAnimation, @AnimRes int exitAnimation) {
mEnterAnimation = enterAnimation;
mExitAnimation = exitAnimation;
}
/**
* Sets the start animations.
*
* @param context Application context.
* @param enterResId Resource ID of the "enter" animation for the browser.
* @param exitResId Resource ID of the "exit" animation for the application.
*/
public Builder setStartAnimations(
@NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation(
context, enterResId, exitResId).toBundle();
return this;
}
/**
* Sets the start animations.
*
* @param context Application context.
* @param enterResId Resource ID of the "enter" animation for the browser.
* @param exitResId Resource ID of the "exit" animation for the application.
*/
public Builder setStartAnimations(
@NonNull Context context, @AnimRes int enterResId, @AnimRes int exitResId) {
mStartAnimationBundle = ActivityOptionsCompat.makeCustomAnimation(
context, enterResId, exitResId).toBundle();
return this;
}
/**
* Send the crop Intent from an Activity with a custom request code or animation
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(@NonNull Activity activity, int requestCode, @AnimRes int activityCropEnterAnimation) {
activity.startActivityForResult(getIntent(activity), requestCode);
activity.overridePendingTransition(activityCropEnterAnimation, R.anim.ucrop_anim_fade_in);
}
/**
* Send the crop Intent from an Activity with a custom request code or animation
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(@NonNull Activity activity, int requestCode, @AnimRes int activityCropEnterAnimation) {
activity.startActivityForResult(getIntent(activity), requestCode);
activity.overridePendingTransition(activityCropEnterAnimation, R.anim.ucrop_anim_fade_in);
}
/**
* Send the crop Intent from an Activity with a custom request code or animation
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(@NonNull Activity activity, int requestCode, @AnimRes int activityCropEnterAnimation) {
activity.startActivityForResult(getIntent(activity), requestCode);
activity.overridePendingTransition(activityCropEnterAnimation, R.anim.ucrop_anim_fade_in);
}
/**
* Send the crop Intent from an Activity with a custom request code or animation
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void startMultiple(@NonNull Activity activity, int requestCode, @AnimRes int activityCropEnterAnimation) {
activity.startActivityForResult(getMultipleIntent(activity), requestCode);
activity.overridePendingTransition(activityCropEnterAnimation, R.anim.ucrop_anim_fade_in);
}