Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "com.csl.cs108ademoapp"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 31
versionCode 34
versionName "2.3.0"
versionName "2.3.4"
}
}

Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<service android:name=".CustomIME"
android:label="@string/app_ime"
android:exported="true"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
Expand All @@ -27,6 +28,7 @@

<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ else if (strTidCompared.matches("E2806894") && MainActivity.mDid.matches("E28068

double rssiGeiger = rssi;
if (MainActivity.mCs108Library4a.getRssiDisplaySetting() != 0)
rssiGeiger -= 106.98;
rssiGeiger -= MainActivity.mCs108Library4a.dBuV_dBm_constant;
if (geigerTagRssiView != null)
geigerTagRssiView.setText(String.format("%.1f", rssiGeiger));
if (geigerTagGotView != null) geigerTagGotView.setText(strEpc);
Expand Down
87 changes: 4 additions & 83 deletions app/src/main/java/com/csl/cs108ademoapp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Handler;
import android.os.Parcelable;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.drawerlayout.widget.DrawerLayout;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
Expand All @@ -29,9 +25,6 @@
import com.csl.cs108library4a.Cs108Library4A;
import com.csl.cs108library4a.ReaderDevice;

import java.io.UnsupportedEncodingException;
import java.util.List;

public class MainActivity extends AppCompatActivity {
final boolean DEBUG = false; final String TAG = "Hello";
public static boolean activityActive = false;
Expand All @@ -52,7 +45,6 @@ public class MainActivity extends AppCompatActivity {
public static ReaderDevice tagSelected;
Handler mHandler = new Handler();

public static NfcAdapter nfcAdapter = null;
PendingIntent mPendingIntent;
IntentFilter writeTagFilters[];
String[][] techList;
Expand Down Expand Up @@ -85,28 +77,6 @@ protected void onCreate(Bundle savedInstanceState) {
mCs108Library4a = new Cs108Library4A(mContext, mLogView);
mSensorConnector = new SensorConnector(mContext);

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
List<InputMethodInfo> lst = imeManager.getInputMethodList();
for (InputMethodInfo info : lst) {
// MainActivity.mCs108Library4a.appendToLog(info.getId() + " " + info.loadLabel(getPackageManager()).toString());
}
// Intent intent = new Intent(MainActivity.this, CustomIME.class);
// startService(intent);
// savedInstanceState = null;

nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) MainActivity.mCs108Library4a.appendToLog("onNewIntent !!! This device doesn't support NFC");
else if (nfcAdapter.isEnabled() == false) MainActivity.mCs108Library4a.appendToLog("onNewIntent !!! This device doesn't enable NFC");
else {
readFromIntent(getIntent());

mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
writeTagFilters = new IntentFilter[] { tagDetected };
techList = new String[][]{{android.nfc.tech.Ndef.class.getName()}, {android.nfc.tech.NdefFormatable.class.getName()}};
}

super.onCreate(savedInstanceState);
if (savedInstanceState == null) selectItem(DrawerPositions.MAIN);
Log.i(TAG, "MainActivity.onCreate.onCreate: END");
Expand All @@ -128,15 +98,13 @@ protected void onStart() {
@Override
protected void onResume() {
super.onResume();
if (nfcAdapter != null && nfcAdapter.isEnabled()) nfcAdapter.enableForegroundDispatch(this, mPendingIntent, writeTagFilters, techList);
activityActive = true; wedged = false;
if (DEBUG) mCs108Library4a.appendToLog("MainActivity.onResume()");
}

@Override
protected void onPause() {
if (DEBUG) mCs108Library4a.appendToLog("MainActivity.onPause()");
if (nfcAdapter != null) nfcAdapter.disableForegroundDispatch(this);
activityActive = false;
super.onPause();
}
Expand Down Expand Up @@ -290,7 +258,9 @@ public void onBackPressed() {
public static boolean permissionRequesting;
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
MainActivity.mCs108Library4a.appendToLog("onRequestPermissionsResult ====");
MainActivity.mCs108Library4a.appendToLog("permissionRequesting: requestCode = " + requestCode + ", permissions is " + (permissions == null ? "null" : "valid") + ", grantResults is " + (grantResults == null ? "null" : "valid") );
MainActivity.mCs108Library4a.appendToLog("permissionRequesting: permissions[" + permissions.length + "] = " + (permissions != null && permissions.length > 0 ? permissions[0] : ""));
MainActivity.mCs108Library4a.appendToLog("permissionRequesting: grantResults[" + grantResults.length + "] = " + (grantResults != null && grantResults.length > 0 ? grantResults[0] : "") );
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
permissionRequesting = false;
}
Expand Down Expand Up @@ -414,58 +384,9 @@ protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mCs108Library4a.appendToLog("onNewIntent !!! intent.getAction = " + intent.getAction());
readFromIntent(intent);
// if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
// }
}
private void readFromIntent(Intent intent) {
mCs108Library4a.appendToLog("onNewIntent !!! readFromIntent entry");
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
mCs108Library4a.appendToLog("onNewIntent !!! readFromIntent getAction = " + action);
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
mCs108Library4a.appendToLog("onNewIntent !!! readFromIntent rawMsgs.length = " + rawMsgs.length);
mCs108Library4a.appendToLog("onNewIntent !!! readFromIntent rawMsgs[0].toString = " + rawMsgs[0].toString());
NdefMessage[] msgs = null;
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
}
buildTagViews(msgs);
}
}

private void buildTagViews(NdefMessage[] msgs) {
if (msgs == null || msgs.length == 0) return;
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs.length = " + msgs.length + ", msgs[0].getRecords().size = " + msgs[0].getRecords().length);

String text = "";
for (int x = 0; x < msgs.length; x++) {
for (int y = 0; y < msgs[0].getRecords().length; y++) {
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs[" + x + "][" + y + "].Inf = " + msgs[x].getRecords()[y].getTnf());
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs[" + x + "][" + y + "].Type = " + mCs108Library4a.byteArrayToString(msgs[x].getRecords()[y].getType()));
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs[" + x + "][" + y + "].Id = " + mCs108Library4a.byteArrayToString(msgs[x].getRecords()[y].getId()));
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs[" + x + "][" + y + "].Payload = " + mCs108Library4a.byteArrayToString(msgs[x].getRecords()[y].getPayload()));
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews msgs[" + x + "][" + y + "].Class = " + msgs[x].getRecords()[y].getClass().toString());
}}

byte[] payload = msgs[0].getRecords()[0].getPayload();
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews payload.length = " + payload.length + ", with payload[0] = " + payload[0]);
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews payload = " + mCs108Library4a.byteArrayToString(payload));
String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16"; // Get the Text Encoding
int languageCodeLength = payload[0] & 0063; // Get the Language Code, e.g. "en"
// String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
try {
// Get the Text
text = new String(payload, languageCodeLength + 1, payload.length - languageCodeLength - 1, textEncoding);
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews text = " + text);
} catch (UnsupportedEncodingException e) {
mCs108Library4a.appendToLog("onNewIntent !!! buildTagViews UnsupportedEncoding" + e.toString());
Log.e("UnsupportedEncoding", e.toString());
}
//tvNFCContent.setText("NFC Content: " + text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import android.os.Environment;
import android.provider.Settings;

import androidx.core.app.ActivityCompat;

import com.csl.cs108library4a.Cs108Library4A;
import com.csl.cs108library4a.ReaderDevice;

Expand Down Expand Up @@ -379,8 +377,11 @@ public String save2File(String messageStr, boolean requestPermission) {
if (mContext.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
mCs108Library4a.appendToLog("WRITE_EXTERNAL_STORAGE Permission is required !!!");
writeExtPermission = false;
if (requestPermission) { MainActivity.permissionRequesting = true; requestPermissions((Activity) mContext, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return null; }
if (requestPermission) {
mCs108Library4a.appendToLog("requestPermissions WRITE_EXTERNAL_STORAGE 1");
MainActivity.permissionRequesting = true; requestPermissions((Activity) mContext, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return null;
}
} else mCs108Library4a.appendToLog("WRITE_EXTERNAL_STORAGE Permission is GRANTED !!!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import com.csl.cs108ademoapp.fragments.SettingFilterPostFragment;
import com.csl.cs108ademoapp.fragments.SettingFilterPreFragment;
import com.csl.cs108ademoapp.fragments.SettingFilterRssiFragment;

public class FilterAdapter extends FragmentStatePagerAdapter {
private final int NO_OF_TABS = 2;
public Fragment fragment0, fragment1;
private final int NO_OF_TABS = 3;
public Fragment fragment0, fragment1, fragment2;

@Override
public Fragment getItem(int position) {
Expand All @@ -24,6 +25,10 @@ public Fragment getItem(int position) {
fragment = new SettingFilterPostFragment();
fragment1 = fragment;
break;
case 2:
fragment = new SettingFilterRssiFragment();
fragment2 = fragment;
break;
default:
fragment = null;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
rssiTextView.setVisibility(View.VISIBLE);
double rssiValue = reader.getRssi();
if (MainActivity.mCs108Library4a.getRssiDisplaySetting() != 0 && rssiValue > 0)
rssiValue -= 106.98;
rssiValue -= MainActivity.mCs108Library4a.dBuV_dBm_constant;
rssiTextView.setText(String.format("%.1f", rssiValue));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ public void run() {

private class DeviceScanTask extends AsyncTask<Void, String, String> {
private long timeMillisUpdate = System.currentTimeMillis();
boolean usbDeviceFound = false;
ArrayList<ReaderDevice> readersListOld = new ArrayList<ReaderDevice>();
boolean wait4process = false; boolean scanning = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.csl.cs108library4a.ReaderDevice;

public class InventoryRfidSearchFragment extends CommonFragment {
final double dBuV_dBm_constant = 106.98;
double dBuV_dBm_constant = MainActivity.mCs108Library4a.dBuV_dBm_constant;
final int labelMin = -90;
final int labelMax = -10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
rfidRunTime = (TextView) getActivity().findViewById(R.id.inventoryRfidRunTime1);
rfidVoltageLevel = (TextView) getActivity().findViewById(R.id.inventoryRfidVoltageLevel1);
TextView rfidFilterOn = (TextView) getActivity().findViewById(R.id.inventoryRfidFilterOn1);
if (mDid != null || (MainActivity.mCs108Library4a.getSelectEnable() == false && MainActivity.mCs108Library4a.getInvMatchEnable() == false))
if (mDid != null || (MainActivity.mCs108Library4a.getSelectEnable() == false && MainActivity.mCs108Library4a.getInvMatchEnable() == false && MainActivity.mCs108Library4a.getRssiFilterEnable() == false))
rfidFilterOn.setVisibility(View.INVISIBLE);

rfidYieldView = (TextView) getActivity().findViewById(R.id.inventoryRfidYield1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.csl.cs108ademoapp.fragments;

import android.inputmethodservice.Keyboard;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SettingFilterFragment extends CommonFragment {
private ViewPager viewPager;
FilterAdapter mAdapter;

private String[] tabs = {"Pre-filter", "Post-filter"};
private String[] tabs = {"Pre-filter", "Post-filter", "Rssi-filter"};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down
Loading