package com.wasu.cs.widget;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

public class FavHisLinearLayout extends LinearLayout {
	private static final String TAG = "stone";
	AddFocusablesListner listner;
	public FavHisLinearLayout(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public FavHisLinearLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	public FavHisLinearLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}
	int index=2;
	public void  setIndex(int index){
		this.index=index;
	}
	@Override
	public void addFocusables(ArrayList<View> views, int direction,
			int focusableMode) {
		Log.i(TAG, "FavHisLinearLayout addFocusables direction="+direction+
				",focusableMode="+focusableMode+",hasFocus="+hasFocus()+
				",index="+index);
		this.direction=direction;
		if(hasFocus()&&direction==FOCUS_LEFT){
			getChildAt(index).addFocusables(views, direction,focusableMode);
		}else{
			super.addFocusables(views, direction, focusableMode);
			
		}
	}
	int direction=0;
	public int getDirection(){
		return direction;
	}
	
	@Override
	protected void onFocusChanged(boolean gainFocus, int direction,
			Rect previouslyFocusedRect) {
		Log.i(TAG, "FavHisLinearLayout onFocusChanged gainFocus="+gainFocus);
		super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
		
	}
	@Override
	public boolean dispatchUnhandledMove(View focused, int direction) {
		Log.i(TAG, "FavHisLinearLayout dispatchUnhandledMove ");
	//	listner.addFocus();
		return true;
	}
	@Override
	protected boolean onRequestFocusInDescendants(int direction,
			Rect previouslyFocusedRect) {
		super.onRequestFocusInDescendants(direction, previouslyFocusedRect);
		Log.i(TAG, "FavHisLinearLayout onRequestFocusInDescendants="+direction);
		return true;
	}
	@Override
	public boolean hasFocus() {
		Log.i(TAG, "FavHisLinearLayout hasFocusable");
		return super.hasFocusable();
	}
	
	public void setAddFocusablesListner(AddFocusablesListner listner){
		this.listner=listner;
	}
	public interface AddFocusablesListner{
		public void addFocus();
	}
}
