/** * LostFindListFragment.java[v 1.0.0] * class:com.mydream.fragment.freg,LostFindListFragment * �ε±� create at 2016-3-30 * ��Ҫ���ܣ�ʧ�������б� */ package com.bdyjy.fragment; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import com.alibaba.fastjson.JSON; import com.bdyjy.R; import com.bdyjy.activity.MainActivity; import com.bdyjy.constants.Const; import com.bdyjy.constants.HandlerOrder; import com.bdyjy.custom.view.XListView; import com.bdyjy.custom.view.XListView.IXListViewListener; import com.bdyjy.util.OkHttpUtils; import com.bdyjy.util.SPUtils; import com.bdyjy.adapter.LostFindListAdapter; import com.bdyjy.entity.lostfind.LostFindListBean; import com.bdyjy.entity.lostfind.LostFindContentBean; import com.bdyjy.entity.attArryData; import com.bdyjy.entity.lostfind.LostFind; import android.annotation.SuppressLint; import android.app.Fragment; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import android.widget.TextView.OnEditorActionListener; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; @SuppressLint("NewApi") public class LostFindListFragment extends Fragment implements IXListViewListener { private MainActivity ctx; private TextView tv_back; private EditText et_search; // ����״̬�µ������ private TextView tv_search_cancel;// �ر��������� private RelativeLayout rl_searchbar_off; // �ر�״̬�µ������ private RelativeLayout rl_searchbar_on;// ����״̬�µ������ // ������ʾ״̬֮����л� private RelativeLayout l1; private RelativeLayout l2; private RelativeLayout l3; private TextView tv_tag1; private TextView tv_tag2; private TextView tv_tag3; private View view_tag1; private View view_tag2; private View view_tag3; private int type = 0;// ��ȡ���������� 0��־ȫ�� 1��ʾʧ�� 2��ʾ���� private int pageSize = 5;// ���ص��б���Ŀ private int sizeStep = 5;// ÿ�μ��ص���Ŀ private String searchKeys;// �����ؼ��� private boolean is_search = false;// ��������״̬ true ��������״̬ false��������״̬ private Button delete_search; // �����������ܵ��߼����⻹û�н�� private TextWatcher textWatcher = new TextWatcher() { // ������������������һ������ Ŀǰ�Ĺ����� ��������������ݣ� ������ʱ�� ��ʾ��հ��� private CharSequence temp; private int editStart; private int editEnd; @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub temp = s; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub // mTextView.setText(s);//�����������ʵʱ��ʾ } @Override public void afterTextChanged(Editable s) { // ���ݱ䶯֮�� searchKeys = et_search.getText().toString().trim(); if (TextUtils.isEmpty(searchKeys)) { delete_search.setVisibility(View.INVISIBLE); } else { delete_search.setVisibility(View.VISIBLE); } } }; private TextView tv_release; private XListView lv_lost;// ����չʾ�б� private LostFindListAdapter adpater;// ���������� private List<Map<String, Object>> listItems; public LostFindListFragment(MainActivity ctx) { this.ctx = ctx; initHandler(); } /**************** ��Ϣ������ *******************/ String toastMsg = null; Handler handler = null; private void initHandler() { handler = new Handler(ctx.getMainLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case HandlerOrder.TOAST: // ��ȡ����ʧ�� // TODO Toast.makeText(ctx, toastMsg, Toast.LENGTH_LONG).show(); break; case HandlerOrder.UPDATE_LISTVIEW: // ������������ lv_lost.onLoad(); loadData(); break; case HandlerOrder.PROCESSBAR_SHOW: ctx.showRoundProcessDialog(); break; case HandlerOrder.PROCESSBAR_HIDE: ctx.hideRoundProcessDialog(); break; case HandlerOrder.POST_OK: // �ؼ����ύ�ɹ� �첽��ȡ���� �������� String res; handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); res = msg.getData().getString("body"); LostFindListBean bean = JSON.parseObject(res, LostFindListBean.class); String app_result_key = bean.getApp_result_key(); if ("0".equals(app_result_key)) { List<LostFind> list = bean.getData().getRows(); MainActivity.lostfindlist = list; handler.sendEmptyMessage(HandlerOrder.UPDATE_LISTVIEW); return; } else { toastMsg = "��ȡ����ʧ�ܣ���������"; handler.sendEmptyMessage(HandlerOrder.TOAST); } break; case HandlerOrder.POST_ERROR: // ��ȡʧ�� toastMsg = "��ȡ����ʧ�ܣ���������"; handler.sendEmptyMessage(HandlerOrder.TOAST); break; } } }; } /***********************************************/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.lostfind_list_fragment, null); // ������һ���� tv_back = (TextView) view.findViewById(R.id.tv_back); tv_back.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctx.jumpToLakesideFragment(); } }); // ��ת���������� tv_release = (TextView) view.findViewById(R.id.setting); tv_release.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctx.jumpToLostRelease(Const.FRAGMENT2_ID); } }); lv_lost = (XListView) view.findViewById(R.id.lv_lostfind_list); lv_lost.setPullLoadEnable(true); lv_lost.setXListViewListener(this); listItems = new ArrayList<Map<String, Object>>(); // ��ʼ������� rl_searchbar_off = (RelativeLayout) view .findViewById(R.id.searchbar_off); rl_searchbar_on = (RelativeLayout) view.findViewById(R.id.searchbar_on); // ���������� rl_searchbar_off.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { rl_searchbar_off.setVisibility(View.INVISIBLE); rl_searchbar_on.setVisibility(View.VISIBLE); et_search.setFocusable(true); et_search.requestFocus(); // �����Զ��������뷨 InputMethodManager imm = (InputMethodManager) et_search .getContext().getSystemService( Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED); is_search = true; // ���뿪��״̬ Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) et_search .getContext().getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(et_search, 0); } }, 400); } }); tv_search_cancel = (TextView) view.findViewById(R.id.tv_search_cancel); // �ر������� tv_search_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { is_search = false; // ����״̬�ر� rl_searchbar_off.setVisibility(View.VISIBLE); rl_searchbar_on.setVisibility(View.INVISIBLE); et_search.setText(""); pageSize = 5; // ���ҽ���ǰѡ�е�������Ӵֱ�ɫ�������Ļع�ԭstyle tv_tag1.setTextColor(0xFF5A5A5A); tv_tag2.setTextColor(0xFF9A9A9A); tv_tag3.setTextColor(0xFF9A9A9A); type = 0; view_tag1.setBackgroundColor(0xFF5A5A5A); view_tag2.setBackgroundColor(0x005A5A5A); view_tag3.setBackgroundColor(0x005A5A5A); pageSize = 5; getLostFindList(type); } }); // ������������� et_search = (EditText) view.findViewById(R.id.et_search); et_search.addTextChangedListener(textWatcher); et_search.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == 0 || actionId == 3) && event != null) { search(); } return false; } }); lv_lost.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // ����ѡ��ĵ���¼� TextView tv = (TextView) view .findViewById(R.id.tv_lostfind_id_item); getLostFindContent(tv.getText().toString()); } }); // ��ʼ��ɾ����ť delete_search = (Button) view.findViewById(R.id.bt_search_delete); delete_search.setOnClickListener(new OnClickListener() { public void onClick(View view) { et_search.setText(""); } }); if (null == MainActivity.lostfindlist) getLostFindList(0);// ��ȡ�б����� else loadData(); initTab(view); return view; } /** * ��ʼ��ѡ� * * @param view */ private void initTab(View view) { // ���������л� l1 = (RelativeLayout) view.findViewById(R.id.ly_lost1); l2 = (RelativeLayout) view.findViewById(R.id.ly_lost2); l3 = (RelativeLayout) view.findViewById(R.id.ly_lost3); tv_tag1 = (TextView) view.findViewById(R.id.tv_lost_tag1); tv_tag2 = (TextView) view.findViewById(R.id.tv_lost_tag2); tv_tag3 = (TextView) view.findViewById(R.id.tv_lost_tag3); view_tag1 = (View) view.findViewById(R.id.view_lost_tag1); view_tag2 = (View) view.findViewById(R.id.view_lost_tag2); view_tag3 = (View) view.findViewById(R.id.view_lost_tag3); // ÿ���л��������ʺ�̨��Ȼ����ص��б��� l1.setOnClickListener(new OnClickListener() { @SuppressLint("NewApi") @Override public void onClick(View v) { // ���ҽ���ǰѡ�е�������Ӵֱ�ɫ�������Ļع�ԭstyle tv_tag1.setTextColor(0xFF5A5A5A); tv_tag2.setTextColor(0xFF9A9A9A); tv_tag3.setTextColor(0xFF9A9A9A); type = 0; view_tag1.setBackgroundColor(0xFF5A5A5A); view_tag2.setBackgroundColor(0x005A5A5A); view_tag3.setBackgroundColor(0x005A5A5A); pageSize = 5; getLostFindList(type); } }); l2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ���ҽ���ǰѡ�е�������Ӵֱ�ɫ�������Ļع�ԭstyle tv_tag1.setTextColor(0xFF9A9A9A); tv_tag2.setTextColor(0xFF5A5A5A); tv_tag3.setTextColor(0xFF9A9A9A); type = 1; pageSize = 5; view_tag1.setBackgroundColor(0x005A5A5A); view_tag2.setBackgroundColor(0xFF5A5A5A); view_tag3.setBackgroundColor(0x005A5A5A); getLostFindList(type); } }); l3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ���ҽ���ǰѡ�е�������Ӵֱ�ɫ�������Ļع�ԭstyle tv_tag1.setTextColor(0xFF9A9A9A); tv_tag2.setTextColor(0xFF9A9A9A); tv_tag3.setTextColor(0xFF5A5A5A); type = 2; pageSize = 5; view_tag1.setBackgroundColor(0x005A5A5A); view_tag2.setBackgroundColor(0x005A5A5A); view_tag3.setBackgroundColor(0xFF5A5A5A); getLostFindList(type); } }); } // ��listview�������� private void loadData() { Log.i("lost", "ok"); // ���ԭ������ listItems.clear(); Map<String, Object> map = null; for (int i = 0; i < MainActivity.lostfindlist.size(); i++) { map = new HashMap<String, Object>(); String title = MainActivity.lostfindlist.get(i).getTitle(); map.put("title", title); // ��Ʒ���� map.put("image", R.drawable.news_1); // ͼƬ��Դ, ��ʱ��ʹ��ͬһ��ͼƬ��Ϊ���� map.put("time", MainActivity.lostfindlist.get(i).getCreateTime()); map.put("statusShow", MainActivity.lostfindlist.get(i) .getStatusShow()); map.put("id", MainActivity.lostfindlist.get(i).getId()); map.put("showtype", MainActivity.lostfindlist.get(i).getTypeShow()); List<attArryData> attArry = MainActivity.lostfindlist.get(i) .getAttArry(); String http = ""; String http2 = ""; String http1 = ""; try { http1 = attArry.get(0).getFilePath().toString().trim(); http2 = MainActivity.lostfindlist.get(i).getAttachmentPrefix(); } catch (Exception e) { e.printStackTrace(); } http = http2 + http1; map.put("http", http); listItems.add(map); } if (null == adpater) { adpater = new LostFindListAdapter(ctx, listItems); // ���������� lv_lost.setAdapter(adpater); } else { adpater.refresh(listItems); } } // �������װ�Ӻ�̨һ����ȡʧ�������б�ķ��� private void getLostFindList(final int type) { new Thread() { @Override public void run() { handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); // ����get���� String res = null; Log.i("�����������", "������" + type); // ��sharePreference��ȡ��֮ǰ�洢�IJ��� String token = (String) SPUtils.get(ctx, "token", ""); String singnature = (String) SPUtils.get(ctx, "singnature", ""); String st = (String) SPUtils.get(ctx, "st", ""); try { res = OkHttpUtils.getInstance().doGet( ctx, "/admin/lostfound/grid.do?pageNo=1&pageSize=" + pageSize + "&type=" + type + "&token=" + token + "&singnature=" + singnature + "&st=" + st); } catch (Exception e) { e.printStackTrace(); toastMsg = "��ȡʧ�ܣ�������"; handler.sendEmptyMessage(HandlerOrder.TOAST); handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); return; } System.out.println("����ʧ�����죺���󷵻صĽ���ǣ�" + res.trim()); // ArrayList<String> // filePathList=MainActivity.lostfindlist.get(1).getfilePathList(); // System.out.println(MainActivity.lostfindlist.get(1)); handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); // ���Խ�json��ת����bean���� LostFindListBean bean = JSON.parseObject(res, LostFindListBean.class); // System.out.println("xxxx:" + bean.getApp_result_key()); // ����ֵ������JSON��ʽ�����ݣ���Ҫ��������� if (res.trim().length() == 0) { toastMsg = "��ȡʧ��,������"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } String app_result_key = bean.getApp_result_key(); if ("0".equals(app_result_key)) { // ��������˵���������������ݣ���Ҫ�������ȡ���ŵı��� List<LostFind> list = bean.getData().getRows(); // ����Щ���Ŷ���洢��sp�� MainActivity.lostfindlist = list; // ʹ��handlerȥ֪ͨ���̸߳���listview handler.sendEmptyMessage(HandlerOrder.UPDATE_LISTVIEW); } else { toastMsg = "��ȡ����ʧ��,������"; handler.sendEmptyMessage(HandlerOrder.TOAST); } } }.start(); } // �������� �б�ҳ���������� private void search() { handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); // ����get���� // String res = null; HashMap<String, String> map1 = new HashMap<String, String>(); // ��sharePreference��ȡ��֮ǰ�洢�IJ��� String token = (String) SPUtils.get(ctx, "token", ""); String singnature = (String) SPUtils.get(ctx, "singnature", ""); String st = (String) SPUtils.get(ctx, "st", ""); searchKeys = et_search.getText().toString().trim(); Log.i("pageSearchKey is", searchKeys); map1.put("pageSearchKeys", searchKeys); String http = "/admin/lostfound/grid.do?pageNo=1&pageSize" + pageSize + "&type=" + type + "&token=" + token + "&singnature=" + singnature + "&st=" + st; OkHttpUtils.getInstance().doPostAsync(ctx, http, map1, handler); } // �������װ�Ӻ�̨һ����ȡ�������ݵķ��� private void getLostFindContent(final String id) { new Thread() { @Override public void run() { handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); // ����get���� String res = null; // ��sharePreference��ȡ��֮ǰ�洢�IJ��� String token = (String) SPUtils.get(ctx, "token", ""); String singnature = (String) SPUtils.get(ctx, "singnature", ""); String st = (String) SPUtils.get(ctx, "st", ""); try { res = OkHttpUtils.getInstance().doGet( ctx, "/admin/lostfound/findById.do?id=" + id + "&token=" + token + "&singnature=" + singnature + "&st=" + st); LostFindContentBean bean = JSON.parseObject(res, LostFindContentBean.class); if (res.trim().length() == 0) { toastMsg = "��ȡʧ�ܣ�������"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } else { String app_result_key = bean.getApp_result_key(); if ("0".equals(app_result_key))// ���������������ŵ�����, // ��ô��Ҫ������ȡ�����ŵı��⣬���ݣ���ʾ�ڽ����� { LostFind b = bean.getEntity(); MainActivity.lostfindcontent = b; // ��ת������ҳ ctx.jumpToClickById(Const.FRAGMENT_LOSTFINDCONTENT_ID); System.out.println("content��������" + res.trim()); } else { toastMsg = "��ȡ����ʧ�ܣ���������"; handler.sendEmptyMessage(HandlerOrder.TOAST); return; } } } catch (Exception e) { e.printStackTrace(); toastMsg = "��ȡʧ�ܣ�������"; handler.sendEmptyMessage(HandlerOrder.TOAST); handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); } handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); // Log.i("token��ֵ", token); // Log.d("content", res.trim()); } }.start(); } /** * �������������أ�����ˢ����ش��� */ @Override public void onRefresh()// ����ˢ�� { if (is_search == true) { search(); } else { getLostFindList(type); } } @Override public void onLoadMore()// ���Ǽ��ظ��� { pageSize += sizeStep; if (is_search == true) { search(); } else { getLostFindList(type); } } }