Commit e3861bbf authored by Craig Earley's avatar Craig Earley
Browse files

Merge branch 'lint-fixes' into 'master'

Lint fixes

See merge request !12
parents 93d58be6 0c1dd4b7
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="FieldDay" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -62,8 +62,8 @@ android {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-drive:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.0.0'
implementation 'com.google.android.gms:play-services-basement:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.android.gms:play-services-basement:17.1.0'
implementation 'androidx.preference:preference:1.0.0'
}
productFlavors {
......
package fieldscience.cs.earlham.edu.fieldday;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
public class AboutFragment extends Fragment {
class AboutFragment extends Fragment {
public AboutFragment() {
// required empty constructor
......@@ -20,7 +20,7 @@ public class AboutFragment extends Fragment {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_about, container, false);
}
......@@ -28,9 +28,5 @@ public class AboutFragment extends Fragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
}
}
\ No newline at end of file
......@@ -47,29 +47,38 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
public class BenchSampleActivity extends AppCompatActivity {
private static final String TAG = BenchSampleActivity.class.getSimpleName();
public static final String REMOTE_DB = "Remote DB Connected";
private static final String REMOTE_DB = "Remote DB Connected";
private static final String table = "fieldday_reading";
Spinner siteSpinner, sectorSpinner, spotSpinner, platformSpinner, sensorSpinner;
EditText valueET, qualityET, notesET;
ReadingsDatabase db;
String site, sector, spot, platform, sensorName, sensorValue, sensorQuality, tripName, readingNotes, pictureName;
boolean remote_db;
List<String> spotList, platformList;
List<Pair<String, String>> siteList, sectorList, sensorList;
Pair<String, String> sitePair, sectorPair, sensorPair;
Button recordButton, addPictureButton;
private Spinner sectorSpinner;
private Spinner spotSpinner;
private ReadingsDatabase db;
private String site;
private String sector;
private String spot;
private String platform;
private String sensorName;
private String sensorValue;
private String sensorQuality;
private String tripName;
private String readingNotes;
private String pictureName;
private List<String> spotList;
private Pair<String, String> sitePair;
private Pair<String, String> sectorPair;
private Pair<String, String> sensorPair;
private DropdownListAdapter siteAdapter, sectorAdapter, sensorAdapter;
Context context;
ProgressDialog progress;
public static final String directory = ReadingsDatabase.directory;
public static final aSensor sensor = new aSensor("someid","somename");
Uri pictureUri;
File baseDir;
private Context context;
private ProgressDialog progress;
private static final String directory = ReadingsDatabase.directory;
private static final aSensor sensor = new aSensor("someid","somename");
private Uri pictureUri;
private File baseDir;
@Override
protected void onCreate(Bundle savedInstanceState){
......@@ -84,16 +93,16 @@ public class BenchSampleActivity extends AppCompatActivity {
TextView trip_name = findViewById(R.id.tripNameText);
trip_name.setText(String.format("Trip Name: %s", tripName));
siteList = new ArrayList<>();
sectorList = new ArrayList<>();
List<Pair<String, String>> siteList = new ArrayList<>();
List<Pair<String, String>> sectorList = new ArrayList<>();
spotList = new ArrayList<>();
platformList = new ArrayList<>();
sensorList = new ArrayList<>();
List<String> platformList = new ArrayList<>();
List<Pair<String, String>> sensorList = new ArrayList<>();
remote_db = getIntent().getBooleanExtra(REMOTE_DB, false);
boolean remote_db = getIntent().getBooleanExtra(REMOTE_DB, false);
readingNotes = "";
recordButton = findViewById(R.id.recordButton);
addPictureButton = findViewById(R.id.addPicture);
Button recordButton = findViewById(R.id.recordButton);
Button addPictureButton = findViewById(R.id.addPicture);
baseDir = new File(directory);
if (!baseDir.exists()){
baseDir.mkdir();
......@@ -102,7 +111,7 @@ public class BenchSampleActivity extends AppCompatActivity {
// Site spinner, site adapter
if (remote_db) { siteList = db.getSites(null); }
siteList.add(0, new Pair<>("Site", "0"));
siteSpinner = findViewById(R.id.selectSite);
Spinner siteSpinner = findViewById(R.id.selectSite);
siteAdapter = new DropdownListAdapter(this);
siteAdapter.addItems(siteList);
siteSpinner.setAdapter(siteAdapter);
......@@ -116,7 +125,7 @@ public class BenchSampleActivity extends AppCompatActivity {
// Platform spinner, platform adapter
if (remote_db) { platformList.addAll(db.getPlatforms()); }
platformList.add(0, "Platform");
platformSpinner = findViewById(R.id.selectPlatform);
Spinner platformSpinner = findViewById(R.id.selectPlatform);
ArrayAdapter<String> platformAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, platformList);
platformAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
......@@ -124,7 +133,7 @@ public class BenchSampleActivity extends AppCompatActivity {
// Sensor spinner, sensor adapter
sensorList.add(0, new Pair<>("Sensor", "0"));
sensorSpinner = findViewById(R.id.selectSensor);
Spinner sensorSpinner = findViewById(R.id.selectSensor);
sensorAdapter = new DropdownListAdapter(this);
sensorAdapter.addItems(sensorList);
sensorSpinner.setAdapter(sensorAdapter);
......@@ -216,7 +225,7 @@ public class BenchSampleActivity extends AppCompatActivity {
}
});
notesET = findViewById(R.id.readingNotes);
EditText notesET = findViewById(R.id.readingNotes);
notesET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
......@@ -234,7 +243,7 @@ public class BenchSampleActivity extends AppCompatActivity {
}
});
valueET = findViewById(R.id.sensorValue);
EditText valueET = findViewById(R.id.sensorValue);
valueET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
......@@ -257,7 +266,7 @@ public class BenchSampleActivity extends AppCompatActivity {
}
});
qualityET = findViewById(R.id.sensorQuality);
EditText qualityET = findViewById(R.id.sensorQuality);
qualityET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
......@@ -290,22 +299,22 @@ public class BenchSampleActivity extends AppCompatActivity {
});
}
public boolean checkFields() {
private boolean checkFields() {
if ((site == null) || (sector == null) || (spot == null) || (platform == null) ||
(sensor == null) || (sensorValue == null) || (sensorQuality == null)) {
(sensorQuality == null)) {
return false;
} else {
return true;
}
}
public void makeToast(String message) {
private void makeToast(String message) {
Toast t = Toast.makeText(this, message, Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
t.show();
}
public void recordSample() {
private void recordSample() {
Map<String, Float> geo;
geo = findGeoInfo();
if (! geo.isEmpty()) {
......@@ -324,12 +333,12 @@ public class BenchSampleActivity extends AppCompatActivity {
}
public String getTimestamp() {
private String getTimestamp() {
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
return s.format(new Date());
}
public Map<String, Float> findGeoInfo() {
private Map<String, Float> findGeoInfo() {
Map<String,Float> geo = new HashMap<>();
Cursor c = db.query(ReadingsDatabase.T_READING,
"siteID = ? and sectorID = ? and spotID = ?",
......@@ -429,7 +438,7 @@ public class BenchSampleActivity extends AppCompatActivity {
// By default android pictures using the Media.IMAGE_CAPTURE are not full size when returning from
// the activity. I crete a temporary directory to save the file in and retrieve it later.
public File createTempFile() throws Exception {
private File createTempFile() throws Exception {
File temp = new File(baseDir, "tmp");
if (!temp.exists()){
temp.mkdir();
......@@ -465,7 +474,7 @@ public class BenchSampleActivity extends AppCompatActivity {
picturesDir.mkdir();
}
int count = 0;
for (File f : picturesDir.listFiles()){
for (File f : Objects.requireNonNull(picturesDir.listFiles())){
if (f.getName().startsWith(pictureName)){
count += 1;
}
......
......@@ -33,11 +33,11 @@ public class BluetoothLeService extends Service {
public static String current_request = "";
public static boolean isBean = false;
public final static UUID UUID_BLE_SENSOR_VALUE = UUID
private final static UUID UUID_BLE_SENSOR_VALUE = UUID
.fromString(GattAttributes.BLE_SENSOR_VALUE_RX);
public final static UUID UUID_BLE_SENSOR_REQUEST = UUID
private final static UUID UUID_BLE_SENSOR_REQUEST = UUID
.fromString(GattAttributes.BLE_SENSOR_REQUEST_TX);
public final static UUID UUID_BLE_SENSOR_SERVICE = UUID
private final static UUID UUID_BLE_SENSOR_SERVICE = UUID
.fromString(GattAttributes.BLE_SENSOR_SERVICE);
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
......
......@@ -60,7 +60,6 @@ public class BluetoothSensor implements Parcelable {
}
public void setPrimaryService(BluetoothGattService service){
BluetoothGattService sensorService = service;
}
public void setCharacteristics(BluetoothGattCharacteristic writeChar, BluetoothGattCharacteristic readChar){
......@@ -74,7 +73,7 @@ public class BluetoothSensor implements Parcelable {
}
// Returns true if connection succeeded
public boolean connect(Context context){
public void connect(Context context){
gattClient.connect(context, device);
// This listener is used when changes happen in the GattClient class. It is implemented in
......@@ -104,7 +103,7 @@ public class BluetoothSensor implements Parcelable {
}
};
gattClient.setListener(listener);
return gattClient.isConnected();
gattClient.isConnected();
}
// Disconnects from the GATT server
......
......@@ -37,28 +37,29 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
public class DatabaseActionsActivity extends AppCompatActivity {
private static final String DB_DRIVER = "org.postgresql.Driver";
private static final String[] uploadTables = {"fieldday_spot", "fieldday_reading", "fieldday_streaming"};
EditText dbName, username, password, server, port;
Button setup, upload, clean, cleanReadings, cleanStreaming, cleanField;
private String uname, database, pass, host, pNum;
static final String hostid = Build.SERIAL;
private static final String hostid = Build.SERIAL;
public static String trip, url;
public static int tripID, downloadColumnCount = 0, uploadColumnCount = 0;
private static String trip;
private static int tripID;
private static int downloadColumnCount = 0;
private static int uploadColumnCount = 0;
private TextView cleanTV, uploadTV, downloadTV, dbSizeTV, dbStatusTV;
public String[] tripArray, tripIds;
Resources res;
View button;
private String[] tripArray;
private String[] tripIds;
private Resources res;
private View button;
private Connection connection;
SharedPreferences settings;
SharedPreferences.Editor editor;
private SharedPreferences.Editor editor;
private ReadingsDatabase db;
public ProgressDialog progressDialog;
private ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -75,7 +76,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
db = new ReadingsDatabase(getApplicationContext());
settings= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor = settings.edit();
for (String table : ReadingsDatabase.tables) {
......@@ -99,7 +100,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
downloadTV.setText(String.format(res.getString(R.string.lastDownload), settings.getString("lastDownload", "Never")));
server = findViewById(R.id.serverIp);
EditText server = findViewById(R.id.serverIp);
host = settings.getString("host", "cluster.earlham.edu");
server.setText(host);
editor.putString("host", host);
......@@ -123,7 +124,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
dbName = findViewById(R.id.database);
EditText dbName = findViewById(R.id.database);
database = settings.getString("database_name", "field_science");
dbName.setText(database);
editor.putString("database_name", database);
......@@ -147,7 +148,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
username = findViewById(R.id.username);
EditText username = findViewById(R.id.username);
uname = settings.getString("username", "fieldsci");
username.setText(uname);
editor.putString("username", uname);
......@@ -171,7 +172,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
password = findViewById(R.id.password);
EditText password = findViewById(R.id.password);
pass = settings.getString("password", "skalanes");
password.setText(pass);
editor.putString("password", pass);
......@@ -195,7 +196,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
port = findViewById(R.id.port);
EditText port = findViewById(R.id.port);
pNum = settings.getString("port", "5432");
port.setText(pNum);
editor.putString("port", pNum);
......@@ -219,7 +220,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
setup = findViewById(R.id.setupDbButton);
Button setup = findViewById(R.id.setupDbButton);
setup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -227,7 +228,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
clean = findViewById(R.id.wipeDatabase);
Button clean = findViewById(R.id.wipeDatabase);
clean.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -235,7 +236,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
cleanReadings = findViewById(R.id.wipeReadingsTable);
Button cleanReadings = findViewById(R.id.wipeReadingsTable);
cleanReadings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -243,7 +244,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
cleanStreaming = findViewById(R.id.wipeStreamingTable);
Button cleanStreaming = findViewById(R.id.wipeStreamingTable);
cleanStreaming.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -251,7 +252,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
cleanField = findViewById(R.id.wipeFieldData);
Button cleanField = findViewById(R.id.wipeFieldData);
cleanField.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -259,7 +260,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
}
});
upload = findViewById(R.id.uploadButton);
Button upload = findViewById(R.id.uploadButton);
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
......@@ -275,7 +276,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
progressDialog.setProgress(0);
}
public void verify(final View view){
private void verify(final View view){
AlertDialog.Builder builder = new AlertDialog.Builder(DatabaseActionsActivity.this);
switch(view.getId()){
case R.id.setupDbButton:
......@@ -358,7 +359,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
@Override
protected Boolean doInBackground(Void... params) {
try {
url = "jdbc:postgresql://" + host + ":" + pNum + "/" + database;
String url = "jdbc:postgresql://" + host + ":" + pNum + "/" + database;
connection = DriverManager.getConnection(url, uname, pass);
if (connection != null) {
return true;
......@@ -679,7 +680,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
try {
connection.rollback();
} catch (SQLException ex){
Log.e("Rollback", ex.getMessage());
Log.e("Rollback", Objects.requireNonNull(ex.getMessage()));
}
e.printStackTrace();
return false;
......@@ -688,7 +689,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
return null;
}
public String getColumn(Cursor c, String column) {
String getColumn(Cursor c, String column) {
switch (db.getColumnType(column)) {
case ReadingsDatabase.FLOAT:
return(Float.toString(c.getFloat(c.getColumnIndex(column))));
......@@ -740,12 +741,12 @@ public class DatabaseActionsActivity extends AppCompatActivity {
t.show();
}
public String getTimestamp(){
private String getTimestamp(){
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
return s.format(new Date());
}
public void displayDatabaseStatus(int status){
private void displayDatabaseStatus(int status){
String message = "";
int readRows = db.query(ReadingsDatabase.T_READING,null,null).getCount();
int streamRows = db.query(ReadingsDatabase.T_STREAM,null,null).getCount();
......
......@@ -11,7 +11,7 @@ import com.google.android.gms.drive.DriveFolder;
import com.google.android.gms.drive.Metadata;
import com.google.android.gms.drive.widget.DataBufferAdapter;
public class DriveResultsAdapter extends DataBufferAdapter<Metadata> {
class DriveResultsAdapter extends DataBufferAdapter<Metadata> {
private final Context context;
......
......@@ -12,7 +12,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class DropdownListAdapter extends BaseAdapter {
class DropdownListAdapter extends BaseAdapter {
private final ArrayList<Pair<String, String>> dropdownList;
private final Context context;
......@@ -75,7 +75,7 @@ public class DropdownListAdapter extends BaseAdapter {
return view;
}
public class ViewHolderItem {
class ViewHolderItem {
TextView itemName;
ViewHolderItem() {
......
......@@ -2,13 +2,13 @@ package fieldscience.cs.earlham.edu.fieldday;
import java.util.HashMap;
public class GattAttributes {
class GattAttributes {
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";
private static final String BLE_DEVICE_INFO = "0000180a-0000-1000-8000-00805f9b34fb";
static {
attributes.put(BLE_DEVICE_INFO, "Device Information Service");
......
......@@ -13,7 +13,7 @@ import android.util.Log;
import java.util.List;
import java.util.UUID;
public class GattClient {
class GattClient {
private BluetoothGatt gattClient;
private boolean connected;
private Listener mListener;
......@@ -65,8 +65,10 @@ public class GattClient {
gattClient = device.connectGatt(context, false, mGattCallback);
}
public boolean isConnected(){
return gattClient != null && gattClient.connect();
public void isConnected(){
if (gattClient != null) {
gattClient.connect();
}
}