MetroGridView.java
3.71 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.xgimi.gimicinema.view;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.GridView;
public class MetroGridView extends GridView {
private int position = 0;
private boolean isMySetPadding = false;
public MetroGridView(Context context) {
super(context);
isMySetPadding = true;
// setPadding(60, 60, 60, 60);
isMySetPadding = false;
}
public MetroGridView(Context context, AttributeSet attrs) {
super(context, attrs);
isMySetPadding = true;
// setPadding(60, 60, 60, 60);
isMySetPadding = false;
}
@Override
public void setPadding(int left, int top, int right, int bottom) {
if (isMySetPadding) {
super.setPadding(left, top, right, bottom);
}
}
// public void setCurrentPosition(int pos) {
// this.position = pos;
// }
// @SuppressLint("NewApi")
// @Override
// protected void setChildrenDrawingOrderEnabled(boolean enabled) {
// super.setChildrenDrawingOrderEnabled(enabled);
// }
// @Override
// protected int getChildDrawingOrder(int childCount, int i) {
// if (i == childCount - 1) {
// return position;
// }
// if (i == position) {
// return childCount - 1;
// }
// return i;
// }
@Override
protected void onFocusChanged(boolean gainFocus, int direction,
Rect previouslyFocusedRect) {
int lastSelectItem = getSelectedItemPosition();
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (gainFocus) {
setSelection(lastSelectItem);
}
}
// private final static int SCROLL_ITEM_TIME = 1000;//may not important
// private int eventCount = 0;
// private final static int DOUBLE_ROW = 2; //double row
// private final static int SINGLE_ROW = 1; //single row
//
// private int scrollRow = 1;//set the scroll rows if needed default is 1
//
// @Override
// public boolean dispatchKeyEvent(KeyEvent event) {
// if (this.getChildCount() > 0) {
// 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);
// } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP && row == SINGLE_ROW) {
// this.smoothScrollBy(-height, SCROLL_ITEM_TIME);
// }
// }
// }
// return super.dispatchKeyEvent(event);
// }
//
// /**
// * get GridView's item location
// *
// * @return
// */
// @TargetApi(Build.VERSION_CODES.HONEYCOMB)
// public int getItemCurrentRow() {
// int row = 0;
// int position = 0;
// position = this.getSelectedItemPosition();
// int temp = (position / this.getNumColumns() + 1) % 2;
// if (temp == 0) {
// row = DOUBLE_ROW;
// } else {
// row = SINGLE_ROW;
// }
// return row;
// }
//
// public int getScrollRow() {
// return scrollRow;
// }
//
// public void setScrollRow(int scrollRow) {
// this.scrollRow = scrollRow;
// }
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}