| | |
| | | |
| | | |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | import android.widget.Button; |
| | | import android.widget.EditText; |
| | | import android.widget.RelativeLayout; |
| | | import android.widget.TextView; |
| | | |
| | |
| | | * 调光模块,继电器模块控制页面 |
| | | */ |
| | | public class CtrlLightActivity extends BaseActivity { |
| | | /**Topbar*/ |
| | | /** |
| | | * Topbar |
| | | */ |
| | | private RelativeLayout topBarBack; |
| | | private TextView topBarTitle; |
| | | private Button lightBtn; |
| | | private Button lightBtn, brightnessBtn; |
| | | private EditText brightnessEt; |
| | | private TextView lightText; |
| | | private AppliancesInfo appliancesInfo; |
| | | private int lightState; |
| | |
| | | private void initView() { |
| | | lightBtn = findViewById(R.id.ctrlbtn); |
| | | lightText = findViewById(R.id.lightText); |
| | | brightnessBtn = findViewById(R.id.ctrl_brightness); |
| | | brightnessEt = findViewById(R.id.et_brightness); |
| | | |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | HDLCommand.lightCtrl(appliancesInfo, lightState); |
| | | HDLLog.Log("lightBtn: 设置亮度" + lightState); |
| | | // HDLCommand.lightCtrl(appliancesInfo,50); |
| | | HDLLog.Log("lightBtn: 开关灯" + lightState); |
| | | } |
| | | }); |
| | | brightnessBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | String brightnessStr = brightnessEt.getText().toString(); |
| | | if (TextUtils.isEmpty(brightnessStr)) { |
| | | showToast("设置的亮度不能为空"); |
| | | return; |
| | | } |
| | | HDLCommand.lightCtrl(appliancesInfo, Integer.parseInt(brightnessStr)); |
| | | HDLLog.Log("brightnessBtn: 设置亮度" + brightnessStr); |
| | | } |
| | | }); |
| | | } |
| | |
| | | case HDLApConfig.TYPE_LIGHT_MIX_DIMMER: |
| | | case HDLApConfig.TYPE_LIGHT_MIX_RELAY: |
| | | if (appliancesInfo.getCurState() != null) { |
| | | int curLightState = HDLUtlis.getIntegerByObject(appliancesInfo.getCurState()); |
| | | int curLightState = HDLUtlis.getIntegerByObject(appliancesInfo.getCurState()); |
| | | |
| | | lightText.setText("当前灯光亮度:" + curLightState); |
| | | lightBtn.setText("当前灯光亮度:" + curLightState); |
| | | if (curLightState == 100) { |
| | | lightState = 0; |
| | | } else { |
| | | |
| | | if (curLightState == 0) { |
| | | lightState = 100; |
| | | lightBtn.setText("开灯"); |
| | | } else { |
| | | lightState = 0; |
| | | lightBtn.setText("关灯"); |
| | | } |
| | | } else { |
| | | lightText.setText("未获取到灯光亮度"); |
| | |
| | | return; |
| | | } |
| | | int brightness = event.getLightCtrlBackInfo().getBrightness(); |
| | | lightState = brightness == 100 ? 0 : 100;//如果返回100重置状态为0,反之重置状态100 |
| | | lightBtn.setText("当前亮度 = " + brightness); |
| | | lightText.setText("当前亮度 = " + brightness); |
| | | |
| | | if (brightness == 0) { |
| | | lightState = 100; |
| | | lightBtn.setText("开灯"); |
| | | } else { |
| | | lightState = 0; |
| | | lightBtn.setText("关灯"); |
| | | } |
| | | |
| | | /*以下为灯光推送示例代码,可以识别哪个继电器,哪个调光灯,哪个回路,也可用作控制回馈。 |
| | | 按需求调用*/ |
| | | String remarks = event.getLightCtrlBackInfo().getRemarks();//获取返回的灯光备注。如果每个灯光回路备注都唯一,可以直接通过备注判断 |
| | |
| | | showToast("获取灯光状态失败,请重新再试"); |
| | | return; |
| | | } |
| | | int brightness = HDLUtlis.getIntegerByObject(event.getAppliancesInfo().getCurState()); |
| | | lightBtn.setText("亮度 = " + brightness); |
| | | int brightness = HDLUtlis.getIntegerByObject(event.getAppliancesInfo().getCurState()); |
| | | if (brightness == 0) { |
| | | lightState = 100; |
| | | lightBtn.setText("开灯"); |
| | | } else { |
| | | lightState = 0; |
| | | lightBtn.setText("关灯"); |
| | | } |
| | | lightText.setText("当前亮度 = " + brightness); |
| | | showToast("获取状态返回:亮度 = " + brightness); |
| | | showToast("获取状态返回:亮度 = " + brightness); |
| | | } |
| | | break; |
| | | default: |