publicfinalclassPostcardextendsRouteMeta { // Base private Uri uri; private Object tag; // A tag prepare for some thing wrong. private Bundle mBundle; // Data to transform privateintflags= -1; // Flags of route privateinttimeout=300; // Navigation timeout, TimeUnit.Second private IProvider provider; // It will be set value, if this postcard was provider. privateboolean greenChannel; private SerializationService serializationService;
// Animation private Bundle optionsCompat; // The transition animation of activity privateintenterAnim= -1; privateintexitAnim= -1; //... }
private Object _navigation(final Context context, final Postcard postcard, finalint requestCode, final NavigationCallback callback) { // ... switch (postcard.getType()) { case ACTIVITY: // Build intent finalIntentintent=newIntent(currentContext, postcard.getDestination()); intent.putExtras(postcard.getExtras());
// Set flags. intflags= postcard.getFlags(); if (-1 != flags) { intent.setFlags(flags); } elseif (!(currentContext instanceof Activity)) { // Non activity, need less one flag. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); }
// Set Actions Stringaction= postcard.getAction(); if (!TextUtils.isEmpty(action)) { intent.setAction(action); }
// Navigation in main looper. runInMainThread(newRunnable() { @Override publicvoidrun() { startActivity(requestCode, currentContext, intent, postcard, callback); } });
break; case PROVIDER: return postcard.getProvider(); case BOARDCAST: case CONTENT_PROVIDER: case FRAGMENT: ClassfragmentMeta= postcard.getDestination(); try { Objectinstance= fragmentMeta.getConstructor().newInstance(); if (instance instanceof Fragment) { ((Fragment) instance).setArguments(postcard.getExtras()); } elseif (instance instanceof android.support.v4.app.Fragment) { ((android.support.v4.app.Fragment) instance).setArguments(postcard.getExtras()); }
return instance; } catch (Exception ex) { // ... } case METHOD: case SERVICE: default: returnnull; } returnnull; }