Blame view

C5/app/src/main/java/com/sunvote/xpadapp/fragments/ResultVoteFragment.java 9.39 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;
fac86401   孙向锦   初始化C5 Vote
11
12
  import android.widget.TextView;
  
4c3de86c   孙向锦   UI改版第一版
13
14
15
16
  import com.sunvote.util.LogUtil;
  import com.sunvote.xpadapp.R;
  import com.sunvote.xpadapp.base.BaseFragment;
  import com.sunvote.xpadcomm.XPadApiInterface;
fac86401   孙向锦   初始化C5 Vote
17
  
4c3de86c   孙向锦   UI改版第一版
18
  import java.text.DecimalFormat;
fac86401   孙向锦   初始化C5 Vote
19
  
4c3de86c   孙向锦   UI改版第一版
20
  public class ResultVoteFragment extends BaseFragment {
fac86401   孙向锦   初始化C5 Vote
21
  
4c3de86c   孙向锦   UI改版第一版
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
      private static String TAG = ResultVoteFragment.class.getSimpleName();
      private XPadApiInterface.VoteInfo voteInfo;
      private TextView yingdaoresult;
      private TextView shidaoresult;
      // 表決结果
      private TextView fragmentResultMemo;
      private TextView fragmentMemo;
      //
      private LinearLayout tResult;
      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;
      }
  
      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);
  
          tResult = root.findViewById(R.id.t_result);
          dResult = root.findViewById(R.id.d_result);
          pResult = root.findViewById(R.id.p_result);
          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);
          tResult.removeAllViews();
          dResult.removeAllViews();
          pResult.removeAllViews();
  
          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) {
                  tResult.addView(createView(getString(R.string.agree),Color.YELLOW),lp);
                  dResult.addView(createView("" + voteInfo.resultInfo.num4,Color.WHITE),lp);
                  pResult.addView(createView( szc + "%",Color.WHITE),lp);
  
              }
              if (voteInfo.resultInfo.num5 != 0xffff) {
                  tResult.addView(createView(getString(R.string.oppose),Color.YELLOW),lp);
                  dResult.addView(createView("" + voteInfo.resultInfo.num5,Color.WHITE),lp);
                  pResult.addView(createView( sfd + "%",Color.WHITE),lp);
              }
              if (voteInfo.resultInfo.num3 != 0xffff) {
                  tResult.addView(createView(getString(R.string.weian),Color.YELLOW),lp);
                  dResult.addView(createView("" + voteInfo.resultInfo.num3,Color.WHITE),lp);
                  pResult.addView(createView( swa + "%",Color.WHITE),lp);
              }
          } 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) {
                  dResult.addView(createView("" + voteInfo.resultInfo.num4,Color.WHITE), lp);
                  pResult.addView(createView(szc + "%",Color.WHITE), lp);
              }
              if (voteInfo.resultInfo.num5 != 0xffff) {
                  dResult.addView(createView("" + voteInfo.resultInfo.num5,Color.WHITE), lp);
                  pResult.addView(createView(sfd + "%",Color.WHITE), lp);
              }
              if (voteInfo.resultInfo.num6 != 0xffff) {
                  dResult.addView(createView("" + voteInfo.resultInfo.num6,Color.WHITE), lp);
                  pResult.addView(createView(swa + "%",Color.WHITE), lp);
              }
              if (voteInfo.resultInfo.resultType == 2) {
                  fragmentMemo.setText(getString(R.string.biaojue_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
                      tResult.addView(createView(getString(R.string.agree),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
                      tResult.addView(createView(getString(R.string.oppose),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
                      tResult.addView(createView(getString(R.string.abstant),Color.YELLOW), lp);
                  }
              } else if (voteInfo.resultInfo.resultType == 4) {
                  fragmentMemo.setText(getString(R.string.ceping_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
                      tResult.addView(createView(getString(R.string.manyi),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
                      tResult.addView(createView(getString(R.string.jbmanyi),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
                      tResult.addView(createView(getString(R.string.bumanyi),Color.YELLOW), lp);
                  }
              } else if (voteInfo.resultInfo.resultType == 12) {
                  fragmentMemo.setText(getString(R.string.ceping_result));
                  if (voteInfo.resultInfo.num4 != 0xffff) {
                      tResult.addView(createView(getString(R.string.manyi),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num5 != 0xffff) {
                      tResult.addView(createView(getString(R.string.bumanyi),Color.YELLOW), lp);
                  }
                  if (voteInfo.resultInfo.num6 != 0xffff) {
                      tResult.addView(createView(getString(R.string.fcbumanyi),Color.YELLOW), lp);
                  }
              }
              if(voteInfo.resultInfo.num3 != 0xffff){
                  double opt4 = voteInfo.resultInfo.num3 * 1.0 / fenmu * 100;
                  String strOpt4 = formatDoubleToString(opt4, xiaoShuWei, false);
                  tResult.addView(createView(getString(R.string.weian),Color.YELLOW),lp);
                  dResult.addView(createView("" +voteInfo.resultInfo.num3 ,Color.WHITE),lp);
                  pResult.addView(createView(strOpt4 + "%",Color.WHITE),lp);
              }
          }
       }
fac86401   孙向锦   初始化C5 Vote
216
  }