diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1adee69..a728875 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,17 +41,17 @@ + android:value="TODO"/> + android:value="TODO" /> + android:value="TODO" /> + android:value="TODO" /> serviceData = result.getScanRecord().getServiceData(); + Map.Entry entry = serviceData.entrySet().iterator().next(); + byte[] value = entry.getValue(); + byte[] ID = {value[0], value[1], value[2], value[3]}; + String sID = new String(ID); + Log.d(LOG_TAG, sID + " " + device.getAddress()); + } + //Log.d(LOG_TAG, "Timestamp: "+result.getTimestampNanos()+" Name: "+device.getName()+ // " MAC: "+device.getAddress()+ " RSSI: "+result.getRssi()); diff --git a/app/src/main/java/upb/airdocs/Document.java b/app/src/main/java/upb/airdocs/Document.java index 07dd5b5..9e553b0 100644 --- a/app/src/main/java/upb/airdocs/Document.java +++ b/app/src/main/java/upb/airdocs/Document.java @@ -9,12 +9,14 @@ public class Document { public Double latitude = 0.0; public Double longitude = 0.0; public Double altitude = 0.0; + private String similarity = null; - public Document(String name, String description, String fileType, String id) { + public Document(String name, String description, String fileType, String id, String similarity) { this.itemName = name; this.itemDescription = description; this.fileType = fileType; this.id = id; + this.similarity = similarity; } public Document(String name, String description, String fileType, String id, Double latitude, Double longitude, Double altitude) { @@ -27,12 +29,13 @@ public Document(String name, String description, String fileType, String id, Dou this.altitude = altitude; } - public Document(String name, String description, String fileString, String fileType, String id) { + public Document(String name, String description, String fileString, String fileType, String id, String similarity) { this.itemName = name; this.itemDescription = description; this.fileString = fileString; this.fileType = fileType; this.id = id; + this.similarity = similarity; } public Document(String name, String description, String fileString, String fileType, String id, Double latitude, Double longitude, Double altitude) { @@ -64,4 +67,8 @@ public String getFileType() { } public String getId(){ return id;} + + public String getSimilarity() { + return similarity; + } } diff --git a/app/src/main/java/upb/airdocs/DocumentsListAdapter.java b/app/src/main/java/upb/airdocs/DocumentsListAdapter.java index 37b9b72..9713c47 100644 --- a/app/src/main/java/upb/airdocs/DocumentsListAdapter.java +++ b/app/src/main/java/upb/airdocs/DocumentsListAdapter.java @@ -80,12 +80,13 @@ public View getView(int position, View convertView, ViewGroup parent) { final Document currentItem = (Document) getItem(position); String docName = currentItem.getItemName(); final String docDescription = currentItem.getItemDescription(); + final String docSimilarity = currentItem.getSimilarity(); if (!docName.equals("-")) { viewHolder.itemName.setText(docName); }else{ viewHolder.itemName.setVisibility(View.GONE); } - viewHolder.itemDescription.setText(docDescription); + viewHolder.itemDescription.setText(docDescription + " -> " + docSimilarity); String fileString = currentItem.getFileString(); String fileType = currentItem.getFileType(); if (fileString != null){ diff --git a/app/src/main/java/upb/airdocs/ScanService.java b/app/src/main/java/upb/airdocs/ScanService.java index 7825e7b..25b67db 100644 --- a/app/src/main/java/upb/airdocs/ScanService.java +++ b/app/src/main/java/upb/airdocs/ScanService.java @@ -1,5 +1,6 @@ package upb.airdocs; +import android.app.Activity; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -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; @@ -126,6 +129,7 @@ public class ScanService extends Service implements IALocationListener, IARegio String file; String fileType; String delId; + String activity; IALocationManager mManager; @@ -448,7 +452,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(); numberOfCollections = 0; @@ -497,7 +511,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(); @@ -701,4 +714,19 @@ public void onExitRegion(IARegion iaRegion) { mCurrentFloorPlan = iaRegion; } } + 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(); + } + } diff --git a/app/src/main/java/upb/airdocs/SearchDocumentActivity.java b/app/src/main/java/upb/airdocs/SearchDocumentActivity.java index 4087bb8..66b458c 100644 --- a/app/src/main/java/upb/airdocs/SearchDocumentActivity.java +++ b/app/src/main/java/upb/airdocs/SearchDocumentActivity.java @@ -439,13 +439,13 @@ private ArrayList generateItemsList(String jsonString) { System.out.println("latitude" + latitude); System.out.println("longitude" + longitude); + String similarity = docInfo.get("similarity").toString(); if (docInfo.has("file")){ String fileString = (String)docInfo.get("file"); -// TODO HERE - list.add(new Document(docName, docDescription, fileString, fileType, id)); + list.add(new Document(docName, docDescription, fileString, fileType, id, similarity)); } else { - list.add(new Document(docName, docDescription, fileType, id)); + list.add(new Document(docName, docDescription, fileType, id, similarity)); } } diff --git a/app/src/main/java/upb/airdocs/TestingActivity.java b/app/src/main/java/upb/airdocs/TestingActivity.java index 97d39fc..e0bc837 100644 --- a/app/src/main/java/upb/airdocs/TestingActivity.java +++ b/app/src/main/java/upb/airdocs/TestingActivity.java @@ -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) { @@ -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); @@ -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(); + } + } diff --git a/app/src/main/java/upb/airdocs/WiFiScan.java b/app/src/main/java/upb/airdocs/WiFiScan.java index c6d55be..616be46 100644 --- a/app/src/main/java/upb/airdocs/WiFiScan.java +++ b/app/src/main/java/upb/airdocs/WiFiScan.java @@ -6,8 +6,10 @@ import android.content.Intent; import android.content.IntentFilter; import android.location.LocationManager; +import android.media.AudioManager; import android.media.Ringtone; import android.media.RingtoneManager; +import android.media.ToneGenerator; import android.net.Uri; import android.net.wifi.ScanResult; import android.net.wifi.WifiManager; @@ -147,13 +149,8 @@ private void scanSuccess() { } private void beep(){ - try { - Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - Ringtone r = RingtoneManager.getRingtone(mContext, notification); - r.play(); - } catch (Exception e) { - e.printStackTrace(); - } + ToneGenerator toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 200); + toneGen1.startTone(ToneGenerator.TONE_CDMA_PIP,150); } public void unregisterReceiver(){