MultiContentDetailFragmentback.java
14 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
package com.sunvote.xpadapp.fragments;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
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.utils.SharedPreferencesUtil;
import com.sunvote.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
public class MultiContentDetailFragmentback extends BaseFragment {
private String TAG = "MultiContentDetailFr";
private BillInfo bill;
private VoteInfo voteInfo;
// private MultiTitleItem data;
private TextView tvTitle;
private TextView tvTips;
private TextView ivReuslt;
private Button btnA;
private Button btnB;
private Button btnC;
private WebView webContent;
private RelativeLayout panelVote;
private RelativeLayout panelModify;
private RelativeLayout panelTips;
public String[] options;
private boolean showBackBtn;
// public int modifyable;
// public int secret;
private int scale = 0;
private int originSize = 200;
private int voteValue;
private RelativeLayout confirmLayout;
private TextView tvConfirmText;
//btn一行个数
private int btnNum = 10;
public String[] voteOptions = new String[13];
public ContentVoteOnBack contentBackListener;
private String DATABASE_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
public interface ContentVoteOnBack {
void onBack();
}
public void setInfo(BillInfo billInfo, VoteInfo vote, boolean isShowBack) {
bill = billInfo;
voteInfo = vote;
showBackBtn = isShowBack;
}
private void initOptions() {
voteOptions[0] = getString(R.string.zc_fd);
voteOptions[1] = getString(R.string.zc_fd_qq);
voteOptions[2] = getString(R.string.ty_fd_qq);
voteOptions[3] = getString(R.string.my_jbmy_bmy);
voteOptions[4] = getString(R.string.my_jbmy_bmy_blj);
voteOptions[5] = getString(R.string.my_jbmy_yb_bmy);
voteOptions[6] = getString(R.string.fcmy_my_blj_bmy_fcbmy);
voteOptions[7] = getString(R.string.fcty_ty_bqd_bty_fcbty);
voteOptions[8] = getString(R.string.yx_cz_bcz);
voteOptions[9] = getString(R.string.yx_cz_jbcz_bcz);
voteOptions[10] = getString(R.string.y_l_z_c);
voteOptions[11] = getString(R.string.my_bmy_fcbmy);
if (voteInfo == null) {
return;
}
if (voteInfo.mode == XPadApi.VoteType_Vote) {
if (voteInfo.mode1_msgType == 1) {
options = voteOptions[1].split("/");
} else if (voteInfo.mode1_msgType == 2) {
options = voteOptions[0].split("/");
} else if (voteInfo.mode1_msgType == 3) {
options = voteOptions[voteInfo.mode4 - 1].split("/");
}
} else if (voteInfo.mode == XPadApi.VoteType_Evaluate) {
if (voteInfo.mode1_msgType > 0) {
options = voteOptions[voteInfo.mode1_msgType - 1].split("/");
}
}
Log.d(TAG, "options:" + options.toString());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.fragment_multi_content_detailback, container, false);
initOptions();
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;//
}
});
final MainActivity mact = (MainActivity) getActivity();
tvTitle = (TextView) view.findViewById(R.id.content_detail_title);
if (bill.title != null) {
tvTitle.setText(bill.title);
}
webContent = (WebView) view.findViewById(R.id.content_detail_webview);
String filename = "file:///" + DATABASE_PATH + "/sunvote/" + mact.meetingId + "/" + bill.billFile;
webContent.loadUrl(filename);
WebSettings mWebSettings = webContent.getSettings();
webContent.setInitialScale(originSize);
mWebSettings.setJavaScriptEnabled(true);
mWebSettings.setBuiltInZoomControls(true); //
mWebSettings.setDisplayZoomControls(false);
mWebSettings.setSupportZoom(true);
panelVote = (RelativeLayout) view.findViewById(R.id.content_detail_pannal_vote);
panelModify = (RelativeLayout) view.findViewById(R.id.content_detail_pannal_modify);
tvTips = (TextView) view.findViewById(R.id.content_detail_tv_tips);
ivReuslt = (TextView) view.findViewById(R.id.content_detail_tv_result);
ivReuslt.setVisibility(View.INVISIBLE);
panelModify.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
ivReuslt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
/*
btnA = (Button) view.findViewById(R.id.content_detail_btnA);
btnA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (voteInfo.mode2_modify == 1) {
doVoteWithIndex(1);
} else {
showConfirmWithValue(1);
}
}
});
btnB = (Button) view.findViewById(R.id.content_detail_btnB);
btnB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (voteInfo.mode2_modify == 1) {
doVoteWithIndex(2);
} else {
showConfirmWithValue(2);
}
}
});
btnC = (Button) view.findViewById(R.id.content_detail_btnC);
btnC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (options.length == 2) {
if (voteInfo.mode2_modify == 1) {
doVoteWithIndex(2);
} else {
showConfirmWithValue(2);
}
} else {
if (voteInfo.mode2_modify == 1) {
doVoteWithIndex(3);
} else {
showConfirmWithValue(3);
}
}
}
});
*/
ImageButton btnBack = (ImageButton) view.findViewById(R.id.content_detail_btnback);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
goBack();
}
});
if (!showBackBtn) {
btnBack.setVisibility(View.INVISIBLE);
}
Button btnModify = (Button) view.findViewById(R.id.content_detail_btn_modify);
btnModify.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
panelModify.setVisibility(View.GONE);
showVote();
ivReuslt.setVisibility(View.VISIBLE);
}
});
ImageButton btnBigger = (ImageButton) view.findViewById(R.id.content_detail_bigger);
btnBigger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scale++;
if (scale > 10) {
scale = 10;
}
int newsize = originSize + scale * 20;
// Log.d(TAG, "old size = " + originSize + " new size = " +
// newsize);
// tvContent.setTextSize(newsize);
webContent.setInitialScale(newsize);
}
});
ImageButton btnSmaller = (ImageButton) view.findViewById(R.id.content_detail_smaller);
btnSmaller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scale--;
if (scale < 0) {
scale = 0;
}
int newsize = (originSize + scale * 20);
// Log.d(TAG, "old size = " + originSize + " new size = " +
// newsize);
webContent.setInitialScale(newsize);
}
});
tvConfirmText = (TextView) view.findViewById(R.id.content_detail_confirm_textview);
confirmLayout = (RelativeLayout) view.findViewById(R.id.content_detail_confirm_panel);
Button btnConfirmOK = (Button) view.findViewById(R.id.content_detail_btn_confirm_ok);
btnConfirmOK.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
hideConfirm();
doVoteWithIndex(voteValue);
}
});
Button btnConfirmCancel = (Button) view.findViewById(R.id.content_detail_btn_confirm_cancel);
btnConfirmCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
hideConfirm();
}
});
if (voteInfo != null) {
if (options.length == 2) {
btnA.setText(options[0]);
btnB.setVisibility(View.INVISIBLE);
btnC.setText(options[1]);
} else if (options.length == 3) {
btnA.setText(options[0]);
btnB.setText(options[1]);
btnC.setText(options[2]);
}
showVote();
showResult();
checkIsVoted();
} else {
hideVote();
}
return view;
}
String dataStr = "非常满意/满意/不了解/不满意/非常不满意/满意/非常不满意";
String [] dataArray=dataStr.split("/");
private void setButton(String data){
Button btn [] = new Button[dataArray.length];
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
int j = -1;
int f = btn.length;
for (int i=0;i<dataArray.length;i++){
btn[i]=new Button(getActivity());
btn[i].setText(dataArray[i].toString());
btn[i].setTag(dataArray[i].toString());
btn[i].setId(i);
btn[i].setGravity(Gravity.CENTER);
btn[i].setOnClickListener(btnClick);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((width-50)/btnNum, 90);
//设置按钮的宽度和高度
if (i%btnNum == 0) {
j++;
}
f--;
if(f<btnNum){
//最后一行不是3个,是2个,或者是1个,就无法整除,就会报错。加了这一个判断之后就会消除错误
if (i%btnNum == 4 && i%btnNum== 3
&&i%btnNum == 2 && i%btnNum == 1) {
j++;
}
}
params.leftMargin = ((width-50)/btnNum+10)*(i%btnNum); //横坐标定位
params.topMargin = 20 + 2 * 55 * j; //纵坐标定位
panelVote.addView(btn[i],params);
}
}
OnClickListener btnClick=new OnClickListener() {
@Override
public void onClick(View v) {
}
};
private void showConfirmWithValue(int value) {
voteValue = value;
tvConfirmText.setText(
getString(R.string.you_selected) + options[value - 1] + getString(R.string.you_selected_confirm));
confirmLayout.setVisibility(View.VISIBLE);
btnA.setVisibility(View.INVISIBLE);
btnB.setVisibility(View.INVISIBLE);
btnC.setVisibility(View.INVISIBLE);
}
private void hideConfirm() {
confirmLayout.setVisibility(View.GONE);
btnA.setVisibility(View.VISIBLE);
if (options.length == 3) {
btnB.setVisibility(View.VISIBLE);
}
btnC.setVisibility(View.VISIBLE);
}
private void doVoteWithIndex(int index) {
tvTips.setText(getString(R.string.submiting));
bill.voteResult = index;
voteValue = index;
mMainActivity.presenter.submitVote(XPadApi.AnsType_Single, String.valueOf(index));
// mMainActivity.presenter.submitVote(XPadApi.AnsType_BatchSingle,
// bill.billNo + ":" + index);
showResult();
}
// private int result;
private void showResult() {
if (bill.voteResult > 0) {
if (voteInfo.mode3_secret == 0) {
ivReuslt.setText(options[bill.voteResult - 1]);
ivReuslt.setBackgroundResource(R.drawable.voted_empty);
} else {
ivReuslt.setText("");
ivReuslt.setBackgroundResource(R.drawable.voted);
}
ivReuslt.setVisibility(View.VISIBLE);
} else {
ivReuslt.setVisibility(View.INVISIBLE);
}
}
private void goBack() {
if (contentBackListener != null) {
contentBackListener.onBack();
}
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.remove(MultiContentDetailFragmentback.this);
tx.commit();
}
public void hideVote() {
// isStartVote = false;
panelVote.setVisibility(View.GONE);
panelModify.setVisibility(View.GONE);
// btnA.setVisibility(View.INVISIBLE);
// btnB.setVisibility(View.INVISIBLE);
// btnC.setVisibility(View.INVISIBLE);
// ivReuslt.setVisibility(View.INVISIBLE);
// tvTips.setVisibility(View.INVISIBLE);
}
public void showVote() {
// isStartVote = true;
panelVote.setVisibility(View.VISIBLE);
// btnA.setVisibility(View.VISIBLE);
// btnB.setVisibility(View.VISIBLE);
// btnC.setVisibility(View.VISIBLE);
// ivReuslt.setVisibility(View.VISIBLE);
// tvTips.setVisibility(View.VISIBLE);
}
public void disableVote() {
btnA.setEnabled(false);
btnB.setEnabled(false);
btnC.setEnabled(false);
}
private void showModify() {
panelModify.setVisibility(View.VISIBLE);
}
/*
@Override
public void onVoteEvent(VoteInfo info) {
super.onVoteEvent(info);
if (info.mode == XPadApi.VoteType_Stop) {
hideVote();
saveVoteInfo();
} else {
voteInfo = (VoteInfo) info;
if (voteInfo.mode2_modify == 1) {
tvTips.setText(getString(R.string.please_vote_can_modify));
} else {
tvTips.setText(getString(R.string.please_vote_can_not_modify));
}
showVote();
checkIsVoted();
}
}
*/
private void showModifyOrDisable(){
if (voteInfo.mode2_modify == 1) {
showModify();
} else {
disableVote();
}
}
public void onVoteSubmitSuccess() {
tvTips.setText(getString(R.string.submited));
showModifyOrDisable();
saveVoteInfo();
}
@Override
public void onVoteSubmitError() {
super.onVoteSubmitError();
showVote();
}
private void saveVoteInfo(){
SharedPreferencesUtil.saveData(getActivity(),DATAPOS,Integer.valueOf(voteInfo.dataPos));
SharedPreferencesUtil.saveData(getActivity(),VOTEMODE,Integer.valueOf(voteInfo.mode));
SharedPreferencesUtil.saveData(getActivity(),VOTEVALUE,Integer.valueOf(voteValue));
}
private void checkIsVoted(){
Log.i(TAG, "checkIsVoted: ");
Integer datapos = (Integer) SharedPreferencesUtil.getData(getActivity(),DATAPOS,Integer.valueOf(-1));
Integer votemode = (Integer) SharedPreferencesUtil.getData(getActivity(),VOTEMODE,Integer.valueOf(-1));
Integer val = (Integer) SharedPreferencesUtil.getData(getActivity(),VOTEVALUE,Integer.valueOf(-1));
Log.i(TAG, "checkIsVoted: datapos:"+ datapos.intValue() +" voteMode:"+ votemode.intValue()+ " val:"+val.intValue());
if(datapos.intValue() == voteInfo.dataPos && votemode.intValue() == voteInfo.mode && val.intValue()!=-1){
voteValue = val.intValue();
if (bill != null) {
bill.voteResult = voteValue;
}
showResult();
showModifyOrDisable();
tvTips.setText(getString(R.string.submited));
}
}
}