Skip to content

Commit

Permalink
Send documents from the TestingActivity. The documents will be stored…
Browse files Browse the repository at this point in the history
… in the database.
  • Loading branch information
LauraRuse committed Jul 21, 2022
1 parent 26c1fc6 commit 9873548
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Binary file modified app/build/outputs/apk/debug/app-debug.apk
Binary file not shown.
32 changes: 30 additions & 2 deletions app/src/main/java/upb/airdocs/ScanService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package upb.airdocs;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand All @@ -8,6 +9,8 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Build;
Expand Down Expand Up @@ -105,6 +108,7 @@ public class ScanService extends Service {
String file;
String fileType;
String delId;
String activity;

public ScanService() {
}
Expand Down Expand Up @@ -369,7 +373,17 @@ public void sendJSONtoServer(JSONObject jsonObject, int type){
numberOfTotalScans = 0;
sent = 1;
Log.d(LOG_TAG, "Success (send doc)");
announceSendDone(null);
restoreActivityName();
Log.d(LOG_TAG, "Activity name: "+activity);
if (activity != null && activity.equals("Testing")){
displayNumberOfScans();
displaySendStatus();
}
else {
announceSendDone(null);
}
saveActivityName(null);

} else if (type == TYPE_SEARCH_DOC) {
collectionsList = new ArrayList<FingerprintCollection>();
numberOfCollections = 0;
Expand Down Expand Up @@ -418,7 +432,6 @@ public void handleMessage(Message msg) {
case MSG_SEND:
Log.d(LOG_TAG, "Send test fingerprints");
Log.d(LOG_TAG, "address=" + address + " port=" + port);
sendFingerprintsToServer(TYPE_TESTING);
break;
case MSG_START_SCAN:
restoreFieldsTesting();
Expand Down Expand Up @@ -581,4 +594,19 @@ private void restoreAllFields(){
currentFingerprintCollection.setComment(comment);
}

private void restoreActivityName() {
Context context = getApplicationContext();
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file), Context.MODE_PRIVATE);
activity = sharedPref.getString("activity", null);
}
private void saveActivityName(String name){

Context context = getApplicationContext();
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();

editor.putString("activity", name);
editor.apply();
}

}
15 changes: 13 additions & 2 deletions app/src/main/java/upb/airdocs/TestingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ private void getDevIDAndStartService(){
public void onSendButton() {
if (mBound) {
// Create and send a message to the service, using a supported 'what' value
Message msg = Message.obtain(null, ScanService.MSG_SEND, 0, 0);
saveActivityName("Testing");
Message msg = Message.obtain(null, ScanService.MSG_ACTUAL_SEND_DOC, 0, 0);
try {
mMessenger.send(msg);
} catch (RemoteException e) {
Expand All @@ -195,7 +196,7 @@ public void onStartScan() {
if (mBound) {
Message msg;
// Create and send a message to the service, using a supported 'what' value
msg = Message.obtain(null, ScanService.MSG_START_SCAN, 0, 0);
msg = Message.obtain(null, ScanService.MSG_SCAN_TO_POST_DOC, 0, 0);

try {
mMessenger.send(msg);
Expand Down Expand Up @@ -635,4 +636,14 @@ private void restoreFields(){
devIDTextView.setText(devID);
}

private void saveActivityName(String name){

Context context = getApplicationContext();
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();

editor.putString("activity", name);
editor.apply();
}

}

0 comments on commit 9873548

Please sign in to comment.