Skip to content

Commit 3e939a6

Browse files
WallaceSitWallaceSit
WallaceSit
authored and
WallaceSit
committed
v2.14.31-36
v2.14.31-36: • App: correct the problem of no wedge and mqtt in previous version v2.14.30-36: • App, Library: correct the problem of no vibration during RFID inventory when vibration is set • App, Library: revise debug messages, add protection codes for possible exceptions v2.14.29-35: • App, Wedge: show back the “start wedge” button • App, Main: show “Foreground service in action” with hidden some irrelevant button when foreground service is enabled • App, Wedge: avoid auto set foreground service after entering wedge page • App: change back to use 108Library • App: revise debug messages, rename code names, remove some unused codes • Library108: Add protection code for possible exceptions v2.14.28-8.37.34: • App, Connection: Solve the problem of the pixel phone unable to be scanned after disconnection • App, Wedge: add output format selection options, save the settings to library and file • App, Wedge: add barcode inventory • App, Forward Service: add permission check, handle possible connection failure, kill running service when destroying service • App: Rename some codes, relocate some codes, revise some debug messages, add some protection codes for possible exception • Library: Avoid sending A008 and above notification packets out if the controller version is 1.0.15 or below • Library: Try shortening the time before inventory • Library: relocate some codes, revise debug messages, add some protection code for exception, remove some unused codes
1 parent bf65899 commit 3e939a6

File tree

139 files changed

+9603
-7262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+9603
-7262
lines changed

android/FakeDependency.jar

22 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ android {
66
buildConfig true
77
}
88

9-
compileSdk 34
9+
compileSdk 35
1010
defaultConfig {
1111
applicationId "com.csl.cs108ademoapp"
1212
minSdk 23
13-
targetSdk 34
14-
versionCode 41
15-
versionName "2.14.7"
13+
targetSdk 35
14+
versionCode 42
15+
versionName "2.14.31"
1616
}
1717
}
1818

@@ -22,6 +22,5 @@ dependencies {
2222
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
2323
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
2424
implementation 'com.github.hannesa2:paho.mqtt.android:4.3.beta2'
25-
implementation project(':cs108library4a')
2625
implementation project(':cslibrary4a')
2726
}
Binary file not shown.
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
99
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1010

11+
<uses-permission android:name="android.permission.BLUETOOTH" />
1112
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
1213
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
1314

@@ -28,23 +29,24 @@
2829
<application
2930
android:usesCleartextTraffic="true" tools:targetApi="28"
3031
android:allowBackup="true"
32+
android:label="@string/app_name_cs108"
3133
android:icon="@drawable/csl_logo"
32-
android:label="@string/app_name"
3334
android:supportsRtl="true"
3435
android:requestLegacyExternalStorage="true"
3536
android:theme="@style/AppTheme">
3637

3738
<service
3839
android:enabled="true"
39-
android:name=".MyForegroundService"
40+
android:name="MyForegroundService"
4041
android:foregroundServiceType="location"
4142
android:exported="false"
4243
android:stopWithTask="true" />
4344

4445
<service android:name="CustomIME"
45-
android:label="@string/app_ime"
46+
android:label="@string/app_ime_cs108"
4647
android:exported="true"
4748
android:permission="android.permission.BIND_INPUT_METHOD">
49+
4850
<intent-filter>
4951
<action android:name="android.view.InputMethod" />
5052
</intent-filter>
@@ -55,16 +57,17 @@
5557
android:name="MainActivity"
5658
android:exported="true"
5759
android:screenOrientation="portrait">
58-
<intent-filter>
59-
<action android:name="android.intent.action.MAIN" />
60-
<category android:name="android.intent.category.LAUNCHER" />
61-
</intent-filter>
6260

6361
<intent-filter>
6462
<action android:name="android.nfc.action.ACTION_TAG_DISCOVERED" />
6563
<category android:name="android.intent.category.DEFAULT" />
6664
<data android:mimeType="text/plain" />
6765
</intent-filter>
66+
67+
<intent-filter>
68+
<action android:name="android.intent.action.MAIN" />
69+
<category android:name="android.intent.category.LAUNCHER" />
70+
</intent-filter>
6871
</activity>
6972
</application>
7073
</manifest>

app/src/main/java/com/csl/cs108ademoapp/CustomAlertDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void onClick(DialogInterface dialog, int buttonId) {
2828
ans_false.run();
2929
}
3030
});
31-
dialog.setIcon(android.R.drawable.ic_dialog_alert);
31+
dialog.setIcon(R.drawable.alert);
3232
dialog.show();
3333
return true;
3434
}

app/src/main/java/com/csl/cs108ademoapp/CustomIME.java

Lines changed: 148 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,40 @@
1212

