下面列出了怎么用android.support.annotation.AnimRes的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Finish to the activity.
*
* @param activity The activity.
* @param isIncludeSelf True to include the activity, false otherwise.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static boolean finishToActivity(@NonNull final Activity activity,
final boolean isIncludeSelf,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
List<Activity> activities = UtilsBridge.getActivityList();
for (Activity act : activities) {
if (act.equals(activity)) {
if (isIncludeSelf) {
finishActivity(act, enterAnim, exitAnim);
}
return true;
}
finishActivity(act, enterAnim, exitAnim);
}
return false;
}
@NonNull
public PopOptions.Builder setAnimation(@NonNull Activity activity,
@AnimRes @AnimatorRes int enterAnim,
@AnimRes @AnimatorRes int exitAnim) {
this.mNavigationAnimationExecutor = new AnimationOrAnimatorResourceExecutor(activity, enterAnim, exitAnim);
return this;
}
NavOptions(int launchMode, @IdRes int popUpTo, boolean popUpToInclusive,
@AnimRes @AnimatorRes int enterAnim, @AnimRes @AnimatorRes int exitAnim,
@AnimRes @AnimatorRes int popEnterAnim, @AnimRes @AnimatorRes int popExitAnim) {
mLaunchMode = launchMode;
mPopUpTo = popUpTo;
mPopUpToInclusive = popUpToInclusive;
mEnterAnim = enterAnim;
mExitAnim = exitAnim;
mPopEnterAnim = popEnterAnim;
mPopExitAnim = popExitAnim;
}
/**
* 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;
}
/**
* item 加载动画
* @param holder
* @param position
* @param type
*/
protected void setItemAppearAnimation(RecyclerView.ViewHolder holder, int position, @AnimRes int type){
if(position > mLastPosition){
Animation animation = AnimationUtils.loadAnimation(holder.itemView.getContext(),type);
holder.itemView.startAnimation(animation);
mLastPosition = position;
}
}
/**
* Launches the intent passed in and deals with any of the parameters specified
*
* @param activityIntent
* the activity intent to launch
* @param callerActivity
* the caller activity to launch the intent with
* @param launchOptionsBundle
* Additional options for how the Activity should be started, passed in through
* {@link AppCompatActivity#startActivity(Intent, Bundle)} or
* {@link AppCompatActivity#startActivityForResult(Intent, int, Bundle)}
* @param targetFragment
* a target fragment if specified to receive the callback
* {@link AppCompatActivity#onActivityResult(int, int, Intent)} with the specified request code parameter
* @param enterAnim
* the res id of the activity-enter animation, 0 if none specified
* @param exitAnim
* the res id of the activity-exit animation, 0 if none specified
* @param requestCode
* the request code to start the destination activity with
* {@link AppCompatActivity#startActivityForResult(Intent, int)}
* @param shouldFinishActivityAfterResult
* boolean whether should finish the caller activity after launching the
*/
@SuppressWarnings("checkstyle:parameternumber")
@VisibleForTesting
/*package*/ static void launchIntentWithParameters(@NonNull final Intent activityIntent,
@NonNull final AppCompatActivity callerActivity,
@Nullable final Bundle launchOptionsBundle,
@Nullable final Fragment targetFragment,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim,
final int requestCode,
final boolean shouldFinishActivityAfterResult) {
// Launch the activity on the main thread incase there are some animations the caller wants executed
PermissMeUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (requestCode != 0) {
if (targetFragment != null) {
targetFragment.startActivityForResult(activityIntent, requestCode, launchOptionsBundle);
} else {
callerActivity.startActivityForResult(activityIntent, requestCode, launchOptionsBundle);
}
} else {
callerActivity.startActivity(activityIntent, launchOptionsBundle);
}
if (enterAnim != 0 || exitAnim != 0) {
PermissMe.overrideDefaultTransition(callerActivity, enterAnim, exitAnim);
}
if (shouldFinishActivityAfterResult) {
callerActivity.finish();
}
}
});
}
/**
* 设置当前SweetToast实例的出入场动画(App中自定义)
* @param animEnter
* @param animExit
* @return
*/
public SweetToast setAnimations(@AnimRes int animEnter,@AnimRes int animExit){
try {
Animation enter = AnimationUtils.loadAnimation(mContentView.getContext(),animEnter);
Animation exit = AnimationUtils.loadAnimation(mContentView.getContext(),animExit);
return setAnimations(enter,exit);
}catch (Exception e){
//用户传入的动画资源找不到/出现异常,直接返回
Log.e("幻海流心","setAnimations -> e:"+e.getLocalizedMessage());
return this;
}
}
public Builder setCustomAnimations(@AnimRes int animationOpenEnter,
@AnimRes int animationOpenExit, @AnimRes int animationCloseEnter,
@AnimRes int animationCloseExit) {
this.animationOpenEnter = animationOpenEnter;
this.animationOpenExit = animationOpenExit;
this.animationCloseEnter = animationCloseEnter;
this.animationCloseExit = animationCloseExit;
return this;
}
/**
* 设置进入动画和离开动画
*
* @param inAnimResId 进入动画的resID
* @param outAnimResID 离开动画的resID
*/
private void setInAndOutAnimation(@AnimRes int inAnimResId, @AnimRes int outAnimResID) {
Animation inAnim = AnimationUtils.loadAnimation(getContext(), inAnimResId);
inAnim.setDuration(animDuration);
mViewFlipper.setInAnimation(inAnim);
Animation outAnim = AnimationUtils.loadAnimation(getContext(), outAnimResID);
outAnim.setDuration(animDuration);
mViewFlipper.setOutAnimation(outAnim);
}
/**
* Start the activity for result.
*
* @param extras The Bundle of extras to add to this intent.
* @param pkg The name of the package.
* @param cls The name of the class.
* @param requestCode if >= 0, this code will be returned in
* onActivityResult() when the activity exits.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void startActivityForResult(@NonNull final Bundle extras,
@NonNull final Activity activity,
@NonNull final String pkg,
@NonNull final String cls,
final int requestCode,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
startActivityForResult(activity, extras, pkg, cls,
requestCode, getOptionsBundle(activity, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
activity.overridePendingTransition(enterAnim, exitAnim);
}
}
public Builder setActivityAnimations(@AnimRes Integer animationOpenEnter, @AnimRes Integer animationOpenExit, @AnimRes Integer animationCloseEnter, @AnimRes Integer
animationCloseExit){
this.animationOpenEnter = animationOpenEnter;
this.animationOpenExit = animationOpenExit;
this.animationCloseEnter = animationCloseEnter;
this.animationCloseExit = animationCloseExit;
return this;
}
/**
* Set page switch animation
*
* @param nextIn The next page to enter the animation
* @param nextOut The next page out of the animation
* @param quitIn The current page into the animation
* @param quitOut Exit animation for the current page
*/
public void setAnim(@AnimRes int nextIn, @AnimRes int nextOut, @AnimRes int quitIn, @AnimRes int quitOut) {
this.nextIn = nextIn;
this.nextOut = nextOut;
this.quitIn = quitIn;
this.quitOut = quitOut;
next_in = AnimationUtils.loadAnimation(context, quitIn);
next_out = AnimationUtils.loadAnimation(context, quitOut);
}
/**
* Finish the activities whose type not equals the activity class.
*
* @param clz The activity class.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void finishOtherActivities(@NonNull final Class<? extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
List<Activity> activities = UtilsBridge.getActivityList();
for (Activity act : activities) {
if (!act.getClass().equals(clz)) {
finishActivity(act, enterAnim, exitAnim);
}
}
}
/**
* Set a Custom Animation to a Fragment transaction.
*
* @param enterAnim The animation resource to be used when the next fragment enters.
* @param exitAnim The animation resource to be used when the current fragment exits.
* @param popEnterAnim The animation resource to be used when the previous fragment enters on back pressed.
* @param popExitAnim The animation resource to be used when the current fragment exits on back pressed..
*/
public Builder setCustomTransactionAnimation(@AnimRes int enterAnim, @AnimRes int exitAnim,
@AnimRes int popEnterAnim, @AnimRes int popExitAnim) {
data.setEnterAnim(enterAnim);
data.setExitAnim(exitAnim);
data.setPopEnterAnim(popEnterAnim);
data.setPopExitAnim(popExitAnim);
return this;
}
/**
* 设置SweetSnackbar实例的 入场动画 及 离场动画
* @param animateIn
* @param animateOut
* @return
*/
public SnackbarUtils anim(@AnimRes int animateIn, @AnimRes int animateOut){
if(getSnackbar()!=null){
getSnackbar().setAnimations(animateIn,animateOut);
}
return this;
}
/**
* 设置当前SweetToast实例的出入场动画(App中自定义)
* @param animEnter
* @param animExit
* @return
*/
public SweetToast setAnimations(@AnimRes int animEnter,@AnimRes int animExit){
try {
Animation enter = AnimationUtils.loadAnimation(mContentView.getContext(),animEnter);
Animation exit = AnimationUtils.loadAnimation(mContentView.getContext(),animExit);
return setAnimations(enter,exit);
}catch (Exception e){
//用户传入的动画资源找不到/出现异常,直接返回
Log.e("幻海流心","setAnimations -> e:"+e.getLocalizedMessage());
return this;
}
}
@Override
public void withOverlaySlideAnimation(@AnimRes int enter, @AnimRes int exit, @AnimRes int popEnter, @AnimRes int popExit) {
// define animations for whole overlay slides
mOverlaySlidesAnimations[0] = enter;
mOverlaySlidesAnimations[1] = exit;
mOverlaySlidesAnimations[2] = popEnter;
mOverlaySlidesAnimations[3] = popExit;
}
/**
* Method used to set the Animations when the Custom Tab opens
* @param exitEnterAnimation The Enter Animation of the new activity
* @param exitCloseAnimation The Close Animation of the custom tab
*/
public Style setExitAnimation(@AnimRes int exitEnterAnimation, @AnimRes int
exitCloseAnimation){
this.exitEnterAnimation = exitEnterAnimation;
this.exitCloseAnimation = exitCloseAnimation;
return this;
}
/**
* Start the activity.
*
* @param clz The activity class.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void startActivity(@NonNull final Class<? extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
Context context = UtilsBridge.getTopActivityOrApp();
startActivity(context, null, context.getPackageName(), clz.getName(),
getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
}
}
/**
* Start the activity.
*
* @param activity The activity.
* @param clz The activity class.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void startActivity(@NonNull final Activity activity,
@NonNull final Class<? extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
startActivity(activity, null, activity.getPackageName(), clz.getName(),
getOptionsBundle(activity, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
activity.overridePendingTransition(enterAnim, exitAnim);
}
}
/**
* 设置SweetSnackbar实例的 入场动画 及 离场动画
* @param animateIn
* @param animateOut
* @return
*/
public SnackbarUtils anim(@AnimRes int animateIn, @AnimRes int animateOut){
if(getSnackbar()!=null){
getSnackbar().setAnimations(animateIn,animateOut);
}
return this;
}
/**
* Start the activity.
*
* @param extras The Bundle of extras to add to this intent.
* @param activity The activity.
* @param clz The activity class.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void startActivity(@NonNull final Bundle extras,
@NonNull final Activity activity,
@NonNull final Class<? extends Activity> clz,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
startActivity(activity, extras, activity.getPackageName(), clz.getName(),
getOptionsBundle(activity, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
activity.overridePendingTransition(enterAnim, exitAnim);
}
}
/**
* Start the activity.
*
* @param extras The Bundle of extras to add to this intent.
* @param pkg The name of the package.
* @param cls The name of the class.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
*/
public static void startActivity(@NonNull final Bundle extras,
@NonNull final String pkg,
@NonNull final String cls,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
Context context = UtilsBridge.getTopActivityOrApp();
startActivity(context, extras, pkg, cls, getOptionsBundle(context, enterAnim, exitAnim));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
}
}
/**
* Start the activity.
*
* @param intent The description of the activity to start.
* @param enterAnim A resource ID of the animation resource to use for the
* incoming activity.
* @param exitAnim A resource ID of the animation resource to use for the
* outgoing activity.
* @return {@code true}: success<br>{@code false}: fail
*/
public static boolean startActivity(@NonNull final Intent intent,
@AnimRes final int enterAnim,
@AnimRes final int exitAnim) {
Context context = UtilsBridge.getTopActivityOrApp();
boolean isSuccess = startActivity(intent, context, getOptionsBundle(context, enterAnim, exitAnim));
if (isSuccess) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && context instanceof Activity) {
((Activity) context).overridePendingTransition(enterAnim, exitAnim);
}
}
return isSuccess;
}
@AnimRes int getPushOutAnim() {
return mPushOutAnim;
}
@AnimRes int getPopOutAnim() {
return mPopOutAnim;
}
@Override
public boolean navigateTo(Type fragmentClass, Bundle bundle, @AnimRes int enterAnimId, @AnimRes int exitAnimId) {
return false;
}
protected <T extends BaseActivityLauncher> T animate(final T son, @AnimRes int enterResId, @AnimRes int exitResId){
ActivityAnimate.animate(mFrom,mActivityOptionsBox,enterResId,exitResId);
return son;
}
public Explicit animate(@AnimRes int enterResId, @AnimRes int exitResId){
return animate(this,enterResId,exitResId);
}
public static XmlResourceParser getAnimation(@AnimRes int animRes) {
return Base.getResources().getAnimation(animRes);
}