| | |
| | | package cn.com.basic.face.service;
|
| | |
|
| | | import android.content.Context;
|
| | | import android.content.SharedPreferences;
|
| | | import android.widget.Toast;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.common.SqliteSqlBean;
|
| | | import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
| | | import cn.com.basic.face.discern.query.item.DeviceQueryItem;
|
| | | import cn.com.basic.face.fragment.CheckInFragment;
|
| | | import cn.com.basic.face.fragment.DeviceFragment;
|
| | | import cn.com.basic.face.fragment.VisitorRegisterFragment;
|
| | | import cn.com.basic.face.service.sqlite.DeviceDao;
|
| | | import cn.com.basic.face.service.sync.DeleteLastMonthRecordAndPictureThread;
|
| | | import cn.com.basic.face.service.sync.SyncDownThread;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.io.File;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.entity.Device;
|
| | | import cn.com.basic.face.util.SharedPreferencesUtils;
|
| | | import cn.com.basic.face.service.sync.SyncUpThread;
|
| | | import cn.com.basic.face.util.SqliteSqlUtil;
|
| | |
|
| | | public class DeviceMng {
|
| | | public static DeviceMng instance = new DeviceMng();
|
| | |
|
| | | public static final String authorationId = "101";
|
| | | private SyncUpThread syncUpThread = null;
|
| | | private SyncDownThread syncDownThread = null;
|
| | | private DeleteLastMonthRecordAndPictureThread deleteLastMonthRecordAndPictureThread = null;
|
| | |
|
| | | public static String authorationId = "101";
|
| | |
|
| | | public static DeviceMng getInstance() {
|
| | | return instance;
|
| | | }
|
| | |
|
| | | public void findPlace() {
|
| | | try {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL + AppApi.Query.DEVICE_QUERY);
|
| | | params.addBodyParameter(Device.FieldNames.authorizationId, authorationId);
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<Device> places = resultBean.getListBeanOfType(Device.class);
|
| | | if (places.size() > 0) {
|
| | | BaseApplication.getInstance().setDevice(places.get(0));
|
| | | } else {
|
| | | Toast.makeText(BaseApplication.getInstance(), "数据库中找不到该设备", Toast.LENGTH_SHORT).show();
|
| | | public void findDevice() {
|
| | | new Thread() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | while (true) {
|
| | | //AttendanceDao.getInstance().reloadLeftList(null, 0, false);
|
| | | if (!BaseApplication.getInstance().deviceAvailable) {
|
| | | load ();
|
| | | } else {
|
| | | break;
|
| | | }
|
| | | Thread.sleep(3000);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | });
|
| | | }
|
| | | }.start();
|
| | | }
|
| | |
|
| | | public void load () {
|
| | | try {
|
| | | // if (authorationId == null || authorationId.trim().length() <= 1) {
|
| | | // getAuthorationId();
|
| | | // MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | // @Override
|
| | | // public void run() {
|
| | | // Toast.makeText(MainActivity.getInstance(), "请填写设备序列号", Toast.LENGTH_SHORT).show();
|
| | | // }
|
| | | // });
|
| | | // return;
|
| | | // }
|
| | | if (MainActivity.getInstance().getInternetAccessible() == CommonVariables.InternetAccess.INTERNET_NOT_INITIALIZE) {
|
| | | return;
|
| | | }
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL + AppApi.Query.DEVICE_QUERY);
|
| | |
|
| | | params.addBodyParameter(Device.FieldNames.sn, authorationId);
|
| | | params.addBodyParameter(Device.FieldNames.type, CommonVariables.DeviceType.ANDROID_DEVICE);
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | loadAfterReturn(getList(Device.class));
|
| | | }
|
| | | });
|
| | | } else {
|
| | | loadAfterReturn(DeviceDao.getInstance().loadMainDevice(CommonVariables.DeviceType.ANDROID_DEVICE, authorationId));
|
| | | }
|
| | | } catch (Throwable e) {
|
| | | e.printStackTrace();
|
| | | Toast.makeText(BaseApplication.getInstance(), "数据库中找不到该设备", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | }
|
| | |
|
| | | public void loadAfterReturn(List<Device> devices) {
|
| | | // List<Device> devices = getList(Device.class);
|
| | | if (devices.size() > 0) {
|
| | | final Device device = devices.get(0);
|
| | | BaseApplication.getInstance().setAndroidDevice(device);
|
| | | MainActivity.getInstance().runOnUiThread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | DeviceFragment.getInstance().setAndroidDevice(device);
|
| | |
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | |
|
| | | RequestParams params = new RequestParams(AppApi.BASE_URL + AppApi.Query.DEVICE_QUERY);
|
| | | params.addBodyParameter(Device.FieldNames.belongId, device.getBelongId());
|
| | | params.addBodyParameter(Device.FieldNames.type, CommonVariables.DeviceType.CAMERA1);
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<DeviceQueryItem> devices = resultBean.getList(DeviceQueryItem.class);
|
| | | if (devices.size() > 0) {
|
| | | final DeviceQueryItem camera1 = devices.get(0);
|
| | | BaseApplication.getInstance().setCamera1(camera1);
|
| | | DeviceFragment.getInstance().setCamera1(camera1);
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | | params = new RequestParams(AppApi.BASE_URL + AppApi.Query.DEVICE_QUERY);
|
| | | params.addBodyParameter(Device.FieldNames.belongId, device.getBelongId());
|
| | | params.addBodyParameter(Device.FieldNames.type, CommonVariables.DeviceType.CAMERA2);
|
| | | params.addBodyParameter("deviceCompanyId", BaseApplication.getInstance().getAndroidDevice().getCompanyId());
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | public void success() {
|
| | | List<DeviceQueryItem> devices = resultBean.getList(DeviceQueryItem.class);
|
| | | if (devices.size() > 0) {
|
| | | final DeviceQueryItem camera2 = devices.get(0);
|
| | | BaseApplication.getInstance().setCamera2(camera2);
|
| | | DeviceFragment.getInstance().setCamera2(camera2);
|
| | | }
|
| | | }
|
| | | });
|
| | | } else {
|
| | | List<DeviceQueryItem> camera1List = DeviceDao.getInstance().loadCamera(CommonVariables.DeviceType.CAMERA1, device.getBelongId());
|
| | | if (camera1List != null && camera1List.size() > 0) {
|
| | | final DeviceQueryItem camera1 = camera1List.get(0);
|
| | | BaseApplication.getInstance().setCamera1(camera1);
|
| | | DeviceFragment.getInstance().setCamera1(camera1);
|
| | | }
|
| | | List<DeviceQueryItem> camera2List = DeviceDao.getInstance().loadCamera(CommonVariables.DeviceType.CAMERA2, device.getBelongId());
|
| | | if (camera2List != null && camera2List.size() > 0) {
|
| | | final DeviceQueryItem camera2 = camera2List.get(0);
|
| | | BaseApplication.getInstance().setCamera2(camera2);
|
| | | DeviceFragment.getInstance().setCamera2(camera2);
|
| | | }
|
| | | }
|
| | | }
|
| | | });
|
| | | synchronized (this) {
|
| | | if (syncUpThread == null) {
|
| | | syncUpThread = new SyncUpThread();
|
| | | syncUpThread.start();
|
| | | }
|
| | | if (syncDownThread == null) {
|
| | | syncDownThread = new SyncDownThread();
|
| | | syncDownThread.start();
|
| | | }
|
| | | if (deleteLastMonthRecordAndPictureThread == null) {
|
| | | deleteLastMonthRecordAndPictureThread = new DeleteLastMonthRecordAndPictureThread();
|
| | | deleteLastMonthRecordAndPictureThread.start();
|
| | | }
|
| | | }
|
| | | } else {
|
| | | Toast.makeText(BaseApplication.getInstance(), "数据库中找不到该设备", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | }
|
| | |
|
| | | public void getAuthorationId() {
|
| | | SharedPreferences school = DeviceMng.getInstance().loadSharedPreferences(CommonVariables.DeviceSharedPreferences.SCHOOL);
|
| | | if (!"".equals(school.getString("fragment_device_right_device_info_sn", ""))) {
|
| | | authorationId = school.getString("fragment_device_right_device_info_sn", "");
|
| | | }
|
| | | }
|
| | |
|
| | | public void saveWifiSetting(Map<String, String> fields) {
|
| | | SharedPreferencesUtils.save(CommonVariables.DeviceSharedPreferences.WIFI, fields);
|
| | | }
|
| | |
|
| | | public void saveLanSetting(Map<String, String> fields) {
|
| | |
|
| | | // RequestParams params = new RequestParams(AppApi.BASE_URL + AppApi.Query.DEVICE_QUERY);
|
| | | // params.addBodyParameter(Device.FieldNames.sn, authorationId);
|
| | | // params.addBodyParameter(Device.FieldNames.type, CommonVariables.DeviceType.ANDROID_DEVICE);
|
| | | // x.http().post(params, new BaseCommonCallBack() {
|
| | | // public void success() {
|
| | | // List<Device> places = resultBean.getList(Device.class);
|
| | | // if (places.size() > 0) {
|
| | | // BaseApplication.getInstance().setAndroidDevice(places.get(0));
|
| | | // } else {
|
| | | // Toast.makeText(BaseApplication.getInstance(), "数据库中找不到该设备", Toast.LENGTH_SHORT).show();
|
| | | // }
|
| | | // }
|
| | | // });
|
| | | //
|
| | | //
|
| | | // SharedPreferencesUtils.save(CommonVariables.DeviceSharedPreferences.LAN, fields);
|
| | | }
|
| | |
|
| | | public void saveSchoolSetting(Map<String, String> fields) {
|
| | | SharedPreferencesUtils.save(CommonVariables.DeviceSharedPreferences.SCHOOL, fields);
|
| | | getAuthorationId();
|
| | | }
|
| | |
|
| | | public void saveCamera1Setting(Map<String, String> fields) {
|
| | | SharedPreferencesUtils.save(CommonVariables.DeviceSharedPreferences.CAMERA1, fields);
|
| | | }
|
| | |
|
| | | public void saveCamera2Setting(Map<String, String> fields) {
|
| | | SharedPreferencesUtils.save(CommonVariables.DeviceSharedPreferences.CAMERA2, fields);
|
| | | }
|
| | |
|
| | | public SharedPreferences loadSharedPreferences(String name) {
|
| | | return MainActivity.getInstance().getSharedPreferences(name, Context.MODE_PRIVATE);
|
| | | }
|
| | |
|
| | | public String get(SharedPreferences sharedPreferences, String key) {
|
| | | return sharedPreferences.getString(key, "");
|
| | | }
|
| | |
|
| | | public String getCamera2Address() {
|
| | | String username = "admin";
|
| | | String password = "admin12345";
|
| | | String ip = "192.168.1.70";
|
| | | String port = "554";
|
| | | DeviceQueryItem camera2 = DeviceFragment.getInstance().getCamera2();
|
| | | if (camera2 != null) {
|
| | | return "rtsp://admin:admin12345@"+camera2.getIp()+":554/h264/ch1/main/av_stream";
|
| | | }
|
| | | return "rtsp://admin:admin12345@192.168.1.202:554/h264/ch1/main/av_stream";
|
| | | }
|
| | |
|
| | | public String getCamera1Address() {
|
| | | String username = "admin";
|
| | | String password = "a1234567";
|
| | | String ip = "192.168.1.68";
|
| | | String port = "554";
|
| | | DeviceQueryItem camera1 = DeviceFragment.getInstance().getCamera1();
|
| | | if (camera1 != null) {
|
| | | return "rtsp://admin:admin12345@"+camera1.getIp()+":554/h264/ch1/main/av_stream";
|
| | | }
|
| | | return "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream";
|
| | | }
|
| | |
|
| | | public void updateDevice(RequestParams params, Device camera) {
|
| | | if (BaseApplication.getInstance().networkAvailable()) {
|
| | | params.setUri(AppApi.BASE_URL +AppApi.DEVICE_EDIT);
|
| | | x.http().post(params, new BaseCommonCallBack() {
|
| | | @Override
|
| | | public void success() {
|
| | | SqliteSqlUtil.insert(getExtraList(SqliteSqlBean.class));
|
| | | Toast.makeText(BaseApplication.getInstance(),"修改成功", Toast.LENGTH_SHORT).show();
|
| | | }
|
| | | });
|
| | | } else {
|
| | | DeviceDao.getInstance().updateDevice(camera);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|