1313
import com.csl.cslibrary4a.RfidReaderChipData;
1414

15+
import java.io.IOException;
16+
import java.net.DatagramPacket;
17+
import java.net.DatagramSocket;
18+
import java.net.InetAddress;
19+
import java.net.SocketException;
1520
import java.util.ArrayList;
1621

1722
import static android.content.ContentValues.TAG;
1823

1924
public class CustomIME extends InputMethodService { //implements KeyboardView.OnKeyboardActionListener {
2025
Handler mHandler = new Handler();
26+
InputConnection ic;
27+
DatagramSocket datagramSocket;
28+
InetAddress hostAddress = null;
2129

2230
@Override
2331
public void onCreate() {
2432
super.onCreate();
33+
try {
34+
hostAddress = hostAddress = InetAddress.getByName("127.0.0.1");
35+
Log.i("Hello", "udpSocket hostAddress is valid");
36+
datagramSocket = new DatagramSocket(9394, hostAddress);
37+
if (datagramSocket == null) Log.i("Hello", "udpSocket is null");
38+
else Log.i("Hello", "udpSocket is valid");
39+
//byte[] buffer = new byte[16];
40+
//DatagramPacket packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName("localhost"), 14552);
41+
//udpsocket.send(packet);
42+
} catch (SocketException e) {
43+
Log.e("UDP: ", "udpSocket Socket Error: ", e);
44+
} catch (IOException e) {
45+
Log.e("UDP Send: ", "udpSocket IO Error", e);
46+
} catch (Exception ex) {
47+
Log.i("Hello", "udpSocket Exception Error: " + ex.getMessage());
48+
}
2549
appendToLog("CustomIME.onCreate()");
2650
}
2751
@Override
@@ -35,81 +59,139 @@ public View onCreateInputView() {
3559
keyboardView.setKeyboard(keyboard);
3660
//keyboardView.setOnKeyboardActionListener(this);
3761
}
62+
ic = getCurrentInputConnection();
63+
Log.i("Hello", "udpSocket inputConnection is " + (ic == null ? "null" : "valid"));
3864
return keyboardView;
3965
}
4066
@Override
4167
public void onDestroy() {
4268
appendToLog("CustomIME.onDestroy()");
4369
mHandler.removeCallbacks(serviceRunnable);
70+
datagramSocket.close();
4471
super.onDestroy();
4572
}
4673

