Commit 461cd126 authored by y0no's avatar y0no
Browse files

Create context getter on NewBtLE

Remove useless context argument from BtScanner constructor
Update FingerprintMgr class
Save signature to file
parent f8cbe015
......@@ -7,7 +7,6 @@ import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.util.Log;
import android.widget.ListView;
import android.widget.TextView;
......@@ -26,14 +25,12 @@ public class BtScanner {
private DeviceAdapter m_oUiAdapter;
private TextView m_oStatus;
private ListView m_oList;
private Context m_oContext;
private List<ScanFilter> m_lFilter;
private ScanSettings m_oSettings;
private HashMap<String, DeviceInfo> m_oDetectedDevices;
public BtScanner(Context context, TextView status, ListView list) {
m_oContext = context;
public BtScanner(TextView status, ListView list) {
m_oStatus = status;
m_oList = list;
m_oUiAdapter = (DeviceAdapter)m_oList.getAdapter();
......
package fr.y0no.newbtle;
import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
......@@ -8,7 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import fr.y0no.newbtle.utils.ADParser;
import fr.y0no.newbtle.utils.Conversion;
import fr.y0no.newbtle.utils.FileLog;
/**
* Created by y0no on 08/07/16.
......@@ -54,6 +53,13 @@ public class FingerprintMgr {
public static void addSignature(String name, DeviceSignature signature) {
m_oSignatures.put(name, signature);
Log.d(TAG, "New signature : " + signature.getName());
Log.d(TAG, m_oSignatures.toString());
// Add signature to text file
String sigFile = String.format("%s;%s;%s",name, signature.getType(), signature.getName());
FileLog.write("signature.txt", sigFile,NewBtLE.getContext());
}
public static DeviceSignature getOrCreateSignature(DeviceInfo device) {
......@@ -67,16 +73,14 @@ public class FingerprintMgr {
ADParser.toRecords(signature))) {
Log.d(TAG, "Signature already known : " + model.getName());
device.setM_oSignature(model);
return model;
}
}
String signatureString = ADParser.toSignature(device.getM_bData());
String sigString = ADParser.toSignature(device.getM_bData());
DeviceSignature signature = new DeviceSignature(DEVICE_TYPE.UNKNOWN, device.getDeviceName());
m_oSignatures.put(signatureString, signature);
Log.d(TAG, "New signature : " + signature.getName());
Log.d(TAG, m_oSignatures.toString());
addSignature(sigString, signature);
return signature;
}
......@@ -92,7 +96,6 @@ public class FingerprintMgr {
}
}
}
Log.d(TAG, "Type found: " + type_found);
return type_found;
}
}
package fr.y0no.newbtle;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.annotation.NonNull;
......@@ -18,16 +19,20 @@ public class NewBtLE extends AppCompatActivity {
private final static String TAG = "NEWBTLE/Activity";
private final static int MY_PERMISSIONS_REQUEST_GPS = 1;
private boolean m_bScanning = false;
private boolean m_bPermissions = true;
private BtScanner m_oBtScanner;
private TextView m_oStatus;
private ListView m_oList;
private DeviceAdapter m_oAdapter;
private static Context m_oContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NewBtLE.m_oContext = getApplicationContext();
setContentView(R.layout.activity_main);
m_oStatus = (TextView)findViewById(R.id.tStatus);
......@@ -58,7 +63,7 @@ public class NewBtLE extends AppCompatActivity {
}
private void startScan() {
m_oBtScanner = new BtScanner(getApplicationContext(), m_oStatus, m_oList);
m_oBtScanner = new BtScanner(m_oStatus, m_oList);
if (m_oBtScanner.enableAdapter() && !m_bScanning && m_bPermissions) {
m_oBtScanner.startScan();
m_bScanning = true;
......@@ -85,4 +90,8 @@ public class NewBtLE extends AppCompatActivity {
}
}
public static Context getContext() {
return NewBtLE.m_oContext;
}
}
package fr.y0no.newbtle.utils;
import android.content.Context;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Created by y0no on 08/07/16.
*/
public class FileLog {
private static final String TAG = "FileWriter";
public static void write(String filename, String message, Context context) {
try {
File path = context.getExternalFilesDir(null);
File file = new File(path, filename);
FileOutputStream stream = new FileOutputStream(file, true);
stream.write(message.getBytes());
stream.write('\n');
stream.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
}
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