兼容版本

This commit is contained in:
limqhz
2020-08-31 23:13:30 +08:00
parent c387c49140
commit 20c92eeea4
5 changed files with 29 additions and 33 deletions

View File

@@ -189,11 +189,11 @@ public class MainActivity extends SDBaseActivity {
private void initQrIcon() {
Integer venueId = SDAppConfig.getInstance().getVenueId();
String deviceName = DeviceIdUtil.newGenerateDeviceName(this);
String deviceName = SDAppConfig.getInstance().getDeviceName();
String deviceType = SDAppConfig.getInstance().getDeviceType();
String qrCert = deviceName + Constant.QRCODE_WORD + venueId + Constant.QRCODE_WORD + deviceType;
if (venueId != null) {
Bitmap qrImage = QRCodeUtil.createQRImage(qrCert, 100, 100);
Bitmap qrImage = QRCodeUtil.createQRImage(qrCert, 150, 150);
qrCodeIvEnter.setImageBitmap(qrImage);
}

View File

@@ -11,6 +11,7 @@ public class SDAppConfig {
private final String KEY_CACHE = "KEY_CACHE";
private final String STORE_VENUE = "STORE_VENUE";
private final String STORE_DEVICE_TYPE = "STORE_DEVICE_TYPE";
private final String STORE_DEVICE_NAME = "STORE_DEVICE_NAME";
private SharedPreferences sp;
private SharedPreferences.Editor spEditor;
@@ -19,6 +20,7 @@ public class SDAppConfig {
*/
private Integer venueId;
private String deviceType;
private String deviceName;
private SDAppConfig() {
}
@@ -45,17 +47,20 @@ public class SDAppConfig {
public void configData() {
this.venueId = sp.getInt(STORE_VENUE, 0);
String storeType = sp.getString(STORE_DEVICE_TYPE, "ENTER");
String storeName = sp.getString(STORE_DEVICE_NAME, "ERROR_DEVICE_NAME");
if (!TextUtils.isEmpty(storeType)) {
this.deviceType = storeType;
}
configSet(venueId, deviceType);
if (!TextUtils.isEmpty(storeName)) {
this.deviceName = storeName;
}
configSet();
}
public void configSet(Integer venueId, String deviceType) {
this.venueId = venueId;
this.deviceType = deviceType;
public void configSet() {
spEditor.putInt(STORE_VENUE, venueId);
spEditor.putString(STORE_DEVICE_TYPE, deviceType);
spEditor.putString(STORE_DEVICE_NAME, deviceName);
spEditor.commit();
}
@@ -74,4 +79,12 @@ public class SDAppConfig {
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
}

View File

@@ -87,7 +87,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
*/
private HeartBeat getHbMessage() {
HeartBeat hb = new HeartBeat();
hb.setDeviceName(DeviceIdUtil.newGenerateDeviceName(mContext));
hb.setDeviceName(SDAppConfig.getInstance().getDeviceName());
hb.setVenueId(SDAppConfig.getInstance().getVenueId());
hb.setDeviceType(SDAppConfig.getInstance().getDeviceType());
return hb;

View File

@@ -108,23 +108,4 @@ public class DeviceIdUtil {
return macSerial;
}
/**
* 兼容版本从SP中获取
* @param context
* @return
*/
static final public String newGenerateDeviceName(Context context) {
String deviceName = "";
if (sp == null) {
sp = context.getSharedPreferences(DEVICE_NAME, Context.MODE_PRIVATE);
spEditor = sp.edit();
deviceName = UUID.randomUUID().toString().replace("-", "");
spEditor.putString(DEVICE_NAME,deviceName);
spEditor.commit();
}else {
deviceName = sp.getString(DEVICE_NAME,"ERROR_DEVICE_NAME");
}
return deviceName;
}
}

View File

@@ -62,7 +62,7 @@
android:padding="15dp"
android:gravity="center"
android:lineSpacingExtra="10dp"
tools:text="测试测试测试\n测试测试测试\n测试测试"
tools:text="123"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
@@ -82,15 +82,16 @@
android:text="小程序二维码"
android:textColor="@color/black"
android:gravity="center"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/qr_code_iv_small"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:src="@mipmap/venue_sport"
android:layout_width="100dp"
android:layout_height="100dp"/>
android:layout_width="150dp"
android:layout_height="150dp"/>
</LinearLayout>
@@ -105,14 +106,15 @@
android:text="进场二维码"
android:textColor="@color/black"
android:gravity="center"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/qr_code_enter_loading"
android:layout_marginTop="15dp"
android:layout_width="100dp"
android:layout_height="100dp">
android:layout_marginTop="10dp"
android:layout_width="150dp"
android:layout_height="150dp">
<ImageView
android:id="@+id/qr_code_iv_enter"