package com.bdyjy.fragment; import android.annotation.SuppressLint; import android.app.Fragment; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Telephony; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.util.HashMap; import com.alibaba.fastjson.JSON; import com.bdyjy.R; import com.bdyjy.activity.MainActivity; import com.bdyjy.constants.HandlerOrder; import com.bdyjy.entity.complaint.ComplaintContentQueryResultBean; import com.bdyjy.entity.upload.ImgUploadResultBean; import com.bdyjy.entity.venue.CommitResultBean; import com.bdyjy.util.OkHttpUtils; import com.bdyjy.util.SPUtils; /** * holy ���������еĽ��鷴�� * * @author */ public class FeedbackFragment extends Fragment { private Handler handler; private String toastMsg; private TextView tv_back; private MainActivity ctx; private void initHandler() { handler = new Handler() { @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: // listView1.onLoad(); // loadData(); break; case HandlerOrder.PROCESSBAR_SHOW: ctx.showRoundProcessDialog(); break; case HandlerOrder.PROCESSBAR_HIDE: ctx.hideRoundProcessDialog(); break; case HandlerOrder.UPLOAD_ERROR: Toast.makeText(ctx, "�ϴ������������쳣", Toast.LENGTH_LONG).show(); ctx.hideRoundProcessDialog(); break; case HandlerOrder.UPLOAD_OK: handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); case HandlerOrder.POST_OK: // ���������post֮��Ľ�� handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_HIDE); // ����ֵ������JSON��ʽ�����ݣ���Ҫ��������� String res = msg.getData().get("body").toString(); System.out.println("post_result:\n" + res); ComplaintContentQueryResultBean bean = JSON.parseObject(res, ComplaintContentQueryResultBean.class); String app_result_key = bean.getApp_result_key(); if ("0".equals(app_result_key)) { toastMsg = "������Ϣ�ύ�ɹ�"; handler.sendEmptyMessage(HandlerOrder.TOAST); handler.sendEmptyMessage(HandlerOrder.TO_MAIN); ctx.jumpToPersonalSettingFragment(); } else { toastMsg = bean.getApp_result_message_key();// "��Ϣ�ύʧ�ܣ�������"; handler.sendEmptyMessage(HandlerOrder.TOAST); } break; } } }; } public FeedbackFragment(MainActivity ctx) { this.ctx = ctx; initHandler(); } private EditText tel; private String contact; private EditText info; private String details; private Button submit; @SuppressLint("InflateParams") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.feedback_fragment, null); tv_back = (TextView) view.findViewById(R.id.tv_back); tv_back.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctx.jumpToPersonalSettingFragment(); } }); tel=(EditText)view.findViewById(R.id.tel); info=(EditText)view.findViewById(R.id.infor); submit=(Button)view.findViewById(R.id.submit); submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub contact=tel.getText().toString(); details=info.getText().toString(); //commit Commit(); } }); return view; } private void Commit () { new Thread() { @Override public void run() { // ȡ��ҳ���ϵIJ����Լ�Ӧ���Ѿ��洢�IJ��� 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", ""); // ����post���� tryPost(contact, details,token,singnature, st); System.out.println("�ϴ������ǣ�"+contact+details); } }.start(); } /** * �����첽post��ʽ�����ύ */ private void tryPost( String contact, String details,String token,String singnature, String st) { // ����ʹ���첽post������� HashMap<String, String> map = new HashMap<String, String>(); // ���ڿ�ʼ������� map.put("details",details); map.put("contact", contact); String http = "/admin/feedback/addSave.do?token=" + token + "&singnature=" + singnature + "&st=" + st; handler.sendEmptyMessage(HandlerOrder.PROCESSBAR_SHOW); OkHttpUtils.getInstance().doPostAsync(ctx, http, map, handler); } }