Search in sources :

Example 46 with ViewGroup

use of android.view.ViewGroup in project Conductor by bluelinelabs.

the class ViewUtils method reportAttached.

public static void reportAttached(View view, boolean attached, boolean propogateToChildren) {
    if (view instanceof AttachFakingFrameLayout) {
        ((AttachFakingFrameLayout) view).setAttached(attached, false);
    }
    List<OnAttachStateChangeListener> listeners = getAttachStateListeners(view);
    // Add, then remove an OnAttachStateChangeListener to initialize the attachStateListeners variable inside a view
    if (listeners == null) {
        OnAttachStateChangeListener tmpListener = new OnAttachStateChangeListener() {

            @Override
            public void onViewAttachedToWindow(View v) {
            }

            @Override
            public void onViewDetachedFromWindow(View v) {
            }
        };
        view.addOnAttachStateChangeListener(tmpListener);
        view.removeOnAttachStateChangeListener(tmpListener);
        listeners = getAttachStateListeners(view);
    }
    for (OnAttachStateChangeListener listener : listeners) {
        if (attached) {
            listener.onViewAttachedToWindow(view);
        } else {
            listener.onViewDetachedFromWindow(view);
        }
    }
    if (propogateToChildren && view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = viewGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
            reportAttached(viewGroup.getChildAt(i), attached, true);
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) OnAttachStateChangeListener(android.view.View.OnAttachStateChangeListener) View(android.view.View)

Example 47 with ViewGroup

use of android.view.ViewGroup in project Conductor by bluelinelabs.

the class ControllerTests method testActivityResultForChild.

@Test
public void testActivityResultForChild() {
    TestController parent = new TestController();
    TestController child = new TestController();
    router.pushController(RouterTransaction.with(parent));
    parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID)).setRoot(RouterTransaction.with(child));
    CallState childExpectedCallState = new CallState(true);
    CallState parentExpectedCallState = new CallState(true);
    // Ensure that calling onActivityResult w/o requesting a result doesn't do anything
    router.onActivityResult(1, Activity.RESULT_OK, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure starting an activity for result gets us the result back
    child.startActivityForResult(new Intent("action"), 1);
    router.onActivityResult(1, Activity.RESULT_OK, null);
    childExpectedCallState.onActivityResultCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure requesting a result w/o calling startActivityForResult works
    child.registerForActivityResult(2);
    router.onActivityResult(2, Activity.RESULT_OK, null);
    childExpectedCallState.onActivityResultCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) Intent(android.content.Intent) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 48 with ViewGroup

use of android.view.ViewGroup in project Conductor by bluelinelabs.

the class ControllerTests method testAddRemoveChildControllers.

