| | |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.GPSManagerUtils; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ConfirmationTipDialog; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | | import com.hdl.sdk.link.core.bean.LinkResponse; |
| | |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.core.connect.HDLUdpConnect; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | |
| | | |
| | | /** |
| | | * 我的电站界面 |
| | | * B端-电站界面 |
| | | */ |
| | | public class MyPowerStationActivity extends CustomBaseActivity { |
| | | |
| | |
| | | this.pushTokens(); |
| | | //点击极光通知栏消息进来 |
| | | this.clickJpushNotificationMessage(); |
| | | //通知限权 |
| | | this.notificationSet(); |
| | | //初始化权限 |
| | | this.requestPermissions(); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | //启动页与mainActivity样式一样,这样启动页和mainActivity看上去是一个界面,目的是为了mainActivity遮住下一页; |
| | | // AppManagerUtils.getAppManager().finishActivity(StartActivity.class); |
| | | portConflictDialog(); |
| | | // Intent intent = new Intent(_mActivity, MyPowerStationActivity.class); |
| | | // intent.setFlags(Intent.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); |
| | | // intent.putExtra("skip", "skip");//里面判断有这个标识就跳转到消息中心界面 |
| | | // _mActivity.startActivity(intent); |
| | | //点击极光通知栏消息进来 |
| | | // this.clickJpushNotificationMessage(); |
| | | } |
| | | |
| | | |
| | |
| | | * 上传极光注册ID到云端 |
| | | */ |
| | | private void pushTokens() { |
| | | String is_registrationID = HDLApp.getInstance().getKey("registrationID"); |
| | | String registrationId_tag = "registrationID_" + UserConfigManage.getInstance().getUserId(); |
| | | String is_registrationID = HDLApp.getInstance().getKey(registrationId_tag); |
| | | if (is_registrationID.equals("true")) { |
| | | //上过就没有必要在上传啦 |
| | | return; |
| | |
| | | UserConfigManage.getInstance().setPushId(pushId); |
| | | UserConfigManage.getInstance().Save(); |
| | | } |
| | | HDLApp.getInstance().setInfoMap("registrationID", "true");//记录一下状态,后台杀死app会清空; |
| | | HdlLogLogic.print("添加极光ID到云端--->registrationID:" + finalRegistrationID, true); |
| | | HDLApp.getInstance().setInfoMap(registrationId_tag, "true");//记录一下状态,后台杀死app会清空; |
| | | HdlLogLogic.print("添加极光ID到云端--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("添加极光ID到云端失败--->registrationID:" + finalRegistrationID, true); |
| | | HDLApp.getInstance().setInfoMap(registrationId_tag, "false");//记录一下状态,后台杀死app会清空; |
| | | HdlLogLogic.print("添加极光ID到云端失败--->registrationID:" + UserConfigManage.getInstance().getUserName() + "--->" + finalRegistrationID, true); |
| | | } |
| | | }); |
| | | |
| | |
| | | viewBinding.myMeBottomIl3.titleTv.setText(R.string.power_station_me); |
| | | this.bottomViewChangeOfStyle(); |
| | | |
| | | |
| | | } |
| | | |
| | | private void bottomViewChangeOfStyle() { |
| | |
| | | } |
| | | |
| | | public void requestPermissions() { |
| | | //Manifest.permission.ACCESS_COARSE_LOCATION |
| | | //消息通知限权 |
| | | this.notificationSet(); |
| | | //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}); |
| | |
| | | HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | uniCallBackBaseBean.setType(response.getTopic()); |
| | | uniCallBackBaseBean.setData(response.getData()); |
| | | // if (com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().getUni()) { |
| | | // try { |
| | | // String t = String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL); |
| | | // com.hdl.photovoltaic.ui.test.UniAppMqtt.getInstance().publish(t, JSONObject.toJSON(uniCallBackBaseBean).toString()); |
| | | // } catch (Exception ignored) { |
| | | // } |
| | | // } else { |
| | | HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); |
| | | // } |
| | | // } |
| | | |
| | | } else if (msg instanceof LinkResponse) { |
| | |
| | | * 初始化mqtt客户端 |
| | | */ |
| | | public void initMqttClient() { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.init(_mActivity, info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); |
| | | if (!MqttRecvClient.getInstance().isInit()) { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.getInstance().setConnectParam(info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord(), null); |
| | | MqttRecvClient.getInstance().connect(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("读取mqtt远程信息失败--->" + e.getMessage(), e.getCode(), true); |
| | | } |
| | | }); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("读取mqtt远程信息失败--->" + e.getMessage(), e.getCode(), true); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | |
| | | HdlThreadLogic.runSubThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //防止app启动的时候没有网络(app也登录不了),导致获取不了mqtt远程连接信息; |
| | | initMqttClient(); |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> obj) { |
| | |
| | | |
| | | |
| | | /** |
| | | * 物理按键返回事件 |
| | | * 物理按键返回事件(包括左滑移除事件) |
| | | */ |
| | | @Override |
| | | public void onBackPressed() { |
| | |
| | | private void locationUpdates() { |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); |
| | | GPSManagerUtils.getInstance().getLocation(this); |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | // 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | |
| | | } |
| | | }); |
| | | |
| | | } else { |
| | | // //INTERNET 允许使用网络 |
| | | // //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | // //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | // if (ActivityCompat.checkSelfPermission(_mActivity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
| | | // // TODO: Consider calling |
| | | // // ActivityCompat#requestPermissions |
| | | // // here to request the missing permissions, and then overriding |
| | | // // public void onRequestPermissionsResult(int requestCode, String[] permissions, |
| | | // // int[] grantResults) |
| | | // // to handle the case where the user grants the permission. See the documentation |
| | | // // for ActivityCompat#requestPermissions for more details. |
| | | // return; |
| | | // } |
| | | // HdlLogLogic.print("开始纬度经度--->", true); |
| | | // Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | // |
| | | // //建议这个 minTime 不小于 60000,即 1 分钟,这样会更加高效而且省电 |
| | | // locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() { |
| | | // @Override |
| | | // public void onLocationChanged(@NonNull Location location) { |
| | | // // 当位置发生变化时调用此方法 |
| | | // double latitude = location.getLatitude(); // 获取纬度 |
| | | // double longitude = location.getLongitude(); // 获取经度 |
| | | // |
| | | // HdlLogLogic.print("纬度--->" + latitude, true); |
| | | // HdlLogLogic.print("经度--->" + longitude, true); |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 端口冲突 |
| | | */ |
| | | private void portConflictDialog() { |
| | | if (!HDLUdpConnect.getInstance().isBindSuccess()) { |
| | | ConfirmationTipDialog dialog = new ConfirmationTipDialog(_mActivity); |
| | | dialog.show(); |
| | | dialog.setTitle(getString(R.string.loading_title_tip)); |
| | | dialog.setContent(getString(R.string.port_conflict)); |
| | | dialog.setConfirmation(getString(R.string.home_login_affirm)); |
| | | dialog.setYesOnclickListener(new ConfirmationCancelDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm() { |
| | | dialog.dismiss(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | } |