mirror of
https://github.com/mik3y/usb-serial-for-android.git
synced 2026-08-11 16:32:53 +00:00
fixed some warnings
This commit is contained in:
+8
-5
@@ -5,6 +5,8 @@ import android.content.Context;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.ListFragment;
|
||||
import android.view.Menu;
|
||||
@@ -25,7 +27,7 @@ import java.util.Locale;
|
||||
|
||||
public class DevicesFragment extends ListFragment {
|
||||
|
||||
class ListItem {
|
||||
static class ListItem {
|
||||
UsbDevice device;
|
||||
int port;
|
||||
UsbSerialDriver driver;
|
||||
@@ -37,7 +39,7 @@ public class DevicesFragment extends ListFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<ListItem> listItems = new ArrayList<>();
|
||||
private final ArrayList<ListItem> listItems = new ArrayList<>();
|
||||
private ArrayAdapter<ListItem> listAdapter;
|
||||
private int baudRate = 19200;
|
||||
private boolean withIoManager = true;
|
||||
@@ -47,8 +49,9 @@ public class DevicesFragment extends ListFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
listAdapter = new ArrayAdapter<ListItem>(getActivity(), 0, listItems) {
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
public View getView(int position, View view, @NonNull ViewGroup parent) {
|
||||
ListItem item = listItems.get(position);
|
||||
if (view == null)
|
||||
view = getActivity().getLayoutInflater().inflate(R.layout.device_list_item, parent, false);
|
||||
@@ -78,7 +81,7 @@ public class DevicesFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_devices, menu);
|
||||
}
|
||||
|
||||
@@ -142,7 +145,7 @@ public class DevicesFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
public void onListItemClick(@NonNull ListView l, @NonNull View v, int position, long id) {
|
||||
ListItem item = listItems.get(position-1);
|
||||
if(item.driver == null) {
|
||||
Toast.makeText(getActivity(), "no driver", Toast.LENGTH_SHORT).show();
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class MainActivity extends AppCompatActivity implements FragmentManager.O
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
if(intent.getAction().equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")) {
|
||||
if("android.hardware.usb.action.USB_DEVICE_ATTACHED".equals(intent.getAction())) {
|
||||
TerminalFragment terminal = (TerminalFragment)getSupportFragmentManager().findFragmentByTag("terminal");
|
||||
if (terminal != null)
|
||||
terminal.status("USB device detected");
|
||||
|
||||
+9
-9
@@ -42,7 +42,7 @@ import java.util.concurrent.Executors;
|
||||
|
||||
public class TerminalFragment extends Fragment implements SerialInputOutputManager.Listener {
|
||||
|
||||
private enum UsbPermission { Unknown, Requested, Granted, Denied };
|
||||
private enum UsbPermission { Unknown, Requested, Granted, Denied }
|
||||
|
||||
private static final String INTENT_ACTION_GRANT_USB = BuildConfig.APPLICATION_ID + ".GRANT_USB";
|
||||
private static final int WRITE_WAIT_MILLIS = 2000;
|
||||
@@ -51,8 +51,8 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag
|
||||
private int deviceId, portNum, baudRate;
|
||||
private boolean withIoManager;
|
||||
|
||||
private BroadcastReceiver broadcastReceiver;
|
||||
private Handler mainLooper;
|
||||
private final BroadcastReceiver broadcastReceiver;
|
||||
private final Handler mainLooper;
|
||||
private TextView receiveText;
|
||||
private ControlLines controlLines;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag
|
||||
broadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if(intent.getAction().equals(INTENT_ACTION_GRANT_USB)) {
|
||||
if(INTENT_ACTION_GRANT_USB.equals(intent.getAction())) {
|
||||
usbPermission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
|
||||
? UsbPermission.Granted : UsbPermission.Denied;
|
||||
connect();
|
||||
@@ -258,10 +258,10 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag
|
||||
return;
|
||||
}
|
||||
try {
|
||||
byte[] data = (str + '\n').getBytes();
|
||||
byte[] data = (str + '\n').getBytes();
|
||||
SpannableStringBuilder spn = new SpannableStringBuilder();
|
||||
spn.append("send " + data.length + " bytes\n");
|
||||
spn.append(HexDump.dumpHexString(data)+"\n");
|
||||
spn.append(HexDump.dumpHexString(data)).append("\n");
|
||||
spn.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorSendText)), 0, spn.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
receiveText.append(spn);
|
||||
usbSerialPort.write(data, WRITE_WAIT_MILLIS);
|
||||
@@ -291,7 +291,7 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag
|
||||
SpannableStringBuilder spn = new SpannableStringBuilder();
|
||||
spn.append("receive " + data.length + " bytes\n");
|
||||
if(data.length > 0)
|
||||
spn.append(HexDump.dumpHexString(data)+"\n");
|
||||
spn.append(HexDump.dumpHexString(data)).append("\n");
|
||||
receiveText.append(spn);
|
||||
}
|
||||
|
||||
@@ -304,8 +304,8 @@ public class TerminalFragment extends Fragment implements SerialInputOutputManag
|
||||
class ControlLines {
|
||||
private static final int refreshInterval = 200; // msec
|
||||
|
||||
private Runnable runnable;
|
||||
private ToggleButton rtsBtn, ctsBtn, dtrBtn, dsrBtn, cdBtn, riBtn;
|
||||
private final Runnable runnable;
|
||||
private final ToggleButton rtsBtn, ctsBtn, dtrBtn, dsrBtn, cdBtn, riBtn;
|
||||
|
||||
ControlLines(View view) {
|
||||
runnable = this::run; // w/o explicit Runnable, a new lambda would be created on each postDelayed, which would not be found again by removeCallbacks
|
||||
|
||||
Reference in New Issue
Block a user