diff --git a/build.gradle b/build.gradle index 87b40877..82d92403 100755 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:2.2.2' } } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/ActivityHostedRouter.java b/conductor/src/main/java/com/bluelinelabs/conductor/ActivityHostedRouter.java index 4f9f3cc8..352ba6ad 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/ActivityHostedRouter.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/ActivityHostedRouter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.ViewGroup; import com.bluelinelabs.conductor.ControllerChangeHandler.ControllerChangeListener; @@ -30,13 +31,13 @@ public final void setHost(@NonNull LifecycleHandler lifecycleHandler, @NonNull V } } - @Override + @Override @Nullable public Activity getActivity() { return lifecycleHandler != null ? lifecycleHandler.getLifecycleActivity() : null; } @Override - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { super.onActivityDestroyed(activity); lifecycleHandler = null; } @@ -49,37 +50,37 @@ public final void invalidateOptionsMenu() { } @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { lifecycleHandler.onActivityResult(requestCode, resultCode, data); } @Override - void startActivity(Intent intent) { + void startActivity(@NonNull Intent intent) { lifecycleHandler.startActivity(intent); } @Override - void startActivityForResult(String instanceId, Intent intent, int requestCode) { + void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode) { lifecycleHandler.startActivityForResult(instanceId, intent, requestCode); } @Override - void startActivityForResult(String instanceId, Intent intent, int requestCode, Bundle options) { + void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode, @Nullable Bundle options) { lifecycleHandler.startActivityForResult(instanceId, intent, requestCode, options); } @Override - void registerForActivityResult(String instanceId, int requestCode) { + void registerForActivityResult(@NonNull String instanceId, int requestCode) { lifecycleHandler.registerForActivityResult(instanceId, requestCode); } @Override - void unregisterForActivityResults(String instanceId) { + void unregisterForActivityResults(@NonNull String instanceId) { lifecycleHandler.unregisterForActivityResults(instanceId); } @Override - void requestPermissions(String instanceId, @NonNull String[] permissions, int requestCode) { + void requestPermissions(@NonNull String instanceId, @NonNull String[] permissions, int requestCode) { lifecycleHandler.requestPermissions(instanceId, permissions, requestCode); } @@ -88,12 +89,12 @@ boolean hasHost() { return lifecycleHandler != null; } - @Override + @Override @NonNull List getSiblingRouters() { return lifecycleHandler.getRouters(); } - @Override + @Override @NonNull Router getRootRouter() { return this; } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/Backstack.java b/conductor/src/main/java/com/bluelinelabs/conductor/Backstack.java index 3ac02106..2563966c 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/Backstack.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/Backstack.java @@ -1,6 +1,8 @@ package com.bluelinelabs.conductor; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.util.ArrayDeque; import java.util.ArrayList; @@ -24,20 +26,23 @@ public int size() { return backStack.size(); } + @Nullable public RouterTransaction root() { return backStack.size() > 0 ? backStack.getLast() : null; } - @Override + @Override @NonNull public Iterator iterator() { return backStack.iterator(); } + @NonNull public Iterator reverseIterator() { return backStack.descendingIterator(); } - public List popTo(RouterTransaction transaction) { + @NonNull + public List popTo(@NonNull RouterTransaction transaction) { List popped = new ArrayList<>(); if (backStack.contains(transaction)) { while (backStack.peek() != transaction) { @@ -50,24 +55,27 @@ public List popTo(RouterTransaction transaction) { return popped; } + @NonNull public RouterTransaction pop() { RouterTransaction popped = backStack.pop(); popped.controller.destroy(); return popped; } + @Nullable public RouterTransaction peek() { return backStack.peek(); } - public void remove(RouterTransaction transaction) { + public void remove(@NonNull RouterTransaction transaction) { backStack.removeFirstOccurrence(transaction); } - public void push(RouterTransaction transaction) { + public void push(@NonNull RouterTransaction transaction) { backStack.push(transaction); } + @NonNull public List popAll() { List list = new ArrayList<>(); while (!isEmpty()) { @@ -76,7 +84,7 @@ public List popAll() { return list; } - public void setBackstack(List backstack) { + public void setBackstack(@NonNull List backstack) { for (RouterTransaction existingTransaction : backStack) { boolean contains = false; for (RouterTransaction newTransaction : backstack) { @@ -97,7 +105,7 @@ public void setBackstack(List backstack) { } } - public void saveInstanceState(Bundle outState) { + public void saveInstanceState(@NonNull Bundle outState) { ArrayList entryBundles = new ArrayList<>(backStack.size()); for (RouterTransaction entry : backStack) { entryBundles.add(entry.saveInstanceState()); @@ -106,7 +114,7 @@ public void saveInstanceState(Bundle outState) { outState.putParcelableArrayList(KEY_ENTRIES, entryBundles); } - public void restoreInstanceState(Bundle savedInstanceState) { + public void restoreInstanceState(@NonNull Bundle savedInstanceState) { ArrayList entryBundles = savedInstanceState.getParcelableArrayList(KEY_ENTRIES); if (entryBundles != null) { Collections.reverse(entryBundles); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/ChangeHandlerFrameLayout.java b/conductor/src/main/java/com/bluelinelabs/conductor/ChangeHandlerFrameLayout.java index 89eb4be6..50eefd0c 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/ChangeHandlerFrameLayout.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/ChangeHandlerFrameLayout.java @@ -3,6 +3,8 @@ import android.annotation.TargetApi; import android.content.Context; import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewGroup; @@ -42,12 +44,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { } @Override - public void onChangeStarted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) { + public void onChangeStarted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) { inProgressTransactionCount++; } @Override - public void onChangeCompleted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) { + public void onChangeCompleted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) { inProgressTransactionCount--; } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/Conductor.java b/conductor/src/main/java/com/bluelinelabs/conductor/Conductor.java index 3bc84704..63ff6850 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/Conductor.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/Conductor.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.ViewGroup; import com.bluelinelabs.conductor.internal.LifecycleHandler; @@ -26,7 +27,8 @@ private Conductor() {} * for restoring the Router's state if possible. * @return A fully configured {@link Router} instance for use with this Activity/ViewGroup pair. */ - public static Router attachRouter(@NonNull Activity activity, @NonNull ViewGroup container, Bundle savedInstanceState) { + @NonNull + public static Router attachRouter(@NonNull Activity activity, @NonNull ViewGroup container, @Nullable Bundle savedInstanceState) { LifecycleHandler lifecycleHandler = LifecycleHandler.install(activity); Router router = lifecycleHandler.getRouter(container, savedInstanceState); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java b/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java index 08d6c95f..4ca9dafe 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java @@ -10,6 +10,7 @@ import android.os.Parcelable; import android.support.annotation.IdRes; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.SparseArray; import android.view.LayoutInflater; @@ -90,17 +91,18 @@ public abstract class Controller { private final ControllerChangeListener childRouterChangeListener = new ControllerChangeListener() { @Override - public void onChangeStarted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) { + public void onChangeStarted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) { if (isPush) { onChildControllerPushed(to); } } @Override - public void onChangeCompleted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler) { } + public void onChangeCompleted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler) { } }; - static Controller newInstance(Bundle bundle) { + @NonNull + static Controller newInstance(@NonNull Bundle bundle) { final String className = bundle.getString(KEY_CLASS_NAME); //noinspection ConstantConditions Constructor[] constructors = ClassUtils.classForName(className, false).getConstructors(); @@ -134,7 +136,7 @@ protected Controller() { * * @param args Any arguments that need to be retained. */ - protected Controller(Bundle args) { + protected Controller(@Nullable Bundle args) { this.args = args; instanceId = UUID.randomUUID().toString(); ensureRequiredConstructor(); @@ -163,11 +165,19 @@ public final Router getRouter() { /** * Returns any arguments that were set in this Controller's constructor */ + @Nullable public Bundle getArgs() { return args; } - public final Router getChildRouter(@NonNull ViewGroup container, String tag) { + @NonNull + public final Router getChildRouter(@NonNull ViewGroup container) { + //noinspection deprecation + return getChildRouter(container, null); + } + + @Deprecated @NonNull + public final Router getChildRouter(@NonNull ViewGroup container, @Nullable String tag) { @IdRes final int containerId = container.getId(); ControllerHostedRouter childRouter = null; @@ -222,6 +232,7 @@ public final boolean isAttached() { /** * Return this Controller's View, if available. */ + @Nullable public final View getView() { return view; } @@ -229,6 +240,7 @@ public final View getView() { /** * Returns the host Activity of this Controller's {@link Router} */ + @Nullable public final Activity getActivity() { return router.getActivity(); } @@ -236,6 +248,7 @@ public final Activity getActivity() { /** * Returns the Resources from the host Activity */ + @Nullable public final Resources getResources() { Activity activity = getActivity(); return activity != null ? activity.getResources() : null; @@ -244,6 +257,7 @@ public final Resources getResources() { /** * Returns the Application Context derived from the host Activity */ + @Nullable public final Context getApplicationContext() { Activity activity = getActivity(); return activity != null ? activity.getApplicationContext() : null; @@ -252,6 +266,7 @@ public final Context getApplicationContext() { /** * Returns this Controller's parent Controller if it is a child Controller. */ + @Nullable public final Controller getParentController() { return parentController; } @@ -260,6 +275,7 @@ public final Controller getParentController() { * Returns this Controller's instance ID, which is generated when the instance is created and * retained across restarts. */ + @NonNull public final String getInstanceId() { return instanceId; } @@ -270,7 +286,8 @@ public final String getInstanceId() { * @param instanceId The instance ID being searched for * @return The matching Controller, if one exists */ - final Controller findController(String instanceId) { + @Nullable + final Controller findController(@NonNull String instanceId) { if (this.instanceId.equals(instanceId)) { return this; } @@ -287,6 +304,7 @@ final Controller findController(String instanceId) { /** * Returns all of this Controller's child Routers */ + @NonNull public final List getChildRouters() { List routers = new ArrayList<>(); for (Router router : childRouters) { @@ -302,7 +320,7 @@ public final List getChildRouters() { * * @param target The Controller that is the target of this one. */ - public void setTargetController(Controller target) { + public void setTargetController(@Nullable Controller target) { if (targetInstanceId != null) { throw new RuntimeException("Target controller already set. A controller's target may only be set once."); } @@ -315,6 +333,7 @@ public void setTargetController(Controller target) { * * @return This Controller's target */ + @Nullable public final Controller getTargetController() { if (targetInstanceId != null) { return router.getRootRouter().getControllerWithInstanceId(targetInstanceId); @@ -328,7 +347,7 @@ public final Controller getTargetController() { * * @param view The View to which this Controller should be bound. */ - protected void onDestroyView(View view) { } + protected void onDestroyView(@NonNull View view) { } /** * Called when this Controller begins the process of being swapped in or out of the host view. @@ -368,22 +387,22 @@ protected void onDestroy() { } /** * Called when this Controller's host Activity is started */ - protected void onActivityStarted(Activity activity) { } + protected void onActivityStarted(@NonNull Activity activity) { } /** * Called when this Controller's host Activity is resumed */ - protected void onActivityResumed(Activity activity) { } + protected void onActivityResumed(@NonNull Activity activity) { } /** * Called when this Controller's host Activity is paused */ - protected void onActivityPaused(Activity activity) { } + protected void onActivityPaused(@NonNull Activity activity) { } /** * Called when this Controller's host Activity is stopped */ - protected void onActivityStopped(Activity activity) { } + protected void onActivityStopped(@NonNull Activity activity) { } /** * Called to save this Controller's View state. As Views can be detached and destroyed as part of the @@ -422,7 +441,7 @@ protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { } /** * Calls startActivity(Intent) from this Controller's host Activity. */ - public final void startActivity(final Intent intent) { + public final void startActivity(@NonNull final Intent intent) { executeWithRouter(new RouterRequiringFunc() { @Override public void execute() { router.startActivity(intent); } }); @@ -431,7 +450,7 @@ public final void startActivity(final Intent intent) { /** * Calls startActivityForResult(Intent, int) from this Controller's host Activity. */ - public final void startActivityForResult(final Intent intent, final int requestCode) { + public final void startActivityForResult(@NonNull final Intent intent, final int requestCode) { executeWithRouter(new RouterRequiringFunc() { @Override public void execute() { router.startActivityForResult(instanceId, intent, requestCode); } }); @@ -440,7 +459,7 @@ public final void startActivityForResult(final Intent intent, final int requestC /** * Calls startActivityForResult(Intent, int, Bundle) from this Controller's host Activity. */ - public final void startActivityForResult(final Intent intent, final int requestCode, final Bundle options) { + public final void startActivityForResult(@NonNull final Intent intent, final int requestCode, @Nullable final Bundle options) { executeWithRouter(new RouterRequiringFunc() { @Override public void execute() { router.startActivityForResult(instanceId, intent, requestCode, options); } }); @@ -466,7 +485,7 @@ public final void registerForActivityResult(final int requestCode) { * @param resultCode The resultCode that was returned to the host Activity's onActivityResult method * @param data The data Intent that was returned to the host Activity's onActivityResult method */ - public void onActivityResult(int requestCode, int resultCode, Intent data) { } + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { } /** * Calls requestPermission(String[], int) from this Controller's host Activity. Results for this request, @@ -523,7 +542,7 @@ public boolean handleBack() { * * @param lifecycleListener The listener */ - public void addLifecycleListener(LifecycleListener lifecycleListener) { + public void addLifecycleListener(@NonNull LifecycleListener lifecycleListener) { if (!lifecycleListeners.contains(lifecycleListener)) { lifecycleListeners.add(lifecycleListener); } @@ -534,13 +553,14 @@ public void addLifecycleListener(LifecycleListener lifecycleListener) { * * @param lifecycleListener The listener to be removed */ - public void removeLifecycleListener(LifecycleListener lifecycleListener) { + public void removeLifecycleListener(@NonNull LifecycleListener lifecycleListener) { lifecycleListeners.remove(lifecycleListener); } /** * Returns this Controller's {@link RetainViewMode}. Defaults to {@link RetainViewMode#RELEASE_DETACH}. */ + @NonNull public RetainViewMode getRetainViewMode() { return retainViewMode; } @@ -549,8 +569,8 @@ public RetainViewMode getRetainViewMode() { * Sets this Controller's {@link RetainViewMode}, which will influence when its view will be released. * This is useful when a Controller's view hierarchy is expensive to tear down and rebuild. */ - public void setRetainViewMode(RetainViewMode retainViewMode) { - this.retainViewMode = retainViewMode; + public void setRetainViewMode(@NonNull RetainViewMode retainViewMode) { + this.retainViewMode = retainViewMode != null ? retainViewMode : RetainViewMode.RELEASE_DETACH; if (this.retainViewMode == RetainViewMode.RELEASE_DETACH && !attached) { removeViewReference(); } @@ -560,6 +580,7 @@ public void setRetainViewMode(RetainViewMode retainViewMode) { * Returns the {@link ControllerChangeHandler} that should be used for pushing this Controller, or null * if the handler from the {@link RouterTransaction} should be used instead. */ + @Nullable public final ControllerChangeHandler getOverriddenPushHandler() { return overriddenPushHandler; } @@ -568,7 +589,7 @@ public final ControllerChangeHandler getOverriddenPushHandler() { * Overrides the {@link ControllerChangeHandler} that should be used for pushing this Controller. If this is a * non-null value, it will be used instead of the handler from the {@link RouterTransaction}. */ - public void overridePushHandler(ControllerChangeHandler overriddenPushHandler) { + public void overridePushHandler(@Nullable ControllerChangeHandler overriddenPushHandler) { this.overriddenPushHandler = overriddenPushHandler; } @@ -576,6 +597,7 @@ public void overridePushHandler(ControllerChangeHandler overriddenPushHandler) { * Returns the {@link ControllerChangeHandler} that should be used for popping this Controller, or null * if the handler from the {@link RouterTransaction} should be used instead. */ + @Nullable public ControllerChangeHandler getOverriddenPopHandler() { return overriddenPopHandler; } @@ -584,7 +606,7 @@ public ControllerChangeHandler getOverriddenPopHandler() { * Overrides the {@link ControllerChangeHandler} that should be used for popping this Controller. If this is a * non-null value, it will be used instead of the handler from the {@link RouterTransaction}. */ - public void overridePopHandler(ControllerChangeHandler overriddenPopHandler) { + public void overridePopHandler(@Nullable ControllerChangeHandler overriddenPopHandler) { this.overriddenPopHandler = overriddenPopHandler; } @@ -628,7 +650,7 @@ public final void setOptionsMenuHidden(boolean optionsMenuHidden) { * @param menu The menu into which your options should be placed. * @param inflater The inflater that can be used to inflate your menu items. */ - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } + public void onCreateOptionsMenu(@Nullable Menu menu, @Nullable MenuInflater inflater) { } /** * Prepare the screen's options menu to be displayed. This is called directly before showing the @@ -636,7 +658,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } * * @param menu The menu that will be displayed */ - public void onPrepareOptionsMenu(Menu menu) { } + public void onPrepareOptionsMenu(@Nullable Menu menu) { } /** * Called when an option menu item has been selected by the user. @@ -644,7 +666,7 @@ public void onPrepareOptionsMenu(Menu menu) { } * @param item The selected item. * @return True if this event has been consumed, false if it has not. */ - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(@Nullable MenuItem item) { return false; } @@ -696,11 +718,11 @@ final void executeWithRouter(@NonNull RouterRequiringFunc listener) { } } - final void activityStarted(Activity activity) { + final void activityStarted(@NonNull Activity activity) { onActivityStarted(activity); } - final void activityResumed(Activity activity) { + final void activityResumed(@NonNull Activity activity) { if (!attached && view != null && viewIsAttached) { attach(view); } else if (attached) { @@ -710,11 +732,11 @@ final void activityResumed(Activity activity) { onActivityResumed(activity); } - final void activityPaused(Activity activity) { + final void activityPaused(@NonNull Activity activity) { onActivityPaused(activity); } - final void activityStopped(Activity activity) { + final void activityStopped(@NonNull Activity activity) { onActivityStopped(activity); } @@ -1034,7 +1056,7 @@ private void performOnRestoreInstanceState() { } } - final void changeStarted(ControllerChangeHandler changeHandler, ControllerChangeType changeType) { + final void changeStarted(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { if (!changeType.isEnter) { for (ControllerHostedRouter router : childRouters) { router.setDetachFrozen(true); @@ -1049,7 +1071,7 @@ final void changeStarted(ControllerChangeHandler changeHandler, ControllerChange } } - final void changeEnded(ControllerChangeHandler changeHandler, ControllerChangeType changeType) { + final void changeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { if (!changeType.isEnter) { for (ControllerHostedRouter router : childRouters) { router.setDetachFrozen(false); @@ -1086,27 +1108,27 @@ final void setDetachFrozen(boolean frozen) { } } - final void createOptionsMenu(Menu menu, MenuInflater inflater) { + final void createOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { if (attached && hasOptionsMenu && !optionsMenuHidden) { onCreateOptionsMenu(menu, inflater); } } - final void prepareOptionsMenu(Menu menu) { + final void prepareOptionsMenu(@NonNull Menu menu) { if (attached && hasOptionsMenu && !optionsMenuHidden) { onPrepareOptionsMenu(menu); } } - final boolean optionsItemSelected(MenuItem item) { + final boolean optionsItemSelected(@NonNull MenuItem item) { return attached && hasOptionsMenu && !optionsMenuHidden && onOptionsItemSelected(item); } - private void monitorChildRouter(ControllerHostedRouter childRouter) { + private void monitorChildRouter(@NonNull ControllerHostedRouter childRouter) { childRouter.addChangeListener(childRouterChangeListener); } - private void onChildControllerPushed(Controller controller) { + private void onChildControllerPushed(@NonNull Controller controller) { if (!childBackstack.contains(controller)) { childBackstack.add(controller); controller.addLifecycleListener(new LifecycleListener() { @@ -1118,7 +1140,7 @@ public void postDestroy(@NonNull Controller controller) { } } - final void setParentController(Controller controller) { + final void setParentController(@Nullable Controller controller) { parentController = controller; } @@ -1129,7 +1151,8 @@ private void ensureRequiredConstructor() { } } - private static Constructor getDefaultConstructor(Constructor[] constructors) { + @Nullable + private static Constructor getDefaultConstructor(@NonNull Constructor[] constructors) { for (Constructor constructor : constructors) { if (constructor.getParameterTypes().length == 0) { return constructor; @@ -1138,7 +1161,8 @@ private static Constructor getDefaultConstructor(Constructor[] constructors) { return null; } - private static Constructor getBundleConstructor(Constructor[] constructors) { + @Nullable + private static Constructor getBundleConstructor(@NonNull Constructor[] constructors) { for (Constructor constructor : constructors) { if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == Bundle.class) { return constructor; diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/ControllerChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/ControllerChangeHandler.java index 1e137e5b..d4277f63 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/ControllerChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/ControllerChangeHandler.java @@ -2,6 +2,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; @@ -37,7 +38,7 @@ public abstract class ControllerChangeHandler { * @param isPush True if this is a push transaction, false if it's a pop. * @param changeListener This listener must be called when any transitions or animations are completed. */ - public abstract void performChange(@NonNull ViewGroup container, View from, View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener); + public abstract void performChange(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener); public ControllerChangeHandler() { ensureDefaultConstructor(); @@ -64,7 +65,7 @@ public void restoreFromBundle(@NonNull Bundle bundle) { } * @param newHandler the change handler that has caused this push to be aborted * @param newTop the controller that will now be at the top of the backstack */ - public void onAbortPush(@NonNull ControllerChangeHandler newHandler, Controller newTop) { } + public void onAbortPush(@NonNull ControllerChangeHandler newHandler, @Nullable Controller newTop) { } /** * Will be called on change handlers that push a controller if the controller being pushed is @@ -72,6 +73,7 @@ public void onAbortPush(@NonNull ControllerChangeHandler newHandler, Controller */ public void completeImmediately() { } + @NonNull final Bundle toBundle() { Bundle bundle = new Bundle(); bundle.putString(KEY_CLASS_NAME, getClass().getName()); @@ -83,6 +85,7 @@ final Bundle toBundle() { return bundle; } + @NonNull final ControllerChangeHandler copy() { return fromBundle(toBundle()); } @@ -95,7 +98,8 @@ private void ensureDefaultConstructor() { } } - public static ControllerChangeHandler fromBundle(Bundle bundle) { + @Nullable + public static ControllerChangeHandler fromBundle(@Nullable Bundle bundle) { if (bundle != null) { String className = bundle.getString(KEY_CLASS_NAME); ControllerChangeHandler changeHandler = ClassUtils.newInstance(className); @@ -107,7 +111,7 @@ public static ControllerChangeHandler fromBundle(Bundle bundle) { } } - static boolean completePushImmediately(String controllerInstanceId) { + static boolean completePushImmediately(@NonNull String controllerInstanceId) { ControllerChangeHandler changeHandler = inProgressPushHandlers.get(controllerInstanceId); if (changeHandler != null) { changeHandler.completeImmediately(); @@ -117,7 +121,7 @@ static boolean completePushImmediately(String controllerInstanceId) { return false; } - public static void abortPush(Controller toAbort, Controller newController, ControllerChangeHandler newChangeHandler) { + public static void abortPush(@NonNull Controller toAbort, @Nullable Controller newController, @NonNull ControllerChangeHandler newChangeHandler) { ControllerChangeHandler handlerForPush = inProgressPushHandlers.get(toAbort.getInstanceId()); if (handlerForPush != null) { handlerForPush.onAbortPush(newChangeHandler, newController); @@ -125,11 +129,11 @@ public static void abortPush(Controller toAbort, Controller newController, Contr } } - public static void executeChange(final Controller to, final Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler inHandler) { + public static void executeChange(@Nullable final Controller to, @Nullable final Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler inHandler) { executeChange(to, from, isPush, container, inHandler, new ArrayList()); } - public static void executeChange(final Controller to, final Controller from, final boolean isPush, final ViewGroup container, final ControllerChangeHandler inHandler, @NonNull final List listeners) { + public static void executeChange(@Nullable final Controller to, @Nullable final Controller from, final boolean isPush, @Nullable final ViewGroup container, @Nullable final ControllerChangeHandler inHandler, @NonNull final List listeners) { if (container != null) { final ControllerChangeHandler handler = inHandler != null ? inHandler : new SimpleSwapChangeHandler(); @@ -140,7 +144,7 @@ public static void executeChange(final Controller to, final Controller from, fin } for (ControllerChangeListener listener : listeners) { - listener.onChangeStarted(to, from, isPush, container, inHandler); + listener.onChangeStarted(to, from, isPush, container, handler); } final ControllerChangeType toChangeType = isPush ? ControllerChangeType.PUSH_ENTER : ControllerChangeType.POP_ENTER; @@ -175,7 +179,7 @@ public void onChangeCompleted() { } for (ControllerChangeListener listener : listeners) { - listener.onChangeCompleted(to, from, isPush, container, inHandler); + listener.onChangeCompleted(to, from, isPush, container, handler); } if (handler.forceRemoveViewOnPush && fromView != null) { @@ -210,7 +214,7 @@ public interface ControllerChangeListener { * @param container The containing ViewGroup * @param handler The change handler being used. */ - void onChangeStarted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler); + void onChangeStarted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler); /** * Called when a {@link ControllerChangeHandler} has completed changing {@link Controller}s @@ -221,7 +225,7 @@ public interface ControllerChangeListener { * @param container The containing ViewGroup * @param handler The change handler that was used. */ - void onChangeCompleted(Controller to, Controller from, boolean isPush, ViewGroup container, ControllerChangeHandler handler); + void onChangeCompleted(@Nullable Controller to, @Nullable Controller from, boolean isPush, @NonNull ViewGroup container, @NonNull ControllerChangeHandler handler); } /** diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/ControllerHostedRouter.java b/conductor/src/main/java/com/bluelinelabs/conductor/ControllerHostedRouter.java index 50b42848..0b4e3283 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/ControllerHostedRouter.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/ControllerHostedRouter.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.support.annotation.IdRes; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.ViewGroup; import com.bluelinelabs.conductor.ControllerChangeHandler.ControllerChangeListener; @@ -24,7 +25,7 @@ class ControllerHostedRouter extends Router { ControllerHostedRouter() { } - ControllerHostedRouter(int hostId, String tag) { + ControllerHostedRouter(int hostId, @Nullable String tag) { this.hostId = hostId; this.tag = tag; } @@ -76,20 +77,20 @@ void destroy() { super.destroy(); } - @Override + @Override @Nullable public Activity getActivity() { return hostController != null ? hostController.getActivity() : null; } @Override - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { super.onActivityDestroyed(activity); removeHost(); } @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { + public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().onActivityResult(requestCode, resultCode, data); } @@ -103,42 +104,42 @@ public void invalidateOptionsMenu() { } @Override - void startActivity(Intent intent) { + void startActivity(@NonNull Intent intent) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().startActivity(intent); } } @Override - void startActivityForResult(String instanceId, Intent intent, int requestCode) { + void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().startActivityForResult(instanceId, intent, requestCode); } } @Override - void startActivityForResult(String instanceId, Intent intent, int requestCode, Bundle options) { + void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode, @Nullable Bundle options) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().startActivityForResult(instanceId, intent, requestCode, options); } } @Override - void registerForActivityResult(String instanceId, int requestCode) { + void registerForActivityResult(@NonNull String instanceId, int requestCode) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().registerForActivityResult(instanceId, requestCode); } } @Override - void unregisterForActivityResults(String instanceId) { + void unregisterForActivityResults(@NonNull String instanceId) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().unregisterForActivityResults(instanceId); } } @Override - void requestPermissions(String instanceId, String[] permissions, int requestCode) { + void requestPermissions(@NonNull String instanceId, @NonNull String[] permissions, int requestCode) { if (hostController != null && hostController.getRouter() != null) { hostController.getRouter().requestPermissions(instanceId, permissions, requestCode); } @@ -150,7 +151,7 @@ boolean hasHost() { } @Override - public void saveInstanceState(Bundle outState) { + public void saveInstanceState(@NonNull Bundle outState) { super.saveInstanceState(outState); outState.putInt(KEY_HOST_ID, hostId); @@ -158,7 +159,7 @@ public void saveInstanceState(Bundle outState) { } @Override - public void restoreInstanceState(Bundle savedInstanceState) { + public void restoreInstanceState(@NonNull Bundle savedInstanceState) { super.restoreInstanceState(savedInstanceState); hostId = savedInstanceState.getInt(KEY_HOST_ID); @@ -166,7 +167,7 @@ public void restoreInstanceState(Bundle savedInstanceState) { } @Override - void setControllerRouter(Controller controller) { + void setControllerRouter(@NonNull Controller controller) { super.setControllerRouter(controller); controller.setParentController(hostController); } @@ -175,11 +176,12 @@ int getHostId() { return hostId; } + @Nullable String getTag() { return tag; } - @Override + @Override @NonNull List getSiblingRouters() { List list = new ArrayList<>(); list.addAll(hostController.getChildRouters()); @@ -187,7 +189,7 @@ List getSiblingRouters() { return list; } - @Override + @Override @NonNull Router getRootRouter() { if (hostController != null && hostController.getRouter() != null) { return hostController.getRouter().getRootRouter(); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/RestoreViewOnCreateController.java b/conductor/src/main/java/com/bluelinelabs/conductor/RestoreViewOnCreateController.java index 1d9a2aa8..3b9160ef 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/RestoreViewOnCreateController.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/RestoreViewOnCreateController.java @@ -26,12 +26,11 @@ protected RestoreViewOnCreateController() { * * @param args Any arguments that need to be retained. */ - protected RestoreViewOnCreateController(Bundle args) { + protected RestoreViewOnCreateController(@Nullable Bundle args) { super(args); } - @NonNull - @Override + @Override @NonNull protected final View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { return onCreateView(inflater, container, viewState); } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/Router.java b/conductor/src/main/java/com/bluelinelabs/conductor/Router.java index 77aa2742..9c6f9002 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/Router.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/Router.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -41,6 +42,7 @@ public abstract class Router { /** * Returns this Router's host Activity */ + @Nullable public abstract Activity getActivity(); /** @@ -51,7 +53,7 @@ public abstract class Router { * @param resultCode The Activity's onActivityResult resultCode * @param data The Activity's onActivityResult data */ - public abstract void onActivityResult(int requestCode, int resultCode, Intent data); + public abstract void onActivityResult(int requestCode, int resultCode, @Nullable Intent data); /** * This should be called by the host Activity when its onRequestPermissionsResult method is called. The call will be forwarded @@ -62,7 +64,7 @@ public abstract class Router { * @param permissions The Activity's onRequestPermissionsResult permissions * @param grantResults The Activity's onRequestPermissionsResult grantResults */ - public void onRequestPermissionsResult(String instanceId, int requestCode, String[] permissions, int[] grantResults) { + public void onRequestPermissionsResult(@NonNull String instanceId, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { Controller controller = getControllerWithInstanceId(instanceId); if (controller != null) { controller.requestPermissionsResult(requestCode, permissions, grantResults); @@ -77,6 +79,7 @@ public void onRequestPermissionsResult(String instanceId, int requestCode, Strin */ public boolean handleBack() { if (!backstack.isEmpty()) { + //noinspection ConstantConditions if (backstack.peek().controller.handleBack()) { return true; } else if (popCurrentController()) { @@ -93,7 +96,11 @@ public boolean handleBack() { * @return Whether or not this Router still has controllers remaining on it after popping. */ public boolean popCurrentController() { - return popController(backstack.peek().controller); + RouterTransaction transaction = backstack.peek(); + if (transaction == null) { + throw new IllegalStateException("Trying to pop the current controller when there are none on the backstack."); + } + return popController(transaction.controller); } /** @@ -102,7 +109,7 @@ public boolean popCurrentController() { * @param controller The controller that should be popped from this Router * @return Whether or not this Router still has controllers remaining on it after popping. */ - public boolean popController(Controller controller) { + public boolean popController(@NonNull Controller controller) { RouterTransaction topController = backstack.peek(); boolean poppingTopController = topController != null && topController.controller == controller; @@ -153,11 +160,13 @@ public void replaceTopController(@NonNull RouterTransaction transaction) { } final ControllerChangeHandler handler = transaction.pushChangeHandler(); - final boolean oldHandlerRemovedViews = topTransaction.pushChangeHandler() == null || topTransaction.pushChangeHandler().removesFromViewOnPush(); - final boolean newHandlerRemovesViews = handler == null || handler.removesFromViewOnPush(); - if (!oldHandlerRemovedViews && newHandlerRemovesViews) { - for (RouterTransaction visibleTransaction : getVisibleTransactions(backstack.iterator())) { - performControllerChange(null, visibleTransaction.controller, true, handler != null ? handler.copy() : new SimpleSwapChangeHandler()); + if (topTransaction != null) { + final boolean oldHandlerRemovedViews = topTransaction.pushChangeHandler() == null || topTransaction.pushChangeHandler().removesFromViewOnPush(); + final boolean newHandlerRemovesViews = handler == null || handler.removesFromViewOnPush(); + if (!oldHandlerRemovedViews && newHandlerRemovesViews) { + for (RouterTransaction visibleTransaction : getVisibleTransactions(backstack.iterator())) { + performControllerChange(null, visibleTransaction.controller, true, handler != null ? handler.copy() : new SimpleSwapChangeHandler()); + } } } @@ -189,6 +198,7 @@ public int getContainerId() { * in the stack. This defaults to false so that the developer can either finish its containing Activity or otherwise * hide its parent view without any strange artifacting. */ + @NonNull public Router setPopsLastView(boolean popsLastView) { this.popsLastView = popsLastView; return this; @@ -209,8 +219,9 @@ public boolean popToRoot() { * @param changeHandler The {@link ControllerChangeHandler} to handle this transaction * @return Whether or not any {@link Controller}s were popped in order to get to the root transaction */ - public boolean popToRoot(ControllerChangeHandler changeHandler) { + public boolean popToRoot(@Nullable ControllerChangeHandler changeHandler) { if (backstack.size() > 1) { + //noinspection ConstantConditions popToTransaction(backstack.root(), changeHandler); return true; } else { @@ -235,7 +246,7 @@ public boolean popToTag(@NonNull String tag) { * @param changeHandler The {@link ControllerChangeHandler} to handle this transaction * @return Whether or not the {@link Controller} with the passed tag is now at the top */ - public boolean popToTag(@NonNull String tag, ControllerChangeHandler changeHandler) { + public boolean popToTag(@NonNull String tag, @Nullable ControllerChangeHandler changeHandler) { for (RouterTransaction transaction : backstack) { if (tag.equals(transaction.tag())) { popToTransaction(transaction, changeHandler); @@ -283,7 +294,8 @@ public void setRoot(@NonNull RouterTransaction transaction) { * @param instanceId The instance ID being searched for * @return The matching Controller, if one exists */ - public Controller getControllerWithInstanceId(String instanceId) { + @Nullable + public Controller getControllerWithInstanceId(@NonNull String instanceId) { for (RouterTransaction transaction : backstack) { Controller controllerWithId = transaction.controller.findController(instanceId); if (controllerWithId != null) { @@ -299,7 +311,8 @@ public Controller getControllerWithInstanceId(String instanceId) { * @param tag The tag being searched for * @return The matching Controller, if one exists */ - public Controller getControllerWithTag(String tag) { + @Nullable + public Controller getControllerWithTag(@NonNull String tag) { for (RouterTransaction transaction : backstack) { if (tag.equals(transaction.tag())) { return transaction.controller; @@ -318,6 +331,7 @@ public int getBackstackSize() { /** * Returns the current backstack, ordered from root to most recently pushed. */ + @NonNull public List getBackstack() { List list = new ArrayList<>(); Iterator backstackIterator = backstack.reverseIterator(); @@ -334,7 +348,7 @@ public List getBackstack() { * @param newBackstack The new backstack * @param changeHandler An optional change handler to be used to handle the root view of transition */ - public void setBackstack(@NonNull List newBackstack, ControllerChangeHandler changeHandler) { + public void setBackstack(@NonNull List newBackstack, @Nullable ControllerChangeHandler changeHandler) { List oldVisibleTransactions = getVisibleTransactions(backstack.iterator()); removeAllExceptVisibleAndUnowned(); @@ -370,7 +384,7 @@ public void setBackstack(@NonNull List newBackstack, Controll for (int i = 1; i < newVisibleTransactions.size(); i++) { RouterTransaction transaction = newVisibleTransactions.get(i); handler = transaction.pushChangeHandler() != null ? transaction.pushChangeHandler().copy() : new SimpleSwapChangeHandler(); - performControllerChange(transaction.controller, newVisibleTransactions.get(i - 1).controller, true, handler.copy()); + performControllerChange(transaction.controller, newVisibleTransactions.get(i - 1).controller, true, handler); } } } @@ -394,7 +408,7 @@ public boolean hasRootController() { * * @param changeListener The listener */ - public void addChangeListener(ControllerChangeListener changeListener) { + public void addChangeListener(@NonNull ControllerChangeListener changeListener) { if (!changeListeners.contains(changeListener)) { changeListeners.add(changeListener); } @@ -405,7 +419,7 @@ public void addChangeListener(ControllerChangeListener changeListener) { * * @param changeListener The listener to be removed */ - public void removeChangeListener(ControllerChangeListener changeListener) { + public void removeChangeListener(@NonNull ControllerChangeListener changeListener) { changeListeners.remove(changeListener); } @@ -423,14 +437,14 @@ public void rebindIfNeeded() { } } - public final void onActivityResult(String instanceId, int requestCode, int resultCode, Intent data) { + public final void onActivityResult(@NonNull String instanceId, int requestCode, int resultCode, @Nullable Intent data) { Controller controller = getControllerWithInstanceId(instanceId); if (controller != null) { controller.onActivityResult(requestCode, resultCode, data); } } - public final void onActivityStarted(Activity activity) { + public final void onActivityStarted(@NonNull Activity activity) { for (RouterTransaction transaction : backstack) { transaction.controller.activityStarted(activity); @@ -440,7 +454,7 @@ public final void onActivityStarted(Activity activity) { } } - public final void onActivityResumed(Activity activity) { + public final void onActivityResumed(@NonNull Activity activity) { for (RouterTransaction transaction : backstack) { transaction.controller.activityResumed(activity); @@ -450,7 +464,7 @@ public final void onActivityResumed(Activity activity) { } } - public final void onActivityPaused(Activity activity) { + public final void onActivityPaused(@NonNull Activity activity) { for (RouterTransaction transaction : backstack) { transaction.controller.activityPaused(activity); @@ -460,7 +474,7 @@ public final void onActivityPaused(Activity activity) { } } - public final void onActivityStopped(Activity activity) { + public final void onActivityStopped(@NonNull Activity activity) { for (RouterTransaction transaction : backstack) { transaction.controller.activityStopped(activity); @@ -470,7 +484,7 @@ public final void onActivityStopped(Activity activity) { } } - public void onActivityDestroyed(Activity activity) { + public void onActivityDestroyed(@NonNull Activity activity) { prepareForContainerRemoval(); changeListeners.clear(); @@ -503,7 +517,7 @@ public void prepareForHostDetach() { } } - public void saveInstanceState(Bundle outState) { + public void saveInstanceState(@NonNull Bundle outState) { prepareForHostDetach(); Bundle backstackState = new Bundle(); @@ -513,7 +527,7 @@ public void saveInstanceState(Bundle outState) { outState.putBoolean(KEY_POPS_LAST_VIEW, popsLastView); } - public void restoreInstanceState(Bundle savedInstanceState) { + public void restoreInstanceState(@NonNull Bundle savedInstanceState) { Bundle backstackBundle = savedInstanceState.getParcelable(KEY_BACKSTACK); backstack.restoreInstanceState(backstackBundle); popsLastView = savedInstanceState.getBoolean(KEY_POPS_LAST_VIEW); @@ -524,7 +538,7 @@ public void restoreInstanceState(Bundle savedInstanceState) { } } - public final void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public final void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { for (RouterTransaction transaction : backstack) { transaction.controller.createOptionsMenu(menu, inflater); @@ -534,7 +548,7 @@ public final void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } } - public final void onPrepareOptionsMenu(Menu menu) { + public final void onPrepareOptionsMenu(@NonNull Menu menu) { for (RouterTransaction transaction : backstack) { transaction.controller.prepareOptionsMenu(menu); @@ -544,7 +558,7 @@ public final void onPrepareOptionsMenu(Menu menu) { } } - public final boolean onOptionsItemSelected(MenuItem item) { + public final boolean onOptionsItemSelected(@NonNull MenuItem item) { for (RouterTransaction transaction : backstack) { if (transaction.controller.optionsItemSelected(item)) { return true; @@ -559,7 +573,7 @@ public final boolean onOptionsItemSelected(MenuItem item) { return false; } - private void popToTransaction(@NonNull RouterTransaction transaction, ControllerChangeHandler changeHandler) { + private void popToTransaction(@NonNull RouterTransaction transaction, @Nullable ControllerChangeHandler changeHandler) { RouterTransaction topTransaction = backstack.peek(); List poppedTransactions = backstack.popTo(transaction); trackDestroyingControllers(poppedTransactions); @@ -579,6 +593,7 @@ void prepareForContainerRemoval() { } } + @NonNull final List getControllers() { List controllers = new ArrayList<>(); @@ -590,6 +605,7 @@ final List getControllers() { return controllers; } + @Nullable public final Boolean handleRequestedPermission(@NonNull String permission) { for (RouterTransaction transaction : backstack) { if (transaction.controller.didRequestPermission(permission)) { @@ -599,7 +615,7 @@ public final Boolean handleRequestedPermission(@NonNull String permission) { return null; } - private void performControllerChange(RouterTransaction to, RouterTransaction from, boolean isPush) { + private void performControllerChange(@Nullable RouterTransaction to, @Nullable RouterTransaction from, boolean isPush) { if (isPush && to != null) { to.onAttachedToRouter(); } @@ -620,7 +636,7 @@ private void performControllerChange(RouterTransaction to, RouterTransaction fro performControllerChange(toController, fromController, isPush, changeHandler); } - private void performControllerChange(final Controller to, final Controller from, boolean isPush, @NonNull ControllerChangeHandler changeHandler) { + private void performControllerChange(@Nullable final Controller to, @Nullable final Controller from, boolean isPush, @Nullable ControllerChangeHandler changeHandler) { if (to != null) { setControllerRouter(to); } else if (backstack.size() == 0 && !popsLastView) { @@ -636,7 +652,7 @@ private void pushToBackstack(@NonNull RouterTransaction entry) { backstack.push(entry); } - private void trackDestroyingController(RouterTransaction transaction) { + private void trackDestroyingController(@NonNull RouterTransaction transaction) { if (!transaction.controller.isDestroyed()) { destroyingControllers.add(transaction.controller); @@ -649,7 +665,7 @@ public void postDestroy(@NonNull Controller controller) { } } - private void trackDestroyingControllers(List transactions) { + private void trackDestroyingControllers(@NonNull List transactions) { for (RouterTransaction transaction : transactions) { trackDestroyingController(transaction); } @@ -679,7 +695,7 @@ private void removeAllExceptVisibleAndUnowned() { } } - private void addRouterViewsToList(Router router, List list) { + private void addRouterViewsToList(@NonNull Router router, @NonNull List list) { for (Controller controller : router.getControllers()) { if (controller.getView() != null) { list.add(controller.getView()); @@ -691,7 +707,7 @@ private void addRouterViewsToList(Router router, List list) { } } - private List getVisibleTransactions(Iterator backstackIterator) { + private List getVisibleTransactions(@NonNull Iterator backstackIterator) { List transactions = new ArrayList<>(); while (backstackIterator.hasNext()) { RouterTransaction transaction = backstackIterator.next(); @@ -706,18 +722,18 @@ private List getVisibleTransactions(Iterator getSiblingRouters(); - abstract Router getRootRouter(); + @NonNull abstract List getSiblingRouters(); + @NonNull abstract Router getRootRouter(); } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/RouterTransaction.java b/conductor/src/main/java/com/bluelinelabs/conductor/RouterTransaction.java index d45cbbf4..67a5813f 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/RouterTransaction.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/RouterTransaction.java @@ -2,6 +2,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; /** * Metadata used for adding {@link Controller}s to a {@link Router}. @@ -21,6 +22,7 @@ public class RouterTransaction { private ControllerChangeHandler popControllerChangeHandler; private boolean attachedToRouter; + @NonNull public static RouterTransaction with(@NonNull Controller controller) { return new RouterTransaction(controller); } @@ -41,15 +43,18 @@ void onAttachedToRouter() { attachedToRouter = true; } + @NonNull public Controller controller() { return controller; } + @Nullable public String tag() { return tag; } - public RouterTransaction tag(String tag) { + @NonNull + public RouterTransaction tag(@Nullable String tag) { if (!attachedToRouter) { this.tag = tag; return this; @@ -58,6 +63,7 @@ public RouterTransaction tag(String tag) { } } + @Nullable public ControllerChangeHandler pushChangeHandler() { ControllerChangeHandler handler = controller.getOverriddenPushHandler(); if (handler == null) { @@ -66,7 +72,8 @@ public ControllerChangeHandler pushChangeHandler() { return handler; } - public RouterTransaction pushChangeHandler(ControllerChangeHandler handler) { + @NonNull + public RouterTransaction pushChangeHandler(@Nullable ControllerChangeHandler handler) { if (!attachedToRouter) { pushControllerChangeHandler = handler; return this; @@ -75,6 +82,7 @@ public RouterTransaction pushChangeHandler(ControllerChangeHandler handler) { } } + @Nullable public ControllerChangeHandler popChangeHandler() { ControllerChangeHandler handler = controller.getOverriddenPopHandler(); if (handler == null) { @@ -83,7 +91,8 @@ public ControllerChangeHandler popChangeHandler() { return handler; } - public RouterTransaction popChangeHandler(ControllerChangeHandler handler) { + @NonNull + public RouterTransaction popChangeHandler(@Nullable ControllerChangeHandler handler) { if (!attachedToRouter) { popControllerChangeHandler = handler; return this; @@ -95,6 +104,7 @@ public RouterTransaction popChangeHandler(ControllerChangeHandler handler) { /** * Used to serialize this transaction into a Bundle */ + @NonNull public Bundle saveInstanceState() { Bundle bundle = new Bundle(); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AnimatorChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AnimatorChangeHandler.java index 9bb7328f..c86be644 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AnimatorChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AnimatorChangeHandler.java @@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; @@ -61,7 +62,7 @@ public void restoreFromBundle(@NonNull Bundle bundle) { } @Override - public void onAbortPush(@NonNull ControllerChangeHandler newHandler, Controller newTop) { + public void onAbortPush(@NonNull ControllerChangeHandler newHandler, @Nullable Controller newTop) { super.onAbortPush(newHandler, newTop); canceled = true; @@ -98,7 +99,8 @@ public boolean removesFromViewOnPush() { * @param isPush True if this is a push transaction, false if it's a pop. * @param toAddedToContainer True if the "to" view was added to the container as a part of this ChangeHandler. False if it was already in the hierarchy. */ - protected abstract Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer); + @NonNull + protected abstract Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, boolean toAddedToContainer); /** * Will be called after the animation is complete to reset the View that was removed to its pre-animation state. @@ -106,7 +108,7 @@ public boolean removesFromViewOnPush() { protected abstract void resetFromView(@NonNull View from); @Override - public final void performChange(@NonNull final ViewGroup container, final View from, final View to, final boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { + public final void performChange(@NonNull final ViewGroup container, @Nullable final View from, @Nullable final View to, final boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { boolean readyToAnimate = true; final boolean addingToView = to != null && to.getParent() == null; @@ -138,7 +140,7 @@ public boolean onPreDraw() { } } - private void complete(ControllerChangeCompletedListener changeListener, AnimatorListener animatorListener) { + private void complete(@NonNull ControllerChangeCompletedListener changeListener, @Nullable AnimatorListener animatorListener) { if (!completed) { completed = true; changeListener.onChangeCompleted(); @@ -152,7 +154,7 @@ private void complete(ControllerChangeCompletedListener changeListener, Animator } } - private void performAnimation(@NonNull final ViewGroup container, final View from, final View to, final boolean isPush, final boolean toAddedToContainer, @NonNull final ControllerChangeCompletedListener changeListener) { + private void performAnimation(@NonNull final ViewGroup container, @Nullable final View from, @Nullable final View to, final boolean isPush, final boolean toAddedToContainer, @NonNull final ControllerChangeCompletedListener changeListener) { if (canceled) { complete(changeListener, null); return; diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AutoTransitionChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AutoTransitionChangeHandler.java index f19ff60a..72a47913 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AutoTransitionChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/AutoTransitionChangeHandler.java @@ -3,6 +3,7 @@ import android.annotation.TargetApi; import android.os.Build; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.transition.AutoTransition; import android.transition.Transition; import android.view.View; @@ -14,9 +15,8 @@ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class AutoTransitionChangeHandler extends TransitionChangeHandler { - @Override - @NonNull - protected Transition getTransition(@NonNull ViewGroup container, View from, View to, boolean isPush) { + @Override @NonNull + protected Transition getTransition(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush) { return new AutoTransition(); } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/FadeChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/FadeChangeHandler.java index e91c23d3..beba8665 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/FadeChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/FadeChangeHandler.java @@ -4,6 +4,7 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; @@ -26,8 +27,8 @@ public FadeChangeHandler(long duration, boolean removesFromViewOnPush) { super(duration, removesFromViewOnPush); } - @Override - protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { + @Override @NonNull + protected Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, boolean toAddedToContainer) { AnimatorSet animator = new AnimatorSet(); if (to != null && toAddedToContainer) { animator.play(ObjectAnimator.ofFloat(to, View.ALPHA, 0, 1)); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/HorizontalChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/HorizontalChangeHandler.java index e8886acf..06f1d438 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/HorizontalChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/HorizontalChangeHandler.java @@ -4,6 +4,7 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; @@ -26,8 +27,8 @@ public HorizontalChangeHandler(long duration, boolean removesFromViewOnPush) { super(duration, removesFromViewOnPush); } - @Override - protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { + @Override @NonNull + protected Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, boolean toAddedToContainer) { AnimatorSet animatorSet = new AnimatorSet(); if (isPush) { diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/SimpleSwapChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/SimpleSwapChangeHandler.java index f8b12c5c..b39a5b38 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/SimpleSwapChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/SimpleSwapChangeHandler.java @@ -2,6 +2,7 @@ import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.ViewGroup; @@ -44,7 +45,7 @@ public void restoreFromBundle(@NonNull Bundle bundle) { } @Override - public void onAbortPush(@NonNull ControllerChangeHandler newHandler, Controller newTop) { + public void onAbortPush(@NonNull ControllerChangeHandler newHandler, @Nullable Controller newTop) { super.onAbortPush(newHandler, newTop); canceled = true; @@ -62,7 +63,7 @@ public void completeImmediately() { } @Override - public void performChange(@NonNull ViewGroup container, View from, View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener) { + public void performChange(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener) { if (!canceled) { if (from != null && (!isPush || removesFromViewOnPush)) { container.removeView(from); @@ -89,7 +90,7 @@ public boolean removesFromViewOnPush() { } @Override - public void onViewAttachedToWindow(View v) { + public void onViewAttachedToWindow(@NonNull View v) { v.removeOnAttachStateChangeListener(this); if (changeListener != null) { @@ -100,5 +101,5 @@ public void onViewAttachedToWindow(View v) { } @Override - public void onViewDetachedFromWindow(View v) { } + public void onViewDetachedFromWindow(@NonNull View v) { } } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandler.java index 630dac7a..ebdb416a 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandler.java @@ -3,6 +3,7 @@ import android.annotation.TargetApi; import android.os.Build; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.transition.Transition; import android.transition.Transition.TransitionListener; import android.transition.TransitionManager; @@ -29,17 +30,17 @@ public abstract class TransitionChangeHandler extends ControllerChangeHandler { * @param isPush True if this is a push transaction, false if it's a pop. */ @NonNull - protected abstract Transition getTransition(@NonNull ViewGroup container, View from, View to, boolean isPush); + protected abstract Transition getTransition(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush); @Override - public void onAbortPush(@NonNull ControllerChangeHandler newHandler, Controller newTop) { + public void onAbortPush(@NonNull ControllerChangeHandler newHandler, @Nullable Controller newTop) { super.onAbortPush(newHandler, newTop); canceled = true; } @Override - public void performChange(@NonNull final ViewGroup container, View from, View to, boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { + public void performChange(@NonNull final ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { if (canceled) { changeListener.onChangeCompleted(); return; diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandlerCompat.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandlerCompat.java index 39699dfe..6a00d179 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandlerCompat.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/TransitionChangeHandlerCompat.java @@ -3,6 +3,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; @@ -15,13 +16,10 @@ */ public class TransitionChangeHandlerCompat extends ControllerChangeHandler { - private static final String KEY_TRANSITION_HANDLER_CLASS = "TransitionChangeHandlerCompat.transitionChangeHandler.class"; - private static final String KEY_FALLBACK_HANDLER_CLASS = "TransitionChangeHandlerCompat.fallbackChangeHandler.class"; - private static final String KEY_TRANSITION_HANDLER_STATE = "TransitionChangeHandlerCompat.transitionChangeHandler.state"; - private static final String KEY_FALLBACK_HANDLER_STATE = "TransitionChangeHandlerCompat.fallbackChangeHandler.state"; + private static final String KEY_CHANGE_HANDLER_CLASS = "TransitionChangeHandlerCompat.changeHandler.class"; + private static final String KEY_HANDLER_STATE = "TransitionChangeHandlerCompat.changeHandler.state"; - private TransitionChangeHandler transitionChangeHandler; - private ControllerChangeHandler fallbackChangeHandler; + private ControllerChangeHandler changeHandler; public TransitionChangeHandlerCompat() { } @@ -32,57 +30,43 @@ public TransitionChangeHandlerCompat() { } * @param transitionChangeHandler The change handler that will be used on API 21 and above * @param fallbackChangeHandler The change handler that will be used on APIs below 21 */ - public TransitionChangeHandlerCompat(TransitionChangeHandler transitionChangeHandler, ControllerChangeHandler fallbackChangeHandler) { - this.transitionChangeHandler = transitionChangeHandler; - this.fallbackChangeHandler = fallbackChangeHandler; - } - - @Override - public void performChange(@NonNull final ViewGroup container, View from, View to, boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { + public TransitionChangeHandlerCompat(@NonNull TransitionChangeHandler transitionChangeHandler, @NonNull ControllerChangeHandler fallbackChangeHandler) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - transitionChangeHandler.performChange(container, from, to, isPush, changeListener); + changeHandler = transitionChangeHandler; } else { - fallbackChangeHandler.performChange(container, from, to, isPush, changeListener); + changeHandler = fallbackChangeHandler; } } + @Override + public void performChange(@NonNull final ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, @NonNull final ControllerChangeCompletedListener changeListener) { + changeHandler.performChange(container, from, to, isPush, changeListener); + } + @Override public void saveToBundle(@NonNull Bundle bundle) { super.saveToBundle(bundle); - bundle.putString(KEY_TRANSITION_HANDLER_CLASS, transitionChangeHandler.getClass().getName()); - bundle.putString(KEY_FALLBACK_HANDLER_CLASS, fallbackChangeHandler.getClass().getName()); - - Bundle transitionBundle = new Bundle(); - transitionChangeHandler.saveToBundle(transitionBundle); - bundle.putBundle(KEY_TRANSITION_HANDLER_STATE, transitionBundle); + bundle.putString(KEY_CHANGE_HANDLER_CLASS, changeHandler.getClass().getName()); - Bundle fallbackBundle = new Bundle(); - fallbackChangeHandler.saveToBundle(fallbackBundle); - bundle.putBundle(KEY_FALLBACK_HANDLER_STATE, fallbackBundle); + Bundle stateBundle = new Bundle(); + changeHandler.saveToBundle(stateBundle); + bundle.putBundle(KEY_HANDLER_STATE, stateBundle); } @Override public void restoreFromBundle(@NonNull Bundle bundle) { super.restoreFromBundle(bundle); - String transitionClassName = bundle.getString(KEY_TRANSITION_HANDLER_CLASS); - transitionChangeHandler = ClassUtils.newInstance(transitionClassName); + String className = bundle.getString(KEY_CHANGE_HANDLER_CLASS); + changeHandler = ClassUtils.newInstance(className); //noinspection ConstantConditions - transitionChangeHandler.restoreFromBundle(bundle.getBundle(KEY_TRANSITION_HANDLER_STATE)); - - String fallbackClassName = bundle.getString(KEY_FALLBACK_HANDLER_CLASS); - fallbackChangeHandler = ClassUtils.newInstance(fallbackClassName); - //noinspection ConstantConditions - fallbackChangeHandler.restoreFromBundle(bundle.getBundle(KEY_FALLBACK_HANDLER_STATE)); + changeHandler.restoreFromBundle(bundle.getBundle(KEY_HANDLER_STATE)); } @Override public boolean removesFromViewOnPush() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - return transitionChangeHandler.removesFromViewOnPush(); - } else { - return fallbackChangeHandler.removesFromViewOnPush(); - } + return changeHandler.removesFromViewOnPush(); } + } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/VerticalChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/VerticalChangeHandler.java index 4030cc4b..7322858b 100755 --- a/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/VerticalChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/changehandler/VerticalChangeHandler.java @@ -4,6 +4,7 @@ import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; @@ -30,8 +31,8 @@ public VerticalChangeHandler(long duration, boolean removesFromViewOnPush) { super(duration, removesFromViewOnPush); } - @Override - protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { + @Override @NonNull + protected Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, boolean toAddedToContainer) { AnimatorSet animator = new AnimatorSet(); List viewAnimators = new ArrayList<>(); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/internal/ClassUtils.java b/conductor/src/main/java/com/bluelinelabs/conductor/internal/ClassUtils.java index 34ee53f6..de6dccc3 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/internal/ClassUtils.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/internal/ClassUtils.java @@ -1,16 +1,13 @@ package com.bluelinelabs.conductor.internal; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; public class ClassUtils { - @SuppressWarnings("unchecked") - public static Class classForName(String className) { - return classForName(className, true); - } - - @SuppressWarnings("unchecked") - public static Class classForName(String className, boolean allowEmptyName) { + @Nullable @SuppressWarnings("unchecked") + public static Class classForName(@NonNull String className, boolean allowEmptyName) { if (allowEmptyName && TextUtils.isEmpty(className)) { return null; } @@ -22,10 +19,10 @@ public static Class classForName(String className, boolean allo } } - @SuppressWarnings("unchecked") - public static T newInstance(String className) { + @Nullable @SuppressWarnings("unchecked") + public static T newInstance(@NonNull String className) { try { - Class cls = classForName(className); + Class cls = classForName(className, true); return cls != null ? cls.newInstance() : null; } catch (Exception e) { throw new RuntimeException("An exception occurred while creating a new instance of " + className + ". " + e.getMessage()); diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/internal/LifecycleHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/internal/LifecycleHandler.java index 1c23da7c..456b2ec6 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/internal/LifecycleHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/internal/LifecycleHandler.java @@ -11,6 +11,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.SparseArray; import android.view.Menu; import android.view.MenuInflater; @@ -50,7 +51,8 @@ public LifecycleHandler() { setHasOptionsMenu(true); } - private static LifecycleHandler findInActivity(Activity activity) { + @Nullable + private static LifecycleHandler findInActivity(@NonNull Activity activity) { LifecycleHandler lifecycleHandler = (LifecycleHandler)activity.getFragmentManager().findFragmentByTag(FRAGMENT_TAG); if (lifecycleHandler != null) { lifecycleHandler.registerActivityListener(activity); @@ -58,7 +60,8 @@ private static LifecycleHandler findInActivity(Activity activity) { return lifecycleHandler; } - public static LifecycleHandler install(Activity activity) { + @NonNull + public static LifecycleHandler install(@NonNull Activity activity) { LifecycleHandler lifecycleHandler = findInActivity(activity); if (lifecycleHandler == null) { lifecycleHandler = new LifecycleHandler(); @@ -68,7 +71,8 @@ public static LifecycleHandler install(Activity activity) { return lifecycleHandler; } - public Router getRouter(ViewGroup container, Bundle savedInstanceState) { + @NonNull + public Router getRouter(@NonNull ViewGroup container, @Nullable Bundle savedInstanceState) { ActivityHostedRouter router = routerMap.get(getRouterHashKey(container)); if (router == null) { router = new ActivityHostedRouter(); @@ -88,19 +92,21 @@ public Router getRouter(ViewGroup container, Bundle savedInstanceState) { return router; } + @NonNull public List getRouters() { return new ArrayList(routerMap.values()); } + @Nullable public Activity getLifecycleActivity() { return activity; } - private static int getRouterHashKey(ViewGroup viewGroup) { + private static int getRouterHashKey(@NonNull ViewGroup viewGroup) { return viewGroup.getId(); } - private void registerActivityListener(Activity activity) { + private void registerActivityListener(@NonNull Activity activity) { this.activity = activity; if (!hasRegisteredCallbacks) { @@ -255,11 +261,11 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - public void registerForActivityResult(String instanceId, int requestCode) { + public void registerForActivityResult(@NonNull String instanceId, int requestCode) { activityRequestMap.put(requestCode, instanceId); } - public void unregisterForActivityResults(String instanceId) { + public void unregisterForActivityResults(@NonNull String instanceId) { for (int i = activityRequestMap.size() - 1; i >= 0; i--) { if (instanceId.equals(activityRequestMap.get(activityRequestMap.keyAt(i)))) { activityRequestMap.removeAt(i); @@ -267,18 +273,18 @@ public void unregisterForActivityResults(String instanceId) { } } - public void startActivityForResult(String instanceId, Intent intent, int requestCode) { + public void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode) { registerForActivityResult(instanceId, requestCode); startActivityForResult(intent, requestCode); } - public void startActivityForResult(String instanceId, Intent intent, int requestCode, Bundle options) { + public void startActivityForResult(@NonNull String instanceId, @NonNull Intent intent, int requestCode, @Nullable Bundle options) { registerForActivityResult(instanceId, requestCode); startActivityForResult(intent, requestCode, options); } @TargetApi(Build.VERSION_CODES.M) - public void requestPermissions(String instanceId, String[] permissions, int requestCode) { + public void requestPermissions(@NonNull String instanceId, @NonNull String[] permissions, int requestCode) { if (attached) { permissionRequestMap.put(requestCode, instanceId); requestPermissions(permissions, requestCode); @@ -349,7 +355,7 @@ private static class PendingPermissionRequest implements Parcelable { final String[] permissions; final int requestCode; - public PendingPermissionRequest(String instanceId, String[] permissions, int requestCode) { + PendingPermissionRequest(@NonNull String instanceId, @NonNull String[] permissions, int requestCode) { this.instanceId = instanceId; this.permissions = permissions; this.requestCode = requestCode; @@ -361,10 +367,12 @@ private PendingPermissionRequest(Parcel in) { requestCode = in.readInt(); } + @Override public int describeContents() { return 0; } + @Override public void writeToParcel(Parcel out, int flags) { out.writeString(instanceId); out.writeStringArray(permissions); @@ -372,10 +380,12 @@ public void writeToParcel(Parcel out, int flags) { } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override public PendingPermissionRequest createFromParcel(Parcel in) { return new PendingPermissionRequest(in); } + @Override public PendingPermissionRequest[] newArray(int size) { return new PendingPermissionRequest[size]; } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/internal/NoOpControllerChangeHandler.java b/conductor/src/main/java/com/bluelinelabs/conductor/internal/NoOpControllerChangeHandler.java index bc438b25..77d7fd44 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/internal/NoOpControllerChangeHandler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/internal/NoOpControllerChangeHandler.java @@ -1,6 +1,7 @@ package com.bluelinelabs.conductor.internal; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.View; import android.view.ViewGroup; @@ -9,7 +10,7 @@ public class NoOpControllerChangeHandler extends ControllerChangeHandler { @Override - public void performChange(@NonNull ViewGroup container, @NonNull View from, @NonNull View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener) { + public void performChange(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, @NonNull ControllerChangeCompletedListener changeListener) { changeListener.onChangeCompleted(); } diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/internal/StringSparseArrayParceler.java b/conductor/src/main/java/com/bluelinelabs/conductor/internal/StringSparseArrayParceler.java index 6681df3e..9735f655 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/internal/StringSparseArrayParceler.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/internal/StringSparseArrayParceler.java @@ -2,17 +2,18 @@ import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.NonNull; import android.util.SparseArray; public class StringSparseArrayParceler implements Parcelable { private final SparseArray stringSparseArray; - public StringSparseArrayParceler(SparseArray stringSparseArray) { + public StringSparseArrayParceler(@NonNull SparseArray stringSparseArray) { this.stringSparseArray = stringSparseArray; } - private StringSparseArrayParceler(Parcel in) { + private StringSparseArrayParceler(@NonNull Parcel in) { stringSparseArray = new SparseArray<>(); final int size = in.readInt(); @@ -22,14 +23,17 @@ private StringSparseArrayParceler(Parcel in) { } } + @NonNull public SparseArray getStringSparseArray() { return stringSparseArray; } + @Override public int describeContents() { return 0; } + @Override public void writeToParcel(Parcel out, int flags) { final int size = stringSparseArray.size(); @@ -44,10 +48,12 @@ public void writeToParcel(Parcel out, int flags) { } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override public StringSparseArrayParceler createFromParcel(Parcel in) { return new StringSparseArrayParceler(in); } + @Override public StringSparseArrayParceler[] newArray(int size) { return new StringSparseArrayParceler[size]; } diff --git a/conductor/src/test/java/com/bluelinelabs/conductor/TestController.java b/conductor/src/test/java/com/bluelinelabs/conductor/TestController.java index 87e26e23..a06e3d50 100644 --- a/conductor/src/test/java/com/bluelinelabs/conductor/TestController.java +++ b/conductor/src/test/java/com/bluelinelabs/conductor/TestController.java @@ -68,7 +68,7 @@ protected void onDetach(@NonNull View view) { } @Override - protected void onDestroyView(View view) { + protected void onDestroyView(@NonNull View view) { super.onDestroyView(view); currentCallState.destroyViewCalls++; } diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandler.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandler.java index 6c1151d2..78b48c57 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandler.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandler.java @@ -120,7 +120,7 @@ public CircularRevealChangeHandler(int cx, int cy, long duration, boolean remove this.cy = cy; } - @Override + @Override @NonNull protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { final float radius = (float) Math.hypot(cx, cy); Animator animator = null; diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandlerCompat.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandlerCompat.java index ab525bb2..ea9cd0f8 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandlerCompat.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/CircularRevealChangeHandlerCompat.java @@ -16,7 +16,7 @@ public CircularRevealChangeHandlerCompat(@NonNull View fromView, @NonNull View c super(fromView, containerView); } - @Override + @Override @NonNull protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return super.getAnimator(container, from, to, isPush, toAddedToContainer); diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/FlipChangeHandler.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/FlipChangeHandler.java index a61d3e43..cc6e4524 100755 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/FlipChangeHandler.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/FlipChangeHandler.java @@ -52,7 +52,7 @@ public FlipChangeHandler(FlipDirection flipDirection, long animationDuration) { this.animationDuration = animationDuration; } - @Override + @Override @NonNull protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { AnimatorSet animatorSet = new AnimatorSet(); diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/ScaleFadeChangeHandler.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/ScaleFadeChangeHandler.java index 60632577..193010da 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/ScaleFadeChangeHandler.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/changehandler/ScaleFadeChangeHandler.java @@ -15,7 +15,7 @@ public ScaleFadeChangeHandler() { super(DEFAULT_ANIMATION_DURATION, true); } - @Override + @Override @NonNull protected Animator getAnimator(@NonNull ViewGroup container, View from, View to, boolean isPush, boolean toAddedToContainer) { AnimatorSet animator = new AnimatorSet(); if (to != null && toAddedToContainer) { diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/DragDismissController.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/DragDismissController.java index 63dcf0ec..2fe84dac 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/DragDismissController.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/DragDismissController.java @@ -46,7 +46,7 @@ protected void onViewBound(@NonNull View view) { } @Override - protected void onDestroyView(View view) { + protected void onDestroyView(@NonNull View view) { super.onDestroyView(view); ((ElasticDragDismissFrameLayout)view).removeListener(dragDismissListener); diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/PagerController.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/PagerController.java index fae5a1bb..fec0430a 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/PagerController.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/PagerController.java @@ -12,6 +12,8 @@ import com.bluelinelabs.conductor.demo.controllers.base.BaseController; import com.bluelinelabs.conductor.support.ControllerPagerAdapter; +import java.util.Locale; + import butterknife.BindView; public class PagerController extends BaseController { @@ -27,7 +29,7 @@ public PagerController() { pagerAdapter = new ControllerPagerAdapter(this, false) { @Override public Controller getItem(int position) { - return new ChildController(String.format("Child #%d (Swipe to see more)", position), PAGE_COLORS[position], true); + return new ChildController(String.format(Locale.getDefault(), "Child #%d (Swipe to see more)", position), PAGE_COLORS[position], true); } @Override @@ -50,7 +52,7 @@ protected void onViewBound(@NonNull View view) { } @Override - protected void onDestroyView(View view) { + protected void onDestroyView(@NonNull View view) { viewPager.setAdapter(null); super.onDestroyView(view); } diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/RxLifecycleController.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/RxLifecycleController.java index 6329edf0..1dc132f3 100755 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/RxLifecycleController.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/RxLifecycleController.java @@ -92,7 +92,7 @@ public void call(Long num) { } @Override - protected void onDestroyView(View view) { + protected void onDestroyView(@NonNull View view) { super.onDestroyView(view); Log.i(TAG, "onDestroyView() called"); diff --git a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/base/ButterKnifeController.java b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/base/ButterKnifeController.java index b56e873b..610af12a 100644 --- a/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/base/ButterKnifeController.java +++ b/demo/src/main/java/com/bluelinelabs/conductor/demo/controllers/base/ButterKnifeController.java @@ -34,7 +34,7 @@ protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup protected void onViewBound(@NonNull View view) { } @Override - protected void onDestroyView(View view) { + protected void onDestroyView(@NonNull View view) { super.onDestroyView(view); unbinder.unbind(); unbinder = null; diff --git a/demo/src/main/res/values/material_colors.xml b/demo/src/main/res/values/material_colors.xml index 10af6fc3..20d778d6 100644 --- a/demo/src/main/res/values/material_colors.xml +++ b/demo/src/main/res/values/material_colors.xml @@ -1,23 +1,23 @@ - @color/red_300 - @color/light_green_300 - @color/teal_300 - @color/pink_300 - @color/brown_300 - @color/purple_300 - @color/lime_300 - @color/blue_grey_300 - @color/deep_purple_300 - @color/green_300 - @color/indigo_300 - @color/yellow_300 - @color/blue_300 - @color/orange_300 - @color/light_blue_300 - @color/deep_orange_300 - @color/cyan_300 - @color/grey_300 + @color/red_300 + @color/light_green_300 + @color/teal_300 + @color/pink_300 + @color/brown_300 + @color/purple_300 + @color/lime_300 + @color/blue_grey_300 + @color/deep_purple_300 + @color/green_300 + @color/indigo_300 + @color/yellow_300 + @color/blue_300 + @color/orange_300 + @color/light_blue_300 + @color/deep_orange_300 + @color/cyan_300 + @color/grey_300 \ No newline at end of file