ResultVoteFragment.java
13.1 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
package com.sunvote.xpadapp.fragments;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.sunvote.util.LogUtil;
import com.sunvote.xpadapp.MainActivity;
import com.sunvote.xpadapp.R;
import com.sunvote.xpadapp.base.BaseFragment;
import com.sunvote.xpadcomm.XPadApiInterface;
import org.apache.tools.ant.Main;
import java.text.DecimalFormat;
public class ResultVoteFragment extends BaseFragment {
private static String TAG = ResultVoteFragment.class.getSimpleName();
private XPadApiInterface.VoteInfo voteInfo;
private TextView yingdaoresult;
private TextView shidaoresult;
// 表決结果
private TextView fragmentResultMemo;
private TextView fragmentMemo;
//
private RelativeLayout dataTitleLayout1;
private RelativeLayout dataTitleLayout2;
private RelativeLayout dataTitleLayout3;
private RelativeLayout dataTitleLayout4;
// private LinearLayout dResult;
// private LinearLayout pResult;
public static String formatDoubleToString(double value, Integer digits, boolean remove) {
if (value == 0 || value == 100) {
DecimalFormat df = new DecimalFormat("0");
return df.format(value);
}
if (digits == null || digits < 0) {
return String.valueOf(value);
} else if (digits == 0) {
DecimalFormat df = new DecimalFormat("0");
return df.format(value);
} else {
String temp = "0";
if (remove) {
temp = "#";
}
StringBuffer buffer = new StringBuffer("0.");
for (int i = 0; i < digits; i++) {
buffer.append(temp);
}
DecimalFormat df = new DecimalFormat(buffer.toString());
return df.format(value);
}
}
public void setVoteInfo(XPadApiInterface.VoteInfo voteInfo) {
this.voteInfo = voteInfo;
}
private View createView(String txt,int color) {
TextView tv1 = new TextView(getActivity());
ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
tv1.setLayoutParams(vlp);//设置TextView的布局
tv1.setText(txt);
tv1.setGravity(Gravity.CENTER);
tv1.setTextSize(25);
tv1.setTextColor(color);
return tv1;
}
@Override
public void onResume() {
super.onResume();
((MainActivity)getActivity()).setBackgroundColor(Color.parseColor("#042148"));
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_result_vote, container, false);
root.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
yingdaoresult = root.findViewById(R.id.yingdaoresult);
shidaoresult = root.findViewById(R.id.shidaoresult);
fragmentResultMemo = root.findViewById(R.id.fragment_result_memo);
fragmentMemo = root.findViewById(R.id.fragment_memo);
dataTitleLayout1 = root.findViewById(R.id.data_title_layout1);
dataTitleLayout2 = root.findViewById(R.id.data_title_layout2);
dataTitleLayout3 = root.findViewById(R.id.data_title_layout3);
dataTitleLayout4 = root.findViewById(R.id.data_title_layout4);
showResult();
return root;
}
private void showResult() {
int pass = voteInfo.resultInfo.bits & 0xF;
int xiaoShuWei = (voteInfo.resultInfo.bits >> 4) & 0xF;
int fenmu = voteInfo.resultInfo.num0;
LogUtil.d(TAG, "xiaoshu:" + xiaoShuWei + " fenmu:" + fenmu);
if (voteInfo.resultInfo.num1 != 0xffff) {
yingdaoresult.setText("" + voteInfo.resultInfo.num1);
}
if (voteInfo.resultInfo.num2 != 0xffff) {
shidaoresult.setText("" + voteInfo.resultInfo.num2);
}
if (pass == 0xf) {
fragmentResultMemo.setText("");
} else if (pass == 0) {
fragmentResultMemo.setText(getString(R.string.no_pass));
} else {
fragmentResultMemo.setText(getString(R.string.pass));
}
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT,1.0f);
if (voteInfo.resultInfo.resultType == 1) {
fragmentMemo.setText(getString(R.string.biaojue_result));
String szc = "" ;
String sfd = "" ;
String swa = "" ;
if (fenmu > 0 && fenmu != 0xffff) {
double pzc = voteInfo.resultInfo.num4 * 1.0 / fenmu * 100;
szc = formatDoubleToString(pzc, xiaoShuWei, false);
double pfd = voteInfo.resultInfo.num5 * 1.0 / fenmu * 100;
sfd = formatDoubleToString(pfd, xiaoShuWei, false);
double pwa = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
swa = formatDoubleToString(pwa, xiaoShuWei, false);
}
if (voteInfo.resultInfo.num4 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num4 ;
if(szc != null && !"".equals(szc)){
text += "(" + szc + "%)" ;
}
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.agree));
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text2))).setText(text);
}
if (voteInfo.resultInfo.num5 != 0xffff) {
dataTitleLayout2.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num5 ;
if(sfd != null && !"".equals(sfd)){
text += "(" + sfd + "%)" ;
}
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.oppose));
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text2))).setText(text);
}
if (voteInfo.resultInfo.num3 != 0xffff) {
dataTitleLayout3.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num3 ;
if(swa != null && !"".equals(swa)){
text += "(" + swa + "%)" ;
}
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.weian));
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text2))).setText(text);
}
} else {
String szc = "";
String sfd = "";
String swa = "";
if (fenmu > 0 && fenmu != 0xffff) {
double pzc = voteInfo.resultInfo.num4 * 1.0 / fenmu * 100;
szc = formatDoubleToString(pzc, xiaoShuWei, false);
double pfd = voteInfo.resultInfo.num5 * 1.0 / fenmu * 100;
sfd = formatDoubleToString(pfd, xiaoShuWei, false);
double pwa = voteInfo.resultInfo.num6 * 1.0 / fenmu * 100;
swa = formatDoubleToString(pwa, xiaoShuWei, false);
}
if (voteInfo.resultInfo.num4 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num4 ;
if(szc != null && !"".equals(szc)){
text += "(" + szc + "%)" ;
}
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text2))).setText(text);
}
if (voteInfo.resultInfo.num5 != 0xffff) {
dataTitleLayout2.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num5 ;
if(sfd != null && !"".equals(sfd)){
text += "(" + sfd + "%)" ;
}
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text2))).setText(text);
}
if (voteInfo.resultInfo.num6 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
String text = "" + voteInfo.resultInfo.num6 ;
if(swa != null && !"".equals(swa)){
text += "(" + swa + "%)" ;
}
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text2))).setText(text);
}
if (voteInfo.resultInfo.resultType == 2) {
fragmentMemo.setText(getString(R.string.biaojue_result));
if (voteInfo.resultInfo.num4 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.agree));
}
if (voteInfo.resultInfo.num5 != 0xffff) {
dataTitleLayout2.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.oppose));
}
if (voteInfo.resultInfo.num6 != 0xffff) {
dataTitleLayout3.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.abstant));
}
if (pass == 0) {
fragmentResultMemo.setText(getString(R.string.no_pass));
} else {
fragmentResultMemo.setText(getString(R.string.pass));
}
} else if (voteInfo.resultInfo.resultType == 4) {
fragmentMemo.setText(getString(R.string.ceping_result));
if (voteInfo.resultInfo.num4 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.manyi));
}
if (voteInfo.resultInfo.num5 != 0xffff) {
dataTitleLayout2.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.jbmanyi));
}
if (voteInfo.resultInfo.num6 != 0xffff) {
dataTitleLayout3.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.bumanyi));
}
if (pass == 0) {
fragmentResultMemo.setText(getString(R.string.manyi));
} else if (pass == 1) {
fragmentResultMemo.setText(getString(R.string.jbmanyi));
} else {
fragmentResultMemo.setText(getString(R.string.bumanyi));
}
} else if (voteInfo.resultInfo.resultType == 12) {
fragmentMemo.setText(getString(R.string.ceping_result));
if (voteInfo.resultInfo.num4 != 0xffff) {
dataTitleLayout1.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.manyi));
}
if (voteInfo.resultInfo.num5 != 0xffff) {
dataTitleLayout2.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.bumanyi));
}
if (voteInfo.resultInfo.num6 != 0xffff) {
dataTitleLayout3.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.fcbumanyi));
}
if (pass == 0) {
fragmentResultMemo.setText(getString(R.string.manyi));
} else if (pass == 1) {
fragmentResultMemo.setText(getString(R.string.bumanyi));
} else {
fragmentResultMemo.setText(getString(R.string.fcbumanyi));
}
}
if(voteInfo.resultInfo.num3 != 0xffff){
double opt4 = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
String strOpt4 = formatDoubleToString(opt4, xiaoShuWei, false);
dataTitleLayout4.setVisibility(View.VISIBLE);
((TextView)(dataTitleLayout4.findViewById(R.id.data_title_layout4_text1))).setText(getString(R.string.weian));
String text = "" + voteInfo.resultInfo.num3 ;
if(strOpt4 != null && !"".equals(strOpt4)){
text += "(" + strOpt4 + "%)" ;
}
((TextView)(dataTitleLayout4.findViewById(R.id.data_title_layout4_text2))).setText(text);
}
}
if (pass == 0xf) {
fragmentResultMemo.setText("");
}
}
}