com.tk.httpClientErp.buscheck.BusDetailActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.tk.httpClientErp.buscheck.BusDetailActivity.java

Source

package com.tk.httpClientErp.buscheck;

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.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

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

public class BusDetailActivity extends Activity {

    private TextView mLicense;
    private TextView mDeptName;
    private TextView mLastCheckTime;
    private TextView mcheckMile;

    private Button mSingleCheckButton; // 

    private CheckBox mFangXiangJi;
    private CheckBox mZhiLaGan;
    private CheckBox mHengLaGan;
    private CheckBox mZhuanXiangJieBi;
    private CheckBox mSiLunZhiDong;
    private CheckBox mQuCheZhiDong;
    private CheckBox mQiBeng;
    private CheckBox mQiLu;
    private CheckBox mQiPing;
    private CheckBox mRanQiGuanDao;
    private CheckBox mZhuKongFa;
    private CheckBox mBanZhouLuoSi;
    private CheckBox mLunTaiLuoSi;
    private CheckBox mChuanDongZhouLuoSi;
    private CheckBox mZhongJianZhiJiaLuoSi;

    private String mBusId;
    private HashMap<String, Object> mBusHaMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checkbusdetail);
        mBusId = getIntent().getStringExtra("busID");
        mBusHaMap = MyStore.getBeanByParam(mBusId, "busID", MyStore.busList);

        mLicense = (TextView) findViewById(R.id.check_busdetail_license);
        mDeptName = (TextView) findViewById(R.id.check_busdetail_deptname);
        mLastCheckTime = (TextView) findViewById(R.id.check_busdetail_lastchecktime);
        mcheckMile = (TextView) findViewById(R.id.check_busdetail_mile);

        mcheckMile.setText(mBusHaMap.get("checkMile").toString());
        mLicense.setText(mBusHaMap.get("license").toString());
        mDeptName.setText(mBusHaMap.get("deptName").toString());
        mLastCheckTime.setText(mBusHaMap.get("securityCheckDate").toString());

        // checkbox
        mFangXiangJi = (CheckBox) findViewById(R.id.check_busdetail_direction);
        mFangXiangJi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("direction"))));
        mFangXiangJi.setOnCheckedChangeListener(checkBoxCommon("direction", mBusHaMap));

        mZhiLaGan = (CheckBox) findViewById(R.id.check_busdetail_draglink);
        mZhiLaGan.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("draglink"))));
        mZhiLaGan.setOnCheckedChangeListener(checkBoxCommon("draglink", mBusHaMap));

        mHengLaGan = (CheckBox) findViewById(R.id.check_busdetail_tierod);
        mHengLaGan.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("tierod"))));
        mHengLaGan.setOnCheckedChangeListener(checkBoxCommon("tierod", mBusHaMap));

        mZhuanXiangJieBi = (CheckBox) findViewById(R.id.check_busdetail_knucklearm);
        mZhuanXiangJieBi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("knucklearm"))));
        mZhuanXiangJieBi.setOnCheckedChangeListener(checkBoxCommon("knucklearm", mBusHaMap));

        mSiLunZhiDong = (CheckBox) findViewById(R.id.check_busdetail_fourwheelbraking);
        mSiLunZhiDong.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("fourwheelbraking"))));
        mSiLunZhiDong.setOnCheckedChangeListener(checkBoxCommon("fourwheelbraking", mBusHaMap));

        mQuCheZhiDong = (CheckBox) findViewById(R.id.check_busdetail_parkingbraking);
        mQuCheZhiDong.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("parkingbraking"))));
        mQuCheZhiDong.setOnCheckedChangeListener(checkBoxCommon("parkingbraking", mBusHaMap));

        mQiBeng = (CheckBox) findViewById(R.id.check_busdetail_pump);
        mQiBeng.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("pump"))));
        mQiBeng.setOnCheckedChangeListener(checkBoxCommon("pump", mBusHaMap));

        mQiLu = (CheckBox) findViewById(R.id.check_busdetail_gascircuit);
        mQiLu.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("gascircuit"))));
        mQiLu.setOnCheckedChangeListener(checkBoxCommon("gascircuit", mBusHaMap));

        mQiPing = (CheckBox) findViewById(R.id.check_busdetail_airbottle);
        mQiPing.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("airbottle"))));
        mQiPing.setOnCheckedChangeListener(checkBoxCommon("airbottle", mBusHaMap));

        mRanQiGuanDao = (CheckBox) findViewById(R.id.check_busdetail_gaspipeline);
        mRanQiGuanDao.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("gaspipeline"))));
        mRanQiGuanDao.setOnCheckedChangeListener(checkBoxCommon("gaspipeline", mBusHaMap));

        mZhuKongFa = (CheckBox) findViewById(R.id.check_busdetail_maincontrolvalve);
        mZhuKongFa.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("maincontrolvalve"))));
        mZhuKongFa.setOnCheckedChangeListener(checkBoxCommon("maincontrolvalve", mBusHaMap));

        mBanZhouLuoSi = (CheckBox) findViewById(R.id.check_busdetail_Halfshaftscrew);
        mBanZhouLuoSi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("Halfshaftscrew"))));
        mBanZhouLuoSi.setOnCheckedChangeListener(checkBoxCommon("Halfshaftscrew", mBusHaMap));

        mLunTaiLuoSi = (CheckBox) findViewById(R.id.check_busdetail_tyrewhorl);
        mLunTaiLuoSi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("tyrewhorl"))));
        mLunTaiLuoSi.setOnCheckedChangeListener(checkBoxCommon("tyrewhorl", mBusHaMap));

        mChuanDongZhouLuoSi = (CheckBox) findViewById(R.id.check_busdetail_Driveshaftscrews);
        mChuanDongZhouLuoSi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("Driveshaftscrews"))));
        mChuanDongZhouLuoSi.setOnCheckedChangeListener(checkBoxCommon("Driveshaftscrews", mBusHaMap));

        mZhongJianZhiJiaLuoSi = (CheckBox) findViewById(R.id.check_busdetail_middle_bracket_screws);
        mZhongJianZhiJiaLuoSi.setChecked(BlToIntOrIntToBl.objToBl((mBusHaMap.get("bracketScrews"))));
        mZhongJianZhiJiaLuoSi.setOnCheckedChangeListener(checkBoxCommon("bracketScrews", mBusHaMap));

        // ~
        mSingleCheckButton = (Button) findViewById(R.id.check_singleBus_button);
        mSingleCheckButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mBusHaMap.containsValue(true)) { // mapturefalse
                    mBusHaMap.put("mResult", true);
                } else {
                    mBusHaMap.put("mResult", false);
                }
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                JSONObject busDetailJsonObj = new JSONObject(mBusHaMap);
                params.add(new BasicNameValuePair("busDetailInfo", busDetailJsonObj.toString()));
                try {
                    final String reultString = HttpClientUtil.postRequest("/android.do?method=checkBusDetail",
                            params, MyStore.sessionID);
                    BusDetailActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(BusDetailActivity.this,
                                    HttpClientUtil.callBackSuccOrFail(reultString, "resualt"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    });
                } catch (TimeoutException e) {
                    BusDetailActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(BusDetailActivity.this, MyStore.TIMEOUTLOGIN, Toast.LENGTH_SHORT).show();
                        }
                    });
                    e.printStackTrace();
                }
                BusDetailActivity.this.finish();
                if (HttpClientUtil.reSUCCorFAILE)
                    MyStore.deletBeanById(mBusId, "busID", MyStore.busList); // List
            }
        });
    }

    /**
     * Checkbox
     * 
     * @param paremString
     * @param busHaMap
     * @return
     */
    private OnCheckedChangeListener checkBoxCommon(final String paramString,
            final HashMap<String, Object> busHaMap) {
        OnCheckedChangeListener changeListener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                busHaMap.put(paramString, isChecked);
            }
        };
        return changeListener;
    }
}