VideoSmoothGridView.java
1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
}
}