Commit 3956d706 authored by UIUANG\Zsc's avatar UIUANG\Zsc

传称源码初版

parent a3bfb899
Pipeline #251 failed with stages
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$USER_HOME$/.gradle/wrapper/dists/gradle-6.1.1-all/cfmwm155h49vnt3hynmlrsdst/gradle-6.1.1" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/DigiTransfer" />
<option value="$PROJECT_DIR$/Transfer" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id 'com.android.library'
}
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
android.libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = "${project.name}_v" + android.defaultConfig.versionName + '_sdk.aar'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
task makeJar(type: Copy) {
//删除存在的
delete 'build/libs/myjar.jar'
//设置拷贝的文件
from('build/intermediates/aar_main_jar/release/')
//打进jar包后的文件目录
into('build/libs/')
//将classes.jar放入build/libs/目录下
//include ,exclude参数来设置过滤
//(我们只关心classes.jar这个文件)
include('classes.jar')
//重命名
rename ('classes.jar', 'myjar.jar')
}
makeJar.dependsOn(build)
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.wmdigit.digitransfer;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.uiuang.digitransfer.test", appContext.getPackageName());
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wmdigit.digitransfer">
</manifest>
\ No newline at end of file
package com.wmdigit.digitransfer;
import android.util.Log;
import com.wmdigit.digitransfer.exception.ErrCode;
import com.wmdigit.digitransfer.exception.ScalesApiException;
import com.wmdigit.digitransfer.handler.ObjectHandler;
import com.wmdigit.digitransfer.util.NetWorkUtils;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
public class DigiScaleTransfer {
private static DigiScaleTransfer instance;
private int addressFour;
private ObjectHandler scalesApiHandler;
private final String TAG = DigiScaleTransfer.this.getClass().getSimpleName();
private ServerSocket serverSocket;
public static DigiScaleTransfer getInstance(ObjectHandler scalesApiHandler) {
if (instance == null) {
instance = new DigiScaleTransfer(scalesApiHandler);
}
return instance;
}
private DigiScaleTransfer(ObjectHandler scalesApiHandler) {
this.scalesApiHandler = scalesApiHandler;
String hostAddress = null;
hostAddress = NetWorkUtils.getLocalIp();
int of = hostAddress.lastIndexOf(".");
String addressFourStr = hostAddress.substring(of + 1);
addressFour = Integer.parseInt(addressFourStr);
Log.i("AT", hostAddress);
}
public void init() {
ThreadCacheManager.getExecutorService().execute(new Runnable() {
@Override
public void run() {
try {
serverSocket = new ServerSocket(addressFour + 2000);
} catch (IOException var5) {
throw new ScalesApiException(ErrCode.PORT_OCCUPIED_EXCEPTION);
}
while (true) {
Socket socket = null;
try {
socket =serverSocket.accept();
int localPort = serverSocket.getLocalPort();
Log.i("port", "端口号" + localPort);
scalesApiHandler.setSocket(socket, addressFour);
ThreadCacheManager.getExecutorService().execute(scalesApiHandler);
// Thread thread = new Thread(this.scalesApiHandler);
// thread.start();
} catch (SocketTimeoutException var3) {
throw new ScalesApiException(ErrCode.OUT_TIME_EXCEPTION);
} catch (IOException var4) {
throw new ScalesApiException(ErrCode.RECEIVE_DATA_EXCEPTION);
}
}
}
});
}
public void destroy() {
try {
this.serverSocket.close();
} catch (IOException var2) {
var2.printStackTrace();
}
}
}
package com.wmdigit.digitransfer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadCacheManager {
static ExecutorService executorService;
public static ExecutorService getExecutorService() {
if (executorService == null) {
executorService = Executors.newCachedThreadPool();
}
return executorService;
}
}
package com.wmdigit.digitransfer.bean;
public class Commodity {
private Integer pluNo;
private String itemCode;
private String commodity1;
private String commodity2;
private String commodity3;
private String commodity4;
private double unitPrice;
private int weightingFlag;
private int usedByDate;
private int sellByDate;
private int packedByDate;
private String mgNo;
private String specialMessage1;
private String specialMessage2;
private String specialMessage3;
private String specialMessage4;
private String specialMessage5;
private String ingredient1;
private String ingredient2;
private String ingredient3;
private String ingredient4;
private String ingredient5;
private int barcodeFlag;
private int BarcodeFormat;
private String labelFormat1;
public Integer getPluNo() {
return pluNo;
}
public void setPluNo(Integer pluNo) {
this.pluNo = pluNo;
}
public String getItemCode() {
return itemCode;
}
public void setItemCode(String itemCode) {
this.itemCode = itemCode;
}
public String getCommodity1() {
return commodity1;
}
public void setCommodity1(String commodity1) {
this.commodity1 = commodity1;
}
public String getCommodity2() {
return commodity2;
}
public void setCommodity2(String commodity2) {
this.commodity2 = commodity2;
}
public String getCommodity3() {
return commodity3;
}
public void setCommodity3(String commodity3) {
this.commodity3 = commodity3;
}
public String getCommodity4() {
return commodity4;
}
public void setCommodity4(String commodity4) {
this.commodity4 = commodity4;
}
public double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(double unitPrice) {
this.unitPrice = unitPrice;
}
public int getWeightingFlag() {
return weightingFlag;
}
public void setWeightingFlag(int weightingFlag) {
this.weightingFlag = weightingFlag;
}
public int getUsedByDate() {
return usedByDate;
}
public void setUsedByDate(int usedByDate) {
this.usedByDate = usedByDate;
}
public int getSellByDate() {
return sellByDate;
}
public void setSellByDate(int sellByDate) {
this.sellByDate = sellByDate;
}
public int getPackedByDate() {
return packedByDate;
}
public void setPackedByDate(int packedByDate) {
this.packedByDate = packedByDate;
}
public String getMgNo() {
return mgNo;
}
public void setMgNo(String mgNo) {
this.mgNo = mgNo;
}
public String getSpecialMessage1() {
return specialMessage1;
}
public void setSpecialMessage1(String specialMessage1) {
this.specialMessage1 = specialMessage1;
}
public String getSpecialMessage2() {
return specialMessage2;
}
public void setSpecialMessage2(String specialMessage2) {
this.specialMessage2 = specialMessage2;
}
public String getSpecialMessage3() {
return specialMessage3;
}
public void setSpecialMessage3(String specialMessage3) {
this.specialMessage3 = specialMessage3;
}
public String getSpecialMessage4() {
return specialMessage4;
}
public void setSpecialMessage4(String specialMessage4) {
this.specialMessage4 = specialMessage4;
}
public String getSpecialMessage5() {
return specialMessage5;
}
public void setSpecialMessage5(String specialMessage5) {
this.specialMessage5 = specialMessage5;
}
public String getIngredient1() {
return ingredient1;
}
public void setIngredient1(String ingredient1) {
this.ingredient1 = ingredient1;
}
public String getIngredient2() {
return ingredient2;
}
public void setIngredient2(String ingredient2) {
this.ingredient2 = ingredient2;
}
public String getIngredient3() {
return ingredient3;
}
public void setIngredient3(String ingredient3) {
this.ingredient3 = ingredient3;
}
public String getIngredient4() {
return ingredient4;
}
public void setIngredient4(String ingredient4) {
this.ingredient4 = ingredient4;
}
public String getIngredient5() {
return ingredient5;
}
public void setIngredient5(String ingredient5) {
this.ingredient5 = ingredient5;
}
public int getBarcodeFlag() {
return barcodeFlag;
}
public void setBarcodeFlag(int barcodeFlag) {
this.barcodeFlag = barcodeFlag;
}
public int getBarcodeFormat() {
return BarcodeFormat;
}
public void setBarcodeFormat(int barcodeFormat) {
BarcodeFormat = barcodeFormat;
}
public String getLabelFormat1() {
return labelFormat1;
}
public void setLabelFormat1(String labelFormat1) {
this.labelFormat1 = labelFormat1;
}
@Override
public String toString() {
return "Commodity{" +
"pluNo=" + pluNo +
", itemCode='" + itemCode + '\'' +
", commodity1='" + commodity1 + '\'' +
", commodity2='" + commodity2 + '\'' +
", commodity3='" + commodity3 + '\'' +
", commodity4='" + commodity4 + '\'' +
", unitPrice=" + unitPrice +
", weightingFlag=" + weightingFlag +
", usedByDate=" + usedByDate +
", sellByDate=" + sellByDate +
", packedByDate=" + packedByDate +
", mgNo='" + mgNo + '\'' +
", specialMessage1='" + specialMessage1 + '\'' +
", specialMessage2='" + specialMessage2 + '\'' +
", specialMessage3='" + specialMessage3 + '\'' +
", specialMessage4='" + specialMessage4 + '\'' +
", specialMessage5='" + specialMessage5 + '\'' +
", ingredient1='" + ingredient1 + '\'' +
", ingredient2='" + ingredient2 + '\'' +
", ingredient3='" + ingredient3 + '\'' +
", ingredient4='" + ingredient4 + '\'' +
", ingredient5='" + ingredient5 + '\'' +
", barcodeFlag='" + barcodeFlag + '\'' +
", BarcodeFormat='" + BarcodeFormat + '\'' +
", labelFormat1='" + labelFormat1 + '\'' +
'}';
}
}
package com.wmdigit.digitransfer.exception;
public enum ErrCode {
PORT_OCCUPIED_EXCEPTION("0001", "端口被占"),
OUT_TIME_EXCEPTION("0002", "连接超时"),
RECEIVE_DATA_EXCEPTION("0003", "连接异常");
private String code;
private String msg;
private ErrCode(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return this.code;
}
public String getMsg() {
return this.msg;
}
}
package com.wmdigit.digitransfer.exception;
public class ScalesApiException extends RuntimeException {
private String errMsg;
private String errCode;
public ScalesApiException(ErrCode errCode) {
super(errCode.getMsg());
this.errCode = errCode.getCode();
this.errMsg = errCode.getMsg();
}
}
package com.wmdigit.digitransfer.handler;
import com.wmdigit.digitransfer.bean.Commodity;
import java.net.Socket;
public interface ObjectHandler extends Runnable{
void replyCommand(byte[] bytes);
void downPlu(Commodity commodity);
void setSocket(Socket socket,int addressFour);
}
package com.wmdigit.digitransfer.handler;
import com.wmdigit.digitransfer.bean.Commodity;
import com.wmdigit.digitransfer.util.ByteBufferUtils;
import com.wmdigit.digitransfer.util.Hex2BytesUtils;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public abstract class ScalesApiHandler implements ObjectHandler {
private Socket socket;
private int addressFour;
public ScalesApiHandler() {
}
public void run() {
try {
DataInputStream socketIn = new DataInputStream(socket.getInputStream());
byte[] mReceivedBuffer = new byte[1600];
int read = 0;
while ((read = socketIn.read(mReceivedBuffer)) != -1) {
if (socketIn.available() == 0) {
ByteBuffer byteBuffer = ByteBuffer.allocate(read);
byteBuffer.put(mReceivedBuffer, 0, read);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN).flip();
byte[] byteArray = byteBuffer.array();
System.out.println(Hex2BytesUtils.bytesToHexString2(byteArray));
switch (byteArray[0]) {
case (byte) 247:
String hexString = Hex2BytesUtils.bytesToHexString(byteArray);
String hex = Integer.toHexString(255 & addressFour);
String hex2;
if (addressFour > 153) {
hex2 = "F74F00000" + addressFour;
}else {
hex2 = "F74F000000" + hex;
}
System.out.println(hex2);
if (hexString.equals("F74F00000000")) {
String s1 = "00 00 00 " + hex + " 00 b6 00 00 00 00 00 01 00 00 00 01 00 00 00 00 16 01 04 01 00 20 10 01 24 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 03 " +
"77 5e e0 c0 a8 31 " +
hex + " 00 00 00 00 00 31 30 36 00 00 00 09 02 09 71 52 00 00 00 11 00 00 83 47 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
//c0 =192,a8 =168,
byte[] bytes1 = Hex2BytesUtils.string2Bytes(s1);
replyCommand(bytes1);
} else if (hexString.equals(hex2)) {
System.out.println(hex2);
byte[] bytes1 = new byte[1];
bytes1[0] = (byte) 226;
replyCommand(bytes1);
}
break;
case (byte) 241:
switch (byteArray[1]) {
case (byte) 37:
Commodity commodity = new Commodity();
byteBuffer.position(2);
int pluNo = ByteBufferUtils.bytesToInteger(byteBuffer, 4);
commodity.setPluNo(pluNo);
byteBuffer.position(13);
int weigh = ByteBufferUtils.bytesToInt(byteBuffer);
commodity.setWeightingFlag(weigh);
double unitPriceDouble = ByteBufferUtils.bytesToInteger(byteBuffer, 3);
double unitPrice = unitPriceDouble / 100;
commodity.setUnitPrice(unitPrice);
int barcodeFlag = ByteBufferUtils.bytesToInt(byteBuffer);
// System.out.println("标签格式样式:" + barcodeFlag);
commodity.setBarcodeFlag(barcodeFlag);
int barcodeFormat = ByteBufferUtils.bytesToInt(byteBuffer);
// System.out.println("条码格式BarcodeFormat:" + barcodeFormat);
commodity.setBarcodeFormat(barcodeFormat);
// byte[] bytes1 = subBytes(receivedBytes, 19, 1);
String labelFormat1 = ByteBufferUtils.bytesToString(byteBuffer,1);
commodity.setLabelFormat1(labelFormat1);
// System.out.println("条码前缀" + labelFormat1);
String itemCode = ByteBufferUtils.bytesToString(byteBuffer, 5).replaceAll("(0)+$", "");
// System.out.println("项目代码:" + itemCode);
commodity.setItemCode(itemCode);
byteBuffer.position(byteBuffer.position()+1);
String groupNo = String.valueOf(ByteBufferUtils.bytesToInteger(byteBuffer, 2));
// System.out.println("MGNo 主组:" + groupNo);
commodity.setMgNo(groupNo);
int usedByDate = ByteBufferUtils.bytesToInteger(byteBuffer, 2);
// System.out.println("售出日期:UsedByDate:" + usedByDate);
commodity.setUsedByDate(usedByDate);
int sellByDate = ByteBufferUtils.bytesToInteger(byteBuffer, 2);
// System.out.println("保质期:SellByDate:" + sellByDate);
commodity.setSellByDate(sellByDate);
int packedByDate = ByteBufferUtils.bytesToInteger(byteBuffer, 2);
// System.out.println("包装日期,PackedByDate:" + packedByDate);
commodity.setPackedByDate(packedByDate);
// System.out.println("包装日期,PackedByDate:" + packedByDate);
byteBuffer.position(48);
int traceabilityFlag = ByteBufferUtils.bytesToInt(byteBuffer);
int traceabilityNo = ByteBufferUtils.bytesToInteger(byteBuffer, 2);
System.out.println("追溯码开关" + traceabilityFlag + ",追溯码内容" + traceabilityNo);
commodity.setPackedByDate(packedByDate);
byteBuffer.position(152);
int commodity1Start = byteBuffer.get();
if (commodity1Start == 3) {
int commodity1Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("commodity1Font:" + commodity1Font);
int commodity1Length = ByteBufferUtils.bytesToInt(byteBuffer);
String commodity1 = ByteBufferUtils.bytesToHexString(byteBuffer, commodity1Length);
commodity.setCommodity1(commodity1);
int commodity2Start = byteBuffer.get();
if (commodity2Start == 13) {
int commodity2Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("commodity2Font:" + commodity2Font);
int commodity2Length = ByteBufferUtils.bytesToInt(byteBuffer);
String commodity2 = ByteBufferUtils.bytesToHexString(byteBuffer, commodity2Length);
commodity.setCommodity2(commodity2);
int commodity3Start = byteBuffer.get();
if (commodity3Start == 13) {
int commodity3Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("commodity3Font:" + commodity3Font);
int commodity3Length = ByteBufferUtils.bytesToInt(byteBuffer);
String commodity3 = ByteBufferUtils.bytesToHexString(byteBuffer, commodity3Length);
commodity.setCommodity3(commodity3);
byte commodity4Start = byteBuffer.get();
if (commodity4Start == 13) {
int commodity4Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("commodity4Font:" + commodity4Font);
int commodity4Length = ByteBufferUtils.bytesToInt(byteBuffer);
String commodity4 = ByteBufferUtils.bytesToHexString(byteBuffer, commodity4Length);
commodity.setCommodity4(commodity4);
byte ingredient1Start = byteBuffer.get();
if (ingredient1Start == 12) {
getIngredient(byteBuffer, commodity);
}
} else {
getIngredient(byteBuffer, commodity);
}
} else {
getIngredient(byteBuffer, commodity);
}
} else if (commodity1Start == 12) {
getIngredient(byteBuffer, commodity);
}
}
downPlu(commodity);
byte[] bytes3 = new byte[1];
bytes3[0] = 6;
replyCommand(bytes3);
break;
case (byte) 176:
byteBuffer.position(12);
int i = byteBuffer.array().length-1- 12;
byte[] bytes = new byte[i];
byteBuffer.get(bytes);
String s = new String(byteArray,"GBK");
System.out.println(s);
byte[] bytes4 = new byte[1];
bytes4[0] = (byte) 225;
replyCommand(bytes4);
break;
}
}
}
}
} catch (Exception var12) {
var12.printStackTrace();
} finally {
if (this.socket != null) {
try {
this.socket.close();
} catch (IOException var11) {
var11.printStackTrace();
}
}
}
}
private void getIngredient(ByteBuffer byteBuffer, Commodity commodity) throws UnsupportedEncodingException {
int Ingredient1Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("Ingredient1Font:" + Ingredient1Font);
int ingredient1Length = ByteBufferUtils.bytesToInt(byteBuffer);
String ingredient1 = ByteBufferUtils.bytesToHexString(byteBuffer, ingredient1Length);
commodity.setIngredient1(ingredient1);
if (byteBuffer.get() == 13) {
int Ingredient2Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("Ingredient2Font:" + Ingredient2Font);
int ingredient2Length = ByteBufferUtils.bytesToInt(byteBuffer);
String ingredient2 = ByteBufferUtils.bytesToHexString(byteBuffer, ingredient2Length);
commodity.setIngredient2(ingredient2);
if (byteBuffer.get() == 13) {
int Ingredient3Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("Ingredient3Font:" + Ingredient3Font);
int ingredient3Length = ByteBufferUtils.bytesToInt(byteBuffer);
String ingredient3 = ByteBufferUtils.bytesToHexString(byteBuffer, ingredient3Length);
commodity.setIngredient3(ingredient3);
if (byteBuffer.get() == 13) {
int Ingredient4Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("Ingredient4Font:" + Ingredient4Font);
int ingredient4Length = ByteBufferUtils.bytesToInt(byteBuffer);
String ingredient4 = ByteBufferUtils.bytesToHexString(byteBuffer, ingredient4Length);
commodity.setIngredient4(ingredient4);
if (byteBuffer.get() == 13) {
int Ingredient5Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("Ingredient5Font:" + Ingredient5Font);
int ingredient5Length = ByteBufferUtils.bytesToInt(byteBuffer);
String ingredient5 = ByteBufferUtils.bytesToHexString(byteBuffer, ingredient5Length);
commodity.setIngredient5(ingredient5);
if (byteBuffer.get() == 12) {
getSpecialMessage(byteBuffer, commodity);
}
} else {
getSpecialMessage(byteBuffer, commodity);
}
} else {
getSpecialMessage(byteBuffer, commodity);
}
} else {
getSpecialMessage(byteBuffer, commodity);
}
} else {
getSpecialMessage(byteBuffer, commodity);
}
}
private void getSpecialMessage(ByteBuffer byteBuffer, Commodity commodity) throws UnsupportedEncodingException {
int SpecialMessage1Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("SpecialMessage1Font:" + SpecialMessage1Font);
int specialMessage1Length = ByteBufferUtils.bytesToInt(byteBuffer);
String specialMessage1 = ByteBufferUtils.bytesToHexString(byteBuffer, specialMessage1Length);
commodity.setSpecialMessage1(specialMessage1);
if (byteBuffer.get() == 12) {
int SpecialMessage2Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("SpecialMessage2Font:" + SpecialMessage2Font);
int specialMessage2Length = ByteBufferUtils.bytesToInt(byteBuffer);
String specialMessage2 = ByteBufferUtils.bytesToHexString(byteBuffer, specialMessage2Length);
commodity.setSpecialMessage2(specialMessage2);
if (byteBuffer.get() == 12) {
int SpecialMessage3Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("SpecialMessage3Font:" + SpecialMessage3Font);
int specialMessage3Length = ByteBufferUtils.bytesToInt(byteBuffer);
String specialMessage3 = ByteBufferUtils.bytesToHexString(byteBuffer, specialMessage3Length);
commodity.setSpecialMessage3(specialMessage3);
if (byteBuffer.get() == 12) {
int SpecialMessage4Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("SpecialMessage4Font:" + SpecialMessage4Font);
int specialMessage4Length = ByteBufferUtils.bytesToInt(byteBuffer);
String specialMessage4 = ByteBufferUtils.bytesToHexString(byteBuffer, specialMessage4Length);
commodity.setSpecialMessage4(specialMessage4);
if (byteBuffer.get() == 12) {
int SpecialMessage5Font = ByteBufferUtils.bytesToInt(byteBuffer);
System.out.println("SpecialMessage5Font:" + SpecialMessage5Font);
int specialMessage5Length = ByteBufferUtils.bytesToInt(byteBuffer);
String specialMessage5 = ByteBufferUtils.bytesToHexString(byteBuffer, specialMessage5Length);
commodity.setSpecialMessage5(specialMessage5);
}
}
}
}
}
@Override
public void setSocket(Socket socket, int addressFour) {
this.socket = socket;
this.addressFour = addressFour;
}
@Override
public void replyCommand(byte[] bytes) {
OutputStream socketOut = null;
try {
socketOut = socket.getOutputStream();
socketOut.write(bytes);
socketOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.wmdigit.digitransfer.util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class ByteBufferUtils {
public static int bytesToInteger(ByteBuffer byteBuffer, int size) {
byte[] bytes = new byte[size];
byteBuffer.get(bytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; ++i) {
String hex = Integer.toHexString(255 & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
Integer integer = Integer.valueOf(sb.toString());
return integer;
}
public static String bytesToString(ByteBuffer byteBuffer, int size) {
byte[] bytes = new byte[size];
byteBuffer.get(bytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; ++i) {
String hex = Integer.toHexString(255 & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
public static int bytesToInt(ByteBuffer byteBuffer) {
byte[] bytes = new byte[1];
byteBuffer.get(bytes);
return bytes[0];
}
public static String bytesToHexString(ByteBuffer byteBuffer, int i) throws UnsupportedEncodingException {
byte[] bArr = new byte[i];
byteBuffer.get(bArr);
return new String(bArr, "GBK").replace("\u0000", "");
}
}
package com.wmdigit.digitransfer.util;
public class Hex2BytesUtils {
public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < bytes.length; ++i) {
String hex = Integer.toHexString(255 & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString().toUpperCase();
}
public static String bytesToHexString2(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < bytes.length; ++i) {
String hex = Integer.toHexString(255 & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex + " ");
}
return sb.toString().toUpperCase();
}
public static byte[] string2Bytes(String hexString) {
String[] split = hexString.split(" ");
byte[] bytes = new byte[split.length];
for (int i = 0; i < split.length; i++) {
bytes[i] = (byte) Integer.parseInt(split[i], 16);
}
return bytes;
}
}
package com.wmdigit.digitransfer.util;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class NetWorkUtils {
/**
* 获取本地IP列表
*
* @return
*/
public static String getLocalIp() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
NetworkInterface networkInterface;
Enumeration<InetAddress> inetAddresses;
InetAddress inetAddress;
String ip;
while (networkInterfaces.hasMoreElements()) {
networkInterface = networkInterfaces.nextElement();
inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
inetAddress = inetAddresses.nextElement();
if (inetAddress != null && inetAddress instanceof Inet4Address) { // IPV4
ip = inetAddress.getHostAddress();
if (!"127.0.0.1".equals(ip) && !"localhost".equals(ip)) {
return ip;
}
}
}
}
} catch (SocketException e) {
}
return null;
}
}
package com.wmdigit.digitransfer;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id 'com.android.library'
}
android {
compileSdkVersion 31
defaultConfig {
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.wmdigit.transfer;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.uiuang.transfer.test", appContext.getPackageName());
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wmdigit.transfer">
</manifest>
\ No newline at end of file
package com.wmdigit.transfer;
import android.util.Log;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ScaleTransfer {
private final String TAG = ScaleTransfer.this.getClass().getSimpleName();
private ServerSocket serverSocket;
private static class ScaleTransferHolder {
public static ScaleTransfer instance = new ScaleTransfer();
private ScaleTransferHolder() {
}
}
public static ScaleTransfer getInstance() {
return ScaleTransferHolder.instance;
}
public void startLoadPluData(ScaleTransferListener scaleTransferListener, int port) {
ThreadCacheManager.getExecutorService().execute(new Runnable() {
public final void run() {
String str = "Transfer";
try {
serverSocket = new ServerSocket(port);
Log.d(TAG, port + "");
Socket accept = null;
while (true) {
accept = serverSocket.accept();
System.out.println("New connection accepted " +
accept.getInetAddress() + ":" +accept.getPort());
Log.i(TAG, "服务开启");
if (scaleTransferListener != null) {
scaleTransferListener.onConnected();
}
ThreadCacheManager.getExecutorService().execute(new SocketHandler(accept, scaleTransferListener));
}
} catch (IOException e) {
if (scaleTransferListener != null) {
scaleTransferListener.onIOException(e.getLocalizedMessage());
}
StringBuilder sb = new StringBuilder();
sb.append("Exception listening port 3001.==");
sb.append(e.getLocalizedMessage());
Log.e(str, sb.toString());
} catch (Throwable th2) {
// r3.addSuppressed(th2);
}
}
});
}
public void destroy() {
try {
this.serverSocket.close();
} catch (IOException var2) {
var2.printStackTrace();
}
}
}
package com.wmdigit.transfer;
import com.wmdigit.transfer.domain.DataBean;
import java.util.List;
public interface ScaleTransferListener {
void onConnected();
void onDataReceived(String str);
void onException(String str);
void onIOException(String str);
void onStart(String str);
void pluList(List<DataBean> dataBeans);
}
package com.wmdigit.transfer;
import android.util.Log;
import com.wmdigit.transfer.domain.CommandHeader;
import com.wmdigit.transfer.domain.DataBean;
import com.wmdigit.transfer.wrapper.DataPackUtils;
import com.wmdigit.transfer.wrapper.DataPackWrapper;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.List;
public class SocketHandler implements Runnable{
private ScaleTransferListener listener;
private Socket socket;
public SocketHandler(Socket socket2, ScaleTransferListener scaleTransferListener) {
this.socket = socket2;
this.listener = scaleTransferListener;
}
public void run() {
DataPackUtils instance = DataPackUtils.getInstance();
try {
DataInputStream is = new DataInputStream(new BufferedInputStream(this.socket.getInputStream()));
byte[] bytes = new byte[1600];
boolean var4 = false;
int read;
while(-1 != (read = is.read(bytes))) {
if (is.available() == 0) {
String hexString = bytesToHexString(bytes);
DataPackWrapper parse = instance.parse(bytes, read);
instance.setOut(parse);
OutputStream outputStream = null;
try {
outputStream = this.socket.getOutputStream();
outputStream.write(parse.getOutBytes());
} catch (IOException var17) {
var17.printStackTrace();
}
outputStream.flush();
// List<DataBean> beanList = parse.getBeanList();
// CommandHeader inHeader = parse.getInHeader();
// Log.d("inHeader", inHeader.toString());
// this.listener.pluList(beanList);
}
}
} catch (IOException var18) {
var18.printStackTrace();
} finally {
if (this.socket != null) {
try {
this.socket.close();
} catch (IOException var16) {
var16.printStackTrace();
}
}
}
}
public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < bytes.length; ++i) {
// Log.d("TAG", bytes[i] + "");
String hex = Integer.toHexString(255 & bytes[i]).toUpperCase();
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
}
package com.wmdigit.transfer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadCacheManager {
static ExecutorService executorService;
public static ExecutorService getExecutorService() {
if (executorService == null) {
executorService = Executors.newCachedThreadPool();
}
return executorService;
}
}
package com.wmdigit.transfer.constant;
public enum ControlResponseEnum {
MASK_SCALE_TYPE_CTRL(4095),
OK(0),
FILE_NOT_CREATED(4096),
NO_FREE_RECORD(8192),
FILE_CORRUPT(12288),
NOT_FOUND(16384),
WRONG_KEY(20480),
DOUBLE_KEY(24576),
NETWORT_ERROR(28672),
DEVICE_BUSY(32768),
TIME_OUT(36864),
SCALE_TYPE_ERROR(45056),
BAD_PARAMETER(49152),
GENERAL_ERROR(53248),
UNDEFINED_COMMAND(57344),
UNPRATICAL(61440);
private int value;
private ControlResponseEnum(int i) {
this.value = i;
}
public static ControlResponseEnum fromValue(int i) {
ControlResponseEnum[] values;
for (ControlResponseEnum controlResponseEnum : values()) {
if (controlResponseEnum.value() == i) {
return controlResponseEnum;
}
}
return null;
}
public int value() {
return this.value;
}
}
package com.wmdigit.transfer.constant;
public enum ControlTypeEnum {
WRITE(0),
DELETE(1),
DELETE_ALL(8),
READ(2),
READ_GE(3),
READ_LE(4),
READ_GT(5),
READ_LT(6);
private int value;
private ControlTypeEnum(int i) {
this.value = i;
}
public static ControlTypeEnum fromValue(int i) {
ControlTypeEnum[] values;
for (ControlTypeEnum controlTypeEnum : values()) {
if (controlTypeEnum.value() == i) {
return controlTypeEnum;
}
}
return null;
}
public int value() {
return this.value;
}
}
package com.wmdigit.transfer.constant;
public enum DataTypeEnum {
PLU(207, 1207),
ACC(209, 1209);
private int hValue;
private int value;
private DataTypeEnum(int i, int i2) {
this.value = i;
this.hValue = i2;
}
public static DataTypeEnum fromValue(int i, ScaleTypeEnum scaleTypeEnum) {
DataTypeEnum[] values;
for (DataTypeEnum dataTypeEnum : values()) {
if (ScaleTypeEnum.HH00 == scaleTypeEnum) {
if (dataTypeEnum.hValue() == i) {
return dataTypeEnum;
}
} else if (dataTypeEnum.value() == i) {
return dataTypeEnum;
}
}
return null;
}
public int value() {
return this.value;
}
public int hValue() {
return this.hValue;
}
}
package com.wmdigit.transfer.constant;
public enum DateUnitEnum {
DAY(0, "day"),
DATE(1, "date");
private String unit;
private int value;
private DateUnitEnum(int i, String str) {
this.value = i;
this.unit = str;
}
public static DateUnitEnum fromValue(int i) {
DateUnitEnum[] values;
for (DateUnitEnum dateUnitEnum : values()) {
if (dateUnitEnum.value() == i) {
return dateUnitEnum;
}
}
return null;
}
public int value() {
return this.value;
}
public String unit() {
return this.unit;
}
}
package com.wmdigit.transfer.constant;
public enum FixedWeightUsageEnum {
FIXED_WEIGHT(0),
BY_COUNT_UNIT_DES(1);
private int value;
private FixedWeightUsageEnum(int i) {
this.value = i;
}
public static FixedWeightUsageEnum fromValue(int i) {
FixedWeightUsageEnum[] values;
for (FixedWeightUsageEnum fixedWeightUsageEnum : values()) {
if (fixedWeightUsageEnum.value() == i) {
return fixedWeightUsageEnum;
}
}
return null;
}
public int value() {
return this.value;
}
}
package com.wmdigit.transfer.constant;
public enum PrintDateFormatEnum {
YYMMDD(1, "YYMMDD"),
DDMMYY(4, "DDMMYY"),
MMDD(2, "MMDD"),
DAYS(3, "Days"),
MMDDYY(7, "MMDDYY");
private String format;
private int value;
private PrintDateFormatEnum(int i, String str) {
this.value = i;
this.format = str;
}
public static PrintDateFormatEnum fromValue(int i) {
PrintDateFormatEnum[] values;
for (PrintDateFormatEnum printDateFormatEnum : values()) {
if (printDateFormatEnum.value() == i) {
return printDateFormatEnum;
}
}
return null;
}
public int value() {
return this.value;
}
public String format() {
return this.format;
}
}
package com.wmdigit.transfer.constant;
public enum ScaleTypeEnum {
BCOM(120),
BPRO(100),
RL00(60),
HH00(222);
private int value;
private ScaleTypeEnum(int i) {
this.value = i;
}
public int value() {
return this.value;
}
}
package com.wmdigit.transfer.converter;
import com.wmdigit.transfer.domain.DomainBean;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public interface BeanConverter<T extends DomainBean> {
public static final String DEFAULT_ENCODING = "GBK";
public static final String UNICODE_ENCODING = "Unicode";
public final class CC {
public static int calcCrc16(byte[] bArr, int i, int i2) {
int i3 = 0;
while (i < i2) {
i3 ^= bArr[i] << 8;
for (int i4 = 0; i4 < 8; i4++) {
i3 = (32768 & i3) != 0 ? (i3 << 1) ^ 4129 : i3 << 1;
}
i++;
}
return i3;
}
public static boolean hasLength(String str) {
return str != null && !str.isEmpty();
}
public static String trimCharacter(String str, char c) {
if (!hasLength(str)) {
return str;
}
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && sb.charAt(0) == c) {
sb.deleteCharAt(0);
}
while (sb.length() > 0 && sb.charAt(sb.length() - 1) == c) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString().trim();
}
public static String bytesToText(ByteBuffer byteBuffer, int i) throws UnsupportedEncodingException {
byte[] bArr = new byte[i];
byteBuffer.get(bArr);
return trimCharacter(new String(bArr, BeanConverter.DEFAULT_ENCODING).replace("\u0000", ""), (char) 0);
}
public static String doubleBytesToText(ByteBuffer byteBuffer, int i) throws UnsupportedEncodingException {
ByteBuffer order = ByteBuffer.allocate(i * 2).order(ByteOrder.BIG_ENDIAN);
for (int i2 = 0; i2 < i; i2++) {
order.putShort(byteBuffer.getShort());
}
return trimCharacter(new String(order.array(), BeanConverter.UNICODE_ENCODING).replace("\u0000", ""), (char) 0);
}
}
ByteBuffer fromBean(T t);
T toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException;
T toDeleteBean(ByteBuffer byteBuffer);
}
package com.wmdigit.transfer.converter;
import com.wmdigit.transfer.constant.ControlTypeEnum;
import com.wmdigit.transfer.constant.DataTypeEnum;
import com.wmdigit.transfer.constant.ScaleTypeEnum;
import com.wmdigit.transfer.domain.CommandHeader;
import java.nio.ByteBuffer;
public class CommandHeaderConverter implements BeanConverter<CommandHeader> {
public ByteBuffer fromBean(CommandHeader commandHeader) {
return null;
}
public CommandHeader toBean(ByteBuffer byteBuffer) {
if (byteBuffer == null || byteBuffer.limit() < 15) {
return null;
}
CommandHeader commandHeader = new CommandHeader();
commandHeader.setStart(byteBuffer.get());
commandHeader.setTotalLength(byteBuffer.getShort());
commandHeader.setPageNum(byteBuffer.getShort());
commandHeader.setCompressed((commandHeader.getTotalLength() & Short.MIN_VALUE) != 0);
if (commandHeader.isCompressed()) {
return commandHeader;
}
commandHeader.setPageLength(byteBuffer.getShort());
commandHeader.setCmdrsp(byteBuffer.get());
commandHeader.setCommand(byteBuffer.getShort());
commandHeader.setControl(byteBuffer.getShort());
commandHeader.setDepartno(byteBuffer.getShort());
commandHeader.setDeviceno(byteBuffer.get());
short control = commandHeader.getControl();
commandHeader.setControlType(ControlTypeEnum.fromValue(control & 15));
int i = (control >> 4) & 255;
if (i == 120 || i == 130) {
commandHeader.setScaleType(ScaleTypeEnum.BCOM);
} else if (i >= 100 && i <= 110) {
commandHeader.setScaleType(ScaleTypeEnum.BPRO);
} else if (i == 0 || ((i >= 60 && i <= 68) || i == 255 || i == 15)) {
if (commandHeader.getDeviceno() == 1 && commandHeader.getPageLength() > 68 && commandHeader.getCommand() == 207) {
commandHeader.setScaleType(ScaleTypeEnum.BPRO);
} else if (commandHeader.getDeviceno() == 1 && commandHeader.getPageLength() > 604 && commandHeader.getCommand() == 209) {
commandHeader.setScaleType(ScaleTypeEnum.BPRO);
} else {
commandHeader.setScaleType(ScaleTypeEnum.RL00);
}
} else if (i == 222) {
commandHeader.setScaleType(ScaleTypeEnum.HH00);
}
commandHeader.setDataType(DataTypeEnum.fromValue(commandHeader.getCommand(), commandHeader.getScaleType()));
return commandHeader;
}
public CommandHeader toDeleteBean(ByteBuffer byteBuffer) {
throw new UnsupportedOperationException("Not implemented.");
}
}
package com.wmdigit.transfer.converter;
import android.util.Log;
import com.wmdigit.transfer.constant.DataTypeEnum;
import com.wmdigit.transfer.constant.ScaleTypeEnum;
import com.wmdigit.transfer.converter.bpro.AccBproConverter;
import com.wmdigit.transfer.converter.bpro.PluBproConverter;
import com.wmdigit.transfer.converter.hh.AccHhConverter;
import com.wmdigit.transfer.converter.hh.PluHhConverter;
import com.wmdigit.transfer.converter.rl00.AccRl00Converter;
import com.wmdigit.transfer.converter.rl00.PluRl00Converter;
import com.wmdigit.transfer.domain.DataBean;
public class ConverterFactory {
public static BeanConverter<? extends DataBean> create(ScaleTypeEnum scaleTypeEnum, DataTypeEnum dataTypeEnum) {
if (ScaleTypeEnum.BPRO == scaleTypeEnum || ScaleTypeEnum.BCOM == scaleTypeEnum) {
if (DataTypeEnum.PLU == dataTypeEnum) {
return new PluBproConverter();
}
if (DataTypeEnum.ACC == dataTypeEnum) {
return new AccBproConverter();
}
} else if (ScaleTypeEnum.RL00 == scaleTypeEnum) {
if (DataTypeEnum.PLU == dataTypeEnum) {
return new PluRl00Converter();
}
if (DataTypeEnum.ACC == dataTypeEnum) {
return new AccRl00Converter();
}
} else if (ScaleTypeEnum.HH00 == scaleTypeEnum) {
if (DataTypeEnum.PLU == dataTypeEnum) {
return new PluHhConverter();
}
if (DataTypeEnum.ACC == dataTypeEnum) {
return new AccHhConverter();
}
}
return null;
}
}
package com.wmdigit.transfer.converter.bpro;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Acc;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class AccBproConverter implements BeanConverter<Acc> {
public ByteBuffer fromBean(Acc acc) {
return null;
}
public Acc toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
Acc acc = new Acc();
acc.accNo = byteBuffer.getShort();
acc.groupNo = byteBuffer.get();
acc.depNo = byteBuffer.get();
String doubleBytesToText = CC.doubleBytesToText(byteBuffer, (byteBuffer.capacity() - byteBuffer.position()) / 2);
String substring = doubleBytesToText.substring(0, doubleBytesToText.length() - 1);
acc.content = substring;
acc.setAccContent(substring.split("\u001a"));
return acc;
}
public Acc toDeleteBean(ByteBuffer byteBuffer) {
return new Acc();
}
}
package com.wmdigit.transfer.converter.bpro;
import com.wmdigit.transfer.constant.FixedWeightUsageEnum;
import com.wmdigit.transfer.constant.PrintDateFormatEnum;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Plu;
import com.wmdigit.transfer.wrapper.DataPackUtils;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class PluBproConverter implements BeanConverter<Plu> {
public ByteBuffer fromBean(Plu plu) {
return null;
}
public Plu toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
Plu plu = new Plu();
plu.setPluNo(byteBuffer.getInt());
plu.setItemNo(CC.bytesToText(byteBuffer, 13));
byteBuffer.getShort();
plu.setDeptNo(byteBuffer.get());
plu.setNameTextA(CC.doubleBytesToText(byteBuffer, 28));
plu.setUnitPriceA(byteBuffer.getInt());
plu.setUnitPriceB(byteBuffer.getInt());
plu.setLabelNoA(byteBuffer.get());
plu.setLabelNoB(byteBuffer.get());
plu.setTareNoA(byteBuffer.get());
plu.setPriceRuleNo(byteBuffer.get());
byteBuffer.getInt();
if (DataPackUtils.getInstance().getFixedWeightUse() == FixedWeightUsageEnum.FIXED_WEIGHT) {
plu.setFixWeight(((double) byteBuffer.getInt()) / 10.0d);
} else {
plu.setPriceUnitDesA(CC.bytesToText(byteBuffer, 4));
plu.setPriceUnitDesB(plu.getPriceUnitDesA());
}
plu.setGroupNo(byteBuffer.getInt());
plu.setBarcodeNo(byteBuffer.getShort());
plu.setSafeHandingNo(byteBuffer.get());
plu.setGraphicNoA(String.valueOf(byteBuffer.get()));
byte b = byteBuffer.get();
byte b2 = byteBuffer.get();
byte b3 = byteBuffer.get();
byteBuffer.get();
plu.setPriceUnitA(b & 3);
plu.setPriceUnitB(plu.getPriceUnitA());
boolean z = true;
plu.setPriceChangeFlagA(((b >> 2) & 1) == 1);
plu.setPriceChangeFlagB(plu.isPriceChangeFlagA());
plu.setDiscountFlagA(((b >> 3) & 1) == 1);
plu.setDiscountFlagB(plu.isDiscountFlagA());
int i = b >> 4;
plu.setPrintPackedDate(i != 0);
if (plu.isPrintPackedDate()) {
PrintDateFormatEnum fromValue = PrintDateFormatEnum.fromValue(i);
if (fromValue != null) {
plu.setPackedDateFormat(fromValue.format());
}
}
byte b4 = (byte) (b2 & 15);
plu.setPrintSellByDate(b4 != 0);
if (plu.isPrintSellByDate()) {
PrintDateFormatEnum fromValue2 = PrintDateFormatEnum.fromValue(b4);
if (fromValue2 != null) {
plu.setSellByDateFormat(fromValue2.format());
}
}
int i2 = b2 >> 4;
plu.setPrintBestBeforeDate(i2 != 0);
if (plu.isPrintBestBeforeDate()) {
PrintDateFormatEnum fromValue3 = PrintDateFormatEnum.fromValue(i2);
if (fromValue3 != null) {
plu.setBestBeforeDateFormat(fromValue3.format());
}
}
if (((b3 >> 4) & 1) != 1) {
z = false;
}
plu.setTraceable(z);
StringBuilder sb = new StringBuilder();
String str = "";
sb.append(str);
sb.append(byteBuffer.getInt());
plu.setBestBeforeDate(sb.toString());
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append(byteBuffer.getInt());
plu.setSellByDate(sb2.toString());
plu.setEtNo(byteBuffer.getInt());
plu.setNutritionNo(byteBuffer.getInt());
plu.setNameTextB(CC.doubleBytesToText(byteBuffer, 150));
return plu;
}
public Plu toDeleteBean(ByteBuffer byteBuffer) {
Plu plu = new Plu(byteBuffer.getInt());
byteBuffer.getInt();
byteBuffer.getInt();
return plu;
}
}
package com.wmdigit.transfer.converter.decompress;
import androidx.annotation.RequiresApi;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.BitSet;
public class DecompressUtils {
private static final int MAX_WINDOW_SIZE = 1024;
private static double log(double d, double d2) {
return Math.log(d) / Math.log(d2);
}
public static int log2Ceil(double d) {
if (d <= 0.0d) {
return -1;
}
return (int) Math.ceil(log(d, 2.0d));
}
@RequiresApi(api = 19)
public static int decompress(byte[] bArr, byte[] bArr2, int i) {
short s;
BitSet valueOf = BitSet.valueOf(bArr2);
BitSet bitSet = new BitSet(32);
int i2 = i;
int i3 = 0;
short s2 = 0;
int i4 = 0;
int i5 = 0;
while (i3 < i2) {
boolean bit = getBit(valueOf, i4);
int i6 = i4 + 1;
if (!bit) {
bArr[i3] = getByte(valueOf, i6);
i4 = i6 + 8;
s2 = (short) (s2 + 1);
} else {
short s3 = -1;
while (bit) {
s3 = (short) (s3 + 1);
bit = getBit(valueOf, i6);
i6++;
}
if (s3 > 0) {
bitSet.clear();
int i7 = 32 - s3;
for (int i8 = 0; i8 < s3; i8++) {
bitSet.set(i7 + i8, getBit(valueOf, i6 + i8));
}
i6 += s3;
s = (short) (((short) ((int) (((long) ((short) (1 << s3))) + getNormalLong(bitSet)))) + 1);
} else {
s = 2;
}
int log2Ceil = log2Ceil((double) s2);
bitSet.clear();
int i9 = 32 - log2Ceil;
for (int i10 = 0; i10 < log2Ceil; i10++) {
bitSet.set(i9 + i10, getBit(valueOf, i6 + i10));
}
i4 = i6 + log2Ceil;
short normalLong = (short) ((int) getNormalLong(bitSet));
for (short s4 = 0; s4 < s; s4 = (short) (s4 + 1)) {
bArr[i3 + s4] = bArr[i5 + normalLong + s4];
}
s2 = (short) (s2 + s);
i3 += s - 1;
}
if (s2 > MAX_WINDOW_SIZE) {
i5 += s2 - 1024;
s2 = 1024;
}
i3++;
}
return s2;
}
public static boolean getBit(BitSet bitSet, int i) {
return bitSet.get(((i / 8) * 8) + (7 - (i % 8)));
}
public static byte getByte(BitSet bitSet, int i) {
byte b = 0;
for (int i2 = 0; i2 < 8; i2++) {
b = (byte) (b + ((getBit(bitSet, i + i2) ? 1 : 0) << (7 - i2)));
}
return b;
}
public static long getNormalLong(BitSet bitSet) {
ByteBuffer order = ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN);
//TODO 0墙砖了
order.put((byte) 0).put((byte) 0).put((byte) 0).put((byte) 0).put(getNormalByte(bitSet, 0)).put(getNormalByte(bitSet, 8)).put(getNormalByte(bitSet, 16)).put(getNormalByte(bitSet, 24)).flip();
return order.getLong();
}
public static byte getNormalByte(BitSet bitSet, int i) {
byte b = 0;
for (int i2 = 0; i2 < 8; i2++) {
b = (byte) (b + ((bitSet.get(i + i2) ? 1 : 0) << (7 - i2)));
}
return b;
}
}
package com.wmdigit.transfer.converter.hh;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Acc;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class AccHhConverter implements BeanConverter<Acc> {
public ByteBuffer fromBean(Acc acc) {
return null;
}
public Acc toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
Acc acc = new Acc();
acc.accNo = byteBuffer.getShort();
acc.depNo = byteBuffer.get();
acc.groupNo = byteBuffer.get();
String doubleBytesToText = CC.doubleBytesToText(byteBuffer, (byteBuffer.capacity() - byteBuffer.position()) / 2);
acc.content = doubleBytesToText;
acc.setAccContent(doubleBytesToText.substring(0, doubleBytesToText.length() - 1).split("\u001a"));
return acc;
}
public Acc toDeleteBean(ByteBuffer byteBuffer) {
return new Acc();
}
}
package com.wmdigit.transfer.converter.hh;
import com.wmdigit.transfer.constant.DateUnitEnum;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Plu;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class PluHhConverter implements BeanConverter<Plu> {
public ByteBuffer fromBean(Plu plu) {
return null;
}
public Plu toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
ByteBuffer byteBuffer2 = byteBuffer;
Plu plu = new Plu();
plu.setPluNo(byteBuffer.getInt());
plu.setItemNo(CC.bytesToText(byteBuffer2, 16));
plu.setDeptNo(byteBuffer.getInt());
plu.setGroupNo(byteBuffer.getInt());
plu.setNameTextA(CC.doubleBytesToText(byteBuffer2, 28));
plu.setUnitPriceA(byteBuffer.getInt());
plu.setUnitPriceB(byteBuffer.getInt());
plu.setLabelNoA(byteBuffer.get());
plu.setLabelNoB(byteBuffer.get());
plu.setLabelNoC(byteBuffer.get());
plu.setGraphicNoA(String.valueOf(byteBuffer.get()));
plu.setGraphicNoB(String.valueOf(byteBuffer.get()));
plu.setGraphicNoC(String.valueOf(byteBuffer.get()));
plu.setPriceUnitA(byteBuffer.get());
plu.setPriceUnitB(plu.getPriceUnitA());
byteBuffer.get();
plu.setFixWeight((double) byteBuffer.getInt());
plu.setBarcodeNo(byteBuffer.getInt());
plu.setTareNoA(byteBuffer.getInt());
plu.setPriceUnitDesA(CC.doubleBytesToText(byteBuffer2, 4));
plu.setPriceUnitDesB(plu.getPriceUnitDesA());
byte b = byteBuffer.get();
byte b2 = byteBuffer.get();
short s = byteBuffer.getShort();
boolean z = false;
String str = "20%1$s-%2$02d-%3$02d %4$02d:%5$02d:%6$02d";
String format = String.format(str, new Object[]{Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get())});
plu.setPrintPackedDate(b != 0);
String str2 = "";
if (b2 == 0) {
StringBuilder sb = new StringBuilder();
sb.append(str2);
sb.append(s);
plu.setPackedDate(sb.toString());
plu.setPackedDateUnit(DateUnitEnum.DAY.unit());
} else {
plu.setPackedDate(format);
plu.setPackedDateUnit(DateUnitEnum.DATE.unit());
}
byte b3 = byteBuffer.get();
byte b4 = byteBuffer.get();
short s2 = byteBuffer.getShort();
String format2 = String.format(str, new Object[]{Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get())});
plu.setPrintSellByDate(b3 != 0);
if (b4 == 0) {
StringBuilder sb2 = new StringBuilder();
sb2.append(str2);
sb2.append(s2);
plu.setSellByDate(sb2.toString());
plu.setSellByDateUnit(DateUnitEnum.DAY.unit());
} else {
plu.setSellByDate(format2);
plu.setSellByDateUnit(DateUnitEnum.DATE.unit());
}
byte b5 = byteBuffer.get();
byte b6 = byteBuffer.get();
short s3 = byteBuffer.getShort();
String format3 = String.format(str, new Object[]{Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get())});
plu.setPrintBestBeforeDate(b5 != 0);
if (b6 == 0) {
StringBuilder sb3 = new StringBuilder();
sb3.append(str2);
sb3.append(s3);
plu.setBestBeforeDate(sb3.toString());
plu.setBestBeforeDateUnit(DateUnitEnum.DAY.unit());
} else {
plu.setBestBeforeDate(format3);
plu.setBestBeforeDateUnit(DateUnitEnum.DATE.unit());
}
byteBuffer.getShort();
plu.setEtNo(byteBuffer.getInt());
plu.setNutritionNo(byteBuffer.getInt());
plu.setSpecialPriceStartDate(String.format(str, new Object[]{Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get())}));
plu.setSpecialPriceEndDate(String.format(str, new Object[]{Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get()), Byte.valueOf(byteBuffer.get())}));
plu.setSpecialPrice((double) byteBuffer.getInt());
byte b7 = byteBuffer.get();
plu.setPriceChangeFlagA((b7 & 1) == 1);
plu.setPriceChangeFlagB(plu.isPriceChangeFlagA());
plu.setDiscountFlagA(((b7 >> 1) & 1) == 1);
plu.setDiscountFlagB(plu.isDiscountFlagA());
plu.setSpecialPrice(((b7 >> 2) & 1) == 1);
if (((b7 >> 3) & 1) == 1) {
z = true;
}
plu.setTraceable(z);
return plu;
}
public Plu toDeleteBean(ByteBuffer byteBuffer) {
Plu plu = new Plu(byteBuffer.getInt());
byteBuffer.getInt();
byteBuffer.getInt();
return plu;
}
}
package com.wmdigit.transfer.converter.rl00;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Acc;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class AccRl00Converter implements BeanConverter<Acc> {
public ByteBuffer fromBean(Acc acc) {
return null;
}
public Acc toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
Acc acc = new Acc();
acc.accNo = byteBuffer.getShort();
acc.depNo = byteBuffer.get();
byteBuffer.get();
byteBuffer.get();
byteBuffer.get();
String bytesToText = CC.bytesToText(byteBuffer, byteBuffer.capacity() - byteBuffer.position());
String substring = bytesToText.substring(0, bytesToText.length() - 2);
acc.content = substring;
acc.setAccContent(substring.split("\u001a\u001b"));
return acc;
}
public Acc toDeleteBean(ByteBuffer byteBuffer) {
return new Acc();
}
}
package com.wmdigit.transfer.converter.rl00;
import android.util.Log;
import com.wmdigit.transfer.constant.FixedWeightUsageEnum;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.domain.Plu;
import com.wmdigit.transfer.wrapper.DataPackUtils;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
public class PluRl00Converter implements BeanConverter<Plu> {
public ByteBuffer fromBean(Plu plu) {
return null;
}
public Plu toBean(ByteBuffer byteBuffer) throws UnsupportedEncodingException {
Plu plu = new Plu();
plu.setPluNo(byteBuffer.getInt());
plu.setItemNo(CC.bytesToText(byteBuffer, 13));
plu.setNameTextA(CC.bytesToText(byteBuffer, 28));
byteBuffer.get();
plu.setUnitPriceA(byteBuffer.getInt());
plu.setLabelNoA(byteBuffer.get());
plu.setTareNoA(byteBuffer.get());
byteBuffer.getShort();
if (DataPackUtils.getInstance().getFixedWeightUse() == FixedWeightUsageEnum.FIXED_WEIGHT) {
plu.setFixWeight((double) byteBuffer.getInt());
} else {
plu.setPriceUnitDesA(CC.bytesToText(byteBuffer, 4));
plu.setPriceUnitDesB(plu.getPriceUnitDesA());
}
plu.setGroupNo(byteBuffer.getShort());
short s = byteBuffer.getShort();
plu.setPriceUnitA(s & 1);
boolean z = true;
plu.setPriceChangeFlagA(((s >> 1) & 1) == 1);
plu.setDiscountFlagA(((s >> 5) & 1) == 1);
if (((s >> 13) & 1) != 1) {
z = false;
}
plu.setTraceable(z);
StringBuilder sb = new StringBuilder();
String str = "";
sb.append(str);
sb.append(byteBuffer.getShort());
plu.setBestBeforeDate(sb.toString());
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append(byteBuffer.getShort());
plu.setSellByDate(sb2.toString());
plu.setEtNo(byteBuffer.getShort());
return plu;
}
public Plu toDeleteBean(ByteBuffer byteBuffer) {
Plu plu = new Plu(byteBuffer.getInt());
byteBuffer.getInt();
byteBuffer.getInt();
return plu;
}
}
package com.wmdigit.transfer.domain;
public class Acc implements DataBean {
public int accNo;
public String content;
public String content1;
public String content2;
public String content3;
public String content4;
public int depNo;
public int font1;
public int font2;
public int font3;
public int font4;
public int groupNo;
public void setAccContent(String[] strArr) {
if (strArr != null && strArr.length > 0) {
for (int i = 0; i < strArr.length; i++) {
if (i == 0) {
this.content1 = strArr[0];
} else if (i == 1) {
this.content2 = strArr[1];
} else if (i == 2) {
this.content3 = strArr[2];
} else if (i == 3) {
this.content4 = strArr[3];
}
}
}
}
@Override
public String toString() {
return "Acc{" +
"accNo=" + accNo +
", content='" + content + '\'' +
", content1='" + content1 + '\'' +
", content2='" + content2 + '\'' +
", content3='" + content3 + '\'' +
", content4='" + content4 + '\'' +
", depNo=" + depNo +
", font1=" + font1 +
", font2=" + font2 +
", font3=" + font3 +
", font4=" + font4 +
", groupNo=" + groupNo +
'}';
}
}
package com.wmdigit.transfer.domain;
import com.wmdigit.transfer.constant.ControlTypeEnum;
import com.wmdigit.transfer.constant.DataTypeEnum;
import com.wmdigit.transfer.constant.ScaleTypeEnum;
public class CommandHeader implements DomainBean {
private byte cmdrsp;
private short command;
private short control;
private ControlTypeEnum controlType;
private DataTypeEnum dataType;
private short departno;
private byte deviceno;
private boolean isCompressed;
private short pageLength;
private short pageNum;
private ScaleTypeEnum scaleType;
private byte start;
private short totalLength;
public byte getStart() {
return this.start;
}
public void setStart(byte b) {
this.start = b;
}
public short getTotalLength() {
return this.totalLength;
}
public void setTotalLength(short s) {
this.totalLength = s;
}
public short getPageNum() {
return this.pageNum;
}
public void setPageNum(short s) {
this.pageNum = s;
}
public short getPageLength() {
return this.pageLength;
}
public void setPageLength(short s) {
this.pageLength = s;
}
public byte getCmdrsp() {
return this.cmdrsp;
}
public void setCmdrsp(byte b) {
this.cmdrsp = b;
}
public short getCommand() {
return this.command;
}
public void setCommand(short s) {
this.command = s;
}
public short getControl() {
return this.control;
}
public void setControl(short s) {
this.control = s;
}
public short getDepartno() {
return this.departno;
}
public void setDepartno(short s) {
this.departno = s;
}
public byte getDeviceno() {
return this.deviceno;
}
public void setDeviceno(byte b) {
this.deviceno = b;
}
public ScaleTypeEnum getScaleType() {
return this.scaleType;
}
public void setScaleType(ScaleTypeEnum scaleTypeEnum) {
this.scaleType = scaleTypeEnum;
}
public ControlTypeEnum getControlType() {
return this.controlType;
}
public void setControlType(ControlTypeEnum controlTypeEnum) {
this.controlType = controlTypeEnum;
}
public DataTypeEnum getDataType() {
return this.dataType;
}
public void setDataType(DataTypeEnum dataTypeEnum) {
this.dataType = dataTypeEnum;
}
public boolean isCompressed() {
return this.isCompressed;
}
public void setCompressed(boolean z) {
this.isCompressed = z;
}
@Override
public String toString() {
return "CommandHeader{" +
"cmdrsp=" + cmdrsp +
", command=" + command +
", control=" + control +
", controlType=" + controlType +
", dataType=" + dataType +
", departno=" + departno +
", deviceno=" + deviceno +
", isCompressed=" + isCompressed +
", pageLength=" + pageLength +
", pageNum=" + pageNum +
", scaleType=" + scaleType +
", start=" + start +
", totalLength=" + totalLength +
'}';
}
}
package com.wmdigit.transfer.domain;
public interface DataBean extends DomainBean {
}
package com.wmdigit.transfer.domain;
public interface DomainBean {
}
package com.wmdigit.transfer.domain;
import com.wmdigit.transfer.constant.DateUnitEnum;
import com.wmdigit.transfer.constant.PrintDateFormatEnum;
public class Plu implements DataBean {
public static final String DEFAULT_DATE_FORMAT = PrintDateFormatEnum.YYMMDD.format();
public static final String DEFAULT_DATE_UNIT = DateUnitEnum.DAY.unit();
private int barcodeNo;
private String bestBeforeDate;
private String bestBeforeDateFormat;
private String bestBeforeDateUnit;
private int deptNo;
private boolean discountFlagA;
private boolean discountFlagB;
private int etNo;
private double fixWeight;
private String graphicNoA;
private String graphicNoB;
private String graphicNoC;
private int groupNo;
private boolean isPrintBestBeforeDate = true;
private boolean isPrintPackedDate = true;
private boolean isPrintSellByDate = true;
private boolean isSpecialPrice;
private boolean isTraceable;
private String itemNo;
private int labelNoA;
private int labelNoB;
private int labelNoC;
private String nameTextA;
private String nameTextB;
private int nutritionNo;
private String packedDate;
private String packedDateFormat;
private String packedDateUnit;
private int pluNo;
private boolean priceChangeFlagA;
private boolean priceChangeFlagB;
private int priceRuleNo;
private int priceUnitA;
private int priceUnitB;
private String priceUnitDesA;
private String priceUnitDesB;
private int safeHandingNo;
private String sellByDate;
private String sellByDateFormat;
private String sellByDateUnit;
private double specialPrice;
private String specialPriceEndDate;
private String specialPriceStartDate;
private int tareNoA;
private int unitPriceA;
private int unitPriceB;
public Plu() {
String str = DEFAULT_DATE_UNIT;
this.packedDateUnit = str;
this.sellByDateUnit = str;
this.bestBeforeDateUnit = str;
String str2 = DEFAULT_DATE_FORMAT;
this.packedDateFormat = str2;
this.sellByDateFormat = str2;
this.bestBeforeDateFormat = str2;
}
public Plu(int i) {
String str = DEFAULT_DATE_UNIT;
this.packedDateUnit = str;
this.sellByDateUnit = str;
this.bestBeforeDateUnit = str;
String str2 = DEFAULT_DATE_FORMAT;
this.packedDateFormat = str2;
this.sellByDateFormat = str2;
this.bestBeforeDateFormat = str2;
this.pluNo = i;
}
public int getDeptNo() {
return this.deptNo;
}
public void setDeptNo(int i) {
this.deptNo = i;
}
public int getPluNo() {
return this.pluNo;
}
public void setPluNo(int i) {
this.pluNo = i;
}
public String getItemNo() {
return this.itemNo;
}
public void setItemNo(String str) {
this.itemNo = str;
}
public String getNameTextA() {
return this.nameTextA;
}
public void setNameTextA(String str) {
this.nameTextA = str;
}
public String getNameTextB() {
return this.nameTextB;
}
public void setNameTextB(String str) {
this.nameTextB = str;
}
public int getUnitPriceA() {
return this.unitPriceA;
}
public void setUnitPriceA(int i) {
this.unitPriceA = i;
}
public boolean isPriceChangeFlagA() {
return this.priceChangeFlagA;
}
public void setPriceChangeFlagA(boolean z) {
this.priceChangeFlagA = z;
}
public boolean isDiscountFlagA() {
return this.discountFlagA;
}
public void setDiscountFlagA(boolean z) {
this.discountFlagA = z;
}
public int getPriceUnitA() {
return this.priceUnitA;
}
public void setPriceUnitA(int i) {
this.priceUnitA = i;
}
public String getPriceUnitDesA() {
return this.priceUnitDesA;
}
public void setPriceUnitDesA(String str) {
this.priceUnitDesA = str;
}
public int getUnitPriceB() {
return this.unitPriceB;
}
public void setUnitPriceB(int i) {
this.unitPriceB = i;
}
public boolean isPriceChangeFlagB() {
return this.priceChangeFlagB;
}
public void setPriceChangeFlagB(boolean z) {
this.priceChangeFlagB = z;
}
public boolean isDiscountFlagB() {
return this.discountFlagB;
}
public void setDiscountFlagB(boolean z) {
this.discountFlagB = z;
}
public int getPriceUnitB() {
return this.priceUnitB;
}
public void setPriceUnitB(int i) {
this.priceUnitB = i;
}
public String getPriceUnitDesB() {
return this.priceUnitDesB;
}
public void setPriceUnitDesB(String str) {
this.priceUnitDesB = str;
}
public int getLabelNoA() {
return this.labelNoA;
}
public void setLabelNoA(int i) {
this.labelNoA = i;
}
public int getLabelNoB() {
return this.labelNoB;
}
public void setLabelNoB(int i) {
this.labelNoB = i;
}
public int getLabelNoC() {
return this.labelNoC;
}
public void setLabelNoC(int i) {
this.labelNoC = i;
}
public int getEtNo() {
return this.etNo;
}
public void setEtNo(int i) {
this.etNo = i;
}
public int getTareNoA() {
return this.tareNoA;
}
public void setTareNoA(int i) {
this.tareNoA = i;
}
public int getGroupNo() {
return this.groupNo;
}
public void setGroupNo(int i) {
this.groupNo = i;
}
public double getFixWeight() {
return this.fixWeight;
}
public void setFixWeight(double d) {
this.fixWeight = d;
}
public String getPackedDateUnit() {
return this.packedDateUnit;
}
public void setPackedDateUnit(String str) {
this.packedDateUnit = str;
}
public String getSellByDateUnit() {
return this.sellByDateUnit;
}
public void setSellByDateUnit(String str) {
this.sellByDateUnit = str;
}
public String getBestBeforeDateUnit() {
return this.bestBeforeDateUnit;
}
public void setBestBeforeDateUnit(String str) {
this.bestBeforeDateUnit = str;
}
public String getPackedDateFormat() {
return this.packedDateFormat;
}
public void setPackedDateFormat(String str) {
this.packedDateFormat = str;
}
public String getSellByDateFormat() {
return this.sellByDateFormat;
}
public void setSellByDateFormat(String str) {
this.sellByDateFormat = str;
}
public String getBestBeforeDateFormat() {
return this.bestBeforeDateFormat;
}
public void setBestBeforeDateFormat(String str) {
this.bestBeforeDateFormat = str;
}
public String getPackedDate() {
return this.packedDate;
}
public void setPackedDate(String str) {
this.packedDate = str;
}
public String getSellByDate() {
return this.sellByDate;
}
public void setSellByDate(String str) {
this.sellByDate = str;
}
public String getBestBeforeDate() {
return this.bestBeforeDate;
}
public void setBestBeforeDate(String str) {
this.bestBeforeDate = str;
}
public boolean isPrintPackedDate() {
return this.isPrintPackedDate;
}
public void setPrintPackedDate(boolean z) {
this.isPrintPackedDate = z;
}
public boolean isPrintSellByDate() {
return this.isPrintSellByDate;
}
public void setPrintSellByDate(boolean z) {
this.isPrintSellByDate = z;
}
public boolean isPrintBestBeforeDate() {
return this.isPrintBestBeforeDate;
}
public void setPrintBestBeforeDate(boolean z) {
this.isPrintBestBeforeDate = z;
}
public boolean isTraceable() {
return this.isTraceable;
}
public void setTraceable(boolean z) {
this.isTraceable = z;
}
public int getPriceRuleNo() {
return this.priceRuleNo;
}
public void setPriceRuleNo(int i) {
this.priceRuleNo = i;
}
public int getBarcodeNo() {
return this.barcodeNo;
}
public void setBarcodeNo(int i) {
this.barcodeNo = i;
}
public int getNutritionNo() {
return this.nutritionNo;
}
public void setNutritionNo(int i) {
this.nutritionNo = i;
}
public String getGraphicNoA() {
return this.graphicNoA;
}
public void setGraphicNoA(String str) {
this.graphicNoA = str;
}
public String getGraphicNoB() {
return this.graphicNoB;
}
public void setGraphicNoB(String str) {
this.graphicNoB = str;
}
public String getGraphicNoC() {
return this.graphicNoC;
}
public void setGraphicNoC(String str) {
this.graphicNoC = str;
}
public int getSafeHandingNo() {
return this.safeHandingNo;
}
public void setSafeHandingNo(int i) {
this.safeHandingNo = i;
}
public double getSpecialPrice() {
return this.specialPrice;
}
public void setSpecialPrice(double d) {
this.specialPrice = d;
}
public String getSpecialPriceStartDate() {
return this.specialPriceStartDate;
}
public void setSpecialPriceStartDate(String str) {
this.specialPriceStartDate = str;
}
public String getSpecialPriceEndDate() {
return this.specialPriceEndDate;
}
public void setSpecialPriceEndDate(String str) {
this.specialPriceEndDate = str;
}
public boolean isSpecialPrice() {
return this.isSpecialPrice;
}
public void setSpecialPrice(boolean z) {
this.isSpecialPrice = z;
}
@Override
public String toString() {
return "Plu{" +
"barcodeNo=" + barcodeNo +
", bestBeforeDate='" + bestBeforeDate + '\'' +
", bestBeforeDateFormat='" + bestBeforeDateFormat + '\'' +
", bestBeforeDateUnit='" + bestBeforeDateUnit + '\'' +
", deptNo=" + deptNo +
", discountFlagA=" + discountFlagA +
", discountFlagB=" + discountFlagB +
", etNo=" + etNo +
", fixWeight=" + fixWeight +
", graphicNoA='" + graphicNoA + '\'' +
", graphicNoB='" + graphicNoB + '\'' +
", graphicNoC='" + graphicNoC + '\'' +
", groupNo=" + groupNo +
", isPrintBestBeforeDate=" + isPrintBestBeforeDate +
", isPrintPackedDate=" + isPrintPackedDate +
", isPrintSellByDate=" + isPrintSellByDate +
", isSpecialPrice=" + isSpecialPrice +
", isTraceable=" + isTraceable +
", itemNo='" + itemNo + '\'' +
", labelNoA=" + labelNoA +
", labelNoB=" + labelNoB +
", labelNoC=" + labelNoC +
", nameTextA='" + nameTextA + '\'' +
", nameTextB='" + nameTextB + '\'' +
", nutritionNo=" + nutritionNo +
", packedDate='" + packedDate + '\'' +
", packedDateFormat='" + packedDateFormat + '\'' +
", packedDateUnit='" + packedDateUnit + '\'' +
", pluNo=" + pluNo +
", priceChangeFlagA=" + priceChangeFlagA +
", priceChangeFlagB=" + priceChangeFlagB +
", priceRuleNo=" + priceRuleNo +
", priceUnitA=" + priceUnitA +
", priceUnitB=" + priceUnitB +
", priceUnitDesA='" + priceUnitDesA + '\'' +
", priceUnitDesB='" + priceUnitDesB + '\'' +
", safeHandingNo=" + safeHandingNo +
", sellByDate='" + sellByDate + '\'' +
", sellByDateFormat='" + sellByDateFormat + '\'' +
", sellByDateUnit='" + sellByDateUnit + '\'' +
", specialPrice=" + specialPrice +
", specialPriceEndDate='" + specialPriceEndDate + '\'' +
", specialPriceStartDate='" + specialPriceStartDate + '\'' +
", tareNoA=" + tareNoA +
", unitPriceA=" + unitPriceA +
", unitPriceB=" + unitPriceB +
'}';
}
}
package com.wmdigit.transfer.wrapper;
import android.util.Log;
import com.wmdigit.transfer.constant.ControlResponseEnum;
import com.wmdigit.transfer.constant.FixedWeightUsageEnum;
import com.wmdigit.transfer.constant.ScaleTypeEnum;
import com.wmdigit.transfer.converter.BeanConverter;
import com.wmdigit.transfer.converter.CommandHeaderConverter;
import com.wmdigit.transfer.converter.ConverterFactory;
import com.wmdigit.transfer.domain.CommandHeader;
import com.wmdigit.transfer.domain.DataBean;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class DataPackUtils {
public static final int DECOMPRESS_BUF_SIZE = 1500;
public static final int MAX_PAGE_NUM = 8;
public static final int REC_BUF_SIZE = 1600;
private static DataPackUtils instance;
private CommandHeaderConverter commandHeaderConverter = new CommandHeaderConverter();
private FixedWeightUsageEnum fixedWeightUse = FixedWeightUsageEnum.FIXED_WEIGHT;
private DataPackUtils() {
}
public static synchronized DataPackUtils getInstance() {
DataPackUtils dataPackUtils;
synchronized (DataPackUtils.class) {
if (instance == null) {
instance = new DataPackUtils();
}
dataPackUtils = instance;
}
return dataPackUtils;
}
public DataPackWrapper parse(byte[] bArr, int i) throws IOException {
int i2 = i - 2;
int calcCrc16 = BeanConverter.CC.calcCrc16(bArr, 1, i2);
byte b = (byte) ((calcCrc16 >> 8) & 255);
byte b2 = (byte) (calcCrc16 & 255);
if (i > 2) {
if (bArr[i2] != b || bArr[i - 1] != b2) {
return new DataPackWrapper(false);
}
}else {
return new DataPackWrapper(false);
}
ByteBuffer allocate = ByteBuffer.allocate(i);
allocate.put(bArr, 0, i);
allocate.order(ByteOrder.LITTLE_ENDIAN).flip();
CommandHeader bean = this.commandHeaderConverter.toBean(allocate);
if (bean.isCompressed()) {
bean.getPageNum();
bean = this.commandHeaderConverter.toBean(allocate);
}
DataPackWrapper dataPackWrapper = new DataPackWrapper(allocate, bean);
if (dataPackWrapper.isWrite() || dataPackWrapper.isDelete()) {
BeanConverter create = ConverterFactory.create(bean.getScaleType(), bean.getDataType());
if (create != null) {
int i3 = 0;
while (i3 < bean.getPageNum()) {
try {
allocate.position((bean.getPageLength() * i3) + 15);
if (dataPackWrapper.isWrite()) {
dataPackWrapper.addBean((DataBean) create.toBean(allocate));
} else {
dataPackWrapper.addBean((DataBean) create.toDeleteBean(allocate));
}
i3++;
} catch (UnsupportedEncodingException e) {
dataPackWrapper.setResultOk(false);
throw new RuntimeException(e);
}
}
}
}
return dataPackWrapper;
}
public void setOut(DataPackWrapper dataPackWrapper) {
ScaleTypeEnum scaleType = dataPackWrapper.getInHeader().getScaleType();
if (scaleType == null) {
dataPackWrapper.setOutBytes(new byte[]{6});
return;
}
if (ScaleTypeEnum.RL00 != scaleType || dataPackWrapper.isRead()) {
int capacity = dataPackWrapper.getInBuffer().capacity();
Log.d("RL00", capacity + "");
ByteBuffer order = ByteBuffer.allocate(capacity + 1).order(ByteOrder.LITTLE_ENDIAN);
if (!dataPackWrapper.isResultOk()) {
int control = (dataPackWrapper.getInHeader().getControl() & ControlResponseEnum.MASK_SCALE_TYPE_CTRL.value()) | ControlResponseEnum.GENERAL_ERROR.value();
byte b = (byte) ((control >> 8) & 255);
byte b2 = (byte) (control & 255);
ByteBuffer inBuffer = dataPackWrapper.getInBuffer();
inBuffer.position(10);
inBuffer.put(b2).put(b);
}
order.put((byte) 102).put(dataPackWrapper.getInBuffer().array());
dataPackWrapper.setOutBytes(order.array());
return;
}
// Log.d("RL00", "ceshi");
dataPackWrapper.setOutBytes(new byte[]{6});
}
public FixedWeightUsageEnum getFixedWeightUse() {
return this.fixedWeightUse;
}
public void setFixedWeightUse(FixedWeightUsageEnum fixedWeightUsageEnum) {
this.fixedWeightUse = fixedWeightUsageEnum;
}
}
package com.wmdigit.transfer.wrapper;
import com.wmdigit.transfer.constant.ControlTypeEnum;
import com.wmdigit.transfer.domain.CommandHeader;
import com.wmdigit.transfer.domain.DataBean;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
public class DataPackWrapper {
private List<DataBean> beanList = new ArrayList();
private final ByteBuffer inBuffer;
private final CommandHeader inHeader;
private boolean isResultOk = true;
private byte[] outBytes;
private CommandHeader outHeader;
public DataPackWrapper(boolean z) {
this.isResultOk = z;
this.inBuffer = null;
this.inHeader = null;
}
public DataPackWrapper(ByteBuffer byteBuffer, CommandHeader commandHeader) {
this.inBuffer = byteBuffer;
this.inHeader = commandHeader;
}
public boolean isRead() {
ControlTypeEnum controlType = this.inHeader.getControlType();
return (ControlTypeEnum.WRITE == controlType || ControlTypeEnum.DELETE == controlType || ControlTypeEnum.DELETE_ALL == controlType) ? false : true;
}
public boolean isWrite() {
return ControlTypeEnum.WRITE == this.inHeader.getControlType();
}
public boolean isDelete() {
return ControlTypeEnum.DELETE == this.inHeader.getControlType();
}
public boolean isDeleteAll() {
return ControlTypeEnum.DELETE_ALL == this.inHeader.getControlType();
}
public DataPackWrapper addBean(DataBean dataBean) {
this.beanList.add(dataBean);
return this;
}
public List<DataBean> getBeanList() {
return this.beanList;
}
public void setBeanList(List<DataBean> list) {
this.beanList = list;
}
public byte[] getOutBytes() {
return this.outBytes;
}
public void setOutBytes(byte[] bArr) {
this.outBytes = bArr;
}
public ByteBuffer getInBuffer() {
return this.inBuffer;
}
public CommandHeader getInHeader() {
return this.inHeader;
}
public boolean isResultOk() {
return this.isResultOk;
}
public void setResultOk(boolean z) {
this.isResultOk = z;
}
public CommandHeader getOutHeader() {
return this.outHeader;
}
public void setOutHeader(CommandHeader commandHeader) {
this.outHeader = commandHeader;
}
}
package com.wmdigit.transfer;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
String plu = "123";
plu.getBytes("")
}
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int length1 = nums1.length, length2 = nums2.length;
int totalLength = length1 + length2;
if (totalLength % 2 == 1) { // 可以将两种情况合并,奇数会求两次同样的k
int midIndex = totalLength / 2;
double median = getKthElement(nums1, nums2, midIndex + 1);
return median;
} else {
int midIndex1 = totalLength / 2 - 1, midIndex2 = totalLength / 2;
double median = (getKthElement(nums1, nums2, midIndex1 + 1) + getKthElement(nums1, nums2, midIndex2 + 1)) / 2.0;
return median;
}
}
public int getKthElement(int[] nums1, int[] nums2, int k) {
/* 主要思路:要找到第 k (k>1) 小的元素,那么就取 pivot1 = nums1[k/2-1] 和 pivot2 = nums2[k/2-1] 进行比较
* 这里的 "/" 表示整除
* nums1 中小于等于 pivot1 的元素有 nums1[0 .. k/2-2] 共计 k/2-1 个
* nums2 中小于等于 pivot2 的元素有 nums2[0 .. k/2-2] 共计 k/2-1 个
* 取 pivot = min(pivot1, pivot2),两个数组中小于等于 pivot 的元素共计不会超过 (k/2-1) + (k/2-1) <= k-2 个
* 这样 pivot 本身最大也只能是第k-1小的元素
* 如果 pivot = pivot1,那么 nums1[0 .. k/2-1] 都不可能是第 k 小的元素。把这些元素全部 "删除",剩下的作为新的 nums1 数组
* 如果 pivot = pivot2,那么 nums2[0 .. k/2-1] 都不可能是第 k 小的元素。把这些元素全部 "删除",剩下的作为新的 nums2 数组
* 由于我们 "删除" 了一些元素(这些元素都比第 k 小的元素要小),因此需要修改 k 的值,减去删除的数的个数
*/
int length1 = nums1.length, length2 = nums2.length;
int index1 = 0, index2 = 0;
int kthElement = 0;
while (true) {
// 特殊情况
if (index1 == length1) { // 第二种特殊情况,一个数组为空
return nums2[index2 + k - 1];
}
if (index2 == length2) { // 第二种特殊情况,一个数组为空
return nums1[index1 + k - 1];
}
if (k == 1) { // 第三种特殊情况,k=1
return Math.min(nums1[index1], nums2[index2]);
}
// 正常情况,index1,index2作为起始点,newindex1,newindex2作为比较点 在不停的更新
int half = k / 2;
int newIndex1 = Math.min(index1 + half, length1) - 1; //第一种特殊情况,发生越界,记录需要比较的位置
int newIndex2 = Math.min(index2 + half, length2) - 1; //第一种特殊情况,发生越界,记录需要比较的位置
int pivot1 = nums1[newIndex1], pivot2 = nums2[newIndex2]; //获取两个需要比较的数
if (pivot1 <= pivot2) { // <=将两种情况合并
k -= (newIndex1 - index1 + 1); //两者相减后+1,这才是真正减去的长度
index1 = newIndex1 + 1; //连同比较位置也一同删去了,所以新的开始是 比较位置 的后一位
} else {
k -= (newIndex2 - index2 + 1);
index2 = newIndex2 + 1;
}
}
}
}
\ No newline at end of file
/build
\ No newline at end of file
File added
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.wmdigit.socketdemo"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
implementation project(path: ':Transfer')
implementation files('libs\\wintecscales.jar')
implementation project(path: ':DigiTransfer')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.wmdigit.socketdemo;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.wmdigit.socketdemo", appContext.getPackageName());
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wmdigit.socketdemo">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SocketDemo">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.wmdigit.socketdemo;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
public class Commodity implements Serializable {
private Integer plu;
private String tradeName;
private String name;
private String articleNumber;
private Integer number;
private Double price;
private Integer tagNumber;
private String unit;
private Integer tare;
private Integer suggestDate;
private Integer expirationDate;
private Integer discount;
private Integer unitPrice;
private Integer information;
private Integer pricingManner;
private Date startDate;
private Date endDate;
private String startTime;
private String endTime;
private Double sale;
private Integer saleType;
public Commodity() {
}
public Integer getPricingManner() {
return this.pricingManner;
}
public void setPricingManner(Integer pricingManner) {
this.pricingManner = pricingManner;
}
public Integer getSaleType() {
return this.saleType;
}
public void setSaleType(Integer saleType) {
this.saleType = saleType;
}
public Integer getDiscount() {
return this.discount;
}
public void setDiscount(Integer discount) {
this.discount = discount;
}
public Integer getUnitPrice() {
return this.unitPrice;
}
public void setUnitPrice(Integer unitPrice) {
this.unitPrice = unitPrice;
}
public Integer getPlu() {
return this.plu;
}
public void setPlu(Integer plu) {
this.plu = plu;
}
public String getTradeName() {
return this.tradeName;
}
public void setTradeName(String tradeName) {
this.tradeName = tradeName;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getArticleNumber() {
return this.articleNumber;
}
public void setArticleNumber(String articleNumber) {
this.articleNumber = articleNumber;
}
public Integer getNumber() {
return this.number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Double getPrice() {
return this.price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getTagNumber() {
return this.tagNumber;
}
public void setTagNumber(Integer tagNumber) {
this.tagNumber = tagNumber;
}
public String getUnit() {
return this.unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer getTare() {
return this.tare;
}
public void setTare(Integer tare) {
this.tare = tare;
}
public Integer getSuggestDate() {
return this.suggestDate;
}
public void setSuggestDate(Integer suggestDate) {
this.suggestDate = suggestDate;
}
public Integer getExpirationDate() {
return this.expirationDate;
}
public void setExpirationDate(Integer expirationDate) {
this.expirationDate = expirationDate;
}
public Integer getInformation() {
return this.information;
}
public void setInformation(Integer information) {
this.information = information;
}
public Date getStartDate() {
return this.startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return this.endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getStartTime() {
return this.startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return this.endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public Double getSale() {
return this.sale;
}
public void setSale(Double sale) {
this.sale = sale;
}
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o != null && this.getClass() == o.getClass()) {
Commodity commodity = (Commodity)o;
return Objects.equals(this.plu, commodity.plu) && Objects.equals(this.tradeName, commodity.tradeName) && Objects.equals(this.name, commodity.name) && Objects.equals(this.articleNumber, commodity.articleNumber) && Objects.equals(this.number, commodity.number) && Objects.equals(this.price, commodity.price) && Objects.equals(this.tagNumber, commodity.tagNumber) && Objects.equals(this.unit, commodity.unit) && Objects.equals(this.tare, commodity.tare) && Objects.equals(this.suggestDate, commodity.suggestDate) && Objects.equals(this.expirationDate, commodity.expirationDate) && Objects.equals(this.discount, commodity.discount) && Objects.equals(this.unitPrice, commodity.unitPrice) && Objects.equals(this.information, commodity.information) && Objects.equals(this.pricingManner, commodity.pricingManner) && Objects.equals(this.startDate, commodity.startDate) && Objects.equals(this.endDate, commodity.endDate) && Objects.equals(this.startTime, commodity.startTime) && Objects.equals(this.endTime, commodity.endTime) && Objects.equals(this.sale, commodity.sale) && Objects.equals(this.saleType, commodity.saleType);
} else {
return false;
}
}
public int hashCode() {
return Objects.hash(new Object[]{this.plu, this.tradeName, this.name, this.articleNumber, this.number, this.price, this.tagNumber, this.unit, this.tare, this.suggestDate, this.expirationDate, this.discount, this.unitPrice, this.information, this.pricingManner, this.startDate, this.endDate, this.startTime, this.endTime, this.sale, this.saleType});
}
public String toString() {
return "Commodity{plu=" + this.plu + ", tradeName='" + this.tradeName + '\'' + ", name='" + this.name + '\'' + ", articleNumber=" + this.articleNumber + ", number=" + this.number + ", price=" + this.price + ", tagNumber=" + this.tagNumber + ", unit='" + this.unit + '\'' + ", tare=" + this.tare + ", suggestDate=" + this.suggestDate + ", expirationDate=" + this.expirationDate + ", discount=" + this.discount + ", unitPrice=" + this.unitPrice + ", information=" + this.information + ", pricingManner=" + this.pricingManner + ", startDate=" + this.startDate + ", endDate=" + this.endDate + ", startTime='" + this.startTime + '\'' + ", endTime='" + this.endTime + '\'' + ", sale=" + this.sale + ", saleType=" + this.saleType + '}';
}
public String toChString() {
return "Commodity{PUL号=" + this.plu + ", 商品名称='" + this.tradeName + '\'' + ", 第二品名='" + this.name + '\'' + ", 货号=" + this.articleNumber + ", 商品组号=" + this.number + ", 单价=" + this.price + ", 标签号=" + this.tagNumber + ", 计价单位='" + this.unit + '\'' + ", 皮重号=" + this.tare + ", 推荐日期=" + this.suggestDate + ", 保质日期=" + this.expirationDate + ", 是否允许打折=" + this.discount + ", 是否允许修改单价=" + this.unitPrice + ", 附加信息号=" + this.information + ", 计价方式=" + this.pricingManner + ", 特价开始日期=" + this.startDate + ", 特价结束日期=" + this.endDate + ", 特价开始时间=" + this.startTime + ", 特价结束时间=" + this.endTime + ", 特价=" + this.sale + ", 特价类型=" + this.saleType + '}';
}
}
package com.wmdigit.socketdemo;
import android.os.CountDownTimer;
import android.util.Log;
public class CountDownTimerUtils {
private CountDownTimer countDownTimer;
private CountDownTimerUtils() {
}
public static CountDownTimerUtils getInstance() {
return Single.COUNT_DOWN_TIMER_UTILS;
}
public void setTime(final TimerListener timerListener) {
if (null == countDownTimer) {
countDownTimer = new CountDownTimer(5 * 1000L, 1000) {
@Override
public void onTick(long l) {
Log.e("定时器", l / 1000 + "");
}
@Override
public void onFinish() {
Log.e("定时器", Thread.currentThread().getName());
//执行获取灯的状态
timerListener.timeFinish();
}
};
}
}
private static final class Single {
private static final CountDownTimerUtils COUNT_DOWN_TIMER_UTILS = new CountDownTimerUtils();
}
public void startTime() {
if (null != countDownTimer) {
countDownTimer.start();
}
}
/**
* 取消定时
*/
public void cancelTime() {
if (null != countDownTimer) {
countDownTimer.cancel();
}
}
}
package com.wmdigit.socketdemo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class HandlerThread implements Runnable {
private Socket socket;
public HandlerThread(Socket client) {
socket = client;
new Thread(this).start();
}
public void run() {
try {
// 读取客户端数据
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String clientInputStr = input.readLine();//这里要注意和客户端输出流的写方法对应,否则会抛 EOFException
// 处理客户端数据
System.out.println("客户端发过来的内容:" + clientInputStr);
// 向客户端回复信息
// PrintStream out = new PrintStream(socket.getOutputStream());
// System.out.print("请输入:\t");
// // 发送键盘输入的一行
// String s = new BufferedReader(new InputStreamReader(System.in)).readLine();
// out.println(s);
// out.close();
input.close();
} catch (Exception e) {
System.out.println("服务器 run 异常: " + e.getMessage());
} finally {
if (socket != null) {
try {
socket.close();
} catch (Exception e) {
socket = null;
System.out.println("服务端 finally 异常:" + e.getMessage());
}
}
}
}
}
package com.wmdigit.socketdemo;
import android.util.Log;
public class Hex2BytesUtils {
public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < bytes.length; ++i) {
// Log.d("TAG", bytes[i] + "");
String hex = Integer.toHexString(255 & bytes[i]).toUpperCase();
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
public static byte[] hexStringToBytes(String hexString) {
if (hexString == null || hexString.equals("")) {
return null;
}
hexString = hexString.toUpperCase();
int length = hexString.length() / 2;
char[] hexChars = hexString.toCharArray();
byte[] d = new byte[length];
for (int i = 0; i < length; i++) {
int pos = i * 2;
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
}
return d;
}
private static byte charToByte(char c) {
return (byte) "0123456789ABCDEF".indexOf(c);
}
}
package com.wmdigit.socketdemo;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.wmdigit.digitransfer.DigiScaleTransfer;
import java.net.ServerSocket;
public class MainActivity extends AppCompatActivity {
public String TAG = MainActivity.this.getClass().getName();
private ServerSocket serverSocket;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
DigiScaleTransfer.getInstance(new ScalesHandler()).init();
} catch (Exception e) {
e.printStackTrace();
Log.i("ATG", e.getLocalizedMessage());
}
// startSocket(2141);
// ScaleTransfer.getInstance().startLoadPluData(new ScaleTransfer2(), 3001);
// ScaleTransfer.getInstance().startLoadPluData(new ScaleTransfer2(), 2033);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
\ No newline at end of file
package com.wmdigit.socketdemo;
import android.util.Log;
import com.wmdigit.transfer.ScaleTransferListener;
import com.wmdigit.transfer.domain.Acc;
import com.wmdigit.transfer.domain.DataBean;
import com.wmdigit.transfer.domain.Plu;
import java.util.ArrayList;
import java.util.List;
public class ScaleTransfer2 implements ScaleTransferListener {
String TAG = ScaleTransfer2.class.getName();
private final CountDownTimerUtils timerUtils;
private boolean isTimer = false;
private List<Plu> pluList = new ArrayList<>();
public ScaleTransfer2() {
timerUtils = CountDownTimerUtils.getInstance();
timerUtils.setTime(new TimerListener() {
@Override
public void timeFinish() {
isTimer = false;
for (Plu plu : pluList) {
Log.d("TSG-timeFinish", plu.toString());
}
}
});
}
@Override
public void onConnected() {
}
@Override
public void onDataReceived(String str) {
}
@Override
public void onException(String str) {
}
@Override
public void onIOException(String str) {
}
@Override
public void onStart(String str) {
}
@Override
public void pluList(List<DataBean> dataBeans) {
if (dataBeans.size() < 8) {
isTimer = false;
timerUtils.cancelTime();
for (DataBean item : dataBeans) {
if (item instanceof Plu) {
Plu plu = (Plu) item;
pluList.add(plu);
}
}
for (Plu plu : pluList) {
Log.d("TSG-plu>8", plu.toString());
}
} else {
if (!isTimer) {
isTimer = true;
pluList.clear();
} else {
timerUtils.cancelTime();
}
timerUtils.startTime();
for (DataBean item : dataBeans) {
if (item instanceof Plu) {
Plu plu = (Plu) item;
pluList.add(plu);
}
}
}
// for (DataBean item : dataBeans) {
// if (item instanceof Plu) {
// Plu plu = (Plu) item;
//// String string = socketProduct.toChString();
// Log.d(TAG, plu.toString());
// } else if (item instanceof Acc) {
// Acc acc = (Acc) item;
// Log.d(TAG, acc.toString());
// }
// }
}
}
package com.wmdigit.socketdemo;
import android.util.Log;
import com.wmdigit.digitransfer.bean.Commodity;
import com.wmdigit.digitransfer.handler.ScalesApiHandler;
public class ScalesHandler extends ScalesApiHandler {
@Override
public void downPlu(Commodity commodity) {
Log.d("TAG", commodity.toString());
}
}
package com.wmdigit.socketdemo;
import java.io.File;
import java.util.Collection;
import java.util.Iterator;
import java.util.StringTokenizer;
public class StringUtils {
public static String[] splitString(String var0, String var1) {
StringTokenizer var2 = new StringTokenizer(var0, var1);
String[] var3 = new String[var2.countTokens()];
for(int var4 = 0; var4 < var3.length; ++var4) {
var3[var4] = var2.nextToken();
}
return var3;
}
public static String trimWhitespace(String var0) {
if (var0 == null) {
return var0;
} else {
StringBuffer var1 = new StringBuffer();
for(int var2 = 0; var2 < var0.length(); ++var2) {
char var3 = var0.charAt(var2);
if (var3 != '\n' && var3 != '\f' && var3 != '\r' && var3 != '\t') {
var1.append(var3);
}
}
return var1.toString().trim();
}
}
public static String join(Collection var0, String var1) {
StringBuffer var2 = new StringBuffer();
for(Iterator var3 = var0.iterator(); var3.hasNext(); var2.append((String)var3.next())) {
if (var2.length() != 0) {
var2.append(var1);
}
}
return var2.toString();
}
public static String replaceSeparators(String var0) {
return var0.replace('/', '.').replace(File.separatorChar, '.');
}
}
package com.wmdigit.socketdemo;
public interface TimerListener {
/**
* 定时完成
*/
void timeFinish();
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.SocketDemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
\ No newline at end of file
<resources>
<string name="app_name">SocketDemo</string>
</resources>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.SocketDemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
package com.wmdigit.socketdemo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
\ No newline at end of file
#Thu Apr 22 17:23:35 GMT+08:00 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
include ':app'
rootProject.name = "SocketDemo"
include ':Transfer'
include ':DigiTransfer'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment