iFish7/iFish7/src/main/java/com/ifish/activity/MainSixControlActivity.java

953 lines
37 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ifish.activity;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ifish.basebean.BaseBean;
import com.ifish.basebean.DeleteDevice;
import com.ifish.basebean.Device;
import com.ifish.basebean.ErrorReceiveObj;
import com.ifish.basebean.ErrorReceiveToast;
import com.ifish.basebean.ErrorSendObj;
import com.ifish.basebean.ErrorSendTimeSetting;
import com.ifish.basebean.ErrorSendToast;
import com.ifish.basebean.EventBean;
import com.ifish.basebean.JpushDeleteDeviceMac;
import com.ifish.basebean.RenameDevice;
import com.ifish.basebean.ShareDevice;
import com.ifish.basebean.UnBindDevice;
import com.ifish.baseclass.BaseGradeActivity;
import com.ifish.tcp.BackInfoModelSixXunDuo;
import com.ifish.tcp.TcpReceiveThread;
import com.ifish.tcp.TcpSendThread;
import com.ifish.utils.AnimationUtil;
import com.ifish.utils.Commons;
import com.ifish.utils.HttpListener;
import com.ifish.utils.HttpManager;
import com.ifish.utils.L;
import com.ifish.utils.SPUtil;
import com.ifish.utils.ToastUtil;
import com.ifish.view.PopWindowDevice_EventBus;
import com.ifish.view.SelectorImageView;
import com.ifish.view.SwipeRefreshLayout;
import com.ifish.wheelview.adapter.ArrayWheelAdapter;
import com.ifish.wheelview.view.WheelView;
import com.squareup.picasso.Picasso;
import java.net.Socket;
import java.util.List;
import de.greenrobot.event.EventBus;
import static com.ifish.activity.MainTabActivity.DeviceOnLine;
/**
* @ClassName: MainSixControlActivity
* @Description: 六控询多页面
* @author Jacky dada
* @date 2016年10月31日 17:04:10
*/
public class MainSixControlActivity extends BaseGradeActivity implements SwipeRefreshLayout.OnRefreshListener {
private SPUtil sp;
private String mac = "";
private boolean isToast = true,rl_setting_clickble=true,rl_center_clickble=true;
private boolean isWIFI = false,isFirstAPP=false,isWaterDialog=false;
private CountDownTimer WifiChangeTimer,RefreshTimer,LoadingTimer,TcpTimer;
private SwipeRefreshLayout sw;
private int position=0;
private ProgressBar mypro;
private SelectorImageView iv_1,iv_2,iv_3,iv_4,iv_5,iv_6;
private ImageView iv_left;
private TextView tv_left,tv_watertemp;
private BackInfoModelSixXunDuo backQueryObjSixXunDuo;
private Dialog waterTempDialog;
private HttpManager hm=HttpManager.getInstance();
private ImageView title_img_right;
private TextView tv_1,tv_2,tv_3,tv_4,tv_5,tv_6;
private ImageView iv_img;
private Device deviceBean;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.six_control_xunduo_activity);
deviceBean = (Device) getIntent().getSerializableExtra("device");
init();
initView();
initListener();
L.i( "---3-------------onCreate"+HttpManager.Store_URL+Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getLogo());
ReviewBrand();
LoginDevice();
}
public void onEventMainThread(BackInfoModelSixXunDuo event) {
DeviceOnLine=true;
// stopLoadingTimer();
stopRefreshTimer();
dismissProgressDialog();
dismissProgressDialogCancelble();
mypro.setVisibility(View.GONE);
backQueryObjSixXunDuo=event;
resetIVFlag();
stopTimer();
rl_setting_clickble=true;
sw.setRefreshing(false);
Commons.is_ShowSpecial=true;
byte string1 = event.getOnoff1();
byte string2 = event.getOnoff2();
byte string3 = event.getOnoff3();
byte string4 = event.getOnoff4();
byte string5 = event.getOnoff5();
byte string6 = event.getHeatStatus();//加热棒
tv_watertemp.setText(""+(int)event.getWendu()/10);
if (isWaterDialog) {
if (waterTempDialog!=null) {
waterTempDialog.dismiss();
}
isWaterDialog=false;
}
if (Byte.toString(string1).equals(Commons.FishKey.On)) {//气泵
iv_1.toggle(true);
} else {
iv_1.toggle(false);
}
if (Byte.toString(string2).equals(Commons.FishKey.On)) {//灯1
iv_2.toggle(true);
} else {
iv_2.toggle(false);
}
if (Byte.toString(string3).equals(Commons.FishKey.On)) {//灯2
iv_3.toggle(true);
} else {
iv_3.toggle(false);
}
if (Byte.toString(string4).equals(Commons.FishKey.On)) {//护理灯
iv_4.toggle(true);
} else {
iv_4.toggle(false);
}
if (Byte.toString(string5).equals(Commons.FishKey.On)) {//水泵
iv_5.toggle(true);
} else {
iv_5.toggle(false);
}
if (Byte.toString(string6).equals(Commons.FishKey.On)) {//加热棒
iv_6.toggle(true);
} else {
iv_6.toggle(false);
}
}
//接收到发送方出错的指令
public void onEventMainThread(ErrorSendObj event) {
L.i("===========发送方异常=============");
errorDevice();
}
//接收到接受方出错的指令
public void onEventMainThread(ErrorReceiveObj event) {
L.i("===========接收方异常=============");
errorDevice();
}
//接收到发送方出错的吐司
public void onEventMainThread(ErrorSendToast event) {
errorDevice();
}
//接收到接受方出错的吐司
public void onEventMainThread(ErrorReceiveToast event) {
errorDevice();
}
private void errorDevice(){
closeSoket();
DeviceOnLine=false;
Commons.IS_EventBus=true;
sw.setRefreshing(false);
mypro.setVisibility(View.GONE);
EventBus.getDefault().post(new ErrorSendTimeSetting());//提示设置界面已离线
L.i("===========离线=============");
}
//接收登录返回的指令
public void onEventMainThread(Boolean event) {
stopTimer();
resetIVFlag();
isWaterDialog=false;
mypro.setVisibility(View.GONE);
dismissProgressDialog();
if (event) {
checkDevice();
DeviceOnLine=true;
}else{
stopRefreshTimer();
// stopLoadingTimer();
dismissProgressDialogCancelble();
OffLineDevice();
}
}
private void OffLineDevice(){//设备离线的处理
DeviceOnLine=false;
rl_setting_clickble=true;
sw.setRefreshing(false);
mypro.setVisibility(View.GONE);
Commons.IS_EventBus=true;
EventBus.getDefault().post(new ErrorSendTimeSetting());//提示设置界面已离线
}
//发送控制设备开灯的指令
private void OnDevice(final int timer_number){
new Thread() {
@Override
public void run() {
super.run();
MainTabActivity.spmap.put(Commons.FishKey.timer_number, timer_number);
MainTabActivity.map.put(Commons.FishKey.Key, Commons.FishKey.On);//开灯
MainTabActivity.map.put(Commons.FishKey.Mac,mac);
TcpSendThread ts3 = new TcpSendThread(MainTabActivity.socket,MainTabActivity.map,MainTabActivity.spmap);
Thread thread3 = new Thread(ts3);
thread3.start();
}
}.start();
}
//发送控制设备关灯的指令
private void OFFDevice(final int timer_number){
new Thread() {
@Override
public void run() {
super.run();
MainTabActivity.spmap.put(Commons.FishKey.timer_number, timer_number);
MainTabActivity.map.put(Commons.FishKey.Key, Commons.FishKey.Off);//开灯
MainTabActivity.map.put(Commons.FishKey.Mac,mac);
TcpSendThread ts3 = new TcpSendThread(MainTabActivity.socket,MainTabActivity.map,MainTabActivity.spmap);
Thread thread3 = new Thread(ts3);
thread3.start();
}
}.start();
}
//设置加热棒温度
private void setHotWater(final String hot_water_temp){
new Thread() {
@Override
public void run() {
super.run();
MainTabActivity.map.put(Commons.FishKey.Key, Commons.FishKey.HotWaterTemp);
MainTabActivity.map.put(Commons.FishKey.hot_water_temp,hot_water_temp);
MainTabActivity.map.put(Commons.FishKey.Mac,mac);
TcpSendThread ts3 = new TcpSendThread(MainTabActivity.socket,MainTabActivity.map);
Thread thread3 = new Thread(ts3);
thread3.start();
}
}.start();
}
//点击灯后的倒计时
private void startTimer(){
rl_setting_clickble=false;
if (TcpTimer==null) {
TcpTimer=new CountDownTimer(4000,600) {//倒数4秒 没有反应则判断TCP指令失效
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {//倒计时结束
resetIVFlag();
isWaterDialog=false;
mypro.setVisibility(View.GONE);
dismissProgressDialog();
ToastUtil.showSpecial(MainSixControlActivity.this, Commons.Text.Repost);
}
};
}
TcpTimer.start();
}
private void stopTimer(){
if (TcpTimer!=null) {
TcpTimer.cancel();
}
}
//重置三个按钮所有状态
private void resetIVFlag(){
rl_center_clickble=true;
rl_setting_clickble=true;
}
private void initView() {
sw = findMyViewById(R.id.sw);
iv_img=findMyViewById(R.id.iv_img);
Picasso.with(MainSixControlActivity.this).load(R.drawable.six_control_xunduo_bg).into(iv_img);
mypro = (ProgressBar) findViewById(R.id.mypro);
iv_1 = (SelectorImageView) findViewById(R.id.iv_1);
iv_2 = (SelectorImageView) findViewById(R.id.iv_2);
iv_3 = (SelectorImageView) findViewById(R.id.iv_3);
iv_4 = (SelectorImageView) findViewById(R.id.iv_4);
iv_5 = (SelectorImageView) findViewById(R.id.iv_5);
iv_6 = (SelectorImageView) findViewById(R.id.iv_6);
iv_left = (ImageView) findViewById(R.id.iv_left);
tv_left = (TextView) findViewById(R.id.tv_left);
tv_watertemp = (TextView) findViewById(R.id.tv_watertemp);
title_img_right = (ImageView) findViewById(R.id.title_img_right);
tv_1=findMyViewById(R.id.tv_1);
tv_2=findMyViewById(R.id.tv_2);
tv_3=findMyViewById(R.id.tv_3);
tv_4=findMyViewById(R.id.tv_4);
tv_5=findMyViewById(R.id.tv_5);
tv_6=findMyViewById(R.id.tv_6);
}
private void initListener() {
sw.setOnRefreshListener(this);
iv_1.setOnClickListener(this);
iv_2.setOnClickListener(this);
iv_3.setOnClickListener(this);
iv_4.setOnClickListener(this);
iv_5.setOnClickListener(this);
iv_6.setOnClickListener(this);
iv_left.setOnClickListener(this);
tv_left.setOnClickListener(this);
title_img_right.setOnClickListener(this);
findViewById(R.id.iv_right).setOnClickListener(this);
findViewById(R.id.tv_right).setOnClickListener(this);
}
private void ReviewBrand() {
try {//展示厂家
if (Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList()!=null) {//厂家为空则展示默认的鱼影
Picasso.with(MainSixControlActivity.this)
.load(HttpManager.Store_URL+Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0))
.getVenderList().getLogo()).error(R.drawable.ifish_logo_default)
.placeholder(getDrawable(R.drawable.ifish_logo_default))
.into(iv_left);
String brandName = Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getBrandName();
if (!TextUtils.isEmpty(brandName)){
tv_left.setText(brandName);
}
L.i("厂家Logo="+HttpManager.Store_URL+Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getLogo());
}
} catch (Exception e) {
}
}
@Override
protected void onResume() {
super.onResume();
try {
Commons.IS_EventBus=true;
if (isFirstAPP) {
if (DeviceOnLine) {
checkDevice();
}else{
//设备已离线,登录设备
LoginDevice();
}
}
isFirstAPP=true;
} catch (Exception e) {
}
getLocalIconName();
}
/**
* 获取本地图标名字
*/
public void getLocalIconName(){
String locatText=sp.getString(mac+Commons.LoginSPKey.ICONNAME);
//本地集合json字符串不为空才能进行转化
if(!TextUtils.isEmpty(locatText)){
List<String> locatTextList=null;
try {
locatTextList = new Gson().fromJson(locatText, new TypeToken<List<String>>(){}.getType());
if (locatTextList != null&&locatTextList.size()==6) {
if(!TextUtils.isEmpty(locatTextList.get(0))){
tv_1.setText(locatTextList.get(0));
}
if(!TextUtils.isEmpty(locatTextList.get(1))){
tv_2.setText(locatTextList.get(1));
}
if(!TextUtils.isEmpty(locatTextList.get(2))){
tv_3.setText(locatTextList.get(2));
}
if(!TextUtils.isEmpty(locatTextList.get(3))){
tv_4.setText(locatTextList.get(3));
}
if(!TextUtils.isEmpty(locatTextList.get(4))){
tv_5.setText(locatTextList.get(4));
}
if(!TextUtils.isEmpty(locatTextList.get(5))){
tv_6.setText(locatTextList.get(5));
}
}
} catch (Exception e) {
}
}
}
public void onEventMainThread(DeleteDevice event) {//删除鱼缸
delDevice();
}
private void delDevice() {
for (int i = 0; i < Commons.DEVICE.size(); i++) {
if (mac.equals(Commons.DEVICE.get(i).getMacAddress())) {
position=i;
break;
}
}
AlertDialog.Builder dialog = new AlertDialog.Builder(MainSixControlActivity.this,AlertDialog.THEME_HOLO_LIGHT);
dialog.setMessage("确认删除设备?");
dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
showProgressDialog();
try {
hm.deleteDeviceUser(new HttpListener<BaseBean<Device>>() {
private int result;
@Override
public void success(BaseBean<Device> baseBean) {
result = baseBean.result;
}
@Override
public void finish() {
UIhandler.sendEmptyMessage(result);
}
@Override
public void error(Exception e, String msg) {
result= Commons.NetWork.ERROR;
}
}, Commons.DEVICE.get(position).getDeviceId(), Commons.USER.getUserId());
} catch (Exception e) {
e.printStackTrace();
}
}
});
dialog.setNegativeButton("取消",null);
dialog.show();
}
public Handler UIhandler=new Handler(){
public void handleMessage(android.os.Message msg) {
dismissProgressDialog();
/**
* 1修改成功
0修改失败
-4请求验证失败请重新登陆
*/
switch (msg.what) {
case Commons.NetWork.Del:
case Commons.NetWork.Success:
for (int i = 0; i < Commons.DeviceCamera.size(); i++) {
if (Commons.DEVICE.get(position).getDeviceId().equals(Commons.DeviceCamera.get(i).deviceId)) {
Commons.DeviceCamera.remove(i);
break;//删除摄像头和鱼缸的关系
}
}
Commons.DEVICE.remove(position);
if (Commons.DEVICE.size()==0) {//当删除的是最后一个设备的时候,则回到解绑状态 隐藏聊天室
EventBus.getDefault().post(new UnBindDevice());
}else{
if (position<=Commons.DevicePosition) {
if (Commons.DevicePosition==0) {
sp.putInt(Commons.LoginSPKey.Position, Commons.DevicePosition);
}else{
Commons.DevicePosition=Commons.DevicePosition-1;
sp.putInt(Commons.LoginSPKey.Position, Commons.DevicePosition);
}
}
Commons.IS_CAMERA=false;
sp.putBoolean(Commons.LoginSPKey.IS_CAMERA, Commons.IS_CAMERA);
}
ToastUtil.show(MainSixControlActivity.this, "删除成功");
finish();
AnimationUtil.finishAnimation(MainSixControlActivity.this);
break;
case Commons.NetWork.Fail:
ToastUtil.show(MainSixControlActivity.this, "删除失败");
break;
case Commons.NetWork.ReLogin:
ToastUtil.show(MainSixControlActivity.this, "请求验证失败 请重新登陆");
Commons.clean();
startActivity(new Intent(MainSixControlActivity.this, LoadingActivity.class));
break;
case Commons.NetWork.ERROR:
ToastUtil.show(MainSixControlActivity.this, Commons.Text.ERROR);
break;
case Commons.NetWork.NotImplemented:
ToastUtil.show(MainSixControlActivity.this, Commons.Text.Unknown);
break;
default:
ToastUtil.show(MainSixControlActivity.this, Commons.Text.ServerException);
break;
}
}
};
// //接收绑定之后loading的指令
// public void onEventMainThread(ProgessObj event) {
// showProgressDialogCancelble();
// startLoadingTimer();
// }
public void onEventMainThread(EventBean eventBean){
if (eventBean!=null && EventBean.CHANGE_DEVICE_NAME.equals(eventBean.name)){
setTitle(eventBean.value);
}
}
private void init() {
sp = SPUtil.getInstance(this);
EventBus.getDefault().register(this);
isToast = true;
isFirstAPP=false;
try {
if (deviceBean!=null){
mac = deviceBean.getMacAddress();
setAcTitle(deviceBean.getShowName(),mac);
}else {
initTitle(Commons.DEVICE.get(Commons.DevicePosition).getShowName());
mac = Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0))
.getMacAddress();
Commons.DevicePosition = sp.getInt(Commons.LoginSPKey.Position, 0);
}
} catch (Exception e) {
try {
mac = Commons.DEVICE.get(0).getMacAddress();
sp.putInt(Commons.LoginSPKey.Position, 0);
Commons.DevicePosition = 0;
} catch (Exception e1) {
}
}
IntentFilter mFilter = new IntentFilter();
mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);//让接受者只收到网络发生改变的广播
registerReceiver(mReceiver, mFilter);//注册广播接收者
new CountDownTimer(2000, 2000) {
public void onTick(long millisUntilFinished) {}
public void onFinish() {
isWIFI=true;
}
}.start();
}
private void StartWifiChangeTimer(){
showProgressDialogCancelble();
if (WifiChangeTimer==null) {
WifiChangeTimer=new CountDownTimer(2500,2000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
LoginDevice();
}
};
}
WifiChangeTimer.start();
}
private void StopWifiChangeTimer(){
if (WifiChangeTimer!=null) {
WifiChangeTimer.cancel();
}
}
/**
* 监听wifi 手机网络改变 重新登录
*/
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
private ConnectivityManager connectivityManager;
private NetworkInfo info;
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {//当网络发生改变 进入此判断
Log.d("mark", "网络状态已经改变");
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//得到连接管理者的里面的信息
info = connectivityManager.getActiveNetworkInfo();
if(info != null && info.isAvailable()) {//当信息不为空 且可用的时候进来
String name = info.getTypeName();
Log.d("mark", "当前网络名称:" + name);
if (isWIFI) {
StartWifiChangeTimer();
}
} else {
Log.d("mark", "没有可用网络");
}
}
}
};
@Override
public void onRefresh() {
RefreshDevice();
}
//刷新设备
private void RefreshDevice() {
rl_setting_clickble=false;
Commons.is_ShowSpecial=true;
LoginDevice();
}
//发送登录设备的指令
private void LoginDevice() {
startRefreshTimer();
mypro.setVisibility(View.VISIBLE);
new Thread() {
@Override
public void run() {
super.run();
try {
if (MainTabActivity.socket==null) {
MainTabActivity.socket = new Socket(HttpManager.FISH_URL, HttpManager.FISH_URL_PORT);
L.i("===============新建的soket"+MainTabActivity.socket.getLocalPort());
}
MainTabActivity.map.put(Commons.FishKey.Key, Commons.FishKey.Login);//登录
MainTabActivity.map.put(Commons.FishKey.Mac,mac);
TcpReceiveThread tr = new TcpReceiveThread(MainTabActivity.socket);
Thread thread1 = new Thread(tr);
thread1.start();
TcpSendThread ts = new TcpSendThread(MainTabActivity.socket,MainTabActivity.map);
Thread thread2 = new Thread(ts);
thread2.start();
} catch (Exception e) {
}
}
}.start();
}
//发送查询设备温度 定时器的指令
private void checkDevice(){
new Thread() {
@Override
public void run() {
super.run();
MainTabActivity.map.put(Commons.FishKey.Key, Commons.FishKey.Query);//查询
MainTabActivity.map.put(Commons.FishKey.Mac,mac);
TcpSendThread ts3 = new TcpSendThread(MainTabActivity.socket,MainTabActivity.map);
Thread thread3 = new Thread(ts3);
thread3.start();
}
}.start();
}
private void startRefreshTimer(){
if (RefreshTimer==null) {
RefreshTimer=new CountDownTimer(3500,2000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
mypro.setVisibility(View.GONE);
rl_setting_clickble=true;
sw.setRefreshing(false);
dismissProgressDialogCancelble();
try {
Commons.IS_EventBus=true;
if (isToast) {
ToastUtil.showSpecial(MainSixControlActivity.this, Commons.Text.Repost);
}
} catch (Exception e) {
}
}
};
}
RefreshTimer.start();
}
private void stopRefreshTimer(){
if (RefreshTimer!=null) {
RefreshTimer.cancel();
}
}
private void unregisterBroadCast(){
unregisterReceiver(mReceiver);//activity销毁的时候需要解除注册
}
public void closeSoket(){//关闭soket
if (MainTabActivity.socket!=null) {
try {
MainTabActivity.socket.close();
} catch (Exception e) {
}
}
MainTabActivity.socket=null;
}
private void stopAllTimer(){
// stopLoadingTimer();
StopWifiChangeTimer();
stopRefreshTimer();
}
// private void startLoadingTimer(){
// if (LoadingTimer==null) {
// LoadingTimer=new CountDownTimer(1500,2000) {
// @Override
// public void onTick(long millisUntilFinished) {
// }
// @Override
// public void onFinish() {
// Commons.is_ShowSpecial=true;
// onRefresh();
// }
// };
// }
// LoadingTimer.start();
// }
// private void stopLoadingTimer(){
// if (LoadingTimer!=null) {
// LoadingTimer.cancel();
// }
// }
//收到鱼缸解绑推送
public void onEventMainThread(JpushDeleteDeviceMac event) {
if (mac.equals(event.mac)) {
ToastUtil.show(MainSixControlActivity.this, "您已失去设备的控制权");
finish();
AnimationUtil.finishAnimation(this);
}
}
private void showOffWaterDialog(final int num) {
rl_center_clickble=true;
AlertDialog.Builder dialog=new AlertDialog.Builder(MainSixControlActivity.this);
dialog.setTitle("提示");
dialog.setCancelable(true);
dialog.setMessage("确认关闭水泵");
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {}
});
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
rl_center_clickble=false;
dialog.dismiss();
startTimer();
mypro.setVisibility(View.VISIBLE);
OFFDevice(num);
}
});
dialog.show();
}
private void showHeatWenduDialog() {
rl_center_clickble=true;
final String[] temps=new String[46];
for (int i = 0; i < 46; i++) {
temps[i]=i+5+"";
}
int currentItem=0;
final WheelView wv_water;
Button bt_submit;
waterTempDialog=new Dialog(MainSixControlActivity.this,R.style.HOLOMyDialogs);
waterTempDialog.setCancelable(true);
Window window=waterTempDialog.getWindow();
window.setContentView(R.layout.sethotwatertemp_dialog);
wv_water = (WheelView)window. findViewById(R.id.wv_water);
bt_submit = (Button)window. findViewById(R.id.bt_submit);
wv_water.setViewAdapter(new ArrayWheelAdapter<String>(MainSixControlActivity.this, temps));
waterTempDialog.show();
if (backQueryObjSixXunDuo!=null) {
String temp=backQueryObjSixXunDuo.getHeatWendu()/10+"";
for (int i = 0; i < temps.length; i++) {
if (temp.equals(temps[i])) {
currentItem=i;
break;
}
}
if (currentItem==0) {//如果默认设置第一个 就显示第一个温度 但是获取到的温度为空的话就显示20摄氏度
if ("5".equals(temp)) {
wv_water.setCurrentItem(currentItem);
}else{
wv_water.setCurrentItem(15);
}
}else{
wv_water.setCurrentItem(currentItem);
}
}else{
wv_water.setCurrentItem(15);
}
bt_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isWaterDialog=true;
showProgressDialog();
startTimer();
setHotWater(temps[wv_water.getCurrentItem()]);
}
});
}
@Override
public void onClick(View v) {//点击事件
Intent i=new Intent();
super.onClick(v);
switch (v.getId()) {
case R.id.iv_left://品牌展示
case R.id.tv_left://品牌展示
String brandIntroduce="";
String brandName="";
try {
brandIntroduce= Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getBrandIntroduce();
brandName= Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getVenderList().getBrandName();
} catch (Exception e) {
brandIntroduce=HttpManager.Vender_URL;
brandName="鱼影科技";
}
if (!brandIntroduce.contains("http")) {
brandIntroduce=HttpManager.Vender_URL;
}
i.putExtra(WebViewBrandActivity.URL, brandIntroduce);
i.putExtra(WebViewBrandActivity.WEBVIEWTITLE, brandName);
i.setClass(MainSixControlActivity.this, WebViewBrandActivity.class);
startActivity(i);
AnimationUtil.startAnimation(MainSixControlActivity.this);
break;
case R.id.iv_right://定时设置
case R.id.tv_right://定时设置
if (rl_setting_clickble) {
if (!DeviceOnLine) {
ToastUtil.show(MainSixControlActivity.this, Commons.Text.OFFDevice);
return;
}
i.putExtra("mac", mac);
i.putExtra("backQueryObjXunDuo", backQueryObjSixXunDuo);
i.setClass(MainSixControlActivity.this, TimeSettingThree.class);
startActivity(i);
AnimationUtil.startAnimation(MainSixControlActivity.this);
}
break;
case R.id.iv_1:
if (rl_center_clickble) {
mypro.setVisibility(View.VISIBLE);
rl_center_clickble=false;
startTimer();
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
LoginDevice();
}else{
if (!iv_1.isChecked()) {
OnDevice(1);
}else{
OFFDevice(1);
}
}
}
break;
case R.id.iv_2:
if (rl_center_clickble) {
mypro.setVisibility(View.VISIBLE);
rl_center_clickble=false;
startTimer();
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
LoginDevice();
}else{
if (!iv_2.isChecked()) {
OnDevice(2);
}else{
OFFDevice(2);
}
}
}
break;
case R.id.iv_3:
if (rl_center_clickble) {
mypro.setVisibility(View.VISIBLE);
rl_center_clickble=false;
startTimer();
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
LoginDevice();
}else{
if (!iv_3.isChecked()) {
OnDevice(3);
}else{
OFFDevice(3);
}
}
}
break;
case R.id.iv_4:
if (rl_center_clickble) {
mypro.setVisibility(View.VISIBLE);
rl_center_clickble=false;
startTimer();
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
LoginDevice();
}else{
if (!iv_4.isChecked()) {
OnDevice(4);
}else{
OFFDevice(4);
}
}
}
break;
case R.id.iv_5:
if (rl_center_clickble) {
rl_center_clickble=false;
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
startTimer();
LoginDevice();
}else{
if (!iv_5.isChecked()) {
mypro.setVisibility(View.VISIBLE);
startTimer();
OnDevice(5);
}else{
//关闭水泵需要二次确认
showOffWaterDialog(5);
}
}
}
break;
case R.id.iv_6:
if (rl_center_clickble) {
rl_center_clickble=false;
if (!DeviceOnLine) {//离线就发登录指令 否则开关灯
startTimer();
LoginDevice();
}else{
//设置加热棒温度对话框
showHeatWenduDialog();
}
}
break;
case R.id.title_img_right://打开右侧泡泡窗口
//是否展示“分享设备”
if (Commons.FishKey.On.equals(Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getIsMaster())) {
new PopWindowDevice_EventBus(MainSixControlActivity.this, true).showPopupWindow(title_img_right);
}else{
new PopWindowDevice_EventBus(MainSixControlActivity.this, false).showPopupWindow(title_img_right);
}
break;
}
}
public void onEventMainThread(ShareDevice event) {//分享鱼缸
Intent i=new Intent(this,ShareActivity.class);
i.putExtra("deviceId", Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)).getDeviceId());
startActivity(i);
AnimationUtil.startAnimation(this);
}
public void onEventMainThread(RenameDevice event) {//修改鱼缸名字
Intent i=new Intent(this,ChangeDeviceName_0F_Activity.class);
i.putExtra("device", Commons.DEVICE.get(sp.getInt(Commons.LoginSPKey.Position, 0)));
i.putExtra("position", sp.getInt(Commons.LoginSPKey.Position, 0));
startActivity(i);
AnimationUtil.startAnimation(this);
}
@Override
protected void onDestroy() {
isToast=false;
stopAllTimer();
unregisterBroadCast();
EventBus.getDefault().unregister(this);
closeSoket();
super.onDestroy();
}
}