@Test
public void testAddRemoveChildControllers() {
    TestController parent = new TestController();
    TestController child1 = new TestController();
    TestController child2 = new TestController();
    router.pushController(RouterTransaction.with(parent));
    assertEquals(0, parent.getChildRouters().size());
    assertNull(child1.getParentController());
    assertNull(child2.getParentController());
    Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.setPopsLastView(true);
    childRouter.setRoot(RouterTransaction.with(child1));
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(1, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertNull(child2.getParentController());
    childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.pushController(RouterTransaction.with(child2));
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(2, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(child2, childRouter.getControllers().get(1));
    assertEquals(parent, child1.getParentController());
    assertEquals(parent, child2.getParentController());
    childRouter.popController(child2);
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(1, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertNull(child2.getParentController());
    childRouter.popController(child1);
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(0, childRouter.getBackstackSize());
    assertNull(child1.getParentController());
    assertNull(child2.getParentController());
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 49 with ViewGroup

use of android.view.ViewGroup in project Conductor by bluelinelabs.

the class ControllerTests method testPermissionResultForChild.

@Test
public void testPermissionResultForChild() {
    final String[] requestedPermissions = new String[] { "test" };
    TestController parent = new TestController();
    TestController child = new TestController();
    router.pushController(RouterTransaction.with(parent));
    parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID)).setRoot(RouterTransaction.with(child));
    CallState childExpectedCallState = new CallState(true);
    CallState parentExpectedCallState = new CallState(true);
    // Ensure that calling handleRequestedPermission w/o requesting a result doesn't do anything
    router.onRequestPermissionsResult("anotherId", 1, requestedPermissions, new int[] { 1 });
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure requesting the permission gets us the result back
    try {
        child.requestPermissions(requestedPermissions, 1);
    } catch (NoSuchMethodError ignored) {
    }
    router.onRequestPermissionsResult(child.getInstanceId(), 1, requestedPermissions, new int[] { 1 });
    childExpectedCallState.onRequestPermissionsResultCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 50 with ViewGroup

use of android.view.ViewGroup in project Conductor by bluelinelabs.

the class ControllerChangeHandler method executeChange.

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<ControllerChangeListener> listeners) {
    if (isPush && to != null && to.isDestroyed()) {
        throw new IllegalStateException("Trying to push a controller that has already been destroyed. (" + to.getClass().getSimpleName() + ")");
    }
    if (container != null) {
        final ControllerChangeHandler handler;
        if (inHandler == null) {
            handler = new SimpleSwapChangeHandler();
        } else if (inHandler.hasBeenUsed && !inHandler.isReusable()) {
            handler = inHandler.copy();
        } else {
            handler = inHandler;
        }
        handler.hasBeenUsed = true;
        if (isPush && to != null) {
            inProgressPushHandlers.put(to.getInstanceId(), handler);
            if (from != null) {
                completePushImmediately(from.getInstanceId());
            }
        } else if (!isPush && from != null) {
            abortPush(from, to, handler);
        }
        for (ControllerChangeListener listener : listeners) {
            listener.onChangeStarted(to, from, isPush, container, handler);
        }
        final ControllerChangeType toChangeType = isPush ? ControllerChangeType.PUSH_ENTER : ControllerChangeType.POP_ENTER;
        final ControllerChangeType fromChangeType = isPush ? ControllerChangeType.PUSH_EXIT : ControllerChangeType.POP_EXIT;
        final View toView;
        if (to != null) {
            toView = to.inflate(container);
            to.changeStarted(handler, toChangeType);
        } else {
            toView = null;
        }
        final View fromView;
        if (from != null) {
            fromView = from.getView();
            from.changeStarted(handler, fromChangeType);
        } else {
            fromView = null;
        }
        handler.performChange(container, fromView, toView, isPush, new ControllerChangeCompletedListener() {

            @Override
            public void onChangeCompleted() {
                if (from != null) {
                    from.changeEnded(handler, fromChangeType);
                }
                if (to != null) {
                    inProgressPushHandlers.remove(to.getInstanceId());
                    to.changeEnded(handler, toChangeType);
                }
                for (ControllerChangeListener listener : listeners) {
                    listener.onChangeCompleted(to, from, isPush, container, handler);
                }
                if (handler.forceRemoveViewOnPush && fromView != null) {
                    ViewParent fromParent = fromView.getParent();
                    if (fromParent != null && fromParent instanceof ViewGroup) {
                        ((ViewGroup) fromParent).removeView(fromView);
                    }
                }
            }
        });
    }
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) SimpleSwapChangeHandler(com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler) View(android.view.View)

Aggregations

ViewGroup (android.view.ViewGroup)2327 View (android.view.View)1300 TextView (android.widget.TextView)452 ImageView (android.widget.ImageView)282 ArrayList (java.util.ArrayList)204 ViewParent (android.view.ViewParent)185 ListView (android.widget.ListView)159 LayoutInflater (android.view.LayoutInflater)127 FrameLayout (android.widget.FrameLayout)127 Paint (android.graphics.Paint)126 AdapterView (android.widget.AdapterView)118 LinearLayout (android.widget.LinearLayout)113 AbsListView (android.widget.AbsListView)106 RecyclerView (android.support.v7.widget.RecyclerView)100 Drawable (android.graphics.drawable.Drawable)95 Animator (android.animation.Animator)94 AnimatedView (carbon.animation.AnimatedView)88 ComponentView (carbon.component.ComponentView)88 RippleView (carbon.drawable.ripple.RippleView)88 ShadowView (carbon.shadow.ShadowView)88