FileDocCategorySizeDatePackage
FocusAfterRemovalTest.javaAPI DocAndroid 1.5 API4600Wed May 06 22:42:02 BST 2009com.android.frameworktest.focus

FocusAfterRemovalTest

public class FocusAfterRemovalTest extends android.test.ActivityInstrumentationTestCase
{@link FocusAfterRemoval} is set up to exercise cases where the views that have focus become invisible or GONE.

Fields Summary
private android.widget.LinearLayout
mLeftLayout
private android.widget.Button
mTopLeftButton
private android.widget.Button
mBottomLeftButton
private android.widget.Button
mTopRightButton
private android.widget.Button
mBottomRightButton
Constructors Summary
public FocusAfterRemovalTest()

        super("com.android.frameworktest", FocusAfterRemoval.class);
    
Methods Summary
public voidsetUp()

        super.setUp();

        final FocusAfterRemoval a = getActivity();
        mLeftLayout = (LinearLayout) a.findViewById(R.id.leftLayout);
        mTopLeftButton = (Button) a.findViewById(R.id.topLeftButton);
        mBottomLeftButton = (Button) a.findViewById(R.id.bottomLeftButton);
        mTopRightButton = (Button) a.findViewById(R.id.topRightButton);
        mBottomRightButton = (Button) a.findViewById(R.id.bottomRightButton);
    
public voidtestFocusLeavesWhenFocusedViewBecomesGone()


        // move to top right
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
        assertTrue(mTopRightButton.hasFocus());

        // click making it GONE
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        assertEquals(View.GONE, mTopRightButton.getVisibility());

        assertTrue("focus should jump to visible button",
                mTopLeftButton.hasFocus());
    
public voidtestFocusLeavesWhenFocusedViewBecomesInvisible()


        // move to bottom right
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertTrue(mBottomRightButton.hasFocus());

        // click making it INVISIBLE
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        assertEquals(View.INVISIBLE, mBottomRightButton.getVisibility());

        assertTrue("focus should jump to visible button",
                mTopLeftButton.hasFocus());
    
public voidtestFocusLeavesWhenParentLayoutInvisible()


        // move down to bottom left button
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        assertTrue(mBottomLeftButton.hasFocus());

        // clicking on this button makes its parent linear layout INVISIBLE
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        assertEquals(View.INVISIBLE,
                getActivity().findViewById(R.id.leftLayout).getVisibility());

        assertTrue("focus should jump to visible button",
                mTopRightButton.hasFocus());
    
public voidtestFocusLeavesWhenParentLayoutIsGone()


        // clicking on this button makes its parent linear layout GONE
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
        assertEquals(View.GONE, mLeftLayout.getVisibility());

        assertTrue("focus should jump to visible button",
                mTopRightButton.hasFocus());

    
public voidtestSetUpConditions()

        assertNotNull(mLeftLayout);
        assertNotNull(mTopLeftButton);
        assertNotNull(mTopRightButton);
        assertNotNull(mBottomLeftButton);
        assertNotNull(mBottomRightButton);

        assertTrue(mTopLeftButton.hasFocus());