diff --git a/app/build.gradle b/app/build.gradle index f9a2be8..9b4e713 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,19 +1,26 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 33 + namespace 'com.csl.cs710awedgeapp' + buildFeatures { + buildConfig true + } + + compileSdk 34 defaultConfig { applicationId "com.csl.cs710awedgeapp" - minSdkVersion 21 - targetSdkVersion 33 - versionCode 5 - versionName "5.9.11" + minSdk 23 + targetSdk 34 + versionCode 13 + versionName "5.14.23" } - namespace 'com.csl.cs710awedgeapp' } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.google.android.material:material:1.9.0' - implementation project(path: ':cs710library4a') -} + implementation 'com.google.android.material:material:1.12.0' + implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'com.github.hannesa2:paho.mqtt.android:4.3.beta2' + implementation project(':cslibrary4a') +} \ No newline at end of file diff --git a/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.apk b/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.apk deleted file mode 100644 index 4b12786..0000000 Binary files a/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.apk and /dev/null differ diff --git a/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.zip b/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.zip deleted file mode 100644 index 75bf2dc..0000000 Binary files a/app/release/JAVAwedgeCS710SCS108-20230915-v5.9.11-2-6-7-app-release.zip and /dev/null differ diff --git a/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.aab b/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.aab new file mode 100644 index 0000000..fd58a47 Binary files /dev/null and b/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.aab differ diff --git a/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.zip b/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.zip new file mode 100644 index 0000000..e1613c4 Binary files /dev/null and b/app/release/JAVAwedgeCS710SCS108-20240826-v5.14.23-6.26.25-app-release.zip differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1cb8656..5483ff8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,26 +1,35 @@ - + - - + + + + + + + + + - - + + + @@ -31,16 +40,17 @@ android:name="MainActivity" android:exported="true" android:screenOrientation="portrait"> - - - - + + + + + \ No newline at end of file diff --git a/cs108library4a/src/main/java/com/csl/cs108library4a/CustomAlertDialog.java b/app/src/main/java/com/csl/cs710awedgeapp/CustomAlertDialog.java similarity index 93% rename from cs108library4a/src/main/java/com/csl/cs108library4a/CustomAlertDialog.java rename to app/src/main/java/com/csl/cs710awedgeapp/CustomAlertDialog.java index 49908be..21ba99b 100644 --- a/cs108library4a/src/main/java/com/csl/cs108library4a/CustomAlertDialog.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/CustomAlertDialog.java @@ -1,4 +1,4 @@ -package com.csl.cs108library4a; +package com.csl.cs710awedgeapp; import android.app.Activity; import android.app.AlertDialog; @@ -28,7 +28,7 @@ public void onClick(DialogInterface dialog, int buttonId) { ans_false.run(); } }); - dialog.setIcon(android.R.drawable.ic_dialog_alert); + dialog.setIcon(R.drawable.alert); dialog.show(); return true; } diff --git a/app/src/main/java/com/csl/cs710awedgeapp/CustomIME.java b/app/src/main/java/com/csl/cs710awedgeapp/CustomIME.java index 66bcfb8..64d58ed 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/CustomIME.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/CustomIME.java @@ -10,7 +10,7 @@ import android.view.View; import android.view.inputmethod.InputConnection; -import com.csl.cs710library4a.CsLibrary4A; +import com.csl.cslibrary4a.RfidReaderChipData; import java.util.ArrayList; @@ -46,6 +46,7 @@ public void onDestroy() { ArrayList epcArrayList = new ArrayList(); InventoryRfidTask inventoryRfidTask; + InventoryBarcodeTask inventoryBarcodeTask; boolean inventoring = false; private Runnable serviceRunnable = new Runnable() { @Override @@ -53,63 +54,86 @@ public void run() { String strCurrentIME = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); String strCompare = getPackageName(); appendToLog("CustomIME Debug 0 with strCurrentIME = " + strCurrentIME + ", strCompare = " + strCompare); - if (strCurrentIME.contains(strCompare) == false) return; - - mHandler.postDelayed(serviceRunnable, 1000); - if (MainActivity.sharedObjects == null) return; - if (MainActivity.csLibrary4A == null) return; - - if (inventoring == false) { MainActivity.sharedObjects.serviceArrayList.clear(); epcArrayList.clear(); } - if (MainActivity.mContext == null) return; - appendToLog("CustomIME Debug 1 with activityActive = " + MainActivity.activityActive + ", wedged = " + MainActivity.wedged + ", isBleConnected = " + MainActivity.csLibrary4A.isBleConnected()); - if (MainActivity.activityActive == false /*&& MainActivity.wedged*/ && MainActivity.csLibrary4A.isBleConnected()) { - if (MainActivity.csLibrary4A.getTriggerButtonStatus() == false) { - appendToLog("CustomIME Debug 2"); - startStopHandler(); - inventoring = false; - } else if (inventoring == false) { - appendToLog("CustomIME Debug 3"); - if (MainActivity.sharedObjects.runningInventoryRfidTask == false && MainActivity.sharedObjects.runningInventoryBarcodeTask == false && MainActivity.csLibrary4A.mrfidToWriteSize() == 0) { + if (strCurrentIME.contains(strCompare) == false) { } + else if (MainActivity.sharedObjects == null || MainActivity.csLibrary4A == null) { } + else if (MainActivity.mContext == null) return; + else { + if (inventoring == false) { + MainActivity.sharedObjects.serviceArrayList.clear(); + epcArrayList.clear(); + } + appendToLog("CustomIME Debug 1 with activityActive = " + MainActivity.activityActive + ", wedged = " + MainActivity.wedged + ", isBleConnected = " + MainActivity.csLibrary4A.isBleConnected()); + if (MainActivity.activityActive == false /*&& MainActivity.wedged*/ && MainActivity.csLibrary4A.isBleConnected()) { + if (MainActivity.csLibrary4A.getTriggerButtonStatus() == false) { + appendToLog("CustomIME Debug 2 with runningInventoryRfidTask = " + MainActivity.sharedObjects.runningInventoryRfidTask); + appendToLog("CustomIME Debug 2 with runningInventoryBarcodeTask = " + MainActivity.sharedObjects.runningInventoryBarcodeTask); startStopHandler(); - inventoring = true; - } - } else { - appendToLog("CustomIME Debug 4"); - while (MainActivity.sharedObjects.serviceArrayList.size() != 0) { - String strEpc = MainActivity.sharedObjects.serviceArrayList.get(0); MainActivity.sharedObjects.serviceArrayList.remove(0); - boolean matched = false; - for (int i = 0; i < epcArrayList.size(); i++) { - if (epcArrayList.get(i).matches(strEpc)) { - matched = true; - break; - } + inventoring = false; + } else if (inventoring == false) { + appendToLog("CustomIME Debug 3 with runningInventoryRfidTask = " + MainActivity.sharedObjects.runningInventoryRfidTask + ", and mrfidToWriteSize = " + MainActivity.csLibrary4A.mrfidToWriteSize()); + appendToLog("CustomIME Debug 3 with runningInventoryBarcodeTask = " + MainActivity.sharedObjects.runningInventoryBarcodeTask); + if (MainActivity.sharedObjects.runningInventoryRfidTask == false && MainActivity.sharedObjects.runningInventoryBarcodeTask == false && MainActivity.csLibrary4A.mrfidToWriteSize() == 0) { + startStopHandler(); + inventoring = true; } - if (matched == false && strEpc != null) { - epcArrayList.add(strEpc); - InputConnection ic = getCurrentInputConnection(); - if (MainActivity.wedgePrefix != null) strEpc = MainActivity.wedgePrefix + strEpc; - if (MainActivity.wedgeSuffix != null) strEpc += MainActivity.wedgeSuffix; - switch (MainActivity.wedgeDelimiter) { - default: - strEpc += "\n"; - break; - case 0x09: - strEpc += "\t"; - break; - case 0x2C: - strEpc += ","; - break; - case 0x20: - strEpc += " "; - break; - case -1: - break; + } else { + appendToLog("CustomIME Debug 4"); + while (MainActivity.sharedObjects.serviceArrayList.size() != 0) { + String strEpc = MainActivity.sharedObjects.serviceArrayList.get(0); + MainActivity.sharedObjects.serviceArrayList.remove(0); + appendToLog("CustomIME Debug 4A with strEpc = " + strEpc); + String strSgtin = null; + if (MainActivity.wedgeOutput == 1) { + strSgtin = MainActivity.csLibrary4A.getUpcSerial(strEpc); + MainActivity.csLibrary4A.appendToLog("strSgtin = " + (strSgtin == null ? "null" : strSgtin)); + if (strSgtin == null) strEpc = null; + } + boolean matched = false; + if (epcArrayList != null && strEpc != null) { + for (int i = 0; i < epcArrayList.size(); i++) { + if (epcArrayList.get(i).matches(strEpc)) { + matched = true; + break; + } + } + } + if (matched == false && strEpc != null) { + epcArrayList.add(strEpc); + InputConnection ic = getCurrentInputConnection(); + String strValue = strEpc; + if (strSgtin != null) strValue = strSgtin; + if (MainActivity.wedgePrefix != null) + strValue = MainActivity.wedgePrefix + strValue; + if (MainActivity.wedgeSuffix != null) + strValue += MainActivity.wedgeSuffix; + MainActivity.csLibrary4A.appendToLog("CustomIME, serviceRunnable: wedgeDelimiter = " + MainActivity.wedgeDelimiter); + switch (MainActivity.wedgeDelimiter) { + default: + strValue += "\n"; + break; + case 0x09: + strValue += "\t"; + break; + case 0x2C: + strValue += ","; + break; + case 0x20: + strValue += " "; + break; + case -1: + break; + } + MainActivity.csLibrary4A.appendToLog("CustomIME BtData to Keyboard: " + strValue); + ic.commitText(strValue, 1); } - ic.commitText(strEpc, 1); } } } } + int iDelayms = 500; + if (inventoring) iDelayms = 100; + MainActivity.csLibrary4A.appendToLog("CustomIME BtData set next time as " + iDelayms); + mHandler.postDelayed(serviceRunnable, iDelayms); } }; @@ -121,17 +145,26 @@ void startStopHandler() { if (inventoryRfidTask != null) { if (inventoryRfidTask.getStatus() == AsyncTask.Status.RUNNING) started = true; } + if (inventoryBarcodeTask != null) { + if (inventoryBarcodeTask.getStatus() == AsyncTask.Status.RUNNING) started = true; + } appendToLog("CustomIME Debug 10"); if ((started && MainActivity.csLibrary4A.getTriggerButtonStatus()) || (started == false && MainActivity.csLibrary4A.getTriggerButtonStatus() == false)) return; if (started == false) { + appendToLog("CustomIME Debug 11 with BtData wedgeOutput = " + MainActivity.wedgeOutput); + if (MainActivity.wedgeOutput == 2) { + inventoryBarcodeTask = new InventoryBarcodeTask(); + inventoryBarcodeTask.execute(); + } else { + MainActivity.csLibrary4A.setPowerLevel(MainActivity.wedgePower); + MainActivity.csLibrary4A.startOperation(RfidReaderChipData.OperationTypes.TAG_INVENTORY_COMPACT); + inventoryRfidTask = new InventoryRfidTask(); + inventoryRfidTask.execute(); + } + } else { appendToLog("CustomIME Debug 11"); - MainActivity.csLibrary4A.startOperation(CsLibrary4A.OperationTypes.TAG_INVENTORY); - inventoryRfidTask = new InventoryRfidTask(); - inventoryRfidTask.execute(); - } - else { - appendToLog("CustomIME Debug 11"); - inventoryRfidTask.taskCancelReason = InventoryRfidTask.TaskCancelRReason.BUTTON_RELEASE; + if (inventoryRfidTask != null) inventoryRfidTask.taskCancelReason = InventoryRfidTask.TaskCancelRReason.BUTTON_RELEASE; + if (inventoryBarcodeTask != null) inventoryBarcodeTask.taskCancelReason = InventoryBarcodeTask.TaskCancelRReason.BUTTON_RELEASE; } } } \ No newline at end of file diff --git a/app/src/main/java/com/csl/cs710awedgeapp/DrawerListContent.java b/app/src/main/java/com/csl/cs710awedgeapp/DrawerListContent.java index c3efc77..fdd6251 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/DrawerListContent.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/DrawerListContent.java @@ -26,6 +26,7 @@ public enum DrawerPositions { UCODE8, UCODEDNA, BAPCARD, COLDCHAIN, AURASENSE, KILOWAY, + LONGJING, AXZON, RFMICRON, FDMICRO, CTESIUS, @@ -55,16 +56,17 @@ public static DrawerPositions toDrawerPosition(int x) { case 15: return COLDCHAIN; case 16: return AURASENSE; case 17: return KILOWAY; - case 18: return AXZON; - //case 15: return RFMICRON; - case 19: return FDMICRO; - case 20: return CTESIUS; - case 21: return ASYGNTAG; - - case 22: return REGISTER; - case 23: return READWRITEUSER; - case 24: return WEDGE; - case 25: return DIRECTWEDGE; + case 18: return LONGJING; + case 19: return AXZON; + //case 18: return RFMICRON; + case 20: return FDMICRO; + case 21: return CTESIUS; + case 22: return ASYGNTAG; + + case 23: return REGISTER; + case 24: return READWRITEUSER; + case 25: return WEDGE; + case 26: return DIRECTWEDGE; } return null; } @@ -84,8 +86,6 @@ public static DrawerPositions toDrawerPosition(int x) { addItem(new DrawerItem("9", "Security", R.drawable.dl_access)); addItem(new DrawerItem("10", "Impinj Special Features", R.drawable.dl_loc)); - //addItem(new DrawerItem("10", "Impinj M775", R.drawable.dl_loc)); - //addItem(new DrawerItem("11", "Impinj Autotune", R.drawable.dl_loc)); addItem(new DrawerItem("11", "Alien", R.drawable.dl_loc)); addItem(new DrawerItem("12", "NXP UCODE 8", R.drawable.dl_loc)); addItem(new DrawerItem("13", "NXP UCODE DNA", R.drawable.dl_loc)); @@ -93,16 +93,16 @@ public static DrawerPositions toDrawerPosition(int x) { addItem(new DrawerItem("15", "uEm Cold Chain CS8300", R.drawable.dl_loc)); addItem(new DrawerItem("16", "uEm Aura-sense", R.drawable.dl_loc)); addItem(new DrawerItem("17", "Kiloway KX2005X-BL", R.drawable.dl_rr)); - addItem(new DrawerItem("18", "Axzon", R.drawable.dl_loc)); - //addItem(new DrawerItem("18", "Axzon Magnus", R.drawable.dl_loc)); - addItem(new DrawerItem("19", "FM13DT160", R.drawable.dl_loc)); - addItem(new DrawerItem("20", "Landa CTESIUS", R.drawable.dl_loc)); - addItem(new DrawerItem("21", "Asygn AS321x", R.drawable.dl_loc)); - - addItem(new DrawerItem("22", "Register Tag", R.drawable.dl_rr)); - addItem(new DrawerItem("23", "Large sized memory read/write", R.drawable.dl_rr)); - addItem(new DrawerItem("24", "Wedge", R.drawable.dl_rr)); - addItem(new DrawerItem("25", "Direct Wedge", R.drawable.dl_rr)); + addItem(new DrawerItem("18", "EL-N2ESL CS6861", R.drawable.dl_rr)); + addItem(new DrawerItem("19", "Axzon", R.drawable.dl_loc)); + addItem(new DrawerItem("20", "FM13DT160", R.drawable.dl_loc)); + addItem(new DrawerItem("21", "Landa CTESIUS", R.drawable.dl_loc)); + addItem(new DrawerItem("22", "Asygn AS321x", R.drawable.dl_loc)); + + addItem(new DrawerItem("23", "Register Tag", R.drawable.dl_rr)); + addItem(new DrawerItem("24", "Large sized memory read/write", R.drawable.dl_rr)); + addItem(new DrawerItem("25", "Wedge", R.drawable.dl_rr)); + addItem(new DrawerItem("26", "Direct Wedge", R.drawable.dl_rr)); } private static void addItem(DrawerItem item) { diff --git a/app/src/main/java/com/csl/cs710awedgeapp/InventoryBarcodeTask.java b/app/src/main/java/com/csl/cs710awedgeapp/InventoryBarcodeTask.java new file mode 100644 index 0000000..d575212 --- /dev/null +++ b/app/src/main/java/com/csl/cs710awedgeapp/InventoryBarcodeTask.java @@ -0,0 +1,290 @@ +package com.csl.cs710awedgeapp; + +import android.os.AsyncTask; +import android.os.Handler; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.csl.cs710awedgeapp.adapters.ReaderListAdapter; +import com.csl.cslibrary4a.ReaderDevice; + +import java.util.ArrayList; + +public class InventoryBarcodeTask extends AsyncTask { + final boolean DEBUG = false, ALLOW_WEDGE = true; + public enum TaskCancelRReason { + NULL, INVALD_REQUEST, DESTORY, STOP, BUTTON_RELEASE, TIMEOUT + } + final private boolean bAdd2End = false; + final boolean endingRequest = false; + + public TaskCancelRReason taskCancelReason; + int batteryCountInventory_old; long startTimeMillis, runTimeMillis; + + private int total, allTotal; + private int yield = 0; + private long timeMillis; + + boolean requestSound = false; boolean requestNewSound = false; boolean requestNewVibrate = false; long timeMillisNewVibrate; + long timeMillisSound = 0; + Handler handler = new Handler(); boolean bUseVibrateMode0 = false; + + protected void onPreExecute() { + MainActivity.sharedObjects.runningInventoryBarcodeTask = true; + if (button != null) button.setText("Stop"); if (button1 != null) button1.setText("Stop"); + total = 0; allTotal = 0; yield = 0; + if (tagsList != null) { + yield = tagsList.size(); + for (int i = 0; i < yield; i++) { + allTotal += tagsList.get(i).getCount(); + } + } +// tagsList.clear(); +// readerListAdapter.notifyDataSetChanged(); + timeMillis = 0; startTimeMillis = System.currentTimeMillis(); runTimeMillis = startTimeMillis; + taskCancelReason = TaskCancelRReason.NULL; + if (barcodeYieldView != null) barcodeYieldView.setText(""); + + MainActivity.csLibrary4A.barcodeInventory(true); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("InventoryBarcodeFragment.InventoryRfidTask.onPreExecute()"); + if (MainActivity.csLibrary4A.getInventoryVibrate() && bUseVibrateMode0 == false) MainActivity.csLibrary4A.setVibrateOn(3); + } + + @Override + protected String doInBackground(Void... a) { + while (MainActivity.csLibrary4A.isBleConnected() && isCancelled() == false) { + int batteryCount = MainActivity.csLibrary4A.getBatteryCount(); + if (batteryCountInventory_old != batteryCount) { + batteryCountInventory_old = batteryCount; + publishProgress("VV"); + } + if (System.currentTimeMillis() > runTimeMillis + 1000) { + runTimeMillis = System.currentTimeMillis(); + publishProgress("WW"); + } + if (System.currentTimeMillis() - timeMillisSound > 1000) { + timeMillisSound = System.currentTimeMillis(); + requestSound = true; + } + byte[] onBarcodeEvent = MainActivity.csLibrary4A.onBarcodeEvent(); + if (onBarcodeEvent != null) { + MainActivity.csLibrary4A.appendToLog("BarStream: onBarcodeEvent= " + MainActivity.csLibrary4A.byteArrayToString(onBarcodeEvent)); + String stringBar = null; + if (true) stringBar = new String(onBarcodeEvent); + else if (onBarcodeEvent.length != 0) { + for (int i = 0; i < onBarcodeEvent.length; i++) { + String stringLetter = ""; + if (false && onBarcodeEvent[i] == 0x0D) { if (false) stringLetter = ""; } + else if (false && onBarcodeEvent[i] == 0x0A) { if (false) stringLetter = ""; } + else { + byte[] arrayLetter = new byte[1]; + arrayLetter[0] = onBarcodeEvent[i]; + stringLetter = new String(arrayLetter); + if (stringLetter.length() == 0) MainActivity.csLibrary4A.appendToLog("Non-printable character = " + MainActivity.csLibrary4A.byteArrayToString(arrayLetter)); + } + if (stringBar == null) stringBar = stringLetter; + else stringBar += stringLetter; + } + } + MainActivity.csLibrary4A.appendToLog("BarStream: onBarcodeEvent, stringBar= " + stringBar); + if (stringBar != null) { if (stringBar.length() != 0) { publishProgress(null, stringBar.trim()); } } + timeMillis = System.currentTimeMillis(); + } else if (System.currentTimeMillis() - timeMillis > 300) { if (taskCancelReason != TaskCancelRReason.NULL) cancel(true); } + if (MainActivity.csLibrary4A.isBleConnected() == false) taskCancelReason = TaskCancelRReason.DESTORY; + } + return "End of Asynctask()"; + } + + @Override + protected void onProgressUpdate(String... output) { + if (output != null) { + if (output[0] != null) { + if (output[0].length() == 2) { + if (output[0].contains("WW")) { + long timePeriod = (System.currentTimeMillis() - startTimeMillis) / 1000; + if (timePeriod > 0) + if (barcodeRunTime != null) barcodeRunTime.setText(String.format("Run time: %d sec", timePeriod)); + } else if (taskCancelReason == TaskCancelRReason.NULL) { + if (barcodeVoltageLevel != null) barcodeVoltageLevel.setText(MainActivity.csLibrary4A.getBatteryDisplay(true)); + } + } + return; + } + if (registerBarValue != null) registerBarValue.setText(output[1]); + boolean match = false; + if (false || tagsList != null) { + MainActivity.csLibrary4A.appendToLog("BarMatch: Matching bdata = " + output[1]); + for (int i = 0; i < tagsList.size(); i++) { + String strInList = tagsList.get(i).getAddress(); + if (output[1].length() == strInList.length() && output[1].indexOf(strInList) == 0) { + MainActivity.csLibrary4A.appendToLog("BarMatch: Matched stored bdata" + i + "= " + tagsList.get(i).getAddress()); + ReaderDevice readerDevice = tagsList.get(i); + int count = readerDevice.getCount(); + count++; + readerDevice.setCount(count); + tagsList.set(i, readerDevice); + match = true; + break; + } else MainActivity.csLibrary4A.appendToLog("BarMatch: NOT Matched stored bdata" + i + "= " + tagsList.get(i).getAddress()); + } + } + if (match == false) { + if (ALLOW_WEDGE) MainActivity.sharedObjects.serviceArrayList.add(output[1]); + MainActivity.csLibrary4A.appendToLog(output[1] + " is added to MainActivity.shareObjects.serviceArrayList with size = " + MainActivity.sharedObjects.serviceArrayList.size()); + + ReaderDevice readerDevice = new ReaderDevice("", output[1], false, "", 1, 0); + if (tagsList != null) { + if (bAdd2End) tagsList.add(readerDevice); + else tagsList.add(0, readerDevice); + } + yield++; + if (barcodeYieldView != null) barcodeYieldView.setText("Unique:" + String.valueOf(yield)); + requestNewSound = true; requestNewVibrate = true; + } + total++; allTotal++; + if (barcodeRateView != null) barcodeRateView.setText("Total:" + String.valueOf(allTotal)); + if (readerListAdapter != null) readerListAdapter.notifyDataSetChanged(); + + if (playerN != null && playerO != null) { + if (requestSound && playerO.isPlaying() == false && playerN.isPlaying() == false) { + if (true) { + if (bStartBeepWaiting == false) { + bStartBeepWaiting = true; + handler.postDelayed(runnableStartBeep, 250); + } + if (MainActivity.csLibrary4A.getInventoryVibrate()) { + boolean validVibrate0 = false, validVibrate = false; + if (MainActivity.csLibrary4A.getVibrateModeSetting() == 0) { + if (requestNewVibrate) validVibrate0 = true; + } else validVibrate0 = true; + requestNewVibrate = false; + + if (bUseVibrateMode0 && validVibrate0 && bStartVibrateWaiting == false) { + if (System.currentTimeMillis() - timeMillisNewVibrate > MainActivity.csLibrary4A.getVibrateWindow() * 1000 ) { + timeMillisNewVibrate = System.currentTimeMillis(); + validVibrate = true; + } + } + if (validVibrate) { + MainActivity.csLibrary4A.setVibrateOn(1); + bStartVibrateWaiting = true; + handler.postDelayed(runnableStartVibrate, MainActivity.csLibrary4A.getVibrateTime()); + } + } + } else { + requestSound = false; + if (requestNewSound) { + requestNewSound = false; + if (playerN != null) playerN.start(); + } else { + if (playerO != null) playerO.start(); + } + } + } + } + } else { + if (DEBUG) MainActivity.csLibrary4A.appendToLog("InventoryBarcodeFragment with NULL data"); + } + } + + boolean bStartBeepWaiting = false; + Runnable runnableStartBeep = new Runnable() { + @Override + public void run() { + bStartBeepWaiting = false; + requestSound = false; + if (requestNewSound) { + requestNewSound = false; + playerN.start(); //playerN.setVolume(300, 300); + } else { + playerO.start(); //playerO.setVolume(30, 30); + } + } + }; + + boolean bStartVibrateWaiting = false; + Runnable runnableStartVibrate = new Runnable() { + @Override + public void run() { + bStartVibrateWaiting = false; + } + }; + + @Override + protected void onCancelled() { + super.onCancelled(); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("InventoryBarcodeFragment() onCancelled()"); + + DeviceConnectTask4InventoryEnding(taskCancelReason); + } + + @Override + protected void onPostExecute(String result) { + if (DEBUG) MainActivity.csLibrary4A.appendToLog("InventoryBarcodeFragment() onPostExecute(): " + result); + + DeviceConnectTask4InventoryEnding(taskCancelReason); + } + + private EditText registerBarValue; + private ArrayList tagsList; + private ReaderListAdapter readerListAdapter; + private TextView barcodeRunTime, barcodeVoltageLevel; + private TextView barcodeYieldView; + private Button button, button1; String textButton, btextButton1; + private TextView barcodeRateView; + private boolean noToast; + CustomMediaPlayer playerO, playerN; + public InventoryBarcodeTask() { } + public InventoryBarcodeTask(ArrayList tagsList, ReaderListAdapter readerListAdapter, EditText registerBarValue, + TextView barcodeRunTime, TextView barcodeVoltageLevel, + TextView barcodeYieldView, Button button, Button button1, TextView barcodeRateView, boolean noToast) { + this.registerBarValue = registerBarValue; + this.tagsList = tagsList; + this.readerListAdapter = readerListAdapter; + this.barcodeRunTime = barcodeRunTime; + this.barcodeVoltageLevel = barcodeVoltageLevel; + this.barcodeYieldView = barcodeYieldView; + this.button = button; textButton = button.getText().toString(); + this.button1 = button1; if (button1 != null) btextButton1 = button1.getText().toString(); + this.barcodeRateView = barcodeRateView; + this.noToast = noToast; + + playerO = MainActivity.sharedObjects.playerO; + playerN = MainActivity.sharedObjects.playerN; + } + + void DeviceConnectTask4InventoryEnding(TaskCancelRReason taskCancelRReason) { + if (readerListAdapter != null) readerListAdapter.notifyDataSetChanged(); + MainActivity.csLibrary4A.barcodeInventory(false); + if (true) MainActivity.csLibrary4A.appendToLog("DeviceConnectTask4InventoryEnding(): sent setBarcodeOn(false)"); + if (taskCancelReason == null) { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + if (noToast == false) Toast.makeText(MainActivity.mContext, R.string.toast_abort_by_END, Toast.LENGTH_SHORT).show(); + button.setText(textButton); + if (button1 != null) button1.setText(btextButton1); + } + }, 5000); + } else { + if (endingRequest) { + switch (taskCancelReason) { + case STOP: + if (noToast == false) + Toast.makeText(MainActivity.mContext, R.string.toast_abort_by_STOP, Toast.LENGTH_SHORT).show(); + break; + case BUTTON_RELEASE: + if (noToast == false) + Toast.makeText(MainActivity.mContext, R.string.toast_abort_by_BUTTON, Toast.LENGTH_SHORT).show(); + break; + } + } + if (button != null) button.setText(textButton); + if (button1 != null) button1.setText(btextButton1); + } + MainActivity.sharedObjects.runningInventoryBarcodeTask = false; + MainActivity.csLibrary4A.setVibrateOn(0); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/csl/cs710awedgeapp/InventoryRfidTask.java b/app/src/main/java/com/csl/cs710awedgeapp/InventoryRfidTask.java index 1154590..aaca130 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/InventoryRfidTask.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/InventoryRfidTask.java @@ -8,8 +8,8 @@ import android.widget.Toast; import com.csl.cs710awedgeapp.adapters.ReaderListAdapter; -import com.csl.cs710library4a.CsLibrary4A; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cslibrary4a.ReaderDevice; +import com.csl.cslibrary4a.RfidReaderChipData; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -19,13 +19,14 @@ public class InventoryRfidTask extends AsyncTask { final boolean DEBUG = false; final boolean ALLOW_WEDGE = true; boolean ALLOW_RTSAVE = false; public enum TaskCancelRReason { - NULL, INVALD_REQUEST, DESTORY, STOP, BUTTON_RELEASE, TIMEOUT, RFID_RESET + NULL, INVALD_REQUEST, DESTORY, STOP, BUTTON_RELEASE, TIMEOUT, RFID_RESET, ERROR } final private boolean bAdd2End = false; final boolean endingRequest = true; Context context; public TaskCancelRReason taskCancelReason; + public boolean bSgtinOnly = false, bProtectOnly; private boolean invalidRequest; boolean beepEnable; @@ -54,7 +55,7 @@ public enum TaskCancelRReason { boolean requestSound = false; boolean requestNewSound = false; boolean requestNewVibrate = false; long timeMillisNewVibrate; String strEpcOld = ""; - private ArrayList rx000pkgDataArrary = new ArrayList(); + private ArrayList rx000pkgDataArrary = new ArrayList(); private String endingMessaage; SaveList2ExternalTask saveExternalTask; @@ -71,9 +72,7 @@ void inventoryHandler_setup() { } MainActivity.csLibrary4A.appendToLog("yield = " + yield + ", allTotal = " + allTotal); } - MainActivity.csLibrary4A.invalidata = 0; - MainActivity.csLibrary4A.invalidUpdata = 0; - MainActivity.csLibrary4A.validata = 0; + MainActivity.csLibrary4A.clearInvalidata(); timeMillis = System.currentTimeMillis(); startTimeMillis = System.currentTimeMillis(); runTimeMillis = startTimeMillis; firstTime = 0; @@ -93,12 +92,11 @@ void inventoryHandler_setup() { MainActivity.mSensorConnector.mLocationDevice.turnOn(true); MainActivity.mSensorConnector.mSensorDevice.turnOn(true); if (ALLOW_RTSAVE) { - saveExternalTask = new SaveList2ExternalTask(); - try { - saveExternalTask.openServer(); + saveExternalTask = new SaveList2ExternalTask(false); + if (saveExternalTask.openServer(false)) { serverConnectValid = true; MainActivity.csLibrary4A.appendToLog("openServer is done"); - } catch (Exception ex) { + } else { MainActivity.csLibrary4A.appendToLog("openServer has Exception"); } } @@ -119,10 +117,11 @@ protected void onPreExecute() { inventoryHandler_setup(); } + byte[] notificationData; @Override protected String doInBackground(Void... a) { boolean ending = false, triggerReleased = false; long triggerReleaseTime = 0; - CsLibrary4A.Rx000pkgData rx000pkgData = null; + RfidReaderChipData.Rx000pkgData rx000pkgData = null; while (MainActivity.csLibrary4A.onRFIDEvent() != null) { } //clear up possible message before operation while (MainActivity.csLibrary4A.isBleConnected() && isCancelled() == false && ending == false && MainActivity.csLibrary4A.isRfidFailure() == false) { int batteryCount = MainActivity.csLibrary4A.getBatteryCount(); @@ -134,11 +133,13 @@ protected String doInBackground(Void... a) { runTimeMillis = System.currentTimeMillis(); publishProgress("WW"); } + + notificationData = MainActivity.csLibrary4A.onNotificationEvent(); rx000pkgData = MainActivity.csLibrary4A.onRFIDEvent(); if (rx000pkgData != null && MainActivity.csLibrary4A.mrfidToWriteSize() == 0) { if (rx000pkgData.responseType == null) { publishProgress("null response"); - } else if (rx000pkgData.responseType == CsLibrary4A.HostCmdResponseTypes.TYPE_18K6C_INVENTORY) { + } else if (rx000pkgData.responseType == RfidReaderChipData.HostCmdResponseTypes.TYPE_18K6C_INVENTORY) { { if (rx000pkgData.decodedError != null) publishProgress(rx000pkgData.decodedError); else { @@ -147,7 +148,7 @@ protected String doInBackground(Void... a) { rx000pkgDataArrary.add(rx000pkgData); publishProgress(null, "", ""); } } - } else if (rx000pkgData.responseType == CsLibrary4A.HostCmdResponseTypes.TYPE_18K6C_INVENTORY_COMPACT) { + } else if (rx000pkgData.responseType == RfidReaderChipData.HostCmdResponseTypes.TYPE_18K6C_INVENTORY_COMPACT) { { if (rx000pkgData.decodedError != null) publishProgress(rx000pkgData.decodedError); else { @@ -155,18 +156,22 @@ protected String doInBackground(Void... a) { rx000pkgDataArrary.add(rx000pkgData); publishProgress(null, "", ""); } } - } else if (rx000pkgData.responseType == CsLibrary4A.HostCmdResponseTypes.TYPE_ANTENNA_CYCLE_END) { + } else if (rx000pkgData.responseType == RfidReaderChipData.HostCmdResponseTypes.TYPE_ANTENNA_CYCLE_END) { timeMillis = System.currentTimeMillis(); - } else if (rx000pkgData.responseType == CsLibrary4A.HostCmdResponseTypes.TYPE_COMMAND_ABORT_RETURN) { + } else if (rx000pkgData.responseType == RfidReaderChipData.HostCmdResponseTypes.TYPE_COMMAND_ABORT_RETURN) { MainActivity.csLibrary4A.appendToLog("AAA: Abort return is received !!!"); ending = true; - } else if (rx000pkgData.responseType == CsLibrary4A.HostCmdResponseTypes.TYPE_COMMAND_END) { + } else if (rx000pkgData.responseType == RfidReaderChipData.HostCmdResponseTypes.TYPE_COMMAND_END) { if (rx000pkgData.decodedError != null) endingMessaage = rx000pkgData.decodedError; if (continousRequest) { MainActivity.csLibrary4A.batteryLevelRequest(); - MainActivity.csLibrary4A.startOperation(CsLibrary4A.OperationTypes.TAG_INVENTORY_COMPACT); + MainActivity.csLibrary4A.startOperation(RfidReaderChipData.OperationTypes.TAG_INVENTORY_COMPACT); } else ending = true; } + } else if (false && notificationData != null) { + MainActivity.csLibrary4A.appendToLog("matched Error: resultError=" + MainActivity.csLibrary4A.byteArrayToString(notificationData)); + publishProgress("P"); + taskCancelReason = TaskCancelRReason.ERROR; } if (false) { if (MainActivity.csLibrary4A.mrfidToWriteSize() != 0) timeMillis = System.currentTimeMillis(); @@ -244,6 +249,9 @@ void inventoryHandler_endReason() { case TIMEOUT: message = "Time Out"; break; + case ERROR: + message = "Inventory Notification Error code A101: " + MainActivity.csLibrary4A.byteArrayToString(notificationData); + break; default: message = taskCancelReason.name(); break; @@ -269,7 +277,7 @@ void tagHandler() { long currentTime = 0; { while (rx000pkgDataArrary.size() != 0) { - CsLibrary4A.Rx000pkgData rx000pkgData = rx000pkgDataArrary.get(0); + RfidReaderChipData.Rx000pkgData rx000pkgData = rx000pkgDataArrary.get(0); rx000pkgDataArrary.remove(0); if (rx000pkgData == null) { if (DEBUG) MainActivity.csLibrary4A.appendToLog("InventoryRfidTask: null rx000pkgData !!!"); @@ -340,6 +348,7 @@ void tagHandler() { int iPc = Integer.parseInt(strPc, 16); String strXpc = null; int iSensorData = ReaderDevice.INVALID_SENSORDATA; if ((iPc & 0x0200) != 0 && strEpc != null && strEpc.length() >= 8) { + MainActivity.csLibrary4A.appendToLog("strPc = " + strPc + ", strEpc = " + strEpc); int iXpcw1 = Integer.parseInt(strEpc.substring(0, 4), 16); if ((iXpcw1 & 0x8000) != 0) { strXpc = strEpc.substring(0, 8); @@ -439,11 +448,12 @@ void tagHandler() { else strTidCompared = "E28011"; } MainActivity.csLibrary4A.appendToLog("strTidCompared = " + strTidCompared); - if (strTidCompared.matches("E282402")) { } + if (strTidCompared.matches("E28011")) { } + else if (strTidCompared.matches("E2806894") && MainActivity.mDid.matches("E2806894C")) { } + else if (strTidCompared.matches("E281D")) { } + else if (strTidCompared.matches("E282402")) { } else if (strTidCompared.matches("E282403")) { } else if (strTidCompared.matches("E282405")) { } - else if (strTidCompared.matches("E2806894") && MainActivity.mDid.matches("E2806894C")) { } - else if (strTidCompared.matches("E28011")) { } else { //if (strMdid.matches("E280B0")) boolean bMatched = false; if (strExtra1 != null && strExtra1.indexOf(strTidCompared) == 0) { @@ -478,16 +488,28 @@ else if (strTidCompared.matches("E28011")) { } } else if (readerListAdapter.getSelectDupElim()) { ReaderDevice readerDevice = null; int iMatchItem = -1; - if (true) { + if (false) { int index = Collections.binarySearch(MainActivity.sharedObjects.tagsIndexList, new SharedObjects.TagsIndex(strAddresss, 0)); if (index >= 0) { iMatchItem = MainActivity.sharedObjects.tagsIndexList.size() - 1 - MainActivity.sharedObjects.tagsIndexList.get(index).getPosition(); } } else { + String strCompare = null; + if (extra1Bank == 2) { + strCompare = strExtra1; //MainActivity.csLibrary4A.appendToLog("1strExtra = " + strExtra1 + ", " + readerDevice.getTid() + ", " + readerDevice.getTid().matches(strCompare)); + } else if (extra2Bank == 2) { + strCompare = strExtra2; //MainActivity.csLibrary4A.appendToLog("2strExtra = " + strExtra2 + ", " + readerDevice.getTid() + ", " + readerDevice.getTid().matches(strCompare)); + } for (int i = 0; i < tagsList.size(); i++) { - if (strEpc.matches(tagsList.get(i).getAddress())) { - iMatchItem = i; - break; + //MainActivity.csLibrary4A.appendToLog("strEpc = " + strEpc + ", tagsList.get(" + i + ").getAdddress = " + tagsList.get(i).getAddress()); + if (strEpc == null || tagsList.get(i).getAddress() == null) { } + else if (strEpc.matches(tagsList.get(i).getAddress())) { + boolean bTidMatched = true; + if (strCompare != null && tagsList.get(i).getTid() != null) bTidMatched = tagsList.get(i).getTid().matches(strCompare); + if (bTidMatched) { + iMatchItem = i; + break; + } } } } @@ -525,7 +547,23 @@ else if (readerDevice.getstrExtra2() != null) { } } if (ALLOW_WEDGE) MainActivity.sharedObjects.serviceArrayList.add(strEpc); - if (match == false) { + + boolean bAddDevice = true; String strValue = null; + if (bSgtinOnly) { + strValue = MainActivity.csLibrary4A.getUpcSerial(strEpc); + MainActivity.csLibrary4A.appendToLog("bSgtinOnly = " + bSgtinOnly + ", strValue = " + (strValue == null ? "null" : strValue)); + if (strValue == null) bAddDevice = false; + } else if (bProtectOnly) { + if (strExtra1 != null) { + bAddDevice = false; + strValue = strExtra1.substring(strExtra1.length() - 1); + int iValue = Integer.parseInt(strValue, 16); + MainActivity.csLibrary4A.appendToLog("bProtectOnly = " + bProtectOnly + ", strExtra1 = " + (strExtra1 == null ? "null" : strExtra1) + ", iValue = " + iValue); + if ((iValue & 0x02) != 0) bAddDevice = true; + } else MainActivity.csLibrary4A.appendToLog("NULL strExtra1"); + } + if (bAddDevice == false) { } + else if (match == false) { if (tagsList == null) { strEpcOld = strEpc; updated = true; @@ -538,6 +576,7 @@ else if (readerDevice.getstrExtra2() != null) { new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").format(new Date()), new SimpleDateFormat("z").format(new Date()).replaceAll("GMT", ""), MainActivity.mSensorConnector.mLocationDevice.getLocation(), MainActivity.mSensorConnector.mSensorDevice.getEcompass(), 1, rssi, phase, chidx, port, portstatus, backport1, backport2, codeSensor, codeRssi, codeTempC, brand, iSensorData); + if (bSgtinOnly && strValue != null) readerDevice.setUpcSerial(strValue); if (strMdid != null) { if (strMdid.indexOf("E282402") == 0) readerDevice.setCodeSensorMax(0x1F); else readerDevice.setCodeSensorMax(0x1FF); @@ -545,12 +584,14 @@ else if (readerDevice.getstrExtra2() != null) { if (bAdd2End) tagsList.add(readerDevice); else tagsList.add(0, readerDevice); SharedObjects.TagsIndex tagsIndex = new SharedObjects.TagsIndex(strAddresss, tagsList.size() - 1); MainActivity.sharedObjects.tagsIndexList.add(tagsIndex); Collections.sort(MainActivity.sharedObjects.tagsIndexList); + MainActivity.csLibrary4A.appendToLog("openServer: serverConnectValid is " + serverConnectValid); if (serverConnectValid && ALLOW_RTSAVE && true) { try { // saveExternalTask = new SaveList2ExternalTask(); // saveExternalTask.openServer(); String msgOutput = saveExternalTask.createJSON(null, readerDevice).toString(); MainActivity.csLibrary4A.appendToLog("Json = " + msgOutput); saveExternalTask.write2Server(msgOutput); + MainActivity.csLibrary4A.appendToLog("openServer: write2Server data = " + msgOutput); // saveExternalTask.closeServer(); MainActivity.csLibrary4A.appendToLog("write2Server is done"); @@ -564,7 +605,7 @@ else if (readerDevice.getstrExtra2() != null) { requestNewSound = true; requestNewVibrate = true; requestSound = true; } - if (updated) { + if (updated && bAddDevice) { total++; allTotal++; } @@ -577,15 +618,15 @@ else if (readerDevice.getstrExtra2() != null) { if (requestSound && requestNewSound) requestSoundCount = 0; if (readerListAdapter != null) readerListAdapter.notifyDataSetChanged(); if (invalidDisplay) { - if (rfidYieldView != null) rfidYieldView.setText(String.valueOf(total) + "," + String.valueOf(MainActivity.csLibrary4A.validata)); - if (rfidRateView != null) rfidRateView.setText(String.valueOf(MainActivity.csLibrary4A.invalidata) + "," + String.valueOf(MainActivity.csLibrary4A.invalidUpdata)); + if (rfidYieldView != null) rfidYieldView.setText(String.valueOf(total) + "," + String.valueOf(MainActivity.csLibrary4A.getValidata())); + if (rfidRateView != null) rfidRateView.setText(String.valueOf(MainActivity.csLibrary4A.getInvalidata()) + "," + String.valueOf(MainActivity.csLibrary4A.getInvalidUpdata())); } else { String stringTemp = "Unique:" + String.valueOf(yield); if (true) { - float fErrorRate = (float) MainActivity.csLibrary4A.invalidata / ((float) MainActivity.csLibrary4A.validata + (float) MainActivity.csLibrary4A.invalidata) * 100; - stringTemp += "\nE" + String.valueOf(MainActivity.csLibrary4A.invalidata) + "/" + String.valueOf(MainActivity.csLibrary4A.validata) + "/" + String.valueOf((int) fErrorRate); + float fErrorRate = (float) MainActivity.csLibrary4A.getInvalidata() / ((float) MainActivity.csLibrary4A.getValidata() + (float) MainActivity.csLibrary4A.getInvalidata()) * 100; + stringTemp += "\nE" + String.valueOf(MainActivity.csLibrary4A.getInvalidata()) + "/" + String.valueOf(MainActivity.csLibrary4A.getValidata()) + "/" + String.valueOf((int) fErrorRate); } else if (true) { - stringTemp += "\nE" + String.valueOf(MainActivity.csLibrary4A.invalidata) + "," + String.valueOf(MainActivity.csLibrary4A.invalidUpdata) + "/" + String.valueOf(MainActivity.csLibrary4A.validata); + stringTemp += "\nE" + String.valueOf(MainActivity.csLibrary4A.getInvalidata()) + "," + String.valueOf(MainActivity.csLibrary4A.getInvalidUpdata()) + "/" + String.valueOf(MainActivity.csLibrary4A.getValidata()); } if (rfidYieldView != null) rfidYieldView.setText(stringTemp); if (total != 0 && currentTime - firstTimeOld > 500) { @@ -753,12 +794,8 @@ void DeviceConnectTask4InventoryEnding(TaskCancelRReason taskCancelReason) { MainActivity.csLibrary4A.abortOperation(); //added in case previous command end is received with inventory stopped MainActivity.csLibrary4A.appendToLog("serverConnectValid = " + serverConnectValid); if (serverConnectValid && ALLOW_RTSAVE) { - try { - saveExternalTask.closeServer(); - MainActivity.csLibrary4A.appendToLog("closeServer is done"); - } catch (Exception ex) { - MainActivity.csLibrary4A.appendToLog("closeServer has Exception"); - } + if (saveExternalTask.closeServer()) MainActivity.csLibrary4A.appendToLog("closeServer is done"); + else MainActivity.csLibrary4A.appendToLog("closeServer has Exception"); } MainActivity.csLibrary4A.appendToLog("INVENDING: Ending with endingRequest = " + endingRequest); if (MainActivity.mContext == null) return; diff --git a/app/src/main/java/com/csl/cs710awedgeapp/MainActivity.java b/app/src/main/java/com/csl/cs710awedgeapp/MainActivity.java index dac876f..06f037a 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/MainActivity.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/MainActivity.java @@ -6,20 +6,19 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import android.net.Uri; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.util.Log; import android.view.Gravity; import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.csl.cs710awedgeapp.DrawerListContent.DrawerPositions; import com.csl.cs710awedgeapp.fragments.*; -import com.csl.cs710library4a.CsLibrary4A; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cslibrary4a.CsLibrary4A; +import com.csl.cslibrary4a.ReaderDevice; import java.io.BufferedReader; import java.io.File; @@ -71,7 +70,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) selectItem(drawerPositionsDefault); - if (DEBUG) Log.i(TAG, "MainActivity.onCreate.onCreate: END"); + if (true) Log.i(TAG, "MainActivity.onCreate.onCreate: END"); loadWedgeSettingFile(); } @@ -112,16 +111,21 @@ protected void onStop() { protected void onDestroy() { if (DEBUG) csLibrary4A.appendToLog("MainActivity.onDestroy()"); if (true) { csLibrary4A.disconnect(true); } + //csLibrary4A = null; super.onDestroy(); } private void selectItem(DrawerPositions position) { if (DEBUG) Log.i(TAG, "MainActivity.selectItem: position = " + position); switch (position) { + case ABOUT: + fragment = new AboutFragment(); + break; case DIRECTWEDGE: fragment = new DirectWedgeFragment(); break; } + FragmentManager fragmentManager = getSupportFragmentManager(); if (position == drawerPositionsDefault) { @@ -165,17 +169,17 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in permissionRequesting = false; } - public static boolean wedged = false; - - // The click listener for ListView in the navigation drawer - private class DrawerItemClickListener implements ListView.OnItemClickListener { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (DEBUG) Log.i(TAG, "MainActivity.onItemClick: position = " + position + ", id = " + id); - selectItem(DrawerListContent.DrawerPositions.toDrawerPosition(position)); - } + public void privacyClicked(View view) { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.parse("https://www.convergence.com.hk/apps-privacy-policy")); + startActivity(intent); } + public void aboutClicked(View view) { selectItem(DrawerPositions.ABOUT); } + public static boolean wedged = false; + @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -187,13 +191,14 @@ private void readFromIntent(Intent intent) { String action = intent.getAction(); } - public static String fileName = "SimpleWedgeSettings"; + public static String fileName = "csReaderA_SimpleWedge"; public static String wedgePrefix = null, wedgeSuffix = null; - public static int wedgeDelimiter = 0x0a, wedgePower = 300; + public static int wedgeOutput = 0, wedgeDelimiter = 0x0a, wedgePower = 300; void loadWedgeSettingFile() { File path = this.getFilesDir(); File file = new File(path, fileName); boolean bNeedDefault = true, DEBUG = false; + MainActivity.csLibrary4A.appendToLog(fileName + "file.exists = " + file.exists()); if (file.exists()) { int length = (int) file.length(); byte[] bytes = new byte[length]; @@ -215,6 +220,9 @@ void loadWedgeSettingFile() { wedgeSuffix = dataArray[1]; } else if (dataArray[0].matches("wedgeDelimiter")) { wedgeDelimiter = Integer.valueOf(dataArray[1]); + MainActivity.csLibrary4A.appendToLog("MainActivity, loadWedgeSettingFile: wedgeDelimiter = " + wedgeDelimiter); + } else if (dataArray[0].matches("wedgeOutput")) { + wedgeOutput = Integer.valueOf(dataArray[1]); } } } diff --git a/app/src/main/java/com/csl/cs710awedgeapp/SaveList2ExternalTask.java b/app/src/main/java/com/csl/cs710awedgeapp/SaveList2ExternalTask.java index 22b57ea..5a8bd0f 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/SaveList2ExternalTask.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/SaveList2ExternalTask.java @@ -1,19 +1,20 @@ package com.csl.cs710awedgeapp; -import android.Manifest; -import android.app.Activity; +import static android.content.Context.WIFI_SERVICE; +import static com.csl.cs710awedgeapp.MainActivity.csLibrary4A; +import static com.csl.cs710awedgeapp.MainActivity.mContext; + import android.bluetooth.BluetoothAdapter; -import android.content.pm.PackageManager; import android.media.MediaScannerConnection; import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.os.Build; import android.os.Environment; import android.provider.Settings; -import android.widget.Toast; +import android.util.Log; -import com.csl.cs710library4a.CsLibrary4A; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cslibrary4a.ReaderDevice; +import com.csl.cslibrary4a.RfidReaderChipData; import org.json.JSONArray; import org.json.JSONObject; @@ -46,20 +47,16 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -import static android.content.Context.WIFI_SERVICE; -import static androidx.core.app.ActivityCompat.requestPermissions; -import static com.csl.cs710awedgeapp.MainActivity.mContext; -import static com.csl.cs710awedgeapp.MainActivity.csLibrary4A; - public class SaveList2ExternalTask extends AsyncTask { - String messageStr; - String resultDisplay = "", errorDisplay; + public String messageStr; + String resultDisplay = ""; + public String errorDisplay; ArrayList tagsList; ReaderDevice tagDevice1; CustomPopupWindow customPopupWindow; boolean savedFile = false; int fileFormat = 0; - String url = null; + public String url = null, strBearer = null; HttpURLConnection con; String stringBluetoothMAC, stringWifiMac; @@ -107,15 +104,21 @@ else if (stringBluetoothMAC.contains("020000000000")) { } } } - public SaveList2ExternalTask() { } + boolean bImpinjServer = false; + public SaveList2ExternalTask(boolean bImpinjServer) { + csLibrary4A.appendToLog("bImpinjServer = " + bImpinjServer); + this.bImpinjServer = bImpinjServer; + } @Override protected void onPreExecute() { - if (tagsList == null) cancel(true); - - if (MainActivity.csLibrary4A.getSavingFormatSetting() == 0) messageStr = createJSON(tagsList, null).toString(); - else messageStr = createCSV(tagsList, null); - resultDisplay = save2File(messageStr, true); + if (!bImpinjServer) { + if (tagsList == null) cancel(true); + if (MainActivity.csLibrary4A.getSavingFormatSetting() == 0) + messageStr = createJSON(tagsList, null).toString(); + else messageStr = createCSV(tagsList, null); + resultDisplay = save2File(messageStr, true); + } customPopupWindow = new CustomPopupWindow(mContext); csLibrary4A.appendToLog("SaveList2ExternalTask: resultDisplay = " + resultDisplay); if (resultDisplay == null) resultDisplay = ""; @@ -128,18 +131,20 @@ protected void onPreExecute() { } protected String doInBackground(Void... params) { + Log.i("Hello", "bImpinjServer: doInBackground starts"); if (MainActivity.csLibrary4A.isBleConnected() == false) { resultDisplay += "Error in sending data to server as the reader is not connected"; return null; - } else if (MainActivity.csLibrary4A.getSaveCloudEnable() == false) { + } else if (MainActivity.csLibrary4A.getSaveCloudEnable() == false && bImpinjServer == false) { resultDisplay += "No saving to cloud as it is disabled"; return null; } try { if (true) { - openServer(); - write2Server(messageStr); - closeServer(); + csLibrary4A.appendToLog("bImpinjServer: doInBackground starts doing"); + openServer(bImpinjServer); csLibrary4A.appendToLog("bImpinjServer: doInBackground after openServer"); + write2Server(messageStr); csLibrary4A.appendToLog("bImpinjServer: doInBackground after write2Server"); + closeServer(); csLibrary4A.appendToLog("bImpinjServer: doInBackground after closeServer"); } else if (true) { String serverAddress = "192.168.25.119:21"; String addressPort[]; @@ -176,7 +181,11 @@ protected void onProgressUpdate(Void... output) { } protected void onCancelled() { } protected void onPostExecute(String output) { if (savedFile == false) resultDisplay += "\n" + save2File(messageStr, false); - customPopupWindow.popupWindow.dismiss(); customPopupWindow.popupStart(resultDisplay, false); + customPopupWindow.popupWindow.dismiss(); + csLibrary4A.appendToLog("bImpinjServer = " + bImpinjServer + ", responseCode = " + responseCode + ", resultDisplay = " + resultDisplay); + if (resultDisplay != null && resultDisplay.length() != 0) { + if (!bImpinjServer || responseCode != 200) customPopupWindow.popupStart(resultDisplay, false); + } } public String createStrEpcList() { @@ -283,16 +292,16 @@ public String createCSV(ArrayList tagsList0, ReaderDevice tagDevic String objectTag; objectTag = "PC,"; objectTag += "EPC,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.RESERVE_BANK.ordinal())) != 0) objectTag += "Reserve Bank,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.EPC_BANK.ordinal())) != 0) objectTag += "EPC Bank,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TID_BANK.ordinal())) != 0) objectTag += "TID Bank,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.USER_BANK.ordinal())) != 0) objectTag += "User Bank,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.PHASE.ordinal())) != 0) objectTag += "Phase,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.CHANNEL.ordinal())) != 0) objectTag += "Channel,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TIME.ordinal())) != 0) objectTag += "Time Of Read,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TIMEZONE.ordinal())) != 0) objectTag += "Time Zone,"; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.LOCATION.ordinal())) != 0) objectTag += "location Of Read Latitude, Location of Read Longitude, "; - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.DIRECTION.ordinal())) != 0) objectTag += "eCompass"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.RESERVE_BANK.ordinal())) != 0) objectTag += "Reserve Bank,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.EPC_BANK.ordinal())) != 0) objectTag += "EPC Bank,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TID_BANK.ordinal())) != 0) objectTag += "TID Bank,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.USER_BANK.ordinal())) != 0) objectTag += "User Bank,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.PHASE.ordinal())) != 0) objectTag += "Phase,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.CHANNEL.ordinal())) != 0) objectTag += "Channel,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TIME.ordinal())) != 0) objectTag += "Time Of Read,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TIMEZONE.ordinal())) != 0) objectTag += "Time Zone,"; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.LOCATION.ordinal())) != 0) objectTag += "location Of Read Latitude, Location of Read Longitude, "; + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.DIRECTION.ordinal())) != 0) objectTag += "eCompass"; objectTag += "\n"; object += objectTag; } @@ -332,21 +341,21 @@ public String createCSV(ArrayList tagsList0, ReaderDevice tagDevic objectTag = String.format("=\"%s\",", pcData); objectTag += String.format("=\"%s\",", epcData); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.RESERVE_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", resBankData); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.EPC_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", epcBankData); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TID_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", tidBankData); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.USER_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", userBankData); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.PHASE.ordinal())) != 0) objectTag += String.format("%d,", phase); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.CHANNEL.ordinal())) != 0) objectTag += String.format("%d,", channel); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TIME.ordinal())) != 0) objectTag += String.format("=\"%s\",", timeOfRead); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.TIMEZONE.ordinal())) != 0) objectTag += String.format("%s,", timeZone); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.LOCATION.ordinal())) != 0) objectTag += String.format("%s,", location); - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.DIRECTION.ordinal())) != 0)objectTag += String.format("%s", compass); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.RESERVE_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", resBankData); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.EPC_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", epcBankData); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TID_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", tidBankData); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.USER_BANK.ordinal())) != 0) objectTag += String.format("=\"%s\",", userBankData); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.PHASE.ordinal())) != 0) objectTag += String.format("%d,", phase); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.CHANNEL.ordinal())) != 0) objectTag += String.format("%d,", channel); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TIME.ordinal())) != 0) objectTag += String.format("=\"%s\",", timeOfRead); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.TIMEZONE.ordinal())) != 0) objectTag += String.format("%s,", timeZone); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.LOCATION.ordinal())) != 0) objectTag += String.format("%s,", location); + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.DIRECTION.ordinal())) != 0)objectTag += String.format("%s", compass); objectTag += "\n"; object += objectTag; } - if ((csvColumnSelect & (0x01 << CsLibrary4A.CsvColumn.OTHERS.ordinal())) != 0) { + if ((csvColumnSelect & (0x01 << RfidReaderChipData.CsvColumn.OTHERS.ordinal())) != 0) { object += "\nUser Description,this is example tag data\n"; object += String.format("RFID Reader Name,=\"%s\"\n", MainActivity.csLibrary4A.getBluetoothICFirmwareName()); @@ -367,6 +376,7 @@ public String save2File(String messageStr, boolean requestPermission) { String resultDisplay = ""; if (MainActivity.csLibrary4A.getSaveFileEnable() == false) return "No saving file as it is disabled"; boolean writeExtPermission = true; +/* if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (mContext.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { csLibrary4A.appendToLog("WRITE_EXTERNAL_STORAGE Permission is required !!!"); @@ -379,18 +389,19 @@ public String save2File(String messageStr, boolean requestPermission) { } } else csLibrary4A.appendToLog("WRITE_EXTERNAL_STORAGE Permission is GRANTED !!!"); } - +*/ errorDisplay = null; if (writeExtPermission == false) { errorDisplay = "denied WRITE_EXTERNAL_STORAGE Permission !!!"; } else if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) == false) errorDisplay = "Error in mouting external storage !!!"; else { - File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Environment.DIRECTORY_DOWNLOADS + "/csReaderJava"); + String strDir = "csReaderJava"; + File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Environment.DIRECTORY_DOWNLOADS + "/" + strDir); if (path.exists() == false) path.mkdirs(); if (path.exists() == false) errorDisplay = "Error in making directory !!!"; else { String dateTime = new SimpleDateFormat("yyMMdd_HHmmss").format(new Date()); - String fileName = "csReaderJava_" + dateTime + (csLibrary4A.getSavingFormatSetting() == 0 ? ".txt" : ".csv"); + String fileName = strDir + "_" + dateTime + (csLibrary4A.getSavingFormatSetting() == 0 ? ".txt" : ".csv"); File file = new File(path, fileName); if (file == null) errorDisplay = "Error in making directory !!!"; else { @@ -401,7 +412,7 @@ public String save2File(String messageStr, boolean requestPermission) { outputStream.write(messageStr.getBytes()); errorDisplay = "Error in close()"; outputStream.close(); MediaScannerConnection.scanFile(mContext, new String[]{file.getAbsolutePath()}, null, null); - resultDisplay = "Success in saving data to Download/csReaderJava/" + fileName; + resultDisplay = "Success in saving data to Download/" + strDir + "/" + fileName; errorDisplay = null; } catch (Exception ex) { errorDisplay += ex.getMessage(); @@ -413,62 +424,94 @@ public String save2File(String messageStr, boolean requestPermission) { return resultDisplay; } - public void openServer() throws Exception { - if (false) { - url = "https://"; - url += "192.168.25.21:"; - url += "29090/WebServiceRESTs/1.0/req/"; - } else if (false) url = "http://ptsv2.com/t/10i1t-1519143332/post"; - else url = csLibrary4A.getServerLocation(); - - errorDisplay = "Error in SSLContext.getInstance()"; SSLContext sc = SSLContext.getInstance("TLS"); - errorDisplay = "Error in SSLContext.init()"; sc.init(null, new TrustManager[]{ - new X509TrustManager() { - @Override - public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { - throw new UnsupportedOperationException("TrustManager.checkClientTrusted: Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } + public boolean openServer(boolean bImpinjServer) { + boolean bValue = true; + try { + if (false) { + url = "https://"; + url += "192.168.25.21:"; + url += "29090/WebServiceRESTs/1.0/req/"; + } else if (false) url = "http://ptsv2.com/t/10i1t-1519143332/post"; + else if (bImpinjServer) { + } //url = "https://h9tqczg9-7275.asse.devtunnels.ms/api/Auth/login"; //"https://142.251.220.110"; // + else url = csLibrary4A.getServerLocation(); + + errorDisplay = "Error in SSLContext.getInstance()"; + SSLContext sc = SSLContext.getInstance("TLS"); + errorDisplay = "Error in SSLContext.init()"; + sc.init(null, new TrustManager[]{ + new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { + throw new UnsupportedOperationException("TrustManager.checkClientTrusted: Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } - @Override - public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { - } + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { + } + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + } + }, new SecureRandom()); + if (true) { + errorDisplay = "Error in setDefaultSSLSocketFactory()"; + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + errorDisplay = "Error in setDefaultHostnameVerifier()"; + HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override - public X509Certificate[] getAcceptedIssuers() { - return null; + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; } - } - }, new SecureRandom()); - if (true) { - errorDisplay = "Error in setDefaultSSLSocketFactory()"; HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - errorDisplay = "Error in setDefaultHostnameVerifier()"; HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { - @Override - public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { - return true; - } - }); - } - HttpsURLConnection.setFollowRedirects(false); - - errorDisplay = "Error in URL()"; URL obj = new URL(url); - errorDisplay = "Error in openConnection()"; - boolean isHttps = false; - if (url.length() >= 6) { - if (url.substring(0, 6).matches("https:")) isHttps = true; - } - con = (HttpURLConnection) obj.openConnection(); - if (isHttps) { - con = (HttpsURLConnection) obj.openConnection(); + }); + } + HttpsURLConnection.setFollowRedirects(false); + + errorDisplay = "Error in URL()"; + URL obj = new URL(url); + MainActivity.csLibrary4A.appendToLog("obj is " + (obj != null ? "valid" : "NULL") + " with url = " + url); + errorDisplay = "Error in openConnection()"; + boolean isHttps = false; + if (url.length() >= 6) { + if (url.substring(0, 6).matches("https:")) isHttps = true; + } + con = (HttpURLConnection) obj.openConnection(); + if (isHttps) { + con = (HttpsURLConnection) obj.openConnection(); + } + errorDisplay = "Error in setConnectTimeout()"; + con.setConnectTimeout(MainActivity.csLibrary4A.getServerTimeout() * 1000); + errorDisplay = "Error in setRequestMethod()"; + con.setRequestMethod("POST"); + //errorDisplay = "Error in setRequestProperty(User-Agent)"; con.setRequestProperty("User-Agent", "Mozilla/5.0"); + //errorDisplay = "Error in setRequestProperty(text/plain)"; con.setRequestProperty("text/plain", "text/plain"); + //errorDisplay = "Error in setRequestProperty(Accept-Language)"; con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); + MainActivity.csLibrary4A.appendToLog("authenticate in url position : " + url.indexOf("authenticate")); + if (url.indexOf("authenticate") >= 0) { + String string = strBearer; + MainActivity.csLibrary4A.appendToLog("Authorization value = " + string); + errorDisplay = "Error in setRequestProperty(Authorization)"; + con.setRequestProperty("Authorization", string); + } + errorDisplay = "Error in setRequestProperty(Content)"; + con.setRequestProperty("Content-Type", "application/json); //; charset=utf8"); + errorDisplay = "Error in setDoOutput()"; + con.setDoOutput(true); + errorDisplay = "Error in setDoInput()"; + con.setDoInput(true); + } catch (Exception ex) { + bValue = false; } - errorDisplay = "Error in setConnectTimeout()"; con.setConnectTimeout(MainActivity.csLibrary4A.getServerTimeout() * 1000); - errorDisplay = "Error in setRequestMethod()"; con.setRequestMethod("POST"); - errorDisplay = "Error in setRequestProperty(User-Agent)"; con.setRequestProperty("User-Agent", "Mozilla/5.0"); - errorDisplay = "Error in setRequestProperty(Accept-Languag)"; con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); - errorDisplay = "Error in setDoOutput()"; con.setDoOutput(true); + return bValue; } + boolean serverWritten = false; public void write2Server(String messageStr0) { + csLibrary4A.appendToLog("messageStr0 = " + messageStr0); try { + //InputStream is = con.getInputStream(); DataInputStream ir = new DataInputStream(is); errorDisplay = "Error in getOutputStream()"; OutputStream os = con.getOutputStream(); errorDisplay = "Error in DataOutputStream()"; DataOutputStream wr = new DataOutputStream(os); @@ -478,32 +521,42 @@ public void write2Server(String messageStr0) { errorDisplay = "Error in close(wr)"; wr.close(); errorDisplay = "Error in close(os)"; os.close(); serverWritten = true; + //csLibrary4A.appendToLog("inputStream = " + ir.readUTF()); } catch (Exception ex) { MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay + ", execpetion = " + ex.getMessage()); } } - public void closeServer() throws Exception { + + public int responseCode; public String response = null; + public boolean closeServer() { + boolean bValue = true; if (serverWritten) { - errorDisplay = "Error in getResponseCode()"; - int responseCode = con.getResponseCode(); - MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); - MainActivity.csLibrary4A.appendToLog("responseCode = " + responseCode); - if (responseCode != 200) - errorDisplay = "Error in response code = " + responseCode; - else { - BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); - MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); - String inputLine; - String response = ""; - while ((inputLine = in.readLine()) != null) { - response += inputLine; + try { + errorDisplay = "Error in getResponseCode()"; + responseCode = con.getResponseCode(); + //MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); + MainActivity.csLibrary4A.appendToLog("responseCode = " + responseCode); + if (responseCode != 200) + errorDisplay = "Error in response code = " + responseCode; + else { + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + //MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); + String inputLine; + response = ""; + while ((inputLine = in.readLine()) != null) { + response += inputLine; + } + in.close(); + //MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); + resultDisplay += "Success in sending data to server with response = " + response; + MainActivity.csLibrary4A.appendToLog("response = " + response); + errorDisplay = null; } - in.close(); - MainActivity.csLibrary4A.appendToLog("errorDisplay = " + errorDisplay); - resultDisplay += "Success in sending data to server with response = " + response; - errorDisplay = null; + } catch (Exception ex) { + bValue = false; } } con.disconnect(); + return bValue; } } \ No newline at end of file diff --git a/app/src/main/java/com/csl/cs710awedgeapp/SensorConnector.java b/app/src/main/java/com/csl/cs710awedgeapp/SensorConnector.java index 2895682..062fc1f 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/SensorConnector.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/SensorConnector.java @@ -14,8 +14,6 @@ import androidx.core.app.ActivityCompat; import android.widget.Toast; -import com.csl.cs710library4a.CsLibrary4A; - import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -36,10 +34,8 @@ public String getTimeStamp() { private Sensor mAccelerometer; private Sensor mMagnetometer; - private CsLibrary4A mCsLibrary4A = MainActivity.csLibrary4A; SensorConnector(Context context) { - mCsLibrary4A = MainActivity.csLibrary4A; mLocationDevice = new LocationDevice(context); mSensorDevice = new SensorDevice(context); } @@ -65,27 +61,27 @@ public String getLocation() { PackageManager mPackageManager; mPackageManager = (PackageManager) context.getPackageManager(); if (!(mPackageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION))) { - if (DEBUG) mCsLibrary4A.appendToLog("there is NO Feature_Location"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("there is NO Feature_Location"); Toast.makeText(context.getApplicationContext(), "there is NO LOCATION_FEATURE in this phone !!! Please use another phone.", Toast.LENGTH_LONG).show(); } else locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE); } public void turnOn(boolean onStatus) { if (locationManager != null) { - if (true) mCsLibrary4A.appendToLog("permission.ACCESS_FINE_LOCATION = " + ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)); - if (true) mCsLibrary4A.appendToLog("permission.ACCESS_COARSE_LOCATION = " + ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION)); + if (true) MainActivity.csLibrary4A.appendToLog("permission.ACCESS_FINE_LOCATION = " + ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION)); + if (true) MainActivity.csLibrary4A.appendToLog("permission.ACCESS_COARSE_LOCATION = " + ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION)); if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(mContext.getApplicationContext(), "LOCATION_FEATURE permission is NOT GRANTED in this phone !!! Please go to Phone Setup and enable Location Services and Relaunch.", Toast.LENGTH_SHORT).show(); } else if (onStatus && this.onStatus == false) { this.onStatus = onStatus; - if (true) mCsLibrary4A.appendToLog("LocationDevice.setRfidOn(): ON with LocationManager: ON"); - if (true) mCsLibrary4A.appendToLog("LocationManager.PASSIVE_PROVIDER = " + LocationManager.PASSIVE_PROVIDER); + if (true) MainActivity.csLibrary4A.appendToLog("LocationDevice.setRfidOn(): ON with LocationManager: ON"); + if (true) MainActivity.csLibrary4A.appendToLog("LocationManager.PASSIVE_PROVIDER = " + LocationManager.PASSIVE_PROVIDER); location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener); - locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener); + if (true) locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, locationListener); //not working in iData2S phone } else if (onStatus == false && this.onStatus) { this.onStatus = onStatus; - if (DEBUG) mCsLibrary4A.appendToLog("LocationDevice.setRfidOn(): OFF"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("LocationDevice.setRfidOn(): OFF"); locationManager.removeUpdates(locationListener); } } @@ -94,7 +90,7 @@ public void turnOn(boolean onStatus) { private LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { - if (true) mCsLibrary4A.appendToLog("onLocationChanged(): " + location.getProvider()); + if (true) MainActivity.csLibrary4A.appendToLog("onLocationChanged(): " + location.getProvider()); location = location; } @@ -135,9 +131,9 @@ public String getEcompass() { mSensorManager = (SensorManager) mContext.getSystemService(SENSOR_SERVICE); List deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); - if (DEBUG) mCsLibrary4A.appendToLog("SensorDevice(): List of sensors"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("SensorDevice(): List of sensors"); for (int i = 0; i < deviceSensors.size(); i++) { - if (DEBUG) mCsLibrary4A.appendToLog(deviceSensors.get(i).getType() + "," + deviceSensors.get(i).getName()); + if (DEBUG) MainActivity.csLibrary4A.appendToLog(deviceSensors.get(i).getType() + "," + deviceSensors.get(i).getName()); } } @@ -157,11 +153,11 @@ public void turnOn(boolean onStatus) { mSensorManager.unregisterListener(sensorEventListener); } else { this.onStatus = onStatus; - if (DEBUG) mCsLibrary4A.appendToLog("SensorDevice.setRfidOn(): ON"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("SensorDevice.setRfidOn(): ON"); } } else if (this.onStatus && onStatus == false) { this.onStatus = onStatus; - if (DEBUG) mCsLibrary4A.appendToLog("SensorDevice.setRfidOn(): OFF"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("SensorDevice.setRfidOn(): OFF"); mSensorManager.unregisterListener(sensorEventListener); } } @@ -182,7 +178,7 @@ public void onSensorChanged(SensorEvent event) { mLastAccelerometerSet = true; // appendToLog("onSensorChanged(): updated mAccelerometer"); } else { - if (DEBUG) mCsLibrary4A.appendToLog("onSensorChanged(): mAccelerometer: " + event.values.length); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("onSensorChanged(): mAccelerometer: " + event.values.length); } } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { if (event.values.length == mLastMagnetometer.length) { @@ -190,10 +186,10 @@ public void onSensorChanged(SensorEvent event) { mLastMagnetometerSet = true; // appendToLog("onSensorChanged(): updated mMagnetometer"); } else { - if (DEBUG) mCsLibrary4A.appendToLog("onSensorChanged(): mMagnetometer: " + event.values.length); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("onSensorChanged(): mMagnetometer: " + event.values.length); } } else { - if (DEBUG) mCsLibrary4A.appendToLog("onSensorChanged(): " + event.sensor.getType() + "," + event.sensor.getName()); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("onSensorChanged(): " + event.sensor.getType() + "," + event.sensor.getName()); } if (mLastAccelerometerSet && mLastMagnetometerSet) { @@ -203,7 +199,7 @@ public void onSensorChanged(SensorEvent event) { } mLastAccelerometerSet = false; mLastMagnetometerSet = false; - if (DEBUG) mCsLibrary4A.appendToLog("onSensorChanged(): updated mOrientation with mOrientation=" + mOrientation[0]); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("onSensorChanged(): updated mOrientation with mOrientation=" + mOrientation[0]); } } diff --git a/app/src/main/java/com/csl/cs710awedgeapp/SharedObjects.java b/app/src/main/java/com/csl/cs710awedgeapp/SharedObjects.java index eeb3c3c..796e84f 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/SharedObjects.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/SharedObjects.java @@ -5,7 +5,7 @@ import androidx.annotation.Keep; import androidx.annotation.NonNull; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cslibrary4a.ReaderDevice; import java.util.ArrayList; diff --git a/app/src/main/java/com/csl/cs710awedgeapp/adapters/ReaderListAdapter.java b/app/src/main/java/com/csl/cs710awedgeapp/adapters/ReaderListAdapter.java index c3a7b36..a2a7aa9 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/adapters/ReaderListAdapter.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/adapters/ReaderListAdapter.java @@ -11,7 +11,7 @@ import com.csl.cs710awedgeapp.MainActivity; import com.csl.cs710awedgeapp.R; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cslibrary4a.ReaderDevice; import java.util.ArrayList; @@ -67,6 +67,12 @@ public View getView(int position, View convertView, ViewGroup parent) { text1 += reader.getAddress(); } } + if (reader.getUpcSerial() != null) { + if (reader.getUpcSerial().length() != 0) { + if (text1.length() != 0) text1 += "\n"; + text1 += reader.getUpcSerial(); + } + } if (MainActivity.csLibrary4A.isBleScanning()) { if (reader.getServiceUUID2p1() == 0) text1 += "\nCS108 Reader"; else if (reader.getServiceUUID2p1() == 2) text1 += "\nCS710S Reader"; @@ -150,7 +156,7 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView readerDetailA = (TextView) convertView.findViewById(R.id.reader_detailA); TextView readerDetailB = (TextView) convertView.findViewById(R.id.reader_detailB); - if (reader.isConnected() || checkedTextView.isChecked() || select4detail == false) { + if (true || reader.isConnected() || checkedTextView.isChecked() || select4detail == false) { readerDetailA.setText(reader.getDetails()); readerDetailB.setText(""); if (reader.isConnected()) { diff --git a/app/src/main/java/com/csl/cs710awedgeapp/fragments/AboutFragment.java b/app/src/main/java/com/csl/cs710awedgeapp/fragments/AboutFragment.java new file mode 100644 index 0000000..74d976f --- /dev/null +++ b/app/src/main/java/com/csl/cs710awedgeapp/fragments/AboutFragment.java @@ -0,0 +1,134 @@ +package com.csl.cs710awedgeapp.fragments; + +import android.os.Bundle; +import android.os.Handler; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; + +import com.csl.cs710awedgeapp.BuildConfig; +import com.csl.cs710awedgeapp.MainActivity; +import com.csl.cs710awedgeapp.R; + +public class AboutFragment extends CommonFragment { + Handler mHandler = new Handler(); + long timeMillis = 0; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState, true); + return inflater.inflate(R.layout.fragment_about, container, false); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + actionBar.setIcon(R.drawable.dl_about); + actionBar.setTitle(R.string.title_activity_about); + + TextView appVersionView = (TextView) getActivity().findViewById(R.id.appVersion); + appVersionView.setText(BuildConfig.VERSION_NAME); + TextView libVersionView = (TextView) getActivity().findViewById(R.id.libVersion); + libVersionView.setText(MainActivity.csLibrary4A.getlibraryVersion()); + + MainActivity.mSensorConnector.mLocationDevice.turnOn(true); + MainActivity.mSensorConnector.mSensorDevice.turnOn(true); + mHandler.post(updateRunnable); + } + + @Override + public void onDestroy() { + MainActivity.mSensorConnector.mLocationDevice.turnOn(false); + MainActivity.mSensorConnector.mSensorDevice.turnOn(false); + mHandler.removeCallbacks(updateRunnable); + super.onDestroy(); + } + + public AboutFragment() { + super("AboutFragment"); + } + + private final Runnable updateRunnable = new Runnable() { + @Override + public void run() { + TextView timeStampView = (TextView) getActivity().findViewById(R.id.timeStamp); + TextView locationView = (TextView) getActivity().findViewById(R.id.GeoLocation); + TextView eCompassView = (TextView) getActivity().findViewById(R.id.eCompass); + + TextView radioVersion = (TextView) getActivity().findViewById(R.id.radioVersion); + TextView modelVersion = (TextView) getActivity().findViewById(R.id.modelVersion); + TextView moduleRfidOnStatus = (TextView) getActivity().findViewById(R.id.moduleRfid_onStatus); + TextView moduleBarOnStatus = (TextView) getActivity().findViewById(R.id.moduleBar_onStatus); + TextView triggerOnStatus = (TextView) getActivity().findViewById(R.id.trigger_onStatus); + TextView moduleBattery = (TextView) getActivity().findViewById(R.id.module_battery); + TextView moduleVersionLabel = (TextView) getActivity().findViewById(R.id.module_versionLabel); + if (MainActivity.csLibrary4A.get98XX() == 2) moduleVersionLabel.setText("Atmel firmware version"); + else if (MainActivity.csLibrary4A.get98XX() == 0) moduleVersionLabel.setText("SiliconLab firmware version"); + TextView moduleVersion = (TextView) getActivity().findViewById(R.id.module_version); + TextView radioSerial = (TextView) getActivity().findViewById(R.id.radio_serialnumber); + TextView radioBoardVersion = (TextView) getActivity().findViewById(R.id.radio_boardVersion); + TextView productSerial = (TextView) getActivity().findViewById(R.id.module_productserialnumber); + TextView boardVersion = (TextView) getActivity().findViewById(R.id.module_boardversion); + TextView barcodeSerial = (TextView) getActivity().findViewById(R.id.moduleBar_serialNumber); + TextView barcodeDate = (TextView) getActivity().findViewById(R.id.moduleBar_date); + TextView barcodeVersion = (TextView) getActivity().findViewById(R.id.moduleBar_version); + + TextView bluetoothVersion = (TextView) getActivity().findViewById(R.id.bluetooth_version); + TextView bluetoothAddress = (TextView) getActivity().findViewById(R.id.bluetooth_address); + TextView bluetoothRssi = (TextView) getActivity().findViewById(R.id.bluetooth_rssi); + + timeStampView.setText(MainActivity.mSensorConnector.getTimeStamp()); + locationView.setText(MainActivity.mSensorConnector.mLocationDevice.getLocation()); + eCompassView.setText(MainActivity.mSensorConnector.mSensorDevice.getEcompass()); + if (MainActivity.csLibrary4A.isBleConnected()) { + if (System.currentTimeMillis() - timeMillis > 5000) { + timeMillis = System.currentTimeMillis(); + radioVersion.setText(MainActivity.csLibrary4A.getMacVer()); + modelVersion.setText(MainActivity.csLibrary4A.getModelNumber()); + moduleVersion.setText(MainActivity.csLibrary4A.hostProcessorICGetFirmwareVersion()); + bluetoothVersion.setText(MainActivity.csLibrary4A.getBluetoothICFirmwareVersion()); + MainActivity.csLibrary4A.batteryLevelRequest(); + } + moduleRfidOnStatus.setText(MainActivity.csLibrary4A.getRfidOnStatus() ? "on" : "off"); + triggerOnStatus.setText(MainActivity.csLibrary4A.getTriggerButtonStatus() ? "pressed" : "released"); + moduleBarOnStatus.setText(MainActivity.csLibrary4A.getBarcodeOnStatus() ? "on" : "off"); + moduleBattery.setText(MainActivity.csLibrary4A.getBatteryDisplay(true)); + if (MainActivity.csLibrary4A.isRfidFailure()) radioSerial.setText("Not available"); + else radioSerial.setText(MainActivity.csLibrary4A.getRadioSerial()); + radioBoardVersion.setText(MainActivity.csLibrary4A.getRadioBoardVersion()); + productSerial.setText(MainActivity.csLibrary4A.getHostProcessorICSerialNumber()); + boardVersion.setText(MainActivity.csLibrary4A.getHostProcessorICBoardVersion()); + if (MainActivity.csLibrary4A.isBarcodeFailure()) barcodeSerial.setText("Not available"); + else { + barcodeSerial.setText(MainActivity.csLibrary4A.getBarcodeSerial()); + barcodeDate.setText(MainActivity.csLibrary4A.getBarcodeDate()); + barcodeVersion.setText(MainActivity.csLibrary4A.getBarcodeVersion()); + } + bluetoothAddress.setText(MainActivity.csLibrary4A.getBluetoothDeviceAddress()); + bluetoothRssi.setText(String.valueOf(MainActivity.csLibrary4A.getRssi())); + } else { + radioVersion.setText(""); + moduleRfidOnStatus.setText(""); + moduleBarOnStatus.setText(""); + triggerOnStatus.setText(""); + moduleBattery.setText(""); + moduleVersion.setText(""); + bluetoothVersion.setText(""); + radioSerial.setText(""); + radioBoardVersion.setText(""); + productSerial.setText(""); + boardVersion.setText(""); + barcodeSerial.setText(""); + bluetoothAddress.setText(""); + bluetoothRssi.setText(""); + } + mHandler.postDelayed(updateRunnable, 1000); + } + }; +} diff --git a/app/src/main/java/com/csl/cs710awedgeapp/fragments/CommonFragment.java b/app/src/main/java/com/csl/cs710awedgeapp/fragments/CommonFragment.java index 894aea3..a47a5c0 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/fragments/CommonFragment.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/fragments/CommonFragment.java @@ -5,11 +5,6 @@ import android.graphics.Color; import android.os.Bundle; import android.os.Handler; - -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; - import android.text.SpannableString; import android.text.style.ForegroundColorSpan; import android.util.Log; @@ -21,10 +16,14 @@ import android.view.ViewGroup; import android.widget.Toast; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; + +import com.csl.cs710awedgeapp.CustomAlertDialog; import com.csl.cs710awedgeapp.CustomPopupWindow; import com.csl.cs710awedgeapp.MainActivity; import com.csl.cs710awedgeapp.R; -import com.csl.cs710library4a.CustomAlertDialog; public abstract class CommonFragment extends Fragment { final boolean DEBUG = false; final String TAG = "Hello"; @@ -74,10 +73,20 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void run() { short reportCount = 5; - if (MainActivity.csLibrary4A.isBleConnected()) reportCount = MainActivity.csLibrary4A.getTriggerReportingCount(); + if (MainActivity.csLibrary4A.isBleConnected()) { + byte[] notificationData = MainActivity.csLibrary4A.onNotificationEvent(); + if (false && notificationData != null) { + MainActivity.csLibrary4A.appendToLog("2 matched Error: " + MainActivity.csLibrary4A.byteArrayToString(notificationData)); + CustomPopupWindow customPopupWindow = new CustomPopupWindow(MainActivity.mContext); + customPopupWindow.popupStart("Common Notification Error Code A101: " + MainActivity.csLibrary4A.byteArrayToString(notificationData), false); + } + reportCount = MainActivity.csLibrary4A.getTriggerReportingCount(); + } + mHandler.postDelayed(updateTriggerRunnable, reportCount * 1100); if (menuTriggerItem == null) return; if (MainActivity.csLibrary4A.isBleConnected() == false) { menuTriggerItem.setTitle(""); return; } + int triggerCount = MainActivity.csLibrary4A.getTriggerCount(); if (triggerCount != triggerCount_old) { triggerCount_old = triggerCount; @@ -130,23 +139,27 @@ public void run() { if (MainActivity.csLibrary4A.isRfidFailure()) { if (rfidFailure == false) { rfidFailure = true; - CustomAlertDialog appdialog = new CustomAlertDialog(); - appdialog.Confirm((Activity) MainActivity.mContext, "Rfid Transmission failure", - "Do you want to disconnect the Bluetooth ?", - "No thanks", "Disconnect", - new Runnable() { - @Override - public void run() { - if (DEBUG) MainActivity.csLibrary4A.appendToLog("Confirm is pressed"); - MainActivity.csLibrary4A.forceBTdisconnect(); - } - }, - new Runnable() { - @Override - public void run() { - if (DEBUG) MainActivity.csLibrary4A.appendToLog("Cancel is pressed."); - } - }); + if (false) { + CustomAlertDialog appdialog = new CustomAlertDialog(); + appdialog.Confirm((Activity) MainActivity.mContext, "Rfid Transmission failure", + "Do you want to disconnect the Bluetooth ?", + "No thanks", "Disconnect", + new Runnable() { + @Override + public void run() { + if (DEBUG) + MainActivity.csLibrary4A.appendToLog("Confirm is pressed"); + MainActivity.csLibrary4A.forceBTdisconnect(); + } + }, + new Runnable() { + @Override + public void run() { + if (DEBUG) + MainActivity.csLibrary4A.appendToLog("Cancel is pressed."); + } + }); + } } } else rfidFailure = false; @@ -293,7 +306,7 @@ public void onStop() { @Override public void onDestroyView() { - if (DEBUG) MainActivity.csLibrary4A.appendToLog(fragmentName); + if (false) MainActivity.csLibrary4A.appendToLog(fragmentName); super.onDestroyView(); } diff --git a/app/src/main/java/com/csl/cs710awedgeapp/fragments/DirectWedgeFragment.java b/app/src/main/java/com/csl/cs710awedgeapp/fragments/DirectWedgeFragment.java index b1723cb..ff3f1f5 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/fragments/DirectWedgeFragment.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/fragments/DirectWedgeFragment.java @@ -1,11 +1,21 @@ package com.csl.cs710awedgeapp.fragments; +import static android.Manifest.permission.ACCESS_COARSE_LOCATION; +import static android.Manifest.permission.ACCESS_FINE_LOCATION; +import static android.Manifest.permission.BLUETOOTH_CONNECT; +import static android.Manifest.permission.BLUETOOTH_SCAN; +import static android.Manifest.permission.READ_EXTERNAL_STORAGE; +import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; +import static android.content.Context.LOCATION_SERVICE; + +import static com.csl.cs710awedgeapp.MainActivity.mContext; + import android.Manifest; import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.content.pm.PackageManager; -import android.graphics.Color; import android.graphics.drawable.ColorDrawable; +import android.location.LocationManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -34,9 +44,9 @@ import com.csl.cs710awedgeapp.adapters.ReaderListAdapter; import com.csl.cs710awedgeapp.MainActivity; import com.csl.cs710awedgeapp.R; -import com.csl.cs710library4a.CsLibrary4A; -import com.csl.cs710library4a.CustomAlertDialog; -import com.csl.cs710library4a.ReaderDevice; +import com.csl.cs710awedgeapp.CustomAlertDialog; +import com.csl.cslibrary4a.BluetoothGatt; +import com.csl.cslibrary4a.ReaderDevice; import java.util.ArrayList; import java.util.List; @@ -46,7 +56,6 @@ public class DirectWedgeFragment extends CommonFragment { private ArrayList readersList = MainActivity.sharedObjects.readersList; Handler handler = new Handler(); private ReaderListAdapter readerListAdapter; - private CsLibrary4A mCsLibrary4A = MainActivity.csLibrary4A; boolean bConnecting = false; boolean bCurrentIMEmatched = false; String stringImeExpected, stringLabelExpected; @@ -65,6 +74,7 @@ public void onActivityCreated(Bundle savedInstanceState) { TableRow tableRow2 = getActivity().findViewById(R.id.directWedgeRow2); TableRow tableRow3 = getActivity().findViewById(R.id.directWedgeRow3); TableRow tableRow4 = getActivity().findViewById(R.id.directWedgeRow4); + TableRow tableRow5 = getActivity().findViewById(R.id.directWedgeRow5); TableRow tableRowStart = getActivity().findViewById(R.id.directWedgeRowStart); if (getActivity().getPackageName().contains("cs710awedgeapp")) { androidx.appcompat.app.ActionBar actionBar; @@ -72,9 +82,11 @@ public void onActivityCreated(Bundle savedInstanceState) { actionBar.setIcon(R.drawable.dl_access); ColorDrawable colorDrawable = new ColorDrawable(getResources().getColor(R.color.colorPrimary)); actionBar.setBackgroundDrawable(colorDrawable); - actionBar.setTitle("CSL Data Wedge v" + BuildConfig.VERSION_NAME); - - } else if (getActivity().getPackageName().contains("cs710ademoapp")) { + actionBar.setTitle(R.string.app_ime_simplewedge1); + actionBar.setDisplayHomeAsUpEnabled(false); + //String strTitle = actionBar.getTitle().toString() + " v" + BuildConfig.VERSION_NAME; + //actionBar.setTitle(strTitle); + } else { //if (getActivity().getPackageName().contains("cs710ademoapp")) { ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); actionBar.setIcon(R.drawable.dl_inv); actionBar.setTitle("Wedge"); @@ -83,6 +95,7 @@ public void onActivityCreated(Bundle savedInstanceState) { tableRow2.setVisibility(View.GONE); tableRow3.setVisibility(View.GONE); tableRow4.setVisibility(View.GONE); + tableRow5.setVisibility(View.GONE); tableRowStart.setVisibility(View.VISIBLE); } @@ -103,7 +116,7 @@ public void onActivityCreated(Bundle savedInstanceState) { boolean DEBUG = true; @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (DEBUG) mCsLibrary4A.appendToLog("OnItemClickListener: bConnecting = " + bConnecting + ", position = " + position); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("OnItemClickListener: bConnecting = " + bConnecting + ", position = " + position); if (bConnecting) return; ReaderDevice readerDevice = readerListAdapter.getItem(position); @@ -123,12 +136,12 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } readerListAdapter.notifyDataSetChanged(); - if (DEBUG) mCsLibrary4A.appendToLog("OnItemClickListener: readerDevice.getSelected = " + readerDevice.getSelected()); - if (mCsLibrary4A.isBleConnected() && readerDevice.getSelected() == false && readerDevice.isConnected()) { - if (DEBUG) mCsLibrary4A.appendToLog("OnItemClickListener: going to disconnect"); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("OnItemClickListener: readerDevice.getSelected = " + readerDevice.getSelected()); + if (MainActivity.csLibrary4A.isBleConnected() && readerDevice.getSelected() == false && readerDevice.isConnected()) { + if (DEBUG) MainActivity.csLibrary4A.appendToLog("OnItemClickListener: going to disconnect"); disconnectWedge(); - } else if (mCsLibrary4A.isBleConnected() == false && readerDevice.getSelected()) { - if (DEBUG) mCsLibrary4A.appendToLog("OnItemClickListener: going to CONNECT"); + } else if (MainActivity.csLibrary4A.isBleConnected() == false && readerDevice.getSelected()) { + if (DEBUG) MainActivity.csLibrary4A.appendToLog("OnItemClickListener: going to CONNECT"); if (true) connectWedge(readerDevice); } } @@ -138,7 +151,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) buttonSetup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mCsLibrary4A.isBleConnected() || true) new SettingWedgeFragment().show(getChildFragmentManager(), "TAG"); + if (MainActivity.csLibrary4A.isBleConnected() || true) new SettingWedgeFragment().show(getChildFragmentManager(), "TAG"); else if (MainActivity.csLibrary4A.mrfidToWriteSize() != 0) Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.toast_not_ready), Toast.LENGTH_SHORT).show(); else Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.toast_ble_not_connected), Toast.LENGTH_SHORT).show(); } @@ -149,7 +162,7 @@ public void onClick(View v) { @Override public void onClick(View v) { if (bConnecting) return; - if (mCsLibrary4A.isBleConnected()) { + if (MainActivity.csLibrary4A.isBleConnected()) { disconnectWedge(); readerListAdapter.notifyDataSetChanged(); } else { @@ -168,11 +181,12 @@ public void onClick(View v) { }); Button buttonStart = (Button) getActivity().findViewById(R.id.directWedgeButtonStart); + if (getActivity().getPackageName().matches("com.csl.cs710ademoapp")) buttonStart.setVisibility(View.VISIBLE); buttonStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (mCsLibrary4A.isBleConnected()) { - if (mCsLibrary4A.mrfidToWriteSize() == 0) { + if (MainActivity.csLibrary4A.isBleConnected()) { + if (MainActivity.csLibrary4A.mrfidToWriteSize() == 0) { MainActivity.wedged = true; Intent i = new Intent(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_HOME); @@ -186,7 +200,7 @@ public void onClick(View v) { buttonInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - CustomPopupWindow customPopupWindow = new CustomPopupWindow(MainActivity.mContext); + CustomPopupWindow customPopupWindow = new CustomPopupWindow(mContext); String stringInfo = "1. For the first time launching the application, please grant device permission for location, connectivity and enabling . \n\n" + "2. Readers will be discovered by the app and please check the box on the right hand side to select the reader to be connected. \n\n" + @@ -201,7 +215,8 @@ public void onClick(View v) { } }); - handler.post(runnableStart); + handler.post(runnableStartService); + handler.postDelayed(runnableStart, 1000); } @Override @@ -222,17 +237,85 @@ public DirectWedgeFragment() { } void disconnectWedge() { - mCsLibrary4A.disconnect(false); bleDisConnecting = true; bConnecting = false; + MainActivity.csLibrary4A.disconnect(false); bleDisConnecting = true; bConnecting = false; readersList.clear(); buttonConnect.setText("Connect"); handler.removeCallbacks(runnableStart); handler.postDelayed(runnableStart, 2000); } void connectWedge(ReaderDevice readerDevice) { MainActivity.csLibrary4A.scanLeDevice(false); - mCsLibrary4A.connect(readerDevice); bConnecting = true; + MainActivity.csLibrary4A.connect(readerDevice); bConnecting = true; buttonConnect.setText("Connecting"); } + Runnable runnableStartService = new Runnable() { + boolean DEBUG = false; + + @Override + public void run() { + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, WRITE_EXTERNAL_STORAGE) = " + ActivityCompat.checkSelfPermission(mContext, WRITE_EXTERNAL_STORAGE)); + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, READ_EXTERNAL_STORAGE) = " + ActivityCompat.checkSelfPermission(mContext, READ_EXTERNAL_STORAGE)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (mContext.checkSelfPermission(WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + MainActivity.csLibrary4A.appendToLog("runnableStartService: requestPermissions WRITE_EXTERNAL_STORAGE"); // + requestPermissions(new String[] { WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE }, 1); + //Toast.makeText(mContext, com.csl.cslibrary4a.R.string.toast_permission_not_granted, Toast.LENGTH_SHORT).show(); + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: WRITE_EXTERNAL_STORAGE is permitted"); /// + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: no need to handle WRITE_EXTERNAL_STORAGE"); + + LocationManager locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); + MainActivity.csLibrary4A.appendToLog("runnableStartService: locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) = " + locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)); + MainActivity.csLibrary4A.appendToLog("runnableStartService: locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) = " + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)); + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, ACCESS_FINE_LOCATION) = " + ActivityCompat.checkSelfPermission(mContext, ACCESS_FINE_LOCATION)); + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, ACCESS_COARSE_LOCATION) = " + ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if ((ActivityCompat.checkSelfPermission(mContext, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { + CustomAlertDialog appdialog = new CustomAlertDialog(); + appdialog.Confirm(getActivity(), "Use your location", + "This app collects location data in the background. In terms of the features using this location data in the background, this App collects location data when it is reading RFID tag in all inventory pages. The purpose of this is to correlate the RFID tag with the actual GNSS(GPS) location of the tag. In other words, this is to track the physical location of the logistics item tagged with the RFID tag.", + "No thanks", "Turn on", + new Runnable() { + @Override + public void run() { + MainActivity.csLibrary4A.appendToLog("runnableStartService: allow permission in ACCESS_FINE_LOCATION handler"); + MainActivity.csLibrary4A.appendToLog("runnableStartService: requestPermissions ACCESS_FINE_LOCATION"); + requestPermissions(new String[] { ACCESS_FINE_LOCATION }, 123); //ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION + //if (false) Toast.makeText(mContext, com.csl.cslibrary4a.R.string.toast_permission_not_granted, Toast.LENGTH_SHORT).show(); + /*{ + LocationManager locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE); + if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) == false && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) == false) { + MainActivity.csLibrary4A.appendToLog("popupAlert: StreamOut: start activity ACTION_LOCATION_SOURCE_SETTINGS"); + Intent intent1 = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + mContext.startActivity(intent1); + } + }*/ + //bleEnableRequestShown0 = true; mHandler.postDelayed(mRquestAllowRunnable, 60000); + //bAlerting = false; + } + }, + new Runnable() { + @Override + public void run() { + MainActivity.csLibrary4A.appendToLog("runnableStartService: reject permission in ACCESS_FINE_LOCATION handler"); + //bAlerting = false; + //bleEnableRequestShown0 = true; mHandler.postDelayed(mRquestAllowRunnable, 60000); + } + }); + MainActivity.csLibrary4A.appendToLog("runnableStartService: started ACCESS_FINE_LOCATION handler"); + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: handled ACCESS_FINE_LOCATION"); + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: no need to handle ACCESS_FINE_LOCATION"); + + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, BLUETOOTH_CONNECT) = " + ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_CONNECT)); + MainActivity.csLibrary4A.appendToLog("runnableStartService: ActivityCompat.checkSelfPermission(activity, BLUETOOTH_SCAN) = " + ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_SCAN)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { + MainActivity.csLibrary4A.appendToLog("runnableStartService: requestPermissions BLUETOOTH_SCAN and BLUETOOTH_CONNECT"); + requestPermissions(new String[] { BLUETOOTH_SCAN, BLUETOOTH_CONNECT }, 123); + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: handled BLUETOOTH_CONNECT and BLUETOOTH_SCAN"); + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: no need to handle BLUETOOTH_SCAN and BLUETOOTH_CONNECT"); + } + }; + int runningMode = -1, connectWait = 0, scanWait = 0; Runnable runnableStart = new Runnable() { @Override @@ -241,7 +324,7 @@ public void run() { if (MainActivity.csLibrary4A.isBleConnected()) { if (MainActivity.csLibrary4A.mrfidToWriteSize() == 0) { MainActivity.csLibrary4A.setPowerLevel(MainActivity.wedgePower); - MainActivity.csLibrary4A.appendToLog("isBleConnected is true with mrfidToWriteSize = " + mCsLibrary4A.mrfidToWriteSize()); + MainActivity.csLibrary4A.appendToLog("runnableStart: isBleConnected is true with mrfidToWriteSize = " + MainActivity.csLibrary4A.mrfidToWriteSize()); bConnecting = false; for (int i = 0; i < readersList.size(); i++) { ReaderDevice readerDevice = readersList.get(i); @@ -255,23 +338,25 @@ public void run() { return; } //else Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.toast_not_ready), Toast.LENGTH_SHORT).show(); } else if (bConnecting) { - MainActivity.csLibrary4A.appendToLog("bConnecting is true"); + MainActivity.csLibrary4A.appendToLog("runnableStart: bConnecting is true"); } else if (MainActivity.csLibrary4A.isBleScanning()) { - MainActivity.csLibrary4A.appendToLog("isBleScanning is true"); + MainActivity.csLibrary4A.appendToLog("runnableStart: isBleScanning is true"); boolean listUpdated = false; - if (false && ++scanWait > 10) { + if (++scanWait > 10) { + boolean bValue1 = MainActivity.csLibrary4A.scanLeDevice(false); + MainActivity.csLibrary4A.appendToLog("runnableStart: STOP scanning with result = " + bValue1); scanWait = 0; readersList.clear(); listUpdated = true; } while (true) { - CsLibrary4A.Cs108ScanData cs108ScanData = MainActivity.csLibrary4A.getNewDeviceScanned(); + BluetoothGatt.Cs108ScanData cs108ScanData = MainActivity.csLibrary4A.getNewDeviceScanned(); if (cs108ScanData != null) { - CsLibrary4A.Cs108ScanData scanResultA = cs108ScanData; + BluetoothGatt.Cs108ScanData scanResultA = cs108ScanData; if (getActivity() == null) continue; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) continue; + if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) continue; } else if (ActivityCompat.checkSelfPermission(getActivity().getApplicationContext(), Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) continue; - if (DEBUG) mCsLibrary4A.appendToLog("scanResultA.device.getType() = " + scanResultA.device.getType() + ". scanResultA.rssi = " + scanResultA.rssi); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("runnableStart: scanResultA.device.getType() = " + scanResultA.device.getType() + ". scanResultA.rssi = " + scanResultA.rssi); if (scanResultA.device.getType() == BluetoothDevice.DEVICE_TYPE_LE && (true || scanResultA.rssi < 0)) { boolean match = false; for (int i = 0; i < readersList.size(); i++) { @@ -296,16 +381,31 @@ public void run() { readersList.add(readerDevice); listUpdated = true; } } else { - if (DEBUG) mCsLibrary4A.appendToLog("deviceScanTask: rssi=" + scanResultA.rssi + ", error type=" + scanResultA.device.getType()); + if (DEBUG) MainActivity.csLibrary4A.appendToLog("runnableStart: deviceScanTask: rssi=" + scanResultA.rssi + ", error type=" + scanResultA.device.getType()); } - } else break; + scanWait = 0; + } else { + MainActivity.csLibrary4A.appendToLog("runnableStart: NO reader is found with scanWait = " + scanWait); + break; + } } if (listUpdated) readerListAdapter.notifyDataSetChanged(); } else { - MainActivity.csLibrary4A.appendToLog("isBleScanning is FALSE"); - bConnecting = false; connectWait = 0; scanWait = 0; - boolean bValue1 = MainActivity.csLibrary4A.scanLeDevice(true); - MainActivity.csLibrary4A.appendToLog("runnableStart: starting scanLeDevice is " + bValue1 + " with isScanning = " + MainActivity.csLibrary4A.isBleScanning()); + MainActivity.csLibrary4A.appendToLog("runnableStart: isBleScanning is FALSE"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(mContext, BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { + //MainActivity.csLibrary4A.appendToLog("runnableStartService: requestPermissions BLUETOOTH_SCAN and BLUETOOTH_CONNECT"); + //requestPermissions(new String[] { BLUETOOTH_SCAN, BLUETOOTH_CONNECT }, 123); + MainActivity.csLibrary4A.appendToLog("runnableStart: CANNOT start scanLeDevice as BLUETOOTH_CONNECT && BLUETOOTH_SCAN is NOT yet permitted"); + } else if ((ActivityCompat.checkSelfPermission(mContext, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(mContext, ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { + MainActivity.csLibrary4A.appendToLog("runnableStart: CANNOT start scanLeDevice as ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION is NOT yet permitted"); + } else { + MainActivity.csLibrary4A.appendToLog("runnableStartService: BLUETOOTH_CONNECT and BLUETOOTH_SCAN and (ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION) is permitted"); + bConnecting = false; connectWait = 0; scanWait = 0; + boolean bValue1 = MainActivity.csLibrary4A.scanLeDevice(true); + MainActivity.csLibrary4A.appendToLog("runnableStart: starting scanLeDevice is " + bValue1 + " with isScanning = " + MainActivity.csLibrary4A.isBleScanning()); + } + } else MainActivity.csLibrary4A.appendToLog("runnableStartService: no need to handle BLUETOOTH_SCAN and BLUETOOTH_CONNECT"); } handler.postDelayed(runnableStart, 1000); } @@ -346,13 +446,14 @@ void updateCurrentIMEMatched() { boolean bFound = false; List list = null; stringImeExpected = getActivity().getPackageName() + ".CustomIME"; - if (MainActivity.drawerPositionsDefault != DrawerListContent.DrawerPositions.MAIN) stringLabelExpected = getResources().getString(R.string.app_ime1); - else stringLabelExpected = getResources().getString(R.string.app_ime); + if (MainActivity.drawerPositionsDefault != DrawerListContent.DrawerPositions.MAIN) stringLabelExpected = getResources().getString(R.string.app_ime_simplewedge1); + else if (getActivity().getPackageName().contains("cs710ademoapp")) stringLabelExpected = getResources().getString(R.string.app_ime_cs710); + else stringLabelExpected = getResources().getString(R.string.app_ime_cs108); InputMethodManager inputMethodManager = inputMethodManager = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE); MainActivity.csLibrary4A.appendToLog("FEATURE_INPUT_METHODS is " + getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_INPUT_METHODS)); list = inputMethodManager.getEnabledInputMethodList(); bFound = false; - //MainActivity.csLibrary4A.appendToLog("getCurrentInputMethodSubtype = " + inputMethodManager.getCurrentInputMethodSubtype().getLanguageTag()); + MainActivity.csLibrary4A.appendToLog("getCurrentInputMethodSubtype = " + inputMethodManager.getCurrentInputMethodSubtype().getLanguageTag()); for (int i = 0; i < list.size(); i++) { MainActivity.csLibrary4A.appendToLog("enabled " + i + ": " + list.get(i).getServiceName() + ", " + list.get(i).getPackageName() @@ -387,7 +488,7 @@ void updateCurrentIMEMatched() { if (list.get(i).getServiceName().contains(stringImeExpected) && list.get(i).loadLabel(getActivity().getPackageManager()).toString().contains(stringLabelExpected)) { bFound = true; MainActivity.csLibrary4A.appendToLog("Found expected IME with id = " + list.get(i).getId()); - String idCurrent = Settings.Secure.getString(MainActivity.mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); + String idCurrent = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); MainActivity.csLibrary4A.appendToLog("Found current IME with id = " + idCurrent); if (list.get(i).getId().matches(idCurrent)) { MainActivity.csLibrary4A.appendToLog("expected IME matches current IME"); diff --git a/app/src/main/java/com/csl/cs710awedgeapp/fragments/SettingWedgeFragment.java b/app/src/main/java/com/csl/cs710awedgeapp/fragments/SettingWedgeFragment.java index 18c9b93..324bf41 100644 --- a/app/src/main/java/com/csl/cs710awedgeapp/fragments/SettingWedgeFragment.java +++ b/app/src/main/java/com/csl/cs710awedgeapp/fragments/SettingWedgeFragment.java @@ -19,7 +19,7 @@ public class SettingWedgeFragment extends DialogFragment { EditText editTextPower, editTextPrefix, editTextSuffix; - Spinner spinnerDelimiter; + Spinner spinnerDelimiter, spinnerOutput; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -59,6 +59,8 @@ public void onClick(DialogInterface dialog, int whichButton) { break; } MainActivity.wedgeDelimiter = wedgeDelimiter; + MainActivity.csLibrary4A.appendToLog("SettingWedgeFragment, onCreateDialog: wedgeDelimiter = " + MainActivity.wedgeOutput); + MainActivity.wedgeOutput = spinnerOutput.getSelectedItemPosition(); saveWedgeSetting2File(); getDialog().dismiss(); } @@ -87,6 +89,7 @@ public void onClick(DialogInterface dialog, int whichButton) { MainActivity.csLibrary4A.appendToLog("targetAdapter is " + (targetAdapter == null ? "null" : "valid")); targetAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); int position = 0; + MainActivity.csLibrary4A.appendToLog("SettingWedgeFragment, onCreatDialog: wedgeDelimiter = " + MainActivity.wedgeDelimiter); switch (MainActivity.wedgeDelimiter) { default: position = 0; @@ -107,6 +110,17 @@ public void onClick(DialogInterface dialog, int whichButton) { MainActivity.csLibrary4A.appendToLog("position is " + position); spinnerDelimiter.setAdapter(targetAdapter); spinnerDelimiter.setSelection(position); + + spinnerOutput = (Spinner) view.findViewById(R.id.directWedgeSettingSpinnerOutput); + MainActivity.csLibrary4A.appendToLog("spinnerOutput is " + (spinnerOutput == null ? "null" : "valid")); + ArrayAdapter targetAdapter1 = ArrayAdapter.createFromResource(getActivity(), R.array.wedgeOutput_options, R.layout.custom_spinner_layout); + MainActivity.csLibrary4A.appendToLog("targetAdapter1 is " + (targetAdapter1 == null ? "null" : "valid")); + targetAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + int position1 = MainActivity.wedgeOutput; + MainActivity.csLibrary4A.appendToLog("position1 is " + position1); + spinnerOutput.setAdapter(targetAdapter1); + spinnerOutput.setSelection(position1); + return builder.create(); } @@ -120,7 +134,8 @@ void saveWedgeSetting2File() { write2FileStream(stream, "wedgePower," + MainActivity.wedgePower + "\n"); write2FileStream(stream, "wedgePrefix," + MainActivity.wedgePrefix + "\n"); write2FileStream(stream, "wedgeSuffix," + MainActivity.wedgeSuffix + "\n"); - write2FileStream(stream, "wedgeDelimiter," + String.valueOf(MainActivity.wedgeDelimiter) + "\n"); + write2FileStream(stream, "wedgeDelimiter," + String.valueOf(MainActivity.wedgeDelimiter) + "\n"); MainActivity.csLibrary4A.appendToLog("SettingWedgeFragment, saveWedgeFragment: wedgeDelimiter = " + MainActivity.wedgeDelimiter); + write2FileStream(stream, "wedgeOutput," + String.valueOf(MainActivity.wedgeOutput) + "\n"); write2FileStream(stream, "End of data\n"); stream.close(); } catch (Exception ex){ diff --git a/app/src/main/res/drawable/alert.png b/app/src/main/res/drawable/alert.png new file mode 100644 index 0000000..5199518 Binary files /dev/null and b/app/src/main/res/drawable/alert.png differ diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 0000000..4d1f8db --- /dev/null +++ b/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,656 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +