ResultVoteFragmentBack.java
12.8 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
package com.sunvote.xpadapp.fragments;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.sunvote.xpadapp.MainActivity;
import com.sunvote.xpadapp.R;
import com.sunvote.xpadapp.base.BaseFragment;
import com.sunvote.xpadapp.db.modal.BillInfo;
import com.sunvote.xpadapp.db.modal.MultiTitleItem;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.logging.Handler;
public class ResultVoteFragmentBack extends BaseFragment {
public BillInfo bill;
public ArrayList<MultiTitleItem> subInfo;
public VoteInfo voteInfo;
public String resultStr;
String[] options;
String TAG = "ResultVoteFragment";
private int page = 0;
TextView tvBillTitle;
TextView tvSubTitle;
TextView tvOption1;
TextView tvValue1;
TextView tvOption2;
TextView tvValue2;
TextView tvOption3;
TextView tvValue3;
TextView tvOption4;
TextView tvValue4;
TextView tvMemo;
TextView tvPage;
private Handler mHandle;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_result_vote_back, container, false);
final MainActivity mact = (MainActivity) getActivity();
tvBillTitle = (TextView) view.findViewById(R.id.fragment_result_bill_title);
tvSubTitle = (TextView) view.findViewById(R.id.fragment_result_sub_title);
tvOption1 = (TextView) view.findViewById(R.id.fragment_result_option1);
tvValue1 = (TextView) view.findViewById(R.id.fragment_result_value1);
tvOption2 = (TextView) view.findViewById(R.id.fragment_result_option2);
tvValue2 = (TextView) view.findViewById(R.id.fragment_result_value2);
tvOption3 = (TextView) view.findViewById(R.id.fragment_result_option3);
tvValue3 = (TextView) view.findViewById(R.id.fragment_result_value3);
tvOption4 = (TextView) view.findViewById(R.id.fragment_result_option4);
tvValue4 = (TextView) view.findViewById(R.id.fragment_result_value4);
tvMemo = (TextView) view.findViewById(R.id.fragment_result_memo);
RelativeLayout pagePanel = (RelativeLayout) view.findViewById(R.id.fragment_result_page_panel);
tvPage = (TextView) view.findViewById(R.id.fragment_result_page);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
Button btnPageUp = (Button) view.findViewById(R.id.fragment_result_pageup);
Button btnPageDown = (Button) view.findViewById(R.id.fragment_result_pagedown);
btnPageUp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (page > 0) {
page--;
showResultByPage();
tvPage.setText(String.format("%d/%d", page + 1, subInfo.size()));
}
}
});
btnPageDown.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (page < subInfo.size() - 1) {
page++;
showResultByPage();
tvPage.setText(String.format("%d/%d", page + 1, subInfo.size()));
}
}
});
ImageButton btnBack = (ImageButton) view.findViewById(R.id.fragment_result_vote_btn_back);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.remove(ResultVoteFragmentBack.this);
tx.commit();
// mact.resultFragment = null;
}
});
pagePanel.setVisibility(View.INVISIBLE);
// if (bill != null && bill.title != null) {
// //tvBillTitle.setText(bill.title);
// }
// tvBillTitle.setText(getString(R.string.ceping_result));
return view;
}
private void showResult(){
int pass = voteInfo.resultInfo.bits & 0xF;
int xiaoShuWei = (voteInfo.resultInfo.bits >> 4) & 0xF;
int fenmu = voteInfo.resultInfo.num0;
Log.d(TAG, "xiaoshu:" + xiaoShuWei + " fenmu:" + fenmu);
if (voteInfo.resultInfo.resultType == 0) {// ???
tvBillTitle.setText(getString(R.string.signin_result));
// tvSubTitle.setText("???????");
tvOption1.setText(getString(R.string.yindao) + getString(R.string.maohao));
tvValue1.setText(String.valueOf(voteInfo.resultInfo.num2) + getString(R.string.ren));
tvOption2.setText(getString(R.string.shidao) + getString(R.string.maohao));
tvValue2.setText(String.valueOf(voteInfo.resultInfo.num3) + getString(R.string.ren));
tvOption3.setText(getString(R.string.weidao) + getString(R.string.maohao));
tvValue3.setText(String.valueOf(voteInfo.resultInfo.num1) + getString(R.string.ren));
if (pass == 0xf) {
tvMemo.setText("");
} else if (pass == 0) {
tvMemo.setText(getString(R.string.bufuherenshu));
} else {
tvMemo.setText(getString(R.string.fuherenshu));
}
} else if (voteInfo.resultInfo.resultType == 1) {
// tvBillTitle.setText(getString(R.string.biaojue_result));
String strYDSD = "";
if (voteInfo.resultInfo.num1 != 0xffff) {
strYDSD = strYDSD + getString(R.string.yindao) + ":" + voteInfo.resultInfo.num1;
}
if (voteInfo.resultInfo.num2 != 0xffff) {
strYDSD = strYDSD + " " + getString(R.string.shidao) + ":" + voteInfo.resultInfo.num2;
}
tvBillTitle.setText(strYDSD);
tvOption1.setText(getString(R.string.agree));
tvValue1.setText(String.valueOf(voteInfo.resultInfo.num4) + getString(R.string.piao));
tvOption2.setText(getString(R.string.oppose));
tvValue2.setText(String.valueOf(voteInfo.resultInfo.num5) + getString(R.string.piao));
tvOption3.setText(getString(R.string.weian));
tvValue3.setText(String.valueOf(voteInfo.resultInfo.num3) + getString(R.string.piao));
if (fenmu > 0 && fenmu != 0xffff) {
double pzc = voteInfo.resultInfo.num4 * 1.0 / fenmu * 100;
String szc = formatDoubleToString(pzc, xiaoShuWei, false);
double pfd = voteInfo.resultInfo.num5 * 1.0 / fenmu * 100;
String sfd = formatDoubleToString(pfd, xiaoShuWei, false);
double pwa = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
String swa = formatDoubleToString(pwa, xiaoShuWei, false);
tvValue1.setText(String.valueOf(voteInfo.resultInfo.num4) + " (" + szc + "%)");
tvValue2.setText(String.valueOf(voteInfo.resultInfo.num5) + " (" + sfd + "%)");
tvValue3.setText(String.valueOf(voteInfo.resultInfo.num3) + " (" + swa + "%)");
}
if (voteInfo.resultInfo.num4 == 0xffff) {
tvOption1.setText("");
tvValue1.setText(String.valueOf(""));
}
if (voteInfo.resultInfo.num5 == 0xffff) {
tvOption2.setText("");
tvValue2.setText(String.valueOf(""));
}
if (voteInfo.resultInfo.num3 == 0xffff) {
tvOption3.setText("");
tvValue3.setText(String.valueOf(""));
}
if (pass == 0xf) {
tvMemo.setText("");
} else if (pass == 0) {
tvMemo.setText(getString(R.string.biaojue_result)+getString(R.string.maohao)+getString(R.string.no_pass));
} else {
tvMemo.setText(getString(R.string.biaojue_result)+getString(R.string.maohao)+getString(R.string.pass));
}
} else {
if (voteInfo.resultInfo.resultType == 2) {
// tvBillTitle.setText(getString(R.string.biaojue_result));
tvOption1.setText(getString(R.string.agree));
tvOption2.setText(getString(R.string.oppose));
tvOption3.setText(getString(R.string.abstant));
if (pass == 0) {
tvMemo.setText(getString(R.string.biaojue_result)+getString(R.string.maohao)+getString(R.string.no_pass));
} else {
tvMemo.setText(getString(R.string.biaojue_result)+getString(R.string.maohao)+getString(R.string.pass));
}
} else if (voteInfo.resultInfo.resultType == 4) {
tvOption1.setText(getString(R.string.manyi));
tvOption2.setText(getString(R.string.jbmanyi));
tvOption3.setText(getString(R.string.bumanyi));
if (pass == 0) {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.manyi));
} else if (pass == 1) {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.jbmanyi));
} else {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.bumanyi));
}
} else if (voteInfo.resultInfo.resultType == 12) {
tvOption1.setText(getString(R.string.manyi));
tvOption2.setText(getString(R.string.bumanyi));
tvOption3.setText(getString(R.string.fcbumanyi));
if (pass == 0) {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.manyi));
} else if (pass == 1) {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.bumanyi));
} else {
tvMemo.setText(getString(R.string.ceping_result)+getString(R.string.maohao)+getString(R.string.fcbumanyi));
}
}
if (pass == 0xf) {
tvMemo.setText("");
}
// bg:0,69,134
String strYDSD = "";
if (voteInfo.resultInfo.num1 != 0xffff) {
strYDSD = strYDSD + getString(R.string.yindao) + ":" + voteInfo.resultInfo.num1;
}
if (voteInfo.resultInfo.num2 != 0xffff) {
strYDSD = strYDSD + " " + getString(R.string.shidao) + ":" + voteInfo.resultInfo.num2;
}
tvBillTitle.setText(strYDSD);
tvOption4.setText(getString(R.string.weian));
tvValue4.setText(String.valueOf(voteInfo.resultInfo.num3) + getString(R.string.piao));
tvValue1.setText(String.valueOf(voteInfo.resultInfo.num4) + getString(R.string.piao));
tvValue2.setText(String.valueOf(voteInfo.resultInfo.num5) + getString(R.string.piao));
tvValue3.setText(String.valueOf(voteInfo.resultInfo.num6) + getString(R.string.piao));
if (fenmu > 0 && fenmu != 0xffff) {
double pzc = voteInfo.resultInfo.num4 * 1.0 / fenmu * 100;
String strOpt1 = formatDoubleToString(pzc, xiaoShuWei, false);
double pfd = voteInfo.resultInfo.num5 * 1.0 / fenmu * 100;
String strOpt2 = formatDoubleToString(pfd, xiaoShuWei, false);
double opt3 = voteInfo.resultInfo.num6 * 1.0 / fenmu * 100;
String strOpt3 = formatDoubleToString(opt3, xiaoShuWei, false);
double opt4 = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
String strOpt4 = formatDoubleToString(opt4, xiaoShuWei, false);
tvValue1.setText(String.valueOf(voteInfo.resultInfo.num4) + " (" + strOpt1 + "%)");
tvValue2.setText(String.valueOf(voteInfo.resultInfo.num5) + " (" + strOpt2 + "%)");
tvValue3.setText(String.valueOf(voteInfo.resultInfo.num6) + " (" + strOpt3 + "%)");
tvValue4.setText(String.valueOf(voteInfo.resultInfo.num3) + " (" + strOpt4 + "%)");
}
if (voteInfo.resultInfo.num4 == 0xffff) {
tvOption1.setText("");
tvValue1.setText(String.valueOf(""));
}
if (voteInfo.resultInfo.num5 == 0xffff) {
tvOption2.setText("");
tvValue2.setText(String.valueOf(""));
}
if (voteInfo.resultInfo.num6 == 0xffff) {
tvOption3.setText("");
tvValue3.setText(String.valueOf(""));
}
if (voteInfo.resultInfo.num3 == 0xffff) {
tvOption4.setText("");
tvValue4.setText(String.valueOf(""));
}
}
}
private void showResultByPage() {
Log.d("ResultVoteFragment", "page:" + page + " resultStr:" + resultStr);
if (options != null) {
if (options.length > 0) {
tvOption1.setText(options[0]);
}
if (options.length > 1) {
tvOption2.setText(options[1]);
}
if (options.length == 2) {
tvOption3.setVisibility(View.INVISIBLE);
tvValue3.setVisibility(View.INVISIBLE);
} else if (options.length > 2) {
tvOption3.setText(options[2]);
}
}
if (resultStr == null || resultStr.length() == 0) {
return;
}
if (subInfo == null) {
Log.d(TAG, "subInfo is null");
MultiTitleItem it = subInfo.get(page);
tvBillTitle.setText(it.title);
}
String[] results = resultStr.split(";");
Log.d("ResultVoteFragment", "results:" + results[page]);
String[] ary = results[page].split(",");
if (ary.length > 0) {
tvValue1.setText(ary[0]);
}
if (ary.length > 1) {
tvValue2.setText(ary[1]);
}
if (ary.length > 2) {
tvValue3.setText(ary[2]);
}
if (ary.length > options.length) {
if (ary[ary.length - 1].equals("0")) {
tvMemo.setText(getString(R.string.no_pass));
} else {
tvMemo.setText(getString(R.string.pass));
}
}
}
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);
}
}
}