|
|
@@ -1,17 +1,278 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.activity.oa;
|
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
+import android.text.Editable;
|
|
|
+import android.util.DisplayMetrics;
|
|
|
+import android.view.Gravity;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.PopupWindow;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
import com.xzjmyk.pm.activity.ui.base.BaseActivity;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.entity.EditChangeListener;
|
|
|
+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.util.auto.HttpHandler;
|
|
|
+import com.xzjmyk.pm.activity.util.DisplayUtil;
|
|
|
+import com.xzjmyk.pm.activity.view.RecycleViewDivider;
|
|
|
+import com.xzjmyk.pm.activity.view.crouton.Crouton;
|
|
|
|
|
|
-public class SelectRemarkActivity extends BaseActivity {
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+public class SelectRemarkActivity extends BaseActivity implements HttpHandler.OnResultListener {
|
|
|
+
|
|
|
+ private RecyclerView recyclerview;
|
|
|
+ private List<Bean> beanList;
|
|
|
+ private RecycleAdapter adapter;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_select_remark);
|
|
|
- RecyclerView recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
|
|
|
+ recyclerview = (RecyclerView) findViewById(R.id.recyclerview);
|
|
|
+ EditText search_edit = (EditText) findViewById(R.id.search_edit);
|
|
|
+ search_edit.addTextChangedListener(new EditChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ String input = editable.toString();
|
|
|
+ if (StringUtils.isEmpty(input)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ if (ListUtils.isEmpty(beanList)) return;
|
|
|
+ List<Bean> beans = new ArrayList<>();
|
|
|
+ for (Bean e : beanList) {
|
|
|
+ if (StringUtils.isInclude(e.name, input))
|
|
|
+ beans.add(e);
|
|
|
+ }
|
|
|
+ adapter.setBeanList(beans);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ initData();
|
|
|
+ initView();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
+ getMenuInflater().inflate(R.menu.menu_add_icon, menu);
|
|
|
+ return super.onCreateOptionsMenu(menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+ if (item.getItemId() == R.id.add_item) {
|
|
|
+ showPup();
|
|
|
+ }
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 显示数据
|
|
|
+ private void showPup() {
|
|
|
+ showSaveCompany();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private PopupWindow popupWindow = null;
|
|
|
+
|
|
|
+ private void showSaveCompany( ) {
|
|
|
+ // 一个自定义的布局,作为显示的内容
|
|
|
+ View contentView = LayoutInflater.from(ct).inflate(
|
|
|
+ R.layout.item_select_remark_pop, null);
|
|
|
+ // 设置按钮的点击事件
|
|
|
+ final EditText company_et = (EditText) contentView.findViewById(R.id.company_et);
|
|
|
+ DisplayMetrics dm = getResources().getDisplayMetrics();
|
|
|
+ int w_screen = dm.widthPixels;
|
|
|
+ int h_screen = dm.heightPixels;
|
|
|
+ w_screen = DisplayUtil.dip2px(this, 300);
|
|
|
+ h_screen = DisplayUtil.dip2px(this, 145);
|
|
|
+
|
|
|
+ contentView.findViewById(R.id.ok_tv).setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ String message = company_et.getText().toString();
|
|
|
+ if (StringUtils.isEmpty(message))
|
|
|
+ Crouton.showToast(ct, "请输入有效数据", R.color.load_warning);
|
|
|
+ else {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("data", message);
|
|
|
+ setResult(0x20, intent);
|
|
|
+ popupWindow.dismiss();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ contentView.findViewById(R.id.not_tv).setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ popupWindow.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ popupWindow = new PopupWindow(contentView, w_screen, h_screen, true);
|
|
|
+ popupWindow.setTouchable(true);
|
|
|
+ popupWindow.setOutsideTouchable(false);
|
|
|
+ // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
|
|
|
+// popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_main));
|
|
|
+ // 设置好参数之后再show
|
|
|
+ popupWindow.showAtLocation(contentView, Gravity.CENTER, 0, 0);
|
|
|
+ setbg(0.4f);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setbg(float alpha) {
|
|
|
+ WindowManager.LayoutParams lp = getWindow().getAttributes();
|
|
|
+ lp.alpha = alpha;
|
|
|
+ getWindow().setAttributes(lp);
|
|
|
+ if (popupWindow == null) return;
|
|
|
+ popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ WindowManager.LayoutParams lp = getWindow().getAttributes();
|
|
|
+ lp.alpha = 1f;
|
|
|
+ getWindow().setAttributes(lp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+ recyclerview.setLayoutManager(new LinearLayoutManager(this));
|
|
|
+ RecycleViewDivider viewDivider = new RecycleViewDivider(this, LinearLayout.HORIZONTAL, 1, getResources().getColor(R.color.gray_light));
|
|
|
+ recyclerview.addItemDecoration(viewDivider);
|
|
|
+ adapter = new RecycleAdapter(beanList);
|
|
|
+ recyclerview.setAdapter(adapter);
|
|
|
+ loadNet();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initData() {
|
|
|
+ beanList = new ArrayList<>();
|
|
|
+ Bean bean = new Bean();
|
|
|
+ bean.type = 1;
|
|
|
+ bean.name = "客情维护";
|
|
|
+ beanList.add(bean);
|
|
|
+ bean = new Bean();
|
|
|
+ bean.type = 1;
|
|
|
+ bean.name = "业务办理";
|
|
|
+ beanList.add(bean);
|
|
|
+ bean = new Bean();
|
|
|
+ bean.type = 1;
|
|
|
+ bean.name = "其它拜访";
|
|
|
+ beanList.add(bean);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadNet() {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("condition", "1=1");
|
|
|
+ HttpHandler.getInstance().loadERPByNet(0x11, "mobile/crm/getBusinessChanceStage.action", param, null, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void result(int what, boolean isJSON, String message, Bundle bundle) {
|
|
|
+ if (what == 0x11 && isJSON) {
|
|
|
+ JSONArray array = JSON.parseObject(message).getJSONArray("stages");
|
|
|
+ handlerData(array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void error(int what, int statuCode, String message, Bundle bundle) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void handlerData(JSONArray array) {
|
|
|
+ if (ListUtils.isEmpty(array)) return;
|
|
|
+ Bean bean = null;
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
+ bean = new Bean();
|
|
|
+ bean.type = 1;
|
|
|
+ bean.name = array.getJSONObject(i).getString("BS_NAME");
|
|
|
+ beanList.add(beanList.size(), bean);
|
|
|
+ }
|
|
|
+ adapter.setBeanList(beanList);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ViewHolder> {
|
|
|
+ private List<Bean> beanList;
|
|
|
+
|
|
|
+ public RecycleAdapter(List<Bean> beanList) {
|
|
|
+ this.beanList = beanList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Bean> getBeanList() {
|
|
|
+ return beanList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBeanList(List<Bean> beanList) {
|
|
|
+ this.beanList = beanList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
+ View view = LayoutInflater.from(ct).inflate(R.layout.item_remark, parent, false);
|
|
|
+ return new ViewHolder(view);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBindViewHolder(ViewHolder holder, final int position) {
|
|
|
+ if (beanList.get(position).type == 2) {//输入
|
|
|
+ holder.et.setVisibility(View.VISIBLE);
|
|
|
+ holder.tv.setVisibility(View.GONE);
|
|
|
+ } else if (beanList.get(position).type == 1) {//显示
|
|
|
+ holder.tv.setVisibility(View.VISIBLE);
|
|
|
+ holder.et.setVisibility(View.GONE);
|
|
|
+ holder.tv.setText(StringUtils.isEmpty(beanList.get(position).name) ? "" : beanList.get(position).name);
|
|
|
+ }
|
|
|
+ holder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ String message = beanList.get(position).name;
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("data", message);
|
|
|
+ setResult(0x20, intent);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getItemCount() {
|
|
|
+ return ListUtils.isEmpty(beanList) ? 0 : beanList.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
+ TextView tv;
|
|
|
+ EditText et;
|
|
|
+
|
|
|
+ public ViewHolder(View itemView) {
|
|
|
+ super(itemView);
|
|
|
+ tv = (TextView) itemView.findViewById(R.id.tv);
|
|
|
+ et = (EditText) itemView.findViewById(R.id.et);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class Bean {
|
|
|
+ String name;
|
|
|
+ int type;
|
|
|
}
|
|
|
}
|