VideoSmoothGridView.java 1.97 KB
package com.xgimi.gimicinema.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.GridView;

public class VideoSmoothGridView extends GridView  {

	private final static int SCROLL_ITEM_TIME = 200;//may not important
	private String TAG = "VerticalSmoothGridView";
	private boolean isHandle = false;
	private int firstDy = 0;
	private final int smoothTime = 200;
	private int delayTime = 400;
	private int eventCount = 0;

	private final static int DOUBLE_ROW = 2; //double row
	private final static int SINGLE_ROW = 1; //single row
	/**
     * <默认构造函数>
     */
    public VideoSmoothGridView(Context context) {
        super(context);
    }

    public VideoSmoothGridView(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    public VideoSmoothGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
//
//	@Override
//	public boolean dispatchKeyEvent(KeyEvent event) {
//		int height = this.getChildAt(0).getHeight();
//		eventCount++;
//		// for different item it may occurs twice
//		if (eventCount % 2 != 0) {
//			int row = 0;
//			row = getItemCurrentRow();
//			if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN && row == DOUBLE_ROW) {
//				this.smoothScrollBy(height, SCROLL_ITEM_TIME);
//				invalidate();
//			} else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP && row == SINGLE_ROW) {
//				this.smoothScrollBy(-height, SCROLL_ITEM_TIME);
//				invalidate();
//			}
//		}
//		return super.dispatchKeyEvent(event);
//	}
	/**
	 *
	 * get GridView's item location
	 *
	 * @return
	 */
	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public int getItemCurrentRow() {
		int position = 0;
		int row = 0;
		position = this.getSelectedItemPosition();
		int temp = (position / this.getNumColumns() + 1) % 2;
		if (temp == 0) {
			row = DOUBLE_ROW;
		} else {
			row = SINGLE_ROW;
		}
		return row;
	}
}