com.zld.ui.ZldNewActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.zld.ui.ZldNewActivity.java

Source

/*******************************************************************************
 * Copyright (c) 2015 by ehoo Corporation all right reserved.
 * 2015413
 *******************************************************************************/
package com.zld.ui;

import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.support.v4.app.FragmentManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.vz.PlateResult;
import com.vz.tcpsdk;
import com.vzvison.database.DeviceInfoTable;
import com.vzvison.database.SnapImageTable;
import com.vzvison.database.plateCallbackInfoTable;
import com.vzvison.database.plateHelper;
import com.vzvison.device.DeviceInfo;
import com.vzvison.device.DeviceSet;
import com.zld.R;
import com.zld.application;
import com.zld.bean.AllOrder;
import com.zld.bean.AppInfo;
import com.zld.bean.CarBitmapInfo;
import com.zld.bean.CarNumberOrder;
import com.zld.bean.LeaveOrder;
import com.zld.bean.MyCameraInfo;
import com.zld.bean.MyLedInfo;
import com.zld.bean.ShaerUiInfo;
import com.zld.bean.UploadImg;
import com.zld.db.SqliteManager;
import com.zld.fragment.CashFragment;
import com.zld.fragment.EntranceFragment;
import com.zld.fragment.ExitFragment;
import com.zld.fragment.OrderDetailsFragment;
import com.zld.fragment.OrderListFragment;
import com.zld.fragment.OrderListFragment.OrderListListener;
import com.zld.fragment.ParkinfoFragment;
import com.zld.fragment.ParkrecordFragment;
import com.zld.fragment.ParkrecordFragment.ParkRecordListener;
import com.zld.fragment.TitleFragment;
import com.zld.lib.constant.Constant;
import com.zld.lib.http.HttpManager;
import com.zld.lib.http.RequestParams;
import com.zld.lib.state.ComeInCarState;
import com.zld.lib.state.OrderListState;
import com.zld.lib.util.BitmapUtil;
import com.zld.lib.util.CameraManager;
import com.zld.lib.util.FileUtil;
import com.zld.lib.util.ImageUitls;
import com.zld.lib.util.IsServiceStart;
import com.zld.lib.util.LedControl;
import com.zld.lib.util.PollingUtils;
import com.zld.lib.util.SharedPreferencesUtils;
import com.zld.lib.util.SocketUtil;
import com.zld.lib.util.StringUtils;
import com.zld.lib.util.TimeTypeUtil;
import com.zld.lib.util.VoicePlayer;
import com.zld.photo.DecodeManager;
import com.zld.photo.UpLoadImage;
import com.zld.service.DetectionServerService;
import com.zld.service.DownLoadService;
import com.zld.service.HomeExitPageService;
import com.zld.service.PollingService;
import com.zld.service.ShareUiService;
import com.zld.view.LineLocalRestartDialog;
import com.zld.view.RestartDialog;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

/**
 * <pre>
 * :
 * :   2015413
 * ?:   HZC
 *
 * ?
 *    
 *    
 *     2015413
 * </pre>
 */
