|
@@ -0,0 +1,124 @@
|
|
|
+package com.wisdom.hydroponics.ui.activity;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.wisdom.hydroponics.R;
|
|
|
+import com.wisdom.hydroponics.base.BaseActivity;
|
|
|
+import com.wisdom.hydroponics.bean.BindDeviceBean;
|
|
|
+import com.wisdom.hydroponics.bean.DeviceInfoBean;
|
|
|
+import com.wisdom.hydroponics.utils.SPUtil;
|
|
|
+import com.wisdom.hydroponics.utils.WQNetUtil;
|
|
|
+import com.wisdom.hydroponics.utils.WQUtils;
|
|
|
+
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import butterknife.BindView;
|
|
|
+import butterknife.ButterKnife;
|
|
|
+import butterknife.OnClick;
|
|
|
+
|
|
|
+public class EditNameActivity extends BaseActivity {
|
|
|
+ @BindView(R.id.iv_base_activity_back)
|
|
|
+ ImageView ivBaseActivityBack;
|
|
|
+ @BindView(R.id.tv_title_center)
|
|
|
+ TextView tvTitleCenter;
|
|
|
+ @BindView(R.id.tv_title_right)
|
|
|
+ TextView tvTitleRight;
|
|
|
+ @BindView(R.id.et_editName_text)
|
|
|
+ EditText etEditNameText;
|
|
|
+ @BindView(R.id.bt_editName_ok)
|
|
|
+ Button btEditNameOk;
|
|
|
+ private String mac;
|
|
|
+ private String ed_name;
|
|
|
+ private String edName;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int setView() {
|
|
|
+ return R.layout.activity_editname;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ ivBaseActivityBack.setVisibility(View.VISIBLE);
|
|
|
+ tvTitleCenter.setText("编辑设备名称");
|
|
|
+
|
|
|
+ Intent intent = getIntent();
|
|
|
+ mac = intent.getStringExtra("MAC");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @OnClick({R.id.iv_base_activity_back, R.id.bt_editName_ok})
|
|
|
+ public void onViewClicked(View view) {
|
|
|
+ switch (view.getId()) {
|
|
|
+ case R.id.iv_base_activity_back:
|
|
|
+ finish();
|
|
|
+ break;
|
|
|
+ case R.id.bt_editName_ok:
|
|
|
+ edName = etEditNameText.getText().toString().trim();
|
|
|
+ if (!TextUtils.isEmpty(edName)) {
|
|
|
+ setDataName(mac, edName);
|
|
|
+ } else {
|
|
|
+ WQUtils.showToast(this,"请输入设备名称");
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改名称
|
|
|
+ private void setDataName(String device_mac, String device_name) {
|
|
|
+ JSONObject jsonObj = new JSONObject();
|
|
|
+ try {
|
|
|
+ jsonObj.put("DeviceMac", device_mac);
|
|
|
+ jsonObj.put("DeviceName", device_name);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送网络请求
|
|
|
+ WQNetUtil.postHttp(this,jsonObj, SPUtil.getString(this, "URL") + "Device/UpdateDeviceNameByMac", handler);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ String json = (String) msg.obj;
|
|
|
+ Gson gson = new Gson();
|
|
|
+ BindDeviceBean bindDeviceBean = gson.fromJson(json, BindDeviceBean.class);
|
|
|
+ if (bindDeviceBean != null && bindDeviceBean.getReturnCode() == 200) {
|
|
|
+
|
|
|
+ showOK(bindDeviceBean.getMessage() + "");
|
|
|
+ } else {
|
|
|
+ WQUtils.tip(EditNameActivity.this, bindDeviceBean.getMessage() + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void showOK(String str) {
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
+ builder.setMessage(str);
|
|
|
+ builder.setTitle("提示");
|
|
|
+ builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ dialog.dismiss();
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.putExtra("Name",edName);
|
|
|
+ setResult(RESULT_OK,intent);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.create().show();
|
|
|
+ }
|
|
|
+}
|