ContentVoteFragment.java
8.83 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
package com.sunvote.xpadapp.fragments;
import com.sunvote.util.LogUtil;
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.xpadcomm.XPadApi;
import com.sunvote.xpadcomm.XPadApiInterface.EvaluateInfo;
import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebView.FindListener;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class ContentVoteFragment extends BaseFragment {
private String TAG = "ContentVoteFragment";
private TextView tvTitle;
private WebView tvContent;
private TextView tvModify;
private TextView tvTips;
private TextView ivReuslt;
private Button btnA;
private Button btnB;
private Button btnC;
private Button btnModify;
private RelativeLayout tipLayout;
private RelativeLayout voteLayout;
private RelativeLayout modifyLayout;
private int scale = 0;
private int originSize = 200;
private BillInfo bill;
private VoteInfo voteInfo;
private EvaluateInfo evaluateInfo;
private int modifyable;
private int secret;
private String[] options;
private String DATABASE_PATH = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
public ContentVoteFragment() {
super();
}
public void setInfo(BillInfo info){
bill = info;
options = bill.billOptions.split("/");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LogUtil.d("ContentVoteFragment", "onCreateView");
View view = inflater.inflate(R.layout.fragment_contentvote, container, false);
tvModify = view.findViewById(R.id.contentvote_tvmodify);
tvTitle = view.findViewById(R.id.contentvote_title);
tvTitle.setText(mMainActivity.meetingInfo.meetingTitle);
tvContent = view.findViewById(R.id.contentvote_content);
String filename = "file:///" + DATABASE_PATH + "/sunvote/" + mMainActivity.meetingInfo.meetingID + "/"
+ bill.billFile;
tvContent.loadUrl(filename);
WebSettings mWebSettings = tvContent.getSettings();
tvContent.setInitialScale(originSize);
mWebSettings.setSupportZoom(true);
tvTips = (TextView) view.findViewById(R.id.contentvote_tv_tips);
ivReuslt = (TextView) view.findViewById(R.id.contentvote_tv_result);
ivReuslt.setVisibility(View.INVISIBLE);
tipLayout = (RelativeLayout) view.findViewById(R.id.contentvote_pannal_tips);
voteLayout = (RelativeLayout) view.findViewById(R.id.contentvote_pannal_vote);
modifyLayout = (RelativeLayout) view.findViewById(R.id.contentvote_pannal_modify);
// tvContent.setTextSize(originSize);
ImageButton btnBigger = (ImageButton) view.findViewById(R.id.contentvote_bigger);
btnBigger.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scale++;
if (scale > 10) {
scale = 10;
}
int newsize = originSize + scale * 20;
LogUtil.d(TAG, "old size = " + originSize + " new size = " + newsize);
// tvContent.setTextSize(newsize);
tvContent.setInitialScale(newsize);
}
});
ImageButton btnSmaller = (ImageButton) view.findViewById(R.id.contentvote_smaller);
btnSmaller.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scale--;
if (scale < -3) {
scale = -3;
}
int newsize = (originSize + scale * 20);
LogUtil.d(TAG, "old size = " + originSize + " new size = " + newsize);
tvContent.setInitialScale(newsize);
}
});
btnA = (Button) view.findViewById(R.id.contentvote_btnA);
btnA.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doVoteWithIndex(1);
}
});
btnB = (Button) view.findViewById(R.id.contentvote_btnB);
btnB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doVoteWithIndex(2);
}
});
btnC = (Button) view.findViewById(R.id.contentvote_btnC);
btnC.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (options.length == 2) {
doVoteWithIndex(2);
} else {
doVoteWithIndex(3);
}
}
});
btnModify = (Button) view.findViewById(R.id.contentvote_btn_modify);
btnModify.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showVote();
}
});
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]);
}
hideVote();
return view;
}
private void doVoteWithIndex(int index) {
// tvModify.setText(getString(R.string.submiting));
mMainActivity.presenter.submitVote(XPadApi.AnsType_Single, String.valueOf(index));
if (secret == 0) {
if (bill.billType == BillInfo.BillType_Vote) {
ivReuslt.setText("");
ivReuslt.setBackgroundResource(getResultResourceByTitle(options[index - 1]));
} else if (bill.billType == BillInfo.BillType_Evaluate) {
ivReuslt.setText(options[index - 1]);
ivReuslt.setBackgroundResource(R.drawable.voted_empty);
}
} else {
ivReuslt.setText("");
ivReuslt.setBackgroundResource(R.drawable.voted);
}
ivReuslt.setVisibility(View.VISIBLE);
if (modifyable == 1) {
showModify();
} else {
disableVote();
}
}
private void hideVote() {
voteLayout.setVisibility(View.INVISIBLE);
ivReuslt.setVisibility(View.INVISIBLE);
// tvTips.setVisibility(View.INVISIBLE);
}
private void showVote() {
voteLayout.setVisibility(View.VISIBLE);
//tipLayout.setVisibility(View.VISIBLE);
modifyLayout.setVisibility(View.INVISIBLE);
ivReuslt.setVisibility(View.INVISIBLE);
tvTips.setVisibility(View.VISIBLE);
}
private void disableVote() {
// btnA.setVisibility(View.INVISIBLE);
// btnB.setVisibility(View.INVISIBLE);
// btnC.setVisibility(View.INVISIBLE);
voteLayout.setVisibility(View.INVISIBLE);
//tipLayout.setVisibility(View.INVISIBLE);
modifyLayout.setVisibility(View.INVISIBLE);
}
private void showTips() {
voteLayout.setVisibility(View.INVISIBLE);
//tipLayout.setVisibility(View.VISIBLE);
modifyLayout.setVisibility(View.INVISIBLE);
}
private void showModify() {
voteLayout.setVisibility(View.INVISIBLE);
tipLayout.setVisibility(View.INVISIBLE);
modifyLayout.setVisibility(View.VISIBLE);
}
@Override
public void onVoteEvent(int baseId, int iMode, Object info) {
/* if (iMode == XPadApi.VoteType_Vote) {
voteInfo = (VoteInfo) info;
modifyable = voteInfo.modifyMode;
secret = voteInfo.secretMode;
if (modifyable == 1) {
tvModify.setText(getString(R.string.please_vote_can_modify));
} else {
tvModify.setText(getString(R.string.please_vote_can_not_modify));
}
showVote();
} else if (iMode == XPadApi.VoteType_Evaluate) {
evaluateInfo = (EvaluateInfo) info;
modifyable = evaluateInfo.modify;
secret = evaluateInfo.secrecy;
showVote();
} else if (iMode == XPadApi.VoteType_Stop) {
disableVote();
}*/
}
@Override
public void onVoteSubmitSuccess() {
tvModify.setText(getString(R.string.submited));
super.onVoteSubmitSuccess();
}
}