|
|
@@ -0,0 +1,293 @@
|
|
|
+package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.BaseAdapter;
|
|
|
+import android.widget.CheckBox;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.bean.oa.SelectBean;
|
|
|
+import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.JsonValidator;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.view.EmptyLayout;
|
|
|
+import com.xzjmyk.pm.activity.view.ClearEditText;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 为了不影响通用类SelectActivity ,这里另行拷贝一份单独用
|
|
|
+ */
|
|
|
+public class SelectAlarmTimeActivity extends BaseActivity{
|
|
|
+ private ListView list;//列表控件
|
|
|
+ private ListAdapter adapter;
|
|
|
+ private EmptyLayout emptyLayout;
|
|
|
+
|
|
|
+ private int type = -1;//1 网络 2.本地
|
|
|
+ private String title = "";//标题
|
|
|
+ private boolean isSingle = true;//是否单选
|
|
|
+ //location
|
|
|
+ private List<SelectBean> formBeaan;//数据来源
|
|
|
+ //net
|
|
|
+ private String action;//网址
|
|
|
+ private HashMap<String, Object> param;//参数
|
|
|
+ private String key;//从网络请求的json对象中获取显示列表的key
|
|
|
+ private String showKey;//从列表对象中获取选择索引(name)的key
|
|
|
+
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ if (progressDialog != null && progressDialog.isShowing())
|
|
|
+ progressDialog.dismiss();
|
|
|
+ if (msg.what == 0x11) {
|
|
|
+ String message = msg.getData().getString("result");
|
|
|
+ if (StringUtils.isEmpty(message)) return;
|
|
|
+ JsonValidator validator = new JsonValidator();
|
|
|
+ if (!validator.validate(message)) return;
|
|
|
+ JSONObject object = JSON.parseObject(message);
|
|
|
+ if (object == null) return;
|
|
|
+ if (!StringUtils.isEmpty(key)) {
|
|
|
+ if (StringUtils.isEmpty(showKey)) return;
|
|
|
+ if (object.containsKey(key)) {
|
|
|
+ JSONArray array = object.getJSONArray(key);
|
|
|
+ if (array == null || array.size() <= 0) {
|
|
|
+ emptyLayout.showEmpty();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (formBeaan == null) formBeaan = new ArrayList<>();
|
|
|
+ else formBeaan.clear();
|
|
|
+ SelectBean bean = null;
|
|
|
+ JSONObject chce = null;
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ chce = array.getJSONObject(i);
|
|
|
+ if (chce == null) continue;
|
|
|
+ bean = new SelectBean();
|
|
|
+ if (chce.containsKey(showKey)) {
|
|
|
+ bean.setName(chce.getString(showKey));
|
|
|
+ bean.setObject(chce.toString());
|
|
|
+ bean.setJson(chce.toString());
|
|
|
+ formBeaan.add(bean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!ListUtils.isEmpty(formBeaan)) {
|
|
|
+ //TODO 不为空的情况下提交给适配器
|
|
|
+ if (adapter == null) {
|
|
|
+ adapter = new ListAdapter(formBeaan);
|
|
|
+ list.setAdapter(adapter);
|
|
|
+ } else {
|
|
|
+ adapter.setFormBeaan(formBeaan);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {//当返回的没有不需要key值时候
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ emptyLayout.showEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private ClearEditText search_edit;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (android.R.id.home==item.getItemId()){
|
|
|
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
+ imm.hideSoftInputFromWindow(search_edit.getWindowToken(), 0);
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ initIntent();
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.alarm_changetime_select);
|
|
|
+ initView();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ if (!StringUtils.isEmpty(title)) getSupportActionBar().setTitle(title);
|
|
|
+ list = (ListView) findViewById(R.id.listview);
|
|
|
+ search_edit = (ClearEditText) findViewById(R.id.search_edit);
|
|
|
+ search_edit.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ if (ListUtils.isEmpty(formBeaan)) return;
|
|
|
+ String str = editable.toString().trim();
|
|
|
+ ArrayList<SelectBean> list = new ArrayList<>();
|
|
|
+ for (SelectBean e : formBeaan) {
|
|
|
+ if (!StringUtils.isEmpty(e.getName()) && StringUtils.isInclude(e.getName(), str)) {
|
|
|
+ list.add(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (adapter != null) {
|
|
|
+ adapter.setFormBeaan(list);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ emptyLayout = new EmptyLayout(ct, list);
|
|
|
+ emptyLayout.setShowLoadingButton(false);
|
|
|
+ emptyLayout.setShowEmptyButton(false);
|
|
|
+ emptyLayout.setShowErrorButton(false);
|
|
|
+ emptyLayout.setEmptyViewRes(R.layout.view_empty);
|
|
|
+ adapter = new ListAdapter();
|
|
|
+ if (!ListUtils.isEmpty(formBeaan))
|
|
|
+ adapter.setFormBeaan(formBeaan);
|
|
|
+ list.setAdapter(adapter);
|
|
|
+ if (type == 1)
|
|
|
+ loadDateByNet();
|
|
|
+ list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
+ List<SelectBean> formBeaan = adapter.getFormBeaan();
|
|
|
+ if (isSingle) {
|
|
|
+ SelectBean bean = formBeaan.get(i);
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("data", bean);
|
|
|
+ setResult(0x20, intent);
|
|
|
+ finish();
|
|
|
+ } else {
|
|
|
+ formBeaan.get(i).setClick(true);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initIntent() {
|
|
|
+ Intent intent = getIntent();
|
|
|
+ if (intent == null) return;
|
|
|
+ type = intent.getIntExtra("type", -1);
|
|
|
+ title = intent.getStringExtra("title");
|
|
|
+ isSingle = intent.getBooleanExtra("isSingle", true);
|
|
|
+ int reid = intent.getIntExtra("reid", -1);
|
|
|
+ if (reid != -1)
|
|
|
+ setTheme(getSharedPreferences("cons", MODE_PRIVATE).getInt("theme", reid));
|
|
|
+ if (type == 1) {
|
|
|
+ action = intent.getStringExtra("action");
|
|
|
+ key = intent.getStringExtra("key");
|
|
|
+ showKey = intent.getStringExtra("showKey");
|
|
|
+ param = intent.getParcelableExtra("showKey");
|
|
|
+ Bundle bundle = getIntent().getExtras();
|
|
|
+ param = (HashMap<String, Object>) bundle.getSerializable("param");
|
|
|
+ } else if (type == 2) {
|
|
|
+ formBeaan = intent.getParcelableArrayListExtra("data");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*从服务器上获取数据*/
|
|
|
+ private void loadDateByNet() {
|
|
|
+ if (progressDialog != null)
|
|
|
+ progressDialog.show();
|
|
|
+ String url = CommonUtil.getSharedPreferences(ct, "erp_baseurl") + action;
|
|
|
+ String sessionId = CommonUtil.getSharedPreferences(ct, "sessionId");
|
|
|
+ if (param != null) {
|
|
|
+ param.put("sessionId", sessionId);
|
|
|
+ } else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
|
|
|
+ headers.put("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(ct, "sessionId"));
|
|
|
+ ViewUtil.httpSendRequest(ct, url, param, handler, headers, 0x11, null, null, "post");
|
|
|
+ }
|
|
|
+
|
|
|
+ class ListAdapter extends BaseAdapter {
|
|
|
+ private List<SelectBean> formBeaan;
|
|
|
+
|
|
|
+ public ListAdapter() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public ListAdapter(List<SelectBean> formBeaan) {
|
|
|
+ this.formBeaan = formBeaan;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFormBeaan(List<SelectBean> formBeaan) {
|
|
|
+ this.formBeaan = formBeaan;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<SelectBean> getFormBeaan() {
|
|
|
+ return formBeaan;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return formBeaan == null ? 0 : formBeaan.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getItem(int i) {
|
|
|
+ return formBeaan.get(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int i) {
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ //临时变量
|
|
|
+ SelectBean chche = null;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
+ ViewHoler holer = null;
|
|
|
+ if (view == null) {
|
|
|
+ view = LayoutInflater.from(ct).inflate(R.layout.select_list_item, null);
|
|
|
+ holer = new ListAdapter.ViewHoler();
|
|
|
+ holer.select_scb = (CheckBox) view.findViewById(R.id.select_scb);
|
|
|
+ holer.name_tv = (TextView) view.findViewById(R.id.name_tv);
|
|
|
+ view.setTag(holer);
|
|
|
+ } else {
|
|
|
+ holer = (ViewHoler) view.getTag();
|
|
|
+ }
|
|
|
+ chche = formBeaan.get(i);
|
|
|
+ holer.name_tv.setText(StringUtils.isEmpty(chche.getName()) ? "" : chche.getName());
|
|
|
+ holer.select_scb.setChecked(chche.isClick());
|
|
|
+ holer.select_scb.setFocusable(false);
|
|
|
+ holer.select_scb.setClickable(false);
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHoler {
|
|
|
+ CheckBox select_scb;
|
|
|
+ TextView name_tv;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|