Java 类android.view.ViewTreeObserver.OnGlobalFocusChangeListener 实例源码
项目:android_packages_apps_tv
文件:MenuView.java
public MenuView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLayoutInflater = LayoutInflater.from(context);
// Set hardware layer type for smooth animation of lots of views.
setLayerType(LAYER_TYPE_HARDWARE, null);
getViewTreeObserver().addOnGlobalFocusChangeListener(new OnGlobalFocusChangeListener() {
@Override
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
MenuRowView newParent = getParentMenuRowView(newFocus);
if (newParent != null) {
if (DEBUG) Log.d(TAG, "Focus changed to " + newParent);
// When the row is selected, the row view itself has the focus because the row
// is collapsed. To make the child of the row have the focus, requestFocus()
// should be called again after the row is expanded. It's done in
// setSelectedPosition().
setSelectedPositionSmooth(mMenuRowViews.indexOf(newParent));
}
}
});
mLayoutManager = new MenuLayoutManager(context, this);
}