ChangeScreenAreaPopupWindow.java
5.5 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
package com.cnlive.goldenline.ui.widget;
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.AnimationUtils;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.util.CharsequencePharse;
import com.cnlive.goldenline.util.ResLoader;
/**
* Description:重磅预约 更改选区 弹框
* Created on 2017/3/18
* Author : 萧
*/
public class ChangeScreenAreaPopupWindow extends PopupWindow {
private TextView tv_a;
private TextView tv_b;
private TextView tv_c;
private TextView tv_d;
private TextView tv_e;
private SparseArray<Integer> textsizes;
private SparseArray<Integer> colors;
private int currentArea = 0;
private int selectedBgRes;
private int normalBgRes;
public ChangeScreenAreaPopupWindow(Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.layout_changetheatrearea_pop, null);
view.setAnimation(AnimationUtils.loadAnimation(context, R.anim.pop_topenter_anim));
this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
ColorDrawable cd = new ColorDrawable(Color.WHITE);
this.setBackgroundDrawable(cd);
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
this.setFocusable(true);
this.setContentView(view);
this.setOutsideTouchable(false);
this.setAnimationStyle(R.style.popup_anim_top);
selectedBgRes = R.drawable.rectangle_f8b451;
normalBgRes = R.drawable.rectangle_c5c5c5;
colors = new SparseArray<>();
colors.put(1, ResLoader.Color(context, R.color.color_333));
colors.put(2, Color.parseColor("#727272"));
colors.put(3, Color.parseColor("#f8b551"));
textsizes = new SparseArray<>();
textsizes.put(1, 13);
textsizes.put(2, 10);
textsizes.put(3, 9);
tv_a = (TextView) view.findViewById(R.id.theatrearea_tv_a);
tv_b = (TextView) view.findViewById(R.id.theatrearea_tv_b);
tv_c = (TextView) view.findViewById(R.id.theatrearea_tv_c);
tv_d = (TextView) view.findViewById(R.id.theatrearea_tv_d);
tv_e = (TextView) view.findViewById(R.id.theatrearea_tv_e);
tv_a.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("A区", 12, 100, 38)).format());
tv_b.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("B区", 12, 100, 38)).format());
tv_c.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("C区", 12, 100, 38)).format());
tv_d.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("D区", 12, 100, 38)).format());
tv_e.setText(CharsequencePharse.init().setColors(colors).setTextSizes(textsizes).setContents(formatContents("E区", 12, 100, 38)).format());
tv_a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeBg(0);
}
});
tv_b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeBg(1);
}
});
tv_c.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeBg(2);
}
});
tv_d.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeBg(3);
}
});
tv_e.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
changeBg(4);
}
});
}
private SparseArray formatContents(String title, int currentSeats, int seatCount, int 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 changeBg(int desArea) {
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:
tv_a.setBackgroundResource(selectedBgRes);
break;
case 1:
tv_b.setBackgroundResource(selectedBgRes);
break;
case 2:
tv_c.setBackgroundResource(selectedBgRes);
break;
case 3:
tv_d.setBackgroundResource(selectedBgRes);
break;
case 4:
tv_e.setBackgroundResource(selectedBgRes);
break;
}
currentArea = desArea;
}
}