@SuppressLint("HandlerLeak")
public class ZldNewActivity extends BaseActivity
        implements OrderListListener, ParkRecordListener, tcpsdk.OnDataReceiver {
    private String TAG = "ZldNewActivity";
    private Intent serviceIntent;
    public static ZldNewActivity instance;
    public CashFragment cashFragment;
    public ExitFragment exitFragment;
    public TitleFragment titleFragment;
    public OrderListFragment listFragment;
    //    private FragmentManager fragmentManager;
    public EntranceFragment entranceFragment;
    public ParkinfoFragment parkinfoFragment;
    private ParkrecordFragment recordFragment;
    public OrderDetailsFragment detailsFragment;
    private MyBroadCaseReceiver myBroadCaseReceiver;

    public final static int REFRESH = 1;
    public final static int SHOW = 2;
    public final static int SHOW_DIALOG = 3;
    public final static int RESTART = 4;
    public final static int HOME_CAMERA_ERROR_DIALOG = 5;
    public final static int CANCEL_HOME_CAMERA_ERROR_DIALOG = 6;
    public final static int SPEAK = 7;
    public final static int POLE_UP_IMAGE = 8;

    public final static int FULL = 10;
    private static final String INTENT_KEY = "intentkey";

    private SocketUtil socketUtil;
    private MyLedInfo homeledinfo;
    private MyLedInfo exitledinfo;
    private String exitLedFirShow;
    public SqliteManager sqliteManager;

    /**
     * ?
     */
    //    private String type;
    public String passid;
    private long time = 0;
    private Timer timer;
    //    private boolean isCameraOk = false;
    private RestartDialog restartDialog;
    private RestartDialog homerestartDialog;
    private String cameraExitIp;
    public Bitmap resultBitmap;
    //    private int nType = 0;
    //    private int x, y, width, height;
    public boolean isExitComeinCar = false;
    private ArrayList<MyLedInfo> myLedInfoList;
    private HashMap<String, MyLedInfo> cameraipPassid;
    public String freeCarNumber = Constant.sZero;
    private long comeIntime;
    private ArrayList<String> poleIDInList;
    private ArrayList<String> poleIDOutList;

    /**
     * ??Camera
     */
    public ArrayList<MyCameraInfo> selectCameraIn;
    /**
     * ??Camera
     */
    public ArrayList<MyCameraInfo> selectCameraOut;
    /**
     * ????cameraipMyLedInfo
     */
    public HashMap<String, MyLedInfo> selectIpIn;
    /**
     * ????cameraipMyLedInfo
     */
    public HashMap<String, MyLedInfo> selectIpOut;

    public static int editFreeCarNumber = -10000; // ???

    //    DetectionServerService detectionServerService;
    PollingService pollingService;

    public Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            //            boolean isCameraOk;
            switch (msg.what) {
            case Constant.LEAVEORDER_MSG:
                setLeaveOrder(msg);
                break;
            case Constant.COMECAR_MSG:
                try {
                    if (poleIDOutList.size() > 0) {
                        uploadExitPolePhoto(msg, false);
                    } else {
                        showExitInfo(msg);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case Constant.SHOWVIDEO_MSG:

                break;
            case Constant.PARKING_NUMS_MSG:
                // ???,?
                ShaerUiInfo info = (ShaerUiInfo) msg.obj;
                freeCarNumber = info.getFree();
                if (parkinfoFragment.getTime().equals("")) {
                    parkinfoFragment.getChargePeopleInfo();
                }
                break;
            case Constant.OPENCAMERA_SUCCESS_MSG:
                // ??
                //                    isCameraOk = true;
                updateExitCameraState(true);
                if (restartDialog != null) {
                    //???,,false ???
                    restartDialog.setOk(false);
                }
                showToast("???");
                Log.e(TAG, "???");
                //                    new Thread(new Runnable() {
                //                        @Override
                //                        public void run() {
                //                            if (selectCameraOut.size() > 0) {
                //                                uploadCameraState(selectCameraOut.get(0), Constant.CAMERA_STATE_SUCCESS);
                //                            }
                //                        }
                //                    }).start();
                break;
            case Constant.OPENCAMERA_FAIL_MSG:
                Log.e(TAG, "??");
                if (msg.arg1 == -1) {//?,??,
                    showToast("??");
                    CameraManager.reOpenCamera();
                } else if (msg.arg2 == 0) {
                    //                        isCameraOk = false;
                    updateExitCameraState(false);
                    showToast("????");
                }
                FileUtil.writeSDFile("??", "exit camera is close");
                //                    new Thread(new Runnable() {
                //                        @Override
                //                        public void run() {
                //                            if (selectCameraOut.size() > 0) {
                //                                uploadCameraState(selectCameraOut.get(0), Constant.CAMERA_STATE_FAILE);
                //                            }
                //                        }
                //                    }).start();
                break;
            case Constant.KEEP_TIME:
                initLedShowAd();
                break;
            case Constant.SHOWPIC_ONRIGHT_MSG:
                //?
                Log.e(TAG, "?,???");
                deleteOrderIamgeInfo((String) msg.obj);
                break;
            case Constant.RESTART_YES:
                closeAndRestart();
                break;
            case Constant.KEEPALIVE:
                Log.e(TAG, "?" + time);
                Log.e("-----", "?KEEPALIVEKEEPALIVE");
                //                    isCameraOk = true;
                time = System.currentTimeMillis();
                updateExitCameraState(true);
                if (restartDialog != null) {
                    //???,,false ???
                    restartDialog.setOk(false);
                }
                break;
            case Constant.KEEPALIVE_TIME:
                //                    isCameraOk = false;
                updateExitCameraState(false);
                Log.e(TAG, "?");
                if (selectCameraOut != null && selectCameraOut.size() > 0) {
                    showToast("??");
                    restartDialog = new RestartDialog(ZldNewActivity.this, com.zld.R.style.nfcnewdialog, handler,
                            0);
                    restartDialog.setI(5);
                    restartDialog.setOk(true);
                    restartDialog.initTimer();
                    restartDialog.satrtTiming();
                    restartDialog.show();
                } else {
                    break;
                }

                //                    new Thread(new Runnable() {
                //                        @Override
                //                        public void run() {
                //                            if (selectCameraOut.size() > 0)
                //                                uploadCameraState(selectCameraOut.get(0), Constant.CAMERA_STATE_FAILE);
                //                        }
                //                    }).start();
                break;
            case Constant.EXIT_DELAYED_TIME://?
                time = System.currentTimeMillis() + 20000;
                break;
            case Constant.HOME_DELAYED_TIME://?
                updateTime();
                break;
            case Constant.STOP:
                break;
            case Constant.LIST_REFRESH:
                @SuppressWarnings("unchecked")
                ArrayList<AllOrder> localorders = (ArrayList<AllOrder>) msg.obj;
                int type = msg.arg1;
                localOrderShow(localorders, type);
                break;
            case Constant.CLEAR_ORDER:
                initAllFragmentView();
                hideClearOrder();
                break;
            case Constant.UPPOLE_IMAGR_SUCCESS:
                showToast("??");
                break;
            case Constant.UPPOLE_IMAGR_ERROR:
                showToast("?");
                break;
            }
        }
    };

    //   private static ZldNewActivity zldNewActivity=null;
    //   public ZldNewActivity(){}
    public static ZldNewActivity getInstance() {
        //      if(zldNewActivity==null){
        //         zldNewActivity = new ZldNewActivity();
        //      }
        //      return zldNewActivity;
        return instance;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        instance = this;
        initSqliteManager();
        //        initvz();
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.zld_new_layout);
        //        Intent intent = new Intent(this, DetectionServerService.class);
        //        /** Activity? */
        //        bindService(intent, conn, Context.BIND_AUTO_CREATE);
        Intent intentPoll = new Intent(this, PollingService.class); // ? ???
        bindService(intentPoll, connPoll, Context.BIND_AUTO_CREATE);

        initvz();
        ((application) getApplication()).setZldNewActivity(this);

        initImei();
        initView();
        initDevices();
        initLEDs();
        setLedConn();
        startPollService();
        getChargeInfo();
        initCameraInfo();
        initTimer();
        getCameraIpOutPassid();
        getCameraInList();
        getCameraOutList();
        getLedCameraIpIn();
        getLedCameraIpOut();
        /* ???? */
        hideFreeAndChargeBtn();
        passid = getPassid();
        satrtTiming();
        //?
        handler.sendEmptyMessageDelayed(Constant.KEEP_TIME, 10000);
        //        handlerNumber.postDelayed(runnable, 5000);
        berthHandler = new BerthHandler(this);
        berthHandler.sendEmptyMessageDelayed(Constant.BerthHandlerWhat, 5000);
        FileUtil.writeSDFile("", "379-->" + System.currentTimeMillis());
    }

    public application m_gb = null;
    public DeviceInfoTable m_DeviceInfoTable = null;
    public DisplayMetrics dm;
    public Map<Integer, DeviceSet> vedioGroup = new HashMap<Integer, DeviceSet>();

    private void initvz() {

        tcpsdk.getInstance().setup();

        //requestWindowFeature(Window.FEATURE_NO_TITLE);//?

        plateHelper so = new plateHelper(ZldNewActivity.this, "yitijiDatabase.db", null, 1);
        plateCallbackInfoTable pct = new plateCallbackInfoTable();
        pct.setDataBaseHelper(so);

        SnapImageTable sit = new SnapImageTable();
        sit.setDataBaseHelper(so);

        android.app.Application ct = (android.app.Application) getApplicationContext();

        m_gb = (application) ct;

        m_gb.setplateCallbackInfoTable(pct);
        m_gb.setSnapImageTable(sit);

        m_DeviceInfoTable = new DeviceInfoTable();
        m_DeviceInfoTable.setDataBaseHelper(so);

        m_gb.getplateCallbackInfoTable().ClearAll();
        m_gb.getSnapImageTable().ClearAll();

        //   m_DeviceInfoTable.ClearAll();

        //        int count = m_DeviceInfoTable.getRowCount();

        dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

    }

    //    /**
    //     * ??
    //     * @param cameraid  ?id
    //     * @param camerastate ??
    //     */
    //    public void uploadCameraState(MyCameraInfo cameraid, String camerastate) {
    ////      RequestParams params = new RequestParams();
    ////      params.setUrlHeader(Constant.requestUrl + Constant.UPLOAD_CAMERA_STATE);
    ////      params.setUrlParams("cameraid", cameraid.getCameraid());
    ////      params.setUrlParams("state", camerastate);
    ////      String url = params.getRequstUrl();
    ////      Log.e(TAG, "??url---------------->>" + url);
    ////      HttpManager.requestGET(this, url,this);
    //    }
    //
    //    /**
    //     * ??
    //     * @param cameraid  ?id
    //     * @param brakestate ??
    //     */
    //    public void uploadBrakeState(MyCameraInfo cameraid, String brakestate) {
    //      RequestParams params = new RequestParams();
    //      params.setUrlHeader(Constant.requestUrl + Constant.UPLOAD_BRAKE_STATE);
    //      params.setUrlParams("passid", cameraid.getPassid());
    //      params.setUrlParams("cameraid", cameraid.getCameraid());
    //      params.setUrlParams("state", brakestate);
    //      String url = params.getRequstUrl();
    //      Log.e(TAG, "??url---------------->>" + url);
    //      HttpManager.requestGET(this, url,this);      
    //    }

    protected void localOrderShow(ArrayList<AllOrder> localorders, int type2) {
        if (listFragment != null) {
            listFragment.localOrderShow(localorders, type2);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        boolean param = SharedPreferencesUtils.getParam(getApplicationContext(), "zld_config", "isupdate", false);
        if (param) {
            listFragment.getOrderInPark(true);
        }
    }

    private void initImei() {
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        AppInfo.getInstance().setImei(telephonyManager.getDeviceId());
    }

    private void initView() {
        FragmentManager fragmentManager;
        fragmentManager = getSupportFragmentManager();
        titleFragment = (TitleFragment) fragmentManager.findFragmentById(R.id.title_fragment);
        listFragment = (OrderListFragment) fragmentManager.findFragmentById(R.id.order_list_fragment);
        detailsFragment = (OrderDetailsFragment) fragmentManager.findFragmentById(R.id.order_details_fragment);
        cashFragment = (CashFragment) fragmentManager.findFragmentById(R.id.cash_fragment);
        entranceFragment = (EntranceFragment) fragmentManager.findFragmentById(R.id.entrance_fragment);
        recordFragment = (ParkrecordFragment) fragmentManager.findFragmentById(R.id.park_record_fragment);
        parkinfoFragment = (ParkinfoFragment) fragmentManager.findFragmentById(R.id.park_info_fragment);
        exitFragment = (ExitFragment) fragmentManager.findFragmentById(R.id.exit_fragment);
    }

    //    private ServiceConnection conn = new ServiceConnection() {
    //        /** ??? */
    //        @Override
    //        public void onServiceConnected(ComponentName name, IBinder service) {
    //            detectionServerService = ((DetectionServerService.ServiceBinder) service).getService();
    //        }
    //
    //        /** ??? */
    //        @Override
    //        public void onServiceDisconnected(ComponentName name) {
    //            detectionServerService = null;
    //        }
    //
    //    };

    private ServiceConnection connPoll = new ServiceConnection() {
        /** ??? */
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            pollingService = ((PollingService.ServiceBinder) service).getService();

        }

        /** ??? */
        @Override
        public void onServiceDisconnected(ComponentName name) {
            pollingService = null;
        }

    };

    /**
     * ??
     */
    private void initDevices() {
        String type;
        type = SharedPreferencesUtils.getParam(getApplicationContext(), "set_workStation", "workStationType", "");
        if (type != null) {
            if (type.equals("?") || type.equals("?")) {
                startBroadcast();
                startService();
            }
        }
    }

    /**
     * ?LEDSocket
     */
    private void initLEDs() {
        // TODO Auto-generated method stub
        if (socketUtil == null) {
            socketUtil = new SocketUtil();
        }
    }

    /**
     * ???
     */
    private void initSqliteManager() {
        if (sqliteManager == null) {
            //         sqliteManager = new SqliteManager(this);
            //            sqliteManager = ((application) getApplication()).getSqliteManager();
            sqliteManager = ((application) getApplication()).getSqliteManager(ZldNewActivity.this);
        }
    }

    /**
     * ?
     */
    private void initTimer() {
        // TODO Auto-generated method stub
        if (timer == null) {
            timer = new Timer();
        }
    }

    /**
     * ?LED?
     */
    private void setLedConn() {
        if (myLedInfoList == null) {
            myLedInfoList = sqliteManager.selectLed(SqliteManager.PASSTYPE_ALL);
        }
        if (myLedInfoList.size() != 0) {
            LedControl.getLedinstance().startLedConn();
        } else {
            showToast("??LED");
        }
    }

    /**
     * ??
     */
    public void getChargeInfo() {
        // TODO Auto-generated method stub
        if (parkinfoFragment != null) {
            parkinfoFragment.getChargePeopleInfo();
        }
    }

    /**
     * ?Camera?
     */
    private void initCameraInfo() {
        // TODO Auto-generated method stub
        /** ??1??? */
        ArrayList<MyCameraInfo> selectCamera = sqliteManager.selectCamera(SqliteManager.PASSTYPE_OUT);
        if (selectCamera.size() != 0) {
            for (int i = 0; i < selectCamera.size(); i++) {
                final MyCameraInfo myCameraInfo = selectCamera.get(i);
                if (myCameraInfo.getIp() != null) {
                    /** ???,3s??? */
                    TimerTask task = new TimerTask() {
                        public void run() {
                            Log.e(TAG, "??IP" + myCameraInfo.getIp());
                            CameraManager.openCamera(handler, myCameraInfo.getIp());
                            //                     entranceFragment.initFrame(myCameraInfo.getIp());
                        }
                    };
                    Timer timer = new Timer();
                    timer.schedule(task, 3000);
                }
            }
        }
        // ???ID
        poleIDInList = new ArrayList<String>();
        poleIDOutList = new ArrayList<String>();
    }

    private void initLedShowAd() {
        if (myLedInfoList == null) {
            myLedInfoList = sqliteManager.selectLed(SqliteManager.PASSTYPE_ALL);
        }
        for (int i = 0; i < myLedInfoList.size(); i++) {
            MyLedInfo myLedInfo = myLedInfoList.get(i);
            if (myLedInfo != null) {
                String leduid = myLedInfo.getLeduid();
                String matercont = myLedInfo.getMatercont();
                socketUtil.sendLedData(myLedInfo, leduid, matercont, null, false);
            }
        }
        try {
            File filelog = new File(FileUtil.getSDCardPath() + "/tcb/data.txt");
            if (filelog.exists() && filelog.isFile()) {
                Long length = filelog.length();
                if (length > 20 * 1024 * 1024) {
                    // 10M
                    filelog.delete();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        FileUtil.fileRegularDelete();
    }

    /**
     * service??????UI
     */
    private void startBroadcast() {
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.exit");
        filter.addAction("com.zld.action.startservicereceiver");
        filter.addAction("com.zld.action.restartservicereceiver");
        myBroadCaseReceiver = new MyBroadCaseReceiver();
        this.registerReceiver(myBroadCaseReceiver, filter);
    }

    private void startService() {
        serviceIntent = new Intent(this, HomeExitPageService.class);
        Bundle bundle = new Bundle();
        bundle.putString(INTENT_KEY, "init");
        bundle.putString("comid", AppInfo.getInstance().getComid());
        bundle.putString("uid", AppInfo.getInstance().getUid());
        serviceIntent.putExtras(bundle);
        this.startService(serviceIntent);
    }

    /**
     * ??
     */
    //    Handler handlerNumber = new Handler();
    //    Runnable runnable = new Runnable() {
    //        @Override
    //        public void run() {
    //            if (freeCarNumber != null) {
    //                showFreeCarNumber();
    //            }
    //            handlerNumber.postDelayed(this, 6000);
    //        }
    //    };
    private static BerthHandler berthHandler;

    static class BerthHandler extends Handler {
        WeakReference<ZldNewActivity> weakReference;

        BerthHandler(ZldNewActivity zldNewActivity) {
            weakReference = new WeakReference<ZldNewActivity>(zldNewActivity);
        }

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            ZldNewActivity zldNewActivity = weakReference.get();
            if (zldNewActivity.freeCarNumber != null) {
                zldNewActivity.showFreeCarNumber();
            }
            berthHandler.removeMessages(Constant.BerthHandlerWhat);
            berthHandler.sendEmptyMessageDelayed(Constant.BerthHandlerWhat, 6000);
        }
    }

    public void showFreeCarNumber() {
        if (System.currentTimeMillis() - comeIntime < 6000) {
            return;
        }

        ShaerUiInfo info = new ShaerUiInfo();
        int number = Integer.valueOf(freeCarNumber); // ?
        info.setFree(freeCarNumber);
        if (editFreeCarNumber == 0) {
            info.setFree(String.valueOf(number)); // 0?
        } else if (editFreeCarNumber != -10000) {
            number += editFreeCarNumber; //
            info.setFree(String.valueOf(number));
        }
        if (number <= 0) {
            editFreeCarNumber -= number;
            number = 0;
        }

        parkinfoFragment.setShare(info);
        SharedPreferencesUtils.setParam(getApplicationContext(), "carNumber", "carNumber", number + "");
        if (homeledinfo == null) {
            return;
        }
        if (!TextUtils.isEmpty(homeledinfo.getType()) && homeledinfo.getType().equals(Constant.sOne)) {
            String content;

            if (number <= 0) {
                content = "?";

            } else if (number > 0 && number < 10) {
                content = "?000" + number;
            } else if (number > 10 && number < 100) {
                content = "?00" + number;
            } else if (number > 100 && number < 1000) {
                content = "?0" + number;
            } else if (number > 1000 && number < 10000) {
                content = "?" + number;
            } else {
                return;
            }
            //         PollingUtils.stopPollingService(this, ShareUiService.class,
            //               "com.zld.service.ShareUi_Temp");

            //         socketUtil.sendLedData(homeledinfo, "42", content, "", false);
            if (homeledinfo.getHeight().equals("16")) {
                socketUtil.sendLedData(homeledinfo, "41", content, "", false);
            } else {
                socketUtil.sendLedData(homeledinfo, "42", content, "", false);
            }
        } else {
            if (!TextUtils.isEmpty(homeledinfo.getHeight()) && homeledinfo.getHeight().equals("16")) {
                socketUtil.sendLedData(homeledinfo, "41", "", "", false);
            } else {
                socketUtil.sendLedData(homeledinfo, "42", "", "", false);
            }
        }
    }

    /**
     * ?? : 2015314 ?:
     *
     * @param bundle ?
     * @throws IOException
     */
    private void showHomeInfo(Bundle bundle) throws IOException {
        int height = bundle.getInt("carPlateheight");
        int width = bundle.getInt("carPlatewidth");
        int x = bundle.getInt("xCoordinate");
        int y = bundle.getInt("yCoordinate");
        String carPlate = bundle.getString("carPlate");
        /*int billingType = bundle.getInt("billingType");// ?,
        int nType = bundle.getInt("nType");
        int resType = bundle.getInt("resType");*/
        byte[] byteArray = bundle.getByteArray("bitmap");
        String ledContent = bundle.getString("led_content");
        String cameraIp = bundle.getString("cameraIp");
        long time = System.currentTimeMillis();
        Log.e(TAG, "??" + carPlate + " " + time);
        SharedPreferencesUtils.setParam(getApplicationContext(), "zld_config", "carPlate", carPlate);
        SharedPreferencesUtils.setParam(getApplicationContext(), "zld_config", "current_time", time);
        /* ??ip??ledip?,?ledip??ledinfo,??? */
        if (selectIpIn == null || selectIpIn.size() == 0) {
            showToast("???LED???");
        } else {
            homeledinfo = selectIpIn.get(cameraIp);
            Timer timer = new Timer();//Timer
            timer.schedule(new TimerTask() {
                public void run() {
                    socketUtil.sendLedData(null, homeledinfo.getLedip(), null, null, false);
                    this.cancel();
                }
            }, 200);//

            if (ledContent != null) {
                if (homeledinfo != null) {
                    String passtype = homeledinfo.getPasstype();
                    if (passtype.equals(Constant.sZero)) {
                        Log.e(TAG, "homeledinfo:" + homeledinfo);
                        comeIntime = System.currentTimeMillis();
                        if (null != homeledinfo.getLeduid() && homeledinfo.getLeduid().equals("41")) {
                            socketUtil.sendLedData(homeledinfo, "42", ledContent, "", true);
                        } else {
                            socketUtil.sendLedData(homeledinfo, "190351508", ledContent, "", true);
                        }
                        //**
                        //         PollingUtils.startPollingService(this, 0, 1, ShareUiService.class,
                        //               "com.zld.service.ShareUi_Temp");
                    }
                }
            }
        }
        Bitmap homeBitmap = ImageUitls.byteBitmap(byteArray);
        homeBitmap = BitmapUtil.zoomImg(homeBitmap, 1280, 720);

        entranceFragment.refreshView(homeBitmap);
        setDetailInCarState(ComeInCarState.ENTRANCE_COME_IN_CAR_STATE);

        if (listFragment != null) {
            Log.e("OrderListState",
                    "?????" + OrderListState.getInstance().getState());
            if (OrderListState.getInstance().isOrderFinishState()) {//????
                if (x + width <= homeBitmap.getWidth() && y + height <= homeBitmap.getHeight()) {
                    if (x < 10 && y < 10 && width < 10 && height < 10) {
                        detailsFragment.refreshCarPlate(null);
                    } else {
                        Log.e(TAG, "???");
                        if (x > 0 && y > 0 && width > 0 && height > 0) {
                            Bitmap smallCarPlateBmp = Bitmap.createBitmap(homeBitmap, x, y, width, height);
                            detailsFragment.refreshCarPlate(smallCarPlateBmp);
                        }
                    }
                } else {
                    detailsFragment.refreshCarPlate(null);
                }
            }
        }
    }

    /**
     * ??
     */
    private void uploadExitPolePhoto(Message msg, boolean isIn) {
        InputStream bitmapToInputStream = ImageUitls.getBitmapInputStream(Constant.sZero, (Bitmap) msg.obj);
        super.isInternet(this);
        UpLoadImage upLoadImage = new UpLoadImage();

        upLoadImage.setmHandler(handler);
        upLoadImage.setComid(AppInfo.getInstance().getComid());

        upLoadImage.uploadPoleImage(bitmapToInputStream, this, isIn);
        //      liftPoleState.setState(LiftPoleState.LIFTPOLESTATE_NO);
    }

    /**
     * ?? : 2015417 ?:
     *
     * @param msg param
     * @throws IOException
     */
    private void showExitInfo(Message msg) throws IOException {
        int x, y, width, height, nType;
        Log.e(TAG, "????");
        CarBitmapInfo exitCarBmpInfo = new CarBitmapInfo();
        detailsFragment.hidePopupWindow();
        if (msg.obj instanceof Bitmap) {
            resultBitmap = (Bitmap) msg.obj;
            Bundle bd = msg.getData();
            //         int billingType = bd.getInt("billingType");
            nType = bd.getInt("nType");
            String carPlate = bd.getString("carPlate");
            x = bd.getInt("xCoordinate");
            y = bd.getInt("yCoordinate");
            width = bd.getInt("carPlatewidth");
            height = bd.getInt("carPlateheight");
            exitCarBmpInfo.setCarPlate(carPlate);
            exitCarBmpInfo.setBitmap(resultBitmap);
            exitCarBmpInfo.setCarPlateheight(height);
            exitCarBmpInfo.setCarPlatewidth(width);
            exitCarBmpInfo.setxCoordinate(x);
            exitCarBmpInfo.setyCoordinate(y);
            exitCarBmpInfo.setNtype(nType);
            int resType = bd.getInt("resType");
            cameraExitIp = bd.getString("cameraIp");
            if (!carPlate.contains("")) {
                String param = SharedPreferencesUtils.getParam(getApplicationContext(), "zld_config", "carPlate",
                        null);
                long currentTimeMillis = System.currentTimeMillis();
                long param2 = SharedPreferencesUtils.getParam(getApplicationContext(), "zld_config", "current_time",
                        currentTimeMillis);
                Log.e(TAG, "" + param + "=" + currentTimeMillis);
                // ??null ??
                if (param != null && param2 != 0L && param2 != currentTimeMillis) {
                    //?? ?-? ?? 1
                    //? return ?
                    long time = currentTimeMillis - param2;
                    Log.e(TAG, "" + time);
                    if (carPlate.equals(param) && (currentTimeMillis - param2) < 30 * 1000) {
                        Log.e(TAG, "" + carPlate);
                        return;
                    }
                }
            }
            exitledinfo = selectIpOut.get(cameraExitIp);
            if (cameraipPassid.get(cameraExitIp) != null) {
                passid = cameraipPassid.get(cameraExitIp).getPassid();
            }
            exitFragment.refreshAllView(exitCarBmpInfo);
            if (resType == 8) {
                setDetailInCarState(ComeInCarState.EXIT_COME_IN_CAR_STATE);
                /*??,??*/
                beforeRefresh();
                //??
                if (!AppInfo.getInstance().getIsLocalServer(ZldNewActivity.this)) {//???
                                                                                   // 
                    boolean param = SharedPreferencesUtils.getParam(getApplicationContext(), "nettype", "isLocal",
                            false);
                    Log.e("isLocal", "ZldNewActivity showExitInfo get isLocal " + param);
                    if (param) {
                        //                  getLocalOrderDBManager();
                        if (listFragment != null && listFragment.orderListState != null) {
                            listFragment.orderListState.setState(OrderListState.AUTO_SEARCH_STATE);
                        }
                        //                  doAutoSearchTimeOut(resultBitmap,billingType, carPlate);
                        //                  return;
                    }
                }
                hideSeal();
                /* ??,,*/
                hidePrepay();
                showCost();
                setDetailInCarState(ComeInCarState.EXIT_COME_IN_CAR_STATE);
                Log.e(TAG, "???" + detailsFragment.comeInCarState.getState());
                isExitComeinCar = true;
                /* ??? ?? ?*/
                FileUtil.writeSDFile("LOG",
                        "?>>>>>>>>>showExitInfo  " + exitCarBmpInfo.getCarPlate());
                //            HttpManager.UpLogs(ZldNewActivity.this,"?>>>>>>>>>showExitInfo  "+exitCarBmpInfo.getCarPlate());
                search(exitCarBmpInfo.getCarPlate());

            } else if (resType == 4) {
                /* ? */
                /*??takePhotoLinsternull?
                   ??,????*/
                if (takePhotoLinster != null) {
                    takePhotoLinster.setTakePhotoLinster(resultBitmap);
                }
            }
        }
    }

    /**
     * ?item?
     */
    public AllOrder getItemOrder() {
        if (listFragment == null) {
            return null;
        }
        return listFragment.getItemOrder();
    }

    /**
     * ??
     */
    public void cashOrder() {
        if (listFragment == null || getItemOrder() == null) {
            return;
        }
        String orderid = getItemOrder().getId();
        String localid = getItemOrder().getLocalid();
        listFragment.cashOrder(0, orderid, localid);
    }

    /**
     * ?????
     */
    public void setCurrentOrderState() {
        OrderListState.getInstance().setState(OrderListState.PARK_IN_STATE);
    }

    /**
     * ????
     */
    public void setModifyState() {
        OrderListState.getInstance().setState(OrderListState.MODIFY_ORDER_STATE);
    }

    /**
     * ?
     */
    public void refreshListOrder() {
        if (listFragment != null) {
            Log.e("OrderListState",
                    "????" + OrderListState.getInstance().getState());
            if (OrderListState.getInstance().isParkInState() || OrderListState.getInstance().isClearFinishState()) {
                /*???,?,????,?*/
                setDetailInCarState(ComeInCarState.AUTO_REFRESH_ORDER_LIST);
                listFragment.getOrderInPark(true);
            }
        }
    }

    public void initAllFragmentView() {
        if (entranceFragment != null) {
            entranceFragment.refreshView(null);
        }
        if (detailsFragment != null) {
            detailsFragment.refreshView(null);
        }
        if (cashFragment != null) {
            cashFragment.refreshView(null);
        }
    }

    /**
     * ?
     */
    @SuppressWarnings("unused")
    private void beforeCar() {
        Log.e(TAG, "?" + isCashFree());
        if (isCashFree()) {
            cashFragment.freeOrder(false, null);
        }
        cashFragment.setFree(true);
    }

    /**
     * isCashFree?,?..??,??
     */
    private void beforeRefresh() {
        Log.e(TAG, "??" + isCashFree());
        if (isCashFree()) {
            getChargeInfo();
        }
        cashFragment.setFree(true);
    }

    /**
     * ???,ListItem?,? ,? ???,
     */
    public void setDetailInCarState(int state) {
        if (detailsFragment != null) {
            if (detailsFragment.comeInCarState != null) {
                detailsFragment.comeInCarState.setState(state);
            }
        }
    }

    public void setUserName() {
        parkinfoFragment.setChargePeople(AppInfo.getInstance().getName());
        parkinfoFragment.getChargePeopleInfo();
        /*???Uid?*/
        updateUid();
    }

    @Override
    public void refreshDetailView(CarNumberOrder order) {
        Log.e(TAG, "ActivityrefreshDetailView?" + detailsFragment + "==" + order);
        if (detailsFragment != null) {
            detailsFragment.refreshView(order);
        }
    }

    @Override
    public void refreshCashView(CarNumberOrder order) {
        // TODO Auto-generated method stub
        Log.e(TAG, "ActivityrefreshCashView?" + cashFragment + "==" + order);
        if (cashFragment != null) {
            cashFragment.refreshView(order);
        }
    }

    @Override
    public void refreshRecordView(CarNumberOrder order) {
        // TODO Auto-generated method stub
        Log.e(TAG, "ActivityrefreshRecordView?" + recordFragment + "==" + order);
        if (recordFragment != null) {
            recordFragment.refreshView(order);
        }
    }

    @Override
    public void refreshSmallCarPlate(Bitmap bitmap) {
        if (detailsFragment != null) {
            detailsFragment.refreshCarPlate(bitmap);
        }
    }

    public void search(String carNumber) {
        if (listFragment != null) {
            listFragment.searchCarNumber(carNumber, OrderListState.AUTO_SEARCH_STATE);
        }
    }

    public class MyBroadCaseReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context arg0, Intent intent) {
            try {
                // Service????
                Log.e(TAG, "intent:" + intent);
                if (intent != null) {
                    Log.e(TAG, "Activityaction--" + intent.getAction());
                    if (intent.getAction().equals("android.intent.action.exit")) {
                        Bundle bundle = intent.getExtras();
                        if (bundle != null) {
                            switch (bundle.getInt("receiver_key")) {
                            case POLE_UP_IMAGE:
                                byte[] bitmapByte = bundle.getByteArray("bitmap");
                                Bitmap birmap = ImageUitls.byteBitmap(bitmapByte);
                                Message msg = new Message();
                                msg.obj = birmap;
                                if (poleIDInList.size() > 0) {
                                    uploadExitPolePhoto(msg, true);
                                }
                                break;
                            case REFRESH:
                                refreshListOrder();
                                break;
                            case SHOW:
                                showHomeInfo(bundle);
                                break;
                            case SHOW_DIALOG:
                                FileUtil.writeSDFile("??", "???"
                                        + TimeTypeUtil.getComplexStringTime(System.currentTimeMillis()));
                                break;
                            case HOME_CAMERA_ERROR_DIALOG:
                                Log.e(TAG, "? ");
                                if (restartDialog != null && restartDialog.isShowing()) {
                                    break;
                                }
                                if (selectCameraIn != null && selectCameraIn.size() > 0) {
                                    homerestartDialog = new RestartDialog(ZldNewActivity.this,
                                            com.zld.R.style.nfcnewdialog, handler, 1);
                                    homerestartDialog.setI(5);
                                    homerestartDialog.setOk(true);
                                    homerestartDialog.initTimer();
                                    homerestartDialog.satrtTiming();
                                    homerestartDialog.show();
                                } else {
                                    break;
                                }

                                break;
                            case CANCEL_HOME_CAMERA_ERROR_DIALOG:
                                if (homerestartDialog != null) {
                                    //???,,false ???
                                    homerestartDialog.setOk(false);
                                }
                                break;
                            case SPEAK:
                                String content = bundle.getString("led_content");
                                String collect = bundle.getString("led_collect");
                                if (homeledinfo.getHeight().equals("16")) {
                                    socketUtil.sendLedData(homeledinfo, "41", content, collect, true);
                                } else {
                                    socketUtil.sendLedData(homeledinfo, "42", collect, content, true);
                                }
                                //                        sendLedShow(collect, content);
                                break;
                            case Constant.REFRESH_NOMONTHCAR_IMAGE:
                                refershImg("home_nomonthcar_icon");
                                break;
                            case Constant.REFRESH_NOMONTHCAR2_IMAGE:
                                refershImg("home_month2car_icon");
                                break;
                            case Constant.HOME_CAR_OUTDATE_ICON:
                                refershImg("home_car_outdate_icon");
                                break;
                            case FULL:
                                String show = bundle.getString("led_content");
                                String play = bundle.getString("led_collect");
                                playVoice(play);
                                if (homeledinfo.getHeight().equals("16")) {
                                    socketUtil.sendLedData(homeledinfo, "41", show, play, true);
                                } else {
                                    socketUtil.sendLedData(homeledinfo, "42", show, play, true);
                                }
                                //                        sendLedShow(collect, content);
                                break;
                            case 1221:
                                String str = bundle.getString("orderid");
                                showToast(str);
                                LineLocalRestartDialog dialog = new LineLocalRestartDialog(ZldNewActivity.this,
                                        com.zld.R.style.nfcnewdialog, null, str, "?", "?");
                                dialog.show();
                                break;
                            }
                        }
                    } else if (intent.getAction().equals("com.zld.action.startservicereceiver")) {
                        Log.e(TAG, "??service");
                        startPollService();
                    } else if (intent.getAction().equals("com.zld.action.restartservicereceiver")) {
                        Bundle bundle = intent.getExtras();
                        Log.e(TAG, "bundle?null" + bundle);
                        if (bundle != null) {
                            boolean isLine = bundle.getBoolean("isLine", false);
                            Log.e("linelocal", "?????" + isLine);
                            LineLocalRestartDialog restartDialog = new LineLocalRestartDialog(ZldNewActivity.this,
                                    com.zld.R.style.nfcnewdialog, handler, isLine);
                            restartDialog.show();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * ? 30?? 5?? 5
     */
    public void stopPollService() {
        // TODO Auto-generated method stub
        PollingUtils.stopPollingService(this, PollingService.class, "com.zld.service.Polling_Service");
        PollingUtils.stopPollingService(this, ShareUiService.class, "com.zld.service.ShareUi_Service");
        PollingUtils.stopPollingService(this, DownLoadService.class, "com.zld.service.DownLoadImage_Service");
        PollingUtils.stopPollingService(this, DetectionServerService.class,
                "com.zld.service.DetectionServer_Service");
    }

    /**
     * ?
     */
    public void upload(InputStream bitmapToInputStream, String orderId, int type) {
        super.isInternet(this);
        UpLoadImage upLoadImage = new UpLoadImage();
        upLoadImage.setPhotoType(type);
        upLoadImage.setmHandler(handler);
        upLoadImage.setComid(AppInfo.getInstance().getComid());
        upLoadImage.upload(bitmapToInputStream, orderId, exitFragment.exitCarBmpInfo.getxCoordinate() + "",
                exitFragment.exitCarBmpInfo.getyCoordinate() + "",
                exitFragment.exitCarBmpInfo.getCarPlatewidth() + "",
                exitFragment.exitCarBmpInfo.getCarPlateheight() + "", exitFragment.exitCarBmpInfo.getCarPlate());

    }

    /**
     * ?,???
     *
     * @param orderId param
     */
    private void deleteOrderIamgeInfo(String orderId) {
        if (orderId == null) {
            return;
        }
        UploadImg selectImage = this.sqliteManager.selectImage(orderId);
        if (selectImage != null) {
            String imgexitpath = selectImage.getImgexitpath();
            String imghomepath = selectImage.getImghomepath();
            if (imgexitpath != null) {//?
                ImageUitls.deleteImageFile(imgexitpath);
                Log.e(TAG, "???" + orderId);
                this.sqliteManager.deleteData(orderId);
            }
            if (imghomepath != null) {
                ImageUitls.deleteImageFile(imghomepath);
            }
        }
    }

    public void showToast(String text) {
        super.showToast(text);
    }

    /**
     * ??,???????3 ?,
     */
    public void showOrHideBtn() {
        if (listFragment != null) {
            Log.e("OrderListState", "??" + OrderListState.getInstance().getState());
            if (OrderListState.getInstance().isParkOutState()) {
                detailsFragment.hideBtn();
                hideFreeAndChargeBtn();
            } else {
                /*?????*/
                if (OrderListState.getInstance().isClearFinishState()) {
                    showFreeAndChargeBtn();
                }
            }
        }
    }

    public void showFreeHideChargeFinish() {
        if (cashFragment != null) {
            cashFragment.showFreeHideChargeFinish();
        }
    }

    /**
     * ?
     *
     * @param msg `
     */
    public void setLeaveOrder(Message msg) {
        LeaveOrder order = (LeaveOrder) msg.obj;
        Log.e(TAG, "???");
        //        if (order == null) {
        //            // setNullViewYes();
        //        }
        if (!TextUtils.isEmpty(order.getOrderid())) {
            setLeaveState(order);
        }
    }

    @SuppressLint("NewApi")
    public void setLeaveState(LeaveOrder order) {
        Log.e("-------", "setLeaveState");
        if (order.getState() != null && Integer.parseInt(order.getState()) == 1) {
            // 0 
            cashFragment.hideSeal();
        } else if (order.getState() != null) {
            if (Integer.parseInt(order.getState()) == 2) {
                payBack(order.getOrderid());//
                CarNumberOrder currenOrder = detailsFragment.getCurrenOrder();
                AllOrder itemOrder = getItemOrder();
                if (currenOrder != null && itemOrder != null) {
                    /** ???? */
                    if (currenOrder.getCarnumber().equals(order.getCarnumber())
                            || itemOrder.getCarnumber().equals(order.getCarnumber())) {
                        String collect = order.getTotal();
                        String carNumber = order.getCarnumber();
                        carUserPayed(carNumber, collect);
                    }
                }
            } else if (Integer.parseInt(order.getState()) == 0) {
                // 2 
                cashFragment.hideSeal();
            } else if (Integer.parseInt(order.getState()) == -1) {
                // -1 
                showToast("");
            } else {
                showToast("?" + order.getState());
            }
        }
    }

    /**
     * 
     */
    public void payBack(String orderid) {
        RequestParams params = new RequestParams();
        params.setUrlHeader(Constant.requestUrl + Constant.PAY_BACK);
        params.setUrlParams("orderid", orderid);
        params.setUrlParams("comid", AppInfo.getInstance().getComid());
        String url = params.getRequstUrl();
        Log.e(TAG, "url---------------->>" + url);
        HttpManager.requestGET(this, url, this);
    }

    /**
     * 
     */
    Handler handle = new Handler() {
        public void handleMessage(Message msg) {
            carUserPayeds((String) msg.obj);
        }
    };

    public void carUserPayed(String carNumber, String collect) {
        Log.e("--", carNumber);
        Message msg = new Message();
        msg.obj = collect;
        handle.sendMessage(msg);
    }

    public void carUserPayeds(String collect) {
        cashFragment.hideFreeBtn();

        if (getItemOrder().getShopticketid() != null) {
            cashFragment.hideCost();
            cashFragment.setPrepayed(null);
        } else {
            cashFragment.showSeal();
        }

        /* ??,??,?? */
        cashFragment.setFree(false);
        VoicePlayer.getInstance(this).playVoice("");
        if (collect.endsWith(Constant.sZero) && Double.parseDouble(collect) > 0.00f) {
            collect = collect.substring(0, collect.length() - 2);
        }
        controlExitPole();
        /*???*/
        OrderListState.getInstance().setState(OrderListState.ORDER_FINISH_UPPOLE_STATE);
        if (exitledinfo != null && Integer.parseInt(exitledinfo.getWidth()) > 64) {
            sendLedShow(exitledinfo.getMatercont(), "      ",
                    "" + collect + "");
        } else if (exitledinfo != null) {
            sendLedShow(exitledinfo.getMatercont(), "",
                    "" + collect + "");
        }

        getChargeInfo();
    }

    /***
     * OrderDetailsFrament ??Led
     */
    public void sendLedShow(String collectFir, String collectSec, String content) {
        Log.e(TAG, "?:" + exitledinfo);
        String ip = "";
        //???ip,???LED(???ip);
        if (exitledinfo == null) {
            if (selectCameraOut != null) {
                for (int i = 0; i < selectCameraOut.size(); i++) {
                    MyCameraInfo myCameraInfo = selectCameraOut.get(i);
                    if (myCameraInfo != null) {
                        String passtype = myCameraInfo.getPasstype();
                        if (passtype != null && passtype.equals(Constant.sOne)) {
                            ip = myCameraInfo.getIp();
                        }
                    }
                }
            }
            exitledinfo = selectIpOut.get(ip);
        }
        if (exitledinfo != null) {
            String passtype = exitledinfo.getPasstype();
            if (passtype != null && passtype.equals(Constant.sOne)) {
                Log.e(TAG, "??LED:" + "  collect:" + collectSec + "  content:" + content);
                if (null != exitledinfo.getLeduid() && exitledinfo.getLeduid().equals("41")) {
                    if (collectFir != null) {
                        exitLedFirShow = collectFir;
                        Timer timer = new Timer();//Timer
                        timer.schedule(new TimerTask() {
                            public void run() {
                                socketUtil.sendLedData(exitledinfo, "41", exitLedFirShow, null, false);
                                exitLedFirShow = "";
                                this.cancel();
                            }
                        }, 100);//

                    }
                    socketUtil.sendLedData(exitledinfo, "42", collectSec, content, true);
                } else {
                    socketUtil.sendLedData(exitledinfo, "190351508", collectSec, content, true);
                }
            }
        }
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        Log.e("shuyu", "onDestroy??");
        super.onDestroy();
        stopPollService();
        //        this.unbindService(conn);
        LedControl.getLedinstance().destory();
        if (myBroadCaseReceiver != null) {
            this.unregisterReceiver(myBroadCaseReceiver);
            Log.e(TAG, "");
        }
        if (serviceIntent != null) {
            stopService(serviceIntent);
        }
        Intent intent = new Intent(this, DetectionServerService.class);
        stopService(intent);

        DecodeManager.getinstance().stopYitiji();
        tcpsdk.getInstance().cleanup();
        m_gb.getplateCallbackInfoTable().ClearAll();
        m_gb.getSnapImageTable().ClearAll();
    }

    /**
     * ??
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //      showToast("");
        return keyCode == KeyEvent.KEYCODE_BACK || super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        // TODO Auto-generated method stub
        if (event.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
            cashFragment.setFocus();
            return true;
        }
        return event.getKeyCode() == KeyEvent.KEYCODE_ENTER || super.dispatchKeyEvent(event);
    }

    public void updateUid() {
        Bundle bundle = new Bundle();
        bundle.putString("uid", AppInfo.getInstance().getUid());
        serIntent(new Intent(), bundle, "updateuid");
    }

    public void updateExitCameraState(boolean isCameraOk) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("isCameraOk", isCameraOk);
        serIntent(new Intent(), bundle, "exitcamerastate");
    }

    public void updateTime() {
        Bundle bundle = new Bundle();
        serIntent(new Intent(), bundle, "updatetime");
    }

    /**
     * ?Cameraip?? ??
     */
    public void controlExitPole() {
        Log.e(TAG, "cameraExitIp:" + cameraExitIp);
        if (cameraExitIp != null) {
            DecodeManager.getinstance().controlPole(DecodeManager.openPole, cameraExitIp);
            exitledinfo = selectIpOut.get(cameraExitIp);
            Timer timer = new Timer();//Timer
            timer.schedule(new TimerTask() {
                public void run() {
                    if (socketUtil == null || exitledinfo == null) {
                        return;
                    }
                    socketUtil.sendLedData(null, exitledinfo.getLedip(), null, null, false);
                    this.cancel();
                }
            }, 200);//

            new Thread(new Runnable() {
                // ?????????????
                public void run() {
                    try {
                        Thread.sleep(2000);
                        DecodeManager.getinstance().controlPole(DecodeManager.openPole, cameraExitIp);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }).start();

            /*???*/
            //         Log.e("taigan","?:"+result);
            //         new Thread(new Runnable() {
            //            @Override
            //            public void run() {
            //               uploadBrakeState(selectCameraOut.get(0),result+"");
            //            }
            //         }).start();
        }
    }

    /**
     * ?Cameraip?? ??
     */
    public void controlExitCamera() {
        Log.e(TAG, "cameraExitIp:" + cameraExitIp);
        if (cameraExitIp != null) {
            DecodeManager.getinstance().getOneImg(cameraExitIp);
        }
    }

    /**
     * ?Service???
     *
     * @param intent 1
     * @param bundle 2
     * @param action 3
     */
    private void serIntent(Intent intent, Bundle bundle, String action) {
        intent.setClass(ZldNewActivity.this, HomeExitPageService.class);
        bundle.putString(INTENT_KEY, action);
        intent.putExtras(bundle);
        PendingIntent sender = PendingIntent.getService(ZldNewActivity.this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), sender);
    }

    private void getCameraInList() {
        selectCameraIn = sqliteManager.selectCamera(SqliteManager.PASSTYPE_IN);
    }

    private void getCameraOutList() {
        selectCameraOut = sqliteManager.selectCamera(SqliteManager.PASSTYPE_OUT);
    }

    private void getLedCameraIpIn() {
        selectIpIn = sqliteManager.selectIp(SqliteManager.PASSTYPE_IN);
        if (selectIpIn != null && selectIpIn.size() > 0) {
            homeledinfo = selectIpIn.get(selectCameraIn.get(0).getIp());
        }
    }

    private void getLedCameraIpOut() {
        selectIpOut = sqliteManager.selectIp(SqliteManager.PASSTYPE_OUT);
    }

    private void getCameraIpOutPassid() {
        cameraipPassid = sqliteManager.selectIp(SqliteManager.PASSTYPE_OUT);
    }

    /**
     * ??
     */
    public void showFreeAndChargeBtn() {
        cashFragment.showFreeAndChargeBtn();
    }

    /**
     * ????
     */
    public void hideFreeAndChargeBtn() {
        cashFragment.hideFreeAndChargeBtn();
    }

    /**
     * ???
     */
    public void hideSealBtn() {
        cashFragment.hideSeal();
    }

    /**
     * ???
     */
    public boolean isCashFree() {
        return cashFragment.isFree();
    }

    /**
     * ?,?
     */
    public boolean isPolicePole(int nType) {
        /* ? */
        if (nType == Constant.LT_ARMPOL || nType == Constant.LT_ARMPOL2 || nType == Constant.LT_ARMPOL2_ZONGDUI
                || nType == Constant.LT_ARMPOL_ZONGDUI || nType == Constant.LT_ARMY || nType == Constant.LT_ARMY2
                || nType == Constant.LT_POLICE) {
            /* controlExitPole();*/
            clickFreeOrder(true);
            return true;
        }
        return false;
    }

    /**
     * isPolice ??
     */
    public void clickFreeOrder(boolean isPolice) {
        if (cashFragment != null)
            cashFragment.freeActionHandle(isPolice, null);
    }

    /**
     * ?RadioButton
     */
    public void changeRadioBtnColor(int position) {
        if (listFragment != null)
            listFragment.changeRadioBtnColor(position);
    }

    /**
     * 
     */
    public void showCost() {
        if (cashFragment != null)
            cashFragment.ShowCost();
    }

    /**
     * ???
     */
    public void hidePrepay() {
        if (cashFragment != null)
            cashFragment.hidePrepay();
    }

    /**
     * ???
     */
    public void hideSeal() {
        if (cashFragment != null)
            cashFragment.hideSeal();
    }

    //    /**
    //     * ???
    //     */
    //    public void hideSearch() {
    //        if (exitFragment != null)
    //            exitFragment.hideSearch();
    //    }

    //    /**
    //     * ?
    //     */
    //    public void showSearch() {
    //        if (exitFragment != null)
    //            exitFragment.showSearch();
    //    }

    //    /**
    //     * ????
    //     */
    //    public void setOutPoleEnable(Boolean enable) {
    //        exitFragment.setOpenPoleTouchEnable(enable);
    //    }

    /**
     * ???
     */
    public void hideClearOrder() {
        if (detailsFragment != null)
            detailsFragment.hideBtn();
    }
    //
    //    /**?*/
    //    public void showClearOrder() {
    //        if (detailsFragment != null)
    //            detailsFragment.showBtn();
    //    }
    //
    //    public ArrayList<AllOrder> selectMonthUser(ArrayList<AllOrder> localorders) {
    //        if (listFragment != null) {
    ////         localorders = listFragment.selectMonthUser(localorders);
    //        }
    //        return localorders;
    //    }

    /**
     * ??ID
     */
    public String getPassid() {
        if (selectCameraOut.size() > 0) {
            MyCameraInfo myCameraInfo = selectCameraOut.get(0);
            if (myCameraInfo != null) {
                cameraExitIp = myCameraInfo.getIp();
                if (cameraExitIp != null) {
                    passid = myCameraInfo.getPassid();
                    Log.e(TAG, "-->>passid:" + passid);
                    return passid;
                }
            }
        } else if (selectCameraIn.size() > 0) {
            MyCameraInfo myCameraInfo = selectCameraIn.get(0);
            if (myCameraInfo != null) {
                String cameraInIp = myCameraInfo.getIp();
                if (cameraInIp != null) {
                    passid = myCameraInfo.getPassid();
                    Log.e(TAG, "-->>passid:" + passid);
                    return passid;
                }
            }
        }
        return null;
    }

    //    public void saveImage(Bitmap bitmap, final String carnumber, String orderid) {
    //        if (carnumber == null || orderid == null) {
    //            return;
    //        }
    //        //???---
    //        Log.e(TAG, "carnumber:" + carnumber + " orderid:" + orderid);
    //        ImageUitls.SaveImageInfo(sqliteManager, bitmap,
    //                AppInfo.getInstance().getUid(), carnumber, orderid,
    //                x + "", y + "", Constant.EXIT_PHOTOTYPE + "", width + "", height + "");
    //    }
    //
    //    /**
    //     * ???
    //     */
    //    public void getMoney() {
    //        if (parkinfoFragment != null) {
    //            parkinfoFragment.getTollManMoney();
    //        }
    //    }

    /**
     * or??
     *
     * @param total  1
     * @param mobpay 2
     * @param boo    true   false ?
     */
    public void addTollmanMoney(String total, String mobpay, boolean boo) {
        Float money;
        Float mobilemoney;
        if (total == null || total.equals("null")) {
            total = Constant.sZero;
        }
        if (mobpay == null || mobpay.equals("null")) {
            mobpay = Constant.sZero;
        }
        String cashpay = SharedPreferencesUtils.getParam(getApplicationContext(), "userinfo", "cashpay",
                Constant.sZero);
        String mobilepay = SharedPreferencesUtils.getParam(getApplicationContext(), "userinfo", "mobilepay",
                Constant.sZero);

        Log.e(TAG, "?" + total + "== ??" + mobpay + "== ???"
                + cashpay);
        if (boo) {
            money = Float.parseFloat(cashpay) + Float.parseFloat(total);
            mobilemoney = Float.parseFloat(mobilepay) + Float.parseFloat(mobpay);
        } else {
            money = Float.parseFloat(cashpay) - Float.parseFloat(total);
            mobilemoney = Float.parseFloat(mobilepay) - Float.parseFloat(mobpay);
        }

        SharedPreferencesUtils.setParam(getApplicationContext(), "userinfo", "cashpay",
                "" + StringUtils.formatFloat(money));
        SharedPreferencesUtils.setParam(getApplicationContext(), "userinfo", "mobilepay",
                "" + StringUtils.formatFloat(mobilemoney));
        Log.e(TAG, "?--->>>?" + money + "== ??" + mobilemoney);
    }

    //    /**
    //     * ??
    //     */
    //    public void subTollmanMoney(String total, String mobpay) {
    //        total = (total == null) ? Constant.sZero : total;
    //        String cashpay = SharedPreferencesUtils.getParam(
    //                getApplicationContext(), "userinfo", "cashpay", Constant.sZero);
    //        Log.e(TAG, "?" + total + "== ??" + mobpay + "== ???" + cashpay);
    //        Float money = Float.parseFloat(cashpay) - Float.parseFloat(total);
    //        SharedPreferencesUtils.setParam(
    //                getApplicationContext(), "userinfo", "cashpay", "" + StringUtils.formatFloat(money));
    //
    //        mobpay = (mobpay == null) ? Constant.sZero : mobpay;
    //        String mobilepay = SharedPreferencesUtils.getParam(
    //                getApplicationContext(), "userinfo", "mobilepay", Constant.sZero);
    //        Float mobilemoney = Float.parseFloat(mobilepay) - Float.parseFloat(mobpay);
    //        SharedPreferencesUtils.setParam(
    //                getApplicationContext(), "userinfo", "mobilepay", "" + StringUtils.formatFloat(mobilemoney));
    //        Log.e(TAG, "?--->>>?" + money + "== ??" + mobilemoney);
    //    }

    private TakePhotoLinster takePhotoLinster;

    //    public void setTakePhotoLinster(TakePhotoLinster takePhotoLinster) {
    //        this.takePhotoLinster = takePhotoLinster;
    //    }

    public interface TakePhotoLinster {
        void setTakePhotoLinster(Bitmap bitmap);
    }

    public void setMoneyAndTime(String logontime) {
        if (parkinfoFragment != null) {
            parkinfoFragment.getLocalMoney();
            if (logontime != null) {
                String time = TimeTypeUtil.getStringTime(Long.valueOf(logontime + "000"));
                parkinfoFragment.setTime(time);
            }
        }
    }

    public MyLedInfo getExitledinfo() {
        return exitledinfo;
    }

    //    public void setExitledinfo(MyLedInfo exitledinfo) {
    //        this.exitledinfo = exitledinfo;
    //    }

    private void closeAndRestart() {
        titleFragment.closeAndRestart();
    }

    /**
     * 
     */
    private void satrtTiming() {
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                // TODO Auto-generated method stub
                long currentTimeMillis = System.currentTimeMillis();
                if (time == 0 || (currentTimeMillis - time) > 30000) {
                    Message message = new Message();
                    message.what = Constant.KEEPALIVE_TIME;
                    handler.sendMessage(message);
                }
            }
        };
        timer.schedule(task, 20000, 10000);
    }

    /**
     * ? 30?? 5?? 5
     */
    public void startPollService() {
        // TODO Auto-generated method stub
        if (!IsServiceStart.isServiceRunning(this, "com.zld.service.ShareUi_Service")) {
            Log.e(TAG, "????--->ShareUi_Service");
            PollingUtils.startPollingService(this, 0, 30, ShareUiService.class, "com.zld.service.ShareUi_Service");
        }
        //      if (!IsServiceStart.isServiceRunning(this,
        //            "com.zld.service.Polling_Service")) {
        //         Log.e(TAG, "????--->Polling_Service");
        //         PollingUtils.startPollingService(this, 0, 5, PollingService.class,
        //               "com.zld.service.Polling_Service");
        //      }
        if (!IsServiceStart.isServiceRunning(this, "com.zld.service.DownLoadImage_Service")) {
            Log.e(TAG, "???,5--->DownLoadImage_Service");
            PollingUtils.startPollingService(this, 0, 5 * 60, DownLoadService.class,
                    "com.zld.service.DownLoadImage_Service");
        }
        if (!IsServiceStart.isServiceRunning(this, "com.zld.service.DetectionServer_Service")) {
            Log.e(TAG, "???,1ping?--->DetectionServer_Service");
            PollingUtils.startPollingService(this, 0, 10, DetectionServerService.class,
                    "com.zld.service.DetectionServer_Service");
        }
    }

    //    /**
    //     * led?
    //     *
    //     * @param
    //     * @param
    //     */
    //    public void uploadLEDState(String ledip, String ledstate) {
    ////      Log.e("LedServerRunnable", "ledip---------------->>" + ledip);
    ////      String ledid = null;
    ////      ArrayList<MyLedInfo> list = sqliteManager.selectLedByAddress(ledip);
    ////      if(list!=null&&list.size()>0){
    ////         MyLedInfo myled = list.get(0);
    ////         if(myled!=null){
    ////            ledid = myled.getId();
    ////         }
    ////      }
    ////      if(ledid!=null){
    ////         RequestParams params = new RequestParams();
    ////         params.setUrlHeader(Constant.requestUrl + Constant.UPLOAD_LED_STATE);
    ////         params.setUrlParams("ledid", ledid);
    ////         params.setUrlParams("state", ledstate);
    ////         String url = params.getRequstUrl();
    ////         Log.e("LedServerRunnable", "led?url---------------->>" + url);
    ////         HttpManager.requestGET(this, url,this);
    ////      }
    //    }

    /**
     * ?
     */
    public void refershImg(String imgname) {
        ApplicationInfo appInfo = getApplicationInfo();
        int resID = getResources().getIdentifier(imgname, "drawable", appInfo.packageName);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resID);
        entranceFragment.refreshView(bitmap);
    }

    public ArrayList<String> getPoleIDInList() {
        return poleIDInList;
    }

    public ArrayList<String> getPoleIDOutList() {
        return poleIDOutList;
    }

    // -1   0?
    public void setHaveFreeCarNumber(int editFreeCarNumbers) {
        if (editFreeCarNumbers != -1 && editFreeCarNumbers != 0) {
            if (editFreeCarNumber == -10000) {
                editFreeCarNumber = 0;
            }
            editFreeCarNumber += editFreeCarNumbers;
        } else if (editFreeCarNumbers == 0) {
            if (freeCarNumber != null)
                editFreeCarNumber = -Integer.valueOf(freeCarNumber);
        } else {
            editFreeCarNumber = editFreeCarNumbers;
        }
        showFreeCarNumber();
    }

    public void playVoice(String content) {
        VoicePlayer.getInstance(this).playVoice(content);
    }

    @Override
    public void onDataReceive(int handle, PlateResult plateResult, int uNumPlates, int eResultType, byte[] pImgFull,
            int nFullSize, byte[] pImgPlateClip, int nClipSize) {
        try {
            DeviceSet ds = this.getDeviceSetFromHandle(handle);

            if (ds == null) {
                Toast.makeText(ZldNewActivity.this, "?:", Toast.LENGTH_SHORT)
                        .show();
            }

            DeviceInfo di = ds.getDeviceInfo();

            String dateText = "";

            dateText += plateResult.struBDTime.bdt_year;
            dateText += "/";

            dateText += plateResult.struBDTime.bdt_mon;
            dateText += "/";

            dateText += plateResult.struBDTime.bdt_mday;
            dateText += " ";

            dateText += plateResult.struBDTime.bdt_hour;
            dateText += ":";

            dateText += plateResult.struBDTime.bdt_min;
            dateText += ":";

            dateText += plateResult.struBDTime.bdt_sec;

            String plateText = new String(plateResult.license, "GBK");

            if (!m_gb.getplateCallbackInfoTable().addCallbackInfo(di.DeviceName, plateText, dateText, pImgFull,
                    pImgPlateClip)) {
                Toast.makeText(ZldNewActivity.this, "?", Toast.LENGTH_SHORT).show();
            }

            Log.i("visizion", "decodeByteArray begin");

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;//??? 
            options.inInputShareable = true;
            Bitmap bmp;
            try {

                bmp = BitmapFactory.decodeByteArray(pImgFull, 0, pImgFull.length, options);
                if (bmp != null) {
                    Message msg = new Message();

                    msg.what = PlateImage;

                    msg.arg1 = ds.getDeviceInfo().id;
                    msg.obj = bmp;
                    Bundle data = new Bundle();
                    data.putString("plate", plateText);
                    msg.setData(data);

                    handler.sendMessage(msg);
                }
            } catch (OutOfMemoryError e) {
                Log.e("Map", "Tile Loader (241) Out Of Memory Error " + e.getLocalizedMessage());
                System.gc();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                Log.i("visizion", "decodeByteArray end");
            }

        } catch (UnsupportedEncodingException e) {

            Toast.makeText(ZldNewActivity.this, "???", Toast.LENGTH_SHORT).show();
        }
    }

    public static final int PlateImage = 0x200012;

    public DeviceSet getDeviceSetFromHandle(int handle) {
        java.util.Iterator it = vedioGroup.entrySet().iterator();
        while (it.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
            DeviceSet ds = (DeviceSet) entry.getValue();

            if ((ds != null) && (handle == ds.getDeviceInfo().handle)) {
                return ds;
            }
        }

        return null;
    }

    public DeviceSet getDeviceSetFromId(int id) {
        java.util.Iterator it = vedioGroup.entrySet().iterator();
        while (it.hasNext()) {
            java.util.Map.Entry entry = (java.util.Map.Entry) it.next();
            DeviceSet ds = (DeviceSet) entry.getValue();

            if ((Integer) entry.getKey() == id) {
                return ds;
            }
        }

        return null;
    }

}