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

Merge branch 'upgrade-android-version' into 'master'

Upgrading the Android version and related components

See merge request !8
parents 88d2270b fb570df5
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
......@@ -32,12 +32,12 @@ def computeVersionCode = { ->
return VersionCode
}
android {
compileSdkVersion 22
compileSdkVersion 27
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "fieldscience.cs.earlham.edu.fieldday"
minSdkVersion 21
targetSdkVersion 22
minSdkVersion 23
targetSdkVersion 27
versionName "fieldDay_" + getGitHash() + "_" + getVersionCode() + ".apk"
}
buildTypes {
......@@ -59,10 +59,10 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-drive:8.4.0'
implementation 'com.google.android.gms:play-services-auth:8.4.0'
implementation 'com.google.android.gms:play-services-base:8.4.0'
implementation 'com.google.android.gms:play-services-basement:8.4.0'
implementation 'com.google.android.gms:play-services-drive:11.0.0'
implementation 'com.google.android.gms:play-services-auth:11.0.0'
implementation 'com.google.android.gms:play-services-base:11.0.0'
implementation 'com.google.android.gms:play-services-basement:11.0.0'
}
productFlavors {
}
......
......@@ -2,14 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fieldscience.cs.earlham.edu.fieldday">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.bluetooth_le" />
<uses-feature
......@@ -17,6 +17,7 @@
android:required="false" />
<application
android:allowBackup="true"
android:supportsRtl="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MainTheme">
......
......@@ -2,6 +2,7 @@ package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
......@@ -24,8 +25,15 @@ public class AboutFragment extends Fragment {
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
}
}
@Override
......
package fieldscience.cs.earlham.edu.fieldday;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
......@@ -9,6 +10,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
......@@ -17,6 +19,7 @@ import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
......@@ -62,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;
......@@ -181,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();
}
......@@ -315,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() {
......@@ -392,6 +394,24 @@ public class BenchSampleActivity extends Activity {
}
public void takePicture(View v) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(BenchSampleActivity.this,
new String[]{Manifest.permission.CAMERA},
1);
return;
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(BenchSampleActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
1);
return;
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ) {
ActivityCompat.requestPermissions(BenchSampleActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);
return;
}
File tempFile = null;
try {
tempFile = createTempFile();
......@@ -452,7 +472,7 @@ public class BenchSampleActivity extends Activity {
File picture = new File(picturesDir, pictureName + ".png");
if (picture.exists()) {
if (count > 0) {
picture = new File(picturesDir, pictureName + "-" + Integer.toString(count) + ".png");
picture = new File(picturesDir, pictureName + "-" + count + ".png");
}
}
......
......@@ -16,8 +16,6 @@ public class BluetoothLeService extends Service {
private final static String TAG = BluetoothLeService.class.getSimpleName();
private BluetoothManager mBluetoothManager;
private BluetoothAdapter mBluetoothAdapter;
private int mConnectionState = STATE_DISCONNECTED;
private BluetoothSensor btSensor;
private static final int STATE_DISCONNECTED = 0;
......@@ -43,8 +41,6 @@ public class BluetoothLeService extends Service {
.fromString(GattAttributes.BLE_SENSOR_SERVICE);
public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
private BluetoothGattService gattService;
private final BluetoothSensor.Listener listener = new BluetoothSensor.Listener() {
@Override
public void onCharacteristicRead(UUID characteristicUUID, String data) {
......@@ -55,7 +51,7 @@ public class BluetoothLeService extends Service {
public void onServiceInformation() {
for (BluetoothGattService s : btSensor.getServices()){
if (s.getUuid().equals(UUID_BLE_SENSOR_SERVICE)) {
gattService = btSensor.getService(UUID_BLE_SENSOR_SERVICE);
BluetoothGattService gattService = btSensor.getService(UUID_BLE_SENSOR_SERVICE);
btSensor.setPrimaryService(gattService);
btSensor.setCharacteristics(
gattService.getCharacteristic(UUID_BLE_SENSOR_REQUEST),
......@@ -113,7 +109,7 @@ public class BluetoothLeService extends Service {
}
}
mBluetoothAdapter = mBluetoothManager.getAdapter();
BluetoothAdapter mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter == null) {
Log.e(TAG, "Unable to obtain a BluetoothAdapter.");
return false;
......@@ -123,7 +119,7 @@ public class BluetoothLeService extends Service {
public boolean connect(BluetoothSensor bluetoothSensor) {
btSensor = bluetoothSensor;
mConnectionState = STATE_CONNECTING;
int mConnectionState = STATE_CONNECTING;
btSensor.setListener(listener);
return btSensor.connect(this);
}
......
......@@ -8,19 +8,18 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.util.List;
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;
private BluetoothGattService sensorService;
public BluetoothSensor(BluetoothDevice device){
Log.d("Bluetooth Sensor", device.toString());
......@@ -61,7 +60,7 @@ public class BluetoothSensor implements Parcelable {
}
public void setPrimaryService(BluetoothGattService service){
sensorService = service;
BluetoothGattService sensorService = service;
}
public void setCharacteristics(BluetoothGattCharacteristic writeChar, BluetoothGattCharacteristic readChar){
......
......@@ -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")));
......@@ -472,7 +472,7 @@ public class DatabaseActionsActivity extends Activity {
while(rs.next()) {
count += 1;
for (String column : columns){
publishProgress(new Integer[]{index, count});
publishProgress(index, count);
switch(db.getColumnType(column)){
case ReadingsDatabase.FLOAT:
cv.put(column, rs.getFloat(column));
......@@ -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) {
......@@ -562,7 +562,7 @@ public class DatabaseActionsActivity extends Activity {
int count = 0;
for (String table : tables) {
String columns[] = db.getColumns(table);
String[] columns = db.getColumns(table);
// Query local sqlite table, all columns, all rows
Cursor c = db.query(table, null, null);
int index = Arrays.asList(tables).indexOf(table);
......@@ -582,7 +582,7 @@ public class DatabaseActionsActivity extends Activity {
while (c.moveToNext()) {
count += 1;
Log.d("Progress (row count):", Integer.toString(count));
publishProgress(new Integer[] {index, (int) ((((double) count)/((double) totalCount))*100.0)});
publishProgress(index, (int) ((((double) count)/((double) totalCount))*100.0));
String q = String.format(res.getString(
R.string.spotQuery),
Integer.toString(c.getInt(c.getColumnIndex("tripID"))),
......@@ -625,7 +625,7 @@ public class DatabaseActionsActivity extends Activity {
count += 1;
Log.d("Progress (row count):", Integer.toString(count));
float countFraction = ((float) count / (float) totalCount);
publishProgress(new Integer[]{index, (int) (countFraction) * 100});
publishProgress(index, (int) (countFraction) * 100);
for (int i = 0; i < columns.length; i++) {
String piece = getColumn(c, columns[i]);
if (piece.length() > 0) {
......@@ -661,8 +661,8 @@ public class DatabaseActionsActivity extends Activity {
+ "'" + hostid + "'" + ","
+ "'" + startTS + "'" + ","
+ "'" + endTS + "'" + ","
+ Integer.toString(readingCount) + ","
+ Integer.toString(streamingCount)
+ readingCount + ","
+ streamingCount
+ "); ";
Log.d("UPLOADREC Full query", uploadRecordQuery);
st.executeUpdate(uploadRecordQuery);
......@@ -757,21 +757,21 @@ public class DatabaseActionsActivity extends Activity {
break;
case 1:
if (readRows == 1){readRowStr = "reading";}
message = "Initialized, " + Integer.toString(readRows) + " " + readRowStr;
message = "Initialized, " + readRows + " " + readRowStr;
break;
case 2:
if (readRows == 1){readRowStr = "reading";}
if (streamRows == 1){streamRowStr = "stream entry";}
message = "Initialized, "
+ Integer.toString(readRows) + " " + readRowStr + " and "
+ Integer.toString(streamRows) + " " + streamRowStr;
+ readRows + " " + readRowStr + " and "
+ streamRows + " " + streamRowStr;
break;
case 3:
message = "Initialized, no readings or streaming data.";
break;
case 4:
if (streamRows == 1){streamRowStr = "stream entry";}
message = "Initialized, " + Integer.toString(streamRows) + " " + streamRowStr;
message = "Initialized, " + streamRows + " " + streamRowStr;
break;
default:
break;
......
......@@ -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);
......
package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
......@@ -11,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();
......@@ -62,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);
......@@ -61,12 +62,10 @@ public abstract class GoogleDriveConnect extends Activity implements GoogleApiCl
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data){
super.onActivityResult(requestCode,resultCode,data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
if (resultCode == RESULT_OK){
googleApiClient.connect();
}
break;
if (requestCode == REQUEST_CODE_RESOLUTION) {
if (resultCode == RESULT_OK) {
googleApiClient.connect();
}
}
}
......
......@@ -26,9 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
public class GoogleDriveFileBrowser extends GoogleDriveConnect {
private ListView filesListView;
private DriveResultsAdapter filesAdapter;
private Button fileButton, folderButton;
private String fileName;
private DriveId folderId;
private static final String TAG = "GoogleDriveFileBrowser";
......@@ -39,7 +37,7 @@ public class GoogleDriveFileBrowser extends GoogleDriveConnect {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drive);
filesListView = (ListView) findViewById(R.id.listFileResults);
ListView filesListView = (ListView) findViewById(R.id.listFileResults);
filesAdapter = new DriveResultsAdapter(this);
filesListView.setAdapter(filesAdapter);
filesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
......@@ -60,7 +58,7 @@ public class GoogleDriveFileBrowser extends GoogleDriveConnect {
fileName = "";
fileButton = (Button) findViewById(R.id.createFileButton);
Button fileButton = (Button) findViewById(R.id.createFileButton);
fileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -68,7 +66,7 @@ public class GoogleDriveFileBrowser extends GoogleDriveConnect {
}
});
folderButton = (Button) findViewById(R.id.createFolderButton);
Button folderButton = (Button) findViewById(R.id.createFolderButton);
folderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -118,7 +116,7 @@ public class GoogleDriveFileBrowser extends GoogleDriveConnect {
private void askForName(View v){
AlertDialog.Builder builder = new AlertDialog.Builder(GoogleDriveFileBrowser.this, AlertDialog.THEME_HOLO_LIGHT);
final EditText name = new EditText(this);
name.setTextColor(getResources().getColor(R.color.text_green));
// name.setTextColor(getResources().getColor(R.color.text_green));
builder.setView(name);
builder.setNegativeButton("Cancel", null);
......
......@@ -2,6 +2,7 @@ package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
......@@ -23,8 +24,16 @@ public class LabNotebookFragment extends Fragment {
}
@Override
public void onAttach(Activity activity) { super.onAttach(activity); }
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
}
}
@Override
public void onDetach() { super.onDetach(); }
......
package fieldscience.cs.earlham.edu.fieldday;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
......@@ -9,8 +10,10 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.view.View;
public class MainScreenActivity extends Activity {
......@@ -21,6 +24,11 @@ public class MainScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainScreenActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
1);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainscreen_frame);
context = this;
......
......@@ -2,6 +2,7 @@ package fieldscience.cs.earlham.edu.fieldday;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
......@@ -23,8 +24,15 @@ public class MainScreenFragment extends Fragment {
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);