74+
Runnable yourRunnable = new Runnable() {
75+
@Override
76+
public void run() {
77+
byte[] buffer = new byte[250];
78+
Log.i("Hello", "udpSocket yourRunnable starts");
79+
DatagramPacket datagramPacket = new DatagramPacket(buffer, buffer.length);
80+
ic = getCurrentInputConnection();
81+
try {
82+
Log.i("Hello", "udpSocket try starts");
83+
// String outString = "Client say: bye bye";
84+
// buffer = outString.getBytes();
85+
// DatagramPacket outDatagramPackat = new DatagramPacket(buffer, buffer.length, hostAddress, 9394);
86+
// datagramSocket.send(outDatagramPackat);
87+
// Log.i("Hello", "udpSocket sent data");
88+
89+
String strDataReceived;
90+
do {
91+
strDataReceived = null;
92+
datagramSocket.receive(datagramPacket);
93+
strDataReceived = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
94+
Log.i("Hello", "udpSocket received data: " + strDataReceived);
95+
ic.commitText(strDataReceived, 1);
96+
} while (strDataReceived != null && strDataReceived.length() != 0);
97+
} catch (IOException ex) {
98+
Log.i("Hello", "udpSocket receive IOException Error: " + ex.toString());
99+
}
100+
}
101+
};
102+
47103
ArrayList<String> epcArrayList = new ArrayList<String>();
48104
InventoryRfidTask inventoryRfidTask;
105+
InventoryBarcodeTask inventoryBarcodeTask;
49106
boolean inventoring = false;
50107
private Runnable serviceRunnable = new Runnable() {
51108
@Override
52109
public void run() {
53110
String strCurrentIME = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
54111
String strCompare = getPackageName();
55112
appendToLog("CustomIME Debug 0 with strCurrentIME = " + strCurrentIME + ", strCompare = " + strCompare);
56-
if (strCurrentIME.contains(strCompare) == false) return;
57-
58-
mHandler.postDelayed(serviceRunnable, 1000);
59-
if (MainActivity.sharedObjects == null) return;
60-
if (MainActivity.csLibrary4A == null) return;
61-
62-
if (inventoring == false) { MainActivity.sharedObjects.serviceArrayList.clear(); epcArrayList.clear(); }
63-
if (MainActivity.mContext == null) return;
64-
appendToLog("CustomIME Debug 1 with activityActive = " + MainActivity.activityActive + ", wedged = " + MainActivity.wedged + ", isBleConnected = " + MainActivity.csLibrary4A.isBleConnected());
65-
if (MainActivity.activityActive == false /*&& MainActivity.wedged*/ && MainActivity.csLibrary4A.isBleConnected()) {
66-
if (MainActivity.csLibrary4A.getTriggerButtonStatus() == false) {
67-
appendToLog("CustomIME Debug 2");
68-
startStopHandler();
69-
inventoring = false;
70-
} else if (inventoring == false) {
71-
appendToLog("CustomIME Debug 3");
72-
if (MainActivity.sharedObjects.runningInventoryRfidTask == false && MainActivity.sharedObjects.runningInventoryBarcodeTask == false && MainActivity.csLibrary4A.mrfidToWriteSize() == 0) {
113+
if (strCurrentIME.contains(strCompare) == false) { }
114+
else if (MainActivity.sharedObjects == null || MainActivity.csLibrary4A == null) {
115+
if (false) { new Thread(yourRunnable).start(); }
116+
}
117+
else if (MainActivity.mContext == null) return;
118+
else {
119+
if (inventoring == false) {
120+
MainActivity.sharedObjects.serviceArrayList.clear();
121+
epcArrayList.clear();
122+
}
123+
appendToLog("CustomIME Debug 1 with activityActive = " + MainActivity.activityActive + ", wedged = " + MainActivity.wedged + ", isBleConnected = " + MainActivity.csLibrary4A.isBleConnected());
124+
if (MainActivity.activityActive == false /*&& MainActivity.wedged*/ && MainActivity.csLibrary4A.isBleConnected()) {
125+
if (MainActivity.csLibrary4A.getTriggerButtonStatus() == false) {
126+
appendToLog("CustomIME Debug 2 with runningInventoryRfidTask = " + MainActivity.sharedObjects.runningInventoryRfidTask);
127+
appendToLog("CustomIME Debug 2 with runningInventoryBarcodeTask = " + MainActivity.sharedObjects.runningInventoryBarcodeTask);
73128
startStopHandler();
74-
inventoring = true;
75-
}
76-
} else {
77-
appendToLog("CustomIME Debug 4");
78-
while (MainActivity.sharedObjects.serviceArrayList.size() != 0) {
79-
String strEpc = MainActivity.sharedObjects.serviceArrayList.get(0); MainActivity.sharedObjects.serviceArrayList.remove(0);
80-
boolean matched = false;
81-
for (int i = 0; i < epcArrayList.size(); i++) {
82-
if (epcArrayList.get(i).matches(strEpc)) {
83-
matched = true;
84-
break;
85-
}
129+
inventoring = false;
130+
} else if (inventoring == false) {
131+
appendToLog("CustomIME Debug 3 with runningInventoryRfidTask = " + MainActivity.sharedObjects.runningInventoryRfidTask + ", and mrfidToWriteSize = " + MainActivity.csLibrary4A.mrfidToWriteSize());
132+
appendToLog("CustomIME Debug 3 with runningInventoryBarcodeTask = " + MainActivity.sharedObjects.runningInventoryBarcodeTask);
133+
if (MainActivity.sharedObjects.runningInventoryRfidTask == false && MainActivity.sharedObjects.runningInventoryBarcodeTask == false && MainActivity.csLibrary4A.mrfidToWriteSize() == 0) {
134+
startStopHandler();
135+
inventoring = true;
86136
}
87-
if (matched == false && strEpc != null) {
88-
epcArrayList.add(strEpc);
89-
InputConnection ic = getCurrentInputConnection();
90-
if (MainActivity.wedgePrefix != null) strEpc = MainActivity.wedgePrefix + strEpc;
91-
if (MainActivity.wedgeSuffix != null) strEpc += MainActivity.wedgeSuffix;
92-
switch (MainActivity.wedgeDelimiter) {
93-
default:
94-
strEpc += "\n";
95-
break;
96-
case 0x09:
97-
strEpc += "\t";
98-
break;
99-
case 0x2C:
100-
strEpc += ",";
101-
break;
102-
case 0x20:
103-
strEpc += " ";
104-
break;
105-
case -1:
106-
break;
137+
} else {
138+
appendToLog("CustomIME Debug 4");
139+
while (MainActivity.sharedObjects.serviceArrayList.size() != 0) {
140+
String strEpc = MainActivity.sharedObjects.serviceArrayList.get(0);
141+
MainActivity.sharedObjects.serviceArrayList.remove(0);
142+
appendToLog("CustomIME Debug 4A with strEpc = " + strEpc);
143+
String strSgtin = null;
144+
if (MainActivity.csLibrary4A.getWedgeOutput() == 1) {
145+
strSgtin = MainActivity.csLibrary4A.getUpcSerial(strEpc);
146+
MainActivity.csLibrary4A.appendToLog("strSgtin = " + (strSgtin == null ? "null" : strSgtin));
147+
if (strSgtin == null) strEpc = null;
148+
}
149+
boolean matched = false;
150+
if (epcArrayList != null && strEpc != null) {
151+
for (int i = 0; i < epcArrayList.size(); i++) {
152+
if (epcArrayList.get(i).matches(strEpc)) {
153+
matched = true;
154+
break;
155+
}
156+
}
157+
}
158+
if (matched == false && strEpc != null) {
159+
epcArrayList.add(strEpc);
160+
InputConnection ic = getCurrentInputConnection();
161+
String strValue = strEpc;
162+
if (strSgtin != null) strValue = strSgtin;
163+
if (MainActivity.csLibrary4A.getWedgePrefix() != null)
164+
strValue = MainActivity.csLibrary4A.getWedgePrefix() + strValue;
165+
if (MainActivity.csLibrary4A.getWedgeSuffix() != null)
166+
strValue += MainActivity.csLibrary4A.getWedgeSuffix();
167+
MainActivity.csLibrary4A.appendToLog("CustomIME, serviceRunnable: wedgeDelimiter = " + MainActivity.csLibrary4A.getWedgeDelimiter());
168+
switch (MainActivity.csLibrary4A.getWedgeDelimiter()) {
169+
default:
170+
strValue += "\n";
171+
break;
172+
case 0x09:
173+
strValue += "\t";
174+
break;
175+
case 0x2C:
176+
strValue += ",";
177+
break;
178+
case 0x20:
179+
strValue += " ";
180+
break;
181+
case -1:
182+
break;
183+
}
184+
MainActivity.csLibrary4A.appendToLog("CustomIME BtData to Keyboard: " + strValue);
185+
ic.commitText(strValue, 1);
107186
}
108-
ic.commitText(strEpc, 1);
109187
}
110188
}
111189
}
112190
}
191+
int iDelayms = 500;
192+
if (inventoring) iDelayms = 100;
193+
MainActivity.csLibrary4A.appendToLog("CustomIME BtData set next time as " + iDelayms);
194+
mHandler.postDelayed(serviceRunnable, iDelayms);
113195
}
114196
};
115197

@@ -121,17 +203,26 @@ void startStopHandler() {
121203
if (inventoryRfidTask != null) {
122204
if (inventoryRfidTask.getStatus() == AsyncTask.Status.RUNNING) started = true;
123205
}
206+
if (inventoryBarcodeTask != null) {
207+
if (inventoryBarcodeTask.getStatus() == AsyncTask.Status.RUNNING) started = true;
208+
}
124209
appendToLog("CustomIME Debug 10");
125210
if ((started && MainActivity.csLibrary4A.getTriggerButtonStatus()) || (started == false && MainActivity.csLibrary4A.getTriggerButtonStatus() == false)) return;
126211
if (started == false) {
212+
appendToLog("CustomIME Debug 11 with BtData wedgeOutput = " + MainActivity.csLibrary4A.getWedgeOutput());
213+
if (MainActivity.csLibrary4A.getWedgeOutput() == 2) {
214+
inventoryBarcodeTask = new InventoryBarcodeTask();
215+
inventoryBarcodeTask.execute();
216+
} else {
217+
MainActivity.csLibrary4A.setPowerLevel(MainActivity.csLibrary4A.getWedgePower());
218+
MainActivity.csLibrary4A.startOperation(RfidReaderChipData.OperationTypes.TAG_INVENTORY_COMPACT);
219+
inventoryRfidTask = new InventoryRfidTask();
220+
inventoryRfidTask.execute();
221+
}
222+
} else {
127223
appendToLog("CustomIME Debug 11");
128-
MainActivity.csLibrary4A.startOperation(RfidReaderChipData.OperationTypes.TAG_INVENTORY);
129-
inventoryRfidTask = new InventoryRfidTask();
130-
inventoryRfidTask.execute();
131-
}
132-
else {
133-
appendToLog("CustomIME Debug 11");
134-
inventoryRfidTask.taskCancelReason = InventoryRfidTask.TaskCancelRReason.BUTTON_RELEASE;
224+
if (inventoryRfidTask != null) inventoryRfidTask.taskCancelReason = InventoryRfidTask.TaskCancelRReason.BUTTON_RELEASE;
225+
if (inventoryBarcodeTask != null) inventoryBarcodeTask.taskCancelReason = InventoryBarcodeTask.TaskCancelRReason.BUTTON_RELEASE;
135226
}
136227
}
137228
}

0 commit comments

Comments
 (0)