ResultElectionFragmentBack.java
8.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
package com.sunvote.xpadapp.fragments;
import java.util.ArrayList;
import com.sunvote.xpadapp.MainActivity;
import com.sunvote.xpadapp.R;
import com.sunvote.xpadapp.base.MyFragment;
import com.sunvote.xpadapp.db.modal.BillInfo;
import com.sunvote.xpadapp.db.modal.MultiTitleItem;
import com.sunvote.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface;
import com.sunvote.xpadcomm.XPadApiInterface.BatchVoteInfo;
import android.annotation.SuppressLint;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnScrollChangeListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class ResultElectionFragmentBack extends MyFragment {
private String TAG = "ResultElectionFragment";
public String[] aryContent;
public byte[] data;
public BillInfo bill;
public ArrayList<MultiTitleItem> subInfo;
public ArrayList<ResultItem> aryList;
public String resultStr;
public String[] options;
private TextView tvTitle;
private ListView listview;
private MyAdapter mAdapter;
private int paiminType;
public class ResultItem {
public String name;//姓名
public int nameIndex;//排名
public int agreeNum;// 赞成票数
public int opposeNum;// 反对票数
public int abstantNum;// 弃权票数
public int electionResult;//结果
}
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.fragment_result_election, container, false);
final MainActivity mact = (MainActivity) getActivity();
initData();
ImageButton btnBack = (ImageButton) view.findViewById(R.id.fragment_result_election_btn_back);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.remove(ResultElectionFragmentBack.this);
tx.commit();
//mact.resultFragment = null;
}
});
listview = (ListView) view.findViewById(R.id.fragment_result_election_list);
aryContent = resultStr.split(";");
if (aryContent.length > 0) {
paiminType = aryContent[0].equals("0") ? 0 : 1;
}
/*aryList = new ArrayList<ResultItem>();
for (int i = 1; i < aryContent.length; i++) {
ResultItem tempItem = new ResultItem();
if (i < subInfo.size()) {
MultiTitleItem it = subInfo.get(i-1);
tempItem.name = it.title;
tempItem.piaoshu = Integer.parseInt(aryContent[i]);
} else {
String[] aryOther = aryContent[i].split(",");
if (aryOther.length > 1) {
tempItem.name = aryOther[0];
tempItem.piaoshu = Integer.parseInt(aryOther[1]);
}
}
aryList.add(tempItem);
}
calcPaimin();*/
mAdapter = new MyAdapter(getActivity());
listview.setAdapter(mAdapter);
tvTitle = (TextView) view.findViewById(R.id.fragment_result_election_bill_title);
tvTitle.setText(bill.title);
return view;
}
int fenmu;//百分比分母
int goToBe;//应到
int goTo;//实到
private void initData() {
int bitNum = data[2] & 0xf;
int digiters = data[2] >> 4 & 0xf;
int voteNo = data[3] & 0xff;
int resultSelectModel = data[4] & 0xf; //控制选举结果模式
int resultShowModel = data[4] >> 4 & 0xf; //显示结果模式
aryList = new ArrayList<ResultItem>();
if (bitNum == 0) { //单字节数值
fenmu = data[5] & 0xff;
goToBe= data[6] & 0xff;
goTo= data[7] & 0xff;
int pos = 8;
int i = pos;
for (; i < data.length; i++) {
if (data[i] == '\0')
break;
ResultItem it = new ResultItem();
it.nameIndex = data[pos] & 0xff;
int nameLenght = data[pos++] & 0xff;
String hex = Integer.toHexString((data[pos++] << 8 | data[pos+nameLenght]) & 0xffff);
int pollNum = data[pos++] & 0xff;
subInfo = mMainActivity.dbm.getCandidateList(mMainActivity.meetingId, bill.billId);
aryList.add(it);
}
} else {
fenmu = (data[5] << 8 | data[6]) & 0xffff;
goToBe = (data[7] << 8 | data[8]) & 0xffff;
goTo = (data[9] << 8 | data[10]) & 0xffff;
int pos = 11;
int i = pos;
for (; i < data.length; i++) {
if (data[i] == '\0')
break;
ResultItem it = new ResultItem();
it.nameIndex = (data[pos] << 8 | data[pos++]) & 0xffff;
int nameLenght = (data[pos++] << 8 | data[pos++]) & 0xffff;
String hex = Integer.toHexString((data[pos++] << 8 | data[pos+nameLenght]) & 0xffff);
int pollNum = data[pos++] & 0xff;
subInfo = mMainActivity.dbm.getCandidateList(mMainActivity.meetingId, bill.billId);
aryList.add(it);
}
}
}
/*public void calcPaimin(){
for(int i=0;i<aryList.size();i++){
for(int j=i;j<aryList.size();j++){
ResultItem it = aryList.get(i);
ResultItem it1 = aryList.get(j);
if(it1.piaoshu>it.piaoshu){
aryList.remove(j);
aryList.add(i, it1);
}
}
}
int paimin = 1;
int binlie = 0;
for(int i=0;i<aryList.size();i++){
ResultItem it = aryList.get(i);
if( i>0 ){
ResultItem pit = aryList.get(i-1);
if(it.piaoshu == pit.piaoshu){
binlie++;
}else if(it.piaoshu < pit.piaoshu){
paimin++;
if(paiminType==1){
paimin+= binlie;
}
binlie=0;
}
}
it.paimin = paimin;
}
}*/
/*
*
* 新的选举结果格式如 0;2;2;3;4;5;张三,3 0代表排名方式按1123,如传1代表排名方式1134,就是排名递增
* 从第二个数字开始为候选人名单表格里面的按ID排序的候选人的赞成票数 另选他人的就接在候选人后面
*
*
*
*
*/
/*
* MyAdapter
*
*/
private class MyAdapter extends BaseAdapter {
private LayoutInflater mInflater; //
public MyAdapter(Context context) {
this.mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return aryList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return aryList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
return super.isEnabled(position);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Log.v("BaseAdapterTest", "getView " + position + " " + convertView);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_result_election_item, null);
holder = new ViewHolder();
holder.tvNum = (TextView) convertView.findViewById(R.id.item_result_election_num);
holder.tvName = (TextView) convertView.findViewById(R.id.item_result_election_name);
holder.tvAgree = (TextView) convertView.findViewById(R.id.item_result_election_agree);
holder.tvOppose = (TextView) convertView.findViewById(R.id.item_result_election_oppose_num);
holder.tvAbstant = (TextView) convertView.findViewById(R.id.item_result_election_abstant_num);
holder.tvResult = (TextView) convertView.findViewById(R.id.item_result_election_result);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ResultItem it = aryList.get(position);
holder.tvNum.setText(String.valueOf(it.nameIndex));
holder.tvName.setText(it.name);
holder.tvAgree.setText(String.valueOf(it.agreeNum));
holder.tvOppose.setText(String.valueOf(it.opposeNum));
holder.tvAbstant.setText(String.valueOf(it.abstantNum));
holder.tvResult.setText(String.valueOf(it.electionResult));
return convertView;
}
public final class ViewHolder {
public TextView tvNum;
public TextView tvName;
public TextView tvAgree;
public TextView tvOppose;
public TextView tvAbstant;
public TextView tvResult;
}
}
}