MultiContentDetailFragment.java
19.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
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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
package com.sunvote.xpadapp.fragments;
import android.annotation.TargetApi;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.ContextCompat;
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.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnRenderListener;
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.VoteResult;
import com.sunvote.xpadapp.utils.SharedPreferencesUtil;
import com.sunvote.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
import com.ycanfunc.util.StringUtils;
import java.io.File;
public class MultiContentDetailFragment 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 PDFViewPager pdfView;
private PDFView pdfView;
private Button btnLookPdf;
// private RelativeLayout panelVote;
private RelativeLayout panelVotes;
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;
private MainActivity mact;
private RelativeLayout contentDetailLayout;
public String[] voteOptions = new String[13];
//btn一行个数
private int btnNum = 6;
//关闭当前Fragment
public boolean isClose = true;
//pdf 页码
public int pdfPageNum = 0;
private String filename;
public ContentVoteOnBack contentBackListener;
private String DATABASE_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
//自定义评测
private final int customVote=101;
//pdf延迟加载
private int pdfDelayLoadTime=500;
private int uType;
public interface ContentVoteOnBack {
void onBack(VoteResult result);
}
public void setInfo(BillInfo billInfo, VoteInfo vote, boolean isShowBack,int pageNum,int mUIType) {
bill = billInfo;
voteInfo = vote;
showBackBtn = isShowBack;
pdfPageNum = pageNum;
uType=mUIType;
}
public void setPdfPage(int page){
if(pdfView!=null){
pdfView.jumpTo(page-1);
//pdfView.setCurrentItem(page-1);
}
}
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) {
if(voteInfo.mode4==customVote){ //自定义评测
if(bill!=null && !StringUtils.isEmpty(bill.billOptions)){
options = bill.billOptions.split("/");
}
}else {
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 void onResume() {
super.onResume();
isClose= true;
openPdfFile();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView");
View view = inflater.inflate(R.layout.fragment_multi_content_detail, container, false);
contentDetailLayout =view.findViewById(R.id.content_detail_pannal_vote1);
initOptions();
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;//
}
});
mact = (MainActivity) getActivity();
tvTitle = (TextView) view.findViewById(R.id.content_detail_title);
if(bill!=null){
if (bill.title != null) {
tvTitle.setText(bill.title);
}
}
final View pdfViews = view.findViewById(R.id.content_detail_scview);
pdfViews.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
;
}
});
pdfView = view.findViewById(R.id.content_detail_pdfview);
filename = DATABASE_PATH + "/sunvote/" + mact.meetingId + "/" + bill.billFile;
panelVotes = (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);
new Handler().postDelayed(new Runnable(){
public void run() {
//execute the task
openPdfFile();
}
}, pdfDelayLoadTime);
panelVotes.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
panelModify.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
ivReuslt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
;
}
});
btnLookPdf= (Button) view.findViewById(R.id.btn_look_pdf);
btnLookPdf.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
isClose= false;
mact.isLoadPDF = false;
pdfPageNum=pdfView.getCurrentPage()+1;
//pdfPageNum=pdfView.getCurrentItem()+1;
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
PDFContextShowFragment pdfShow = new PDFContextShowFragment();
mact.pdfFragment = pdfShow;
pdfShow.setInfo(filename, bill.billFile,pdfPageNum + "","0",false);
tx.add(R.id.frame_content, pdfShow, "pdfShow");
if(uType==1){
tx.addToBackStack(null);
}else {
mact.multiContentFragment = null;
fm.popBackStack();
}
tx.commitAllowingStateLoss();
}
});
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);
}else{
btnBack.setVisibility(View.VISIBLE);
}
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);
}
});
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(voteInfo.mode4==customVote){
contentDetailLayout.setVisibility(View.VISIBLE);
panelVotes.setVisibility(View.GONE);
if(options!=null){
setButton(options);
}
}else{
contentDetailLayout.setVisibility(View.INVISIBLE);
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]);
}
setBtnModle(1,false);
showVote();
}
showResult();
checkIsVoted();
panelVotes.setVisibility(View.VISIBLE);
} else {
panelVotes.setVisibility(View.GONE);
hideVote();
}
return view;
}
private void openPdfFile(){
if(filename != null) {
File file = new File(filename);
if (file.exists()) {
pdfView.fromFile(file)
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
//.onPageChange(onPageChangeListener)
.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int nbPages, float pageWidth, float pageHeight) {
pdfView.fitToWidth(pdfPageNum - 1);
}
})
.enableAnnotationRendering(false)
.password(null)
.scrollHandle(null)
.enableAntialiasing(true)
.spacing(0)
.load();
} else {
Toast.makeText(getActivity(), "议案文件未找到", Toast.LENGTH_LONG).show();
}
}
}
/**
* 自定评测按钮 wutaian 2017.08.23
* @param data
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setButton(String [] data){
Button btn [] = new Button[data.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<data.length;i++){
btn[i]=new Button(getActivity());
btn[i].setText(data[i].toString());
btn[i].setTag(data[i].toString());
btn[i].setId(i);
btn[i].setGravity(Gravity.CENTER);
btn[i].setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.agree_selector));
btn[i].setTextAppearance(getActivity(),R.style.ContentDetailButtonStyle);
if(data[i].toString().getBytes().length > 9){
btn[i].setTextSize(18);
}
btn[i].setOnClickListener(btnClick);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((width-80)/btnNum, 105);
//设置按钮的宽度和高度
if (i%btnNum == 0) {
j++;
}
f--;
if(f<btnNum){
//最后一行不是3个,是2个,或者是1个,就无法整除,就会报错。加了这一个判断之后就会消除错误
if (i%btnNum == 5 && i%btnNum == 4 && i%btnNum== 3
&&i%btnNum == 2 && i%btnNum == 1) {
j++;
}
}
params.leftMargin = ((width-50)/btnNum + 10)*(i%btnNum); //横坐标定位
params.topMargin = 10 + 2 * 55 * j; //纵坐标定位
contentDetailLayout.addView(btn[i],params);
}
}
/**
* 评测按钮点击事件 wutaian 2017.08.23
*/
View.OnClickListener btnClick=new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i = 0;i<options.length;i++){
if(options[i].equals(v.getTag())){
if (voteInfo.mode2_modify == 1) {
doVoteWithIndex(i+1);
} else {
showConfirmWithValue(i+1);
}
break;
}
}
}
};
/**
* 设置按钮模式 wutaian 2017.08.23
* @param model
* 1:隐藏显示模式 2:编辑与不可编辑
* @param isBoolean
* true:显示,可编辑 false:隐藏,不可编辑
*/
private void setBtnModle(int model,boolean isBoolean){
for (int i = 0, j = contentDetailLayout.getChildCount(); i < j; i++) {
View child = contentDetailLayout.getChildAt(i);
if (child instanceof Button) {
Button btn= (Button) child;
if(model==1){
if(isBoolean){
btn.setVisibility(View.VISIBLE);
}else{
btn.setVisibility(View.INVISIBLE);
}
}else if(model==2){
btn.setEnabled(isBoolean);
}
}
}
}
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);
btnLookPdf.setVisibility(View.GONE);
if(voteInfo.mode4==customVote){
setBtnModle(2,true);
}else{
btnA.setVisibility(View.INVISIBLE);
btnB.setVisibility(View.INVISIBLE);
btnC.setVisibility(View.INVISIBLE);
}
}
private void hideConfirm() {
confirmLayout.setVisibility(View.GONE);
btnLookPdf.setVisibility(View.VISIBLE);
if(voteInfo.mode4==customVote){
setBtnModle(2,true);
}else{
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();
disableVote();
}
// private int result;
private void showResult() {
if (bill.voteResult > 0) {
ivReuslt.setVisibility(View.INVISIBLE);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
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);
}
},200);
} else {
ivReuslt.setVisibility(View.INVISIBLE);
}
}
private void goBack() {
isClose= true;
if (contentBackListener != null) {
VoteResult result=new VoteResult();
result.selectResult=voteValue;
contentBackListener.onBack(result);
}
/*BasePDFPagerAdapter adapter = (BasePDFPagerAdapter) pdfView.getAdapter();
if (adapter != null) {
adapter.close();
adapter = null;
}*/
FragmentManager fm = getFragmentManager();
FragmentTransaction tx = fm.beginTransaction();
tx.remove(MultiContentDetailFragment.this);
tx.commit();
}
public void hideVote() {
// isStartVote = false;
panelVotes.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;
if(voteInfo.mode4==customVote){
contentDetailLayout.setVisibility(View.VISIBLE);
setBtnModle(2,true);
setBtnModle(1,true);
}else{
contentDetailLayout.setVisibility(View.INVISIBLE);
panelVotes.setVisibility(View.VISIBLE);
enableVote();
}
// btnA.setVisibility(View.VISIBLE);
// btnB.setVisibility(View.VISIBLE);
// btnC.setVisibility(View.VISIBLE);
// ivReuslt.setVisibility(View.VISIBLE);
// tvTips.setVisibility(View.VISIBLE);
}
public void disableVote() {
if(voteInfo.mode4==customVote){
contentDetailLayout.setVisibility(View.VISIBLE);
setBtnModle(2,false);
}else{
contentDetailLayout.setVisibility(View.INVISIBLE);
btnA.setEnabled(false);
btnB.setEnabled(false);
btnC.setEnabled(false);
}
}
public void enableVote() {
if(voteInfo.mode4==customVote){
contentDetailLayout.setVisibility(View.VISIBLE);
setBtnModle(2,true);
}else{
btnA.setEnabled(true);
btnB.setEnabled(true);
btnC.setEnabled(true);
}
}
private void showModify() {
if(voteInfo.mode4==customVote){
contentDetailLayout.setVisibility(View.INVISIBLE);
}
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();
//btnLookPdf.setEnabled(true);
} else {
disableVote();
//btnLookPdf.setEnabled(false);
}
}
@Override
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));
}
}
}