TableActivity.java
12.7 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
package com.huaheng.tab.util;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.InputFilter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.huaheng.common.InputFilterMinMax;
import com.huaheng.common.WMSUtils;
import com.huaheng.common.adapter.AbsCommonAdapter;
import com.huaheng.common.adapter.AbsViewHolder;
import com.huaheng.common.adapter.RefreshParams;
import com.huaheng.common.model.BaseBean;
import com.huaheng.common.model.TableModel;
import com.huaheng.common.widget.MyListView;
import com.huaheng.common.widget.SyncHorizontalScrollView;
import com.huaheng.common.widget.pullrefresh.AbPullToRefreshView;
import com.huaheng.tab.R;
import com.huaheng.tab.WMSApplication;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;
public class TableActivity extends Activity {
@BindView(R.id.backImage)
public ImageView backImage;
@BindView(R.id.commonTitle)
TextView commonTitle;
@BindView(R.id.buttonLayout)
LinearLayout buttonLayout;
@BindView(R.id.right_title_container)
public LinearLayout rightTitleContainer;
@BindView(R.id.title_horsv)
SyncHorizontalScrollView titleHorsv;
@BindView(R.id.right_container_listview)
public MyListView rightContainerListview;
@BindView(R.id.content_horsv)
SyncHorizontalScrollView contentHorsv;
@BindView(R.id.pull_refresh_scroll)
ScrollView pullRefreshScroll;
@BindView(R.id.pulltorefreshview)
public AbPullToRefreshView pulltorefreshview;
@BindView(R.id.allPage)
TextView allPage;
@BindView(R.id.alterPage)
TextView alterPage;
@BindView(R.id.fromPage)
TextView fromPage;
@BindView(R.id.firstPage)
TextView firstPage;
@BindView(R.id.upPage)
TextView upPage;
@BindView(R.id.downPage)
TextView downPage;
@BindView(R.id.lastPage)
TextView lastPage;
@BindView(R.id.jumpPage)
TextView jumpPage;
@BindView(R.id.basePageContainer)
FrameLayout basePageContainer;
private ViewGroup viewGroup;
public Context mContext;
public int pageNo = 1;
public int pageSize = 10;
public int mAlertPage = 1;
public int upPageNo = pageNo;
public AbsCommonAdapter<TableModel> mRightAdapter;
public List<BaseBean> tableBeans;
public List<BaseBean> selectTableBeans = new ArrayList<>();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_table);
mContext = this;
viewGroup = (ViewGroup) this.findViewById(R.id.buttonLayout);
initActivityOnCreate(savedInstanceState);
initView();
}
/**
* 页面初始化
*/
protected void initActivityOnCreate(Bundle savedInstanceState) {
}
private void initView() {
// 设置两个水平控件的联动
titleHorsv.setScrollView(contentHorsv);
contentHorsv.setScrollView(titleHorsv);
pulltorefreshview.setPullRefreshEnable(false);
pulltorefreshview.setLoadMoreEnable(false);
rightContainerListview.setAdapter(mRightAdapter);
rightContainerListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
setSelectBean(tableBeans.get(position));
mRightAdapter.notifyDataSetChanged();
}
});
}
public void setBackImageVisible(int visible) {
if (backImage != null) {
backImage.setVisibility(visible);
}
}
public void setTitle(String message) {
if (commonTitle != null) {
commonTitle.setText(message);
}
}
@OnClick({R.id.backImage, R.id.firstPage, R.id.upPage, R.id.downPage, R.id.lastPage, R.id.jumpPage})
public void onClick(View view) {
switch (view.getId()) {
case R.id.backImage:
onBackPressed();
break;
case R.id.firstPage:
getTalbeByCondition(1);
break;
case R.id.upPage:
getTalbeByCondition(pageNo - 1);
break;
case R.id.downPage:
getTalbeByCondition(pageNo + 1);
break;
case R.id.lastPage:
getTalbeByCondition(mAlertPage);
break;
case R.id.jumpPage:
showJumpDialog();
break;
}
}
public void setButtonView(int layoutResID) {
LayoutInflater.from(this).inflate(layoutResID, viewGroup, true);
}
private void showJumpDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_choose, null);
TextView cancel = view.findViewById(R.id.choosepage_cancel);
TextView sure = view.findViewById(R.id.choosepage_sure);
final EditText edittext = view.findViewById(R.id.choosepage_edittext);
edittext.setFilters(new InputFilter[]{new InputFilterMinMax(1, mAlertPage)});
final Dialog dialog = builder.create();
dialog.show();
dialog.getWindow().setContentView(view);
//使editext可以唤起软键盘
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
sure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getTalbeByCondition(Integer.parseInt(edittext.getText().toString()));
dialog.dismiss();
}
});
}
protected void getTalbeByCondition(int page) {
}
public void freshMenuText(int size) {
int alter = size / pageSize + 1;
if (size % pageSize == 0) {
alter = alter - 1;
}
if (size == 0) {
alter = 0;
}
mAlertPage = alter;
allPage.setText(String.format(getResources().getString(R.string.all_page), size));
alterPage.setText(String.format(getResources().getString(R.string.alter_page), 10));
fromPage.setText(String.format(getResources().getString(R.string.from_page), pageNo, mAlertPage));
firstPage.setText(String.format(getResources().getString(R.string.first_page)));
upPage.setText(String.format(getResources().getString(R.string.up_page)));
downPage.setText(String.format(getResources().getString(R.string.down_page)));
lastPage.setText(String.format(getResources().getString(R.string.last_page)));
jumpPage.setText(String.format(getResources().getString(R.string.jump_page)));
if (mAlertPage > 1) {
firstPage.setTextColor(getResources().getColor(R.color.black));
lastPage.setTextColor(getResources().getColor(R.color.black));
jumpPage.setTextColor(getResources().getColor(R.color.black));
firstPage.setClickable(true);
lastPage.setClickable(true);
jumpPage.setClickable(true);
} else {
firstPage.setTextColor(getResources().getColor(R.color.gray_bg));
lastPage.setTextColor(getResources().getColor(R.color.gray_bg));
jumpPage.setTextColor(getResources().getColor(R.color.gray_bg));
firstPage.setClickable(false);
lastPage.setClickable(false);
jumpPage.setClickable(false);
}
if (pageNo == 1) {
upPage.setTextColor(getResources().getColor(R.color.gray_bg));
upPage.setEnabled(false);
} else {
upPage.setTextColor(getResources().getColor(R.color.black));
upPage.setEnabled(true);
}
if (pageNo == mAlertPage || mAlertPage == 0) {
downPage.setTextColor(getResources().getColor(R.color.gray_bg));
downPage.setEnabled(false);
} else {
downPage.setTextColor(getResources().getColor(R.color.black));
downPage.setEnabled(true);
}
}
public void clearSelectBean() {
selectTableBeans.removeAll(selectTableBeans);
selectTableBeans = new ArrayList<>();
mRightAdapter.clearData(true);
}
public boolean setSelectBean(BaseBean baseBean) {
boolean contained = false;
int index = 0;
for (BaseBean baseBean1 : selectTableBeans) {
index++;
if (baseBean1.getId() == baseBean.getId()) {
contained = true;
break;
}
}
if (contained) {
selectTableBeans.remove(index - 1);
return false;
}
selectTableBeans.add(baseBean);
select(baseBean);
return true;
}
public void select(BaseBean baseBean) {
}
public boolean isSelectBean(BaseBean baseBean) {
boolean contained = false;
for (BaseBean baseBean1 : selectTableBeans) {
if (baseBean1.getId() == baseBean.getId()) {
contained = true;
break;
}
}
if (contained) {
return true;
}
return false;
}
public boolean enableSelctBean() {
if (selectTableBeans == null) {
WMSUtils.showShort(mContext, mContext.getString(R.string.please_select_one_order));
return false;
}
if (selectTableBeans.size() != 1) {
WMSUtils.showShort(mContext, mContext.getString(R.string.please_select_one_order));
return false;
}
return true;
}
public void setSelectBackground(AbsViewHolder helper, int pos) {
View view = helper.getConvertView();
BaseBean baseBean = tableBeans.get(pos);
if (isSelectBean(baseBean)) {
view.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
} else {
view.setBackgroundColor(getResources().getColor(R.color.white));
}
}
public void setData(List<BaseBean> baseBeans) {
doGetDatas(0, RefreshParams.REFRESH_DATA, baseBeans);
}
public void doGetDatas(int pageno, int state, List<BaseBean> baseBeans) {
// if (state == RefreshParams.REFRESH_DATA) {
pulltorefreshview.onHeaderRefreshFinish();
// } else {
// pulltorefreshview.onFooterLoadFinish();
// }
setDatas(baseBeans, state);
}
public void setDatas(List<BaseBean> baseBeans, int type) {
}
public TextView addTitleText(String title, int width) {
TextView titleView = new TextView(mContext);
titleView.setText(title);
titleView.setWidth((int)(width * 1.4));
titleView.setHeight(40);
titleView.setTextSize(12);
titleView.setTextColor(Color.BLACK);
titleView.setPadding(4,0,4,0);
titleView.setMaxLines(2);
titleView.setGravity(Gravity.CENTER);
rightTitleContainer.addView(titleView);
return titleView;
}
public void addMessageText(LinearLayout linearLayout, int width, String message) {
TextView titleView = new TextView(mContext);
titleView.setText(message);
titleView.setWidth((int)(width * 1.4));
titleView.setHeight((int)(42* 1.35));
titleView.setTextSize(12);
titleView.setTextColor(Color.BLACK);
titleView.setPadding(4,0,4,0);
titleView.setMaxLines(2);
titleView.setGravity(Gravity.CENTER);
linearLayout.addView(titleView);
}
public void addMessageColorText(LinearLayout linearLayout, int width, String message, int color) {
TextView titleView = new TextView(mContext);
titleView.setText(message);
titleView.setWidth((int)(width * 1.4));
titleView.setHeight((int)(42* 1.35));
titleView.setTextSize(12);
titleView.setTextColor(Color.BLACK);
titleView.setPadding(4,0,4,0);
titleView.setMaxLines(2);
titleView.setBackgroundColor(WMSApplication.getContext().getResources().getColor(R.color.green));
titleView.setGravity(Gravity.CENTER);
linearLayout.addView(titleView);
}
}