flutter_plugin_device_apps icon indicating copy to clipboard operation
flutter_plugin_device_apps copied to clipboard

[Feature request] Option to change 'openApp' transition

Open emvaized opened this issue 5 years ago • 9 comments

Currently the app opened with openApp method slides in. It will be great to provide functionality to customize this transition somehow - for example, make opened app scale up.

emvaized avatar May 12 '20 20:05 emvaized

Also trying to figure out how to do that..

Normally overridePendingTransition is used on Android, but I dont know yet how it applies to flutter.

cgestes avatar Jul 16 '20 23:07 cgestes

@cgestes I've also tried to implement this solution, but it didn't work either... Currently I'm stuck with disabling any animation at all, which is clumsy, but still better than standard slide-in transition in my opinion.

emvaized avatar Jul 18 '20 01:07 emvaized

I did use overridePendingTransition with success.

Opening: I call it just after startActivity Coming back from the launched app: I call it in onResume

Took me a long time to figure it out!

cgestes avatar Aug 16 '20 14:08 cgestes

@cgestes And what animation did you passed there? And where it was stored?

emvaized avatar Aug 16 '20 14:08 emvaized

I did:

overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

cgestes avatar Aug 16 '20 17:08 cgestes

@cgestes Sounds great! But in my case console complains that it can't resolve method overridePendingTransition. Maybe I miss some imports?

emvaized avatar Aug 17 '20 06:08 emvaized

It seems to be a method of the Activity android java class.

cgestes avatar Aug 17 '20 15:08 cgestes

@cgestes Well, seems I already had this imported in the file.. Screenshot_20200818_073817

Maybe you forgot to mention some extra steps that you did to make it work?

emvaized avatar Aug 18 '20 04:08 emvaized

@cgestes Well, seems I already had this imported in the file.. Screenshot_20200818_073817

Maybe you forgot to mention some extra steps that you did to make it work?

Little bit late with a reply to this, but I did the following and the animations changed as per the overridePendingTransitions value.

Import the following

import android.app.Activity;
import android.app.ActivityOptions;

Amend the openApp to the following

private boolean openApp(@NonNull String packageName) {
        if (!isAppInstalled(packageName)) {
            Log.w(LOG_TAG, "Application with package name \"" + packageName + "\" is not installed on this device");
            return false;
        }

        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);

        if (IntentUtils.isIntentOpenable(launchIntent, context)) {

            ActivityOptions options =
                    ActivityOptions.makeCustomAnimation(context, android.R.anim.fade_in, android.R.anim.fade_out);

            context.startActivity(launchIntent, options.toBundle());

            return true;
        }

        return false;
    }

When testing the animation now fades in on launching another application.

I've found a bit of a hack to be able to get the clipRevealAnimation to work, by passing the data of the scale, height and width down to the function, it works with the animation, but the offset on the screen doesn't always match up to where the onPress is being generated (in my case below I always want it to render from the middle of the screen, but the Y axis offset sometimes is a bit off when passing down the renderBox offset.

 private boolean openApp(@NonNull String packageName, int startX, int startY, int height, int width) {
        if (!isAppInstalled(packageName)) {
            Log.w(LOG_TAG, "Application with package name \"" + packageName + "\" is not installed on this device");
            return false;
        }

        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);

        if (IntentUtils.isIntentOpenable(launchIntent, context)) {

            View view = new View(context);
            view.setLayoutParams(new LayoutParams(height, width));

            int startingX = width / 2;
            int startingY = startY;

            ActivityOptions options = ActivityOptions.makeClipRevealAnimation(view, startingX, startingY, 0, 0);

            context.startActivity(launchIntent, options.toBundle());

            return true;
        }

        return false;
    }

Will see if I can improve this to get it to work as intended, and also as mentioned before getting the reverse animation to work when calling onResume

tomosullivan8 avatar Sep 12 '22 16:09 tomosullivan8