Blame view

C5/app/src/main/java/com/sunvote/xpadapp/fragments/ResultVoteFragment.java 13.1 KB
fac86401   孙向锦   初始化C5 Vote
1
2
  package com.sunvote.xpadapp.fragments;
  
4c3de86c   孙向锦   UI改版第一版
3
  import android.graphics.Color;
fac86401   孙向锦   初始化C5 Vote
4
  import android.os.Bundle;
fac86401   孙向锦   初始化C5 Vote
5
6
7
  import android.view.Gravity;
  import android.view.LayoutInflater;
  import android.view.View;
fac86401   孙向锦   初始化C5 Vote
8
  import android.view.View.OnClickListener;
4c3de86c   孙向锦   UI改版第一版
9
10
  import android.view.ViewGroup;
  import android.widget.LinearLayout;
49b6752a   孙向锦   批次表决
11
  import android.widget.RelativeLayout;
fac86401   孙向锦   初始化C5 Vote
12
13
  import android.widget.TextView;
  
4c3de86c   孙向锦   UI改版第一版
14
  import com.sunvote.util.LogUtil;
75386c29   孙向锦   选举结果UI修改
15
  import com.sunvote.xpadapp.MainActivity;
4c3de86c   孙向锦   UI改版第一版
16
17
18
  import com.sunvote.xpadapp.R;
  import com.sunvote.xpadapp.base.BaseFragment;
  import com.sunvote.xpadcomm.XPadApiInterface;
fac86401   孙向锦   初始化C5 Vote
19
  
49b6752a   孙向锦   批次表决
20
21
  import org.apache.tools.ant.Main;
  
4c3de86c   孙向锦   UI改版第一版
22
  import java.text.DecimalFormat;
fac86401   孙向锦   初始化C5 Vote
23
  
4c3de86c   孙向锦   UI改版第一版
24
  public class ResultVoteFragment extends BaseFragment {
fac86401   孙向锦   初始化C5 Vote
25
  
4c3de86c   孙向锦   UI改版第一版
26
27
28
29
30
31
32
33
      private static String TAG = ResultVoteFragment.class.getSimpleName();
      private XPadApiInterface.VoteInfo voteInfo;
      private TextView yingdaoresult;
      private TextView shidaoresult;
      // 表決结果
      private TextView fragmentResultMemo;
      private TextView fragmentMemo;
      //
49b6752a   孙向锦   批次表决
34
35
36
37
38
39
      private RelativeLayout dataTitleLayout1;
      private RelativeLayout dataTitleLayout2;
      private RelativeLayout dataTitleLayout3;
      private RelativeLayout dataTitleLayout4;
  //    private LinearLayout dResult;
  //    private LinearLayout pResult;
4c3de86c   孙向锦   UI改版第一版
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
  
      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;
      }
  
49b6752a   孙向锦   批次表决
84
85
86
87
88
89
      @Override
      public void onResume() {
          super.onResume();
          ((MainActivity)getActivity()).setBackgroundColor(Color.parseColor("#042148"));
      }
  
4c3de86c   孙向锦   UI改版第一版
90
91
92
93
94
95
96
97
98
99
100
      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);
49b6752a   孙向锦   批次表决
101
102
103
104
105
106
  
          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);
  
4c3de86c   孙向锦   UI改版第一版
107
108
109
110
111
112
113
114
115
          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);
4c3de86c   孙向锦   UI改版第一版
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
          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) {
49b6752a   孙向锦   批次表决
145
146
147
148
149
150
151
                  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);
4c3de86c   孙向锦   UI改版第一版
152
153
              }
              if (voteInfo.resultInfo.num5 != 0xffff) {
49b6752a   孙向锦   批次表决
154
155
156
157
158
159
160
                  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);
4c3de86c   孙向锦   UI改版第一版
161
162
              }
              if (voteInfo.resultInfo.num3 != 0xffff) {
49b6752a   孙向锦   批次表决
163
164
165
166
167
168
169
                  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);
4c3de86c   孙向锦   UI改版第一版
170
171
172
173
174
175
176
177
178
179
180
181
182
183
              }
          } 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) {
49b6752a   孙向锦   批次表决
184
185
186
187
188
189
190
  
                  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);
4c3de86c   孙向锦   UI改版第一版
191
192
              }
              if (voteInfo.resultInfo.num5 != 0xffff) {
49b6752a   孙向锦   批次表决
193
194
                  dataTitleLayout2.setVisibility(View.VISIBLE);
                  String text = "" + voteInfo.resultInfo.num5 ;
ab44099d   孙向锦   修改结果显示不正确
195
196
                  if(sfd != null && !"".equals(sfd)){
                      text += "(" + sfd + "%)" ;
49b6752a   孙向锦   批次表决
197
198
                  }
                  ((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text2))).setText(text);
