Example usage for android.view View focusSearch

List of usage examples for android.view View focusSearch

Introduction

In this page you can find the example usage for android.view View focusSearch.

Prototype

public View focusSearch(@FocusRealDirection int direction) 

Source Link

Document

Find the nearest view in the specified direction that can take focus.

Usage

From source file:android.support.v7.widget.BaseRecyclerViewInstrumentationTest.java

public View focusSearch(final View focused, final int direction) throws Throwable {
    final View[] result = new View[1];
    runTestOnUiThread(new Runnable() {
        @Override/*  www.ja  v  a  2s  . co  m*/
        public void run() {
            View view = focused.focusSearch(direction);
            if (view != null && view != focused) {
                view.requestFocus();
            }
            result[0] = view;
        }
    });
    return result[0];
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void test27766012() throws Throwable {
    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear_with_button_onleft);
    intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.horizontal_item);
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 2);
    intent.putExtra(GridActivity.EXTRA_STAGGERED, false);
    intent.putExtra(GridActivity.EXTRA_UPDATE_SIZE, false);
    initActivity(intent);//from   w w w  . ja  v  a 2 s . c o m
    mOrientation = BaseGridView.VERTICAL;
    mNumRows = 1;

    // set remove animator two seconds
    mGridView.getItemAnimator().setRemoveDuration(2000);
    final View view = mGridView.getChildAt(1);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            view.requestFocus();
        }
    });
    assertTrue(view.hasFocus());
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            mActivity.removeItems(0, 2);
        }

    });
    // wait one second, removing second view is still attached to parent
    Thread.sleep(1000);
    assertSame(view.getParent(), mGridView);
    runTestOnUiThread(new Runnable() {
        @Override
        public void run() {
            // refocus to the removed item and do a focus search.
            view.requestFocus();
            view.focusSearch(View.FOCUS_UP);
        }

    });
}