AddMeshActivity.java
5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright 2017 wugian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qnbar.smc;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import com.qnbar.smc.service.TelinkLightService;
import com.telink.bluetooth.light.model.Mesh;
import com.xgimi.gimicinema.R;
import com.xgimi.gimicinema.application.FangTangApplication;
public final class AddMeshActivity extends Activity {
private ImageView backView;
private Button btnSave;
private FangTangApplication mApplication;
private OnClickListener clickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (v == backView) {
finish();
} else if (v == btnSave) {
saveMesh();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.activity_add_mesh);
this.mApplication = (FangTangApplication) this.getApplication();
this.backView = (ImageView) this
.findViewById(R.id.img_header_menu_left);
this.backView.setOnClickListener(this.clickListener);
this.btnSave = (Button) this.findViewById(R.id.btn_save);
this.btnSave.setOnClickListener(this.clickListener);
this.updateGUI();
TelinkLightService.Instance().idleMode(false);
}
private void updateGUI() {
if (this.mApplication.isEmptyMesh())
return;
EditText txtMeshName = (EditText) this.findViewById(R.id.txt_mesh_name);
EditText txtPassword = (EditText) this
.findViewById(R.id.txt_mesh_password);
EditText txtFactoryMeshName = (EditText) this
.findViewById(R.id.txt_factory_name);
EditText txtFactoryPassword = (EditText) this
.findViewById(R.id.txt_factory_password);
Mesh mesh = this.mApplication.getMesh();
txtMeshName.setText(mesh.name);
txtPassword.setText(mesh.password);
txtFactoryMeshName.setText(mesh.factoryName);
txtFactoryPassword.setText(mesh.factoryPassword);
}
@SuppressLint("ShowToast")
private void saveMesh() {
EditText txtMeshName = (EditText) this.findViewById(R.id.txt_mesh_name);
EditText txtPassword = (EditText) this
.findViewById(R.id.txt_mesh_password);
EditText txtFactoryMeshName = (EditText) this
.findViewById(R.id.txt_factory_name);
EditText txtFactoryPassword = (EditText) this
.findViewById(R.id.txt_factory_password);
//EditText otaText = (EditText) this.findViewById(R.id.ota_device);
Mesh mesh = this.mApplication.getMesh();
String newfactoryName = txtMeshName.getText().toString().trim();
String newfactoryPwd = txtPassword.getText().toString().trim();
String factoryName = txtFactoryMeshName.getText().toString().trim();
String factoryPwd = txtFactoryPassword.getText().toString().trim();
if (mesh == null)
mesh = new Mesh();
if (!factoryName.equals(mesh.factoryName) || !factoryPwd.equals(mesh.factoryPassword)) {
mesh.allocDeviceAddress = null;
mesh.devices.clear();
}
mesh.name = newfactoryName;
mesh.password = newfactoryPwd;
mesh.factoryName = factoryName;
mesh.factoryPassword = factoryPwd;
//mesh.otaDevice = otaText.getText().toString().trim();
if (mesh.saveOrUpdate()) {
this.mApplication.setMesh(mesh);
Toast.makeText(AddMeshActivity.this, "保存mesh成功", Toast.LENGTH_SHORT).show();
// int connectMeshAddress = mesh.getDeviceAddress();
//
// if (connectMeshAddress == -1) {
//// show("哎呦,网络里的灯泡太多了!目前可以有256灯");
// this.finish();
// return;
// }
//
// //更新参数
// LeUpdateParameters params = Parameters.createUpdateParameters();
// params.setOldMeshName(mesh.factoryName);
// params.setOldPassword(mesh.factoryPassword);
// params.setNewMeshName(mesh.name);
// params.setNewPassword(mesh.password);
//
//// DeviceInfo deviceInfo = event.getArgs();
//// deviceInfo.meshAddress = connectMeshAddress;
//// params.setUpdateDeviceList(deviceInfo);
// //params.set(Parameters.PARAM_DEVICE_LIST, deviceInfo);
// TelinkLightService.Instance().idleMode(true);
// //加灯
// TelinkLightService.Instance().updateMesh(params);
}
}
}