New file |
| | |
| | | package com.utils; |
| | | |
| | | import android.Manifest; |
| | | import android.app.Activity; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Build; |
| | | import android.support.v4.app.ActivityCompat; |
| | | import android.widget.Toast; |
| | | |
| | | import com.callBack.IAddCamera; |
| | | import com.common.openapi.ClassInstanceManager; |
| | | import com.lechange.demo.tools.MediaPlayHelper; |
| | | import com.mm.android.deviceaddmodule.CommonParam; |
| | | import com.mm.android.deviceaddmodule.DeviceAddActivity; |
| | | import com.mm.android.deviceaddmodule.LCDeviceEngine; |
| | | import com.mm.android.deviceaddmodule.mobilecommon.AppConsume.ProviderManager; |
| | | import com.mm.android.deviceaddmodule.openapi.CONST; |
| | | 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 String homeId; |
| | | private String token; |
| | | private String subAccessToken; |
| | | private IAddCamera iAddCamera; |
| | | |
| | | public Activity getActivity() { |
| | | return activity; |
| | | } |
| | | |
| | | /** |
| | | * instance |
| | | */ |
| | | private volatile static HdlToLcUtils instance; |
| | | |
| | | /** |
| | | * getInstance |
| | | * |
| | | * @return HDLLink |
| | | */ |
| | | public static synchronized HdlToLcUtils getInstance() { |
| | | if (instance == null) { |
| | | synchronized (HdlToLcUtils.class) { |
| | | if (instance == null) { |
| | | instance = new HdlToLcUtils(); |
| | | } |
| | | } |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | 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()); |
| | | // if (isChina) { |
| | | //// mAppSecret = "f869433de68a4a06bb8f9bb89118fc"; |
| | | //// mAppid = "lc2ea929282d5f4636"; |
| | | // mUrl = CONST.Envirment.CHINA_TEST.url; |
| | | // ProviderManager.getAppProvider().setAppType(0); |
| | | // } else { |
| | | // secretKey = "017fc27bb987496f9a677e4e6f0c88"; |
| | | // appKey = "lc0285433bc7e8423d"; |
| | | // url = CONST.Envirment.OVERSEAS_PRO.url; |
| | | ProviderManager.getAppProvider().setAppType(1); |
| | | // } |
| | | |
| | | |
| | | |
| | | try { |
| | | CommonParam commonParam = new CommonParam(); |
| | | commonParam.setEnvirment(url);//云端连接 |
| | | commonParam.setContext(activity.getApplication()); |
| | | commonParam.setAppId(appKey); |
| | | commonParam.setAppSecret(secretKey); |
| | | |
| | | //SDK信息初始化 |
| | | LCDeviceEngine.newInstance().init(commonParam); |
| | | } catch (Throwable e) { |
| | | Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show(); |
| | | } |
| | | } |
| | | 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) { |
| | | if(!EventBus.getDefault().isRegistered(this)){ |
| | | EventBus.getDefault().register(this); |
| | | } |
| | | //开启添加页面 |
| | | activity.startActivity(new Intent(activity.getApplication(), DeviceAddActivity.class)); |
| | | |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onGetMessage(String obj) { |
| | | if(obj.equals("backXamarin")){ |
| | | iAddCamera.back(); |
| | | |
| | | if(EventBus.getDefault().isRegistered(this)){ |
| | | EventBus.getDefault().unregister(this); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void play(String deviceId){ |
| | | new DeviceUtils(deviceId).play(); |
| | | } |
| | | |
| | | |
| | | public void setActivity(Activity activity) { |
| | | this.activity = activity; |
| | | } |
| | | |
| | | public String getHomeId() { |
| | | return homeId; |
| | | } |
| | | |
| | | public void setHomeId(String homeId) { |
| | | this.homeId = homeId; |
| | | LCDeviceEngine.newInstance().setHomeId(homeId); |
| | | } |
| | | |
| | | public String getToken() { |
| | | return token; |
| | | } |
| | | |
| | | public void setToken(String token) { |
| | | this.token = token; |
| | | LCDeviceEngine.newInstance().accessToken=(token); |
| | | } |
| | | |
| | | public String getSubAccessToken() { |
| | | return subAccessToken; |
| | | } |
| | | |
| | | public void setSubAccessToken(String subAccessToken) { |
| | | this.subAccessToken = subAccessToken; |
| | | LCDeviceEngine.newInstance().setSubAccessToken(subAccessToken); |
| | | } |
| | | |
| | | private void getSubAccountToken(String openId){ |
| | | UserNetManager.getInstance().subAccountToken(openId, new IUserDataCallBack() { |
| | | @Override |
| | | public void onCallBackOpenId(String str) { |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable throwable) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 请求对讲权限 |
| | | */ |
| | | 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 |
| | | && 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; |
| | | } |
| | | 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) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) |
| | | || ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_EXTERNAL_STORAGE)) { |
| | | ActivityCompat.requestPermissions(activity, |
| | | new String[]{ |
| | | Manifest.permission.RECORD_AUDIO, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION, |
| | | Manifest.permission.CAMERA, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | Manifest.permission.READ_EXTERNAL_STORAGE}, |
| | | 1); |
| | | } else { |
| | | ActivityCompat.requestPermissions(activity, |
| | | new String[]{ |
| | | Manifest.permission.RECORD_AUDIO, |
| | | Manifest.permission.ACCESS_COARSE_LOCATION, |
| | | Manifest.permission.CAMERA, |
| | | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| | | Manifest.permission.READ_EXTERNAL_STORAGE}, |
| | | 1); |
| | | } |
| | | } |
| | | |
| | | } |