package com.wasu.cs.widget;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Created by jeepc on 2016/9/6.
 */

public class HisFavLinearLayoutManager extends LinearLayoutManager {
    public HisFavLinearLayoutManager(Context context) {
        super(context);
    }

    public HisFavLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }

    public HisFavLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }
/*

    @Override
    public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) {
        // Need to be called in order to layout new row/column
        View nextFocus = super.onFocusSearchFailed(focused, focusDirection, recycler, state);

        if (nextFocus == null) {
            return null;
        }
        */
/**
         * 获取当前焦点的位置
         *//*

        int fromPos = getPosition(focused);
        */
/**
         * 获取我们希望的下一个焦点的位置
         *//*

        int nextPos = getNextViewPos(fromPos, focusDirection);

        return findViewByPosition(nextPos);
    }
*/


    protected int getNextViewPos(int fromPos, int direction) {
        int offset = calcOffsetToNextView(direction);
        return fromPos + offset;
    }
    protected int calcOffsetToNextView(int direction) {
        int orientation = getOrientation();

        if (orientation == VERTICAL) {
            switch (direction) {
                case View.FOCUS_DOWN:
                    return 1;
                case View.FOCUS_UP:
                    return -1;
            }
        } else if (orientation == HORIZONTAL) {
            switch (direction) {
                case View.FOCUS_RIGHT:
                    return 1;
                case View.FOCUS_LEFT:
                    return -1;
            }
        }

        return 0;
    }
}
