com.stardon.carassistant.Activity.BusinessRecordFunctionList_Activity.java Source code

Java tutorial

Introduction

Here is the source code for com.stardon.carassistant.Activity.BusinessRecordFunctionList_Activity.java

Source

package com.stardon.carassistant.Activity;

import java.util.HashMap;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.stardon.carassistant.R;
import com.stardon.carassistant.application.BaseActivity;
import com.stardon.carassistant.application.CarAssistantApplication;
import com.stardon.carassistant.bean.BaseResponseBodyVO;
import com.stardon.carassistant.bean.BaseResponseMsgVO;
import com.stardon.carassistant.bean.Bean08Q12;
import com.stardon.carassistant.bean.ResponseRootVo;
import com.stardon.carassistant.db.UserDao;
import com.stardon.carassistant.db.tab.User;
import com.stardon.carassistant.dialog.MyToast;
import com.stardon.carassistant.utils.LocalImageHelper;
import com.stardon.stardonframe.net.volleyframenet.VolleyInterface;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * @: BusinessRecordFunctionList_Activity
 * @: 1.  <br/>
 *        a.  <br/>
 *        b.    <br/>
 *        abToast b08Q12 <br/>
 *        Toastmessage <br/>
 *            
 *         <br/>
 *        2.  <br/>
 *          Toast* <br/>
 *         abToast b08W11 <br/>
 *        Toastmessage <br/>
 *         Toast <br/>
 *        3. <br/>
 *        0 <br/>
 *        1  <br/>
 *        a.  <br/>
 *        3.1.2108Q12 <br/>
 *        3.1.2208Q12 <br/>
 *        2 a. <br/>
 *        Toast <br/>
 *         <br/>
 *        3.1.23 <br/>
 *        3.1.24 <br/>
 *        3.1.25 <br/>
 * @: 
 * @: 2016-9-23
 * @:
 * @:
 * @:
 */
public class BusinessRecordFunctionList_Activity extends BaseActivity {

    // items
    /**
     * Item
     */
    private RelativeLayout itemBasicInfo;
    /**
     * Item
     */
    private RelativeLayout itemPhotoEnvir;
    /**
     * Item
     */
    private RelativeLayout itemPhotoLicense;
    /**
     * Item
     */
    private RelativeLayout itemPhotoProof;
    /**
     * Item
     */
    private RelativeLayout itemButton;
    /**
     * Item
     */
    private RelativeLayout itemMessage;
    // 
    /**
     * 
     */
    private TextView statusitemBasicInfo;
    /**
     * 
     */
    private TextView statusitemPhotoEnvir;
    /**
     * 
     */
    private TextView statusitemPhotoLicense;
    /**
     * 
     */
    private TextView statusitemPhotoProof;

