parent
7b9fc382dc
commit
f98ce6f6e4
@ -0,0 +1,102 @@ |
||||
package com.android.base.app.fragment; |
||||
|
||||
import android.content.Context; |
||||
import android.view.animation.Animation; |
||||
import android.view.animation.AnimationUtils; |
||||
|
||||
import com.android.base.R; |
||||
|
||||
import androidx.fragment.app.FragmentTransaction; |
||||
|
||||
public final class AnimatorHelper { |
||||
|
||||
private Animation noneAnim, noneAnimFixed; |
||||
private Animation enterAnim, exitAnim, popEnterAnim, popExitAnim; |
||||
|
||||
private Context context; |
||||
private FragmentAnimator fragmentAnimator; |
||||
|
||||
AnimatorHelper(Context context, FragmentAnimator fragmentAnimator) { |
||||
this.context = context; |
||||
notifyChanged(fragmentAnimator); |
||||
} |
||||
|
||||
void notifyChanged(FragmentAnimator fragmentAnimator) { |
||||
this.fragmentAnimator = fragmentAnimator; |
||||
if (fragmentAnimator != null) { |
||||
initEnterAnim(); |
||||
initExitAnim(); |
||||
initPopEnterAnim(); |
||||
initPopExitAnim(); |
||||
} |
||||
} |
||||
|
||||
public Animation getNoneAnim() { |
||||
if (noneAnim == null) { |
||||
noneAnim = AnimationUtils.loadAnimation(context, R.anim.no_anim); |
||||
} |
||||
return noneAnim; |
||||
} |
||||
|
||||
public Animation getNoneAnimFixed() { |
||||
if (noneAnimFixed == null) { |
||||
noneAnimFixed = new Animation() { |
||||
}; |
||||
} |
||||
return noneAnimFixed; |
||||
} |
||||
|
||||
private Animation initEnterAnim() { |
||||
if (fragmentAnimator.getEnter() == 0) { |
||||
enterAnim = AnimationUtils.loadAnimation(context, R.anim.no_anim); |
||||
} else { |
||||
enterAnim = AnimationUtils.loadAnimation(context, fragmentAnimator.getEnter()); |
||||
} |
||||
return enterAnim; |
||||
} |
||||
|
||||
private Animation initExitAnim() { |
||||
if (fragmentAnimator.getExit() == 0) { |
||||
exitAnim = AnimationUtils.loadAnimation(context, R.anim.no_anim); |
||||
} else { |
||||
exitAnim = AnimationUtils.loadAnimation(context, fragmentAnimator.getExit()); |
||||
} |
||||
return exitAnim; |
||||
} |
||||
|
||||
private Animation initPopEnterAnim() { |
||||
if (fragmentAnimator.getPopEnter() == 0) { |
||||
popEnterAnim = AnimationUtils.loadAnimation(context, R.anim.no_anim); |
||||
} else { |
||||
popEnterAnim = AnimationUtils.loadAnimation(context, fragmentAnimator.getPopEnter()); |
||||
} |
||||
return popEnterAnim; |
||||
} |
||||
|
||||
private Animation initPopExitAnim() { |
||||
if (fragmentAnimator.getPopExit() == 0) { |
||||
popExitAnim = AnimationUtils.loadAnimation(context, R.anim.no_anim); |
||||
} else { |
||||
popExitAnim = AnimationUtils.loadAnimation(context, fragmentAnimator.getPopExit()); |
||||
} |
||||
return popExitAnim; |
||||
} |
||||
|
||||
Animation onCreateAnimation(BaseFragment baseFragment, int transit, boolean enter, int nextAnim) { |
||||
if (transit == FragmentTransaction.TRANSIT_FRAGMENT_OPEN) { |
||||
if (enter) { |
||||
return enterAnim; |
||||
} else { |
||||
return popExitAnim; |
||||
} |
||||
} else if (transit == FragmentTransaction.TRANSIT_FRAGMENT_CLOSE) { |
||||
if (enter) { |
||||
return popEnterAnim; |
||||
} else { |
||||
return exitAnim; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@ |
||||
package com.android.base.app.fragment; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import com.android.base.R; |
||||
|
||||
|
||||
public class DefaultHorizontalAnimator extends FragmentAnimator implements Parcelable { |
||||
|
||||
public DefaultHorizontalAnimator() { |
||||
enter = R.anim.h_fragment_enter; |
||||
exit = R.anim.h_fragment_exit; |
||||
popEnter = R.anim.h_fragment_pop_enter; |
||||
popExit = R.anim.h_fragment_pop_exit; |
||||
} |
||||
|
||||
protected DefaultHorizontalAnimator(Parcel in) { |
||||
super(in); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
super.writeToParcel(dest, flags); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public static final Creator<DefaultHorizontalAnimator> CREATOR = new Creator<DefaultHorizontalAnimator>() { |
||||
@Override |
||||
public DefaultHorizontalAnimator createFromParcel(Parcel in) { |
||||
return new DefaultHorizontalAnimator(in); |
||||
} |
||||
|
||||
@Override |
||||
public DefaultHorizontalAnimator[] newArray(int size) { |
||||
return new DefaultHorizontalAnimator[size]; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,42 @@ |
||||
package com.android.base.app.fragment; |
||||
|
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
public class DefaultNoAnimator extends FragmentAnimator implements Parcelable { |
||||
|
||||
public DefaultNoAnimator() { |
||||
enter = 0; |
||||
exit = 0; |
||||
popEnter = 0; |
||||
popExit = 0; |
||||
} |
||||
|
||||
protected DefaultNoAnimator(Parcel in) { |
||||
super(in); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
super.writeToParcel(dest, flags); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public static final Creator<DefaultNoAnimator> CREATOR = new Creator<DefaultNoAnimator>() { |
||||
@Override |
||||
public DefaultNoAnimator createFromParcel(Parcel in) { |
||||
return new DefaultNoAnimator(in); |
||||
} |
||||
|
||||
@Override |
||||
public DefaultNoAnimator[] newArray(int size) { |
||||
return new DefaultNoAnimator[size]; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,43 @@ |
||||
package com.android.base.app.fragment; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import com.android.base.R; |
||||
|
||||
public class DefaultVerticalAnimator extends FragmentAnimator implements Parcelable { |
||||
|
||||
public DefaultVerticalAnimator() { |
||||
enter = R.anim.v_fragment_enter; |
||||
exit = R.anim.v_fragment_exit; |
||||
popEnter = R.anim.v_fragment_pop_enter; |
||||
popExit = R.anim.v_fragment_pop_exit; |
||||
} |
||||
|
||||
protected DefaultVerticalAnimator(Parcel in) { |
||||
super(in); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
super.writeToParcel(dest, flags); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public static final Creator<DefaultVerticalAnimator> CREATOR = new Creator<DefaultVerticalAnimator>() { |
||||
@Override |
||||
public DefaultVerticalAnimator createFromParcel(Parcel in) { |
||||
return new DefaultVerticalAnimator(in); |
||||
} |
||||
|
||||
@Override |
||||
public DefaultVerticalAnimator[] newArray(int size) { |
||||
return new DefaultVerticalAnimator[size]; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,105 @@ |
||||
package com.android.base.app.fragment; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import androidx.annotation.AnimRes; |
||||
|
||||
public class FragmentAnimator implements Parcelable { |
||||
|
||||
@AnimRes protected int enter; |
||||
@AnimRes protected int exit; |
||||
@AnimRes protected int popEnter; |
||||
@AnimRes protected int popExit; |
||||
|
||||
public FragmentAnimator() { |
||||
} |
||||
|
||||
public FragmentAnimator(int enter, int exit) { |
||||
this.enter = enter; |
||||
this.exit = exit; |
||||
} |
||||
|
||||
public FragmentAnimator(int enter, int exit, int popEnter, int popExit) { |
||||
this.enter = enter; |
||||
this.exit = exit; |
||||
this.popEnter = popEnter; |
||||
this.popExit = popExit; |
||||
} |
||||
|
||||
public FragmentAnimator copy() { |
||||
return new FragmentAnimator(getEnter(), getExit(), getPopEnter(), getPopExit()); |
||||
} |
||||
|
||||
protected FragmentAnimator(Parcel in) { |
||||
enter = in.readInt(); |
||||
exit = in.readInt(); |
||||
popEnter = in.readInt(); |
||||
popExit = in.readInt(); |
||||
} |
||||
|
||||
public static final Creator<FragmentAnimator> CREATOR = new Creator<FragmentAnimator>() { |
||||
@Override |
||||
public FragmentAnimator createFromParcel(Parcel in) { |
||||
return new FragmentAnimator(in); |
||||
} |
||||
|
||||
@Override |
||||
public FragmentAnimator[] newArray(int size) { |
||||
return new FragmentAnimator[size]; |
||||
} |
||||
}; |
||||
|
||||
public int getEnter() { |
||||
return enter; |
||||
} |
||||
|
||||
public FragmentAnimator setEnter(int enter) { |
||||
this.enter = enter; |
||||
return this; |
||||
} |
||||
|
||||
public int getExit() { |
||||
return exit; |
||||
} |
||||
|
||||
/** |
||||
* enter animation |
||||
*/ |
||||
public FragmentAnimator setExit(int exit) { |
||||
this.exit = exit; |
||||
return this; |
||||
} |
||||
|
||||
public int getPopEnter() { |
||||
return popEnter; |
||||
} |
||||
|
||||
public FragmentAnimator setPopEnter(int popEnter) { |
||||
this.popEnter = popEnter; |
||||
return this; |
||||
} |
||||
|
||||
public int getPopExit() { |
||||
return popExit; |
||||
} |
||||
|
||||
public FragmentAnimator setPopExit(int popExit) { |
||||
this.popExit = popExit; |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
dest.writeInt(enter); |
||||
dest.writeInt(exit); |
||||
dest.writeInt(popEnter); |
||||
dest.writeInt(popExit); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<translate |
||||
android:duration="300" |
||||
android:fromXDelta="100%p" |
||||
android:interpolator="@android:anim/decelerate_interpolator" |
||||
android:toXDelta="0"/> |
||||
|
||||
</set> |
@ -0,0 +1,10 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<translate |
||||
android:duration="300" |
||||
android:fromXDelta="0" |
||||
android:interpolator="@android:anim/accelerate_interpolator" |
||||
android:toXDelta="100%p" /> |
||||
|
||||
</set> |
@ -0,0 +1,9 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:duration="300"> |
||||
|
||||
<translate |
||||
android:fromXDelta="-26%p" |
||||
android:toXDelta="0" /> |
||||
|
||||
</set> |
@ -0,0 +1,9 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:duration="300"> |
||||
|
||||
<translate |
||||
android:fromXDelta="0%p" |
||||
android:toXDelta="-26%p" /> |
||||
|
||||
</set> |
@ -0,0 +1,5 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:duration="0"> |
||||
|
||||
</set> |
@ -0,0 +1,9 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:duration="300"> |
||||
|
||||
<alpha |
||||
android:fromAlpha="1.0" |
||||
android:toAlpha="1.0" /> |
||||
|
||||
</set> |
@ -0,0 +1,40 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
/* |
||||
** Copyright 2009, The Android Open Source Project |
||||
** |
||||
** Licensed under the Apache License, Version 2.0 (the "License"); |
||||
** you may not use this file except in compliance with the License. |
||||
** You may obtain a copy of the License at |
||||
** |
||||
** http://www.apache.org/licenses/LICENSE-2.0 |
||||
** |
||||
** Unless required by applicable law or agreed to in writing, software |
||||
** distributed under the License is distributed on an "AS IS" BASIS, |
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
** See the License for the specific language governing permissions and |
||||
** limitations under the License. |
||||
*/ |
||||
--> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shareInterpolator="false" |
||||
android:zAdjustment="top"> |
||||
|
||||
<alpha |
||||
android:fromAlpha="0.0" |
||||
android:toAlpha="1.0" |
||||
android:interpolator="@android:anim/decelerate_interpolator" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="false" |
||||
android:fillAfter="true" |
||||
android:duration="200" /> |
||||
|
||||
<translate |
||||
android:fromYDelta="8%" |
||||
android:toYDelta="0" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="true" |
||||
android:fillAfter="true" |
||||
android:interpolator="@android:anim/decelerate_interpolator" |
||||
android:duration="300" /> |
||||
|
||||
</set> |
@ -0,0 +1,41 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
/* |
||||
** Copyright 2009, The Android Open Source Project |
||||
** |
||||
** Licensed under the Apache License, Version 2.0 (the "License"); |
||||
** you may not use this file except in compliance with the License. |
||||
** You may obtain a copy of the License at |
||||
** |
||||
** http://www.apache.org/licenses/LICENSE-2.0 |
||||
** |
||||
** Unless required by applicable law or agreed to in writing, software |
||||
** distributed under the License is distributed on an "AS IS" BASIS, |
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
** See the License for the specific language governing permissions and |
||||
** limitations under the License. |
||||
*/ |
||||
--> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:shareInterpolator="false" |
||||
android:zAdjustment="top"> |
||||
|
||||
<alpha |
||||
android:fromAlpha="1.0" |
||||
android:toAlpha="0.0" |
||||
android:interpolator="@android:anim/linear_interpolator" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="false" |
||||
android:fillAfter="true" |
||||
android:startOffset="100" |
||||
android:duration="150" /> |
||||
|
||||
<translate |
||||
android:fromYDelta="0%" |
||||
android:toYDelta="8%" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="true" |
||||
android:fillAfter="true" |
||||
android:interpolator="@android:anim/accelerate_interpolator" |
||||
android:duration="250" /> |
||||
|
||||
</set> |
@ -0,0 +1,30 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
/* |
||||
** Copyright 2009, The Android Open Source Project |
||||
** |
||||
** Licensed under the Apache License, Version 2.0 (the "License"); |
||||
** you may not use this file except in compliance with the License. |
||||
** You may obtain a copy of the License at |
||||
** |
||||
** http://www.apache.org/licenses/LICENSE-2.0 |
||||
** |
||||
** Unless required by applicable law or agreed to in writing, software |
||||
** distributed under the License is distributed on an "AS IS" BASIS, |
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
** See the License for the specific language governing permissions and |
||||
** limitations under the License. |
||||
*/ |
||||
--> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:zAdjustment="normal"> |
||||
|
||||
<alpha |
||||
android:fromAlpha="0.7" |
||||
android:toAlpha="1.0" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="true" |
||||
android:fillAfter="true" |
||||
android:interpolator="@android:anim/accelerate_interpolator" |
||||
android:duration="250" /> |
||||
|
||||
</set> |
@ -0,0 +1,30 @@ |
||||
<?xml version="1.0" encoding="utf-8"?><!-- |
||||
/* |
||||
** Copyright 2009, The Android Open Source Project |
||||
** |
||||
** Licensed under the Apache License, Version 2.0 (the "License"); |
||||
** you may not use this file except in compliance with the License. |
||||
** You may obtain a copy of the License at |
||||
** |
||||
** http://www.apache.org/licenses/LICENSE-2.0 |
||||
** |
||||
** Unless required by applicable law or agreed to in writing, software |
||||
** distributed under the License is distributed on an "AS IS" BASIS, |
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
** See the License for the specific language governing permissions and |
||||
** limitations under the License. |
||||
*/ |
||||
--> |
||||
<set xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:zAdjustment="normal"> |
||||
|
||||
<alpha |
||||
android:fromAlpha="1.0" |
||||
android:toAlpha="0.9" |
||||
android:fillEnabled="true" |
||||
android:fillBefore="false" |
||||
android:fillAfter="true" |
||||
android:interpolator="@android:anim/decelerate_interpolator" |
||||
android:duration="300" /> |
||||
|
||||
</set> |
Loading…
Reference in new issue