ChooseScreenView.java
12.9 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package com.cnlive.goldenline.ui.widget;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.ui.model.ScreenInfoBean;
import com.cnlive.goldenline.util.CharsequencePharse;
import com.cnlive.goldenline.util.ResLoader;
/**
* Description:选厅
* Created on 2017/3/9
* Author : 萧
*/
public class ChooseScreenView extends LinearLayout {
private static final String TAG = "ChooseScreenView";
private FrameLayout layout_center;
private ImageView img_center;
private TextView tv_center;
private ImageView img_top;
private TextView tv_top;
private ImageView img_left;
private TextView tv_left;
private ImageView img_right;
private TextView tv_right;
private ImageView img_bottom;
private TextView tv_bottom;
private int areaColor;
private int selectColor;
private int defColor;
private int seatStateUnNormalRes;
private int seatStateNormalRes;
private int areaCenter = 100, areaLeft = 100, areaRight = 100, areaBottom = 100, areaTop = 100;
private int countCenter = 100, countLeft = 100, countRight = 100, countBottom = 100, countTop = 100;
private SparseArray<Integer> colors;
private SparseArray<Integer> textsizes;
private ScreenInfoBean bean;
public ChooseScreenView(Context context) {
super(context);
// Log.e(TAG, "ChooseScreenView: ");
initView(context);
}
public ChooseScreenView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public ChooseScreenView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}
private void initView(Context context) {
// Log.e(TAG, "initView: begin");
View view = LayoutInflater.from(context).inflate(R.layout.layout_choosescreen, this);
layout_center = (FrameLayout) view.findViewById(R.id.choosescreen_layout_center);
img_center = (ImageView) view.findViewById(R.id.choosescreen_img_center);
tv_center = (TextView) view.findViewById(R.id.choosescreen_tv_center);
img_left = (ImageView) view.findViewById(R.id.choosescreen_img_left);
tv_left = (TextView) view.findViewById(R.id.choosescreen_tv_left);
img_right = (ImageView) view.findViewById(R.id.choosescreen_img_right);
tv_right = (TextView) view.findViewById(R.id.choosescreen_tv_right);
img_top = (ImageView) view.findViewById(R.id.choosescreen_img_top);
tv_top = (TextView) view.findViewById(R.id.choosescreen_tv_top);
img_bottom = (ImageView) view.findViewById(R.id.choosescreen_img_bottom);
tv_bottom = (TextView) view.findViewById(R.id.choosescreen_tv_bottom);
OnClickListener onClickListener = new OnClickListener();
layout_center.setOnClickListener(onClickListener);
img_top.setOnClickListener(onClickListener);
img_bottom.setOnClickListener(onClickListener);
img_left.setOnClickListener(onClickListener);
img_right.setOnClickListener(onClickListener);
// Log.e(TAG, "initView: end");
initDefContent();
}
private void initDefContent() {
// Log.e(TAG, "initDefContent: begin");
seatStateNormalRes = R.mipmap.onlive_chose_seat;
seatStateUnNormalRes = R.mipmap.onlive_chose_seat_unselected;
areaColor = Color.parseColor("#8dc670");
defColor = Color.parseColor("#7d7d7d");
selectColor = Color.parseColor("#ff584b");
colors = new SparseArray<>();
colors.put(1, areaColor);
colors.put(2, selectColor);
colors.put(3, defColor);
textsizes = new SparseArray<>();
textsizes.put(1, 13);
tv_center.setText(initTitle("A区\n", areaCenter, countCenter));
tv_top.setText(initTitle("E区", areaTop, countTop));
tv_left.setText(initTitle("B区\n", areaLeft, countLeft));
tv_right.setText(initTitle("C区\n", areaRight, countRight));
tv_bottom.setText(initTitle("D区", areaBottom, countBottom));
tv_top.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), seatStateNormalRes), null);
tv_bottom.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), seatStateNormalRes), null);
tv_center.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), seatStateNormalRes));
tv_left.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), seatStateNormalRes));
tv_right.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), seatStateNormalRes));
// Log.e(TAG, "initDefContent: end");
}
private CharSequence initTitle(String title, int currentValue, int count) {
SparseArray<String> contents = new SparseArray<>();
contents.put(1, title);
contents.put(2, String.valueOf(currentValue));
contents.put(3, "/" + String.valueOf(count));
return CharsequencePharse.init().setColors(colors).setContents(contents).setTextSizes(textsizes).format();
}
public interface ScreenSelectedListener {
void onScreenSelected(ScreenInfoBean hallId,String areaId);
}
public ScreenSelectedListener onScreenSelectedListener;
public void setOnScreenSelectedListener(ScreenSelectedListener onScreenSelectedListener,ScreenInfoBean bean) {
this.bean = bean;
this.onScreenSelectedListener = onScreenSelectedListener;
}
class OnClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.choosescreen_layout_center:
if (onScreenSelectedListener != null) {
onScreenSelectedListener.onScreenSelected(bean,"A");
}
// Toast.makeText(getContext(), "选择A区", Toast.LENGTH_SHORT).show();
break;
case R.id.choosescreen_img_bottom:
if (onScreenSelectedListener != null) {
onScreenSelectedListener.onScreenSelected(bean,"D");
}
// Toast.makeText(getContext(), "选择D区", Toast.LENGTH_SHORT).show();
break;
case R.id.choosescreen_img_top:
if (onScreenSelectedListener != null) {
onScreenSelectedListener.onScreenSelected(bean,"E");
}
// Toast.makeText(getContext(), "选择E区", Toast.LENGTH_SHORT).show();
break;
case R.id.choosescreen_img_left:
if (onScreenSelectedListener != null) {
onScreenSelectedListener.onScreenSelected(bean,"B");
}
// Toast.makeText(getContext(), "选择B区", Toast.LENGTH_SHORT).show();
break;
case R.id.choosescreen_img_right:
if (onScreenSelectedListener != null) {
onScreenSelectedListener.onScreenSelected(bean,"C");
}
// Toast.makeText(getContext(), "选择C区", Toast.LENGTH_SHORT).show();
break;
}
}
}
public void updateLeftSeats(ScreenInfoBean t) {
this.areaCenter = areaCenter;
this.areaLeft = areaLeft;
this.areaRight = areaRight;
this.areaBottom = areaBottom;
this.areaTop = areaTop;
tv_center.setText(initTitle(t.getAreaName()+"\n", areaCenter, countCenter));
tv_top.setText(initTitle("E区", areaTop, countTop));
tv_left.setText(initTitle("B区\n", areaLeft, countLeft));
tv_right.setText(initTitle("C区\n", areaRight, countRight));
tv_bottom.setText(initTitle("D区", areaBottom, countBottom));
tv_top.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), areaTop == countTop ? seatStateUnNormalRes : seatStateNormalRes), null);
tv_bottom.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), areaBottom == countBottom ? seatStateUnNormalRes : seatStateNormalRes), null);
tv_center.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaCenter == countCenter ? seatStateUnNormalRes : seatStateNormalRes));
tv_left.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaLeft == countLeft ? seatStateUnNormalRes : seatStateNormalRes));
tv_right.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaRight == countRight ? seatStateUnNormalRes : seatStateNormalRes));
}
public void updateLeftSeats(int areaCenter, int areaLeft, int areaRight, int areaBottom, int areaTop) {
this.areaCenter = areaCenter;
this.areaLeft = areaLeft;
this.areaRight = areaRight;
this.areaBottom = areaBottom;
this.areaTop = areaTop;
tv_center.setText(initTitle("A区\n", areaCenter, countCenter));
tv_top.setText(initTitle("E区", areaTop, countTop));
tv_left.setText(initTitle("B区\n", areaLeft, countLeft));
tv_right.setText(initTitle("C区\n", areaRight, countRight));
tv_bottom.setText(initTitle("D区", areaBottom, countBottom));
tv_top.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), areaTop == countTop ? seatStateUnNormalRes : seatStateNormalRes), null);
tv_bottom.setCompoundDrawablesWithIntrinsicBounds(null, null, ResLoader.Drawable(getContext(), areaBottom == countBottom ? seatStateUnNormalRes : seatStateNormalRes), null);
tv_center.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaCenter == countCenter ? seatStateUnNormalRes : seatStateNormalRes));
tv_left.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaLeft == countLeft ? seatStateUnNormalRes : seatStateNormalRes));
tv_right.setCompoundDrawablesWithIntrinsicBounds(null, null, null, ResLoader.Drawable(getContext(), areaRight == countRight ? seatStateUnNormalRes : seatStateNormalRes));
}
public int getCountCenter() {
return countCenter;
}
public void setCountCenter(int countCenter) {
this.countCenter = countCenter;
}
public int getCountLeft() {
return countLeft;
}
public void setCountLeft(int countLeft) {
this.countLeft = countLeft;
}
public int getCountRight() {
return countRight;
}
public void setCountRight(int countRight) {
this.countRight = countRight;
}
public int getCountBottom() {
return countBottom;
}
public void setCountBottom(int countBottom) {
this.countBottom = countBottom;
}
public int getCountTop() {
return countTop;
}
public void setCountTop(int countTop) {
this.countTop = countTop;
}
public int getAreaColor() {
return areaColor;
}
public void setAreaColor(int areaColor) {
this.areaColor = areaColor;
}
public int getSelectColor() {
return selectColor;
}
public void setSelectColor(int selectColor) {
this.selectColor = selectColor;
}
public int getDefColor() {
return defColor;
}
public void setDefColor(int defColor) {
this.defColor = defColor;
}
public int getSeatStateUnNormalRes() {
return seatStateUnNormalRes;
}
public void setSeatStateUnNormalRes(int seatStateUnNormalRes) {
this.seatStateUnNormalRes = seatStateUnNormalRes;
}
public int getSeatStateNormalRes() {
return seatStateNormalRes;
}
public void setSeatStateNormalRes(int seatStateNormalRes) {
this.seatStateNormalRes = seatStateNormalRes;
}
public int getAreaCenter() {
return areaCenter;
}
public void setAreaCenter(int areaCenter) {
this.areaCenter = areaCenter;
}
public int getAreaLeft() {
return areaLeft;
}
public void setAreaLeft(int areaLeft) {
this.areaLeft = areaLeft;
}
public int getAreaRight() {
return areaRight;
}
public void setAreaRight(int areaRight) {
this.areaRight = areaRight;
}
public int getAreaBottom() {
return areaBottom;
}
public void setAreaBottom(int areaBottom) {
this.areaBottom = areaBottom;
}
public int getAreaTop() {
return areaTop;
}
public void setAreaTop(int areaTop) {
this.areaTop = areaTop;
}
}