Example usage for android.view ViewTreeObserver.OnGlobalFocusChangeListener ViewTreeObserver.OnGlobalFocusChangeListener

List of usage examples for android.view ViewTreeObserver.OnGlobalFocusChangeListener ViewTreeObserver.OnGlobalFocusChangeListener

Introduction

In this page you can find the example usage for android.view ViewTreeObserver.OnGlobalFocusChangeListener ViewTreeObserver.OnGlobalFocusChangeListener.

Prototype

ViewTreeObserver.OnGlobalFocusChangeListener

Source Link

Usage

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupSideListArea(View view) {
    sideListArea = (LinearLayout) view.findViewById(R.id.sidelist_layout);
    if (sideListArea == null) {
        return;/*w ww .j a  va  2 s  .c  o m*/
    }

    FragmentActivity activity = getActivity();
    if (activity instanceof TorrentViewActivity) {
        ((TorrentViewActivity) activity).setBottomToolbarEnabled(false);
        ((TorrentViewActivity) activity).setShowGlobalActionBar(false);
    }

    if (!AndroidUtils.hasTouchScreen()) {
        // Switch SideList width based on focus.  For touch screens, we use
        // touch events.  For non-touch screens (TV) we watch for focus changes
        ViewTreeObserver vto = sideListArea.getViewTreeObserver();
        vto.addOnGlobalFocusChangeListener(new ViewTreeObserver.OnGlobalFocusChangeListener() {

            @Override
            public void onGlobalFocusChanged(View oldFocus, View newFocus) {

                boolean isChildOfSideList = isChildOf(newFocus, sideListArea);
                boolean isHeader = childOrParentHasTag(newFocus, "sideheader");
                if ((sidelistIsExpanded == null || sidelistIsExpanded) && !isChildOfSideList) {
                    //left focus
                    sidelistInFocus = false;
                    expandSideListWidth(false);
                } else if ((sidelistIsExpanded == null || !sidelistIsExpanded) && isHeader
                        && newFocus != listSideFilter) {
                    sidelistInFocus = true;
                    expandSideListWidth(true);
                }
            }
        });
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        LayoutTransition layoutTransition = new LayoutTransition();
        layoutTransition.setDuration(300);
        sideListArea.setLayoutTransition(layoutTransition);
    }

    // Could have used a ExpandableListView.. oh well
    setupExpando(view, R.id.sidesort_header, R.id.sidesort_list);
    setupExpando(view, R.id.sidetag_header, R.id.sidetag_list);
    setupExpando(view, R.id.sidefilter_header, R.id.sidefilter_list);
    setupExpando(view, R.id.sideactions_header, R.id.sideactions_list);

    setupSideFilter(view);
    setupSideTags(view);
    setupSideSort(view);
    setupSideActions(view);
}