fix bug 修改Json传递失败问题
This commit is contained in:
@@ -48,7 +48,7 @@ android {
|
||||
*/
|
||||
// buildConfigField("String", "SERVER_IP", "\"120.27.209.4\"")
|
||||
// buildConfigField("String", "SERVER_PORT", "\"56792\"")
|
||||
buildConfigField("String", "SERVER_IP", "\"127.0.0.1\"")
|
||||
buildConfigField("String", "SERVER_IP", "\"192.168.0.108\"")
|
||||
buildConfigField("String", "SERVER_PORT", "\"56792\"")
|
||||
/**
|
||||
* 门禁连接地址
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.ydd.sportfaceid;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.ContentLoadingProgressBar;
|
||||
import android.text.Html;
|
||||
@@ -20,7 +19,6 @@ import com.ydd.sportfaceid.config.SDAppConfig;
|
||||
import com.ydd.sportfaceid.event.QRCodeEvent;
|
||||
import com.ydd.sportfaceid.main.SDBaseActivity;
|
||||
import com.ydd.sportfaceid.netty.config.Constant;
|
||||
import com.ydd.sportfaceid.netty.message.DeviceType;
|
||||
import com.ydd.sportfaceid.service.ClientService;
|
||||
import com.ydd.sportfaceid.setting.SDSettingActivity;
|
||||
import com.ydd.sportfaceid.utils.DeviceIdUtil;
|
||||
@@ -155,17 +153,17 @@ public class MainActivity extends SDBaseActivity {
|
||||
break;
|
||||
|
||||
case R.id.btn_refresh:
|
||||
configView();
|
||||
refreshWebView();
|
||||
break;
|
||||
|
||||
case R.id.btn_last_day:
|
||||
current_date = TimeUtil.getSpecifiedDayAfter(current_date,1);
|
||||
configView();
|
||||
refreshWebView();
|
||||
break;
|
||||
|
||||
case R.id.btn_next_day:
|
||||
current_date = TimeUtil.getSpecifiedDayAfter(current_date,-1);
|
||||
configView();
|
||||
refreshWebView();
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -185,10 +183,10 @@ public class MainActivity extends SDBaseActivity {
|
||||
private void initQrIcon() {
|
||||
Integer venueId = SDAppConfig.getInstance().getVenueId();
|
||||
String deviceName = DeviceIdUtil.generateDeviceId(this);
|
||||
DeviceType deviceType = SDAppConfig.getInstance().getDeviceType();
|
||||
String deviceType = SDAppConfig.getInstance().getDeviceType();
|
||||
String qrCert = deviceName + Constant.QRCODE_WORD + venueId + Constant.QRCODE_WORD + deviceType;
|
||||
if (venueId != 0) {
|
||||
Bitmap qrImage = QRCodeUtil.createQRImage(qrCert, qrCodeIvEnter.getWidth(), qrCodeIvEnter.getHeight());
|
||||
if (venueId != null) {
|
||||
Bitmap qrImage = QRCodeUtil.createQRImage(qrCert, 100, 100);
|
||||
qrCodeIvEnter.setImageBitmap(qrImage);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.ydd.sportfaceid.netty.message.DeviceType;
|
||||
|
||||
public class SDAppConfig {
|
||||
|
||||
private static SDAppConfig config;
|
||||
@@ -20,7 +18,7 @@ public class SDAppConfig {
|
||||
* 场馆ID
|
||||
*/
|
||||
private Integer venueId;
|
||||
private DeviceType deviceType;
|
||||
private String deviceType;
|
||||
|
||||
private SDAppConfig() {
|
||||
}
|
||||
@@ -48,16 +46,16 @@ public class SDAppConfig {
|
||||
this.venueId = sp.getInt(STORE_VENUE, 0);
|
||||
String storeType = sp.getString(STORE_DEVICE_TYPE, "ENTER");
|
||||
if (!TextUtils.isEmpty(storeType)) {
|
||||
this.deviceType = DeviceType.valueOf(storeType);
|
||||
this.deviceType = storeType;
|
||||
}
|
||||
configSet(venueId, deviceType);
|
||||
}
|
||||
|
||||
public void configSet(Integer venueId, DeviceType deviceType) {
|
||||
public void configSet(Integer venueId, String deviceType) {
|
||||
this.venueId = venueId;
|
||||
this.deviceType = deviceType;
|
||||
spEditor.putInt(STORE_VENUE, venueId);
|
||||
spEditor.putString(STORE_DEVICE_TYPE, deviceType.name());
|
||||
spEditor.putString(STORE_DEVICE_TYPE, deviceType);
|
||||
spEditor.commit();
|
||||
}
|
||||
|
||||
@@ -69,11 +67,11 @@ public class SDAppConfig {
|
||||
this.venueId = venueId;
|
||||
}
|
||||
|
||||
public DeviceType getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setDeviceType(DeviceType deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import com.ydd.sportfaceid.config.SDAppConfig;
|
||||
import com.ydd.sportfaceid.netty.message.DeviceType;
|
||||
import com.ydd.sportfaceid.netty.message.HeartBeat;
|
||||
import com.ydd.sportfaceid.netty.message.MessageDTO;
|
||||
import com.ydd.sportfaceid.service.MessageService;
|
||||
@@ -87,7 +86,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
HeartBeat hb = new HeartBeat();
|
||||
hb.setDeviceName(DeviceIdUtil.generateDeviceId(mContext));
|
||||
hb.setVenueId(SDAppConfig.getInstance().getVenueId());
|
||||
hb.setEnterOrOut(SDAppConfig.getInstance().getDeviceType());
|
||||
hb.setDeviceType(SDAppConfig.getInstance().getDeviceType());
|
||||
return hb;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.ydd.sportfaceid.netty.message;
|
||||
|
||||
/**
|
||||
* 设备属性,控制入场还是控制出场
|
||||
*/
|
||||
public enum DeviceType {
|
||||
|
||||
ENTER(0,"进场"),
|
||||
OUT(1,"出场");
|
||||
private int code;
|
||||
private String name;
|
||||
|
||||
DeviceType(int code, String name) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class HeartBeat implements Serializable {
|
||||
private String deviceName; //设备号
|
||||
|
||||
@Expose
|
||||
private DeviceType EnterOrOut; //出入标志
|
||||
private String deviceType; //出入标志
|
||||
|
||||
public Integer getVenueId() {
|
||||
return venueId;
|
||||
@@ -38,11 +38,11 @@ public class HeartBeat implements Serializable {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public DeviceType getEnterOrOut() {
|
||||
return EnterOrOut;
|
||||
public String getDeviceType() {
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
public void setEnterOrOut(DeviceType enterOrOut) {
|
||||
EnterOrOut = enterOrOut;
|
||||
public void setDeviceType(String deviceType) {
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.ydd.sportfaceid.setting;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
@@ -13,25 +11,20 @@ import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ydd.sportfaceid.R;
|
||||
import com.ydd.sportfaceid.config.SDAppConfig;
|
||||
import com.ydd.sportfaceid.main.SDBaseActivity;
|
||||
import com.ydd.sportfaceid.netty.message.DeviceType;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import com.ydd.sportfaceid.utils.JsonMapper;
|
||||
import com.ydd.sportfaceid.utils.TimeUntil;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SDSettingActivity extends SDBaseActivity {
|
||||
public static final String TAG = "SDSettingActivity_TAG";
|
||||
@@ -46,14 +39,12 @@ public class SDSettingActivity extends SDBaseActivity {
|
||||
|
||||
List<VenueItem> resultList = null;
|
||||
|
||||
boolean init = false;
|
||||
|
||||
Handler handler = new Handler(){
|
||||
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
init = true;
|
||||
initSpinner();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,40 +55,37 @@ public class SDSettingActivity extends SDBaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sdsetting);
|
||||
ButterKnife.bind(this);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String url = "https://lmqhznn.goho.co/getVenueList";
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "setConfigError: ", e);
|
||||
showToast("网络异常,请稍候再试!");
|
||||
}
|
||||
if (!response.isSuccessful()) {
|
||||
}
|
||||
String result = null;
|
||||
try {
|
||||
result = response.body().string();
|
||||
System.out.println("result ================" + result);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
resultList = JsonMapper.fromJson(result,new TypeToken<List<VenueItem>>(){}.getType());
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
handler.sendMessage(message);
|
||||
new Thread(() -> {
|
||||
String url = "https://lmqhznn.goho.co/getVenueList";
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "setConfigError: ", e);
|
||||
//Can't toast on a thread that has not called Looper.prepare()
|
||||
// showToast("网络异常,请稍候再试!");
|
||||
}
|
||||
if (!response.isSuccessful()) {
|
||||
}
|
||||
String result = null;
|
||||
try {
|
||||
result = response.body().string();
|
||||
System.out.println("result ================" + result);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
resultList = JsonMapper.fromJson(result,new TypeToken<List<VenueItem>>(){}.getType());
|
||||
List<VenueItem> objectList = new Gson().fromJson(result, new TypeToken<List<VenueItem>>(){}.getType());
|
||||
System.out.println(resultList.get(0).getVenueId());
|
||||
System.out.println(objectList.get(0).getVenueId());
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
handler.sendMessage(message);
|
||||
}).start();
|
||||
while (init){
|
||||
initSpinner();
|
||||
init = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +124,7 @@ public class SDSettingActivity extends SDBaseActivity {
|
||||
}
|
||||
|
||||
String deviceTypeStr = (String) radioButton.getTag();
|
||||
DeviceType deviceType = DeviceType.valueOf(deviceTypeStr);
|
||||
String deviceType = deviceTypeStr;
|
||||
|
||||
SDAppConfig.getInstance().configSet(venueId, deviceType);
|
||||
showToast("设置成功!");
|
||||
@@ -177,14 +165,14 @@ public class SDSettingActivity extends SDBaseActivity {
|
||||
}
|
||||
});
|
||||
// TODO: wyb, 2020-07-29, 这里可以设置为当前场馆的index.
|
||||
int position = 0;
|
||||
for (VenueItem venueItem : resultList){
|
||||
if (spinnerValue.equals(venueItem.getVenueId())){
|
||||
break;
|
||||
}
|
||||
position ++ ;
|
||||
}
|
||||
venueCellView.setSelection(position, false);
|
||||
// int position = 0;
|
||||
// for (VenueItem venueItem : resultList){
|
||||
// if (spinnerValue.equals(venueItem.getVenueId())){
|
||||
// break;
|
||||
// }
|
||||
// position ++ ;
|
||||
// }
|
||||
// venueCellView.setSelection(position, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.ydd.sportfaceid.setting;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class VenueItem implements Serializable {
|
||||
@Expose
|
||||
private Integer venueId;
|
||||
@Expose
|
||||
private String venueName;
|
||||
|
||||
public VenueItem(Integer venueId, String venueName) {
|
||||
@@ -26,4 +30,9 @@ public class VenueItem implements Serializable {
|
||||
public void setVenueName(String venueName) {
|
||||
this.venueName = venueName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return venueId + "-" + venueName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/bg_color"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
@@ -14,5 +8,4 @@
|
||||
android:textStyle="bold"
|
||||
tools:text="测试场馆1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</LinearLayout>
|
||||
android:layout_height="match_parent"/>
|
||||
Reference in New Issue
Block a user