com.tk.httpClientErp.headmancheck.HeadmancheckDetailActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.tk.httpClientErp.headmancheck.HeadmancheckDetailActivity.java

Source

package com.tk.httpClientErp.headmancheck;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeoutException;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.tk.MyStore;
import com.tk.httpClientErp.R;
import com.tk.netUtil.HttpClientUtil;
import com.tk.netUtil.MySimpleAdapter;

public class HeadmancheckDetailActivity extends ListActivity {

    private List<HashMap<String, Object>> headmancheckDetail;
    private String gd_no;
    private boolean mResult = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        gd_no = getIntent().getStringExtra("gd_no");
        headmancheckDetail = MyStore.getBeanListByParam(gd_no, "gd_no", MyStore.headManCheckList);
        String[] from = new String[] { "baoyang", "workername", "gwname", "gs", "workgoupid", "starttime",
                "finishtime", "xmname", "gd_no", "license", "bustypename", "intime", "mResult", "bus_no" };
        int[] to = new int[] { R.id.headmancheck_detail_maintenance, R.id.headmancheck_detail_fix,
                R.id.headmancheck_detail_station, R.id.headmancheck_detail_worktime,
                R.id.headmancheck_detail_fault_code, R.id.headmancheck_detail_begintime,
                R.id.headmancheck_detail_endtime, R.id.headmancheck_detail_project,
                R.id.headmancheck_detail_orderno, R.id.headmancheck_detail_License,
                R.id.headmancheck_detail_busmodel, R.id.headmancheck_detail_admissiontime,
                R.id.headmancheck_detail_checkbox, R.id.headmancheck_detail_bus_no };
        MySimpleAdapter adapter = new MySimpleAdapter(this, headmancheckDetail,
                R.layout.activity_headmancheckdetail, from, to);
        adapter.setWhichCheckbox(R.id.headmancheck_detail_checkbox);
        adapter.setWhichParam("mResult");
        setListAdapter(adapter);
    }

    /**
     * =========================================
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.headmanchecklist, menu);
        return true;
    }

    /**
     * =====================================
     */
    @SuppressWarnings("unchecked")
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        String reultString = null;
        switch (item.getItemId()) {
        case R.id.menu_item_headmanchecklist_check_yes:
            HashMap<String, Object> hashMapsYES = MyStore.subAndDel(MyStore.headManCheckList);
            List<JSONObject> submitJsonArrayYES = (List<JSONObject>) hashMapsYES.get("submitJsonArray");
            List<HashMap<String, Object>> delListYES = (List<HashMap<String, Object>>) hashMapsYES.get("delList");
            params.add(new BasicNameValuePair("submitJsonArray", submitJsonArrayYES.toString()));
            try {
                reultString = HttpClientUtil.postRequest("/android.do?method=updateHeadmancheckYES", params,
                        MyStore.sessionID);
            } catch (TimeoutException e) {
                e.printStackTrace();
                HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(HeadmancheckDetailActivity.this, MyStore.TIMEOUTLOGIN, Toast.LENGTH_SHORT)
                                .show();
                    }
                });
            }
            reultString = HttpClientUtil.callBackSuccOrFail(reultString, "resualt");
            if (HttpClientUtil.reSUCCorFAILE && delListYES.size() != 0) {
                MyStore.headManCheckList.removeAll(delListYES);
                headmancheckDetail.removeAll(delListYES);
            }
            final String MSG = reultString;
            HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(HeadmancheckDetailActivity.this, MSG, Toast.LENGTH_SHORT).show();
                }
            });
            if (headmancheckDetail.size() == 0) {
                MyStore.deletBeanById(gd_no, "gd_no", MyStore.headManCheckFenzu);
                HeadmancheckDetailActivity.this.finish(); // Activity
            }
            ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
            break;
        case R.id.menu_item_headmanchecklist_check_no:
            HashMap<String, Object> hashMapsNO = MyStore.subAndDel(MyStore.headManCheckList);
            List<JSONObject> submitJsonArrayNO = (List<JSONObject>) hashMapsNO.get("submitJsonArray");
            List<HashMap<String, Object>> delListNO = (List<HashMap<String, Object>>) hashMapsNO.get("delList");
            params.add(new BasicNameValuePair("submitJsonArray", submitJsonArrayNO.toString()));
            try {
                reultString = HttpClientUtil.postRequest("/android.do?method=updateHeadmancheckNO", params,
                        MyStore.sessionID);
            } catch (TimeoutException e) {
                e.printStackTrace();
                HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(HeadmancheckDetailActivity.this, MyStore.TIMEOUTLOGIN, Toast.LENGTH_SHORT)
                                .show();
                    }
                });
            }
            reultString = HttpClientUtil.callBackSuccOrFail(reultString, "resualt");
            if (HttpClientUtil.reSUCCorFAILE && delListNO.size() != 0) {
                MyStore.headManCheckList.removeAll(delListNO);
                headmancheckDetail.removeAll(delListNO);
            }
            final String MSG2 = reultString;
            HeadmancheckDetailActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(HeadmancheckDetailActivity.this, MSG2, Toast.LENGTH_SHORT).show();
                }
            });
            if (headmancheckDetail.size() == 0) {
                MyStore.deletBeanById(gd_no, "gd_no", MyStore.headManCheckFenzu);
                HeadmancheckDetailActivity.this.finish(); // Activity
            }
            ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
            break;
        case R.id.menu_item_headmanchecklist_selectec_or_cancle:
            MyStore.selectORcancle(mResult, "mResult", headmancheckDetail);
            mResult = mResult == true ? false : true;
            ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
            break;
        }
        return true;
    }

    @Override
    public void onResume() {
        super.onResume();
        ((MySimpleAdapter) getListAdapter()).notifyDataSetChanged();
    }

}