Commit 8c6f4f41 authored by Craig Earley's avatar Craig Earley
Browse files

applies Lint fixes, second iteration

parent c7e60df9
......@@ -65,7 +65,7 @@ public class BenchSampleActivity extends Activity {
Context context;
ProgressDialog progress;
public static final String directory = ReadingsDatabase.directory;
public static aSensor sensor = new aSensor("someid","somename");
public static final aSensor sensor = new aSensor("someid","somename");
Uri pictureUri;
File baseDir;
......@@ -184,7 +184,7 @@ public class BenchSampleActivity extends Activity {
platform = parent.getItemAtPosition(position).toString();
sensorName = null;
sensorAdapter.clear();
sensorAdapter.addItem(new Pair<String,String>("Sensor","0"));
sensorAdapter.addItem(new Pair<>("Sensor", "0"));
sensorAdapter.addItems(db.getSensors(platform));
sensorAdapter.notifyDataSetChanged();
}
......@@ -318,9 +318,8 @@ public class BenchSampleActivity extends Activity {
} else {
makeToast("not successful");
}
}else{ //insert a new entry to the table
}//insert a new entry to the table
}
}
public String getTimestamp() {
......
......@@ -14,9 +14,10 @@ import java.util.UUID;
public class BluetoothSensor implements Parcelable {
private List<UUID> uuids;
private String address, name;
private BluetoothDevice device;
private GattClient gattClient;
private final String address;
private final String name;
private final BluetoothDevice device;
private final GattClient gattClient;
private Listener mListener;
private BluetoothGattCharacteristic readChar, writeChar;
......
......@@ -400,8 +400,8 @@ public class DatabaseActionsActivity extends Activity {
try {
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select tripName, tripID from fieldday_trip");
List<String> trips = new ArrayList<String>();
List<String> ids = new ArrayList<String>();
List<String> trips = new ArrayList<>();
List<String> ids = new ArrayList<>();
while (rs.next()) {
trips.add(rs.getString("tripName"));
ids.add(Integer.toString(rs.getInt("tripID")));
......@@ -532,7 +532,7 @@ public class DatabaseActionsActivity extends Activity {
}
private class uploadTables extends AsyncTask<Void, Integer, Boolean> {
String[] tables = {"fieldday_spot", "fieldday_reading", "fieldday_streaming"};
final String[] tables = {"fieldday_spot", "fieldday_reading", "fieldday_streaming"};
@Override
protected Boolean doInBackground(Void... params) {
......
......@@ -13,7 +13,7 @@ import com.google.android.gms.drive.widget.DataBufferAdapter;
public class DriveResultsAdapter extends DataBufferAdapter<Metadata> {
private Context context;
private final Context context;
public DriveResultsAdapter(Context context) {
super(context, R.layout.file_list);
......
......@@ -10,10 +10,11 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class DropdownListAdapter extends BaseAdapter {
private ArrayList<Pair<String, String>> dropdownList;
private Context context;
private final ArrayList<Pair<String, String>> dropdownList;
private final Context context;
public DropdownListAdapter(Context context) {
super();
......@@ -61,7 +62,7 @@ public class DropdownListAdapter extends BaseAdapter {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.dropdown_item, parent, false);
view = Objects.requireNonNull(inflater).inflate(R.layout.dropdown_item, parent, false);
holder = new ViewHolderItem();
holder.itemName = (TextView) view.findViewById(R.id.itemName);
view.setTag(holder);
......
......@@ -3,12 +3,12 @@ package fieldscience.cs.earlham.edu.fieldday;
import java.util.HashMap;
public class GattAttributes {
private static HashMap<String, String> attributes = new HashMap();
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
public static String BLE_SENSOR_SERVICE = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E";
public static String BLE_SENSOR_VALUE_RX = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E";
public static String BLE_SENSOR_REQUEST_TX = "6E400002-B5A3-F393-E0A9-E50E24DCCA9E";
public static String BLE_DEVICE_INFO = "0000180a-0000-1000-8000-00805f9b34fb";
private static final HashMap<String, String> attributes = new HashMap();
public static final String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
public static final String BLE_SENSOR_SERVICE = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E";
public static final String BLE_SENSOR_VALUE_RX = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E";
public static final String BLE_SENSOR_REQUEST_TX = "6E400002-B5A3-F393-E0A9-E50E24DCCA9E";
public static final String BLE_DEVICE_INFO = "0000180a-0000-1000-8000-00805f9b34fb";
static {
attributes.put(BLE_DEVICE_INFO, "Device Information Service");
......
......@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;
......@@ -44,7 +45,7 @@ public abstract class GoogleDriveConnect extends Activity implements GoogleApiCl
public void onConnected(Bundle bundle) { Log.i("GoogleDriveConnect", "Google Drive Connected");}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
......
......@@ -12,6 +12,7 @@ import android.widget.ImageView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
public class MyDocumentViewer extends Activity {
......@@ -24,9 +25,9 @@ public class MyDocumentViewer extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mydocviewier);
docImageView = (ImageView) findViewById(R.id.myDocView);
fileToOpen = (File) getIntent().getExtras().get("fileToOpen");
fileToOpen = (File) Objects.requireNonNull(getIntent().getExtras()).get("fileToOpen");
if (fileToOpen.getName().endsWith(".pdf")){
if (Objects.requireNonNull(fileToOpen).getName().endsWith(".pdf")){
openPDF();
Log.d("Open PDF", fileToOpen.getName());
} else if (fileToOpen.getName().endsWith(".jpeg") || fileToOpen.getName().endsWith("jpg") ||
......
......@@ -32,6 +32,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class MyDocumentsActivity extends Activity {
......@@ -63,9 +64,9 @@ public class MyDocumentsActivity extends Activity {
}
});
downloadList = new ArrayList<String>();
dirList = new ArrayList<String>();
localDirList = new ArrayList<File>();
downloadList = new ArrayList<>();
dirList = new ArrayList<>();
localDirList = new ArrayList<>();
// Check to see if the root directory exists. If it does, get the list of files in it to
// use for the ListView of file
......@@ -85,10 +86,10 @@ public class MyDocumentsActivity extends Activity {
filesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (myDocumentsAdapter.getItem(position).isDirectory()) {
if (Objects.requireNonNull(myDocumentsAdapter.getItem(position)).isDirectory()) {
File folder = myDocumentsAdapter.getItem(position);
localDirList = getFilesInDir(folder);
if (!folder.equals(rootDir)) {
if (!Objects.requireNonNull(folder).equals(rootDir)) {
localDirList.add(folder.getParentFile());
}
myDocumentsAdapter.clear();
......@@ -133,7 +134,7 @@ public class MyDocumentsActivity extends Activity {
}
public ArrayList<File> getFilesInDir(File directory){
ArrayList<File> list = new ArrayList<File>();
ArrayList<File> list = new ArrayList<>();
if (directory.listFiles().length == 0) {
return null;
} else {
......
package fieldscience.cs.earlham.edu.fieldday;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -10,29 +11,31 @@ import android.widget.TextView;
import java.io.File;
import java.util.ArrayList;
import java.util.Objects;
public class MyDocumentsAdapter extends ArrayAdapter<File> {
private Context context;
private final Context context;
public MyDocumentsAdapter(Context c, ArrayList<File> files) {
super(c, R.layout.file_list, files);
context = c;
}
public View getView(int position, View convertView, ViewGroup parent){
@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent){
File file = getItem(position);
if (convertView == null){
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.file_list, parent, false);
convertView = Objects.requireNonNull(layoutInflater).inflate(R.layout.file_list, parent, false);
}
TextView fName = (TextView) convertView.findViewById(R.id.objectName);
ImageView fType = (ImageView) convertView.findViewById(R.id.objectType);
fName.setText(file.getName());
fName.setText(Objects.requireNonNull(file).getName());
if (file.isDirectory()){
fType.setImageDrawable(context.getResources().getDrawable(R.drawable.folder_black_icon, null));
} else {
......
......@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class ReadingsDatabase extends SQLiteOpenHelper {
......@@ -86,7 +87,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
static final String host = Build.SERIAL;
private static final int DATABASE_VERSION = 1;
public static File dbPath;
public static String[] tables = {T_HOST, T_TRIP, T_SITE, T_SECTOR, T_SPOT, T_PLATFORM, T_SENSOR, T_UPLOAD};
public static final String[] tables = {T_HOST, T_TRIP, T_SITE, T_SECTOR, T_SPOT, T_PLATFORM, T_SENSOR, T_UPLOAD};
public static final String FLOAT = "float";
public static final String INT = "integer";
public static final String TEXT = "text";
......@@ -96,13 +97,13 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
// Array separating columns by type. This is used when updating from remote database;
public static String[] text_columns = {C_SITENOTES, C_SECTORNOTES, C_READINGNOTES,
public static final String[] text_columns = {C_SITENOTES, C_SECTORNOTES, C_READINGNOTES,
C_SPOTNOTES, C_IMAGEFILENAME};
public static String[] varchar_columns = {C_HOSTID, C_TRIPNAME, C_SITENAME, C_SECTORNAME, C_SPOTIMAGEFOLDER,
public static final String[] varchar_columns = {C_HOSTID, C_TRIPNAME, C_SITENAME, C_SECTORNAME, C_SPOTIMAGEFOLDER,
C_PLATFORMID, C_PLATFORMNAME, C_PLATFORMTYPE, C_SENSORID,
C_SENSORID, C_SENSORTYPE, C_SENSORUNITS};
public static String[] integer_columns = {C_TRIPID, C_SITEID, C_SECTORID, C_SPOTID, C_SATELLITES, C_UPLOADID, C_READCOUNT, C_STREAMCOUNT};
public static String[] float_columns = {C_QUALITY, C_LATITUDE, C_LONGITUDE, C_ELEVATION, C_ACCURACY};
public static final String[] integer_columns = {C_TRIPID, C_SITEID, C_SECTORID, C_SPOTID, C_SATELLITES, C_UPLOADID, C_READCOUNT, C_STREAMCOUNT};
public static final String[] float_columns = {C_QUALITY, C_LATITUDE, C_LONGITUDE, C_ELEVATION, C_ACCURACY};
//C_VALUE_ONE, C_VALUE_TWO, C_VALUE_THREE,
private static ReadingsDatabase sInstance = null;
......@@ -388,7 +389,6 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
e.printStackTrace();
}
} else {
success = false;
}
return(success);
}
......@@ -532,7 +532,7 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
new String[]{Integer.toString(siteid), Integer.toString(sectorid)},
null, null, null);
}
while(c.moveToNext()){
while(Objects.requireNonNull(c).moveToNext()){
values.add(Integer.toString(c.getInt(c.getColumnIndex(C_SPOTID))));
}
c.close();
......
......@@ -2,6 +2,7 @@ package fieldscience.cs.earlham.edu.fieldday;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -9,17 +10,19 @@ import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Objects;
public class SensorListAdapter extends ArrayAdapter<aSensor> {
private Context context;
private final Context context;
public SensorListAdapter(Context c, ArrayList<aSensor> sensorArrayList) {
super(c, R.layout.fragment_sensorlist, sensorArrayList);
context = c;
}
public View getView(int position, View convertView, ViewGroup parent) {
@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ViewHolderItem holder;
aSensor sensor = getItem(position);
Resources res = context.getResources();
......@@ -27,7 +30,7 @@ public class SensorListAdapter extends ArrayAdapter<aSensor> {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fragment_sensorlist, parent, false);
convertView = Objects.requireNonNull(inflater).inflate(R.layout.fragment_sensorlist, parent, false);
holder = new ViewHolderItem();
holder.sensorName = (TextView)convertView.findViewById(R.id.sensor);
......@@ -39,7 +42,7 @@ public class SensorListAdapter extends ArrayAdapter<aSensor> {
}
holder.sensorName.setText(String.format(res.getString(R.string.built_in_sensor),
sensor.getName()));
Objects.requireNonNull(sensor).getName()));
if ((sensor.getLastValues() == null) || (sensor.getLastValueString().equals(""))) {
holder.sensorValue.setText("");
} else {
......
......@@ -102,7 +102,7 @@ public class SensorSampleActivity extends Activity {
public static final String directory = ReadingsDatabase.directory;
private ServiceConnection sampleServiceConnection = new ServiceConnection() {
private final ServiceConnection sampleServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
sampleService = ((SensorSampleService.LocalBinder) service).getService();
......@@ -472,7 +472,7 @@ public class SensorSampleActivity extends Activity {
trip_name.setText(String.format("Trip Name: %s", tripName));
context = this;
listSensors = new ArrayList<aSensor>();
listSensors = new ArrayList<>();
remote_db = getIntent().getBooleanExtra(REMOTE_DB, false);
buttonHandler = new Handler();
......@@ -713,7 +713,7 @@ public class SensorSampleActivity extends Activity {
final View dialog = layoutInflater.inflate(R.layout.alert_calibration_value, null);
final EditText value = (EditText) dialog.findViewById(R.id.calibrationValue);
final Spinner dropdown = (Spinner) dialog.findViewById(R.id.sensorSpinner);
ArrayList<String> sensorCalib = new ArrayList<String>();
ArrayList<String> sensorCalib = new ArrayList<>();
for (aSensor s : sensors){
sensorCalib.add(s.getName());
}
......
......@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class SensorSampleService extends Service implements SensorEventListener {
......@@ -74,7 +75,7 @@ public class SensorSampleService extends Service implements SensorEventListener
private static final String TAG = "SensorSampleService";
private ServiceConnection btServiceConnection = new ServiceConnection() {
private final ServiceConnection btServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
btService = ((BluetoothLeService.LocalBinder) service).getService();
......@@ -173,8 +174,8 @@ public class SensorSampleService extends Service implements SensorEventListener
sampleNotes = "";
loggingInterval = 5000;
sensorList = new ArrayList<aSensor>();
builtinList = new ArrayList<Sensor>();
sensorList = new ArrayList<>();
builtinList = new ArrayList<>();
db = ReadingsDatabase.getInstance(this);
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
......@@ -189,7 +190,7 @@ public class SensorSampleService extends Service implements SensorEventListener
// for ActivityCompat#requestPermissions for more details.
return;
}
setLocation(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
setLocation(Objects.requireNonNull(locationManager).getLastKnownLocation(LocationManager.GPS_PROVIDER));
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
......@@ -240,7 +241,7 @@ public class SensorSampleService extends Service implements SensorEventListener
Log.d(TAG, "Starting service.");
// Set the sensor type and the logging interval from the activity that started the service
loggingInterval = intent.getExtras().getLong(LOG_INTERVAL);
loggingInterval = Objects.requireNonNull(intent.getExtras()).getLong(LOG_INTERVAL);
sampleOnce = intent.getExtras().getBoolean(SAMPLE_ONCE);
tripName = intent.getExtras().getString(TRIP_NAME);
site = intent.getExtras().getString(SITE);
......@@ -249,7 +250,7 @@ public class SensorSampleService extends Service implements SensorEventListener
dbHandler = new Handler();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "fieldday:samplingwakelock");
mWakeLock = Objects.requireNonNull(pm).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "fieldday:samplingwakelock");
mWakeLock.acquire();
if (sampleOnce) {
......@@ -412,7 +413,7 @@ public class SensorSampleService extends Service implements SensorEventListener
builtinList.addAll(mSensorManager.getSensorList(Sensor.TYPE_ALL));
Log.d(TAG, "Built in sensors: " + builtinList.toString());
List<Sensor> toRemove = new ArrayList<Sensor>();
List<Sensor> toRemove = new ArrayList<>();
for (Sensor s : builtinList){
if (s.getStringType().contains("android")){
......
......@@ -28,6 +28,7 @@ import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class SensorScanActivity extends ListActivity {
private boolean scanning, remote_db;
......@@ -56,7 +57,7 @@ public class SensorScanActivity extends ListActivity {
remote_db = getIntent().getBooleanExtra(SensorSampleActivity.REMOTE_DB, false);
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
btAdapter = bluetoothManager.getAdapter();
btAdapter = Objects.requireNonNull(bluetoothManager).getAdapter();
}
@Override
......@@ -110,7 +111,7 @@ public class SensorScanActivity extends ListActivity {
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
filters = new ArrayList<ScanFilter>();
filters = new ArrayList<>();
scanLeDevice(true);
}
mLeDeviceListAdapter = new LeDeviceListAdapter();
......@@ -139,7 +140,7 @@ public class SensorScanActivity extends ListActivity {
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
filters = new ArrayList<ScanFilter>();
filters = new ArrayList<>();
scanLeDevice(true);
}
super.onActivityResult(requestCode, resultCode, data);
......@@ -185,12 +186,12 @@ public class SensorScanActivity extends ListActivity {
// Adapter for holding devices found through scanning.
private class LeDeviceListAdapter extends BaseAdapter {
private ArrayList<BluetoothDevice> mLeDevices;
private LayoutInflater mInflator;
private final ArrayList<BluetoothDevice> mLeDevices;
private final LayoutInflater mInflator;
public LeDeviceListAdapter() {
super();
mLeDevices = new ArrayList<BluetoothDevice>();
mLeDevices = new ArrayList<>();
mInflator = SensorScanActivity.this.getLayoutInflater();
}
......@@ -248,7 +249,7 @@ public class SensorScanActivity extends ListActivity {
}
}
private ScanCallback mLeScanCallback = new ScanCallback() {
private final ScanCallback mLeScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.i("callbackType", String.valueOf(callbackType));
......
......@@ -11,7 +11,10 @@ public class aSensor implements Parcelable {
private float[] lastValues;
private float quality;
private Integer numberValues;
private String type, platform, name, id;
private final String type;
private String platform;
private String name;
private String id;
private Sensor sensor;
// Using Built In sensors
......
......@@ -134,7 +134,7 @@
android:text="@string/sixtySeconds" />
</RadioGroup>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
<ListView
android:layout_width="330dp"
android:layout_height="wrap_content"
android:id="@android:id/list"
......
......@@ -21,7 +21,7 @@
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
......
......@@ -22,7 +22,7 @@
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />-->
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="4dp"
......
......@@ -168,7 +168,7 @@
android:textColor="#FFFFFF" />
</RadioGroup>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
<ListView
android:layout_width="330dp"
android:layout_height="wrap_content"
android:id="@android:id/list"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment