ChooseSeatPopWindow.java
21.2 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
package com.cnlive.goldenline.ui.widget;
import android.animation.Animator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.application.GoldenLineApplication;
import com.cnlive.goldenline.ui.activity.ConfirmOrderActivity;
import com.cnlive.goldenline.ui.activity.iview.IChooseSeatView;
import com.cnlive.goldenline.ui.activity.presenter.SeatPresenter;
import com.cnlive.goldenline.ui.model.ScreenInfoBean;
import com.cnlive.goldenline.ui.widget.animation.Techniques;
import com.cnlive.goldenline.ui.widget.animation.YoYo;
import com.cnlive.goldenline.ui.widget.selectionview.data.AuditoriumInfo;
import com.cnlive.goldenline.ui.widget.selectionview.data.DataEmulate;
import com.cnlive.goldenline.ui.widget.selectionview.data.MySelectedSeats;
import com.cnlive.goldenline.ui.widget.selectionview.data.SeatUserBean;
import com.cnlive.goldenline.ui.widget.selectionview.view.MidLineImpl;
import com.cnlive.goldenline.ui.widget.selectionview.view.OutlineMapImpl;
import com.cnlive.goldenline.ui.widget.selectionview.view.RowBarImpl;
import com.cnlive.goldenline.ui.widget.selectionview.view.Seat;
import com.cnlive.goldenline.ui.widget.selectionview.view.SeatImagePoolImpl;
import com.cnlive.goldenline.ui.widget.selectionview.view.SeatSelectionListener;
import com.cnlive.goldenline.ui.widget.selectionview.view.SeatSelectionView;
import com.cnlive.goldenline.ui.widget.selectionview.view.SeatState;
import com.cnlive.goldenline.ui.widget.selectionview.view.SeatType;
import com.cnlive.goldenline.util.CharsequencePharse;
import com.cnlive.goldenline.util.ResLoader;
import com.cnlive.goldenline.util.SeatViewUtls;
import com.cnlive.goldenline.util.TimeUtil;
import com.cnlive.goldenline.util.ToastUtil;
import java.util.List;
import sviolet.turquoise.util.common.BitmapUtils;
import sviolet.turquoise.util.droid.MeasureUtils;
/**
* Description:直播-选座弹框
* Created on 2017/3/14
* Author : 萧
*/
public class ChooseSeatPopWindow extends PopupWindow implements IChooseSeatView, View.OnClickListener {
private TextView tv_time;
private TextView tv_title;
private SeatSelectionView seatSelectionView;
private RelativeLayout layout_bottom_bar;
private LinearLayout layout_container;
private TextView tv_price;
private ScreenInfoBean mScreenInBean;
private SeatImagePoolImpl imagePool;
private MySelectedSeats selectedSeats;
private com.cnlive.goldenline.ui.widget.selectionview.view.SeatTable seatTable;
private Activity mCtx;
private SeatPresenter mPresenter;
private Seat mSeat;
/**
* 更换选区弹出的界面
*/
private RelativeLayout layout_area_list;
private TextView tv_a;
private TextView tv_b;
private TextView tv_c;
private TextView tv_d;
private TextView tv_e;
ImageView img_collapse;
private String liveId;
private String mSeatRow;
private String mSeatCloneId;
private ProgressDialog mDialog;
@SuppressWarnings("unchecked")
public ChooseSeatPopWindow(final Activity context, final String coverUrl,
final ScreenInfoBean bean,
final String liveId,
long hallId,
final String areaId,
final String title,
final String desc,
final String time, final float price, int height) {
if (context != null) {
selectedareaId = areaId;
mCtx = context;
this.liveId = liveId;
mScreenInBean = bean;
mPresenter = new SeatPresenter();
mPresenter.attachView(this);
mPresenter.getSeatUserInfo(liveId, hallId, areaId);
@SuppressLint("InflateParams") View view = LayoutInflater.from(mCtx).inflate(R.layout.layout_chooseseat_pop, null);
view.setAnimation(AnimationUtils.loadAnimation(mCtx, R.anim.pop_enter_anim_slow));
this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
ColorDrawable cd = new ColorDrawable(Color.WHITE);
this.setBackgroundDrawable(cd);
this.setHeight(height > 0 ? height : ViewGroup.LayoutParams.WRAP_CONTENT);
this.setFocusable(true);
this.setContentView(view);
this.setOutsideTouchable(false);
this.setAnimationStyle(R.style.popup_anim_slow);
tv_title = (TextView) view.findViewById(R.id.chooseseat_tv_title);
tv_time = (TextView) view.findViewById(R.id.chooseseat_tv_time);
ImageView img_change = (ImageView) view.findViewById(R.id.chooseseat_img_change);
img_change.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeArea(false);
}
});
ImageView img_close = (ImageView) view.findViewById(R.id.img_close);
img_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
seatSelectionView = (SeatSelectionView) view.findViewById(R.id.chooseseat_selection_view);
layout_bottom_bar = (RelativeLayout) view.findViewById(R.id.chooseseat_bottom_bar);
layout_container = (LinearLayout) view.findViewById(R.id.chooseseat_layout_containter);
tv_price = (TextView) view.findViewById(R.id.chooseseat_tv_price);
View btn_confirm = view.findViewById(R.id.chooseseat_btn_confirm);
btn_confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ConfirmOrderActivity.startActivityForResust(mCtx,
String.valueOf(bean.getHallId()),
liveId,
selectedareaId,
price,
mSeatRow,
mSeatCloneId,
title,
desc,
coverUrl,
time,
bean.getTitle()
);
dismiss();
}
});
initSeatView(title, price, time);
this.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
try {
imagePool.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
});
layout_area_list = (RelativeLayout) view.findViewById(R.id.chooseseat_layout_changearea_root);
tv_a = (TextView) view.findViewById(R.id.theatrearea_tv_a);
tv_a.setOnClickListener(this);
tv_b = (TextView) view.findViewById(R.id.theatrearea_tv_b);
tv_b.setOnClickListener(this);
tv_c = (TextView) view.findViewById(R.id.theatrearea_tv_c);
tv_c.setOnClickListener(this);
tv_d = (TextView) view.findViewById(R.id.theatrearea_tv_d);
tv_d.setOnClickListener(this);
tv_e = (TextView) view.findViewById(R.id.theatrearea_tv_e);
tv_e.setOnClickListener(this);
img_collapse = (ImageView) view.findViewById(R.id.chooseseat_img_collapse);
img_collapse.setOnClickListener(this);
selectedBgRes = R.drawable.rectangle_f8b451;
normalBgRes = R.drawable.rectangle_c5c5c5;
SparseArray<Integer> colors = new SparseArray<>();
colors.put(1, ResLoader.Color(mCtx, R.color.color_333));
colors.put(2, Color.parseColor("#727272"));
colors.put(3, Color.parseColor("#f8b551"));
SparseArray<Integer> textsizes = new SparseArray<>();
textsizes.put(1, 13);
textsizes.put(2, 10);
textsizes.put(3, 9);
tv_a.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("A区", bean.getAreaCenter(), 100, price)).format());
tv_b.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("B区", bean.getAreaLeft(), 100, price)).format());
tv_c.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("C区", bean.getAreaRight(), 100, price)).format());
tv_d.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("D区", bean.getAreaBottom(), 100, price)).format());
tv_e.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("E区", bean.getAreaTop(), 100, price)).format());
}
}
private SparseArray formatContents(String title, int currentSeats, int seatCount, float price) {
SparseArray<String> contents = new SparseArray<>();
contents.put(1, title + "\n");
contents.put(2, currentSeats + "/" + seatCount + "\n");
contents.put(3, "金币 " + price);
return contents;
}
private void initSeatView(String title, float price, String time) {
final Context context = GoldenLineApplication.getInstance().getApplicationContext();
AuditoriumInfo auditoriumInfo = new AuditoriumInfo();
auditoriumInfo.setSession(TimeUtil.getInstance().dateAdd(0, time, "yyyy-MM-dd HH:mm:ss", 0));
auditoriumInfo.setAuditoriumName(title);
auditoriumInfo.setMaxSeatNum(1);
auditoriumInfo.setPrice(price);
seatTable = DataEmulate.initSeatTable3(context);
tv_title.setText(title);
tv_time.setText(formatTime(auditoriumInfo.getSession()));
selectedSeats = new MySelectedSeats(
seatSelectionView,
auditoriumInfo,
context,
layout_bottom_bar,
layout_container,
tv_price,
null);
//配置座位数据
seatSelectionView.setData(seatTable);
//设置背景色
seatSelectionView.setBackground(0xF7F7F7);
//配置行标记
seatSelectionView.setRowBar(new RowBarImpl(MeasureUtils.dp2px(context, 18), 10, 0x80000000, 0xFFF0F0F0, MeasureUtils.dp2px(context, 12)));
//配置概要图
seatSelectionView.setOutlineMap(new OutlineMapImpl(MeasureUtils.getScreenWidth(context) * 2 / 5, 0x70000000, 0xFFFAFAFA, 0xFFFF5050, 0xFF20FF20, 0xC0F0F020, MeasureUtils.dp2px(context, 1f)));
//配置概要图显示时间
seatSelectionView.setOutlineDelay(1000);
//配置中线
seatSelectionView.setMidLine(new MidLineImpl(MeasureUtils.dp2px(context, 2), 0xFFC0C0C0, true, new float[]{MeasureUtils.dp2px(context, 2), MeasureUtils.dp2px(context, 5)}));
//配置座位各种状态的图片
imagePool = new SeatImagePoolImpl();
imagePool.setImage(SeatType.SINGLE, SeatState.AVAILABLE, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.seat_nor));
imagePool.setImage(SeatType.SINGLE, SeatState.UNAVAILABLE, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.seat_selected));
imagePool.setImage(SeatType.SINGLE, SeatState.SELECTED, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.seat_selected));
imagePool.setImage(SeatType.SINGLE, SeatState.MALE, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.private_chat_male_icon));
imagePool.setImage(SeatType.SINGLE, SeatState.FEMALE, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.private_chat_female_icon));
imagePool.setImage(SeatType.SINGLE, SeatState.DEFAULT, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.icon_default_portrait_87));
imagePool.setImage(SeatType.SINGLE, SeatState.REDPOIN, BitmapUtils.decodeFromResource(context.getResources(), R.mipmap.notify_red));
seatSelectionView.setImagePool(imagePool);
//配置座位选择监听器
seatSelectionView.setSeatSelectionListener(new SeatSelectionListener() {
@Override
public boolean onSeatSelect(Seat seat) {
mSeatRow = String.valueOf(seat.getRow() + 1);
mSeatCloneId = seat.getColumnId();
return selectedSeats.onSelect(seat);
}
@Override
public boolean onSeatDeselect(Seat seat) {
//处理座位选择事件
return selectedSeats.onDeselect(seat);
}
@Override
public void onUnavailableSeatSelect(Seat seat) {
if (seat != null && seat.getSeatUser() != null) {
ToastUtil.showToast("该座位以被预约");
}
}
@Override
public void onInvalidAreaClick() {
}
});
}
private String formatTime(String time) {
int dayOfWeek = TimeUtil.getInstance().getDayOfWeek(time);
StringBuilder sb = new StringBuilder();
switch (dayOfWeek) {
case 1:
sb.append("周日");
break;
case 2:
sb.append("周一");
break;
case 3:
sb.append("周二");
break;
case 4:
sb.append("周三");
break;
case 5:
sb.append("周四");
break;
case 6:
sb.append("周五");
break;
case 7:
sb.append("周六");
break;
}
String mm = time.substring(5, 7);
if (mm.startsWith("0")) {
mm = mm.substring(1);
}
String date = time.substring(8, 10);
if (date.startsWith("0")) {
date = date.substring(1);
}
sb.append(" ").append(mm).append("月");
sb.append(date).append("日");
sb.append(" ").append(time.substring(11, 16));
return sb.toString();
}
@Override
public void netError(int state) {
}
@Override
public void showLoadingDialog() {
mDialog = ProgressDialog.show(mCtx, "正在获取选座信息", "请稍后...");
}
@Override
public void dismissLoadingDialog() {
mDialog.dismiss();
}
@Override
public void showMsg(String msg) {
ToastUtil.showToast(msg);
}
@Override
public void updateSeatTable(List<SeatUserBean> list) {
setSeatAvalable(SeatState.AVAILABLE);
seatSelectionView.invalidate();
for (SeatUserBean item : list) {
//因为数据在选座的时候没有0排0座,所以默认加1了,这要将座位还原回去
int clone = item.getCloneId() - 1;
int row = item.getRowId() - 1;
//因为第四排是没有座位所有还原回去一个
if (clone >= 3) {
clone = clone+1;
}
Seat seat = seatTable.getSeat(row, clone);
seat.setState(SeatState.UNAVAILABLE + "_" + item.getUserId());
seat.setSeatUser(item);
SeatViewUtls.loadUserImage(mCtx.getResources(), seat, item, seatSelectionView, imagePool);
}
}
/**
* 初始化时座位都是不可选的
* 当网络完成之后,将所有座位设置成可用状态
*/
private void setSeatAvalable(String state) {
for (int row = 0; row < 10; row++) {
for (int column = 0; column < 11; column++) {
if (column == 3)
continue;
Seat seat = seatTable.getSeat(row, column);
seat.setState(state);
seat.setSeatUser(null);
}
}
seatSelectionView.refreshOutlineMap();
}
private int selectedBgRes;
private int normalBgRes;
private int currentArea = 0;
private String selectedareaId;
/**
* 切换区的时候,切换背景颜色
*
* @param desArea desArea
*/
private void changeBg(int desArea) {
selectedSeats.removeAllSeat();
setSeatAvalable(SeatState.UNAVAILABLE);
seatSelectionView.invalidate();
if (currentArea == desArea) return;
switch (currentArea) {
case 0:
tv_a.setBackgroundResource(normalBgRes);
break;
case 1:
tv_b.setBackgroundResource(normalBgRes);
break;
case 2:
tv_c.setBackgroundResource(normalBgRes);
break;
case 3:
tv_d.setBackgroundResource(normalBgRes);
break;
case 4:
tv_e.setBackgroundResource(normalBgRes);
break;
}
switch (desArea) {
case 0:
selectedareaId = "A";
tv_a.setBackgroundResource(selectedBgRes);
mPresenter.getSeatUserInfo(liveId, mScreenInBean.getHallId(), "A");
break;
case 1:
selectedareaId = "B";
tv_b.setBackgroundResource(selectedBgRes);
mPresenter.getSeatUserInfo(liveId, mScreenInBean.getHallId(), "B");
break;
case 2:
tv_c.setBackgroundResource(selectedBgRes);
mPresenter.getSeatUserInfo(liveId, mScreenInBean.getHallId(), "C");
selectedareaId = "C";
break;
case 3:
selectedareaId = "D";
tv_d.setBackgroundResource(selectedBgRes);
mPresenter.getSeatUserInfo(liveId, mScreenInBean.getHallId(), "D");
break;
case 4:
selectedareaId = "E";
tv_e.setBackgroundResource(selectedBgRes);
mPresenter.getSeatUserInfo(liveId, mScreenInBean.getHallId(), "E");
break;
}
currentArea = desArea;
changeArea(true);
}
private void changeArea(boolean isCollapse) {
if (isCollapse) {
YoYo.with(Techniques.SlideOutUp).duration(1200).interpolate(new AccelerateDecelerateInterpolator())
.withListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
if (layout_area_list.getVisibility() != View.VISIBLE)
layout_area_list.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
})
.playOn(layout_area_list);
} else {
YoYo.with(Techniques.SlideInDown).duration(1200).interpolate(new AccelerateDecelerateInterpolator())
.withListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
if (layout_area_list.getVisibility() != View.VISIBLE)
layout_area_list.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
})
.playOn(layout_area_list);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.theatrearea_tv_a:
changeBg(0);
break;
case R.id.theatrearea_tv_b:
changeBg(1);
break;
case R.id.theatrearea_tv_c:
changeBg(2);
break;
case R.id.theatrearea_tv_d:
changeBg(3);
break;
case R.id.theatrearea_tv_e:
changeBg(4);
break;
case R.id.chooseseat_img_collapse:
changeArea(true);
break;
}
}
}