    // true=false=
    /**
     * 
     */
    private boolean statusFlagBasicInfo = false;
    /**
     * 
     */
    private boolean statusFlagPhotoEnvir = false;
    /**
     * 
     */
    private boolean statusFlagPhotoLicense = false;
    /**
     * 
     */
    private boolean statusFlagPhotoProof = false;
    /**
     * 
     */
    private TextView statusItem;
    /**
     * 
     */
    private String orgcode;
    /**
     * 08Q12
     */
    private HashMap<String, String> data08Q12;
    /**
     * 
     */
    private Button confirm;
    /**
     * 
     */
    private int orgType;
    private User user;
    private UserDao dao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_record_function_list);
        // 
        //           LocalImageHelper.init(CarAssistantApplication.getInstance());
        dao = UserDao.getInstance();
        user = dao.queryCurrentUser();
        orgType = Integer.valueOf(user.getUsertype());
        switch (orgType) {
        case 1:
            changeTitleText(R.string.function_list_title_1);
            break;
        case 2:
            changeTitleText(R.string.function_list_title_2);
            break;
        default:
            break;
        }
        // 
        getTitleBack().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        orgcode = user.getOrgnumber();
        // 
        initView();
        getSavedInfo();
        refreshStauts();
        if (orgcode == null || "".equals(orgcode)) {
            return;
        }
        request08Q12();
    }

    /**
     * @: initView
     * @: 
     * @: null
     * @: void
     * @ IOException:
     * @ NullPointerException:
     */
    private void initView() {
        itemBasicInfo = (RelativeLayout) findViewById(R.id.function_list_item_1);
        itemPhotoEnvir = (RelativeLayout) findViewById(R.id.function_list_item_2);
        itemPhotoLicense = (RelativeLayout) findViewById(R.id.function_list_item_3);
        itemPhotoProof = (RelativeLayout) findViewById(R.id.function_list_item_4);
        itemBasicInfo.setOnClickListener(itemOnclickListener);
        itemPhotoEnvir.setOnClickListener(itemOnclickListener);
        itemPhotoLicense.setOnClickListener(itemOnclickListener);
        itemPhotoProof.setOnClickListener(itemOnclickListener);

        itemButton = (RelativeLayout) findViewById(R.id.function_list_item_5);
        itemMessage = (RelativeLayout) findViewById(R.id.function_list_item_6);
        itemMessage.setOnClickListener(itemOnclickListener);

        statusitemBasicInfo = (TextView) findViewById(R.id.function_list_status1);
        statusitemPhotoEnvir = (TextView) findViewById(R.id.function_list_status2);
        statusitemPhotoLicense = (TextView) findViewById(R.id.function_list_status3);
        statusitemPhotoProof = (TextView) findViewById(R.id.function_list_status4);

        statusitemBasicInfo.setVisibility(View.INVISIBLE);
        statusitemPhotoEnvir.setVisibility(View.INVISIBLE);
        statusitemPhotoLicense.setVisibility(View.INVISIBLE);
        statusitemPhotoProof.setVisibility(View.INVISIBLE);

        statusItem = (TextView) findViewById(R.id.function_list_status6);

        confirm = (Button) findViewById(R.id.function_confirm);
        confirm.setOnClickListener(confirmListener);
    }

    /**
     * 1<br/>
     * a.  <br/>
     * 3.1.2108Q12 <br/>
     * 3.1.2208Q12 <br/>
     * 2 <br/>
     * a. <br/>
     * Toast <br/>
     *  <br/>
     * 3.1.23 <br/>
     * 3.1.24 <br/>
     * 3.1.25 <br/>
     */
    private OnClickListener itemOnclickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            Bundle bundle = new Bundle();
            Bean08Q12 bean = bean08Q12;
            bundle.putSerializable("bean", bean);
            switch (v.getId()) {
            case R.id.function_list_item_1:// 
                switch (orgType) {// 
                case 1:
                    jumpTo(DetectionOrganizationInfoRecord_Activity.class, bundle, true);
                    break;
                case 2:
                    jumpTo(MaintainOrganizationInfoRecord_Activity.class, bundle, true);
                    break;
                default:
                    break;
                }
                break;
            case R.id.function_list_item_2:// 
                if (!statusFlagBasicInfo) {
                    MyToast.showButtom(getContext(), "");
                    break;
                }
                bundle.putBoolean("statusFlag", statusFlagPhotoEnvir);
                bundle.putString("type", "1");
                jumpTo(OrganizationEnvironmentPhotos_Activity.class, bundle, true);
                break;
            case R.id.function_list_item_3:// 
                if (!statusFlagBasicInfo) {
                    MyToast.showButtom(getContext(), "");
                    break;
                }
                bundle.putString("type", "2");
                bundle.putBoolean("statusFlag", statusFlagPhotoLicense);
                bundle.putString("flag", "1");
                jumpTo(OrganizationCharterPhoto_Activity.class, bundle, true);
                break;
            case R.id.function_list_item_4:// 
                if (!statusFlagBasicInfo) {
                    MyToast.showButtom(getContext(), "");
                    break;
                }
                bundle.putString("type", "3");
                bundle.putBoolean("statusFlag", statusFlagPhotoProof);
                bundle.putString("flag", "2");
                jumpTo(OrganizationEnvironmentPhotos_Activity.class, bundle, true);
                break;
            case R.id.function_list_item_6:// 
                jumpTo(RecordAudit_Activity.class, bundle, true);
                break;
            default:
                break;
            }

        }
    };

    /**
     *  <br/>
     *  <br/>
     * <br/>
     * Toast* <br/>
     * 18W11 <br/>
     */
    private OnClickListener confirmListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (statusFlagBasicInfo && statusFlagPhotoLicense) {
                request08W11();
                return;
            }
            MyToast.showButtom(getContext(), "*");
        }
    };

    /**
     * @: getContext
     * @: context
     * @: null
     * @: Context
     * @ IOException:
     * @ NullPointerException:
     */
    private Context getContext() {
        return this;
    }

    private Bean08Q12 bean08Q12;

    /**
     * @: request08Q12
     * @: 08Q12 <br/>
     *         <br/>
     *        Toastmessage <br/>
     *         <br/>
     *           <br/>
     *         <br/>
     *         <br/>
     * @: null
     * @: void
     * @ IOException:
     * @ NullPointerException:
     */
    private void request08Q12() {
        String jkid = "08Q12";
        StringBuilder xmlData = new StringBuilder();
        xmlData.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
        xmlData.append("<root>");
        xmlData.append("<QueryCondition>");
        xmlData.append("<orgcode>" + orgcode + "</orgcode>");
        xmlData.append("</QueryCondition>");
        xmlData.append("</root>");
        doRequest(METHOD_QUERY, jkid, xmlData.toString(), new VolleyInterface() {

            @Override
            public void onMySuccess(JSONObject result) {

            }

            @Override
            public void onMySuccess(String result) {
                Document doc = null;
                try {
                    doc = DocumentHelper.parseText(result);
                    Element root = doc.getRootElement();
                    Element head = root.element("head");
                    String code = head.elementTextTrim("code");
                    String message = head.elementTextTrim("message");
                    if (!"1".equals(code)) {// 1.
                        MyToast.showButtom(getContext(), message);
                        return;
                    }
                    {
                        XStream xstream = new XStream(new DomDriver());
                        xstream.ignoreUnknownElements();
                        xstream.alias("root", ResponseRootVo.class);
                        xstream.alias("head", BaseResponseMsgVO.class);
                        xstream.alias("body", BaseResponseBodyVO.class);
                        xstream.aliasField("vehispara", BaseResponseBodyVO.class, "bean08Q12");// 
                        xstream.alias("vehispara", Bean08Q12.class);// 
                        ResponseRootVo b = (ResponseRootVo) xstream.fromXML(result);
                        bean08Q12 = b.getBody().getBean08Q12();
                    }
                    Element body = root.element("body");
                    List<Element> elementList = body.element("vehispara").elements();
                    data08Q12 = new HashMap<String, String>();
                    for (Element element : elementList) {
                        data08Q12.put(element.getName(), element.getTextTrim());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                try {
                    user.setOrgrecoedstate(data08Q12.get("reviewstate"));
                    dao.saveUser(user);
                    reviewstate = data08Q12.get("reviewstate");
                    code = data08Q12.get("code");
                    ishavephoto = data08Q12.get("ishavephoto");
                    pic = data08Q12.get("pic");
                    zzpic = data08Q12.get("zzpic");
                    refreshStauts();
                } catch (Exception e) {
                }
            }

            @Override
            public void onMyError(VolleyError result) {
            }
        });
    }

    /**
     * @: request08W11
     * @: 08W11 <br/>
     *        Toast <br/>
     *        Toastmessage <br/>
     * @: null
     * @: void
     * @ IOException:
     * @ NullPointerException:
     */
    private void request08W11() {
        String jkid = "08W11";
        StringBuilder xmlData = new StringBuilder();
        xmlData.append("<?xml version=\"1.0\" encoding=\"GBK\"?>");
        xmlData.append("<root>");
        xmlData.append("<vehispara>");
        xmlData.append("<orgcode>" + orgcode + "</orgcode>");
        xmlData.append("</vehispara>");
        xmlData.append("</root>");
        doRequest(METHOD_WRITE, jkid, xmlData.toString(), new VolleyInterface() {

            @Override
            public void onMySuccess(JSONObject result) {

            }

            @Override
            public void onMySuccess(String result) {
                Document doc = null;
                try {
                    doc = DocumentHelper.parseText(result);
                    Element root = doc.getRootElement();
                    Element head = root.element("head");
                    String code = head.elementTextTrim("code");
                    String message = head.elementTextTrim("message");
                    MyToast.showButtom(getContext(), message);
                    if (!"1".equals(code)) {// 1.
                        return;
                    }
                    user.setOrgrecoedstate("1");
                    dao.saveUser(user);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // 
                itemButton.setVisibility(View.GONE);
                itemMessage.setVisibility(View.VISIBLE);
                statusItem.setText(R.string.function_list_confirmed);
            }

            @Override
            public void onMyError(VolleyError result) {

            }
        });
    }

    @Override
    public void onBackPressed() {
        setResult(RESULT_OK);
        finish();
    }

    /*
     * <p>Title onDestroy</p> <p>Description </p>
     * @see com.stardon.carassistant.application.BaseActivity#onDestroy()
     */
    /**
     * 
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (data08Q12 == null || data08Q12.size() <= 0) {
            return;
        }
        SharedPreferences mySharedPreferences = getSharedPreferences("BRF_STATUS", Activity.MODE_PRIVATE);
        // SharedPreferences.Editor
        SharedPreferences.Editor editor = mySharedPreferences.edit();
        // putString
        editor.putString("reviewstate", data08Q12.get("reviewstate"));
        editor.putString("code", data08Q12.get("code"));
        editor.putString("ishavephoto", data08Q12.get("ishavephoto"));
        editor.putString("pic", data08Q12.get("pic"));
        editor.putString("zzpic", data08Q12.get("zzpic"));
        editor.putString("phone", user.getPhone());
        editor.commit();
    }

    /**
     * //  // 0: // 1: // 2: // 3:
     */
    private String reviewstate;
    /**
     * 
     */
    private String code;
    /**
     * 
     */
    private String ishavephoto;
    /**
     * 
     */
    private String pic;
    /**
     * 
     */
    private String zzpic;

    private void getSavedInfo() {
        SharedPreferences sharedPreferences = getSharedPreferences("BRF_STATUS", Activity.MODE_PRIVATE);
        if (!sharedPreferences.getString("phone", "0").equals(user.getPhone())) {
            return;
        }
        // getStringvalue2value
        reviewstate = sharedPreferences.getString("reviewstate", "0");
        code = sharedPreferences.getString("code", null);
        ishavephoto = sharedPreferences.getString("ishavephoto", "0");
        pic = sharedPreferences.getString("pic", null);
        zzpic = sharedPreferences.getString("zzpic", "0");
    }

    /**
     * @: refreshStauts
     * @: 
     * @: null
     * @: void
     * @ IOException:
     * @ NullPointerException:
     */
    private void refreshStauts() {
        reviewstate = reviewstate == null || "".equals(reviewstate) ? "0" : reviewstate;
        ishavephoto = ishavephoto == null || "".equals(ishavephoto) ? "0" : ishavephoto;
        zzpic = zzpic == null || "".equals(zzpic) ? "0" : zzpic;
        // 
        // 0:
        // 1:
        // 2:
        // 3:
        switch (Integer.valueOf(reviewstate)) {
        case 0:
            itemButton.setVisibility(View.VISIBLE);
            itemMessage.setVisibility(View.GONE);
            break;
        case 1:
            itemButton.setVisibility(View.GONE);
            itemMessage.setVisibility(View.VISIBLE);
            statusItem.setText(R.string.function_list_confirmed);
            statusItem.setTextColor(getContext().getResources().getColor(R.color.text_blue));
            break;
        case 2:
            itemButton.setVisibility(View.GONE);
            itemMessage.setVisibility(View.VISIBLE);
            statusItem.setText(R.string.function_list_unaudited);
            statusItem.setTextColor(getContext().getResources().getColor(R.color.text_red));
            break;
        case 3:
            itemButton.setVisibility(View.GONE);
            itemMessage.setVisibility(View.VISIBLE);
            statusItem.setText(R.string.function_list_finished);
            statusItem.setTextColor(getContext().getResources().getColor(R.color.text_green));
            break;
        default:
            break;
        }
        // 
        if (code != null && !"".equals(code)) {// 
            statusitemBasicInfo.setText(R.string.function_list_complete);
            statusitemBasicInfo.setVisibility(View.VISIBLE);
            statusFlagBasicInfo = true;
        } else {
            statusitemBasicInfo.setText(R.string.function_list_unfill);
            statusitemBasicInfo.setVisibility(View.VISIBLE);
            statusFlagBasicInfo = false;
        }
        // 
        if (Integer.valueOf(ishavephoto) > 0) {
            statusitemPhotoEnvir.setText(R.string.function_list_complete);
            statusitemPhotoEnvir.setVisibility(View.VISIBLE);
            statusFlagPhotoEnvir = true;
        } else {
            statusitemPhotoEnvir.setText(R.string.function_list_unfill);
            statusitemPhotoEnvir.setVisibility(View.VISIBLE);
            statusFlagPhotoEnvir = false;
        }
        // 
        if (pic != null && !"".equals(pic)) {
            statusitemPhotoLicense.setText(R.string.function_list_complete);
            statusFlagPhotoLicense = true;
            statusitemPhotoLicense.setVisibility(View.VISIBLE);
        } else {
            statusitemPhotoLicense.setText(R.string.function_list_unfill);
            statusitemPhotoLicense.setVisibility(View.VISIBLE);
            statusFlagPhotoLicense = false;
        }
        // 
        if (Integer.valueOf(zzpic) > 0) {
            statusitemPhotoProof.setText(R.string.function_list_complete);
            statusitemPhotoProof.setVisibility(View.VISIBLE);
            statusFlagPhotoProof = true;
        } else {
            statusitemPhotoProof.setText(R.string.function_list_unfill);
            statusitemPhotoProof.setVisibility(View.VISIBLE);
            statusFlagPhotoProof = false;
        }
    }

}