Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Animation on running new application

I'm creating new launcher for myself. now when I run applications from my main activity it has this default animation which put my launcher behind and pops new application on top of it. Instead of this, I want to attach my own animation. Preferably I want to default material animation revealing from touch point.

Things I have tried so far:

You need to use a Theme.AppCompat theme (or descendant) with this activity on Android

http://tips.androidhive.info/2015/09/android-how-to-apply-material-design-theme/

 <style name="swLaunch" parent="swLaunch.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/explode</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/explode</item>
    <item name="android:windowEnterAnimation">@android:transition/explode</item>
    <item name="android:windowExitAnimation">@android:transition/explode</item>
    <item name="android:taskToFrontEnterAnimation">@android:transition/explode</item>
    <item name="android:taskToBackEnterAnimation">@android:transition/explode</item>
    <item name="android:taskToFrontExitAnimation">@android:transition/explode</item>
    <item name="android:taskToBackExitAnimation">@android:transition/explode</item>
    <item name="android:inAnimation">@android:transition/explode</item>
    <item name="android:layoutAnimation">@android:transition/explode</item>
    <item name="android:windowShowAnimation">@android:transition/explode</item>
    <item name="android:activityOpenEnterAnimation">@android:transition/explode</item>
    <item name="android:fragmentOpenEnterAnimation">@android:transition/explode</item>
</style>

this is how I launch my applications:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
if (launchIntent != null) {
    startActivity(launchIntent);
}
like image 479
CBeTJlu4ok Avatar asked Nov 02 '16 09:11

CBeTJlu4ok


1 Answers

To animate starting an activity:

int left = 0, top = 0;
int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
ActivityOptions opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
startActivity(i, opts.toBundle());

where i is an Intent and v is a View

to animate going back to home screen (either by pressing Home button or Back button)

@Override
public void onResume() {
    super.onResume();
    // override default transition animation
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
like image 61
CBeTJlu4ok Avatar answered Nov 11 '22 04:11

CBeTJlu4ok