| | |
| | | import com.mm.android.deviceaddmodule.LCDeviceEngine; |
| | | import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.ProviderManager; |
| | | import com.mm.android.deviceaddmodule.openapi.CONST; |
| | | import com.mm.android.deviceaddmodule.openapi.HttpClient; |
| | | import com.usermodule.net.IUserDataCallBack; |
| | | import com.usermodule.net.UserNetManager; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | public class HdlToLcUtils { |
| | | |
| | | private Activity activity; |
| | | private Activity activity; |
| | | private String homeId; |
| | | private String token; |
| | | private String subAccessToken; |
| | | private IAddCamera iAddCamera; |
| | | |
| | | public Activity getActivity() { |
| | | public Activity getActivity() { |
| | | return activity; |
| | | } |
| | | |
| | |
| | | return instance; |
| | | } |
| | | |
| | | public void initData(Activity activity, String appKey, String secretKey,String url) { |
| | | public void initData(Activity activity, String appKey, String secretKey, String url) { |
| | | this.activity = activity; |
| | | MediaPlayHelper.initContext(activity.getApplication().getApplicationContext()); |
| | | ClassInstanceManager.newInstance().init(activity.getApplication().getApplicationContext()); |
| | |
| | | // mUrl = CONST.Envirment.CHINA_TEST.url; |
| | | // ProviderManager.getAppProvider().setAppType(0); |
| | | // } else { |
| | | // mAppSecret = "017fc27bb987496f9a677e4e6f0c88"; |
| | | // mAppid = "lc0285433bc7e8423d"; |
| | | // mUrl = CONST.Envirment.OVERSEAS_PRO.url; |
| | | ProviderManager.getAppProvider().setAppType(1); |
| | | // secretKey = "017fc27bb987496f9a677e4e6f0c88"; |
| | | // appKey = "lc0285433bc7e8423d"; |
| | | // url = CONST.Envirment.OVERSEAS_PRO.url; |
| | | ProviderManager.getAppProvider().setAppType(1); |
| | | // } |
| | | |
| | | |
| | | |
| | | try { |
| | |
| | | Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | public void openActivity() { |
| | | |
| | | public void openActivity() { |
| | | try { |
| | | // getSubAccountToken("827a98c98da7469b8bc19bb6a3c7651906"); |
| | | activity.startActivity(new Intent(activity, com.lechange.demo.ui.DeviceListActivity.class)); |
| | | } catch (Throwable e) { |
| | | Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | |
| | | public void addCamera(IAddCamera iAddCamera) { |
| | | public void addCamera(IAddCamera iAddCamera) { |
| | | if (!EventBus.getDefault().isRegistered(this)) { |
| | | EventBus.getDefault().register(this); |
| | | } |
| | | this.iAddCamera = iAddCamera; |
| | | //开启添加页面 |
| | | activity.startActivity(new Intent(activity.getApplication(), DeviceAddActivity.class)); |
| | | HdlToLcUtils.getInstance().requestCameraPermissions(); |
| | | |
| | | } |
| | | |
| | | public void play(String deviceId){ |
| | | new DeviceUtils(deviceId).play(); |
| | | public void ShowErrorInfo(boolean isShow) { |
| | | HttpClient.SetShowErrorInfo(isShow); |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onGetMessage(String obj) { |
| | | if (obj.equals("backXamarin")) { |
| | | if (EventBus.getDefault().isRegistered(this)) { |
| | | EventBus.getDefault().unregister(this); |
| | | } |
| | | |
| | | if (iAddCamera != null) |
| | | iAddCamera.back(); |
| | | } |
| | | } |
| | | |
| | | public void play(String deviceId, String title) { |
| | | new DeviceUtils(deviceId, title).play(); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | public void setToken(String token) { |
| | | this.token = token; |
| | | LCDeviceEngine.newInstance().accessToken=(token); |
| | | LCDeviceEngine.newInstance().accessToken = (token); |
| | | } |
| | | |
| | | public String getSubAccessToken() { |
| | |
| | | LCDeviceEngine.newInstance().setSubAccessToken(subAccessToken); |
| | | } |
| | | |
| | | private void getSubAccountToken(String openId){ |
| | | private void getSubAccountToken(String openId) { |
| | | UserNetManager.getInstance().subAccountToken(openId, new IUserDataCallBack() { |
| | | @Override |
| | | public void onCallBackOpenId(String str) { |
| | | if (str!=null){ |
| | | if (str != null) { |
| | | //暂不保存到sp中了,因为获取需要context。 |
| | | // PreferencesHelper.getInstance(getApplicationContext()).set(Constants.SUBACCOUNTTOKEN,str); |
| | | LCDeviceEngine.newInstance().setSubAccessToken(str); |
| | | |
| | | activity.startActivity(new Intent(activity,com.lechange.demo.ui.DeviceListActivity.class)); |
| | | activity.startActivity(new Intent(activity, com.lechange.demo.ui.DeviceListActivity.class)); |
| | | } |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | |
| | | public boolean checkCameraPermissions() { |
| | | boolean isGranted = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED |
| | | && ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED |
| | | && ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; |
| | | return isGranted; |
| | | } |
| | | |
| | | /** |
| | | * 请求摄像头权限 |
| | | */ |
| | | public void requestCameraPermissions() { |
| | | boolean isMinSDKM = Build.VERSION.SDK_INT < 23; |
| | | boolean isGranted = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED |
| | | && ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED |
| | | && ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; |
| | | if (isMinSDKM || isGranted) { |
| | | return; |
| | | } |
| | | requestRecordCameraPermission(); |
| | | } |
| | | |
| | | |
| | | private void requestRecordCameraPermission() { |
| | | if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { |
| | | ActivityCompat.requestPermissions(activity, |
| | | new String[]{ |
| | | Manifest.permission.CAMERA, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | Manifest.permission.READ_EXTERNAL_STORAGE}, |
| | | 1); |
| | | } else { |
| | | ActivityCompat.requestPermissions(activity, |
| | | new String[]{ |
| | | Manifest.permission.CAMERA, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | Manifest.permission.READ_EXTERNAL_STORAGE}, |
| | | 1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 请求对讲权限 |
| | | */ |
| | | public void requestPermission() { |
| | | public void requestPermission() { |
| | | boolean isMinSDKM = Build.VERSION.SDK_INT < 23; |
| | | boolean isGranted = ActivityCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED |
| | | && ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED |
| | |
| | | requestRecordAudioPermission(); |
| | | } |
| | | |
| | | private void requestRecordAudioPermission() { |
| | | private void requestRecordAudioPermission() { |
| | | if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.RECORD_AUDIO) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_COARSE_LOCATION) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA) |