4c3de86c   孙向锦   UI改版第一版
199
200
              }
              if (voteInfo.resultInfo.num6 != 0xffff) {
49b6752a   孙向锦   批次表决
201
202
                  dataTitleLayout1.setVisibility(View.VISIBLE);
                  String text = "" + voteInfo.resultInfo.num6 ;
ab44099d   孙向锦   修改结果显示不正确
203
204
                  if(swa != null && !"".equals(swa)){
                      text += "(" + swa + "%)" ;
49b6752a   孙向锦   批次表决
205
206
                  }
                  ((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text2))).setText(text);
4c3de86c   孙向锦   UI改版第一版
207
208
209
210
              }
              if (voteInfo.resultInfo.resultType == 2) {
                  fragmentMemo.setText(getString(R.string.biaojue_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
49b6752a   孙向锦   批次表决
211
212
                      dataTitleLayout1.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.agree));
4c3de86c   孙向锦   UI改版第一版
213
214
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
49b6752a   孙向锦   批次表决
215
216
                      dataTitleLayout2.setVisibility(View.VISIBLE);
                  ((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.oppose));
4c3de86c   孙向锦   UI改版第一版
217
218
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
49b6752a   孙向锦   批次表决
219
220
                      dataTitleLayout3.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.abstant));
4c3de86c   孙向锦   UI改版第一版
221
                  }
81252b84   孙向锦   C5 vote
222
223
224
225
226
                  if (pass == 0) {
                      fragmentResultMemo.setText(getString(R.string.no_pass));
                  } else {
                      fragmentResultMemo.setText(getString(R.string.pass));
                  }
4c3de86c   孙向锦   UI改版第一版
227
228
229
              } else if (voteInfo.resultInfo.resultType == 4) {
                  fragmentMemo.setText(getString(R.string.ceping_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
49b6752a   孙向锦   批次表决
230
231
                      dataTitleLayout1.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.manyi));
4c3de86c   孙向锦   UI改版第一版
232
233
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
49b6752a   孙向锦   批次表决
234
235
                      dataTitleLayout2.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.jbmanyi));
4c3de86c   孙向锦   UI改版第一版
236
237
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
49b6752a   孙向锦   批次表决
238
239
                      dataTitleLayout3.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.bumanyi));
4c3de86c   孙向锦   UI改版第一版
240
                  }
81252b84   孙向锦   C5 vote
241
242
243
244
245
246
247
                  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));
                  }
4c3de86c   孙向锦   UI改版第一版
248
249
250
              } else if (voteInfo.resultInfo.resultType == 12) {
                  fragmentMemo.setText(getString(R.string.ceping_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
49b6752a   孙向锦   批次表决
251
252
                      dataTitleLayout1.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout1.findViewById(R.id.data_title_layout1_text1))).setText(getString(R.string.manyi));
4c3de86c   孙向锦   UI改版第一版
253
254
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
49b6752a   孙向锦   批次表决
255
256
                      dataTitleLayout2.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout2.findViewById(R.id.data_title_layout2_text1))).setText(getString(R.string.bumanyi));
4c3de86c   孙向锦   UI改版第一版
257
258
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
49b6752a   孙向锦   批次表决
259
260
                      dataTitleLayout3.setVisibility(View.VISIBLE);
                      ((TextView)(dataTitleLayout3.findViewById(R.id.data_title_layout3_text1))).setText(getString(R.string.fcbumanyi));
4c3de86c   孙向锦   UI改版第一版
261
                  }
81252b84   孙向锦   C5 vote
262
263
264
265
266
267
268
                  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));
                  }
4c3de86c   孙向锦   UI改版第一版
269
270
271
272
              }
              if(voteInfo.resultInfo.num3 != 0xffff){
                  double opt4 = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
                  String strOpt4 = formatDoubleToString(opt4, xiaoShuWei, false);
49b6752a   孙向锦   批次表决
273
274
275
276
277
278
279
                  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);
4c3de86c   孙向锦   UI改版第一版
280
281
              }
          }
81252b84   孙向锦   C5 vote
282
283
284
          if (pass == 0xf) {
              fragmentResultMemo.setText("");
          }
4c3de86c   孙向锦   UI改版第一版
285
       }
fac86401   孙向锦   初始化C5 Vote
286
  }