Skip to content

Commit

Permalink
fix bug: add transition animation to ActivityLauncher with fragment l…
Browse files Browse the repository at this point in the history
…aunch
  • Loading branch information
yjfnypeu committed Aug 30, 2017
1 parent 3a54ded commit 605b17d
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.content.Context;
import android.content.Intent;

import com.lzh.nonview.router.extras.RouteBundleExtras;

/**
* Default Activity Launcher for {@link com.lzh.nonview.router.route.ActivityRoute}
*/
Expand All @@ -39,27 +41,37 @@ public Intent createIntent(Context context) {
public void open(Fragment fragment) throws Exception {
Intent intent = createIntent(fragment.getActivity());
fragment.startActivityForResult(intent, extras.getRequestCode());
overridePendingTransition(fragment.getActivity(), extras);
}

@Override
public void open(android.support.v4.app.Fragment fragment) throws Exception {
Intent intent = createIntent(fragment.getContext());
fragment.startActivityForResult(intent, extras.getRequestCode());
overridePendingTransition(fragment.getActivity(), extras);
}

@Override
public void open(Context context) throws Exception{
Intent intent = createIntent(context);
if (context instanceof Activity) {
((Activity) context).startActivityForResult(intent,extras.getRequestCode());
int inAnimation = extras.getInAnimation();
int outAnimation = extras.getOutAnimation();
if (inAnimation >= 0 && outAnimation >= 0) {
((Activity) context).overridePendingTransition(inAnimation,outAnimation);
}
overridePendingTransition((Activity) context, extras);
} else {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}

protected void overridePendingTransition(Activity activity, RouteBundleExtras extras) {
if (activity == null || extras == null) {
return;
}

int inAnimation = extras.getInAnimation();
int outAnimation = extras.getOutAnimation();
if (inAnimation >= 0 && outAnimation >= 0) {
activity.overridePendingTransition(inAnimation,outAnimation);
}
}
}

0 comments on commit 605b17d

Please sign in to comment.