| | |
| | | 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.util.AppApi;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.entity.Place;
|
| | | import cn.com.basic.face.discern.entity.Device;
|
| | | import cn.com.basic.face.util.SharedPreferencesUtils;
|
| | |
|
| | | public class DeviceMng {
|
| | | public static DeviceMng instance = new DeviceMng();
|
| | |
|
| | | public static final String authorationId = "101";
|
| | | public static String authorationId = null;
|
| | |
|
| | | public static DeviceMng getInstance() {
|
| | | return instance;
|
| | | }
|
| | |
|
| | | public void findPlace() {
|
| | | public void findDevice() {
|
| | | new Thread() {
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | while (true) {
|
| | | if (!BaseApplication.getInstance().deviceAvailable) {
|
| | | load ();
|
| | | } else {
|
| | | break;
|
| | | }
|
| | | Thread.sleep(3000);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }.start();
|
| | | }
|
| | |
|
| | | public void load () {
|
| | | try {
|
| | | RequestParams params = new RequestParams(AppApi.BASEURL + AppApi.PLACE_LIST);
|
| | | params.addBodyParameter(Place.FieldNames.authorizationId, authorationId);
|
| | | if (authorationId == null || authorationId.trim().length() <= 1) {
|
| | | getAuthorationId();
|
| | | return;
|
| | | }
|
| | | 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<Place> places = resultBean.getListBeanOfType(Place.class);
|
| | | List<Device> places = resultBean.getListBeanOfType(Device.class);
|
| | | if (places.size() > 0) {
|
| | | BaseApplication.getInstance().setPlace(places.get(0));
|
| | | BaseApplication.getInstance().setDevice(places.get(0));
|
| | | } 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) {
|
| | | 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 getCamera1Address() {
|
| | | String username = "admin";
|
| | | String password = "admin12345";
|
| | | String ip = "192.168.1.70";
|
| | | String port = "554";
|
| | |
|
| | | // SharedPreferences camera1 = DeviceMng.getInstance().loadSharedPreferences(CommonVariables.DeviceSharedPreferences.CAMERA1);
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_username", ""))) {
|
| | | // username = camera1.getString("fragment_device_right_camera1_username", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_password", ""))) {
|
| | | // password = camera1.getString("fragment_device_right_camera1_password", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_ip", ""))) {
|
| | | // ip = camera1.getString("fragment_device_right_camera1_ip", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_port", ""))) {
|
| | | // port = camera1.getString("fragment_device_right_camera1_port", "");
|
| | | // }
|
| | |
|
| | | return "rtsp://"+username+":"+password+"@"+ip+":"+port+"/h264/ch1/sub/av_stream";
|
| | | }
|
| | |
|
| | | public String getCamera2Address() {
|
| | | String username = "admin";
|
| | | String password = "a1234567";
|
| | | String ip = "192.168.1.68";
|
| | | String port = "554";
|
| | |
|
| | | // SharedPreferences camera1 = DeviceMng.getInstance().loadSharedPreferences(CommonVariables.DeviceSharedPreferences.CAMERA2);
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_username", ""))) {
|
| | | // username = camera1.getString("fragment_device_right_camera1_username", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_password", ""))) {
|
| | | // password = camera1.getString("fragment_device_right_camera1_password", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_ip", ""))) {
|
| | | // ip = camera1.getString("fragment_device_right_camera1_ip", "");
|
| | | // }
|
| | | // if (!"".equals(camera1.getString("fragment_device_right_camera1_port", ""))) {
|
| | | // port = camera1.getString("fragment_device_right_camera1_port", "");
|
| | | // }
|
| | |
|
| | | return "rtsp://"+username+":"+password+"@"+ip+":"+port+"/h264/ch1/sub/av_stream";
|
| | | }
|
| | |
|
| | | }
|