| | |
| | | import android.Manifest; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.os.Parcel; |
| | | import android.os.Parcelable; |
| | | import android.view.MotionEvent; |
| | | import android.view.View; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | | import com.hdl.sdk.link.core.bean.LinkResponse; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * 我的电站界面 |
| | | */ |
| | | public class MyPowerStationActivity extends CustomBaseActivity { |
| | | |
| | | |
| | | private ActivityMyPowerStationBinding viewBinding; |
| | | private int currentFragmentIndex = 0; |
| | | private int currentFragmentIndex = 1; |
| | | private EventListener allTopicsListener; |
| | | |
| | | |
| | | @Override |
| | |
| | | initView(); |
| | | //初始化界面监听器 |
| | | initEvent(); |
| | | //注册监听 |
| | | registerAllTopicsListener(); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | viewBinding.myPowerStationBottomIl1.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | currentFragmentIndex = 0; |
| | | bottomViewChangeOfStyle(); |
| | | } |
| | | }); |
| | | viewBinding.myPowerStationBottomIl2.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | currentFragmentIndex = 1; |
| | | bottomViewChangeOfStyle(); |
| | | } |
| | | }); |
| | | viewBinding.myMessageBottomIl2.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | currentFragmentIndex = 2; |
| | | bottomViewChangeOfStyle(); |
| | | } |
| | | }); |
| | | viewBinding.myMeBottomIl3.clickTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | currentFragmentIndex = 3; |
| | | bottomViewChangeOfStyle(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack(); |
| | | //移除监听 |
| | | HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setText(R.string.my_power_station_电站); |
| | | viewBinding.myPowerStationBottomIl2.titleTv.setText(R.string.my_power_station_我的); |
| | | viewBinding.myMessageBottomIl2.titleTv.setText(R.string.message_消息); |
| | | viewBinding.myMeBottomIl3.titleTv.setText(R.string.my_power_station_我的); |
| | | this.bottomViewChangeOfStyle(); |
| | | |
| | | } |
| | | |
| | | private void bottomViewChangeOfStyle() { |
| | | if (this.currentFragmentIndex == 0) { |
| | | if (this.currentFragmentIndex == 1) { |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.VISIBLE); |
| | | viewBinding.myPowerStationFcv2.setVisibility(View.GONE); |
| | | viewBinding.myMessageFcv2.setVisibility(View.GONE); |
| | | viewBinding.myMeFcv3.setVisibility(View.GONE); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | viewBinding.myPowerStationBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme)); |
| | | viewBinding.myPowerStationBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else { |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else if (this.currentFragmentIndex == 2) { |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.GONE); |
| | | viewBinding.myPowerStationFcv2.setVisibility(View.VISIBLE); |
| | | viewBinding.myMessageFcv2.setVisibility(View.VISIBLE); |
| | | viewBinding.myMeFcv3.setVisibility(View.GONE); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myPowerStationBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedme)); |
| | | viewBinding.myPowerStationBottomIl2.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | |
| | | |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_select)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedme)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | } else if (this.currentFragmentIndex == 3) { |
| | | viewBinding.myPowerStationFcv1.setVisibility(View.GONE); |
| | | viewBinding.myMessageFcv2.setVisibility(View.GONE); |
| | | viewBinding.myMeFcv3.setVisibility(View.VISIBLE); |
| | | viewBinding.myPowerStationBottomIl1.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.unselectedpowerstation)); |
| | | viewBinding.myPowerStationBottomIl1.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMessageBottomIl2.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.message_unselected)); |
| | | viewBinding.myMessageBottomIl2.titleTv.setTextColor(getColor(R.color.text_65000000)); |
| | | viewBinding.myMeBottomIl3.iconIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.selectedme)); |
| | | viewBinding.myMeBottomIl3.titleTv.setTextColor(getColor(R.color.text_90000000)); |
| | | } |
| | | } |
| | | |
| | | |
| | | public void requestPermissions() { |
| | | String[] ary = PermissionUtils.checkPermission(_mActivity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 注册所有主题数据的监听 |
| | | */ |
| | | private void registerAllTopicsListener() { |
| | | allTopicsListener = new EventListener() { |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | if (msg instanceof LinkResponse) { |
| | | LinkResponse response = (LinkResponse) msg; |
| | | if (response.getTopic() == null) { |
| | | return; |
| | | } |
| | | HdlLogLogic.print("监听到的数据===========" + new Gson().toJson(response)); |
| | | // if (response.getTopic().endsWith("custom/native/inverter/up")) { |
| | | HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | uniCallBackBaseBean.setType(response.getTopic()); |
| | | uniCallBackBaseBean.setData(response.getData()); |
| | | HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); |
| | | // } |
| | | |
| | | } |
| | | } |
| | | }; |
| | | HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | |
| | | } |